Temp push for Yoyo

Dieser Commit ist enthalten in:
Zeanon 2021-04-17 18:38:03 +02:00
Ursprung ac54f8ef17
Commit 315e58a4ae
7 geänderte Dateien mit 417 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<FlagType<?>, Flag.Value<?>> flags;
protected final JsonObject jsonObject;
public FlagStorage(final JsonObject jsonObject) {
flags = new HashMap<>();
this.jsonObject = jsonObject;
readKeys();
}
public <T extends Enum<T> & Flag.Value<T>> boolean set(final FlagType<T> flagType, final Flag.Value<T> 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()));
}
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Flag.Value<?>> {
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<Flag> flags;
static {
flags = EnumSet.allOf(Flag.class);
}
private final Class<? extends Value<?>> valueType;
private final Flag.Value<?> defaultValue;
private final Value<?>[] values;
<T extends Enum<T> & Value<T>> Flag(final Class<? extends Value<T>> valueType, final Flag.Value<T> 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<T extends Enum<T> & Value<T>> {
T getValue();
T getValueOf(final String name);
T[] getValues();
String getChatValue();
default String getName() {
return this.getValue().name().toLowerCase();
}
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.region.flags;
public interface FlagType<T extends Flag.Value<?>> {
String name();
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<DAMAGE> {
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;
}
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<FIRE> {
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;
}
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<FREEZE> {
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;
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<TNT> {
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;
}
}
}