Reputation: 57
I am working on developing a minecraft plugin based on the Movie InTime. When a player kills you you are susposed to lose 25% of your time and drop it in the form of a TimeCard (Book). The player who killed you can then pick up the TimeCard and use it.
Currently the plugin is only attempting to get the players years, multiply them by 25% and then issue the command to remove 25 years from the player. (y tells the server to take years not days, weeks, hours)
Here is the code for it:
Integer time = itapi.getPlayerYears(player.getName());
Double remove = Integer.valueOf(time) * 0.25;
String minus = String.valueOf(remove) + 'y' ;
itapi.removeTime(player.getName(), itapi.getDeathTime());
ItemStack book = itapi.createTimeCard("Death of " + player.getName(), minus, 1);
itapi.removeTime(player.getName(), minus);
e.getDrops().add(book);
though when a player gets killed this error is thrown:
Caused by: java.lang.NumberFormatException: For input string: "1.25"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[?:1.7.0]
at java.lang.Integer.parseInt(Integer.java:492) ~[?:1.7.0]
at java.lang.Integer.parseInt(Integer.java:527) ~[?:1.7.0]
at com.BlackMage.InTime2.InTime2API.removeTime(InTime2API.java:551) ~[?:?]
I am beyond confused on how to resolve these errors and after trying several different things am looking for some advice
Upvotes: 0
Views: 118
Reputation: 849
If you look lower in the stack trace, you'll see:
Caused by: java.lang.NumberFormatException: For input string: "1.25"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[?:1.7.0]
at java.lang.Integer.parseInt(Integer.java:492) ~[?:1.7.0]
at java.lang.Integer.parseInt(Integer.java:527) ~[?:1.7.0]
at com.BlackMage.InTime2.InTime2API.removeTime(InTime2API.java:551) ~[?:?]
at com.BlackMage.InTime2.DeathListener.onDeath(DeathListener.java:37) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0]
Look at the removeTime method in InTime2API (on line 551, or just find a line that tries to call parseInt
in that method). If you want the parse to succeed, you'll need to do parseFloat
instead of parseInt
and store the result in a float variable.
Upvotes: 1
Reputation: 240898
somewhere in your code you are parsing a String
to int
, and it attempts for 1.25
which isn't an int
so the error
Caused by: java.lang.NumberFormatException: For input string: "1.25"
Upvotes: 3