Fixed lag when getting game profiles

Fixed runtime deobf
Cleaned a few imports
This commit is contained in:
Chicken-Bones committed 2014-08-27 14:27:19 +10:00
1 parent 5ad106d1a0
commit 3fdb34245d
4 files changed
+73 -21

No files matched your search

+34 -4
View File
@@ -1,15 +1,18 @@
package codechicken.core;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import codechicken.lib.asm.ObfMapping;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.MinecraftServer;
import net.minecraft.command.CommandHandler;
import net.minecraft.inventory.Container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.command.ICommand;
import net.minecraft.util.IChatComponent;
public class ServerUtils extends CommonUtils
@@ -44,14 +47,41 @@ public class ServerUtils extends CommonUtils
player.openContainer.addCraftingToCrafters(player);
}
private static Field field_152661_c;
private static Class<?> c_ProfileEntry;
private static Method func_152668_a;
static {
try {
field_152661_c = ReflectionManager.getField(new ObfMapping("net/minecraft/server/management/PlayerProfileCache", "field_152661_c", "[Ljava/util/Map;"));
c_ProfileEntry = ServerUtils.class.getClassLoader().loadClass("net.minecraft.server.management.PlayerProfileCache$ProfileEntry");
func_152668_a = c_ProfileEntry.getDeclaredMethod(
new ObfMapping("net/minecraft/server/management/PlayerProfileCache$ProfileEntry",
"func_152668_a", "()Lcom/mojang/authlib/GameProfile;").toRuntime().s_name);
func_152668_a.setAccessible(true);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static GameProfile getGameProfile(String username) {
EntityPlayer player = getPlayer(username);
if(player != null)
return player.getGameProfile();
username = username.toLowerCase(Locale.ROOT);
try {//use reflection to bypass saving the game profiles every time we ask the cache for one
Object cacheEntry = ((Map) field_152661_c.get(mc().func_152358_ax())).get(username);
if(cacheEntry != null)
return (GameProfile) func_152668_a.invoke(cacheEntry);
} catch (Exception e) {
throw new RuntimeException(e);
}
return mc().func_152358_ax().func_152655_a(username);
}
public static boolean isPlayerOP(String username) {
GameProfile prof = getGameProfile(username);
if(prof == null) return false;
return mc().getConfigurationManager().func_152596_g(getGameProfile(username));
return prof != null && mc().getConfigurationManager().func_152596_g(prof);
}
public static boolean isPlayerOwner(String username) {