Skip to content

Commit

Permalink
Rename OfflinePlayer to OfflinePlayerStub (#5417)
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Roy <[email protected]>
  • Loading branch information
mdcfe and JRoy authored Jul 4, 2023
1 parent 563d3fa commit 6012959
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void calculateBalanceTopMap() {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -955,13 +955,13 @@ public User getUser(final UUID base) {
@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;
Expand Down
10 changes: 5 additions & 5 deletions Essentials/src/main/java/com/earth2me/essentials/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public TriState isAuthorizedExact(final String node) {
}

private boolean isAuthorizedCheck(final String node) {
if (base instanceof OfflinePlayer) {
if (base instanceof OfflinePlayerStub) {
return false;
}

Expand All @@ -170,7 +170,7 @@ private boolean isAuthorizedCheck(final String node) {
}

private boolean isPermSetCheck(final String node) {
if (base instanceof OfflinePlayer) {
if (base instanceof OfflinePlayerStub) {
return false;
}

Expand All @@ -188,7 +188,7 @@ private boolean isPermSetCheck(final String node) {
}

private TriState isAuthorizedExactCheck(final String node) {
if (base instanceof OfflinePlayer) {
if (base instanceof OfflinePlayerStub) {
return TriState.UNSET;
}

Expand Down Expand Up @@ -311,7 +311,7 @@ public void dispose() {

private void _dispose() {
if (!base.isOnline()) {
this.base = new OfflinePlayer(getConfigUUID(), ess.getServer());
this.base = new OfflinePlayerStub(getConfigUUID(), ess.getServer());
}
cleanup();
}
Expand Down Expand Up @@ -679,7 +679,7 @@ public boolean toggleAfk(final AfkStatusChangeEvent.Cause cause) {

@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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public User load(final org.bukkit.OfflinePlayer player) throws UserDoesNotExistE
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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;
Expand Down Expand Up @@ -30,7 +30,7 @@ public void run(final Server server, final CommandSource sender, final String co
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")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -42,7 +42,7 @@ public void run(final Server server, final User user, final String commandLabel,
}
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 -> {
Expand Down Expand Up @@ -101,7 +101,7 @@ public void run(final Server server, final User user, final String commandLabel,
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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -29,7 +29,7 @@ public void run(final Server server, final CommandSource sender, final String co
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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -324,7 +325,7 @@ public boolean createPlayerAccount(OfflinePlayer player) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -98,11 +98,11 @@ public User getUser(final String name) {
}

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;
Expand Down Expand Up @@ -164,9 +164,9 @@ public User loadUncachedUser(final UUID uuid) {

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class MessagingTest {

private final OfflinePlayer base1;
private final OfflinePlayerStub base1;
private final Essentials ess;
private final FakeServer server;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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;

Expand All @@ -34,7 +34,7 @@ private void should(final String what) {
}

public void testUpdate() {
final OfflinePlayer base1alt = server.createPlayer(base1.getName());
final OfflinePlayerStub base1alt = server.createPlayer(base1.getName());
assertEquals(base1alt, ess.getUser(base1alt).getBase());
}

Expand All @@ -43,7 +43,7 @@ public void testHome() {
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -145,7 +145,7 @@ private class NewPlayerTeleport implements Runnable {

@Override
public void run() {
if (user.getBase() instanceof OfflinePlayer || !user.getBase().isOnline()) {
if (user.getBase() instanceof OfflinePlayerStub || !user.getBase().isOnline()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ void addPlayer(final Player base1) {
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;
}
Expand Down Expand Up @@ -823,7 +823,7 @@ public File getWorldContainer() {
}

@Override
public OfflinePlayer[] getOfflinePlayers() {
public OfflinePlayerStub[] getOfflinePlayers() {
throw new UnsupportedOperationException("Not supported yet.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
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);
Expand All @@ -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);
Expand Down

0 comments on commit 6012959

Please sign in to comment.