Add FixedGlobalFlagStorage

This commit is contained in:
2025-07-31 18:17:38 +02:00
parent 01d9532aa6
commit 6a5507321e
4 changed files with 87 additions and 6 deletions
@@ -20,6 +20,7 @@
package de.steamwar.bausystem.region;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.core.Core;
import lombok.NonNull;
import java.io.File;
@@ -37,17 +38,20 @@ public class FixedFlagStorage implements FlagStorage {
@Override
public @NonNull <T extends Enum<T> & Flag.Value<T>> RegionFlagPolicy has(@NonNull Flag<T> flag) {
return RegionFlagPolicy.NOT_APPLICABLE;
if (flag.oneOf(Flag.ITEMS) && Core.getVersion() < 20) {
return RegionFlagPolicy.NOT_APPLICABLE;
}
return RegionFlagPolicy.WRITABLE;
}
@Override
public <T extends Enum<T> & Flag.Value<T>> boolean set(@NonNull Flag<T> flag, @NonNull T value) {
return false;
return flagMap.put(flag, value) != value;
}
@Override
public @NonNull <T extends Enum<T> & Flag.Value<T>> FlagOptional<T> get(@NonNull Flag<T> flag) {
return FlagOptional.of(flag);
return FlagOptional.of(flag, (T) flagMap.get(flag));
}
@Override
@@ -0,0 +1,78 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 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 de.steamwar.bausystem.region.flags.ColorMode;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.ProtectMode;
import de.steamwar.bausystem.region.flags.TNTMode;
import de.steamwar.core.Core;
import lombok.NonNull;
import java.util.HashMap;
import java.util.Map;
public class FixedGlobalFlagStorage implements FlagStorage {
private Map<Flag<?>, Flag.Value<?>> flagMap = new HashMap<>();
public FixedGlobalFlagStorage() {
flagMap.put(Flag.TNT, TNTMode.DENY);
}
@Override
public @NonNull <T extends Enum<T> & Flag.Value<T>> RegionFlagPolicy has(@NonNull Flag<T> flag) {
if (flag.oneOf(Flag.PROTECT, Flag.TESTBLOCK, Flag.NO_GRAVITY, Flag.CHANGED)) {
return RegionFlagPolicy.NOT_APPLICABLE;
}
if (flag.oneOf(Flag.ITEMS) && Core.getVersion() < 20) {
return RegionFlagPolicy.NOT_APPLICABLE;
}
if (flag.oneOf(Flag.COLOR)) {
return RegionFlagPolicy.READ_ONLY;
}
return RegionFlagPolicy.WRITABLE;
}
@Override
public <T extends Enum<T> & Flag.Value<T>> boolean set(@NonNull Flag<T> flag, @NonNull T value) {
if (has(flag).isWritable()) {
return flagMap.put(flag, value) != value;
} else {
return false;
}
}
@Override
public @NonNull <T extends Enum<T> & Flag.Value<T>> FlagOptional<T> get(@NonNull Flag<T> flag) {
if (flag.oneOf(Flag.COLOR)) {
return FlagOptional.of((Flag) flag, ColorMode.YELLOW);
}
if (flag.oneOf(Flag.PROTECT)) {
return FlagOptional.of((Flag) flag, ProtectMode.INACTIVE);
}
return FlagOptional.of(flag, (T) flagMap.get(flag));
}
@Override
public void clear() {
flagMap.clear();
}
}
@@ -36,7 +36,7 @@ public final class FixedGlobalRegion implements Region {
private static final Point MIN_POINT = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
private static final Point MAX_POINT = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
private static final FlagStorage FLAG_STORAGE = FixedFlagStorage.createFromFile(null); // TODO: Update to either File or Region creation!
private static final FlagStorage FLAG_STORAGE = new FixedGlobalFlagStorage();
private static final UUID GLOBAL_REGION_ID = new UUID(0, 0);