Per block "PlayerMoveEvent"?

Discussion in 'Plugin Development' started by B3N909, Jun 26, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    Hello I am trying to make a code that uses the "PlayerMoveEvent" and then when a player moves to a **NEW** block it only runs the rest of the method? Here is my code:

    Show Spoiler
    package me.atm.main;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.plugin.PluginManager;
    public class Main extends JavaPlugin implements Listener{
    public void onEnable(){
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvents(this, this);
    public void onDisable(){
    public void onMove(PlayerMoveEvent e){
    //finds player & creates location to check for block under the player!        
    final Player p = e.getPlayer();
    final Location l = p.getLocation();
    final Location d = new Location(l.getWorld(), l.getX(), l.getY() - 1, l.getZ());
    //This retrives where the player walked to and from so we can compare and see if this is the new block or the same!
    Location from = e.getFrom();
    Location to  = e.getTo();
    double x1 = Math.round(from.getX());
    double y1 = Math.round(from.getY());
    double z1 = Math.round(from.getZ());
    double x2 = Math.round(to.getX());
    double y2 = Math.round(to.getY());
    double z2 = Math.round(to.getZ());
    //Compares "to" and "from" to check if player is in same or diffrent block!
    if(x1 == x2 && y1 == y2 && z1 == z2){
    final int test = 1;
    test = 1;
    //Checks if qurtz is under player!
    if(test == 0 && d.getBlock().getType().equals(Material.QUARTZ_BLOCK)){
    p.sendMessage("You are at a ATM!");
    test = 0;

    If you were to try to paste that in Eclipse or something it should work though the variable "test" is having problems?? Thanks in advance!
  2. B3N909 Please learn what the Java keyword "final" is before trying to use it. :)
  3. Offline


    This code makes no sense at all. Try proof reading it and understand what you do in each line.
  4. Offline


    AdamQpzm I was using them to make the Variable public to all other methods (I dont know if that was right but I was told to do it in another forum post)

    Necrodoom ,I just added some foot notes so you guys can better understand it. This code is meant to make it so when a player stands on a quartz block it messages the player BUT when he only stands on it and does not wiggle around. <---- THAT IS THE PROBLEM!!!

    I am just mind bobbled with this question... ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 9, 2016
  5. Offline


    You could take my PlayerMoveBlockEvent from this thread.
  6. Offline


    Try doing something like this
    1. @EventHandler
    2. public void playerMoveEvent(PlayerMoveEvent event){
    3. Location from = event.getFrom();
    4. Location to = event.getTo();
    6. if(from.getBlockX() == to.getBlockX() || from.getBlockY() == to.getBlockY() || from.getBlockZ() == to.getBlockZ(){
    7. return;
    8. }
    10. [Insert code here!]
    11. }
  7. Offline


    Thanks everyone for your answers! I just ended up doing a onPlayerInteract event and then checking for the block the player is standing on!
  8. Offline


    Maybe yes, if half the variables you created there even made sense in what you are trying to do.
    I suggest learning java, so you can understand what you wrote.
  9. Offline


    Necrodoom I sorry if I was being confusing. I do know java just when I do stuff it do not make it in the most efficient manor.
  10. Offline


    B3N909 er, you created an int called test, set it to 1, then declared it final, which means it cannot be modified, then the very next line, you try to modify it... By setting it to 1, again. Then you check if the variable is 0, which, of course, will always fail.

    Also, creating the location d, which is an exact duplicate of l, was completely pointless and made no sense either.
    mythbusterma likes this.
  11. Offline


    Necrodoom , oops... I though that "final" declared the variable to be inherited in all methods.... Atleast that is what another forum post told me... :) Thanks for the clarification!
Thread Status:
Not open for further replies.

Share This Page