SteamWar/BauSystem2.0
Archiviert
12
0
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-06-15 17:46:04 +02:00
Ursprung 9141db7686
Commit d89088b65a
4 geänderte Dateien mit 53 neuen und 60 gelöschten Zeilen

Datei anzeigen

@ -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<Flag, Flag.Value<?>> flags;
protected Set<Tag> 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());

Datei anzeigen

@ -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<Flag> flags;

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.region.flags.other;
import de.steamwar.bausystem.region.flags.Flag;
public enum BackupMode implements Flag.Value<BackupMode> {
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();
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.region.tags;
public enum Tag {
CHANGED,
}