summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-06-08 03:18:33 +0200
committersnowleo <schneeleo@gmail.com>2011-06-08 03:18:33 +0200
commit1b984f60a56644f3e63f8ed093ee2ca0a5df1e6d (patch)
treec741ee920dc650a009f6ec10144d5186f896584a
parentce8d75df9444bf0dd92334ec6fc2b7968e1f638c (diff)
downloadEssentials-1b984f60a56644f3e63f8ed093ee2ca0a5df1e6d.tar
Essentials-1b984f60a56644f3e63f8ed093ee2ca0a5df1e6d.tar.gz
Essentials-1b984f60a56644f3e63f8ed093ee2ca0a5df1e6d.tar.lz
Essentials-1b984f60a56644f3e63f8ed093ee2ca0a5df1e6d.tar.xz
Essentials-1b984f60a56644f3e63f8ed093ee2ca0a5df1e6d.zip
Refactoring of the signs
Todo: Eco signs, Protection signs New permission: essentials.signs.[signname].break
-rw-r--r--Essentials/src/com/earth2me/essentials/Charge.java81
-rw-r--r--Essentials/src/com/earth2me/essentials/ChargeException.java15
-rw-r--r--Essentials/src/com/earth2me/essentials/Essentials.java35
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java6
-rw-r--r--Essentials/src/com/earth2me/essentials/IEssentials.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/Teleport.java6
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandtpall.java6
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java257
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignBalance.java21
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignDisposal.java24
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignException.java15
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignFree.java37
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignHeal.java34
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignMail.java32
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignTime.java57
-rw-r--r--Essentials/src/com/earth2me/essentials/signs/SignWarp.java69
16 files changed, 622 insertions, 75 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Charge.java b/Essentials/src/com/earth2me/essentials/Charge.java
index 5098b3b1f..a84bfa918 100644
--- a/Essentials/src/com/earth2me/essentials/Charge.java
+++ b/Essentials/src/com/earth2me/essentials/Charge.java
@@ -5,27 +5,27 @@ import org.bukkit.inventory.ItemStack;
public class Charge
{
- private final String command;
- private final Double costs;
- private final ItemStack items;
- private final IEssentials ess;
+ private final transient String command;
+ private final transient Double costs;
+ private final transient ItemStack items;
+ private final transient IEssentials ess;
- public Charge(String command, IEssentials ess)
+ public Charge(final String command, final IEssentials ess)
{
this(command, null, null, ess);
}
- public Charge(double money, IEssentials ess)
+ public Charge(final double money, final IEssentials ess)
{
this(null, money, null, ess);
}
- public Charge(ItemStack items, IEssentials ess)
+ public Charge(final ItemStack items, final IEssentials ess)
{
this(null, null, items, ess);
}
-
- private Charge(String command, Double money, ItemStack item, IEssentials ess)
+
+ private Charge(final String command, final Double money, final ItemStack item, final IEssentials ess)
{
this.command = command;
this.costs = money;
@@ -33,46 +33,40 @@ public class Charge
this.ess = ess;
}
- public void isAffordableFor(IUser user) throws Exception
+ public void isAffordableFor(final IUser user) throws ChargeException
{
- double mon = user.getMoney();
- if (costs != null)
+ final double mon = user.getMoney();
+ if (costs != null
+ && mon < costs
+ && !user.isAuthorized("essentials.eco.loan"))
{
- if (mon < costs && !user.isAuthorized("essentials.eco.loan"))
- {
- throw new Exception(Util.i18n("notEnoughMoney"));
- }
+ throw new ChargeException(Util.i18n("notEnoughMoney"));
}
- if (items != null)
+
+ if (items != null
+ && !InventoryWorkaround.containsItem(user.getInventory(), true, items))
{
- if (!InventoryWorkaround.containsItem(user.getInventory(), true, items))
- {
- throw new Exception(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " ")));
- }
+ throw new ChargeException(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " ")));
}
- if (command != null && !command.isEmpty())
+
+ if (command != null && !command.isEmpty()
+ && !user.isAuthorized("essentials.nocommandcost.all")
+ && !user.isAuthorized("essentials.nocommandcost." + command)
+ && mon < ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command)
+ && !user.isAuthorized("essentials.eco.loan"))
{
- if (user.isAuthorized("essentials.nocommandcost.all")
- || user.isAuthorized("essentials.nocommandcost." + command))
- {
- return;
- }
- double cost = ess.getSettings().getCommandCost(command.startsWith("/") ? command.substring(1) : command);
- if (mon < cost && !user.isAuthorized("essentials.eco.loan"))
- {
- throw new Exception(Util.i18n("notEnoughMoney"));
- }
+ throw new ChargeException(Util.i18n("notEnoughMoney"));
}
}
- public void charge(IUser user) throws Exception
+ public void charge(final IUser user) throws ChargeException
{
- double mon = user.getMoney();
if (costs != null)
{
+ final double mon = user.getMoney();
if (mon < costs && !user.isAuthorized("essentials.eco.loan"))
{
- throw new Exception(Util.i18n("notEnoughMoney"));
+ throw new ChargeException(Util.i18n("notEnoughMoney"));
}
user.takeMoney(costs);
}
@@ -80,23 +74,20 @@ public class Charge
{
if (!InventoryWorkaround.containsItem(user.getInventory(), true, items))
{
- throw new Exception(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " ")));
+ throw new ChargeException(Util.format("missingItems", items.getAmount(), items.getType().toString().toLowerCase().replace("_", " ")));
}
InventoryWorkaround.removeItem(user.getInventory(), true, items);
user.updateInventory();
}
- if (command != null && !command.isEmpty())
+ if (command != null && !command.isEmpty()
+ && !user.isAuthorized("essentials.nocommandcost.all")
+ && !user.isAuthorized("essentials.nocommandcost." + command))
{
- if (user.isAuthorized("essentials.nocommandcost.all")
- || user.isAuthorized("essentials.nocommandcost." + command))
- {
- return;
- }
-
- double cost = ess.getSettings().getCommandCost(command.startsWith("/") ? command.substring(1) : command);
+ final double mon = user.getMoney();
+ final double cost = ess.getSettings().getCommandCost(command.charAt(0) == '/' ? command.substring(1) : command);
if (mon < cost && !user.isAuthorized("essentials.eco.loan"))
{
- throw new Exception(Util.i18n("notEnoughMoney"));
+ throw new ChargeException(Util.i18n("notEnoughMoney"));
}
user.takeMoney(cost);
}
diff --git a/Essentials/src/com/earth2me/essentials/ChargeException.java b/Essentials/src/com/earth2me/essentials/ChargeException.java
new file mode 100644
index 000000000..2fa4c7289
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/ChargeException.java
@@ -0,0 +1,15 @@
+package com.earth2me.essentials;
+
+
+public class ChargeException extends Exception
+{
+ public ChargeException(final String message)
+ {
+ super(message);
+ }
+
+ public ChargeException(final String message, final Throwable throwable)
+ {
+ super(message, throwable);
+ }
+}
diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java
index 8c5975929..edd27bbf7 100644
--- a/Essentials/src/com/earth2me/essentials/Essentials.java
+++ b/Essentials/src/com/earth2me/essentials/Essentials.java
@@ -474,21 +474,7 @@ public class Essentials extends JavaPlugin implements IEssentials
}
catch (Throwable ex)
{
- sender.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
- LogRecord lr = new LogRecord(Level.WARNING, Util.format("errorCallingCommand", commandLabel));
- lr.setThrown(ex);
- if (getSettings().isDebug())
- {
- logger.log(lr);
- }
- else
- {
- if (enableErrorLogging)
- {
- errorHandler.publish(lr);
- errorHandler.flush();
- }
- }
+ showError(sender, ex, commandLabel);
return true;
}
}
@@ -499,6 +485,25 @@ public class Essentials extends JavaPlugin implements IEssentials
}
}
+ public void showError(final CommandSender sender, final Throwable exception, final String commandLabel)
+ {
+ sender.sendMessage(Util.format("errorWithMessage", exception.getMessage()));
+ final LogRecord logRecord = new LogRecord(Level.WARNING, Util.format("errorCallingCommand", commandLabel));
+ logRecord.setThrown(exception);
+ if (getSettings().isDebug())
+ {
+ logger.log(logRecord);
+ }
+ else
+ {
+ if (enableErrorLogging)
+ {
+ errorHandler.publish(logRecord);
+ errorHandler.flush();
+ }
+ }
+ }
+
public void loadBanList()
{
//I don't like this but it needs to be done until CB fixors
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
index 0189c72a7..64206dac0 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsBlockListener.java
@@ -220,11 +220,7 @@ public class EssentialsBlockListener extends BlockListener
}
catch (Throwable ex)
{
- user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
- if (ess.getSettings().isDebug())
- {
- logger.log(Level.WARNING, ex.getMessage(), ex);
- }
+ ess.showError(user, ex, "onSignChange");
}
}
diff --git a/Essentials/src/com/earth2me/essentials/IEssentials.java b/Essentials/src/com/earth2me/essentials/IEssentials.java
index 824de99a9..426724c61 100644
--- a/Essentials/src/com/earth2me/essentials/IEssentials.java
+++ b/Essentials/src/com/earth2me/essentials/IEssentials.java
@@ -73,4 +73,6 @@ public interface IEssentials
EssentialsDependancyChecker getDependancyChecker();
IPermissionsHandler getPermissionsHandler();
+
+ void showError(final CommandSender sender, final Throwable exception, final String commandLabel);
}
diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java
index 404319ca8..535e6e088 100644
--- a/Essentials/src/com/earth2me/essentials/Teleport.java
+++ b/Essentials/src/com/earth2me/essentials/Teleport.java
@@ -101,11 +101,7 @@ public class Teleport implements Runnable
}
catch (Throwable ex)
{
- user.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
- if (ess.getSettings().isDebug())
- {
- logger.log(Level.WARNING, ex.getMessage(), ex);
- }
+ ess.showError(user.getBase(), ex, "teleport");
}
return;
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java
index 86311cd2e..7892fb345 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpall.java
@@ -50,11 +50,7 @@ public class Commandtpall extends EssentialsCommand
}
catch (Exception ex)
{
- sender.sendMessage(Util.format("errorWithMessage", ex.getMessage()));
- if (ess.getSettings().isDebug())
- {
- logger.log(Level.WARNING, ex.getMessage(), ex);
- }
+ ess.showError(sender, ex, getName());
}
}
}
diff --git a/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
new file mode 100644
index 000000000..3d5546e5e
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/signs/EssentialsSign.java
@@ -0,0 +1,257 @@
+package com.earth2me.essentials.signs;
+
+import com.earth2me.essentials.Charge;
+import com.earth2me.essentials.ChargeException;
+import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.ItemDb;
+import com.earth2me.essentials.User;
+import com.earth2me.essentials.Util;
+import org.bukkit.block.Block;
+import org.bukkit.block.Sign;
+import org.bukkit.craftbukkit.block.CraftSign;
+import org.bukkit.event.block.BlockBreakEvent;
+import org.bukkit.event.block.SignChangeEvent;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.inventory.ItemStack;
+
+
+public class EssentialsSign
+{
+ protected transient final String signName;
+ private static final String FORMAT_SUCCESS = "§1[%s]";
+ private static final String FORMAT_FAIL = "§4[%s]";
+
+ public EssentialsSign(final String signName)
+ {
+ this.signName = signName;
+ }
+
+ public final boolean onSignCreate(final SignChangeEvent event, final IEssentials ess)
+ {
+ final ISign sign = new EventSign(event);
+ sign.setLine(0, String.format(FORMAT_FAIL, this.signName));
+ final User user = ess.getUser(event.getPlayer());
+ if (!user.isAuthorized("essentials.signs." + signName.toLowerCase() + ".create"))
+ {
+ return false;
+ }
+ boolean ret;
+ try
+ {
+ ret = onSignCreate(sign, user, getUsername(user), ess);
+ }
+ catch (SignException ex)
+ {
+ ess.showError(user, ex, signName);
+ ret = false;
+ }
+ if (ret)
+ {
+ sign.setLine(0, String.format(FORMAT_SUCCESS, this.signName));
+ }
+ return ret;
+ }
+
+ private String getUsername(final User user)
+ {
+ return user.getName().substring(0, user.getName().length() > 14 ? 14 : user.getName().length());
+ }
+
+ public final boolean onSignInteract(final PlayerInteractEvent event, final IEssentials ess)
+ {
+ final ISign sign = new BlockSign(event.getClickedBlock());
+ final User user = ess.getUser(event.getPlayer());
+ try
+ {
+ return user.isAuthorized("essentials.signs." + signName.toLowerCase() + ".use")
+ && onSignInteract(sign, user, getUsername(user), ess);
+ }
+ catch (ChargeException ex)
+ {
+ ess.showError(user, ex, signName);
+ return false;
+ }
+ catch (SignException ex)
+ {
+ ess.showError(user, ex, signName);
+ return false;
+ }
+ }
+
+ public final boolean onSignBreak(final BlockBreakEvent event, final IEssentials ess)
+ {
+ final ISign sign = new BlockSign(event.getBlock());
+ final User user = ess.getUser(event.getPlayer());
+ try
+ {
+ return user.isAuthorized("essentials.signs." + signName.toLowerCase() + ".break")
+ && onSignBreak(sign, user, getUsername(user), ess);
+ }
+ catch (SignException ex)
+ {
+ ess.showError(user, ex, signName);
+ return false;
+ }
+ }
+
+ protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
+ {
+ return true;
+ }
+
+ protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
+ {
+ return true;
+ }
+
+ protected boolean onSignBreak(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
+ {
+ return true;
+ }
+
+ protected final void validateCharge(final ISign sign, final int index) throws SignException
+ {
+ final String line = sign.getLine(index);
+ if (line.isEmpty())
+ {
+ return;
+ }
+
+ final boolean isMoney = line.matches("^[^0-9-][\\.0-9]+");
+ if (isMoney)
+ {
+ final double quantity = Double.parseDouble(line.substring(1));
+ if (quantity <= 0)
+ {
+ throw new SignException(Util.i18n("moreThanZero"));
+ }
+ sign.setLine(index, Util.formatCurrency(quantity));
+ }
+ else
+ {
+ final String[] split = line.split("[ :-]+", 2);
+ if (split.length != 2)
+ {
+ throw new SignException(Util.i18n("invalidCharge"));
+ }
+ final int quantity = Integer.parseInt(split[0]);
+ if (quantity <= 1)
+ {
+ throw new SignException(Util.i18n("moreThanZero"));
+ }
+ final String item = split[1].toLowerCase();
+ if (!item.equalsIgnoreCase("times"))
+ {
+ getItemStack(item);
+ }
+ sign.setLine(index, quantity + " " + item);
+ }
+ }
+
+ protected final ItemStack getItemStack(final String itemName) throws SignException
+ {
+ try
+ {
+ return ItemDb.get(itemName);
+ }
+ catch (Exception ex)
+ {
+ throw new SignException(ex.getMessage(), ex);
+ }
+ }
+
+ protected final Charge getCharge(final ISign sign, final int index, final IEssentials ess) throws SignException
+ {
+ final String line = sign.getLine(index);
+ if (line.isEmpty())
+ {
+ return new Charge(signName.toLowerCase() + "sign", ess);
+ }
+
+ final boolean isMoney = line.matches("^[^0-9-][\\.0-9]+");
+ if (isMoney)
+ {
+ final double quantity = Double.parseDouble(line.substring(1));
+ if (quantity <= 0)
+ {
+ throw new SignException(Util.i18n("moreThanZero"));
+ }
+ return new Charge(quantity, ess);
+ }
+ else
+ {
+ final String[] split = line.split("[ :-]+", 2);
+ if (split.length != 2)
+ {
+ throw new SignException(Util.i18n("invalidCharge"));
+ }
+ final int quantity = Integer.parseInt(split[0]);
+ if (quantity <= 1)
+ {
+ throw new SignException(Util.i18n("moreThanZero"));
+ }
+ final String item = split[1].toLowerCase();
+ if (item.equalsIgnoreCase("times"))
+ {
+ sign.setLine(index, (quantity - 1) + " times");
+ return new Charge(signName.toLowerCase() + "sign", ess);
+ }
+ else
+ {
+ final ItemStack stack = getItemStack(item);
+ stack.setAmount(quantity);
+ return new Charge(quantity, ess);
+ }
+ }
+ }
+
+
+ static class EventSign implements ISign
+ {
+ private final transient SignChangeEvent event;
+
+ public EventSign(final SignChangeEvent event)
+ {
+ this.event = event;
+ }
+
+ public final String getLine(final int index)
+ {
+ return event.getLine(index);
+ }
+
+ public final void setLine(final int index, final String text)
+ {
+ event.setLine(index, text);
+ }
+ }
+
+
+ static class BlockSign implements ISign
+ {
+ private final transient Sign sign;
+
+ public BlockSign(final Block block)
+ {
+ this.sign = new CraftSign(block);
+ }
+
+ public final String getLine(final int index)
+ {
+ return sign.getLine(index);
+ }
+
+ public final void setLine(final int index, final String text)
+ {
+ sign.setLine(index, text);
+ }
+ }
+
+
+ public interface ISign
+ {
+ String getLine(final int index);
+
+ void setLine(final int index, final String text);
+ }
+}
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignBalance.java b/Essentials/src/com/earth2me/essentials/signs/SignBalance.java
new file mode 100644
index 000000000..3b961eef6
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/signs/SignBalance.java
@@ -0,0 +1,21 @@
+package com.earth2me.essentials.signs;
+
+import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.User;
+import com.earth2me.essentials.Util;
+
+
+public class SignBalance extends EssentialsSign
+{
+ public SignBalance()
+ {
+ super("Balance");
+ }
+
+ @Override
+ protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
+ {
+ player.sendMessage(Util.format("balance", player.getMoney()));
+ return true;
+ }
+}
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignDisposal.java b/Essentials/src/com/earth2me/essentials/signs/SignDisposal.java
new file mode 100644
index 000000000..e4d050305
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/signs/SignDisposal.java
@@ -0,0 +1,24 @@
+package com.earth2me.essentials.signs;
+
+import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.User;
+import net.minecraft.server.InventoryPlayer;
+import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
+
+
+public class SignDisposal extends EssentialsSign
+{
+ public SignDisposal()
+ {
+ super("Disposal");
+ }
+
+ @Override
+ protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess)
+ {
+ final CraftInventoryPlayer inv = new CraftInventoryPlayer(new InventoryPlayer(player.getHandle()));
+ inv.clear();
+ player.showInventory(inv);
+ return true;
+ }
+}
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignException.java b/Essentials/src/com/earth2me/essentials/signs/SignException.java
new file mode 100644
index 000000000..1195bbb68
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/signs/SignException.java
@@ -0,0 +1,15 @@
+package com.earth2me.essentials.signs;
+
+
+public class SignException extends Exception
+{
+ public SignException(final String message)
+ {
+ super(message);
+ }
+
+ public SignException(final String message, final Throwable throwable)
+ {
+ super(message, throwable);
+ }
+}
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignFree.java b/Essentials/src/com/earth2me/essentials/signs/SignFree.java
new file mode 100644
index 000000000..dfdb58bd5
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/signs/SignFree.java
@@ -0,0 +1,37 @@
+package com.earth2me.essentials.signs;
+
+import com.earth2me.essentials.Charge;
+import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.ItemDb;
+import com.earth2me.essentials.User;
+import net.minecraft.server.InventoryPlayer;
+import org.bukkit.craftbukkit.inventory.CraftInventoryPlayer;
+import org.bukkit.inventory.ItemStack;
+
+
+public class SignFree extends EssentialsSign
+{
+ public SignFree()
+ {
+ super("Free");
+ }
+
+ @Override
+ protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
+ {
+ getItemStack(sign.getLine(1));
+ return true;
+ }
+
+ @Override
+ protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
+ {
+ final ItemStack item = getItemStack(sign.getLine(1));
+ final CraftInventoryPlayer inv = new CraftInventoryPlayer(new InventoryPlayer(player.getHandle()));
+ inv.clear();
+ item.setAmount(9 * 4 * 64);
+ inv.addItem(item);
+ player.showInventory(inv);
+ return true;
+ }
+}
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignHeal.java b/Essentials/src/com/earth2me/essentials/signs/SignHeal.java
new file mode 100644
index 000000000..4426c9720
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/signs/SignHeal.java
@@ -0,0 +1,34 @@
+package com.earth2me.essentials.signs;
+
+import com.earth2me.essentials.Charge;
+import com.earth2me.essentials.ChargeException;
+import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.User;
+import com.earth2me.essentials.Util;
+
+
+public class SignHeal extends EssentialsSign
+{
+ public SignHeal()
+ {
+ super("Heal");
+ }
+
+ @Override
+ protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
+ {
+ validateCharge(sign, 1);
+ return true;
+ }
+
+ @Override
+ protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
+ {
+ final Charge charge = getCharge(sign, 1, ess);
+ charge.isAffordableFor(player);
+ player.setHealth(20);
+ player.sendMessage(Util.i18n("youAreHealed"));
+ charge.charge(player);
+ return true;
+ }
+}
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignMail.java b/Essentials/src/com/earth2me/essentials/signs/SignMail.java
new file mode 100644
index 000000000..1c3d162c4
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/signs/SignMail.java
@@ -0,0 +1,32 @@
+package com.earth2me.essentials.signs;
+
+import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.User;
+import com.earth2me.essentials.Util;
+import java.util.List;
+
+
+public class SignMail extends EssentialsSign
+{
+ public SignMail()
+ {
+ super("Mail");
+ }
+
+ @Override
+ protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
+ {
+ final List<String> mail = player.getMails();
+ if (mail.isEmpty())
+ {
+ player.sendMessage(Util.i18n("noNewMail"));
+ return false;
+ }
+ for (String s : mail)
+ {
+ player.sendMessage(s);
+ }
+ player.sendMessage(Util.i18n("markMailAsRead"));
+ return true;
+ }
+}
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignTime.java b/Essentials/src/com/earth2me/essentials/signs/SignTime.java
new file mode 100644
index 000000000..845cfbcca
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/signs/SignTime.java
@@ -0,0 +1,57 @@
+package com.earth2me.essentials.signs;
+
+import com.earth2me.essentials.Charge;
+import com.earth2me.essentials.ChargeException;
+import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.User;
+import com.earth2me.essentials.Util;
+
+
+public class SignTime extends EssentialsSign
+{
+ public SignTime()
+ {
+ super("Time");
+ }
+
+ @Override
+ protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
+ {
+ validateCharge(sign, 2);
+ final String timeString = sign.getLine(1);
+ if ("Day".equalsIgnoreCase(timeString))
+ {
+ sign.setLine(1, "§2Day");
+ return true;
+ }
+ if ("Night".equalsIgnoreCase(timeString))
+ {
+ sign.setLine(1, "§2Night");
+ return true;
+ }
+ throw new SignException(Util.i18n("onlyDayNight"));
+ }
+
+ @Override
+ protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
+ {
+ final Charge charge = getCharge(sign, 2, ess);
+ charge.isAffordableFor(player);
+ final String timeString = sign.getLine(1);
+ long time = player.getWorld().getTime();
+ time -= time % 24000;
+ if ("§2Day".equalsIgnoreCase(timeString))
+ {
+ player.getWorld().setTime(time + 24000);
+ charge.charge(player);
+ return true;
+ }
+ if ("§2Night".equalsIgnoreCase(timeString))
+ {
+ player.getWorld().setTime(time + 37700);
+ charge.charge(player);
+ return true;
+ }
+ throw new SignException(Util.i18n("onlyDayNight"));
+ }
+}
diff --git a/Essentials/src/com/earth2me/essentials/signs/SignWarp.java b/Essentials/src/com/earth2me/essentials/signs/SignWarp.java
new file mode 100644
index 000000000..0851991ab
--- /dev/null
+++ b/Essentials/src/com/earth2me/essentials/signs/SignWarp.java
@@ -0,0 +1,69 @@
+package com.earth2me.essentials.signs;
+
+import com.earth2me.essentials.Charge;
+import com.earth2me.essentials.ChargeException;
+import com.earth2me.essentials.IEssentials;
+import com.earth2me.essentials.User;
+
+
+public class SignWarp extends EssentialsSign
+{
+ public SignWarp()
+ {
+ super("Warp");
+ }
+
+ @Override
+ protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException
+ {
+ validateCharge(sign, 3);
+ final String warpName = sign.getLine(1);
+
+ if (warpName.isEmpty())
+ {
+ sign.setLine(1, "§dWarp name!");
+ return false;
+ }
+ else
+ {
+ try
+ {
+ ess.getWarps().getWarp(warpName);
+ }
+ catch (Exception ex)
+ {
+ throw new SignException(ex.getMessage(), ex);
+ }
+ final String group = sign.getLine(2);
+ if ("Everyone".equalsIgnoreCase(group))
+ {
+ sign.setLine(2, "§2Everyone");
+ }
+ return true;
+ }
+ }
+
+ @Override
+ protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException
+ {
+ final String warpName = sign.getLine(1);
+ final String group = sign.getLine(2);
+ if ((!group.isEmpty()
+ && ("§2Everyone".equals(group)
+ || player.inGroup(group)))
+ || (!ess.getSettings().getPerWarpPermission() || player.isAuthorized("essentials.warp." + warpName)))
+ {
+ final Charge charge = getCharge(sign, 3, ess);
+ try
+ {
+ player.getTeleport().warp(warpName, charge);
+ }
+ catch (Exception ex)
+ {
+ throw new SignException(ex.getMessage(), ex);
+ }
+ return true;
+ }
+ return false;
+ }
+}