Solved Block trail problems

Discussion in 'Plugin Development' started by kember007, Jun 18, 2015.

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

    kember007

    So my scenario is this.. I'm trying to have a trail of glowstone below the player that fallows them when they move, each block should only stay there for about 1.5 seconds then be set back to the original block. However my problem is that the PlayerMoveEvent triggers not only when the player moves 1 block or more but whenever the player moves, so this means the player will move onto a block then keep moving and the block will be set back to the original once but then the next time the moved the block would have been glowstone so it would be permanently set to glowstone. Anyways here is my code and thanks for any help :)
    Code:java
    1.  
    2. Map<Player,String> lightPath = new HashMap<Player,String>();
    3. Map<Location,Material> blockType = new HashMap<Location,Material>();
    4.  
    5. @EventHandler
    6. public void onPlayerMove(PlayerMoveEvent event)
    7. {
    8. final Player player = event.getPlayer();
    9. if(lightPath.containsKey(player))
    10. {
    11. final Location loc = player.getLocation().subtract(0, 1, 0);
    12. final Block block = loc.getBlock();
    13. blockType.put(loc, block.getType());
    14. if(!block.getType().equals(Material.AIR))
    15. {
    16. if(event.getFrom().getX() == event.getTo().getX() || event.getFrom().getY() == event.getTo().getY() || event.getFrom().getZ() == event.getTo().getZ())
    17. {
    18. block.setType(Material.GLOWSTONE);
    19. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    20. {
    21. public void run()
    22. {
    23. block.setType(blockType.get(loc));
    24. player.sendMessage(blockType.get(loc).toString()); // Message for debugging purposes
    25. }
    26. }, 30);
    27. }
    28. }
    29. }
    30. }
    31.  
    32.  
     
    Last edited: Jun 18, 2015
  2. Offline

    tomudding

    Check if the block is already glowstone, because then you don't have to make it glowstone
     
    kember007 likes this.
  3. Offline

    kember007

    tomudding likes this.
Thread Status:
Not open for further replies.

Share This Page