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)
This commit is contained in:
boy0001 2014-09-23 12:08:31 +10:00
parent e4e9b80c02
commit ccd237d2c0
16 changed files with 543 additions and 44 deletions

View File

@ -137,7 +137,7 @@ public enum C {
Info Info
*/ */
PLOT_INFO_UNCLAIMED("&cPlot &6%s&c is not yet claimed"), 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,"), PLOT_USER_LIST(" &6%user%&c,"),
/* /*
Generating Generating
@ -186,6 +186,17 @@ public enum C {
*/ */
NEED_ON_OFF("&cYou need to specify a value. Possible values: &6on&c, &6off"), NEED_ON_OFF("&cYou need to specify a value. Possible values: &6on&c, &6off"),
SETTING_UPDATED("&cYou successfully updated the setting"), 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 Helper
*/ */

View File

@ -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();
}
}

View File

@ -41,7 +41,7 @@ public class PlayerFunctions {
OfflinePlayer player = Bukkit.getOfflinePlayer(plot.owner); OfflinePlayer player = Bukkit.getOfflinePlayer(plot.owner);
long lp = player.getLastPlayed(); long lp = player.getLastPlayed();
long cu = System.currentTimeMillis(); long cu = System.currentTimeMillis();
return (lp - cu) > 30l; return (lp - cu) > 30l;
} }
/** /**

View File

@ -17,6 +17,7 @@ import org.bukkit.block.Biome;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
/** /**
@ -86,6 +87,7 @@ public class Plot implements Cloneable{
this.settings.setAlias(""); this.settings.setAlias("");
this.settings.setPosition(PlotHomePosition.DEFAULT); this.settings.setPosition(PlotHomePosition.DEFAULT);
this.delete = false; this.delete = false;
this.settings.setFlags(new Flag[0]);
this.world = world; this.world = world;
} }
@ -99,7 +101,7 @@ public class Plot implements Cloneable{
* @param changeTime * @param changeTime
* @param time * @param time
*/ */
public Plot(PlotId id, UUID owner, Biome plotBiome, ArrayList<UUID> helpers, ArrayList<UUID> denied, boolean changeTime, long time, boolean rain, String alias, PlotHomePosition position, String world) { public Plot(PlotId id, UUID owner, Biome plotBiome, ArrayList<UUID> helpers, ArrayList<UUID> denied, boolean changeTime, long time, boolean rain, String alias, PlotHomePosition position, Flag[] flags, String world) {
this.id = id; this.id = id;
this.settings = new PlotSettings(this); this.settings = new PlotSettings(this);
this.settings.setBiome(plotBiome); this.settings.setBiome(plotBiome);
@ -113,6 +115,10 @@ public class Plot implements Cloneable{
this.settings.setAlias(alias); this.settings.setAlias(alias);
this.settings.setPosition(position); this.settings.setPosition(position);
this.delete = false; this.delete = false;
if (flags!=null)
this.settings.setFlags(flags);
else
this.settings.setFlags(new Flag[0]);
this.world = world; this.world = world;
} }

View File

@ -10,6 +10,7 @@
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import ca.mera.CameraAPI; import ca.mera.CameraAPI;
import com.intellectualcrafters.plot.Logger.LogLevel; import com.intellectualcrafters.plot.Logger.LogLevel;
import com.intellectualcrafters.plot.Settings.Web; import com.intellectualcrafters.plot.Settings.Web;
import com.intellectualcrafters.plot.commands.Camera; 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.MySQL;
import com.intellectualcrafters.plot.database.PlotMeConverter; import com.intellectualcrafters.plot.database.PlotMeConverter;
import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent; import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent;
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
import com.intellectualcrafters.plot.listeners.PlayerEvents; import com.intellectualcrafters.plot.listeners.PlayerEvents;
import com.intellectualcrafters.plot.listeners.WorldEditListener; import com.intellectualcrafters.plot.listeners.WorldEditListener;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import me.confuser.barapi.BarAPI; import me.confuser.barapi.BarAPI;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -66,6 +70,10 @@ public class PlotMain extends JavaPlugin {
public static File translationsFile; public static File translationsFile;
public static YamlConfiguration translations; public static YamlConfiguration translations;
public static int translations_ver = 1; public static int translations_ver = 1;
/**
* list of usable flags
*/
public static Set<Flag> registeredFlags = new HashSet<Flag>();
/** /**
* MySQL Object * MySQL Object
*/ */
@ -120,6 +128,22 @@ public class PlotMain extends JavaPlugin {
*/ */
private static HashMap<String, PlotWorld> worlds = new HashMap<String, PlotWorld>(); private static HashMap<String, PlotWorld> worlds = new HashMap<String, PlotWorld>();
public static Set<Flag> 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 * Get all plots
* *
@ -132,7 +156,11 @@ public class PlotMain extends JavaPlugin {
} }
return new HashSet<Plot>(myplots); return new HashSet<Plot>(myplots);
} }
/**
*
* @param player
* @return
*/
public static Set<Plot> getPlots(Player player) { public static Set<Plot> getPlots(Player player) {
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
ArrayList<Plot> myplots = new ArrayList<Plot>(); ArrayList<Plot> myplots = new ArrayList<Plot>();
@ -145,6 +173,12 @@ public class PlotMain extends JavaPlugin {
} }
return new HashSet<Plot>(myplots); return new HashSet<Plot>(myplots);
} }
/**
*
* @param world
* @param player
* @return
*/
public static Set<Plot> getPlots(World world, Player player) { public static Set<Plot> getPlots(World world, Player player) {
UUID uuid = player.getUniqueId(); UUID uuid = player.getUniqueId();
ArrayList<Plot> myplots = new ArrayList<Plot>(); ArrayList<Plot> myplots = new ArrayList<Plot>();
@ -155,7 +189,11 @@ public class PlotMain extends JavaPlugin {
} }
return new HashSet<Plot>(myplots); return new HashSet<Plot>(myplots);
} }
/**
*
* @param world
* @return
*/
public static HashMap<PlotId, Plot> getPlots(World world) { public static HashMap<PlotId, Plot> getPlots(World world) {
if (plots.containsKey(world.getName())) { if (plots.containsKey(world.getName())) {
return plots.get(world.getName()); return plots.get(world.getName());
@ -168,17 +206,36 @@ public class PlotMain extends JavaPlugin {
public static String[] getPlotWorlds() { public static String[] getPlotWorlds() {
return (worlds.keySet().toArray(new String[0])); return (worlds.keySet().toArray(new String[0]));
} }
/**
*
* @return
*/
public static String[] getPlotWorldsString() { public static String[] getPlotWorldsString() {
return plots.keySet().toArray(new String[0]); return plots.keySet().toArray(new String[0]);
} }
/**
*
* @param world
* @return
*/
public static boolean isPlotWorld(World world) { public static boolean isPlotWorld(World world) {
return (worlds.containsKey(world.getName())); return (worlds.containsKey(world.getName()));
} }
/**
*
* @param world
* @return
*/
public static PlotWorld getWorldSettings(World world) { public static PlotWorld getWorldSettings(World world) {
if (worlds.containsKey(world.getName())) if (worlds.containsKey(world.getName()))
return worlds.get(world.getName()); return worlds.get(world.getName());
return null; return null;
} }
/**
*
* @param world
* @return
*/
public static PlotWorld getWorldSettings(String world) { public static PlotWorld getWorldSettings(String world) {
if (worlds.containsKey(world)) if (worlds.containsKey(world))
return worlds.get(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])); 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); plots.get(world).remove(id);
return true;
} }
/** /**
* Replace the plot object with an updated version * Replace the plot object with an updated version
@ -228,7 +292,14 @@ public class PlotMain extends JavaPlugin {
continue; continue;
} }
if (PlayerFunctions.hasExpired(plot)) { 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)) { if (PlotMain.plots.containsKey(world)) {
for (Plot plot : PlotMain.plots.get(world).values()) { for (Plot plot : PlotMain.plots.get(world).values()) {
if (PlayerFunctions.hasExpired(plot)) { 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);
}
} }
} }
} }

View File

@ -9,6 +9,11 @@
package com.intellectualcrafters.plot; 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; import org.bukkit.block.Biome;
/** /**
@ -32,6 +37,10 @@ public class PlotSettings {
* plot rain * plot rain
*/ */
private boolean rain; private boolean rain;
/**
*
*/
private Set<Flag> flags;
/** /**
* plot time * plot time
*/ */
@ -112,12 +121,55 @@ public class PlotSettings {
} }
/** /**
* *
* @param alias
*/ */
public void setAlias(String alias) { public void setAlias(String alias) {
this.alias = 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<Flag>(Arrays.asList(flags));
}
/**
*
* @return
*/
public Set<Flag> 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 PlotHomePosition getPosition() { return this.position; }
public void setPosition(PlotHomePosition position) { this.position = position; } public void setPosition(PlotHomePosition position) { this.position = position; }
public String getAlias() { return this.alias; } public String getAlias() { return this.alias; }

View File

@ -82,7 +82,20 @@ public class PlotAPI {
public void sendConsoleMessage(C c) { public void sendConsoleMessage(C c) {
sendConsoleMessage(c.s()); 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 * Get a plot based on the ID
* @param id * @param id

View File

@ -30,9 +30,14 @@ public class Clear extends SubCommand {
return true; return true;
} }
Plot plot = PlayerFunctions.getCurrentPlot(plr); Plot plot = PlayerFunctions.getCurrentPlot(plr);
DBFunc.delete(plr.getWorld().getName(), plot); boolean result = PlotMain.removePlot(plr.getWorld().getName(), plot.id);
PlotMain.removePlot(plr.getWorld().getName(), plot.id); if (result) {
plot.clear(plr); DBFunc.delete(plr.getWorld().getName(), plot);
plot.clear(plr);
}
else {
PlayerFunctions.sendMessage(plr, "Plot clearing has been denied.");
}
return true; return true;
} }
} }

