From f61069674cf4da6dc9a2e18658a96bb6beb8496e Mon Sep 17 00:00:00 2001 From: Flemmli97 Date: Wed, 9 Jun 2021 14:45:08 +0200 Subject: [PATCH] admin unlock items --- .../flemmli97/flan/commands/CommandClaim.java | 18 +++++++++++++++++- .../flemmli97/flan/config/LangCommands.java | 4 ++-- .../flemmli97/flan/config/LangConfig.java | 1 + .../permissionapi/CommandPermission.java | 2 ++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/flemmli97/flan/commands/CommandClaim.java b/src/main/java/io/github/flemmli97/flan/commands/CommandClaim.java index 8a6d851..1fe9cc9 100644 --- a/src/main/java/io/github/flemmli97/flan/commands/CommandClaim.java +++ b/src/main/java/io/github/flemmli97/flan/commands/CommandClaim.java @@ -55,7 +55,8 @@ public class CommandClaim { .then(CommandManager.literal("addClaim").requires(src -> CommandPermission.perm(src, CommandPermission.claimCreate)).then(CommandManager.argument("from", BlockPosArgumentType.blockPos()).then(CommandManager.argument("to", BlockPosArgumentType.blockPos()).executes(CommandClaim::addClaim)))) .then(CommandManager.literal("menu").requires(src -> CommandPermission.perm(src, CommandPermission.cmdMenu)).executes(CommandClaim::openMenu)) .then(CommandManager.literal("trapped").requires(src -> CommandPermission.perm(src, CommandPermission.cmdTrapped)).executes(CommandClaim::trapped)) - .then(CommandManager.literal("unlockDrops").executes(CommandClaim::unlockDrops)) + .then(CommandManager.literal("unlockDrops").executes(CommandClaim::unlockDrops) + .then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()).requires(src -> CommandPermission.perm(src, CommandPermission.cmdUnlockAll, true)).executes(CommandClaim::unlockDropsPlayers))) .then(CommandManager.literal("personalGroups").requires(src -> CommandPermission.perm(src, CommandPermission.cmdPGroup)).executes(CommandClaim::openPersonalGroups)) .then(CommandManager.literal("claimInfo").requires(src -> CommandPermission.perm(src, CommandPermission.cmdInfo)).executes(CommandClaim::claimInfo)) .then(CommandManager.literal("transferClaim").requires(src -> CommandPermission.perm(src, CommandPermission.cmdTransfer)).then(CommandManager.argument("player", GameProfileArgumentType.gameProfile()).executes(CommandClaim::transferClaim))) @@ -214,6 +215,21 @@ public class CommandClaim { return Command.SINGLE_SUCCESS; } + private static int unlockDropsPlayers(CommandContext context) throws CommandSyntaxException { + Collection profs = GameProfileArgumentType.getProfileArgument(context, "players"); + List success = new ArrayList<>(); + for (GameProfile prof : profs) { + ServerPlayerEntity player = context.getSource().getMinecraftServer().getPlayerManager().getPlayer(prof.getId()); + if (player != null) { + PlayerClaimData data = PlayerClaimData.get(player); + data.unlockDeathItems(); + success.add(prof.getName()); + } + } + context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.unlockDropsMulti, success), Formatting.GOLD), false); + return Command.SINGLE_SUCCESS; + } + private static int openPersonalGroups(CommandContext context) throws CommandSyntaxException { ServerPlayerEntity player = context.getSource().getPlayer(); PersonalGroupScreenHandler.openGroupMenu(player); diff --git a/src/main/java/io/github/flemmli97/flan/config/LangCommands.java b/src/main/java/io/github/flemmli97/flan/config/LangCommands.java index 43a9ebd..d92d5a4 100644 --- a/src/main/java/io/github/flemmli97/flan/config/LangCommands.java +++ b/src/main/java/io/github/flemmli97/flan/config/LangCommands.java @@ -15,7 +15,7 @@ public class LangCommands { map.put("deleteAll", new String[]{"deleteAll", "Deletes all your claims (you need to double type to confirm it so no accidents)."}); map.put("deleteSubClaim", new String[]{"deleteSubClaim", "Deletes the current subclaim."}); map.put("deleteAllSubClaims", new String[]{"deleteAllSubClaims", "Deletes all subclaim of the current claim."}); - map.put("list", new String[]{"list", "Lists all claims you have. If op also gives ability to list other players claims."}); + map.put("list", new String[]{"list ", "Lists all claims you have. If op also gives ability to list other players claims."}); map.put("switchMode", new String[]{"switchMode", "Switch between normal and subclaim mode."}); map.put("group", new String[]{"group (add | remove ) | (players add | remove [overwrite])", "- Adds/removes the group with that name. Also editable via the claim menu.", "- Adds/remove a player to the group. If overwrite then will overwrite the players current group else does nothing. Also editable via the claim menu."}); map.put("transferClaim", new String[]{"transferClaim ", "Gives ownership of the claim to the specified player. Only works if you're the claim owner."}); @@ -25,7 +25,7 @@ public class LangCommands { map.put("sellBlocks", new String[]{"sellBlocks ", "Sells claimblocks. Needs gunpowder currency installed."}); map.put("buyBlocks", new String[]{"buyBlocks ", "Buys claimblocks. Needs gunpowder currency installed."}); map.put("trapped", new String[]{"trapped", "If in a claim not owned by the player attempts to teleport the player out of it after 5 seconds."}); - map.put("unlockDrops", new String[]{"unlockDrops", "Unlocks dropped items from death so other players can pick them up too."}); + map.put("unlockDrops", new String[]{"unlockDrops ", "Unlocks dropped items from death so other players can pick them up too. Or all of the given players (needs OP)"}); map.put("reload", new String[]{"reload", "Reloads the config ingame."}); map.put("adminMode", new String[]{"adminMode", "Switches to admin mode ignoring all claims."}); diff --git a/src/main/java/io/github/flemmli97/flan/config/LangConfig.java b/src/main/java/io/github/flemmli97/flan/config/LangConfig.java index f2b836d..49dd2d4 100644 --- a/src/main/java/io/github/flemmli97/flan/config/LangConfig.java +++ b/src/main/java/io/github/flemmli97/flan/config/LangConfig.java @@ -126,6 +126,7 @@ public class LangConfig { public String unlockDropsCmd = "Your deathitems are protected. Use %s to unlock them for other players"; public String unlockDrops = "Your deathitems are now unlocked for %s ticks"; + public String unlockDropsMulti = "Unlocked drops for %s"; public LangCommands cmdLang = new LangCommands(); diff --git a/src/main/java/io/github/flemmli97/flan/integration/permissionapi/CommandPermission.java b/src/main/java/io/github/flemmli97/flan/integration/permissionapi/CommandPermission.java index f43b710..a96e9df 100644 --- a/src/main/java/io/github/flemmli97/flan/integration/permissionapi/CommandPermission.java +++ b/src/main/java/io/github/flemmli97/flan/integration/permissionapi/CommandPermission.java @@ -40,6 +40,8 @@ public class CommandPermission { public static final String cmdSell = "flan.command.buy"; public static final String cmdBuy = "flan.command.sell"; + public static final String cmdUnlockAll = "flan.command.unlock.all"; + public static boolean perm(CommandSource src, String perm) { return perm(src, perm, false); }