diff --git a/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java b/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java index 0606eb0a2..b00c14718 100644 --- a/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/Bukkit/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java @@ -45,7 +45,6 @@ import org.bukkit.OfflinePlayer; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; - import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -66,21 +65,21 @@ import java.util.UUID; * @see PS */ public class PlotAPI { - + /** * Permission that allows for admin access, this permission node will allow the player to use any part of the * plugin, without limitations. - * @deprecated Use C.PERMISSION_ADMIN.s() instead + * @deprecated Use C.PERMISSION_ADMIN instead */ @Deprecated public static final String ADMIN_PERMISSION = C.PERMISSION_ADMIN.s(); - + /** * @deprecated Use new PlotAPI() instead */ @Deprecated public PlotAPI(final JavaPlugin plugin) {} - + /** * @see PS * @@ -93,7 +92,7 @@ public class PlotAPI { */ @Deprecated public PlotAPI() {} - + /** * Get all plots * @@ -104,7 +103,7 @@ public class PlotAPI { public Set getAllPlots() { return PS.get().getPlots(); } - + /** * Return all plots for a player * @@ -115,7 +114,7 @@ public class PlotAPI { public Set getPlayerPlots(final Player player) { return PS.get().getPlots(BukkitUtil.getPlayer(player)); } - + /** * Add a plot world * @@ -125,7 +124,7 @@ public class PlotAPI { public void addPlotArea(final PlotArea plotArea) { PS.get().addPlotArea(plotArea); } - + /** * @return main configuration * @@ -134,7 +133,7 @@ public class PlotAPI { public YamlConfiguration getConfig() { return PS.get().config; } - + /** * @return storage configuration * @@ -143,7 +142,7 @@ public class PlotAPI { public YamlConfiguration getStorage() { return PS.get().storage; } - + /** * Get the main class for this plugin
- Contains a lot of fields and methods - not very well organized
* Only use this if you really need it @@ -155,7 +154,7 @@ public class PlotAPI { public PS getMain() { return PS.get(); } - + /** * ChunkManager class contains several useful methods
* - Chunk deletion
@@ -179,7 +178,7 @@ public class PlotAPI { public SetQueue getSetQueue() { return SetQueue.IMP; } - + /** * UUIDWrapper class has basic methods for getting UUIDS (it's recommended to use the UUIDHandler class instead) * @@ -190,7 +189,7 @@ public class PlotAPI { public UUIDWrapper getUUIDWrapper() { return UUIDHandler.getUUIDWrapper(); } - + /** * Do not use this. Instead use FlagManager.[method] in your code. * - Flag related stuff @@ -203,7 +202,7 @@ public class PlotAPI { public FlagManager getFlagManager() { return new FlagManager(); } - + /** * Do not use this. Instead use MainUtil.[method] in your code. * - Basic plot management stuff @@ -216,7 +215,7 @@ public class PlotAPI { public MainUtil getMainUtil() { return new MainUtil(); } - + /** * Do not use this. Instead use C.PERMISSION_[method] in your code. * - Basic permission management stuff @@ -235,7 +234,7 @@ public class PlotAPI { } return perms.toArray(new String[perms.size()]); } - + /** * SchematicHandler class contains methods related to pasting, reading and writing schematics * @@ -246,7 +245,7 @@ public class PlotAPI { public SchematicHandler getSchematicHandler() { return SchematicHandler.manager; } - + /** * Use C.[caption] instead * @@ -258,7 +257,7 @@ public class PlotAPI { public C[] getCaptions() { return C.values(); } - + /** * Get the plot manager for a world. - Most of these methods can be accessed through the MainUtil * @@ -276,7 +275,7 @@ public class PlotAPI { } return getPlotManager(world.getName()); } - + public Set getPlotAreas(World world) { if (world == null) { return new HashSet<>(); @@ -308,7 +307,7 @@ public class PlotAPI { return null; } } - + /** * Get the settings for a world (settings bundled in PlotArea class) - You will need to downcast for the specific * settings a Generator has. e.g. DefaultPlotWorld class implements PlotArea @@ -327,7 +326,7 @@ public class PlotAPI { } return getWorldSettings(world.getName()); } - + /** * Get the settings for a world (settings bundled in PlotArea class) * @@ -354,7 +353,7 @@ public class PlotAPI { return null; } } - + /** * Send a message to a player. * @@ -367,7 +366,7 @@ public class PlotAPI { public void sendMessage(final Player player, final C c) { MainUtil.sendMessage(BukkitUtil.getPlayer(player), c); } - + /** * Send a message to a player. - Supports color codes * @@ -379,7 +378,7 @@ public class PlotAPI { public void sendMessage(final Player player, final String string) { MainUtil.sendMessage(BukkitUtil.getPlayer(player), string); } - + /** * Send a message to the console. - Supports color codes * @@ -390,7 +389,7 @@ public class PlotAPI { public void sendConsoleMessage(final String msg) { PS.log(msg); } - + /** * Send a message to the console * @@ -400,9 +399,9 @@ public class PlotAPI { * @see com.intellectualcrafters.plot.config.C */ public void sendConsoleMessage(final C c) { - sendConsoleMessage(c.s()); + sendConsoleMessage(c); } - + /** * Register a flag for use in plots * @@ -414,7 +413,7 @@ public class PlotAPI { public void addFlag(final AbstractFlag flag) { FlagManager.addFlag(flag); } - + /** * get all the currently registered flags * @@ -426,7 +425,7 @@ public class PlotAPI { public AbstractFlag[] getFlags() { return FlagManager.getFlags().toArray(new AbstractFlag[FlagManager.getFlags().size()]); } - + /** * Get a plot based on the ID * @@ -449,7 +448,7 @@ public class PlotAPI { } return area.getPlot(new PlotId(x, z)); } - + /** * Get a plot based on the location * @@ -465,7 +464,7 @@ public class PlotAPI { } return BukkitUtil.getLocation(l).getPlot(); } - + /** * Get a plot based on the player location * @@ -479,7 +478,7 @@ public class PlotAPI { public Plot getPlot(final Player player) { return this.getPlot(player.getLocation()); } - + /** * Check whether or not a player has a plot * @@ -493,7 +492,7 @@ public class PlotAPI { public boolean hasPlot(final World world, final Player player) { return getPlots(world, player, true) != null && getPlots(world, player, true).length > 0; } - + /** * Get all plots for the player * @@ -517,7 +516,7 @@ public class PlotAPI { } return pPlots.toArray(new Plot[pPlots.size()]); } - + /** * Get all plots for the world * @@ -536,7 +535,7 @@ public class PlotAPI { Collection plots = PS.get().getPlots(world.getName()); return plots.toArray(new Plot[plots.size()]); } - + /** * Get all plot worlds * @@ -548,7 +547,7 @@ public class PlotAPI { Set plotWorldStrings = PS.get().getPlotWorldStrings(); return plotWorldStrings.toArray(new String[plotWorldStrings.size()]); } - + /** * Get if plot world * @@ -562,7 +561,7 @@ public class PlotAPI { public boolean isPlotWorld(final World world) { return PS.get().hasPlotArea(world.getName()); } - + /** * Get plot locations * @@ -578,7 +577,7 @@ public class PlotAPI { public Location[] getLocations(final Plot p) { return new Location[] { BukkitUtil.getLocation(p.getBottom()), BukkitUtil.getLocation(p.getTop()), BukkitUtil.getLocation(p.getHome()) }; } - + /** * Get home location * @@ -591,7 +590,7 @@ public class PlotAPI { public Location getHomeLocation(final Plot p) { return BukkitUtil.getLocation(p.getHome()); } - + /** * Get Bottom Location (min, min, min) * @@ -607,14 +606,14 @@ public class PlotAPI { public Location getBottomLocation(final Plot p) { return BukkitUtil.getLocation(p.getBottom()); } - + /** * Get Top Location (max, max, max) * * @param p Plot that you want to get the location for * * @return plot top location - * + * * @deprecated As merged plots may not have a rectangular shape * * @see Plot @@ -623,7 +622,7 @@ public class PlotAPI { public Location getTopLocation(final Plot p) { return BukkitUtil.getLocation(p.getTop()); } - + /** * Check whether or not a player is in a plot * @@ -635,7 +634,7 @@ public class PlotAPI { public boolean isInPlot(final Player player) { return getPlot(player) != null; } - + /** * Register a subcommand * @@ -650,7 +649,7 @@ public class PlotAPI { MainCommand.getInstance().createCommand(c); } } - + /** * Get the PlotSquared class * @@ -661,7 +660,7 @@ public class PlotAPI { public PS getPlotSquared() { return PS.get(); } - + /** * Get the player plot count * @@ -677,7 +676,7 @@ public class PlotAPI { } return BukkitUtil.getPlayer(player).getPlotCount(world.getName()); } - + /** * Get a collection containing the players plots * @@ -696,7 +695,7 @@ public class PlotAPI { } return BukkitUtil.getPlayer(player).getPlots(world.getName()); } - + /** * Get the numbers of plots, which the player is able to build in * @@ -709,7 +708,7 @@ public class PlotAPI { final PlotPlayer pp = BukkitUtil.getPlayer(player); return pp.getAllowedPlots(); } - + /** * Get the PlotPlayer for a player
* - The PlotPlayer is usually cached and will provide useful functions relating to players @@ -722,7 +721,7 @@ public class PlotAPI { public PlotPlayer wrapPlayer(final Player player) { return PlotPlayer.wrap(player); } - + /** * Get the PlotPlayer for a UUID (Please note that PlotSquared can be configured to provide different UUIDs than bukkit) * @@ -734,7 +733,7 @@ public class PlotAPI { public PlotPlayer wrapPlayer(final UUID uuid) { return PlotPlayer.wrap(uuid); } - + /** * Get the PlotPlayer for a username * @@ -746,7 +745,7 @@ public class PlotAPI { public PlotPlayer wrapPlayer(final String player) { return PlotPlayer.wrap(player); } - + /** * Get the PlotPlayer for an offline player
* Note that this will work if the player is offline, however not all functionality will work diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index a753a0931..d3bd24b9b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -87,7 +87,6 @@ import org.bukkit.generator.ChunkGenerator; import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; - import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -97,12 +96,12 @@ import java.util.List; import java.util.UUID; public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { - + public static BukkitMain THIS; public static WorldEditPlugin worldEdit; - + private int[] version; - + @Override public int[] getServerVersion() { if (version == null) { @@ -123,20 +122,20 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } return version; } - + @Override public void onEnable() { THIS = this; new PS(this, "Bukkit"); } - + @Override public void onDisable() { PS.get().disable(); Bukkit.getScheduler().cancelTasks(this); THIS = null; } - + @Override public void log(String message) { if (THIS != null && Bukkit.getServer().getConsoleSender() != null) { @@ -151,20 +150,20 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } System.out.println(ConsoleColors.fromString(message)); } - + @Override public void disable() { if (THIS != null) { onDisable(); } } - + @Override public int[] getPluginVersion() { final String[] split = getDescription().getVersion().split("\\."); return new int[] { Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) }; } - + @Override public void registerCommands() { final BukkitCommand bcmd = new BukkitCommand(); @@ -174,25 +173,25 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { plotCommand.setTabCompleter(bcmd); MainCommand.getInstance().addCommand(new DebugUUID()); } - + @Override public File getDirectory() { return getDataFolder(); } - + @Override public File getWorldContainer() { return Bukkit.getWorldContainer(); } - + @Override public TaskManager getTaskManager() { return new BukkitTaskManager(); } - + @Override public void runEntityTask() { - log(C.PREFIX.s() + "KillAllEntities started."); + log(C.PREFIX + "KillAllEntities started."); TaskManager.runTaskRepeat(new Runnable() { @Override public void run() { @@ -335,7 +334,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } }, 20); } - + @Override final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) { final HybridGen result = new HybridGen(); @@ -344,7 +343,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } return (ChunkGenerator) result.specify(); } - + @Override public void registerPlayerEvents() { getServer().getPluginManager().registerEvents(new PlayerEvents(), this); @@ -355,23 +354,23 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { getServer().getPluginManager().registerEvents(new PlayerEvents_1_8_3(), this); } } - + @Override public void registerInventoryEvents() { // Part of PlayerEvents - can be moved if necessary } - + @Override public void registerPlotPlusEvents() { PlotPlusListener.startRunnable(this); getServer().getPluginManager().registerEvents(new PlotPlusListener(), this); } - + @Override public void registerForceFieldEvents() { getServer().getPluginManager().registerEvents(new ForceFieldListener(), this); } - + @Override public boolean initWorldEdit() { if (getServer().getPluginManager().getPlugin("WorldEdit") != null) { @@ -388,7 +387,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } return false; } - + @Override public EconHandler getEconomyHandler() { try { @@ -400,7 +399,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } return null; } - + @Override public PlotQueue initPlotQueue() { try { @@ -439,12 +438,12 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { return new SlowQueue(); } } - + @Override public WorldUtil initWorldUtil() { return new BukkitUtil(); } - + @Override public boolean initPlotMeConverter() { TaskManager.runTaskLaterAsync(new Runnable() { @@ -463,7 +462,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { }, 20); return Bukkit.getPluginManager().getPlugin("PlotMe") != null || Bukkit.getPluginManager().getPlugin("AthionPlots") != null; } - + @Override public GeneratorWrapper getGenerator(final String world, final String name) { if (name == null) { @@ -480,17 +479,17 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { return new BukkitPlotGenerator(new HybridGen()); } } - + @Override public HybridUtils initHybridUtils() { return new BukkitHybridUtils(); } - + @Override public SetupUtils initSetupUtils() { return new BukkitSetupUtils(); } - + @Override public UUIDHandlerImplementation initUUIDHandler() { final boolean checkVersion = PS.get().checkVersion(getServerVersion(), 1, 7, 6); @@ -514,7 +513,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { Settings.OFFLINE_MODE = true; } if (!checkVersion) { - log(C.PREFIX.s() + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature."); + log(C.PREFIX + " &c[WARN] Titles are disabled - please update your version of Bukkit to support this feature."); Settings.TITLES = false; FlagManager.removeFlag(FlagManager.getFlag("titles")); } else { @@ -524,59 +523,59 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } } if (Settings.OFFLINE_MODE) { - log(C.PREFIX.s() + " &6PlotSquared is using Offline Mode UUIDs either because of user preference, or because you are using an old version of Bukkit"); + log(C.PREFIX + " &6PlotSquared is using Offline Mode UUIDs either because of user preference, or because you are using an old version of Bukkit"); } else { - log(C.PREFIX.s() + " &6PlotSquared is using online UUIDs"); + log(C.PREFIX + " &6PlotSquared is using online UUIDs"); } return Settings.USE_SQLUUIDHANDLER ? new SQLUUIDHandler(wrapper) : new FileUUIDHandler(wrapper); } - + @Override public ChunkManager initChunkManager() { return new BukkitChunkManager(); } - + @Override public EventUtil initEventUtil() { return new BukkitEventUtil(); } - + @Override public void unregister(final PlotPlayer player) { BukkitUtil.removePlayer(player.getName()); } - + @Override public void registerChunkProcessor() { getServer().getPluginManager().registerEvents(new ChunkListener(), this); } - + @Override public void registerWorldEvents() { getServer().getPluginManager().registerEvents(new WorldEvents(), this); } - + @Override public InventoryUtil initInventoryUtil() { return new BukkitInventoryUtil(); } - + @Override public String getServerName() { return Bukkit.getServerName(); } - + @Override public void startMetrics() { try { Metrics metrics = new Metrics(this); metrics.start(); - log(C.PREFIX.s() + "&6Metrics enabled."); + log(C.PREFIX + "&6Metrics enabled."); } catch (IOException e) { - log(C.PREFIX.s() + "&cFailed to load up metrics."); + log(C.PREFIX + "&cFailed to load up metrics."); } } - + @Override public void setGenerator(final String worldname) { World world = BukkitUtil.getWorld(worldname); @@ -615,18 +614,18 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { PS.get().loadWorld(worldname, null); } } - + @Override public SchematicHandler initSchematicHandler() { return new BukkitSchematicHandler(); } - + @Override public AbstractTitle initTitleManager() { // Already initialized in UUID handler return AbstractTitle.TITLE_CLASS; } - + @Override public PlotPlayer wrapPlayer(final Object obj) { if (obj instanceof Player) { @@ -640,13 +639,13 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { } return null; } - + @Override public String getNMSPackage() { String name = Bukkit.getServer().getClass().getPackage().getName(); return name.substring(name.lastIndexOf('.') + 1); } - + @Override public ChatManager initChatManager() { if (Settings.FANCY_CHAT) { @@ -655,12 +654,12 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { return new BukkitPlainChatManager(); } } - + @Override public GeneratorWrapper wrapPlotGenerator(IndependentPlotGenerator generator) { return new BukkitPlotGenerator(generator); } - + @Override public List getPluginIds() { ArrayList names = new ArrayList<>(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java index 333af35ac..41491ff87 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java @@ -70,7 +70,7 @@ public abstract class TextualComponent implements Cloneable { } static boolean isTranslatableText(final TextualComponent component) { - return (component instanceof ComplexTextTypeComponent) && ((ComplexTextTypeComponent) component).getKey().equals("translate"); + return (component instanceof ComplexTextTypeComponent) && component.getKey().equals("translate"); } /** diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java b/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java index dd3fa9e38..33c335a4d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/commands/DebugUUID.java @@ -42,7 +42,6 @@ import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper; import com.plotsquared.bukkit.uuid.OfflineUUIDWrapper; import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.CommandDeclaration; - import java.io.File; import java.io.FilenameFilter; import java.io.IOException; @@ -63,16 +62,16 @@ usage = "/plot uuidconvert ", requiredType = RequiredType.CONSOLE, category = CommandCategory.DEBUG) public class DebugUUID extends SubCommand { - + public DebugUUID() { requiredArguments = new Argument[] { Argument.String }; } - + @Override public boolean onCommand(final PlotPlayer player, final String[] args) { final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper(); final UUIDWrapper newWrapper; - + switch (args[0].toLowerCase()) { case "lower": newWrapper = new LowerOfflineUUIDWrapper(); @@ -104,7 +103,7 @@ public class DebugUUID extends SubCommand { MainUtil.sendMessage(player, "&7Retype the command with the override parameter when ready :)"); return false; } - + if (currentUUIDWrapper.getClass().getCanonicalName().equals(newWrapper.getClass().getCanonicalName())) { MainUtil.sendMessage(player, "&cUUID mode already in use!"); return false; @@ -114,14 +113,14 @@ public class DebugUUID extends SubCommand { for (Entry entry : UUIDHandler.getPlayers().entrySet()) { entry.getValue().kick("PlotSquared UUID conversion has been initiated. You may reconnect when finished."); } - + MainUtil.sendMessage(player, "&7 - Initializing map"); final HashMap uCMap = new HashMap<>(); final HashMap uCReverse = new HashMap<>(); - + MainUtil.sendMessage(player, "&7 - Collecting playerdata"); - + final HashSet worlds = new HashSet<>(); worlds.add(WorldUtil.IMP.getMainWorld()); worlds.add("world"); @@ -142,7 +141,7 @@ public class DebugUUID extends SubCommand { final UUID uuid = UUID.fromString(s); uuids.add(uuid); } catch (final Exception e) { - MainUtil.sendMessage(player, C.PREFIX.s() + "Invalid playerdata: " + current); + MainUtil.sendMessage(player, C.PREFIX + "Invalid playerdata: " + current); } } final File playersFolder = new File(worldname + File.separator + "players"); @@ -158,7 +157,7 @@ public class DebugUUID extends SubCommand { } } } - + MainUtil.sendMessage(player, "&7 - Populating map"); UUID uuid2; final UUIDWrapper wrapper = new DefaultUUIDWrapper(); @@ -172,7 +171,7 @@ public class DebugUUID extends SubCommand { uCReverse.put(uuid2, uuid); } } catch (final Throwable e) { - MainUtil.sendMessage(player, C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat"); + MainUtil.sendMessage(player, C.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat"); } } for (final String name : names) { @@ -204,7 +203,7 @@ public class DebugUUID extends SubCommand { MainUtil.sendMessage(player, "&a - Successfully repopulated"); } } - + MainUtil.sendMessage(player, "&7 - Replacing cache"); TaskManager.runTaskAsync(new Runnable() { @Override @@ -215,9 +214,9 @@ public class DebugUUID extends SubCommand { UUIDHandler.add(new StringWrapper(name), entry.getValue()); } } - + MainUtil.sendMessage(player, "&7 - Scanning for applicable files (uuids.txt)"); - + final File file = new File(PS.get().IMP.getDirectory(), "uuids.txt"); if (file.exists()) { try { @@ -250,12 +249,12 @@ public class DebugUUID extends SubCommand { e.printStackTrace(); } } - + MainUtil.sendMessage(player, "&7 - Replacing wrapper"); UUIDHandler.setUUIDWrapper(newWrapper); - + MainUtil.sendMessage(player, "&7 - Updating plot objects"); - + for (final Plot plot : PS.get().getPlots()) { final UUID value = uCMap.get(plot.owner); if (value != null) { @@ -265,13 +264,13 @@ public class DebugUUID extends SubCommand { plot.getMembers().clear(); plot.getDenied().clear(); } - + MainUtil.sendMessage(player, "&7 - Deleting database"); final AbstractDB database = DBFunc.dbManager; final boolean result = database.deleteTables(); - + MainUtil.sendMessage(player, "&7 - Creating tables"); - + try { database.createTables(); if (!result) { @@ -294,7 +293,7 @@ public class DebugUUID extends SubCommand { e.printStackTrace(); return; } - + if (newWrapper instanceof OfflineUUIDWrapper) { PS.get().config.set("UUID.force-lowercase", false); PS.get().config.set("UUID.offline", true); @@ -307,9 +306,9 @@ public class DebugUUID extends SubCommand { } catch (IOException e) { MainUtil.sendMessage(player, "Could not save configuration. It will need to be manuall set!"); } - + MainUtil.sendMessage(player, "&7 - Populating tables"); - + TaskManager.runTaskAsync(new Runnable() { @Override public void run() { @@ -322,7 +321,7 @@ public class DebugUUID extends SubCommand { }); } }); - + MainUtil.sendMessage(player, "&aIt is now safe for players to join"); MainUtil.sendMessage(player, "&cConversion is still in progress, you will be notified when it is complete"); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java index 559dbb202..8e8a559c2 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/APlotMeConnector.java @@ -53,16 +53,16 @@ public abstract class APlotMeConnector { public Location getPlotTopLocAbs(final int path, final int plot, final PlotId plotid) { final int px = plotid.x; final int pz = plotid.y; - final int x = (px * (path + plot)) - ((int) Math.floor(path / 2)) - 1; - final int z = (pz * (path + plot)) - ((int) Math.floor(path / 2)) - 1; + final int x = (px * (path + plot)) - (int) Math.floor(path / 2) - 1; + final int z = (pz * (path + plot)) - (int) Math.floor(path / 2) - 1; return new Location(null, x, 256, z); } public Location getPlotBottomLocAbs(final int path, final int plot, final PlotId plotid) { final int px = plotid.x; final int pz = plotid.y; - final int x = (px * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1; - final int z = (pz * (path + plot)) - plot - ((int) Math.floor(path / 2)) - 1; + final int x = (px * (path + plot)) - plot - (int) Math.floor(path / 2) - 1; + final int z = (pz * (path + plot)) - plot - (int) Math.floor(path / 2) - 1; return new Location(null, x, 1, z); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java index f3bf16a19..12f941c81 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java @@ -20,16 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.plotsquared.bukkit.listeners; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.util.Vector; - import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; @@ -37,8 +27,18 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.plotsquared.bukkit.events.PlayerEnterPlotEvent; import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.util.BukkitUtil; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.util.Vector; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +/** -/** */ public class ForceFieldListener implements Listener { private Set getNearbyPlayers(final Player player, final Plot plot) { @@ -73,17 +73,19 @@ public class ForceFieldListener implements Listener { Location oPlayerLocation = e.getLocation(); final double playerX = playerLocation.getX(), playerY = playerLocation.getY(), playerZ = playerLocation.getZ(), oPlayerX = oPlayerLocation.getX(), oPlayerY = oPlayerLocation.getY(), oPlayerZ = oPlayerLocation .getZ(); - double x = 0d, y = 0d, z = 0d; + double x = 0d; if (playerX < oPlayerX) { x = 1.0d; } else if (playerX > oPlayerX) { x = -1.0d; } + double y = 0d; if (playerY < oPlayerY) { y = 0.5d; } else if (playerY > oPlayerY) { y = -0.5d; } + double z = 0d; if (playerZ < oPlayerZ) { z = 1.0d; } else if (playerZ > oPlayerZ) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 40ca9a4fa..5e4d81812 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -615,6 +615,11 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_DESTROY_ROAD)) { return; } + if (PS.get().worldedit != null && pp.getAttribute("worldedit")) { + if (player.getItemInHand().getTypeId() == PS.get().worldedit.getConfiguration().wandItem) { + return; + } + } MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_ROAD); event.setCancelled(true); } @@ -1165,6 +1170,11 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen default: return; } + if (PS.get().worldedit != null && pp.getAttribute("worldedit")) { + if (player.getItemInHand().getTypeId() == PS.get().worldedit.getConfiguration().wandItem) { + return; + } + } if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, loc, lb, true)) { event.setCancelled(true); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index bc0809699..6fcb63c60 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -2,19 +2,64 @@ package com.plotsquared.bukkit.util; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.generator.AugmentedUtils; -import com.intellectualcrafters.plot.object.*; +import com.intellectualcrafters.plot.object.BlockLoc; +import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.util.*; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotLoc; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.PlotChunk; +import com.intellectualcrafters.plot.util.SetQueue; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.bukkit.object.entity.EntityWrapper; -import org.bukkit.*; -import org.bukkit.block.*; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.Note; +import org.bukkit.SkullType; +import org.bukkit.World; +import org.bukkit.block.Banner; +import org.bukkit.block.Beacon; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.BlockState; +import org.bukkit.block.BrewingStand; +import org.bukkit.block.Chest; +import org.bukkit.block.CommandBlock; +import org.bukkit.block.CreatureSpawner; +import org.bukkit.block.Dispenser; +import org.bukkit.block.Dropper; +import org.bukkit.block.Furnace; +import org.bukkit.block.Hopper; +import org.bukkit.block.Jukebox; +import org.bukkit.block.NoteBlock; +import org.bukkit.block.Sign; +import org.bukkit.block.Skull; import org.bukkit.block.banner.Pattern; -import org.bukkit.entity.*; +import org.bukkit.entity.Animals; +import org.bukkit.entity.Creature; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; import java.util.Map.Entry; +import java.util.Set; public class BukkitChunkManager extends ChunkManager { @@ -595,7 +640,6 @@ public class BukkitChunkManager extends ChunkManager { } } while (SetQueue.IMP.forceChunkSet()) { - ; } restoreBlocks(world1, 0, 0); restoreEntities(world1, 0, 0); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSchematicHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSchematicHandler.java index 76a08dd65..1b07ba7d7 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSchematicHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSchematicHandler.java @@ -20,7 +20,13 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.plotsquared.bukkit.util; -import com.intellectualcrafters.jnbt.*; +import com.intellectualcrafters.jnbt.ByteArrayTag; +import com.intellectualcrafters.jnbt.CompoundTag; +import com.intellectualcrafters.jnbt.IntTag; +import com.intellectualcrafters.jnbt.ListTag; +import com.intellectualcrafters.jnbt.ShortTag; +import com.intellectualcrafters.jnbt.StringTag; +import com.intellectualcrafters.jnbt.Tag; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.RegionWrapper; @@ -35,8 +41,13 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Set; /** * Schematic Handler @@ -73,7 +84,7 @@ public class BukkitSchematicHandler extends SchematicHandler { schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0)); schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0)); // Arrays of data types - final List tileEntities = new ArrayList<>(); + final List tileEntities = new ArrayList<>(); final byte[] blocks = new byte[width * height * length]; final byte[] blockData = new byte[width * height * length]; // Queue @@ -126,7 +137,7 @@ public class BukkitSchematicHandler extends SchematicHandler { @Override public void run() { final long start = System.currentTimeMillis(); - while ((!chunks.isEmpty()) && ((System.currentTimeMillis() - start) < 20)) { + while (!chunks.isEmpty() && ((System.currentTimeMillis() - start) < 20)) { // save schematics final ChunkLoc chunk = chunks.remove(0); final Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z); @@ -154,7 +165,7 @@ public class BukkitSchematicHandler extends SchematicHandler { } for (int y = sy; y <= Math.min(255, ey); y++) { final int ry = y - sy; - final int i1 = (ry * width * length); + final int i1 = ry * width * length; for (int z = zzb; z <= zzt; z++) { final int rz = z - bz; final int i2 = i1 + (rz * width); @@ -275,7 +286,7 @@ public class BukkitSchematicHandler extends SchematicHandler { final StateWrapper wrapper = new StateWrapper(state); final CompoundTag rawTag = wrapper.getTag(); if (rawTag != null) { - final Map values = new HashMap(); + final Map values = new HashMap<>(); for (final Entry entry : rawTag.getValue().entrySet()) { values.put(entry.getKey(), entry.getValue()); } @@ -283,7 +294,7 @@ public class BukkitSchematicHandler extends SchematicHandler { values.put("x", new IntTag("x", x)); values.put("y", new IntTag("y", y)); values.put("z", new IntTag("z", z)); - final CompoundTag tileEntityTag = new CompoundTag(values); + CompoundTag tileEntityTag = new CompoundTag(values); tileEntities.add(tileEntityTag); } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java index db0807f80..974dbcf2c 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_9.java @@ -227,10 +227,8 @@ public class FastQueue_1_9 extends SlowQueue { int x = MainUtil.x_loc[j][k]; int y = MainUtil.y_loc[j][k]; int z = MainUtil.z_loc[j][k]; - int id = n; Object iblock = methodGetByCombinedId.call((int) n); setType.call(x, y & 15, z, iblock); - continue; } } } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java index 4129abaa0..0acb942f6 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/FileUUIDHandler.java @@ -10,12 +10,15 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.StringWrapper; -import com.intellectualcrafters.plot.util.*; +import com.intellectualcrafters.plot.util.ExpireManager; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.plotsquared.bukkit.util.NbtFactory; import org.bukkit.Bukkit; import org.bukkit.World; - import java.io.File; import java.io.FileInputStream; import java.io.FilenameFilter; @@ -28,16 +31,16 @@ import java.util.List; import java.util.UUID; public class FileUUIDHandler extends UUIDHandlerImplementation { - + public FileUUIDHandler(final UUIDWrapper wrapper) { super(wrapper); } - + @Override public boolean startCaching(final Runnable whenDone) { return super.startCaching(whenDone) && cache(whenDone); } - + public boolean cache(final Runnable whenDone) { final File container = Bukkit.getWorldContainer(); final List worlds = Bukkit.getWorlds(); @@ -50,7 +53,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation { TaskManager.runTaskAsync(new Runnable() { @Override public void run() { - PS.debug(C.PREFIX.s() + "&6Starting player data caching for: " + world); + PS.debug(C.PREFIX + "&6Starting player data caching for: " + world); final File uuidfile = new File(PS.get().IMP.getDirectory(), "uuids.txt"); if (uuidfile.exists()) { try { @@ -112,7 +115,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation { } } catch (final Exception e) { e.printStackTrace(); - PS.debug(C.PREFIX.s() + "Invalid playerdata: " + current); + PS.debug(C.PREFIX + "Invalid playerdata: " + current); } } } @@ -150,7 +153,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation { final UUID uuid = UUID.fromString(s); uuids.add(uuid); } catch (final Exception e) { - PS.debug(C.PREFIX.s() + "Invalid playerdata: " + current); + PS.debug(C.PREFIX + "Invalid playerdata: " + current); } } break; @@ -195,7 +198,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation { } toAdd.put(new StringWrapper(name), uuid); } catch (final Throwable e) { - PS.debug(C.PREFIX.s() + "&6Invalid playerdata: " + uuid.toString() + ".dat"); + PS.debug(C.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat"); } } for (final String name : names) { @@ -226,7 +229,7 @@ public class FileUUIDHandler extends UUIDHandlerImplementation { }); return true; } - + @Override public void fetchUUID(final String name, final RunnableVal ifFetch) { TaskManager.runTaskAsync(new Runnable() { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLUUIDHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLUUIDHandler.java index f8ead1ff3..86d125820 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLUUIDHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLUUIDHandler.java @@ -1,5 +1,21 @@ package com.plotsquared.bukkit.uuid; +import com.google.common.collect.HashBiMap; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.database.SQLite; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; +import com.intellectualcrafters.plot.uuid.UUIDWrapper; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; + import java.io.InputStreamReader; import java.io.OutputStream; import java.net.HttpURLConnection; @@ -13,25 +29,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.UUID; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; - -import com.google.common.collect.HashBiMap; -import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.database.SQLite; -import com.intellectualcrafters.plot.object.RunnableVal; -import com.intellectualcrafters.plot.object.StringWrapper; -import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.UUIDHandler; -import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; -import com.intellectualcrafters.plot.uuid.UUIDWrapper; - public class SQLUUIDHandler extends UUIDHandlerImplementation { - + final String PROFILE_URL = "https://sessionserver.mojang.com/session/minecraft/profile/"; final int MAX_REQUESTS = 500; final int INTERVAL = 12000; @@ -57,13 +56,13 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation { } startCaching(null); } - + private Connection getConnection() { synchronized (_sqLite) { return _sqLite.getConnection(); } } - + @Override public boolean startCaching(final Runnable whenDone) { if (!super.startCaching(whenDone)) { @@ -76,11 +75,9 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation { final HashBiMap toAdd = HashBiMap.create(new HashMap()); final PreparedStatement statement = getConnection().prepareStatement("SELECT `uuid`, `username` FROM `usercache`"); final ResultSet resultSet = statement.executeQuery(); - StringWrapper username; - UUID uuid; while (resultSet.next()) { - username = new StringWrapper(resultSet.getString("username")); - uuid = UUID.fromString(resultSet.getString("uuid")); + StringWrapper username = new StringWrapper(resultSet.getString("username")); + UUID uuid = UUID.fromString(resultSet.getString("uuid")); toAdd.put(new StringWrapper(username.value), uuid); } statement.close(); @@ -195,10 +192,10 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation { }); return true; } - + @Override public void fetchUUID(final String name, final RunnableVal ifFetch) { - PS.debug(C.PREFIX.s() + "UUID for '" + name + "' was null. We'll cache this from the mojang servers!"); + PS.debug(C.PREFIX + "UUID for '" + name + "' was null. We'll cache this from the mojang servers!"); if (ifFetch == null) { return; } @@ -230,7 +227,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation { } }); } - + @Override public void handleShutdown() { super.handleShutdown(); @@ -240,7 +237,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation { throw new SQLUUIDHandlerException("Couldn't close database connection", e); } } - + @Override public boolean add(final StringWrapper name, final UUID uuid) { // Ignoring duplicates @@ -253,7 +250,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation { statement.setString(1, uuid.toString()); statement.setString(2, name.toString()); statement.execute(); - PS.debug(C.PREFIX.s() + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'"); + PS.debug(C.PREFIX + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'"); } catch (final SQLException e) { e.printStackTrace(); } @@ -263,7 +260,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation { } return false; } - + /** * This is useful for name changes */ @@ -278,7 +275,7 @@ public class SQLUUIDHandler extends UUIDHandlerImplementation { statement.setString(1, name.value); statement.setString(2, uuid.toString()); statement.execute(); - PS.debug(C.PREFIX.s() + "Name change for '" + uuid + "' to '" + name.value + "'"); + PS.debug(C.PREFIX + "Name change for '" + uuid + "' to '" + name.value + "'"); } catch (final SQLException e) { e.printStackTrace(); } diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/MemorySection.java b/Core/src/main/java/com/intellectualcrafters/configuration/MemorySection.java index bce9578f5..6099d235f 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/MemorySection.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/MemorySection.java @@ -76,7 +76,7 @@ public class MemorySection implements ConfigurationSection { } catch (NumberFormatException ignored) { } } else if (obj instanceof List) { - final List val = ((List) obj); + final List val = (List) obj; if (!val.isEmpty()) { return toDouble(val.get(0), def); } @@ -94,7 +94,7 @@ public class MemorySection implements ConfigurationSection { } catch (NumberFormatException ignored) { } } else if (obj instanceof List) { - final List val = ((List) obj); + final List val = (List) obj; if (!val.isEmpty()) { return toInt(val.get(0), def); } @@ -112,7 +112,7 @@ public class MemorySection implements ConfigurationSection { } catch (NumberFormatException ignored) { } } else if (obj instanceof List) { - final List val = ((List) obj); + final List val = (List) obj; if (!val.isEmpty()) { return toLong(val.get(0), def); } @@ -166,7 +166,7 @@ public class MemorySection implements ConfigurationSection { builder.insert(0, parent.getName()); } - if ((key != null) && (!key.isEmpty())) { + if ((key != null) && !key.isEmpty()) { if (builder.length() > 0) { builder.append(separator); } @@ -528,7 +528,7 @@ public class MemorySection implements ConfigurationSection { final List result = new ArrayList<>(); for (final Object object : list) { - if ((object instanceof String) || (isPrimitiveWrapper(object))) { + if ((object instanceof String) || isPrimitiveWrapper(object)) { result.add(String.valueOf(object)); } } @@ -819,7 +819,7 @@ public class MemorySection implements ConfigurationSection { for (final Map.Entry entry : sec.map.entrySet()) { output.add(createPath(section, entry.getKey(), this)); - if ((deep) && (entry.getValue() instanceof ConfigurationSection)) { + if (deep && (entry.getValue() instanceof ConfigurationSection)) { final ConfigurationSection subsection = (ConfigurationSection) entry.getValue(); mapChildrenKeys(output, subsection, deep); } diff --git a/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java b/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java index 34fb066c9..d1e9c11e7 100644 --- a/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java +++ b/Core/src/main/java/com/intellectualcrafters/configuration/file/YamlConfiguration.java @@ -159,7 +159,7 @@ public class YamlConfiguration extends FileConfiguration { boolean readingHeader = true; boolean foundHeader = false; - for (int i = 0; (i < lines.length) && (readingHeader); i++) { + for (int i = 0; (i < lines.length) && readingHeader; i++) { final String line = lines[i]; if (line.startsWith(COMMENT_PREFIX)) { @@ -172,7 +172,7 @@ public class YamlConfiguration extends FileConfiguration { } foundHeader = true; - } else if ((foundHeader) && (line.isEmpty())) { + } else if (foundHeader && line.isEmpty()) { result.append("\n"); } else if (foundHeader) { readingHeader = false; @@ -189,11 +189,11 @@ public class YamlConfiguration extends FileConfiguration { if (options().copyHeader()) { final Configuration def = getDefaults(); - if ((def != null) && (def instanceof FileConfiguration)) { + if (def != null && def instanceof FileConfiguration) { final FileConfiguration filedefaults = (FileConfiguration) def; final String defaultsHeader = filedefaults.buildHeader(); - if ((defaultsHeader != null) && (!defaultsHeader.isEmpty())) { + if ((defaultsHeader != null) && !defaultsHeader.isEmpty()) { return defaultsHeader; } } @@ -210,7 +210,7 @@ public class YamlConfiguration extends FileConfiguration { for (int i = lines.length - 1; i >= 0; i--) { builder.insert(0, "\n"); - if ((startedHeader) || (!lines[i].isEmpty())) { + if (startedHeader || !lines[i].isEmpty()) { builder.insert(0, lines[i]); builder.insert(0, COMMENT_PREFIX); startedHeader = true; diff --git a/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java b/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java index c090c1967..7233d9979 100644 --- a/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java +++ b/Core/src/main/java/com/intellectualcrafters/json/JSONObject.java @@ -363,7 +363,7 @@ public class JSONObject { } public static Writer quote(final String string, final Writer w) throws IOException { - if ((string == null) || (string.isEmpty())) { + if ((string == null) || string.isEmpty()) { w.write("\"\""); return w; } @@ -427,7 +427,7 @@ public class JSONObject { */ public static Object stringToValue(final String string) { Double d; - if (string.equals("")) { + if (string.isEmpty()) { return string; } if (string.equalsIgnoreCase("true")) { @@ -1115,7 +1115,7 @@ public class JSONObject { } else if (name.startsWith("is")) { key = name.substring(2); } - if ((!key.isEmpty()) && Character.isUpperCase(key.charAt(0)) && (method.getParameterTypes().length == 0)) { + if (!key.isEmpty() && Character.isUpperCase(key.charAt(0)) && (method.getParameterTypes().length == 0)) { if (key.length() == 1) { key = key.toLowerCase(); } else if (!Character.isUpperCase(key.charAt(1))) { diff --git a/Core/src/main/java/com/intellectualcrafters/json/JSONTokener.java b/Core/src/main/java/com/intellectualcrafters/json/JSONTokener.java index b6ad424e0..0563977b4 100644 --- a/Core/src/main/java/com/intellectualcrafters/json/JSONTokener.java +++ b/Core/src/main/java/com/intellectualcrafters/json/JSONTokener.java @@ -342,7 +342,7 @@ public class JSONTokener { } back(); string = sb.toString().trim(); - if ("".equals(string)) { + if (string != null && string.isEmpty()) { throw syntaxError("Missing value"); } return JSONObject.stringToValue(string); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index fc530ecab..7c6cb45f1 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -54,7 +54,6 @@ import com.intellectualcrafters.plot.util.WorldUtil; import com.intellectualcrafters.plot.util.area.QuadMap; import com.plotsquared.listener.WESubscriber; import com.sk89q.worldedit.WorldEdit; - import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -165,7 +164,7 @@ public class PS { } TASK = IMP.getTaskManager(); if (!C.ENABLED.s().isEmpty()) { - log(C.ENABLED.s()); + log(C.ENABLED); } setupConfigs(); translationFile = new File(IMP.getDirectory() + File.separator + "translations" + File.separator + "PlotSquared.use_THIS.yml"); @@ -1370,10 +1369,10 @@ public class PS { // Conventional plot generator PlotArea plotArea = pg.getNewPlotArea(world, null, null, null); PlotManager plotManager = pg.getNewPlotManager(); - log(C.PREFIX.s() + "&aDetected world load for '" + world + "'"); - log(C.PREFIX.s() + "&3 - generator: &7" + baseGenerator + ">" + pg); - log(C.PREFIX.s() + "&3 - plotworld: &7" + plotArea.getClass().getName()); - log(C.PREFIX.s() + "&3 - manager: &7" + plotManager.getClass().getName()); + log(C.PREFIX + "&aDetected world load for '" + world + "'"); + log(C.PREFIX + "&3 - generator: &7" + baseGenerator + ">" + pg); + log(C.PREFIX + "&3 - plotworld: &7" + plotArea.getClass().getName()); + log(C.PREFIX + "&3 - manager: &7" + plotManager.getClass().getName()); if (!config.contains(path)) { config.createSection(path); worldSection = config.getConfigurationSection(path); @@ -1399,7 +1398,7 @@ public class PS { PS.debug("World possibly already loaded: " + world); return; } - log(C.PREFIX.s() + "&aDetected world load for '" + world + "'"); + log(C.PREFIX + "&aDetected world load for '" + world + "'"); String gen_string = worldSection.getString("generator.plugin", "PlotSquared"); if (type == 2) { Set clusters = clusters_tmp != null ? clusters_tmp.get(world) : new HashSet(); @@ -1415,7 +1414,7 @@ public class PS { worldSection.createSection("areas." + fullId); DBFunc.replaceWorld(world, world + ";" + name, pos1, pos2); // NPE - log(C.PREFIX.s() + "&3 - " + name + "-" + pos1 + "-" + pos2); + log(C.PREFIX + "&3 - " + name + "-" + pos1 + "-" + pos2); GeneratorWrapper areaGen = IMP.getGenerator(world, gen_string); if (areaGen == null) { throw new IllegalArgumentException("Invalid Generator: " + gen_string); @@ -1428,10 +1427,10 @@ public class PS { } catch (final IOException e) { e.printStackTrace(); } - log(C.PREFIX.s() + "&c | &9generator: &7" + baseGenerator + ">" + areaGen); - log(C.PREFIX.s() + "&c | &9plotworld: &7" + pa); - log(C.PREFIX.s() + "&c | &9manager: &7" + pa); - log(C.PREFIX.s() + "&cNote: &7Area created for cluster:" + name + " (invalid or old configuration?)"); + log(C.PREFIX + "&c | &9generator: &7" + baseGenerator + ">" + areaGen); + log(C.PREFIX + "&c | &9plotworld: &7" + pa); + log(C.PREFIX + "&c | &9manager: &7" + pa); + log(C.PREFIX + "&cNote: &7Area created for cluster:" + name + " (invalid or old configuration?)"); areaGen.getPlotGenerator().initialize(pa); areaGen.augment(pa); toLoad.add(pa); @@ -1453,9 +1452,9 @@ public class PS { } catch (final IOException e) { e.printStackTrace(); } - log(C.PREFIX.s() + "&3 - generator: &7" + baseGenerator + ">" + areaGen); - log(C.PREFIX.s() + "&3 - plotworld: &7" + pa); - log(C.PREFIX.s() + "&3 - manager: &7" + pa.getPlotManager()); + log(C.PREFIX + "&3 - generator: &7" + baseGenerator + ">" + areaGen); + log(C.PREFIX + "&3 - plotworld: &7" + pa); + log(C.PREFIX + "&3 - manager: &7" + pa.getPlotManager()); areaGen.getPlotGenerator().initialize(pa); areaGen.augment(pa); addPlotArea(pa); @@ -1465,7 +1464,7 @@ public class PS { throw new IllegalArgumentException("Invalid type for multi-area world. Expected `2`, got `" + type + "`"); } for (String areaId : areasSection.getKeys(false)) { - log(C.PREFIX.s() + "&3 - " + areaId); + log(C.PREFIX + "&3 - " + areaId); String[] split = areaId.split("([^\\-]+)(?:-{1})(-{0,1}\\d+\\;-{0,1}\\d+)(?:-{1})(-{0,1}\\d+\\;-{0,1}\\d+)"); if (split.length != 3) { throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `--`"); @@ -1524,10 +1523,10 @@ public class PS { } catch (final IOException e) { e.printStackTrace(); } - log(C.PREFIX.s() + "&aDetected area load for '" + world + "'"); - log(C.PREFIX.s() + "&c | &9generator: &7" + baseGenerator + ">" + areaGen); - log(C.PREFIX.s() + "&c | &9plotworld: &7" + pa); - log(C.PREFIX.s() + "&c | &9manager: &7" + pa.getPlotManager()); + log(C.PREFIX + "&aDetected area load for '" + world + "'"); + log(C.PREFIX + "&c | &9generator: &7" + baseGenerator + ">" + areaGen); + log(C.PREFIX + "&c | &9plotworld: &7" + pa); + log(C.PREFIX + "&c | &9manager: &7" + pa.getPlotManager()); areaGen.getPlotGenerator().initialize(pa); areaGen.augment(pa); addPlotArea(pa); @@ -1764,7 +1763,7 @@ public class PS { public void setupDatabase() { try { if (Settings.DB.USE_MONGO) { - log(C.PREFIX.s() + "MongoDB is not yet implemented"); + log(C.PREFIX + "MongoDB is not yet implemented"); log(C.PREFIX + "&cNo storage type is set!"); IMP.disable(); return; @@ -1786,7 +1785,7 @@ public class PS { this.clusters_tmp = DBFunc.getClusters(); } } catch (ClassNotFoundException | SQLException e) { - log(C.PREFIX.s() + "&cFailed to open DATABASE connection. The plugin will disable itself."); + log(C.PREFIX + "&cFailed to open DATABASE connection. The plugin will disable itself."); if (Settings.DB.USE_MONGO) { log("$4MONGO"); } else if (Settings.DB.USE_MYSQL) { @@ -2195,7 +2194,7 @@ public class PS { // Misc Settings.DEBUG = config.getBoolean("debug"); if (Settings.DEBUG) { - log(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off."); + log(C.PREFIX + "&6Debug Mode Enabled (Default). Edit the config to turn this off."); } Settings.CONSOLE_COLOR = config.getBoolean("console.color"); if (!config.getBoolean("chat.fancy") || !checkVersion(IMP.getServerVersion(), 1, 8, 0)) { @@ -2216,7 +2215,7 @@ public class PS { public void setupConfigs() { final File folder = new File(IMP.getDirectory() + File.separator + "config"); if (!folder.exists() && !folder.mkdirs()) { - log(C.PREFIX.s() + "&cFailed to create the /plugins/config folder. Please create it manually."); + log(C.PREFIX + "&cFailed to create the /plugins/config folder. Please create it manually."); } try { styleFile = new File(IMP.getDirectory() + File.separator + "translations" + File.separator + "style.yml"); @@ -2315,7 +2314,7 @@ public class PS { settings.put("Schematics Save Path", "" + Settings.SCHEMATIC_SAVE_PATH); settings.put("API Location", "" + Settings.API_URL); for (final Entry setting : settings.entrySet()) { - log(C.PREFIX.s() + String.format("&cKey: &6%s&c, Value: &6%s", setting.getKey(), setting.getValue())); + log(C.PREFIX + String.format("&cKey: &6%s&c, Value: &6%s", setting.getKey(), setting.getValue())); } } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Biome.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Biome.java index 2fbdf20a8..73db810b9 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Biome.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Biome.java @@ -37,7 +37,7 @@ aliases = { "biome", "sb", "setb", "b" }, category = CommandCategory.APPEARANCE, requiredType = RequiredType.NONE) public class Biome extends SetCommand { - + @Override public boolean set(final PlotPlayer plr, final Plot plot, final String value) { final int biome = WorldUtil.IMP.getBiomeFromString(value); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Chat.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Chat.java index 1b23c5a2c..9874cbf94 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Chat.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Chat.java @@ -14,6 +14,6 @@ public class Chat extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, final String... args) { - return MainCommand.onCommand(player, "plot", new String[] { "toggle", "chat" }); + return MainCommand.onCommand(player, "plot", "toggle", "chat"); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Database.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Database.java index d56462616..853fe0d03 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Database.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Database.java @@ -85,7 +85,7 @@ public class Database extends SubCommand { MainUtil.sendMessage(player, "/plot database import [sqlite file] [prefix]"); return false; } - File file = MainUtil.getFile(PS.get().IMP.getDirectory(), (args[1].endsWith(".db")) ? args[1] : args[1] + ".db"); + File file = MainUtil.getFile(PS.get().IMP.getDirectory(), args[1].endsWith(".db") ? args[1] : args[1] + ".db"); if (!file.exists()) { MainUtil.sendMessage(player, "&6Database does not exist: " + file); return false; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java index 647bfbfcc..3cd2f4828 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Delete.java @@ -90,7 +90,7 @@ public class Delete extends SubCommand { } } }; - if (Settings.CONFIRM_DELETE && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) { + if (Settings.CONFIRM_DELETE && !Permissions.hasPermission(plr, "plots.confirm.bypass")) { CmdConfirm.addPending(plr, "/plot delete " + plot.getId(), run); } else { TaskManager.runTask(run); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/GenerateDocs.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/GenerateDocs.java index f6110e670..635af7030 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/GenerateDocs.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/GenerateDocs.java @@ -17,7 +17,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class GenerateDocs { - public static void main(final String[] args) { + + public static void main(String[] args) { MainCommand.getInstance().addCommand(new WE_Anywhere()); MainCommand.getInstance().addCommand(new Cluster()); final ArrayList> commands = MainCommand.getInstance().getCommands(); @@ -39,8 +40,8 @@ public class GenerateDocs { printCommand(command); } } - - public static void printCommand(final Command command) { + + public static void printCommand(Command command) { try { final String clazz = command.getClass().getSimpleName(); final String name = command.getCommand(); @@ -129,8 +130,8 @@ public class GenerateDocs { return new ArrayList<>(usages); } - public static List getPerms(final String cmd, final List lines) { - final HashSet perms = new HashSet(); + public static List getPerms(String cmd, List lines) { + final HashSet perms = new HashSet<>(); final Pattern p = Pattern.compile("\"([^\"]*)\""); final Pattern p2 = Pattern.compile("C.PERMISSION_\\s*(\\w+)"); String last = null; @@ -202,13 +203,13 @@ public class GenerateDocs { } return new ArrayList<>(perms); } - - public static String getComments(final List lines) { + + public static String getComments(List lines) { final StringBuilder result = new StringBuilder(); for (String line : lines) { line = line.trim(); if (line.startsWith("/** ") || line.startsWith("*/ ") || line.startsWith("* ")) { - line = (line.replaceAll("/[*][*] ", "").replaceAll("[*]/ ", "").replaceAll("[*] ", "")).trim(); + line = line.replaceAll("/[*][*] ", "").replaceAll("[*]/ ", "").replaceAll("[*] ", "").trim(); result.append(line + "\n"); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java index 1d0576f99..b583af95a 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java @@ -44,7 +44,7 @@ requiredType = RequiredType.NONE) public class Inbox extends SubCommand { public void displayComments(final PlotPlayer player, final List oldComments, int page) { - if ((oldComments == null) || (oldComments.isEmpty())) { + if ((oldComments == null) || oldComments.isEmpty()) { MainUtil.sendMessage(player, C.INBOX_EMPTY); return; } @@ -65,10 +65,10 @@ public class Inbox extends SubCommand { } final StringBuilder string = new StringBuilder(); string.append(StringMan.replaceAll(C.COMMENT_LIST_HEADER_PAGED.s(), "%amount%", comments.length, "%cur", page + 1, "%max", totalPages + 1, "%word", "all") + "\n"); - PlotComment c; + // This might work xD - for (int x = (page * 12); x < max; x++) { - c = comments[x]; + for (int x = page * 12; x < max; x++) { + PlotComment c = comments[x]; String color; if (player.getName().equals(c.senderName)) { color = "&a"; @@ -152,12 +152,11 @@ public class Inbox extends SubCommand { if (!inbox.getComments(plot, new RunnableVal>() { @Override public void run(List value) { - final List comments = value; - if (index > comments.size()) { + if (index > value.size()) { sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + ""); return; } - final PlotComment comment = comments.get(index - 1); + final PlotComment comment = value.get(index - 1); inbox.removeComment(plot, comment); plot.getSettings().removeComment(comment); MainUtil.sendMessage(player, C.COMMENT_REMOVED, comment.comment); @@ -199,8 +198,7 @@ public class Inbox extends SubCommand { if (!inbox.getComments(plot, new RunnableVal>() { @Override public void run(List value) { - final List comments = value; - displayComments(player, comments, page); + displayComments(player, value, page); } })) { if (plot == null) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java index 4d899277d..eac2244de 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -33,7 +33,6 @@ import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; - import java.util.HashSet; import java.util.UUID; @@ -43,7 +42,7 @@ import java.util.UUID; public class Merge extends SubCommand { public final static String[] values = new String[] { "north", "east", "south", "west", "auto" }; public final static String[] aliases = new String[] { "n", "e", "s", "w", "all" }; - + public static String direction(float yaw) { yaw = yaw / 90; final int i = Math.round(yaw); @@ -65,7 +64,7 @@ public class Merge extends SubCommand { return ""; } } - + @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location loc = plr.getLocationFull(); @@ -131,7 +130,7 @@ public class Merge extends SubCommand { } MainUtil.sendMessage(plr, C.NO_AVAILABLE_AUTOMERGE); return false; - + } for (int i = 0; i < values.length; i++) { if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) { @@ -165,7 +164,7 @@ public class Merge extends SubCommand { return false; } if (!Permissions.hasPermission(plr, C.PERMISSION_MERGE_OTHER)) { - MainUtil.sendMessage(plr, C.NO_PERMISSION, C.PERMISSION_MERGE_OTHER.s()); + MainUtil.sendMessage(plr, C.NO_PERMISSION, C.PERMISSION_MERGE_OTHER); return false; } HashSet uuids = adjacent.getOwners(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Save.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Save.java index 31fda1af0..712b689df 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Save.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Save.java @@ -1,9 +1,5 @@ package com.intellectualcrafters.plot.commands; -import java.net.URL; -import java.util.List; -import java.util.UUID; - import com.intellectualcrafters.jnbt.CompoundTag; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; @@ -19,6 +15,10 @@ import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.general.commands.CommandDeclaration; +import java.net.URL; +import java.util.List; +import java.util.UUID; + @CommandDeclaration(command = "save", aliases = { "backup" }, description = "Save your plot", category = CommandCategory.SCHEMATIC, requiredType = RequiredType.NONE, permission = "plots.save") public class Save extends SubCommand { @@ -73,7 +73,7 @@ public class Save extends SubCommand { return; } MainUtil.sendMessage(plr, C.SAVE_SUCCESS); - final List schematics = (List) plr.getMeta("plot_schematics"); + final List schematics = plr.getMeta("plot_schematics"); if (schematics != null) { schematics.add(file); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java index 803b3c194..2469ac249 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java @@ -52,7 +52,7 @@ public class SetHome extends SetCommand { Plot base = plot.getBasePlot(false); Location bot = base.getBottomAbs(); Location loc = plr.getLocationFull(); - BlockLoc rel = new BlockLoc(loc.getX() - bot.getX(), loc.getY(), loc.getZ() - bot.getZ(), loc.getYaw(), loc.getPitch());; + BlockLoc rel = new BlockLoc(loc.getX() - bot.getX(), loc.getY(), loc.getZ() - bot.getZ(), loc.getYaw(), loc.getPitch()); base.setHome(rel); return MainUtil.sendMessage(plr, C.POSITION_SET); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Setup.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Setup.java index 9f04cff40..ba37ac891 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Setup.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Setup.java @@ -66,7 +66,7 @@ public class Setup extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { // going through setup - SetupObject object = (SetupObject) plr.getMeta("setup"); + SetupObject object = plr.getMeta("setup"); if (object == null) { object = new SetupObject(); plr.setMeta("setup", object); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index 337668069..6c4894ca4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -23,22 +23,32 @@ package com.intellectualcrafters.plot.flag; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.object.*; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotCluster; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.PlotSettings; +import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.Permissions; - -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * Flag Manager Utility * */ public class FlagManager { - + private final static HashSet reserved = new HashSet<>(); - + private final static HashSet flags = new HashSet<>(); - + /** * Reserve a flag so that it cannot be set by players * @param flag @@ -46,7 +56,7 @@ public class FlagManager { public static void reserveFlag(final String flag) { reserved.add(flag); } - + /** * Get if a flag is reserved * @param flag @@ -55,7 +65,7 @@ public class FlagManager { public static boolean isReserved(final String flag) { return reserved.contains(flag); } - + /** * Get the reserved flags * @return @@ -63,7 +73,7 @@ public class FlagManager { public static HashSet getReservedFlags() { return (HashSet) reserved.clone(); } - + /** * Unreserve a flag * @param flag @@ -71,7 +81,7 @@ public class FlagManager { public static void unreserveFlag(final String flag) { reserved.remove(flag); } - + /** * Register an AbstractFlag with PlotSquared * @@ -82,9 +92,9 @@ public class FlagManager { public static boolean addFlag(final AbstractFlag af) { return addFlag(af, false); } - + public static boolean addFlag(final AbstractFlag af, final boolean reserved) { - PS.debug(C.PREFIX.s() + "&8 - Adding flag: &7" + af); + PS.debug(C.PREFIX + "&8 - Adding flag: &7" + af); PS.get().foreachPlotArea(new RunnableVal() { @Override public void run(PlotArea value) { @@ -125,7 +135,7 @@ public class FlagManager { } return flag_string.toString(); } - + public static Flag getSettingFlag(final PlotArea area, final PlotSettings settings, final String id) { Flag flag; if (settings.flags.isEmpty() || (flag = settings.flags.get(id)) == null) { @@ -139,7 +149,7 @@ public class FlagManager { } return flag; } - + public static boolean isBooleanFlag(final Plot plot, final String key, final boolean defaultValue) { final Flag flag = FlagManager.getPlotFlagRaw(plot, key); if (flag == null) { @@ -151,7 +161,7 @@ public class FlagManager { } return defaultValue; } - + /** * Get the value of a flag for a plot (respects flag defaults) * @param plot @@ -177,7 +187,7 @@ public class FlagManager { } return getSettingFlag(plot.getArea(), plot.getSettings(), flag); } - + public static boolean isPlotFlagTrue(final Plot plot, final String strFlag) { if (plot.owner == null) { return false; @@ -185,7 +195,7 @@ public class FlagManager { final Flag flag = getPlotFlagRaw(plot, strFlag); return !(flag == null || !((Boolean) flag.getValue())); } - + public static boolean isPlotFlagFalse(final Plot plot, final String strFlag) { if (plot.owner == null) { return false; @@ -196,7 +206,7 @@ public class FlagManager { } return false; } - + /** * Get the value of a flag for a plot (ignores flag defaults) * @param plot @@ -206,14 +216,14 @@ public class FlagManager { public static Flag getPlotFlagAbs(final Plot plot, final String flag) { return getSettingFlagAbs(plot.getSettings(), flag); } - + public static Flag getSettingFlagAbs(final PlotSettings settings, final String flag) { if (settings.flags.isEmpty()) { return null; } return settings.flags.get(flag); } - + /** * Add a flag to a plot * @param origin @@ -231,7 +241,7 @@ public class FlagManager { } return true; } - + public static boolean addPlotFlagAbs(final Plot plot, final Flag flag) { final boolean result = EventUtil.manager.callFlagAdd(flag, plot); if (!result) { @@ -240,14 +250,14 @@ public class FlagManager { plot.getFlags().put(flag.getKey(), flag); return true; } - + public static boolean addClusterFlag(final PlotCluster cluster, final Flag flag) { getSettingFlag(cluster.area, cluster.settings, flag.getKey()); cluster.settings.flags.put(flag.getKey(), flag); DBFunc.setFlags(cluster, cluster.settings.flags.values()); return true; } - + /** * * @param plot @@ -259,7 +269,7 @@ public class FlagManager { } return getSettingFlags(plot.getArea(), plot.getSettings()); } - + public static HashMap getPlotFlags(PlotArea area, final PlotSettings settings, final boolean ignorePluginflags) { final HashMap flags = new HashMap<>(); if (area != null && !area.DEFAULT_FLAGS.isEmpty()) { @@ -275,14 +285,14 @@ public class FlagManager { } else { flags.putAll(settings.flags); } - + return flags; } - + public static HashMap getSettingFlags(PlotArea area, final PlotSettings settings) { return getPlotFlags(area, settings, false); } - + public static boolean removePlotFlag(final Plot plot, final String id) { final Flag flag = plot.getFlags().remove(id); if (flag == null) { @@ -297,7 +307,7 @@ public class FlagManager { DBFunc.setFlags(plot, plot.getFlags().values()); return true; } - + public static boolean removeClusterFlag(final PlotCluster cluster, final String id) { final Flag flag = cluster.settings.flags.remove(id); if (flag == null) { @@ -311,7 +321,7 @@ public class FlagManager { DBFunc.setFlags(cluster, cluster.settings.flags.values()); return true; } - + public static void setPlotFlags(final Plot origin, final Set flags) { for (Plot plot : origin.getConnectedPlots()) { if (flags != null && !flags.isEmpty()) { @@ -328,7 +338,7 @@ public class FlagManager { DBFunc.setFlags(plot, plot.getFlags().values()); } } - + public static void setClusterFlags(final PlotCluster cluster, final Set flags) { if (flags != null && !flags.isEmpty()) { cluster.settings.flags.clear(); @@ -342,7 +352,7 @@ public class FlagManager { } DBFunc.setFlags(cluster, cluster.settings.flags.values()); } - + public static Flag[] removeFlag(final Flag[] flags, final String r) { final Flag[] f = new Flag[flags.length - 1]; int index = 0; @@ -353,7 +363,7 @@ public class FlagManager { } return f; } - + public static Set removeFlag(final Set flags, final String r) { final HashSet newflags = new HashSet<>(); for (final Flag flag : flags) { @@ -363,7 +373,7 @@ public class FlagManager { } return newflags; } - + /** * Get a list of registered AbstractFlag objects * @@ -372,7 +382,7 @@ public class FlagManager { public static HashSet getFlags() { return flags; } - + /** * Get a list of registered AbstractFlag objects based on player permissions * @@ -389,7 +399,7 @@ public class FlagManager { } return returnFlags; } - + /** * Get an AbstractFlag by a string Returns null if flag does not exist * @@ -405,7 +415,7 @@ public class FlagManager { } return null; } - + /** * Get an AbstractFlag by a string * @@ -420,7 +430,7 @@ public class FlagManager { } return getFlag(string); } - + /** * Remove a registered AbstractFlag * @@ -431,7 +441,7 @@ public class FlagManager { public static boolean removeFlag(final AbstractFlag flag) { return flags.remove(flag); } - + public static HashMap parseFlags(final List flagstrings) { final HashMap map = new HashMap<>(); for (final String key : flagstrings) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/GeneratorWrapper.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/GeneratorWrapper.java index a5a1a7e1f..7dee024a6 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/GeneratorWrapper.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/GeneratorWrapper.java @@ -23,17 +23,16 @@ package com.intellectualcrafters.plot.generator; import com.intellectualcrafters.plot.object.PlotArea; public interface GeneratorWrapper { - public IndependentPlotGenerator getPlotGenerator(); - - public T getPlatformGenerator(); - public void augment(PlotArea area); - - public boolean isFull(); - - @Override - public String toString(); - - @Override - public boolean equals(Object obj); + IndependentPlotGenerator getPlotGenerator(); + + T getPlatformGenerator(); + + void augment(PlotArea area); + + boolean isFull(); + + @Override String toString(); + + @Override boolean equals(Object obj); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java index 2e9138d7c..5873f4d2b 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridPlotWorld.java @@ -32,7 +32,6 @@ import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler.Dimension; import com.intellectualcrafters.plot.util.SchematicHandler.Schematic; - import java.io.File; import java.util.HashMap; import java.util.HashSet; @@ -177,7 +176,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { PS.debug("&c - road schematics are disabled for this world."); } } - + @Override public boolean isCompatible(PlotArea plotworld) { if (!(plotworld instanceof SquarePlotWorld)) { @@ -250,7 +249,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { } } if (schem1 == null || schem2 == null || ROAD_WIDTH == 0) { - PS.debug(C.PREFIX.s() + "&3 - schematic: &7false"); + PS.debug(C.PREFIX + "&3 - schematic: &7false"); return; } ROAD_SCHEMATIC_ENABLED = true; @@ -298,7 +297,7 @@ public class HybridPlotWorld extends ClassicPlotWorld { } } } - + public void addOverlayBlock(short x, final short y, short z, final short id, byte data, final boolean rotate) { if (z < 0) { z += SIZE; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java index 0f2e85a4f..2b79bf7a5 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java @@ -41,17 +41,17 @@ public abstract class SquarePlotManager extends GridPlotManager { @Override public Location getPlotTopLocAbs(final PlotArea plotworld, final PlotId plotid) { - final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); + final SquarePlotWorld dpw = (SquarePlotWorld) plotworld; final int px = plotid.x; final int pz = plotid.y; - final int x = (dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1; - final int z = (dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1; + final int x = (dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - (int) Math.floor(dpw.ROAD_WIDTH / 2) - 1; + final int z = (dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - (int) Math.floor(dpw.ROAD_WIDTH / 2) - 1; return new Location(plotworld.worldname, x, Math.min(plotworld.MAX_BUILD_HEIGHT, 255), z); } @Override public PlotId getPlotIdAbs(final PlotArea plotworld, int x, final int y, int z) { - final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); + final SquarePlotWorld dpw = (SquarePlotWorld) plotworld; if (dpw.ROAD_OFFSET_X != 0) { x -= dpw.ROAD_OFFSET_X; } @@ -73,20 +73,20 @@ public abstract class SquarePlotManager extends GridPlotManager { } final int size = dpw.PLOT_WIDTH + dpw.ROAD_WIDTH; int idx; - int idz; if (x < 0) { - idx = (x / size); + idx = x / size; x = size + (x % size); } else { idx = (x / size) + 1; - x = (x % size); + x = x % size; } + int idz; if (z < 0) { - idz = (z / size); + idz = z / size; z = size + (z % size); } else { idz = (z / size) + 1; - z = (z % size); + z = z % size; } return ((z <= pathWidthLower) || (z > end) || (x <= pathWidthLower) || (x > end)) ? null : new PlotId(idx, idz); } @@ -94,7 +94,7 @@ public abstract class SquarePlotManager extends GridPlotManager { @Override public PlotId getPlotId(final PlotArea plotworld, int x, final int y, int z) { try { - final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); + final SquarePlotWorld dpw = (SquarePlotWorld) plotworld; if (plotworld == null) { return null; } @@ -117,23 +117,23 @@ public abstract class SquarePlotManager extends GridPlotManager { int dx; int rx; if (x < 0) { - dx = (x / size); + dx = x / size; rx = size + (x % size); } else { dx = (x / size) + 1; - rx = (x % size); + rx = x % size; } int dz; int rz; if (z < 0) { - dz = (z / size); + dz = z / size; rz = size + (z % size); } else { dz = (z / size) + 1; - rz = (z % size); + rz = z % size; } PlotId id = new PlotId(dx, dz); - boolean[] merged = new boolean[] { (rz <= pathWidthLower), (rx > end), (rz > end), (rx <= pathWidthLower) }; + boolean[] merged = new boolean[]{rz <= pathWidthLower, rx > end, rz > end, rx <= pathWidthLower}; int hash = MainUtil.hash(merged); // Not merged, and no need to check if it is if (hash == 0) { @@ -182,11 +182,11 @@ public abstract class SquarePlotManager extends GridPlotManager { */ @Override public Location getPlotBottomLocAbs(final PlotArea plotworld, final PlotId plotid) { - final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld); + final SquarePlotWorld dpw = (SquarePlotWorld) plotworld; final int px = plotid.x; final int pz = plotid.y; - final int x = (dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2)); - final int z = (dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2)); + final int x = (dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - (int) Math.floor(dpw.ROAD_WIDTH / 2); + final int z = (dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - (int) Math.floor(dpw.ROAD_WIDTH / 2); return new Location(plotworld.worldname, x, plotworld.MIN_BUILD_HEIGHT, z); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java b/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java index 6d938df3a..ee56f2cdf 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxOwner.java @@ -1,8 +1,5 @@ package com.intellectualcrafters.plot.object.comment; -import java.util.ArrayList; -import java.util.List; - import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -10,6 +7,9 @@ import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.TaskManager; +import java.util.ArrayList; +import java.util.List; + public class InboxOwner extends CommentInbox { @Override @@ -17,10 +17,10 @@ public class InboxOwner extends CommentInbox { if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.read." + toString()); } - return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions + return Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions .hasPermission(player, "plots.inbox.read." + toString() - + ".other"))); + + ".other")); } @Override @@ -28,9 +28,10 @@ public class InboxOwner extends CommentInbox { if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.write." + toString()); } - return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." + return Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions + .hasPermission(player, "plots.inbox.write." + toString() - + ".other"))); + + ".other")); } @Override @@ -38,9 +39,10 @@ public class InboxOwner extends CommentInbox { if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); } - return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + return Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions + .hasPermission(player, "plots.inbox.modify." + toString() - + ".other"))); + + ".other")); } @Override @@ -59,7 +61,7 @@ public class InboxOwner extends CommentInbox { public void run(List value) { whenDone.value = value; if (value != null) { - for (final PlotComment comment : (ArrayList) value) { + for (final PlotComment comment : value) { plot.getSettings().addComment(comment); } } else { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java b/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java index 50d9a23b8..a58195f76 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/comment/InboxPublic.java @@ -1,8 +1,5 @@ package com.intellectualcrafters.plot.object.comment; -import java.util.ArrayList; -import java.util.List; - import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -10,6 +7,9 @@ import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.TaskManager; +import java.util.ArrayList; +import java.util.List; + public class InboxPublic extends CommentInbox { @Override @@ -17,10 +17,10 @@ public class InboxPublic extends CommentInbox { if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.read." + toString()); } - return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions + return Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (plot.isOwner(player.getUUID()) || Permissions .hasPermission(player, "plots.inbox.read." + toString() - + ".other"))); + + ".other")); } @Override @@ -28,9 +28,10 @@ public class InboxPublic extends CommentInbox { if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.write." + toString()); } - return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." + return Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (plot.isOwner(player.getUUID()) || Permissions + .hasPermission(player, "plots.inbox.write." + toString() - + ".other"))); + + ".other")); } @Override @@ -38,9 +39,10 @@ public class InboxPublic extends CommentInbox { if (plot == null) { return Permissions.hasPermission(player, "plots.inbox.modify." + toString()); } - return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + return Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (plot.isOwner(player.getUUID()) || Permissions + .hasPermission(player, "plots.inbox.modify." + toString() - + ".other"))); + + ".other")); } @Override @@ -59,7 +61,7 @@ public class InboxPublic extends CommentInbox { public void run(List value) { whenDone.value = value; if (value != null) { - for (final PlotComment comment : (ArrayList) value) { + for (final PlotComment comment : value) { plot.getSettings().addComment(comment); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/CmdConfirm.java b/Core/src/main/java/com/intellectualcrafters/plot/util/CmdConfirm.java index aad301155..385e50e9a 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/CmdConfirm.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/CmdConfirm.java @@ -6,7 +6,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer; public class CmdConfirm { public static CmdInstance getPending(final PlotPlayer player) { - return player.getMeta("cmdConfirm"); + return player.getMeta("cmdConfirm"); } public static void removePending(final PlotPlayer player) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java index af78b4302..9988818a7 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ExpireManager.java @@ -54,20 +54,22 @@ public class ExpireManager { public void confirmExpiry(final PlotPlayer pp) { if (Settings.AUTO_CLEAR_CONFIRMATION && plotsToDelete != null && !plotsToDelete.isEmpty() && pp.hasPermission("plots.admin.command.autoclear")) { final int num = plotsToDelete.size(); - Iterator iter = plotsToDelete.iterator(); - while (iter.hasNext()) { - final Plot current = iter.next(); + for (final Plot current : plotsToDelete) { if (isExpired(current)) { TaskManager.runTask(new Runnable() { @Override public void run() { pp.teleport(current.getCenter()); PlotMessage msg = new PlotMessage() - .text(num + " " + (num > 1 ? "plots are" : "plot is") + " expired:").color("$1").command("/plot list expired").tooltip("/plot list expired") + .text(num + " " + (num > 1 ? "plots are" : "plot is") + " expired:").color("$1").command("/plot list expired") + .tooltip("/plot list expired") //.text("\n - ").color("$3").text("Delete all (/plot delete expired)").color("$2").command("/plot delete expired") - .text("\n - ").color("$3").text("Delete this (/plot delete)").color("$2").command("/plot delete").tooltip("/plot delete") - .text("\n - ").color("$3").text("Remind later (/plot set keep 1d)").color("$2").command("/plot set keep 1d").tooltip("/plot set keep 1d") - .text("\n - ").color("$3").text("Keep this (/plot set keep true)").color("$2").command("/plot set keep true").tooltip("/plot set keep true"); + .text("\n - ").color("$3").text("Delete this (/plot delete)").color("$2").command("/plot delete") + .tooltip("/plot delete") + .text("\n - ").color("$3").text("Remind later (/plot set keep 1d)").color("$2").command("/plot set keep 1d") + .tooltip("/plot set keep 1d") + .text("\n - ").color("$3").text("Keep this (/plot set keep true)").color("$2").command("/plot set keep true") + .tooltip("/plot set keep true"); msg.send(pp); } }); @@ -75,7 +77,6 @@ public class ExpireManager { } } plotsToDelete.clear(); - return; } } @@ -247,7 +248,7 @@ public class ExpireManager { return false; } final long compared = System.currentTimeMillis() - last; - if (compared >= (TimeUnit.DAYS.toMillis(Settings.AUTO_CLEAR_DAYS))) { + if (compared >= TimeUnit.DAYS.toMillis(Settings.AUTO_CLEAR_DAYS)) { return true; } } @@ -266,7 +267,7 @@ public class ExpireManager { return false; } } else if (value instanceof Long) { - if (((Long) value) > System.currentTimeMillis()) { + if ((Long) value > System.currentTimeMillis()) { return false; } } else { // Invalid? diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/Permissions.java b/Core/src/main/java/com/intellectualcrafters/plot/util/Permissions.java index 5815d510b..e4bba25f2 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/Permissions.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/Permissions.java @@ -1,12 +1,12 @@ package com.intellectualcrafters.plot.util; -import java.util.HashMap; - import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.PlotPlayer; import com.plotsquared.general.commands.CommandCaller; +import java.util.HashMap; + /** * The Permissions class handles checking user permissions.
* - This will respect * nodes and plots.admin and can be used to check permission ranges (e.g. plots.plot.5)
@@ -34,7 +34,7 @@ public class Permissions { if (!Settings.PERMISSION_CACHING) { return hasPermission((CommandCaller) player, perm); } - HashMap map = (HashMap) player.getMeta("perm"); + HashMap map = player.getMeta("perm"); if (map != null) { Boolean result = map.get(perm); if (result != null) { @@ -63,7 +63,7 @@ public class Permissions { final String[] nodes = perm.split("\\."); final StringBuilder n = new StringBuilder(); for (int i = 0; i <= (nodes.length - 1); i++) { - n.append(nodes[i] + (".")); + n.append(nodes[i] + "."); if (!perm.equals(n + C.PERMISSION_STAR.s())) { if (player.hasPermission(n + C.PERMISSION_STAR.s())) { return true; @@ -106,7 +106,7 @@ public class Permissions { final String[] nodes = stub.split("\\."); final StringBuilder n = new StringBuilder(); for (int i = 0; i < (nodes.length - 1); i++) { - n.append(nodes[i] + (".")); + n.append(nodes[i] + "."); if (!stub.equals(n + C.PERMISSION_STAR.s())) { if (player.hasPermission(n + C.PERMISSION_STAR.s())) { return Integer.MAX_VALUE; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/PlotGamemode.java b/Core/src/main/java/com/intellectualcrafters/plot/util/PlotGamemode.java index 2e2fc6200..6df304d43 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/PlotGamemode.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/PlotGamemode.java @@ -1,5 +1,5 @@ package com.intellectualcrafters.plot.util; public enum PlotGamemode { - ADVENTURE, SURVIVAL, CREATIVE, SPECTATOR; + ADVENTURE, SURVIVAL, CREATIVE, SPECTATOR } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/PlotWeather.java b/Core/src/main/java/com/intellectualcrafters/plot/util/PlotWeather.java index 799798a9f..918d7f4e8 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/PlotWeather.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/PlotWeather.java @@ -1,5 +1,5 @@ package com.intellectualcrafters.plot.util; public enum PlotWeather { - RAIN, CLEAR, RESET; + RAIN, CLEAR, RESET } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index d92907c18..27fbef2c8 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -24,6 +24,7 @@ import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.schematic.PlotItem; + import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -166,7 +167,8 @@ public abstract class SchematicHandler { final int HEIGHT = demensions.getY(); // Validate dimensions RegionWrapper region = plot.getLargestRegion(); - if ((((region.maxX - region.minX + x_offset) + 1) < WIDTH) || (((region.maxZ - region.minZ + z_offset) + 1) < LENGTH) || (HEIGHT > 256)) { + if (((region.maxX - region.minX + x_offset + 1) < WIDTH) || ((region.maxZ - region.minZ + z_offset + 1) < LENGTH) || (HEIGHT + > 256)) { PS.debug("Schematic is too large"); PS.debug("(" + WIDTH + "," + LENGTH + "," + HEIGHT + ") is bigger than (" + (region.maxX - region.minX) + "," + (region.maxZ - region.minZ) + ",256)"); TaskManager.runTask(whenDone); @@ -451,7 +453,7 @@ public abstract class SchematicHandler { final List blockStates = ListTag.class.cast(tagMap.get("TileEntities")).getValue(); for (final Tag stateTag : blockStates) { try { - final CompoundTag ct = ((CompoundTag) stateTag); + final CompoundTag ct = (CompoundTag) stateTag; final Map state = ct.getValue(); final short x = IntTag.class.cast(state.get("x")).getValue().shortValue(); final short y = IntTag.class.cast(state.get("y")).getValue().shortValue(); @@ -782,15 +784,15 @@ public abstract class SchematicHandler { int dz = schematicDimension.getZ(); for (int y = y1; y <= y2; y++) { - int yy = y >= 0 ? (y < dy ? y : y - dy) : y + dy; + int yy = y >= 0 ? y < dy ? y : y - dy : y + dy; int i1 = yy * dx * dz; int j1 = (y - y1) * width * length; for (int z = z1; z <= z2; z++) { - int zz = z >= 0 ? (z < dz ? z : z - dz) : z + dz; + int zz = z >= 0 ? z < dz ? z : z - dz : z + dz; int i2 = i1 + zz * dx; int j2 = j1 + (z - z1) * width; for (int x = x1; x <= x2; x++) { - int xx = x >= 0 ? (x < dx ? x : x - dx) : x + dx; + int xx = x >= 0 ? x < dx ? x : x - dx : x + dx; int i3 = i2 + xx; int j3 = j2 + (x - x1); ids2[j3] = ids[i3]; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/SetQueue.java b/Core/src/main/java/com/intellectualcrafters/plot/util/SetQueue.java index b12926ad6..e6dace181 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SetQueue.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SetQueue.java @@ -179,7 +179,7 @@ public class SetQueue { return false; } final ChunkWrapper other = (ChunkWrapper) obj; - return ((x == other.x) && (z == other.z) && (StringMan.isEqual(world, other.world))); + return (x == other.x) && (z == other.z) && StringMan.isEqual(world, other.world); } @Override diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java b/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java index b66397298..0db7096cf 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandlerImplementation.java @@ -14,7 +14,6 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper; - import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -29,19 +28,19 @@ public abstract class UUIDHandlerImplementation { public UUIDWrapper uuidWrapper = null; public HashSet unknown = new HashSet<>(); private BiMap uuidMap = HashBiMap.create(new HashMap()); - + public UUIDHandlerImplementation(final UUIDWrapper wrapper) { uuidWrapper = wrapper; players = new ConcurrentHashMap<>(); } - + /** * If the UUID is not found, some commands can request to fetch the UUID when possible * @param name * @param ifFetch */ public abstract void fetchUUID(final String name, final RunnableVal ifFetch); - + /** * Start UUID caching (this should be an async task) * Recommended to override this is you want to cache offline players @@ -52,20 +51,20 @@ public abstract class UUIDHandlerImplementation { } return CACHED = true; } - + public UUIDWrapper getUUIDWrapper() { return uuidWrapper; } - + public void setUUIDWrapper(final UUIDWrapper wrapper) { uuidWrapper = wrapper; } - + public void rename(final UUID uuid, final StringWrapper name) { uuidMap.inverse().remove(uuid); uuidMap.put(name, uuid); } - + public void add(final BiMap toAdd) { if (uuidMap.isEmpty()) { uuidMap = toAdd; @@ -86,9 +85,9 @@ public abstract class UUIDHandlerImplementation { } uuidMap.put(name, uuid); } - PS.debug(C.PREFIX.s() + "&6Cached a total of: " + uuidMap.size() + " UUIDs"); + PS.debug(C.PREFIX + "&6Cached a total of: " + uuidMap.size() + " UUIDs"); } - + public boolean add(final StringWrapper name, final UUID uuid) { if ((uuid == null)) { return false; @@ -102,7 +101,7 @@ public abstract class UUIDHandlerImplementation { } return false; } - + /* * lazy UUID conversion: * - Useful if the person misconfigured the database, or settings before PlotMe conversion @@ -165,25 +164,25 @@ public abstract class UUIDHandlerImplementation { } return true; } - + public boolean uuidExists(final UUID uuid) { return uuidMap.containsValue(uuid); } - + public BiMap getUUIDMap() { return uuidMap; } - + public boolean nameExists(final StringWrapper wrapper) { return uuidMap.containsKey(wrapper); } - + public void handleShutdown() { players.clear(); uuidMap.clear(); uuidWrapper = null; } - + public String getName(final UUID uuid) { if (uuid == null) { return null; @@ -200,7 +199,7 @@ public abstract class UUIDHandlerImplementation { } return null; } - + public UUID getUUID(final String name, final RunnableVal ifFetch) { if ((name == null) || (name.isEmpty())) { return null; @@ -228,15 +227,15 @@ public abstract class UUIDHandlerImplementation { } return null; } - + public UUID getUUID(final PlotPlayer player) { return uuidWrapper.getUUID(player); } - + public UUID getUUID(final OfflinePlotPlayer player) { return uuidWrapper.getUUID(player); } - + public PlotPlayer getPlayer(final UUID uuid) { String name = getName(uuid); if (name != null) { @@ -244,13 +243,13 @@ public abstract class UUIDHandlerImplementation { } return null; } - + public PlotPlayer getPlayer(final String name) { return players.get(name); } - + public Map getPlayers() { return players; } - + } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpPage.java b/Core/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpPage.java index f4a7f6876..677347461 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpPage.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/helpmenu/HelpPage.java @@ -1,36 +1,35 @@ package com.intellectualcrafters.plot.util.helpmenu; -import java.util.ArrayList; -import java.util.List; - import com.intellectualcrafters.plot.commands.CommandCategory; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; +import java.util.ArrayList; +import java.util.List; public class HelpPage { - + private final List helpObjects; private final String _header; - + public HelpPage(final CommandCategory category, final int currentPage, final int maxPages) { helpObjects = new ArrayList<>(); _header = C.HELP_PAGE_HEADER.s().replace("%category%", category == null ? "ALL" : category.toString()).replace("%current%", (currentPage + 1) + "").replace("%max%", (maxPages + 1) + ""); } - + public void render(final PlotPlayer player) { if (helpObjects.size() < 1) { MainUtil.sendMessage(player, C.NOT_VALID_NUMBER, "(0)"); } else { - MainUtil.sendMessage(player, C.HELP_HEADER.s(), false); + MainUtil.sendMessage(player, C.HELP_HEADER, false); MainUtil.sendMessage(player, _header, false); for (final HelpObject object : helpObjects) { MainUtil.sendMessage(player, object.toString(), false); } - MainUtil.sendMessage(player, C.HELP_FOOTER.s(), false); + MainUtil.sendMessage(player, C.HELP_FOOTER, false); } } - + public void addHelpItem(final HelpObject object) { helpObjects.add(object); } diff --git a/Core/src/main/java/com/plotsquared/general/commands/CommandManager.java b/Core/src/main/java/com/plotsquared/general/commands/CommandManager.java index 377421832..5b5b428a6 100644 --- a/Core/src/main/java/com/plotsquared/general/commands/CommandManager.java +++ b/Core/src/main/java/com/plotsquared/general/commands/CommandManager.java @@ -85,10 +85,14 @@ public class CommandManager { } public int handle(final T plr, String input) { - if ((initialCharacter != null) && !input.startsWith(initialCharacter + "")) { + if (initialCharacter != null && !input.startsWith(initialCharacter + "")) { return CommandHandlingOutput.NOT_COMMAND; } - input = initialCharacter == null ? input : input.substring(1); + if (initialCharacter == null) { + input = input; + } else { + input = input.substring(1); + } final String[] parts = input.split(" "); String[] args; final String command = parts[0].toLowerCase(); diff --git a/Core/src/main/java/com/plotsquared/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/listener/PlotListener.java index 5278d4ee7..e8b2be66c 100644 --- a/Core/src/main/java/com/plotsquared/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/listener/PlotListener.java @@ -29,8 +29,17 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal; -import com.intellectualcrafters.plot.util.*; - +import com.intellectualcrafters.plot.util.AbstractTitle; +import com.intellectualcrafters.plot.util.CommentManager; +import com.intellectualcrafters.plot.util.EventUtil; +import com.intellectualcrafters.plot.util.ExpireManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.PlotGamemode; +import com.intellectualcrafters.plot.util.PlotWeather; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -40,7 +49,7 @@ import java.util.UUID; */ public class PlotListener { - + public static boolean plotEntry(final PlotPlayer pp, final Plot plot) { if (plot.isDenied(pp.getUUID()) && !Permissions.hasPermission(pp, "plots.admin.entry.denied")) { return false; @@ -59,7 +68,7 @@ public class PlotListener { final int size = flags.size(); boolean titles = Settings.TITLES; final String greeting; - + if (size != 0) { final Flag titleFlag = flags.get("titles"); if (titleFlag != null) { @@ -115,7 +124,7 @@ public class PlotListener { if (weatherFlag != null) { pp.setWeather((PlotWeather) weatherFlag.getValue()); } - + final Flag musicFlag = flags.get("music"); if (musicFlag != null) { final Integer id = (Integer) musicFlag.getValue(); @@ -174,7 +183,7 @@ public class PlotListener { } return true; } - + public static boolean plotExit(final PlotPlayer pp, final Plot plot) { pp.deleteMeta("lastplot"); EventUtil.manager.callLeave(pp, plot); diff --git a/Sponge/build.gradle b/Sponge/build.gradle index a0300fd06..203cf013c 100644 --- a/Sponge/build.gradle +++ b/Sponge/build.gradle @@ -17,6 +17,7 @@ apply plugin: 'com.github.johnrengelman.shadow' dependencies { compile project(':Core') compile 'org.spongepowered:spongeapi:4.0.3' + compile 'org.mcstats.sponge:metrics:R8-SNAPSHOT' } sourceCompatibility = 1.8 @@ -31,6 +32,10 @@ repositories { name = "Sponge" url = "https://repo.spongepowered.org/maven" } + maven { + name = "Sponge Metrics" + url = "http://repo.mcstats.org/content/repositories/releases/" + } } minecraft { version = "1.8.9-11.15.1.1742" @@ -49,7 +54,9 @@ processResources { shadowJar { dependencies { include(dependency(':Core')) + include(dependency('org.mcstats.sponge:metrics:R8-SNAPSHOT')) } + relocate 'org.mcstats', 'com.plotsquared.stats' archiveName = "${parent.name}-${project.name}-${parent.version}.jar" destinationDir = file '../target' } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java index fe1357820..2e83355e6 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -41,7 +41,6 @@ import com.plotsquared.sponge.util.SpongeEconHandler; import com.plotsquared.sponge.util.SpongeEventUtil; import com.plotsquared.sponge.util.SpongeHybridUtils; import com.plotsquared.sponge.util.SpongeInventoryUtil; -import com.plotsquared.sponge.util.SpongeMetrics; import com.plotsquared.sponge.util.SpongeSchematicHandler; import com.plotsquared.sponge.util.SpongeSetupUtils; import com.plotsquared.sponge.util.SpongeTaskManager; @@ -52,6 +51,7 @@ import com.plotsquared.sponge.util.block.SlowQueue; import com.plotsquared.sponge.uuid.SpongeLowerOfflineUUIDWrapper; import com.plotsquared.sponge.uuid.SpongeOnlineUUIDWrapper; import com.plotsquared.sponge.uuid.SpongeUUIDHandler; +import org.mcstats.Metrics; import org.slf4j.Logger; import org.spongepowered.api.Game; import org.spongepowered.api.Server; @@ -70,6 +70,7 @@ import org.spongepowered.api.world.gen.WorldGenerator; import org.spongepowered.api.world.gen.WorldGeneratorModifier; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -303,10 +304,10 @@ public class SpongeMain implements IPlotMain { @Override public void startMetrics() { try { - final SpongeMetrics metrics = new SpongeMetrics(game, (PluginContainer) this); + Metrics metrics = new Metrics(game, (PluginContainer) this); metrics.start(); log(C.PREFIX.s() + "&6Metrics enabled."); - } catch (final Exception e) { + } catch (IOException e) { log(C.PREFIX.s() + "&cFailed to load up metrics."); } } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongeAugmentedGenerator.java b/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongeAugmentedGenerator.java index 332b1f3f7..fca8a7213 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongeAugmentedGenerator.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/generator/SpongeAugmentedGenerator.java @@ -18,9 +18,10 @@ import java.util.List; public class SpongeAugmentedGenerator implements GenerationPopulator { private static SpongeAugmentedGenerator generator; - - private SpongeAugmentedGenerator() {}; - + + private SpongeAugmentedGenerator() { + } + public static SpongeAugmentedGenerator get(World world) { WorldGenerator wg = world.getWorldGenerator(); List populators = wg.getGenerationPopulators(); diff --git a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java index a28eeef7e..7dc01806b 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -84,7 +84,7 @@ public class MainListener { if (Settings.USE_PLOTME_ALIAS) { SpongeMain.THIS.getGame().getCommandManager().process(source, ("plots " + event.getArguments()).trim()); } else { - source.sendMessage(SpongeUtil.getText(C.NOT_USING_PLOTME.s())); + source.sendMessage(SpongeUtil.getText(C.NOT_USING_PLOTME)); } event.setCancelled(true); } diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeMetrics.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeMetrics.java deleted file mode 100644 index 0aa09932b..000000000 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeMetrics.java +++ /dev/null @@ -1,518 +0,0 @@ -package com.plotsquared.sponge.util; - -/* - * Copyright 2011-2013 Tyler Blair. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and contributors and should not be interpreted as representing official policies, - * either expressed or implied, of anybody else. - */ - -import com.google.inject.Inject; -import com.intellectualcrafters.plot.PS; -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.net.Proxy; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLEncoder; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.zip.GZIPOutputStream; -import ninja.leaping.configurate.commented.CommentedConfigurationNode; -import ninja.leaping.configurate.hocon.HoconConfigurationLoader; -import ninja.leaping.configurate.loader.ConfigurationLoader; -import org.spongepowered.api.Game; -import org.spongepowered.api.plugin.PluginContainer; -import org.spongepowered.api.scheduler.Task; - -public class SpongeMetrics { - - /** - * The current revision number - */ - private final static int REVISION = 7; - - /** - * The base url of the metrics domain - */ - private static final String BASE_URL = "http://report.mcstats.org"; - - /** - * The url used to report a server's status - */ - private static final String REPORT_URL = "/plugin/%s"; - - /** - * Interval of time to ping (in minutes) - */ - private static final int PING_INTERVAL = 15; - - /** - * The game data is being sent for - */ - private final Game game; - - /** - * The plugin this metrics submits for - */ - private final PluginContainer plugin; - /** - * Lock for synchronization - */ - private final Object optOutLock = new Object(); - /** - * The plugin configuration file - */ - private CommentedConfigurationNode config; - /** - * The configuration loader - */ - private ConfigurationLoader configurationLoader; - /** - * The plugin configuration file - */ - private File configurationFile; - /** - * Unique server id - */ - private String guid; - /** - * Debug mode - */ - private boolean debug; - /** - * The scheduled task - */ - private volatile Task task = null; - - @Inject - public SpongeMetrics(final Game game, final PluginContainer plugin) throws IOException { - if (plugin == null) { - throw new IllegalArgumentException("Plugin cannot be null"); - } - - this.game = game; - this.plugin = plugin; - - loadConfiguration(); - } - - /** - * GZip compress a string of bytes - * - * @param input - * @return - */ - public static byte[] gzip(final String input) { - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - GZIPOutputStream gzos = null; - - try { - gzos = new GZIPOutputStream(baos); - gzos.write(input.getBytes("UTF-8")); - } catch (final IOException e) { - e.printStackTrace(); - } finally { - if (gzos != null) { - try { - gzos.close(); - } catch (final IOException ignore) { - } - } - } - - return baos.toByteArray(); - } - - /** - * Appends a json encoded key/value pair to the given string builder. - * - * @param json - * @param key - * @param value - * @throws java.io.UnsupportedEncodingException - */ - private static void appendJSONPair(final StringBuilder json, final String key, final String value) throws UnsupportedEncodingException { - boolean isValueNumeric = false; - - try { - if (value.equals("0") || !value.endsWith("0")) { - Double.parseDouble(value); - isValueNumeric = true; - } - } catch (final NumberFormatException e) { - isValueNumeric = false; - } - - if (json.charAt(json.length() - 1) != '{') { - json.append(','); - } - - json.append(escapeJSON(key)); - json.append(':'); - - if (isValueNumeric) { - json.append(value); - } else { - json.append(escapeJSON(value)); - } - } - - /** - * Escape a string to create a valid JSON string - * - * @param text - * @return - */ - private static String escapeJSON(final String text) { - final StringBuilder builder = new StringBuilder(); - - builder.append('"'); - for (int index = 0; index < text.length(); index++) { - final char chr = text.charAt(index); - - switch (chr) { - case '"': - case '\\': - builder.append('\\'); - builder.append(chr); - break; - case '\b': - builder.append("\\b"); - break; - case '\t': - builder.append("\\t"); - break; - case '\n': - builder.append("\\n"); - break; - case '\r': - builder.append("\\r"); - break; - default: - if (chr < ' ') { - final String t = "000" + Integer.toHexString(chr); - builder.append("\\u" + t.substring(t.length() - 4)); - } else { - builder.append(chr); - } - break; - } - } - builder.append('"'); - - return builder.toString(); - } - - /** - * Encode text as UTF-8 - * - * @param text the text to encode - * @return the encoded text, as UTF-8 - */ - private static String urlEncode(final String text) throws UnsupportedEncodingException { - return URLEncoder.encode(text, "UTF-8"); - } - - /** - * Loads the configuration - */ - private void loadConfiguration() { - configurationFile = getConfigFile(); - configurationLoader = HoconConfigurationLoader.builder().setFile(configurationFile).build(); - - try { - if (!configurationFile.exists()) { - configurationFile.createNewFile(); - config = configurationLoader.load(); - - config.setComment("This contains settings for MCStats: http://mcstats.org"); - config.getNode("mcstats.guid").setValue(UUID.randomUUID().toString()); - config.getNode("mcstats.opt-out").setValue(false); - config.getNode("mcstats.debug").setValue(false); - - configurationLoader.save(config); - } else { - config = configurationLoader.load(); - } - - guid = config.getNode("mcstats.guid").getString(); - debug = config.getNode("mcstats.debug").getBoolean(); - } catch (final IOException e) { - e.printStackTrace(); - } - } - - /** - * Start measuring statistics. This will immediately create an async repeating task as the plugin and send the - * initial data to the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200 - * ticks. - * - * @return True if statistics measuring is running, otherwise false. - */ - public boolean start() { - synchronized (optOutLock) { - // Did we opt out? - if (isOptOut()) { - return false; - } - - // Is metrics already running? - if (task != null) { - return true; - } - - // Begin hitting the server with glorious data - final Task.Builder builder = game.getScheduler().createTaskBuilder(); - builder.async().interval(PING_INTERVAL, TimeUnit.MINUTES).execute(new Runnable() { - - private boolean firstPost = true; - - @Override - public void run() { - try { - // This has to be synchronized or it can collide with the disable method. - synchronized (optOutLock) { - // Disable Task, if it is running and the server owner decided to opt-out - if (isOptOut() && (task != null)) { - task.cancel(); - task = null; - } - } - - // We use the inverse of firstPost because if it is the first time we are posting, - // it is not a interval ping, so it evaluates to FALSE - // Each time thereafter it will evaluate to TRUE, i.e PING! - postPlugin(!firstPost); - - // After the first post we set firstPost to false - // Each post thereafter will be a ping - firstPost = false; - } catch (final IOException e) { - if (debug) { - PS.debug("[Metrics] " + e.getMessage()); - } - } - } - }); - return true; - } - } - - /** - * Has the server owner denied plugin metrics? - * - * @return true if metrics should be opted out of it - */ - public boolean isOptOut() { - synchronized (optOutLock) { - loadConfiguration(); - - return config.getNode("mcstats.opt-out").getBoolean(); - } - } - - /** - * Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task. - * - * @throws java.io.IOException - */ - public void enable() throws IOException { - // This has to be synchronized or it can collide with the check in the task. - synchronized (optOutLock) { - // Check if the server owner has already set opt-out, if not, set it. - if (isOptOut()) { - config.getNode("mcstats.opt-out").setValue(false); - configurationLoader.save(config); - } - - // Enable Task, if it is not running - if (task == null) { - start(); - } - } - } - - /** - * Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task. - * - * @throws java.io.IOException - */ - public void disable() throws IOException { - // This has to be synchronized or it can collide with the check in the task. - synchronized (optOutLock) { - // Check if the server owner has already set opt-out, if not, set it. - if (!isOptOut()) { - config.getNode("mcstats.opt-out").setValue(true); - configurationLoader.save(config); - } - - // Disable Task, if it is running - if (task != null) { - task.cancel(); - task = null; - } - } - } - - /** - * Gets the File object of the config file that should be used to store data such as the GUID and opt-out status - * - * @return the File object for the config file - */ - public File getConfigFile() { - // TODO configDir - final File configFolder = new File("config"); - - return new File(configFolder, "PluginMetrics.conf"); - } - - /** - * Generic method that posts a plugin to the metrics website - * - */ - private void postPlugin(final boolean isPing) throws IOException { - // Server software specific section - final String pluginName = plugin.getName(); - final boolean onlineMode = game.getServer().getOnlineMode(); // TRUE if online mode is enabled - final String pluginVersion = plugin.getVersion().get(); - // TODO no visible way to get MC version at the moment - // TODO added by game.getPlatform().getMinecraftVersion() -- impl in 2.1 - final String serverVersion = String.format("%s %s", "Sponge", game.getPlatform().getMinecraftVersion()); - final int playersOnline = game.getServer().getOnlinePlayers().size(); - - // END server software specific section -- all code below does not use any code outside of this class / Java - - // Construct the post data - final StringBuilder json = new StringBuilder(1024); - json.append('{'); - - // The plugin's description file containg all of the plugin data such as name, version, author, etc - appendJSONPair(json, "guid", guid); - appendJSONPair(json, "plugin_version", pluginVersion); - appendJSONPair(json, "server_version", serverVersion); - appendJSONPair(json, "players_online", Integer.toString(playersOnline)); - - // New data as of R6 - final String osname = System.getProperty("os.name"); - String osarch = System.getProperty("os.arch"); - final String osversion = System.getProperty("os.version"); - final String java_version = System.getProperty("java.version"); - final int coreCount = Runtime.getRuntime().availableProcessors(); - - // normalize os arch .. amd64 -> x86_64 - if (osarch.equals("amd64")) { - osarch = "x86_64"; - } - - appendJSONPair(json, "osname", osname); - appendJSONPair(json, "osarch", osarch); - appendJSONPair(json, "osversion", osversion); - appendJSONPair(json, "cores", Integer.toString(coreCount)); - appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0"); - appendJSONPair(json, "java_version", java_version); - - // If we're pinging, append it - if (isPing) { - appendJSONPair(json, "ping", "1"); - } - - // close json - json.append('}'); - - // Create the url - final URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName))); - - // Connect to the website - URLConnection connection; - - // Mineshafter creates a socks proxy, so we can safely bypass it - // It does not reroute POST requests so we need to go around it - if (isMineshafterPresent()) { - connection = url.openConnection(Proxy.NO_PROXY); - } else { - connection = url.openConnection(); - } - - final byte[] uncompressed = json.toString().getBytes(); - final byte[] compressed = gzip(json.toString()); - - // Headers - connection.addRequestProperty("User-Agent", "MCStats/" + REVISION); - connection.addRequestProperty("Content-Type", "application/json"); - connection.addRequestProperty("Content-Encoding", "gzip"); - connection.addRequestProperty("Content-Length", Integer.toString(compressed.length)); - connection.addRequestProperty("Accept", "application/json"); - connection.addRequestProperty("Connection", "close"); - - connection.setDoOutput(true); - - if (debug) { - PS.debug("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length); - } - - // Write the data - final OutputStream os = connection.getOutputStream(); - os.write(compressed); - os.flush(); - - // Now read the response - final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String response = reader.readLine(); - - // close resources - os.close(); - reader.close(); - - if ((response == null) || response.startsWith("ERR") || response.startsWith("7")) { - if (response == null) { - response = "null"; - } else if (response.startsWith("7")) { - response = response.substring(response.startsWith("7,") ? 2 : 1); - } - - throw new IOException(response); - } - } - - /** - * Check if mineshafter is present. If it is, we need to bypass it to send POST requests - * - * @return true if mineshafter is installed on the server - */ - private boolean isMineshafterPresent() { - try { - Class.forName("mineshafter.MineServer"); - return true; - } catch (final Exception e) { - return false; - } - } - -} diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java index b69b0adef..3f163e62d 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeUtil.java @@ -86,7 +86,7 @@ public class SpongeUtil extends WorldUtil { System.out.println(method + ": " + cause.toString()); System.out.println(method + ": " + cause.getClass()); System.out.println(method + ": " + StringMan.getString(cause.all())); - System.out.println(method + ": " + (cause.root())); + System.out.println(method + ": " + cause.root()); } public static void initBiomeCache() { @@ -291,7 +291,7 @@ public class SpongeUtil extends WorldUtil { id = Short.parseShort(split[0]); match = 0; } else { - List types = ReflectionUtils.getStaticFields(BlockTypes.class); + List types = ReflectionUtils.getStaticFields(BlockTypes.class); final StringComparison.ComparisonResult comparison = new StringComparison(name, types.toArray(new BlockType[types.size()])) { @Override