From 0a667afeb1ceb38ae2051a631477c83cb0892c25 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 18 Nov 2015 22:27:01 +0000 Subject: [PATCH] finally fixed beds. major cleanup of code, much more organized now, thank you, Me!!!! oh my god both of my eyes are twitching --- .../mineplex/core/common/util/UtilBlock.java | 79 +++++++++++++++++++ .../mineplex/game/clans/clans/ClansGame.java | 59 ++------------ .../clans/clans/commands/ClansCommand.java | 46 +---------- 3 files changed, 88 insertions(+), 96 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java index d33376cba..31a26c403 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java @@ -653,6 +653,10 @@ public class UtilBlock return false; } + if (location == null){ + return false; + } + if (location.getY() <= 0) { return false; @@ -716,6 +720,81 @@ public class UtilBlock return pillowBlock.getBlock().getType().equals(Material.BED_BLOCK) && footBlock.getBlock().getType().equals(Material.BED_BLOCK); } + + public static boolean deleteBed(Location home) + { + if (home == null) + { + return false; + } + + if (home.getY() <= 0) + { + return false; + } + + int xModif = 0; + int zModif = 0; + byte data = home.getBlock().getData(); + + boolean isSpecifiedHead = (data & 0x8) != 0; + Location head = isSpecifiedHead ? home : null; + Location foot = isSpecifiedHead ? null : home; + + EnumDirection direction = null; + + if ((data & 0x2) != 0) + { + zModif = -1; + direction = EnumDirection.NORTH; + } + + if ((data & 0x3) != 0) + { + xModif = 1; + direction = EnumDirection.EAST; + } + + if ((data & 0x0) != 0) + { + zModif = 1; + direction = EnumDirection.SOUTH; + } + + if ((data & 0x1) != 0) + { + xModif = -1; + direction = EnumDirection.WEST; + } + + if (xModif == 0 && zModif == 0) + { + return false; + } + + if (head == null) + { + head = foot.clone().add(xModif, 0, zModif); + } + else + { + foot = head.clone().add(xModif, 0, zModif); + } + + if (foot == null && head == null) + { + return false; + } + + head.getBlock().setType(Material.AIR); + head.getBlock().setData((byte) 0); + + foot.getBlock().setType(Material.AIR); + foot.getBlock().setData((byte) 0); + + return true; + } + /** * hingeSide: 0 = left, 1 = right

* open: true if the door should be placed open, false for it to be closed.

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 8884f57d2..32c64f701 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 @@ -17,6 +17,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; +import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityExplodeEvent; @@ -662,7 +663,10 @@ public class ClansGame extends MiniPlugin else { UtilPlayer.message(player, F.main("Clans", "You have destroyed " + F.elem(blockClan.getName()) + "'s Clan Home!")); - removeHome(blockClan, blockClan.getHome()); + + UtilBlock.deleteBed(blockClan.getHome()); + + blockClan.setHome(null); } return; @@ -672,8 +676,9 @@ public class ClansGame extends MiniPlugin { event.setCancelled(true); - removeHome(blockClan, blockClan.getHome()); + UtilBlock.deleteBed(blockClan.getHome()); + blockClan.setHome(null); UtilPlayer.message(player, F.main("Clans", "You have removed your Clan Home.")); } else @@ -682,54 +687,4 @@ public class ClansGame extends MiniPlugin UtilPlayer.message(player, F.main("Clans", "Only the Clan Leader and Admins can remove the Clan Home.")); } } - - private void removeHome(ClanInfo clan, Location clanHome) - { - clanHome.getBlock().setType(Material.AIR); - - byte data = clanHome.getBlock().getData(); - - EnumDirection dir = null; - int xModif = 0; - int zModif = 0; - - if ((data & (1 << 0x2)) != 0) - { - 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); - } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java index 20d1c15a2..ba67339fa 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java @@ -884,6 +884,7 @@ public class ClansCommand extends CommandBase return; } + // Place New boolean bedPlaced = UtilBlock.placeBed(caller.getLocation(), EnumDirection.fromAngle(caller.getLocation().getYaw()), false, false); if (!bedPlaced) @@ -895,50 +896,7 @@ public class ClansCommand extends CommandBase // Cleanup old if (clan.getHome() != null) { - byte data = clan.getHome().getBlock().getData(); - - EnumDirection dir = EnumDirection.fromAngle(caller.getLocation().getYaw()); - int xModif = 0; - int zModif = 0; - - if ((data & (1 << 0x2)) != 0) - { - 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) - { - UtilPlayer.message(caller, F.main("Clans", "Error whilst cleaning up old home bed!")); - } - - Block headBlock = clan.getHome().clone().add(xModif, 0, zModif).getBlock(); - if (clan.getHome().getBlock().getType().equals(Material.BED_BLOCK)) - { - headBlock.setType(Material.AIR); - clan.getHome().getBlock().setType(Material.AIR); - } - else - { - // Shouldn'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!!!]"); - UtilPlayer.message(caller, F.main("Clans", "Error whilst cleaning up old home bed!")); - } + System.out.println("OLD CLEANUP: " + UtilBlock.deleteBed(clan.getHome())); } // Task