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 :/
UUIDuuid=UUID.fromString(uuid_string);Playerplayer=Bukkit.getOfflinePlayer(uuid).getPlayer();ISpecialPlayerInventoryopeninv_inv=openinv.getSpecialInventory(player,player.isOnline());//null point exeptionInventoryinv=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)
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
}
});
```
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));
```
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.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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)
{trying to get player inv by uuid)
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)
Well, yeah, you're using
OfflinePlayer#getPlayerto obtain your Player object. That returns null for offline players.If you want to support name input as well:
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.
Thank you, but I don't want to manipulate inventories for now, only read them :)