diff --git a/README.md b/README.md index 9eae661..8809b79 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ To further customize the plugin, check `plugins/islands/config.yml`. | `islands.home` | Use /home command | | `islands.home.list` | Use /homes command | | `islands.turst` | Trust person | -| `islands.turst.list` | Not implemented | +| `islands.turst.list` | List island's trusted players | | `islands.untrust` | Untrust person | | `islands.visit` | Visit island | @@ -125,6 +125,7 @@ Bypasses | `islands.bypass.name` | Name anyone's island | | `islands.bypass.unname` | Unname anyone's island | | `islands.bypass.trust` | Add trusted person to anyone's island | +| `islands.bypass.trust.list` | List any island's trusted players | | `islands.bypass.untrust` | Remove trusted person from anyone's island | | `islands.bypass.protection` | Interact with anyone's island | | `islands.bypass.home` | Use /home from anywhere | diff --git a/src/me/aleksilassila/islands/Main.java b/src/me/aleksilassila/islands/Main.java index c5ffdbb..51c8e20 100644 --- a/src/me/aleksilassila/islands/Main.java +++ b/src/me/aleksilassila/islands/Main.java @@ -2,6 +2,7 @@ import me.aleksilassila.islands.commands.IslandCommands; import me.aleksilassila.islands.commands.IslandManagmentCommands; +import me.aleksilassila.islands.commands.TrustCommands; import me.aleksilassila.islands.generation.EmptyWorldGenerator; import me.aleksilassila.islands.listeners.IslandsListener; import net.milkbowl.vault.permission.Permission; @@ -56,8 +57,12 @@ public void onEnable() { islandCommands.new HomeCommand(); islandCommands.new VisitCommand(); - islandCommands.new TrustCommand(); - islandCommands.new UntrustCommand(); + + TrustCommands trustCommands = new TrustCommands(this); + + trustCommands.new UntrustCommand(); + trustCommands.new TrustCommand(); + trustCommands.new ListTrustedCommand(); new IslandsListener(this); diff --git a/src/me/aleksilassila/islands/Permissions.java b/src/me/aleksilassila/islands/Permissions.java index a57357e..9f62781 100644 --- a/src/me/aleksilassila/islands/Permissions.java +++ b/src/me/aleksilassila/islands/Permissions.java @@ -11,11 +11,8 @@ public static boolean checkPermission(Player player, String permission) { String[] parts = permission.split("\\."); - Bukkit.getLogger().info("Parts: " + String.join(" ", parts)); - for (int index = 0; index < parts.length; index++) { String joined = String.join(".", Arrays.copyOfRange(parts, 0, index + 1)); - Bukkit.getLogger().info("Starred: " + joined + ".*"); if (player.hasPermission(joined + ".*")) return true; } diff --git a/src/me/aleksilassila/islands/commands/IslandCommands.java b/src/me/aleksilassila/islands/commands/IslandCommands.java index f9f3c5c..c5b10a5 100644 --- a/src/me/aleksilassila/islands/commands/IslandCommands.java +++ b/src/me/aleksilassila/islands/commands/IslandCommands.java @@ -28,115 +28,6 @@ public IslandCommands(Main plugin) { this.grid = plugin.islands.grid; } - public class UntrustCommand implements CommandExecutor { - public UntrustCommand() { - plugin.getCommand("untrust").setExecutor(this); - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) return false; - - Player player = (Player) sender; - - plugin.islands.confirmations.remove(player.getUniqueId().toString()); - - if (!Permissions.checkPermission(player, Permissions.island.untrust)) { - player.sendMessage(Messages.error.NO_PERMISSION); - return true; - } - - - if (!player.getWorld().equals(plugin.islandsWorld)) { - player.sendMessage(Messages.error.WRONG_WORLD); - return true; - } - - - if (args.length != 1) { - player.sendMessage(Messages.help.UNTRUST); - return true; - } - - String ownerUUID = plugin.islands.grid.getBlockOwnerUUID(player.getLocation().getBlockX(), player.getLocation().getBlockZ()); - String islandId = plugin.islands.grid.getIslandId(player.getLocation().getBlockX(), player.getLocation().getBlockZ()); - - if (ownerUUID == null || islandId == null) { - player.sendMessage(Messages.error.NOT_ON_ISLAND); - return true; - } - - if (!ownerUUID.equals(player.getUniqueId().toString()) && !Permissions.checkPermission(player, Permissions.bypass.untrust)) { - player.sendMessage(Messages.error.NOT_OWNED); - return true; - } - - Player targetPlayer = Bukkit.getPlayer(args[0]); - - if (targetPlayer == null) { - player.sendMessage(Messages.error.PLAYER_NOT_FOUND); - return true; - } - - plugin.islands.grid.removeTrusted(islandId, targetPlayer.getUniqueId().toString()); - - player.sendMessage(Messages.success.UNTRUSTED); - - return true; - } - } - - public class TrustCommand implements CommandExecutor { - public TrustCommand() { - plugin.getCommand("trust").setExecutor(this); - } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!(sender instanceof Player)) return false; - - Player player = (Player) sender; - - plugin.islands.confirmations.remove(player.getUniqueId().toString()); - - if (!Permissions.checkPermission(player, Permissions.island.trust)) { - player.sendMessage(Messages.error.NO_PERMISSION); - return true; - } - - if (args.length != 1) { - player.sendMessage(Messages.help.TRUST); - return true; - } - - String ownerUUID = plugin.islands.grid.getBlockOwnerUUID(player.getLocation().getBlockX(), player.getLocation().getBlockZ()); - String islandId = plugin.islands.grid.getIslandId(player.getLocation().getBlockX(), player.getLocation().getBlockZ()); - - if (ownerUUID == null || islandId == null) { - player.sendMessage(Messages.error.NOT_ON_ISLAND); - return true; - } - - if (!ownerUUID.equals(player.getUniqueId().toString()) && !Permissions.checkPermission(player, Permissions.bypass.trust)) { - player.sendMessage(Messages.error.NOT_OWNED); - return true; - } - - Player targetPlayer = Bukkit.getPlayer(args[0]); - - if (targetPlayer == null) { - player.sendMessage(Messages.error.PLAYER_NOT_FOUND); - return true; - } - - plugin.islands.grid.addTrusted(islandId, targetPlayer.getUniqueId().toString()); - - player.sendMessage(Messages.success.TRUSTED); - - return true; - } - } - public class VisitCommand implements CommandExecutor { public VisitCommand() { @@ -174,7 +65,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St if (islandId != null) { player.teleport(plugin.islands.grid.getIslandSpawn(islandId)); } else { - player.sendMessage(Messages.error.ISLAND_NOT_FOUND); + player.sendMessage(Messages.error.HOME_NOT_FOUND); } return true; @@ -295,10 +186,7 @@ static class Messages extends ChatUtils { static class error { public static final String ISLAND_NOT_FOUND = error("404 - Home not found."); public static final String NO_PERMISSION = error("You don't have permission to use this command."); - public static final String NOT_ON_ISLAND = error("You have to be on an island."); - public static final String NOT_OWNED = error("You don't own this island."); - public static final String PLAYER_NOT_FOUND = error("Player not found."); - public static final String WRONG_WORLD = error("You can't use that command in this world."); + public static final String HOME_NOT_FOUND = error("404 - Home not found :("); public static String COOLDOWN(int remainingTime) { return error("You took damage recently. You have to wait for " + remainingTime + "s before teleporting."); @@ -306,8 +194,7 @@ public static String COOLDOWN(int remainingTime) { } static class success { - public static final String UNTRUSTED = success("Player untrusted!"); - public static final String TRUSTED = success("Player trusted!"); + public static String HOMES_FOUND(int amount) { return success("Found " + amount + " home(s)."); @@ -320,9 +207,6 @@ static class info { } static class help { - - public static final String UNTRUST = info("/untrust (You have to be on target island)"); - public static final String TRUST = info("/trust (You have to be on target island)"); public static final String VISIT = info("Usage: /visit name"); public static final String HOME = error("Usage: /home "); } diff --git a/src/me/aleksilassila/islands/commands/TrustCommands.java b/src/me/aleksilassila/islands/commands/TrustCommands.java new file mode 100644 index 0000000..2c3515e --- /dev/null +++ b/src/me/aleksilassila/islands/commands/TrustCommands.java @@ -0,0 +1,174 @@ +package me.aleksilassila.islands.commands; + +import me.aleksilassila.islands.Main; +import me.aleksilassila.islands.Permissions; +import me.aleksilassila.islands.utils.Messages; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.UUID; + +public class TrustCommands { + private Main plugin; + + public TrustCommands(Main plugin) { + this.plugin = plugin; + } + + public class UntrustCommand implements CommandExecutor { + public UntrustCommand() { + plugin.getCommand("untrust").setExecutor(this); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) return false; + + Player player = (Player) sender; + + plugin.islands.confirmations.remove(player.getUniqueId().toString()); + + if (!Permissions.checkPermission(player, Permissions.island.untrust)) { + player.sendMessage(Messages.error.NO_PERMISSION); + return true; + } + + + if (!player.getWorld().equals(plugin.islandsWorld)) { + player.sendMessage(Messages.error.WRONG_WORLD); + return true; + } + + + if (args.length != 1) { + player.sendMessage(Messages.help.UNTRUST); + return true; + } + + String ownerUUID = plugin.islands.grid.getBlockOwnerUUID(player.getLocation().getBlockX(), player.getLocation().getBlockZ()); + String islandId = plugin.islands.grid.getIslandId(player.getLocation().getBlockX(), player.getLocation().getBlockZ()); + + if (ownerUUID == null || islandId == null) { + player.sendMessage(Messages.error.NOT_ON_ISLAND); + return true; + } + + if (!ownerUUID.equals(player.getUniqueId().toString()) && !Permissions.checkPermission(player, Permissions.bypass.untrust)) { + player.sendMessage(Messages.error.NOT_OWNED); + return true; + } + + Player targetPlayer = Bukkit.getPlayer(args[0]); + + if (targetPlayer == null) { + player.sendMessage(Messages.error.PLAYER_NOT_FOUND); + return true; + } + + plugin.islands.grid.removeTrusted(islandId, targetPlayer.getUniqueId().toString()); + + player.sendMessage(Messages.success.UNTRUSTED); + + return true; + } + } + + public class TrustCommand implements CommandExecutor { + public TrustCommand() { + plugin.getCommand("trust").setExecutor(this); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) return false; + + Player player = (Player) sender; + + plugin.islands.confirmations.remove(player.getUniqueId().toString()); + + if (!Permissions.checkPermission(player, Permissions.island.trust)) { + player.sendMessage(Messages.error.NO_PERMISSION); + return true; + } + + if (args.length != 1) { + player.sendMessage(Messages.help.TRUST); + return true; + } + + String ownerUUID = plugin.islands.grid.getBlockOwnerUUID(player.getLocation().getBlockX(), player.getLocation().getBlockZ()); + String islandId = plugin.islands.grid.getIslandId(player.getLocation().getBlockX(), player.getLocation().getBlockZ()); + + if (ownerUUID == null || islandId == null) { + player.sendMessage(Messages.error.NOT_ON_ISLAND); + return true; + } + + if (!ownerUUID.equals(player.getUniqueId().toString()) && !Permissions.checkPermission(player, Permissions.bypass.trust)) { + player.sendMessage(Messages.error.NOT_OWNED); + return true; + } + + Player targetPlayer = Bukkit.getPlayer(args[0]); + + if (targetPlayer == null) { + player.sendMessage(Messages.error.PLAYER_NOT_FOUND); + return true; + } + + plugin.islands.grid.addTrusted(islandId, targetPlayer.getUniqueId().toString()); + + player.sendMessage(Messages.success.TRUSTED); + + return true; + } + } + + public class ListTrustedCommand implements CommandExecutor { + public ListTrustedCommand() { + plugin.getCommand("trusted").setExecutor(this); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) return false; + + Player player = (Player) sender; + + plugin.islands.confirmations.remove(player.getUniqueId().toString()); + + if (!Permissions.checkPermission(player, Permissions.island.listTrusted)) { + player.sendMessage(Messages.error.NO_PERMISSION); + return true; + } + + String ownerUUID = plugin.islands.grid.getBlockOwnerUUID(player.getLocation().getBlockX(), player.getLocation().getBlockZ()); + String islandId = plugin.islands.grid.getIslandId(player.getLocation().getBlockX(), player.getLocation().getBlockZ()); + + if (ownerUUID == null || islandId == null) { + player.sendMessage(Messages.error.NOT_ON_ISLAND); + return true; + } + + if (!ownerUUID.equals(player.getUniqueId().toString()) && !Permissions.checkPermission(player, Permissions.bypass.listTrusted)) { + player.sendMessage(Messages.error.NOT_OWNED); + return true; + } + + List trustedList = plugin.islands.grid.getTrusted(islandId); + + player.sendMessage(Messages.info.TRUSTED_INFO(trustedList.size())); + for (String uuid : trustedList) { + Player trustedPlayer = Bukkit.getPlayer(UUID.fromString(uuid)); + + if (trustedPlayer != null) player.sendMessage(Messages.info.TRUSTED_PLAYER(trustedPlayer.getDisplayName())); + } + + return true; + } + } +} diff --git a/src/me/aleksilassila/islands/generation/IslandGrid.java b/src/me/aleksilassila/islands/generation/IslandGrid.java index 05af2c1..4c9edc9 100644 --- a/src/me/aleksilassila/islands/generation/IslandGrid.java +++ b/src/me/aleksilassila/islands/generation/IslandGrid.java @@ -3,6 +3,7 @@ import com.sun.istack.internal.NotNull; import com.sun.istack.internal.Nullable; import me.aleksilassila.islands.Islands; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; @@ -269,12 +270,6 @@ public void removeTrusted(String islandId, String UUID) { @NotNull public List getTrusted(String islandId) { - ConfigurationSection section = getIslandsConfig().getConfigurationSection("islands." + islandId + ".trusted"); - - if (section == null) { - return new ArrayList<>(); - } - return getIslandsConfig().getStringList("islands." + islandId + ".trusted"); } diff --git a/src/me/aleksilassila/islands/utils/Messages.java b/src/me/aleksilassila/islands/utils/Messages.java index 2dc8ac3..cfc9543 100644 --- a/src/me/aleksilassila/islands/utils/Messages.java +++ b/src/me/aleksilassila/islands/utils/Messages.java @@ -15,8 +15,9 @@ public static class error { public static final String WRONG_WORLD = error("You can't use that command in this world."); public static final String SUBCOMMAND_NOT_FOUND = error("Invalid subcommand."); public static final String ERROR = "An internal error occurred. Contact staff."; - public static String ISLAND_GEN_FAILED = error("Island regeneration failed."); - public static String TELEPORT_FAILED = error("Could not teleport."); + public static final String NOT_ON_ISLAND = error("You have to be on an island."); + public static final String NOT_OWNED = error("You don't own this island."); + public static final String PLAYER_NOT_FOUND = error("Player not found."); public static String NO_BIOME_FOUND = error("Biome not found."); public static String NO_LOCATIONS_FOR_BIOME = error("No available locations for specified biome."); } @@ -26,7 +27,8 @@ public static class success { public static final String UNNAMED = success("Island unnamed and made private."); public static final String ISLAND_GEN_TITLE = ChatColor.GOLD + "Island generation event added to queue."; public static final String ISLAND_GEN_SUBTITLE = ChatColor.GOLD + "Explore the wilderness while your island is being generated. Use /home to access your island."; - public static String ISLAND_GEN = success("Island generation started."); + public static final String UNTRUSTED = success("Player untrusted!"); + public static final String TRUSTED = success("Player trusted!"); public static String OWNER_CHANGED(String name) { return success("Island owner switched to " + name + "."); @@ -43,9 +45,19 @@ public static String ISLAND_RECEIVED(String playerName, String islandName) { public static class info { public static final String CONFIRM = info("Are you sure? Repeat the command to confirm."); + + public static String TRUSTED_INFO(int numberOfPlayers) { + return info("You have trusted " + numberOfPlayers + " player(s)."); + } + + public static String TRUSTED_PLAYER(String displayName) { + return ChatColor.GRAY + " - " + displayName; + } } public static class help { + public static final String UNTRUST = info("/untrust (You have to be on target island)"); + public static final String TRUST = info("/trust (You have to be on target island)"); public static String CREATE = ChatColor.GRAY + "/island create ()"; public static String REGENERATE = ChatColor.GRAY + "/island regenerate () (You have to be on target island)"; public static String NAME = ChatColor.GRAY + "/island name (You have to be on target island)"; diff --git a/src/plugin.yml b/src/plugin.yml index c3eca3e..ed870e5 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,13 +1,10 @@ name: Islands -version: 1.0 +version: 1.1 author: Aleksi Lassila main: me.aleksilassila.islands.Main api-version: 1.16 softdepend: [Vault] commands: - go: - description: Your description - usage: / island: description: Island managment usage: / biome @@ -24,7 +21,10 @@ commands: usage: / trust: description: Trust a player + usage: / player + trusted: + description: List trusted players usage: / untrust: description: Untrust a player - usage: / + usage: / player