diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java index 84446aa00..833c0b780 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/FlagCmd.java @@ -197,25 +197,26 @@ public class FlagCmd extends SubCommand { } if (args.length == 3 && flag instanceof ListFlag) { String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " "); - Optional flag1 = - plot.getFlag((Flag>) flag); - if (flag1.isPresent()) { - boolean o = flag1.get().removeAll((Collection) flag.parseValue(value)); - if (o) { - if (flag1.get().isEmpty()) { - final boolean result = plot.removeFlag(flag); - if (result) { - MainUtil.sendMessage(player, Captions.FLAG_REMOVED); + final ListFlag listFlag = (ListFlag) flag; + final Optional collectionOptional = plot.getFlag(listFlag); + if (collectionOptional.isPresent()) { + final Collection parsedCollection = (Collection) flag.parseValue(value); + if (parsedCollection.isEmpty()) { + return !MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); + } + final Collection flagCollection = collectionOptional.get(); + if (flagCollection.removeAll(parsedCollection)) { + if (flagCollection.isEmpty()) { + if (plot.removeFlag(flag)) { + return MainUtil.sendMessage(player, Captions.FLAG_REMOVED); } else { - MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); + return !MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); } - return true; } else { MainUtil.sendMessage(player, Captions.FLAG_REMOVED); } } else { - MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); - return false; + return !MainUtil.sendMessage(player, Captions.FLAG_NOT_REMOVED); } } DBFunc.setFlags(plot, plot.getFlags()); @@ -259,16 +260,19 @@ public class FlagCmd extends SubCommand { } Object val = parsed; if (flag instanceof ListFlag) { - Optional flag1 = - plot.getFlag((Flag>) flag); - if (flag1.isPresent()) { - boolean o = flag1.get().addAll((Collection) parsed); - if (o) { + final Collection parsedCollection = (Collection) parsed; + if (parsedCollection.isEmpty()) { + return !MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); + } + final ListFlag listFlag = (ListFlag) flag; + final Optional collectionOptional = plot.getFlag(listFlag); + if (collectionOptional.isPresent()) { + final Collection flagCollection = collectionOptional.get(); + if (flagCollection.addAll(parsedCollection)) { MainUtil.sendMessage(player, Captions.FLAG_ADDED); - val = flag1.get(); + val = flagCollection; } else { - MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); - return false; + return !MainUtil.sendMessage(player, Captions.FLAG_NOT_ADDED); } } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java index 56cd0e901..4be8ac475 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/PlotBlockListFlag.java @@ -2,9 +2,14 @@ package com.github.intellectualsites.plotsquared.plot.flag; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; +import com.github.intellectualsites.plotsquared.plot.util.LegacyMappings; import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import java.util.Arrays; import java.util.HashSet; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; public class PlotBlockListFlag extends ListFlag> { @@ -17,14 +22,9 @@ public class PlotBlockListFlag extends ListFlag> { } @Override public HashSet parseValue(final String value) { - final HashSet list = new HashSet<>(); - for (final String item : value.split(",")) { - final PlotBlock block = PlotSquared.get().IMP.getLegacyMappings().fromAny(item); - if (block != null) { - list.add(block); - } - } - return list; + final LegacyMappings legacyMappings = PlotSquared.get().IMP.getLegacyMappings(); + return Arrays.stream(value.split(",")).map(legacyMappings::fromAny).filter(Objects::nonNull) + .collect(Collectors.toCollection(HashSet::new)); } @Override public String getValueDescription() {