Archiviert
13
0

Fix FreezeListener

Dieser Commit ist enthalten in:
yoyosource 2023-09-15 21:05:00 +02:00
Ursprung e2710684c0
Commit 12f2fbcf89
2 geänderte Dateien mit 102 neuen und 27 gelöschten Zeilen

Datei anzeigen

@ -19,16 +19,21 @@
package de.steamwar.teamserver.listener;
import de.steamwar.core.Core;
import de.steamwar.teamserver.Builder;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.type.Switch;
import org.bukkit.entity.EntityType;
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.EntitySpawnEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public class FreezeListener implements Listener {
@ -50,9 +55,8 @@ public class FreezeListener implements Listener {
@EventHandler
public void onBlockCanBuild(BlockCanBuildEvent e) {
if (!e.isBuildable()) return;
if (!freeze) {
if (!freeze)
return;
}
if (e.getMaterial() == Material.TNT) {
e.setBuildable(false);
e.getBlock().setType(Material.TNT, false);
@ -61,65 +65,137 @@ public class FreezeListener implements Listener {
@EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent e) {
if (!freeze) {
return;
if (freeze) {
e.setCancelled(true);
}
e.setCancelled(true);
}
@EventHandler
public void onPhysicsEvent(BlockPhysicsEvent e) {
if (!freeze) {
return;
if (freeze) {
e.setCancelled(true);
}
e.setCancelled(true);
}
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent e) {
if (!freeze) {
return;
if (freeze) {
e.setCancelled(true);
}
e.setCancelled(true);
}
@EventHandler
public void onPistonRetract(BlockPistonRetractEvent e) {
if (!freeze) {
return;
if (freeze) {
e.setCancelled(true);
}
e.setCancelled(true);
}
@EventHandler
public void onBlockGrow(BlockGrowEvent e) {
if (!freeze) {
return;
if (freeze) {
e.setCancelled(true);
}
e.setCancelled(true);
}
@EventHandler
public void onRedstoneEvent(BlockRedstoneEvent e) {
if (!freeze) {
return;
if (freeze) {
e.setNewCurrent(e.getOldCurrent());
}
e.setNewCurrent(e.getOldCurrent());
}
@EventHandler
public void onBlockDispense(BlockDispenseEvent e) {
if (!freeze) {
return;
if (freeze) {
e.setCancelled(true);
}
e.setCancelled(true);
}
@EventHandler
public void onInventoryMoveEvent(InventoryMoveItemEvent e) {
if (!freeze) {
return;
if (freeze) {
e.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent e) {
if (Core.getVersion() < 19) return;
if (e.getPlayer().getInventory().getItemInMainHand().getType() == Material.DEBUG_STICK) return;
if (freeze) {
if (e.isCancelled()) return;
e.setCancelled(true);
e.getBlock().setType(Material.AIR, false);
}
}
/*
@EventHandler
public void onBlockPlace(BlockPlaceEvent e) {
if (Core.getVersion() < 19) return;
if (!e.getItemInHand().getType().isBlock()) return;
if (Region.getRegion(e.getBlock().getLocation()).get(Flag.FREEZE) == FreezeMode.ACTIVE) {
e.setCancelled(true);
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
e.getBlock().setType(e.getItemInHand().getType(), false);
}, 1L);
}
}
*/
@EventHandler
public void onFluidLevelChange(FluidLevelChangeEvent e) {
if (freeze) {
e.setCancelled(true);
}
}
@EventHandler
public void onBlockSpread(BlockSpreadEvent e) {
if (freeze) {
e.setCancelled(true);
}
}
@EventHandler
public void onBlockFromTo(BlockFromToEvent e) {
if (freeze) {
e.setCancelled(true);
}
}
@EventHandler
public void onSpongeAbsorb(SpongeAbsorbEvent e) {
if (freeze) {
e.setCancelled(true);
}
}
@EventHandler
public void onBlockForm(BlockFormEvent e) {
if (freeze) {
e.setCancelled(true);
}
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
if (freeze) {
Block block = e.getClickedBlock();
if (block.getType() == Material.LEVER) {
Switch data = ((Switch) block.getBlockData());
data.setPowered(!data.isPowered());
block.setBlockData(data, false);
}
}
}
@EventHandler
public void onBlockFade(BlockFadeEvent event) {
if (freeze) {
event.setCancelled(true);
}
e.setCancelled(true);
}
}

Datei anzeigen

@ -36,6 +36,5 @@ public class PlayerChange implements Listener {
public void onPlayerQuit(PlayerQuitEvent event) {
if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer())))
Bukkit.shutdown();
}
}