Add Tag
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
9141db7686
Commit
d89088b65a
@ -20,11 +20,17 @@
|
|||||||
package de.steamwar.bausystem.region;
|
package de.steamwar.bausystem.region;
|
||||||
|
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
|
import de.steamwar.bausystem.region.tags.Tag;
|
||||||
import yapion.hierarchy.types.YAPIONObject;
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tags and Flags are not allowed to have overlaping names.
|
||||||
|
*/
|
||||||
public class FlagStorage {
|
public class FlagStorage {
|
||||||
|
|
||||||
public static FlagStorage createStorage(YAPIONObject yapionObject) {
|
public static FlagStorage createStorage(YAPIONObject yapionObject) {
|
||||||
@ -37,6 +43,11 @@ public class FlagStorage {
|
|||||||
flagStorage.set(flag, flag.getDefaultValue());
|
flagStorage.set(flag, flag.getDefaultValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (final Tag tag : Tag.values()) {
|
||||||
|
if (yapionObject.containsKey(tag.name())) {
|
||||||
|
flagStorage.set(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
return flagStorage;
|
return flagStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,13 +56,18 @@ public class FlagStorage {
|
|||||||
for (final Flag flag : Flag.getFlags()) {
|
for (final Flag flag : Flag.getFlags()) {
|
||||||
yapionObject.add(flag.name(), flagStorage.get(flag).getValue().name());
|
yapionObject.add(flag.name(), flagStorage.get(flag).getValue().name());
|
||||||
}
|
}
|
||||||
|
for (Tag tag : flagStorage.tagSet) {
|
||||||
|
yapionObject.add(tag.name(), true);
|
||||||
|
}
|
||||||
return yapionObject;
|
return yapionObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<Flag, Flag.Value<?>> flags;
|
protected Map<Flag, Flag.Value<?>> flags;
|
||||||
|
protected Set<Tag> tagSet;
|
||||||
|
|
||||||
public FlagStorage() {
|
public FlagStorage() {
|
||||||
flags = new EnumMap<>(Flag.class);
|
flags = new EnumMap<>(Flag.class);
|
||||||
|
tagSet = new HashSet<>();
|
||||||
readKeys();
|
readKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,6 +79,18 @@ public class FlagStorage {
|
|||||||
return flags.get(flagType);
|
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() {
|
private void readKeys() {
|
||||||
for (final Flag flag : Flag.getFlags()) {
|
for (final Flag flag : Flag.getFlags()) {
|
||||||
flags.put(flag, flag.getDefaultValue());
|
flags.put(flag, flag.getDefaultValue());
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
package de.steamwar.bausystem.region.flags;
|
package de.steamwar.bausystem.region.flags;
|
||||||
|
|
||||||
import de.steamwar.bausystem.region.Region;
|
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.region.flags.flagvalues.*;
|
||||||
import de.steamwar.bausystem.shared.EnumDisplay;
|
import de.steamwar.bausystem.shared.EnumDisplay;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -37,8 +36,7 @@ public enum Flag implements EnumDisplay {
|
|||||||
FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW, region -> true),
|
FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW, region -> true),
|
||||||
DAMAGE("FLAG_DAMAGE", DamageMode.class, DamageMode.ALLOW, region -> false),
|
DAMAGE("FLAG_DAMAGE", DamageMode.class, DamageMode.ALLOW, region -> false),
|
||||||
FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE, region -> true),
|
FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE, region -> true),
|
||||||
PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.INACTIVE, region -> region.getFloorLevel() != 0),
|
PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.INACTIVE, region -> region.getFloorLevel() != 0);
|
||||||
BACKUP("", BackupMode.class, BackupMode.UNCHANGED, region -> false);
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private static final Set<Flag> flags;
|
private static final Set<Flag> flags;
|
||||||
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
24
BauSystem_Main/src/de/steamwar/bausystem/region/tags/Tag.java
Normale Datei
24
BauSystem_Main/src/de/steamwar/bausystem/region/tags/Tag.java
Normale Datei
@ -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,
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren