While causing problems when on multiplier

Discussion in 'Plugin Development' started by XSilver_FalconX, Aug 14, 2014.

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

    XSilver_FalconX

    Hi!

    I'm having a problem with this code snippet...
    basically it works perfectly with one player but then when another player runs the same while it repeats the StartThat.get(player); constantly creating a large negative number crashing the server.

    I tried to make everything "Player Specific" in the case that everything would be set to the player not just a general array which I thought would solve my problem, and it did not.

    I'm hoping the Bukkit community can help me out in my time of need as I have run out of options and ideas :p.

    Thank you very much in advance.

    Code:java
    1. /* Method to Repair Cobble Walls */
    2.  
    3. public HashMap<String, Location> ocation = new HashMap();
    4. public HashMap<String, Integer> startThat = new HashMap();
    5. public ArrayList brokenBlocks = new ArrayList();
    6.  
    7. if (ocation.containsKey(player.getName())) {
    8. if (brokenBlocks.isEmpty() == false) {
    9. double start = ocation.get(player.getName()).getY();
    10. int startt = (int) start;
    11. startThat.put(player.getName(), startt);
    12. double current = 1 + block.getY();
    13. while (startThat.get(player.getName()) != current) {
    14. int i = startThat.get(player.getName());
    15. i --;
    16. startThat.put(player.getName(), i);
    17.  
    18. //Printing - [StartThat.get(x)]; constantly when dealing with 2 players running the operation
    19. //Although current stays the same
    20.  
    21. System.out.println(startThat.get(player.getName()) + " -- " + current);
    22. Location airchk = new Location(player.getWorld(), ocation.get(player.getName()).getX(), startThat.get(player.getName()), ocation.get(player.getName()).getZ());
    23. if (brokenBlocks.contains(airchk)) {
    24. if (airchk.getBlock().getType().equals(Material.AIR)) {
    25. if (airchk.getX() == ocation.get(player.getName()).getX()) {
    26. player.sendMessage(ChatColor.RED + "Broken Parts");
    27. checkRemove(player);
    28. //no reason to keep checking for more broken blocks
    29. break;
    30. }
     
  2. I'd say the problem is that you're comparing integer and double, but I'm not 100% sure. You should try to floor the double before comparing. This line is the problem:
    Code:java
    1. startThat.get(player.getName()) != current

    startThat.get(player.getName()) can also return null, so you should do a null-check before comparing, because double is always different than null.
     
    mine-care likes this.
Thread Status:
Not open for further replies.

Share This Page