Fix IllegalStateException in sign click patch

Cleanup
This commit is contained in:
KHobbits 2012-08-31 00:47:53 +01:00
parent cf79a8fdca
commit 930eb7ae86
5 changed files with 101 additions and 9 deletions

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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)
@ -397,6 +398,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)

View File

@ -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();

View File

@ -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)