Fixed flag system

This commit is contained in:
boy0001 2015-01-30 10:49:00 +11:00
parent ab465868ee
commit 4475290443
5 changed files with 24 additions and 10 deletions

View File

@ -30,6 +30,7 @@ import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.AbstractFlag;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
@ -110,7 +111,7 @@ public class FlagCmd extends SubCommand {
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove"); PlayerFunctions.sendMessage(player, C.NO_PERMISSION, "plots.flag.remove");
return false; return false;
} }
if (args.length != 3) { if (args.length != 2 && args.length != 3) {
PlayerFunctions.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag remove <flag> [values]"); PlayerFunctions.sendMessage(player, C.COMMAND_SYNTAX, "/plot flag remove <flag> [values]");
return false; return false;
} }
@ -128,10 +129,17 @@ public class FlagCmd extends SubCommand {
PlayerFunctions.sendMessage(player, C.FLAG_NOT_IN_PLOT); PlayerFunctions.sendMessage(player, C.FLAG_NOT_IN_PLOT);
return false; return false;
} }
boolean result = FlagManager.removePlotFlag(plot, flag.getKey()); if (args.length == 3 && flag.getAbstractFlag().isList()) {
if (!result) { String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
PlayerFunctions.sendMessage(player, C.FLAG_NOT_REMOVED); ((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value);
return false; DBFunc.setFlags(plot.world, plot, plot.settings.flags);
}
else {
boolean result = FlagManager.removePlotFlag(plot, flag.getKey());
if (!result) {
PlayerFunctions.sendMessage(player, C.FLAG_NOT_REMOVED);
return false;
}
} }
PlayerFunctions.sendMessage(player, C.FLAG_REMOVED); PlayerFunctions.sendMessage(player, C.FLAG_REMOVED);
PlotListener.plotEntry(player, plot); PlotListener.plotEntry(player, plot);
@ -166,13 +174,14 @@ public class FlagCmd extends SubCommand {
flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed); flag = new Flag(FlagManager.getFlag(args[1].toLowerCase(), true), parsed);
} }
else { else {
((FlagValue.ListValue) flag.getValue()).add(flag.getValue(), value); ((FlagValue.ListValue) flag.getAbstractFlag().value).add(flag.getValue(), value);
} }
boolean result = FlagManager.addPlotFlag(plot, flag); boolean result = FlagManager.addPlotFlag(plot, flag);
if (!result) { if (!result) {
PlayerFunctions.sendMessage(player, C.FLAG_NOT_ADDED); PlayerFunctions.sendMessage(player, C.FLAG_NOT_ADDED);
return false; return false;
} }
DBFunc.setFlags(plot.world, plot, plot.settings.flags);
PlayerFunctions.sendMessage(player, C.FLAG_ADDED); PlayerFunctions.sendMessage(player, C.FLAG_ADDED);
PlotListener.plotEntry(player, plot); PlotListener.plotEntry(player, plot);
return true; return true;

View File

@ -49,7 +49,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
*/ */
public static final String MAIN_PERMISSION = "plots.use"; public static final String MAIN_PERMISSION = "plots.use";
private final static SubCommand[] _subCommands = new SubCommand[]{new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Ban(), new Unban(), new OP(), new DEOP(), new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Setup(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec()}; private final static SubCommand[] _subCommands = new SubCommand[]{new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Ban(), new Unban(), new OP(), new DEOP(), new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Setup(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd()};
public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() { public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
{ {

View File

@ -78,14 +78,14 @@ public class PlotMeConverter {
@Override @Override
public void run() { public void run() {
try { try {
sendMessage("Conversion has started");
sendMessage("Connecting to PlotMe DB");
final ArrayList<Plot> createdPlots = new ArrayList<>(); final ArrayList<Plot> createdPlots = new ArrayList<>();
final String dataFolder = new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator; final String dataFolder = new File(".").getAbsolutePath() + File.separator + "plugins" + File.separator + "PlotMe" + File.separator;
final File plotMeFile = new File(dataFolder + "config.yml"); final File plotMeFile = new File(dataFolder + "config.yml");
if (!plotMeFile.exists()) { if (!plotMeFile.exists()) {
return; return;
} }
sendMessage("Conversion has started");
sendMessage("Connecting to PlotMe DB");
final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile); final FileConfiguration plotConfig = YamlConfiguration.loadConfiguration(plotMeFile);
int count = 0; int count = 0;

View File

@ -704,7 +704,7 @@ public class SQLManager implements AbstractDB {
if (element.contains(":")) { if (element.contains(":")) {
final String[] split = element.split(":"); final String[] split = element.split(":");
try { try {
String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("<EFBFBD>", ","); String flag_str = split[1].replaceAll("\u00AF", ":").replaceAll("\u00B4", ",");
Flag flag = new Flag(FlagManager.getFlag(split[0], true), flag_str); Flag flag = new Flag(FlagManager.getFlag(split[0], true), flag_str);
flags.add(flag); flags.add(flag);
} catch (final Exception e) { } catch (final Exception e) {

View File

@ -52,4 +52,9 @@ public class PlotBlock {
public int hashCode() { public int hashCode() {
return (id + data) * (id + data + 1) + data; return (id + data) * (id + data + 1) + data;
} }
@Override
public String toString() {
return this.id + ":" + this.data;
}
} }