13
0
geforkt von Mirrors/Paper

More improvements to PlayerProfile code

.equals() was wrong
clean up createPlayerProfile code
don't set profile to null if the complete call fails
Dieser Commit ist enthalten in:
Aikar 2018-03-22 21:56:18 -04:00
Ursprung 1b8ea6f3bb
Commit 855f21c54e

Datei anzeigen

@ -6,7 +6,7 @@ Subject: [PATCH] Basic PlayerProfile API
diff --git a/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java diff --git a/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java
new file mode 100644 new file mode 100644
index 000000000..616a7b218 index 000000000..63782747c
--- /dev/null --- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java +++ b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java
@@ -0,0 +0,0 @@ @@ -0,0 +0,0 @@
@ -18,7 +18,6 @@ index 000000000..616a7b218
+import com.mojang.authlib.properties.Property; +import com.mojang.authlib.properties.Property;
+import com.mojang.authlib.properties.PropertyMap; +import com.mojang.authlib.properties.PropertyMap;
+import net.minecraft.server.MinecraftServer; +import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.UserCache;
+import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.spigotmc.SpigotConfig; +import org.spigotmc.SpigotConfig;
+ +
@ -27,6 +26,7 @@ index 000000000..616a7b218
+import java.util.AbstractSet; +import java.util.AbstractSet;
+import java.util.Collection; +import java.util.Collection;
+import java.util.Iterator; +import java.util.Iterator;
+import java.util.Objects;
+import java.util.Set; +import java.util.Set;
+import java.util.UUID; +import java.util.UUID;
+ +
@ -49,27 +49,18 @@ index 000000000..616a7b218
+ +
+ private static GameProfile createGameProfile(UUID id, String name) { + private static GameProfile createGameProfile(UUID id, String name) {
+ new GameProfile(id, name); // Validate that both are not null + new GameProfile(id, name); // Validate that both are not null
+ MinecraftServer server = MinecraftServer.getServer();
+ UserCache userCache = server.getUserCache();
+ GameProfile profile; + GameProfile profile;
+ +
+ if (id == null) { + if (id == null) {
+ profile = getProfileByName(name); + profile = getProfileByName(name);
+ if (profile != null) {
+ id = profile.getId();
+ }
+ } else { + } else {
+ profile = userCache.getProfile(id); + profile = MinecraftServer.getServer().getUserCache().getProfile(id);
+ if (profile != null) {
+ name = profile.getName();
+ }
+ } + }
+ +
+ GameProfile resultProfile = new GameProfile(id, name); + if (profile == null) {
+ if (profile != null) { + profile = new GameProfile(id, name);
+ copyProfileProperties(profile, resultProfile);
+ } + }
+ return resultProfile; + return profile;
+ } + }
+ +
+ private static GameProfile getProfileByName(String name) { + private static GameProfile getProfileByName(String name) {
@ -130,10 +121,11 @@ index 000000000..616a7b218
+ MinecraftServer server = MinecraftServer.getServer(); + MinecraftServer server = MinecraftServer.getServer();
+ String name = profile.getName(); + String name = profile.getName();
+ if (profile.getId() == null) { + if (profile.getId() == null) {
+ profile = getProfileByName(name); + GameProfile profile = getProfileByName(name);
+ if (profile == null) { + if (profile == null) {
+ throw new NullPointerException("Could not get UUID for Player " + name); + throw new NullPointerException("Could not get UUID for Player " + name);
+ } + }
+ this.profile = profile;
+ } + }
+ if (!profile.isComplete() || (textures && !hasTextures())) { + if (!profile.isComplete() || (textures && !hasTextures())) {
+ GameProfile result = server.getSessionService().fillProfileProperties(profile, true); + GameProfile result = server.getSessionService().fillProfileProperties(profile, true);
@ -196,7 +188,10 @@ index 000000000..616a7b218
+ +
+ @Override + @Override
+ public boolean equals(Object o) { + public boolean equals(Object o) {
+ return profile.equals(o); + if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ CraftPlayerProfile that = (CraftPlayerProfile) o;
+ return Objects.equals(profile, that.profile);
+ } + }
+ +
+ @Override + @Override