Don't find username on the main thread. Not friendly with partial names.

This commit is contained in:
Jikoo
2014-12-01 16:11:20 -05:00
parent 2a66b2e81b
commit 21cd1926ae
6 changed files with 127 additions and 52 deletions

View File

@@ -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);
}

View File

@@ -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;
}
}

View File

@@ -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;
}