Update CraftBukkit to Minecraft 1.7.8

By: Travis Watkins <amaranth@ubuntu.com>
This commit is contained in:
CraftBukkit/Spigot 2014-04-10 20:04:38 -05:00
parent db3aa0246f
commit d24dac2c06
13 changed files with 407 additions and 176 deletions

View File

@ -4,7 +4,7 @@
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId> <artifactId>craftbukkit</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.7.5-R0.1-SNAPSHOT</version> <version>1.7.8-R0.1-SNAPSHOT</version>
<name>CraftBukkit</name> <name>CraftBukkit</name>
<url>http://www.bukkit.org</url> <url>http://www.bukkit.org</url>
@ -12,8 +12,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<api.version>unknown</api.version> <api.version>unknown</api.version>
<junit.version>4.11</junit.version> <junit.version>4.11</junit.version>
<minecraft.version>1.7.5</minecraft.version> <minecraft.version>1.7.8</minecraft.version>
<minecraft_version>1_7_R2</minecraft_version> <minecraft_version>1_7_R3</minecraft_version>
<buildtag.prefix>git-Bukkit-</buildtag.prefix> <buildtag.prefix>git-Bukkit-</buildtag.prefix>
<buildtag.suffix></buildtag.suffix> <buildtag.suffix></buildtag.suffix>
</properties> </properties>

View File

