SteamWar/BauSystem2.0
Archiviert
12
0

TYPEREPLACE_HELPAdd initial modular bau impl

Dieser Commit ist enthalten in:
yoyosource 2024-01-30 16:08:22 +01:00
Ursprung aeb5ebfc12
Commit 5c48983375
15 geänderte Dateien mit 2108 neuen und 981 gelöschten Zeilen

Datei-Diff unterdrückt, da er zu groß ist Diff laden

Datei-Diff unterdrückt, da er zu groß ist Diff laden

Datei anzeigen

@ -23,6 +23,8 @@ import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.bausystem.configplayer.Config;
import de.steamwar.bausystem.features.tpslimit.TPSFreezeUtils;
import de.steamwar.bausystem.linkage.LinkageUtils;
import de.steamwar.bausystem.region.FlagStorage;
import de.steamwar.bausystem.region.GlobalRegion;
import de.steamwar.bausystem.region.loader.PrototypeLoader;
import de.steamwar.bausystem.region.loader.RegionLoader;
import de.steamwar.bausystem.region.loader.Updater;
@ -40,6 +42,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import yapion.hierarchy.types.YAPIONObject;
import java.io.IOException;
import java.io.OutputStream;
@ -66,6 +69,8 @@ public class BauSystem extends JavaPlugin implements Listener {
instance = this;
SWUtils.setBausystem(instance);
new GlobalRegion(new FlagStorage(), new YAPIONObject());
/*
try {
PrototypeLoader.load();
RegionLoader.load();
@ -77,6 +82,7 @@ public class BauSystem extends JavaPlugin implements Listener {
new Updater(PrototypeLoader.file, PrototypeLoader::load);
new Updater(RegionLoader.file, RegionLoader::load);
*/
SWCommandUtils.addValidator(Player.class, validator(Permission.BUILD));
SWCommandUtils.addValidator(CommandSender.class, validator(Permission.BUILD));

Datei anzeigen

@ -46,6 +46,7 @@ import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.ObjIntConsumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Datei anzeigen

@ -0,0 +1,37 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.regionnew.Tile;
import de.steamwar.linkage.Linked;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
@Linked
public class TileActionBar implements Listener {
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§e" + Tile.of(event.getTo())));
}
}

Datei anzeigen

@ -35,6 +35,8 @@ public enum Flag implements EnumDisplay {
FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE),
PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE),
ITEMS("FLAG_ITEMS", ItemMode.class, ItemMode.INACTIVE),
TESTBLOCK("FLAG_TESTBLOCK", TestblockMode.class, TestblockMode.NO_VALUE),
CHANGED("FLAG_CHANGED", ChangedMode.class, ChangedMode.NO_CHANGE),
;
@Getter

Datei anzeigen

@ -0,0 +1,58 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.flagvalues;
import de.steamwar.bausystem.region.flags.Flag;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum ChangedMode implements Flag.Value<ChangedMode> {
NO_CHANGE("FLAG_CHANGED_NO_CHANGE", false),
HAS_CHANGE("FLAG_CHANGED_HAS_CHANGE", true);
private static ChangedMode[] values;
private final String chatValue;
private final Boolean changed;
@Override
public ChangedMode[] getValues() {
if (ChangedMode.values == null) {
ChangedMode.values = ChangedMode.values(); //NOSONAR
}
return ChangedMode.values;
}
@Override
public ChangedMode getValue() {
return this;
}
@Override
public ChangedMode getValueOf(final String name) {
try {
return ChangedMode.valueOf(name.toUpperCase());
} catch (IllegalArgumentException e) {
return null;
}
}
}

Datei anzeigen

@ -0,0 +1,62 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.flagvalues;
import de.steamwar.bausystem.region.flags.Flag;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum TestblockMode implements Flag.Value<TestblockMode> {
NO_VALUE("FLAG_TESTBLOCK_NO_VALUE", false, false),
NORTH("FLAG_TESTBLOCK_NORTH", false, true),
SOUTH("FLAG_TESTBLOCK_SOUTH", false, false),
FIXED_NORTH("FLAG_TESTBLOCK_NORTH", true, true),
FIXED_SOUTH("FLAG_TESTBLOCK_SOUTH", true, false);
private static TestblockMode[] values;
private final String chatValue;
private final boolean fixed;
private final boolean north;
@Override
public TestblockMode[] getValues() {
if (TestblockMode.values == null) {
TestblockMode.values = TestblockMode.values(); //NOSONAR
}
return TestblockMode.values;
}
@Override
public TestblockMode getValue() {
return this;
}
@Override
public TestblockMode getValueOf(final String name) {
try {
return TestblockMode.valueOf(name.toUpperCase());
} catch (IllegalArgumentException e) {
return null;
}
}
}

