Add FixedRegionSystem and ModularRegionSystem
Dieser Commit ist enthalten in:
Ursprung
5c48983375
Commit
11a0bdbe8d
@ -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));
|
||||
|
@ -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
|
||||
|
@ -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 <T extends Enum<T> & Flag.Value<T>> 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<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();
|
||||
}
|
||||
|
@ -28,6 +28,9 @@ import java.util.stream.Stream;
|
||||
|
||||
public interface RegionSystem {
|
||||
|
||||
void load();
|
||||
void save();
|
||||
|
||||
Region get(Location location);
|
||||
Optional<Region> get(String name);
|
||||
|
||||
|
56
BauSystem_RegionFixed/build.gradle
Normale Datei
56
BauSystem_RegionFixed/build.gradle
Normale Datei
@ -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')
|
||||
}
|
@ -17,10 +17,9 @@
|
||||
* 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 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
|
@ -17,11 +17,12 @@
|
||||
* 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.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<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()
|
56
BauSystem_RegionModular/build.gradle
Normale Datei
56
BauSystem_RegionModular/build.gradle
Normale Datei
@ -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')
|
||||
}
|
@ -17,12 +17,12 @@
|
||||
* 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.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<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);
|
||||
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<Region> get(String name) {
|
||||
return Optional.ofNullable(REGIONS_BY_NAME.get(name));
|
@ -17,12 +17,13 @@
|
||||
* 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.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<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;
|
@ -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()));
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren