Variables Being Reset.

Discussion in 'Plugin Development' started by danthonywalker, Nov 3, 2013.

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

    danthonywalker

    Code:java
    1. public HashSet<String> xenos = new HashSet<String>();
    2.  
    3. @EventHandler
    4. public void xenoDoubleJump(PlayerToggleFlightEvent event)
    5. {
    6. System.out.print(xenos.size()); //DEBUGGING PURPOSES
    7. if(event.isFlying() && xenos.contains(event.getPlayer().getName()))
    8. {
    9. System.out.print("test"); //DEBUGGING PURPOSES
    10. event.getPlayer().setFlying(false);
    11. event.getPlayer().setVelocity(event.getPlayer().getLocation().getDirection().setY(1.1));
    12. // CHANGE THE 1.1 SO IT BECOMES INCREASINGLY INCREMENTAL AS THE GAME TIME INCREASES \\
    13. }
    14.  
    15. }
    16.  
    17. @EventHandler
    18. public void xenoMovement(PlayerMoveEvent event)
    19. {
    20. if(xenos.contains(event.getPlayer().getName()))
    21. event.getPlayer().setVelocity(event.getPlayer().getLocation().getDirection().multiply(2));
    22. // CHANGE THE 2 SO IT BECOMES INCREASINGLY INCREMENTAL AS THE GAME TIME INCREASES \\
    23. }
    24.  
    25. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    26. {
    27. if(!(sender.isOp()) || !(sender instanceof Player)) return false;
    28. Player player = (Player) sender;
    29.  
    30. if(xenos.contains(player.getName()))
    31. {
    32. player.setAllowFlight(false);
    33. xenos.remove(player.getName());
    34. }
    35.  
    36. else
    37. {
    38. player.setAllowFlight(true);
    39. xenos.add(player.getName());
    40. }
    41.  
    42. System.out.print(xenos.size()); //DEBUGGING PURPOSES
    43. return true;
    44. }


    So every time you do the /xeno command it should add the player's name to the HashSet, which it does because after I do the command it prints out the size of the HashSet as 1, however, when I try to fly it displays it as 0, as if it got reset. Can someone tell me what I'm doing wrong to cause it to reset like that? Thanks.
     
  2. Offline

    mrkirby153

    @danhthonywalker

    Try using an ArrayList instead of a HashSet
     
Thread Status:
Not open for further replies.

Share This Page