Non-solid blocks should not be blocking a players view of interacting with something. Fixes issue #91

This commit is contained in:
H31IX committed 2012-06-18 02:22:33 -04:00
1 parent a895bf94bd
commit 23303295bf
5 files changed
+25 -137

No files matched your search

@@ -105,6 +105,10 @@ public class CommandHandler implements CommandExecutor
cs.sendMessage(GREEN + "Debug information posted to: " + WHITE + report.getURL());
cs.sendMessage(GREEN + "Please include this link when making bug reports.");
}
else
{
cs.sendMessage(PERMISSIONS_ERROR);
}
}
public void handleXRay(CommandSender cs, String[] args)
@@ -168,7 +168,7 @@ public class PlayerListener extends EventListener
public void onPlayerInteract(PlayerInteractEvent event)
{
Player player = event.getPlayer();
Block playerClick = player.getTargetBlock(null, 5);
Block playerClick = player.getTargetBlock(Utilities.getNonSolid(), 5);
PlayerInventory inv = player.getInventory();
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)
{
@@ -403,56 +403,11 @@ public class Backend
public boolean checkVisuals(Player player, Block targetBlock, Block playerClick)
{
/*if (isInteracting(player) || playerClick.isLiquid())
{
return false;
}*/
if (!Utilities.isInteractable(targetBlock.getType()))
{
return false;
}
//trapdoor fix
if (playerClick.getType() == Material.TRAP_DOOR)
{
Location x1 = new Location(targetBlock.getWorld(), playerClick.getX() - 1, playerClick.getY(), playerClick.getZ());
Location x2 = new Location(targetBlock.getWorld(), playerClick.getX() + 1, playerClick.getY(), playerClick.getZ());
Location y1 = new Location(targetBlock.getWorld(), playerClick.getX(), playerClick.getY() - 1, playerClick.getZ());
Location y2 = new Location(targetBlock.getWorld(), playerClick.getX(), playerClick.getY() + 1, playerClick.getZ());
Location z1 = new Location(targetBlock.getWorld(), playerClick.getX(), playerClick.getY(), playerClick.getZ() - 1);
Location z2 = new Location(targetBlock.getWorld(), playerClick.getX(), playerClick.getY(), playerClick.getZ() + 1);
if (x1.equals(targetBlock.getLocation()) || x2.equals(targetBlock.getLocation()) || y1.equals(targetBlock.getLocation()) || y2.equals(targetBlock.getLocation()) || z1.equals(targetBlock.getLocation()) || z2.equals(targetBlock.getLocation()))
{
String dir = Utilities.getCardinalDirection(player);
int minimum = 0;
if (dir.equalsIgnoreCase("E"))
{
minimum = 0;
}
if (dir.equalsIgnoreCase("W"))
{
minimum = 1;
}
if (dir.equalsIgnoreCase("N"))
{
minimum = 2;
}
if (dir.equalsIgnoreCase("S"))
{
minimum = 3;
}
if ((int) playerClick.getData() == minimum)
return true; // they have to be hacking here.
if ((int) playerClick.getData() == minimum + 4 && (playerClick.getLocation().distance(player.getLocation())) < 2)
return false; // couldn't be hacking.
}
}
double x = targetBlock.getX() - playerClick.getX() * ((targetBlock.getX() - playerClick.getX() * 1) < 0 ? -1 : 1);
double y = targetBlock.getY() - playerClick.getY() * ((targetBlock.getY() - playerClick.getY() * 1) < 0 ? -1 : 1);
double z = targetBlock.getZ() - playerClick.getZ() * ((targetBlock.getZ() - playerClick.getZ() * 1) < 0 ? -1 : 1);
@@ -75,7 +75,7 @@ public class PastebinReport
{
Runtime runtime = Runtime.getRuntime();
report.append("Java: " + System.getProperty("java.vendor") + " " + System.getProperty("java.version") + " (" + System.getProperty("java.vendor.url") + ")" + '\n');
report.append("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " (" + System.getProperty("os.arch") + ")" + '\n');
report.append("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + '\n');
report.append("Free Memory: " + runtime.freeMemory() / 1024 / 1024 + "MB" + '\n');
report.append("Max Memory: " + runtime.maxMemory() / 1024 / 1024 + "MB" + '\n');
report.append("Total Memory: " + runtime.totalMemory() / 1024 / 1024 + "MB" + '\n');
@@ -21,6 +21,7 @@ package net.h31ix.anticheat.util;
import com.gmail.nossr50.datatypes.AbilityType;
import com.gmail.nossr50.mcMMO;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import net.h31ix.anticheat.Anticheat;
import org.bukkit.Bukkit;
@@ -34,7 +35,7 @@ public final class Utilities
private static final List<Material> INSTANT_BREAK = new ArrayList<Material>();
private static final List<Material> FOOD = new ArrayList<Material>();
private static final List<Material> INTERACTABLE = new ArrayList<Material>();
private static final List<Material> PRESSURE_PLATES = new ArrayList<Material>();
private static final HashSet<Byte> NOTSOLID = new HashSet<Byte>();
public static void alert(String[] message)
{
@@ -51,79 +52,6 @@ public final class Utilities
}
}
/*
*
* Credits to sk89q for the calculation of cardinal direction.
*
*
*/
/**
* Get the cardinal compass direction of a player.
*
* @param player
* @return
*/
public static String getCardinalDirection(Player player)
{
double rot = (player.getLocation().getYaw() - 90) % 360;
if (rot < 0)
{
rot += 360.0;
}
return getDirection(rot);
}
/**
* Converts a rotation to a cardinal direction name.
*
* @param rot
* @return
*/
private static String getDirection(double rot)
{
if (0 <= rot && rot < 22.5)
{
return "N";
}
else if (22.5 <= rot && rot < 67.5)
{
return "N";
}
else if (67.5 <= rot && rot < 112.5)
{
return "E";
}
else if (112.5 <= rot && rot < 157.5)
{
return "E";
}
else if (157.5 <= rot && rot < 202.5)
{
return "S";
}
else if (202.5 <= rot && rot < 247.5)
{
return "S";
}
else if (247.5 <= rot && rot < 292.5)
{
return "W";
}
else if (292.5 <= rot && rot < 337.5)
{
return "W";
}
else if (337.5 <= rot && rot < 360.0)
{
return "N";
}
else
{
return null;
}
}
public static boolean cantStandAt(Block block)
{
return !canStand(block) && cantStandClose(block) && cantStandFar(block);
@@ -158,10 +86,10 @@ public final class Utilities
{
return INTERACTABLE.contains(m);
}
public static boolean isPressurePlate(Material m)
public static HashSet<Byte> getNonSolid()
{
return PRESSURE_PLATES.contains(m);
return NOTSOLID;
}
public static boolean sprintFly(Player player)
@@ -249,19 +177,20 @@ public final class Utilities
INTERACTABLE.add(Material.STONE_BUTTON);
INTERACTABLE.add(Material.LEVER);
INTERACTABLE.add(Material.CHEST);
//INTERACTABLE.add(Material.DISPENSER);
//INTERACTABLE.add(Material.CAULDRON);
//INTERACTABLE.add(Material.ENCHANTMENT_TABLE);
//INTERACTABLE.add(Material.WOOD_DOOR);
//INTERACTABLE.add(Material.IRON_DOOR);
//INTERACTABLE.add(Material.WORKBENCH);
//INTERACTABLE.add(Material.CAKE_BLOCK);
//INTERACTABLE.add(Material.STONE_PLATE);
//INTERACTABLE.add(Material.FENCE_GATE);
//INTERACTABLE.add(Material.TRAP_DOOR);
//INTERACTABLE.add(Material. - placeholder.
PRESSURE_PLATES.add(Material.STONE_PLATE);
PRESSURE_PLATES.add(Material.WOOD_PLATE);
NOTSOLID.add((byte)Material.TORCH.getId());
NOTSOLID.add((byte)Material.REDSTONE_TORCH_OFF.getId());
NOTSOLID.add((byte)Material.REDSTONE_TORCH_OFF.getId());
NOTSOLID.add((byte)Material.FENCE.getId());
NOTSOLID.add((byte)Material.FENCE_GATE.getId());
NOTSOLID.add((byte)Material.IRON_FENCE.getId());
NOTSOLID.add((byte)Material.NETHER_FENCE.getId());
NOTSOLID.add((byte)Material.TRAP_DOOR.getId());
NOTSOLID.add((byte)Material.SIGN.getId());
NOTSOLID.add((byte)Material.STONE_BUTTON.getId());
NOTSOLID.add((byte)Material.LEVER.getId());
NOTSOLID.add((byte)Material.AIR.getId());
NOTSOLID.add((byte)Material.WATER.getId());
NOTSOLID.add((byte)Material.LAVA.getId());
FOOD.add(Material.COOKED_BEEF);
FOOD.add(Material.COOKED_CHICKEN);
FOOD.add(Material.COOKED_FISH);