From dfb67704537e9ec2497d65f2a11f7f6f1b097865 Mon Sep 17 00:00:00 2001 From: jojo Date: Thu, 4 Feb 2021 09:55:39 +0100 Subject: [PATCH] Fix Freeze Exceptions --- .../bausystem/commands/CommandFreeze.java | 10 ++++++++ .../bausystem/world/RegionListener.java | 23 +++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java index 2364e98..5baa134 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandFreeze.java @@ -19,7 +19,10 @@ package de.steamwar.bausystem.commands; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.world.Region; +import de.steamwar.core.Core; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.block.*; @@ -55,6 +58,7 @@ public class CommandFreeze extends RegionToggleCommand { @EventHandler public void onBlockCanBuild(BlockCanBuildEvent e) { + if (Core.getVersion() == 12) return; if (!e.isBuildable()) return; if (!Region.getRegion(e.getBlock().getLocation()).isFreeze()) return; if (e.getMaterial() == Material.TNT) { @@ -66,6 +70,12 @@ public class CommandFreeze extends RegionToggleCommand { @EventHandler public void onEntityChangeBlock(EntityChangeBlockEvent e) { if (Region.getRegion(e.getBlock().getLocation()).isFreeze()) e.setCancelled(true); + if (Core.getVersion() == 15) return; + if (e.isCancelled()) { + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), () -> { + e.getBlock().setType(Material.TNT, false); + }, 1L); + } } @EventHandler diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java index 47d49c0..ac6825e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/RegionListener.java @@ -38,10 +38,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockCanBuildEvent; -import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.block.*; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; @@ -72,8 +69,9 @@ public class RegionListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onBlockCanBuild(BlockCanBuildEvent e) { - Player p = e.getPlayer(); + if (Core.getVersion() == 12) return; + Player p = e.getPlayer(); try{ if (Welt.noPermission(p, Permission.build)){ p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier keine Blöcke platzieren"); @@ -84,6 +82,21 @@ public class RegionListener implements Listener { } } + @EventHandler(priority = EventPriority.LOWEST) + public void onBlockPlace(BlockPlaceEvent e) { + if (Core.getVersion() == 15) return; + + Player p = e.getPlayer(); + try{ + if (Welt.noPermission(p, Permission.build)){ + p.sendMessage(BauSystem.PREFIX + "§cDu darfst hier keine Blöcke platzieren"); + e.setCancelled(true); + } + }catch(NullPointerException ex){ + //ignored, caused by worldedit brushes + } + } + private static final String[] shortcutCommands = {"//1", "//2", "//90", "//-90", "//180", "//p", "//c", "//flopy", "//floppy", "//flopyp", "//floppyp", "//u", "//r"}; private boolean isWorldEditCommand(String command) {