mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 12:25:46 +01:00
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:
parent
e4e9b80c02
commit
ccd237d2c0
@ -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
|
||||
*/
|
||||
|
44
PlotSquared/src/com/intellectualcrafters/plot/Flag.java
Normal file
44
PlotSquared/src/com/intellectualcrafters/plot/Flag.java
Normal 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();
|
||||
}
|
||||
}
|
@ -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<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.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;
|
||||
}
|
||||
|
||||
|
@ -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<Flag> registeredFlags = new HashSet<Flag>();
|
||||
/**
|
||||
* MySQL Object
|
||||
*/
|
||||
@ -120,6 +128,22 @@ public class PlotMain extends JavaPlugin {
|
||||
*/
|
||||
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
|
||||
*
|
||||
@ -132,7 +156,11 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
return new HashSet<Plot>(myplots);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public static Set<Plot> getPlots(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
ArrayList<Plot> myplots = new ArrayList<Plot>();
|
||||
@ -145,6 +173,12 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
return new HashSet<Plot>(myplots);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param world
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public static Set<Plot> getPlots(World world, Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
ArrayList<Plot> myplots = new ArrayList<Plot>();
|
||||
@ -155,7 +189,11 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
return new HashSet<Plot>(myplots);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param world
|
||||
* @return
|
||||
*/
|
||||
public static HashMap<PlotId, Plot> 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,18 +292,31 @@ public class PlotMain extends JavaPlugin {
|
||||
continue;
|
||||
}
|
||||
if (PlayerFunctions.hasExpired(plot)) {
|
||||
PlotDeleteEvent event = new PlotDeleteEvent(world,plot.id);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if(!event.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else {
|
||||
DBFunc.delete(world, plot);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
for (String world:getPlotWorldsString()) {
|
||||
if (PlotMain.plots.containsKey(world)) {
|
||||
for (Plot plot : PlotMain.plots.get(world).values()) {
|
||||
if (PlayerFunctions.hasExpired(plot)) {
|
||||
PlotDeleteEvent event = new PlotDeleteEvent(world,plot.id);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if(!event.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else {
|
||||
DBFunc.delete(world, plot);
|
||||
}
|
||||
}
|
||||
@ -247,6 +324,7 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On Load.
|
||||
|
@ -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<Flag> flags;
|
||||
/**
|
||||
* plot time
|
||||
*/
|
||||
@ -113,11 +122,54 @@ 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<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 void setPosition(PlotHomePosition position) { this.position = position; }
|
||||
public String getAlias() { return this.alias; }
|
||||
|
@ -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
|
||||
|
@ -30,9 +30,14 @@ public class Clear extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
Plot plot = PlayerFunctions.getCurrentPlot(plr);
|
||||
boolean result = PlotMain.removePlot(plr.getWorld().getName(), plot.id);
|
||||
if (result) {
|
||||
DBFunc.delete(plr.getWorld().getName(), plot);
|
||||
PlotMain.removePlot(plr.getWorld().getName(), plot.id);
|
||||
plot.clear(plr);
|
||||
}
|
||||
else {
|
||||
PlayerFunctions.sendMessage(plr, "Plot clearing has been denied.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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")
|
||||
@ -77,6 +82,57 @@ public class Set extends SubCommand{
|
||||
}
|
||||
}
|
||||
|
||||
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.length < 2) {
|
||||
PlayerFunctions.sendMessage(plr, C.NEED_ON_OFF);
|
||||
|
@ -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,7 +139,8 @@ public class DBFunc {
|
||||
* @param plot
|
||||
*/
|
||||
public static void delete(final String world, final Plot plot) {
|
||||
PlotMain.removePlot(world,plot.id);
|
||||
boolean result = PlotMain.removePlot(world,plot.id);
|
||||
if (result) {
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -162,6 +166,7 @@ public class DBFunc {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create plot settings
|
||||
@ -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<flags.length; i++) {
|
||||
String[] split = flags_string[i].split(":");
|
||||
flags[i] = new Flag(split[0], split[1]);
|
||||
}
|
||||
|
||||
ArrayList<UUID> helpers = plotHelpers(id);
|
||||
ArrayList<UUID> 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);
|
||||
}
|
||||
@ -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) {
|
||||
|
@ -87,6 +87,7 @@ public class PlotMeConverter {
|
||||
false,
|
||||
"",
|
||||
PlotHomePosition.DEFAULT,
|
||||
null,
|
||||
world.getName()
|
||||
);
|
||||
DBFunc.createPlot(pl);
|
||||
|
@ -29,6 +29,10 @@ public class PlayerClaimPlotEvent extends PlayerEvent implements Cancellable{
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
public Plot getPlot() {
|
||||
return this.plot;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user