Commits vergleichen

...

3 Commits

Autor SHA1 Nachricht Datum
yoyosource
6bd8350fa5 Fix things!
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
2024-04-21 16:15:32 +02:00
yoyosource
11a0bdbe8d Add FixedRegionSystem and ModularRegionSystem 2024-04-21 16:13:39 +02:00
yoyosource
5c48983375 TYPEREPLACE_HELPAdd initial modular bau impl 2024-04-21 16:13:33 +02:00
17 geänderte Dateien mit 2315 neuen und 982 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,9 +23,12 @@ 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;
import de.steamwar.bausystem.regionnew.Region;
import de.steamwar.bausystem.utils.TickListener;
import de.steamwar.bausystem.worlddata.WorldData;
import de.steamwar.command.AbstractValidator;
@ -33,6 +36,7 @@ import de.steamwar.command.SWCommandUtils;
import de.steamwar.message.Message;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
@ -40,6 +44,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 +71,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 +84,11 @@ public class BauSystem extends JavaPlugin implements Listener {
new Updater(PrototypeLoader.file, PrototypeLoader::load);
new Updater(RegionLoader.file, RegionLoader::load);
*/
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
Region.get(new Location(Bukkit.getWorlds().get(0), 0, 0, 0));
}, 10);
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

@ -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,176 @@
/*
* 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 RegionType getRegionType() {
return RegionType.GLOBAL;
}
@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,160 @@
/*
* 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 lombok.RequiredArgsConstructor;
import org.bukkit.Location;
import javax.annotation.Nullable;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
public interface Region {
RegionSystem regionSystem = load();
private static RegionSystem load() {
try {
return (RegionSystem) Class.forName("de.steamwar.bausystem.region.ModularRegionSystem").getConstructor().newInstance();
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException |
IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
static Region get(Location location) {
return regionSystem.get(location);
}
enum HasFlagResult {
NOT_APPLICABLE,
READ_ONLY,
WRITABLE
}
@RequiredArgsConstructor
enum RegionType {
GLOBAL(false, false, false, true),
WATER(true, false, false, false),
WATER_CONNECTING(true, false, false, false),
LAND(false, true, false, false),
LAND_CONNECTING(false, true, false, false),
WALL(false, false, true, false),
OLD(false, false, false, false),
;
public final boolean water;
public final boolean land;
public final boolean wall;
public final boolean global;
}
interface ChunkCoordinatesConsumer {
void accept(int chunkX, int chunkZ);
}
interface ChunkCoordinatePredicate {
boolean test(int chunkX, int chunkZ);
}
RegionType getRegionType();
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,41 @@
/*
* 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 {
void load();
void save();
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,56 @@
/*
* 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/>.
*/
plugins {
id 'base'
id 'java'
}
group 'steamwar'
version '1.0'
compileJava.options.encoding = 'UTF-8'
sourceCompatibility = 17
targetCompatibility = 17
sourceSets {
main {
java {
srcDirs = ['src/']
}
resources {
srcDirs = ['src/']
exclude '**/*.java', '**/*.kt'
}
}
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.22'
testCompileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
implementation project(":BauSystem_Main")
compileOnly 'org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT'
compileOnly swdep('SpigotCore')
compileOnly swdep('FastAsyncWorldEdit-1.18')
}

Datei anzeigen

@ -0,0 +1,182 @@
/*
* 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 com.sk89q.worldedit.EditSession;
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 RegionType getRegionType() {
return RegionType.OLD;
}
@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,76 @@
/*
* 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.GlobalRegion;
import de.steamwar.bausystem.regionnew.Region;
import de.steamwar.bausystem.regionnew.RegionSystem;
import lombok.Getter;
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 {
@Getter
private static FixedRegionSystem instance;
public FixedRegionSystem() {
instance = this;
}
private static final Map<String, Region> REGION_MAP = new HashMap<>();
@Override
public void load() {
// TODO: Add Load
}
@Override
public void save() {
// TODO: Add Save
}
@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,56 @@
/*
* 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/>.
*/
plugins {
id 'base'
id 'java'
}
group 'steamwar'
version '1.0'
compileJava.options.encoding = 'UTF-8'
sourceCompatibility = 17
targetCompatibility = 17
sourceSets {
main {
java {
srcDirs = ['src/']
}
resources {
srcDirs = ['src/']
exclude '**/*.java', '**/*.kt'
}
}
}
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.22'
testCompileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
implementation project(":BauSystem_Main")
compileOnly 'org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT'
compileOnly swdep('SpigotCore')
compileOnly swdep('FastAsyncWorldEdit-1.18')
}

Datei anzeigen

@ -0,0 +1,88 @@
/*
* 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.GlobalRegion;
import de.steamwar.bausystem.regionnew.Region;
import de.steamwar.bausystem.regionnew.RegionSystem;
import lombok.Getter;
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 {
@Getter
private static ModularRegionSystem instance;
public ModularRegionSystem() {
instance = this;
new TileActionBar();
}
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 void load() {
// TODO: Add Load
}
@Override
public void save() {
// TODO: Add Save
}
public Region get(Tile tile) {
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 Region get(Location location) {
return get(Tile.of(location));
}
@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;
}
}

Datei anzeigen

@ -0,0 +1,101 @@
/*
* 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 org.bukkit.Location;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
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;
}
public Tile offset(int tileDx, int tileDz) {
int tileX = this.tileX + tileDx;
int tileZ = this.tileZ + tileDz;
if (tileX < -MAX_X || tileX >= MAX_X || tileZ < -MAX_Z || tileZ >= MAX_Z) {
return null;
}
return new Tile(tileX, tileZ);
}
public Set<Tile> surrounding() {
Set<Tile> tiles = new HashSet<>();
for (int dx = -1; dx <= 1; dx++) {
for (int dz = -1; dz <= 1; dz++) {
if (dx == 0 && dz == 0) continue;
tiles.add(offset(dx, dz));
}
}
tiles.remove(null);
return tiles;
}
public Set<Tile> adjacent() {
Set<Tile> tiles = new HashSet<>();
tiles.add(offset(-1, 0));
tiles.add(offset(1, 0));
tiles.add(offset(0, -1));
tiles.add(offset(0, 1));
tiles.remove(null);
return tiles;
}
@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,45 @@
/*
* 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.BauSystem;
import de.steamwar.bausystem.regionnew.Region;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
public class TileActionBar implements Listener {
public TileActionBar() {
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Tile tile = Tile.of(event.getTo());
Region region = Region.get(event.getTo());
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§e" + tile + " §8- §e" + region.getClass().getSimpleName()));
}
}