Files
SteamWar/BauSystem/BauSystem_RegionDynamic/src/de/steamwar/bausystem/region/DynamicRegionVisualizer2.java
T

81 lines
3.2 KiB
Java

/*
* 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
}
}