Fix getting white list, ban list, and op list. Fixes BUKKIT-5538

The getEntries methods on these return player names instead of UUIDs.
As we need the UUIDs for our API we add a getValues method to get at
the data we need. To further ensure we get the most data possible we
also add a way to get at the stored GameProfile to ensure we always
have both the UUID and the name from the list.

By: Travis Watkins <amaranth@ubuntu.com>
This commit is contained in:
CraftBukkit/Spigot
2014-04-17 03:31:49 -05:00
parent 35ef785bd7
commit a546a14bb1
5 changed files with 55 additions and 28 deletions

View File

@@ -2,7 +2,9 @@ package org.bukkit.craftbukkit;
import net.minecraft.server.IpBanEntry; import net.minecraft.server.IpBanEntry;
import net.minecraft.server.IpBanList; import net.minecraft.server.IpBanList;
import net.minecraft.server.MinecraftServer;
import java.io.IOException;
import java.util.Date; import java.util.Date;
public final class CraftIpBanEntry implements org.bukkit.BanEntry { public final class CraftIpBanEntry implements org.bukkit.BanEntry {
@@ -75,6 +77,10 @@ public final class CraftIpBanEntry implements org.bukkit.BanEntry {
public void save() { public void save() {
IpBanEntry entry = new IpBanEntry(target, this.created, this.source, this.expiration, this.reason); IpBanEntry entry = new IpBanEntry(target, this.created, this.source, this.expiration, this.reason);
this.list.add(entry); this.list.add(entry);
this.list.save(); try {
this.list.save();
} catch (IOException ex) {
MinecraftServer.getLogger().error("Failed to save banned-ips.json, " + ex.getMessage());
}
} }
} }

View File

@@ -1,11 +1,13 @@
package org.bukkit.craftbukkit; package org.bukkit.craftbukkit;
import java.io.IOException;
import java.net.InetSocketAddress; 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.IpBanEntry;
import net.minecraft.server.IpBanList; import net.minecraft.server.IpBanList;
import net.minecraft.server.MinecraftServer;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
@@ -39,7 +41,13 @@ public class CraftIpBanList implements org.bukkit.BanList {
StringUtils.isBlank(reason) ? null : reason); StringUtils.isBlank(reason) ? null : reason);
list.add(entry); list.add(entry);
list.save();
try {
list.save();
} catch (IOException ex) {
MinecraftServer.getLogger().error("Failed to save banned-ips.json, " + ex.getMessage());
}
return new CraftIpBanEntry(target, entry, list); return new CraftIpBanEntry(target, entry, list);
} }

View File

