Some additional JavaDoc's (PlotMain.class)

Added option to teleport to road on login
This commit is contained in:
Sauilitired 2014-11-20 19:29:05 +01:00
parent 7b83ea2413
commit ef7e021937
6 changed files with 113 additions and 33 deletions

View File

@ -73,6 +73,9 @@ import java.util.concurrent.TimeUnit;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class PlotMain extends JavaPlugin { public class PlotMain extends JavaPlugin {
/**
* Permission that allows for "everything"
*/
public static final String ADMIN_PERMISSION = public static final String ADMIN_PERMISSION =
"plots.admin"; "plots.admin";
/** /**
@ -190,7 +193,7 @@ public class PlotMain extends JavaPlugin {
e.printStackTrace(); 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 * Set the uuid saver
* *
* @param saver new saver * @param saver new saver
* @see com.intellectualcrafters.plot.uuid.UUIDSaver
*/ */
public static void setUUIDSaver(final UUIDSaver saver) { public static void setUUIDSaver(final UUIDSaver saver) {
uuidSaver = saver; uuidSaver = saver;
@ -370,6 +374,12 @@ public class PlotMain extends JavaPlugin {
return new HashSet<>(myplots); 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<PlotId, Plot> getPlots(final String world) { public static HashMap<PlotId, Plot> getPlots(final String world) {
if (plots.containsKey(world)) { if (plots.containsKey(world)) {
return plots.get(world); return plots.get(world);
@ -477,6 +487,13 @@ public class PlotMain extends JavaPlugin {
return (values.toArray(new Plot[values.size()])); 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) { public static boolean removePlot(final String world, final PlotId id, final boolean callEvent) {
if (callEvent) { if (callEvent) {
final PlotDeleteEvent event = new PlotDeleteEvent(world, id); 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")); 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) { public static boolean teleportPlayer(final Player player, final Location from, final Plot plot) {
final PlayerTeleportToPlotEvent event = new PlayerTeleportToPlotEvent(player, from, plot); final PlayerTeleportToPlotEvent event = new PlayerTeleportToPlotEvent(player, from, plot);
Bukkit.getServer().getPluginManager().callEvent(event); 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()))); System.out.println(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + c.s())));
} }
/**
* Reload all translations
* @throws IOException
*/
public static void reloadTranslations() throws IOException { public static void reloadTranslations() throws IOException {
C.setupTranslations(); 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) { public static long getLastPlayed(final UUID uuid) {
if (uuid == null) { if (uuid == null) {
return 0; return 0;
@ -921,7 +937,7 @@ public class PlotMain extends JavaPlugin {
options.put("api.location", Settings.API_URL); options.put("api.location", Settings.API_URL);
options.put("api.custom", Settings.CUSTOM_API); options.put("api.custom", Settings.CUSTOM_API);
options.put("titles", Settings.TITLES); 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.enabled", Settings.MOB_CAP_ENABLED);
options.put("perm-based-mob-cap.max", Settings.MOB_CAP); options.put("perm-based-mob-cap.max", Settings.MOB_CAP);
@ -934,6 +950,7 @@ public class PlotMain extends JavaPlugin {
if (Settings.DEBUG) { if (Settings.DEBUG) {
sendConsoleSenderMessage(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off."); 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.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs");
Settings.WORLDGUARD = config.getBoolean("worldguard.enabled"); Settings.WORLDGUARD = config.getBoolean("worldguard.enabled");
Settings.MOB_PATHFINDING = config.getBoolean("mob_pathfinding"); 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"); Settings.SCHEMATIC_SAVE_PATH = config.getString("schematics.save_path");
} }
/**
* Create a plotworld config section
* @param plotworld World to create the section for
*/
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void createConfiguration(final PlotWorld plotworld) { public static void createConfiguration(final PlotWorld plotworld) {
final Map<String, Object> options = new HashMap<>(); final Map<String, Object> 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) { public static void addPlotWorld(final String world, final PlotWorld plotworld, final PlotManager manager) {
worlds.put(world, plotworld); worlds.put(world, plotworld);
managers.put(world, manager); 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) { public static void removePlotWorld(final String world) {
plots.remove(world); plots.remove(world);
managers.remove(world); managers.remove(world);
worlds.remove(world); worlds.remove(world);
} }
/**
* Get all plots
* @return All Plos in a hashmap (world, Hashmap contiang ids and objects))
*/
public static HashMap<String, HashMap<PlotId, Plot>> getAllPlotsRaw() { public static HashMap<String, HashMap<PlotId, Plot>> getAllPlotsRaw() {
return plots; return plots;
} }
public static void setAllPlotsRaw(final HashMap<String, HashMap<PlotId, Plot>> plots) { /**
PlotMain.plots = new LinkedHashMap<>(plots); * Set all plots
// PlotMain.plots.putAll(plots); *
} * @param plots New Plot LinkedHashMap
*/
public static void setAllPlotsRaw(final LinkedHashMap<String, HashMap<PlotId, Plot>> plots) { public static void setAllPlotsRaw(final LinkedHashMap<String, HashMap<PlotId, Plot>> plots) {
PlotMain.plots = plots; PlotMain.plots = plots;
} }
/** /**
* !!WorldGeneration!! * Set all plots
*
* @param plots New Plot HashMap
*/
public static void setAllPlotsRaw(final HashMap<String, HashMap<PlotId, Plot>> plots) {
PlotMain.plots = new LinkedHashMap<>(plots);
// PlotMain.plots.putAll(plots);
}
/**
* Get the PlotSquared World Generator
*
* @see com.intellectualcrafters.plot.generator.WorldGenerator
*/ */
@Override @Override
public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) { final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) {
return new WorldGenerator(world); return new WorldGenerator(world);
} }
/**
* Setup the logger mechanics
*/
private void setupLogger() { private void setupLogger() {
final File log = new File(getMain().getDataFolder() + File.separator + "logs" + File.separator + "plots.log"); final File log = new File(getMain().getDataFolder() + File.separator + "logs" + File.separator + "plots.log");
if (!log.exists()) { if (!log.exists()) {
@ -1335,7 +1385,7 @@ public class PlotMain extends JavaPlugin {
*/ */
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void onEnable() { final public void onEnable() {
// Pre-Steps // Pre-Steps
{ {
// Init the logger // Init the logger
@ -1560,7 +1610,7 @@ public class PlotMain extends JavaPlugin {
* On unload * On unload
*/ */
@Override @Override
public void onDisable() { final public void onDisable() {
try { try {
C.saveTranslations(); C.saveTranslations();
} catch (Exception e) { } catch (Exception e) {

View File

@ -332,6 +332,7 @@ public class PlotAPI {
* *
* @param c (Caption) * @param c (Caption)
* @see #sendConsoleMessage(String) * @see #sendConsoleMessage(String)
* @see com.intellectualcrafters.plot.config.C
*/ */
public void sendConsoleMessage(@NotNull final C c) { public void sendConsoleMessage(@NotNull final C c) {
sendConsoleMessage(c.s()); sendConsoleMessage(c.s());
@ -342,6 +343,7 @@ public class PlotAPI {
* *
* @param flag Flag that should be registered * @param flag Flag that should be registered
* @see com.intellectualcrafters.plot.flag.FlagManager#addFlag(com.intellectualcrafters.plot.flag.AbstractFlag) * @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) { public void addFlag(@NotNull final AbstractFlag flag) {
FlagManager.addFlag(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#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.util.PlotHelper#getPlotHome(org.bukkit.World, com.intellectualcrafters.plot.object.Plot)
* @see com.intellectualcrafters.plot.object.PlotHomePosition * @see com.intellectualcrafters.plot.object.PlotHomePosition
* @see com.intellectualcrafters.plot.object.Plot
*/ */
public Location[] getLocations(@NotNull final Plot p) { public Location[] getLocations(@NotNull final Plot p) {
final World world = Bukkit.getWorld(p.world); final World world = Bukkit.getWorld(p.world);
@ -485,6 +488,7 @@ public class PlotAPI {
* @return plot bottom location * @return plot bottom location
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotHome(org.bukkit.World, com.intellectualcrafters.plot.object.Plot) * @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.PlotHomePosition
* @see com.intellectualcrafters.plot.object.Plot
*/ */
public Location getHomeLocation(@NotNull final Plot p) { public Location getHomeLocation(@NotNull final Plot p) {
return PlotHelper.getPlotHome(p.getWorld(), p.id); 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 * @param p Plot that you want to get the location for
* @return plot bottom location * @return plot bottom location
* @see com.intellectualcrafters.plot.util.PlotHelper#getPlotBottomLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId) * @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) { public Location getBottomLocation(@NotNull final Plot p) {
final World world = Bukkit.getWorld(p.world); 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 * @param p Plot that you want to get the location for
* @return plot top location * @return plot top location
* @see PlotHelper#getPlotTopLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId) * @see PlotHelper#getPlotTopLoc(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId)
* @see com.intellectualcrafters.plot.object.Plot
*/ */
public Location getTopLocation(@NotNull final Plot p) { public Location getTopLocation(@NotNull final Plot p) {
final World world = Bukkit.getWorld(p.world); final World world = Bukkit.getWorld(p.world);
@ -530,6 +536,7 @@ public class PlotAPI {
* *
* @param c SubCommand, that we want to register * @param c SubCommand, that we want to register
* @see com.intellectualcrafters.plot.commands.MainCommand#subCommands * @see com.intellectualcrafters.plot.commands.MainCommand#subCommands
* @see com.intellectualcrafters.plot.commands.SubCommand
*/ */
public void registerCommand(@NotNull final SubCommand c) { public void registerCommand(@NotNull final SubCommand c) {
MainCommand.subCommands.add(c); MainCommand.subCommands.add(c);

View File

@ -197,6 +197,7 @@ public enum C {
* Teleport / Entry * Teleport / Entry
*/ */
TELEPORTED_TO_PLOT("&6You have been teleported"), TELEPORTED_TO_PLOT("&6You have been teleported"),
TELEPORTED_TO_ROAD("&cYou got teleported to the road"),
/* /*
* Set Block * Set Block
*/ */

View File

@ -29,6 +29,11 @@ package com.intellectualcrafters.plot.config;
*/ */
public class Settings { public class Settings {
/**
* Teleport to path on login
*/
public static boolean TELEPORT_ON_LOGIN = false;
/** /**
* Mob Cap Enabled * Mob Cap Enabled
*/ */

View File

@ -28,6 +28,7 @@ import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.*; import com.intellectualcrafters.plot.object.*;
import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlayerFunctions;
import com.intellectualcrafters.plot.util.PlotHelper;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@ -73,9 +74,14 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} }
// textures(event.getPlayer()); // textures(event.getPlayer());
if (isInPlot(event.getPlayer().getLocation())) { if (isInPlot(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())); plotEntry(event.getPlayer(), getCurrentPlot(event.getPlayer().getLocation()));
} }
} }
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public static void PlayerMove(final PlayerMoveEvent event) { public static void PlayerMove(final PlayerMoveEvent event) {

View File

@ -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 * Get the plot home
* @param w World * @param w World