SteamWar/BauSystem2.0
Archiviert
12
0

Add FixedRegionSystem and ModularRegionSystem

Dieser Commit ist enthalten in:
yoyosource 2024-03-12 15:01:21 +01:00
Ursprung 5c48983375
Commit 11a0bdbe8d
11 geänderte Dateien mit 259 neuen und 53 gelöschten Zeilen

Datei anzeigen

@ -28,6 +28,7 @@ import de.steamwar.bausystem.region.GlobalRegion;
import de.steamwar.bausystem.region.loader.PrototypeLoader; import de.steamwar.bausystem.region.loader.PrototypeLoader;
import de.steamwar.bausystem.region.loader.RegionLoader; import de.steamwar.bausystem.region.loader.RegionLoader;
import de.steamwar.bausystem.region.loader.Updater; import de.steamwar.bausystem.region.loader.Updater;
import de.steamwar.bausystem.regionnew.Region;
import de.steamwar.bausystem.utils.TickListener; import de.steamwar.bausystem.utils.TickListener;
import de.steamwar.bausystem.worlddata.WorldData; import de.steamwar.bausystem.worlddata.WorldData;
import de.steamwar.command.AbstractValidator; import de.steamwar.command.AbstractValidator;
@ -35,6 +36,7 @@ import de.steamwar.command.SWCommandUtils;
import de.steamwar.message.Message; import de.steamwar.message.Message;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -84,6 +86,10 @@ public class BauSystem extends JavaPlugin implements Listener {
new Updater(RegionLoader.file, RegionLoader::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(Player.class, validator(Permission.BUILD));
SWCommandUtils.addValidator(CommandSender.class, validator(Permission.BUILD)); SWCommandUtils.addValidator(CommandSender.class, validator(Permission.BUILD));
SWCommandUtils.addValidator("supervisor", validator(Permission.SUPERVISOR)); SWCommandUtils.addValidator("supervisor", validator(Permission.SUPERVISOR));

Datei anzeigen

@ -37,23 +37,8 @@ public class GlobalRegion implements Region {
} }
@Override @Override
public boolean isGlobal() { public RegionType getRegionType() {
return true; return RegionType.GLOBAL;
}
@Override
public boolean isWallRegion() {
return false;
}
@Override
public boolean isLandRegion() {
return false;
}
@Override
public boolean isWaterRegion() {
return false;
} }
@Override @Override

Datei anzeigen

@ -22,17 +22,28 @@ package de.steamwar.bausystem.regionnew;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.regionnew.modular.ModularRegionSystem;
import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SchematicNode;
import lombok.RequiredArgsConstructor;
import org.bukkit.Location; import org.bukkit.Location;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.File; import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional; import java.util.Optional;
public interface Region { 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) { static Region get(Location location) {
return regionSystem.get(location); return regionSystem.get(location);
@ -44,6 +55,23 @@ public interface Region {
WRITABLE 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 { interface ChunkCoordinatesConsumer {
void accept(int chunkX, int chunkZ); void accept(int chunkX, int chunkZ);
} }
@ -52,13 +80,12 @@ public interface Region {
boolean test(int chunkX, int chunkZ); boolean test(int chunkX, int chunkZ);
} }
boolean isGlobal(); RegionType getRegionType();
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); HasFlagResult hasFlag(Flag flag);
void setFlag(Flag flag, Flag.Value<?> value); void setFlag(Flag flag, Flag.Value<?> value);
Flag.Value<?> getFlag(Flag flagType); Flag.Value<?> getFlag(Flag flagType);
default <T extends Enum<T> & Flag.Value<T>> T getFlagValue(Flag flagType) { default <T extends Enum<T> & Flag.Value<T>> T getFlagValue(Flag flagType) {
@ -72,6 +99,7 @@ public interface Region {
} }
Point getMinPoint(); Point getMinPoint();
Point getMaxPoint(); Point getMaxPoint();
boolean inRegion(Location location); boolean inRegion(Location location);
@ -103,21 +131,30 @@ public interface Region {
void forEachChunk(ChunkCoordinatesConsumer consumer); void forEachChunk(ChunkCoordinatesConsumer consumer);
ChunkCoordinatePredicate getChunkOutsidePredicate(); ChunkCoordinatePredicate getChunkOutsidePredicate();
Optional<ChunkCoordinatePredicate> getBuildChunkOutsidePredicate(boolean extension); Optional<ChunkCoordinatePredicate> getBuildChunkOutsidePredicate(boolean extension);
Optional<ChunkCoordinatePredicate> getTestblockChunkOutsidePredicate(boolean extension); Optional<ChunkCoordinatePredicate> getTestblockChunkOutsidePredicate(boolean extension);
Optional<File> getGameModeConfig(); Optional<File> getGameModeConfig();
Optional<EditSession> copy(); Optional<EditSession> copy();
Optional<EditSession> copyBuild(boolean extension); Optional<EditSession> copyBuild(boolean extension);
Optional<EditSession> copyTestblock(boolean extension); Optional<EditSession> copyTestblock(boolean extension);
void reset(); void reset();
void resetBuild(@Nullable SchematicNode schematicNode, boolean extension); void resetBuild(@Nullable SchematicNode schematicNode, boolean extension);
void resetBuildWireframe(boolean extension); void resetBuildWireframe(boolean extension);
void resetTestblock(@Nullable SchematicNode schematicNode, boolean extension); void resetTestblock(@Nullable SchematicNode schematicNode, boolean extension);
void remember(EditSession editSession); void remember(EditSession editSession);
boolean undo(); boolean undo();
boolean redo(); boolean redo();
} }

Datei anzeigen

@ -28,6 +28,9 @@ import java.util.stream.Stream;
public interface RegionSystem { public interface RegionSystem {
void load();
void save();
Region get(Location location); Region get(Location location);
Optional<Region> get(String name); Optional<Region> get(String name);

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

@ -17,10 +17,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.regionnew.fixed; package de.steamwar.bausystem.region;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.TestblockMode; import de.steamwar.bausystem.region.flags.flagvalues.TestblockMode;
import de.steamwar.bausystem.regionnew.Region; import de.steamwar.bausystem.regionnew.Region;
@ -34,23 +33,8 @@ import java.util.Optional;
public class FixedRegionImpl implements Region { // TODO: Finalize this public class FixedRegionImpl implements Region { // TODO: Finalize this
@Override @Override
public boolean isGlobal() { public RegionType getRegionType() {
return false; return RegionType.OLD;
}
@Override
public boolean isWallRegion() {
return false;
}
@Override
public boolean isLandRegion() {
return false;
}
@Override
public boolean isWaterRegion() {
return false;
} }
@Override @Override

Datei anzeigen

@ -17,11 +17,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.regionnew.fixed; package de.steamwar.bausystem.region;
import de.steamwar.bausystem.regionnew.GlobalRegion; import de.steamwar.bausystem.regionnew.GlobalRegion;
import de.steamwar.bausystem.regionnew.Region; import de.steamwar.bausystem.regionnew.Region;
import de.steamwar.bausystem.regionnew.RegionSystem; import de.steamwar.bausystem.regionnew.RegionSystem;
import lombok.Getter;
import org.bukkit.Location; import org.bukkit.Location;
import java.util.HashMap; import java.util.HashMap;
@ -31,8 +32,25 @@ import java.util.stream.Stream;
public class FixedRegionSystem implements RegionSystem { public class FixedRegionSystem implements RegionSystem {
@Getter
private static FixedRegionSystem instance;
public FixedRegionSystem() {
instance = this;
}
private static final Map<String, Region> REGION_MAP = new HashMap<>(); 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 @Override
public Region get(Location location) { public Region get(Location location) {
return REGION_MAP.values().stream() return REGION_MAP.values().stream()

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

@ -17,12 +17,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.regionnew.modular; package de.steamwar.bausystem.region;
import de.steamwar.bausystem.regionnew.GlobalRegion; import de.steamwar.bausystem.regionnew.GlobalRegion;
import de.steamwar.bausystem.regionnew.Region; import de.steamwar.bausystem.regionnew.Region;
import de.steamwar.bausystem.regionnew.RegionSystem; import de.steamwar.bausystem.regionnew.RegionSystem;
import de.steamwar.bausystem.regionnew.Tile; import lombok.Getter;
import org.bukkit.Location; import org.bukkit.Location;
import java.util.HashMap; import java.util.HashMap;
@ -33,13 +33,29 @@ import java.util.stream.Stream;
public class ModularRegionSystem implements RegionSystem { 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<Tile, UUID> OCCUPIED_TILES = new HashMap<>();
private Map<UUID, Region> REGIONS = new HashMap<>(); private Map<UUID, Region> REGIONS = new HashMap<>();
private Map<String, Region> REGIONS_BY_NAME = new HashMap<>(); private Map<String, Region> REGIONS_BY_NAME = new HashMap<>();
@Override @Override
public Region get(Location location) { public void load() {
Tile tile = Tile.of(location); // TODO: Add Load
}
@Override
public void save() {
// TODO: Add Save
}
public Region get(Tile tile) {
if (tile == null) { if (tile == null) {
return GlobalRegion.GLOBAL_REGION; return GlobalRegion.GLOBAL_REGION;
} }
@ -50,6 +66,11 @@ public class ModularRegionSystem implements RegionSystem {
return REGIONS.get(uuid); return REGIONS.get(uuid);
} }
@Override
public Region get(Location location) {
return get(Tile.of(location));
}
@Override @Override
public Optional<Region> get(String name) { public Optional<Region> get(String name) {
return Optional.ofNullable(REGIONS_BY_NAME.get(name)); return Optional.ofNullable(REGIONS_BY_NAME.get(name));

Datei anzeigen

@ -17,12 +17,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package de.steamwar.bausystem.regionnew; package de.steamwar.bausystem.region;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.inventory.meta.MapMeta;
import java.util.HashSet;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
public class Tile { public class Tile {
@ -50,6 +51,37 @@ public class Tile {
this.tileZ = tileZ; 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 @Override
public boolean equals(Object object) { public boolean equals(Object object) {
if (this == object) return true; if (this == object) return true;

Datei anzeigen

@ -19,19 +19,27 @@
package de.steamwar.bausystem.region; package de.steamwar.bausystem.region;
import de.steamwar.bausystem.regionnew.Tile; import de.steamwar.bausystem.BauSystem;
import de.steamwar.linkage.Linked; import de.steamwar.bausystem.regionnew.Region;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
@Linked
public class TileActionBar implements Listener { public class TileActionBar implements Listener {
public TileActionBar() {
Bukkit.getPluginManager().registerEvents(this, BauSystem.getInstance());
}
@EventHandler @EventHandler
public void onPlayerMove(PlayerMoveEvent event) { 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()));
} }
} }