diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildCommand.java index 56caf6f0..194600f2 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/BuildCommand.java @@ -64,7 +64,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N } case 1: { - if (!player.hasPermission("buildsystem.build.others")) { + if (!player.hasPermission("buildsystem.build.other")) { plugin.sendPermissionMessage(player); return true; } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/GamemodeCommand.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/GamemodeCommand.java index ba9f207c..7304f08e 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/GamemodeCommand.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/command/GamemodeCommand.java @@ -46,37 +46,35 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N } Player player = (Player) sender; - if (!player.hasPermission("buildsystem.gamemode")) { - plugin.sendPermissionMessage(player); + if (args.length == 0) { + sendUsageMessage(player); return true; } - if (args.length != 0) { - switch (args[0].toLowerCase(Locale.ROOT)) { - case "survival": - case "s": - case "0": - setGamemode(player, args, GameMode.SURVIVAL, Messages.getString("gamemode_survival", player)); - break; - case "creative": - case "c": - case "1": - setGamemode(player, args, GameMode.CREATIVE, Messages.getString("gamemode_creative", player)); - break; - case "adventure": - case "a": - case "2": - setGamemode(player, args, GameMode.ADVENTURE, Messages.getString("gamemode_adventure", player)); - break; - case "spectator": - case "sp": - case "3": - setGamemode(player, args, GameMode.SPECTATOR, Messages.getString("gamemode_spectator", player)); - break; - default: - sendUsageMessage(player); - break; - } + switch (args[0].toLowerCase(Locale.ROOT)) { + case "survival": + case "s": + case "0": + setGamemode(player, args, GameMode.SURVIVAL, Messages.getString("gamemode_survival", player)); + break; + case "creative": + case "c": + case "1": + setGamemode(player, args, GameMode.CREATIVE, Messages.getString("gamemode_creative", player)); + break; + case "adventure": + case "a": + case "2": + setGamemode(player, args, GameMode.ADVENTURE, Messages.getString("gamemode_adventure", player)); + break; + case "spectator": + case "sp": + case "3": + setGamemode(player, args, GameMode.SPECTATOR, Messages.getString("gamemode_spectator", player)); + break; + default: + sendUsageMessage(player); + break; } return true; @@ -92,6 +90,7 @@ private void setGamemode(Player player, String[] args, GameMode gameMode, String break; default: this.sendUsageMessage(player); + break; } } @@ -100,7 +99,7 @@ private void sendUsageMessage(Player player) { } private void setPlayerGamemode(Player player, GameMode gameMode, String gameModeName) { - if (!player.hasPermission("buildsystem.gamemode")) { + if (!player.hasPermission(String.format("buildsystem.gamemode.%s", gameMode.name().toLowerCase(Locale.ROOT)))) { plugin.sendPermissionMessage(player); return; } @@ -110,7 +109,7 @@ private void setPlayerGamemode(Player player, GameMode gameMode, String gameMode } private void setTargetGamemode(Player player, String[] args, GameMode gameMode, String gameModeName) { - if (!player.hasPermission("buildsystem.gamemode.others")) { + if (!player.hasPermission(String.format("buildsystem.gamemode.%s.other", gameMode.name().toLowerCase(Locale.ROOT)))) { plugin.sendPermissionMessage(player); return; } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/BuildTabComplete.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/BuildTabComplete.java index f4524ed5..50276494 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/BuildTabComplete.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/BuildTabComplete.java @@ -47,7 +47,7 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman } if (args.length == 1) { - if (!player.hasPermission("buildsystem.build.others")) { + if (!player.hasPermission("buildsystem.build.other")) { Bukkit.getOnlinePlayers().forEach(pl -> addArgument(args[0], pl.getName(), arrayList)); } } diff --git a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/GamemodeTabComplete.java b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/GamemodeTabComplete.java index 8f3ca01c..7526b6ce 100644 --- a/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/GamemodeTabComplete.java +++ b/buildsystem-core/src/main/java/de/eintosti/buildsystem/tabcomplete/GamemodeTabComplete.java @@ -19,6 +19,7 @@ import de.eintosti.buildsystem.BuildSystem; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Locale; import org.bukkit.Bukkit; @@ -38,40 +39,45 @@ public GamemodeTabComplete(BuildSystem plugin) { @Override public List onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) { ArrayList arrayList = new ArrayList<>(); - if (!(sender instanceof Player)) { return arrayList; } - Player player = (Player) sender; - - if (!player.hasPermission("buildsystem.gamemode")) { - return arrayList; - } + Player player = (Player) sender; if (args.length == 1) { - for (GameMode gameMode : GameMode.values()) { - addArgument(args[0], gameMode.name().toLowerCase(Locale.ROOT), arrayList); - } + Arrays.stream(GameMode.values()) + .map(gameMode -> gameMode.name().toLowerCase(Locale.ROOT)) + .filter(gameModeName -> player.hasPermission(String.format("buildsystem.gamemode.%s", gameModeName))) + .forEach(gameModeName -> addArgument(args[0], gameModeName, arrayList)); } else if (args.length == 2) { - if (!player.hasPermission("buildsystem.gamemode.others")) { - return arrayList; - } - + String gameModeName; switch (args[0].toLowerCase(Locale.ROOT)) { case "survival": case "s": case "0": + gameModeName = GameMode.SURVIVAL.name().toLowerCase(Locale.ROOT); + break; case "creative": case "c": case "1": + gameModeName = GameMode.CREATIVE.name().toLowerCase(Locale.ROOT); + break; case "adventure": case "a": case "2": + gameModeName = GameMode.ADVENTURE.name().toLowerCase(Locale.ROOT); + break; case "spectator": case "sp": case "3": - Bukkit.getOnlinePlayers().forEach(pl -> addArgument(args[1], pl.getName(), arrayList)); + gameModeName = GameMode.SPECTATOR.name().toLowerCase(Locale.ROOT); break; + default: + return arrayList; + } + + if (player.hasPermission(String.format("buildsystem.gamemode.%s.other", gameModeName))) { + Bukkit.getOnlinePlayers().forEach(pl -> addArgument(args[1], pl.getName(), arrayList)); } } diff --git a/buildsystem-core/src/main/resources/plugin.yml b/buildsystem-core/src/main/resources/plugin.yml index cd02ce30..928b6d4c 100644 --- a/buildsystem-core/src/main/resources/plugin.yml +++ b/buildsystem-core/src/main/resources/plugin.yml @@ -99,6 +99,22 @@ permissions: - buildsystem.setstatus.notstarted default: op description: Permission for specific status states + buildsystem.gamemode: + children: + - buildsystem.gamemode.survival + - buildsystem.gamemode.creative + - buildsystem.gamemode.adventure + - buildsystem.gamemode.spectator + default: op + description: Permission for changing own gamemode + buildsystem.gamemode.other: + children: + - buildsystem.gamemode.survival.other + - buildsystem.gamemode.creative.other + - buildsystem.gamemode.adventure.other + - buildsystem.gamemode.spectator.other + default: op + description: Permission for changing other player's gamemode buildsystem.physics.message: description: Receive the message that physics are disabled in a world. default: true