summaryrefslogtreecommitdiffstats
path: root/EssentialsSigns/src
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2012-10-06 17:02:58 +0200
committersnowleo <schneeleo@gmail.com>2012-10-06 17:02:58 +0200
commitae10bcdffecb86122231e4ca57655d0bebb93996 (patch)
tree8dd546f05a64110b00150873978b3c810f184f70 /EssentialsSigns/src
parentbb798a1051b7ae6b184edbc866926b6c268e1dc2 (diff)
downloadEssentials-ae10bcdffecb86122231e4ca57655d0bebb93996.tar
Essentials-ae10bcdffecb86122231e4ca57655d0bebb93996.tar.gz
Essentials-ae10bcdffecb86122231e4ca57655d0bebb93996.tar.lz
Essentials-ae10bcdffecb86122231e4ca57655d0bebb93996.tar.xz
Essentials-ae10bcdffecb86122231e4ca57655d0bebb93996.zip
Cleanup
Diffstat (limited to 'EssentialsSigns/src')
-rw-r--r--EssentialsSigns/src/net/ess3/signs/EssentialsSign.java117
-rw-r--r--EssentialsSigns/src/net/ess3/signs/SignBlockListener.java18
-rw-r--r--EssentialsSigns/src/net/ess3/signs/SignGameMode.java4
-rw-r--r--EssentialsSigns/src/net/ess3/signs/SignInfo.java4
-rw-r--r--EssentialsSigns/src/net/ess3/signs/SignRepair.java8
-rw-r--r--EssentialsSigns/src/net/ess3/signs/SignTrade.java3
6 files changed, 74 insertions, 80 deletions
diff --git a/EssentialsSigns/src/net/ess3/signs/EssentialsSign.java b/EssentialsSigns/src/net/ess3/signs/EssentialsSign.java
index 60a76b9bd..4aa10c25a 100644
--- a/EssentialsSigns/src/net/ess3/signs/EssentialsSign.java
+++ b/EssentialsSigns/src/net/ess3/signs/EssentialsSign.java
@@ -1,6 +1,5 @@
package net.ess3.signs;
-
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
@@ -23,12 +22,12 @@ public class EssentialsSign
{
private static final Set<Material> EMPTY_SET = new HashSet<Material>();
protected transient final String signName;
-
+
public EssentialsSign(final String signName)
{
this.signName = signName;
}
-
+
public final boolean onSignCreate(final SignChangeEvent event, final IEssentials ess)
{
final ISign sign = new EventSign(event);
@@ -60,22 +59,22 @@ public class EssentialsSign
// Return true, so the player sees the wrong sign.
return true;
}
-
+
public String getSuccessName()
{
return _("signFormatSuccess", this.signName);
}
-
+
public String getTemplateName()
{
return _("signFormatTemplate", this.signName);
}
-
+
private String getUsername(final IUser user)
{
return user.getName().substring(0, user.getName().length() > 13 ? 13 : user.getName().length());
}
-
+
public final boolean onSignInteract(final Block block, final Player player, final IEssentials ess)
{
final ISign sign = new BlockSign(block);
@@ -96,7 +95,7 @@ public class EssentialsSign
return false;
}
}
-
+
public final boolean onSignBreak(final Block block, final Player player, final IEssentials ess)
{
final ISign sign = new BlockSign(block);
@@ -112,22 +111,22 @@ public class EssentialsSign
return false;
}
}
-
+
protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException
{
return true;
}
-
+
protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException
{
return true;
}
-
+
protected boolean onSignBreak(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException
{
return true;
}
-
+
public final boolean onBlockPlace(final Block block, final Player player, final IEssentials ess)
{
final IUser user = ess.getUserMap().getUser(player);
@@ -145,7 +144,7 @@ public class EssentialsSign
}
return false;
}
-
+
public final boolean onBlockInteract(final Block block, final Player player, final IEssentials ess)
{
final IUser user = ess.getUserMap().getUser(player);
@@ -163,7 +162,7 @@ public class EssentialsSign
}
return false;
}
-
+
public final boolean onBlockBreak(final Block block, final Player player, final IEssentials ess)
{
final IUser user = ess.getUserMap().getUser(player);
@@ -177,32 +176,32 @@ public class EssentialsSign
}
return false;
}
-
+
public boolean onBlockBreak(final Block block, final IEssentials ess)
{
return true;
}
-
+
public boolean onBlockExplode(final Block block, final IEssentials ess)
{
return true;
}
-
+
public boolean onBlockBurn(final Block block, final IEssentials ess)
{
return true;
}
-
+
public boolean onBlockIgnite(final Block block, final IEssentials ess)
{
return true;
}
-
+
public boolean onBlockPush(final Block block, final IEssentials ess)
{
return true;
}
-
+
public static boolean checkIfBlockBreaksSigns(final Block block)
{
final Block sign = block.getRelative(BlockFace.UP);
@@ -231,32 +230,32 @@ public class EssentialsSign
}
return false;
}
-
+
public static boolean isValidSign(final ISign sign)
{
return sign.getLine(0).matches("ยง1\\[.*\\]");
}
-
+
protected boolean onBlockPlace(final Block block, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException
{
return true;
}
-
+
protected boolean onBlockInteract(final Block block, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException
{
return true;
}
-
+
protected boolean onBlockBreak(final Block block, final IUser player, final String username, final IEssentials ess) throws SignException
{
return true;
}
-
+
public Set<Material> getBlocks()
{
return EMPTY_SET;
}
-
+
protected final void validateTrade(final ISign sign, final int index, final IEssentials ess) throws SignException
{
final String line = sign.getLine(index).trim();
@@ -271,7 +270,7 @@ public class EssentialsSign
sign.setLine(index, FormatUtil.shortCurrency(money, ess));
}
}
-
+
protected final void validateTrade(final ISign sign, final int amountIndex, final int itemIndex,
final IUser player, final IEssentials ess) throws SignException
{
@@ -287,7 +286,7 @@ public class EssentialsSign
sign.setLine(amountIndex, Integer.toString(item.getAmount()));
sign.setLine(itemIndex, sign.getLine(itemIndex).trim());
}
-
+
protected final Trade getTrade(final ISign sign, final int amountIndex, final int itemIndex,
final IUser player, final IEssentials ess) throws SignException
{
@@ -305,7 +304,7 @@ public class EssentialsSign
item.setAmount(amount);
return new Trade(item, ess);
}
-
+
protected final void validateInteger(final ISign sign, final int index) throws SignException
{
final String line = sign.getLine(index).trim();
@@ -316,7 +315,7 @@ public class EssentialsSign
final int quantity = getIntegerPositive(line);
sign.setLine(index, Integer.toString(quantity));
}
-
+
protected final int getIntegerPositive(final String line) throws SignException
{
final int quantity = getInteger(line);
@@ -326,13 +325,13 @@ public class EssentialsSign
}
return quantity;
}
-
+
protected final int getInteger(final String line) throws SignException
{
try
{
final int quantity = Integer.parseInt(line);
-
+
return quantity;
}
catch (NumberFormatException ex)
@@ -340,7 +339,7 @@ public class EssentialsSign
throw new SignException("Invalid sign", ex);
}
}
-
+
protected final ItemStack getItemStack(final String itemName, final int quantity, final IEssentials ess) throws SignException
{
try
@@ -354,13 +353,13 @@ public class EssentialsSign
throw new SignException(ex.getMessage(), ex);
}
}
-
+
protected final Double getMoney(final String line) throws SignException
{
final boolean isMoney = line.matches("^[^0-9-\\.][\\.0-9]+$");
return isMoney ? getDoublePositive(line.substring(1)) : null;
}
-
+
protected final Double getDoublePositive(final String line) throws SignException
{
final double quantity = getDouble(line);
@@ -370,7 +369,7 @@ public class EssentialsSign
}
return quantity;
}
-
+
protected final Double getDouble(final String line) throws SignException
{
try
@@ -382,12 +381,12 @@ public class EssentialsSign
throw new SignException(ex.getMessage(), ex);
}
}
-
+
protected final Trade getTrade(final ISign sign, final int index, final IEssentials ess) throws SignException
{
return getTrade(sign, index, 1, ess);
}
-
+
protected final Trade getTrade(final ISign sign, final int index, final int decrement, final IEssentials ess) throws SignException
{
final String line = sign.getLine(index).trim();
@@ -395,7 +394,7 @@ public class EssentialsSign
{
return new Trade(signName.toLowerCase(Locale.ENGLISH) + "sign", ess);
}
-
+
final Double money = getMoney(line);
if (money == null)
{
@@ -405,7 +404,7 @@ public class EssentialsSign
throw new SignException(_("invalidCharge"));
}
final int quantity = getIntegerPositive(split[0]);
-
+
final String item = split[1].toLowerCase(Locale.ENGLISH);
if (item.equalsIgnoreCase("times"))
{
@@ -429,89 +428,89 @@ public class EssentialsSign
return new Trade(money, ess);
}
}
-
-
+
+
static class EventSign implements ISign
{
private final transient SignChangeEvent event;
private final transient Block block;
-
+
public EventSign(final SignChangeEvent event)
{
this.event = event;
this.block = event.getBlock();
}
-
+
@Override
public final String getLine(final int index)
{
return event.getLine(index);
}
-
+
@Override
public final void setLine(final int index, final String text)
{
event.setLine(index, text);
}
-
+
@Override
public Block getBlock()
{
return block;
}
-
+
@Override
public void updateSign()
{
}
}
-
-
+
+
static class BlockSign implements ISign
{
private final transient Sign sign;
private final transient Block block;
-
+
public BlockSign(final Block block)
{
this.block = block;
this.sign = (Sign)block.getState();
}
-
+
@Override
public final String getLine(final int index)
{
return sign.getLine(index);
}
-
+
@Override
public final void setLine(final int index, final String text)
{
sign.setLine(index, text);
}
-
+
@Override
public final Block getBlock()
{
return block;
}
-
+
@Override
public final void updateSign()
{
sign.update();
}
}
-
-
+
+
public interface ISign
{
String getLine(final int index);
-
+
void setLine(final int index, final String text);
-
+
public Block getBlock();
-
+
void updateSign();
}
}
diff --git a/EssentialsSigns/src/net/ess3/signs/SignBlockListener.java b/EssentialsSigns/src/net/ess3/signs/SignBlockListener.java
index d5cf4ff14..e7fc11d44 100644
--- a/EssentialsSigns/src/net/ess3/signs/SignBlockListener.java
+++ b/EssentialsSigns/src/net/ess3/signs/SignBlockListener.java
@@ -69,14 +69,14 @@ public class SignBlockListener implements Listener
return true;
}
for (EssentialsSign sign : plugin.getSettings().getEnabledSigns())
+ {
+ if (sign.getBlocks().contains(block.getType())
+ && !sign.onBlockBreak(block, player, ess))
{
- if (sign.getBlocks().contains(block.getType())
- && !sign.onBlockBreak(block, player, ess))
- {
- LOGGER.log(Level.INFO, "A block was protected by a sign.");
- return true;
- }
- }
+ LOGGER.log(Level.INFO, "A block was protected by a sign.");
+ return true;
+ }
+ }
return false;
}
@@ -208,7 +208,7 @@ public class SignBlockListener implements Listener
{
return;
}
-
+
for (Block block : event.getBlocks())
{
if (((block.getTypeId() == WALL_SIGN
@@ -238,7 +238,7 @@ public class SignBlockListener implements Listener
{
return;
}
-
+
if (event.isSticky())
{
final Block block = event.getBlock();
diff --git a/EssentialsSigns/src/net/ess3/signs/SignGameMode.java b/EssentialsSigns/src/net/ess3/signs/SignGameMode.java
index e8a8e5b79..1109956ab 100644
--- a/EssentialsSigns/src/net/ess3/signs/SignGameMode.java
+++ b/EssentialsSigns/src/net/ess3/signs/SignGameMode.java
@@ -35,13 +35,13 @@ public class SignGameMode extends EssentialsSign
{
final Trade charge = getTrade(sign, 2, ess);
final String mode = sign.getLine(1).trim();
-
+
if (mode.isEmpty())
{
throw new SignException(_("invalidSignLine", 2));
}
charge.isAffordableFor(player);
-
+
//this needs to be fixed
player.getPlayer().setGameMode(player.getPlayer().getGameMode() == GameMode.SURVIVAL ? GameMode.CREATIVE : GameMode.SURVIVAL);
player.sendMessage(_("gameMode", _(player.getPlayer().getGameMode().toString().toLowerCase(Locale.ENGLISH)), player.getPlayer().getDisplayName()));
diff --git a/EssentialsSigns/src/net/ess3/signs/SignInfo.java b/EssentialsSigns/src/net/ess3/signs/SignInfo.java
index c738667b8..dd37d6462 100644
--- a/EssentialsSigns/src/net/ess3/signs/SignInfo.java
+++ b/EssentialsSigns/src/net/ess3/signs/SignInfo.java
@@ -1,6 +1,5 @@
package net.ess3.signs;
-
import java.io.IOException;
import net.ess3.api.ChargeException;
import net.ess3.api.IEssentials;
@@ -53,6 +52,3 @@ public class SignInfo extends EssentialsSign
return true;
}
}
-
-
-
diff --git a/EssentialsSigns/src/net/ess3/signs/SignRepair.java b/EssentialsSigns/src/net/ess3/signs/SignRepair.java
index 9da4b4d3f..1610f16f8 100644
--- a/EssentialsSigns/src/net/ess3/signs/SignRepair.java
+++ b/EssentialsSigns/src/net/ess3/signs/SignRepair.java
@@ -23,10 +23,10 @@ public class SignRepair extends EssentialsSign
{
sign.setLine(1, "Hand");
}
- else if (!repairTarget.equalsIgnoreCase("all") && !repairTarget.equalsIgnoreCase("hand") )
+ else if (!repairTarget.equalsIgnoreCase("all") && !repairTarget.equalsIgnoreCase("hand"))
{
throw new SignException(_("invalidSignLine", 2));
- }
+ }
validateTrade(sign, 2, ess);
return true;
}
@@ -36,7 +36,7 @@ public class SignRepair extends EssentialsSign
{
final Trade charge = getTrade(sign, 2, ess);
charge.isAffordableFor(player);
-
+
Commandrepair command = new Commandrepair();
command.init(ess, "repair");
String[] args = new String[]
@@ -51,7 +51,7 @@ public class SignRepair extends EssentialsSign
{
throw new SignException(ex.getMessage(), ex);
}
- charge.charge(player);
+ charge.charge(player);
return true;
}
}
diff --git a/EssentialsSigns/src/net/ess3/signs/SignTrade.java b/EssentialsSigns/src/net/ess3/signs/SignTrade.java
index 3038cc27c..dc5129cbb 100644
--- a/EssentialsSigns/src/net/ess3/signs/SignTrade.java
+++ b/EssentialsSigns/src/net/ess3/signs/SignTrade.java
@@ -10,8 +10,7 @@ import org.bukkit.inventory.ItemStack;
//TODO: Sell Enchantment on Trade signs?
public class SignTrade extends EssentialsSign
-{
-
+{
public SignTrade()
{
super("Trade");