From d8f9c7a00c45ff034b49e9fa769c45a6fa9edc7e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jan 2020 19:27:35 +0100 Subject: [PATCH] Freeze World during pasting Signed-off-by: Lixfel --- .../fightsystem/fight/FightTeam_8.java | 15 --------------- .../steamwar/fightsystem/fight/FightTeam.java | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java b/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java index 0e21939..0485755 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java @@ -13,17 +13,12 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.IFightSystem; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.DyeColor; import org.bukkit.Material; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.scoreboard.Team; import java.io.IOException; @@ -95,20 +90,10 @@ class FightTeam_8 { } EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); - FreezeWorld freezer = new FreezeWorld(); - Bukkit.getPluginManager().registerEvents(freezer, IFightSystem.getPlugin()); ClipboardHolder ch = new ClipboardHolder(clipboard, w.getWorldData()); ch.setTransform(aT); Operations.completeBlindly(ch.createPaste(e, w.getWorldData()).to(v).build()); e.flushQueue(); - HandlerList.unregisterAll(freezer); return e; } - - static class FreezeWorld implements Listener{ - @EventHandler - public void onBlockPhysicsEvent(BlockPhysicsEvent e){ - e.setCancelled(true); - } - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 380f060..aff472f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -4,6 +4,7 @@ import com.sk89q.worldedit.EditSession; import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.IFightSystem; import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.fightsystem.utils.FightScoreboard; @@ -17,6 +18,10 @@ import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.inventory.Inventory; import org.bukkit.scoreboard.NameTagVisibility; import org.bukkit.scoreboard.Team; @@ -242,6 +247,7 @@ public class FightTeam implements IFightTeam{ } private void pasteSchematic(){ + FreezeWorld freezer = new FreezeWorld(); EditSession e; try { switch(Core.getVersion()){ @@ -271,6 +277,7 @@ public class FightTeam implements IFightTeam{ throw new SecurityException("Error pasting arena in schematic", ex); } replaceTeamColor(e); + HandlerList.unregisterAll(freezer); Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), this::teleportToSpawn,40); } @@ -406,4 +413,15 @@ public class FightTeam implements IFightTeam{ assert maximumHearts != 0; return currentHearts / maximumHearts; } + + private static class FreezeWorld implements Listener { + private FreezeWorld(){ + Bukkit.getPluginManager().registerEvents(this, IFightSystem.getPlugin()); + } + + @EventHandler + public void onBlockPhysicsEvent(BlockPhysicsEvent e){ + e.setCancelled(true); + } + } }