Created
June 30, 2012 21:11
-
-
Save Zren/3025540 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onPlayerMove() | |
from = Vector(-44.973586, 63.000000, 184.599402) | |
to = Vector(-44.976534, 63.000000, 184.491422) | |
Delta = Vector(-0.002948, 0.000000, -0.107980) | |
Delta (Normalized) = Vector(-0.027288, 0.000000, -0.999628) | |
inFront = Vector(-45.003822, 63.000000, 183.491795) | |
inFront (Block) = Vector(-46.000000, 63.000000, 183.000000) | |
onPlayerMove() | |
from = Vector(-44.976534, 63.000000, 184.491422) | |
to = Vector(-44.926589, 63.000000, 184.349126) | |
Delta = Vector(0.049944, 0.000000, -0.142296) | |
Delta (Normalized) = Vector(0.331182, 0.000000, -0.943567) | |
inFront = Vector(-44.595408, 63.000000, 183.405559) | |
inFront (Block) = Vector(-45.000000, 63.000000, 183.000000) | |
onPlayerMove() | |
from = Vector(-44.926589, 63.000000, 184.349126) | |
to = Vector(-44.899320, 63.000000, 184.271433) | |
Delta = Vector(0.027270, 0.000000, -0.077694) | |
Delta (Normalized) = Vector(0.331182, 0.000000, -0.943567) | |
inFront = Vector(-44.568138, 63.000000, 183.327866) | |
inFront (Block) = Vector(-45.000000, 63.000000, 183.000000) | |
onPlayerMove() | |
from = Vector(-44.899320, 63.000000, 184.271433) | |
to = Vector(-44.876301, 63.000000, 184.205850) | |
Delta = Vector(0.023019, 0.000000, -0.065582) | |
Delta (Normalized) = Vector(0.331182, 0.000000, -0.943567) | |
inFront = Vector(-44.545120, 63.000000, 183.262283) | |
inFront (Block) = Vector(-45.000000, 63.000000, 183.000000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void onEnable() { | |
TaskInjector.newInstance(this); | |
getServer().getPluginManager().registerEvents(new Listener() { | |
@EventHandler | |
public void onPlayerMove(PlayerMoveEvent event) { | |
// TODO Check for same world. | |
World world = event.getTo().getWorld(); | |
Vector from = event.getFrom().toVector(); | |
Vector to = event.getTo().toVector(); | |
// Skip when the player is just rotating head. | |
if (from.distanceSquared(to) == 0) // distSquared is faster as it doesn't involve a sqrt(). | |
return; | |
System.out.println("onPlayerMove()"); | |
System.out.println(String.format("\tfrom = \t%s", blockVectorToString(from))); | |
System.out.println(String.format("\tto = \t%s", blockVectorToString(to))); | |
Vector delta = to.clone().subtract(from); | |
System.out.println(String.format("\tDelta = \t%s", blockVectorToString(delta))); | |
delta = delta.normalize(); | |
System.out.println(String.format("\tDelta (Normalized) = \t%s", blockVectorToString(delta))); | |
Vector inFrontVector = to.clone().add(delta); | |
System.out.println(String.format("\tinFront = \t%s", blockVectorToString(inFrontVector))); | |
Location inFrontVectorLoc = inFrontVector.toLocation(world); | |
System.out.println(String.format("\tinFront (Block) = \t%s", blockVectorToString(inFrontVectorLoc.getBlock().getLocation().toVector()))); | |
} | |
}, this); | |
System.out.println(String.format("[%s] Enabled - Version: %s", getDescription().getName(), getDescription().getVersion())); | |
} | |
public static String blockVectorToString(Vector v) { | |
return String.format("Vector(%8f, %8f, %8f)", v.getX(), v.getY(), v.getZ()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment