forked from SteamWar/SteamWar
Update DynamicRegionCommand
This commit is contained in:
+6
@@ -37,6 +37,12 @@ public class DynamicRegionCommand extends SWCommand {
|
|||||||
@Register({"dynamic"})
|
@Register({"dynamic"})
|
||||||
public void visualizeRegions(Player player) {
|
public void visualizeRegions(Player player) {
|
||||||
SWPlayer swPlayer = SWPlayer.of(player);
|
SWPlayer swPlayer = SWPlayer.of(player);
|
||||||
|
if (swPlayer.hasComponent(DynamicRegionEditor2.class)) {
|
||||||
|
swPlayer.removeComponent(DynamicRegionEditor2.class);
|
||||||
|
} else {
|
||||||
|
swPlayer.setComponent(new DynamicRegionEditor2());
|
||||||
|
}
|
||||||
|
if (true) return;
|
||||||
if (swPlayer.hasComponent(DynamicRegionVisualizer.class)) {
|
if (swPlayer.hasComponent(DynamicRegionVisualizer.class)) {
|
||||||
swPlayer.removeComponent(DynamicRegionVisualizer.class);
|
swPlayer.removeComponent(DynamicRegionVisualizer.class);
|
||||||
swPlayer.removeComponent(DynamicRegionEditor.class);
|
swPlayer.removeComponent(DynamicRegionEditor.class);
|
||||||
|
|||||||
+76
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* 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 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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user