From 182f4cbd223acb9f10845b762161effa9a6df0ac Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Sun, 9 Nov 2014 12:51:17 +0100 Subject: [PATCH] Fixed a heckload of warnings --- .../plot/api/PlotAPI.java | 29 +++++----- .../plot/commands/Inbox.java | 3 - .../plot/commands/Info.java | 3 +- .../plot/commands/Kick.java | 4 +- .../plot/commands/Paste.java | 3 - .../plot/commands/Purge.java | 8 +-- .../plot/commands/Rate.java | 4 +- .../plot/commands/Reload.java | 3 - .../plot/commands/Schematic.java | 34 +++++------ .../plot/commands/Set.java | 35 ++++++------ .../plot/commands/Setup.java | 54 +++++++++--------- .../plot/commands/SubCommand.java | 1 + .../plot/commands/TP.java | 7 ++- .../plot/commands/Unlink.java | 18 +++--- .../plot/commands/Visit.java | 24 ++++---- .../plot/commands/list.java | 30 +++++----- .../plot/commands/plugin.java | 56 +++++++++---------- 17 files changed, 153 insertions(+), 163 deletions(-) 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 f433e17eb..c85e5fca2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java @@ -42,11 +42,14 @@ import java.util.Set; @SuppressWarnings({"unused", "javadoc"}) public class PlotAPI { + /** + * Admin Permission + */ + public static final String ADMIN_PERMISSION = "plots.admin"; private static PlotHelper plotHelper; private static PlayerFunctions playerFunctions; private static FlagManager flagManager; private static SchematicHandler schematicHandler; - private static C c; // Methods/fields in PlotMain class @@ -63,15 +66,21 @@ public class PlotAPI { // PlotMain.removePlot(world, id, callEvent) // PlotMain.teleportPlayer(player, from, plot) // PlotMain.updatePlot(plot); + private static C c; + // Reference // To access plotMain stuff. private final PlotMain plotMain; - // Reference /** - * Admin Permission + * Constructor. Insert any Plugin. + * (Optimally the plugin that is accessing the method) + * + * @param plugin Plugin used to access this method */ - public static final String ADMIN_PERMISSION = "plots.admin"; + public PlotAPI(final JavaPlugin plugin) { + this.plotMain = JavaPlugin.getPlugin(PlotMain.class); + } /** * Get all plots @@ -122,16 +131,6 @@ public class PlotAPI { return PlotMain.storage; } - /** - * Constructor. Insert any Plugin. - * (Optimally the plugin that is accessing the method) - * - * @param plugin Plugin used to access this method - */ - public PlotAPI(final JavaPlugin plugin) { - this.plotMain = JavaPlugin.getPlugin(PlotMain.class); - } - /** * Get the main class for this plugin
* - Contains a lot of fields and methods - not very well organized
@@ -288,7 +287,7 @@ public class PlotAPI { * @return array of Flag[] */ public AbstractFlag[] getFlags() { - return FlagManager.getFlags().toArray(new AbstractFlag[0]); + return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]); } /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java index 39994d3b7..0651ee3bd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java @@ -31,9 +31,6 @@ import java.util.Arrays; import java.util.List; import java.util.UUID; -/** - * Created by Citymonstret on 2014-08-01. - */ public class Inbox extends SubCommand { public Inbox() { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java index 4d22738a8..c8353b80d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -36,6 +36,7 @@ import java.util.UUID; /** * @author Citymonstret */ +@SuppressWarnings({"unused", "deprecated", "javadoc"}) public class Info extends SubCommand { public Info() { @@ -55,7 +56,7 @@ public class Info extends SubCommand { plot = PlayerFunctions.getCurrentPlot(player); } else { if (args.length < 2) { - PlayerFunctions.sendMessage(player, C.INFO_SYNTAX_CONSOLE); + PlayerFunctions.sendMessage(null, C.INFO_SYNTAX_CONSOLE); return false; } final PlotWorld plotworld = PlotMain.getWorldSettings(args[0]); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Kick.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Kick.java index 284c1a49a..cad071f8e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Kick.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Kick.java @@ -28,9 +28,7 @@ import com.intellectualcrafters.plot.PlotMain; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -/** - * Created by Citymonstret on 2014-08-01. - */ +@SuppressWarnings({"unused", "deprecation", "javadoc"}) public class Kick extends SubCommand { public Kick() { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Paste.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Paste.java index 255936707..b44ba780c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Paste.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Paste.java @@ -24,9 +24,6 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.*; import org.bukkit.entity.Player; -/** - * Created by Citymonstret on 2014-10-12. - */ public class Paste extends SubCommand { public Paste() { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java index 49ec9d587..9d1484cd0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Purge.java @@ -28,9 +28,7 @@ import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.database.DBFunc; import org.bukkit.entity.Player; -/** - * @Deprecated - */ +@SuppressWarnings({"unused", "deprecated", "javadoc"}) public class Purge extends SubCommand { public Purge() { @@ -54,12 +52,12 @@ public class Purge extends SubCommand { } if (!PlotMain.isPlotWorld(world)) { - PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_WORLD); + PlayerFunctions.sendMessage(null, C.NOT_VALID_PLOT_WORLD); return false; } PlotMain.getPlots(world).remove(id); DBFunc.purge(world, id); - PlayerFunctions.sendMessage(plr, "&aPurge of '" + args[0] + "' was successful!"); + PlayerFunctions.sendMessage(null, "&aPurge of '" + args[0] + "' was successful!"); return true; } catch (final Exception e) { PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index 6bb4958c6..b6c38772e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -26,9 +26,7 @@ import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.Plot; import org.bukkit.entity.Player; -/** - * Created by Citymonstret on 2014-10-02. - */ +@SuppressWarnings({"unused", "deprecated", "javadoc"}) public class Rate extends SubCommand { /* diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Reload.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Reload.java index ddab5c2ce..2db4d7dd1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Reload.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Reload.java @@ -27,9 +27,6 @@ import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotWorld; import org.bukkit.entity.Player; -/** - * @Deprecated - */ public class Reload extends SubCommand { public Reload() { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java index 64a3cadbb..4e8435c86 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Schematic.java @@ -31,21 +31,22 @@ import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; +import java.util.Collection; import java.util.HashMap; public class Schematic extends SubCommand { + private int counter = 0; + private boolean running = false; + private Plot[] plots; + private int task; + public Schematic() { super("schematic", "plots.schematic", "Schematic Command", "schematic {arg}", "sch", CommandCategory.ACTIONS, false); // TODO command to fetch schematic from worldedit directory } - private int counter = 0; - private boolean running = false; - private Plot[] plots; - private int task; - @Override public boolean execute(final Player plr, final String... args) { if (args.length < 1) { @@ -186,16 +187,16 @@ public class Schematic extends SubCommand { return false; } if (args.length != 2) { - PlayerFunctions.sendMessage(plr, "&cNeed world arg. Use &7/plots sch exportall "); + PlayerFunctions.sendMessage(null, "&cNeed world arg. Use &7/plots sch exportall "); return false; } final HashMap plotmap = PlotMain.getPlots(args[1]); if ((plotmap == null) || (plotmap.size() == 0)) { - PlayerFunctions.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall "); + PlayerFunctions.sendMessage(null, "&cInvalid world. Use &7/plots sch exportall "); return false; } if (this.running) { - PlayerFunctions.sendMessage(plr, "&cTask is already running."); + PlayerFunctions.sendMessage(null, "&cTask is already running."); return false; } @@ -206,7 +207,8 @@ public class Schematic extends SubCommand { final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"); - this.plots = plotmap.values().toArray(new Plot[0]); + Collection values = plotmap.values(); + this.plots = values.toArray(new Plot[values.size()]); this.running = true; this.counter = 0; @@ -224,17 +226,17 @@ public class Schematic extends SubCommand { final String o = UUIDHandler.getName(plot.owner); final String owner = o == null ? "unknown" : o; if (sch == null) { - PlayerFunctions.sendMessage(plr, "&7 - Skipped plot &c" + plot.id); + PlayerFunctions.sendMessage(null, "&7 - Skipped plot &c" + plot.id); } else { Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() { @Override public void run() { - PlayerFunctions.sendMessage(plr, "&6ID: " + plot.id); + PlayerFunctions.sendMessage(null, "&6ID: " + plot.id); final boolean result = SchematicHandler.save(sch, Settings.SCHEMATIC_SAVE_PATH + "/" + plot.id.x + ";" + plot.id.y + "," + worldname + "," + owner + ".schematic"); if (!result) { - PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c" + plot.id); + PlayerFunctions.sendMessage(null, "&7 - Failed to save &c" + plot.id); } else { - PlayerFunctions.sendMessage(plr, "&7 - &aExport success: " + plot.id); + PlayerFunctions.sendMessage(null, "&7 - &aExport success: " + plot.id); } } }); @@ -274,16 +276,16 @@ public class Schematic extends SubCommand { final String[] split = args[2].split(";"); final PlotId i = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1])); if ((PlotMain.getPlots(world) == null) || (PlotMain.getPlots(world).get(i) == null)) { - PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save "); + PlayerFunctions.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save "); return false; } p2 = PlotMain.getPlots(world).get(i); } catch (final Exception e) { - PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save "); + PlayerFunctions.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save "); return false; } } else { - PlayerFunctions.sendMessage(plr, "&cInvalid world or id. Use &7/plots sch save "); + PlayerFunctions.sendMessage(null, "&cInvalid world or id. Use &7/plots sch save "); return false; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java index 6ebfabb41..51be1ab3c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -42,13 +42,13 @@ import java.util.List; */ public class Set extends SubCommand { + public static String[] values = new String[]{"biome", "wall", "wall_filling", "floor", "alias", "home", "flag"}; + public static String[] aliases = new String[]{"b", "w", "wf", "f", "a", "h", "fl"}; + public Set() { super(Command.SET, "Set a plot value", "set {arg} {value...}", CommandCategory.ACTIONS, true); } - public static String[] values = new String[]{"biome", "wall", "wall_filling", "floor", "alias", "home", "flag"}; - public static String[] aliases = new String[]{"b", "w", "wf", "f", "a", "h", "fl"}; - @SuppressWarnings("deprecation") @Override public boolean execute(final Player plr, final String... args) { @@ -66,10 +66,7 @@ public class Set extends SubCommand { return false; } if (args.length < 1) { - final StringBuilder builder = new StringBuilder(); - builder.append(C.SUBCOMMAND_SET_OPTIONS_HEADER.s()); - builder.append(getArgumentList(values)); - PlayerFunctions.sendMessage(plr, builder.toString()); + PlayerFunctions.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + getArgumentList(values)); return false; } for (int i = 0; i < aliases.length; i++) { @@ -79,12 +76,10 @@ public class Set extends SubCommand { } } /* TODO: Implement option */ - final boolean advanced_permissions = true; - if (advanced_permissions) { - if (!PlotMain.hasPermission(plr, "plots.set." + args[0].toLowerCase())) { - PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.set." + args[0].toLowerCase()); - return false; - } + // final boolean advanced_permissions = true; + if (!PlotMain.hasPermission(plr, "plots.set." + args[0].toLowerCase())) { + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION, "plots.set." + args[0].toLowerCase()); + return false; } if (args[0].equalsIgnoreCase("flag")) { @@ -141,8 +136,8 @@ public class Set extends SubCommand { if (oldFlag != null) { newflags.remove(oldFlag); } - plot.settings.setFlags(newflags.toArray(new Flag[0])); - DBFunc.setFlags(plr.getWorld().getName(), plot, newflags.toArray(new Flag[0])); + plot.settings.setFlags(newflags.toArray(new Flag[newflags.size()])); + DBFunc.setFlags(plr.getWorld().getName(), plot, newflags.toArray(new Flag[newflags.size()])); PlayerFunctions.sendMessage(plr, C.FLAG_REMOVED); PlotListener.plotEntry(plr, plot); return true; @@ -169,7 +164,8 @@ public class Set extends SubCommand { return false; } plot.settings.addFlag(flag); - DBFunc.setFlags(plr.getWorld().getName(), plot, plot.settings.getFlags().toArray(new Flag[0])); + java.util.Set flags = plot.settings.getFlags(); + DBFunc.setFlags(plr.getWorld().getName(), plot, flags.toArray(new Flag[flags.size()])); PlayerFunctions.sendMessage(plr, C.FLAG_ADDED); PlotListener.plotEntry(plr, plot); return true; @@ -312,8 +308,7 @@ public class Set extends SubCommand { // int index = 0; // - byte b = (byte) 0; - Material m = null; + Material m; // final PlotBlock[] blocks = new PlotBlock[strings.length]; @@ -341,6 +336,7 @@ public class Set extends SubCommand { blocks[index] = new PlotBlock((short) m.getId(), (byte) 0); } else { + byte b; try { b = (byte) Integer.parseInt(ss[1]); } catch (final Exception e) { @@ -396,10 +392,11 @@ public class Set extends SubCommand { return true; } { - AbstractFlag af = new AbstractFlag(""); + AbstractFlag af; try { af = new AbstractFlag(args[0].toLowerCase()); } catch (final Exception e) { + af = new AbstractFlag(""); } if (FlagManager.getFlags().contains(af)) { final StringBuilder a = new StringBuilder(); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java index 30b3e42b0..4737a7eba 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Setup.java @@ -38,34 +38,14 @@ import java.util.HashMap; import java.util.Map; /** - * Created by Citymonstret on 2014-09-26. + * Created 2014-09-26 for PlotSquared + * + * @author Citymonstret, Empire92 */ public class Setup extends SubCommand implements Listener { public static Map setupMap = new HashMap<>(); - private class SetupObject { - String world; - String plugin; - int current = 0; - - ConfigurationNode[] step; - - public SetupObject(final String world, final PlotWorld plotworld, final String plugin) { - this.world = world; - this.step = plotworld.getSettingNodes(); - this.plugin = plugin; - } - - public int getCurrent() { - return this.current; - } - - public int getMax() { - return this.step.length; - } - } - public Setup() { super("setup", "plots.admin", "Setup a PlotWorld", "setup {world} {generator}", "setup", CommandCategory.ACTIONS, false); } @@ -109,7 +89,9 @@ public class Setup extends SubCommand implements Listener { final ChunkGenerator generator = plugin.getDefaultWorldGenerator(world, ""); final World myworld = WorldCreator.name(world).generator(generator).createWorld(); PlayerFunctions.sendMessage(plr, "&aLoaded world."); - plr.teleport(myworld.getSpawnLocation()); + if (plr != null) { + plr.teleport(myworld.getSpawnLocation()); + } break; } } @@ -183,7 +165,7 @@ public class Setup extends SubCommand implements Listener { return true; } - final ArrayList generators = new ArrayList(); + final ArrayList generators = new ArrayList<>(); ChunkGenerator generator = null; @@ -220,4 +202,26 @@ public class Setup extends SubCommand implements Listener { } } + private class SetupObject { + String world; + String plugin; + int current = 0; + + ConfigurationNode[] step; + + public SetupObject(final String world, final PlotWorld plotworld, final String plugin) { + this.world = world; + this.step = plotworld.getSettingNodes(); + this.plugin = plugin; + } + + public int getCurrent() { + return this.current; + } + + public int getMax() { + return this.step.length; + } + } + } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java index bacb6f222..73ad918b0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SubCommand.java @@ -30,6 +30,7 @@ import org.bukkit.entity.Player; * * @author Citymonstret */ +@SuppressWarnings({"deprecation", "unused", "javadoc"}) public abstract class SubCommand { public boolean isPlayer; /** diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/TP.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/TP.java index 342253ee0..57dc2827a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/TP.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/TP.java @@ -27,6 +27,7 @@ import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; + /** * @author Citymonstret */ @@ -79,9 +80,13 @@ public class TP extends SubCommand { } a = split[0]; } + @SuppressWarnings("deprecation") final Player player = Bukkit.getPlayer(a); if (player != null) { - final Plot[] plots = PlotMain.getPlots(world, player).toArray(new Plot[0]); + final java.util.Set plotMainPlots = + PlotMain.getPlots(world, player); + final Plot[] plots = + plotMainPlots.toArray(new Plot[plotMainPlots.size()]); if (plots.length > index) { return plots[index]; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java index b294e61f4..e1ea63586 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Unlink.java @@ -44,18 +44,16 @@ public class Unlink extends SubCommand { @Override public boolean execute(final Player plr, final String... args) { if (!PlayerFunctions.isInPlot(plr)) { - PlayerFunctions.sendMessage(plr, "You're not in a plot."); - return true; + return sendMessage(plr, C.NOT_IN_PLOT); } final Plot plot = PlayerFunctions.getCurrentPlot(plr); if (((plot == null) || !plot.hasOwner() || !plot.getOwner().equals(plr.getUniqueId())) && !PlotMain.hasPermission(plr, "plots.admin")) { - PlayerFunctions.sendMessage(plr, C.NO_PLOT_PERMS); - return true; + return sendMessage(plr, C.NO_PLOT_PERMS); } if (PlayerFunctions.getTopPlot(plr.getWorld(), plot).equals(PlayerFunctions.getBottomPlot(plr.getWorld(), plot))) { - PlayerFunctions.sendMessage(plr, C.UNLINK_IMPOSSIBLE); - return true; + return sendMessage(plr, C.UNLINK_IMPOSSIBLE); } + final World world = plr.getWorld(); final PlotId pos1 = PlayerFunctions.getBottomPlot(world, plot).id; final PlotId pos2 = PlayerFunctions.getTopPlot(world, plot).id; @@ -117,7 +115,13 @@ public class Unlink extends SubCommand { SetBlockFast.update(plr); } } catch (final Exception e) { - + // execute(final Player plr, final String... args) { + try { + PlotMain.sendConsoleSenderMessage( + "Error on: " + getClass().getMethod("execute", Player.class, String[].class).toGenericString() + ":119, when trying to use \"SetBlockFast#update\""); + } catch (Exception ex) { + ex.printStackTrace(); + } } manager.finishPlotUnlink(world, plotworld, ids); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java index a9422ce47..6dd49d522 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java @@ -21,7 +21,10 @@ package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.*; +import com.intellectualcrafters.plot.C; +import com.intellectualcrafters.plot.Plot; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.UUIDHandler; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -46,38 +49,31 @@ public class Visit extends SubCommand { @Override public boolean execute(final Player plr, final String... args) { if (args.length < 1) { - PlayerFunctions.sendMessage(plr, C.NEED_USER); - return true; + return sendMessage(plr, C.NEED_USER); } final String username = args[0]; - final UUID uuid = UUIDHandler.getUUID(username); List plots = null; if (uuid != null) { plots = getPlots(uuid); } if ((uuid == null) || plots.isEmpty()) { - PlayerFunctions.sendMessage(plr, C.FOUND_NO_PLOTS); - return true; + return sendMessage(plr, C.FOUND_NO_PLOTS); } if (args.length < 2) { - final Plot plot = plots.get(0); - PlotMain.teleportPlayer(plr, plr.getLocation(), plot); + PlotMain.teleportPlayer(plr, plr.getLocation(), plots.get(0)); return true; } int i; try { i = Integer.parseInt(args[1]); } catch (final Exception e) { - PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER); - return true; + return sendMessage(plr, C.NOT_VALID_NUMBER); } if ((i < 0) || (i >= plots.size())) { - PlayerFunctions.sendMessage(plr, C.NOT_VALID_NUMBER); - return true; + return sendMessage(plr, C.NOT_VALID_NUMBER); } - final Plot plot = plots.get(i); - PlotMain.teleportPlayer(plr, plr.getLocation(), plot); + PlotMain.teleportPlayer(plr, plr.getLocation(), plots.get(i)); return true; } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java index 40adca9c3..9f76f3fe9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -37,6 +37,17 @@ public class list extends SubCommand { super(Command.LIST, "List all plots", "list {mine|shared|all|world}", CommandCategory.INFO, false); } + private static String getName(final UUID id) { + if (id == null) { + return "none"; + } + /* + * String name = Bukkit.getOfflinePlayer(id).getName(); if (name == + * null) { return "none"; } return name; + */ + return UUIDHandler.getName(id); + } + @Override public boolean execute(final Player plr, final String... args) { if (args.length < 1) { @@ -52,7 +63,7 @@ public class list extends SubCommand { } if (args[0].equalsIgnoreCase("mine") && (plr != null)) { final StringBuilder string = new StringBuilder(); - string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "your") + "\n"); + string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "your")).append("\n"); int idx = 0; for (final Plot p : PlotMain.getPlots(plr)) { string.append(C.PLOT_LIST_ITEM_ORDERED.s().replaceAll("%in", idx + 1 + "").replaceAll("%id", p.id.toString()).replaceAll("%world", p.world).replaceAll("%owner", getName(p.owner))).append("\n"); @@ -67,7 +78,7 @@ public class list extends SubCommand { return true; } else if (args[0].equalsIgnoreCase("shared") && (plr != null)) { final StringBuilder string = new StringBuilder(); - string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all") + "\n"); + string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")).append("\n"); for (final Plot p : PlotMain.getPlotsSorted()) { if (p.helpers.contains(plr.getUniqueId())) { string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id", p.id.toString()).replaceAll("%world", p.world).replaceAll("%owner", getName(p.owner))).append("\n"); @@ -111,7 +122,7 @@ public class list extends SubCommand { final StringBuilder string = new StringBuilder(); - string.append(C.PLOT_LIST_HEADER_PAGED.s().replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%word%", "all") + "\n"); + string.append(C.PLOT_LIST_HEADER_PAGED.s().replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%word%", "all")).append("\n"); Plot p; // This might work xD @@ -125,7 +136,7 @@ public class list extends SubCommand { return true; } else if (args[0].equalsIgnoreCase("world") && (plr != null)) { final StringBuilder string = new StringBuilder(); - string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all") + "\n"); + string.append(C.PLOT_LIST_HEADER.s().replaceAll("%word%", "all")).append("\n"); final HashMap plots = PlotMain.getPlots(plr.getWorld()); for (final Plot p : plots.values()) { string.append(C.PLOT_LIST_ITEM.s().replaceAll("%id", p.id.toString()).replaceAll("%world", p.world).replaceAll("%owner", getName(p.owner))).append("\n"); @@ -140,17 +151,6 @@ public class list extends SubCommand { } } - private static String getName(final UUID id) { - if (id == null) { - return "none"; - } - /* - * String name = Bukkit.getOfflinePlayer(id).getName(); if (name == - * null) { return "none"; } return name; - */ - return UUIDHandler.getName(id); - } - private String getArgumentList(final String[] strings) { final StringBuilder builder = new StringBuilder(); for (final String s : strings) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java index 32684d812..5c48a185d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/plugin.java @@ -35,12 +35,12 @@ import java.util.ArrayList; public class plugin extends SubCommand { + public static String downloads, version; + public plugin() { super("plugin", "plots.use", "Show plugin information", "plugin", "pl", CommandCategory.INFO, false); } - public static String downloads, version; - public static void setup(final JavaPlugin plugin) { plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { @Override @@ -65,6 +65,30 @@ public class plugin extends SubCommand { }, 200l); } + private static String convertToNumericString(final String str, final boolean dividers) { + final StringBuilder builder = new StringBuilder(); + for (final char c : str.toCharArray()) { + if (Character.isDigit(c)) { + builder.append(c); + } else if (dividers && ((c == ',') || (c == '.') || (c == '-') || (c == '_'))) { + builder.append(c); + } + } + return builder.toString(); + } + + private static String getInfo(final String link) throws Exception { + final URLConnection connection = new URL(link).openConnection(); + connection.addRequestProperty("User-Agent", "Mozilla/4.0"); + final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String document = "", line; + while ((line = reader.readLine()) != null) { + document += (line + "\n"); + } + reader.close(); + return document; + } + @Override public boolean execute(final Player plr, final String... args) { Bukkit.getScheduler().runTaskAsynchronously(JavaPlugin.getPlugin(PlotMain.class), new Runnable() { @@ -87,32 +111,4 @@ public class plugin extends SubCommand { return true; } - private static String convertToNumericString(final String str, final boolean dividers) { - final StringBuilder builder = new StringBuilder(); - for (final char c : str.toCharArray()) { - if (Character.isDigit(c)) { - builder.append(c); - } else if (dividers && ((c == ',') || (c == '.') || (c == '-') || (c == '_'))) { - builder.append(c); - } - } - return builder.toString(); - } - - /** - * @param link - * @return - */ - private static String getInfo(final String link) throws Exception { - final URLConnection connection = new URL(link).openConnection(); - connection.addRequestProperty("User-Agent", "Mozilla/4.0"); - final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String document = "", line; - while ((line = reader.readLine()) != null) { - document += (line + "\n"); - } - reader.close(); - return document; - } - }