From ccd237d2c0e35d0ad0a6b07690d4b8c3dcf44958 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 23 Sep 2014 12:08:31 +1000 Subject: [PATCH] Added plot flags to API - Old database will break yet again (yay!) (Once we get more people using the plugin I'll have it add the missing columns) --- .../src/com/intellectualcrafters/plot/C.java | 13 ++- .../com/intellectualcrafters/plot/Flag.java | 44 +++++++++ .../plot/PlayerFunctions.java | 2 +- .../com/intellectualcrafters/plot/Plot.java | 8 +- .../intellectualcrafters/plot/PlotMain.java | 88 ++++++++++++++++- .../plot/PlotSettings.java | 56 ++++++++++- .../plot/api/PlotAPI.java | 15 ++- .../plot/commands/Clear.java | 11 ++- .../plot/commands/Info.java | 3 + .../plot/commands/Set.java | 62 +++++++++++- .../plot/database/DBFunc.java | 97 ++++++++++++++----- .../plot/database/PlotMeConverter.java | 1 + .../plot/events/PlayerClaimPlotEvent.java | 6 +- .../plot/events/PlotDeleteEvent.java | 61 ++++++++++++ .../plot/events/PlotFlagAddEvent.java | 60 ++++++++++++ .../plot/events/PlotFlagRemoveEvent.java | 60 ++++++++++++ 16 files changed, 543 insertions(+), 44 deletions(-) create mode 100644 PlotSquared/src/com/intellectualcrafters/plot/Flag.java create mode 100644 PlotSquared/src/com/intellectualcrafters/plot/events/PlotDeleteEvent.java create mode 100644 PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java create mode 100644 PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java diff --git a/PlotSquared/src/com/intellectualcrafters/plot/C.java b/PlotSquared/src/com/intellectualcrafters/plot/C.java index 8d97ae7cd..a713e97db 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/C.java @@ -137,7 +137,7 @@ public enum C { Info */ PLOT_INFO_UNCLAIMED("&cPlot &6%s&c is not yet claimed"), - PLOT_INFO("plot ID: &6%id%&c, plot Alias: &6%alias%&c, plot Owner: &6%owner%&c, plot Biome: &6%biome%&c, plot Time: &6%time%&c, plot Weather: &6%weather%&c, plot Helpers:&6%helpers%&c, plot Denied:&6%denied%&c"), + PLOT_INFO("plot ID: &6%id%&c, plot Alias: &6%alias%&c, plot Owner: &6%owner%&c, plot Biome: &6%biome%&c, plot Time: &6%time%&c, plot Weather: &6%weather%&c, plot Helpers:&6%helpers%&c, plot Denied:&6%denied%&c, plot flags: &6%flags%"), PLOT_USER_LIST(" &6%user%&c,"), /* Generating @@ -186,6 +186,17 @@ public enum C { */ NEED_ON_OFF("&cYou need to specify a value. Possible values: &6on&c, &6off"), SETTING_UPDATED("&cYou successfully updated the setting"), + /* + * Flag + */ + NEED_KEY("&cYou need to specify a flag"), + NOT_VALID_FLAG("&cThat is not a valid flag"), + NOT_VALID_VALUE("&cFlag values must be alphanumerical"), + FLAG_NOT_IN_PLOT("&cThe plot does not have that flag"), + FLAG_NOT_REMOVED("&cThe flag could not be removed"), + FLAG_NOT_ADDED("&cThe flag could not be added"), + FLAG_REMOVED("&6Successfully removed flag"), + FLAG_ADDED("&6Successfully added flag"), /* Helper */ diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Flag.java b/PlotSquared/src/com/intellectualcrafters/plot/Flag.java new file mode 100644 index 000000000..f7edd01fc --- /dev/null +++ b/PlotSquared/src/com/intellectualcrafters/plot/Flag.java @@ -0,0 +1,44 @@ +package com.intellectualcrafters.plot; + +import org.apache.commons.lang.StringUtils; +import org.bukkit.ChatColor; + +public class Flag { + private String key; + private String value; + public Flag(String key, String value) { + if (!StringUtils.isAlphanumeric(key) || !StringUtils.isAlphanumeric(ChatColor.stripColor(value))) + throw new IllegalArgumentException("Flag must be alphanumerical"); + if (key.length()>16) + throw new IllegalArgumentException("Key must be <= 16 characters"); + if (value.length()>48) + throw new IllegalArgumentException("Value must be <= 48 characters"); + this.key = key.toLowerCase(); + this.value = value; + } + public String getKey() { + return this.key; + } + public String getValue() { + return this.value; + } + @Override + public String toString() { + return this.key+":"+this.value; + } + @Override + public boolean equals(Object obj){ + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Flag other = (Flag) obj; + return (this.key==other.key); + } + @Override + public int hashCode() { + return key.hashCode(); + } +} diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java index 5d439dbee..013e074c1 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java @@ -41,7 +41,7 @@ public class PlayerFunctions { OfflinePlayer player = Bukkit.getOfflinePlayer(plot.owner); long lp = player.getLastPlayed(); long cu = System.currentTimeMillis(); - return (lp - cu) > 30l; + return (lp - cu) > 30l; } /** diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java index a13a8e96f..a6cdfc8fe 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Plot.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Plot.java @@ -17,6 +17,7 @@ import org.bukkit.block.Biome; import org.bukkit.entity.Player; import java.util.ArrayList; +import java.util.Set; import java.util.UUID; /** @@ -86,6 +87,7 @@ public class Plot implements Cloneable{ this.settings.setAlias(""); this.settings.setPosition(PlotHomePosition.DEFAULT); this.delete = false; + this.settings.setFlags(new Flag[0]); this.world = world; } @@ -99,7 +101,7 @@ public class Plot implements Cloneable{ * @param changeTime * @param time */ - public Plot(PlotId id, UUID owner, Biome plotBiome, ArrayList helpers, ArrayList denied, boolean changeTime, long time, boolean rain, String alias, PlotHomePosition position, String world) { + public Plot(PlotId id, UUID owner, Biome plotBiome, ArrayList helpers, ArrayList denied, boolean changeTime, long time, boolean rain, String alias, PlotHomePosition position, Flag[] flags, String world) { this.id = id; this.settings = new PlotSettings(this); this.settings.setBiome(plotBiome); @@ -113,6 +115,10 @@ public class Plot implements Cloneable{ this.settings.setAlias(alias); this.settings.setPosition(position); this.delete = false; + if (flags!=null) + this.settings.setFlags(flags); + else + this.settings.setFlags(new Flag[0]); this.world = world; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index 7cc51bb9e..b15fa1517 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -10,6 +10,7 @@ package com.intellectualcrafters.plot; import ca.mera.CameraAPI; + import com.intellectualcrafters.plot.Logger.LogLevel; import com.intellectualcrafters.plot.Settings.Web; import com.intellectualcrafters.plot.commands.Camera; @@ -18,10 +19,13 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.MySQL; import com.intellectualcrafters.plot.database.PlotMeConverter; import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent; +import com.intellectualcrafters.plot.events.PlotDeleteEvent; import com.intellectualcrafters.plot.listeners.PlayerEvents; import com.intellectualcrafters.plot.listeners.WorldEditListener; import com.sk89q.worldedit.bukkit.WorldEditPlugin; + import me.confuser.barapi.BarAPI; + import org.bukkit.*; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Entity; @@ -66,6 +70,10 @@ public class PlotMain extends JavaPlugin { public static File translationsFile; public static YamlConfiguration translations; public static int translations_ver = 1; + /** + * list of usable flags + */ + public static Set registeredFlags = new HashSet(); /** * MySQL Object */ @@ -120,6 +128,22 @@ public class PlotMain extends JavaPlugin { */ private static HashMap worlds = new HashMap(); + public static Set getFlags() { + return registeredFlags; + } + + public static boolean isRegisteredFlag(String arg) { + for (Flag flag:registeredFlags) { + if (flag.getKey().equalsIgnoreCase(arg)) + return true; + } + return false; + } + + public static boolean registerFlag(Flag flag) { + return registeredFlags.add(flag); + } + /** * Get all plots * @@ -132,7 +156,11 @@ public class PlotMain extends JavaPlugin { } return new HashSet(myplots); } - + /** + * + * @param player + * @return + */ public static Set getPlots(Player player) { UUID uuid = player.getUniqueId(); ArrayList myplots = new ArrayList(); @@ -145,6 +173,12 @@ public class PlotMain extends JavaPlugin { } return new HashSet(myplots); } + /** + * + * @param world + * @param player + * @return + */ public static Set getPlots(World world, Player player) { UUID uuid = player.getUniqueId(); ArrayList myplots = new ArrayList(); @@ -155,7 +189,11 @@ public class PlotMain extends JavaPlugin { } return new HashSet(myplots); } - + /** + * + * @param world + * @return + */ public static HashMap getPlots(World world) { if (plots.containsKey(world.getName())) { return plots.get(world.getName()); @@ -168,17 +206,36 @@ public class PlotMain extends JavaPlugin { public static String[] getPlotWorlds() { return (worlds.keySet().toArray(new String[0])); } + /** + * + * @return + */ public static String[] getPlotWorldsString() { return plots.keySet().toArray(new String[0]); } + /** + * + * @param world + * @return + */ public static boolean isPlotWorld(World world) { return (worlds.containsKey(world.getName())); } + /** + * + * @param world + * @return + */ public static PlotWorld getWorldSettings(World world) { if (worlds.containsKey(world.getName())) return worlds.get(world.getName()); return null; } + /** + * + * @param world + * @return + */ public static PlotWorld getWorldSettings(String world) { if (worlds.containsKey(world)) return worlds.get(world); @@ -193,8 +250,15 @@ public class PlotMain extends JavaPlugin { return (Plot[])(plots.get(world.getName()).values().toArray(new Plot[0])); } - public static void removePlot(String world, PlotId id) { + public static boolean removePlot(String world, PlotId id) { + PlotDeleteEvent event = new PlotDeleteEvent(world,id); + Bukkit.getServer().getPluginManager().callEvent(event); + if(!event.isCancelled()) { + event.setCancelled(true); + return false; + } plots.get(world).remove(id); + return true; } /** * Replace the plot object with an updated version @@ -228,7 +292,14 @@ public class PlotMain extends JavaPlugin { continue; } if (PlayerFunctions.hasExpired(plot)) { - DBFunc.delete(world, plot); + PlotDeleteEvent event = new PlotDeleteEvent(world,plot.id); + Bukkit.getServer().getPluginManager().callEvent(event); + if(!event.isCancelled()) { + event.setCancelled(true); + } + else { + DBFunc.delete(world, plot); + } } } } @@ -240,7 +311,14 @@ public class PlotMain extends JavaPlugin { if (PlotMain.plots.containsKey(world)) { for (Plot plot : PlotMain.plots.get(world).values()) { if (PlayerFunctions.hasExpired(plot)) { - DBFunc.delete(world, plot); + PlotDeleteEvent event = new PlotDeleteEvent(world,plot.id); + Bukkit.getServer().getPluginManager().callEvent(event); + if(!event.isCancelled()) { + event.setCancelled(true); + } + else { + DBFunc.delete(world, plot); + } } } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java index 618528412..f44c27c8f 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotSettings.java @@ -9,6 +9,11 @@ package com.intellectualcrafters.plot; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; import org.bukkit.block.Biome; /** @@ -32,6 +37,10 @@ public class PlotSettings { * plot rain */ private boolean rain; + /** + * + */ + private Set flags; /** * plot time */ @@ -112,12 +121,55 @@ public class PlotSettings { } /** - * + * + * @param alias */ public void setAlias(String alias) { this.alias = alias; } - + + /** + * + * @param flag + */ + public void addFlag(Flag flag) { + this.flags.add(flag); + } + /** + * + * @param flags + */ + public void setFlags(Flag[] flags) { + this.flags = new HashSet(Arrays.asList(flags)); + } + /** + * + * @return + */ + public Set getFlags() { + return this.flags; + } + /** + * + * @param flag + * @return + */ + public Flag getFlag(String flag) { + for (Flag myflag:flags) { + if (myflag.getKey()==flag) + return myflag; + } + return null; + } + /** + * + * @param flag + * @return + */ + public boolean hasFlag(Flag flag) { + return this.flags.contains(flag); + } + public PlotHomePosition getPosition() { return this.position; } public void setPosition(PlotHomePosition position) { this.position = position; } public String getAlias() { return this.alias; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/api/PlotAPI.java b/PlotSquared/src/com/intellectualcrafters/plot/api/PlotAPI.java index 3d40c51ec..61cf1c538 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/api/PlotAPI.java @@ -82,7 +82,20 @@ public class PlotAPI { public void sendConsoleMessage(C c) { sendConsoleMessage(c.s()); } - + /** + * Register a flag for use in plots + * @param flag + */ + public void registerFlag(Flag flag) { + PlotMain.registerFlag(flag); + } + /** + * get all the currently registered flags + * @return array of Flag[] + */ + public Flag[] getRegisteredFlags() { + return PlotMain.getFlags().toArray(new Flag[0]); + } /** * Get a plot based on the ID * @param id diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java index f296ad252..285e7f8aa 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java @@ -30,9 +30,14 @@ public class Clear extends SubCommand { return true; } Plot plot = PlayerFunctions.getCurrentPlot(plr); - DBFunc.delete(plr.getWorld().getName(), plot); - PlotMain.removePlot(plr.getWorld().getName(), plot.id); - plot.clear(plr); + boolean result = PlotMain.removePlot(plr.getWorld().getName(), plot.id); + if (result) { + DBFunc.delete(plr.getWorld().getName(), plot); + plot.clear(plr); + } + else { + PlayerFunctions.sendMessage(plr, "Plot clearing has been denied."); + } return true; } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java index 8153fc88c..f57539b7c 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Info.java @@ -11,6 +11,8 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.*; import com.intellectualcrafters.plot.database.DBFunc; + +import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.OfflinePlayer; @@ -76,6 +78,7 @@ public class Info extends SubCommand{ info = info.replaceAll("%weather%", plot.settings.getRain() ? "rain" : "default"); info = info.replaceAll("%helpers%", getPlayerList(plot.helpers)); info = info.replaceAll("%denied%", getPlayerList(plot.denied)); + info = info.replaceAll("%flags%", StringUtils.join(plot.settings.getFlags(),"").length() > 0 ? StringUtils.join(plot.settings.getFlags(),"") : "none"); PlayerFunctions.sendMessage(player, info); return true; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java index 0cf115670..3e1117009 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Set.java @@ -11,6 +11,11 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.*; import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.events.PlotDeleteEvent; +import com.intellectualcrafters.plot.events.PlotFlagAddEvent; +import com.intellectualcrafters.plot.events.PlotFlagRemoveEvent; + +import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -34,10 +39,10 @@ public class Set extends SubCommand{ } public static String[] values = new String[] { - "biome", "wall", "wall_filling", "floor", "alias", "home", "rain" + "biome", "wall", "wall_filling", "floor", "alias", "home", "rain", "flag" }; public static String[] aliases = new String[] { - "b", "w", "wf", "f", "a", "h", "r" + "b", "w", "wf", "f", "a", "h", "r", "fl" }; @SuppressWarnings("deprecation") @@ -76,7 +81,58 @@ public class Set extends SubCommand{ return false; } } - + + if(args[0].equalsIgnoreCase("flag")) { + if(args.length < 2) { + PlayerFunctions.sendMessage(plr, C.NEED_KEY); + return false; + } + if (!PlotMain.isRegisteredFlag(args[1])) { + PlayerFunctions.sendMessage(plr, C.NOT_VALID_FLAG); + return false; + } + if (!plr.hasPermission("plots.set.flag" + args[1].toLowerCase())) { + PlayerFunctions.sendMessage(plr, C.NO_PERMISSION); + return false; + } + if (args.length==2) { + if (!plot.settings.hasFlag(new Flag(args[1], ""))) { + PlayerFunctions.sendMessage(plr, C.FLAG_NOT_IN_PLOT); + return false; + } + Flag flag = plot.settings.getFlag(args[1].toLowerCase()); + PlotFlagRemoveEvent event = new PlotFlagRemoveEvent(flag,plot); + Bukkit.getServer().getPluginManager().callEvent(event); + if(!event.isCancelled()) { + PlayerFunctions.sendMessage(plr, C.FLAG_NOT_REMOVED); + event.setCancelled(true); + return false; + } + java.util.Set newflags = plot.settings.getFlags(); + newflags.remove(flag); + plot.settings.setFlags(newflags.toArray(new Flag[0])); + PlayerFunctions.sendMessage(plr, C.FLAG_REMOVED); + return true; + } + try { + String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length)," "); + Flag flag = new Flag(args[1], value); + PlotFlagAddEvent event = new PlotFlagAddEvent(flag,plot); + Bukkit.getServer().getPluginManager().callEvent(event); + if(!event.isCancelled()) { + PlayerFunctions.sendMessage(plr, C.FLAG_NOT_ADDED); + event.setCancelled(true); + return false; + } + plot.settings.addFlag(flag); + PlayerFunctions.sendMessage(plr, C.FLAG_ADDED); + return true; + } + catch (Exception e) { + PlayerFunctions.sendMessage(plr, "&c"+e.getMessage()); + return false; + } + } if(args[0].equalsIgnoreCase("rain")) { if(args.length < 2) { PlayerFunctions.sendMessage(plr, C.NEED_ON_OFF); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java index 42e96fda2..5301d90f3 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java @@ -8,6 +8,7 @@ */ package com.intellectualcrafters.plot.database; +import com.intellectualcrafters.plot.Flag; import com.intellectualcrafters.plot.Logger; import com.intellectualcrafters.plot.Logger.LogLevel; import com.intellectualcrafters.plot.Plot; @@ -15,6 +16,7 @@ import com.intellectualcrafters.plot.PlotHomePosition; import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotMain; +import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.World; @@ -118,6 +120,7 @@ public class DBFunc { " `time` INT(11) DEFAULT '8000'," + " `deny_entry` TINYINT(1) DEFAULT '0'," + " `alias` VARCHAR(50) DEFAULT NULL," + + " `flags` VARCHAR(512) DEFAULT NULL," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " PRIMARY KEY (`plot_plot_id`)," + " UNIQUE KEY `unique_alias` (`alias`)" + @@ -136,31 +139,33 @@ public class DBFunc { * @param plot */ public static void delete(final String world, final Plot plot) { - PlotMain.removePlot(world,plot.id); - runTask(new Runnable() { - @Override - public void run() { - PreparedStatement stmt = null; - int id = getId(world,plot.id); - try { - stmt = connection.prepareStatement("DELETE FROM `plot_settings` WHERE `plot_plot_id` = ?"); - stmt.setInt(1, id); - stmt.executeUpdate(); - stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `plot_helpers` WHERE `plot_plot_id` = ?"); - stmt.setInt(1, id); - stmt.executeUpdate(); - stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `plot` WHERE `id` = ?"); - stmt.setInt(1, id); - stmt.executeUpdate(); - stmt.close(); - } catch (SQLException e) { - e.printStackTrace(); - Logger.add(LogLevel.DANGER, "Failed to delete plot " + plot.id); + boolean result = PlotMain.removePlot(world,plot.id); + if (result) { + runTask(new Runnable() { + @Override + public void run() { + PreparedStatement stmt = null; + int id = getId(world,plot.id); + try { + stmt = connection.prepareStatement("DELETE FROM `plot_settings` WHERE `plot_plot_id` = ?"); + stmt.setInt(1, id); + stmt.executeUpdate(); + stmt.close(); + stmt = connection.prepareStatement("DELETE FROM `plot_helpers` WHERE `plot_plot_id` = ?"); + stmt.setInt(1, id); + stmt.executeUpdate(); + stmt.close(); + stmt = connection.prepareStatement("DELETE FROM `plot` WHERE `id` = ?"); + stmt.setInt(1, id); + stmt.executeUpdate(); + stmt.close(); + } catch (SQLException e) { + e.printStackTrace(); + Logger.add(LogLevel.DANGER, "Failed to delete plot " + plot.id); + } } - } - }); + }); + } } /** @@ -233,6 +238,17 @@ public class DBFunc { UUID owner = UUID.fromString(r.getString("owner")); Biome plotBiome = Biome.valueOf((String) settings.get("biome")); if(plotBiome == null) plotBiome = Biome.FOREST; + String[] flags_string; + if (settings.get("flags") == null) + flags_string = new String[] {}; + else + flags_string = ((String) settings.get("flags")).split(","); + Flag[] flags = new Flag[flags_string.length]; + for (int i = 0; i helpers = plotHelpers(id); ArrayList denied = plotDenied(id); //boolean changeTime = ((Short) settings.get("custom_time") == 0) ? false : true; @@ -249,7 +265,7 @@ public class DBFunc { if(plotHomePosition.isMatching((String)settings.get("position"))) position = plotHomePosition; if(position == null) position = PlotHomePosition.DEFAULT; - p = new Plot(plot_id, owner, plotBiome, helpers, denied, /*changeTime*/ false, time, rain, alias, position, worldname); + p = new Plot(plot_id, owner, plotBiome, helpers, denied, /*changeTime*/ false, time, rain, alias, position, flags, worldname); if (plots.containsKey(worldname)) { plots.get(worldname).put((plot_id), p); } @@ -272,7 +288,7 @@ public class DBFunc { * @param plot * @param rain */ - public static void setWeather(final String world, final Plot plot, final boolean rain) { + public static void setWeather(final String world, final Plot plot, final boolean rain) { plot.settings.setRain(rain); runTask(new Runnable() { @Override @@ -291,6 +307,32 @@ public class DBFunc { } }); } + public static void setFlags(final String world, final Plot plot, final Flag[] flags) { + plot.settings.setFlags(flags); + final StringBuilder flag_string = new StringBuilder(); + int i = 0; + for (Flag flag:flags) { + if (i!=0) + flag_string.append(","); + flag_string.append(flag.getKey()+":"+flag.getValue()); + i++; + } + 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.toString()); + stmt.setInt(2, getId(world, plot.id)); + stmt.execute(); + stmt.close(); + } catch(SQLException e) { + e.printStackTrace(); + Logger.add(LogLevel.WARNING, "Could not set weather for plot " + plot.id); + } + } + }); + } /** * @@ -386,6 +428,9 @@ public class DBFunc { var = "position"; val = r.getObject(var); h.put(var, val); + var = "flags"; + val = r.getObject(var); + h.put(var, val); } stmt.close();; } catch(SQLException e) { diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/PlotMeConverter.java b/PlotSquared/src/com/intellectualcrafters/plot/database/PlotMeConverter.java index cc8ce27df..d162e85d0 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/PlotMeConverter.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/PlotMeConverter.java @@ -87,6 +87,7 @@ public class PlotMeConverter { false, "", PlotHomePosition.DEFAULT, + null, world.getName() ); DBFunc.createPlot(pl); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java index 0b1384b3a..286bd82fb 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlayerClaimPlotEvent.java @@ -28,7 +28,11 @@ public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable{ super(player); this.plot = plot; } - + + public Plot getPlot() { + return this.plot; + } + public static HandlerList getHandlerList() { return handlers; } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotDeleteEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotDeleteEvent.java new file mode 100644 index 000000000..aeb1a0399 --- /dev/null +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotDeleteEvent.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) IntellectualCrafters - 2014. + * You are not allowed to distribute and/or monetize any of our intellectual property. + * IntellectualCrafters is not affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. + * + * >> File = PlayerClaimPlotEvent.java + * >> Generated by: Citymonstret at 2014-08-09 15:21 + */ + +package com.intellectualcrafters.plot.events; + +import com.intellectualcrafters.plot.Plot; +import com.intellectualcrafters.plot.PlotId; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +/** + * Created by Citymonstret on 2014-08-09. + */ +public class PlotDeleteEvent extends Event implements Cancellable{ + private static HandlerList handlers = new HandlerList(); + private boolean cancelled; + + private PlotId id; + private String world; + + public PlotDeleteEvent(String world, PlotId id) { + this.id = id; + this.world = world; + } + + public PlotId getPlotId() { + return this.id; + } + + public String getWorld() { + return this.world; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public HandlerList getHandlers() { + return handlers; + } + + @Override + public boolean isCancelled() { + return this.cancelled; + } + + @Override + public void setCancelled(boolean b) { + this.cancelled = b; + } +} diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java new file mode 100644 index 000000000..7db77f504 --- /dev/null +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagAddEvent.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) IntellectualCrafters - 2014. + * You are not allowed to distribute and/or monetize any of our intellectual property. + * IntellectualCrafters is not affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. + * + * >> File = PlayerClaimPlotEvent.java + * >> Generated by: Citymonstret at 2014-08-09 15:21 + */ + +package com.intellectualcrafters.plot.events; + +import com.intellectualcrafters.plot.Flag; +import com.intellectualcrafters.plot.Plot; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * Created by Citymonstret on 2014-08-09. + */ +public class PlotFlagAddEvent extends Event implements Cancellable{ + private static HandlerList handlers = new HandlerList(); + private boolean cancelled; + + private Plot plot; + private Flag flag; + + public PlotFlagAddEvent(Flag flag, Plot plot) { + this.plot = plot; + this.flag = flag; + } + + public Plot getPlot() { + return this.plot; + } + + public Flag getFlag() { + return this.flag; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public HandlerList getHandlers() { + return handlers; + } + + @Override + public boolean isCancelled() { + return this.cancelled; + } + + @Override + public void setCancelled(boolean b) { + this.cancelled = b; + } +} diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java new file mode 100644 index 000000000..1afbcdd07 --- /dev/null +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotFlagRemoveEvent.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) IntellectualCrafters - 2014. + * You are not allowed to distribute and/or monetize any of our intellectual property. + * IntellectualCrafters is not affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. + * + * >> File = PlayerClaimPlotEvent.java + * >> Generated by: Citymonstret at 2014-08-09 15:21 + */ + +package com.intellectualcrafters.plot.events; + +import com.intellectualcrafters.plot.Flag; +import com.intellectualcrafters.plot.Plot; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * Created by Citymonstret on 2014-08-09. + */ +public class PlotFlagRemoveEvent extends Event implements Cancellable{ + private static HandlerList handlers = new HandlerList(); + private boolean cancelled; + + private Plot plot; + private Flag flag; + + public PlotFlagRemoveEvent(Flag flag, Plot plot) { + this.plot = plot; + this.flag = flag; + } + + public Plot getPlot() { + return this.plot; + } + + public Flag getFlag() { + return this.flag; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + public HandlerList getHandlers() { + return handlers; + } + + @Override + public boolean isCancelled() { + return this.cancelled; + } + + @Override + public void setCancelled(boolean b) { + this.cancelled = b; + } +}