player.setExp(0.50F); working in one plugin but not another?

Discussion in 'Plugin Development' started by 22vortex22, Nov 26, 2013.

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

    22vortex22

    Hey guys Im working on a plugin that requires the Exp to go from full down to half then zero. I already have all the code but for some reason player.setExp(0.50F); isn't working. I tested it in another plugin and it works fine. Could someone help me figure out why its not working. Anyways here is my code

    Code:java
    1. @EventHandler
    2. public void OnPlayerRocket(PlayerInteractEvent event){
    3. final Player player = event.getPlayer();
    4. if (!plugin.RocketCooldown.contains(player.getName())){
    5. if (!plugin.RocketCooldown2.contains(player.getName())){
    6. if((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() ==Action.RIGHT_CLICK_BLOCK) && player.getItemInHand().getType() == Material.FIREWORK){
    7. player.setVelocity(player.getLocation().getDirection()
    8. .multiply(1.05).setY(1.15));
    9. player.setExp(0.50F);
    10. plugin.RocketCooldown2.add(player.getName());
    11. }
    12. }
    13. if (plugin.RocketCooldown2.contains(player.getName())){
    14. if((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() ==Action.RIGHT_CLICK_BLOCK) && player.getItemInHand().getType() == Material.FIREWORK){
    15. player.setVelocity(player.getLocation().getDirection()
    16. .multiply(1.05).setY(1.15));
    17. plugin.RocketCooldown.add(player.getName());
    18. player.setExp(0);
    19.  
    20. }
    21.  
    22. }
    23. }
    24. }
    25. @EventHandler
    26. public void OnGround(PlayerMoveEvent e){
    27. Player p = e.getPlayer();
    28. if(p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR) {
    29. plugin.RocketCooldown.remove(p.getName());
    30. plugin.RocketCooldown2.remove(p.getName());
    31. p.setExp(1);
    32. }
    33. }
    34.  


    Or Here http://pastebin.com/hCuBXyLd
     
  2. Offline

    Garris0n

    Everything else is working and it's just the setExp?
     
  3. Offline

    BungeeTheCookie

  4. Offline

    sgavster

    Is the other code working? If not, are your events registered?
     
  5. Offline

    22vortex22

    All my code is working except the player.setExp(0.50F) And yes my events are registered

    Bump please guys I would love some answers?

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

    Garris0n

    Is it possible that anything else is setting their exp afterwards?
     
  7. Offline

    sgavster

  8. Offline

    22vortex22

    I don't think so. You can check the code.
    I need to solve this D:
     
  9. Offline

    calebbfmv

    Sounds like you have 2 plugins running a setExp , which would cause errors. Remove all plugins except for that one and try it.
     
  10. Offline

    22vortex22



    Nope. My plugin is by itself and it still doesn't go to the halfway mark. It goes to 1 and 0 perfectly but never 0.50
     
  11. Offline

    calebbfmv

    22vortex22
    I found it:
    You're checking if the player is contained in a second list after you add him to it, so the code is acting on both at the same time. :p You need to remove the player from all other lists before setting his Exp from .50f to 0, otherwise its going to act on both. You understand?
     
  12. Offline

    22vortex22

    Im checking if hes not in the list. Thats why I have a ! infront of it.
    And no I don't really understand :/
     
  13. Offline

    calebbfmv

    Code:
            player.setExp(0.50F);
            plugin.RocketCooldown2.add(player.getName());
            if (plugin.RocketCooldown2.contains(player.getName())){
                if((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() ==Action.RIGHT_CLICK_BLOCK) && player.getItemInHand().getType() == Material.FIREWORK){
                    player.setVelocity(player.getLocation().getDirection()
                            .multiply(1.05).setY(1.15));
                    plugin.RocketCooldown.add(player.getName());
                    player.setExp(0);
    
    Look at the code: Your adding them to a list after you set their exp, all good, but then you check if that SAME list contains the player, and if it does, your setting his exp to 0, ergo why you are getting it to go from 1-0 and skipping the half.
     
    sgavster likes this.
  14. Offline

    22vortex22

    How do I fix it? calebbfmv
     
  15. Offline

    calebbfmv

    22vortex22
    Simple.
    Check is exp and set it to 0 if its at .5f
     
  16. Offline

    22vortex22

    I must be really stupid calebbfmv but how do I check the xp and turn it into an if statement?
     
  17. Offline

    sgavster

    calebbfmv likes this.
  18. Offline

    calebbfmv

    sgavster
    Just had to get in on this didn't you? :D
     
  19. Offline

    22vortex22

    It works but its giving me 3 jumps now, I only want two

    sgavster calebbfmv

    Code:java
    1. @EventHandler
    2. public void OnPlayerRocket(PlayerInteractEvent event){
    3. Player player = event.getPlayer();
    4. if (player.getExp() == 1){
    5. if((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() ==Action.RIGHT_CLICK_BLOCK) && player.getItemInHand().getType() == Material.FIREWORK){
    6. player.setVelocity(player.getLocation().getDirection()
    7. .multiply(1.05).setY(1.15));
    8. player.setExp(0.50F);
    9. }
    10. }
    11. else if(player.getExp() == 0.50F) {
    12. if((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() ==Action.RIGHT_CLICK_BLOCK) && player.getItemInHand().getType() == Material.FIREWORK){
    13. player.setVelocity(player.getLocation().getDirection()
    14. .multiply(1.05).setY(1.15));
    15. player.setExp(0);
    16. }
    17. }
    18.  
    19. }
    20. @EventHandler
    21. public void OnGround(PlayerMoveEvent e){
    22. Player p = e.getPlayer();
    23. if(p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR) {
    24. p.setExp(1);
    25. }
    26. }
    27.  
     
  20. Offline

    calebbfmv

    This is where some lists come in handy:
    Code:
    //where you set exp to 0.5f:
    player.setExp(0.5f);
    plugin.RocketCooldownList2.add(player.getName());
    //where you set his exp to 0:
    if(plugin.RocketCooldownList2.cotains(player.getName()) && player.getExp() == 0.5f){
    
     
  21. Offline

    22vortex22

    Guys it still gives me 3 jumps. I think this is because before I fully get off the ground it resets it again. However I am uploading a video to let you guys better understand. Here is the updated code if you need it


    Code:java
    1. @EventHandler
    2. public void OnPlayerRocket(PlayerInteractEvent event){
    3. Player player = event.getPlayer();
    4. if(player.getExp() == 1f){
    5. if((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() ==Action.RIGHT_CLICK_BLOCK) && player.getItemInHand().getType() == Material.FIREWORK){
    6. player.setVelocity(player.getLocation().getDirection()
    7. .multiply(1.05).setY(1.15));
    8. player.setExp(0.50F);
    9. plugin.RocketCooldown2.add(player.getName());
    10. }
    11. }
    12. else if(plugin.RocketCooldown2.contains(player.getName()) && player.getExp() == 0.5f){
    13. if((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() ==Action.RIGHT_CLICK_BLOCK) && player.getItemInHand().getType() == Material.FIREWORK){
    14. player.setVelocity(player.getLocation().getDirection()
    15. .multiply(1.05).setY(1.15));
    16. player.setExp(0);
    17. }
    18. }
    19.  
    20. }
    21. int time;
    22. @EventHandler
    23. public void OnGround(PlayerMoveEvent e){
    24. final Player p = e.getPlayer();
    25. Bukkit.getServer().getScheduler().runTaskLater(plugin, new Runnable()
    26. {
    27. @Override
    28. public void run(){
    29. if(p.getLocation().add(0,-1,0).getBlock().getType() != Material.AIR){
    30. p.setExp(1);
    31. }
    32. }
    33. }
    34. ,19L);
    35.  
    36.  
    37. }
    38.  


    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
Thread Status:
Not open for further replies.

Share This Page