Move SoulNetwork to UUID system

*Should* work correctly. As for all major changes, needs to be
thoroughly tested.
This commit is contained in:
Nick 2015-12-28 20:13:11 -08:00
parent 8edb8a45e6
commit 24058d7350
14 changed files with 112 additions and 49 deletions

View file

@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.UsernameCache;
import net.minecraftforge.common.util.FakePlayer;
import java.util.UUID;
@ -17,7 +18,7 @@ public class PlayerHelper {
private static final Pattern FAKE_PLAYER_PATTERN = Pattern.compile("^(?:\\[.*\\])|(?:ComputerCraft)$");
public static String getUsernameFromPlayer(EntityPlayer player) {
return player.getGameProfile().getName();
return UsernameCache.getLastKnownUsername(getUUIDFromPlayer(player));
}
public static EntityPlayer getPlayerFromUsername(String username) {
@ -27,10 +28,32 @@ public class PlayerHelper {
return MinecraftServer.getServer().getConfigurationManager().getPlayerByUsername(username);
}
public static EntityPlayer getPlayerFromUUID(String uuid) {
return getPlayerFromUsername(getUsernameFromUUID(uuid));
}
public static EntityPlayer getPlayerFromUUID(UUID uuid) {
return getPlayerFromUsername(getUsernameFromUUID(uuid));
}
public static UUID getUUIDFromPlayer(EntityPlayer player) {
return player.getGameProfile().getId();
}
public static String getUsernameFromUUID(String uuid) {
return UsernameCache.getLastKnownUsername(UUID.fromString(uuid));
}
public static String getUsernameFromUUID(UUID uuid) {
return UsernameCache.getLastKnownUsername(uuid);
}
public static String getUsernameFromStack(ItemStack stack) {
stack = NBTHelper.checkNBT(stack);
return PlayerHelper.getUsernameFromUUID(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID));
}
public static boolean isFakePlayer(EntityPlayer player) {
return player instanceof FakePlayer || FAKE_PLAYER_PATTERN.matcher(getUsernameFromPlayer(player)).matches();
}
@ -38,8 +61,8 @@ public class PlayerHelper {
public static void causeNauseaToPlayer(ItemStack stack) {
stack = NBTHelper.checkNBT(stack);
if (!Strings.isNullOrEmpty(stack.getTagCompound().getString(Constants.NBT.OWNER_NAME)))
causeNauseaToPlayer(stack.getTagCompound().getString(Constants.NBT.OWNER_NAME));
if (!Strings.isNullOrEmpty(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID)))
causeNauseaToPlayer(stack.getTagCompound().getString(Constants.NBT.OWNER_UUID));
}
public static void causeNauseaToPlayer(String ownerName) {