Add classchest command.

The classchest command can be used to link a chest to a class directly
(although still in the same world) without having to position them in
a specific pillar under the signs.
This commit is contained in:
garbagemule 2013-08-13 14:54:34 +02:00
parent c24f9f8ccc
commit 1673078df5
5 changed files with 47 additions and 25 deletions

View File

@ -1,7 +1,7 @@
name: MobArena
author: garbagemule
main: com.garbagemule.MobArena.MobArena
version: 0.95.5.15
version: 0.95.5.16
softdepend: [Spout,Towny,Heroes,MagicSpells,Vault]
commands:
ma:

View File

@ -3,6 +3,7 @@ package com.garbagemule.MobArena;
import java.util.*;
import java.util.Map.Entry;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -17,7 +18,8 @@ public class ArenaClass
private Map<String,Boolean> perms;
private Map<String,Boolean> lobbyperms;
private boolean unbreakableWeapons, unbreakableArmor;
private Location classchest;
/**
* Create a new, empty arena class with the given name.
* @param name the class name as it appears in the config-file
@ -243,6 +245,14 @@ public class ArenaClass
}
}
public Location getClassChest() {
return classchest;
}
public void setClassChest(Location loc) {
classchest = loc;
}
public boolean hasUnbreakableWeapons() {
return unbreakableWeapons;
}
@ -267,7 +277,7 @@ public class ArenaClass
if (stack == null) return false;
return Arrays.binarySearch(weaponTypes, stack.getTypeId()) > -1;
}
/**
* Used by the grantItems() method to determine the armor type of a given
* ItemStack. Armor pieces are auto-equipped.

View File

@ -942,28 +942,37 @@ public class ArenaListener
public void run() {
if (!className.equalsIgnoreCase("random")) {
if (useClassChests) {
BlockFace backwards = ((org.bukkit.material.Sign) sign.getData()).getFacing().getOppositeFace();
Block blockSign = sign.getBlock();
Block blockBelow = blockSign.getRelative(BlockFace.DOWN);
Block blockBehind = blockBelow.getRelative(backwards);
// If the block below this sign is a class sign, swap the order
if (blockBelow.getType() == Material.WALL_SIGN || blockBelow.getType() == Material.SIGN_POST) {
String className = ChatColor.stripColor(((Sign) blockBelow.getState()).getLine(0)).toLowerCase();
if (arena.getClasses().containsKey(className)) {
blockSign = blockBehind; // Use blockSign as a temp while swapping
blockBehind = blockBelow;
blockBelow = blockSign;
// Check for stored class chests first
ArenaClass ac = plugin.getArenaMaster().getClasses().get(className.toLowerCase());
Location loc = ac.getClassChest();
Block blockChest;
if (loc != null) {
blockChest = loc.getBlock();
} else {
// Otherwise, start the search
BlockFace backwards = ((org.bukkit.material.Sign) sign.getData()).getFacing().getOppositeFace();
Block blockSign = sign.getBlock();
Block blockBelow = blockSign.getRelative(BlockFace.DOWN);
Block blockBehind = blockBelow.getRelative(backwards);
// If the block below this sign is a class sign, swap the order
if (blockBelow.getType() == Material.WALL_SIGN || blockBelow.getType() == Material.SIGN_POST) {
String className = ChatColor.stripColor(((Sign) blockBelow.getState()).getLine(0)).toLowerCase();
if (arena.getClasses().containsKey(className)) {
blockSign = blockBehind; // Use blockSign as a temp while swapping
blockBehind = blockBelow;
blockBelow = blockSign;
}
}
// TODO: Make number of searches configurable
// First check the pillar below the sign
blockChest = findChestBelow(blockBelow, 6);
// Then, if no chest was found, check the pillar behind the sign
if (blockChest == null) blockChest = findChestBelow(blockBehind, 6);
}
// TODO: Make number of searches configurable
// First check the pillar below the sign
Block blockChest = findChestBelow(blockBelow, 6);
// 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) {
InventoryHolder holder = (InventoryHolder) blockChest.getState();
@ -971,9 +980,7 @@ public class ArenaListener
// Guard against double-chests for now
if (contents.length > 36) {
ItemStack[] newContents = new ItemStack[36];
for (int i = 0; i < 36; i++) {
newContents[i] = contents[i];
}
System.arraycopy(contents, 0, newContents, 0, 36);
contents = newContents;
}
arena.assignClassGiveInv(p, className, contents);

View File

@ -358,6 +358,10 @@ public class ArenaMasterImpl implements ArenaMaster
// Register the permission.
registerPermission("mobarena.classes." + lowercase, PermissionDefault.TRUE).addParent("mobarena.classes", true);
// Check for class chests
Location cc = section.getLocation("classchest", null);
arenaClass.setClassChest(cc);
// Finally add the class to the classes map.
classes.put(lowercase, arenaClass);
return arenaClass;

View File

@ -198,6 +198,7 @@ public class CommandHandler implements CommandExecutor
register(SpawnpointsCommand.class);
register(AutoGenerateCommand.class);
register(AutoDegenerateCommand.class);
register(ClassChestCommand.class);
}
/**