API for offline players doesn't work #77

Closed
opened 2017-09-04 06:10:59 -04:00 by NotJustPizza · 3 comments
NotJustPizza commented 2017-09-04 06:10:59 -04:00 (Migrated from github.com)

I'm trying to get inventory of online and offline players using OpenInv API, but it only works for online players. When I'm trying to get inventory of offline player I'm getting null :/

(getting openinv instance in main plugin class)

 openinv = (OpenInv) getServer().getPluginManager().getPlugin("OpenInv");

{trying to get player inv by uuid)

UUID uuid = UUID.fromString(uuid_string);
Player player = Bukkit.getOfflinePlayer(uuid).getPlayer();

ISpecialPlayerInventory openinv_inv = openinv.getSpecialInventory(player, player.isOnline()); //null point exeption
Inventory inv = openinv_inv.getBukkitInventory();

Note: opeinv.getInventory() also works only for online players

(probably not related, because this code works for online players, but I'm executing it as async task)

Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() {
    @Override
    public void run() {
        //code
    }
});
I'm trying to get inventory of online and offline players using OpenInv API, but it only works for online players. When I'm trying to get inventory of offline player I'm getting null :/ (getting openinv instance in main plugin class) ```java openinv = (OpenInv) getServer().getPluginManager().getPlugin("OpenInv"); ``` {trying to get player inv by uuid) ```java UUID uuid = UUID.fromString(uuid_string); Player player = Bukkit.getOfflinePlayer(uuid).getPlayer(); ISpecialPlayerInventory openinv_inv = openinv.getSpecialInventory(player, player.isOnline()); //null point exeption Inventory inv = openinv_inv.getBukkitInventory(); ``` Note: opeinv.getInventory() also works only for online players (probably not related, because this code works for online players, but I'm executing it as async task) ```java Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() { @Override public void run() { //code } }); ```
Jikoo commented 2017-09-04 07:16:00 -04:00 (Migrated from github.com)

Well, yeah, you're using OfflinePlayer#getPlayer to obtain your Player object. That returns null for offline players.

Player player = openInv.loadPlayer(Bukkit.getOfflinePlayer(uuid));

If you want to support name input as well:

Player player = openInv.loadPlayer(openInv.matchPlayer(uuidString));
Well, yeah, you're using `OfflinePlayer#getPlayer` to obtain your Player object. That returns null for offline players. ```Java Player player = openInv.loadPlayer(Bukkit.getOfflinePlayer(uuid)); ``` If you want to support name input as well: ```Java Player player = openInv.loadPlayer(openInv.matchPlayer(uuidString)); ```
Jikoo commented 2017-09-04 07:18:12 -04:00 (Migrated from github.com)

I also strongly recommend you only load the player async, then manipulate the inventory on the main thread. You're opening yourself to concurrency issues otherwise.

I also strongly recommend you only load the player async, then manipulate the inventory on the main thread. You're opening yourself to concurrency issues otherwise.
NotJustPizza commented 2017-09-04 08:08:52 -04:00 (Migrated from github.com)

Thank you, but I don't want to manipulate inventories for now, only read them :)

Thank you, but I don't want to manipulate inventories for now, only read them :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: minster586/OpenInv#77
No description provided.