diff options
Diffstat (limited to 'src/main/java/org')
12 files changed, 403 insertions, 172 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftBanEntry.java b/src/main/java/org/bukkit/craftbukkit/CraftIpBanEntry.java index 39ece748..583f9ab6 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftBanEntry.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftIpBanEntry.java @@ -1,21 +1,21 @@ package org.bukkit.craftbukkit; -import java.util.Date; +import net.minecraft.server.IpBanEntry; +import net.minecraft.server.IpBanList; -import net.minecraft.server.BanEntry; -import net.minecraft.server.BanList; +import java.util.Date; -public final class CraftBanEntry implements org.bukkit.BanEntry { - private final BanList list; - private final String name; +public final class CraftIpBanEntry implements org.bukkit.BanEntry { + private final IpBanList list; + private final String target; private Date created; private String source; private Date expiration; private String reason; - public CraftBanEntry(BanEntry entry, BanList list) { + public CraftIpBanEntry(String target, IpBanEntry entry, IpBanList list) { this.list = list; - this.name = entry.getName(); + this.target = target; this.created = entry.getCreated() != null ? new Date(entry.getCreated().getTime()) : null; this.source = entry.getSource(); this.expiration = entry.getExpires() != null ? new Date(entry.getExpires().getTime()) : null; @@ -24,7 +24,7 @@ public final class CraftBanEntry implements org.bukkit.BanEntry { @Override public String getTarget() { - return this.name; + return this.target; } @Override @@ -73,14 +73,8 @@ public final class CraftBanEntry implements org.bukkit.BanEntry { @Override public void save() { - BanEntry entry = new BanEntry(this.name); - entry.setCreated(this.created); - entry.setSource(this.source); - entry.setExpires(this.expiration); - entry.setReason(this.reason); - + IpBanEntry entry = new IpBanEntry(target, this.created, this.source, this.expiration, this.reason); this.list.add(entry); this.list.save(); } - } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftBanList.java b/src/main/java/org/bukkit/craftbukkit/CraftIpBanList.java index e4abd053..75dc31bb 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftBanList.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftIpBanList.java @@ -1,21 +1,20 @@ package org.bukkit.craftbukkit; -import java.util.Collection; +import java.net.InetSocketAddress; import java.util.Date; import java.util.Set; +import net.minecraft.server.IpBanEntry; +import net.minecraft.server.IpBanList; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.Validate; import com.google.common.collect.ImmutableSet; -import net.minecraft.server.BanEntry; -import net.minecraft.server.BanList; +public class CraftIpBanList implements org.bukkit.BanList { + private final IpBanList list; -public class CraftBanList implements org.bukkit.BanList { - private final BanList list; - - public CraftBanList(BanList list){ + public CraftIpBanList(IpBanList list) { this.list = list; } @@ -23,33 +22,34 @@ public class CraftBanList implements org.bukkit.BanList { public org.bukkit.BanEntry getBanEntry(String target) { Validate.notNull(target, "Target cannot be null"); - if (!list.getEntries().containsKey(target)) { + IpBanEntry entry = (IpBanEntry) list.get(target); + if (entry == null) { return null; } - return new CraftBanEntry((BanEntry) list.getEntries().get(target), list); + return new CraftIpBanEntry(target, entry, list); } @Override public org.bukkit.BanEntry addBan(String target, String reason, Date expires, String source) { Validate.notNull(target, "Ban target cannot be null"); - BanEntry entry = new BanEntry(target); - entry.setSource(StringUtils.isBlank(source) ? entry.getSource() : source); // Use default if null/empty - entry.setExpires(expires); // Null values are interpreted as "forever" - entry.setReason(StringUtils.isBlank(reason) ? entry.getReason() : reason); // Use default if null/empty + IpBanEntry entry = new IpBanEntry(target, new Date(), + StringUtils.isBlank(source) ? null : source, expires, + StringUtils.isBlank(reason) ? null : reason); list.add(entry); list.save(); - return new CraftBanEntry(entry, list); + return new CraftIpBanEntry(target, entry, list); } @Override public Set<org.bukkit.BanEntry> getBanEntries() { ImmutableSet.Builder<org.bukkit.BanEntry> builder = ImmutableSet.builder(); - for (BanEntry entry : (Collection<BanEntry>) list.getEntries().values()) { - builder.add(new CraftBanEntry(entry, list)); + for (String target : list.getEntries()) { + builder.add(new CraftIpBanEntry(target, (IpBanEntry) list.get(target), list)); } + return builder.build(); } @@ -57,7 +57,7 @@ public class CraftBanList implements org.bukkit.BanList { public boolean isBanned(String target) { Validate.notNull(target, "Target cannot be null"); - return list.isBanned(target); + return list.isBanned(InetSocketAddress.createUnresolved(target, 0)); } @Override @@ -66,5 +66,4 @@ public class CraftBanList implements org.bukkit.BanList { list.remove(target); } - } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java index 24b00662..bec41346 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java @@ -6,11 +6,11 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import net.minecraft.server.BanEntry; import net.minecraft.server.EntityPlayer; import net.minecraft.server.NBTTagCompound; import net.minecraft.server.WorldNBTStorage; +import net.minecraft.util.com.mojang.authlib.GameProfile; import org.bukkit.BanList; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -24,14 +24,19 @@ import org.bukkit.plugin.Plugin; @SerializableAs("Player") public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializable { - private final String name; + private final GameProfile profile; private final CraftServer server; private final WorldNBTStorage storage; - protected CraftOfflinePlayer(CraftServer server, String name) { + protected CraftOfflinePlayer(CraftServer server, GameProfile profile) { this.server = server; - this.name = name; + this.profile = profile; this.storage = (WorldNBTStorage) (server.console.worlds.get(0).getDataManager()); + + } + + public GameProfile getProfile() { + return profile; } public boolean isOnline() { @@ -39,86 +44,96 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa } public String getName() { - return name; - } - - // TODO: In 1.7.6+ OfflinePlayer lookup should be by UUID and store it like it does the name now - public UUID getUniqueId() { - NBTTagCompound data = getData(); - if (data == null) { - return null; + Player player = getPlayer(); + if (player != null) { + return player.getName(); } - if (data.hasKeyOfType("UUIDMost", 4) && data.hasKeyOfType("UUIDLeast", 4)) { - return new UUID(data.getLong("UUIDMost"), data.getLong("UUIDLeast")); + NBTTagCompound data = getBukkitData(); + + if (data != null) { + if (data.hasKey("lastKnownName")) { + return data.getString("lastKnownName"); + } } return null; } + public UUID getUniqueId() { + return profile.getId(); + } + public Server getServer() { return server; } public boolean isOp() { - return server.getHandle().isOp(getName().toLowerCase()); + return server.getHandle().isOp(profile); } public void setOp(boolean value) { - if (value == isOp()) return; + if (value == isOp()) { + return; + } if (value) { - server.getHandle().addOp(getName().toLowerCase()); + server.getHandle().addOp(profile); } else { - server.getHandle().removeOp(getName().toLowerCase()); + server.getHandle().removeOp(profile); } } public boolean isBanned() { - return server.getBanList(BanList.Type.NAME).isBanned(getName()); + return server.getBanList(BanList.Type.UUID).isBanned(getUniqueId().toString()); } public void setBanned(boolean value) { if (value) { - server.getBanList(BanList.Type.NAME).addBan(getName(), null, null, null); + server.getBanList(BanList.Type.UUID).addBan(getUniqueId().toString(), null, null, null); } else { - server.getBanList(BanList.Type.NAME).pardon(getName()); + server.getBanList(BanList.Type.UUID).pardon(getUniqueId().toString()); } } public boolean isWhitelisted() { - return server.getHandle().getWhitelisted().contains(name.toLowerCase()); + return server.getHandle().isWhitelisted(profile); } public void setWhitelisted(boolean value) { if (value) { - server.getHandle().addWhitelist(name.toLowerCase()); + server.getHandle().addWhitelist(profile); } else { - server.getHandle().removeWhitelist(name.toLowerCase()); + server.getHandle().removeWhitelist(profile); } } public Map<String, Object> serialize() { Map<String, Object> result = new LinkedHashMap<String, Object>(); - result.put("name", name); + result.put("UUID", profile.getId().toString()); return result; } public static OfflinePlayer deserialize(Map<String, Object> args) { - return Bukkit.getServer().getOfflinePlayer((String) args.get("name")); + // Backwards comparability + if (args.get("name") != null) { + return Bukkit.getServer().getOfflinePlayer((String) args.get("name")); + } + + return Bukkit.getServer().getOfflinePlayer(UUID.fromString((String) args.get("UUID"))); } @Override public String toString() { - return getClass().getSimpleName() + "[name=" + name + "]"; + return getClass().getSimpleName() + "[UUID=" + profile.getId() + "]"; } public Player getPlayer() { for (Object obj : server.getHandle().players) { EntityPlayer player = (EntityPlayer) obj; - if (player.getName().equalsIgnoreCase(getName())) { + if (player.getUniqueID().equals(getUniqueId())) { return (player.playerConnection != null) ? player.playerConnection.getPlayer() : null; } } @@ -128,28 +143,27 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa @Override public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (!(obj instanceof OfflinePlayer)) { + if (obj == null || !(obj instanceof OfflinePlayer)) { return false; } + OfflinePlayer other = (OfflinePlayer) obj; - if ((this.getName() == null) || (other.getName() == null)) { + if ((this.getUniqueId() == null) || (other.getUniqueId() == null)) { return false; } - return this.getName().equalsIgnoreCase(other.getName()); + + return this.getUniqueId().equals(other.getUniqueId()); } @Override public int hashCode() { int hash = 5; - hash = 97 * hash + (this.getName() != null ? this.getName().toLowerCase().hashCode() : 0); + hash = 97 * hash + (this.getUniqueId() != null ? this.getUniqueId().toString().hashCode() : 0); return hash; } private NBTTagCompound getData() { - return storage.getPlayerData(getName()); + return storage.getPlayerData(getUniqueId().toString()); } private NBTTagCompound getBukkitData() { @@ -166,7 +180,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa } private File getDataFile() { - return new File(storage.getPlayerDir(), name + ".dat"); + return new File(storage.getPlayerDir(), getUniqueId() + ".dat"); } public long getFirstPlayed() { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftProfileBanEntry.java b/src/main/java/org/bukkit/craftbukkit/CraftProfileBanEntry.java new file mode 100644 index 00000000..499c5aac --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftProfileBanEntry.java @@ -0,0 +1,81 @@ +package org.bukkit.craftbukkit; + +import net.minecraft.server.GameProfileBanEntry; +import net.minecraft.server.GameProfileBanList; +import net.minecraft.util.com.mojang.authlib.GameProfile; + +import java.util.Date; + +public final class CraftProfileBanEntry implements org.bukkit.BanEntry { + private final GameProfileBanList list; + private final GameProfile profile; + private Date created; + private String source; + private Date expiration; + private String reason; + + public CraftProfileBanEntry(GameProfile profile, GameProfileBanEntry entry, GameProfileBanList list) { + this.list = list; + this.profile = profile; + this.created = entry.getCreated() != null ? new Date(entry.getCreated().getTime()) : null; + this.source = entry.getSource(); + this.expiration = entry.getExpires() != null ? new Date(entry.getExpires().getTime()) : null; + this.reason = entry.getReason(); + } + + @Override + public String getTarget() { + return this.profile.getId().toString(); + } + + @Override + public Date getCreated() { + return this.created == null ? null : (Date) this.created.clone(); + } + + @Override + public void setCreated(Date created) { + this.created = created; + } + + @Override + public String getSource() { + return this.source; + } + + @Override + public void setSource(String source) { + this.source = source; + } + + @Override + public Date getExpiration() { + return this.expiration == null ? null : (Date) this.expiration.clone(); + } + + @Override + public void setExpiration(Date expiration) { + if (expiration != null && expiration.getTime() == new Date(0, 0, 0, 0, 0, 0).getTime()) { + expiration = null; // Forces "forever" + } + + this.expiration = expiration; + } + + @Override + public String getReason() { + return this.reason; + } + + @Override + public void setReason(String reason) { + this.reason = reason; + } + + @Override + public void save() { + GameProfileBanEntry entry = new GameProfileBanEntry(profile, this.created, this.source, this.expiration, this.reason); + this.list.add(entry); + this.list.save(); + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftProfileBanList.java b/src/main/java/org/bukkit/craftbukkit/CraftProfileBanList.java new file mode 100644 index 00000000..c077daa1 --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftProfileBanList.java @@ -0,0 +1,86 @@ +package org.bukkit.craftbukkit; + +import java.util.Date; +import java.util.Set; +import java.util.UUID; + +import net.minecraft.server.GameProfileBanEntry; +import net.minecraft.server.GameProfileBanList; +import net.minecraft.util.com.mojang.authlib.GameProfile; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang.Validate; + +import com.google.common.collect.ImmutableSet; + +public class CraftProfileBanList implements org.bukkit.BanList { + private final GameProfileBanList list; + + public CraftProfileBanList(GameProfileBanList list){ + this.list = list; + } + + @Override + public org.bukkit.BanEntry getBanEntry(String target) { + Validate.notNull(target, "Target cannot be null"); + + UUID id = UUID.fromString(target); + GameProfile profile = new GameProfile(id, null); + + GameProfileBanEntry entry = (GameProfileBanEntry) list.get(profile); + if (entry == null) { + return null; + } + + return new CraftProfileBanEntry(profile, entry, list); + } + + @Override + public org.bukkit.BanEntry addBan(String target, String reason, Date expires, String source) { + Validate.notNull(target, "Ban target cannot be null"); + + UUID id = UUID.fromString(target); + GameProfile profile = new GameProfile(id, null); + + GameProfileBanEntry entry = new GameProfileBanEntry(profile, new Date(), + StringUtils.isBlank(source) ? null : source, expires, + StringUtils.isBlank(reason) ? null : reason); + + list.add(entry); + list.save(); + return new CraftProfileBanEntry(profile, entry, list); + } + + @Override + public Set<org.bukkit.BanEntry> getBanEntries() { + ImmutableSet.Builder<org.bukkit.BanEntry> builder = ImmutableSet.builder(); + for (String target : list.getEntries()) { + UUID id = UUID.fromString(target); + GameProfile profile = new GameProfile(id, null); + + builder.add(new CraftProfileBanEntry(profile, (GameProfileBanEntry) list.get(profile), list)); + } + + return builder.build(); + } + + @Override + public boolean isBanned(String target) { + Validate.notNull(target, "Target cannot be null"); + + UUID id = UUID.fromString(target); + GameProfile profile = new GameProfile(id, null); + + return list.isBanned(profile); + } + + @Override + public void pardon(String target) { + Validate.notNull(target, "Target cannot be null"); + + UUID id = UUID.fromString(target); + GameProfile profile = new GameProfile(id, null); + + list.remove(profile); + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 2b5aa31a..748d887d 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -15,7 +15,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; @@ -92,6 +91,7 @@ import net.minecraft.server.WorldServer; import net.minecraft.server.WorldSettings; import net.minecraft.server.WorldType; import net.minecraft.util.com.google.common.base.Charsets; +import net.minecraft.util.com.mojang.authlib.GameProfile; import net.minecraft.util.io.netty.buffer.ByteBuf; import net.minecraft.util.io.netty.buffer.ByteBufOutputStream; import net.minecraft.util.io.netty.buffer.Unpooled; @@ -204,7 +204,7 @@ public final class CraftServer implements Server { private YamlConfiguration configuration; private YamlConfiguration commandsConfiguration; private final Yaml yaml = new Yaml(new SafeConstructor()); - private final Map<String, OfflinePlayer> offlinePlayers = new MapMaker().softValues().makeMap(); + private final Map<java.util.UUID, OfflinePlayer> offlinePlayers = new MapMaker().softValues().makeMap(); private final AutoUpdater updater; private final EntityMetadataStore entityMetadata = new EntityMetadataStore(); private final PlayerMetadataStore playerMetadata = new PlayerMetadataStore(); @@ -514,7 +514,7 @@ public final class CraftServer implements Server { } // TODO: In 1.7.6+ this should use the server's UUID->EntityPlayer map - public Player getPlayer(UUID id) { + public Player getPlayer(java.util.UUID id) { for (Player player : getOnlinePlayers()) { if (player.getUniqueId().equals(id)) { return player; @@ -734,7 +734,7 @@ public final class CraftServer implements Server { loadIcon(); playerList.getIPBans().load(); - playerList.getNameBans().load(); + playerList.getProfileBans().load(); for (WorldServer world : console.worlds) { world.difficulty = difficulty; @@ -1013,7 +1013,7 @@ public final class CraftServer implements Server { return worlds.get(name.toLowerCase()); } - public World getWorld(UUID uid) { + public World getWorld(java.util.UUID uid) { for (World world : worlds.values()) { if (world.getUID().equals(uid)) { return world; @@ -1258,54 +1258,44 @@ public final class CraftServer implements Server { } public OfflinePlayer getOfflinePlayer(String name) { - return getOfflinePlayer(name, true); - } - - public OfflinePlayer getOfflinePlayer(String name, boolean search) { Validate.notNull(name, "Name cannot be null"); - OfflinePlayer result = getPlayerExact(name); - String lname = name.toLowerCase(); + // This is potentially blocking :( + GameProfile profile = MinecraftServer.getServer().getUserCache().a(name); + if (profile == null) { + // Make an OfflinePlayer using an offline mode UUID since the name has no profile + return getOfflinePlayer(new GameProfile(java.util.UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), name)); + } - if (result == null) { - result = offlinePlayers.get(lname); + return getOfflinePlayer(profile.getId()); + } - if (result == null) { - if (search) { - WorldNBTStorage storage = (WorldNBTStorage) console.worlds.get(0).getDataManager(); - for (String dat : storage.getPlayerDir().list(new DatFileFilter())) { - String datName = dat.substring(0, dat.length() - 4); - if (datName.equalsIgnoreCase(name)) { - name = datName; - break; - } - } - } + public OfflinePlayer getOfflinePlayer(java.util.UUID id) { + Validate.notNull(id, "UUID cannot be null"); - result = new CraftOfflinePlayer(this, name); - offlinePlayers.put(lname, result); + OfflinePlayer result = getPlayer(id); + if (result == null) { + result = offlinePlayers.get(id); + if (result == null) { + result = new CraftOfflinePlayer(this, new GameProfile(id, null)); + offlinePlayers.put(id, result); } } else { - offlinePlayers.remove(lname); + offlinePlayers.remove(id); } return result; } - // TODO: In 1.7.6+ this should just lookup the UUID-based player data filename - public OfflinePlayer getOfflinePlayer(UUID id) { - String name = MojangNameLookup.lookupName(id); - if (name == null) { - // This is completely wrong - name = "InvalidUUID"; - } - - return getOfflinePlayer(name); + public OfflinePlayer getOfflinePlayer(GameProfile profile) { + OfflinePlayer player = new CraftOfflinePlayer(this, profile); + offlinePlayers.put(profile.getId(), player); + return player; } @SuppressWarnings("unchecked") public Set<String> getIPBans() { - return new HashSet<String>(playerList.getIPBans().getEntries().keySet()); + return new HashSet<String>(Arrays.asList(playerList.getIPBans().getEntries())); } public void banIP(String address) { @@ -1323,28 +1313,34 @@ public final class CraftServer implements Server { public Set<OfflinePlayer> getBannedPlayers() { Set<OfflinePlayer> result = new HashSet<OfflinePlayer>(); - for (Object name : playerList.getNameBans().getEntries().keySet()) { - result.add(getOfflinePlayer((String) name)); + for (String id : playerList.getProfileBans().getEntries()) { + try { + result.add(getOfflinePlayer(java.util.UUID.fromString(id))); + } catch (IllegalArgumentException ex) { + // This shouldn't happen + } } return result; } @Override - public BanList getBanList(BanList.Type type){ + public BanList getBanList(BanList.Type type) { Validate.notNull(type, "Type cannot be null"); switch(type){ case IP: - return new CraftBanList(playerList.getIPBans()); + return new CraftIpBanList(playerList.getIPBans()); case NAME: - default: // Fall through as a player name list for safety - return new CraftBanList(playerList.getNameBans()); + return null; + case UUID: + default: + return new CraftProfileBanList(playerList.getProfileBans()); } } public void setWhitelist(boolean value) { - playerList.hasWhitelist = value; + playerList.setHasWhitelist(value); console.getPropertyManager().a("white-list", value); } @@ -1364,8 +1360,12 @@ public final class CraftServer implements Server { public Set<OfflinePlayer> getOperators() { Set<OfflinePlayer> result = new HashSet<OfflinePlayer>(); - for (Object name : playerList.getOPs()) { - result.add(getOfflinePlayer((String) name)); + for (String id : playerList.getOPs().getEntries()) { + try { + result.add(getOfflinePlayer(java.util.UUID.fromString(id))); + } catch (IllegalArgumentException ex) { + // This shouldn't ever happen + } } return result; @@ -1442,8 +1442,13 @@ public final class CraftServer implements Server { Set<OfflinePlayer> players = new HashSet<OfflinePlayer>(); for (String file : files) { - players.add(getOfflinePlayer(file.substring(0, file.length() - 4), false)); + try { + players.add(getOfflinePlayer(java.util.UUID.fromString(file.substring(0, file.length() - 4)))); + } catch (IllegalArgumentException ex) { + // Who knows what is in this directory, just ignore invalid files + } } + players.addAll(Arrays.asList(getOnlinePlayers())); return players.toArray(new OfflinePlayer[players.size()]); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index 5fc334a9..7dded2b4 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -10,6 +10,7 @@ import net.minecraft.server.BlockCocoa; import net.minecraft.server.BlockRedstoneWire; import net.minecraft.server.Blocks; import net.minecraft.server.EnumSkyBlock; +import net.minecraft.server.GameProfileSerializer; import net.minecraft.server.Item; import net.minecraft.server.NBTTagCompound; import net.minecraft.server.TileEntitySkull; @@ -423,9 +424,12 @@ public class CraftBlock implements Block { net.minecraft.server.ItemStack nmsStack = new net.minecraft.server.ItemStack(item, 1, block.getDropData(chunk.getHandle().world, x, y, z)); TileEntitySkull tileentityskull = (TileEntitySkull) chunk.getHandle().world.getTileEntity(x, y, z); - if (tileentityskull.getSkullType() == 3 && tileentityskull.getExtraType() != null && tileentityskull.getExtraType().length() > 0) { + if (tileentityskull.getSkullType() == 3 && tileentityskull.getGameProfile() != null) { nmsStack.setTag(new NBTTagCompound()); - nmsStack.getTag().setString("SkullOwner", tileentityskull.getExtraType()); + NBTTagCompound nbttagcompound = new NBTTagCompound(); + + GameProfileSerializer.a(nbttagcompound, tileentityskull.getGameProfile()); + nmsStack.getTag().set("SkullOwner", nbttagcompound); } drops.add(CraftItemStack.asBukkitCopy(nmsStack)); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java index 4e121a3d..d5447605 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java @@ -1,28 +1,30 @@ package org.bukkit.craftbukkit.block; -import com.google.common.base.Strings; - +import net.minecraft.server.MinecraftServer; import net.minecraft.server.TileEntitySkull; +import net.minecraft.util.com.mojang.authlib.GameProfile; +import org.bukkit.OfflinePlayer; import org.bukkit.SkullType; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Skull; +import org.bukkit.craftbukkit.CraftOfflinePlayer; import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.entity.CraftPlayer; public class CraftSkull extends CraftBlockState implements Skull { private final TileEntitySkull skull; - private String player; + private GameProfile profile; private SkullType skullType; private byte rotation; - private final int MAX_OWNER_LENGTH = 16; public CraftSkull(final Block block) { super(block); CraftWorld world = (CraftWorld) block.getWorld(); skull = (TileEntitySkull) world.getTileEntityAt(getX(), getY(), getZ()); - player = skull.getExtraType(); + profile = skull.getGameProfile(); skullType = getSkullType(skull.getSkullType()); rotation = (byte) skull.getRotation(); } @@ -140,23 +142,36 @@ public class CraftSkull extends CraftBlockState implements Skull { } public boolean hasOwner() { - return !Strings.isNullOrEmpty(player); + return profile != null; } public String getOwner() { - return player; + return profile.getName(); } public boolean setOwner(String name) { - if (name == null || name.length() > MAX_OWNER_LENGTH) { + return false; + } + + public OfflinePlayer getPlayer() { + return MinecraftServer.getServer().server.getOfflinePlayer(profile); + } + + public boolean setPlayer(OfflinePlayer player) { + GameProfile profile; + if (player instanceof CraftPlayer) { + profile = ((CraftPlayer) player).getProfile(); + } else if (player instanceof CraftOfflinePlayer) { + profile = ((CraftOfflinePlayer) player).getProfile(); + } else { return false; } - player = name; - if (skullType != SkullType.PLAYER) { - skullType = SkullType.PLAYER; + if (profile == null) { + return false; } + this.profile = profile; return true; } @@ -176,7 +191,7 @@ public class CraftSkull extends CraftBlockState implements Skull { this.skullType = skullType; if (skullType != SkullType.PLAYER) { - player = ""; + profile = null; } } @@ -185,7 +200,8 @@ public class CraftSkull extends CraftBlockState implements Skull { boolean result = super.update(force, applyPhysics); if (result) { - skull.setSkullType(getSkullType(skullType), player); + skull.setSkullType(getSkullType(skullType)); + skull.setGameProfile(profile); skull.setRotation(rotation); skull.update(); } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHorse.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHorse.java index bca7a2d6..8522cad0 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHorse.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHorse.java @@ -9,6 +9,8 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Horse; import org.bukkit.inventory.HorseInventory; +import java.util.UUID; + public class CraftHorse extends CraftAnimals implements Horse { public CraftHorse(CraftServer server, EntityHorse entity) { @@ -97,28 +99,36 @@ public class CraftHorse extends CraftAnimals implements Horse { @Override public AnimalTamer getOwner() { - if (getOwnerName() == null || "".equals(getOwnerName())) return null; - return getServer().getOfflinePlayer(getOwnerName()); + if (getOwnerUUID() == null) return null; + return getServer().getOfflinePlayer(getOwnerUUID()); } @Override public void setOwner(AnimalTamer owner) { - if (owner != null && !"".equals(owner.getName())) { + if (owner != null) { setTamed(true); getHandle().setPathEntity(null); - setOwnerName(owner.getName()); + setOwnerUUID(owner.getUniqueId()); } else { setTamed(false); - setOwnerName(""); + setOwnerUUID(null); } } - public String getOwnerName() { - return getHandle().getOwnerName(); + public UUID getOwnerUUID() { + try { + return UUID.fromString(getHandle().getOwnerUUID()); + } catch (IllegalArgumentException ex) { + return null; + } } - public void setOwnerName(String name) { - getHandle().setOwnerName(name); + public void setOwnerUUID(UUID uuid) { + if (uuid == null) { + getHandle().setOwnerUUID(""); + } else { + getHandle().setOwnerUUID(uuid.toString()); + } } public HorseInventory getInventory() { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 17c16dc6..b5a54c85 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -13,11 +13,13 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; import net.minecraft.server.*; +import net.minecraft.util.com.mojang.authlib.GameProfile; import org.apache.commons.lang.Validate; import org.apache.commons.lang.NotImplementedException; import org.bukkit.*; @@ -64,7 +66,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { private boolean hasPlayedBefore = false; private final ConversationTracker conversationTracker = new ConversationTracker(); private final Set<String> channels = new HashSet<String>(); - private final Map<String, Player> hiddenPlayers = new MapMaker().softValues().makeMap(); + private final Set<UUID> hiddenPlayers = new HashSet<UUID>(); private int hash = 0; private double health = 20; private boolean scaledHealth = false; @@ -76,9 +78,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player { firstPlayed = System.currentTimeMillis(); } + public GameProfile getProfile() { + return getHandle().getProfile(); + } + @Override public boolean isOp() { - return server.getHandle().isOp(getName()); + return server.getHandle().isOp(getProfile()); } @Override @@ -86,9 +92,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player { if (value == isOp()) return; if (value) { - server.getHandle().addOp(getName()); + server.getHandle().addOp(getProfile()); } else { - server.getHandle().removeOp(getName()); + server.getHandle().removeOp(getProfile()); } perm.recalculatePermissions(); @@ -732,29 +738,29 @@ public class CraftPlayer extends CraftHumanEntity implements Player { @Override public boolean isBanned() { - return server.getBanList(BanList.Type.NAME).isBanned(getName()); + return server.getBanList(BanList.Type.UUID).isBanned(getUniqueId().toString()); } @Override public void setBanned(boolean value) { if (value) { - server.getBanList(BanList.Type.NAME).addBan(getName(), null, null, null); + server.getBanList(BanList.Type.UUID).addBan(getUniqueId().toString(), null, null, null); } else { - server.getBanList(BanList.Type.NAME).pardon(getName()); + server.getBanList(BanList.Type.UUID).pardon(getUniqueId().toString()); } } @Override public boolean isWhitelisted() { - return server.getHandle().getWhitelisted().contains(getName().toLowerCase()); + return server.getHandle().isWhitelisted(getProfile()); } @Override public void setWhitelisted(boolean value) { if (value) { - server.getHandle().addWhitelist(getName().toLowerCase()); + server.getHandle().addWhitelist(getProfile()); } else { - server.getHandle().removeWhitelist(getName().toLowerCase()); + server.getHandle().removeWhitelist(getProfile()); } } @@ -872,8 +878,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player { Validate.notNull(player, "hidden player cannot be null"); if (getHandle().playerConnection == null) return; if (equals(player)) return; - if (hiddenPlayers.containsKey(player.getName())) return; - hiddenPlayers.put(player.getName(), player); + if (hiddenPlayers.contains(player.getUniqueId())) return; + hiddenPlayers.add(player.getUniqueId()); //remove this player from the hidden player's EntityTrackerEntry EntityTracker tracker = ((WorldServer) entity.world).tracker; @@ -891,8 +897,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player { Validate.notNull(player, "shown player cannot be null"); if (getHandle().playerConnection == null) return; if (equals(player)) return; - if (!hiddenPlayers.containsKey(player.getName())) return; - hiddenPlayers.remove(player.getName()); + if (!hiddenPlayers.contains(player.getUniqueId())) return; + hiddenPlayers.remove(player.getUniqueId()); EntityTracker tracker = ((WorldServer) entity.world).tracker; EntityPlayer other = ((CraftPlayer) player).getHandle(); @@ -904,8 +910,12 @@ public class CraftPlayer extends CraftHumanEntity implements Player { getHandle().playerConnection.sendPacket(new PacketPlayOutPlayerInfo(player.getPlayerListName(), true, getHandle().ping)); } + public void removeDisconnectingPlayer(Player player) { + hiddenPlayers.remove(player.getUniqueId()); + } + public boolean canSee(Player player) { - return !hiddenPlayers.containsKey(player.getName()); + return !hiddenPlayers.contains(player.getUniqueId()); } public Map<String, Object> serialize() { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftTameableAnimal.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftTameableAnimal.java index f62d8bcb..d4bf3a0e 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftTameableAnimal.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftTameableAnimal.java @@ -6,6 +6,8 @@ import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.Creature; import org.bukkit.entity.Tameable; +import java.util.UUID; + public class CraftTameableAnimal extends CraftAnimals implements Tameable, Creature { public CraftTameableAnimal(CraftServer server, EntityTameableAnimal entity) { super(server, entity); @@ -16,21 +18,35 @@ public class CraftTameableAnimal extends CraftAnimals implements Tameable, Creat return (EntityTameableAnimal)super.getHandle(); } + public UUID getOwnerUUID() { + try { + return UUID.fromString(getHandle().getOwnerUUID()); + } catch (IllegalArgumentException ex) { + return null; + } + } + + public void setOwnerUUID(UUID uuid) { + if (uuid == null) { + getHandle().setOwnerUUID(""); + } else { + getHandle().setOwnerUUID(uuid.toString()); + } + } + public AnimalTamer getOwner() { - if (("").equals(getOwnerName())) return null; + if (getOwnerUUID() == null) { + return null; + } - AnimalTamer owner = getServer().getPlayerExact(getOwnerName()); + AnimalTamer owner = getServer().getPlayer(getOwnerUUID()); if (owner == null) { - owner = getServer().getOfflinePlayer(getOwnerName()); + owner = getServer().getOfflinePlayer(getOwnerUUID()); } return owner; } - public String getOwnerName() { - return getHandle().getOwnerName(); - } - public boolean isTamed() { return getHandle().isTamed(); } @@ -39,21 +55,17 @@ public class CraftTameableAnimal extends CraftAnimals implements Tameable, Creat if (tamer != null) { setTamed(true); getHandle().setPathEntity(null); - setOwnerName(tamer.getName()); + setOwnerUUID(tamer.getUniqueId()); } else { setTamed(false); - setOwnerName(""); + setOwnerUUID(null); } } - public void setOwnerName(String ownerName) { - getHandle().setOwnerName(ownerName == null ? "" : ownerName); - } - public void setTamed(boolean tame) { getHandle().setTamed(tame); if (!tame) { - setOwnerName(""); + setOwnerUUID(null); } } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 2911d601..4cc25f2c 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -85,7 +85,7 @@ public class CraftEventFactory { if (world.getHandle().dimension != 0) return true; if (spawnSize <= 0) return true; - if (((CraftServer) Bukkit.getServer()).getHandle().getOPs().isEmpty()) return true; + if (((CraftServer) Bukkit.getServer()).getHandle().getOPs().d()) return true; // Should be isEmpty if (player.isOp()) return true; ChunkCoordinates chunkcoordinates = worldServer.getSpawn(); |