mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-23 01:27:40 +01:00
[trunk] warp sign: Only charge the user, if he is authorized to use the sign.
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1377 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
parent
02a9909e8b
commit
14b53db85a
@ -454,44 +454,18 @@ 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(user.getInventory(), true, i))
|
||||
{
|
||||
throw new Exception("You do not have " + q1 + "x " + l1[1] + ".");
|
||||
}
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, i);
|
||||
user.updateInventory();
|
||||
}
|
||||
}
|
||||
|
||||
if (!sign.getLine(2).isEmpty())
|
||||
{
|
||||
if (sign.getLine(2).equals("§2Everyone"))
|
||||
{
|
||||
chargeUserForWarp(sign, user);
|
||||
user.getTeleport().warp(sign.getLine(1), "warpsign");
|
||||
return;
|
||||
}
|
||||
if (user.inGroup(sign.getLine(2)))
|
||||
{
|
||||
chargeUserForWarp(sign, user);
|
||||
user.getTeleport().warp(sign.getLine(1), "warpsign");
|
||||
return;
|
||||
}
|
||||
@ -499,6 +473,7 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
if (user.isAuthorized("essentials.signs.warp.use")
|
||||
&& (!ess.getSettings().getPerWarpPermission() || user.isAuthorized("essentials.warp." + sign.getLine(1))))
|
||||
{
|
||||
chargeUserForWarp(sign, user);
|
||||
user.getTeleport().warp(sign.getLine(1), "warpsign");
|
||||
}
|
||||
return;
|
||||
@ -509,6 +484,39 @@ public class EssentialsPlayerListener extends PlayerListener
|
||||
user.sendMessage("§cError: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void chargeUserForWarp(Sign sign, User user) throws Exception
|
||||
{
|
||||
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(user.getInventory(), true, i))
|
||||
{
|
||||
throw new Exception("You do not have " + q1 + "x " + l1[1] + ".");
|
||||
}
|
||||
InventoryWorkaround.removeItem(user.getInventory(), true, i);
|
||||
user.updateInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerEggThrow(PlayerEggThrowEvent event)
|
||||
|
Loading…
Reference in New Issue
Block a user