mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-01 04:32:11 -07:00
Players directory
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
--- a/net/minecraft/server/players/BanListEntry.java
|
||||
+++ b/net/minecraft/server/players/BanListEntry.java
|
||||
@@ -26,7 +_,7 @@
|
||||
}
|
||||
|
||||
protected BanListEntry(@Nullable T user, JsonObject entryData) {
|
||||
- super(user);
|
||||
+ super(BanListEntry.checkExpiry(user, entryData)); // CraftBukkit
|
||||
|
||||
Date date;
|
||||
try {
|
||||
@@ -80,4 +_,22 @@
|
||||
data.addProperty("expires", this.expires == null ? "forever" : DATE_FORMAT.format(this.expires));
|
||||
data.addProperty("reason", this.reason);
|
||||
}
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ private static <T> T checkExpiry(T object, JsonObject jsonobject) {
|
||||
+ Date expires = null;
|
||||
+
|
||||
+ try {
|
||||
+ expires = jsonobject.has("expires") ? BanListEntry.DATE_FORMAT.parse(jsonobject.get("expires").getAsString()) : null;
|
||||
+ } catch (ParseException ex) {
|
||||
+ // Guess we don't have a date
|
||||
+ }
|
||||
+
|
||||
+ if (expires == null || expires.after(new Date())) {
|
||||
+ return object;
|
||||
+ } else {
|
||||
+ return null;
|
||||
+ }
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
@@ -0,0 +1,212 @@
|
||||
--- a/net/minecraft/server/players/GameProfileCache.java
|
||||
+++ b/net/minecraft/server/players/GameProfileCache.java
|
||||
@@ -17,8 +_,6 @@
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
-import java.io.Reader;
|
||||
-import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
@@ -56,6 +_,10 @@
|
||||
private final AtomicLong operationCount = new AtomicLong();
|
||||
@Nullable
|
||||
private Executor executor;
|
||||
+ // Paper start - Fix GameProfileCache concurrency
|
||||
+ protected final java.util.concurrent.locks.ReentrantLock stateLock = new java.util.concurrent.locks.ReentrantLock();
|
||||
+ protected final java.util.concurrent.locks.ReentrantLock lookupLock = new java.util.concurrent.locks.ReentrantLock();
|
||||
+ // Paper end - Fix GameProfileCache concurrency
|
||||
|
||||
public GameProfileCache(GameProfileRepository profileRepository, File file) {
|
||||
this.profileRepository = profileRepository;
|
||||
@@ -64,10 +_,12 @@
|
||||
}
|
||||
|
||||
private void safeAdd(GameProfileCache.GameProfileInfo profile) {
|
||||
+ try { this.stateLock.lock(); // Paper - Fix GameProfileCache concurrency
|
||||
GameProfile profile1 = profile.getProfile();
|
||||
profile.setLastAccess(this.getNextOperation());
|
||||
this.profilesByName.put(profile1.getName().toLowerCase(Locale.ROOT), profile);
|
||||
this.profilesByUUID.put(profile1.getId(), profile);
|
||||
+ } finally { this.stateLock.unlock(); } // Paper - Fix GameProfileCache concurrency
|
||||
}
|
||||
|
||||
private static Optional<GameProfile> lookupGameProfile(GameProfileRepository profileRepo, String name) {
|
||||
@@ -86,6 +_,8 @@
|
||||
atomicReference.set(null);
|
||||
}
|
||||
};
|
||||
+ if (!org.apache.commons.lang3.StringUtils.isBlank(name) // Paper - Don't lookup a profile with a blank name
|
||||
+ && io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode()) // Paper - Add setting for proxy online mode status
|
||||
profileRepo.findProfilesByNames(new String[]{name}, profileLookupCallback);
|
||||
GameProfile gameProfile = atomicReference.get();
|
||||
return gameProfile != null ? Optional.of(gameProfile) : createUnknownProfile(name);
|
||||
@@ -101,7 +_,7 @@
|
||||
}
|
||||
|
||||
private static boolean usesAuthentication() {
|
||||
- return usesAuthentication;
|
||||
+ return io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode(); // Paper - Add setting for proxy online mode status
|
||||
}
|
||||
|
||||
public void add(GameProfile gameProfile) {
|
||||
@@ -111,15 +_,29 @@
|
||||
Date time = instance.getTime();
|
||||
GameProfileCache.GameProfileInfo gameProfileInfo = new GameProfileCache.GameProfileInfo(gameProfile, time);
|
||||
this.safeAdd(gameProfileInfo);
|
||||
- this.save();
|
||||
+ if(!org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) this.save(true); // Spigot - skip saving if disabled // Paper - Perf: Async GameProfileCache saving
|
||||
}
|
||||
|
||||
private long getNextOperation() {
|
||||
return this.operationCount.incrementAndGet();
|
||||
}
|
||||
|
||||
+ // Paper start
|
||||
+ public @Nullable GameProfile getProfileIfCached(String name) {
|
||||
+ try { this.stateLock.lock(); // Paper - Fix GameProfileCache concurrency
|
||||
+ GameProfileCache.GameProfileInfo entry = this.profilesByName.get(name.toLowerCase(Locale.ROOT));
|
||||
+ if (entry == null) {
|
||||
+ return null;
|
||||
+ }
|
||||
+ entry.setLastAccess(this.getNextOperation());
|
||||
+ return entry.getProfile();
|
||||
+ } finally { this.stateLock.unlock(); } // Paper - Fix GameProfileCache concurrency
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
public Optional<GameProfile> get(String name) {
|
||||
String string = name.toLowerCase(Locale.ROOT);
|
||||
+ boolean stateLocked = true; try { this.stateLock.lock(); // Paper - Fix GameProfileCache concurrency
|
||||
GameProfileCache.GameProfileInfo gameProfileInfo = this.profilesByName.get(string);
|
||||
boolean flag = false;
|
||||
if (gameProfileInfo != null && new Date().getTime() >= gameProfileInfo.expirationDate.getTime()) {
|
||||
@@ -133,19 +_,24 @@
|
||||
if (gameProfileInfo != null) {
|
||||
gameProfileInfo.setLastAccess(this.getNextOperation());
|
||||
optional = Optional.of(gameProfileInfo.getProfile());
|
||||
+ stateLocked = false; this.stateLock.unlock(); // Paper - Fix GameProfileCache concurrency
|
||||
} else {
|
||||
- optional = lookupGameProfile(this.profileRepository, string);
|
||||
+ stateLocked = false; this.stateLock.unlock(); // Paper - Fix GameProfileCache concurrency
|
||||
+ try { this.lookupLock.lock(); // Paper - Fix GameProfileCache concurrency
|
||||
+ optional = lookupGameProfile(this.profileRepository, name); // CraftBukkit - use correct case for offline players
|
||||
+ } finally { this.lookupLock.unlock(); } // Paper - Fix GameProfileCache concurrency
|
||||
if (optional.isPresent()) {
|
||||
this.add(optional.get());
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
- if (flag) {
|
||||
- this.save();
|
||||
+ if (flag && !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) { // Spigot - skip saving if disabled
|
||||
+ this.save(true); // Paper - Perf: Async GameProfileCache saving
|
||||
}
|
||||
|
||||
return optional;
|
||||
+ } finally { if (stateLocked) { this.stateLock.unlock(); } } // Paper - Fix GameProfileCache concurrency
|
||||
}
|
||||
|
||||
public CompletableFuture<Optional<GameProfile>> getAsync(String name) {
|
||||
@@ -157,7 +_,7 @@
|
||||
return completableFuture;
|
||||
} else {
|
||||
CompletableFuture<Optional<GameProfile>> completableFuture1 = CompletableFuture.<Optional<GameProfile>>supplyAsync(
|
||||
- () -> this.get(name), Util.backgroundExecutor().forName("getProfile")
|
||||
+ () -> this.get(name), Util.PROFILE_EXECUTOR // Paper - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
|
||||
)
|
||||
.whenCompleteAsync((gameProfile, exception) -> this.requests.remove(name), this.executor);
|
||||
this.requests.put(name, completableFuture1);
|
||||
@@ -167,6 +_,7 @@
|
||||
}
|
||||
|
||||
public Optional<GameProfile> get(UUID uuid) {
|
||||
+ try { this.stateLock.lock(); // Paper - Fix GameProfileCache concurrency
|
||||
GameProfileCache.GameProfileInfo gameProfileInfo = this.profilesByUUID.get(uuid);
|
||||
if (gameProfileInfo == null) {
|
||||
return Optional.empty();
|
||||
@@ -174,6 +_,7 @@
|
||||
gameProfileInfo.setLastAccess(this.getNextOperation());
|
||||
return Optional.of(gameProfileInfo.getProfile());
|
||||
}
|
||||
+ } finally { this.stateLock.unlock(); } // Paper - Fix GameProfileCache concurrency
|
||||
}
|
||||
|
||||
public void setExecutor(Executor exectutor) {
|
||||
@@ -193,7 +_,7 @@
|
||||
|
||||
try {
|
||||
Object var9;
|
||||
- try (Reader reader = Files.newReader(this.file, StandardCharsets.UTF_8)) {
|
||||
+ try (java.io.Reader reader = Files.newReader(this.file, StandardCharsets.UTF_8)) {
|
||||
JsonArray jsonArray = this.gson.fromJson(reader, JsonArray.class);
|
||||
if (jsonArray != null) {
|
||||
DateFormat dateFormat = createDateFormat();
|
||||
@@ -206,6 +_,11 @@
|
||||
|
||||
return (List<GameProfileCache.GameProfileInfo>)var9;
|
||||
} catch (FileNotFoundException var7) {
|
||||
+ // Spigot Start
|
||||
+ } catch (com.google.gson.JsonSyntaxException | NullPointerException ex) {
|
||||
+ GameProfileCache.LOGGER.warn( "Usercache.json is corrupted or has bad formatting. Deleting it to prevent further issues." );
|
||||
+ this.file.delete();
|
||||
+ // Spigot End
|
||||
} catch (JsonParseException | IOException var8) {
|
||||
LOGGER.warn("Failed to load profile cache {}", this.file, var8);
|
||||
}
|
||||
@@ -213,24 +_,45 @@
|
||||
return list;
|
||||
}
|
||||
|
||||
- public void save() {
|
||||
+ public void save(boolean asyncSave) { // Paper - Perf: Async GameProfileCache saving
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
DateFormat dateFormat = createDateFormat();
|
||||
- this.getTopMRUProfiles(1000).forEach(info -> jsonArray.add(writeGameProfile(info, dateFormat)));
|
||||
+ this.listTopMRUProfiles(org.spigotmc.SpigotConfig.userCacheCap).forEach((info) -> jsonArray.add(writeGameProfile(info, dateFormat))); // Spigot // Paper - Fix GameProfileCache concurrency
|
||||
String string = this.gson.toJson((JsonElement)jsonArray);
|
||||
+ Runnable save = () -> { // Paper - Perf: Async GameProfileCache saving
|
||||
|
||||
- try (Writer writer = Files.newWriter(this.file, StandardCharsets.UTF_8)) {
|
||||
+ try (java.io.Writer writer = Files.newWriter(this.file, StandardCharsets.UTF_8)) {
|
||||
writer.write(string);
|
||||
} catch (IOException var9) {
|
||||
}
|
||||
+ // Paper start - Perf: Async GameProfileCache saving
|
||||
+ };
|
||||
+ if (asyncSave) {
|
||||
+ io.papermc.paper.util.MCUtil.scheduleAsyncTask(save);
|
||||
+ } else {
|
||||
+ save.run();
|
||||
+ }
|
||||
+ // Paper end - Perf: Async GameProfileCache saving
|
||||
}
|
||||
|
||||
private Stream<GameProfileCache.GameProfileInfo> getTopMRUProfiles(int limit) {
|
||||
- return ImmutableList.copyOf(this.profilesByUUID.values())
|
||||
- .stream()
|
||||
- .sorted(Comparator.comparing(GameProfileCache.GameProfileInfo::getLastAccess).reversed())
|
||||
- .limit(limit);
|
||||
- }
|
||||
+ // Paper start - Fix GameProfileCache concurrency
|
||||
+ return this.listTopMRUProfiles(limit).stream();
|
||||
+ }
|
||||
+
|
||||
+ private List<GameProfileCache.GameProfileInfo> listTopMRUProfiles(int limit) {
|
||||
+ try {
|
||||
+ this.stateLock.lock();
|
||||
+ return this.profilesByUUID.values()
|
||||
+ .stream()
|
||||
+ .sorted(Comparator.comparing(GameProfileCache.GameProfileInfo::getLastAccess).reversed())
|
||||
+ .limit(limit)
|
||||
+ .toList();
|
||||
+ } finally {
|
||||
+ this.stateLock.unlock();
|
||||
+ }
|
||||
+ }
|
||||
+ // Paper end - Fix GameProfileCache concurrency
|
||||
|
||||
private static JsonElement writeGameProfile(GameProfileCache.GameProfileInfo profileInfo, DateFormat dateFormat) {
|
||||
JsonObject jsonObject = new JsonObject();
|
@@ -0,0 +1,96 @@
|
||||
--- a/net/minecraft/server/players/OldUsersConverter.java
|
||||
+++ b/net/minecraft/server/players/OldUsersConverter.java
|
||||
@@ -20,6 +_,9 @@
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.core.UUIDUtil;
|
||||
+import net.minecraft.nbt.CompoundTag;
|
||||
+import net.minecraft.nbt.NbtAccounter;
|
||||
+import net.minecraft.nbt.NbtIo;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import net.minecraft.util.StringUtil;
|
||||
@@ -49,7 +_,8 @@
|
||||
|
||||
private static void lookupPlayers(MinecraftServer server, Collection<String> names, ProfileLookupCallback callback) {
|
||||
String[] strings = names.stream().filter(name -> !StringUtil.isNullOrEmpty(name)).toArray(String[]::new);
|
||||
- if (server.usesAuthentication()) {
|
||||
+ if (server.usesAuthentication() ||
|
||||
+ (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode())) { // Spigot: bungee = online mode, for now. // Paper - Add setting for proxy online mode status
|
||||
server.getProfileRepository().findProfilesByNames(strings, callback);
|
||||
} else {
|
||||
for (String string : strings) {
|
||||
@@ -65,7 +_,7 @@
|
||||
try {
|
||||
userBanList.load();
|
||||
} catch (IOException var6) {
|
||||
- LOGGER.warn("Could not load existing file {}", userBanList.getFile().getName(), var6);
|
||||
+ LOGGER.warn("Could not load existing file {}", userBanList.getFile().getName()); // CraftBukkit - don't print stacktrace
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +_,7 @@
|
||||
try {
|
||||
ipBanList.load();
|
||||
} catch (IOException var11) {
|
||||
- LOGGER.warn("Could not load existing file {}", ipBanList.getFile().getName(), var11);
|
||||
+ LOGGER.warn("Could not load existing file {}", ipBanList.getFile().getName()); // CraftBukkit - don't print stacktrace
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +_,7 @@
|
||||
try {
|
||||
serverOpList.load();
|
||||
} catch (IOException var6) {
|
||||
- LOGGER.warn("Could not load existing file {}", serverOpList.getFile().getName(), var6);
|
||||
+ LOGGER.warn("Could not load existing file {}", serverOpList.getFile().getName()); // CraftBukkit - don't print stacktrace
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +_,7 @@
|
||||
try {
|
||||
userWhiteList.load();
|
||||
} catch (IOException var6) {
|
||||
- LOGGER.warn("Could not load existing file {}", userWhiteList.getFile().getName(), var6);
|
||||
+ LOGGER.warn("Could not load existing file {}", userWhiteList.getFile().getName()); // CraftBukkit - don't print stacktrace
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,6 +_,37 @@
|
||||
private void movePlayerFile(File file3, String oldFileName, String newFileName) {
|
||||
File file4 = new File(worldPlayersDirectory, oldFileName + ".dat");
|
||||
File file5 = new File(file3, newFileName + ".dat");
|
||||
+ // CraftBukkit start - Use old file name to seed lastKnownName
|
||||
+ CompoundTag root = null;
|
||||
+
|
||||
+ try {
|
||||
+ root = NbtIo.readCompressed(new java.io.FileInputStream(file4), NbtAccounter.unlimitedHeap());
|
||||
+ } catch (Exception exception) {
|
||||
+ // Paper start
|
||||
+ io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(exception);
|
||||
+ exception.printStackTrace();
|
||||
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(exception);
|
||||
+ // Paper end
|
||||
+ }
|
||||
+
|
||||
+ if (root != null) {
|
||||
+ if (!root.contains("bukkit")) {
|
||||
+ root.put("bukkit", new CompoundTag());
|
||||
+ }
|
||||
+ CompoundTag data = root.getCompound("bukkit");
|
||||
+ data.putString("lastKnownName", oldFileName);
|
||||
+
|
||||
+ try {
|
||||
+ NbtIo.writeCompressed(root, new java.io.FileOutputStream(file1));
|
||||
+ } catch (Exception exception) {
|
||||
+ // Paper start
|
||||
+ io.papermc.paper.util.StacktraceDeobfuscator.INSTANCE.deobfuscateThrowable(exception);
|
||||
+ exception.printStackTrace();
|
||||
+ com.destroystokyo.paper.exception.ServerInternalException.reportInternalException(exception);
|
||||
+ // Paper end
|
||||
+ }
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
OldUsersConverter.ensureDirectoryExists(file3);
|
||||
if (!file4.renameTo(file5)) {
|
||||
throw new OldUsersConverter.ConversionError("Could not convert file for " + oldFileName);
|
@@ -0,0 +1,41 @@
|
||||
--- a/net/minecraft/server/players/SleepStatus.java
|
||||
+++ b/net/minecraft/server/players/SleepStatus.java
|
||||
@@ -14,8 +_,11 @@
|
||||
}
|
||||
|
||||
public boolean areEnoughDeepSleeping(int requiredSleepPercentage, List<ServerPlayer> sleepingPlayers) {
|
||||
- int i = (int)sleepingPlayers.stream().filter(Player::isSleepingLongEnough).count();
|
||||
- return i >= this.sleepersNeeded(requiredSleepPercentage);
|
||||
+ // CraftBukkit start
|
||||
+ int i = (int) sleepingPlayers.stream().filter(player -> player.isSleepingLongEnough() || player.fauxSleeping).count();
|
||||
+ boolean anyDeepSleep = sleepingPlayers.stream().anyMatch(Player::isSleepingLongEnough);
|
||||
+ return anyDeepSleep && i >= this.sleepersNeeded(requiredSleepPercentage);
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
|
||||
public int sleepersNeeded(int requiredSleepPercentage) {
|
||||
@@ -35,16 +_,22 @@
|
||||
int i1 = this.sleepingPlayers;
|
||||
this.activePlayers = 0;
|
||||
this.sleepingPlayers = 0;
|
||||
+ boolean anySleep = false; // CraftBukkit
|
||||
|
||||
for (ServerPlayer serverPlayer : players) {
|
||||
if (!serverPlayer.isSpectator()) {
|
||||
this.activePlayers++;
|
||||
- if (serverPlayer.isSleeping()) {
|
||||
+ if (serverPlayer.isSleeping() || serverPlayer.fauxSleeping) { // CraftBukkit
|
||||
this.sleepingPlayers++;
|
||||
}
|
||||
+ // CraftBukkit start
|
||||
+ if (serverPlayer.isSleeping()) {
|
||||
+ anySleep = true;
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
}
|
||||
}
|
||||
|
||||
- return (i1 > 0 || this.sleepingPlayers > 0) && (i != this.activePlayers || i1 != this.sleepingPlayers);
|
||||
+ return anySleep && (i1 > 0 || this.sleepingPlayers > 0) && (i != this.activePlayers || i1 != this.sleepingPlayers); // CraftBukkit
|
||||
}
|
||||
}
|
@@ -0,0 +1,81 @@
|
||||
--- a/net/minecraft/server/players/StoredUserList.java
|
||||
+++ b/net/minecraft/server/players/StoredUserList.java
|
||||
@@ -26,7 +_,7 @@
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
private final File file;
|
||||
- private final Map<String, V> map = Maps.newHashMap();
|
||||
+ private final Map<String, V> map = Maps.newConcurrentMap(); // Paper - Use ConcurrentHashMap in JsonList
|
||||
|
||||
public StoredUserList(File file) {
|
||||
this.file = file;
|
||||
@@ -48,8 +_,11 @@
|
||||
|
||||
@Nullable
|
||||
public V get(K obj) {
|
||||
- this.removeExpired();
|
||||
- return this.map.get(this.getKeyForUser(obj));
|
||||
+ // Paper start - Use ConcurrentHashMap in JsonList
|
||||
+ return this.map.computeIfPresent(this.getKeyForUser(obj), (k, v) -> {
|
||||
+ return v.hasExpired() ? null : v;
|
||||
+ });
|
||||
+ // Paper end - Use ConcurrentHashMap in JsonList
|
||||
}
|
||||
|
||||
public void remove(K user) {
|
||||
@@ -71,7 +_,7 @@
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
- return this.map.size() < 1;
|
||||
+ return this.map.isEmpty(); // Paper - Use ConcurrentHashMap in JsonList
|
||||
}
|
||||
|
||||
protected String getKeyForUser(K obj) {
|
||||
@@ -79,21 +_,12 @@
|
||||
}
|
||||
|
||||
protected boolean contains(K entry) {
|
||||
+ this.removeExpired(); // CraftBukkit - SPIGOT-7589: Consistently remove expired entries to mirror .get(...)
|
||||
return this.map.containsKey(this.getKeyForUser(entry));
|
||||
}
|
||||
|
||||
private void removeExpired() {
|
||||
- List<K> list = Lists.newArrayList();
|
||||
-
|
||||
- for (V storedUserEntry : this.map.values()) {
|
||||
- if (storedUserEntry.hasExpired()) {
|
||||
- list.add(storedUserEntry.getUser());
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- for (K object : list) {
|
||||
- this.map.remove(this.getKeyForUser(object));
|
||||
- }
|
||||
+ this.map.values().removeIf(StoredUserEntry::hasExpired); // Paper - Use ConcurrentHashMap in JsonList
|
||||
}
|
||||
|
||||
protected abstract StoredUserEntry<K> createEntry(JsonObject entryData);
|
||||
@@ -103,6 +_,7 @@
|
||||
}
|
||||
|
||||
public void save() throws IOException {
|
||||
+ this.removeExpired(); // Paper - remove expired values before saving
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
this.map.values().stream().map(storedEntry -> Util.make(new JsonObject(), storedEntry::serialize)).forEach(jsonArray::add);
|
||||
|
||||
@@ -127,7 +_,14 @@
|
||||
this.map.put(this.getKeyForUser(storedUserEntry.getUser()), (V)storedUserEntry);
|
||||
}
|
||||
}
|
||||
+ // Spigot Start
|
||||
+ } catch (com.google.gson.JsonParseException | NullPointerException ex) {
|
||||
+ org.bukkit.Bukkit.getLogger().log(java.util.logging.Level.WARNING, "Unable to read file " + this.file + ", backing it up to {0}.backup and creating new copy.", ex);
|
||||
+ File backup = new File(this.file + ".backup");
|
||||
+ this.file.renameTo(backup);
|
||||
+ this.file.delete();
|
||||
}
|
||||
+ // Spigot End
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
--- a/net/minecraft/server/players/UserBanListEntry.java
|
||||
+++ b/net/minecraft/server/players/UserBanListEntry.java
|
||||
@@ -1,3 +_,4 @@
|
||||
+// mc-dev import
|
||||
package net.minecraft.server.players;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -37,19 +_,29 @@
|
||||
|
||||
@Nullable
|
||||
private static GameProfile createGameProfile(JsonObject json) {
|
||||
- if (json.has("uuid") && json.has("name")) {
|
||||
+ // Spigot start
|
||||
+ // this whole method has to be reworked to account for the fact Bukkit only accepts UUID bans and gives no way for usernames to be stored!
|
||||
+ UUID uuid = null;
|
||||
+ String name = null;
|
||||
+ if (json.has("uuid")) {
|
||||
String asString = json.get("uuid").getAsString();
|
||||
|
||||
- UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(asString);
|
||||
} catch (Throwable var4) {
|
||||
- return null;
|
||||
}
|
||||
|
||||
- return new GameProfile(uuid, json.get("name").getAsString());
|
||||
+ }
|
||||
+ if ( json.has("name"))
|
||||
+ {
|
||||
+ name = json.get("name").getAsString();
|
||||
+ }
|
||||
+ if ( uuid != null || name != null )
|
||||
+ {
|
||||
+ return new GameProfile( uuid, name );
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
+ // Spigot End
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
--- a/net/minecraft/server/players/UserWhiteList.java
|
||||
+++ b/net/minecraft/server/players/UserWhiteList.java
|
||||
@@ -28,4 +_,23 @@
|
||||
protected String getKeyForUser(GameProfile obj) {
|
||||
return obj.getId().toString();
|
||||
}
|
||||
+ // Paper start - Add whitelist events
|
||||
+ @Override
|
||||
+ public void add(UserWhiteListEntry entry) {
|
||||
+ if (!new io.papermc.paper.event.server.WhitelistStateUpdateEvent(com.destroystokyo.paper.profile.CraftPlayerProfile.asBukkitCopy(entry.getUser()), io.papermc.paper.event.server.WhitelistStateUpdateEvent.WhitelistStatus.ADDED).callEvent()) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ super.add(entry);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void remove(GameProfile profile) {
|
||||
+ if (!new io.papermc.paper.event.server.WhitelistStateUpdateEvent(com.destroystokyo.paper.profile.CraftPlayerProfile.asBukkitCopy(profile), io.papermc.paper.event.server.WhitelistStateUpdateEvent.WhitelistStatus.REMOVED).callEvent()) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ super.remove(profile);
|
||||
+ }
|
||||
+ // Paper end - Add whitelist events
|
||||
}
|
Reference in New Issue
Block a user