Solved Strange Casting Error

Discussion in 'Plugin Help/Development/Requests' started by 1Camer0471, May 22, 2015.

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

    1Camer0471

    Hey Bukkit, I am trying to create a plugin, but for some reason I get this error:
    Error (open)

    [19:25:43 WARN]: [Territories] Task #16 for Territories v1.0 generated an except
    ion
    java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integ
    er
    at me.Zacx.TerritoriesMain.getXpToLevel(TerritoriesMain.java:394) ~[?:?]

    at me.Zacx.TerritoriesMain$4.run(TerritoriesMain.java:560) ~[?:?]
    at org.bukkit.craftbukkit.v1_8_R2.scheduler.CraftTask.run(CraftTask.java
    :53) ~[craftbukkit.jar:git-Bukkit-501372f]
    at org.bukkit.craftbukkit.v1_8_R2.scheduler.CraftScheduler.mainThreadHea
    rtbeat(CraftScheduler.java:349) [craftbukkit.jar:git-Bukkit-501372f]
    at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:6
    77) [craftbukkit.jar:git-Bukkit-501372f]
    at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:3
    36) [craftbukkit.jar:git-Bukkit-501372f]
    at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:6
    26) [craftbukkit.jar:git-Bukkit-501372f]
    at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java
    :534) [craftbukkit.jar:git-Bukkit-501372f]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]



    Here is all relevant code:

    Code:Java
    1.  
    2. public int getXpToLevel(UUID uid) {
    3. int toReturn = getXP().get(uid).intValue();
    4. int toSubtract = 0;
    5.  
    6. if (getLevel().get(uid) == 1) {
    7. toSubtract = 1000;
    8. }
    9. if (getLevel().get(uid) == 2) {
    10. toSubtract = 25000;
    11. }
    12. if (getLevel().get(uid) == 3) {
    13. toSubtract = 50000;
    14. }
    15. if (getLevel().get(uid) == 4) {
    16. toSubtract = 999999999;
    17. }
    18.  
    19.  
    20.  
    21. return toReturn - toSubtract;
    22. }
    23.  


    Line 394 is is line two from the code above.

    Code:Java
    1.  
    2. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    3. public int tillPlayerUpdate = 2;
    4.  
    5.  
    6.  
    7. public void run() {
    8. if (tillPlayerUpdate != -1) {
    9. if (tillPlayerUpdate != 0) {
    10. tillPlayerUpdate--;
    11. } else {
    12. for (Player online : Bukkit.getServer().getOnlinePlayers()) {
    13. int diff = getXpToLevel(online.getUniqueId()) - getXP().get(online.getUniqueId());
    14. online.setMaxHealth(getMaxHealth().get(online.getUniqueId()));
    15. if (diff <= 0) {
    16. getLevel().put(online.getUniqueId(), getLevel().get(online.getUniqueId()) + 1);
    17. online.sendMessage(tPrefix + " ยง9You have Leveled Up!");
    18. }
    19. online.setLevel(getLevel().get(online.getUniqueId()));
    20. online.setExp(0);
    21. }
    22. }
    23. }
    24. }
    25. }, 0L, 20L);
    26.  


    Line 560 is line 13 from the code above.

    Thanks for any help!
     
  2. Offline

    Zombie_Striker

    @1Camer0471 Try instead of trying to get an Integer, get a double. (that's what the error is trying to tell you)
     
  3. Online

    timtower Moderator Moderator

    Moved to Bukkit alternatives
     
  4. Offline

    1Camer0471

    Nvm, I figured it out!
     
Thread Status:
Not open for further replies.

Share This Page