Gintarus

PlayerProfileCache

Jul 1st, 2025
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.34 KB | None | 0 0
  1. package net.minecraft.server.management;
  2.  
  3. import com.google.common.base.Charsets;
  4. import com.google.common.collect.Iterators;
  5. import com.google.common.collect.Lists;
  6. import com.google.common.collect.Maps;
  7. import com.google.common.io.Files;
  8. import com.google.gson.Gson;
  9. import com.google.gson.GsonBuilder;
  10. import com.google.gson.JsonDeserializationContext;
  11. import com.google.gson.JsonDeserializer;
  12. import com.google.gson.JsonElement;
  13. import com.google.gson.JsonObject;
  14. import com.google.gson.JsonSerializationContext;
  15. import com.google.gson.JsonSerializer;
  16. import com.mojang.authlib.Agent;
  17. import com.mojang.authlib.GameProfile;
  18. import com.mojang.authlib.ProfileLookupCallback;
  19. import java.io.BufferedReader;
  20. import java.io.BufferedWriter;
  21. import java.io.File;
  22. import java.io.FileNotFoundException;
  23. import java.io.IOException;
  24. import java.lang.reflect.ParameterizedType;
  25. import java.lang.reflect.Type;
  26. import java.text.ParseException;
  27. import java.text.SimpleDateFormat;
  28. import java.util.ArrayList;
  29. import java.util.Calendar;
  30. import java.util.Date;
  31. import java.util.Iterator;
  32. import java.util.LinkedList;
  33. import java.util.List;
  34. import java.util.Locale;
  35. import java.util.Map;
  36. import java.util.UUID;
  37. import net.minecraft.entity.player.EntityPlayer;
  38. import net.minecraft.server.MinecraftServer;
  39. import org.apache.commons.io.IOUtils;
  40.  
  41. public class PlayerProfileCache
  42. {
  43. public static final SimpleDateFormat field_152659_a = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
  44. private final Map field_152661_c = Maps.newHashMap();
  45. private final Map field_152662_d = Maps.newHashMap();
  46. private final LinkedList field_152663_e = Lists.newLinkedList();
  47. private final MinecraftServer field_152664_f;
  48. protected final Gson field_152660_b;
  49. private final File field_152665_g;
  50. private static final ParameterizedType field_152666_h = new ParameterizedType()
  51. {
  52. private static final String __OBFID = "CL_00001886";
  53. public Type[] getActualTypeArguments()
  54. {
  55. return new Type[] {PlayerProfileCache.ProfileEntry.class};
  56. }
  57. public Type getRawType()
  58. {
  59. return List.class;
  60. }
  61. public Type getOwnerType()
  62. {
  63. return null;
  64. }
  65. };
  66. private static final String __OBFID = "CL_00001888";
  67.  
  68. public PlayerProfileCache(MinecraftServer p_i1171_1_, File p_i1171_2_)
  69. {
  70. this.field_152664_f = p_i1171_1_;
  71. this.field_152665_g = p_i1171_2_;
  72. GsonBuilder var3 = new GsonBuilder();
  73. var3.registerTypeHierarchyAdapter(PlayerProfileCache.ProfileEntry.class, new PlayerProfileCache.Serializer(null));
  74. this.field_152660_b = var3.create();
  75. this.func_152657_b();
  76. }
  77.  
  78. private static GameProfile func_152650_a(MinecraftServer p_152650_0_, String p_152650_1_)
  79. {
  80. final GameProfile[] var2 = new GameProfile[1];
  81. ProfileLookupCallback var3 = new ProfileLookupCallback()
  82. {
  83. private static final String __OBFID = "CL_00001887";
  84. public void onProfileLookupSucceeded(GameProfile p_onProfileLookupSucceeded_1_)
  85. {
  86. var2[0] = p_onProfileLookupSucceeded_1_;
  87. }
  88. public void onProfileLookupFailed(GameProfile p_onProfileLookupFailed_1_, Exception p_onProfileLookupFailed_2_)
  89. {
  90. var2[0] = null;
  91. }
  92. };
  93. p_152650_0_.func_152359_aw().findProfilesByNames(new String[] {p_152650_1_}, Agent.MINECRAFT, var3);
  94.  
  95. if (!p_152650_0_.isServerInOnlineMode() && var2[0] == null)
  96. {
  97. UUID var4 = EntityPlayer.func_146094_a(new GameProfile((UUID)null, p_152650_1_));
  98. GameProfile var5 = new GameProfile(var4, p_152650_1_);
  99. var3.onProfileLookupSucceeded(var5);
  100. }
  101.  
  102. return var2[0];
  103. }
  104.  
  105. public void func_152649_a(GameProfile p_152649_1_)
  106. {
  107. this.func_152651_a(p_152649_1_, (Date)null);
  108. }
  109.  
  110. private void func_152651_a(GameProfile p_152651_1_, Date p_152651_2_)
  111. {
  112. UUID var3 = p_152651_1_.getId();
  113.  
  114. if (p_152651_2_ == null)
  115. {
  116. Calendar var4 = Calendar.getInstance();
  117. var4.setTime(new Date());
  118. var4.add(2, 1);
  119. p_152651_2_ = var4.getTime();
  120. }
  121.  
  122. String var10 = p_152651_1_.getName().toLowerCase(Locale.ROOT);
  123. PlayerProfileCache.ProfileEntry var5 = new PlayerProfileCache.ProfileEntry(p_152651_1_, p_152651_2_, null);
  124. LinkedList var6 = this.field_152663_e;
  125.  
  126. synchronized (this.field_152663_e)
  127. {
  128. if (this.field_152662_d.containsKey(var3))
  129. {
  130. PlayerProfileCache.ProfileEntry var7 = (PlayerProfileCache.ProfileEntry)this.field_152662_d.get(var3);
  131. this.field_152661_c.remove(var7.func_152668_a().getName().toLowerCase(Locale.ROOT));
  132. this.field_152661_c.put(p_152651_1_.getName().toLowerCase(Locale.ROOT), var5);
  133. this.field_152663_e.remove(p_152651_1_);
  134. }
  135. else
  136. {
  137. this.field_152662_d.put(var3, var5);
  138. this.field_152661_c.put(var10, var5);
  139. }
  140.  
  141. this.field_152663_e.addFirst(p_152651_1_);
  142. }
  143. }
  144.  
  145. public GameProfile func_152655_a(String p_152655_1_)
  146. {
  147. String var2 = p_152655_1_.toLowerCase(Locale.ROOT);
  148. PlayerProfileCache.ProfileEntry var3 = (PlayerProfileCache.ProfileEntry)this.field_152661_c.get(var2);
  149.  
  150. if (var3 != null && (new Date()).getTime() >= var3.field_152673_c.getTime())
  151. {
  152. this.field_152662_d.remove(var3.func_152668_a().getId());
  153. this.field_152661_c.remove(var3.func_152668_a().getName().toLowerCase(Locale.ROOT));
  154. LinkedList var4 = this.field_152663_e;
  155.  
  156. synchronized (this.field_152663_e)
  157. {
  158. this.field_152663_e.remove(var3.func_152668_a());
  159. }
  160.  
  161. var3 = null;
  162. }
  163.  
  164. GameProfile var9;
  165.  
  166. if (var3 != null)
  167. {
  168. var9 = var3.func_152668_a();
  169. LinkedList var5 = this.field_152663_e;
  170.  
  171. synchronized (this.field_152663_e)
  172. {
  173. this.field_152663_e.remove(var9);
  174. this.field_152663_e.addFirst(var9);
  175. }
  176. }
  177. else
  178. {
  179. var9 = func_152650_a(this.field_152664_f, var2);
  180.  
  181. if (var9 != null)
  182. {
  183. this.func_152649_a(var9);
  184. var3 = (PlayerProfileCache.ProfileEntry)this.field_152661_c.get(var2);
  185. }
  186. }
  187.  
  188. this.func_152658_c();
  189. return var3 == null ? null : var3.func_152668_a();
  190. }
  191.  
  192. public String[] func_152654_a()
  193. {
  194. ArrayList var1 = Lists.newArrayList(this.field_152661_c.keySet());
  195. return (String[])var1.toArray(new String[var1.size()]);
  196. }
  197.  
  198. public GameProfile func_152652_a(UUID p_152652_1_)
  199. {
  200. PlayerProfileCache.ProfileEntry var2 = (PlayerProfileCache.ProfileEntry)this.field_152662_d.get(p_152652_1_);
  201. return var2 == null ? null : var2.func_152668_a();
  202. }
  203.  
  204. private PlayerProfileCache.ProfileEntry func_152653_b(UUID p_152653_1_)
  205. {
  206. PlayerProfileCache.ProfileEntry var2 = (PlayerProfileCache.ProfileEntry)this.field_152662_d.get(p_152653_1_);
  207.  
  208. if (var2 != null)
  209. {
  210. GameProfile var3 = var2.func_152668_a();
  211. LinkedList var4 = this.field_152663_e;
  212.  
  213. synchronized (this.field_152663_e)
  214. {
  215. this.field_152663_e.remove(var3);
  216. this.field_152663_e.addFirst(var3);
  217. }
  218. }
  219.  
  220. return var2;
  221. }
  222.  
  223. public void func_152657_b()
  224. {
  225. List var1 = null;
  226. BufferedReader var2 = null;
  227. label81:
  228. {
  229. try
  230. {
  231. var2 = Files.newReader(this.field_152665_g, Charsets.UTF_8);
  232. var1 = (List)this.field_152660_b.fromJson(var2, field_152666_h);
  233. break label81;
  234. }
  235. catch (FileNotFoundException var10)
  236. {
  237. ;
  238. }
  239. finally
  240. {
  241. IOUtils.closeQuietly(var2);
  242. }
  243.  
  244. return;
  245. }
  246.  
  247. if (var1 != null)
  248. {
  249. this.field_152661_c.clear();
  250. this.field_152662_d.clear();
  251. LinkedList var3 = this.field_152663_e;
  252.  
  253. synchronized (this.field_152663_e)
  254. {
  255. this.field_152663_e.clear();
  256. }
  257.  
  258. var1 = Lists.reverse(var1);
  259. Iterator var12 = var1.iterator();
  260.  
  261. while (var12.hasNext())
  262. {
  263. PlayerProfileCache.ProfileEntry var4 = (PlayerProfileCache.ProfileEntry)var12.next();
  264.  
  265. if (var4 != null)
  266. {
  267. this.func_152651_a(var4.func_152668_a(), var4.func_152670_b());
  268. }
  269. }
  270. }
  271. }
  272.  
  273. public void func_152658_c()
  274. {
  275. String var1 = this.field_152660_b.toJson(this.func_152656_a(1000));
  276. BufferedWriter var2 = null;
  277.  
  278. try
  279. {
  280. var2 = Files.newWriter(this.field_152665_g, Charsets.UTF_8);
  281. var2.write(var1);
  282. return;
  283. }
  284. catch (FileNotFoundException var8)
  285. {
  286. return;
  287. }
  288. catch (IOException var9)
  289. {
  290. ;
  291. }
  292. finally
  293. {
  294. IOUtils.closeQuietly(var2);
  295. }
  296. }
  297.  
  298. private List func_152656_a(int p_152656_1_)
  299. {
  300. ArrayList var2 = Lists.newArrayList();
  301. LinkedList var4 = this.field_152663_e;
  302. ArrayList var3;
  303.  
  304. synchronized (this.field_152663_e)
  305. {
  306. var3 = Lists.newArrayList(Iterators.limit(this.field_152663_e.iterator(), p_152656_1_));
  307. }
  308.  
  309. Iterator var8 = var3.iterator();
  310.  
  311. while (var8.hasNext())
  312. {
  313. GameProfile var5 = (GameProfile)var8.next();
  314. PlayerProfileCache.ProfileEntry var6 = this.func_152653_b(var5.getId());
  315.  
  316. if (var6 != null)
  317. {
  318. var2.add(var6);
  319. }
  320. }
  321.  
  322. return var2;
  323. }
  324.  
  325. class ProfileEntry
  326. {
  327. private final GameProfile field_152672_b;
  328. private final Date field_152673_c;
  329. private static final String __OBFID = "CL_00001885";
  330.  
  331. private ProfileEntry(GameProfile p_i46333_2_, Date p_i46333_3_)
  332. {
  333. this.field_152672_b = p_i46333_2_;
  334. this.field_152673_c = p_i46333_3_;
  335. }
  336.  
  337. public GameProfile func_152668_a()
  338. {
  339. return this.field_152672_b;
  340. }
  341.  
  342. public Date func_152670_b()
  343. {
  344. return this.field_152673_c;
  345. }
  346.  
  347. ProfileEntry(GameProfile p_i1166_2_, Date p_i1166_3_, Object p_i1166_4_)
  348. {
  349. this(p_i1166_2_, p_i1166_3_);
  350. }
  351. }
  352.  
  353. class Serializer implements JsonDeserializer, JsonSerializer
  354. {
  355. private static final String __OBFID = "CL_00001884";
  356.  
  357. private Serializer() {}
  358.  
  359. public JsonElement func_152676_a(PlayerProfileCache.ProfileEntry p_152676_1_, Type p_152676_2_, JsonSerializationContext p_152676_3_)
  360. {
  361. JsonObject var4 = new JsonObject();
  362. var4.addProperty("name", p_152676_1_.func_152668_a().getName());
  363. UUID var5 = p_152676_1_.func_152668_a().getId();
  364. var4.addProperty("uuid", var5 == null ? "" : var5.toString());
  365. var4.addProperty("expiresOn", PlayerProfileCache.field_152659_a.format(p_152676_1_.func_152670_b()));
  366. return var4;
  367. }
  368.  
  369. public PlayerProfileCache.ProfileEntry func_152675_a(JsonElement p_152675_1_, Type p_152675_2_, JsonDeserializationContext p_152675_3_)
  370. {
  371. if (p_152675_1_.isJsonObject())
  372. {
  373. JsonObject var4 = p_152675_1_.getAsJsonObject();
  374. JsonElement var5 = var4.get("name");
  375. JsonElement var6 = var4.get("uuid");
  376. JsonElement var7 = var4.get("expiresOn");
  377.  
  378. if (var5 != null && var6 != null)
  379. {
  380. String var8 = var6.getAsString();
  381. String var9 = var5.getAsString();
  382. Date var10 = null;
  383.  
  384. if (var7 != null)
  385. {
  386. try
  387. {
  388. var10 = PlayerProfileCache.field_152659_a.parse(var7.getAsString());
  389. }
  390. catch (ParseException var14)
  391. {
  392. var10 = null;
  393. }
  394. }
  395.  
  396. if (var9 != null && var8 != null)
  397. {
  398. UUID var11;
  399.  
  400. try
  401. {
  402. var11 = UUID.fromString(var8);
  403. }
  404. catch (Throwable var13)
  405. {
  406. return null;
  407. }
  408.  
  409. PlayerProfileCache.ProfileEntry var12 = PlayerProfileCache.this.new ProfileEntry(new GameProfile(var11, var9), var10, null);
  410. return var12;
  411. }
  412. else
  413. {
  414. return null;
  415. }
  416. }
  417. else
  418. {
  419. return null;
  420. }
  421. }
  422. else
  423. {
  424. return null;
  425. }
  426. }
  427.  
  428. public JsonElement serialize(Object p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
  429. {
  430. return this.func_152676_a((PlayerProfileCache.ProfileEntry)p_serialize_1_, p_serialize_2_, p_serialize_3_);
  431. }
  432.  
  433. public Object deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_)
  434. {
  435. return this.func_152675_a(p_deserialize_1_, p_deserialize_2_, p_deserialize_3_);
  436. }
  437.  
  438. Serializer(Object p_i46332_2_)
  439. {
  440. this();
  441. }
  442. }
  443. }
  444.  
Advertisement
Add Comment
Please, Sign In to add comment