Rename OfflinePlayer to OfflinePlayerStub (#5417)

Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com>
This commit is contained in:
MD 2023-07-04 14:45:58 +01:00 committed by GitHub
parent 563d3fab4e
commit 60129594a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 41 additions and 40 deletions

View File

@ -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();

View File

@ -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;

View File

@ -152,7 +152,7 @@ public class User extends UserData implements Comparable<User>, 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<User>, 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<User>, 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<User>, 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<User>, 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());

View File

@ -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;
}

View File

@ -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")) {

View File

@ -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;
}

View File

@ -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)) {

View File

@ -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;
}

View File

@ -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<UUID, User> 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<UUID, User> 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;
}

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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.");
}

View File

@ -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);