From 124614e3d316bbf95892ed317cf88c68e47037b4 Mon Sep 17 00:00:00 2001 From: Daniel Scherf <35780068+dlsf@users.noreply.github.com> Date: Mon, 6 Sep 2021 20:09:28 +0200 Subject: [PATCH] Reformat & Refactor commands, Shorten tab-completion code (#390) * Reformat & Refactor commands * Remove empty line * Shorten command tab-completion code * Optimize imports * Remove unnecessary streams * Remove useless code --- .../commands/AboutCommand.java | 5 ++- .../iridiumskyblock/commands/BanCommand.java | 17 ++++------ .../iridiumskyblock/commands/BankCommand.java | 9 +++-- .../commands/BiomeCommand.java | 34 ++++++++----------- .../commands/BlockValueCommand.java | 15 ++++---- ...ostersCommand.java => BoosterCommand.java} | 15 ++++---- .../commands/BorderCommand.java | 26 +++++++++----- .../commands/BypassCommand.java | 7 ++-- .../iridiumskyblock/commands/ChatCommand.java | 15 ++++---- .../commands/ClearDataCommand.java | 11 +++--- .../iridiumskyblock/commands/Command.java | 5 ++- .../commands/CommandManager.java | 24 +++++++++---- .../commands/CreateCommand.java | 11 +++--- .../commands/DeleteCommand.java | 9 +++-- .../commands/DeleteWarpCommand.java | 22 +++++++----- .../commands/DemoteCommand.java | 27 +++++++-------- .../commands/DepositCommand.java | 11 +++--- .../commands/EditWarpCommand.java | 31 ++++++++++------- .../commands/ExpelCommand.java | 13 ++++--- .../iridiumskyblock/commands/FlyCommand.java | 15 ++++---- .../iridiumskyblock/commands/HelpCommand.java | 13 +++---- .../iridiumskyblock/commands/HomeCommand.java | 7 ++-- .../iridiumskyblock/commands/InfoCommand.java | 17 ++++++---- .../commands/InviteCommand.java | 27 +++++++++------ .../iridiumskyblock/commands/JoinCommand.java | 25 ++++++++------ .../iridiumskyblock/commands/KickCommand.java | 27 +++++++-------- .../commands/LeaveCommand.java | 20 ++++++----- .../commands/LevelCommand.java | 8 +++-- .../iridiumskyblock/commands/LogsCommand.java | 8 ++--- .../commands/MembersCommand.java | 8 ++--- .../commands/MissionCommand.java | 12 ++++--- .../commands/PermissionsCommand.java | 8 ++--- .../commands/PositionCommand.java | 6 ++-- .../commands/PrivateCommand.java | 10 +++--- .../commands/PromoteCommand.java | 28 +++++++-------- .../commands/PublicCommand.java | 9 +++-- .../commands/RecalculateCommand.java | 11 +++--- .../commands/RegenCommand.java | 14 ++++---- .../commands/ReloadCommand.java | 5 ++- .../commands/RenameCommand.java | 13 ++++--- .../commands/RewardsCommand.java | 9 +++-- .../commands/SaveSchematicCommand.java | 10 +++--- .../commands/SetHomeCommand.java | 13 ++++--- .../commands/SetWarpCommand.java | 13 ++++--- .../iridiumskyblock/commands/ShopCommand.java | 6 ++-- .../iridiumskyblock/commands/TopCommand.java | 7 ++-- .../commands/TransferCommand.java | 18 +++++----- .../commands/TrustCommand.java | 17 ++++++---- .../commands/UnBanCommand.java | 22 ++++++------ .../commands/UnInviteCommand.java | 15 ++++---- .../commands/UnTrustCommand.java | 15 ++++---- .../commands/UpgradesCommand.java | 15 ++++---- .../commands/ValueCommand.java | 9 +++-- .../commands/VisitCommand.java | 15 ++++---- .../commands/WarpsCommand.java | 17 ++++++---- .../commands/WithdrawCommand.java | 12 ++++--- .../commands/bank/GiveCommand.java | 17 ++++++---- .../commands/bank/RemoveCommand.java | 17 ++++++---- .../commands/bank/SetCommand.java | 17 ++++++---- .../iridiumskyblock/configs/Commands.java | 2 +- .../iridium/iridiumskyblock/gui/LogsGUI.java | 6 ++-- .../managers/IslandManager.java | 1 - .../iridiumskyblock/utils/PlayerUtils.java | 13 +++++++ 63 files changed, 480 insertions(+), 404 deletions(-) rename src/main/java/com/iridium/iridiumskyblock/commands/{BoostersCommand.java => BoosterCommand.java} (98%) diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/AboutCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/AboutCommand.java index f74f0c513..fa883e579 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/AboutCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/AboutCommand.java @@ -3,11 +3,10 @@ import com.iridium.iridiumcore.utils.StringUtils; import com.iridium.iridiumskyblock.IridiumSkyblock; import java.time.Duration; -import org.bukkit.command.CommandSender; - import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.bukkit.command.CommandSender; /** * Command which display plugin information to the user. @@ -57,7 +56,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/BanCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/BanCommand.java index 194ee8dcf..ce0b01669 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/BanCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/BanCommand.java @@ -8,15 +8,13 @@ import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.BansGUI; import com.iridium.iridiumskyblock.utils.PlayerUtils; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Arrays; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which bans a visitor from your Island. @@ -44,10 +42,10 @@ public boolean execute(CommandSender sender, String[] args) { sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -84,11 +82,13 @@ public boolean execute(CommandSender sender, String[] args) { sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyBanned.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + IridiumSkyblock.getInstance().getDatabaseManager().getIslandBanTableManager().addEntry(new IslandBan(island.get(), user, targetUser)); if (island.get().isInIsland(targetPlayer.getLocation())) { PlayerUtils.teleportSpawn(targetPlayer); targetPlayer.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youHaveBeenBanned.replace("%player%", user.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); } + sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().playerBanned.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return true; } @@ -104,10 +104,7 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return Bukkit.getOnlinePlayers().stream() - .map(Player::getName) - .filter(s -> s.toLowerCase().contains(args[1].toLowerCase())) - .collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/BankCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/BankCommand.java index cc0e69e25..c79dcd050 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/BankCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/BankCommand.java @@ -8,13 +8,12 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.BankGUI; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which opens the Island bank GUI. @@ -50,11 +49,11 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + player.openInventory(new BankGUI(island.get()).getInventory()); return true; } @@ -71,7 +70,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command cmd, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/BiomeCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/BiomeCommand.java index 81ad8665d..31eeb2036 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/BiomeCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/BiomeCommand.java @@ -7,15 +7,14 @@ import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.BiomeGUI; import java.time.Duration; -import org.apache.commons.lang.WordUtils; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.apache.commons.lang.WordUtils; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class BiomeCommand extends Command { @@ -30,15 +29,14 @@ public boolean execute(CommandSender sender, String[] args) { final Player player = (Player) sender; final User user = this.plugin.getUserManager().getUser(player); - final Optional optionalIsland = user.getIsland(); - - if (!optionalIsland.isPresent()) { + final Optional islandOptional = user.getIsland(); + if (!islandOptional.isPresent()) { player.sendMessage(StringUtils.color(this.plugin.getMessages().noIsland.replace("%prefix%", plugin.getConfiguration().prefix))); return false; } if (args.length != 2) { - player.openInventory(new BiomeGUI(1, optionalIsland.get(), player.getWorld().getEnvironment(), getCooldownProvider()).getInventory()); + player.openInventory(new BiomeGUI(1, islandOptional.get(), player.getWorld().getEnvironment(), getCooldownProvider()).getInventory()); // The BiomeGUI handles the cooldown return false; } @@ -50,8 +48,7 @@ public boolean execute(CommandSender sender, String[] args) { return false; } - IridiumSkyblock.getInstance().getIslandManager().setIslandBiome(optionalIsland.get(), biomeOptional.get()); - + IridiumSkyblock.getInstance().getIslandManager().setIslandBiome(islandOptional.get(), biomeOptional.get()); player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().changedBiome .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) .replace("%biome%", WordUtils.capitalizeFully(biomeOptional.get().name().toLowerCase().replace("_", " "))))); @@ -60,17 +57,16 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - if (commandSender instanceof Player) { - Player player = (Player) commandSender; - return Arrays.stream(XBiome.VALUES) - .filter(biome -> biome.getEnvironment() == player.getWorld().getEnvironment()) - .filter(biome -> biome.getBiome() != null) - .map(Enum::toString) - .filter(s -> s.toUpperCase().contains(args[1].toUpperCase())) - .collect(Collectors.toList()); - } else { + if (!(commandSender instanceof Player)) { return Collections.emptyList(); } + + Player player = (Player) commandSender; + return Arrays.stream(XBiome.VALUES) + .filter(biome -> biome.getEnvironment() == player.getWorld().getEnvironment()) + .filter(biome -> biome.getBiome() != null) + .map(XBiome::name) + .collect(Collectors.toList()); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/BlockValueCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/BlockValueCommand.java index 25239f5ae..350e21b62 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/BlockValueCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/BlockValueCommand.java @@ -2,15 +2,15 @@ import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.gui.BlockValueGUI; +import com.iridium.iridiumskyblock.gui.BlockValueGUI.BlockValueType; import com.iridium.iridiumskyblock.gui.InventoryConfigGUI; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which shows all the valuable blocks and spawners. @@ -24,7 +24,6 @@ public class BlockValueCommand extends Command { */ public BlockValueCommand() { super(Collections.singletonList("blockvalues"), "Show the values of blocks", "", true, Duration.ZERO); - } /** @@ -42,11 +41,13 @@ public boolean execute(CommandSender sender, String[] arguments) { player.openInventory(new InventoryConfigGUI(IridiumSkyblock.getInstance().getInventories().blockValueSelectGUI).getInventory()); return true; } + BlockValueGUI.BlockValueType blockValueType = BlockValueGUI.BlockValueType.getType(arguments[1]); if (blockValueType == null) { player.openInventory(new InventoryConfigGUI(IridiumSkyblock.getInstance().getInventories().blockValueSelectGUI).getInventory()); return true; } + player.openInventory(new BlockValueGUI(blockValueType).getInventory()); return true; } @@ -63,8 +64,10 @@ public boolean execute(CommandSender sender, String[] arguments) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players - return Arrays.stream(BlockValueGUI.BlockValueType.values()).map(Enum::toString).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + // Return a new List, so it isn't a list of online players + return Arrays.stream(BlockValueGUI.BlockValueType.values()) + .map(BlockValueType::name) + .collect(Collectors.toList()); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/BoostersCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/BoosterCommand.java similarity index 98% rename from src/main/java/com/iridium/iridiumskyblock/commands/BoostersCommand.java rename to src/main/java/com/iridium/iridiumskyblock/commands/BoosterCommand.java index 8ef30a634..cbad47681 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/BoostersCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/BoosterCommand.java @@ -10,22 +10,21 @@ import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.BoostersGUI; import com.iridium.iridiumskyblock.utils.PlayerUtils; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.time.LocalDateTime; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; -public class BoostersCommand extends Command { +public class BoosterCommand extends Command { /** * The default constructor. */ - public BoostersCommand() { + public BoosterCommand() { super(Arrays.asList("booster", "boosters"), "Open the Island Boosters Menu", "", true, Duration.ZERO); } @@ -42,15 +41,14 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (args.length != 2) { player.openInventory(new BoostersGUI(island.get()).getInventory()); return true; - } String boosterName = args[1]; @@ -59,14 +57,17 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownBooster.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + IslandBooster islandBooster = IridiumSkyblock.getInstance().getIslandManager().getIslandBooster(island.get(), boosterName); if (islandBooster.isActive()) { return false; } + if (!PlayerUtils.pay(player, island.get(), booster.crystalsCost, booster.vaultCost)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + islandBooster.setTime(LocalDateTime.now().plusSeconds(booster.time)); IslandLog islandLog = new IslandLog(island.get(), LogAction.BOOSTER_PURCHASE, user, null, 0, boosterName); IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog); diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/BorderCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/BorderCommand.java index 1610376fb..13844cbad 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/BorderCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/BorderCommand.java @@ -7,14 +7,17 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.InventoryConfigGUI; +import java.time.Duration; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.time.Duration; -import java.util.*; -import java.util.stream.Collectors; - /** * Command which changes the Island's Border Color. */ @@ -40,11 +43,11 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.BORDER)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotManageBorder.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -54,18 +57,23 @@ public boolean execute(CommandSender sender, String[] args) { player.openInventory(new InventoryConfigGUI(IridiumSkyblock.getInstance().getInventories().islandBorder).getInventory()); return true; } + Color color = Color.getColor(args[1]); if (color == null) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notAColor.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!IridiumSkyblock.getInstance().getBorder().enabled.getOrDefault(color, true)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().borderColorDisabled.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + island.get().setColor(color); - island.get().getMembers().stream().map(islandUser -> Bukkit.getPlayer(islandUser.getUuid())).filter(Objects::nonNull).forEach(islandPlayer -> - islandPlayer.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandBorderChanged.replace("%player%", player.getName()).replace("%color%", color.toString()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))) + island.get().getMembers().stream() + .map(islandUser -> Bukkit.getPlayer(islandUser.getUuid())) + .filter(Objects::nonNull) + .forEach(islandPlayer -> islandPlayer.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandBorderChanged.replace("%player%", player.getName()).replace("%color%", color.toString()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))) ); return true; } @@ -81,7 +89,9 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return Arrays.stream(Color.values()).map(Enum::name).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return Arrays.stream(Color.values()) + .map(Color::name) + .collect(Collectors.toList()); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/BypassCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/BypassCommand.java index 67e6c5f09..c72ad0369 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/BypassCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/BypassCommand.java @@ -4,11 +4,10 @@ import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.database.User; import java.time.Duration; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.util.Collections; import java.util.List; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which allows admins to bypass Island restrictions. @@ -51,7 +50,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/ChatCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/ChatCommand.java index f1e1aa42d..d320fc87f 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/ChatCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/ChatCommand.java @@ -6,15 +6,14 @@ import com.iridium.iridiumskyblock.api.UserChatToggleEvent; import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which allows users to chat with their Island members. @@ -40,7 +39,6 @@ public ChatCommand() { public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; Optional island = IridiumSkyblock.getInstance().getUserManager().getUser(player).getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -63,9 +61,8 @@ public boolean execute(CommandSender sender, String[] args) { User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); UserChatToggleEvent userChatToggleEvent = new UserChatToggleEvent(user, !user.isIslandChat()); Bukkit.getPluginManager().callEvent(userChatToggleEvent); - if (userChatToggleEvent.isCancelled()) { - return false; - } + if (userChatToggleEvent.isCancelled()) return false; + user.setIslandChat(!user.isIslandChat()); player.sendMessage(StringUtils.color((user.isIslandChat() ? IridiumSkyblock.getInstance().getMessages().islandChatEnabled : IridiumSkyblock.getInstance().getMessages().islandChatDisabled) .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix)) @@ -86,7 +83,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/ClearDataCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/ClearDataCommand.java index 97708e7a5..064f59ccc 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/ClearDataCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/ClearDataCommand.java @@ -4,12 +4,11 @@ import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.gui.ConfirmationGUI; import com.iridium.iridiumskyblock.managers.DatabaseManager; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which allows admins to bypass Island restrictions. @@ -37,9 +36,9 @@ public boolean execute(CommandSender sender, String[] args) { execute(sender); return true; } + Player player = (Player) sender; - player.openInventory(new ConfirmationGUI(() -> execute(player), getCooldownProvider() - ).getInventory()); + player.openInventory(new ConfirmationGUI(() -> execute(player), getCooldownProvider()).getInventory()); // Return false because the cooldown is set by the ConfirmationGUI return false; } @@ -76,7 +75,7 @@ private void execute(CommandSender commandSender) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/Command.java b/src/main/java/com/iridium/iridiumskyblock/commands/Command.java index 85ea5e159..0ac3bf38f 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/Command.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/Command.java @@ -2,15 +2,14 @@ import com.iridium.iridiumcore.dependencies.fasterxml.annotation.JsonIgnore; import com.iridium.iridiumskyblock.managers.CooldownProvider; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; /** * Abstract commands used to easily create subcommands. diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/CommandManager.java b/src/main/java/com/iridium/iridiumskyblock/commands/CommandManager.java index fd07533b0..1bd8b63af 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/CommandManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/CommandManager.java @@ -9,6 +9,14 @@ import com.iridium.iridiumskyblock.gui.InventoryConfigGUI; import com.iridium.iridiumskyblock.managers.CooldownProvider; import com.iridium.iridiumskyblock.utils.TimeUtils; +import java.lang.reflect.Field; +import java.time.Duration; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -16,10 +24,6 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.Field; -import java.time.Duration; -import java.util.*; - /** * Handles command executions and tab-completions for all commands of this plugin. */ @@ -187,6 +191,7 @@ public List onTabComplete(@NotNull CommandSender commandSender, org.bukk // Handle the tab completion if it's the sub-command selection if (args.length == 1) { ArrayList result = new ArrayList<>(); + for (Command command : commands) { for (String alias : command.aliases) { if (alias.toLowerCase().startsWith(args[0].toLowerCase()) && hasPermissions(commandSender, command)) { @@ -194,6 +199,7 @@ public List onTabComplete(@NotNull CommandSender commandSender, org.bukk } } } + return result; } @@ -204,12 +210,12 @@ public List onTabComplete(@NotNull CommandSender commandSender, org.bukk if (hasPermissions(commandSender, executingCommand)) { List tabCompletion = new ArrayList<>(executingCommand.onTabComplete(commandSender, cmd, label, args)); tabCompletion.addAll(executingCommand.getChildNames()); - return tabCompletion; + return filterTabCompletionResults(tabCompletion, args); } } } - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } @@ -233,4 +239,10 @@ private Command findExecutingCommand(Command baseCommand, String[] args) { return executingCommand; } + private List filterTabCompletionResults(List tabCompletion, String[] arguments) { + return tabCompletion.stream() + .filter(completion -> completion.toLowerCase().contains(arguments[arguments.length - 1].toLowerCase())) + .collect(Collectors.toList()); + } + } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/CreateCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/CreateCommand.java index 17e970345..78edb670a 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/CreateCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/CreateCommand.java @@ -7,14 +7,13 @@ import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.IslandCreateGUI; import java.time.Duration; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.stream.Collectors; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which creates a new Island for a user. @@ -96,11 +95,11 @@ private void createIsland(Player player, String name) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { if (args.length == 3) { - return IridiumSkyblock.getInstance().getSchematics().schematics.keySet().stream().filter(s -> s.contains(args[2])).collect(Collectors.toList()); + return new ArrayList<>(IridiumSkyblock.getInstance().getSchematics().schematics.keySet()); } // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/DeleteCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/DeleteCommand.java index 636ba4691..a3fcb66f7 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/DeleteCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/DeleteCommand.java @@ -6,13 +6,12 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.ConfirmationGUI; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which deletes a User's Island. @@ -39,7 +38,6 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -49,6 +47,7 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotDeleteIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + player.openInventory(new ConfirmationGUI(() -> IridiumSkyblock.getInstance().getIslandManager().deleteIsland(island.get(), user), getCooldownProvider()).getInventory()); // Always return false because the cooldown is set by the ConfirmationGUI @@ -67,7 +66,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/DeleteWarpCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/DeleteWarpCommand.java index 96adbc5e6..35dc67d21 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/DeleteWarpCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/DeleteWarpCommand.java @@ -7,17 +7,15 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.IslandWarp; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import java.util.stream.Stream; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class DeleteWarpCommand extends Command { @@ -49,7 +47,6 @@ public boolean execute(CommandSender sender, String[] args) { if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; - } if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.MANAGE_WARPS)) { @@ -86,16 +83,23 @@ public List onTabComplete(CommandSender commandSender, org.bukkit.comman Optional island = IridiumSkyblock.getInstance().getUserManager().getUser((OfflinePlayer) commandSender).getIsland(); List islandWarps = island.isPresent() ? IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(island.get()) : Collections.emptyList(); if (args.length == 2) { - return islandWarps.stream().map(IslandWarp::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return islandWarps.stream() + .map(IslandWarp::getName) + .collect(Collectors.toList()); } + if (args.length == 3) { - return Stream.of("icon", "description").filter(s -> s.contains(args[2])).collect(Collectors.toList()); + return Arrays.asList("icon", "description"); } + if (args.length == 4) { if (args[2].equalsIgnoreCase("icon")) { - return Arrays.stream(XMaterial.values()).map(XMaterial::name).filter(s -> s.toLowerCase().contains(args[3].toLowerCase())).collect(Collectors.toList()); + return Arrays.stream(XMaterial.values()) + .map(XMaterial::name) + .collect(Collectors.toList()); } } + return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/DemoteCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/DemoteCommand.java index 5a2449ad3..2ec28efb9 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/DemoteCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/DemoteCommand.java @@ -9,17 +9,15 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.IslandLog; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; - +import com.iridium.iridiumskyblock.utils.PlayerUtils; import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which demotes a user in the Island rank system. @@ -62,11 +60,13 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNotInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + IslandRank nextRank = IslandRank.getByLevel(offlinePlayerUser.getIslandRank().getLevel() - 1); if (nextRank == null || offlinePlayerUser.getIslandRank().getLevel() >= user.getIslandRank().getLevel() || !IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.DEMOTE)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotDemoteUser.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (nextRank.equals(IslandRank.VISITOR)) { IridiumSkyblock.getInstance().getCommands().kickCommand.execute(sender, args); return true; @@ -78,18 +78,17 @@ public boolean execute(CommandSender sender, String[] args) { offlinePlayerUser.setIslandRank(nextRank); for (User member : island.get().getMembers()) { - Player p = Bukkit.getPlayer(member.getUuid()); - if (p == null) continue; - if (p.equals(player)) { - p.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().demotedPlayer.replace("%player%", offlinePlayerUser.getName()).replace("%rank%", nextRank.getDisplayName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); + Player islandMember = Bukkit.getPlayer(member.getUuid()); + if (islandMember == null) continue; + if (islandMember.equals(player)) { + islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().demotedPlayer.replace("%player%", offlinePlayerUser.getName()).replace("%rank%", nextRank.getDisplayName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); } else { - p.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userDemotedPlayer.replace("%promoter%", player.getName()).replace("%player%", offlinePlayerUser.getName()).replace("%rank%", nextRank.getDisplayName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); + islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userDemotedPlayer.replace("%promoter%", player.getName()).replace("%player%", offlinePlayerUser.getName()).replace("%rank%", nextRank.getDisplayName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); } } IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_DEMOTED, user, offlinePlayerUser, 0, nextRank.getDisplayName()); IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog); - return true; } @@ -104,7 +103,7 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/DepositCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/DepositCommand.java index 14c7e4eb1..e062b7aa9 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/DepositCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/DepositCommand.java @@ -7,14 +7,13 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.IslandLog; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which deposits a currency into the Island bank. @@ -50,11 +49,13 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + Optional bankItem = IridiumSkyblock.getInstance().getBankItemList().stream().filter(item -> item.getName().equalsIgnoreCase(args[1])).findFirst(); if (!bankItem.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noSuchBankItem.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + try { double amount = bankItem.get().deposit(player, Double.parseDouble(args[2])); if (amount > 0) { @@ -79,7 +80,9 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return IridiumSkyblock.getInstance().getBankItemList().stream().map(BankItem::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return IridiumSkyblock.getInstance().getBankItemList().stream() + .map(BankItem::getName) + .collect(Collectors.toList()); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/EditWarpCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/EditWarpCommand.java index 5480323c3..826893ea4 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/EditWarpCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/EditWarpCommand.java @@ -7,17 +7,15 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.IslandWarp; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import java.util.stream.Stream; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class EditWarpCommand extends Command { @@ -46,7 +44,6 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -63,12 +60,14 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownWarp.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } - //TODO use subcommand system + + //TODO: Use subcommand system switch (args[2]) { case "icon": if (args.length != 4) { sender.sendMessage("/is editwarp icon "); } + Optional xMaterial = XMaterial.matchXMaterial(args[3]); if (xMaterial.isPresent()) { islandWarp.get().setIcon(xMaterial.get()); @@ -105,20 +104,26 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { Optional island = IridiumSkyblock.getInstance().getUserManager().getUser((OfflinePlayer) commandSender).getIsland(); - List islandWarps = - island.isPresent() ? IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(island.get()) : - Collections.emptyList(); + List islandWarps = island.isPresent() ? IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(island.get()) : Collections.emptyList(); + if (args.length == 2) { - return islandWarps.stream().map(IslandWarp::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return islandWarps.stream() + .map(IslandWarp::getName) + .collect(Collectors.toList()); } + if (args.length == 3) { - return Stream.of("icon", "description").filter(s -> s.contains(args[2])).collect(Collectors.toList()); + return Arrays.asList("icon", "description"); } + if (args.length == 4) { if (args[2].equalsIgnoreCase("icon")) { - return Arrays.stream(XMaterial.values()).map(XMaterial::name).filter(s -> s.toLowerCase().contains(args[3].toLowerCase())).collect(Collectors.toList()); + return Arrays.stream(XMaterial.values()) + .map(XMaterial::name) + .collect(Collectors.toList()); } } + return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/ExpelCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/ExpelCommand.java index af992325d..adb207d61 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/ExpelCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/ExpelCommand.java @@ -7,15 +7,14 @@ import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.VisitorsGUI; import com.iridium.iridiumskyblock.utils.PlayerUtils; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class ExpelCommand extends Command { @@ -40,6 +39,7 @@ public boolean execute(CommandSender sender, String[] args) { sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); @@ -52,24 +52,29 @@ public boolean execute(CommandSender sender, String[] args) { player.openInventory(new VisitorsGUI(1, island.get()).getInventory()); return true; } + Player targetPlayer = Bukkit.getPlayer(args[1]); if (targetPlayer == null) { sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notAPlayer.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer); if (island.get().equals(targetUser.getIsland().orElse(null)) || IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island.get(), targetUser).isPresent()) { sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().inYourTeam.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!island.get().isInIsland(targetPlayer.getLocation())) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNotVisitingYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (targetUser.isBypass() || targetPlayer.hasPermission("iridiumskyblock.visitbypass")) { sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotExpelPlayer.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.EXPEL)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noPermission.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/FlyCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/FlyCommand.java index 0f1411c8a..220b71efb 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/FlyCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/FlyCommand.java @@ -5,16 +5,13 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.IslandBooster; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class FlyCommand extends Command { @@ -42,12 +39,14 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notOnAnIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + boolean flight = !user.isFlying(); if (args.length == 2) { if (!args[1].equalsIgnoreCase("enable") && !args[1].equalsIgnoreCase("disable") && !args[1].equalsIgnoreCase("on") && !args[1].equalsIgnoreCase("off")) { sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + flight = args[1].equalsIgnoreCase("enable") || args[1].equalsIgnoreCase("on"); } @@ -56,15 +55,16 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().flightBoosterNotActive.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + user.setFlying(flight); player.setAllowFlight(flight); player.setFlying(flight); + if (flight) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().flightEnabled.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); } else { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().flightDisabled.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); } - return true; } @@ -80,8 +80,9 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { if (args.length == 2) { - return Stream.of("enable", "disable", "on", "off").filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return Arrays.asList("enable", "disable", "on", "off"); } + return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/HelpCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/HelpCommand.java index f884bae06..567db06a2 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/HelpCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/HelpCommand.java @@ -3,6 +3,10 @@ import com.iridium.iridiumcore.utils.StringUtils; import com.iridium.iridiumskyblock.IridiumSkyblock; import java.time.Duration; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; @@ -10,11 +14,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - /** * Command which shows users a list of all IridiumSkyblock commands. */ @@ -65,10 +64,12 @@ public boolean execute(CommandSender sender, String[] arguments) { .replace("%max_page%", String.valueOf(maxPage)))); TextComponent previousButton = new TextComponent(StringUtils.color(IridiumSkyblock.getInstance().getMessages().helpCommandPreviousPage)); TextComponent nextButton = new TextComponent(StringUtils.color(IridiumSkyblock.getInstance().getMessages().helpCommandNextPage)); + if (page != 1) { previousButton.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/is help " + (page - 1))); previousButton.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(StringUtils.color(IridiumSkyblock.getInstance().getMessages().helpCommandPreviousPageHover)).create())); } + if (page != maxPage) { nextButton.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/is help " + (page + 1))); nextButton.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(StringUtils.color(IridiumSkyblock.getInstance().getMessages().helpCommandNextPageHover)).create())); @@ -115,7 +116,7 @@ public List onTabComplete(CommandSender commandSender, org.bukkit.comman } // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/HomeCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/HomeCommand.java index d8b925335..28705f3ca 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/HomeCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/HomeCommand.java @@ -5,13 +5,12 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; import java.time.Duration; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which teleports users to their Island home. @@ -60,7 +59,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/InfoCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/InfoCommand.java index eebf377a6..45708adf6 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/InfoCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/InfoCommand.java @@ -4,17 +4,16 @@ import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; - +import com.iridium.iridiumskyblock.utils.PlayerUtils; import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which shows infos about an Island. @@ -43,6 +42,7 @@ public boolean execute(CommandSender sender, String[] arguments) { sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().mustBeAPlayer.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional userIsland = user.getIsland(); @@ -50,6 +50,7 @@ public boolean execute(CommandSender sender, String[] arguments) { sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + sendInfo(sender, userIsland.get(), user); return true; } @@ -67,6 +68,7 @@ public boolean execute(CommandSender sender, String[] arguments) { sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + sendInfo(sender, targetIsland.get(), targetUser); return true; } @@ -83,6 +85,7 @@ private void sendInfo(CommandSender sender, Island island, User requestedUser) { .filter(user -> user != island.getOwner()) .map(User::getName) .collect(Collectors.joining(", ")); + if (members.isEmpty()) { members = IridiumSkyblock.getInstance().getMessages().none; } @@ -111,7 +114,7 @@ private void sendInfo(CommandSender sender, Island island, User requestedUser) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/InviteCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/InviteCommand.java index 4cc465531..e5d295600 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/InviteCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/InviteCommand.java @@ -4,19 +4,21 @@ import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.LogAction; import com.iridium.iridiumskyblock.PermissionType; -import com.iridium.iridiumskyblock.database.*; +import com.iridium.iridiumskyblock.database.Island; +import com.iridium.iridiumskyblock.database.IslandInvite; +import com.iridium.iridiumskyblock.database.IslandLog; +import com.iridium.iridiumskyblock.database.IslandUpgrade; +import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.InvitesGUI; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; - +import com.iridium.iridiumskyblock.utils.PlayerUtils; import java.time.Duration; import java.util.Arrays; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which invites a user to the Island. @@ -47,32 +49,37 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (args.length == 1) { player.openInventory(new InvitesGUI(island.get()).getInventory()); return true; } + OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[1]); User offlinePlayerUser = IridiumSkyblock.getInstance().getUserManager().getUser(offlinePlayer); List islandMembers = IridiumSkyblock.getInstance().getIslandManager().getIslandMembers(island.get()); IslandUpgrade islandUpgrade = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), "member"); int memberLimit = IridiumSkyblock.getInstance().getUpgrades().memberUpgrade.upgrades.get(islandUpgrade.getLevel()).amount; - if (islandMembers.contains(offlinePlayerUser)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (IridiumSkyblock.getInstance().getIslandManager().getIslandInvite(island.get(), offlinePlayerUser).isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyInvited.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.INVITE)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotInviteMember.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (islandMembers.size() >= memberLimit) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandMemberLimitReached.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + IslandInvite islandInvite = new IslandInvite(island.get(), offlinePlayerUser, user); IridiumSkyblock.getInstance().getDatabaseManager().getIslandInviteTableManager().addEntry(islandInvite); IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_INVITED, user, offlinePlayerUser, 0, ""); @@ -110,7 +117,7 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/JoinCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/JoinCommand.java index 79e7026e7..bfb7e2f9e 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/JoinCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/JoinCommand.java @@ -5,18 +5,20 @@ import com.iridium.iridiumskyblock.IslandRank; import com.iridium.iridiumskyblock.LogAction; import com.iridium.iridiumskyblock.api.UserJoinEvent; -import com.iridium.iridiumskyblock.database.*; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; - +import com.iridium.iridiumskyblock.database.Island; +import com.iridium.iridiumskyblock.database.IslandInvite; +import com.iridium.iridiumskyblock.database.IslandLog; +import com.iridium.iridiumskyblock.database.IslandUpgrade; +import com.iridium.iridiumskyblock.database.User; +import com.iridium.iridiumskyblock.utils.PlayerUtils; import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which enables users to join other Islands. @@ -47,24 +49,25 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); - if (user.getIsland().isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyHaveIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[1]); User offlinePlayerUser = IridiumSkyblock.getInstance().getUserManager().getUser(offlinePlayer); Optional island = offlinePlayerUser.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNoIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + Optional islandInvite = IridiumSkyblock.getInstance().getIslandManager().getIslandInvite(island.get(), user); if (!islandInvite.isPresent() && !user.isBypass()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noInvite.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + IslandUpgrade islandUpgrade = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), "member"); int memberLimit = IridiumSkyblock.getInstance().getUpgrades().memberUpgrade.upgrades.get(islandUpgrade.getLevel()).amount; if (!user.isBypass() && island.get().getMembers().size() >= memberLimit) { @@ -106,7 +109,7 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/KickCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/KickCommand.java index e12ec7b80..359a14d87 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/KickCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/KickCommand.java @@ -9,17 +9,14 @@ import com.iridium.iridiumskyblock.database.IslandLog; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.utils.PlayerUtils; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which kicks a user from an Island. @@ -51,7 +48,6 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -59,15 +55,16 @@ public boolean execute(CommandSender sender, String[] args) { OfflinePlayer targetPlayer = Bukkit.getOfflinePlayer(args[1]); User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer); - if (!island.get().equals(targetUser.getIsland().orElse(null))) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNotInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (targetUser.getIslandRank().getLevel() >= user.getIslandRank().getLevel() || !IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.KICK)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotKickUser.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + UserKickEvent userKickEvent = new UserKickEvent(island.get(), targetUser, user); Bukkit.getPluginManager().callEvent(userKickEvent); if (userKickEvent.isCancelled()) return false; @@ -81,12 +78,12 @@ public boolean execute(CommandSender sender, String[] args) { // Send a message to all other members for (User member : island.get().getMembers()) { - Player p = Bukkit.getPlayer(member.getUuid()); - if (p != null) { - if (!p.equals(player)) { - p.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().kickedPlayer.replace("%kicker%", player.getName()).replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); + Player islandMember = Bukkit.getPlayer(member.getUuid()); + if (islandMember != null) { + if (!islandMember.equals(player)) { + islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().kickedPlayer.replace("%kicker%", player.getName()).replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); } else { - p.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youKickedPlayer.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); + islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youKickedPlayer.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); } } } @@ -107,7 +104,7 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/LeaveCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/LeaveCommand.java index bf6c41792..80216ecac 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/LeaveCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/LeaveCommand.java @@ -10,14 +10,13 @@ import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.ConfirmationGUI; import com.iridium.iridiumskyblock.utils.PlayerUtils; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which allows users to leave their Island. @@ -44,15 +43,16 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (user.getIslandRank().equals(IslandRank.OWNER)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotLeaveIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + player.openInventory(new ConfirmationGUI(() -> { UserLeaveEvent userLeaveEvent = new UserLeaveEvent(island.get(), user); Bukkit.getPluginManager().callEvent(userLeaveEvent); @@ -60,12 +60,14 @@ public boolean execute(CommandSender sender, String[] args) { user.setIsland(null); player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youHaveLeftIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); + for (User member : island.get().getMembers()) { - Player p = Bukkit.getPlayer(member.getUuid()); - if (p != null) { - p.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().playerLeftIsland.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); + Player islandMember = Bukkit.getPlayer(member.getUuid()); + if (islandMember != null) { + islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().playerLeftIsland.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); } } + PlayerUtils.teleportSpawn(player); IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_LEFT, user, null, 0, ""); IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog); @@ -87,7 +89,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/LevelCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/LevelCommand.java index 932e3d20b..804ffad62 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/LevelCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/LevelCommand.java @@ -4,14 +4,13 @@ import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class LevelCommand extends Command { @@ -39,6 +38,7 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notOnAnIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandLevel .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) .replace("%island_level%", String.valueOf(island.get().getLevel())) @@ -59,6 +59,8 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { + // We currently don't want to tab-completion here + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/LogsCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/LogsCommand.java index d80027e01..929999bf7 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/LogsCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/LogsCommand.java @@ -5,13 +5,12 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.LogsGUI; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which opens the Island bank GUI. @@ -37,7 +36,6 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -58,6 +56,8 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { + // We currently don't want to tab-completion here + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/MembersCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/MembersCommand.java index 880d6d52f..2d527a41c 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/MembersCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/MembersCommand.java @@ -5,13 +5,12 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.MembersGUI; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which shows an overview over the members of the Island and allows quick rank management. @@ -43,6 +42,7 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + player.openInventory(new MembersGUI(island.get()).getInventory()); return true; } @@ -59,7 +59,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/MissionCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/MissionCommand.java index 63f0bd4a4..8fe012cae 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/MissionCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/MissionCommand.java @@ -3,19 +3,19 @@ import com.iridium.iridiumcore.utils.StringUtils; import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.Mission; +import com.iridium.iridiumskyblock.Mission.MissionType; import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.InventoryConfigGUI; import com.iridium.iridiumskyblock.gui.MissionsGUI; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class MissionCommand extends Command { @@ -68,8 +68,10 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players - return Arrays.stream(Mission.MissionType.values()).map(Enum::name).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + // Return a new List, so it isn't a list of online players + return Arrays.stream(Mission.MissionType.values()) + .map(MissionType::name) + .collect(Collectors.toList()); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/PermissionsCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/PermissionsCommand.java index 218089246..c99f820a0 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/PermissionsCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/PermissionsCommand.java @@ -5,14 +5,13 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.IslandRanksGUI; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Commands which allows a user to manage the permissions of his Island. @@ -39,7 +38,6 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -61,7 +59,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/PositionCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/PositionCommand.java index 5abecf14b..44eae0908 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/PositionCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/PositionCommand.java @@ -4,11 +4,10 @@ import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.database.User; import java.time.Duration; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.util.Arrays; import java.util.List; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which sets a corner position of a schematic in our own schematic system. @@ -40,6 +39,7 @@ public boolean execute(CommandSender sender, String[] arguments) { User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); int positionType = Integer.parseInt(arguments[1]); + if (positionType == 1) { user.setSchematicPos1(player.getLocation()); } else if (positionType == 2) { diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/PrivateCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/PrivateCommand.java index a95ded34e..196cf61c8 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/PrivateCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/PrivateCommand.java @@ -5,13 +5,12 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.utils.PlayerUtils; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which makes the user's Island unvisitable. @@ -38,7 +37,6 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -54,11 +52,11 @@ public boolean execute(CommandSender sender, String[] args) { visitor.toPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().expelledIslandLocked.replace("%player%", user.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); visitorCount++; } + player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandNowPrivate .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) .replace("%amount%", String.valueOf(visitorCount))) ); - return true; } @@ -74,7 +72,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/PromoteCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/PromoteCommand.java index d9ac4b23f..cacf7a620 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/PromoteCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/PromoteCommand.java @@ -9,17 +9,15 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.IslandLog; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; - +import com.iridium.iridiumskyblock.utils.PlayerUtils; import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which promotes a user in the Island rank system. @@ -51,7 +49,6 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -64,23 +61,26 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNotInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + IslandRank nextRank = IslandRank.getByLevel(targetUser.getIslandRank().getLevel() + 1); if (nextRank == null || nextRank.getLevel() >= user.getIslandRank().getLevel() || !IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.PROMOTE)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotPromoteUser.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + UserPromoteEvent userPromoteEvent = new UserPromoteEvent(island.get(), user, nextRank); Bukkit.getPluginManager().callEvent(userPromoteEvent); if (userPromoteEvent.isCancelled()) return false; targetUser.setIslandRank(nextRank); + for (User member : island.get().getMembers()) { - Player p = Bukkit.getPlayer(member.getUuid()); - if (p != null) { - if (p.equals(player)) { - p.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().promotedPlayer.replace("%player%", targetUser.getName()).replace("%rank%", nextRank.getDisplayName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); + Player islandMember = Bukkit.getPlayer(member.getUuid()); + if (islandMember != null) { + if (islandMember.equals(player)) { + islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().promotedPlayer.replace("%player%", targetUser.getName()).replace("%rank%", nextRank.getDisplayName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); } else { - p.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userPromotedPlayer.replace("%promoter%", player.getName()).replace("%player%", targetUser.getName()).replace("%rank%", nextRank.getDisplayName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); + islandMember.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userPromotedPlayer.replace("%promoter%", player.getName()).replace("%player%", targetUser.getName()).replace("%rank%", nextRank.getDisplayName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); } } } @@ -101,7 +101,7 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/PublicCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/PublicCommand.java index ad029ac93..e11f71453 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/PublicCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/PublicCommand.java @@ -4,13 +4,12 @@ import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which makes the user's Island visitable. @@ -37,11 +36,11 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + island.get().setVisitable(true); sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandNowPublic.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return true; @@ -59,7 +58,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/RecalculateCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/RecalculateCommand.java index 6d308890d..19d0abd6a 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/RecalculateCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/RecalculateCommand.java @@ -3,16 +3,15 @@ import com.iridium.iridiumcore.utils.StringUtils; import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.database.Island; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.scheduler.BukkitTask; - import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.ListIterator; import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.scheduler.BukkitTask; /** * Command which display plugin information to the user. @@ -41,6 +40,7 @@ public boolean execute(CommandSender sender, String[] args) { sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().calculationAlreadyInProcess.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + int interval = 5; List islandList = IridiumSkyblock.getInstance().getDatabaseManager().getIslandTableManager().getEntries(); int seconds = (islandList.size() * interval / 20) % 60; @@ -67,6 +67,7 @@ public void run() { sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().calculatingFinished.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); } } + }, 0, interval); return true; } @@ -83,7 +84,7 @@ public void run() { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java index 7b848d48e..0699c9ce9 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/RegenCommand.java @@ -7,15 +7,14 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.IslandRegenGUI; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.stream.Collectors; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which resets the Island of a user. @@ -42,24 +41,27 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (args.length == 1) { if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.REGEN)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotRegenIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + player.openInventory(new IslandRegenGUI(player, getCooldownProvider()).getInventory()); return false; } + Optional schematicConfig = IridiumSkyblock.getInstance().getSchematics().schematics.entrySet().stream().filter(entry -> entry.getKey().equalsIgnoreCase(args[1])).map(Map.Entry::getValue).findFirst(); if (!schematicConfig.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownSchematic.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + IridiumSkyblock.getInstance().getIslandManager().regenerateIsland(island.get(), user, schematicConfig.get()); return true; } @@ -75,7 +77,7 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return IridiumSkyblock.getInstance().getSchematics().schematics.keySet().stream().filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return new ArrayList<>(IridiumSkyblock.getInstance().getSchematics().schematics.keySet()); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/ReloadCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/ReloadCommand.java index b87558376..b32e71686 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/ReloadCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/ReloadCommand.java @@ -3,10 +3,9 @@ import com.iridium.iridiumcore.utils.StringUtils; import com.iridium.iridiumskyblock.IridiumSkyblock; import java.time.Duration; -import org.bukkit.command.CommandSender; - import java.util.Collections; import java.util.List; +import org.bukkit.command.CommandSender; /** * Command which reloads all configuration files. @@ -47,7 +46,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/RenameCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/RenameCommand.java index 73d8ab3a5..d71944b2d 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/RenameCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/RenameCommand.java @@ -5,15 +5,14 @@ import com.iridium.iridiumskyblock.IslandRank; import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class RenameCommand extends Command { @@ -43,11 +42,13 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + String name = String.join(" ", Arrays.asList(args).subList(1, args.length)); if (!user.getIslandRank().equals(IslandRank.OWNER)) { player.sendMessage(IridiumSkyblock.getInstance().getMessages().cannotChangeName.replace("%prefix%", (IridiumSkyblock.getInstance().getConfiguration()).prefix)); return false; } + if (name.length() > (IridiumSkyblock.getInstance().getConfiguration()).maxIslandName) { player.sendMessage(StringUtils.color((IridiumSkyblock.getInstance().getMessages()).islandNameTooLong .replace("%prefix%", (IridiumSkyblock.getInstance().getConfiguration()).prefix) @@ -56,6 +57,7 @@ public boolean execute(CommandSender sender, String[] args) { )); return false; } + if (name.length() < (IridiumSkyblock.getInstance().getConfiguration()).minIslandName) { player.sendMessage(StringUtils.color((IridiumSkyblock.getInstance().getMessages()).islandNameTooShort .replace("%prefix%", (IridiumSkyblock.getInstance().getConfiguration()).prefix) @@ -64,6 +66,7 @@ public boolean execute(CommandSender sender, String[] args) { )); return false; } + island.get().setName(name); island.get().getMembers().forEach(member -> { Player islandMember = Bukkit.getPlayer(member.getUuid()); @@ -91,7 +94,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/RewardsCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/RewardsCommand.java index b6b5a9ede..84c19fdc4 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/RewardsCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/RewardsCommand.java @@ -5,13 +5,12 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.RewardsGUI; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which opens the Island rewards GUI. @@ -38,11 +37,11 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + player.openInventory(new RewardsGUI(island.get()).getInventory()); return true; } @@ -59,7 +58,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/SaveSchematicCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/SaveSchematicCommand.java index bb4c283f7..7d5812c27 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/SaveSchematicCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/SaveSchematicCommand.java @@ -4,18 +4,20 @@ import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.database.User; import java.time.Duration; +import java.util.Collections; +import java.util.List; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.Collections; -import java.util.List; - /** * Command which saves a schematic in our internal schematic system. */ public class SaveSchematicCommand extends Command { + /** + * The default constructor. + */ public SaveSchematicCommand() { super(Collections.singletonList("saveschematic"), "Create a schematic out of a selected area", "iridiumskyblock.schematic", true, Duration.ZERO); } @@ -69,7 +71,7 @@ public boolean execute(CommandSender sender, String[] arguments) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/SetHomeCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/SetHomeCommand.java index 313e0b8b5..0ea7d0375 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/SetHomeCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/SetHomeCommand.java @@ -5,13 +5,12 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.utils.LocationUtils; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which sets a User's Island home. @@ -38,7 +37,6 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -48,10 +46,12 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().onlySetHomeOnIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!LocationUtils.isSafe(player.getLocation())) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notSafe.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + island.get().setHome(player.getLocation()); player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().setHome.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return true; @@ -67,10 +67,9 @@ public boolean execute(CommandSender sender, String[] args) { * @return The list of tab completions for this command */ @Override - public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String - label, String[] args) { + public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/SetWarpCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/SetWarpCommand.java index 86f4636ef..559bfbdfc 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/SetWarpCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/SetWarpCommand.java @@ -8,14 +8,13 @@ import com.iridium.iridiumskyblock.database.IslandWarp; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.utils.LocationUtils; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class SetWarpCommand extends Command { @@ -44,11 +43,11 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.MANAGE_WARPS)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotManageWarps.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -59,19 +58,23 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().warpAlreadyExists.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + IslandUpgrade islandUpgrade = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), "warp"); if (islandWarps.size() >= IridiumSkyblock.getInstance().getUpgrades().warpsUpgrade.upgrades.get(islandUpgrade.getLevel()).amount) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().warpLimitReached.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!island.get().isInIsland(player.getLocation())) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().onlySetWarpOnIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!LocationUtils.isSafe(player.getLocation())) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notSafe.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + IslandWarp islandWarp = new IslandWarp(island.get(), player.getLocation(), args[1]); if (args.length == 3) { islandWarp.setPassword(args[2]); @@ -96,6 +99,8 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { + // We currently don't want to tab-completion here + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/ShopCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/ShopCommand.java index a659c4730..7b595676a 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/ShopCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/ShopCommand.java @@ -7,15 +7,14 @@ import com.iridium.iridiumskyblock.gui.ShopCategoryGUI; import com.iridium.iridiumskyblock.gui.ShopOverviewGUI; import com.iridium.iridiumskyblock.shop.ShopCategory; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which opens the island shop. @@ -77,7 +76,6 @@ public boolean execute(CommandSender sender, String[] arguments) { public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { return IridiumSkyblock.getInstance().getShopManager().getCategories().stream() .map(shopCategory -> shopCategory.name) - .filter(s -> s.toLowerCase().contains(args[1].toLowerCase())) .collect(Collectors.toList()); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/TopCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/TopCommand.java index 5f766b2aa..fd1c1e85d 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/TopCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/TopCommand.java @@ -2,11 +2,10 @@ import com.iridium.iridiumskyblock.gui.IslandTopGUI; import java.time.Duration; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.util.Collections; import java.util.List; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which opens the {@link IslandTopGUI}. @@ -47,7 +46,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/TransferCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/TransferCommand.java index d8d44ae06..1218d7ac9 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/TransferCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/TransferCommand.java @@ -5,17 +5,15 @@ import com.iridium.iridiumskyblock.IslandRank; import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; - +import com.iridium.iridiumskyblock.utils.PlayerUtils; import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which transfers Island ownership. @@ -47,7 +45,6 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -61,14 +58,17 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotTransferOwnership.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!island.get().equals(targetUser.getIsland().orElse(null))) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().userNotInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (islandOwner.getUuid().equals(targetPlayer.getUniqueId())) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotTransferYourself.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + islandOwner.setIslandRank(IslandRank.CO_OWNER); targetUser.setIslandRank(IslandRank.OWNER); for (User member : island.get().getMembers()) { @@ -95,7 +95,7 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/TrustCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/TrustCommand.java index 0db508b10..c7e996c2e 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/TrustCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/TrustCommand.java @@ -9,17 +9,15 @@ import com.iridium.iridiumskyblock.database.IslandTrusted; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.TrustedGUI; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; - +import com.iridium.iridiumskyblock.utils.PlayerUtils; import java.time.Duration; import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class TrustCommand extends Command { @@ -47,6 +45,7 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.TRUST)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotManageTrusts.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -56,20 +55,24 @@ public boolean execute(CommandSender sender, String[] args) { player.openInventory(new TrustedGUI(island.get()).getInventory()); return true; } + Player targetPlayer = Bukkit.getPlayer(args[1]); if (targetPlayer == null) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notAPlayer.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer); if (targetUser.getIsland().map(Island::getId).orElse(0) == island.get().getId()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyInYourIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island.get(), targetUser).isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().alreadyTrusted.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + IslandTrusted islandTrusted = new IslandTrusted(island.get(), targetUser, user); IridiumSkyblock.getInstance().getDatabaseManager().getIslandTrustedTableManager().addEntry(islandTrusted); @@ -100,7 +103,7 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/UnBanCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/UnBanCommand.java index 103213bc3..f1ccba67d 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/UnBanCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/UnBanCommand.java @@ -6,15 +6,14 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.IslandBan; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** @@ -47,26 +46,29 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), user, PermissionType.UNBAN)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noPermission.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + Player targetPlayer = Bukkit.getPlayer(args[1]); if (targetPlayer == null) { sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notAPlayer.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer); Optional islandBan = IridiumSkyblock.getInstance().getIslandManager().getIslandBan(island.get(), targetUser); if (!islandBan.isPresent()) { sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notBanned.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + Bukkit.getScheduler().runTaskAsynchronously(IridiumSkyblock.getInstance(), () -> IridiumSkyblock.getInstance().getDatabaseManager().getIslandBanTableManager().delete(islandBan.get())); targetPlayer.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().youHaveBeenUnBanned.replace("%player%", user.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); sender.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().playerUnBanned.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); @@ -83,15 +85,15 @@ public boolean execute(CommandSender sender, String[] args) { * @return The list of tab completions for this command */ @Override - public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String - label, String[] args) { + public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { Player player = (Player) commandSender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - return island.map(value -> IridiumSkyblock.getInstance().getDatabaseManager().getIslandBanTableManager().getEntries(value).stream().map(islandBan -> islandBan.getBannedUser().getName() - ).collect(Collectors.toList())).orElse(Collections.emptyList() - ); + return island.map(value -> IridiumSkyblock.getInstance().getDatabaseManager().getIslandBanTableManager().getEntries(value).stream() + .map(islandBan -> islandBan.getBannedUser().getName()) + .collect(Collectors.toList()) + ).orElse(Collections.emptyList()); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/UnInviteCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/UnInviteCommand.java index 813ca1b76..4238c1e2c 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/UnInviteCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/UnInviteCommand.java @@ -7,16 +7,14 @@ import com.iridium.iridiumskyblock.database.IslandInvite; import com.iridium.iridiumskyblock.database.IslandLog; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; - +import com.iridium.iridiumskyblock.utils.PlayerUtils; import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which un-invites a User from an Island. @@ -49,16 +47,17 @@ public boolean execute(CommandSender sender, String[] args) { User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(Bukkit.getServer().getOfflinePlayer(args[1])); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + Optional islandInvite = IridiumSkyblock.getInstance().getIslandManager().getIslandInvite(island.get(), targetUser); if (!islandInvite.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noActiveInvite.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + IridiumSkyblock.getInstance().getDatabaseManager().getIslandInviteTableManager().delete(islandInvite.get()); player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().inviteRevoked.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_UNINVITED, user, targetUser, 0, ""); @@ -77,7 +76,7 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/UnTrustCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/UnTrustCommand.java index 515f07064..b8d28a03c 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/UnTrustCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/UnTrustCommand.java @@ -8,16 +8,14 @@ import com.iridium.iridiumskyblock.database.IslandLog; import com.iridium.iridiumskyblock.database.IslandTrusted; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; - +import com.iridium.iridiumskyblock.utils.PlayerUtils; import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class UnTrustCommand extends Command { @@ -47,11 +45,11 @@ public boolean execute(CommandSender sender, String[] args) { User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(Bukkit.getServer().getOfflinePlayer(args[1])); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.TRUST)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotManageTrusts.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -62,6 +60,7 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().notTrusted.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + IridiumSkyblock.getInstance().getDatabaseManager().getIslandTrustedTableManager().delete(islandTrusted.get()); player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().trustRevoked.replace("%player%", targetUser.getName()).replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); IslandLog islandLog = new IslandLog(island.get(), LogAction.USER_UNTRUSTED, user, targetUser, 0, ""); @@ -80,7 +79,7 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/UpgradesCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/UpgradesCommand.java index e04bbce7b..f98055951 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/UpgradesCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/UpgradesCommand.java @@ -11,14 +11,13 @@ import com.iridium.iridiumskyblock.gui.UpgradesGUI; import com.iridium.iridiumskyblock.upgrades.UpgradeData; import com.iridium.iridiumskyblock.utils.PlayerUtils; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class UpgradesCommand extends Command { @@ -42,31 +41,35 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (args.length != 2) { player.openInventory(new UpgradesGUI(island.get()).getInventory()); return true; } + String upgradeName = args[1]; Upgrade upgrade = IridiumSkyblock.getInstance().getUpgradesList().get(upgradeName); if (upgrade == null) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownUpgrade.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + IslandUpgrade islandUpgrade = IridiumSkyblock.getInstance().getIslandManager().getIslandUpgrade(island.get(), upgradeName); UpgradeData upgradeData = upgrade.upgrades.get(islandUpgrade.getLevel() + 1); if (upgradeData == null) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().maxLevelReached.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!PlayerUtils.pay(player, island.get(), upgradeData.crystals, upgradeData.money)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotAfford.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + islandUpgrade.setLevel(islandUpgrade.getLevel() + 1); IslandLog islandLog = new IslandLog(island.get(), LogAction.UPGRADE_PURCHASE, user, null, 0, upgradeName); IridiumSkyblock.getInstance().getDatabaseManager().getIslandLogTableManager().addEntry(islandLog); @@ -86,7 +89,7 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return IridiumSkyblock.getInstance().getUpgradesList().keySet().stream().filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return new ArrayList<>(IridiumSkyblock.getInstance().getUpgradesList().keySet()); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/ValueCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/ValueCommand.java index 2ef9f03d9..80a5fb638 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/ValueCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/ValueCommand.java @@ -4,13 +4,12 @@ import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which shows the Island's value. @@ -37,11 +36,11 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandValue .replace("%rank%", String.valueOf(island.get().getRank())) .replace("%value%", String.valueOf(island.get().getValue())) @@ -62,7 +61,7 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { // We currently don't want to tab-completion here - // Return a new List so it isn't a list of online players + // Return a new List, so it isn't a list of online players return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/VisitCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/VisitCommand.java index 0f54451a1..1c8ff34fd 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/VisitCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/VisitCommand.java @@ -4,17 +4,15 @@ import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.VisitGUI; +import com.iridium.iridiumskyblock.utils.PlayerUtils; +import java.time.Duration; +import java.util.Collections; +import java.util.List; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; -import java.time.Duration; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - /** * Command which opens visitable islands or visits an island. */ @@ -45,15 +43,16 @@ public boolean execute(CommandSender sender, String[] args) { OfflinePlayer targetPlayer = Bukkit.getOfflinePlayer(args[1]); User targetUser = IridiumSkyblock.getInstance().getUserManager().getUser(targetPlayer); - if (!targetUser.getIsland().isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIslandFound.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!targetUser.getIsland().get().isVisitable() && !player.hasPermission("iridiumskyblock.visitbypass")) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().islandIsPrivate.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + IridiumSkyblock.getInstance().getIslandManager().teleportHome(player, targetUser.getIsland().get(), IridiumSkyblock.getInstance().getConfiguration().teleportDelay); return true; } @@ -69,7 +68,7 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/WarpsCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/WarpsCommand.java index 9b4833ae5..5f1970391 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/WarpsCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/WarpsCommand.java @@ -6,15 +6,14 @@ import com.iridium.iridiumskyblock.database.IslandWarp; import com.iridium.iridiumskyblock.database.User; import com.iridium.iridiumskyblock.gui.WarpsGUI; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class WarpsCommand extends Command { @@ -42,21 +41,25 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (args.length != 2 && args.length != 3) { player.openInventory(new WarpsGUI(island.get()).getInventory()); return true; } + List islandWarps = IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(island.get()); Optional islandWarp = islandWarps.stream().filter(warp -> warp.getName().equalsIgnoreCase(args[1])).findFirst(); if (!islandWarp.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().unknownWarp.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (islandWarp.get().getPassword() != null) { if (args.length != 3) { sender.sendMessage(StringUtils.color(syntax.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix).replace("%warp%", args[1]))); return false; } + if (!islandWarp.get().getPassword().equals(args[2])) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().incorrectPassword.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -82,10 +85,12 @@ public List onTabComplete(CommandSender commandSender, org.bukkit.comman User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); if (island.isPresent()) { - List islandWarps = - IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(island.get()); - return islandWarps.stream().map(IslandWarp::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + List islandWarps = IridiumSkyblock.getInstance().getDatabaseManager().getIslandWarpTableManager().getEntries(island.get()); + return islandWarps.stream() + .map(IslandWarp::getName) + .collect(Collectors.toList()); } + return Collections.emptyList(); } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/WithdrawCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/WithdrawCommand.java index 11d56ffdf..3208b1dc5 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/WithdrawCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/WithdrawCommand.java @@ -8,14 +8,13 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.IslandLog; import com.iridium.iridiumskyblock.database.User; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import java.time.Duration; import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * Command which withdraws a currency from the Island bank. @@ -47,11 +46,11 @@ public boolean execute(CommandSender sender, String[] args) { Player player = (Player) sender; User user = IridiumSkyblock.getInstance().getUserManager().getUser(player); Optional island = user.getIsland(); - if (!island.isPresent()) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + if (!IridiumSkyblock.getInstance().getIslandManager().getIslandPermission(island.get(), IridiumSkyblock.getInstance().getUserManager().getUser(player), PermissionType.WITHDRAW_BANK)) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotWithdraw.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; @@ -62,6 +61,7 @@ public boolean execute(CommandSender sender, String[] args) { player.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().noSuchBankItem.replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix))); return false; } + try { double amount = bankItem.get().withdraw(player, Double.parseDouble(args[2])); if (amount > 0) { @@ -86,7 +86,9 @@ public boolean execute(CommandSender sender, String[] args) { */ @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { - return IridiumSkyblock.getInstance().getBankItemList().stream().map(BankItem::getName).filter(s -> s.toLowerCase().contains(args[1].toLowerCase())).collect(Collectors.toList()); + return IridiumSkyblock.getInstance().getBankItemList().stream() + .map(BankItem::getName) + .collect(Collectors.toList()); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/bank/GiveCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/bank/GiveCommand.java index c59356849..3ca681f93 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/bank/GiveCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/bank/GiveCommand.java @@ -7,16 +7,15 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.IslandBank; import com.iridium.iridiumskyblock.database.User; +import com.iridium.iridiumskyblock.utils.PlayerUtils; import java.time.Duration; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; - import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class GiveCommand extends Command { @@ -64,11 +63,15 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { if (args.length == 3) { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).filter(s -> s.contains(args[2])).collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } + if (args.length == 4) { - return IridiumSkyblock.getInstance().getBankItemList().stream().map(BankItem::getName).filter(s -> s.contains(args[3])).collect(Collectors.toList()); + return IridiumSkyblock.getInstance().getBankItemList().stream() + .map(BankItem::getName) + .collect(Collectors.toList()); } + return Collections.emptyList(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/bank/RemoveCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/bank/RemoveCommand.java index e8c3ae334..80f4f9201 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/bank/RemoveCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/bank/RemoveCommand.java @@ -7,16 +7,15 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.IslandBank; import com.iridium.iridiumskyblock.database.User; +import com.iridium.iridiumskyblock.utils.PlayerUtils; import java.time.Duration; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; - import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class RemoveCommand extends Command { /** @@ -63,11 +62,15 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { if (args.length == 3) { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).filter(s -> s.contains(args[2])).collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } + if (args.length == 4) { - return IridiumSkyblock.getInstance().getBankItemList().stream().map(BankItem::getName).filter(s -> s.contains(args[3])).collect(Collectors.toList()); + return IridiumSkyblock.getInstance().getBankItemList().stream() + .map(BankItem::getName) + .collect(Collectors.toList()); } + return Collections.emptyList(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/commands/bank/SetCommand.java b/src/main/java/com/iridium/iridiumskyblock/commands/bank/SetCommand.java index 2befc0fe8..3a9f78c6d 100644 --- a/src/main/java/com/iridium/iridiumskyblock/commands/bank/SetCommand.java +++ b/src/main/java/com/iridium/iridiumskyblock/commands/bank/SetCommand.java @@ -7,16 +7,15 @@ import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.IslandBank; import com.iridium.iridiumskyblock.database.User; +import com.iridium.iridiumskyblock.utils.PlayerUtils; import java.time.Duration; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; - import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class SetCommand extends Command { /** @@ -63,11 +62,15 @@ public boolean execute(CommandSender sender, String[] args) { @Override public List onTabComplete(CommandSender commandSender, org.bukkit.command.Command command, String label, String[] args) { if (args.length == 3) { - return Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).filter(s -> s.contains(args[2])).collect(Collectors.toList()); + return PlayerUtils.getOnlinePlayerNames(); } + if (args.length == 4) { - return IridiumSkyblock.getInstance().getBankItemList().stream().map(BankItem::getName).filter(s -> s.contains(args[3])).collect(Collectors.toList()); + return IridiumSkyblock.getInstance().getBankItemList().stream() + .map(BankItem::getName) + .collect(Collectors.toList()); } + return Collections.emptyList(); } } diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Commands.java b/src/main/java/com/iridium/iridiumskyblock/configs/Commands.java index c5d3e110b..9ad40378b 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Commands.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Commands.java @@ -17,7 +17,7 @@ public class Commands { public BankCommand bankCommand = new BankCommand(); public BiomeCommand biomeCommand = new BiomeCommand(); public BlockValueCommand blockValueCommand = new BlockValueCommand(); - public BoostersCommand boostersCommand = new BoostersCommand(); + public BoosterCommand boostersCommand = new BoosterCommand(); public BorderCommand borderCommand = new BorderCommand(); public BypassCommand bypassCommand = new BypassCommand(); public ChatCommand chatCommand = new ChatCommand(); diff --git a/src/main/java/com/iridium/iridiumskyblock/gui/LogsGUI.java b/src/main/java/com/iridium/iridiumskyblock/gui/LogsGUI.java index 7c8d66923..d1ed916df 100644 --- a/src/main/java/com/iridium/iridiumskyblock/gui/LogsGUI.java +++ b/src/main/java/com/iridium/iridiumskyblock/gui/LogsGUI.java @@ -100,11 +100,11 @@ public void setItemStack(Inventory inventory, Item item, int page, LogAction... int maxPage = (int) Math.ceil(islandLogs.size() / 10.00); - itemMeta.setLore(lore.stream().map(s -> s + itemMeta.setLore(lore.stream() + .map(loreLine -> loreLine .replace("%current_page%", String.valueOf(page)) .replace("%max_page%", String.valueOf(maxPage > 0 ? maxPage : 1)) - ).collect(Collectors.toList()) - ); + ).collect(Collectors.toList())); itemStack.setItemMeta(itemMeta); inventory.setItem(item.slot, itemStack); } diff --git a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java index c824cd1f9..068f030dc 100644 --- a/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java +++ b/src/main/java/com/iridium/iridiumskyblock/managers/IslandManager.java @@ -52,7 +52,6 @@ public void clearIslandCache() { islandValueSortCache.clearCache(); } - /** * Creates a new world using the current skyblock generator. * diff --git a/src/main/java/com/iridium/iridiumskyblock/utils/PlayerUtils.java b/src/main/java/com/iridium/iridiumskyblock/utils/PlayerUtils.java index b4a0e3b77..265f6f293 100644 --- a/src/main/java/com/iridium/iridiumskyblock/utils/PlayerUtils.java +++ b/src/main/java/com/iridium/iridiumskyblock/utils/PlayerUtils.java @@ -6,6 +6,8 @@ import com.iridium.iridiumskyblock.IridiumSkyblock; import com.iridium.iridiumskyblock.database.Island; import com.iridium.iridiumskyblock.database.IslandBank; +import java.util.List; +import java.util.stream.Collectors; import net.milkbowl.vault.economy.Economy; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -137,4 +139,15 @@ public static void setTotalExperience(final Player player, final int exp) { } } + /** + * Returns a list of the names of all online players. + * + * @return The names of all players. + */ + public static List getOnlinePlayerNames() { + return Bukkit.getOnlinePlayers().stream() + .map(Player::getName) + .collect(Collectors.toList()); + } + }