summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-03-30 12:58:01 +0000
committersnowleo <snowleo@e251c2fe-e539-e718-e476-b85c1f46cddb>2011-03-30 12:58:01 +0000
commitd4f15e62d2a4ec0d4daed9ce3f0961bd52742d77 (patch)
tree0df79b14dcf670d042bdd785eb49eedb36a7bb7f
parent08041599fffe85ef4e5da59cc060a690c7dc8994 (diff)
downloadEssentials-d4f15e62d2a4ec0d4daed9ce3f0961bd52742d77.tar
Essentials-d4f15e62d2a4ec0d4daed9ce3f0961bd52742d77.tar.gz
Essentials-d4f15e62d2a4ec0d4daed9ce3f0961bd52742d77.tar.lz
Essentials-d4f15e62d2a4ec0d4daed9ce3f0961bd52742d77.tar.xz
Essentials-d4f15e62d2a4ec0d4daed9ce3f0961bd52742d77.zip
Revert to 1013
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1022 e251c2fe-e539-e718-e476-b85c1f46cddb
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java143
-rw-r--r--Essentials/src/com/earth2me/essentials/JailPlayerListener.java28
2 files changed, 171 insertions, 0 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java
new file mode 100644
index 000000000..621fe73e8
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java
@@ -0,0 +1,143 @@
+package com.earth2me.essentials;
+
+import org.bukkit.Material;
+import org.bukkit.block.Sign;
+import org.bukkit.craftbukkit.block.CraftSign;
+import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.event.block.Action;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.event.player.PlayerListener;
+import org.bukkit.inventory.ItemStack;
+
+
+public class EssentialsEcoPlayerListener extends PlayerListener
+{
+
+@Override
+ public void onPlayerInteract(PlayerInteractEvent event)
+ {
+
+ if (Essentials.getSettings().areSignsDisabled()) return;
+ if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
+ User user = User.get(event.getPlayer());
+ if (event.getClickedBlock().getType() != Material.WALL_SIGN && event.getClickedBlock().getType() != Material.SIGN_POST)
+ return;
+ Sign sign = new CraftSign(event.getClickedBlock());
+
+ if (sign.getLine(0).equals("§1[Buy]") && user.isAuthorized("essentials.signs.buy.use"))
+ {
+ try
+ {
+ int amount = Integer.parseInt(sign.getLine(1));
+ ItemStack item = ItemDb.get(sign.getLine(2), amount);
+ int cost = Integer.parseInt(sign.getLine(3).substring(1));
+ if (user.getMoney() < cost) throw new Exception("You do not have sufficient funds.");
+ user.takeMoney(cost);
+ user.getInventory().addItem(item);
+ user.updateInventory();
+ }
+ catch (Throwable ex)
+ {
+ user.sendMessage("§cError: " + ex.getMessage());
+ }
+ return;
+ }
+
+ if (sign.getLine(0).equals("§1[Sell]") && user.isAuthorized("essentials.signs.sell.use"))
+ {
+ try
+ {
+ int amount = Integer.parseInt(sign.getLine(1));
+ ItemStack item = ItemDb.get(sign.getLine(2), amount);
+ int cost = Integer.parseInt(sign.getLine(3).substring(1));
+ if (!InventoryWorkaround.containsItem((CraftInventory)user.getInventory(), true, item)) throw new Exception("You do not have enough items to sell.");
+ user.giveMoney(cost);
+ InventoryWorkaround.removeItem((CraftInventory)user.getInventory(), true, item);
+ user.updateInventory();
+ }
+ catch (Throwable ex)
+ {
+ user.sendMessage("§cError: " + ex.getMessage());
+ }
+ return;
+ }
+
+ if (sign.getLine(0).equals("§1[Trade]") && user.isAuthorized("essentials.signs.trade.use"))
+ {
+ try
+ {
+ String[] l1 = sign.getLines()[1].split("[ :-]+");
+ String[] l2 = sign.getLines()[2].split("[ :-]+");
+ boolean m1 = l1[0].matches("\\$[0-9]+");
+ boolean m2 = l2[0].matches("\\$[0-9]+");
+ int q1 = Integer.parseInt(m1 ? l1[0].substring(1) : l1[0]);
+ int q2 = Integer.parseInt(m2 ? l2[0].substring(1) : l2[0]);
+ int r1 = Integer.parseInt(l1[m1 ? 1 : 2]);
+ int r2 = Integer.parseInt(l2[m2 ? 1 : 2]);
+ r1 = r1 - r1 % q1;
+ r2 = r2 - r2 % q2;
+ if (q1 < 1 || q2 < 1) throw new Exception("Quantities must be greater than 0.");
+
+ ItemStack i1 = m1 || r1 <= 0? null : ItemDb.get(l1[1], r1);
+ ItemStack qi1 = m1 ? null : ItemDb.get(l1[1], q1);
+ ItemStack qi2 = m2 ? null : ItemDb.get(l2[1], q2);
+
+ if (user.getName().equals(sign.getLines()[3].substring(2)))
+ {
+ if (m1)
+ {
+ user.giveMoney(r1);
+ }
+ else if (i1 != null)
+ {
+ user.getInventory().addItem(i1);
+ user.updateInventory();
+ }
+ r1 = 0;
+ sign.setLine(1, (m1 ? "$" + q1 : q1 + " " + l1[1]) + ":" + r1);
+ }
+ else
+ {
+ if (m1)
+ {
+ if (user.getMoney() < q1)
+ throw new Exception("You do not have sufficient funds.");
+ }
+ else
+ {
+ if (!InventoryWorkaround.containsItem((CraftInventory)user.getInventory(), true, qi1))
+ throw new Exception("You do not have " + q1 + "x " + l1[1] + ".");
+ }
+
+ if (r2 < q2) throw new Exception("The trade sign does not have enough supply left.");
+
+ if (m1)
+ user.takeMoney(q1);
+ else
+ InventoryWorkaround.removeItem((CraftInventory)user.getInventory(), true, qi1);
+
+ if (m2)
+ user.giveMoney(q2);
+ else
+ user.getInventory().addItem(qi2);
+
+ user.updateInventory();
+
+ r1 += q1;
+ r2 -= q2;
+
+ sign.setLine(0, "§1[Trade]");
+ sign.setLine(1, (m1 ? "$" + q1 : q1 + " " + l1[1]) + ":" + r1);
+ sign.setLine(2, (m2 ? "$" + q2 : q2 + " " + l2[1]) + ":" + r2);
+
+ user.sendMessage("§7Trade completed.");
+ }
+ }
+ catch (Throwable ex)
+ {
+ user.sendMessage("§cError: " + ex.getMessage());
+ }
+ return;
+ }
+ }
+}
diff --git a/Essentials/src/com/earth2me/essentials/JailPlayerListener.java b/Essentials/src/com/earth2me/essentials/JailPlayerListener.java
new file mode 100644
index 000000000..425cdff1c
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/JailPlayerListener.java
@@ -0,0 +1,28 @@
+package com.earth2me.essentials;
+
+import org.bukkit.Server;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.event.player.PlayerListener;
+
+
+public class JailPlayerListener extends PlayerListener
+{
+ private final Server server;
+ private final Essentials parent;
+
+ public JailPlayerListener(Essentials parent)
+ {
+ this.parent = parent;
+ this.server = parent.getServer();
+ }
+
+ @Override
+ public void onPlayerInteract(PlayerInteractEvent event)
+ {
+ User user = User.get(event.getPlayer());
+ if (user.isJailed())
+ {
+ event.setCancelled(true);
+ }
+ }
+}