[Plugin] Shoebill 1.1 - SA-MP Java Development Kit

Quote:
Originally Posted by Urukhay
Посмотреть сообщение
How include Streamer functions to the maven with Shoebill?
Just add this to your pom.xml dependency list

Код:
<dependency>
   <groupId>net.gtaun.shoebill</groupId>
    <artifactId>streamer-wrapper</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>
Add it as a plugin in resources.yml and place the .jar in shoebill/plugins

EDIT: I actually tested it and well it almost works. The only issue is that it fails if I use it in my gamemodes onEnable method with the following exception:

Код:
2016-02-10 10:48:16,420 ERROR [err] - java.lang.NullPointerException
2016-02-10 10:48:16,420 ERROR [err] - 	at net.gtaun.shoebill.streamer.Functions.createDynamicObject(Functions.java:115)
2016-02-10 10:48:16,420 ERROR [err] - 	at net.gtaun.shoebill.streamer.Functions.createDynamicObject(Functions.java:110)
2016-02-10 10:48:16,421 ERROR [err] - 	at net.gtaun.shoebill.streamer.data.DynamicObject.create(DynamicObject.java:60)
2016-02-10 10:48:16,421 ERROR [err] - 	at net.gtaun.shoebill.streamer.data.DynamicObject.create(DynamicObject.java:56)
2016-02-10 10:48:16,421 ERROR [err] - 	at net.gtaun.shoebill.streamer.data.DynamicObject.create(DynamicObject.java:52)
2016-02-10 10:48:16,422 ERROR [err] - 	at lt.ltrp.LtrpGamemode.onEnable(LtrpGamemode.java:81)
2016-02-10 10:48:16,424 ERROR [err] - 	at net.gtaun.shoebill.resource.Resource.enable(Resource.java:91)
2016-02-10 10:48:16,424 ERROR [err] - 	at net.gtaun.shoebill.resource.ResourceManagerImpl.loadGamemode(ResourceManagerImpl.java:179)
2016-02-10 10:48:16,424 ERROR [err] - 	at net.gtaun.shoebill.resource.ResourceManagerImpl.loadAllResource(ResourceManagerImpl.java:62)
2016-02-10 10:48:16,425 ERROR [err] - 	at net.gtaun.shoebill.ShoebillImpl.loadPluginsAndGamemode(ShoebillImpl.java:289)
2016-02-10 10:48:16,426 ERROR [err] - 	at net.gtaun.shoebill.ShoebillImpl.access$100(ShoebillImpl.java:47)
2016-02-10 10:48:16,426 ERROR [err] - 	at net.gtaun.shoebill.ShoebillImpl$1.onAmxLoad(ShoebillImpl.java:233)
2016-02-10 10:48:16,428 ERROR [err] - 	at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.lambda$null$80(SampCallbackManagerImpl.java:60)
2016-02-10 10:48:16,428 ERROR [err] - 	at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1$$Lambda$31/17272983.call(Unknown Source)
2016-02-10 10:48:16,428 ERROR [err] - 	at net.gtaun.shoebill.util.TryUtils.tryTo(TryUtils.java:21)
2016-02-10 10:48:16,431 ERROR [err] - 	at net.gtaun.shoebill.util.TryUtils.tryTo(TryUtils.java:14)
2016-02-10 10:48:16,432 ERROR [err] - 	at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.lambda$onAmxLoad$81(SampCallbackManagerImpl.java:60)
2016-02-10 10:48:16,432 ERROR [err] - 	at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1$$Lambda$30/5764627.accept(Unknown Source)
2016-02-10 10:48:16,432 ERROR [err] - 	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
2016-02-10 10:48:16,433 ERROR [err] - 	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
2016-02-10 10:48:16,433 ERROR [err] - 	at java.util.concurrent.ConcurrentLinkedQueue$CLQSpliterator.forEachRemaining(ConcurrentLinkedQueue.java:851)
2016-02-10 10:48:16,433 ERROR [err] - 	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)
2016-02-10 10:48:16,435 ERROR [err] - 	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
2016-02-10 10:48:16,435 ERROR [err] - 	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
2016-02-10 10:48:16,435 ERROR [err] - 	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
2016-02-10 10:48:16,436 ERROR [err] - 	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
2016-02-10 10:48:16,436 ERROR [err] - 	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
2016-02-10 10:48:16,436 ERROR [err] - 	at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.onAmxLoad(SampCallbackManagerImpl.java:60)
I tracked it down and this is the cause
Код:
hoebill.get().getAmxInstanceManager().getAmxInstances().iterator().next().getNative("CreateDynamicObject");
So basically it can't find the CreateDynamicObject function(which I'm sure exists)... I printed out to be sure, this does return null. I created a 1sec timer in my onEnable with the same code - it worked, an object was created.

