Fix /plot flag remove

This commit is contained in:
Alexander Söderberg 2020-02-18 17:21:03 +01:00
parent 4dd946fba3
commit 2a84ae102e
2 changed files with 14 additions and 14 deletions

View File

@ -266,10 +266,10 @@ import java.util.Map;
final Plot plot = player.getLocation().getPlotAbs(); final Plot plot = player.getLocation().getPlotAbs();
if (args.length == 2 && flag instanceof ListFlag) { if (args.length == 2 && flag instanceof ListFlag) {
String value = StringMan.join(Arrays.copyOfRange(args, 1, args.length), " "); String value = StringMan.join(Arrays.copyOfRange(args, 1, args.length), " ");
final ListFlag<?, ?> listFlag = (ListFlag<?, ?>) flag; final ListFlag listFlag = (ListFlag) flag;
final List<?> list = final List list =
plot.getFlag((Class<? extends ListFlag<?, ?>>) listFlag.getClass()); plot.getFlag((Class<? extends ListFlag<?, ?>>) listFlag.getClass());
final PlotFlag<? extends List<?>, ?> parsedFlag; final PlotFlag parsedFlag;
try { try {
parsedFlag = listFlag.parse(value); parsedFlag = listFlag.parse(value);
} catch (final FlagParseException e) { } catch (final FlagParseException e) {
@ -277,11 +277,11 @@ import java.util.Map;
.send(player, e.getFlag().getName(), e.getValue(), e.getErrorMessage()); .send(player, e.getFlag().getName(), e.getValue(), e.getErrorMessage());
return; return;
} }
if (parsedFlag.getValue().isEmpty()) { if (((List) parsedFlag.getValue()).isEmpty()) {
MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED);
return; return;
} }
if (list.removeAll(parsedFlag.getValue())) { if (list.removeAll((List) parsedFlag.getValue())) {
if (list.isEmpty()) { if (list.isEmpty()) {
if (plot.removeFlag(flag)) { if (plot.removeFlag(flag)) {
MainUtil.sendMessage(player, Captions.FLAG_REMOVED); MainUtil.sendMessage(player, Captions.FLAG_REMOVED);
@ -291,14 +291,19 @@ import java.util.Map;
return; return;
} }
} else { } else {
MainUtil.sendMessage(player, Captions.FLAG_REMOVED); // MainUtil.sendMessage(player, Captions.FLAG_REMOVED);
if (plot.setFlag(parsedFlag.createFlagInstance(list))) {
MainUtil.sendMessage(player, Captions.FLAG_PARTIALLY_REMOVED);
return;
} else {
MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED);
return;
}
} }
} else { } else {
MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED);
return; return;
} }
// TODO reimplement somewhere else: DBFunc.setFlags(plot, plot.getFlags());
return;
} else { } else {
boolean result = plot.removeFlag(flag); boolean result = plot.removeFlag(flag);
if (!result) { if (!result) {
@ -306,12 +311,6 @@ import java.util.Map;
return; return;
} }
} }
/* TODO reimplement, maybe handle it with events?
if (flag == Flags.TIME) {
player.setTime(Long.MAX_VALUE);
} else if (flag == Flags.WEATHER) {
player.setWeather(PlotWeather.RESET);
}*/
MainUtil.sendMessage(player, Captions.FLAG_REMOVED); MainUtil.sendMessage(player, Captions.FLAG_REMOVED);
} }

View File

@ -529,6 +529,7 @@ public enum Captions implements Caption {
FLAG_NOT_REMOVED("$2The flag could not be removed", "Flag"), FLAG_NOT_REMOVED("$2The flag could not be removed", "Flag"),
FLAG_NOT_ADDED("$2The flag could not be added", "Flag"), FLAG_NOT_ADDED("$2The flag could not be added", "Flag"),
FLAG_REMOVED("$4Successfully removed flag", "Flag"), FLAG_REMOVED("$4Successfully removed flag", "Flag"),
FLAG_PARTIALLY_REMOVED("$4Successfully removed flag value(s)", "Flag"),
FLAG_ADDED("$4Successfully added flag", "Flag"), FLAG_ADDED("$4Successfully added flag", "Flag"),
FLAG_TUTORIAL_USAGE("$1Have an admin set the flag: $2%s", "CommandConfig"), FLAG_TUTORIAL_USAGE("$1Have an admin set the flag: $2%s", "CommandConfig"),
FLAG_LIST_ENTRY("$2%s: $1%s", "Flag"), FLAG_LIST_ENTRY("$2%s: $1%s", "Flag"),