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,6 +18,7 @@ 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.
@ -243,6 +245,14 @@ public class ArenaClass
}
}
public Location getClassChest() {
return classchest;
}
public void setClassChest(Location loc) {
classchest = loc;
}
public boolean hasUnbreakableWeapons() {
return unbreakableWeapons;
}

View File

@ -942,6 +942,14 @@ public class ArenaListener
public void run() {
if (!className.equalsIgnoreCase("random")) {
if (useClassChests) {
// 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);
@ -959,10 +967,11 @@ public class ArenaListener
// TODO: Make number of searches configurable
// First check the pillar below the sign
Block blockChest = findChestBelow(blockBelow, 6);
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) {
@ -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);
}
/**