From 1a9f10951dd6cc6bf10238d034daf9b21b5e3895 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 25 Oct 2014 11:16:15 +1100 Subject: [PATCH] flag fixes. --- .../com/intellectualcrafters/plot/Plot.java | 2 +- .../plot/database/SQLManager.java | 46 ++++++++++++++++--- .../plot/listeners/PlotListener.java | 18 ++++++++ 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java index 1a0bf09d6..f4a5af227 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java @@ -65,7 +65,7 @@ public class Plot implements Cloneable { * Has the plot changed since the last save cycle? */ public boolean hasChanged = false; - public boolean countsTowardsMax = true; + public boolean countsTowardsMax = true ; /** * Primary constructor diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/SQLManager.java b/PlotSquared/src/com/intellectualcrafters/plot/database/SQLManager.java index 14b2e6f2b..04eeebe79 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/SQLManager.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/SQLManager.java @@ -22,6 +22,7 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; +import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.block.Biome; @@ -431,21 +432,28 @@ public class SQLManager extends AbstractDB { else { flags_string = ((String) settings.get("flags")).split(","); } - Flag[] flags = new Flag[flags_string.length]; - for (int i = 0; i < flags.length; i++) { + ArrayList flags = new ArrayList(); + boolean exception = false; + for (int i = 0; i < flags_string.length; i++) { if (flags_string[i].contains(":")) { String[] split = flags_string[i].split(":"); try { - flags[i] = new Flag(FlagManager.getFlag(split[0], true), split[1]); + flags.add(new Flag(FlagManager.getFlag(split[0], true), split[1])); } catch (Exception e) { + exception = true; // invalid flag... ignoring it for now. } } else { - flags[i] = new Flag(FlagManager.getFlag(flags_string[i], true), ""); + flags.add(new Flag(FlagManager.getFlag(flags_string[i], true), "")); } } + + if (exception) { + setFlags(worldname, id, flags.toArray(new Flag[0])); + } + ArrayList helpers = plotHelpers(id); ArrayList trusted = plotTrusted(id); ArrayList denied = plotDenied(id); @@ -473,8 +481,7 @@ public class SQLManager extends AbstractDB { for (int i = 0; i < 4; i++) { merged[3 - i] = (merged_int & (1 << i)) != 0; } - p = - new Plot(plot_id, owner, plotBiome, helpers, trusted, denied, alias, position, flags, worldname, merged); + p = new Plot(plot_id, owner, plotBiome, helpers, trusted, denied, alias, position, flags.toArray(new Flag[0]), worldname, merged); if (plots.containsKey(worldname)) { plots.get(worldname).put((plot_id), p); } @@ -561,6 +568,33 @@ public class SQLManager extends AbstractDB { } }); } + + public void setFlags(final String world, final int id, final Flag[] flags) { + ArrayList newflags = new ArrayList(); + for (Flag flag : flags) { + if (flag!=null && flag.getKey()!=null && !flag.getKey().equals("")) { + newflags.add(flag); + } + } + final String flag_string = StringUtils.join(newflags,","); + runTask(new Runnable() { + @Override + public void run() { + try { + PreparedStatement stmt = + connection.prepareStatement("UPDATE `plot_settings` SET `flags` = ? WHERE `plot_plot_id` = ?"); + stmt.setString(1, flag_string); + stmt.setInt(2, id); + stmt.execute(); + stmt.close(); + } + catch (SQLException e) { + e.printStackTrace(); + Logger.add(LogLevel.WARNING, "Could not set flag for plot " + id); + } + } + }); + } /** * @param plot diff --git a/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlotListener.java b/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlotListener.java index 65653e041..7b1b9f21b 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlotListener.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/listeners/PlotListener.java @@ -3,9 +3,12 @@ package com.intellectualcrafters.plot.listeners; import com.intellectualcrafters.plot.*; import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent; import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; + import org.bukkit.*; import org.bukkit.block.Biome; +import org.bukkit.block.Block; import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; import java.util.ArrayList; import java.util.Arrays; @@ -45,6 +48,21 @@ public class PlotListener { public static UUID getUUID(String name) { return UUIDHandler.getUUID(name); } + + // unused + public static void blockChange(Block block, Cancellable event) { + Location loc = block.getLocation(); + String world = loc.getWorld().getName(); + PlotManager manager = PlotMain.getPlotManager(world); + if (manager!=null) { + PlotWorld plotworld = PlotMain.getWorldSettings(world); + PlotId id = manager.getPlotId(plotworld, loc); + if (id==null) { + event.setCancelled(true); + } + } + return; + } public static boolean enteredPlot(Location l1, Location l2) { PlotId p1 = PlayerFunctions.getPlot(new Location(l1.getWorld(), l1.getBlockX(), 64, l1.getBlockZ()));