EDIT2: the NullPointer is solved by loading the streamer first. http://forum.sa-mp.com/showpost.php?...&postcount=705
Reply

@dusk, try to load streamer plugin earlier than Shoebill. In server.cfg (at "plugins" line) place streamer (or streamer.so) before Shoebill.
Reply

@valych thanks, that worked
Reply

Where can i get a Streamer.jar?
Reply

@Urukay once you add it as a dependency in your gamemode and build it, the streamer jar will be downloaded and placed in your local repository. The default on windows is C:\Users\{useer}\.m2\repository

Or simply download it from the Shoebill jenkins server: http://ci.gtaun.net/job/streamer-wrapper/
Reply

@valych: I fixed this issue in the newest runtime build: http://ci.gtaun.net/job/shoebill-runtime/278/
Reply

@mk124, thanks
P.S. Wrote this message just to confirm that it is fixed
Reply

Back to my problem with sampgdk error (link to post: http://forum.sa-mp.com/showpost.php?...&postcount=681)
@mk124, I ran my server on a bare gamemode and that error didn't come up.
Btw, now I get more detailed (I guess) message:
Код:
[sampgdk:error] Too many callback arguments (at most 32 allowed)
[sampgdk:error] Too many callback arguments (at most 32 allowed)
[debug] Server crashed due to an unknown error
[debug] Native backtrace:
[debug] #0 00401c84 in ?? () from samp-server.exe
[debug] #1 0046e8a0 in ?? () from samp-server.exe
[debug] #2 0048f63b in ?? () from samp-server.exe
[debug] #3 570d6d43 in ?? () from C:\Program Files (x86)\Java\jdk1.8.0_65\jre\bin\server\jvm.dll
[debug] #4 570d6d43 in ?? () from C:\Program Files (x86)\Java\jdk1.8.0_65\jre\bin\server\jvm.dll
[debug] #5 77940489 in ?? () from C:\WINDOWS\SYSTEM32\ntdll.dll
[debug] #6 00498da1 in ?? () from samp-server.exe
[debug] #7 00491044 in ?? () from samp-server.exe
[debug] #8 458d5151 in ?? () from samp-server.exe
[debug] #9 15ff50f8 in ?? ()
[debug] #10 004ac0c4 in ?? () from samp-server.exe
So it happens only if I call this function from my pawn gamemode:
PHP код:
stock shoebill_SpawnRandomItems()  

    
CallShoebillFunction("java_SpawnRandomItems"1); 
    return 
1

Can it be due to lack of memory allocated for JVM?
Reply

@valych: Are you using any other plugin than Shoebill when this error occurs? Please compile your game mode in pawno with debug information by following this guide: https://github.com/Zeex/samp-plugin-...ith-debug-info. Then try it again and post the result of the crash detect output.
Reply

@mk124, the gamemode is already being compiled with -d3 option (I even tried to compile with pawn, the result was the same - no any references to lines or components where error is being occured).
Also, I did some other tests and changed the code of java function to this:
PHP код:
    public void spawnItemsFromPoints(Collection<ItemSpawnPointpoints) {
        
Vector3D defaultOffset = new Vector3D();
        
// Limit of amount of objects to be spawned
        
int limit 1;
        for (
ItemSpawnPoint spawnPoint points) {
            if(
limit != -1) {
                if(
limit-- <= 0) {
                    break;
                }
            }
            
Vector3D offset defaultOffset;
            
// Create random item
            
ItemGroup itemModel this.getRandomItemModel(spawnPoint);
            
Item item generateItemWithRandomCondition(itemModel);
            
// Object offsets setup
            
Vector3D rotation spawnPoint.rotation;
            if(
rotation.getX() == 0f && rotation.getY() == 0f) {
                
offset itemModel.getModelPosOffset();
                
rotation itemModel.getModelRotationOffset().clone();
                
rotation.setZ(spawnPoint.rotation.getZ());
            }
            
// Spawn the item
            
GroundItem.create(itemspawnPoint.locationoffset.getX(), offset.getY(), offset.getZ(), rotation.getX(), rotation.getY(), rotation.getZ(), false);
        }
        
//Player.get().forEach(player -> Functions.update(player, StreamerType.OBJECT));
    

In a result, only one object should be spawned. But now, the server didn't crash and started to output next (after I called shoebill_SpawnRandomItems() in pawn):
Код:
[debug] AMX backtrace:
[debug] Run time error 7: "Stack underflow"
[debug]  Stack pointer (STK) is 0x24A8D7C, stack top (STP) is 0x24A8D78
[debug] AMX backtrace:
[debug] Run time error 7: "Stack underflow"
[debug]  Stack pointer (STK) is 0x24A8D7C, stack top (STP) is 0x24A8D78
[debug] AMX backtrace:
[debug] Run time error 7: "Stack underflow"
[debug]  Stack pointer (STK) is 0x24A8D7C, stack top (STP) is 0x24A8D78
[debug] AMX backtrace:
[debug] Run time error 7: "Stack underflow"
[debug]  Stack pointer (STK) is 0x24A8D7C, stack top (STP) is 0x24A8D78
[debug] AMX backtrace:
[debug] Run time error 7: "Stack underflow"
[debug]  Stack pointer (STK) is 0x24A8D7C, stack top (STP) is 0x24A8D78
[debug] AMX backtrace:
[debug] Run time error 7: "Stack underflow"
I have experienced this error once, fixed by increasing #define dynamic value, but this time it didn't help.

Anyway, it's strange, I guess you shouldn't bother with this, until the error appears in other places I'll try to find how to avoid calling that java function from pawn.


Also, another question: how to send an array from pawn to java function except for String type?
For now, I send it as a String and add char's to the string as integers like this:
PHP код:
String array = objects[0];
array += (
char12
Is there another way to do this?
Reply

@valych: If you want to pass a array using CallShoebillFunction you will have to use Int[].class or Boolean[].class as the type when using registerFunction(). In your Pawn Gamemode you pass the array variable, followed by the length of the array.

e.g: CallShoebillFunction("Test", myArray, sizeof(myArray));
Reply

I had a suspicion that there's an issue with returning floats(specifically from MapAndreas), but while testing I encountered another issue.

Pawn function:
pawn Код:
forward GetFloatVal(Float:x, Float:y, &Float:z);
public GetFloatVal(Float:x, Float:y, &Float:z)
{
    z = x * y;
}
Java code
Код:
eventManager.registerHandler(AmxLoadEvent.class, e -> {
            AmxCallable func = e.getAmxInstance().getPublic("GetFloatVal");
            if(func != null) {
                System.out.println("Function found in handler " + e.getAmxInstance().getHandle() + " callbable name:" + func.getName() + " callable return type:" + func.getReturnType());
                float z = 0f;
                ReferenceFloat refZ = new ReferenceFloat(z);
                func.call(2395.3972f, -1548.5687f, refZ);
                z = refZ.getValue();
                System.out.println("Z:" + z);
            } else {
                System.out.println("Function not found in handle " + e.getAmxInstance().getHandle());
            }
        });
Output

Код:
[2016-02-13 16:48:02][INFO][out] Function not found in handle 903863776
[2016-02-13 16:48:02][INFO][out] Function found in handler 903939152 callbable name:GetFloatVal callable return type:INTEGER
[2016-02-13 16:48:02][ERROR][err] java.lang.NoSuchMethodError: net.gtaun.shoebill.SampNativeFunction.callPublic(III[Ljava/lang/Object;)Ljava/lang/Object;
[2016-02-13 16:48:02][ERROR][err] 	at net.gtaun.shoebill.amx.AmxCallableImpl.call(AmxCallableImpl.java:48)
[2016-02-13 16:48:02][ERROR][err] 	at lt.maze.MyGamemode.lambda$onEnable$0(MyGamemode.java:28)
[2016-02-13 16:48:02][ERROR][err] 	at lt.maze.MyGamemode$$Lambda$33/17775924.handleEvent(Unknown Source)
[2016-02-13 16:48:02][ERROR][err] 	at net.gtaun.util.event.EventManagerRoot.dispatchEvent(EventManagerRoot.java:189)
[2016-02-13 16:48:02][ERROR][err] 	at net.gtaun.util.event.EventManager.dispatchEvent(EventManager.java:129)
[2016-02-13 16:48:02][ERROR][err] 	at net.gtaun.shoebill.amx.AmxInstanceManagerImpl.onAmxLoad(AmxInstanceManagerImpl.java:34)
[2016-02-13 16:48:02][ERROR][err] 	at net.gtaun.shoebill.ShoebillImpl$1.onAmxLoad(ShoebillImpl.java:230)
[2016-02-13 16:48:02][ERROR][err] 	at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.lambda$null$80(SampCallbackManagerImpl.java:60)
[2016-02-13 16:48:02][ERROR][err] 	at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1$$Lambda$31/27184720.call(Unknown Source)
[2016-02-13 16:48:02][ERROR][err] 	at net.gtaun.shoebill.util.TryUtils.tryTo(TryUtils.java:21)
[2016-02-13 16:48:02][ERROR][err] 	at net.gtaun.shoebill.util.TryUtils.tryTo(TryUtils.java:14)
[2016-02-13 16:48:02][ERROR][err] 	at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.lambda$onAmxLoad$81(SampCallbackManagerImpl.java:60)
[2016-02-13 16:48:02][ERROR][err] 	at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1$$Lambda$30/31100424.accept(Unknown Source)
[2016-02-13 16:48:02][ERROR][err] 	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
[2016-02-13 16:48:02][ERROR][err] 	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
[2016-02-13 16:48:02][ERROR][err] 	at java.util.concurrent.ConcurrentLinkedQueue$CLQSpliterator.forEachRemaining(ConcurrentLinkedQueue.java:851)
[2016-02-13 16:48:02][ERROR][err] 	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)
[2016-02-13 16:48:02][ERROR][err] 	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
[2016-02-13 16:48:02][ERROR][err] 	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
[2016-02-13 16:48:02][ERROR][err] 	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
[2016-02-13 16:48:02][ERROR][err] 	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
[2016-02-13 16:48:02][ERROR][err] 	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
[2016-02-13 16:48:02][ERROR][err] 	at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.onAmxLoad(SampCallbackManagerImpl.java:60)

[2016-02-13 16:48:02][INFO][out] Z:0.0
Reply

@dusk: You launcher is probably outdated, try to update it via the shoebill-updater.
Reply

@mk124 ah, thanks! Also managed to solve my MapAndreas wrapper issue, it seems I was calling getPublic instead of getNative...


EDIT: Let's talk about checkpoints. How should they be used?

This is my code, is it bad that I do not store the instance of that chekpoint anywhere? Does Shoebill store it internally? When I call player.disableCheckpoint() will it be destroyed? Why can't consumers be set after creating a Checkpoint?
Код:
Checkpoint.create(getRadius(), onEnterConsumer, null).set(player);
Reply

@dusk: When you use the .set() method you actually store it in the Player's class instance. It will automatically be removed when it is not needed anymore.

I pushed an update that allows you to change the location even after the Checkpoint has been create / shown:
http://ci.gtaun.net/job/shoebill-api/213/ and http://ci.gtaun.net/job/shoebill-api/214/

If you don't store the Checkpoint in a variable you can call the player.getCheckpoint() method and you will get the current checkpoint. On this checkpoint object you can now call the setLocation() method to change it's location. The checkpoint will be automatically recreated at it's new location. I also added an convenient constructor if you want to use the CheckpointEnterEvent instead of the Consumers. https://github.com/Shoebill/shoebill...17d9a3d6265R61
Reply

@mk124, found an issue with passing arrays to java function - it is impossible to pass other values except for an array and size of the array to java function. Server is being crashed.
Java code:
PHP код:
        instance.registerFunction("java_TestArray"objects -> {
            
int someValue = (Integer) objects[0]; // in this line the java.lang.ClassCastException is being thrown (read below)
            
Integer[] array = (Integer[])objects[1];
            for (
int i 0< array.lengthi++) {
                if(
someValue == 33) {
                    array[
i] = (2) * 4;
                } else {
                    array[
i] = i+1;
                }
            }
            return 
1;
        }, 
Integer.class, Integer[].class, Integer.class); 
The next message follows after calling the java function from pawn:
Код:
[19:57:52][ERROR][err] java.lang.ClassCastException: [Ljava.lang.Integer; cannot be cast to java.lang.Integer
[19:57:52][ERROR][err]  at com.infected_wars.iw.common.utils.pawn.methods.ItemMethods.lambda$registerPawnFunctions$46(ItemMethods.java:47)
[19:57:52][ERROR][err]  at net.gtaun.shoebill.amx.AmxInstanceImpl.callRegisteredFunction(AmxInstanceImpl.java:67)
[19:57:52][ERROR][err]  at net.gtaun.shoebill.SampEventDispatcher.onRegisteredFunctionCall(SampEventDispatcher.java:2143)
[19:57:52][ERROR][err]  at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.lambda$null$334(SampCallbackManagerImpl.java:847)
[19:57:52][ERROR][err]  at net.gtaun.shoebill.util.TryUtils.tryTo(TryUtils.java:21)
[19:57:52][ERROR][err]  at net.gtaun.shoebill.util.TryUtils.tryTo(TryUtils.java:14)
[19:57:52][ERROR][err]  at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.lambda$onRegisteredFunctionCall$335(SampCallbackManagerImpl.java:847)
[19:57:52][ERROR][err]  at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
[19:57:52][ERROR][err]  at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
[19:57:52][ERROR][err]  at java.util.concurrent.ConcurrentLinkedQueue$CLQSpliterator.forEachRemaining(ConcurrentLinkedQueue.java:851)
[19:57:52][ERROR][err]  at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
[19:57:52][ERROR][err]  at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
[19:57:52][ERROR][err]  at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
[19:57:52][ERROR][err]  at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
[19:57:52][ERROR][err]  at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
[19:57:52][ERROR][err]  at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
[19:57:52][ERROR][err]  at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.onRegisteredFunctionCall(SampCallbackManagerImpl.java:847)
[debug] Server crashed while executing bare.amx
[debug] AMX backtrace:
[debug] #0 native CallShoebillFunction () from Shoebill.DLL
[debug] #1 00000230 in public TestArrayFunction () at D:\Backup of flash card\all for California RolePlay\Survival Project\Java server test\gamemodes\bare.pwn:40
[debug] Native backtrace:
[debug] #0 526e8ef9 in ?? () from C:\Program Files (x86)\Java\jdk1.8.0_65\jre\bin\server\jvm.dll
[debug] #1 52747f5b in ?? () from C:\Program Files (x86)\Java\jdk1.8.0_65\jre\bin\server\jvm.dll
[debug] #2 52749ddc in ?? () from C:\Program Files (x86)\Java\jdk1.8.0_65\jre\bin\server\jvm.dll
[debug] #3 52c88e2b in ?? () from plugins\Shoebill.DLL
[debug] #4 52c8695b in ?? () from plugins\Shoebill.DLL
[debug] #5 004010b6 in ?? () from samp-server.exe
[debug] #6 52d562ca in ?? () from plugins\crashdetect.DLL
[debug] #7 52d58b28 in ?? () from plugins\crashdetect.DLL
[debug] #8 52d509c7 in ?? () from plugins\crashdetect.DLL
[debug] #9 52d5631a in ?? () from plugins\crashdetect.DLL
[debug] #10 546f51b9 in ?? () from plugins\streamer.DLL
[debug] #11 52cac974 in ?? () from plugins\Shoebill.DLL
[debug] #12 100012ad in ?? () from plugins\fixes2.DLL
[debug] #13 00469a46 in ?? () from samp-server.exe
[debug] #14 0048d46b in ?? () from samp-server.exe
[debug] #15 0049b431 in ?? () from samp-server.exe
[debug] #16 0049b441 in ?? () from samp-server.exe
Pawn code (I'm not sure that the problem is in here):
PHP код:
    new array[32];
    
CallShoebillFunction("java_TestArray"33, array, sizeof(array));
    for(new 
032i++) {
        
printf("array[%d] = %d"i, array[i]);
    } 
Also, I tried to move first parameter to the last, and it's worked, but after execution of java function I get NullPointerException message:
Java code:
PHP код:
        instance.registerFunction("java_TestArray"objects -> {
            
int someValue = (Integer) objects[2];
            
Integer[] array = (Integer[])objects[0];
            for (
int i 0< array.lengthi++) {
                if(
someValue == 33) {
                    array[
i] = (2) * 4;
                } else {
                    array[
i] = i+1;
                }
            }
            return 
1;
        }, 
Integer[].class, Integer.class, Integer.class); 
Pawn code (remains the same, just moved 33 to the end):
PHP код:
    new array[32];
    
CallShoebillFunction("java_TestArray", array, sizeof(array), 33);
    for(new 
032i++) {
        
printf("array[%d] = %d"i, array[i]);
    }
    return 
1
Console's messages:
Код:
array[0] = 8
array[1] = 12
array[2] = 16
array[3] = 20
array[4] = 24
array[5] = 28
array[6] = 32
array[7] = 36
array[8] = 40
array[9] = 44
array[10] = 48
array[11] = 52
array[12] = 56
array[13] = 60
array[14] = 64
array[15] = 68
array[16] = 72
array[17] = 76
array[18] = 80
array[19] = 84
array[20] = 88
array[21] = 92
array[22] = 96
array[23] = 100
array[24] = 104
array[25] = 108
array[26] = 112
array[27] = 116
array[28] = 120
array[29] = 124
array[30] = 128
array[31] = 132
[20:06:02][ERROR][err] java.lang.NullPointerException
Or maybe I did something wrong when passing any value to the java function?
Reply

@valych: You don't add the Integer.class at the end for the length, this is just a Pawn thing because the length of the array is not known when you pass it to the plugin. Your function should look like this:
PHP код:
instance.registerFunction("java_TestArray"objects -> { 
            
int someValue = (Integer) objects[0]; // in this line the java.lang.ClassCastException is being thrown (read below) 
            
Integer[] array = (Integer[])objects[1]; 
            for (
int i 0< array.lengthi++) { 
                if(
someValue == 33) { 
                    array[
i] = (2) * 4
                } else { 
                    array[
i] = i+1
                } 
            } 
            return 
1
        }, 
Integer.class, Integer[].class); 
The rest should be alright.
Reply

@mk124, I tried that, but I got the following message:
Код:
[SHOEBILL] Calling java_TestArray with 3 parameters, but was expecting 2 parameters.
array[0] = 0
array[1] = 0
array[2] = 0
array[3] = 0
array[4] = 0
array[5] = 0
array[6] = 0
array[7] = 0
array[8] = 0
array[9] = 0
array[10] = 0
array[11] = 0
array[12] = 0
array[13] = 0
array[14] = 0
array[15] = 0
array[16] = 0
array[17] = 0
array[18] = 0
array[19] = 0
array[20] = 0
array[21] = 0
array[22] = 0
array[23] = 0
array[24] = 0
array[25] = 0
array[26] = 0
array[27] = 0
array[28] = 0
array[29] = 0
array[30] = 0
array[31] = 0
Reply

@valych: Ok, I fixed this issue. Please update your plugin with the Shoebill-Updater.

You should now change your code as following:
1. Don't add an Integer.class for the Pawn's array length

PHP код:
instance.registerFunction("java_TestArray"objects -> {  
            
int someValue = (Integer) objects[0];

            
Integer[] array = (Integer[])objects[1];  
            for (
int i 0< array.lengthi++) {  
                if(
someValue == 33) {  
                    array[
i] = (2) * 4;  
                } else {  
                    array[
i] = i+1;  
                }  
            }  
            return 
1;  
        }, 
Integer.class, Integer[].class); 
and Pawn:
PHP код:
new array[32]; 
    
CallShoebillFunction("java_TestArray"33, array, sizeof(array)); 

    for(new 
032i++) { 
        
printf("array[%d] = %d"i, array[i]); 
    } 
    return 
1
You can now of course change the order of the Integer and the Array if you want. But always keep in mind that after you pass an Pawn array to Shoebill, the size must follow directly after that. Like https://sampwiki.blast.hk/wiki/GetPlayerName
Reply

Код:
commandManager = new PlayerCommandManager(eventManager);
        commandManager.installCommandHandler(HandlerPriority.BOTTOM);
        commandManager.registerCommand("takelesson", new Class[0], new String[0], (player, params) -> {
            LtrpPlayer p = LtrpPlayer.get(player);
            if(p != null) {
                p.sendErrorMessage("Šią komandą galite naudoti tik būdami vairavimo mokyklos transporto priemonėje arba mokyklos patalpose.");
            }
            return true;
        }, null, null);
Код:
2016-02-14 22:30:26,926 ERROR [err] - java.lang.NullPointerException
2016-02-14 22:30:26,926 ERROR [err] -   at net.gtaun.shoebill.common.command.CommandGroup.processCommand(CommandGroup.java:284)
2016-02-14 22:30:26,926 ERROR [err] -   at net.gtaun.shoebill.common.command.CommandGroup.processCommand(CommandGroup.java:267)
2016-02-14 22:30:26,927 ERROR [err] -   at net.gtaun.shoebill.common.command.PlayerCommandManager.processCommand(PlayerCommandManager.java:89)
2016-02-14 22:30:26,927 ERROR [err] -   at net.gtaun.shoebill.common.command.PlayerCommandManager.lambda$installCommandHandler$79(PlayerCommandManager.java:62)
2016-02-14 22:30:26,927 ERROR [err] -   at net.gtaun.shoebill.common.command.PlayerCommandManager$$Lambda$124/22743881.handleEvent(Unknown Source)
2016-02-14 22:30:26,927 ERROR [err] -   at net.gtaun.util.event.EventManagerRoot.dispatchEvent(EventManagerRoot.java:189)
2016-02-14 22:30:26,927 ERROR [err] -   at net.gtaun.util.event.EventManager.dispatchEvent(EventManager.java:129)
2016-02-14 22:30:26,927 ERROR [err] -   at net.gtaun.shoebill.SampEventDispatcher.onPlayerCommandText(SampEventDispatcher.java:248)
2016-02-14 22:30:26,927 ERROR [err] -   at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.lambda$null$100(SampCallbackManagerImpl.java:129)
2016-02-14 22:30:26,928 ERROR [err] -   at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1$$Lambda$299/8312572.call(Unknown Source)
2016-02-14 22:30:26,928 ERROR [err] -   at net.gtaun.shoebill.util.TryUtils.tryTo(TryUtils.java:21)
2016-02-14 22:30:26,928 ERROR [err] -   at net.gtaun.shoebill.util.TryUtils.tryTo(TryUtils.java:14)
2016-02-14 22:30:26,928 ERROR [err] -   at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.lambda$onPlayerCommandText$101(SampCallbackManagerImpl.java:129)
2016-02-14 22:30:26,928 ERROR [err] -   at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1$$Lambda$298/17521583.accept(Unknown Source)
2016-02-14 22:30:26,928 ERROR [err] -   at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
2016-02-14 22:30:26,928 ERROR [err] -   at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
2016-02-14 22:30:26,928 ERROR [err] -   at java.util.concurrent.ConcurrentLinkedQueue$CLQSpliterator.forEachRemaining(ConcurrentLinkedQueue.java:851)
2016-02-14 22:30:26,928 ERROR [err] -   at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:512)
2016-02-14 22:30:26,929 ERROR [err] -   at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:502)
2016-02-14 22:30:26,929 ERROR [err] -   at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
2016-02-14 22:30:26,929 ERROR [err] -   at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
2016-02-14 22:30:26,929 ERROR [err] -   at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
2016-02-14 22:30:26,929 ERROR [err] -   at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
2016-02-14 22:30:26,929 ERROR [err] -   at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.onPlayerCommandText(SampCallbackManagerImpl.java:129)
Reply


Forum Jump:


Users browsing this thread: 20 Guest(s)