Datei anzeigen

@ -0,0 +1,191 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.regionnew;
import com.sk89q.worldedit.EditSession;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.sql.SchematicNode;
import org.bukkit.Location;
import javax.annotation.Nullable;
import java.io.File;
import java.util.Optional;
public class GlobalRegion implements Region {
public static final Region GLOBAL_REGION = new GlobalRegion();
private GlobalRegion() {
}
@Override
public boolean isGlobal() {
return true;
}
@Override
public boolean isWallRegion() {
return false;
}
@Override
public boolean isLandRegion() {
return false;
}
@Override
public boolean isWaterRegion() {
return false;
}
@Override
public HasFlagResult hasFlag(Flag flag) {
return switch (flag) {
case TNT, FIRE, FREEZE, ITEMS -> HasFlagResult.WRITABLE;
default -> HasFlagResult.NOT_APPLICABLE;
};
}
@Override
public void setFlag(Flag flag, Flag.Value<?> value) {
}
@Override
public Flag.Value<?> getFlag(Flag flagType) {
return null;
}
@Override
public Point getMinPoint() {
return new Point(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
}
@Override
public Point getMaxPoint() {
return new Point(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
}
@Override
public boolean inRegion(Location location) {
return true;
}
@Override
public Optional<Point> getBuildMinPoint(boolean extension) {
return Optional.empty();
}
@Override
public Optional<Point> getBuildMaxPoint(boolean extension) {
return Optional.empty();
}
@Override
public boolean inBuildRegion(Location location, boolean extension) {
return false;
}
@Override
public Optional<Point> getTestblockMinPoint(boolean extension) {
return Optional.empty();
}
@Override
public Optional<Point> getTestblockMaxPoint(boolean extension) {
return Optional.empty();
}
@Override
public boolean inTestblockRegion(Location location, boolean extension) {
return false;
}
@Override
public void forEachChunk(ChunkCoordinatesConsumer consumer) {
}
@Override
public ChunkCoordinatePredicate getChunkOutsidePredicate() {
return (chunkX, chunkZ) -> false;
}
@Override
public Optional<ChunkCoordinatePredicate> getBuildChunkOutsidePredicate(boolean extension) {
return Optional.empty();
}
@Override
public Optional<ChunkCoordinatePredicate> getTestblockChunkOutsidePredicate(boolean extension) {
return Optional.empty();
}
@Override
public Optional<File> getGameModeConfig() {
return Optional.empty();
}
@Override
public Optional<EditSession> copy() {
return Optional.empty();
}
@Override
public Optional<EditSession> copyBuild(boolean extension) {
return Optional.empty();
}
@Override
public Optional<EditSession> copyTestblock(boolean extension) {
return Optional.empty();
}
@Override
public void reset() {
}
@Override
public void resetBuild(@Nullable SchematicNode schematicNode, boolean extension) {
}
@Override
public void resetBuildWireframe(boolean extension) {
}
@Override
public void resetTestblock(@Nullable SchematicNode schematicNode, boolean extension) {
}
@Override
public void remember(EditSession editSession) {
}
@Override
public boolean undo() {
return false;
}
@Override
public boolean redo() {
return false;
}
}

Datei anzeigen

@ -0,0 +1,123 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.regionnew;
import com.sk89q.worldedit.EditSession;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.regionnew.modular.ModularRegionSystem;
import de.steamwar.sql.SchematicNode;
import org.bukkit.Location;
import javax.annotation.Nullable;
import java.io.File;
import java.util.Optional;
public interface Region {
RegionSystem regionSystem = new ModularRegionSystem();
static Region get(Location location) {
return regionSystem.get(location);
}
enum HasFlagResult {
NOT_APPLICABLE,
READ_ONLY,
WRITABLE
}
interface ChunkCoordinatesConsumer {
void accept(int chunkX, int chunkZ);
}
interface ChunkCoordinatePredicate {
boolean test(int chunkX, int chunkZ);
}
boolean isGlobal();
boolean isWallRegion(); // TODO: IDK if this is needed
boolean isLandRegion(); // TODO: IDK if this is needed
boolean isWaterRegion(); // TODO: IDK if this is needed
HasFlagResult hasFlag(Flag flag);
void setFlag(Flag flag, Flag.Value<?> value);
Flag.Value<?> getFlag(Flag flagType);
default <T extends Enum<T> & Flag.Value<T>> T getFlagValue(Flag flagType) {
Flag.Value<?> value = getFlag(flagType);
if (value == null) return null;
return (T) value.getValue();
}
default <T extends Enum<T> & Flag.Value<T>> T getFlagValue(Flag flagType, Class<T> type) {
return getFlagValue(flagType);
}
Point getMinPoint();
Point getMaxPoint();
boolean inRegion(Location location);
/**
* Can return {@link Optional#empty()} if {@link #hasFlag(Flag)} returns false for the TestblockFlag
*/
Optional<Point> getBuildMinPoint(boolean extension);
/**
* Can return {@link Optional#empty()} if {@link #hasFlag(Flag)} returns false for the TestblockFlag
*/
Optional<Point> getBuildMaxPoint(boolean extension);
boolean inBuildRegion(Location location, boolean extension);
/**
* Can return {@link Optional#empty()} if {@link #hasFlag(Flag)} returns false for the TestblockFlag
*/
Optional<Point> getTestblockMinPoint(boolean extension);
/**
* Can return {@link Optional#empty()} if {@link #hasFlag(Flag)} returns false for the TestblockFlag
*/
Optional<Point> getTestblockMaxPoint(boolean extension);
boolean inTestblockRegion(Location location, boolean extension);
void forEachChunk(ChunkCoordinatesConsumer consumer);
ChunkCoordinatePredicate getChunkOutsidePredicate();
Optional<ChunkCoordinatePredicate> getBuildChunkOutsidePredicate(boolean extension);
Optional<ChunkCoordinatePredicate> getTestblockChunkOutsidePredicate(boolean extension);
Optional<File> getGameModeConfig();
Optional<EditSession> copy();
Optional<EditSession> copyBuild(boolean extension);
Optional<EditSession> copyTestblock(boolean extension);
void reset();
void resetBuild(@Nullable SchematicNode schematicNode, boolean extension);
void resetBuildWireframe(boolean extension);
void resetTestblock(@Nullable SchematicNode schematicNode, boolean extension);
void remember(EditSession editSession);
boolean undo();
boolean redo();
}

Datei anzeigen

@ -0,0 +1,38 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.regionnew;
import org.bukkit.Location;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;
public interface RegionSystem {
Region get(Location location);
Optional<Region> get(String name);
Stream<Region> getRegions();
boolean isModular();
// TODO: Add creating and removing of Regions as well as moving
}

Datei anzeigen

@ -0,0 +1,69 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.regionnew;
import org.bukkit.Location;
import org.bukkit.inventory.meta.MapMeta;
import java.util.Objects;
public class Tile {
private static final int MAX_X = 1024;
private static final int MAX_Z = 1024;
public static Tile of(Location location) {
int x = location.getBlockX() + 9;
int z = location.getBlockZ() + 9;
if (x < 0) x -= 19;
if (z < 0) z -= 19;
x /= 19;
z /= 19;
if (x < -MAX_X || x >= MAX_X || z < -MAX_Z || z >= MAX_Z) {
return null;
}
return new Tile(x, z);
}
private int tileX;
private int tileZ;
private Tile(int tileX, int tileZ) {
this.tileX = tileX;
this.tileZ = tileZ;
}
@Override
public boolean equals(Object object) {
if (this == object) return true;
if (!(object instanceof Tile tile)) return false;
return tileX == tile.tileX && tileZ == tile.tileZ;
}
@Override
public int hashCode() {
return Objects.hash(tileX, tileZ);
}
@Override
public String toString() {
return tileX + "/" + tileZ;
}
}

Datei anzeigen

@ -0,0 +1,198 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.regionnew.fixed;
import com.sk89q.worldedit.EditSession;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.TestblockMode;
import de.steamwar.bausystem.regionnew.Region;
import de.steamwar.sql.SchematicNode;
import org.bukkit.Location;
import javax.annotation.Nullable;
import java.io.File;
import java.util.Optional;
public class FixedRegionImpl implements Region { // TODO: Finalize this
@Override
public boolean isGlobal() {
return false;
}
@Override
public boolean isWallRegion() {
return false;
}
@Override
public boolean isLandRegion() {
return false;
}
@Override
public boolean isWaterRegion() {
return false;
}
@Override
public HasFlagResult hasFlag(Flag flag) {
return switch (flag) {
case TNT, FIRE, FREEZE, ITEMS, CHANGED -> HasFlagResult.WRITABLE;
case COLOR -> HasFlagResult.WRITABLE; // TODO Only for normal Regions not Spawn Region
case PROTECT -> HasFlagResult.WRITABLE; // TODO: Only for protectable Regions
case TESTBLOCK -> HasFlagResult.READ_ONLY; // TODO: Implement NOT_APPLICABLE for Special regions
};
}
@Override
public void setFlag(Flag flag, Flag.Value<?> value) {
}
@Override
public Flag.Value<?> getFlag(Flag flagType) {
if (flagType == Flag.TESTBLOCK) {
return TestblockMode.NO_VALUE; // TODO: This needs to change based on if the Region is a WarShip Region
}
return null;
}
@Override
public Point getMinPoint() {
return null;
}
@Override
public Point getMaxPoint() {
return null;
}
@Override
public boolean inRegion(Location location) {
return false;
}
@Override
public Optional<Point> getBuildMinPoint(boolean extension) {
return Optional.empty();
}
@Override
public Optional<Point> getBuildMaxPoint(boolean extension) {
return Optional.empty();
}
@Override
public boolean inBuildRegion(Location location, boolean extension) {
return false;
}
@Override
public Optional<Point> getTestblockMinPoint(boolean extension) {
return Optional.empty();
}
@Override
public Optional<Point> getTestblockMaxPoint(boolean extension) {
return Optional.empty();
}
@Override
public boolean inTestblockRegion(Location location, boolean extension) {
return false;
}
@Override
public void forEachChunk(ChunkCoordinatesConsumer consumer) {
}
@Override
public ChunkCoordinatePredicate getChunkOutsidePredicate() {
return null;
}
@Override
public Optional<ChunkCoordinatePredicate> getBuildChunkOutsidePredicate(boolean extension) {
return Optional.empty();
}
@Override
public Optional<ChunkCoordinatePredicate> getTestblockChunkOutsidePredicate(boolean extension) {
return Optional.empty();
}
@Override
public Optional<File> getGameModeConfig() {
return Optional.empty();
}
@Override
public Optional<EditSession> copy() {
return Optional.empty();
}
@Override
public Optional<EditSession> copyBuild(boolean extension) {
return Optional.empty();
}
@Override
public Optional<EditSession> copyTestblock(boolean extension) {
return Optional.empty();
}
@Override
public void reset() {
}
@Override
public void resetBuild(@Nullable SchematicNode schematicNode, boolean extension) {
}
@Override
public void resetBuildWireframe(boolean extension) {
}
@Override
public void resetTestblock(@Nullable SchematicNode schematicNode, boolean extension) {
}
@Override
public void remember(EditSession editSession) {
}
@Override
public boolean undo() {
return false;
}
@Override
public boolean redo() {
return false;
}
}

Datei anzeigen

@ -0,0 +1,58 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.regionnew.fixed;
import de.steamwar.bausystem.regionnew.GlobalRegion;
import de.steamwar.bausystem.regionnew.Region;
import de.steamwar.bausystem.regionnew.RegionSystem;
import org.bukkit.Location;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
public class FixedRegionSystem implements RegionSystem {
private static final Map<String, Region> REGION_MAP = new HashMap<>();
@Override
public Region get(Location location) {
return REGION_MAP.values().stream()
.filter(region -> region.inRegion(location))
.findFirst()
.orElse(GlobalRegion.GLOBAL_REGION);
}
@Override
public Optional<Region> get(String name) {
return Optional.ofNullable(REGION_MAP.get(name));
}
@Override
public Stream<Region> getRegions() {
return REGION_MAP.values().stream();
}
@Override
public boolean isModular() {
return false;
}
}

Datei anzeigen

@ -0,0 +1,67 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 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.regionnew.modular;
import de.steamwar.bausystem.regionnew.GlobalRegion;
import de.steamwar.bausystem.regionnew.Region;
import de.steamwar.bausystem.regionnew.RegionSystem;
import de.steamwar.bausystem.regionnew.Tile;
import org.bukkit.Location;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Stream;
public class ModularRegionSystem implements RegionSystem {
private Map<Tile, UUID> OCCUPIED_TILES = new HashMap<>();
private Map<UUID, Region> REGIONS = new HashMap<>();
private Map<String, Region> REGIONS_BY_NAME = new HashMap<>();
@Override
public Region get(Location location) {
Tile tile = Tile.of(location);
if (tile == null) {
return GlobalRegion.GLOBAL_REGION;
}
UUID uuid = OCCUPIED_TILES.get(tile);
if (uuid == null) {
return GlobalRegion.GLOBAL_REGION;
}
return REGIONS.get(uuid);
}
@Override
public Optional<Region> get(String name) {
return Optional.ofNullable(REGIONS_BY_NAME.get(name));
}
@Override
public Stream<Region> getRegions() {
return REGIONS.values().stream();
}
@Override
public boolean isModular() {
return true;
}
}