From 7029069e311eb241779787bc64be7432848f51b7 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Mon, 15 Dec 2014 12:04:13 +1100 Subject: [PATCH] Fixes Fixed plot auto for mega plot Fixed an issue with SQLManager and SQLite Added config option for max claim area for a mega plot with plot auto Fixed an issue with UUIDHandler + online mode and old minecraft versions. --- .../intellectualcrafters/plot/PlotMain.java | 3 +- .../plot/commands/Auto.java | 62 ++++++++++++------- .../intellectualcrafters/plot/config/C.java | 1 + .../plot/config/Settings.java | 5 +- .../plot/database/SQLManager.java | 59 +++++++++--------- .../plot/util/UUIDHandler.java | 8 ++- 6 files changed, 85 insertions(+), 53 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index f70de0194..22cc3b62c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -924,7 +924,7 @@ public class PlotMain extends JavaPlugin { final Map options = new HashMap<>(); options.put("auto_update", false); - + options.put("claim.max-auto-area", Settings.MAX_AUTO_SIZE); options.put("UUID.offline", Settings.OFFLINE_MODE); options.put("worldguard.enabled", Settings.WORLDGUARD); options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT); @@ -959,6 +959,7 @@ public class PlotMain extends JavaPlugin { Settings.MOB_PATHFINDING = config.getBoolean("mob_pathfinding"); Settings.METRICS = config.getBoolean("metrics"); Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days"); + Settings.MAX_AUTO_SIZE = config.getInt("claim.max-auto-area"); Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled"); Settings.TITLES = config.getBoolean("titles"); Settings.MOB_CAP_ENABLED = config.getBoolean("perm-based-mob-cap.enabled"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index e9bf49ae8..40c05e706 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -23,6 +23,7 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; @@ -31,7 +32,9 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; + import net.milkbowl.vault.economy.Economy; + import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; @@ -106,6 +109,8 @@ public class Auto extends SubCommand { schematic = args[1]; } } catch (final Exception e) { + size_x = 1; + size_z = 1; schematic = args[0]; // PlayerFunctions.sendMessage(plr, // "&cError: Invalid size (X,Y)"); @@ -117,8 +122,19 @@ public class Auto extends SubCommand { // return false; } } - if (PlayerFunctions.getPlayerPlotCount(world, plr) >= PlayerFunctions.getAllowedPlots(plr)) { - PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); + + if (size_x * size_z > Settings.MAX_AUTO_SIZE) { + PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + ""); + return false; + } + int diff = PlayerFunctions.getPlayerPlotCount(world, plr) - PlayerFunctions.getAllowedPlots(plr); + if (diff + (size_x * size_z) >= 0) { + if (diff < 0) { + PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, - diff - 1 + ""); + } + else { + PlayerFunctions.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); + } return false; } final PlotWorld pWorld = PlotMain.getWorldSettings(world); @@ -136,16 +152,16 @@ public class Auto extends SubCommand { } } if (!schematic.equals("")) { - if (pWorld.SCHEMATIC_CLAIM_SPECIFY) { - if (pWorld.SCHEMATICS.contains(schematic.toLowerCase())) { - sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic); - return true; - } - if (!PlotMain.hasPermission(plr, "plots.claim." + schematic) && !plr.hasPermission("plots.admin")) { - PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic); - return true; - } +// if (pWorld.SCHEMATIC_CLAIM_SPECIFY) { + if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) { + sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic); + return true; } + if (!PlotMain.hasPermission(plr, "plots.claim." + schematic) && !plr.hasPermission("plots.admin")) { + PlayerFunctions.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic); + return true; + } +// } } boolean br = false; if ((size_x == 1) && (size_z == 1)) { @@ -165,23 +181,25 @@ public class Auto extends SubCommand { Auto.lastPlot = getNextPlot(Auto.lastPlot, 1); } } else { - - // Why does this need fixing, it should work fine for auto claiming mega plots - - + boolean lastPlot = true; + PlotId lastId = Auto.lastPlot; while (!br) { final PlotId start = getNextPlot(Auto.lastPlot, 1); - // Checking if the current set of plots is a viable option. - { - if ((PlotMain.getPlots(world).get(start) == null) || (PlotMain.getPlots(world).get(start).owner == null)) { - Auto.lastPlot = start; - continue; - } + Auto.lastPlot = start; + if (lastPlot) { + lastId = start; } - + if (PlotMain.getPlots(world).get(start) != null && PlotMain.getPlots(world).get(start).owner != null) { + continue; + } + else { + lastPlot = false; + } + System.out.print("UNOWNED: " + start); final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1); if (isUnowned(world, start, end)) { + System.out.print("LAST PLOT: " + start); for (int i = start.x; i <= end.x; i++) { for (int j = start.y; j <= end.y; j++) { final Plot plot = PlotHelper.getPlot(world, new PlotId(i, j)); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index 343cb10db..2a8e9d310 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -151,6 +151,7 @@ public enum C { NO_PERMISSION("&cYou are lacking the permission node: &6%s"), NO_PLOT_PERMS("&cYou don't have the permissions to do that in this plot"), CANT_CLAIM_MORE_PLOTS("&cYou can't claim more plots."), + CANT_CLAIM_MORE_PLOTS_NUM("&cYou can't claim more than &6%s &cplots at once"), YOU_BE_DENIED("&cYou are not allowed to enter this plot"), NO_PERM_MERGE("&cYou are not the owner of the plot: &6%plot%"), diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 85905c745..4991a619c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -28,7 +28,10 @@ package com.intellectualcrafters.plot.config; * @author Empire92 */ public class Settings { - + /** + * + */ + public static int MAX_AUTO_SIZE = 4; /** * Default worldedit-require-selection-in-mask: false */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 8630bab4e..a08d43b79 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -67,7 +67,8 @@ public class SQLManager implements AbstractDB { connection = c; prefix = p; // Set timout - setTimout(); +// setTimout(); + // Public final SET_OWNER = "UPDATE `" + prefix + "plot` SET `owner` = ? WHERE `plot_id_x` = ? AND `plot_id_z` = ?"; @@ -81,36 +82,38 @@ public class SQLManager implements AbstractDB { "INSERT INTO `" + prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) values "; CREATE_PLOT = "INSERT INTO `" + prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) VALUES(?, ?, ?, ?)"; - - //schedule reconnect - Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable(){ - public void run(){ - try { - connection = PlotMain.getMySQL().forceConnection(); - } - catch (Exception e) { - e.printStackTrace(); - } - } - }, 11000, 11000); - - } - public void setTimout() { - runTask(new Runnable() { - @Override - public void run() { - try { - final PreparedStatement statement = connection.prepareStatement("SET GLOBAL wait_timeout =28800;"); - statement.executeUpdate(); - statement.close(); - } catch (final SQLException e) { - e.printStackTrace(); - Logger.add(LogLevel.DANGER, "Could not reset MySQL timout."); + //schedule reconnect + if (PlotMain.getMySQL() != null) { + Bukkit.getScheduler().scheduleSyncRepeatingTask(PlotMain.getMain(), new Runnable(){ + public void run(){ + try { + connection = PlotMain.getMySQL().forceConnection(); + } + catch (Exception e) { + e.printStackTrace(); + } } - } - }); + }, 11000, 11000); + } + } +// +// public void setTimout() { +// runTask(new Runnable() { +// @Override +// public void run() { +// try { +// final PreparedStatement statement = connection.prepareStatement("SET GLOBAL wait_timeout =28800;"); +// statement.executeQuery(); +// statement.close(); +// } catch (final SQLException e) { +// e.printStackTrace(); +// Logger.add(LogLevel.DANGER, "Could not reset MySQL timout."); +// } +// } +// }); +// } /** * Set Plot owner diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java index 9de09b499..1130fa27a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java @@ -325,6 +325,12 @@ public class UUIDHandler { uuidWrapper = new OfflineUUIDWrapper(); } } - return uuidWrapper.getUUID(player); + try { + return uuidWrapper.getUUID(player); + } + catch (Throwable e) { + uuidWrapper = new OfflineUUIDWrapper(); + return uuidWrapper.getUUID(player); + } } }