/* * 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 . */ package de.steamwar.bausystem.region; import de.steamwar.bausystem.features.region.RegionCommand; import de.steamwar.bausystem.region.dynamic.DynamicRegion; import de.steamwar.bausystem.region.dynamic.Tile; import de.steamwar.bausystem.region.dynamic.path.PathRegion; import de.steamwar.bausystem.region.dynamic.path.PathRegionData; import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.command.AbstractSWCommand; import de.steamwar.command.SWCommand; import org.bukkit.entity.Player; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; @AbstractSWCommand.PartOf(RegionCommand.class) public class DynamicRegionCommand extends SWCommand { public DynamicRegionCommand() { super(""); } @Register({"dynamic", "place"}) public void placeRegion(Player player) { Region region = DynamicRegionSystem.INSTANCE.get(player.getLocation()); if (!region.getType().isGlobal()) return; Optional optionalTile = Tile.fromLocation(player.getLocation()); if (optionalTile.isEmpty()) return; Tile tile = optionalTile.get(); // TODO: Replace! PathRegion dynamicRegion = new PathRegion(UUID.randomUUID(), tile.getMinX(), tile.getMinZ()); dynamicRegion.setRegionData(new PathRegionData(dynamicRegion)); dynamicRegion.getArea().reset(new PasteBuilder(new PasteBuilder.FileProvider(dynamicRegion.getArea().getResetFile())), false); DynamicRegionSystem.INSTANCE.getNeighbours(dynamicRegion).collect(Collectors.toList()) .forEach(r -> r.update(dynamicRegion)); } @Register({"dynamic", "delete"}) public void deleteRegion(Player player) { Region region = DynamicRegionSystem.INSTANCE.get(player.getLocation()); if (region.getType().isCannotDelete()) return; ((DynamicRegion) region).delete(); } }