From cd0ce5769101e9497296d674e147a7861a5b2146 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 18 Nov 2015 09:58:06 +0000 Subject: [PATCH] replaced useless looping with just checking the rotation of the bed. --- .../mineplex/game/clans/clans/ClansGame.java | 51 +++++++++++++++---- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java index 5746e68da..8884f57d2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java @@ -27,7 +27,6 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; -import org.omg.PortableInterceptor.SYSTEM_EXCEPTION; import mineplex.core.MiniPlugin; import mineplex.core.blockrestore.BlockRestoreData; @@ -45,6 +44,7 @@ import mineplex.core.itemstack.ItemStackFactory; import mineplex.game.clans.clans.ClansUtility.ClanRelation; import mineplex.game.clans.core.repository.ClanTerritory; import mineplex.minecraft.game.core.damage.CustomDamageEvent; +import net.minecraft.server.v1_8_R3.EnumDirection; public class ClansGame extends MiniPlugin { @@ -687,16 +687,47 @@ public class ClansGame extends MiniPlugin { clanHome.getBlock().setType(Material.AIR); - for (int x2 = -1; x2 < 1; x2++) + byte data = clanHome.getBlock().getData(); + + EnumDirection dir = null; + int xModif = 0; + int zModif = 0; + + if ((data & (1 << 0x2)) != 0) { - for (int z2 = -1; z2 < 1; z2++) - { - Block block = clanHome.clone().add(x2, 0, z2).getBlock(); - if (block.getType().equals(Material.BED_BLOCK)) - { - block.setType(Material.AIR); - } - } + zModif = -1; + dir = EnumDirection.NORTH; + } + else if ((data & (1 << 0x0)) != 0) + { + zModif = 1; + dir = EnumDirection.SOUTH; + } + else if ((data & (1 << 0x1)) != 0) + { + xModif = -1; + dir = EnumDirection.WEST; + } + else if ((data & (1 << 0x3)) != 0) + { + xModif = 1; + dir = EnumDirection.EAST; + } + + if (dir == null) + { + return; + } + + Block footBlock = clanHome.clone().add(xModif, 0, zModif).getBlock(); + if (footBlock.getType().equals(Material.BED_BLOCK)) + { + footBlock.setType(Material.AIR); + } + else + { + // Shoudln't happen, but just in case: + System.out.println("Second block of " + clan.getName() + "'s Clan Home should be a bed, but isn't. [STRANGE!!!]"); } clan.setHome(null);