[trunk] Warp signs

4th line: charge money or items

git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1097 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
snowleo 2011-04-03 12:02:33 +00:00
parent 7bd9527e34
commit b11964dac4
2 changed files with 34 additions and 0 deletions

View File

@ -121,6 +121,15 @@ public class EssentialsBlockListener extends BlockListener
{
event.setLine(0, "§4[Warp]");
if (user.isAuthorized("essentials.signs.warp.create")) {
if (!event.getLine(3).isEmpty())
{
String[] l1 = event.getLine(3).split("[ :-]+");
boolean m1 = l1[0].matches("\\$[0-9]+");
int q1 = Integer.parseInt(m1 ? l1[0].substring(1) : l1[0]);
if (q1 < 1) throw new Exception("Quantities must be greater than 0.");
if (!m1) ItemDb.get(l1[1]);
event.setLine(3, (m1 ? "$" + q1 : q1 + " " + l1[1]));
}
if (event.getLine(1).isEmpty()) {
event.setLine(1, "§dWarp name here!");
return;

View File

@ -344,6 +344,31 @@ public class EssentialsPlayerListener extends PlayerListener
}
if (sign.getLine(0).equals("§1[Warp]"))
{
if (!sign.getLine(3).isEmpty()) {
String[] l1 = sign.getLine(3).split("[ :-]+");
boolean m1 = l1[0].matches("\\$[0-9]+");
int q1 = Integer.parseInt(m1 ? l1[0].substring(1) : l1[0]);
if (q1 < 1) {
throw new Exception("Quantities must be greater than 0.");
}
if (m1)
{
if (user.getMoney() < q1) {
throw new Exception("You do not have sufficient funds.");
}
user.takeMoney(q1);
user.sendMessage("$" + q1 + " taken from your bank account.");
}
else
{
ItemStack i = ItemDb.get(l1[1], q1);
if (!InventoryWorkaround.containsItem((CraftInventory)user.getInventory(), true, i)) {
throw new Exception("You do not have " + q1 + "x " + l1[1] + ".");
}
InventoryWorkaround.removeItem((CraftInventory)user.getInventory(), true, i);
user.updateInventory();
}
}
if (!sign.getLine(2).isEmpty()) {
if (sign.getLine(2).equals("§2Free")) {
user.teleportCooldown();