The rest of Wundarks commit, cleaned

This commit is contained in:
snowleo 2011-06-07 01:55:39 +02:00
parent 5c258c03dc
commit 640f51564a
2 changed files with 179 additions and 95 deletions

View File

@ -35,8 +35,14 @@ public class EssentialsBlockListener extends BlockListener
@Override
public void onBlockBreak(BlockBreakEvent event)
{
if (event.isCancelled()) return;
if (ess.getSettings().areSignsDisabled()) return;
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"))
{
@ -48,8 +54,8 @@ public class EssentialsBlockListener extends BlockListener
}
}
if (checkProtectionSign(event.getBlock(), user) != NOSIGN &&
checkProtectionSign(event.getBlock(), user) != OWNER)
if (checkProtectionSign(event.getBlock(), user) != NOSIGN
&& checkProtectionSign(event.getBlock(), user) != OWNER)
{
event.setCancelled(true);
user.sendMessage(Util.format("noDestroyPermission", event.getBlock().getType().toString().toLowerCase()));
@ -59,8 +65,14 @@ public class EssentialsBlockListener extends BlockListener
@Override
public void onSignChange(SignChangeEvent event)
{
if (event.isCancelled()) return;
if (ess.getSettings().areSignsDisabled()) return;
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());
@ -70,18 +82,26 @@ public class EssentialsBlockListener extends BlockListener
{
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]"))
@ -94,8 +114,14 @@ public class EssentialsBlockListener extends BlockListener
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]);
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]");
@ -107,29 +133,40 @@ public class EssentialsBlockListener extends BlockListener
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]"))
if (event.getLine(0).equalsIgnoreCase("[Warp]"))
{
event.setLine(0, "§4[Warp]");
if (user.isAuthorized("essentials.signs.warp.create")) {
if (user.isAuthorized("essentials.signs.warp.create"))
{
if (!event.getLine(3).isEmpty())
{
String[] l1 = event.getLine(3).split("[ :-]+", 2);
@ -139,16 +176,26 @@ public class EssentialsBlockListener extends BlockListener
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]);
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()) {
if (event.getLine(1).isEmpty())
{
event.setLine(1, "§dWarp name!");
return;
} else {
}
else
{
ess.getWarps().getWarp(event.getLine(1));
if (event.getLine(2).equalsIgnoreCase("Everyone")) {
if (event.getLine(2).equalsIgnoreCase("Everyone"))
{
event.setLine(2, "§2Everyone");
}
event.setLine(0, "§1[Warp]");
@ -158,10 +205,16 @@ public class EssentialsBlockListener extends BlockListener
}
if (event.getLine(0).equalsIgnoreCase("[Time]"))
{
if (user.isAuthorized("essentials.signs.time.create"))
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;
}
}
@ -178,7 +231,10 @@ public class EssentialsBlockListener extends BlockListener
@Override
public void onBlockPlace(BlockPlaceEvent event)
{
if (event.isCancelled()) return;
if (event.isCancelled())
{
return;
}
Block signBlock = event.getBlockAgainst();
if (signBlock.getType() == Material.WALL_SIGN || signBlock.getType() == Material.SIGN_POST)
{
@ -193,75 +249,78 @@ public class EssentialsBlockListener extends BlockListener
// Do not rely on getItemInHand();
// http://leaky.bukkit.org/issues/663
final ItemStack is = new ItemStack(event.getBlockPlaced().getType(), 1, (short)0, event.getBlockPlaced().getData());
switch(is.getType()) {
case WOODEN_DOOR:
is.setType(Material.WOOD_DOOR);
is.setDurability((short)0);
break;
case IRON_DOOR_BLOCK:
is.setType(Material.IRON_DOOR);
is.setDurability((short)0);
break;
case SIGN_POST:
case WALL_SIGN:
is.setType(Material.SIGN);
is.setDurability((short)0);
break;
case CROPS:
is.setType(Material.SEEDS);
is.setDurability((short)0);
break;
case CAKE_BLOCK:
is.setType(Material.CAKE);
is.setDurability((short)0);
break;
case BED_BLOCK:
is.setType(Material.BED);
is.setDurability((short)0);
break;
case REDSTONE_WIRE:
is.setType(Material.REDSTONE);
is.setDurability((short)0);
break;
case REDSTONE_TORCH_OFF:
case REDSTONE_TORCH_ON:
is.setType(Material.REDSTONE_TORCH_ON);
is.setDurability((short)0);
break;
case DIODE_BLOCK_OFF:
case DIODE_BLOCK_ON:
is.setType(Material.DIODE);
is.setDurability((short)0);
break;
case DOUBLE_STEP:
is.setType(Material.STEP);
break;
case TORCH:
case RAILS:
case LADDER:
case WOOD_STAIRS:
case COBBLESTONE_STAIRS:
case LEVER:
case STONE_BUTTON:
case FURNACE:
case DISPENSER:
case PUMPKIN:
case JACK_O_LANTERN:
case WOOD_PLATE:
case STONE_PLATE:
is.setDurability((short)0);
break;
switch (is.getType())
{
case WOODEN_DOOR:
is.setType(Material.WOOD_DOOR);
is.setDurability((short)0);
break;
case IRON_DOOR_BLOCK:
is.setType(Material.IRON_DOOR);
is.setDurability((short)0);
break;
case SIGN_POST:
case WALL_SIGN:
is.setType(Material.SIGN);
is.setDurability((short)0);
break;
case CROPS:
is.setType(Material.SEEDS);
is.setDurability((short)0);
break;
case CAKE_BLOCK:
is.setType(Material.CAKE);
is.setDurability((short)0);
break;
case BED_BLOCK:
is.setType(Material.BED);
is.setDurability((short)0);
break;
case REDSTONE_WIRE:
is.setType(Material.REDSTONE);
is.setDurability((short)0);
break;
case REDSTONE_TORCH_OFF:
case REDSTONE_TORCH_ON:
is.setType(Material.REDSTONE_TORCH_ON);
is.setDurability((short)0);
break;
case DIODE_BLOCK_OFF:
case DIODE_BLOCK_ON:
is.setType(Material.DIODE);
is.setDurability((short)0);
break;
case DOUBLE_STEP:
is.setType(Material.STEP);
break;
case TORCH:
case RAILS:
case LADDER:
case WOOD_STAIRS:
case COBBLESTONE_STAIRS:
case LEVER:
case STONE_BUTTON:
case FURNACE:
case DISPENSER:
case PUMPKIN:
case JACK_O_LANTERN:
case WOOD_PLATE:
case STONE_PLATE:
is.setDurability((short)0);
break;
}
boolean unlimitedForUser = user.hasUnlimited(is);
if (unlimitedForUser) {
if (unlimitedForUser)
{
ess.scheduleSyncDelayedTask(
new Runnable() {
public void run() {
user.getInventory().addItem(is);
user.updateInventory();
}
});
new Runnable()
{
public void run()
{
user.getInventory().addItem(is);
user.updateInventory();
}
});
}
}
@ -290,14 +349,19 @@ public class EssentialsBlockListener extends BlockListener
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++) {
for (int i = 1; i <= 2; i++)
{
String line = sign.getLine(i);
if (line.startsWith("(") && line.endsWith(")")) {
if (line.startsWith("(") && line.endsWith(")"))
{
line = line.substring(1, line.length() - 1);
if (user.inGroup(line)) {
if (user.inGroup(line))
{
return ALLOWED;
}
} else if (line.equalsIgnoreCase(username)) {
}
else if (line.equalsIgnoreCase(username))
{
return ALLOWED;
}
}

View File

@ -52,7 +52,8 @@ public class EssentialsPlayerListener extends PlayerListener
User user = ess.getUser(event.getPlayer());
user.setDisplayName(user.getNick());
updateCompass(user);
if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty()) {
if (user.isJailed() && user.getJail() != null && !user.getJail().isEmpty())
{
try
{
event.setRespawnLocation(ess.getJail().getJail(user.getJail()));
@ -109,15 +110,18 @@ public class EssentialsPlayerListener extends PlayerListener
Location loc = event.getTo();
World nether = server.getWorld(ess.getSettings().getNetherName());
if (nether == null) {
if (nether == null)
{
for (World world : worlds)
{
if (world.getEnvironment() == World.Environment.NETHER) {
if (world.getEnvironment() == World.Environment.NETHER)
{
nether = world;
break;
}
}
if (nether == null) {
if (nether == null)
{
return;
}
}
@ -489,6 +493,22 @@ public class EssentialsPlayerListener extends PlayerListener
}
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)
{