From 2b36b7314f7f965a507d505d09077325fd5d21c6 Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Sun, 13 Aug 2023 19:46:08 +0100 Subject: [PATCH] Work around potential issues with Mojang API ratelimites on startup (#560) --- .../java/com/Acrobot/ChestShop/UUIDs/NameManager.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java index c9b202e..395673d 100644 --- a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java +++ b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java @@ -12,6 +12,7 @@ import com.Acrobot.ChestShop.Events.AccountAccessEvent; import com.Acrobot.ChestShop.Events.AccountQueryEvent; import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Signs.ChestShopSign; +import com.google.common.base.Charsets; import com.google.common.base.Preconditions; import com.j256.ormlite.dao.Dao; @@ -344,7 +345,13 @@ public class NameManager implements Listener { try { accounts = DaoCreator.getDaoAndCreateTable(Account.class); - adminAccount = new Account(Properties.ADMIN_SHOP_NAME, Bukkit.getOfflinePlayer(Properties.ADMIN_SHOP_NAME).getUniqueId()); + try { + adminAccount = new Account(Properties.ADMIN_SHOP_NAME, Bukkit.getOfflinePlayer(Properties.ADMIN_SHOP_NAME).getUniqueId()); + } catch (NullPointerException ratelimitedException) { + // This happens when the server was ratelimited by Mojang. Unfortunately there is no nice way to check that. + // We fall back to the method used by CraftBukkit to generate an OfflinePlayer's UUID + adminAccount = new Account(Properties.ADMIN_SHOP_NAME, UUID.nameUUIDFromBytes(("OfflinePlayer:" + Properties.ADMIN_SHOP_NAME).getBytes(Charsets.UTF_8))); + } accounts.createOrUpdate(adminAccount); if (!Properties.SERVER_ECONOMY_ACCOUNT.isEmpty()) {