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.Map;
public class FlagStorage {
protected final Map<Flag, Flag.Value<?>> flags;

Datei anzeigen

@ -25,15 +25,13 @@ 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);
public enum Flag {
TNT(TNTMode.class, TNTMode.ALLOW),
FIRE(FIREMode.class, FIREMode.ALLOW),
FREEZE(FREEZEMode.class, FREEZEMode.INACTIVE),
DAMAGE(DAMAGEMode.class, DAMAGEMode.ALLOW);
@Getter
private static final Set<Flag> flags;
@ -42,19 +40,16 @@ public enum Flag implements FlagType<Flag.Value<?>> {
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);
}
@ -64,7 +59,6 @@ public enum Flag implements FlagType<Flag.Value<?>> {
return this.name().toLowerCase();
}
public interface Value<T extends Enum<T> & Value<T>> {
T getValue();

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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