Use Provided Case for Non Existent Offline Players.

Fixes issues with using scoreboards to provide information via pseudo players being all lower cased.

By: md_5 <git@md-5.net>
This commit is contained in:
Spigot 2014-04-14 09:47:44 +10:00
parent 3ffe018032
commit b6ad1541ce
8 changed files with 419 additions and 9 deletions

View file

@ -1,9 +1,104 @@
From 97931158dba30a063fcac2dccac4be91e89f6fb3 Mon Sep 17 00:00:00 2001
From eadd6050bbe94c461d8664a57f5c43073ceee139 Mon Sep 17 00:00:00 2001
From: md_5 <md_5@live.com.au>
Date: Sun, 1 Dec 2013 15:10:48 +1100
Subject: [PATCH] mc-dev imports
diff --git a/src/main/java/net/minecraft/server/BanEntrySerializer.java b/src/main/java/net/minecraft/server/BanEntrySerializer.java
new file mode 100644
index 0000000..3b4b596
--- /dev/null
+++ b/src/main/java/net/minecraft/server/BanEntrySerializer.java
@@ -0,0 +1,89 @@
+package net.minecraft.server;
+
+import java.lang.reflect.Type;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.UUID;
+
+import net.minecraft.util.com.google.gson.JsonDeserializationContext;
+import net.minecraft.util.com.google.gson.JsonDeserializer;
+import net.minecraft.util.com.google.gson.JsonElement;
+import net.minecraft.util.com.google.gson.JsonObject;
+import net.minecraft.util.com.google.gson.JsonSerializationContext;
+import net.minecraft.util.com.google.gson.JsonSerializer;
+import net.minecraft.util.com.mojang.authlib.GameProfile;
+
+class BanEntrySerializer implements JsonDeserializer, JsonSerializer {
+
+ final UserCache a;
+
+ private BanEntrySerializer(UserCache usercache) {
+ this.a = usercache;
+ }
+
+ public JsonElement a(UserCacheEntry usercacheentry, Type type, JsonSerializationContext jsonserializationcontext) {
+ JsonObject jsonobject = new JsonObject();
+
+ jsonobject.addProperty("name", usercacheentry.a().getName());
+ UUID uuid = usercacheentry.a().getId();
+
+ jsonobject.addProperty("uuid", uuid == null ? "" : uuid.toString());
+ jsonobject.addProperty("expiresOn", UserCache.a.format(usercacheentry.b()));
+ return jsonobject;
+ }
+
+ public UserCacheEntry a(JsonElement jsonelement, Type type, JsonDeserializationContext jsondeserializationcontext) {
+ if (jsonelement.isJsonObject()) {
+ JsonObject jsonobject = jsonelement.getAsJsonObject();
+ JsonElement jsonelement1 = jsonobject.get("name");
+ JsonElement jsonelement2 = jsonobject.get("uuid");
+ JsonElement jsonelement3 = jsonobject.get("expiresOn");
+
+ if (jsonelement1 != null && jsonelement2 != null) {
+ String s = jsonelement2.getAsString();
+ String s1 = jsonelement1.getAsString();
+ Date date = null;
+
+ if (jsonelement3 != null) {
+ try {
+ date = UserCache.a.parse(jsonelement3.getAsString());
+ } catch (ParseException parseexception) {
+ date = null;
+ }
+ }
+
+ if (s1 != null && s != null) {
+ UUID uuid;
+
+ try {
+ uuid = UUID.fromString(s);
+ } catch (Throwable throwable) {
+ return null;
+ }
+
+ UserCacheEntry usercacheentry = new UserCacheEntry(this.a, new GameProfile(uuid, s1), date, (GameProfileLookup) null);
+
+ return usercacheentry;
+ } else {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ public JsonElement serialize(Object object, Type type, JsonSerializationContext jsonserializationcontext) {
+ return this.a((UserCacheEntry) object, type, jsonserializationcontext);
+ }
+
+ public Object deserialize(JsonElement jsonelement, Type type, JsonDeserializationContext jsondeserializationcontext) {
+ return this.a(jsonelement, type, jsondeserializationcontext);
+ }
+
+ BanEntrySerializer(UserCache usercache, GameProfileLookup gameprofilelookup) {
+ this(usercache);
+ }
+}
diff --git a/src/main/java/net/minecraft/server/BiomeDecorator.java b/src/main/java/net/minecraft/server/BiomeDecorator.java
new file mode 100644
index 0000000..b048d6c
@ -2611,6 +2706,299 @@ index 0000000..97308d0
+
+ protected abstract StructureStart b(int i, int j);
+}
diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java
new file mode 100644
index 0000000..cde2651
--- /dev/null
+++ b/src/main/java/net/minecraft/server/UserCache.java
@@ -0,0 +1,247 @@
+package net.minecraft.server;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.lang.reflect.ParameterizedType;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.UUID;
+
+import net.minecraft.util.com.google.common.base.Charsets;
+import net.minecraft.util.com.google.common.collect.Iterators;
+import net.minecraft.util.com.google.common.collect.Lists;
+import net.minecraft.util.com.google.common.collect.Maps;
+import net.minecraft.util.com.google.common.io.Files;
+import net.minecraft.util.com.google.gson.Gson;
+import net.minecraft.util.com.google.gson.GsonBuilder;
+import net.minecraft.util.com.mojang.authlib.Agent;
+import net.minecraft.util.com.mojang.authlib.GameProfile;
+import net.minecraft.util.org.apache.commons.io.IOUtils;
+
+public class UserCache {
+
+ public static final SimpleDateFormat a = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
+ private final Map c = Maps.newHashMap();
+ private final Map d = Maps.newHashMap();
+ private final LinkedList e = Lists.newLinkedList();
+ private final MinecraftServer f;
+ protected final Gson b;
+ private final File g;
+ private static final ParameterizedType h = new UserCacheEntryType();
+
+ public UserCache(MinecraftServer minecraftserver, File file1) {
+ this.f = minecraftserver;
+ this.g = file1;
+ GsonBuilder gsonbuilder = new GsonBuilder();
+
+ gsonbuilder.registerTypeHierarchyAdapter(UserCacheEntry.class, new BanEntrySerializer(this, (GameProfileLookup) null));
+ this.b = gsonbuilder.create();
+ this.b();
+ }
+
+ private static GameProfile a(MinecraftServer minecraftserver, String s) {
+ GameProfile[] agameprofile = new GameProfile[1];
+ GameProfileLookup gameprofilelookup = new GameProfileLookup(agameprofile);
+
+ minecraftserver.getGameProfileRepository().findProfilesByNames(new String[] { s}, Agent.MINECRAFT, gameprofilelookup);
+ if (!minecraftserver.getOnlineMode() && agameprofile[0] == null) {
+ UUID uuid = EntityHuman.a(new GameProfile((UUID) null, s));
+ GameProfile gameprofile = new GameProfile(uuid, s);
+
+ gameprofilelookup.onProfileLookupSucceeded(gameprofile);
+ }
+
+ return agameprofile[0];
+ }
+
+ public void a(GameProfile gameprofile) {
+ this.a(gameprofile, (Date) null);
+ }
+
+ private void a(GameProfile gameprofile, Date date) {
+ UUID uuid = gameprofile.getId();
+
+ if (date == null) {
+ Calendar calendar = Calendar.getInstance();
+
+ calendar.setTime(new Date());
+ calendar.add(2, 1);
+ date = calendar.getTime();
+ }
+
+ String s = gameprofile.getName().toLowerCase(Locale.ROOT);
+ UserCacheEntry usercacheentry = new UserCacheEntry(this, gameprofile, date, (GameProfileLookup) null);
+ LinkedList linkedlist = this.e;
+
+ synchronized (this.e) {
+ if (this.d.containsKey(uuid)) {
+ UserCacheEntry usercacheentry1 = (UserCacheEntry) this.d.get(uuid);
+
+ this.c.remove(usercacheentry1.a().getName().toLowerCase(Locale.ROOT));
+ this.c.put(gameprofile.getName().toLowerCase(Locale.ROOT), usercacheentry);
+ this.e.remove(gameprofile);
+ } else {
+ this.d.put(uuid, usercacheentry);
+ this.c.put(s, usercacheentry);
+ }
+
+ this.e.addFirst(gameprofile);
+ }
+ }
+
+ public GameProfile a(String s) {
+ String s1 = s.toLowerCase(Locale.ROOT);
+ UserCacheEntry usercacheentry = (UserCacheEntry) this.c.get(s1);
+
+ if (usercacheentry != null && (new Date()).getTime() >= UserCacheEntry.a(usercacheentry).getTime()) {
+ this.d.remove(usercacheentry.a().getId());
+ this.c.remove(usercacheentry.a().getName().toLowerCase(Locale.ROOT));
+ LinkedList linkedlist = this.e;
+
+ synchronized (this.e) {
+ this.e.remove(usercacheentry.a());
+ }
+
+ usercacheentry = null;
+ }
+
+ GameProfile gameprofile;
+
+ if (usercacheentry != null) {
+ gameprofile = usercacheentry.a();
+ LinkedList linkedlist1 = this.e;
+
+ synchronized (this.e) {
+ this.e.remove(gameprofile);
+ this.e.addFirst(gameprofile);
+ }
+ } else {
+ gameprofile = a(this.f, s1);
+ if (gameprofile != null) {
+ this.a(gameprofile);
+ usercacheentry = (UserCacheEntry) this.c.get(s1);
+ }
+ }
+
+ this.c();
+ return usercacheentry == null ? null : usercacheentry.a();
+ }
+
+ public String[] a() {
+ ArrayList arraylist = Lists.newArrayList(this.c.keySet());
+
+ return (String[]) arraylist.toArray(new String[arraylist.size()]);
+ }
+
+ public GameProfile a(UUID uuid) {
+ UserCacheEntry usercacheentry = (UserCacheEntry) this.d.get(uuid);
+
+ return usercacheentry == null ? null : usercacheentry.a();
+ }
+
+ private UserCacheEntry b(UUID uuid) {
+ UserCacheEntry usercacheentry = (UserCacheEntry) this.d.get(uuid);
+
+ if (usercacheentry != null) {
+ GameProfile gameprofile = usercacheentry.a();
+ LinkedList linkedlist = this.e;
+
+ synchronized (this.e) {
+ this.e.remove(gameprofile);
+ this.e.addFirst(gameprofile);
+ }
+ }
+
+ return usercacheentry;
+ }
+
+ public void b() {
+ List list = null;
+ BufferedReader bufferedreader = null;
+
+ label81: {
+ try {
+ bufferedreader = Files.newReader(this.g, Charsets.UTF_8);
+ list = (List) this.b.fromJson(bufferedreader, h);
+ break label81;
+ } catch (FileNotFoundException filenotfoundexception) {
+ ;
+ } finally {
+ IOUtils.closeQuietly(bufferedreader);
+ }
+
+ return;
+ }
+
+ if (list != null) {
+ this.c.clear();
+ this.d.clear();
+ LinkedList linkedlist = this.e;
+
+ synchronized (this.e) {
+ this.e.clear();
+ }
+
+ list = Lists.reverse(list);
+ Iterator iterator = list.iterator();
+
+ while (iterator.hasNext()) {
+ UserCacheEntry usercacheentry = (UserCacheEntry) iterator.next();
+
+ if (usercacheentry != null) {
+ this.a(usercacheentry.a(), usercacheentry.b());
+ }
+ }
+ }
+ }
+
+ public void c() {
+ String s = this.b.toJson(this.a(1000));
+ BufferedWriter bufferedwriter = null;
+
+ try {
+ bufferedwriter = Files.newWriter(this.g, Charsets.UTF_8);
+ bufferedwriter.write(s);
+ return;
+ } catch (FileNotFoundException filenotfoundexception) {
+ ;
+ } catch (IOException ioexception) {
+ return;
+ } finally {
+ IOUtils.closeQuietly(bufferedwriter);
+ }
+ }
+
+ private List a(int i) {
+ ArrayList arraylist = Lists.newArrayList();
+ LinkedList linkedlist = this.e;
+ ArrayList arraylist1;
+
+ synchronized (this.e) {
+ arraylist1 = Lists.newArrayList(Iterators.limit(this.e.iterator(), i));
+ }
+
+ Iterator iterator = arraylist1.iterator();
+
+ while (iterator.hasNext()) {
+ GameProfile gameprofile = (GameProfile) iterator.next();
+ UserCacheEntry usercacheentry = this.b(gameprofile.getId());
+
+ if (usercacheentry != null) {
+ arraylist.add(usercacheentry);
+ }
+ }
+
+ return arraylist;
+ }
+}
diff --git a/src/main/java/net/minecraft/server/UserCacheEntry.java b/src/main/java/net/minecraft/server/UserCacheEntry.java
new file mode 100644
index 0000000..fe129a5
--- /dev/null
+++ b/src/main/java/net/minecraft/server/UserCacheEntry.java
@@ -0,0 +1,34 @@
+package net.minecraft.server;
+
+import java.util.Date;
+
+import net.minecraft.util.com.mojang.authlib.GameProfile;
+
+class UserCacheEntry {
+
+ private final GameProfile b;
+ private final Date c;
+ final UserCache a;
+
+ private UserCacheEntry(UserCache usercache, GameProfile gameprofile, Date date) {
+ this.a = usercache;
+ this.b = gameprofile;
+ this.c = date;
+ }
+
+ public GameProfile a() {
+ return this.b;
+ }
+
+ public Date b() {
+ return this.c;
+ }
+
+ UserCacheEntry(UserCache usercache, GameProfile gameprofile, Date date, GameProfileLookup gameprofilelookup) {
+ this(usercache, gameprofile, date);
+ }
+
+ static Date a(UserCacheEntry usercacheentry) {
+ return usercacheentry.c;
+ }
+}
diff --git a/src/main/java/net/minecraft/server/WatchableObject.java b/src/main/java/net/minecraft/server/WatchableObject.java
new file mode 100644
index 0000000..678aa91

View file

@ -1,4 +1,4 @@
From 5f845fafc84f7bb01c14e3660f611ca08594bd19 Mon Sep 17 00:00:00 2001
From 8e9683aa649d7c7a0e153b36e60b014defd14812 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Sat, 12 Apr 2014 21:37:12 +1000
Subject: [PATCH] Update Warning
@ -52,5 +52,5 @@ index 008e037..f70db91 100644
OptionParser parser = new OptionParser() {
{
--
1.8.5.2.msysgit.0
1.8.3.2

View file

@ -1,4 +1,4 @@
From 90b1f7d48ce83095e05c2c79bc4bf3921acb66c3 Mon Sep 17 00:00:00 2001
From 790f35890a93bdcc29adb7e0236fb0b83a27b65a Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Sat, 12 Apr 2014 23:30:44 +1000
Subject: [PATCH] Add Conversion Message
@ -17,5 +17,5 @@ index befcdbd..ca7805c 100644
int i;
--
1.8.5.2.msysgit.0
1.8.3.2

View file

@ -1,4 +1,4 @@
From c72b56ce01b9737d0afe6c5a1cb3f82f99ba7238 Mon Sep 17 00:00:00 2001
From 8c41285822798269576483bffed909f913dda5a6 Mon Sep 17 00:00:00 2001
From: "gjmcferrin@gmail.com" <gjmcferrin@gmail.com>
Date: Mon, 10 Feb 2014 10:05:11 -0500
Subject: [PATCH] Properly cancel fishing event. Fixes BUKKIT-5396

View file

@ -1,4 +1,4 @@
From 892218d826551eb7273e3627190d945e37abec90 Mon Sep 17 00:00:00 2001
From 9f04ea45a7c95c062178209c3c3515c7b6194e64 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Sun, 13 Apr 2014 09:00:59 +1000
Subject: [PATCH] Print Stack on InternalException

View file

@ -1,4 +1,4 @@
From a5991905982ab3d4eee97b4b7e59771d5c17ddbf Mon Sep 17 00:00:00 2001
From 86afedb3bfc6d335774c04ee426ddaf94b3121ef Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Sun, 13 Apr 2014 14:41:23 +1000
Subject: [PATCH] Use Offline Player Data Once if Required.

View file

@ -1,4 +1,4 @@
From f7dccc2c54779dd1fb90bb73ab9892ace3b8ff91 Mon Sep 17 00:00:00 2001
From ebc877daab1dd0cb4ee8bec504681606342b0473 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Sun, 13 Apr 2014 14:45:57 +1000
Subject: [PATCH] Use Correct firstPlayed Value.

View file

@ -0,0 +1,22 @@
From d5b3d7663e7b6283eed246a736d507f54ddcedb9 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
Date: Mon, 14 Apr 2014 09:46:20 +1000
Subject: [PATCH] Use Provided Case for Non Existent Offline Players
diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java
index cde2651..bcccaa9 100644
--- a/src/main/java/net/minecraft/server/UserCache.java
+++ b/src/main/java/net/minecraft/server/UserCache.java
@@ -126,7 +126,7 @@ public class UserCache {
this.e.addFirst(gameprofile);
}
} else {
- gameprofile = a(this.f, s1);
+ gameprofile = a(this.f, s); // Spigot - use correct case for offline players
if (gameprofile != null) {
this.a(gameprofile);
usercacheentry = (UserCacheEntry) this.c.get(s1);
--
1.8.3.2