CommandHelper

CommandHelper

46.5k Downloads

Problem with parseLong() in Java

LadyCailinBot opened this issue ยท 5 comments

commented

CMDHELPER-2815 - Reported by MariuszT

I have some CH script which uses sk_region_create():

sk_region_create(@event['location'][3], @cuboid_name, array(@pos1, @pos2))

In the third argument for this function I have this array:

{{0: -4222.0, 1: 76.0, 2: -9245.0, 3: map_world, world: map_world, x: -4222.0, y: 76.0, z: -9245.0}, {-4230.0, 71.0, -9255.0}}

With build [#2413|http://builds.enginehub.org/job/commandhelper/3037/] and previous, everything is ok. But with build [#2414|http://builds.enginehub.org/job/commandhelper/3038/] and every next build I have this error:

{CastException, Expecting an integer, but received "-4222.0" instead, /path/plugins/CommandHelper/includes/cuboids_players.ms, 777}

In WorldEdit.java we have this code:

x = Static.getInt32(point.get(0), t);
y = Static.getInt32(point.get(1), t);
z = Static.getInt32(point.get(2), t);

It leads to getInt32() in Static.java and then to getInt() in the same file. Problem is here:

try {
i = Long.parseLong(c.val());
} catch (NumberFormatException e) {
throw new ConfigRuntimeException("Expecting an integer, but received "" + c.val() + "" instead",
ExceptionType.CastException, t);
}

But I really don't know why it's not working anymore :/ Please help :(

commented

Comment by MariuszT

Bug still exists (build #2452). Here is an simple example http://paste.thezomg.com/12260/87036875/

Error: http://paste.thezomg.com/12262/37086138/

Please help, I can't update CH anymore.

commented

Comment by Tom.Gebbett

It's not a fix, but you can just cast the co-ordinates to integers. Use floor, since it uses the right co-ordinate for positive and negative. (Or so i've found.)

Example:

@p1 = array(floor(@p1[0]),floor(@p1[1]),floor(@p1[2]),@p1[3])
@p2 = array(floor(@p2[0]),floor(@p2[1]),floor(@p2[2]),@p2[3])
@points = array(@p1,@p2)

These should be accepted, it works for me.

I only mention it because you said you couldn't update, and the workaround is pretty simple.

commented

Comment by MariuszT

Yes yes, you're right, of course. I think I'll do a special procedure for this. But I have many many places to edit.

commented

Comment by LadyCailin

I'm not actually sure the "bug" with parseLong should be fixed. If 2.0 isn't an integer, it's a double, even if it is losslessly convertable to an int. I think what should happen instead is that we should allow a double in sk_region_create (and any other places that this is a problem at).

commented

Comment by LadyCailin

Fixed in latest build. Instead of manually parsing the CArray, use ObjectGenerator to pull out a MCLocation, then use getBlockX/Y/Z. This will parse things appropriately.