From 60129594a641e0ef4cb6954f0c639d4917e757ee Mon Sep 17 00:00:00 2001 From: MD <1917406+mdcfe@users.noreply.github.com> Date: Tue, 4 Jul 2023 14:45:58 +0100 Subject: [PATCH] Rename OfflinePlayer to OfflinePlayerStub (#5417) Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com> --- .../java/com/earth2me/essentials/BalanceTopImpl.java | 2 +- .../java/com/earth2me/essentials/Essentials.java | 6 +++--- .../src/main/java/com/earth2me/essentials/User.java | 10 +++++----- .../main/java/com/earth2me/essentials/UserMap.java | 2 +- .../com/earth2me/essentials/commands/Commandban.java | 4 ++-- .../earth2me/essentials/commands/Commandhome.java | 6 +++--- .../earth2me/essentials/commands/Commandmute.java | 4 ++-- .../economy/vault/VaultEconomyProvider.java | 3 ++- .../essentials/userstorage/ModernUserMap.java | 12 ++++++------ .../java/com/earth2me/essentials/EconomyTest.java | 4 ++-- .../java/com/earth2me/essentials/MessagingTest.java | 2 +- .../java/com/earth2me/essentials/StorageTest.java | 2 +- .../java/com/earth2me/essentials/ToggleTest.java | 2 +- .../test/java/com/earth2me/essentials/UserTest.java | 6 +++--- .../spawn/EssentialsSpawnPlayerListener.java | 4 ++-- .../java/com/earth2me/essentials/FakeServer.java | 6 +++--- .../{OfflinePlayer.java => OfflinePlayerStub.java} | 6 +++--- 17 files changed, 41 insertions(+), 40 deletions(-) rename providers/1_12Provider/src/main/java/com/earth2me/essentials/{OfflinePlayer.java => OfflinePlayerStub.java} (99%) diff --git a/Essentials/src/main/java/com/earth2me/essentials/BalanceTopImpl.java b/Essentials/src/main/java/com/earth2me/essentials/BalanceTopImpl.java index 2c65ef7ed..4008b3fe5 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/BalanceTopImpl.java +++ b/Essentials/src/main/java/com/earth2me/essentials/BalanceTopImpl.java @@ -40,7 +40,7 @@ public class BalanceTopImpl implements BalanceTop { user.updateMoneyCache(userMoney); newTotal = newTotal.add(userMoney); final String name; - if (user.getBase() instanceof OfflinePlayer) { + if (user.getBase() instanceof OfflinePlayerStub) { name = user.getLastAccountName(); } else if (user.isHidden()) { name = user.getName(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java index f2f1607bb..d15091858 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java @@ -955,13 +955,13 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { @Override public User getOfflineUser(final String name) { final User user = userMap.getUser(name); - if (user != null && user.getBase() instanceof OfflinePlayer) { + if (user != null && user.getBase() instanceof OfflinePlayerStub) { //This code should attempt to use the last known name of a user, if Bukkit returns name as null. final String lastName = user.getLastAccountName(); if (lastName != null) { - ((OfflinePlayer) user.getBase()).setName(lastName); + ((OfflinePlayerStub) user.getBase()).setName(lastName); } else { - ((OfflinePlayer) user.getBase()).setName(name); + ((OfflinePlayerStub) user.getBase()).setName(name); } } return user; diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index bc354fc0f..cb835a124 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -152,7 +152,7 @@ public class User extends UserData implements Comparable, IMessageRecipien } private boolean isAuthorizedCheck(final String node) { - if (base instanceof OfflinePlayer) { + if (base instanceof OfflinePlayerStub) { return false; } @@ -170,7 +170,7 @@ public class User extends UserData implements Comparable, IMessageRecipien } private boolean isPermSetCheck(final String node) { - if (base instanceof OfflinePlayer) { + if (base instanceof OfflinePlayerStub) { return false; } @@ -188,7 +188,7 @@ public class User extends UserData implements Comparable, IMessageRecipien } private TriState isAuthorizedExactCheck(final String node) { - if (base instanceof OfflinePlayer) { + if (base instanceof OfflinePlayerStub) { return TriState.UNSET; } @@ -311,7 +311,7 @@ public class User extends UserData implements Comparable, IMessageRecipien private void _dispose() { if (!base.isOnline()) { - this.base = new OfflinePlayer(getConfigUUID(), ess.getServer()); + this.base = new OfflinePlayerStub(getConfigUUID(), ess.getServer()); } cleanup(); } @@ -679,7 +679,7 @@ public class User extends UserData implements Comparable, IMessageRecipien @Override public boolean isHiddenFrom(Player player) { - if (getBase() instanceof OfflinePlayer || player instanceof OfflinePlayer) { + if (getBase() instanceof OfflinePlayerStub || player instanceof OfflinePlayerStub) { return true; } return !player.canSee(getBase()); diff --git a/Essentials/src/main/java/com/earth2me/essentials/UserMap.java b/Essentials/src/main/java/com/earth2me/essentials/UserMap.java index c65d91a39..52033b268 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/UserMap.java +++ b/Essentials/src/main/java/com/earth2me/essentials/UserMap.java @@ -40,7 +40,7 @@ public class UserMap { if (player instanceof Player) { userPlayer = (Player) player; } else { - final com.earth2me.essentials.OfflinePlayer essPlayer = new com.earth2me.essentials.OfflinePlayer(player.getUniqueId(), Bukkit.getServer()); + final OfflinePlayerStub essPlayer = new OfflinePlayerStub(player.getUniqueId(), Bukkit.getServer()); essPlayer.setName(player.getName()); userPlayer = essPlayer; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandban.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandban.java index 13b1eb9a1..70594e51e 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandban.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandban.java @@ -2,7 +2,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.Console; -import com.earth2me.essentials.OfflinePlayer; +import com.earth2me.essentials.OfflinePlayerStub; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import org.bukkit.BanList; @@ -30,7 +30,7 @@ public class Commandban extends EssentialsCommand { user = getPlayer(server, args, 0, true, true); } catch (final PlayerNotFoundException e) { nomatch = true; - user = ess.getUser(new OfflinePlayer(args[0], ess.getServer())); + user = ess.getUser(new OfflinePlayerStub(args[0], ess.getServer())); } if (!user.getBase().isOnline()) { if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.ban.offline")) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java index 2bdec352e..b1754d1e1 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhome.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.commands; -import com.earth2me.essentials.OfflinePlayer; +import com.earth2me.essentials.OfflinePlayerStub; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.StringUtil; @@ -42,7 +42,7 @@ public class Commandhome extends EssentialsCommand { } try { if ("bed".equalsIgnoreCase(homeName) && user.isAuthorized("essentials.home.bed")) { - if (!player.getBase().isOnline() || player.getBase() instanceof OfflinePlayer) { + if (!player.getBase().isOnline() || player.getBase() instanceof OfflinePlayerStub) { throw new Exception(tl("bedOffline")); } PaperLib.getBedSpawnLocationAsync(player.getBase(), true).thenAccept(location -> { @@ -101,7 +101,7 @@ public class Commandhome extends EssentialsCommand { user.sendMessage(tl("homes", StringUtil.joinList(homes), count, getHomeLimit(finalPlayer))); } }); - if (!player.getBase().isOnline() || player.getBase() instanceof OfflinePlayer) { + if (!player.getBase().isOnline() || player.getBase() instanceof OfflinePlayerStub) { message.complete(null); return; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandmute.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandmute.java index b0c58f4e9..e1e6b6559 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandmute.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandmute.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.CommandSource; -import com.earth2me.essentials.OfflinePlayer; +import com.earth2me.essentials.OfflinePlayerStub; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.DateUtil; import net.ess3.api.events.MuteStatusChangeEvent; @@ -29,7 +29,7 @@ public class Commandmute extends EssentialsCommand { user = getPlayer(server, args, 0, true, true); } catch (final PlayerNotFoundException e) { nomatch = true; - user = ess.getUser(new OfflinePlayer(args[0], ess.getServer())); + user = ess.getUser(new OfflinePlayerStub(args[0], ess.getServer())); } if (!user.getBase().isOnline() && sender.isPlayer()) { if (!sender.isAuthorized("essentials.mute.offline", ess)) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java b/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java index d231c56ab..18257fbbf 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java +++ b/Essentials/src/main/java/com/earth2me/essentials/economy/vault/VaultEconomyProvider.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.economy.vault; import com.earth2me.essentials.Essentials; +import com.earth2me.essentials.OfflinePlayerStub; import com.earth2me.essentials.api.NoLoanPermittedException; import com.earth2me.essentials.api.UserDoesNotExistException; import com.earth2me.essentials.config.EssentialsUserConfiguration; @@ -324,7 +325,7 @@ public class VaultEconomyProvider implements Economy { if (player instanceof Player) { userPlayer = (Player) player; } else { - final com.earth2me.essentials.OfflinePlayer essPlayer = new com.earth2me.essentials.OfflinePlayer(player.getUniqueId(), ess.getServer()); + final OfflinePlayerStub essPlayer = new OfflinePlayerStub(player.getUniqueId(), ess.getServer()); essPlayer.setName(player.getName()); userPlayer = essPlayer; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java b/Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java index 2fee7e6db..c0ab51c8f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java +++ b/Essentials/src/main/java/com/earth2me/essentials/userstorage/ModernUserMap.java @@ -1,6 +1,6 @@ package com.earth2me.essentials.userstorage; -import com.earth2me.essentials.OfflinePlayer; +import com.earth2me.essentials.OfflinePlayerStub; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.NumberUtil; import com.google.common.cache.CacheBuilder; @@ -98,11 +98,11 @@ public class ModernUserMap extends CacheLoader implements IUserMap { } final User user = getUser(uuidCache.getCachedUUID(name)); - if (user != null && user.getBase() instanceof OfflinePlayer) { + if (user != null && user.getBase() instanceof OfflinePlayerStub) { if (user.getLastAccountName() != null) { - ((OfflinePlayer) user.getBase()).setName(user.getLastAccountName()); + ((OfflinePlayerStub) user.getBase()).setName(user.getLastAccountName()); } else { - ((OfflinePlayer) user.getBase()).setName(name); + ((OfflinePlayerStub) user.getBase()).setName(name); } } return user; @@ -164,9 +164,9 @@ public class ModernUserMap extends CacheLoader implements IUserMap { final File userFile = getUserFile(uuid); if (userFile.exists()) { - player = new OfflinePlayer(uuid, ess.getServer()); + player = new OfflinePlayerStub(uuid, ess.getServer()); user = new User(player, ess); - ((OfflinePlayer) player).setName(user.getLastAccountName()); + ((OfflinePlayerStub) player).setName(user.getLastAccountName()); uuidCache.updateCache(uuid, null); return user; } diff --git a/Essentials/src/test/java/com/earth2me/essentials/EconomyTest.java b/Essentials/src/test/java/com/earth2me/essentials/EconomyTest.java index db8edfae0..ff405e8aa 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/EconomyTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/EconomyTest.java @@ -30,8 +30,8 @@ public class EconomyTest { } catch (final IOException ex) { Assert.fail("IOException"); } - server.addPlayer(new OfflinePlayer(PLAYERNAME, ess.getServer())); - server.addPlayer(new OfflinePlayer(PLAYERNAME2, ess.getServer())); + server.addPlayer(new OfflinePlayerStub(PLAYERNAME, ess.getServer())); + server.addPlayer(new OfflinePlayerStub(PLAYERNAME2, ess.getServer())); } // only one big test, since we use static instances diff --git a/Essentials/src/test/java/com/earth2me/essentials/MessagingTest.java b/Essentials/src/test/java/com/earth2me/essentials/MessagingTest.java index b0bc2a8fc..d0ae184a2 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/MessagingTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/MessagingTest.java @@ -14,7 +14,7 @@ import static org.junit.Assert.assertEquals; public class MessagingTest { - private final OfflinePlayer base1; + private final OfflinePlayerStub base1; private final Essentials ess; private final FakeServer server; diff --git a/Essentials/src/test/java/com/earth2me/essentials/StorageTest.java b/Essentials/src/test/java/com/earth2me/essentials/StorageTest.java index 5998bbcfd..fda8d82bb 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/StorageTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/StorageTest.java @@ -30,7 +30,7 @@ public class StorageTest { public void testOldUserdata() { final ExecuteTimer ext = new ExecuteTimer(); ext.start(); - final OfflinePlayer base1 = server.createPlayer("testPlayer1"); + final OfflinePlayerStub base1 = server.createPlayer("testPlayer1"); server.addPlayer(base1); ext.mark("fake user created"); final UserData user = ess.getUser(base1); diff --git a/Essentials/src/test/java/com/earth2me/essentials/ToggleTest.java b/Essentials/src/test/java/com/earth2me/essentials/ToggleTest.java index b2b85fb3a..4b7ccd9dd 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/ToggleTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/ToggleTest.java @@ -9,7 +9,7 @@ import org.bukkit.plugin.InvalidDescriptionException; import java.io.IOException; public class ToggleTest extends TestCase { - private final OfflinePlayer base1; + private final OfflinePlayerStub base1; private final Essentials ess; private final FakeServer server; diff --git a/Essentials/src/test/java/com/earth2me/essentials/UserTest.java b/Essentials/src/test/java/com/earth2me/essentials/UserTest.java index ff9687014..0c3715545 100644 --- a/Essentials/src/test/java/com/earth2me/essentials/UserTest.java +++ b/Essentials/src/test/java/com/earth2me/essentials/UserTest.java @@ -9,7 +9,7 @@ import java.io.IOException; import java.math.BigDecimal; public class UserTest extends TestCase { - private final OfflinePlayer base1; + private final OfflinePlayerStub base1; private final Essentials ess; private final FakeServer server; @@ -34,7 +34,7 @@ public class UserTest extends TestCase { } public void testUpdate() { - final OfflinePlayer base1alt = server.createPlayer(base1.getName()); + final OfflinePlayerStub base1alt = server.createPlayer(base1.getName()); assertEquals(base1alt, ess.getUser(base1alt).getBase()); } @@ -43,7 +43,7 @@ public class UserTest extends TestCase { final Location loc = base1.getLocation(); loc.setWorld(server.getWorlds().get(0)); user.setHome("home", loc); - final OfflinePlayer base2 = server.createPlayer(base1.getName()); + final OfflinePlayerStub base2 = server.createPlayer(base1.getName()); final User user2 = ess.getUser(base2); final Location home = user2.getHome(loc); diff --git a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java index 59d8b4efe..72f36803d 100644 --- a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java +++ b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java @@ -1,7 +1,7 @@ package com.earth2me.essentials.spawn; import com.earth2me.essentials.Kit; -import com.earth2me.essentials.OfflinePlayer; +import com.earth2me.essentials.OfflinePlayerStub; import com.earth2me.essentials.User; import com.earth2me.essentials.textreader.IText; import com.earth2me.essentials.textreader.KeywordReplacer; @@ -145,7 +145,7 @@ class EssentialsSpawnPlayerListener implements Listener { @Override public void run() { - if (user.getBase() instanceof OfflinePlayer || !user.getBase().isOnline()) { + if (user.getBase() instanceof OfflinePlayerStub || !user.getBase().isOnline()) { return; } diff --git a/providers/1_12Provider/src/main/java/com/earth2me/essentials/FakeServer.java b/providers/1_12Provider/src/main/java/com/earth2me/essentials/FakeServer.java index d8dba3def..bcd93f21b 100644 --- a/providers/1_12Provider/src/main/java/com/earth2me/essentials/FakeServer.java +++ b/providers/1_12Provider/src/main/java/com/earth2me/essentials/FakeServer.java @@ -455,8 +455,8 @@ public final class FakeServer implements Server { pluginManager.callEvent(new PlayerJoinEvent(base1, null)); } - OfflinePlayer createPlayer(final String name) { - final OfflinePlayer player = new OfflinePlayer(name, this); + OfflinePlayerStub createPlayer(final String name) { + final OfflinePlayerStub player = new OfflinePlayerStub(name, this); player.setLocation(new Location(worlds.get(0), 0, 0, 0, 0, 0)); return player; } @@ -823,7 +823,7 @@ public final class FakeServer implements Server { } @Override - public OfflinePlayer[] getOfflinePlayers() { + public OfflinePlayerStub[] getOfflinePlayers() { throw new UnsupportedOperationException("Not supported yet."); } diff --git a/providers/1_12Provider/src/main/java/com/earth2me/essentials/OfflinePlayer.java b/providers/1_12Provider/src/main/java/com/earth2me/essentials/OfflinePlayerStub.java similarity index 99% rename from providers/1_12Provider/src/main/java/com/earth2me/essentials/OfflinePlayer.java rename to providers/1_12Provider/src/main/java/com/earth2me/essentials/OfflinePlayerStub.java index 99772592a..77f778682 100644 --- a/providers/1_12Provider/src/main/java/com/earth2me/essentials/OfflinePlayer.java +++ b/providers/1_12Provider/src/main/java/com/earth2me/essentials/OfflinePlayerStub.java @@ -63,7 +63,7 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -public class OfflinePlayer implements Player { +public class OfflinePlayerStub implements Player { private final transient Server server; private final transient org.bukkit.OfflinePlayer base; private transient Location location = new Location(null, 0, 0, 0, 0, 0); @@ -72,14 +72,14 @@ public class OfflinePlayer implements Player { private boolean isFlying = false; private String name; - public OfflinePlayer(final UUID uuid, final Server server) { + public OfflinePlayerStub(final UUID uuid, final Server server) { this.server = server; this.world = server.getWorlds().get(0); this.base = server.getOfflinePlayer(uuid); this.name = base.getName(); } - public OfflinePlayer(final String name, final Server server) { + public OfflinePlayerStub(final String name, final Server server) { this.server = server; this.world = server.getWorlds().get(0); this.base = server.getOfflinePlayer(name);