@@ -2,8 +2,10 @@ package org.bukkit.craftbukkit;
import net.minecraft.server.GameProfileBanEntry; import net.minecraft.server.GameProfileBanEntry;
import net.minecraft.server.GameProfileBanList; import net.minecraft.server.GameProfileBanList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.com.mojang.authlib.GameProfile; import net.minecraft.util.com.mojang.authlib.GameProfile;
import java.io.IOException;
import java.util.Date; import java.util.Date;
public final class CraftProfileBanEntry implements org.bukkit.BanEntry { public final class CraftProfileBanEntry implements org.bukkit.BanEntry {
@@ -76,6 +78,10 @@ public final class CraftProfileBanEntry implements org.bukkit.BanEntry {
public void save() { public void save() {
GameProfileBanEntry entry = new GameProfileBanEntry(profile, this.created, this.source, this.expiration, this.reason); GameProfileBanEntry entry = new GameProfileBanEntry(profile, this.created, this.source, this.expiration, this.reason);
this.list.add(entry); this.list.add(entry);
this.list.save(); try {
this.list.save();
} catch (IOException ex) {
MinecraftServer.getLogger().error("Failed to save banned-players.json, " + ex.getMessage());
}
} }
} }

View File

@@ -1,11 +1,14 @@
package org.bukkit.craftbukkit; package org.bukkit.craftbukkit;
import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import net.minecraft.server.GameProfileBanEntry; import net.minecraft.server.GameProfileBanEntry;
import net.minecraft.server.GameProfileBanList; import net.minecraft.server.GameProfileBanList;
import net.minecraft.server.JsonListEntry;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.com.mojang.authlib.GameProfile; import net.minecraft.util.com.mojang.authlib.GameProfile;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@@ -47,18 +50,22 @@ public class CraftProfileBanList implements org.bukkit.BanList {
StringUtils.isBlank(reason) ? null : reason); StringUtils.isBlank(reason) ? null : reason);
list.add(entry); list.add(entry);
list.save();
try {
list.save();
} catch (IOException ex) {
MinecraftServer.getLogger().error("Failed to save banned-players.json, " + ex.getMessage());
}
return new CraftProfileBanEntry(profile, entry, list); return new CraftProfileBanEntry(profile, 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 (String target : list.getEntries()) { for (JsonListEntry entry : list.getValues()) {
UUID id = UUID.fromString(target); GameProfile profile = (GameProfile) entry.f(); // Should be getKey
GameProfile profile = new GameProfile(id, null); builder.add(new CraftProfileBanEntry(profile, (GameProfileBanEntry) entry, list));
builder.add(new CraftProfileBanEntry(profile, (GameProfileBanEntry) list.get(profile), list));
} }
return builder.build(); return builder.build();

View File

@@ -76,7 +76,10 @@ import net.minecraft.server.EntityTracker;
import net.minecraft.server.EnumDifficulty; import net.minecraft.server.EnumDifficulty;
import net.minecraft.server.EnumGamemode; import net.minecraft.server.EnumGamemode;
import net.minecraft.server.ExceptionWorldConflict; import net.minecraft.server.ExceptionWorldConflict;
import net.minecraft.server.GameProfileBanEntry;
import net.minecraft.server.GameProfileBanList;
import net.minecraft.server.Items; import net.minecraft.server.Items;
import net.minecraft.server.JsonListEntry;
import net.minecraft.server.PlayerList; import net.minecraft.server.PlayerList;
import net.minecraft.server.RecipesFurnace; import net.minecraft.server.RecipesFurnace;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
@@ -737,8 +740,16 @@ public final class CraftServer implements Server {
chunkGCLoadThresh = configuration.getInt("chunk-gc.load-threshold"); chunkGCLoadThresh = configuration.getInt("chunk-gc.load-threshold");
loadIcon(); loadIcon();
playerList.getIPBans().load(); try {
playerList.getProfileBans().load(); playerList.getIPBans().load();
} catch (IOException ex) {
logger.log(Level.WARNING, "Failed to load banned-ips.json, " + ex.getMessage());
}
try {
playerList.getProfileBans().load();
} catch (IOException ex) {
logger.log(Level.WARNING, "Failed to load banned-players.json, " + ex.getMessage());
}
for (WorldServer world : console.worlds) { for (WorldServer world : console.worlds) {
world.difficulty = difficulty; world.difficulty = difficulty;
@@ -1330,12 +1341,8 @@ 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 (String id : playerList.getProfileBans().getEntries()) { for (JsonListEntry entry : playerList.getProfileBans().getValues()) {
try { result.add(getOfflinePlayer((GameProfile) entry.f())); // Should be getKey
result.add(getOfflinePlayer(UUID.fromString(id)));
} catch (IllegalArgumentException ex) {
// This shouldn't happen
}
} }
return result; return result;
@@ -1364,11 +1371,8 @@ public final class CraftServer implements Server {
public Set<OfflinePlayer> getWhitelistedPlayers() { public Set<OfflinePlayer> getWhitelistedPlayers() {
Set<OfflinePlayer> result = new LinkedHashSet<OfflinePlayer>(); Set<OfflinePlayer> result = new LinkedHashSet<OfflinePlayer>();
for (Object name : playerList.getWhitelisted()) { for (JsonListEntry entry : playerList.getWhitelist().getValues()) {
if (((String)name).length() == 0 || ((String)name).startsWith("#")) { result.add(getOfflinePlayer((GameProfile) entry.f())); // Should be getKey
continue;
}
result.add(getOfflinePlayer((String) name));
} }
return result; return result;
@@ -1377,12 +1381,8 @@ 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 (String id : playerList.getOPs().getEntries()) { for (JsonListEntry entry : playerList.getOPs().getValues()) {
try { result.add(getOfflinePlayer((GameProfile) entry.f())); // Should be getKey
result.add(getOfflinePlayer(UUID.fromString(id)));
} catch (IllegalArgumentException ex) {
// This shouldn't ever happen
}
} }
return result; return result;