@ -1,21 +1,21 @@
package org.bukkit.craftbukkit; package org.bukkit.craftbukkit;
import net.minecraft.server.IpBanEntry;
import net.minecraft.server.IpBanList;
import java.util.Date; import java.util.Date;
import net.minecraft.server.BanEntry; public final class CraftIpBanEntry implements org.bukkit.BanEntry {
import net.minecraft.server.BanList; private final IpBanList list;
private final String target;
public final class CraftBanEntry implements org.bukkit.BanEntry {
private final BanList list;
private final String name;
private Date created; private Date created;
private String source; private String source;
private Date expiration; private Date expiration;
private String reason; private String reason;
public CraftBanEntry(BanEntry entry, BanList list) { public CraftIpBanEntry(String target, IpBanEntry entry, IpBanList list) {
this.list = list; this.list = list;
this.name = entry.getName(); this.target = target;
this.created = entry.getCreated() != null ? new Date(entry.getCreated().getTime()) : null; this.created = entry.getCreated() != null ? new Date(entry.getCreated().getTime()) : null;
this.source = entry.getSource(); this.source = entry.getSource();
this.expiration = entry.getExpires() != null ? new Date(entry.getExpires().getTime()) : null; this.expiration = entry.getExpires() != null ? new Date(entry.getExpires().getTime()) : null;
@ -24,7 +24,7 @@ public final class CraftBanEntry implements org.bukkit.BanEntry {
@Override @Override
public String getTarget() { public String getTarget() {
return this.name; return this.target;
} }
@Override @Override
@ -73,14 +73,8 @@ public final class CraftBanEntry implements org.bukkit.BanEntry {
@Override @Override
public void save() { public void save() {
BanEntry entry = new BanEntry(this.name); IpBanEntry entry = new IpBanEntry(target, this.created, this.source, this.expiration, this.reason);
entry.setCreated(this.created);
entry.setSource(this.source);
entry.setExpires(this.expiration);
entry.setReason(this.reason);
this.list.add(entry); this.list.add(entry);
this.list.save(); this.list.save();
} }
} }

View File

@ -1,21 +1,20 @@
package org.bukkit.craftbukkit; package org.bukkit.craftbukkit;
import java.util.Collection; import java.net.InetSocketAddress;
import java.util.Date; import java.util.Date;
import java.util.Set; 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.StringUtils;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import net.minecraft.server.BanEntry; public class CraftIpBanList implements org.bukkit.BanList {
import net.minecraft.server.BanList; private final IpBanList list;
public class CraftBanList implements org.bukkit.BanList { public CraftIpBanList(IpBanList list) {
private final BanList list;
public CraftBanList(BanList list){
this.list = list; this.list = list;
} }
@ -23,33 +22,34 @@ public class CraftBanList implements org.bukkit.BanList {
public org.bukkit.BanEntry getBanEntry(String target) { public org.bukkit.BanEntry getBanEntry(String target) {
Validate.notNull(target, "Target cannot be null"); Validate.notNull(target, "Target cannot be null");
if (!list.getEntries().containsKey(target)) { IpBanEntry entry = (IpBanEntry) list.get(target);
if (entry == null) {
return null; return null;
} }
return new CraftBanEntry((BanEntry) list.getEntries().get(target), list); return new CraftIpBanEntry(target, entry, list);
} }
@Override @Override
public org.bukkit.BanEntry addBan(String target, String reason, Date expires, String source) { public org.bukkit.BanEntry addBan(String target, String reason, Date expires, String source) {
Validate.notNull(target, "Ban target cannot be null"); Validate.notNull(target, "Ban target cannot be null");
BanEntry entry = new BanEntry(target); IpBanEntry entry = new IpBanEntry(target, new Date(),
entry.setSource(StringUtils.isBlank(source) ? entry.getSource() : source); // Use default if null/empty StringUtils.isBlank(source) ? null : source, expires,
entry.setExpires(expires); // Null values are interpreted as "forever" StringUtils.isBlank(reason) ? null : reason);
entry.setReason(StringUtils.isBlank(reason) ? entry.getReason() : reason); // Use default if null/empty
list.add(entry); list.add(entry);
list.save(); list.save();
return new CraftBanEntry(entry, list); return new CraftIpBanEntry(target, entry, list);
} }
@Override @Override
public Set<org.bukkit.BanEntry> getBanEntries() { public Set<org.bukkit.BanEntry> getBanEntries() {
ImmutableSet.Builder<org.bukkit.BanEntry> builder = ImmutableSet.builder(); ImmutableSet.Builder<org.bukkit.BanEntry> builder = ImmutableSet.builder();
for (BanEntry entry : (Collection<BanEntry>) list.getEntries().values()) { for (String target : list.getEntries()) {
builder.add(new CraftBanEntry(entry, list)); builder.add(new CraftIpBanEntry(target, (IpBanEntry) list.get(target), list));
} }
return builder.build(); return builder.build();
} }
@ -57,7 +57,7 @@ public class CraftBanList implements org.bukkit.BanList {
public boolean isBanned(String target) { public boolean isBanned(String target) {
Validate.notNull(target, "Target cannot be null"); Validate.notNull(target, "Target cannot be null");
return list.isBanned(target); return list.isBanned(InetSocketAddress.createUnresolved(target, 0));
} }
@Override @Override
@ -66,5 +66,4 @@ public class CraftBanList implements org.bukkit.BanList {
list.remove(target); list.remove(target);
} }
} }

View File

@ -6,11 +6,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import net.minecraft.server.BanEntry;
import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPlayer;
import net.minecraft.server.NBTTagCompound; import net.minecraft.server.NBTTagCompound;
import net.minecraft.server.WorldNBTStorage; import net.minecraft.server.WorldNBTStorage;
import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.BanList; import org.bukkit.BanList;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -24,14 +24,19 @@ import org.bukkit.plugin.Plugin;
@SerializableAs("Player") @SerializableAs("Player")
public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializable { public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializable {
private final String name; private final GameProfile profile;
private final CraftServer server; private final CraftServer server;
private final WorldNBTStorage storage; private final WorldNBTStorage storage;
protected CraftOfflinePlayer(CraftServer server, String name) { protected CraftOfflinePlayer(CraftServer server, GameProfile profile) {
this.server = server; this.server = server;
this.name = name; this.profile = profile;
this.storage = (WorldNBTStorage) (server.console.worlds.get(0).getDataManager()); this.storage = (WorldNBTStorage) (server.console.worlds.get(0).getDataManager());
}
public GameProfile getProfile() {
return profile;
} }
public boolean isOnline() { public boolean isOnline() {
@ -39,86 +44,96 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
} }
public String getName() { public String getName() {
return name; Player player = getPlayer();
} if (player != null) {
return player.getName();
// 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;
} }
if (data.hasKeyOfType("UUIDMost", 4) && data.hasKeyOfType("UUIDLeast", 4)) { NBTTagCompound data = getBukkitData();
return new UUID(data.getLong("UUIDMost"), data.getLong("UUIDLeast"));
if (data != null) {
if (data.hasKey("lastKnownName")) {
return data.getString("lastKnownName");
}
} }
return null; return null;
} }
public UUID getUniqueId() {
return profile.getId();
}
public Server getServer() { public Server getServer() {
return server; return server;
} }
public boolean isOp() { public boolean isOp() {
return server.getHandle().isOp(getName().toLowerCase()); return server.getHandle().isOp(profile);
} }
public void setOp(boolean value) { public void setOp(boolean value) {
if (value == isOp()) return; if (value == isOp()) {
return;
}
if (value) { if (value) {
server.getHandle().addOp(getName().toLowerCase()); server.getHandle().addOp(profile);
} else { } else {
server.getHandle().removeOp(getName().toLowerCase()); server.getHandle().removeOp(profile);
} }
} }
public boolean isBanned() { 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) { public void setBanned(boolean value) {
if (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 { } else {
server.getBanList(BanList.Type.NAME).pardon(getName()); server.getBanList(BanList.Type.UUID).pardon(getUniqueId().toString());
} }
} }
public boolean isWhitelisted() { public boolean isWhitelisted() {
return server.getHandle().getWhitelisted().contains(name.toLowerCase()); return server.getHandle().isWhitelisted(profile);
} }
public void setWhitelisted(boolean value) { public void setWhitelisted(boolean value) {
if (value) { if (value) {
server.getHandle().addWhitelist(name.toLowerCase()); server.getHandle().addWhitelist(profile);
} else { } else {
server.getHandle().removeWhitelist(name.toLowerCase()); server.getHandle().removeWhitelist(profile);
} }
} }
public Map<String, Object> serialize() { public Map<String, Object> serialize() {
Map<String, Object> result = new LinkedHashMap<String, Object>(); Map<String, Object> result = new LinkedHashMap<String, Object>();
result.put("name", name); result.put("UUID", profile.getId().toString());
return result; return result;
} }
public static OfflinePlayer deserialize(Map<String, Object> args) { 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 @Override
public String toString() { public String toString() {
return getClass().getSimpleName() + "[name=" + name + "]"; return getClass().getSimpleName() + "[UUID=" + profile.getId() + "]";
} }
public Player getPlayer() { public Player getPlayer() {
for (Object obj : server.getHandle().players) { for (Object obj : server.getHandle().players) {
EntityPlayer player = (EntityPlayer) obj; EntityPlayer player = (EntityPlayer) obj;
if (player.getName().equalsIgnoreCase(getName())) { if (player.getUniqueID().equals(getUniqueId())) {
return (player.playerConnection != null) ? player.playerConnection.getPlayer() : null; return (player.playerConnection != null) ? player.playerConnection.getPlayer() : null;
} }
} }
@ -128,28 +143,27 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == null) { if (obj == null || !(obj instanceof OfflinePlayer)) {
return false;
}
if (!(obj instanceof OfflinePlayer)) {
return false; return false;
} }
OfflinePlayer other = (OfflinePlayer) obj; OfflinePlayer other = (OfflinePlayer) obj;
if ((this.getName() == null) || (other.getName() == null)) { if ((this.getUniqueId() == null) || (other.getUniqueId() == null)) {
return false; return false;
} }
return this.getName().equalsIgnoreCase(other.getName());
return this.getUniqueId().equals(other.getUniqueId());
} }
@Override @Override
public int hashCode() { public int hashCode() {
int hash = 5; 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; return hash;
} }
private NBTTagCompound getData() { private NBTTagCompound getData() {
return storage.getPlayerData(getName()); return storage.getPlayerData(getUniqueId().toString());
} }
private NBTTagCompound getBukkitData() { private NBTTagCompound getBukkitData() {
@ -166,7 +180,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
} }
private File getDataFile() { private File getDataFile() {
return new File(storage.getPlayerDir(), name + ".dat"); return new File(storage.getPlayerDir(), getUniqueId() + ".dat");
} }
public long getFirstPlayed() { public long getFirstPlayed() {

View File

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

View File

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

View File

@ -15,7 +15,6 @@ import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -92,6 +91,7 @@ import net.minecraft.server.WorldServer;
import net.minecraft.server.WorldSettings; import net.minecraft.server.WorldSettings;
import net.minecraft.server.WorldType; import net.minecraft.server.WorldType;
import net.minecraft.util.com.google.common.base.Charsets; 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.ByteBuf;
import net.minecraft.util.io.netty.buffer.ByteBufOutputStream; import net.minecraft.util.io.netty.buffer.ByteBufOutputStream;
import net.minecraft.util.io.netty.buffer.Unpooled; import net.minecraft.util.io.netty.buffer.Unpooled;
@ -204,7 +204,7 @@ public final class CraftServer implements Server {
private YamlConfiguration configuration; private YamlConfiguration configuration;
private YamlConfiguration commandsConfiguration; private YamlConfiguration commandsConfiguration;
private final Yaml yaml = new Yaml(new SafeConstructor()); 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 AutoUpdater updater;
private final EntityMetadataStore entityMetadata = new EntityMetadataStore(); private final EntityMetadataStore entityMetadata = new EntityMetadataStore();
private final PlayerMetadataStore playerMetadata = new PlayerMetadataStore(); 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 // 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()) { for (Player player : getOnlinePlayers()) {
if (player.getUniqueId().equals(id)) { if (player.getUniqueId().equals(id)) {
return player; return player;
@ -734,7 +734,7 @@ public final class CraftServer implements Server {
loadIcon(); loadIcon();
playerList.getIPBans().load(); playerList.getIPBans().load();
playerList.getNameBans().load(); playerList.getProfileBans().load();
for (WorldServer world : console.worlds) { for (WorldServer world : console.worlds) {
world.difficulty = difficulty; world.difficulty = difficulty;
@ -1013,7 +1013,7 @@ public final class CraftServer implements Server {
return worlds.get(name.toLowerCase()); return worlds.get(name.toLowerCase());
} }
public World getWorld(UUID uid) { public World getWorld(java.util.UUID uid) {
for (World world : worlds.values()) { for (World world : worlds.values()) {
if (world.getUID().equals(uid)) { if (world.getUID().equals(uid)) {
return world; return world;
@ -1258,54 +1258,44 @@ public final class CraftServer implements Server {
} }
public OfflinePlayer getOfflinePlayer(String name) { public OfflinePlayer getOfflinePlayer(String name) {
return getOfflinePlayer(name, true);
}
public OfflinePlayer getOfflinePlayer(String name, boolean search) {
Validate.notNull(name, "Name cannot be null"); Validate.notNull(name, "Name cannot be null");
OfflinePlayer result = getPlayerExact(name); // This is potentially blocking :(
String lname = name.toLowerCase(); 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));
}
return getOfflinePlayer(profile.getId());
}
public OfflinePlayer getOfflinePlayer(java.util.UUID id) {
Validate.notNull(id, "UUID cannot be null");
OfflinePlayer result = getPlayer(id);
if (result == null) { if (result == null) {
result = offlinePlayers.get(lname); result = offlinePlayers.get(id);
if (result == null) { if (result == null) {
if (search) { result = new CraftOfflinePlayer(this, new GameProfile(id, null));
WorldNBTStorage storage = (WorldNBTStorage) console.worlds.get(0).getDataManager(); offlinePlayers.put(id, result);
for (String dat : storage.getPlayerDir().list(new DatFileFilter())) {
String datName = dat.substring(0, dat.length() - 4);
if (datName.equalsIgnoreCase(name)) {
name = datName;
break;
}
}
}
result = new CraftOfflinePlayer(this, name);
offlinePlayers.put(lname, result);
} }
} else { } else {
offlinePlayers.remove(lname); offlinePlayers.remove(id);
} }
return result; return result;
} }
// TODO: In 1.7.6+ this should just lookup the UUID-based player data filename public OfflinePlayer getOfflinePlayer(GameProfile profile) {
public OfflinePlayer getOfflinePlayer(UUID id) { OfflinePlayer player = new CraftOfflinePlayer(this, profile);
String name = MojangNameLookup.lookupName(id); offlinePlayers.put(profile.getId(), player);
if (name == null) { return player;
// This is completely wrong
name = "InvalidUUID";
}
return getOfflinePlayer(name);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Set<String> getIPBans() { 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) { public void banIP(String address) {
@ -1323,28 +1313,34 @@ public final class CraftServer implements Server {
public Set<OfflinePlayer> getBannedPlayers() { public Set<OfflinePlayer> getBannedPlayers() {
Set<OfflinePlayer> result = new HashSet<OfflinePlayer>(); Set<OfflinePlayer> result = new HashSet<OfflinePlayer>();
for (Object name : playerList.getNameBans().getEntries().keySet()) { for (String id : playerList.getProfileBans().getEntries()) {
result.add(getOfflinePlayer((String) name)); try {
result.add(getOfflinePlayer(java.util.UUID.fromString(id)));
} catch (IllegalArgumentException ex) {
// This shouldn't happen
}
} }
return result; return result;
} }
@Override @Override
public BanList getBanList(BanList.Type type){ public BanList getBanList(BanList.Type type) {
Validate.notNull(type, "Type cannot be null"); Validate.notNull(type, "Type cannot be null");
switch(type){ switch(type){
case IP: case IP:
return new CraftBanList(playerList.getIPBans()); return new CraftIpBanList(playerList.getIPBans());
case NAME: case NAME:
default: // Fall through as a player name list for safety return null;
return new CraftBanList(playerList.getNameBans()); case UUID:
default:
return new CraftProfileBanList(playerList.getProfileBans());
} }
} }
public void setWhitelist(boolean value) { public void setWhitelist(boolean value) {
playerList.hasWhitelist = value; playerList.setHasWhitelist(value);
console.getPropertyManager().a("white-list", value); console.getPropertyManager().a("white-list", value);
} }
@ -1364,8 +1360,12 @@ public final class CraftServer implements Server {
public Set<OfflinePlayer> getOperators() { public Set<OfflinePlayer> getOperators() {
Set<OfflinePlayer> result = new HashSet<OfflinePlayer>(); Set<OfflinePlayer> result = new HashSet<OfflinePlayer>();
for (Object name : playerList.getOPs()) { for (String id : playerList.getOPs().getEntries()) {
result.add(getOfflinePlayer((String) name)); try {
result.add(getOfflinePlayer(java.util.UUID.fromString(id)));
} catch (IllegalArgumentException ex) {
// This shouldn't ever happen
}
} }
return result; return result;
@ -1442,8 +1442,13 @@ public final class CraftServer implements Server {
Set<OfflinePlayer> players = new HashSet<OfflinePlayer>(); Set<OfflinePlayer> players = new HashSet<OfflinePlayer>();
for (String file : files) { 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())); players.addAll(Arrays.asList(getOnlinePlayers()));
return players.toArray(new OfflinePlayer[players.size()]); return players.toArray(new OfflinePlayer[players.size()]);

View File

@ -10,6 +10,7 @@ import net.minecraft.server.BlockCocoa;
import net.minecraft.server.BlockRedstoneWire; import net.minecraft.server.BlockRedstoneWire;
import net.minecraft.server.Blocks; import net.minecraft.server.Blocks;
import net.minecraft.server.EnumSkyBlock; import net.minecraft.server.EnumSkyBlock;
import net.minecraft.server.GameProfileSerializer;
import net.minecraft.server.Item; import net.minecraft.server.Item;
import net.minecraft.server.NBTTagCompound; import net.minecraft.server.NBTTagCompound;
import net.minecraft.server.TileEntitySkull; 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)); 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); 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.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)); drops.add(CraftItemStack.asBukkitCopy(nmsStack));

View File

@ -1,28 +1,30 @@
package org.bukkit.craftbukkit.block; package org.bukkit.craftbukkit.block;
import com.google.common.base.Strings; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.TileEntitySkull; import net.minecraft.server.TileEntitySkull;
import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.bukkit.OfflinePlayer;
import org.bukkit.SkullType; import org.bukkit.SkullType;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.Skull; import org.bukkit.block.Skull;
import org.bukkit.craftbukkit.CraftOfflinePlayer;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftPlayer;
public class CraftSkull extends CraftBlockState implements Skull { public class CraftSkull extends CraftBlockState implements Skull {
private final TileEntitySkull skull; private final TileEntitySkull skull;
private String player; private GameProfile profile;
private SkullType skullType; private SkullType skullType;
private byte rotation; private byte rotation;
private final int MAX_OWNER_LENGTH = 16;
public CraftSkull(final Block block) { public CraftSkull(final Block block) {
super(block); super(block);
CraftWorld world = (CraftWorld) block.getWorld(); CraftWorld world = (CraftWorld) block.getWorld();
skull = (TileEntitySkull) world.getTileEntityAt(getX(), getY(), getZ()); skull = (TileEntitySkull) world.getTileEntityAt(getX(), getY(), getZ());
player = skull.getExtraType(); profile = skull.getGameProfile();
skullType = getSkullType(skull.getSkullType()); skullType = getSkullType(skull.getSkullType());
rotation = (byte) skull.getRotation(); rotation = (byte) skull.getRotation();
} }
@ -140,23 +142,36 @@ public class CraftSkull extends CraftBlockState implements Skull {
} }
public boolean hasOwner() { public boolean hasOwner() {
return !Strings.isNullOrEmpty(player); return profile != null;
} }
public String getOwner() { public String getOwner() {
return player; return profile.getName();
} }
public boolean setOwner(String name) { 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; return false;
} }
player = name;
if (skullType != SkullType.PLAYER) { if (profile == null) {
skullType = SkullType.PLAYER; return false;
} }
this.profile = profile;
return true; return true;
} }
@ -176,7 +191,7 @@ public class CraftSkull extends CraftBlockState implements Skull {
this.skullType = skullType; this.skullType = skullType;
if (skullType != SkullType.PLAYER) { if (skullType != SkullType.PLAYER) {
player = ""; profile = null;
} }
} }
@ -185,7 +200,8 @@ public class CraftSkull extends CraftBlockState implements Skull {
boolean result = super.update(force, applyPhysics); boolean result = super.update(force, applyPhysics);
if (result) { if (result) {
skull.setSkullType(getSkullType(skullType), player); skull.setSkullType(getSkullType(skullType));
skull.setGameProfile(profile);
skull.setRotation(rotation); skull.setRotation(rotation);
skull.update(); skull.update();
} }

View File

@ -9,6 +9,8 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse; import org.bukkit.entity.Horse;
import org.bukkit.inventory.HorseInventory; import org.bukkit.inventory.HorseInventory;
import java.util.UUID;
public class CraftHorse extends CraftAnimals implements Horse { public class CraftHorse extends CraftAnimals implements Horse {
public CraftHorse(CraftServer server, EntityHorse entity) { public CraftHorse(CraftServer server, EntityHorse entity) {
@ -97,28 +99,36 @@ public class CraftHorse extends CraftAnimals implements Horse {
@Override @Override
public AnimalTamer getOwner() { public AnimalTamer getOwner() {
if (getOwnerName() == null || "".equals(getOwnerName())) return null; if (getOwnerUUID() == null) return null;
return getServer().getOfflinePlayer(getOwnerName()); return getServer().getOfflinePlayer(getOwnerUUID());
} }
@Override @Override
public void setOwner(AnimalTamer owner) { public void setOwner(AnimalTamer owner) {
if (owner != null && !"".equals(owner.getName())) { if (owner != null) {
setTamed(true); setTamed(true);
getHandle().setPathEntity(null); getHandle().setPathEntity(null);
setOwnerName(owner.getName()); setOwnerUUID(owner.getUniqueId());
} else { } else {
setTamed(false); setTamed(false);
setOwnerName(""); setOwnerUUID(null);
} }
} }
public String getOwnerName() { public UUID getOwnerUUID() {
return getHandle().getOwnerName(); try {
return UUID.fromString(getHandle().getOwnerUUID());
} catch (IllegalArgumentException ex) {
return null;
}
} }
public void setOwnerName(String name) { public void setOwnerUUID(UUID uuid) {
getHandle().setOwnerName(name); if (uuid == null) {
getHandle().setOwnerUUID("");
} else {
getHandle().setOwnerUUID(uuid.toString());
}
} }
public HorseInventory getInventory() { public HorseInventory getInventory() {

View File

@ -13,11 +13,13 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.minecraft.server.*; import net.minecraft.server.*;
import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.apache.commons.lang.NotImplementedException; import org.apache.commons.lang.NotImplementedException;
import org.bukkit.*; import org.bukkit.*;
@ -64,7 +66,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
private boolean hasPlayedBefore = false; private boolean hasPlayedBefore = false;
private final ConversationTracker conversationTracker = new ConversationTracker(); private final ConversationTracker conversationTracker = new ConversationTracker();
private final Set<String> channels = new HashSet<String>(); 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 int hash = 0;
private double health = 20; private double health = 20;
private boolean scaledHealth = false; private boolean scaledHealth = false;
@ -76,9 +78,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
firstPlayed = System.currentTimeMillis(); firstPlayed = System.currentTimeMillis();
} }
public GameProfile getProfile() {
return getHandle().getProfile();
}
@Override @Override
public boolean isOp() { public boolean isOp() {
return server.getHandle().isOp(getName()); return server.getHandle().isOp(getProfile());
} }
@Override @Override
@ -86,9 +92,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
if (value == isOp()) return; if (value == isOp()) return;
if (value) { if (value) {
server.getHandle().addOp(getName()); server.getHandle().addOp(getProfile());
} else { } else {
server.getHandle().removeOp(getName()); server.getHandle().removeOp(getProfile());
} }
perm.recalculatePermissions(); perm.recalculatePermissions();
@ -732,29 +738,29 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override @Override
public boolean isBanned() { public boolean isBanned() {
return server.getBanList(BanList.Type.NAME).isBanned(getName()); return server.getBanList(BanList.Type.UUID).isBanned(getUniqueId().toString());
} }
@Override @Override
public void setBanned(boolean value) { public void setBanned(boolean value) {
if (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 { } else {
server.getBanList(BanList.Type.NAME).pardon(getName()); server.getBanList(BanList.Type.UUID).pardon(getUniqueId().toString());
} }
} }
@Override @Override
public boolean isWhitelisted() { public boolean isWhitelisted() {
return server.getHandle().getWhitelisted().contains(getName().toLowerCase()); return server.getHandle().isWhitelisted(getProfile());
} }
@Override @Override
public void setWhitelisted(boolean value) { public void setWhitelisted(boolean value) {
if (value) { if (value) {
server.getHandle().addWhitelist(getName().toLowerCase()); server.getHandle().addWhitelist(getProfile());
} else { } 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"); Validate.notNull(player, "hidden player cannot be null");
if (getHandle().playerConnection == null) return; if (getHandle().playerConnection == null) return;
if (equals(player)) return; if (equals(player)) return;
if (hiddenPlayers.containsKey(player.getName())) return; if (hiddenPlayers.contains(player.getUniqueId())) return;
hiddenPlayers.put(player.getName(), player); hiddenPlayers.add(player.getUniqueId());
//remove this player from the hidden player's EntityTrackerEntry //remove this player from the hidden player's EntityTrackerEntry
EntityTracker tracker = ((WorldServer) entity.world).tracker; 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"); Validate.notNull(player, "shown player cannot be null");
if (getHandle().playerConnection == null) return; if (getHandle().playerConnection == null) return;
if (equals(player)) return; if (equals(player)) return;
if (!hiddenPlayers.containsKey(player.getName())) return; if (!hiddenPlayers.contains(player.getUniqueId())) return;
hiddenPlayers.remove(player.getName()); hiddenPlayers.remove(player.getUniqueId());
EntityTracker tracker = ((WorldServer) entity.world).tracker; EntityTracker tracker = ((WorldServer) entity.world).tracker;
EntityPlayer other = ((CraftPlayer) player).getHandle(); 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)); getHandle().playerConnection.sendPacket(new PacketPlayOutPlayerInfo(player.getPlayerListName(), true, getHandle().ping));
} }
public void removeDisconnectingPlayer(Player player) {
hiddenPlayers.remove(player.getUniqueId());
}
public boolean canSee(Player player) { public boolean canSee(Player player) {
return !hiddenPlayers.containsKey(player.getName()); return !hiddenPlayers.contains(player.getUniqueId());
} }
public Map<String, Object> serialize() { public Map<String, Object> serialize() {

View File

@ -6,6 +6,8 @@ import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Creature; import org.bukkit.entity.Creature;
import org.bukkit.entity.Tameable; import org.bukkit.entity.Tameable;
import java.util.UUID;
public class CraftTameableAnimal extends CraftAnimals implements Tameable, Creature { public class CraftTameableAnimal extends CraftAnimals implements Tameable, Creature {
public CraftTameableAnimal(CraftServer server, EntityTameableAnimal entity) { public CraftTameableAnimal(CraftServer server, EntityTameableAnimal entity) {
super(server, entity); super(server, entity);
@ -16,21 +18,35 @@ public class CraftTameableAnimal extends CraftAnimals implements Tameable, Creat
return (EntityTameableAnimal)super.getHandle(); return (EntityTameableAnimal)super.getHandle();
} }
public AnimalTamer getOwner() { public UUID getOwnerUUID() {
if (("").equals(getOwnerName())) return null; try {
return UUID.fromString(getHandle().getOwnerUUID());
} catch (IllegalArgumentException ex) {
return null;
}
}
AnimalTamer owner = getServer().getPlayerExact(getOwnerName()); public void setOwnerUUID(UUID uuid) {
if (uuid == null) {
getHandle().setOwnerUUID("");
} else {
getHandle().setOwnerUUID(uuid.toString());
}
}
public AnimalTamer getOwner() {
if (getOwnerUUID() == null) {
return null;
}
AnimalTamer owner = getServer().getPlayer(getOwnerUUID());
if (owner == null) { if (owner == null) {
owner = getServer().getOfflinePlayer(getOwnerName()); owner = getServer().getOfflinePlayer(getOwnerUUID());
} }
return owner; return owner;
} }
public String getOwnerName() {
return getHandle().getOwnerName();
}
public boolean isTamed() { public boolean isTamed() {
return getHandle().isTamed(); return getHandle().isTamed();
} }
@ -39,21 +55,17 @@ public class CraftTameableAnimal extends CraftAnimals implements Tameable, Creat
if (tamer != null) { if (tamer != null) {
setTamed(true); setTamed(true);
getHandle().setPathEntity(null); getHandle().setPathEntity(null);
setOwnerName(tamer.getName()); setOwnerUUID(tamer.getUniqueId());
} else { } else {
setTamed(false); setTamed(false);
setOwnerName(""); setOwnerUUID(null);
} }
} }
public void setOwnerName(String ownerName) {
getHandle().setOwnerName(ownerName == null ? "" : ownerName);
}
public void setTamed(boolean tame) { public void setTamed(boolean tame) {
getHandle().setTamed(tame); getHandle().setTamed(tame);
if (!tame) { if (!tame) {
setOwnerName(""); setOwnerUUID(null);
} }
} }

View File

@ -85,7 +85,7 @@ public class CraftEventFactory {
if (world.getHandle().dimension != 0) return true; if (world.getHandle().dimension != 0) return true;
if (spawnSize <= 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; if (player.isOp()) return true;
ChunkCoordinates chunkcoordinates = worldServer.getSpawn(); ChunkCoordinates chunkcoordinates = worldServer.getSpawn();