From 3539e70954fa046e526ed90bfa13336a4a843b5d Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Mon, 7 Sep 2026 14:02:01 +0200 Subject: [PATCH] Update DynamicRegionCommand --- .../region/DynamicRegionCommand.java | 6 ++ .../region/DynamicRegionEditor2.java | 76 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionEditor2.java diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionCommand.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionCommand.java index b0e7c6e5..b1837b36 100644 --- a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionCommand.java +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionCommand.java @@ -37,6 +37,12 @@ public class DynamicRegionCommand extends SWCommand { @Register({"dynamic"}) public void visualizeRegions(Player 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)) { swPlayer.removeComponent(DynamicRegionVisualizer.class); swPlayer.removeComponent(DynamicRegionEditor.class); diff --git a/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionEditor2.java b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionEditor2.java new file mode 100644 index 00000000..68ebf987 --- /dev/null +++ b/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionEditor2.java @@ -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 . + */ + +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 + } +}