From 315e58a4ae87d49baa6031be6a4229e8c75ef94d Mon Sep 17 00:00:00 2001 From: Zeanon Date: Sat, 17 Apr 2021 18:38:03 +0200 Subject: [PATCH] Temp push for Yoyo --- .../bausystem/region/FlagStorage.java | 58 +++++++++++++ .../steamwar/bausystem/region/flags/Flag.java | 82 +++++++++++++++++++ .../bausystem/region/flags/FlagType.java | 25 ++++++ .../region/flags/flagvalues/DAMAGE.java | 61 ++++++++++++++ .../region/flags/flagvalues/FIRE.java | 61 ++++++++++++++ .../region/flags/flagvalues/FREEZE.java | 68 +++++++++++++++ .../region/flags/flagvalues/TNT.java | 62 ++++++++++++++ 7 files changed, 417 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/region/flags/FlagType.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/DAMAGE.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FIRE.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FREEZE.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/TNT.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java b/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java new file mode 100644 index 00000000..4ad92204 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/FlagStorage.java @@ -0,0 +1,58 @@ +/* + * 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; + +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import de.steamwar.bausystem.region.flags.Flag; +import de.steamwar.bausystem.region.flags.FlagType; +import de.steamwar.bausystem.region.flags.flagvalues.FREEZE; +import de.steamwar.bausystem.region.flags.flagvalues.TNT; +import java.util.HashMap; +import java.util.Map; + + +public class FlagStorage { + + protected final Map, Flag.Value> flags; + protected final JsonObject jsonObject; + + public FlagStorage(final JsonObject jsonObject) { + flags = new HashMap<>(); + this.jsonObject = jsonObject; + readKeys(); + } + + public & Flag.Value> boolean set(final FlagType flagType, final Flag.Value value) { + return flags.put(flagType, value) != value; + } + + public Flag.Value get(final Flag flagType) { + set(Flag.TNT_FLAG, TNT.ALLOW); + return flags.get(flagType); + } + + private void readKeys() { + for (final Flag flag : Flag.getFlags()) { + final JsonPrimitive flagValue = jsonObject.getAsJsonPrimitive(flag.name().toLowerCase()); + flags.put(flag, flagValue == null ? flag.getDefaultValue() : flag.getFlagValueOf(flagValue.getAsString().toUpperCase())); + } + } +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java new file mode 100644 index 00000000..4a22d505 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java @@ -0,0 +1,82 @@ +/* + * 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; + + +import de.steamwar.bausystem.region.flags.flagvalues.*; +import java.util.EnumSet; +import java.util.Set; +import lombok.Getter; + + +@Getter +public enum Flag implements FlagType> { + + TNT_FLAG(TNT.class, TNT.ALLOW), + FIRE_FLAG(FIRE.class, FIRE.ALLOW), + FREEZE_FLAG(FREEZE.class, FREEZE.INACTIVE), + DAMAGE_FLAG(DAMAGE.class, DAMAGE.ALLOW); + + + @Getter + private static final Set flags; + + static { + flags = EnumSet.allOf(Flag.class); + } + + + private final Class> valueType; + private final Flag.Value defaultValue; + private final Value[] values; + + + & Value> Flag(final Class> valueType, final Flag.Value defaultValue) { + this.valueType = valueType; + this.defaultValue = defaultValue; + this.values = defaultValue.getValues(); + } + + + public Value getFlagValueOf(final String name) { + return this.defaultValue.getValueOf(name); + } + + @Override + public String toString() { + return this.name().toLowerCase(); + } + + + public interface Value & Value> { + + T getValue(); + + T getValueOf(final String name); + + T[] getValues(); + + String getChatValue(); + + default String getName() { + return this.getValue().name().toLowerCase(); + } + } +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/FlagType.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/FlagType.java new file mode 100644 index 00000000..c043aecc --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/FlagType.java @@ -0,0 +1,25 @@ +/* + * 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; + +public interface FlagType> { + + String name(); +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/DAMAGE.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/DAMAGE.java new file mode 100644 index 00000000..23ce51ee --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/DAMAGE.java @@ -0,0 +1,61 @@ +/* + * 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.flagvalues; + +import de.steamwar.bausystem.region.flags.Flag; +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.md_5.bungee.api.ChatColor; + + +@Getter +@AllArgsConstructor +public enum DAMAGE implements Flag.Value { + + ALLOW(ChatColor.RED + "an"), + DENY(ChatColor.GREEN + "aus"); + + + private static DAMAGE[] values; + private final String chatValue; + + + @Override + public DAMAGE[] getValues() { + if (DAMAGE.values == null) { + DAMAGE.values = DAMAGE.values(); //NOSONAR + } + return DAMAGE.values; + } + + @Override + public DAMAGE getValue() { + return this; + } + + @Override + public DAMAGE getValueOf(final String name) { + try { + return DAMAGE.valueOf(name); + } catch (IllegalArgumentException e) { + return DAMAGE.ALLOW; + } + } +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FIRE.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FIRE.java new file mode 100644 index 00000000..ab170d03 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FIRE.java @@ -0,0 +1,61 @@ +/* + * 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.flagvalues; + +import de.steamwar.bausystem.region.flags.Flag; +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.md_5.bungee.api.ChatColor; + + +@Getter +@AllArgsConstructor +public enum FIRE implements Flag.Value { + + ALLOW(ChatColor.RED + "an"), + DENY(ChatColor.GREEN + "aus"); + + + private static FIRE[] values; + private final String chatValue; + + + @Override + public FIRE[] getValues() { + if (FIRE.values == null) { + FIRE.values = FIRE.values(); //NOSONAR + } + return FIRE.values; + } + + @Override + public FIRE getValue() { + return this; + } + + @Override + public FIRE getValueOf(final String name) { + try { + return FIRE.valueOf(name); + } catch (IllegalArgumentException e) { + return FIRE.ALLOW; + } + } +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FREEZE.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FREEZE.java new file mode 100644 index 00000000..de3a66c5 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/FREEZE.java @@ -0,0 +1,68 @@ +/* + * 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.flagvalues; + + +import de.steamwar.bausystem.region.flags.Flag; +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.md_5.bungee.api.ChatColor; + + +@Getter +@AllArgsConstructor +public enum FREEZE implements Flag.Value { + + ACTIVE("activate", ChatColor.GREEN + "an"), + INACTIVE("deactivate", ChatColor.RED + "aus"); + + + private static FREEZE[] values; + private final String descriptor; + private final String chatValue; + + + @Override + public FREEZE[] getValues() { + if (FREEZE.values == null) { + FREEZE.values = FREEZE.values(); //NOSONAR + } + return FREEZE.values; + } + + @Override + public FREEZE getValue() { + return this; + } + + @Override + public FREEZE getValueOf(final String name) { + try { + return FREEZE.valueOf(name); + } catch (IllegalArgumentException e) { + return FREEZE.INACTIVE; + } + } + + @Override + public String toString() { + return this.descriptor; + } +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/TNT.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/TNT.java new file mode 100644 index 00000000..0efd8e53 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/flagvalues/TNT.java @@ -0,0 +1,62 @@ +/* + * 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.flagvalues; + +import de.steamwar.bausystem.region.flags.Flag; +import lombok.AllArgsConstructor; +import lombok.Getter; +import net.md_5.bungee.api.ChatColor; + + +@Getter +@AllArgsConstructor +public enum TNT implements Flag.Value { + + ALLOW(ChatColor.GREEN + "an"), + DENY(ChatColor.RED + "aus"), + ONLY_TB(ChatColor.GRAY + "Kein " + ChatColor.YELLOW + "Baurahmen"); + + + private static TNT[] values; + private final String chatValue; + + + @Override + public TNT[] getValues() { + if (TNT.values == null) { + TNT.values = TNT.values(); //NOSONAR + } + return TNT.values; + } + + @Override + public TNT getValue() { + return this; + } + + @Override + public TNT getValueOf(final String name) { + try { + return TNT.valueOf(name); + } catch (IllegalArgumentException e) { + return TNT.ALLOW; + } + } +} \ No newline at end of file