SteamWar/BauSystem2.0
Archiviert
12
0

Merge remote-tracking branch 'origin/master'

Dieser Commit ist enthalten in:
yoyosource 2021-07-04 20:22:01 +02:00
Commit a157a0fd95
2 geänderte Dateien mit 202 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,194 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 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.features.region;
import com.sun.istack.internal.NotNull;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.tags.Tag;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.scheduler.BukkitRunnable;
@Linked(LinkageType.LISTENER)
public class RegionListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockFromTo(final BlockFromToEvent event) {
RegionListener.tagChangedRegion(event.getBlock().getLocation());
RegionListener.tagChangedRegion(event.getToBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockIgnite(final BlockIgniteEvent event) {
RegionListener.tagChangedRegion(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBurn(final BlockBurnEvent event) {
RegionListener.tagChangedRegion(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPhysics(final BlockPhysicsEvent event) {
if (event.getBlock().getType() != event.getChangedType()) RegionListener.tagChangedRegion(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onLeavesDecay(final LeavesDecayEvent event) {
RegionListener.tagChangedRegion(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBLockForm(final BlockFormEvent event) {
RegionListener.tagChangedRegion(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockSpread(final BlockSpreadEvent event) {
RegionListener.tagChangedRegion(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockExplode(final BlockExplodeEvent event) {
RegionListener.tagChangedRegion(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityExplode(final EntityExplodeEvent event) {
RegionListener.tagChangedRegion(event.getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onExplosionPrime(final ExplosionPrimeEvent event) {
RegionListener.tagChangedRegion(event.getEntity().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockMultiPlace(final BlockMultiPlaceEvent event) {
new BukkitRunnable() {
@Override
public void run() {
event.getReplacedBlockStates().forEach(blockState -> RegionListener.tagChangedRegion(blockState.getLocation()));
}
}.runTaskAsynchronously(BauSystem.getInstance());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(final BlockPlaceEvent event) {
RegionListener.tagChangedRegion(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onCanBuild(final BlockCanBuildEvent event) {
if (event.isBuildable()) RegionListener.tagChangedRegion(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(final BlockBreakEvent event) {
RegionListener.tagChangedRegion(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInteract(final PlayerInteractEvent event) {
if (event.getClickedBlock() != null) RegionListener.tagChangedRegion(event.getClickedBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntitySpawn(final EntitySpawnEvent event) {
RegionListener.tagChangedRegion(event.getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityChangeBlock(final EntityChangeBlockEvent event) {
RegionListener.tagChangedRegion(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPistonExtend(final BlockPistonExtendEvent event) {
new BukkitRunnable() {
@Override
public void run() {
event.getBlocks().forEach(block -> RegionListener.tagChangedRegion(block.getLocation()));
}
}.runTaskAsynchronously(BauSystem.getInstance());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPistonRetract(final BlockPistonRetractEvent event) {
new BukkitRunnable() {
@Override
public void run() {
event.getBlocks().forEach(block -> RegionListener.tagChangedRegion(block.getLocation()));
}
}.runTaskAsynchronously(BauSystem.getInstance());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockGrow(final BlockGrowEvent event) {
RegionListener.tagChangedRegion(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockRedstone(final BlockRedstoneEvent event) {
RegionListener.tagChangedRegion(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockDispense(final BlockDispenseEvent event) {
RegionListener.tagChangedRegion(event.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryMoveItemMonitor(final InventoryMoveItemEvent event) {
final Location source = event.getSource().getLocation();
final Location destination = event.getDestination().getLocation();
if (source != null) {
RegionListener.tagChangedRegion(source);
}
if (destination != null) {
RegionListener.tagChangedRegion(destination);
}
}
private static void tagChangedRegion(final Location location) {
new BukkitRunnable() {
@Override
public void run() {
Region.getRegion(location).set(Tag.CHANGED);
}
}.runTaskAsynchronously(BauSystem.getInstance());
}
}

Datei anzeigen

@ -23,6 +23,7 @@ import com.sk89q.worldedit.EditSession;
import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; import de.steamwar.bausystem.region.flags.flagvalues.ColorMode;
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; import de.steamwar.bausystem.region.flags.flagvalues.TNTMode;
import de.steamwar.bausystem.region.tags.Tag;
import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.bausystem.shared.SizedStack; import de.steamwar.bausystem.shared.SizedStack;
@ -280,6 +281,13 @@ public class Region {
setLinkedRegion(region -> region.flagStorage.set(flagType, value)); setLinkedRegion(region -> region.flagStorage.set(flagType, value));
} }
public void set(Tag tag) {
if (flagStorage.set(tag)) {
RegionUtils.save(this);
}
setLinkedRegion(region -> region.flagStorage.set(tag));
}
public Flag.Value<?> get(Flag flagType) { public Flag.Value<?> get(Flag flagType) {
return flagStorage.get(flagType); return flagStorage.get(flagType);
} }