Make the chest search happen per-pillar.

This allows for a sneaky little trick, where two lines class signs
becomes possible, if one chest is offset backwards, and the other
chest is positioned at the very bottom block.
This commit is contained in:
Andreas Troelsen
2013-01-26 03:37:49 +01:00
parent 2de480709d
commit fa28964d51
+17 -13
View File
@@ -840,20 +840,14 @@ public class ArenaListener
Block blockBelow = sign.getBlock(); Block blockBelow = sign.getBlock();
Block blockBehind = blockBelow.getRelative(backwards); Block blockBehind = blockBelow.getRelative(backwards);
Block blockChest = null; // TODO: Make number of searches configurable
for (int i = 0; i < 6; i++) { // First check the pillar below the sign
if (blockBelow.getType() == Material.CHEST) { Block blockChest = findChestBelow(blockBelow, 6);
blockChest = blockBelow;
break;
}
if (blockBehind.getType() == Material.CHEST) {
blockChest = blockBehind;
break;
}
blockBelow = blockBelow.getRelative(BlockFace.DOWN);
blockBehind = blockBehind.getRelative(BlockFace.DOWN);
}
// Then, if no chest was found, check the pillar behind the sign
if (blockChest == null) blockChest = findChestBelow(blockBehind, 6);
// If a chest was found, get the contents
if (blockChest != null) { if (blockChest != null) {
InventoryHolder holder = (InventoryHolder) blockChest.getState(); InventoryHolder holder = (InventoryHolder) blockChest.getState();
ItemStack[] contents = holder.getInventory().getContents(); ItemStack[] contents = holder.getInventory().getContents();
@@ -862,6 +856,7 @@ public class ArenaListener
Messenger.tellPlayer(p, Msg.LOBBY_CLASS_PICKED, TextUtils.camelCase(className), arena.getClassLogo(className)); Messenger.tellPlayer(p, Msg.LOBBY_CLASS_PICKED, TextUtils.camelCase(className), arena.getClassLogo(className));
return; return;
} }
// Otherwise just fall through and use the items from the config-file
} }
arena.assignClass(p, className); arena.assignClass(p, className);
Messenger.tellPlayer(p, Msg.LOBBY_CLASS_PICKED, TextUtils.camelCase(className), arena.getClassLogo(className)); Messenger.tellPlayer(p, Msg.LOBBY_CLASS_PICKED, TextUtils.camelCase(className), arena.getClassLogo(className));
@@ -873,6 +868,15 @@ public class ArenaListener
} }
}); });
} }
private Block findChestBelow(Block b, int left) {
if (left < 0) return null;
if (b.getType() == Material.CHEST) {
return b;
}
return findChestBelow(b.getRelative(BlockFace.DOWN), left - 1);
}
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
Player p = event.getPlayer(); Player p = event.getPlayer();