SteamWar/BauSystem2.0
Archiviert
12
0

Fix Flag and stuff

Dieser Commit ist enthalten in:
yoyosource 2021-04-17 20:07:32 +02:00
Ursprung fa8ba1ab81
Commit 25dbe42ba4
6 geänderte Dateien mit 45 neuen und 52 gelöschten Zeilen

Datei anzeigen

@ -25,7 +25,6 @@ import de.steamwar.bausystem.region.flags.Flag;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class FlagStorage { public class FlagStorage {
protected final Map<Flag, Flag.Value<?>> flags; protected final Map<Flag, Flag.Value<?>> flags;

Datei anzeigen

@ -25,15 +25,13 @@ import java.util.EnumSet;
import java.util.Set; import java.util.Set;
import lombok.Getter; import lombok.Getter;
@Getter @Getter
public enum Flag implements FlagType<Flag.Value<?>> { public enum Flag {
TNT_FLAG(TNT.class, TNT.ALLOW),
FIRE_FLAG(FIRE.class, FIRE.ALLOW),
FREEZE_FLAG(FREEZE.class, FREEZE.INACTIVE),
DAMAGE_FLAG(DAMAGE.class, DAMAGE.ALLOW);
TNT(TNTMode.class, TNTMode.ALLOW),
FIRE(FIREMode.class, FIREMode.ALLOW),
FREEZE(FREEZEMode.class, FREEZEMode.INACTIVE),
DAMAGE(DAMAGEMode.class, DAMAGEMode.ALLOW);
@Getter @Getter
private static final Set<Flag> flags; private static final Set<Flag> flags;
@ -42,19 +40,16 @@ public enum Flag implements FlagType<Flag.Value<?>> {
flags = EnumSet.allOf(Flag.class); flags = EnumSet.allOf(Flag.class);
} }
private final Class<? extends Value<?>> valueType; private final Class<? extends Value<?>> valueType;
private final Flag.Value<?> defaultValue; private final Flag.Value<?> defaultValue;
private final Value<?>[] values; private final Value<?>[] values;
<T extends Enum<T> & Value<T>> Flag(final Class<? extends Value<T>> valueType, final Flag.Value<T> defaultValue) { <T extends Enum<T> & Value<T>> Flag(final Class<? extends Value<T>> valueType, final Flag.Value<T> defaultValue) {
this.valueType = valueType; this.valueType = valueType;
this.defaultValue = defaultValue; this.defaultValue = defaultValue;
this.values = defaultValue.getValues(); this.values = defaultValue.getValues();
} }
public Value<?> getFlagValueOf(final String name) { public Value<?> getFlagValueOf(final String name) {
return this.defaultValue.getValueOf(name); return this.defaultValue.getValueOf(name);
} }
@ -64,7 +59,6 @@ public enum Flag implements FlagType<Flag.Value<?>> {
return this.name().toLowerCase(); return this.name().toLowerCase();
} }
public interface Value<T extends Enum<T> & Value<T>> { public interface Value<T extends Enum<T> & Value<T>> {
T getValue(); T getValue();

Datei anzeigen

@ -27,35 +27,35 @@ import net.md_5.bungee.api.ChatColor;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum FIRE implements Flag.Value<FIRE> { public enum DAMAGEMode implements Flag.Value<DAMAGEMode> {
ALLOW(ChatColor.RED + "an"), ALLOW(ChatColor.RED + "an"),
DENY(ChatColor.GREEN + "aus"); DENY(ChatColor.GREEN + "aus");
private static FIRE[] values; private static DAMAGEMode[] values;
private final String chatValue; private final String chatValue;
@Override @Override
public FIRE[] getValues() { public DAMAGEMode[] getValues() {
if (FIRE.values == null) { if (DAMAGEMode.values == null) {
FIRE.values = FIRE.values(); //NOSONAR DAMAGEMode.values = DAMAGEMode.values(); //NOSONAR
} }
return FIRE.values; return DAMAGEMode.values;
} }
@Override @Override
public FIRE getValue() { public DAMAGEMode getValue() {
return this; return this;
} }
@Override @Override
public FIRE getValueOf(final String name) { public DAMAGEMode getValueOf(final String name) {
try { try {
return FIRE.valueOf(name); return DAMAGEMode.valueOf(name);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
return FIRE.ALLOW; return DAMAGEMode.ALLOW;
} }
} }
} }

Datei anzeigen

@ -27,35 +27,35 @@ import net.md_5.bungee.api.ChatColor;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum DAMAGE implements Flag.Value<DAMAGE> { public enum FIREMode implements Flag.Value<FIREMode> {
ALLOW(ChatColor.RED + "an"), ALLOW(ChatColor.RED + "an"),
DENY(ChatColor.GREEN + "aus"); DENY(ChatColor.GREEN + "aus");
private static DAMAGE[] values; private static FIREMode[] values;
private final String chatValue; private final String chatValue;
@Override @Override
public DAMAGE[] getValues() { public FIREMode[] getValues() {
if (DAMAGE.values == null) { if (FIREMode.values == null) {
DAMAGE.values = DAMAGE.values(); //NOSONAR FIREMode.values = FIREMode.values(); //NOSONAR
} }
return DAMAGE.values; return FIREMode.values;
} }
@Override @Override
public DAMAGE getValue() { public FIREMode getValue() {
return this; return this;
} }
@Override @Override
public DAMAGE getValueOf(final String name) { public FIREMode getValueOf(final String name) {
try { try {
return DAMAGE.valueOf(name); return FIREMode.valueOf(name);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
return DAMAGE.ALLOW; return FIREMode.ALLOW;
} }
} }
} }

Datei anzeigen

@ -28,36 +28,36 @@ import net.md_5.bungee.api.ChatColor;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum FREEZE implements Flag.Value<FREEZE> { public enum FREEZEMode implements Flag.Value<FREEZEMode> {
ACTIVE("activate", ChatColor.GREEN + "an"), ACTIVE("activate", ChatColor.GREEN + "an"),
INACTIVE("deactivate", ChatColor.RED + "aus"); INACTIVE("deactivate", ChatColor.RED + "aus");
private static FREEZE[] values; private static FREEZEMode[] values;
private final String descriptor; private final String descriptor;
private final String chatValue; private final String chatValue;
@Override @Override
public FREEZE[] getValues() { public FREEZEMode[] getValues() {
if (FREEZE.values == null) { if (FREEZEMode.values == null) {
FREEZE.values = FREEZE.values(); //NOSONAR FREEZEMode.values = FREEZEMode.values(); //NOSONAR
} }
return FREEZE.values; return FREEZEMode.values;
} }
@Override @Override
public FREEZE getValue() { public FREEZEMode getValue() {
return this; return this;
} }
@Override @Override
public FREEZE getValueOf(final String name) { public FREEZEMode getValueOf(final String name) {
try { try {
return FREEZE.valueOf(name); return FREEZEMode.valueOf(name);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
return FREEZE.INACTIVE; return FREEZEMode.INACTIVE;
} }
} }

Datei anzeigen

@ -27,36 +27,36 @@ import net.md_5.bungee.api.ChatColor;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum TNT implements Flag.Value<TNT> { public enum TNTMode implements Flag.Value<TNTMode> {
ALLOW(ChatColor.GREEN + "an"), ALLOW(ChatColor.GREEN + "an"),
DENY(ChatColor.RED + "aus"), DENY(ChatColor.RED + "aus"),
ONLY_TB(ChatColor.GRAY + "Kein " + ChatColor.YELLOW + "Baurahmen"); ONLY_TB(ChatColor.GRAY + "Kein " + ChatColor.YELLOW + "Baurahmen");
private static TNT[] values; private static TNTMode[] values;
private final String chatValue; private final String chatValue;
@Override @Override
public TNT[] getValues() { public TNTMode[] getValues() {
if (TNT.values == null) { if (TNTMode.values == null) {
TNT.values = TNT.values(); //NOSONAR TNTMode.values = TNTMode.values(); //NOSONAR
} }
return TNT.values; return TNTMode.values;
} }
@Override @Override
public TNT getValue() { public TNTMode getValue() {
return this; return this;
} }
@Override @Override
public TNT getValueOf(final String name) { public TNTMode getValueOf(final String name) {
try { try {
return TNT.valueOf(name); return TNTMode.valueOf(name);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
return TNT.ALLOW; return TNTMode.ALLOW;
} }
} }
} }