diff options
author | KHobbits <rob@khobbits.co.uk> | 2012-08-31 00:47:53 +0100 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2012-08-31 00:47:53 +0100 |
commit | 930eb7ae86c880d0bdb35074061f28650a0d3b3c (patch) | |
tree | 06705520e9d8c5907b9d11826a91dd670a6b61ac | |
parent | cf79a8fdca5650f49b4344e42cea331a50299e91 (diff) | |
download | Essentials-930eb7ae86c880d0bdb35074061f28650a0d3b3c.tar Essentials-930eb7ae86c880d0bdb35074061f28650a0d3b3c.tar.gz Essentials-930eb7ae86c880d0bdb35074061f28650a0d3b3c.tar.lz Essentials-930eb7ae86c880d0bdb35074061f28650a0d3b3c.tar.xz Essentials-930eb7ae86c880d0bdb35074061f28650a0d3b3c.zip |
Fix IllegalStateException in sign click patch
Cleanup
5 files changed, 101 insertions, 9 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 7d8042859..96e5a6796 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -12,7 +12,6 @@ import java.util.List; import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; -import net.minecraft.server.InventoryEnderChest; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.HumanEntity; @@ -26,7 +25,6 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.*; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; @@ -91,7 +89,8 @@ public class EssentialsPlayerListener implements Listener final Location from = event.getFrom(); final Location origTo = event.getTo(); final Location to = origTo.clone(); - if (ess.getSettings().cancelAfkOnMove() && origTo.getY() >= from.getBlockY() + 1) { + if (ess.getSettings().cancelAfkOnMove() && origTo.getY() >= from.getBlockY() + 1) + { user.updateActivity(true); return; } @@ -127,7 +126,8 @@ public class EssentialsPlayerListener implements Listener { user.toggleVanished(); } - if (!user.isJailed()) { + if (!user.isJailed()) + { user.setLastLocation(); } user.updateActivity(false); @@ -342,7 +342,7 @@ public class EssentialsPlayerListener implements Listener user.updateActivity(true); } } - + @EventHandler(priority = EventPriority.LOWEST) public void onPlayerChangedWorldHack(final PlayerChangedWorldEvent event) { @@ -384,6 +384,15 @@ public class EssentialsPlayerListener implements Listener } break; case LEFT_CLICK_AIR: + if (event.getPlayer().isFlying()) + { + final User user = ess.getUser(event.getPlayer()); + if (user.isFlyClickJump()) + { + useFlyClickJump(user); + return; + } + } case LEFT_CLICK_BLOCK: if (event.getItem() != null && event.getItem().getTypeId() != AIR) { @@ -399,6 +408,37 @@ public class EssentialsPlayerListener implements Listener } } + private void useFlyClickJump(final User user) + { + try + { + final Location otarget = Util.getTarget(user); + + ess.scheduleSyncDelayedTask( + new Runnable() + { + @Override + public void run() + { + Location loc = user.getLocation(); + loc.setX(otarget.getX()); + loc.setZ(otarget.getZ()); + while (Util.isBlockDamaging(loc.getWorld(), loc.getBlockX(), loc.getBlockY() -1, loc.getBlockZ())) { + loc.setY(loc.getY() + 1d); + } + user.getBase().teleport(loc, TeleportCause.PLUGIN); + } + }); + } + catch (Exception ex) + { + if (ess.getSettings().isDebug()) + { + LOGGER.log(Level.WARNING, ex.getMessage(), ex); + } + } + } + private boolean usePowertools(final User user, final int id) { final List<String> commandList = user.getPowertool(id); diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index f29fca886..c2b2a2754 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -26,6 +26,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser private transient long lastThrottledAction; private transient long lastActivity = System.currentTimeMillis(); private boolean hidden = false; + private boolean rightClickJump = false; private transient Location afkPosition = null; private boolean invSee = false; private boolean enderSee = false; @@ -717,4 +718,14 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser { lastThrottledAction = System.currentTimeMillis();; } + + public boolean isFlyClickJump() + { + return rightClickJump; + } + + public void setRightClickJump(boolean rightClickJump) + { + this.rightClickJump = rightClickJump; + } } diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index 0b5c3e426..c1f7cd014 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -288,6 +288,7 @@ public class Util public final static int RADIUS = 3; public final static Vector3D[] VOLUME; + public static class Vector3D { public Vector3D(int x, int y, int z) @@ -398,6 +399,15 @@ public class Util public static boolean isBlockUnsafe(final World world, final int x, final int y, final int z) { + if (isBlockDamaging(world, x, y, z)) + { + return true; + } + return isBlockAboveAir(world, x, y, z); + } + + public static boolean isBlockDamaging(final World world, final int x, final int y, final int z) + { final Block below = world.getBlockAt(x, y - 1, z); if (below.getType() == Material.LAVA || below.getType() == Material.STATIONARY_LAVA) { @@ -419,7 +429,7 @@ public class Util { return true; } - return isBlockAboveAir(world, x, y, z); + return false; } public static ItemStack convertBlockToItem(final Block block) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java index ab73c6e01..ba7182628 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandjump.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandjump.java @@ -19,6 +19,21 @@ public class Commandjump extends EssentialsCommand @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { + if (args.length > 0 && args[0].contains("lock") && user.isAuthorized("essentials.jump.lock")) + { + if (user.isFlyClickJump()) + { + user.setRightClickJump(false); + user.sendMessage("Flying wizard mode disabled"); + } + else + { + user.setRightClickJump(true); + user.sendMessage("Enabling flying wizard mode"); + } + return; + } + Location loc; final Location cloc = user.getLocation(); diff --git a/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java b/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java index 7fd563c17..08257c9e4 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignPlayerListener.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.signs; import com.earth2me.essentials.IEssentials; +import java.util.logging.Level; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Sign; @@ -28,9 +29,24 @@ public class SignPlayerListener implements Listener return; } final Block block; - if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) { - block = event.getPlayer().getTargetBlock(null, 5); - } else { + if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) + { + Block targetBlock = null; + try + { + targetBlock = event.getPlayer().getTargetBlock(null, 5); + } + catch (IllegalStateException ex) + { + if (ess.getSettings().isDebug()) + { + ess.getLogger().log(Level.WARNING, ex.getMessage(), ex); + } + } + block = targetBlock; + } + else + { block = event.getClickedBlock(); } if (block == null) |