javadocs + minor restructuring

This commit is contained in:
boy0001 2014-09-25 16:39:13 +10:00
parent f331b1abaa
commit 1a2ff50110
21 changed files with 284 additions and 75 deletions

View File

@ -9,6 +9,11 @@ public class AbstractFlag {
private final String key;
/**
* AbstractFlag is a parameter used in creating a new Flag
* @param key
* The key must be alphabetical characters and <= 16 characters in length
*/
public AbstractFlag(String key) {
if (!StringUtils.isAlpha(key)) {
throw new IllegalArgumentException("Flag must be alphabetic characters");
@ -18,9 +23,17 @@ public class AbstractFlag {
}
this.key = key.toLowerCase();
}
/**
* AbstractFlag key
* @return String
*/
public String getKey() {
return this.key;
}
@Override
public String toString() {
return this.key;
}
}

View File

@ -7,6 +7,17 @@ public class Flag {
private AbstractFlag key;
private String value;
/**
* Flag object used to store basic information for a Plot.
* Flags are a key/value pair.
* For a flag to be usable by a player, you need to register it with PlotSquared.
*
* @param key
* AbstractFlag
* @param value
* Value must be alphanumerical (can have spaces) and be <= 48 characters
* @throws IllegalArgumentException if you provide inadequate inputs
*/
public Flag(AbstractFlag key, String value) {
if (!StringUtils.isAlphanumericSpace(ChatColor.stripColor(value))) {
throw new IllegalArgumentException("Flag must be alphanumerical");
@ -18,14 +29,26 @@ public class Flag {
this.value = value;
}
/**
* Get the AbstractFlag used in creating the flag
* @return AbstractFlag
*/
public AbstractFlag getAbstractFlag() {
return this.key;
}
/**
* Get the key for the AbstractFlag
* @return String
*/
public String getKey() {
return this.key.getKey();
}
/**
* Get the value
* @return String
*/
public String getValue() {
return this.value;
}

View File

@ -8,6 +8,11 @@ public class FlagManager {
private static ArrayList<AbstractFlag> flags;
/**
* Register an AbstractFlag with PlotSquared
* @param flag
* @return
*/
public static boolean addFlag(AbstractFlag flag) {
if (getFlag(flag.getKey()) != null) {
return false;
@ -15,10 +20,20 @@ public class FlagManager {
return flags.add(flag);
}
/**
* Get a list of registered AbstractFlag objects
* @return List (AbstractFlag)
*/
public static List<AbstractFlag> getFlags() {
return flags;
}
/**
* Get an AbstractFlag by a string
* Returns null if flag does not exist
* @param string
* @return AbstractFkag
*/
public static AbstractFlag getFlag(String string) {
for (AbstractFlag flag : flags) {
if (flag.getKey().equalsIgnoreCase(string)) {
@ -28,6 +43,14 @@ public class FlagManager {
return null;
}
/**
* Get an AbstractFlag by a string
*
* @param string
* @param create
* If to create the flag if it does not exist
* @return AbstractFlag
*/
public static AbstractFlag getFlag(String string, boolean create) {
if ((getFlag(string) == null) && create) {
AbstractFlag flag = new AbstractFlag(string);
@ -35,7 +58,22 @@ public class FlagManager {
}
return getFlag(string);
}
/**
* Remove a registered AbstractFlag
* @param flag
* @return boolean
* Result of operation
*/
public static boolean removeFlag(AbstractFlag flag) {
return flags.remove(flag);
}
/**
* Get the flags for a plot
* @param plot
* @return List (AbstractFlag)
*/
public static List<AbstractFlag> getPlotFlags(Plot plot) {
Set<Flag> plotFlags = plot.settings.getFlags();
List<AbstractFlag> flags = new ArrayList<>();

View File

@ -456,7 +456,12 @@ public class PlotHelper {
}
return new Short[] { Short.parseShort(block), 0 };
}
/**
* Clear a plot
* @param requester
* @param plot
*/
public static void clear(final Player requester, final Plot plot) {
final long start = System.nanoTime();
final PlotWorld plotworld = PlotMain.getWorldSettings(Bukkit.getWorld(plot.world));

View File

@ -1,9 +1,22 @@
package com.intellectualcrafters.plot;
public class PlotId {
/**
* x value
*/
public int x;
/**
* y value
*/
public int y;
/**
* PlotId class (PlotId x,y values do not correspond to Block locations)
* @param x
* The plot x coordinate
* @param y
* The plot y coordinate
*/
public PlotId(int x, int y) {
this.x = x;
this.y = y;

View File

@ -10,6 +10,7 @@
package com.intellectualcrafters.plot;
import ca.mera.CameraAPI;
import com.intellectualcrafters.plot.Logger.LogLevel;
import com.intellectualcrafters.plot.Settings.Web;
import com.intellectualcrafters.plot.commands.Camera;
@ -25,7 +26,9 @@ import com.intellectualcrafters.plot.listeners.WorldEditListener;
import com.intellectualcrafters.plot.listeners.WorldGuardListener;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import me.confuser.barapi.BarAPI;
import org.bukkit.*;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.*;
@ -67,10 +70,6 @@ public class PlotMain extends JavaPlugin {
public static File translationsFile;
public static YamlConfiguration translations;
public static int translations_ver = 1;
/**
* list of usable flags
*/
public static Set<Flag> registeredFlags = new HashSet<Flag>();
/**
* MySQL Object
*/
@ -126,28 +125,6 @@ public class PlotMain extends JavaPlugin {
* All loaded plot worlds
*/
private static HashMap<String, PlotWorld> worlds = new HashMap<String, PlotWorld>();
public static Set<Flag> getFlags() {
return registeredFlags;
}
public static boolean isRegisteredFlag(String arg) {
for (Flag flag : registeredFlags) {
if (flag.getKey().equalsIgnoreCase(arg)) {
return true;
}
}
return false;
}
public static boolean registerFlag(Flag flag) {
return registeredFlags.add(flag);
}
public static boolean unRegisterFlag(Flag flag) {
return registeredFlags.remove(flag);
}
/**
* Get all plots
*
@ -495,6 +472,7 @@ public class PlotMain extends JavaPlugin {
worldEdit = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit");
getServer().getPluginManager().registerEvents(new WorldEditListener(), this);
}
if (Settings.WORLDGUARD)
if (getServer().getPluginManager().getPlugin("WorldGuard") != null) {
worldGuard = (WorldGuardPlugin) getServer().getPluginManager().getPlugin("WorldGuard");
getServer().getPluginManager().registerEvents(new WorldGuardListener(this), this);
@ -825,7 +803,8 @@ public class PlotMain extends JavaPlugin {
private static void setupConfig() {
config.set("version", config_ver);
Map<String, Object> options = new HashMap<String, Object>();
// options.put("auto_update", false);
options.put("auto_update", false);
options.put("worldguard.enabled", Settings.WORLDGUARD);
options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT);
options.put("mob_pathfinding", Settings.MOB_PATHFINDING_DEFAULT);
options.put("web.enabled", Web.ENABLED);
@ -847,6 +826,7 @@ public class PlotMain extends JavaPlugin {
Web.ENABLED = config.getBoolean("web.enabled");
Web.PORT = config.getInt("web.port");
Settings.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs");
Settings.WORLDGUARD = config.getBoolean("worldguard.enabled");
Settings.MOB_PATHFINDING = config.getBoolean("mob_pathfinding");
Settings.METRICS = config.getBoolean("metrics");

View File

@ -4,26 +4,27 @@ import java.util.ArrayList;
import org.bukkit.Material;
/**
* This is the PlotWorld class (obviously)
* <br> - All existing PlotWorld instances should be kept in PlotMain (worlds variable)
* <br> - The accessors and mutators are:
* <br> PlotMain.isPlotWorld(world)
* <br> PlotMain.getPlotWorlds() or PlotMain.getPlotWorldsString() <- use this if you don't need to get world objects
* <br> PlotMain.getWorldSettings(World) - get the PlotWorld class for a world
* <br>
* <br> Also added is getWorldPlots(World) as the plots are now sorted per world
* <br>
* <br> To get the world of a plot, you can use plot.world - (string) or plot.getWorld() (world object)
* <br>
* <br> All PlotWorld settings are per world in the settings.yml (these settings are automatically added when a world is loaded, either at startup or if a new world is created):
* <br> - You can find this in the WorldGenerator class (yeah, it's possibly not the best place, but it makes sure worlds are added to the settings.yml)
* <br>
* <br> All new DEFAULT CONSTANTS should be static and be given a value
* <br> All new variables should not be static and should not be given any values here, but rather in the WorldGenerator class
*
**/
public class PlotWorld {
/*
* This is the PlotWorld class (obviously) - All existing PlotWorld
* instances should be kept in PlotMain (worlds variable) - The accessors
* and mutators are: PlotMain.isPlotWorld(world) PlotMain.getPlotWorlds() or
* PlotMain.getPlotWorldsString() <- use this if you don't need to get world
* objects PlotMain.getWorldSettings(World) - get the PlotWorld class for a
* world Also added is getWorldPlots(World) as the plots are now sorted per
* world To get the world of a plot, you can use plot.world - (string) or
* plot.getWorld() (world object) All PlotWorld settings are per world in
* the settings.yml (these settings are automatically added when a world is
* loaded, either at startup or if a new world is created): - You can find
* this in the WorldGenerator class (yeah, it's possibly not the best place,
* but it makes sure worlds are added to the settings.yml) All new DEFAULT
* CONSTANTS should be static and be given a value All new variables should
* not be static and should not be given any values here, but rather in the
* WorldGenerator class
*/
/**
* Road Height
*/

View File

@ -5,6 +5,12 @@ import static com.intellectualcrafters.plot.ReflectionUtils.getRefClass;
import com.intellectualcrafters.plot.ReflectionUtils.RefClass;
import com.intellectualcrafters.plot.ReflectionUtils.RefMethod;
/**
*
* SetBlockFast class<br>
* Used to do fast world editing
*
*/
public class SetBlockFast {
private static final RefClass classBlock = getRefClass("{nms}.Block");

View File

@ -17,6 +17,13 @@ package com.intellectualcrafters.plot;
* @author Empire92
*/
public class Settings {
/**
* WorldGuard region on claimed plots
*/
public static boolean WORLDGUARD = false;
/**
* metrics
*/
public static boolean METRICS = true;
/**
* plot specific resource pack

View File

@ -18,8 +18,10 @@ import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.intellectualcrafters.plot.AbstractFlag;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.Flag;
import com.intellectualcrafters.plot.FlagManager;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
@ -96,8 +98,8 @@ public class PlotAPI {
*
* @param flag
*/
public void registerFlag(Flag flag) {
PlotMain.registerFlag(flag);
public void addFlag(AbstractFlag flag) {
FlagManager.addFlag(flag);
}
/**
@ -105,8 +107,8 @@ public class PlotAPI {
*
* @return array of Flag[]
*/
public Flag[] getRegisteredFlags() {
return PlotMain.getFlags().toArray(new Flag[0]);
public AbstractFlag[] getFlags() {
return FlagManager.getFlags().toArray(new AbstractFlag[0]);
}
/**

View File

@ -24,6 +24,7 @@ import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.AbstractFlag;
import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.Flag;
import com.intellectualcrafters.plot.FlagManager;
import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.Plot;
import com.intellectualcrafters.plot.PlotHelper;
@ -87,10 +88,10 @@ public class Set extends SubCommand {
if (args[0].equalsIgnoreCase("flag")) {
if (args.length < 2) {
PlayerFunctions.sendMessage(plr, C.NEED_KEY.s().replaceAll("%values%", StringUtils.join(PlotMain.getFlags(), "&c, &6")));
PlayerFunctions.sendMessage(plr, C.NEED_KEY.s().replaceAll("%values%", StringUtils.join(FlagManager.getFlags(), "&c, &6")));
return false;
}
if (!PlotMain.isRegisteredFlag(args[1])) {
if (FlagManager.getFlag(args[1])==null) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_FLAG);
return false;
}

View File

@ -105,6 +105,12 @@ public abstract class SubCommand {
this.execute(null, args);
}
/**
* Send a message
* @param plr
* @param c
* @param args
*/
public void sendMessage(Player plr, C c, String... args) {
PlayerFunctions.sendMessage(plr, c, args);
}

View File

@ -25,11 +25,20 @@ public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable {
private Plot plot;
/**
* PlayerClaimPlotEvent: Called when a plot is claimed
* @param player
* @param plot
*/
public PlayerClaimPlotEvent(Player player, Plot plot) {
super(player);
this.plot = plot;
}
/**
* Get the plot involved
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}

View File

@ -15,11 +15,20 @@ public class PlayerEnterPlotEvent extends PlayerEvent {
private Plot plot;
/**
* PlayerEnterPlotEvent: Called when a player leaves a plot
* @param player
* @param plot
*/
public PlayerEnterPlotEvent(Player player, Plot plot) {
super(player);
this.plot = plot;
}
/**
* Get the plot involved
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}

View File

@ -13,16 +13,23 @@ public class PlayerLeavePlotEvent extends PlayerEvent {
private static HandlerList handlers = new HandlerList();
private Plot plot;
/**
* PlayerLeavePlotEvent: Called when a player leaves a plot
* @param player
* @param plot
*/
public PlayerLeavePlotEvent(Player player, Plot plot) {
super(player);
this.plot = plot;
}
/**
* Get the plot involved
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
@Override
public HandlerList getHandlers() {
return handlers;

View File

@ -18,7 +18,13 @@ public class PlayerPlotDeniedEvent extends Event {
private Player initiator;
private boolean added;
private UUID player;
/**
* PlayerPlotDeniedEvent: Called when the denied UUID list is modified for a plot
* @param initiator
* @param plot
* @param player
* @param added
*/
public PlayerPlotDeniedEvent(Player initiator, Plot plot, UUID player, boolean added) {
this.initiator = initiator;
this.plot = plot;
@ -26,18 +32,31 @@ public class PlayerPlotDeniedEvent extends Event {
this.player = player;
}
/**
* If a user was added
* @return boolean
*/
public boolean wasAdded() {
return this.added;
}
/**
* The player added/removed
* @return UUID
*/
public UUID getPlayer() {
return this.player;
}
/**
* The plot involved
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* The player initiating the action
* @return Player
*/
public Player getInitiator() {
return this.initiator;
}

View File

@ -18,26 +18,45 @@ public class PlayerPlotHelperEvent extends Event {
private Player initiator;
private boolean added;
private UUID player;
/**
* PlayerPlotHelperEvent: Called when a plot helper is added/removed
* @param initiator
* @param plot
* @param player
* @param added
*/
public PlayerPlotHelperEvent(Player initiator, Plot plot, UUID player, boolean added) {
this.initiator = initiator;
this.plot = plot;
this.added = added;
this.player = player;
}
/**
* If a player was added
* @return boolean
*/
public boolean wasAdded() {
return this.added;
}
/**
* The UUID added/removed
* @return UUID
*/
public UUID getPlayer() {
return this.player;
}
/**
* The plot involved
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* The player initiating the action
* @return Player
*/
public Player getInitiator() {
return this.initiator;
}

View File

@ -16,7 +16,9 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import com.intellectualcrafters.plot.Plot;
/**
* Called when a player teleports to a plot
*/
public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
@ -24,7 +26,12 @@ public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellabl
private Plot plot;
private boolean cancelled;
/**
* PlayerTeleportToPlotEvent: Called when a player teleports to a plot
* @param player
* @param from
* @param plot
*/
public PlayerTeleportToPlotEvent(Player player, Location from, Plot plot) {
super(player);
this.from = from;
@ -36,10 +43,18 @@ public class PlayerTeleportToPlotEvent extends PlayerEvent implements Cancellabl
return handlers;
}
/**
* Get the from location
* @return Location
*/
public Location getFrom() {
return this.from;
}
/**
* Get the plot involved
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}

View File

@ -16,7 +16,7 @@ import org.bukkit.event.HandlerList;
import com.intellectualcrafters.plot.PlotId;
/**
* Created by Citymonstret on 2014-08-09.
* Called when a plot is deleted
*/
public class PlotDeleteEvent extends Event implements Cancellable {
private static HandlerList handlers = new HandlerList();
@ -24,16 +24,28 @@ public class PlotDeleteEvent extends Event implements Cancellable {
private PlotId id;
private String world;
/**
* PlotDeleteEvent: Called when a plot is deleted
* @param world
* @param id
*/
public PlotDeleteEvent(String world, PlotId id) {
this.id = id;
this.world = world;
}
/**
* Get the PlotId
* @return PlotId
*/
public PlotId getPlotId() {
return this.id;
}
/**
* Get the world name
* @return String
*/
public String getWorld() {
return this.world;
}

View File

@ -17,7 +17,7 @@ import com.intellectualcrafters.plot.Flag;
import com.intellectualcrafters.plot.Plot;
/**
* Created by Citymonstret on 2014-08-09.
* Called when a Flag is added to a plot
*/
public class PlotFlagAddEvent extends Event implements Cancellable {
private static HandlerList handlers = new HandlerList();
@ -26,15 +26,28 @@ public class PlotFlagAddEvent extends Event implements Cancellable {
private Plot plot;
private Flag flag;
/**
* PlotFlagAddEvent: Called when a Flag is added to a plot
* @param flag
* @param plot
*/
public PlotFlagAddEvent(Flag flag, Plot plot) {
this.plot = plot;
this.flag = flag;
}
/**
* Get the plot involved
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* Get the flag involved
* @return Flag
*/
public Flag getFlag() {
return this.flag;
}

View File

@ -17,7 +17,7 @@ import com.intellectualcrafters.plot.Flag;
import com.intellectualcrafters.plot.Plot;
/**
* Created by Citymonstret on 2014-08-09.
* Called when a flag is removed from a plot
*/
public class PlotFlagRemoveEvent extends Event implements Cancellable {
private static HandlerList handlers = new HandlerList();
@ -26,19 +26,30 @@ public class PlotFlagRemoveEvent extends Event implements Cancellable {
private Plot plot;
private Flag flag;
/**
* PlotFlagRemoveEvent: Called when a flag is removed from a plot
* @param flag
* @param plot
*/
public PlotFlagRemoveEvent(Flag flag, Plot plot) {
this.plot = plot;
this.flag = flag;
}
/**
* Get the plot involved
* @return Plot
*/
public Plot getPlot() {
return this.plot;
}
/**
* Get the flag involved
* @return Flag
*/
public Flag getFlag() {
return this.flag;
}
public static HandlerList getHandlerList() {
return handlers;
}