diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index c8024e3f3..4b1388832 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -73,6 +73,9 @@ import java.util.concurrent.TimeUnit; @SuppressWarnings("unused") public class PlotMain extends JavaPlugin { + /** + * Permission that allows for "everything" + */ public static final String ADMIN_PERMISSION = "plots.admin"; /** @@ -190,7 +193,7 @@ public class PlotMain extends JavaPlugin { e.printStackTrace(); } } - }, 0l, /*12 * 60 * 60 * 20l*/ 86_40_00L); + }, 0l, 86_40_00L); } /** @@ -272,6 +275,7 @@ public class PlotMain extends JavaPlugin { * Set the uuid saver * * @param saver new saver + * @see com.intellectualcrafters.plot.uuid.UUIDSaver */ public static void setUUIDSaver(final UUIDSaver saver) { uuidSaver = saver; @@ -370,6 +374,12 @@ public class PlotMain extends JavaPlugin { return new HashSet<>(myplots); } + /** + * Get plots for the specified world + * + * @param world A world, in which you want to search for plots + * @return HashMap containing Plot IDs and Plot Objects + */ public static HashMap getPlots(final String world) { if (plots.containsKey(world)) { return plots.get(world); @@ -477,6 +487,13 @@ public class PlotMain extends JavaPlugin { return (values.toArray(new Plot[values.size()])); } + /** + * Remove a plot + * @param world The Plot World + * @param id The Plot ID + * @param callEvent Whether or not to call the PlotDeleteEvent + * @return true if successful, false if not + */ public static boolean removePlot(final String world, final PlotId id, final boolean callEvent) { if (callEvent) { final PlotDeleteEvent event = new PlotDeleteEvent(world, id); @@ -593,7 +610,12 @@ public class PlotMain extends JavaPlugin { } } - private static double getJavaVersion() { + /** + * Get the java version + * + * @return Java Version as a double + */ + public static double getJavaVersion() { return Double.parseDouble(System.getProperty("java.specification.version")); } @@ -621,27 +643,12 @@ public class PlotMain extends JavaPlugin { } /** - * .. + * Teleport a player to a plot + * @param player Player to teleport + * @param from Previous Location + * @param plot Plot to teleport to + * @return true if successful */ - - // Old Stuff - /* - * private static boolean checkForUpdate() throws IOException { URL call = - * new URL(Settings.Update.VERSION_URL); InputStream stream = - * call.openStream(); BufferedReader reader = new BufferedReader(new - * InputStreamReader(stream)); String latest = reader.readLine(); - * reader.close(); return - * !getPlotMain().getDescription().getVersion().equalsIgnoreCase(latest); } - * private static String getNextUpdateString() throws IOException { URL call - * = new URL(Settings.Update.VERSION_URL); InputStream stream = - * call.openStream(); BufferedReader reader = new BufferedReader(new - * InputStreamReader(stream)); return reader.readLine(); } private static - * void update() throws IOException { sendConsoleSenderMessage(C.PREFIX.s() - * + "&c&lThere is an update! New Update: &6&l" + getNextUpdateString() + - * "&c&l, Current Update: &6&l" + - * getPlotMain().getDescription().getVersion()); } - */ - public static boolean teleportPlayer(final Player player, final Location from, final Plot plot) { final PlayerTeleportToPlotEvent event = new PlayerTeleportToPlotEvent(player, from, plot); Bukkit.getServer().getPluginManager().callEvent(event); @@ -702,10 +709,19 @@ public class PlotMain extends JavaPlugin { System.out.println(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + c.s()))); } + /** + * Reload all translations + * @throws IOException + */ public static void reloadTranslations() throws IOException { C.setupTranslations(); } + /** + * Ge the last played time + * @param uuid UUID for the player + * @return last play time as a long + */ public static long getLastPlayed(final UUID uuid) { if (uuid == null) { return 0; @@ -921,7 +937,7 @@ public class PlotMain extends JavaPlugin { options.put("api.location", Settings.API_URL); options.put("api.custom", Settings.CUSTOM_API); options.put("titles", Settings.TITLES); - + options.put("teleport.on_login", Settings.TELEPORT_ON_LOGIN); options.put("perm-based-mob-cap.enabled", Settings.MOB_CAP_ENABLED); options.put("perm-based-mob-cap.max", Settings.MOB_CAP); @@ -934,6 +950,7 @@ public class PlotMain extends JavaPlugin { if (Settings.DEBUG) { sendConsoleSenderMessage(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off."); } + Settings.TELEPORT_ON_LOGIN = config.getBoolean("teleport.on_login"); Settings.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs"); Settings.WORLDGUARD = config.getBoolean("worldguard.enabled"); Settings.MOB_PATHFINDING = config.getBoolean("mob_pathfinding"); @@ -947,6 +964,10 @@ public class PlotMain extends JavaPlugin { Settings.SCHEMATIC_SAVE_PATH = config.getString("schematics.save_path"); } + /** + * Create a plotworld config section + * @param plotworld World to create the section for + */ @SuppressWarnings("unused") public static void createConfiguration(final PlotWorld plotworld) { final Map options = new HashMap<>(); @@ -1274,6 +1295,12 @@ public class PlotMain extends JavaPlugin { }); } + /** + * Add a Plot world + * @param world World to add + * @param plotworld PlotWorld Object + * @param manager Plot Manager for the new world + */ public static void addPlotWorld(final String world, final PlotWorld plotworld, final PlotManager manager) { worlds.put(world, plotworld); managers.put(world, manager); @@ -1282,33 +1309,56 @@ public class PlotMain extends JavaPlugin { } } + /** + * Remove a plot world + * @param world World to remove + */ public static void removePlotWorld(final String world) { plots.remove(world); managers.remove(world); worlds.remove(world); } + /** + * Get all plots + * @return All Plos in a hashmap (world, Hashmap contiang ids and objects)) + */ public static HashMap> getAllPlotsRaw() { return plots; } - public static void setAllPlotsRaw(final HashMap> plots) { - PlotMain.plots = new LinkedHashMap<>(plots); - // PlotMain.plots.putAll(plots); - } - + /** + * Set all plots + * + * @param plots New Plot LinkedHashMap + */ public static void setAllPlotsRaw(final LinkedHashMap> plots) { PlotMain.plots = plots; } /** - * !!WorldGeneration!! + * Set all plots + * + * @param plots New Plot HashMap + */ + public static void setAllPlotsRaw(final HashMap> plots) { + PlotMain.plots = new LinkedHashMap<>(plots); + // PlotMain.plots.putAll(plots); + } + + /** + * Get the PlotSquared World Generator + * + * @see com.intellectualcrafters.plot.generator.WorldGenerator */ @Override - public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) { + final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) { return new WorldGenerator(world); } + /** + * Setup the logger mechanics + */ private void setupLogger() { final File log = new File(getMain().getDataFolder() + File.separator + "logs" + File.separator + "plots.log"); if (!log.exists()) { @@ -1335,7 +1385,7 @@ public class PlotMain extends JavaPlugin { */ @Override @SuppressWarnings("deprecation") - public void onEnable() { + final public void onEnable() { // Pre-Steps { // Init the logger @@ -1560,7 +1610,7 @@ public class PlotMain extends JavaPlugin { * On unload */ @Override - public void onDisable() { + final public void onDisable() { try { C.saveTranslations(); } catch (Exception e) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java index 816719215..a5171abeb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java @@ -332,6 +332,7 @@ public class PlotAPI { * * @param c (Caption) * @see #sendConsoleMessage(String) + * @see com.intellectualcrafters.plot.config.C */ public void sendConsoleMessage(@NotNull final C c) { sendConsoleMessage(c.s()); @@ -342,6 +343,7 @@ public class PlotAPI { * * @param flag Flag that should be registered * @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag) + * @see com.intellectualcrafters.plot.flag.AbstractFlag */ public void addFlag(@NotNull final AbstractFlag flag) { FlagManager.addFlag(flag); @@ -472,6 +474,7 @@ public class PlotAPI { * @see com.intellectualcrafters.plot.util.PlotHelper#getPlotTopLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId) * @see com.intellectualcrafters.plot.util.PlotHelper#getPlotHome(org.bukkit.World, com.intellectualcrafters.plot.object.Plot) * @see com.intellectualcrafters.plot.object.PlotHomePosition + * @see com.intellectualcrafters.plot.object.Plot */ public Location[] getLocations(@NotNull final Plot p) { final World world = Bukkit.getWorld(p.world); @@ -485,6 +488,7 @@ public class PlotAPI { * @return plot bottom location * @see com.intellectualcrafters.plot.util.PlotHelper#getPlotHome(org.bukkit.World, com.intellectualcrafters.plot.object.Plot) * @see com.intellectualcrafters.plot.object.PlotHomePosition + * @see com.intellectualcrafters.plot.object.Plot */ public Location getHomeLocation(@NotNull final Plot p) { return PlotHelper.getPlotHome(p.getWorld(), p.id); @@ -496,6 +500,7 @@ public class PlotAPI { * @param p Plot that you want to get the location for * @return plot bottom location * @see com.intellectualcrafters.plot.util.PlotHelper#getPlotBottomLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId) + * @see com.intellectualcrafters.plot.object.Plot */ public Location getBottomLocation(@NotNull final Plot p) { final World world = Bukkit.getWorld(p.world); @@ -508,6 +513,7 @@ public class PlotAPI { * @param p Plot that you want to get the location for * @return plot top location * @see PlotHelper#getPlotTopLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId) + * @see com.intellectualcrafters.plot.object.Plot */ public Location getTopLocation(@NotNull final Plot p) { final World world = Bukkit.getWorld(p.world); @@ -530,6 +536,7 @@ public class PlotAPI { * * @param c SubCommand, that we want to register * @see com.intellectualcrafters.plot.commands.MainCommand#subCommands + * @see com.intellectualcrafters.plot.commands.SubCommand */ public void registerCommand(@NotNull final SubCommand c) { MainCommand.subCommands.add(c); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index 16d0d6f7e..331d9c87e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -197,6 +197,7 @@ public enum C { * Teleport / Entry */ TELEPORTED_TO_PLOT("&6You have been teleported"), + TELEPORTED_TO_ROAD("&cYou got teleported to the road"), /* * Set Block */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 158418483..982fa1b93 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -29,6 +29,11 @@ package com.intellectualcrafters.plot.config; */ public class Settings { + /** + * Teleport to path on login + */ + public static boolean TELEPORT_ON_LOGIN = false; + /** * Mob Cap Enabled */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index d761b2861..72e0e3cdb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -28,6 +28,7 @@ import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.util.PlayerFunctions; +import com.intellectualcrafters.plot.util.PlotHelper; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -73,7 +74,12 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi } // textures(event.getPlayer()); if (isInPlot(event.getPlayer().getLocation())) { - plotEntry(event.getPlayer(), getCurrentPlot(event.getPlayer().getLocation())); + if (Settings.TELEPORT_ON_LOGIN) { + event.getPlayer().teleport(PlotHelper.getPlotHomeDefault(getPlot(event.getPlayer()))); + PlayerFunctions.sendMessage(event.getPlayer(), C.TELEPORTED_TO_ROAD); + } else { + plotEntry(event.getPlayer(), getCurrentPlot(event.getPlayer().getLocation())); + } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java index 25d921c53..96071a805 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java @@ -856,6 +856,17 @@ public class PlotHelper { } } + /** + * Retrieve the location of the default plot home position + * @param plot Plot + * @return the location + */ + public static Location getPlotHomeDefault(final Plot plot) { + final Location l = getPlotBottomLoc(plot.getWorld(), plot.getId()).subtract(0, 0, 0); + l.setY(getHeighestBlock(plot.getWorld(), l.getBlockX(), l.getBlockZ())); + return l; + } + /** * Get the plot home * @param w World