diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 1b346af5..85e5fc97 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -28,6 +28,7 @@ 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; @@ -35,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; @@ -84,6 +86,10 @@ public class BauSystem extends JavaPlugin implements Listener { 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)); SWCommandUtils.addValidator("supervisor", validator(Permission.SUPERVISOR)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/regionnew/GlobalRegion.java b/BauSystem_Main/src/de/steamwar/bausystem/regionnew/GlobalRegion.java index ba9ac44c..7e504d31 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/regionnew/GlobalRegion.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/regionnew/GlobalRegion.java @@ -37,23 +37,8 @@ public class GlobalRegion implements Region { } @Override - public boolean isGlobal() { - return true; - } - - @Override - public boolean isWallRegion() { - return false; - } - - @Override - public boolean isLandRegion() { - return false; - } - - @Override - public boolean isWaterRegion() { - return false; + public RegionType getRegionType() { + return RegionType.GLOBAL; } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Region.java index 73f284a4..c233723c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Region.java @@ -22,17 +22,28 @@ 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 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 = new ModularRegionSystem(); + 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); @@ -44,6 +55,23 @@ public interface Region { 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); } @@ -52,13 +80,12 @@ public interface Region { 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 + RegionType getRegionType(); HasFlagResult hasFlag(Flag flag); + void setFlag(Flag flag, Flag.Value value); + Flag.Value getFlag(Flag flagType); default & Flag.Value> T getFlagValue(Flag flagType) { @@ -72,6 +99,7 @@ public interface Region { } Point getMinPoint(); + Point getMaxPoint(); boolean inRegion(Location location); @@ -103,21 +131,30 @@ public interface Region { void forEachChunk(ChunkCoordinatesConsumer consumer); ChunkCoordinatePredicate getChunkOutsidePredicate(); + Optional getBuildChunkOutsidePredicate(boolean extension); + Optional getTestblockChunkOutsidePredicate(boolean extension); Optional getGameModeConfig(); Optional copy(); + Optional copyBuild(boolean extension); + Optional 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(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionSystem.java index 11564e1e..242e7a41 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/regionnew/RegionSystem.java @@ -28,6 +28,9 @@ import java.util.stream.Stream; public interface RegionSystem { + void load(); + void save(); + Region get(Location location); Optional get(String name); diff --git a/BauSystem_RegionFixed/build.gradle b/BauSystem_RegionFixed/build.gradle new file mode 100644 index 00000000..265010a8 --- /dev/null +++ b/BauSystem_RegionFixed/build.gradle @@ -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 . + */ + +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') +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/regionnew/fixed/FixedRegionImpl.java b/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionImpl.java similarity index 92% rename from BauSystem_Main/src/de/steamwar/bausystem/regionnew/fixed/FixedRegionImpl.java rename to BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionImpl.java index 7a02c60c..d03ec90c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/regionnew/fixed/FixedRegionImpl.java +++ b/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionImpl.java @@ -17,10 +17,9 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew.fixed; +package de.steamwar.bausystem.region; 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; @@ -34,23 +33,8 @@ 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; + public RegionType getRegionType() { + return RegionType.OLD; } @Override diff --git a/BauSystem_Main/src/de/steamwar/bausystem/regionnew/fixed/FixedRegionSystem.java b/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionSystem.java similarity index 84% rename from BauSystem_Main/src/de/steamwar/bausystem/regionnew/fixed/FixedRegionSystem.java rename to BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionSystem.java index 1b076a82..28ebe7c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/regionnew/fixed/FixedRegionSystem.java +++ b/BauSystem_RegionFixed/src/de/steamwar/bausystem/region/FixedRegionSystem.java @@ -17,11 +17,12 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew.fixed; +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; @@ -31,8 +32,25 @@ import java.util.stream.Stream; public class FixedRegionSystem implements RegionSystem { + @Getter + private static FixedRegionSystem instance; + + public FixedRegionSystem() { + instance = this; + } + private static final Map 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() diff --git a/BauSystem_RegionModular/build.gradle b/BauSystem_RegionModular/build.gradle new file mode 100644 index 00000000..265010a8 --- /dev/null +++ b/BauSystem_RegionModular/build.gradle @@ -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 . + */ + +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') +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/regionnew/modular/ModularRegionSystem.java b/BauSystem_RegionModular/src/de/steamwar/bausystem/region/ModularRegionSystem.java similarity index 81% rename from BauSystem_Main/src/de/steamwar/bausystem/regionnew/modular/ModularRegionSystem.java rename to BauSystem_RegionModular/src/de/steamwar/bausystem/region/ModularRegionSystem.java index b00c96c5..53a2db81 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/regionnew/modular/ModularRegionSystem.java +++ b/BauSystem_RegionModular/src/de/steamwar/bausystem/region/ModularRegionSystem.java @@ -17,12 +17,12 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew.modular; +package de.steamwar.bausystem.region; 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 lombok.Getter; import org.bukkit.Location; import java.util.HashMap; @@ -33,13 +33,29 @@ import java.util.stream.Stream; public class ModularRegionSystem implements RegionSystem { + @Getter + private static ModularRegionSystem instance; + + public ModularRegionSystem() { + instance = this; + new TileActionBar(); + } + private Map OCCUPIED_TILES = new HashMap<>(); private Map REGIONS = new HashMap<>(); private Map REGIONS_BY_NAME = new HashMap<>(); @Override - public Region get(Location location) { - Tile tile = Tile.of(location); + 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; } @@ -50,6 +66,11 @@ public class ModularRegionSystem implements RegionSystem { return REGIONS.get(uuid); } + @Override + public Region get(Location location) { + return get(Tile.of(location)); + } + @Override public Optional get(String name) { return Optional.ofNullable(REGIONS_BY_NAME.get(name)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Tile.java b/BauSystem_RegionModular/src/de/steamwar/bausystem/region/Tile.java similarity index 65% rename from BauSystem_Main/src/de/steamwar/bausystem/regionnew/Tile.java rename to BauSystem_RegionModular/src/de/steamwar/bausystem/region/Tile.java index 5bb7d9e5..ea3a12da 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/regionnew/Tile.java +++ b/BauSystem_RegionModular/src/de/steamwar/bausystem/region/Tile.java @@ -17,12 +17,13 @@ * along with this program. If not, see . */ -package de.steamwar.bausystem.regionnew; +package de.steamwar.bausystem.region; import org.bukkit.Location; -import org.bukkit.inventory.meta.MapMeta; +import java.util.HashSet; import java.util.Objects; +import java.util.Set; public class Tile { @@ -50,6 +51,37 @@ public class Tile { 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 surrounding() { + Set 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 adjacent() { + Set 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; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/TileActionBar.java b/BauSystem_RegionModular/src/de/steamwar/bausystem/region/TileActionBar.java similarity index 74% rename from BauSystem_Main/src/de/steamwar/bausystem/region/TileActionBar.java rename to BauSystem_RegionModular/src/de/steamwar/bausystem/region/TileActionBar.java index c74df585..86d55c90 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/TileActionBar.java +++ b/BauSystem_RegionModular/src/de/steamwar/bausystem/region/TileActionBar.java @@ -19,19 +19,27 @@ package de.steamwar.bausystem.region; -import de.steamwar.bausystem.regionnew.Tile; -import de.steamwar.linkage.Linked; +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; -@Linked + public class TileActionBar implements Listener { + public TileActionBar() { + Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance()); + } + @EventHandler public void onPlayerMove(PlayerMoveEvent event) { - event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§e" + Tile.of(event.getTo()))); + 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())); } }