finally fixed beds. major cleanup of code, much more organized now, thank you, Me!!!! oh my god both of my eyes are twitching

This commit is contained in:
NewGarbo 2015-11-18 22:27:01 +00:00
parent eded09b1a9
commit 0a667afeb1
3 changed files with 88 additions and 96 deletions

View File

@ -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<p>
* open: true if the door should be placed open, false for it to be closed.<p>

View File

@ -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);
}
}

View File

@ -884,6 +884,7 @@ public class ClansCommand extends CommandBase<ClansManager>
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<ClansManager>
// 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