From 541255fe7ea3915cd4b7bb8e50f1af9c2dfec516 Mon Sep 17 00:00:00 2001 From: Pierre Maurice Schwang Date: Fri, 1 Oct 2021 21:52:30 +0200 Subject: [PATCH] ListFlag#merge should not allow duplicates (Fixes #3157) (#3265) --- .../plotsquared/core/plot/flag/types/ListFlag.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/types/ListFlag.java b/Core/src/main/java/com/plotsquared/core/plot/flag/types/ListFlag.java index a4429cb11..2811883ce 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/types/ListFlag.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/types/ListFlag.java @@ -43,8 +43,18 @@ public abstract class ListFlag, F>> extends PlotFl @Override public F merge(@NonNull List newValue) { final List mergedList = new ArrayList<>(); - mergedList.addAll(getValue()); - mergedList.addAll(newValue); + // If a server already used PS before this fix, we remove all present duplicates on an eventual merge + for (final V v : getValue()) { + if (!mergedList.contains(v)) { + mergedList.add(v); + } + } + // Only add new values if not already present from #getValue() + for (final V v : newValue) { + if (!mergedList.contains(v)) { + mergedList.add(v); + } + } return this.flagOf(mergedList); }