summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Essentials/src/com/earth2me/essentials/Essentials.java23
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java362
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsEcoBlockListener.java250
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java211
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java301
-rw-r--r--Essentials/src/com/earth2me/essentials/JailPlayerListener.java44
6 files changed, 98 insertions, 1093 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java
index e9fc12c38..89ccc900d 100644
--- a/Essentials/src/com/earth2me/essentials/Essentials.java
+++ b/Essentials/src/com/earth2me/essentials/Essentials.java
@@ -189,8 +189,6 @@ public class Essentials extends JavaPlugin implements IEssentials
pm.registerEvent(Type.PLAYER_ANIMATION, playerListener, Priority.High, this);
final EssentialsBlockListener blockListener = new EssentialsBlockListener(this);
- //pm.registerEvent(Type.SIGN_CHANGE, blockListener, Priority.Low, this);
- //pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Lowest, this);
pm.registerEvent(Type.BLOCK_PLACE, blockListener, Priority.Lowest, this);
final SignBlockListener signBlockListener = new SignBlockListener(this);
@@ -214,11 +212,12 @@ public class Essentials extends JavaPlugin implements IEssentials
jail = new Jail(this);
final JailPlayerListener jailPlayerListener = new JailPlayerListener(this);
confList.add(jail);
- pm.registerEvent(Type.BLOCK_BREAK, jail, Priority.High, this);
- pm.registerEvent(Type.BLOCK_DAMAGE, jail, Priority.High, this);
- pm.registerEvent(Type.BLOCK_PLACE, jail, Priority.High, this);
- pm.registerEvent(Type.PLAYER_INTERACT, jailPlayerListener, Priority.High, this);
- //attachEcoListeners();
+ pm.registerEvent(Type.BLOCK_BREAK, jail, Priority.Low, this);
+ pm.registerEvent(Type.BLOCK_DAMAGE, jail, Priority.Low, this);
+ pm.registerEvent(Type.BLOCK_PLACE, jail, Priority.Low, this);
+ pm.registerEvent(Type.PLAYER_INTERACT, jailPlayerListener, Priority.Low, this);
+ pm.registerEvent(Type.PLAYER_RESPAWN, jailPlayerListener, Priority.High, this);
+ pm.registerEvent(Type.PLAYER_TELEPORT, jailPlayerListener, Priority.High, this);
if (settings.isNetherEnabled() && getServer().getWorlds().size() < 2)
{
@@ -599,16 +598,6 @@ public class Essentials extends JavaPlugin implements IEssentials
}
}
- private void attachEcoListeners()
- {
- //PluginManager pm = getServer().getPluginManager();
- //EssentialsEcoBlockListener ecoBlockListener = new EssentialsEcoBlockListener(this);
- //EssentialsEcoPlayerListener ecoPlayerListener = new EssentialsEcoPlayerListener(this);
- //pm.registerEvent(Type.PLAYER_INTERACT, ecoPlayerListener, Priority.High, this);
- //pm.registerEvent(Type.BLOCK_BREAK, ecoBlockListener, Priority.High, this);
- //pm.registerEvent(Type.SIGN_CHANGE, ecoBlockListener, Priority.Monitor, this);
- }
-
public CraftScheduler getScheduler()
{
return (CraftScheduler)this.getServer().getScheduler();
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
index ff31e5aab..7cd15180b 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
@@ -1,15 +1,9 @@
package com.earth2me.essentials;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Material;
-import org.bukkit.block.Block;
-import org.bukkit.block.BlockFace;
-import org.bukkit.block.Sign;
-import org.bukkit.craftbukkit.block.CraftSign;
-import org.bukkit.event.block.*;
+import org.bukkit.event.block.BlockListener;
+import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
@@ -17,15 +11,6 @@ public class EssentialsBlockListener extends BlockListener
{
private final IEssentials ess;
private static final Logger logger = Logger.getLogger("Minecraft");
- public final static List<Material> protectedBlocks = new ArrayList<Material>(4);
-
- static
- {
- protectedBlocks.add(Material.CHEST);
- protectedBlocks.add(Material.BURNING_FURNACE);
- protectedBlocks.add(Material.FURNACE);
- protectedBlocks.add(Material.DISPENSER);
- }
public EssentialsBlockListener(IEssentials ess)
{
@@ -33,216 +18,12 @@ public class EssentialsBlockListener extends BlockListener
}
@Override
- @Deprecated
- public void onBlockBreak(BlockBreakEvent event)
- {
- if (event.isCancelled())
- {
- return;
- }
- if (ess.getSettings().areSignsDisabled())
- {
- return;
- }
- User user = ess.getUser(event.getPlayer());
- if (protectedBlocks.contains(event.getBlock().getType()) && !user.isAuthorized("essentials.signs.protection.override"))
- {
- if (isBlockProtected(event.getBlock(), user))
- {
- event.setCancelled(true);
- user.sendMessage(Util.format("noDestroyPermission", event.getBlock().getType().toString().toLowerCase()));
- return;
- }
- }
-
- if (checkProtectionSign(event.getBlock(), user) != NOSIGN
- && checkProtectionSign(event.getBlock(), user) != OWNER)
- {
- event.setCancelled(true);
- user.sendMessage(Util.format("noDestroyPermission", event.getBlock().getType().toString().toLowerCase()));
- }
- }
-
- @Override
- @Deprecated
- public void onSignChange(SignChangeEvent event)
- {
- if (event.isCancelled())
- {
- return;
- }
- if (ess.getSettings().areSignsDisabled())
- {
- return;
- }
- User user = ess.getUser(event.getPlayer());
- String username = user.getName().substring(0, user.getName().length() > 14 ? 14 : user.getName().length());
-
- try
- {
- if (event.getLine(0).equalsIgnoreCase("[Protection]"))
- {
- Block block = event.getBlock();
- if (user.isAuthorized("essentials.signs.protection.create") && hasAdjacentChest(block) && !isBlockProtected(block, user))
- {
- event.setLine(0, "§1[Protection]");
- }
- else
- {
- event.setLine(0, "§4[Protection]");
- }
- event.setLine(3, username);
- return;
- }
- if (event.getLine(0).equalsIgnoreCase("[Disposal]"))
- {
- if (user.isAuthorized("essentials.signs.disposal.create"))
- {
- event.setLine(0, "§1[Disposal]");
- }
- else
- {
- event.setLine(0, "§4[Disposal]");
- }
- return;
- }
- if (event.getLine(0).equalsIgnoreCase("[Heal]"))
- {
- event.setLine(0, "§4[Heal]");
- if (user.isAuthorized("essentials.signs.heal.create"))
- {
- if (!event.getLine(1).isEmpty())
- {
- String[] l1 = event.getLine(1).split("[ :-]+", 2);
- boolean m1 = l1[0].matches("^[^0-9][\\.0-9]+");
- double q1 = Double.parseDouble(m1 ? l1[0].substring(1) : l1[0]);
- if (q1 < 1 || (!m1 && (int)q1 < 1))
- {
- throw new Exception(Util.i18n("moreThanZero"));
- }
- if (!m1)
- {
- ItemDb.get(l1[1]);
- }
- event.setLine(1, (m1 ? Util.formatCurrency(q1) : (int)q1 + " " + l1[1]));
- }
- event.setLine(0, "§1[Heal]");
- }
- return;
- }
- if (event.getLine(0).equalsIgnoreCase("[Free]"))
- {
- event.setLine(0, "§4[Free]");
- ItemDb.get(event.getLine(1));
- if (user.isAuthorized("essentials.signs.free.create"))
- {
- event.setLine(0, "§1[Free]");
- }
- return;
- }
- if (event.getLine(0).equalsIgnoreCase("[Mail]"))
- {
- if (user.isAuthorized("essentials.signs.mail.create"))
- {
- event.setLine(0, "§1[Mail]");
- }
- else
- {
- event.setLine(0, "§4[Mail]");
- }
- return;
- }
- if (event.getLine(0).equalsIgnoreCase("[Balance]"))
- {
- if (user.isAuthorized("essentials.signs.balance.create"))
- {
- event.setLine(0, "§1[Balance]");
- }
- else
- {
- event.setLine(0, "§4[Balance]");
- }
- return;
- }
- if (event.getLine(0).equalsIgnoreCase("[Warp]"))
- {
- event.setLine(0, "§4[Warp]");
- if (user.isAuthorized("essentials.signs.warp.create"))
- {
- if (!event.getLine(3).isEmpty())
- {
- String[] l1 = event.getLine(3).split("[ :-]+", 2);
- boolean m1 = l1[0].matches("^[^0-9][\\.0-9]+");
- if (!m1 && l1.length != 2)
- {
- throw new Exception(Util.format("invalidSignLine", 4));
- }
- double q1 = Double.parseDouble(m1 ? l1[0].substring(1) : l1[0]);
- if ((int)q1 < 1)
- {
- throw new Exception(Util.i18n("moreThanZero"));
- }
- if (!m1)
- {
- ItemDb.get(l1[1]);
- }
- event.setLine(3, (m1 ? Util.formatCurrency(q1) : (int)q1 + " " + l1[1]));
- }
- if (event.getLine(1).isEmpty())
- {
- event.setLine(1, "§dWarp name!");
- return;
- }
- else
- {
- ess.getWarps().getWarp(event.getLine(1));
- if (event.getLine(2).equalsIgnoreCase("Everyone"))
- {
- event.setLine(2, "§2Everyone");
- }
- event.setLine(0, "§1[Warp]");
- }
- }
- return;
- }
- if (event.getLine(0).equalsIgnoreCase("[Time]"))
- {
- if (user.isAuthorized("essentials.signs.time.create")
- && (event.getLine(1).equalsIgnoreCase("day")
- || event.getLine(1).equalsIgnoreCase("night")))
- {
- event.setLine(0, "§1[Time]");
- }
- else
- {
- event.setLine(0, "§4[Time]");
- }
- return;
- }
- }
- catch (Throwable ex)
- {
- ess.showError(user, ex, "onSignChange");
- }
- }
-
- @Override
public void onBlockPlace(BlockPlaceEvent event)
{
if (event.isCancelled())
{
return;
}
- /*Block signBlock = event.getBlockAgainst();
- if (signBlock.getType() == Material.WALL_SIGN || signBlock.getType() == Material.SIGN_POST)
- {
- Sign sign = new CraftSign(signBlock);
- if (sign.getLine(0).matches("§1\\[[a-zA-Z]+\\]"))
- {
- event.setCancelled(true);
- return;
- }
- }*/
final User user = ess.getUser(event.getPlayer());
// Do not rely on getItemInHand();
// http://leaky.bukkit.org/issues/663
@@ -325,143 +106,4 @@ public class EssentialsBlockListener extends BlockListener
});
}
}
-
- @Deprecated
- private boolean hasAdjacentChest(Block block)
- {
- Block[] faces = getAdjacentBlocks(block);
- for (Block b : faces)
- {
- if (protectedBlocks.contains(b.getType()))
- {
- return true;
- }
- }
- return false;
- }
- private static final int NOT_ALLOWED = 0;
- private static final int ALLOWED = 1;
- private static final int NOSIGN = 2;
- private static final int OWNER = 3;
-
- @Deprecated
- private int checkProtectionSign(Block block, User user)
- {
- String username = user.getName().substring(0, user.getName().length() > 14 ? 14 : user.getName().length());
- if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)
- {
- Sign sign = new CraftSign(block);
- if (sign.getLine(0).equalsIgnoreCase("§1[Protection]") && !user.isAuthorized("essentials.signs.protection.override"))
- {
- for (int i = 1; i <= 2; i++)
- {
- String line = sign.getLine(i);
- if (line.startsWith("(") && line.endsWith(")"))
- {
- line = line.substring(1, line.length() - 1);
- if (user.inGroup(line))
- {
- return ALLOWED;
- }
- }
- else if (line.equalsIgnoreCase(username))
- {
- return ALLOWED;
- }
- }
- if (sign.getLine(3).equalsIgnoreCase(username))
- {
- return OWNER;
- }
- return NOT_ALLOWED;
- }
- }
- return NOSIGN;
- }
-
- @Deprecated
- private static Block[] getAdjacentBlocks(Block block)
- {
- return new Block[]
- {
- block.getFace(BlockFace.NORTH),
- block.getFace(BlockFace.SOUTH),
- block.getFace(BlockFace.EAST),
- block.getFace(BlockFace.WEST),
- block.getFace(BlockFace.DOWN),
- block.getFace(BlockFace.UP)
- };
- }
-
- @Deprecated
- private boolean isBlockProtected(Block block, User user)
- {
- Block[] faces = getAdjacentBlocks(block);
- boolean protect = false;
- for (Block b : faces)
- {
- int check = checkProtectionSign(b, user);
- if (check == NOT_ALLOWED)
- {
- protect = true;
- }
- if (check == ALLOWED || check == OWNER)
- {
- return false;
- }
-
- if (protectedBlocks.contains(b.getType()))
- {
- Block[] faceChest = getAdjacentBlocks(b);
-
- for (Block a : faceChest)
- {
- check = checkProtectionSign(a, user);
- if (check == NOT_ALLOWED)
- {
- protect = true;
- }
- if (check == ALLOWED || check == OWNER)
- {
- return false;
- }
- }
- }
- }
- return protect;
- }
-
- @Deprecated
- private static boolean isBlockProtected(Block block)
- {
- Block[] faces = getAdjacentBlocks(block);
- for (Block b : faces)
- {
- if (b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN)
- {
- Sign sign = new CraftSign(b);
- if (sign.getLine(0).equalsIgnoreCase("§1[Protection]"))
- {
- return true;
- }
- }
- if (protectedBlocks.contains(b.getType()))
- {
- Block[] faceChest = getAdjacentBlocks(b);
-
- for (Block a : faceChest)
- {
- if (a.getType() == Material.SIGN_POST || a.getType() == Material.WALL_SIGN)
- {
- Sign sign = new CraftSign(a);
- if (sign.getLine(0).equalsIgnoreCase("§1[Protection]"))
- {
- return true;
- }
- }
- }
- }
- }
- return false;
- }
}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEcoBlockListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEcoBlockListener.java
deleted file mode 100644
index bb12f8d4c..000000000
--- a/Essentials/src/com/earth2me/essentials/EssentialsEcoBlockListener.java
+++ /dev/null
@@ -1,250 +0,0 @@
-package com.earth2me.essentials;
-
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.bukkit.Material;
-import org.bukkit.block.Sign;
-import org.bukkit.craftbukkit.block.CraftSign;
-import org.bukkit.event.block.BlockBreakEvent;
-import org.bukkit.event.block.BlockListener;
-import org.bukkit.event.block.SignChangeEvent;
-import org.bukkit.inventory.ItemStack;
-
-@Deprecated
-public class EssentialsEcoBlockListener extends BlockListener
-{
- private final IEssentials ess;
- private static final Logger logger = Logger.getLogger("Minecraft");
-
- public EssentialsEcoBlockListener(Essentials ess)
- {
- this.ess = ess;
- }
-
- @Override
- public void onBlockBreak(BlockBreakEvent event)
- {
- if (event.isCancelled())
- {
- return;
- }
- if (ess.getSettings().areSignsDisabled())
- {
- return;
- }
- User user = ess.getUser(event.getPlayer());
- String username = user.getName().substring(0, user.getName().length() > 13 ? 13 : user.getName().length());
- if (event.getBlock().getType() != Material.WALL_SIGN && event.getBlock().getType() != Material.SIGN_POST)
- {
- return;
- }
- Sign sign = new CraftSign(event.getBlock());
-
- if (sign.getLine(0).equals("§1[Trade]"))
- {
- if (!sign.getLine(3).substring(2).equals(username))
- {
- if (!user.isOp())
- {
- event.setCancelled(true);
- }
- return;
- }
- try
- {
- String[] l1 = sign.getLines()[1].split("[ :-]+");
- String[] l2 = sign.getLines()[2].split("[ :-]+");
- boolean m1 = l1[0].matches("[^0-9][0-9]+(\\.[0-9]+)?");
- boolean m2 = l2[0].matches("[^0-9][0-9]+(\\.[0-9]+)?");
- double q1 = Double.parseDouble(m1 ? l1[0].substring(1) : l1[0]);
- double q2 = Double.parseDouble(m2 ? l2[0].substring(1) : l2[0]);
- double r1 = Double.parseDouble(l1[m1 ? 1 : 2]);
- double r2 = Double.parseDouble(l2[m2 ? 1 : 2]);
- if ((!m1 & q1 < 1) || (!m2 & q2 < 1))
- {
- throw new Exception(Util.i18n("moreThanZero"));
- }
-
- ItemStack i1 = m1 || r1 <= 0 ? null : ItemDb.get(l1[1], (int)r1);
- ItemStack i2 = m2 || r2 <= 0 ? null : ItemDb.get(l2[1], (int)r2);
-
- if (m1)
- {
- user.giveMoney(r1);
- }
- else if (i1 != null)
- {
- Map<Integer, ItemStack> leftOver = user.getInventory().addItem(i1);
- for (ItemStack itemStack : leftOver.values())
- {
- InventoryWorkaround.dropItem(user.getLocation(), itemStack);
- }
- }
-
- if (m2)
- {
- user.giveMoney(r2);
- }
- else if (i2 != null)
- {
- Map<Integer, ItemStack> leftOver = user.getInventory().addItem(i2);
- for (ItemStack itemStack : leftOver.values())
- {
- InventoryWorkaround.dropItem(user.getLocation(), itemStack);
- }
- }
- user.updateInventory();
-
- sign.setType(Material.AIR);
- }
- catch (Throwable ex)
- {
- user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
- if (ess.getSettings().isDebug())
- {
- logger.log(Level.WARNING, ex.getMessage(), ex);
- }
- }
- return;
- }
- }
-
- @Override
- public void onSignChange(SignChangeEvent event)
- {
- if (ess.getSettings().areSignsDisabled())
- {
- return;
- }
- User user = ess.getUser(event.getPlayer());
- String username = user.getName().substring(0, user.getName().length() > 13 ? 13 : user.getName().length());
-
- if ((event.getLine(0).equalsIgnoreCase("[Buy]") || event.getLine(0).equalsIgnoreCase("#1[Buy]")) && user.isAuthorized("essentials.signs.buy.create"))
- {
- try
- {
- event.setLine(0, "§1[Buy]");
- event.setLine(1, "" + Math.abs(Integer.parseInt(event.getLine(1))));
- ItemStack is = ItemDb.get(event.getLine(2));
- if (is.getTypeId() == 0 || Math.abs(Integer.parseInt(event.getLine(1))) == 0)
- {
- throw new Exception("Don't sell air.");
- }
- double price = Double.parseDouble(event.getLine(3).replaceAll("[^0-9\\.]", ""));
- event.setLine(3, Util.formatCurrency(price));
- }
- catch (Throwable ex)
- {
- user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
- if (ess.getSettings().isDebug())
- {
- logger.log(Level.WARNING, ex.getMessage(), ex);
- }
- event.setLine(0, "§4[Buy]");
- event.setLine(1, "#");
- event.setLine(2, "Item");
- event.setLine(3, "$Price");
- }
- return;
- }
-
- if ((event.getLine(0).equalsIgnoreCase("[Sell]") || event.getLine(0).equalsIgnoreCase("#1[Sell]")) && user.isAuthorized("essentials.signs.sell.create"))
- {
- try
- {
- event.setLine(0, "§1[Sell]");
- event.setLine(1, "" + Math.abs(Integer.parseInt(event.getLine(1))));
- ItemStack is = ItemDb.get(event.getLine(2));
- if (is.getTypeId() == 0 || Math.abs(Integer.parseInt(event.getLine(1))) == 0)
- {
- throw new Exception("Can't buy air.");
- }
- double price = Double.parseDouble(event.getLine(3).replaceAll("[^0-9\\.]", ""));
- event.setLine(3, Util.formatCurrency(price));
- }
- catch (Throwable ex)
- {
- user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
- if (ess.getSettings().isDebug())
- {
- logger.log(Level.WARNING, ex.getMessage(), ex);
- }
- event.setLine(0, "§4[Sell]");
- event.setLine(1, "#");
- event.setLine(2, "Item");
- event.setLine(3, "$Price");
- }
- return;
- }
-
- if ((event.getLine(0).equalsIgnoreCase("[Trade]") || event.getLine(0).equalsIgnoreCase("#1[Trade]")) && user.isAuthorized("essentials.signs.trade.create"))
- {
- try
- {
- String[] l1 = event.getLine(1).split("[ :-]+");
- String[] l2 = event.getLine(2).split("[ :-]+");
- boolean m1 = l1[0].matches("[^0-9][0-9]+(\\.[0-9]+)?");
- boolean m2 = l2[0].matches("[^0-9][0-9]+(\\.[0-9]+)?");
- double q1 = Double.parseDouble(m1 ? l1[0].substring(1) : l1[0]);
- double q2 = Double.parseDouble(m2 ? l2[0].substring(1) : l2[0]);
- if (m1 ? l1.length != 1 : l1.length != 2)
- {
- throw new Exception(Util.format("invalidSignLine", 2));
- }
- if (m2 ? l2.length != 2 : l2.length != 3)
- {
- throw new Exception(Util.format("invalidSignLine", 3));
- }
- double r2 = Double.parseDouble(l2[m2 ? 1 : 2]);
- r2 = m2 ? r2 : r2 - r2 % q2;
- if ((!m1 & q1 < 1) || (!m2 & q2 < 1) || r2 < 1)
- {
- throw new Exception(Util.i18n("moreThanZero"));
- }
- if (!m1)
- {
- ItemDb.get(l1[1]);
- }
-
- if (m2)
- {
- if (user.getMoney() < r2)
- {
- throw new Exception(Util.i18n("notEnoughMoney"));
- }
- user.takeMoney(r2);
- //user.sendMessage("r2: " + r2 + " q2: " + q2);
- }
- else
- {
- ItemStack i2 = ItemDb.get(l2[1], (int)r2);
- if (!InventoryWorkaround.containsItem(user.getInventory(), true, i2))
- {
- throw new Exception(Util.format("missingItems", (int)r2, l2[1]));
- }
- InventoryWorkaround.removeItem(user.getInventory(), true, i2);
- user.updateInventory();
- }
-
- event.setLine(0, "§1[Trade]");
- event.setLine(1, (m1 ? Util.formatCurrency(q1) : (int)q1 + " " + l1[1]) + ":0");
- event.setLine(2, (m2 ? Util.formatCurrency(q2) : (int)q2 + " " + l2[1]) + ":" + (m2 ? Util.roundDouble(r2) : "" + (int)r2));
- event.setLine(3, "§8" + username);
- }
- catch (Throwable ex)
- {
- user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
- if (ess.getSettings().isDebug())
- {
- logger.log(Level.WARNING, ex.getMessage(), ex);
- }
- event.setLine(0, "§4[Trade]");
- event.setLine(1, "# ItemOr" + ess.getSettings().getCurrencySymbol());
- event.setLine(2, "# ItemOr" + ess.getSettings().getCurrencySymbol() + ":#");
- event.setLine(3, "§8" + username);
- }
- return;
- }
- }
-}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java
deleted file mode 100644
index 72154c886..000000000
--- a/Essentials/src/com/earth2me/essentials/EssentialsEcoPlayerListener.java
+++ /dev/null
@@ -1,211 +0,0 @@
-package com.earth2me.essentials;
-
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.bukkit.Material;
-import org.bukkit.block.Sign;
-import org.bukkit.craftbukkit.block.CraftSign;
-import org.bukkit.event.block.Action;
-import org.bukkit.event.player.PlayerInteractEvent;
-import org.bukkit.event.player.PlayerListener;
-import org.bukkit.inventory.ItemStack;
-
-@Deprecated
-public class EssentialsEcoPlayerListener extends PlayerListener
-{
- private final IEssentials ess;
- private static final Logger logger = Logger.getLogger("Minecraft");
-
- EssentialsEcoPlayerListener(IEssentials ess)
- {
- this.ess = ess;
- }
-
- @Override
- public void onPlayerInteract(PlayerInteractEvent event)
- {
- if (ess.getSettings().areSignsDisabled())
- {
- return;
- }
- if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
- {
- return;
- }
- User user = ess.getUser(event.getPlayer());
- String username = user.getName().substring(0, user.getName().length() > 13 ? 13 : user.getName().length());
- 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);
- double cost = Double.parseDouble(sign.getLine(3).substring(1));
- if (user.getMoney() < cost)
- {
- throw new Exception(Util.i18n("notEnoughMoney"));
- }
- user.takeMoney(cost);
- Map<Integer, ItemStack> leftOver = user.getInventory().addItem(item);
- for (ItemStack itemStack : leftOver.values())
- {
- InventoryWorkaround.dropItem(user.getLocation(), itemStack);
- }
- user.updateInventory();
- }
- catch (Throwable ex)
- {
- user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
- if (ess.getSettings().isDebug())
- {
- logger.log(Level.WARNING, ex.getMessage(), ex);
- }
- }
- 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);
- double cost = Double.parseDouble(sign.getLine(3).substring(1));
-
- if (!InventoryWorkaround.containsItem(user.getInventory(), true, item))
- {
- throw new Exception(Util.format("missingItems", amount, sign.getLine(2)));
- }
- user.giveMoney(cost);
- InventoryWorkaround.removeItem(user.getInventory(), true, item);
- user.updateInventory();
- }
- catch (Throwable ex)
- {
- user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
- if (ess.getSettings().isDebug())
- {
- logger.log(Level.WARNING, ex.getMessage(), ex);
- }
- }
- return;
- }
-
- if (sign.getLine(0).equals("§1[Trade]") && user.isAuthorized("essentials.signs.trade.use"))
- {
- try
- {
- String[] l1 = sign.getLine(1).split("[ :-]+");
- String[] l2 = sign.getLine(2).split("[ :-]+");
- boolean m1 = l1[0].matches("[^0-9][0-9]+(\\.[0-9]+)?");
- boolean m2 = l2[0].matches("[^0-9][0-9]+(\\.[0-9]+)?");
- double q1 = Double.parseDouble(m1 ? l1[0].substring(1) : l1[0]);
- double q2 = Double.parseDouble(m2 ? l2[0].substring(1) : l2[0]);
- double r1 = Double.parseDouble(l1[m1 ? 1 : 2]);
- double r2 = Double.parseDouble(l2[m2 ? 1 : 2]);
- r1 = m1 ? r1 : r1 - r1 % q1;
- r2 = m2 ? r2 : r2 - r2 % q2;
- if ((!m1 & q1 < 1) || (!m2 & q2 < 1))
- {
- throw new Exception(Util.i18n("moreThanZero"));
- }
-
- ItemStack i1 = m1 || r1 <= 0 ? null : ItemDb.get(l1[1], (int)r1);
- ItemStack qi1 = m1 ? null : ItemDb.get(l1[1], (int)q1);
- ItemStack qi2 = m2 ? null : ItemDb.get(l2[1], (int)q2);
-
- if (username.equals(sign.getLine(3).substring(2)))
- {
- if (m1)
- {
- user.giveMoney(r1);
- }
- else if (i1 != null)
- {
- Map<Integer, ItemStack> leftOver = user.getInventory().addItem(i1);
- for (ItemStack itemStack : leftOver.values())
- {
- InventoryWorkaround.dropItem(user.getLocation(), itemStack);
- }
- user.updateInventory();
- }
- r1 = 0;
- sign.setLine(1, (m1 ? Util.formatCurrency(q1) : ((int)q1) + " " + l1[1]) + ":0");
- sign.update();
- }
- else
- {
- if (m1)
- {
- if (user.getMoney() < q1)
- {
- throw new Exception(Util.i18n("notEnoughMoney"));
- }
- }
- else
- {
- if (!InventoryWorkaround.containsItem(user.getInventory(), true, qi1))
- {
- throw new Exception(Util.format("missingItems", (int)q1, l1[1]));
- }
- }
-
- if (r2 < q2)
- {
- throw new Exception(Util.i18n("tradeSignEmpty"));
- }
-
- if (m1)
- {
- user.takeMoney(q1);
- }
- else
- {
- InventoryWorkaround.removeItem(user.getInventory(), true, qi1);
- }
-
- if (m2)
- {
- user.giveMoney(q2);
- }
- else
- {
- Map<Integer, ItemStack> leftOver = user.getInventory().addItem(qi2);
- for (ItemStack itemStack : leftOver.values())
- {
- InventoryWorkaround.dropItem(user.getLocation(), itemStack);
- }
- }
-
- user.updateInventory();
-
- r1 += q1;
- r2 -= q2;
-
-
- sign.setLine(0, "§1[Trade]");
- sign.setLine(1, (m1 ? Util.formatCurrency(q1) : ((int)q1) + " " + l1[1]) + ":" + (m1 ? Util.roundDouble(r1) : "" + (int)r1));
- sign.setLine(2, (m2 ? Util.formatCurrency(q2) : ((int)q2) + " " + l2[1]) + ":" + (m2 ? Util.roundDouble(r2) : "" + (int)r2));
- sign.update();
- user.sendMessage(Util.i18n("tradeCompleted"));
- }
- }
- catch (Throwable ex)
- {
- user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
- if (ess.getSettings().isDebug())
- {
- logger.log(Level.WARNING, ex.getMessage(), ex);
- }
- }
- return;
- }
- }
-}
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
index a975b7c44..64905a4bc 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
@@ -9,7 +9,6 @@ import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
-import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerAnimationEvent;
@@ -32,34 +31,22 @@ import org.bukkit.inventory.ItemStack;
public class EssentialsPlayerListener extends PlayerListener
{
- private static final Logger logger = Logger.getLogger("Minecraft");
- private final Server server;
- private final IEssentials ess;
- private final EssentialsBlockListener essBlockListener;
+ private static final Logger LOGGER = Logger.getLogger("Minecraft");
+ private final transient Server server;
+ private final transient IEssentials ess;
- public EssentialsPlayerListener(IEssentials parent)
+ public EssentialsPlayerListener(final IEssentials parent)
{
this.ess = parent;
this.server = parent.getServer();
- essBlockListener = new EssentialsBlockListener(parent);
}
@Override
- public void onPlayerRespawn(PlayerRespawnEvent event)
+ public void onPlayerRespawn(final PlayerRespawnEvent event)
{
- User user = ess.getUser(event.getPlayer());
+ final User user = ess.getUser(event.getPlayer());
user.setDisplayName(user.getNick());
updateCompass(user);
- if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty())
- {
- try
- {
- event.setRespawnLocation(ess.getJail().getJail(user.getJail()));
- }
- catch (Exception ex)
- {
- }
- }
if (ess.getSettings().changeDisplayName())
{
user.setDisplayName(user.getNick());
@@ -67,18 +54,18 @@ public class EssentialsPlayerListener extends PlayerListener
}
@Override
- public void onPlayerChat(PlayerChatEvent event)
+ public void onPlayerChat(final PlayerChatEvent event)
{
- User user = ess.getUser(event.getPlayer());
+ final User user = ess.getUser(event.getPlayer());
if (user.isMuted())
{
event.setCancelled(true);
- logger.info(Util.format("mutedUserSpeaks", user.getName()));
+ LOGGER.info(Util.format("mutedUserSpeaks", user.getName()));
}
- Iterator<Player> it = event.getRecipients().iterator();
+ final Iterator<Player> it = event.getRecipients().iterator();
while (it.hasNext())
{
- User u = ess.getUser(it.next());
+ final User u = ess.getUser(it.next());
if (u.isIgnoredPlayer(user.getName()))
{
it.remove();
@@ -96,7 +83,7 @@ public class EssentialsPlayerListener extends PlayerListener
}
@Override
- public void onPlayerMove(PlayerMoveEvent event)
+ public void onPlayerMove(final PlayerMoveEvent event)
{
if (event.isCancelled())
{
@@ -116,7 +103,7 @@ public class EssentialsPlayerListener extends PlayerListener
}
final Block block = event.getPlayer().getWorld().getBlockAt(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
- List<World> worlds = server.getWorlds();
+ final List<World> worlds = server.getWorlds();
if (block.getType() == Material.PORTAL && worlds.size() > 1 && user.isAuthorized("essentials.portal"))
{
@@ -125,7 +112,6 @@ public class EssentialsPlayerListener extends PlayerListener
return;
}
- Location loc = event.getTo();
World nether = server.getWorld(ess.getSettings().getNetherName());
if (nether == null)
{
@@ -149,7 +135,7 @@ public class EssentialsPlayerListener extends PlayerListener
{
factor = ess.getSettings().getNetherRatio();
}
- else if (user.getWorld().getEnvironment() != world.getEnvironment())
+ else if (user.getWorld().getEnvironment() == World.Environment.NORMAL && world.getEnvironment() == World.Environment.NETHER)
{
factor = 1.0 / ess.getSettings().getNetherRatio();
}
@@ -158,6 +144,7 @@ public class EssentialsPlayerListener extends PlayerListener
factor = 1.0;
}
+ Location loc = event.getTo();
int x = loc.getBlockX();
int y = loc.getBlockY();
int z = loc.getBlockZ();
@@ -182,14 +169,14 @@ public class EssentialsPlayerListener extends PlayerListener
if (world.getEnvironment() == World.Environment.NETHER || ess.getSettings().getGenerateExitPortals())
{
portal = NetherPortal.createPortal(dest);
- logger.info(Util.format("userCreatedPortal", event.getPlayer().getName()));
+ LOGGER.info(Util.format("userCreatedPortal", event.getPlayer().getName()));
user.sendMessage(Util.i18n("generatingPortal"));
loc = portal.getSpawn();
}
}
else
{
- logger.info(Util.format("userUsedPortal", event.getPlayer().getName()));
+ LOGGER.info(Util.format("userUsedPortal", event.getPlayer().getName()));
user.sendMessage(Util.i18n("usingPortal"));
loc = portal.getSpawn();
}
@@ -215,15 +202,12 @@ public class EssentialsPlayerListener extends PlayerListener
}
@Override
- public void onPlayerQuit(PlayerQuitEvent event)
+ public void onPlayerQuit(final PlayerQuitEvent event)
{
- User user = ess.getUser(event.getPlayer());
- if (ess.getSettings().removeGodOnDisconnect())
+ final User user = ess.getUser(event.getPlayer());
+ if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled())
{
- if (user.isGodModeEnabled())
- {
- user.toggleGodModeEnabled();
- }
+ user.toggleGodModeEnabled();
}
if (user.getSavedInventory() != null)
{
@@ -235,7 +219,7 @@ public class EssentialsPlayerListener extends PlayerListener
return;
}
user.dispose();
- Thread thread = new Thread(new Runnable()
+ final Thread thread = new Thread(new Runnable()
{
public void run()
{
@@ -248,7 +232,7 @@ public class EssentialsPlayerListener extends PlayerListener
rt.gc();
mem = rt.freeMemory() - mem;
mem /= 1024 * 1024;
- logger.log(Level.INFO, Util.format("freedMemory", mem));
+ LOGGER.log(Level.INFO, Util.format("freedMemory", mem));
}
catch (InterruptedException ex)
{
@@ -261,15 +245,15 @@ public class EssentialsPlayerListener extends PlayerListener
}
@Override
- public void onPlayerJoin(PlayerJoinEvent event)
+ public void onPlayerJoin(final PlayerJoinEvent event)
{
ess.getBackup().onPlayerJoin();
- User user = ess.getUser(event.getPlayer());
+ final User user = ess.getUser(event.getPlayer());
//we do not know the ip address on playerlogin so we need to do this here.
if (user.isIpBanned())
{
- String banReason = user.getBanReason();
+ final String banReason = user.getBanReason();
user.kickPlayer(banReason != null && !banReason.isEmpty() ? banReason : Util.i18n("defaultBanReason"));
return;
}
@@ -298,7 +282,7 @@ public class EssentialsPlayerListener extends PlayerListener
if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail"))
{
- List<String> mail = user.getMails();
+ final List<String> mail = user.getMails();
if (mail.isEmpty())
{
user.sendMessage(Util.i18n("noNewMail"));
@@ -311,18 +295,18 @@ public class EssentialsPlayerListener extends PlayerListener
}
@Override
- public void onPlayerLogin(PlayerLoginEvent event)
+ public void onPlayerLogin(final PlayerLoginEvent event)
{
if (event.getResult() != Result.ALLOWED)
{
return;
}
- User user = ess.getUser(event.getPlayer());
+ final User user = ess.getUser(event.getPlayer());
user.setNPC(false);
if (user.isBanned())
{
- String banReason = user.getBanReason();
+ final String banReason = user.getBanReason();
event.disallow(Result.KICK_BANNED, banReason != null && !banReason.isEmpty() ? banReason : Util.i18n("defaultBanReason"));
return;
}
@@ -337,7 +321,7 @@ public class EssentialsPlayerListener extends PlayerListener
updateCompass(user);
}
- private void updateCompass(User user)
+ private void updateCompass(final User user)
{
try
{
@@ -355,28 +339,16 @@ public class EssentialsPlayerListener extends PlayerListener
{
return;
}
- User user = ess.getUser(event.getPlayer());
+ final User user = ess.getUser(event.getPlayer());
if (ess.getSettings().changeDisplayName())
{
user.setDisplayName(user.getNick());
}
- if (!user.isJailed() || user.getJail() == null || user.getJail().isEmpty())
- {
- return;
- }
- try
- {
- event.setTo(ess.getJail().getJail(user.getJail()));
- }
- catch (Exception ex)
- {
- logger.log(Level.WARNING, Util.i18n("returnPlayerToJailError"), ex);
- }
- user.sendMessage(Util.i18n("jailMessage"));
+ updateCompass(user);
}
@Override
- public void onPlayerInteract(PlayerInteractEvent event)
+ public void onPlayerInteract(final PlayerInteractEvent event)
{
if (event.isCancelled())
{
@@ -386,29 +358,12 @@ public class EssentialsPlayerListener extends PlayerListener
{
return;
}
- User user = ess.getUser(event.getPlayer());
- if (user.isJailed())
- {
- event.setCancelled(true);
- return;
- }
- /*if (!ess.getSettings().areSignsDisabled() && EssentialsBlockListener.protectedBlocks.contains(event.getClickedBlock().getType()))
- {
- if (!user.isAuthorized("essentials.signs.protection.override"))
- {
- if (essBlockListener.isBlockProtected(event.getClickedBlock(), user))
- {
- event.setCancelled(true);
- user.sendMessage(Util.format("noAccessPermission", event.getClickedBlock().getType().toString().toLowerCase()));
- return;
- }
- }
- }*/
if (ess.getSettings().getBedSetsHome() && event.getClickedBlock().getType() == Material.BED_BLOCK)
{
try
{
+ final User user = ess.getUser(event.getPlayer());
user.setHome();
user.sendMessage(Util.i18n("homeSetToBed"));
}
@@ -416,175 +371,13 @@ public class EssentialsPlayerListener extends PlayerListener
{
}
}
-
-
- /*if (ess.getSettings().areSignsDisabled())
- {
- return;
- }
- if (event.getClickedBlock().getType() != Material.WALL_SIGN && event.getClickedBlock().getType() != Material.SIGN_POST)
- {
- return;
- }
- Sign sign = new CraftSign(event.getClickedBlock());
-
- try
- {
- if (sign.getLine(0).equals("§1[Free]") && user.isAuthorized("essentials.signs.free.use"))
- {
- ItemStack item = ItemDb.get(sign.getLine(1));
- CraftInventoryPlayer inv = new CraftInventoryPlayer(new InventoryPlayer(user.getHandle()));
- inv.clear();
- item.setAmount(9 * 4 * 64);
- inv.addItem(item);
- user.showInventory(inv);
- return;
- }
- if (sign.getLine(0).equals("§1[Disposal]") && user.isAuthorized("essentials.signs.disposal.use"))
- {
- CraftInventoryPlayer inv = new CraftInventoryPlayer(new InventoryPlayer(user.getHandle()));
- inv.clear();
- user.showInventory(inv);
- return;
- }
- if (sign.getLine(0).equals("§1[Heal]") && user.isAuthorized("essentials.signs.heal.use"))
- {
- if (!sign.getLine(1).isEmpty())
- {
- String[] l1 = sign.getLine(1).split("[ :-]+");
- boolean m1 = l1[0].matches("^[^0-9][\\.0-9]+");
- double q1 = Double.parseDouble(m1 ? l1[0].substring(1) : l1[0]);
- if (!m1 && (int)q1 < 1)
- {
- throw new Exception(Util.i18n("moreThanZero"));
- }
- if (m1)
- {
- if (user.getMoney() < q1)
- {
- throw new Exception(Util.i18n("notEnoughMoney"));
- }
- user.takeMoney(q1);
- user.sendMessage(Util.format("moneyTaken", Util.formatCurrency(q1)));
- }
- else
- {
- ItemStack i = ItemDb.get(l1[1], (int)q1);
- if (!InventoryWorkaround.containsItem(user.getInventory(), true, i))
- {
- throw new Exception(Util.format("missingItems", (int)q1, l1[1]));
- }
- InventoryWorkaround.removeItem(user.getInventory(), true, i);
- user.updateInventory();
- }
- }
- user.setHealth(20);
- user.sendMessage(Util.i18n("youAreHealed"));
- return;
- }
- if (sign.getLine(0).equals("§1[Mail]") && user.isAuthorized("essentials.signs.mail.use") && user.isAuthorized("essentials.mail"))
- {
- List<String> mail = user.getMails();
- if (mail.isEmpty())
- {
- user.sendMessage(Util.i18n("noNewMail"));
- return;
- }
- for (String s : mail)
- {
- user.sendMessage(s);
- }
- user.sendMessage(Util.i18n("markMailAsRead"));
- return;
- }
- if (sign.getLine(0).equals("§1[Balance]") && user.isAuthorized("essentials.signs.balance.use"))
- {
- user.sendMessage(Util.format("balance", user.getMoney()));
- return;
- }
- if (sign.getLine(0).equals("§1[Warp]"))
- {
-
- if (!sign.getLine(2).isEmpty())
- {
- if (sign.getLine(2).equals("§2Everyone"))
- {
- Trade charge = chargeUserForWarp(sign, user);
- user.getTeleport().warp(sign.getLine(1), charge);
- return;
- }
- if (user.inGroup(sign.getLine(2)))
- {
- Trade charge = chargeUserForWarp(sign, user);
- user.getTeleport().warp(sign.getLine(1), charge);
- return;
- }
- }
- if (user.isAuthorized("essentials.signs.warp.use")
- && (!ess.getSettings().getPerWarpPermission() || user.isAuthorized("essentials.warp." + sign.getLine(1))))
- {
- Trade charge = chargeUserForWarp(sign, user);
- user.getTeleport().warp(sign.getLine(1), charge);
- }
- return;
- }
- if (sign.getLine(0).equals("§1[Time]") && user.isAuthorized("essentials.signs.time.use"))
- {
- long time = user.getWorld().getTime();
- time -= time % 24000;
- if ("day".equalsIgnoreCase(sign.getLine(1)))
- {
- user.getWorld().setTime(time + 24000);
- return;
- }
- if ("night".equalsIgnoreCase(sign.getLine(1)))
- {
- user.getWorld().setTime(time + 37700);
- return;
- }
- throw new Exception(Util.i18n("onlyDayNight"));
- }
- }
- catch (Throwable ex)
- {
- user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
- if (ess.getSettings().isDebug())
- {
- logger.log(Level.WARNING, ex.getMessage(), ex);
- }
- }*/
- }
-
- @Deprecated
- private Trade 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][\\.0-9]+");
- double q1 = Double.parseDouble(m1 ? l1[0].substring(1) : l1[0]);
- if (!m1 && (int)q1 < 1)
- {
- throw new Exception(Util.i18n("moreThanZero"));
- }
- if (m1)
- {
- return new Trade(q1, ess);
- }
- else
- {
- ItemStack i = ItemDb.get(l1[1], (int)q1);
- return new Trade(i, ess);
- }
- }
- return new Trade("warpsign", ess);
}
@Override
- public void onPlayerEggThrow(PlayerEggThrowEvent event)
+ public void onPlayerEggThrow(final PlayerEggThrowEvent event)
{
- User user = ess.getUser(event.getPlayer());
- ItemStack is = new ItemStack(Material.EGG, 1);
+ final User user = ess.getUser(event.getPlayer());
+ final ItemStack is = new ItemStack(Material.EGG, 1);
if (user.hasUnlimited(is))
{
user.getInventory().addItem(is);
@@ -593,7 +386,7 @@ public class EssentialsPlayerListener extends PlayerListener
}
@Override
- public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event)
+ public void onPlayerBucketEmpty(final PlayerBucketEmptyEvent event)
{
final User user = ess.getUser(event.getPlayer());
if (user.hasUnlimited(new ItemStack(event.getBucket())))
@@ -610,24 +403,24 @@ public class EssentialsPlayerListener extends PlayerListener
}
@Override
- public void onPlayerAnimation(PlayerAnimationEvent event)
+ public void onPlayerAnimation(final PlayerAnimationEvent event)
{
usePowertools(event);
}
- private void usePowertools(PlayerAnimationEvent event)
+ private void usePowertools(final PlayerAnimationEvent event)
{
if (event.getAnimationType() != PlayerAnimationType.ARM_SWING)
{
return;
}
- User user = ess.getUser(event.getPlayer());
- ItemStack is = user.getItemInHand();
+ final User user = ess.getUser(event.getPlayer());
+ final ItemStack is = user.getItemInHand();
if (is == null || is.getType() == Material.AIR)
{
return;
}
- String command = user.getPowertool(is);
+ final String command = user.getPowertool(is);
if (command == null || command.isEmpty())
{
return;
@@ -651,14 +444,14 @@ public class EssentialsPlayerListener extends PlayerListener
}
@Override
- public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
+ public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
{
if (event.isCancelled())
{
return;
}
- User user = ess.getUser(event.getPlayer());
- String cmd = event.getMessage().toLowerCase().split(" ")[0].replace("/", "").toLowerCase();
+ final User user = ess.getUser(event.getPlayer());
+ final String cmd = event.getMessage().toLowerCase().split(" ")[0].replace("/", "").toLowerCase();
if (("msg".equals(cmd) || "r".equals(cmd) || "mail".equals(cmd)))
{
for (Player player : ess.getServer().getOnlinePlayers())
diff --git a/Essentials/src/com/earth2me/essentials/JailPlayerListener.java b/Essentials/src/com/earth2me/essentials/JailPlayerListener.java
index 865485d8b..5ba333952 100644
--- a/Essentials/src/com/earth2me/essentials/JailPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/JailPlayerListener.java
@@ -1,11 +1,16 @@
package com.earth2me.essentials;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerListener;
+import org.bukkit.event.player.PlayerRespawnEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
public class JailPlayerListener extends PlayerListener
{
+ private static final Logger LOGGER = Logger.getLogger("Minecraft");
private final IEssentials ess;
public JailPlayerListener(IEssentials parent)
@@ -16,10 +21,47 @@ public class JailPlayerListener extends PlayerListener
@Override
public void onPlayerInteract(PlayerInteractEvent event)
{
- User user = ess.getUser(event.getPlayer());
+ final User user = ess.getUser(event.getPlayer());
if (user.isJailed())
{
event.setCancelled(true);
}
}
+
+ @Override
+ public void onPlayerRespawn(PlayerRespawnEvent event)
+ {
+ final User user = ess.getUser(event.getPlayer());
+ if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty())
+ {
+ try
+ {
+ event.setRespawnLocation(ess.getJail().getJail(user.getJail()));
+ }
+ catch (Exception ex)
+ {
+ }
+ }
+ }
+
+ @Override
+ public void onPlayerTeleport(PlayerTeleportEvent event)
+ {
+ final User user = ess.getUser(event.getPlayer());
+ if (!user.isJailed() || user.getJail() == null || user.getJail().isEmpty())
+ {
+ return;
+ }
+ try
+ {
+ event.setTo(ess.getJail().getJail(user.getJail()));
+ }
+ catch (Exception ex)
+ {
+ LOGGER.log(Level.WARNING, Util.i18n("returnPlayerToJailError"), ex);
+ }
+ user.sendMessage(Util.i18n("jailMessage"));
+ }
+
+
}