Don't find username on the main thread. Not friendly with partial names.
This commit is contained in:
@@ -16,8 +16,11 @@
|
||||
|
||||
package com.lishid.openinv.internal;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface IPlayerDataManager {
|
||||
public Player loadPlayer(String name);
|
||||
public Player loadPlayer(UUID uuid);
|
||||
}
|
||||
|
@@ -101,4 +101,29 @@ public class PlayerDataManager implements IPlayerDataManager {
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.lishid.openinv.internal.IPlayerDataManager#loadPlayer(java.util.UUID)
|
||||
*/
|
||||
@Override
|
||||
public Player loadPlayer(UUID uuid) {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
||||
if (player == null || !player.hasPlayedBefore()) {
|
||||
return null;
|
||||
}
|
||||
GameProfile profile = new GameProfile(uuid, player.getName());
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
// Create an entity to load the player data
|
||||
EntityPlayer entity = new EntityPlayer(server, server.getWorldServer(0), profile, new PlayerInteractManager(server.getWorldServer(0)));
|
||||
|
||||
// Get the bukkit entity
|
||||
Player target = (entity == null) ? null : entity.getBukkitEntity();
|
||||
if (target != null) {
|
||||
// Load data
|
||||
target.loadData();
|
||||
// Return the entity
|
||||
return target;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -82,7 +82,7 @@ public class SpecialPlayerInventory extends PlayerInventory implements ISpecialP
|
||||
public ItemStack[] getContents() {
|
||||
ItemStack[] C = new ItemStack[getSize()];
|
||||
System.arraycopy(items, 0, C, 0, items.length);
|
||||
System.arraycopy(items, 0, C, items.length, armor.length);
|
||||
System.arraycopy(armor, 0, C, items.length, armor.length);
|
||||
return C;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user