Skip to content

Commit

Permalink
Supplement OfflinePlayer#hasPlayedBefore checks with #isOnline checks
Browse files Browse the repository at this point in the history
  • Loading branch information
md5sha256 committed Aug 8, 2024
1 parent 5742dd6 commit 2762eba
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void handleCommand(CommandContext<PlayerCommandSource> context) {
exception.printStackTrace();
return;
}
if (!offlinePlayer.hasPlayedBefore()) {
if (!offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
this.messageBridge.message(sender, "cmd-invalidPlayer", offlinePlayer.getName());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
exception.printStackTrace();
return;
}
if (!offlinePlayer.hasPlayedBefore()) {
if (!offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
this.messageBridge.message(sender, "cmd-invalidPlayer", offlinePlayer.getName());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
exception.printStackTrace();
return;
}
if (!offlinePlayer.hasPlayedBefore()) {
if (!offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
this.messageBridge.message(sender, "cmd-invalidPlayer", offlinePlayer.getName());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context)
exception.printStackTrace();
return;
}
if (!offlinePlayer.hasPlayedBefore()) {
if (!offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
this.messageBridge.message(sender, "cmd-invalidPlayer", offlinePlayer.getName());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context)
exception.printStackTrace();
return;
}
if (!landlord.hasPlayedBefore()) {
if (!landlord.hasPlayedBefore() && !landlord.isOnline()) {
this.messageBridge.message(player, "cmd-invalidPlayer", landlord.getName());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
exception.printStackTrace();
return;
}
if (!landlord.hasPlayedBefore()) {
if (!landlord.hasPlayedBefore() && !landlord.isOnline()) {
this.messageBridge.message(sender, "cmd-invalidPlayer", landlord.getName());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
exception.printStackTrace();
return;
}
if (!offlinePlayer.hasPlayedBefore()) {
if (!offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) {
this.messageBridge.message(sender, "cmd-invalidPlayer", offlinePlayer.getName());
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void handleCommand(@Nonnull CommandContext<PlayerCommandSource> context)
exception.printStackTrace();
return;
}
if (!offlinePlayer.hasPlayedBefore()) {
if (!offlinePlayer.hasPlayedBefore() &&!offlinePlayer.isOnline()) {
this.messageBridge.message(sender, "cmd-invalidPlayer", offlinePlayer.getName());
return;
}
Expand All @@ -119,7 +119,7 @@ private void performTransfer(
if (Objects.equals(sender, targetPlayer)) {
throw new AreaShopCommandException("transfer-transferSelf");
}
if (!targetPlayer.hasPlayedBefore()) {
if (!targetPlayer.hasPlayedBefore() && !targetPlayer.isOnline()) {
// Unknown player
throw new AreaShopCommandException("transfer-noPlayer", targetPlayerName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class BuyRegion extends GeneralRegion {

private final Economy economy;

@AssistedInject
BuyRegion(
@Nonnull AreaShop plugin,
Expand Down Expand Up @@ -424,7 +424,7 @@ public boolean buy(OfflinePlayer offlinePlayer) {

// Resell is done, disable that now
disableReselling();

// Send message to the player
message(offlinePlayer, "buy-successResale", oldOwnerName);
Player seller = Bukkit.getPlayer(oldOwner);
Expand Down Expand Up @@ -542,7 +542,7 @@ && getBooleanSetting("buy.sellDisabled")) {

// Give back the money
OfflinePlayer player = Bukkit.getOfflinePlayer(getBuyer());
if(player.hasPlayedBefore() && !noPayBack) {
if((player.hasPlayedBefore() || player.isOnline()) && !noPayBack) {
EconomyResponse response = null;
boolean error = false;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public UUID getLandlord() {
if(landlordName != null && !landlordName.isEmpty()) {
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(landlordName);
if(offlinePlayer.hasPlayedBefore()) {
if(offlinePlayer.hasPlayedBefore() || offlinePlayer.isOnline()) {
return offlinePlayer.getUniqueId();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public void execute() {
if(owner != null) {
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(owner);
if(offlinePlayer.hasPlayedBefore()) {
if(offlinePlayer.hasPlayedBefore() || offlinePlayer.isOnline()) {
existing.add(offlinePlayer.getUniqueId());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public SpigotOfflinePlayerHelper(@NotNull Plugin plugin) {
@Override
public CompletableFuture<Optional<UUID>> lookupUuidAsync(String username) {
return lookupOfflinePlayerAsync(username).thenApply(player -> {
if (player.hasPlayedBefore()) {
if (player.hasPlayedBefore() || player.isOnline()) {
return Optional.of(player.getUniqueId());
}
return Optional.empty();
Expand All @@ -31,6 +31,11 @@ public CompletableFuture<Optional<UUID>> lookupUuidAsync(String username) {
@Override
public CompletableFuture<OfflinePlayer> lookupOfflinePlayerAsync(String username) {
final CompletableFuture<OfflinePlayer> future = new CompletableFuture<>();
OfflinePlayer onlinePlayer = this.plugin.getServer().getPlayerExact(username);
if (onlinePlayer != null) {
future.complete(onlinePlayer);
return future;
}
final Server server = this.plugin.getServer();
server.getScheduler().runTaskAsynchronously(this.plugin, () -> {
@SuppressWarnings("deprecation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public CompletableFuture<Optional<UUID>> lookupUuidAsync(String username) {
@Override
public CompletableFuture<OfflinePlayer> lookupOfflinePlayerAsync(String username) {
final CompletableFuture<OfflinePlayer> future = new CompletableFuture<>();
OfflinePlayer onlinePlayer = this.server.getPlayerExact(username);
if (onlinePlayer != null) {
future.complete(onlinePlayer);
return future;
}
OfflinePlayer cachedPlayer = this.server.getOfflinePlayerIfCached(username);
if (cachedPlayer != null) {
return CompletableFuture.completedFuture(cachedPlayer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public List<UUID> asUniqueIdList() {
for(String playerName : playerNames) {
@SuppressWarnings("deprecation")
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName);
if(offlinePlayer.hasPlayedBefore()) {
if(offlinePlayer.hasPlayedBefore() || offlinePlayer.isOnline()) {
result.add(offlinePlayer.getUniqueId());
}
}
Expand Down

0 comments on commit 2762eba

Please sign in to comment.