Switched to storing UUID instead of username, with Offline Mode compatibility

This commit is contained in:
Katrina Swales committed 2015-02-06 00:42:47 +01:00
1 parent ba76cb4c0b
commit 60ded66263
17 files changed
+167 -86

No files matched your search

@@ -53,9 +53,9 @@ public class DarkSteelController {
private int jumpCount;
private int ticksSinceLastJump;
private final Map<String, Boolean> glideActiveMap = new HashMap<String, Boolean>();
private final Map<String, Boolean> speedActiveMap = new HashMap<String, Boolean>();
private final Map<String, Boolean> stepAssistActiveMap = new HashMap<String, Boolean>();
private final Map<UUID, Boolean> glideActiveMap = new HashMap<UUID, Boolean>();
private final Map<UUID, Boolean> speedActiveMap = new HashMap<UUID, Boolean>();
private final Map<UUID, Boolean> stepAssistActiveMap = new HashMap<UUID, Boolean>();
private boolean nightVisionActive = false;
private boolean removeNightvision = false;
@@ -66,13 +66,13 @@ public class DarkSteelController {
}
public void setGlideActive(EntityPlayer player, boolean isGlideActive) {
if(player.getGameProfile().getName() != null) {
glideActiveMap.put(player.getGameProfile().getName(), isGlideActive);
if(player.getGameProfile().getId() != null) {
glideActiveMap.put(player.getGameProfile().getId(), isGlideActive);
}
}
public boolean isGlideActive(EntityPlayer player) {
Boolean isActive = glideActiveMap.get(player.getGameProfile().getName());
Boolean isActive = glideActiveMap.get(player.getGameProfile().getId());
if(isActive == null) {
return false;
}
@@ -80,13 +80,13 @@ public class DarkSteelController {
}
public void setSpeedActive(EntityPlayer player, boolean isSpeedActive) {
if(player.getGameProfile().getName() != null) {
speedActiveMap.put(player.getGameProfile().getName(), isSpeedActive);
if(player.getGameProfile().getId() != null) {
speedActiveMap.put(player.getGameProfile().getId(), isSpeedActive);
}
}
public boolean isSpeedActive(EntityPlayer player) {
Boolean isActive = speedActiveMap.get(player.getGameProfile().getName());
Boolean isActive = speedActiveMap.get(player.getGameProfile().getId());
if(isActive == null) {
return true;
}
@@ -94,13 +94,13 @@ public class DarkSteelController {
}
public void setStepAssistActive(EntityPlayer player, boolean isActive) {
if(player.getGameProfile().getName() != null) {
stepAssistActiveMap.put(player.getGameProfile().getName(), isActive);
if(player.getGameProfile().getId() != null) {
stepAssistActiveMap.put(player.getGameProfile().getId(), isActive);
}
}
public boolean isStepAssistActive(EntityPlayer player) {
Boolean isActive = stepAssistActiveMap.get(player.getGameProfile().getName());
Boolean isActive = stepAssistActiveMap.get(player.getGameProfile().getId());
if(isActive == null) {
return true;
}
@@ -3,7 +3,9 @@ package crazypants.enderio.machine.hypercube;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Random;
import java.util.UUID;
import crazypants.util.PlayerUtil;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
@@ -196,9 +198,9 @@ public class BlockHyperCube extends BlockEio implements IGuiHandler, IResourceTo
return null;
}
String user = null;
UUID user = null;
if(!tag.getBoolean("channelIsPublic")) {
user = tag.getString("channelUser");
user = PlayerUtil.getPlayerUIDUnstable(tag.getString("channelUser"));
}
return new Channel(channelName, user);
@@ -241,7 +243,7 @@ public class BlockHyperCube extends BlockEio implements IGuiHandler, IResourceTo
TileHyperCube cb = (TileHyperCube) te;
cb.setEnergyStored(PowerHandlerUtil.getStoredEnergyForItem(stack));
if(player instanceof EntityPlayerMP) {
cb.setOwner(((EntityPlayerMP) player).getGameProfile().getName());
cb.setOwner(PlayerUtil.getPlayerUUID(((EntityPlayerMP) player).getGameProfile().getName()));
}
cb.setChannel(getChannelFromItem(stack));
setIoOnTransciever(cb, stack);
@@ -5,9 +5,9 @@ import java.util.UUID;
public class Channel {
final String name;
final String user;
final UUID user;
Channel(String name, String uuid) {
Channel(String name, UUID uuid) {
this.name = trim(name);
this.user = uuid;
}
@@ -4,6 +4,7 @@ import java.awt.Color;
import java.awt.Rectangle;
import java.util.List;
import crazypants.util.PlayerUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
@@ -274,7 +275,7 @@ public class GuiHyperCube extends GuiContainerBase {
Channel c;
if(privateButton.isSelected()) {
c = new Channel(newChannelTF.getText(), Minecraft.getMinecraft().thePlayer.getGameProfile().getName());
c = new Channel(newChannelTF.getText(), PlayerUtil.getPlayerUUID(Minecraft.getMinecraft().thePlayer.getGameProfile().getName()));
} else {
c = new Channel(newChannelTF.getText(), null);
}
@@ -14,6 +14,7 @@ import java.util.Map.Entry;
import java.util.Properties;
import java.util.UUID;
import crazypants.util.PlayerUtil;
import org.apache.commons.io.IOUtils;
import crazypants.enderio.Log;
@@ -33,7 +34,7 @@ public class HyperCubeConfig {
private final List<Channel> publicChannels = new ArrayList<Channel>();
private final Map<String, List<Channel>> userChannels = new HashMap<String, List<Channel>>();
private final Map<UUID, List<Channel>> userChannels = new HashMap<UUID, List<Channel>>();
private final File file;
@@ -53,11 +54,11 @@ public class HyperCubeConfig {
publicChannels.addAll(chans);
}
public Map<String, List<Channel>> getUserChannels() {
public Map<UUID, List<Channel>> getUserChannels() {
return userChannels;
}
public void setUserChannels(Map<String, List<Channel>> channels) {
public void setUserChannels(Map<UUID, List<Channel>> channels) {
userChannels.clear();
userChannels.putAll(channels);
}
@@ -68,10 +69,10 @@ public class HyperCubeConfig {
setChannelListProperty(KEY_PUBLIC_CHANNELS, publicChannels);
StringBuilder userListStr = new StringBuilder();
Iterator<Entry<String, List<Channel>>> itr = userChannels.entrySet().iterator();
Iterator<Entry<UUID, List<Channel>>> itr = userChannels.entrySet().iterator();
while (itr.hasNext()) {
Entry<String, List<Channel>> entry = itr.next();
String user = entry.getKey();
Entry<UUID, List<Channel>> entry = itr.next();
UUID user = entry.getKey();
List<Channel> channels = entry.getValue();
if(user != null && channels != null && !channels.isEmpty()) {
@@ -142,17 +143,19 @@ public class HyperCubeConfig {
users.add(user);
}
}
for (String user : users) {
List<Channel> channels = new ArrayList<Channel>();
loadChannelList(user + KEY_USER_CHANNEL, user, channels);
UUID uuid=PlayerUtil.getPlayerUIDUnstable(user);
loadChannelList(user + KEY_USER_CHANNEL, uuid, channels);
if(!channels.isEmpty()) {
userChannels.put(user, channels);
userChannels.put(uuid, channels);
}
}
}
private void loadChannelList(String key, String user, List<Channel> channels) {
private void loadChannelList(String key, UUID user, List<Channel> channels) {
String chans = props.getProperty(key, "");
//chans = chans.replaceAll(DELIM_ESC, DELIM);
String[] chanSplit = chans.split(DELIM);
@@ -24,7 +24,7 @@ public class HyperCubeRegister {
private final List<Channel> publicChannels = new ArrayList<Channel>();
private final List<Channel> publicChannelsRO = Collections.unmodifiableList(publicChannels);
private final Map<String, List<Channel>> userChannels = new HashMap<String, List<Channel>>();
private final Map<UUID, List<Channel>> userChannels = new HashMap<UUID, List<Channel>>();
//private Configuration config;
private HyperCubeConfig conf;
@@ -45,7 +45,7 @@ public class HyperCubeRegister {
userChannels.putAll(conf.getUserChannels());
}
public synchronized List<Channel> getChannelsForUser(String user) {
public synchronized List<Channel> getChannelsForUser(UUID user) {
List<Channel> result = userChannels.get(user);
if(result == null) {
result = new ArrayList<Channel>();
@@ -2,6 +2,7 @@ package crazypants.enderio.machine.hypercube;
import java.util.UUID;
import crazypants.util.PlayerUtil;
import io.netty.buffer.ByteBuf;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.ByteBufUtils;
@@ -44,7 +45,7 @@ public class PacketAddRemoveChannel implements IMessage, IMessageHandler<PacketA
if(!isPublic) {
user = ByteBufUtils.readUTF8String(data);
}
channel = new Channel(name, user == null ? null : user);
channel = new Channel(name, PlayerUtil.getPlayerUIDUnstable(user));
}
@Override
@@ -1,5 +1,6 @@
package crazypants.enderio.machine.hypercube;
import crazypants.util.PlayerUtil;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
@@ -16,16 +17,16 @@ public class PacketChannelList implements IMessage, IMessageHandler<PacketChanne
private boolean isPrivate;
private List<Channel> channels;
private String userId;
private UUID userId;
public PacketChannelList() {
}
public PacketChannelList(EntityPlayer player, boolean isPrivate) {
this(player.getGameProfile().getName(), isPrivate);
this(PlayerUtil.getPlayerUUID(player.getGameProfile().getName()), isPrivate);
}
public PacketChannelList(String uuid, boolean isPrivate) {
public PacketChannelList(UUID uuid, boolean isPrivate) {
this.userId = uuid;
this.isPrivate = isPrivate;
if(isPrivate && uuid == null) {
@@ -50,7 +51,8 @@ public class PacketChannelList implements IMessage, IMessageHandler<PacketChanne
public void toBytes(ByteBuf buffer) {
buffer.writeBoolean(isPrivate);
if(isPrivate) {
ByteBufUtils.writeUTF8String(buffer, userId.toString());
buffer.writeLong(userId.getMostSignificantBits());
buffer.writeLong(userId.getLeastSignificantBits());
}
buffer.writeInt(channels.size());
for (Channel channel : channels) {
@@ -63,7 +65,10 @@ public class PacketChannelList implements IMessage, IMessageHandler<PacketChanne
public void fromBytes(ByteBuf buffer) {
isPrivate = buffer.readBoolean();
if(isPrivate) {
userId = ByteBufUtils.readUTF8String(buffer);
long long1=buffer.readLong();
long long2=buffer.readLong();
userId = new UUID(long1,long2);
} else {
userId = null;
}
@@ -1,5 +1,6 @@
package crazypants.enderio.machine.hypercube;
import crazypants.util.PlayerUtil;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
@@ -71,7 +72,7 @@ public class PacketClientState implements IMessage, IMessageHandler<PacketClient
selectedChannel = null;
if(name != null && name.trim().length() > 0) {
if(user != null && user.trim().length() > 0) {
selectedChannel = new Channel(name, user);
selectedChannel = new Channel(name, PlayerUtil.getPlayerUIDUnstable(user));
} else {
selectedChannel = new Channel(name, null);
}
@@ -1,18 +1,18 @@
package crazypants.enderio.machine.hypercube;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.ListIterator;
import java.util.*;
import com.mojang.authlib.GameProfile;
import crazypants.util.PlayerUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
@@ -114,7 +114,7 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle
private Channel channel = null;
private Channel registeredChannel = null;
private String owner;
private UUID owner;
private boolean init = true;
@@ -183,7 +183,7 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle
HyperCubeRegister.instance.register(this);
}
public void setOwner(String owner) {
public void setOwner(UUID owner) {
this.owner = owner;
}
@@ -252,7 +252,7 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle
return;
} // else is server, do all logic only on the server
// Pay upkeep cost
storedEnergyRF -= ENERGY_UPKEEP;
@@ -260,7 +260,7 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle
storedEnergyRF -= (MILLIBUCKET_TRANSMISSION_COST * milliBucketsTransfered);
// update power status
storedEnergyRF = Math.max(storedEnergyRF, 0);
storedEnergyRF = Math.max(storedEnergyRF, 0);
milliBucketsTransfered = 0;
@@ -293,7 +293,7 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle
boolean stillConnected = canMaintainConnection();
if(isConnected != stillConnected) {
fluidHandlersDirty = true;
isConnected = stillConnected;
isConnected = stillConnected;
requiresClientSync = true;
}
updateFluidHandlers();
@@ -307,10 +307,10 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle
}
requiresClientSync |= prevRedCheck != redstoneCheckPassed;
boolean powerChanged = lastSyncPowerStored != storedEnergyRF && worldObj.getTotalWorldTime() % 21 == 0;
if(powerChanged) {
lastSyncPowerStored = storedEnergyRF;
lastSyncPowerStored = storedEnergyRF;
EnderIO.packetPipeline.sendToAllAround(new PacketStoredPower(this), this);
}
@@ -423,9 +423,9 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle
}
@Override
public int getMaxEnergyRecieved(ForgeDirection dir) {
public int getMaxEnergyRecieved(ForgeDirection dir) {
if(getModeForChannel(SubChannel.POWER) == IoMode.RECIEVE) {
return 0;
return 0;
}
return internalCapacitor.getMaxEnergyReceived();
}
@@ -442,7 +442,7 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle
@Override
public void setEnergyStored(int stored) {
storedEnergyRF = MathHelper.clamp_int(stored, 0, getMaxEnergyStored());
storedEnergyRF = MathHelper.clamp_int(stored, 0, getMaxEnergyStored());
}
@Override
@@ -813,25 +813,25 @@ public class TileHyperCube extends TileEntityEio implements IInternalPowerHandle
@Override
public void readCustomNBT(NBTTagCompound nbtRoot) {
int energy;
int energy;
if(nbtRoot.hasKey("storedEnergy")) {
energy = (int)(nbtRoot.getFloat("storedEnergy") * 10);
} else {
energy = nbtRoot.getInteger("storedEnergyRF");
}
setEnergyStored(energy);
String channelName = nbtRoot.getString("channelName");
String channelUser = nbtRoot.getString("channelUser");
UUID channelUser = PlayerUtil.getPlayerUIDUnstable(nbtRoot.getString("channelUser"));
if(channelName != null && !channelName.isEmpty()) {
channel = new Channel(channelName, channelUser == null || channelUser.isEmpty() ? null : channelUser);
channel = new Channel(channelName,channelUser);
} else {
channel = null;
}
owner = nbtRoot.getString("owner");
owner = PlayerUtil.getPlayerUIDUnstable(nbtRoot.getString("owner"));
for (SubChannel subChannel : SubChannel.values()) {
String key = "subChannel" + subChannel.ordinal();
@@ -1,6 +1,10 @@
package crazypants.enderio.machine.transceiver;
import crazypants.util.PlayerUtil;
import net.minecraft.nbt.NBTTagCompound;
import org.apache.commons.lang3.builder.ToStringBuilder;
import java.util.UUID;
public class Channel {
@@ -10,19 +14,19 @@ public class Channel {
return null;
}
String name = root.getString("name");
String user = null;
UUID user = null;
if(root.hasKey("user")) {
user = root.getString("user");
user = PlayerUtil.getPlayerUIDUnstable(root.getString("user"));
}
ChannelType type = ChannelType.values()[root.getShort("type")];
return new Channel(name, user, type);
}
private final String name;
final String user;
final UUID user;
final ChannelType type;
public Channel(String name, String user, ChannelType type) {
public Channel(String name, UUID user, ChannelType type) {
this.name = trim(name);
this.user = user;
this.type = type;
@@ -38,8 +42,8 @@ public class Channel {
}
root.setString("name", name);
root.setShort("type", (short)type.ordinal());
if(user != null && user.length() > 0) {
root.setString("user", user);
if(user != null ) {
root.setString("user", user.toString());
}
}
@@ -96,7 +100,7 @@ public class Channel {
return type;
}
public String getUser() {
public UUID getUser() {
return user;
}
@@ -1,6 +1,10 @@
package crazypants.enderio.machine.transceiver;
import crazypants.enderio.EnderIO;
import crazypants.enderio.Log;
import crazypants.util.PlayerUtil;
import java.util.UUID;
public class ClientChannelRegister extends ChannelRegister {
@@ -15,8 +19,8 @@ public class ClientChannelRegister extends ChannelRegister {
public void addChannel(Channel channel) {
if(channel == null) {
return;
}
if(channel.getUser() != null && !channel.getUser().equals(EnderIO.proxy.getClientPlayer().getGameProfile().getName())) {
}
if(channel.getUser() != null && !channel.getUser().equals(PlayerUtil.getPlayerUUID(EnderIO.proxy.getClientPlayer().getGameProfile().getName()))) {
return;
}
super.addChannel(channel);
@@ -15,6 +15,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import crazypants.util.PlayerUtil;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.util.ForgeDirection;
@@ -66,7 +67,7 @@ public class ServerChannelRegister extends ChannelRegister {
}
int oridinal = reader.nextInt();
Channel chan = new Channel(name, user, ChannelType.values()[oridinal]);
Channel chan = new Channel(name, PlayerUtil.getPlayerUIDUnstable(user), ChannelType.values()[oridinal]);
instance.addChannel(chan);
reader.endObject();
@@ -144,7 +145,7 @@ public class ServerChannelRegister extends ChannelRegister {
writer.beginObject();
writer.name("name").value(chan.getName());
if(chan.getUser() != null) {
writer.name("user").value(chan.getUser());
writer.name("user").value(chan.getUser().toString());
}
writer.name("type").value(chan.getType().ordinal());
writer.endObject();
@@ -2,6 +2,7 @@ package crazypants.enderio.machine.transceiver.gui;
import java.awt.Color;
import crazypants.util.PlayerUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
@@ -250,7 +251,7 @@ public class ChannelTab implements ITabPanel {
}
Channel c;
if(privateButton.isSelected()) {
c = new Channel(newChannelTF.getText(), Minecraft.getMinecraft().thePlayer.getGameProfile().getName(), type);
c = new Channel(newChannelTF.getText(), PlayerUtil.getPlayerUUID(Minecraft.getMinecraft().thePlayer.getGameProfile().getName()), type);
} else {
c = new Channel(newChannelTF.getText(), null, type);
}
@@ -35,7 +35,7 @@ public interface ITravelAccessable {
void setLabel(String label);
String getPlacedBy();
UUID getPlacedBy();
void setPlacedBy(EntityPlayer player);
@@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import crazypants.util.PlayerUtil;
import ibxm.Player;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -42,9 +44,9 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
private String label;
private String placedBy;
private UUID placedBy;
private List<String> authorisedUsers = new ArrayList<String>();
private List<UUID> authorisedUsers = new ArrayList<UUID>();
@Override
public boolean canBlockBeAccessed(EntityPlayer playerName) {
@@ -52,12 +54,12 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
return true;
}
if(accessMode == AccessMode.PRIVATE) {
return placedBy != null && placedBy.equals(playerName.getGameProfile().getName());
return placedBy != null && placedBy.equals(PlayerUtil.getPlayerUUID(playerName.getGameProfile().getName()));
}
if(placedBy != null && placedBy.equals(playerName.getGameProfile().getName())) {
if(placedBy != null && placedBy.equals(PlayerUtil.getPlayerUUID(playerName.getGameProfile().getName()))) {
return true;
}
return authorisedUsers.contains(playerName.getGameProfile().getName());
return authorisedUsers.contains(PlayerUtil.getPlayerUUID(playerName.getGameProfile().getName()));
}
@Override
@@ -91,13 +93,13 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
@Override
public boolean getRequiresPassword(EntityPlayer username) {
return getAccessMode() != AccessMode.PUBLIC && !canUiBeAccessed(username) && !authorisedUsers.contains(username.getGameProfile().getName());
return getAccessMode() != AccessMode.PUBLIC && !canUiBeAccessed(username) && !authorisedUsers.contains(PlayerUtil.getPlayerUUID(username.getGameProfile().getName()));
}
@Override
public boolean authoriseUser(EntityPlayer username, ItemStack[] password) {
if(checkPassword(password)) {
authorisedUsers.add(username.getGameProfile().getName());
authorisedUsers.add(PlayerUtil.getPlayerUUID(username.getGameProfile().getName()));
return true;
}
return false;
@@ -105,7 +107,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
@Override
public boolean canUiBeAccessed(EntityPlayer playerName) {
return placedBy != null && placedBy.equals(playerName.getGameProfile().getName());
return placedBy != null && placedBy.equals(PlayerUtil.getPlayerUUID(playerName.getGameProfile().getName()));
}
@Override
@@ -113,7 +115,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
if(accessMode != AccessMode.PRIVATE) {
return true;
}
return placedBy != null && placedBy.equals(playerName.getGameProfile().getName());
return placedBy != null && placedBy.equals(PlayerUtil.getPlayerUUID(playerName.getGameProfile().getName()));
}
@Override
@@ -155,7 +157,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
}
@Override
public String getPlacedBy() {
public UUID getPlacedBy() {
return placedBy;
}
@@ -164,7 +166,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
if(player == null || player.getGameProfile() == null) {
this.placedBy = null;
} else {
placedBy = player.getGameProfile().getName();
placedBy = PlayerUtil.getPlayerUUID(player.getGameProfile().getName());
}
}
@@ -212,7 +214,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
//keep behavior the same for blocks placed prior to this update
accessMode = AccessMode.PUBLIC;
}
placedBy = root.getString("placedBy");
placedBy = PlayerUtil.getPlayerUIDUnstable(root.getString("placedBy"));
for (int i = 0; i < password.length; i++) {
if(root.hasKey("password" + i)) {
NBTTagCompound stackRoot = (NBTTagCompound) root.getTag("password" + i);
@@ -229,7 +231,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
if(user != null) {
user = user.trim();
if(user.length() > 0) {
authorisedUsers.add(user);
authorisedUsers.add(PlayerUtil.getPlayerUIDUnstable(user));
}
}
}
@@ -254,7 +256,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
@Override
protected void writeCustomNBT(NBTTagCompound root) {
root.setShort("accessMode", (short) accessMode.ordinal());
if(placedBy != null && !placedBy.trim().isEmpty()) {
if(placedBy != null ) {
root.setString("placedBy", placedBy.toString());
}
for (int i = 0; i < password.length; i++) {
@@ -266,7 +268,7 @@ public class TileTravelAnchor extends TileEntityEio implements ITravelAccessable
}
}
StringBuffer userStr = new StringBuffer();
for (String user : authorisedUsers) {
for (UUID user : authorisedUsers) {
if(user != null) {
userStr.append(user.toString());
userStr.append(",");
@@ -0,0 +1,56 @@
package crazypants.util;
import net.minecraftforge.common.UsernameCache;
import java.util.Map;
import java.util.UUID;
public class PlayerUtil {
public static UUID getPlayerUUID(String username)
{
/*
if(FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(username);
UUID uuid = null;
if (profile == null)
uuid = EntityPlayer.func_146094_a(new GameProfile(null, username));
else
uuid = profile.getId();
return uuid;
}
else
return PacketPlayerUUID.playerUUID.get(username);
*/
for (Map.Entry<UUID,String> entry : UsernameCache.getMap().entrySet())
{
if (entry.getValue().equalsIgnoreCase(username))
{
return entry.getKey();
}
}
return null;
}
public static UUID getPlayerUIDUnstable(String possibleUUID)
{
if(possibleUUID==null || possibleUUID.isEmpty())
return null;
UUID uuid=null;
try
{
uuid=UUID.fromString(possibleUUID);
}
catch(IllegalArgumentException e)
{
uuid=getPlayerUUID(possibleUUID);
}
return uuid;
}
}