View File

@ -11,6 +11,8 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*; import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.OfflinePlayer; 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("%weather%", plot.settings.getRain() ? "rain" : "default");
info = info.replaceAll("%helpers%", getPlayerList(plot.helpers)); info = info.replaceAll("%helpers%", getPlayerList(plot.helpers));
info = info.replaceAll("%denied%", getPlayerList(plot.denied)); 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); PlayerFunctions.sendMessage(player, info);
return true; return true;
} }

View File

@ -11,6 +11,11 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.*; import com.intellectualcrafters.plot.*;
import com.intellectualcrafters.plot.database.DBFunc; 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.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -34,10 +39,10 @@ public class Set extends SubCommand{
} }
public static String[] values = new String[] { 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[] { public static String[] aliases = new String[] {
"b", "w", "wf", "f", "a", "h", "r" "b", "w", "wf", "f", "a", "h", "r", "fl"
}; };
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -76,7 +81,58 @@ public class Set extends SubCommand{
return false; 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<Flag> 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[0].equalsIgnoreCase("rain")) {
if(args.length < 2) { if(args.length < 2) {
PlayerFunctions.sendMessage(plr, C.NEED_ON_OFF); PlayerFunctions.sendMessage(plr, C.NEED_ON_OFF);

View File

@ -8,6 +8,7 @@
*/ */
package com.intellectualcrafters.plot.database; package com.intellectualcrafters.plot.database;
import com.intellectualcrafters.plot.Flag;
import com.intellectualcrafters.plot.Logger; import com.intellectualcrafters.plot.Logger;
import com.intellectualcrafters.plot.Logger.LogLevel; import com.intellectualcrafters.plot.Logger.LogLevel;
import com.intellectualcrafters.plot.Plot; import com.intellectualcrafters.plot.Plot;
@ -15,6 +16,7 @@ import com.intellectualcrafters.plot.PlotHomePosition;
import com.intellectualcrafters.plot.PlotId; import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.World; import org.bukkit.World;
@ -118,6 +120,7 @@ public class DBFunc {
" `time` INT(11) DEFAULT '8000'," + " `time` INT(11) DEFAULT '8000'," +
" `deny_entry` TINYINT(1) DEFAULT '0'," + " `deny_entry` TINYINT(1) DEFAULT '0'," +
" `alias` VARCHAR(50) DEFAULT NULL," + " `alias` VARCHAR(50) DEFAULT NULL," +
" `flags` VARCHAR(512) DEFAULT NULL," +
" `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," + " `position` VARCHAR(50) NOT NULL DEFAULT 'DEFAULT'," +
" PRIMARY KEY (`plot_plot_id`)," + " PRIMARY KEY (`plot_plot_id`)," +
" UNIQUE KEY `unique_alias` (`alias`)" + " UNIQUE KEY `unique_alias` (`alias`)" +
@ -136,31 +139,33 @@ public class DBFunc {
* @param plot * @param plot
*/ */
public static void delete(final String world, final Plot plot) { public static void delete(final String world, final Plot plot) {
PlotMain.removePlot(world,plot.id); boolean result = PlotMain.removePlot(world,plot.id);
runTask(new Runnable() { if (result) {
@Override runTask(new Runnable() {
public void run() { @Override
PreparedStatement stmt = null; public void run() {
int id = getId(world,plot.id); PreparedStatement stmt = null;
try { int id = getId(world,plot.id);
stmt = connection.prepareStatement("DELETE FROM `plot_settings` WHERE `plot_plot_id` = ?"); try {
stmt.setInt(1, id); stmt = connection.prepareStatement("DELETE FROM `plot_settings` WHERE `plot_plot_id` = ?");
stmt.executeUpdate(); stmt.setInt(1, id);
stmt.close(); stmt.executeUpdate();
stmt = connection.prepareStatement("DELETE FROM `plot_helpers` WHERE `plot_plot_id` = ?"); stmt.close();
stmt.setInt(1, id); stmt = connection.prepareStatement("DELETE FROM `plot_helpers` WHERE `plot_plot_id` = ?");
stmt.executeUpdate(); stmt.setInt(1, id);
stmt.close(); stmt.executeUpdate();
stmt = connection.prepareStatement("DELETE FROM `plot` WHERE `id` = ?"); stmt.close();
stmt.setInt(1, id); stmt = connection.prepareStatement("DELETE FROM `plot` WHERE `id` = ?");
stmt.executeUpdate(); stmt.setInt(1, id);
stmt.close(); stmt.executeUpdate();
} catch (SQLException e) { stmt.close();
e.printStackTrace(); } catch (SQLException e) {
Logger.add(LogLevel.DANGER, "Failed to delete plot " + plot.id); 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")); UUID owner = UUID.fromString(r.getString("owner"));
Biome plotBiome = Biome.valueOf((String) settings.get("biome")); Biome plotBiome = Biome.valueOf((String) settings.get("biome"));
if(plotBiome == null) plotBiome = Biome.FOREST; 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<flags.length; i++) {
String[] split = flags_string[i].split(":");
flags[i] = new Flag(split[0], split[1]);
}
ArrayList<UUID> helpers = plotHelpers(id); ArrayList<UUID> helpers = plotHelpers(id);
ArrayList<UUID> denied = plotDenied(id); ArrayList<UUID> denied = plotDenied(id);
//boolean changeTime = ((Short) settings.get("custom_time") == 0) ? false : true; //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(plotHomePosition.isMatching((String)settings.get("position"))) position = plotHomePosition;
if(position == null) position = PlotHomePosition.DEFAULT; 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)) { if (plots.containsKey(worldname)) {
plots.get(worldname).put((plot_id), p); plots.get(worldname).put((plot_id), p);
} }
@ -272,7 +288,7 @@ public class DBFunc {
* @param plot * @param plot
* @param rain * @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); plot.settings.setRain(rain);
runTask(new Runnable() { runTask(new Runnable() {
@Override @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"; var = "position";
val = r.getObject(var); val = r.getObject(var);
h.put(var, val); h.put(var, val);
var = "flags";
val = r.getObject(var);
h.put(var, val);
} }
stmt.close();; stmt.close();;
} catch(SQLException e) { } catch(SQLException e) {

View File

@ -87,6 +87,7 @@ public class PlotMeConverter {
false, false,
"", "",
PlotHomePosition.DEFAULT, PlotHomePosition.DEFAULT,
null,
world.getName() world.getName()
); );
DBFunc.createPlot(pl); DBFunc.createPlot(pl);

View File

@ -28,7 +28,11 @@ public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable{
super(player); super(player);
this.plot = plot; this.plot = plot;
} }
public Plot getPlot() {
return this.plot;
}
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return handlers;
} }

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}