3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 12:30:06 +01:00

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.
Dieser Commit ist enthalten in:
Travis Watkins 2014-04-17 03:31:49 -05:00
Ursprung 5cbbcae9a9
Commit 6ad36f09e5
9 geänderte Dateien mit 78 neuen und 51 gelöschten Zeilen

Datei anzeigen

@ -79,6 +79,12 @@ public class JsonList {
return (String[]) this.d.keySet().toArray(new String[this.d.size()]); return (String[]) this.d.keySet().toArray(new String[this.d.size()]);
} }
// CraftBukkit start
public Collection<JsonListEntry> getValues() {
return this.d.values();
}
// CraftBukkit end
public boolean d() { public boolean d() {
return this.d.size() < 1; return this.d.size() < 1;
} }
@ -120,7 +126,7 @@ public class JsonList {
return this.d; return this.d;
} }
public void save() { public void save() throws IOException { // CraftBukkit - Added throws
Collection collection = this.d.values(); Collection collection = this.d.values();
String s = this.b.toJson(collection); String s = this.b.toJson(collection);
BufferedWriter bufferedwriter = null; BufferedWriter bufferedwriter = null;
@ -133,7 +139,7 @@ public class JsonList {
} }
} }
public void load() { public void load() throws IOException { // CraftBukkit - Added throws
Collection collection = null; Collection collection = null;
BufferedReader bufferedreader = null; BufferedReader bufferedreader = null;

Datei anzeigen

@ -14,7 +14,7 @@ public class JsonListEntry {
this.a = object; this.a = object;
} }
Object f() { public Object f() { // CraftBukkit -> package private -> public
return this.a; return this.a;
} }

Datei anzeigen

@ -1,5 +1,7 @@
package net.minecraft.server; package net.minecraft.server;
// CraftBukkit - Imported for package private use in JsonList
import java.lang.reflect.Type; import java.lang.reflect.Type;
import net.minecraft.util.com.google.gson.JsonDeserializationContext; import net.minecraft.util.com.google.gson.JsonDeserializationContext;

Datei anzeigen

@ -77,14 +77,12 @@ public class NameReferencingFileConverter {
if (b.exists() && b.isFile()) { if (b.exists() && b.isFile()) {
if (gameprofilebanlist.c().exists()) { if (gameprofilebanlist.c().exists()) {
/* CraftBukkit start - Exception is never thrown
try { try {
gameprofilebanlist.load(); gameprofilebanlist.load();
} catch (FileNotFoundException filenotfoundexception) { // CraftBukkit start - FileNotFoundException -> IOException, don't print stacetrace
e.warn("Could not load existing file " + gameprofilebanlist.c().getName(), filenotfoundexception); } catch (IOException filenotfoundexception) {
e.warn("Could not load existing file " + gameprofilebanlist.c().getName() + ", " + filenotfoundexception.getMessage());
} }
*/
gameprofilebanlist.load();
// CraftBukkit end // CraftBukkit end
} }
@ -115,14 +113,12 @@ public class NameReferencingFileConverter {
if (a.exists() && a.isFile()) { if (a.exists() && a.isFile()) {
if (ipbanlist.c().exists()) { if (ipbanlist.c().exists()) {
/* CraftBukkit start - Exception is never thrown
try { try {
ipbanlist.load(); ipbanlist.load();
} catch (FileNotFoundException filenotfoundexception) { // CraftBukkit start - FileNotFoundException -> IOException, don't print stacetrace
e.warn("Could not load existing file " + ipbanlist.c().getName(), filenotfoundexception); } catch (IOException filenotfoundexception) {
e.warn("Could not load existing file " + ipbanlist.c().getName() + ", " + filenotfoundexception.getMessage());
} }
*/
ipbanlist.load();
// CraftBukkit end // CraftBukkit end
} }
@ -160,14 +156,12 @@ public class NameReferencingFileConverter {
if (c.exists() && c.isFile()) { if (c.exists() && c.isFile()) {
if (oplist.c().exists()) { if (oplist.c().exists()) {
/* CraftBukkit start - Exception is never thrown
try { try {
oplist.load(); oplist.load();
} catch (FileNotFoundException filenotfoundexception) { // CraftBukkit start - FileNotFoundException -> IOException, don't print stacetrace
e.warn("Could not load existing file " + oplist.c().getName(), filenotfoundexception); } catch (IOException filenotfoundexception) {
e.warn("Could not load existing file " + oplist.c().getName() + ", " + filenotfoundexception.getMessage());
} }
*/
oplist.load();
// CraftBukkit end // CraftBukkit end
} }
@ -196,14 +190,12 @@ public class NameReferencingFileConverter {
if (d.exists() && d.isFile()) { if (d.exists() && d.isFile()) {
if (whitelist.c().exists()) { if (whitelist.c().exists()) {
/* CraftBukkit start - Exception is never thrown
try { try {
whitelist.load(); whitelist.load();
} catch (FileNotFoundException filenotfoundexception) { // CraftBukkit start - FileNotFoundException -> IOException, don't print stacetrace
e.warn("Could not load existing file " + whitelist.c().getName(), filenotfoundexception); } catch (IOException filenotfoundexception) {
e.warn("Could not load existing file " + whitelist.c().getName() + ", " + filenotfoundexception.getMessage());
} }
*/
whitelist.load();
// CraftBukkit end // CraftBukkit end
} }

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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