2021-06-08 17:03:16 -04:00
|
|
|
package io.github.flemmli97.flan.commands;
|
2020-08-23 08:52:36 -04:00
|
|
|
|
2021-06-08 17:06:01 -04:00
|
|
|
import com.mojang.authlib.GameProfile;
|
|
|
|
import com.mojang.brigadier.Command;
|
|
|
|
import com.mojang.brigadier.CommandDispatcher;
|
|
|
|
import com.mojang.brigadier.arguments.BoolArgumentType;
|
|
|
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
|
|
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
|
|
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
|
|
import com.mojang.brigadier.context.CommandContext;
|
|
|
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
|
|
import com.mojang.brigadier.suggestion.Suggestions;
|
|
|
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
2021-06-08 17:03:16 -04:00
|
|
|
import io.github.flemmli97.flan.api.ClaimPermission;
|
|
|
|
import io.github.flemmli97.flan.api.PermissionRegistry;
|
|
|
|
import io.github.flemmli97.flan.claim.Claim;
|
|
|
|
import io.github.flemmli97.flan.claim.ClaimStorage;
|
|
|
|
import io.github.flemmli97.flan.claim.PermHelper;
|
|
|
|
import io.github.flemmli97.flan.config.ConfigHandler;
|
|
|
|
import io.github.flemmli97.flan.gui.ClaimMenuScreenHandler;
|
|
|
|
import io.github.flemmli97.flan.gui.PersonalGroupScreenHandler;
|
|
|
|
import io.github.flemmli97.flan.integration.gunpowder.CommandCurrency;
|
|
|
|
import io.github.flemmli97.flan.integration.permissionapi.CommandPermission;
|
|
|
|
import io.github.flemmli97.flan.player.EnumDisplayType;
|
|
|
|
import io.github.flemmli97.flan.player.EnumEditMode;
|
|
|
|
import io.github.flemmli97.flan.player.OfflinePlayerData;
|
|
|
|
import io.github.flemmli97.flan.player.PlayerClaimData;
|
2020-09-02 18:00:44 -04:00
|
|
|
import net.minecraft.command.argument.BlockPosArgumentType;
|
2020-08-23 08:52:36 -04:00
|
|
|
import net.minecraft.command.argument.GameProfileArgumentType;
|
2020-09-02 09:19:31 -04:00
|
|
|
import net.minecraft.server.MinecraftServer;
|
2020-08-23 08:52:36 -04:00
|
|
|
import net.minecraft.server.command.CommandManager;
|
|
|
|
import net.minecraft.server.command.CommandSource;
|
|
|
|
import net.minecraft.server.command.ServerCommandSource;
|
|
|
|
import net.minecraft.server.network.ServerPlayerEntity;
|
|
|
|
import net.minecraft.server.world.ServerWorld;
|
|
|
|
import net.minecraft.text.Text;
|
2020-08-23 17:18:18 -04:00
|
|
|
import net.minecraft.util.Formatting;
|
2020-08-23 08:52:36 -04:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2021-03-19 17:12:26 -04:00
|
|
|
import java.util.ArrayList;
|
2021-04-04 06:33:10 -04:00
|
|
|
import java.util.Collection;
|
2021-05-02 12:06:56 -04:00
|
|
|
import java.util.HashMap;
|
2020-08-23 08:52:36 -04:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2020-09-02 09:19:31 -04:00
|
|
|
import java.util.UUID;
|
2020-08-23 17:18:18 -04:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
2020-12-11 09:18:24 -05:00
|
|
|
import java.util.regex.Pattern;
|
2020-08-23 08:52:36 -04:00
|
|
|
|
|
|
|
public class CommandClaim {
|
|
|
|
|
|
|
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated) {
|
2021-05-02 15:39:06 -04:00
|
|
|
LiteralArgumentBuilder<ServerCommandSource> builder = CommandManager.literal("flan")
|
2021-03-09 07:29:26 -05:00
|
|
|
.then(CommandManager.literal("reload").requires(src -> CommandPermission.perm(src, CommandPermission.cmdReload, true)).executes(CommandClaim::reloadConfig))
|
|
|
|
.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))
|
2021-06-08 16:33:40 -04:00
|
|
|
.then(CommandManager.literal("trapped").requires(src -> CommandPermission.perm(src, CommandPermission.cmdTrapped)).executes(CommandClaim::trapped))
|
2021-06-09 06:49:19 -04:00
|
|
|
.then(CommandManager.literal("unlockDrops").executes(CommandClaim::unlockDrops))
|
2021-05-02 15:39:06 -04:00
|
|
|
.then(CommandManager.literal("personalGroups").requires(src -> CommandPermission.perm(src, CommandPermission.cmdPGroup)).executes(CommandClaim::openPersonalGroups))
|
2021-03-09 07:29:26 -05:00
|
|
|
.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)))
|
|
|
|
.then(CommandManager.literal("delete").requires(src -> CommandPermission.perm(src, CommandPermission.cmdTransfer)).executes(CommandClaim::deleteClaim))
|
|
|
|
.then(CommandManager.literal("deleteAll").requires(src -> CommandPermission.perm(src, CommandPermission.cmdTransfer)).executes(CommandClaim::deleteAllClaim))
|
|
|
|
.then(CommandManager.literal("deleteSubClaim").requires(src -> CommandPermission.perm(src, CommandPermission.cmdTransfer)).executes(CommandClaim::deleteSubClaim))
|
|
|
|
.then(CommandManager.literal("deleteAllSubClaims").requires(src -> CommandPermission.perm(src, CommandPermission.cmdTransfer)).executes(CommandClaim::deleteAllSubClaim))
|
|
|
|
.then(CommandManager.literal("list").requires(src -> CommandPermission.perm(src, CommandPermission.cmdList)).executes(CommandClaim::listClaims).then(CommandManager.argument("player", GameProfileArgumentType.gameProfile()).requires(src -> CommandPermission.perm(src, CommandPermission.cmdListAll, true))
|
2020-10-30 10:38:24 -04:00
|
|
|
.executes(cmd -> listClaims(cmd, GameProfileArgumentType.getProfileArgument(cmd, "player")))))
|
2021-03-09 07:29:26 -05:00
|
|
|
.then(CommandManager.literal("switchMode").requires(src -> CommandPermission.perm(src, CommandPermission.cmdClaimMode)).executes(CommandClaim::switchClaimMode))
|
|
|
|
.then(CommandManager.literal("adminMode").requires(src -> CommandPermission.perm(src, CommandPermission.cmdAdminMode, true)).executes(CommandClaim::switchAdminMode))
|
|
|
|
.then(CommandManager.literal("readGriefPrevention").requires(src -> CommandPermission.perm(src, CommandPermission.cmdGriefPrevention, true)).executes(CommandClaim::readGriefPreventionData))
|
|
|
|
.then(CommandManager.literal("setAdminClaim").requires(src -> CommandPermission.perm(src, CommandPermission.cmdAdminSet, true)).then(CommandManager.argument("toggle", BoolArgumentType.bool()).executes(CommandClaim::toggleAdminClaim)))
|
|
|
|
.then(CommandManager.literal("listAdminClaims").requires(src -> CommandPermission.perm(src, CommandPermission.cmdAdminList, true)).executes(CommandClaim::listAdminClaims))
|
|
|
|
.then(CommandManager.literal("adminDelete").requires(src -> CommandPermission.perm(src, CommandPermission.cmdAdminDelete, true)).executes(CommandClaim::adminDelete)
|
2020-08-25 15:32:00 -04:00
|
|
|
.then(CommandManager.literal("all").then(CommandManager.argument("players", GameProfileArgumentType.gameProfile())
|
2020-10-30 10:38:24 -04:00
|
|
|
.executes(CommandClaim::adminDeleteAll))))
|
2021-03-09 07:29:26 -05:00
|
|
|
.then(CommandManager.literal("giveClaimBlocks").requires(src -> CommandPermission.perm(src, CommandPermission.cmdAdminGive, true)).then(CommandManager.argument("players", GameProfileArgumentType.gameProfile())
|
2020-10-30 10:38:24 -04:00
|
|
|
.then(CommandManager.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::giveClaimBlocks))))
|
2021-05-31 08:30:18 -04:00
|
|
|
.then(CommandManager.literal("buyBlocks").requires(src -> CommandPermission.perm(src, CommandPermission.cmdBuy, false))
|
|
|
|
.then(CommandManager.argument("amount", IntegerArgumentType.integer()).executes(CommandCurrency::buyClaimBlocks)))
|
|
|
|
.then(CommandManager.literal("sellBlocks").requires(src -> CommandPermission.perm(src, CommandPermission.cmdSell, false))
|
|
|
|
.then(CommandManager.argument("amount", IntegerArgumentType.integer()).executes(CommandCurrency::sellClaimBlocks)))
|
2021-03-09 07:29:26 -05:00
|
|
|
.then(CommandManager.literal("group").requires(src -> CommandPermission.perm(src, CommandPermission.cmdGroup))
|
2020-12-11 09:18:24 -05:00
|
|
|
.then(CommandManager.literal("add").then(CommandManager.argument("group", StringArgumentType.string()).executes(CommandClaim::addGroup)))
|
|
|
|
.then(CommandManager.literal("remove").then(CommandManager.argument("group", StringArgumentType.string())
|
2020-10-30 10:38:24 -04:00
|
|
|
.suggests(CommandClaim::groupSuggestion).executes(CommandClaim::removeGroup)))
|
|
|
|
.then(CommandManager.literal("players")
|
|
|
|
.then(CommandManager.literal("add").then(CommandManager.argument("group", StringArgumentType.word()).suggests(CommandClaim::groupSuggestion)
|
2020-08-23 17:18:18 -04:00
|
|
|
.then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()).executes(CommandClaim::addPlayer)
|
2020-10-30 10:38:24 -04:00
|
|
|
.then(CommandManager.literal("overwrite").executes(CommandClaim::forceAddPlayer)))))
|
|
|
|
.then(CommandManager.literal("remove").then(CommandManager.argument("group", StringArgumentType.word()).suggests(CommandClaim::groupSuggestion)
|
2020-08-23 17:18:18 -04:00
|
|
|
.then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()).suggests((context, build) -> {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
2021-05-02 12:06:56 -04:00
|
|
|
List<String> list = new ArrayList<>();
|
2020-08-23 17:18:18 -04:00
|
|
|
ServerCommandSource src = context.getSource();
|
2020-08-25 13:43:52 -04:00
|
|
|
ClaimStorage storage = ClaimStorage.get(src.getWorld());
|
|
|
|
Claim claim = storage.getClaimAt(src.getPlayer().getBlockPos());
|
2020-11-28 14:53:29 -05:00
|
|
|
if (claim != null && claim.canInteract(src.getPlayer(), PermissionRegistry.EDITPERMS, src.getPlayer().getBlockPos())) {
|
2020-08-25 13:43:52 -04:00
|
|
|
list = claim.playersFromGroup(player.getServer(), "");
|
|
|
|
}
|
2020-08-23 17:18:18 -04:00
|
|
|
return CommandSource.suggestMatching(list, build);
|
2020-10-30 10:38:24 -04:00
|
|
|
}).executes(CommandClaim::removePlayer))))))
|
2021-03-09 07:29:26 -05:00
|
|
|
.then(CommandManager.literal("permission").requires(src -> CommandPermission.perm(src, CommandPermission.cmdPermission))
|
2021-05-02 15:39:06 -04:00
|
|
|
.then(CommandManager.literal("personal").then(CommandManager.argument("group", StringArgumentType.string()).suggests(CommandClaim::personalGroupSuggestion)
|
|
|
|
.then(CommandManager.argument("permission", StringArgumentType.word()).suggests((ctx, b) -> permSuggestions(ctx, b, true))
|
|
|
|
.then(CommandManager.argument("toggle", StringArgumentType.word())
|
|
|
|
.suggests((ctx, b) -> CommandSource.suggestMatching(new String[]{"default", "true", "false"}, b)).executes(CommandClaim::editPersonalPerm)))))
|
2020-10-30 10:38:24 -04:00
|
|
|
.then(CommandManager.literal("global").then(CommandManager.argument("permission", StringArgumentType.word()).suggests((ctx, b) -> permSuggestions(ctx, b, false))
|
|
|
|
.then(CommandManager.argument("toggle", StringArgumentType.word()).suggests((ctx, b) -> CommandSource.suggestMatching(new String[]{"default", "true", "false"}, b)).executes(CommandClaim::editGlobalPerm))))
|
2020-12-11 09:18:24 -05:00
|
|
|
.then(CommandManager.literal("group").then(CommandManager.argument("group", StringArgumentType.string()).suggests(CommandClaim::groupSuggestion)
|
2020-09-03 12:00:37 -04:00
|
|
|
.then(CommandManager.argument("permission", StringArgumentType.word()).suggests((ctx, b) -> permSuggestions(ctx, b, true))
|
|
|
|
.then(CommandManager.argument("toggle", StringArgumentType.word())
|
2021-05-02 15:39:06 -04:00
|
|
|
.suggests((ctx, b) -> CommandSource.suggestMatching(new String[]{"default", "true", "false"}, b)).executes(CommandClaim::editGroupPerm))))));
|
2021-06-09 08:06:12 -04:00
|
|
|
builder.then(CommandManager.literal("help").executes(ctx -> CommandHelp.helpMessage(ctx, 0, builder.getArguments()))
|
|
|
|
.then(CommandManager.argument("page", IntegerArgumentType.integer()).executes(ctx -> CommandHelp.helpMessage(ctx, builder.getArguments())))
|
2021-06-09 08:06:29 -04:00
|
|
|
.then(CommandManager.literal("cmd").then(CommandManager.argument("command", StringArgumentType.word()).suggests((ctx, sb) -> CommandSource.suggestMatching(CommandHelp.registeredCommands(ctx, builder.getArguments()), sb)).executes(ctx -> CommandHelp.helpCmd(ctx)))));
|
2021-05-02 15:39:06 -04:00
|
|
|
dispatcher.register(builder);
|
2020-08-23 08:52:36 -04:00
|
|
|
}
|
|
|
|
|
2020-08-25 13:43:52 -04:00
|
|
|
private static int reloadConfig(CommandContext<ServerCommandSource> context) {
|
2020-08-23 17:18:18 -04:00
|
|
|
ConfigHandler.reloadConfigs();
|
2020-08-25 14:35:38 -04:00
|
|
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.configReload), true);
|
2020-08-23 17:18:18 -04:00
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-09-02 18:00:44 -04:00
|
|
|
private static int addClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
|
|
|
BlockPos from = BlockPosArgumentType.getLoadedBlockPos(context, "from");
|
|
|
|
BlockPos to = BlockPosArgumentType.getLoadedBlockPos(context, "to");
|
|
|
|
storage.createClaim(from, to, player);
|
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-09-03 12:00:37 -04:00
|
|
|
private static int transferClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
Collection<GameProfile> profs = GameProfileArgumentType.getProfileArgument(context, "player");
|
|
|
|
if (profs.size() != 1) {
|
|
|
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.onlyOnePlayer, Formatting.RED), false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
GameProfile prof = profs.iterator().next();
|
|
|
|
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
|
|
|
Claim claim = storage.getClaimAt(player.getBlockPos());
|
|
|
|
if (claim == null) {
|
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
|
|
|
return 0;
|
|
|
|
}
|
2021-04-04 06:33:10 -04:00
|
|
|
PlayerClaimData data = PlayerClaimData.get(player);
|
|
|
|
boolean enoughBlocks = true;
|
|
|
|
if (!data.isAdminIgnoreClaim()) {
|
|
|
|
MinecraftServer server = context.getSource().getMinecraftServer();
|
|
|
|
ServerPlayerEntity newOwner = server.getPlayerManager().getPlayer(prof.getId());
|
|
|
|
if (newOwner != null) {
|
|
|
|
PlayerClaimData newData = PlayerClaimData.get(newOwner);
|
|
|
|
enoughBlocks = newData.canUseClaimBlocks(claim.getPlane());
|
|
|
|
} else {
|
|
|
|
OfflinePlayerData newData = new OfflinePlayerData(server, prof.getId());
|
|
|
|
enoughBlocks = ConfigHandler.config.maxClaimBlocks == -1 || newData.getUsedClaimBlocks(server) + claim.getPlane() < newData.claimBlocks + newData.additionalClaimBlocks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!enoughBlocks) {
|
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.ownerTransferNoBlocks, Formatting.RED), false);
|
|
|
|
if (CommandPermission.perm(context.getSource(), CommandPermission.cmdAdminMode, true))
|
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.ownerTransferNoBlocksAdmin, Formatting.RED), false);
|
|
|
|
return 0;
|
|
|
|
}
|
2020-09-03 12:00:37 -04:00
|
|
|
if (!storage.transferOwner(claim, player, prof.getId())) {
|
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.ownerTransferFail, Formatting.RED), false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.ownerTransferSuccess, prof.getName()), Formatting.GOLD), false);
|
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-08-23 17:18:18 -04:00
|
|
|
private static int openMenu(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
PlayerClaimData data = PlayerClaimData.get(player);
|
2020-08-25 13:43:52 -04:00
|
|
|
if (data.getEditMode() == EnumEditMode.DEFAULT) {
|
2020-11-28 14:53:29 -05:00
|
|
|
Claim claim = PermHelper.checkReturn(player, PermissionRegistry.EDITPERMS, PermHelper.genericNoPermMessage(player));
|
2020-08-24 15:03:06 -04:00
|
|
|
if (claim == null)
|
|
|
|
return 0;
|
|
|
|
ClaimMenuScreenHandler.openClaimMenu(player, claim);
|
2020-08-24 16:19:09 -04:00
|
|
|
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
|
2020-08-25 13:43:52 -04:00
|
|
|
} else {
|
2020-08-24 15:03:06 -04:00
|
|
|
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos());
|
|
|
|
Claim sub = claim.getSubClaim(player.getBlockPos());
|
2020-11-28 14:53:29 -05:00
|
|
|
if (sub != null && (claim.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos()) || sub.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos())))
|
2020-08-24 15:03:06 -04:00
|
|
|
ClaimMenuScreenHandler.openClaimMenu(player, sub);
|
2020-11-28 14:53:29 -05:00
|
|
|
else if (claim.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos()))
|
2020-08-24 15:03:06 -04:00
|
|
|
ClaimMenuScreenHandler.openClaimMenu(player, claim);
|
|
|
|
else
|
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermission, Formatting.DARK_RED), false);
|
|
|
|
}
|
2020-08-23 17:18:18 -04:00
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-06-08 16:33:40 -04:00
|
|
|
private static int trapped(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
PlayerClaimData data = PlayerClaimData.get(player);
|
|
|
|
if (data.setTrappedRescue()) {
|
|
|
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.trappedRescue, Formatting.GOLD), false);
|
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
} else {
|
|
|
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.trappedFail, Formatting.RED), false);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-09 06:49:19 -04:00
|
|
|
private static int unlockDrops(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
PlayerClaimData data = PlayerClaimData.get(player);
|
|
|
|
data.unlockDeathItems();
|
|
|
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.unlockDrops, ConfigHandler.config.dropTicks), Formatting.GOLD), false);
|
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-05-02 15:39:06 -04:00
|
|
|
private static int openPersonalGroups(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
PersonalGroupScreenHandler.openGroupMenu(player);
|
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-08-23 17:18:18 -04:00
|
|
|
private static int claimInfo(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos());
|
2020-08-24 15:03:06 -04:00
|
|
|
PlayerClaimData data = PlayerClaimData.get(player);
|
2020-09-03 12:00:37 -04:00
|
|
|
if (claim == null) {
|
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
return 0;
|
2020-09-03 12:00:37 -04:00
|
|
|
}
|
2020-08-25 13:43:52 -04:00
|
|
|
if (data.getEditMode() == EnumEditMode.SUBCLAIM) {
|
2020-08-24 15:03:06 -04:00
|
|
|
Claim sub = claim.getSubClaim(player.getBlockPos());
|
2020-08-25 13:43:52 -04:00
|
|
|
if (sub != null) {
|
2020-08-24 15:03:06 -04:00
|
|
|
List<Text> info = sub.infoString(player);
|
2021-05-02 15:39:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.claimSubHeader, Formatting.AQUA), false);
|
2020-08-24 15:03:06 -04:00
|
|
|
for (Text text : info)
|
|
|
|
player.sendMessage(text, false);
|
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2020-08-23 17:18:18 -04:00
|
|
|
List<Text> info = claim.infoString(player);
|
2020-08-24 15:03:06 -04:00
|
|
|
for (Text text : info)
|
2020-08-23 17:18:18 -04:00
|
|
|
player.sendMessage(text, false);
|
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int deleteClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
|
|
|
Claim claim = storage.getClaimAt(player.getBlockPos());
|
2020-11-28 14:53:29 -05:00
|
|
|
boolean check = PermHelper.check(player, player.getBlockPos(), claim, PermissionRegistry.EDITCLAIM, b -> {
|
2020-08-25 13:43:52 -04:00
|
|
|
if (!b.isPresent())
|
2020-08-24 15:03:06 -04:00
|
|
|
PermHelper.noClaimMessage(player);
|
2020-08-25 13:43:52 -04:00
|
|
|
else if (!b.get())
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaimError, Formatting.DARK_RED), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
else
|
2020-08-25 14:35:38 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaim, Formatting.RED), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
});
|
|
|
|
if (!check)
|
|
|
|
return 0;
|
2020-08-24 15:03:06 -04:00
|
|
|
storage.deleteClaim(claim, true, PlayerClaimData.get(player).getEditMode(), player.getServerWorld());
|
2020-08-23 17:18:18 -04:00
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int deleteAllClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
PlayerClaimData data = PlayerClaimData.get(player);
|
|
|
|
if (data.confirmedDeleteAll()) {
|
|
|
|
for (ServerWorld world : player.getServer().getWorlds()) {
|
|
|
|
ClaimStorage storage = ClaimStorage.get(world);
|
2020-08-25 13:43:52 -04:00
|
|
|
storage.allClaimsFromPlayer(player.getUuid()).forEach((claim) -> storage.deleteClaim(claim, true, PlayerClaimData.get(player).getEditMode(), player.getServerWorld()));
|
2020-08-23 17:18:18 -04:00
|
|
|
}
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaim, Formatting.GOLD), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
data.setConfirmDeleteAll(false);
|
|
|
|
} else {
|
|
|
|
data.setConfirmDeleteAll(true);
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false);
|
|
|
|
}
|
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int deleteSubClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
|
|
|
Claim claim = storage.getClaimAt(player.getBlockPos());
|
2020-08-25 13:43:52 -04:00
|
|
|
if (claim == null) {
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
Claim sub = claim.getSubClaim(player.getBlockPos());
|
2020-08-25 13:43:52 -04:00
|
|
|
if (sub == null) {
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
|
|
|
return 0;
|
2020-08-23 17:18:18 -04:00
|
|
|
}
|
2020-11-28 14:53:29 -05:00
|
|
|
boolean check = PermHelper.check(player, player.getBlockPos(), claim, PermissionRegistry.EDITCLAIM, b -> {
|
2020-08-25 13:43:52 -04:00
|
|
|
if (!b.isPresent())
|
2020-08-24 15:03:06 -04:00
|
|
|
PermHelper.noClaimMessage(player);
|
2020-08-25 13:43:52 -04:00
|
|
|
else if (!b.get())
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaimError, Formatting.DARK_RED), false);
|
|
|
|
else
|
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteSubClaim, Formatting.DARK_RED), false);
|
|
|
|
});
|
|
|
|
if (!check)
|
|
|
|
return 0;
|
|
|
|
claim.deleteSubClaim(sub);
|
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int deleteAllSubClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
2020-11-28 14:53:29 -05:00
|
|
|
Claim claim = PermHelper.checkReturn(player, PermissionRegistry.EDITCLAIM, PermHelper.genericNoPermMessage(player));
|
2020-08-25 13:43:52 -04:00
|
|
|
if (claim == null)
|
2020-08-24 15:03:06 -04:00
|
|
|
return 0;
|
|
|
|
List<Claim> subs = claim.getAllSubclaims();
|
|
|
|
subs.forEach(claim::deleteSubClaim);
|
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteSubClaimAll, Formatting.DARK_RED), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-08-25 13:43:52 -04:00
|
|
|
private static int listClaims(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
2020-09-02 09:19:31 -04:00
|
|
|
return listClaimsFromUUID(context, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int listClaims(CommandContext<ServerCommandSource> context, Collection<GameProfile> profs) throws CommandSyntaxException {
|
2020-09-02 09:36:58 -04:00
|
|
|
if (profs.size() != 1) {
|
2020-09-02 09:19:31 -04:00
|
|
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.onlyOnePlayer, Formatting.RED), false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
GameProfile prof = profs.iterator().next();
|
2020-09-02 09:36:58 -04:00
|
|
|
if (prof == null || prof.getId() == null)
|
2020-09-02 09:19:31 -04:00
|
|
|
return 0;
|
|
|
|
return listClaimsFromUUID(context, prof.getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int listClaimsFromUUID(CommandContext<ServerCommandSource> context, UUID of) throws CommandSyntaxException {
|
|
|
|
MinecraftServer server = context.getSource().getMinecraftServer();
|
2020-09-02 09:36:58 -04:00
|
|
|
ServerPlayerEntity player = of == null ? context.getSource().getPlayer() : server.getPlayerManager().getPlayer(of);
|
2021-05-02 12:06:56 -04:00
|
|
|
Map<World, Collection<Claim>> claims = new HashMap<>();
|
2020-09-02 09:19:31 -04:00
|
|
|
for (ServerWorld world : server.getWorlds()) {
|
2020-08-23 17:18:18 -04:00
|
|
|
ClaimStorage storage = ClaimStorage.get(world);
|
2020-09-02 09:36:58 -04:00
|
|
|
claims.put(world, storage.allClaimsFromPlayer(player != null ? player.getUuid() : of));
|
2020-08-23 17:18:18 -04:00
|
|
|
}
|
2020-11-28 14:53:29 -05:00
|
|
|
if (ConfigHandler.config.maxClaimBlocks != -1) {
|
2020-10-23 18:12:07 -04:00
|
|
|
if (player != null) {
|
|
|
|
PlayerClaimData data = PlayerClaimData.get(player);
|
|
|
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
|
|
|
data.getClaimBlocks(), data.getAdditionalClaims(), data.usedClaimBlocks()), Formatting.GOLD), false);
|
|
|
|
} else {
|
|
|
|
OfflinePlayerData data = new OfflinePlayerData(server, of);
|
|
|
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
|
|
|
data.claimBlocks, data.additionalClaimBlocks, data.getUsedClaimBlocks(server)), Formatting.GOLD), false);
|
|
|
|
}
|
2020-09-02 09:19:31 -04:00
|
|
|
}
|
|
|
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.listClaims, Formatting.GOLD), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
for (Map.Entry<World, Collection<Claim>> entry : claims.entrySet())
|
|
|
|
for (Claim claim : entry.getValue())
|
2020-09-02 09:19:31 -04:00
|
|
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(
|
2020-08-23 17:18:18 -04:00
|
|
|
entry.getKey().getRegistryKey().getValue().toString() + " # " + claim.formattedClaim(), Formatting.YELLOW), false);
|
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-08-25 13:43:52 -04:00
|
|
|
private static int switchClaimMode(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
2020-08-23 17:18:18 -04:00
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
PlayerClaimData data = PlayerClaimData.get(player);
|
|
|
|
data.setEditMode(data.getEditMode() == EnumEditMode.DEFAULT ? EnumEditMode.SUBCLAIM : EnumEditMode.DEFAULT);
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.editMode, data.getEditMode()), Formatting.GOLD), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-08-25 13:43:52 -04:00
|
|
|
private static int switchAdminMode(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
2020-08-23 17:18:18 -04:00
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
PlayerClaimData data = PlayerClaimData.get(player);
|
|
|
|
data.setAdminIgnoreClaim(!data.isAdminIgnoreClaim());
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.adminMode, data.isAdminIgnoreClaim()), Formatting.GOLD), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-08-25 13:43:52 -04:00
|
|
|
private static int adminDelete(CommandContext<ServerCommandSource> context) {
|
2020-08-23 17:18:18 -04:00
|
|
|
ServerCommandSource src = context.getSource();
|
|
|
|
ClaimStorage storage = ClaimStorage.get(src.getWorld());
|
|
|
|
Claim claim = storage.getClaimAt(new BlockPos(src.getPosition()));
|
|
|
|
if (claim == null) {
|
2020-08-24 15:03:06 -04:00
|
|
|
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2020-08-24 15:03:06 -04:00
|
|
|
storage.deleteClaim(claim, true, EnumEditMode.DEFAULT, src.getWorld());
|
|
|
|
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaim, Formatting.RED), true);
|
2020-08-23 17:18:18 -04:00
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int adminDeleteAll(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerCommandSource src = context.getSource();
|
2020-08-25 13:43:52 -04:00
|
|
|
if (src.getEntity() instanceof ServerPlayerEntity) {
|
2020-08-23 17:18:18 -04:00
|
|
|
ServerPlayerEntity player = (ServerPlayerEntity) src.getEntity();
|
|
|
|
PlayerClaimData data = PlayerClaimData.get(player);
|
2020-08-25 13:43:52 -04:00
|
|
|
if (!data.confirmedDeleteAll()) {
|
2020-08-23 17:18:18 -04:00
|
|
|
data.setConfirmDeleteAll(true);
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2021-05-02 12:06:56 -04:00
|
|
|
List<String> players = new ArrayList<>();
|
2020-08-25 13:43:52 -04:00
|
|
|
for (GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) {
|
2020-08-23 17:18:18 -04:00
|
|
|
for (ServerWorld world : src.getWorld().getServer().getWorlds()) {
|
|
|
|
ClaimStorage storage = ClaimStorage.get(world);
|
2020-08-25 13:43:52 -04:00
|
|
|
storage.allClaimsFromPlayer(prof.getId()).forEach((claim) -> storage.deleteClaim(claim, true, EnumEditMode.DEFAULT, world));
|
2020-08-23 17:18:18 -04:00
|
|
|
}
|
|
|
|
players.add(prof.getName());
|
|
|
|
}
|
2020-08-24 15:03:06 -04:00
|
|
|
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.adminDeleteAll, players.toString()), Formatting.GOLD), true);
|
2020-08-23 17:18:18 -04:00
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-09-02 09:19:31 -04:00
|
|
|
private static int toggleAdminClaim(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
|
|
|
Claim claim = storage.getClaimAt(player.getBlockPos());
|
2020-08-23 17:18:18 -04:00
|
|
|
if (claim == null) {
|
2020-09-02 09:19:31 -04:00
|
|
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2020-09-02 09:19:31 -04:00
|
|
|
storage.toggleAdminClaim(player, claim, BoolArgumentType.getBool(context, "toggle"));
|
|
|
|
context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.setAdminClaim, claim.isAdminClaim()), Formatting.GOLD), true);
|
2020-08-24 15:03:06 -04:00
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-09-03 12:00:37 -04:00
|
|
|
private static int listAdminClaims(CommandContext<ServerCommandSource> context) {
|
2020-08-25 15:06:36 -04:00
|
|
|
ServerCommandSource src = context.getSource();
|
|
|
|
Collection<Claim> claims = ClaimStorage.get(src.getWorld()).getAdminClaims();
|
|
|
|
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.listAdminClaims, src.getWorld().getRegistryKey().getValue()), Formatting.GOLD), false);
|
|
|
|
for (Claim claim : claims)
|
|
|
|
src.sendFeedback(PermHelper.simpleColoredText(claim.formattedClaim(), Formatting.YELLOW), false);
|
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-08-25 13:43:52 -04:00
|
|
|
private static int readGriefPreventionData(CommandContext<ServerCommandSource> context) {
|
2020-08-24 15:03:06 -04:00
|
|
|
ServerCommandSource src = context.getSource();
|
|
|
|
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.readGriefpreventionData, Formatting.GOLD), true);
|
2020-09-02 09:19:31 -04:00
|
|
|
ClaimStorage.readGriefPreventionData(src.getMinecraftServer(), src);
|
|
|
|
PlayerClaimData.readGriefPreventionPlayerData(src.getMinecraftServer(), src);
|
|
|
|
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.readGriefpreventionDataSuccess, Formatting.GOLD), true);
|
2020-08-23 17:18:18 -04:00
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int giveClaimBlocks(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerCommandSource src = context.getSource();
|
2021-05-02 12:06:56 -04:00
|
|
|
List<String> players = new ArrayList<>();
|
2020-08-23 17:18:18 -04:00
|
|
|
int amount = IntegerArgumentType.getInteger(context, "amount");
|
2020-08-25 13:43:52 -04:00
|
|
|
for (GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) {
|
2020-08-23 17:18:18 -04:00
|
|
|
ServerPlayerEntity player = src.getMinecraftServer().getPlayerManager().getPlayer(prof.getId());
|
|
|
|
if (player != null) {
|
|
|
|
PlayerClaimData data = PlayerClaimData.get(player);
|
|
|
|
data.setAdditionalClaims(data.getAdditionalClaims() + amount);
|
|
|
|
} else
|
|
|
|
PlayerClaimData.editForOfflinePlayer(src.getMinecraftServer(), prof.getId(), amount);
|
|
|
|
players.add(prof.getName());
|
|
|
|
}
|
2020-08-24 15:03:06 -04:00
|
|
|
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.giveClaimBlocks, players.toString(), amount), Formatting.GOLD), true);
|
2020-08-23 17:18:18 -04:00
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-12-11 09:18:24 -05:00
|
|
|
private static final Pattern allowed = Pattern.compile("[a-zA-Z0-9_+.-]+");
|
|
|
|
|
2020-08-23 17:18:18 -04:00
|
|
|
private static CompletableFuture<Suggestions> groupSuggestion(CommandContext<ServerCommandSource> context, SuggestionsBuilder build) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
2021-05-02 12:06:56 -04:00
|
|
|
List<String> list = new ArrayList<>();
|
2020-08-23 17:18:18 -04:00
|
|
|
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
|
|
|
Claim claim = storage.getClaimAt(player.getBlockPos());
|
2020-11-28 14:53:29 -05:00
|
|
|
if (claim != null && claim.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos())) {
|
2020-08-23 17:18:18 -04:00
|
|
|
list = claim.groups();
|
|
|
|
}
|
2020-12-11 10:30:47 -05:00
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
if (allowed.matcher(list.get(i)).matches())
|
2020-12-11 09:18:24 -05:00
|
|
|
continue;
|
2020-12-11 10:30:47 -05:00
|
|
|
list.set(i, '\"' + list.get(i) + '\"');
|
2020-12-11 09:18:24 -05:00
|
|
|
}
|
2020-08-23 17:18:18 -04:00
|
|
|
return CommandSource.suggestMatching(list, build);
|
|
|
|
}
|
|
|
|
|
2021-05-02 15:39:06 -04:00
|
|
|
private static CompletableFuture<Suggestions> personalGroupSuggestion(CommandContext<ServerCommandSource> context, SuggestionsBuilder build) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
List<String> list = new ArrayList<>(PlayerClaimData.get(player).playerDefaultGroups().keySet());
|
|
|
|
list.sort(null);
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
if (allowed.matcher(list.get(i)).matches())
|
|
|
|
continue;
|
|
|
|
list.set(i, '\"' + list.get(i) + '\"');
|
|
|
|
}
|
|
|
|
return CommandSource.suggestMatching(list, build);
|
|
|
|
}
|
|
|
|
|
2020-08-23 17:18:18 -04:00
|
|
|
private static int addGroup(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
return modifyGroup(context, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int removeGroup(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
return modifyGroup(context, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int modifyGroup(CommandContext<ServerCommandSource> context, boolean remove) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
String group = StringArgumentType.getString(context, "group");
|
|
|
|
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
|
|
|
Claim claim = storage.getClaimAt(player.getBlockPos());
|
|
|
|
if (claim == null) {
|
2020-08-24 15:03:06 -04:00
|
|
|
PermHelper.noClaimMessage(player);
|
2020-08-23 17:18:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2020-08-25 13:43:52 -04:00
|
|
|
if (remove) {
|
2020-08-23 17:18:18 -04:00
|
|
|
if (claim.removePermGroup(player, group))
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.groupRemove, group), Formatting.GOLD), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
else {
|
2020-08-24 15:03:06 -04:00
|
|
|
PermHelper.genericNoPermMessage(player);
|
2020-08-23 17:18:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2020-08-25 13:43:52 -04:00
|
|
|
} else {
|
|
|
|
if (claim.groups().contains(group)) {
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.groupExist, group), Formatting.RED), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
return 0;
|
2020-11-28 14:53:29 -05:00
|
|
|
} else if (claim.editPerms(player, group, PermissionRegistry.EDITPERMS, -1))
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.groupAdd, group), Formatting.GOLD), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
else {
|
2020-08-24 15:03:06 -04:00
|
|
|
PermHelper.genericNoPermMessage(player);
|
2020-08-23 17:18:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int forceAddPlayer(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
String group = StringArgumentType.getString(context, "group");
|
|
|
|
return modifyPlayer(context, group, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int addPlayer(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
String group = StringArgumentType.getString(context, "group");
|
|
|
|
return modifyPlayer(context, group, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int removePlayer(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
return modifyPlayer(context, null, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int modifyPlayer(CommandContext<ServerCommandSource> context, String group, boolean force) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
|
|
|
Claim claim = storage.getClaimAt(player.getBlockPos());
|
|
|
|
if (claim == null) {
|
2020-08-24 15:03:06 -04:00
|
|
|
PermHelper.noClaimMessage(player);
|
2020-08-23 17:18:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2020-11-28 14:53:29 -05:00
|
|
|
if (!claim.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos())) {
|
2020-08-24 15:03:06 -04:00
|
|
|
PermHelper.genericNoPermMessage(player);
|
2020-08-23 17:18:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2021-05-02 12:06:56 -04:00
|
|
|
List<String> modified = new ArrayList<>();
|
2020-08-25 13:43:52 -04:00
|
|
|
for (GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) {
|
|
|
|
if (claim.setPlayerGroup(prof.getId(), group, force))
|
2020-08-23 17:18:18 -04:00
|
|
|
modified.add(prof.getName());
|
|
|
|
}
|
2020-08-25 13:43:52 -04:00
|
|
|
if (!modified.isEmpty())
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.playerModify, group, modified), Formatting.GOLD), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
else
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.playerModifyNo, group, modified), Formatting.RED), false);
|
2020-08-23 17:18:18 -04:00
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
2020-09-03 12:00:37 -04:00
|
|
|
|
|
|
|
private static CompletableFuture<Suggestions> permSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder build, boolean group) {
|
2020-10-30 10:09:57 -04:00
|
|
|
ServerWorld world = context.getSource().getWorld();
|
|
|
|
Claim claim = ClaimStorage.get(world).getClaimAt(new BlockPos(context.getSource().getPosition()));
|
|
|
|
boolean admin = claim != null && claim.isAdminClaim();
|
2021-03-19 17:12:26 -04:00
|
|
|
List<String> allowedPerms = new ArrayList<>();
|
2020-11-28 14:53:29 -05:00
|
|
|
for (ClaimPermission perm : PermissionRegistry.getPerms()) {
|
2020-12-11 10:21:46 -05:00
|
|
|
if (!admin && ConfigHandler.config.globallyDefined(world, perm)) {
|
2020-10-30 10:09:57 -04:00
|
|
|
continue;
|
|
|
|
}
|
2020-11-28 14:53:29 -05:00
|
|
|
if (!group || !PermissionRegistry.globalPerms().contains(perm))
|
2021-03-19 17:12:26 -04:00
|
|
|
allowedPerms.add(perm.id);
|
2020-09-03 12:00:37 -04:00
|
|
|
}
|
2021-03-19 17:12:26 -04:00
|
|
|
return CommandSource.suggestMatching(allowedPerms, build);
|
2020-09-03 12:00:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private static int editGlobalPerm(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
int mode = 0;
|
|
|
|
switch (StringArgumentType.getString(context, "toggle")) {
|
|
|
|
case "true":
|
|
|
|
mode = 1;
|
|
|
|
break;
|
|
|
|
case "false":
|
|
|
|
mode = 0;
|
|
|
|
break;
|
|
|
|
case "default":
|
|
|
|
mode = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return editPerms(context, null, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int editGroupPerm(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
int mode = 0;
|
|
|
|
switch (StringArgumentType.getString(context, "toggle")) {
|
|
|
|
case "true":
|
|
|
|
mode = 1;
|
|
|
|
break;
|
|
|
|
case "false":
|
|
|
|
mode = 0;
|
|
|
|
break;
|
|
|
|
case "default":
|
|
|
|
mode = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return editPerms(context, StringArgumentType.getString(context, "group"), mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static int editPerms(CommandContext<ServerCommandSource> context, String group, int mode) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos());
|
|
|
|
PlayerClaimData data = PlayerClaimData.get(player);
|
|
|
|
if (data.getEditMode() == EnumEditMode.SUBCLAIM) {
|
|
|
|
Claim sub = claim.getSubClaim(player.getBlockPos());
|
|
|
|
if (sub != null)
|
|
|
|
claim = sub;
|
|
|
|
}
|
|
|
|
if (claim == null) {
|
|
|
|
PermHelper.noClaimMessage(player);
|
|
|
|
return 0;
|
|
|
|
}
|
2020-11-28 14:53:29 -05:00
|
|
|
if (!claim.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos())) {
|
2020-09-03 12:00:37 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermission, Formatting.DARK_RED), false);
|
|
|
|
return 0;
|
|
|
|
}
|
2020-11-28 14:53:29 -05:00
|
|
|
ClaimPermission perm;
|
2020-09-03 12:00:37 -04:00
|
|
|
String p = StringArgumentType.getString(context, "permission");
|
|
|
|
try {
|
2020-11-28 14:53:29 -05:00
|
|
|
perm = PermissionRegistry.get(p);
|
|
|
|
if (group != null && PermissionRegistry.globalPerms().contains(perm))
|
2020-09-03 12:00:37 -04:00
|
|
|
throw new IllegalArgumentException();
|
2020-11-28 14:53:29 -05:00
|
|
|
} catch (NullPointerException e) {
|
2020-09-03 12:00:37 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.noSuchPerm, p), Formatting.DARK_RED), false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
String setPerm = mode == 1 ? "true" : mode == 0 ? "false" : "default";
|
|
|
|
if (group == null) {
|
2020-10-30 10:09:57 -04:00
|
|
|
claim.editGlobalPerms(player, perm, mode);
|
2020-09-03 12:00:37 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.editPerm, perm, setPerm), Formatting.GOLD), false);
|
|
|
|
} else {
|
|
|
|
claim.editPerms(player, group, perm, mode);
|
|
|
|
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.editPermGroup, perm, group, setPerm), Formatting.GOLD), false);
|
|
|
|
}
|
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
2021-05-02 15:39:06 -04:00
|
|
|
|
|
|
|
private static int editPersonalPerm(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
String group = StringArgumentType.getString(context, "group");
|
|
|
|
int mode = 0;
|
|
|
|
switch (StringArgumentType.getString(context, "toggle")) {
|
|
|
|
case "true":
|
|
|
|
mode = 1;
|
|
|
|
break;
|
|
|
|
case "false":
|
|
|
|
mode = 0;
|
|
|
|
break;
|
|
|
|
case "default":
|
|
|
|
mode = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ClaimPermission perm;
|
|
|
|
String p = StringArgumentType.getString(context, "permission");
|
|
|
|
try {
|
|
|
|
perm = PermissionRegistry.get(p);
|
|
|
|
if (PermissionRegistry.globalPerms().contains(perm))
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
} catch (NullPointerException e) {
|
|
|
|
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.noSuchPerm, p), Formatting.DARK_RED), false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
String setPerm = mode == 1 ? "true" : mode == 0 ? "false" : "default";
|
|
|
|
if (PlayerClaimData.get(player).editDefaultPerms(group, perm, mode))
|
|
|
|
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.editPersonalGroup, group, perm, setPerm), Formatting.GOLD), false);
|
|
|
|
return Command.SINGLE_SUCCESS;
|
|
|
|
}
|
2020-08-23 08:52:36 -04:00
|
|
|
}
|