[Java API] Get User From PublicUser


#1

Whenever a transaction is created, it has a PublicUser object attached to it. The PublicUser object only has the user’s ID and Username attached to it, which can be problematic if you’re using CubedPay in a gaming-environment such as Minecraft.

Previously, you were able to get the User object from a Transaction (Order at the time). This was better from a developer’s perspective because the User object contains all of the UserProfiles attached to the user, meaning you could get their in-game name as well.

Currently, there is no way to obtain a relevant in-game name while handling a transaction, preventing any attempt provide the user with their package in-game. That being said, I think that there should be some way to get a User object from either a Transaction or a PublicUser object. Personally, I think that simply replacing PublicUser with User would be fine since the only form of sensitive information that can come with it is an email address :woman_shrugging:


#2

I think it’s also worth noting that any command performed through the package runner plugin will only work if the user’s CubedPay username is the same as their in-game username.


#3

Hi Bert,

You should be using the “profile” data that you get with the response in order to get a player from in game.

Thanks
Stuart


#4

Using the REST API, yes. I’m talking about what’s currently available through the Java client, however.


#5

Hi Bert,

I’ve just realised that the Java API we provide doesn’t actually contain that data. I’ve spoken to the relevant people and they’re going to take a look. I’ll let you know when I’ve heard back.

Thanks
Stuart


#6

Haha, thanks Stuart! :smiley:


#7

Hey Bert,

Yep that was definitely a miss on our part! I pushed a change out in the last commit that hopefully should fix said issue. I am going to go through and double check to make sure all is good now! This change will have a version bump by tonight with a proper fix for the runner too.

Thanks
Cameron
:slight_smile:


#8

Thanks for the update!

Unfortunately, using the new version of the Java client you pushed to the Github repo, I’ve stumbled across a new error when listening for incoming transactions.

While I am not using the package runner exactly, the code is the same except for me doing an additional check to see if the player is online.

Stack trace:

01.09 11:33:30 [Server] INFO Found 7 CubedPay events to process..
01.09 11:33:30 [Server] INFO transaction event found
01.09 11:33:30 [Server] INFO CubedPay - Error: Invoke exception on PrismListener#onPurchasedEvent()
01.09 11:33:30 [Server] WARN com.google.shaded.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at path $.profile
01.09 11:33:30 [Server] WARN at com.google.shaded.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224)
01.09 11:33:30 [Server] WARN at com.google.shaded.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
01.09 11:33:30 [Server] WARN at com.google.shaded.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
01.09 11:33:30 [Server] WARN at com.google.shaded.gson.Gson.fromJson(Gson.java:888)
01.09 11:33:30 [Server] WARN at com.google.shaded.gson.Gson.fromJson(Gson.java:953)
01.09 11:33:30 [Server] WARN at com.google.shaded.gson.Gson.fromJson(Gson.java:926)
01.09 11:33:30 [Server] WARN at co.melondev.cubedpay.data.Event$Object.getObject(Event.java:94)
01.09 11:33:30 [Server] WARN at co.melondev.cubedpay.events.shop.transaction.TransactionEvent.getTransaction(TransactionEvent.java:17)
01.09 11:33:30 [Server] WARN at com.berttowne.cubedpay.PrismListener.onPurchasedEvent(PrismListener.java:44)
01.09 11:33:30 [Server] WARN at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
01.09 11:33:30 [Server] WARN at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
01.09 11:33:30 [Server] WARN at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
01.09 11:33:30 [Server] WARN at java.lang.reflect.Method.invoke(Unknown Source)
01.09 11:33:30 [Server] WARN at co.melondev.cubedpay.events.CubedAnnotationProcessor.lambda$emitEvent$20(CubedAnnotationProcessor.java:39)
01.09 11:33:30 [Server] WARN at java.lang.Iterable.forEach(Unknown Source)
01.09 11:33:30 [Server] WARN at co.melondev.cubedpay.events.CubedAnnotationProcessor.emitEvent(CubedAnnotationProcessor.java:36)
01.09 11:33:30 [Server] WARN at co.melondev.cubedpay.CubedPayAPI.emitEvent(CubedPayAPI.java:140)
01.09 11:33:30 [Server] WARN at co.melondev.cubedpay.events.CubedEventRunnable.lambda$null$24(CubedEventRunnable.java:30)
01.09 11:33:30 [Server] WARN at java.util.ArrayList.forEach(Unknown Source)
01.09 11:33:30 [Server] WARN at co.melondev.cubedpay.events.CubedEventRunnable.lambda$run$25(CubedEventRunnable.java:27)
01.09 11:33:30 [Server] WARN at java.util.concurrent.CompletableFuture.uniAccept(Unknown Source)
01.09 11:33:30 [Server] WARN at java.util.concurrent.CompletableFuture$UniAccept.tryFire(Unknown Source)
01.09 11:33:30 [Server] WARN at java.util.concurrent.CompletableFuture.postComplete(Unknown Source)
01.09 11:33:30 [Server] WARN at java.util.concurrent.CompletableFuture.complete(Unknown Source)
01.09 11:33:30 [Server] WARN at retrofit2.adapter.java8.Java8CallAdapterFactory$BodyCallAdapter$2.onResponse(Java8CallAdapterFactory.java:107)

#9

Hey Bert,
Sorry about that just some changes I did not see apparently we are only returning the profile instead of the full object. I did a proper test and seems to be working now. Changes pushes and the jars on the releases were updated. Hopefully that is it for the fixes for that! :slight_smile:


#10

That works! Now the only issue is that my shop is missing the shop:transaction scope (among others) since it was made in early private beta