Merge pull request #132 in MIN/mineplex from bugfix/give-item-offline to develop
* commit '404e049c31df6d4278ee3ed46e7f0b8e2f92ee16': Give item fix for offline players
This commit is contained in:
commit
0fd5540de6
@ -214,6 +214,11 @@ public class CoreClientManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
public void loadAccountIdFromUUID(UUID uuid, Callback<Integer> callback)
|
||||
{
|
||||
_repository.getAccountId(uuid, callback);
|
||||
}
|
||||
|
||||
public void loadClientByName(final String playerName, final Runnable runnable)
|
||||
{
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
|
@ -41,6 +41,7 @@ public class AccountRepository extends RepositoryBase
|
||||
private static String UPDATE_ACCOUNT_NULL_RANK = "UPDATE accounts SET rank=?, donorRank=?, rankPerm=?, rankExpire=? WHERE uuid = ? AND rank IS NULL;";
|
||||
|
||||
private static String SELECT_ACCOUNT_UUID_BY_NAME = "SELECT uuid FROM accounts WHERE name = ? ORDER BY lastLogin DESC;";
|
||||
private static String SELECT_ACCOUNT_ID_BY_UUID = "SELECT id FROM accounts WHERE accounts.uuid = ? LIMIT 1";
|
||||
|
||||
private String _webAddress;
|
||||
|
||||
@ -161,6 +162,15 @@ public class AccountRepository extends RepositoryBase
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void getAccountId(UUID uuid, Callback<Integer> callback)
|
||||
{
|
||||
executeQuery(SELECT_ACCOUNT_ID_BY_UUID, resultSet -> {
|
||||
int accountId = -1;
|
||||
while (resultSet.next()) accountId = resultSet.getInt(1);
|
||||
callback.run(accountId);
|
||||
}, new ColumnVarChar("uuid", 100, uuid.toString()));
|
||||
}
|
||||
|
||||
public String GetClient(String name, UUID uuid, String ipAddress)
|
||||
{
|
||||
LoginToken token = new LoginToken();
|
||||
|
@ -23,6 +23,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.cache.player.PlayerCache;
|
||||
import mineplex.cache.player.PlayerInfo;
|
||||
import mineplex.core.MiniDbClientPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.util.Callback;
|
||||
@ -138,17 +139,28 @@ public class InventoryManager extends MiniDbClientPlugin<ClientInventory>
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
PlayerInfo playerInfo = PlayerCache.getInstance().getPlayer(uuid);
|
||||
if (playerInfo != null)
|
||||
{
|
||||
addItemToInventoryForOffline(callback, PlayerCache.getInstance().getPlayer(uuid).getAccountId(), item, count);
|
||||
addItemToInventoryForOffline(callback, playerInfo.getAccountId(), item, count);
|
||||
}
|
||||
catch (Exception e)
|
||||
else
|
||||
{
|
||||
e.printStackTrace();
|
||||
|
||||
System.out.println("-----DEBUG-----");
|
||||
System.out.println("PlayerCache Instance: " + (PlayerCache.getInstance() == null));
|
||||
System.out.println("PlayerCache Player Object: " + (PlayerCache.getInstance().getPlayer(uuid) == null));
|
||||
ClientManager.loadAccountIdFromUUID(uuid, new Callback<Integer>()
|
||||
{
|
||||
@Override
|
||||
public void run(Integer id)
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
addItemToInventoryForOffline(callback, id, item, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
runSync(() -> callback.run(false));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -55,8 +55,9 @@ public class GiveItemCommand extends CommandBase<InventoryManager>
|
||||
}
|
||||
else
|
||||
{
|
||||
Plugin.getClientManager().loadClientByName(playerName, new Runnable()
|
||||
Plugin.runAsync(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
UUID uuid = Plugin.getClientManager().loadUUIDFromDB(playerName);
|
||||
@ -66,9 +67,16 @@ public class GiveItemCommand extends CommandBase<InventoryManager>
|
||||
Plugin.addItemToInventoryForOffline(new Callback<Boolean>()
|
||||
{
|
||||
public void run (Boolean success)
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
UtilPlayer.message(caller, F.main("Item", "You gave " + F.elem(amount + " " + itemName) + " to offline player " + F.name(playerName)));
|
||||
}
|
||||
else
|
||||
{
|
||||
UtilPlayer.message(caller, F.main("Item", "An error occured while trying to give item to " + F.name(playerName) + "!"));
|
||||
}
|
||||
}
|
||||
}, uuid, item.Name, amount);
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user