forked from SteamWar/SteamWar
Update initial RegionVisualizer and Editor
This commit is contained in:
+6
-3
@@ -21,7 +21,6 @@ package de.steamwar.bausystem.region;
|
||||
|
||||
import de.steamwar.bausystem.Permission;
|
||||
import de.steamwar.bausystem.features.region.RegionCommand;
|
||||
import de.steamwar.bausystem.region.dynamic.Tile;
|
||||
import de.steamwar.command.AbstractSWCommand;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.core.SWPlayer;
|
||||
@@ -37,10 +36,14 @@ public class DynamicRegionCommand extends SWCommand {
|
||||
@Register({"dynamic"})
|
||||
public void visualizeRegions(Player player) {
|
||||
SWPlayer swPlayer = SWPlayer.of(player);
|
||||
if (swPlayer.hasComponent(DynamicRegionEditor2.class)) {
|
||||
if (swPlayer.hasComponent(DynamicRegionVisualizer2.class)) {
|
||||
swPlayer.removeComponent(DynamicRegionVisualizer2.class);
|
||||
swPlayer.removeComponent(DynamicRegionEditor2.class);
|
||||
} else {
|
||||
swPlayer.setComponent(new DynamicRegionEditor2());
|
||||
swPlayer.setComponent(DynamicRegionVisualizer2.INSTANCE);
|
||||
if (Permission.SUPERVISOR.hasPermission(player)) {
|
||||
swPlayer.setComponent(new DynamicRegionEditor2());
|
||||
}
|
||||
}
|
||||
if (true) return;
|
||||
if (swPlayer.hasComponent(DynamicRegionVisualizer.class)) {
|
||||
|
||||
-43
@@ -19,58 +19,15 @@
|
||||
|
||||
package de.steamwar.bausystem.region;
|
||||
|
||||
import de.steamwar.bausystem.region.dynamic.RegionConstructorData;
|
||||
import de.steamwar.bausystem.region.dynamic.Tile;
|
||||
import de.steamwar.bausystem.region.dynamic.path.PathRegion;
|
||||
import de.steamwar.core.SWPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class DynamicRegionEditor2 implements SWPlayer.Component {
|
||||
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
private static final int ORIGIN_X = 10000;
|
||||
private static final int ORIGIN_Z = 10000;
|
||||
|
||||
public DynamicRegionEditor2() {
|
||||
DynamicRegionSystem.INSTANCE.getRegions().forEach(region -> {
|
||||
RegionConstructorData data = DynamicRegionSystem.constructorDataMap.get(region.getClass());
|
||||
if (data == null) return;
|
||||
int widthX = data.widthX();
|
||||
int widthZ = data.widthZ();
|
||||
|
||||
Material material = data.material();
|
||||
if (region instanceof PathRegion pathRegion && pathRegion.isGarden()) {
|
||||
material = Material.GRASS_BLOCK;
|
||||
}
|
||||
|
||||
Tile tile = Tile.fromPoint(region.getArea().getMinPoint(false)).orElseThrow();
|
||||
for (int x = 0; x < widthX; x++) {
|
||||
for (int z = 0; z < widthZ; z++) {
|
||||
int cx = x + tile.getTileX() + ORIGIN_X;
|
||||
int cz = z + tile.getTileZ() + ORIGIN_Z;
|
||||
WORLD.getBlockAt(cx, 1, cz).setType(material, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMount(SWPlayer player) {
|
||||
Location location = player.getPlayer().getLocation().clone().multiply(1.0 / Tile.tileSize).add(ORIGIN_X + 0.5, 0, ORIGIN_Z + 0.5);
|
||||
location.setY(10);
|
||||
player.getPlayer().teleport(location);
|
||||
// TODO: Add anything that is needed for setup
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnmount(SWPlayer player) {
|
||||
Location location = player.getPlayer().getLocation().clone().subtract(ORIGIN_X + 0.5, 0, ORIGIN_Z + 0.5).multiply(Tile.tileSize);
|
||||
location.setY(50);
|
||||
player.getPlayer().teleport(location.add(0.5, 0, 0.5));
|
||||
// TODO: Add anything that is needed for shutdown
|
||||
}
|
||||
}
|
||||
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2026 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.region.dynamic.RegionConstructorData;
|
||||
import de.steamwar.bausystem.region.dynamic.Tile;
|
||||
import de.steamwar.bausystem.region.dynamic.path.PathRegion;
|
||||
import de.steamwar.core.SWPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class DynamicRegionVisualizer2 implements SWPlayer.Component {
|
||||
|
||||
public static final DynamicRegionVisualizer2 INSTANCE = new DynamicRegionVisualizer2();
|
||||
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
private static final int ORIGIN_X = 10000;
|
||||
private static final int ORIGIN_Z = 10000;
|
||||
|
||||
public DynamicRegionVisualizer2() {
|
||||
if (true) return;
|
||||
// TODO: This is only needed once on startup with a clear beforehand to make the region visualization up to date with the Region Data
|
||||
DynamicRegionSystem.INSTANCE.getRegions().forEach(region -> {
|
||||
RegionConstructorData data = DynamicRegionSystem.constructorDataMap.get(region.getClass());
|
||||
if (data == null) return;
|
||||
int widthX = data.widthX();
|
||||
int widthZ = data.widthZ();
|
||||
|
||||
Material material = data.material();
|
||||
if (region instanceof PathRegion pathRegion && pathRegion.isGarden()) {
|
||||
material = Material.GRASS_BLOCK;
|
||||
}
|
||||
|
||||
Tile tile = Tile.fromPoint(region.getArea().getMinPoint(false)).orElseThrow();
|
||||
for (int x = 0; x < widthX; x++) {
|
||||
for (int z = 0; z < widthZ; z++) {
|
||||
int cx = x + tile.getTileX() + ORIGIN_X;
|
||||
int cz = z + tile.getTileZ() + ORIGIN_Z;
|
||||
WORLD.getBlockAt(cx, 1, cz).setType(material, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMount(SWPlayer player) {
|
||||
Location location = player.getPlayer().getLocation().clone().multiply(1.0 / Tile.tileSize).add(ORIGIN_X + 0.5, 0, ORIGIN_Z + 0.5);
|
||||
location.setY(10);
|
||||
player.getPlayer().teleport(location);
|
||||
// TODO: Add anything that is needed for setup
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnmount(SWPlayer player) {
|
||||
Location location = player.getPlayer().getLocation().clone().subtract(ORIGIN_X + 0.5, 0, ORIGIN_Z + 0.5).multiply(Tile.tileSize);
|
||||
location.setY(50);
|
||||
player.getPlayer().teleport(location.add(0.5, 0, 0.5));
|
||||
// TODO: Add anything that is needed for shutdown
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user