From 5fbfce0efd4836645f6e85e1ab20fe5f500c8bad Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Tue, 8 Mar 2022 12:31:02 -0500 Subject: [PATCH] ban tab complete only fills online users, async offline user check Took 5 minutes --- .github/workflows/maven.yml | 17 ----- .../auctionhouse/commands/CommandBan.java | 68 +++++++++---------- 2 files changed, 34 insertions(+), 51 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 202d282..ed297ec 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -30,23 +30,6 @@ jobs: - name: Build with Maven run: mvn verify -B --file pom.xml - transfer: - runs-on: ubuntu-latest - steps: - - name: Transfer main branch to Tweetzy - uses: andstor/copycat-action@v3 - with: - personal_token: ${{ secrets.API_TOKEN_GITHUB }} - src_path: /. - dst_owner: Tweetzy - dst_repo_name: Auction-House - email: kiran.hart@live.com - src_branch: main - dst_branch: main - commit_message: ${{ github.event.head_commit.message }} - exclude: .github/* - clean: true - jitpack: runs-on: ubuntu-latest steps: diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandBan.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandBan.java index 35b9999..1eae59b 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandBan.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandBan.java @@ -52,47 +52,49 @@ public class CommandBan extends AbstractCommand { reason.append(args[i]).append(" "); } - OfflinePlayer offlinePlayer = null; + AuctionHouse.newChain().async(() -> { + OfflinePlayer offlinePlayer = null; - if (target == null) { - // try and look for an offline player - offlinePlayer = Bukkit.getOfflinePlayer(args[0]); - if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore()) { - AuctionHouse.getInstance().getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[0]).sendPrefixedMessage(player); - return ReturnType.FAILURE; + if (target == null) { + // try and look for an offline player + offlinePlayer = Bukkit.getOfflinePlayer(args[0]); + if (offlinePlayer == null || !offlinePlayer.hasPlayedBefore()) { + AuctionHouse.getInstance().getLocale().getMessage("general.playernotfound").processPlaceholder("player", args[0]).sendPrefixedMessage(player); + return; + } } - } - UUID toBan = target == null ? offlinePlayer.getUniqueId() : target.getUniqueId(); + UUID toBan = target == null ? offlinePlayer.getUniqueId() : target.getUniqueId(); - if (!AuctionAPI.getInstance().isValidTimeString(timeString)) { - AuctionHouse.getInstance().getLocale().getMessage("general.invalidtimestring").sendPrefixedMessage(player); - return ReturnType.FAILURE; - } + if (!AuctionAPI.getInstance().isValidTimeString(timeString)) { + AuctionHouse.getInstance().getLocale().getMessage("general.invalidtimestring").sendPrefixedMessage(player); + return; + } - if (reason.toString().length() == 0) { - AuctionHouse.getInstance().getLocale().getMessage("bans.nobanreason").sendPrefixedMessage(player); - return ReturnType.FAILURE; - } + if (reason.toString().length() == 0) { + AuctionHouse.getInstance().getLocale().getMessage("bans.nobanreason").sendPrefixedMessage(player); + return; + } - if (AuctionHouse.getInstance().getAuctionBanManager().getBans().containsKey(toBan)) { - AuctionHouse.getInstance().getLocale().getMessage("bans.playeralreadybanned").processPlaceholder("player", args[0]).sendPrefixedMessage(player); - return ReturnType.FAILURE; - } + if (AuctionHouse.getInstance().getAuctionBanManager().getBans().containsKey(toBan)) { + AuctionHouse.getInstance().getLocale().getMessage("bans.playeralreadybanned").processPlaceholder("player", args[0]).sendPrefixedMessage(player); + return; + } - long bannedSeconds = AuctionAPI.getInstance().getSecondsFromString(timeString); + long bannedSeconds = AuctionAPI.getInstance().getSecondsFromString(timeString); - AuctionBanPlayerEvent auctionBanPlayerEvent = new AuctionBanPlayerEvent(player, toBan, reason.toString().trim(), bannedSeconds, false); - Bukkit.getServer().getPluginManager().callEvent(auctionBanPlayerEvent); - if (auctionBanPlayerEvent.isCancelled()) return ReturnType.FAILURE; + AuctionBanPlayerEvent auctionBanPlayerEvent = new AuctionBanPlayerEvent(player, toBan, reason.toString().trim(), bannedSeconds, true); + Bukkit.getServer().getPluginManager().callEvent(auctionBanPlayerEvent); + if (auctionBanPlayerEvent.isCancelled()) return; - AuctionBan auctionBan = new AuctionBan(toBan, reason.toString().trim(), System.currentTimeMillis() + bannedSeconds * 1000); - AuctionHouse.getInstance().getAuctionBanManager().addBan(auctionBan); - AuctionHouse.getInstance().getLocale().getMessage("bans.bannedplayer").processPlaceholder("player", args[0]).processPlaceholder("ban_amount", TimeUtils.makeReadable(bannedSeconds * 1000)).sendPrefixedMessage(player); + AuctionBan auctionBan = new AuctionBan(toBan, reason.toString().trim(), System.currentTimeMillis() + bannedSeconds * 1000); + AuctionHouse.getInstance().getAuctionBanManager().addBan(auctionBan); + AuctionHouse.getInstance().getLocale().getMessage("bans.bannedplayer").processPlaceholder("player", args[0]).processPlaceholder("ban_amount", TimeUtils.makeReadable(bannedSeconds * 1000)).sendPrefixedMessage(player); - if (target != null) { - AuctionHouse.getInstance().getLocale().getMessage("bans.remainingtime").processPlaceholder("ban_amount", TimeUtils.makeReadable(bannedSeconds * 1000)).sendPrefixedMessage(target); - } + if (target != null) { + AuctionHouse.getInstance().getLocale().getMessage("bans.remainingtime").processPlaceholder("ban_amount", TimeUtils.makeReadable(bannedSeconds * 1000)).sendPrefixedMessage(target); + } + }).execute(); return ReturnType.SUCCESS; } @@ -100,9 +102,7 @@ public class CommandBan extends AbstractCommand { @Override protected List onTab(CommandSender sender, String... args) { if (args.length == 1) { - List players = Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()); - players.addAll(Arrays.stream(Bukkit.getOfflinePlayers()).map(OfflinePlayer::getName).collect(Collectors.toList())); - return players; + return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()); } if (args.length == 2) return Arrays.asList("1m", "1h", "1d", "1y");