diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java index 4b13cbf2..560a6fc8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java @@ -20,11 +20,17 @@ package de.steamwar.bausystem.region; import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.tags.Tag; import yapion.hierarchy.types.YAPIONObject; import java.util.EnumMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; +/** + * Tags and Flags are not allowed to have overlaping names. + */ public class FlagStorage { public static FlagStorage createStorage(YAPIONObject yapionObject) { @@ -37,6 +43,11 @@ public class FlagStorage { flagStorage.set(flag, flag.getDefaultValue()); } } + for (final Tag tag : Tag.values()) { + if (yapionObject.containsKey(tag.name())) { + flagStorage.set(tag); + } + } return flagStorage; } @@ -45,13 +56,18 @@ public class FlagStorage { for (final Flag flag : Flag.getFlags()) { yapionObject.add(flag.name(), flagStorage.get(flag).getValue().name()); } + for (Tag tag : flagStorage.tagSet) { + yapionObject.add(tag.name(), true); + } return yapionObject; } protected Map> flags; + protected Set tagSet; public FlagStorage() { flags = new EnumMap<>(Flag.class); + tagSet = new HashSet<>(); readKeys(); } @@ -63,6 +79,18 @@ public class FlagStorage { return flags.get(flagType); } + public boolean set(final Tag tag) { + return tagSet.add(tag); + } + + public boolean remove(final Tag tag) { + return tagSet.remove(tag); + } + + public boolean is(final Tag tag) { + return tagSet.contains(tag); + } + private void readKeys() { for (final Flag flag : Flag.getFlags()) { flags.put(flag, flag.getDefaultValue()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java index e9ce3486..ef2a65f7 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java @@ -20,7 +20,6 @@ package de.steamwar.bausystem.region.flags; import de.steamwar.bausystem.region.Region; -import de.steamwar.bausystem.region.flags.other.BackupMode; import de.steamwar.bausystem.region.flags.flagvalues.*; import de.steamwar.bausystem.shared.EnumDisplay; import lombok.Getter; @@ -37,8 +36,7 @@ public enum Flag implements EnumDisplay { FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW, region -> true), DAMAGE("FLAG_DAMAGE", DamageMode.class, DamageMode.ALLOW, region -> false), FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE, region -> true), - PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.INACTIVE, region -> region.getFloorLevel() != 0), - BACKUP("", BackupMode.class, BackupMode.UNCHANGED, region -> false); + PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.INACTIVE, region -> region.getFloorLevel() != 0); @Getter private static final Set flags; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/other/BackupMode.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/other/BackupMode.java deleted file mode 100644 index 43ab9115..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/other/BackupMode.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2021 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.bausystem.region.flags.other; - -import de.steamwar.bausystem.region.flags.Flag; - -public enum BackupMode implements Flag.Value { - - CHANGED, - UNCHANGED; - - private static BackupMode[] values; - - @Override - public BackupMode[] getValues() { - if (BackupMode.values == null) { - BackupMode.values = BackupMode.values(); //NOSONAR - } - return BackupMode.values; - } - - @Override - public BackupMode getValue() { - return this; - } - - @Override - public BackupMode getValueOf(final String name) { - try { - return BackupMode.valueOf(name.toUpperCase()); - } catch (IllegalArgumentException e) { - return BackupMode.UNCHANGED; - } - } - - @Override - public String getChatValue() { - throw new UnsupportedOperationException(); - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/tags/Tag.java b/BauSystem_Main/src/de/steamwar/bausystem/region/tags/Tag.java new file mode 100644 index 00000000..e37751d9 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/tags/Tag.java @@ -0,0 +1,24 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.region.tags; + +public enum Tag { + CHANGED, +}