2020-08-23 08:52:36 -04:00
|
|
|
package com.flemmli97.flan.commands;
|
|
|
|
|
|
|
|
import com.flemmli97.flan.claim.Claim;
|
|
|
|
import com.flemmli97.flan.claim.ClaimStorage;
|
|
|
|
import com.flemmli97.flan.claim.EnumPermission;
|
2020-08-24 15:03:06 -04:00
|
|
|
import com.flemmli97.flan.claim.PermHelper;
|
2020-08-23 08:52:36 -04:00
|
|
|
import com.flemmli97.flan.config.ConfigHandler;
|
|
|
|
import com.flemmli97.flan.gui.ClaimMenuScreenHandler;
|
2020-08-23 17:18:18 -04:00
|
|
|
import com.flemmli97.flan.player.EnumDisplayType;
|
2020-08-23 08:52:36 -04:00
|
|
|
import com.flemmli97.flan.player.EnumEditMode;
|
|
|
|
import com.flemmli97.flan.player.PlayerClaimData;
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
import com.mojang.authlib.GameProfile;
|
|
|
|
import com.mojang.brigadier.Command;
|
|
|
|
import com.mojang.brigadier.CommandDispatcher;
|
|
|
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
|
|
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
|
|
|
import com.mojang.brigadier.builder.ArgumentBuilder;
|
|
|
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
2020-08-23 17:18:18 -04:00
|
|
|
import com.mojang.brigadier.context.CommandContext;
|
|
|
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
|
|
|
import com.mojang.brigadier.suggestion.Suggestions;
|
|
|
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
2020-08-23 08:52:36 -04:00
|
|
|
import net.minecraft.command.argument.GameProfileArgumentType;
|
|
|
|
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;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2020-08-23 17:18:18 -04:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
2020-08-23 08:52:36 -04:00
|
|
|
|
|
|
|
public class CommandClaim {
|
|
|
|
|
|
|
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated) {
|
2020-08-23 17:18:18 -04:00
|
|
|
dispatcher.register(addToMainCommand(CommandManager.literal("flan"),
|
|
|
|
CommandManager.literal("reload").executes(CommandClaim::reloadConfig),
|
|
|
|
CommandManager.literal("menu").executes(CommandClaim::openMenu),
|
|
|
|
CommandManager.literal("claimInfo").executes(CommandClaim::claimInfo),
|
|
|
|
CommandManager.literal("delete").executes(CommandClaim::deleteClaim),
|
|
|
|
CommandManager.literal("deleteAll").executes(CommandClaim::deleteAllClaim),
|
2020-08-24 15:03:06 -04:00
|
|
|
CommandManager.literal("deleteSubClaim").executes(CommandClaim::deleteSubClaim),
|
|
|
|
CommandManager.literal("deleteAllSubClaims").executes(CommandClaim::deleteAllSubClaim),
|
2020-08-23 17:18:18 -04:00
|
|
|
CommandManager.literal("list").executes(CommandClaim::listClaims),
|
|
|
|
CommandManager.literal("switchMode").executes(CommandClaim::switchClaimMode),
|
|
|
|
CommandManager.literal("adminMode").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::switchAdminMode),
|
2020-08-24 15:03:06 -04:00
|
|
|
CommandManager.literal("readGriefPrevention").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::readGriefPreventionData),
|
|
|
|
CommandManager.literal("setAdminClaim").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::setAdminClaim),
|
2020-08-23 17:18:18 -04:00
|
|
|
CommandManager.literal("adminDelete").requires(src -> src.hasPermissionLevel(2)).executes(CommandClaim::adminDelete)
|
|
|
|
.then(CommandManager.literal("all").then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()))
|
|
|
|
.executes(CommandClaim::adminDeleteAll)),
|
|
|
|
CommandManager.literal("giveClaimBlocks").requires(src -> src.hasPermissionLevel(2)).then(CommandManager.argument("players", GameProfileArgumentType.gameProfile())
|
|
|
|
.then(CommandManager.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::giveClaimBlocks))),
|
2020-08-23 08:52:36 -04:00
|
|
|
addToMainCommand(CommandManager.literal("group"),
|
2020-08-23 17:18:18 -04:00
|
|
|
CommandManager.literal("add").then(CommandManager.argument("group", StringArgumentType.word()).executes(CommandClaim::addGroup)),
|
|
|
|
CommandManager.literal("remove").then(CommandManager.argument("group", StringArgumentType.word())
|
|
|
|
.suggests(CommandClaim::groupSuggestion).executes(CommandClaim::removeGroup)),
|
|
|
|
addToMainCommand(CommandManager.literal("players"),
|
|
|
|
CommandManager.literal("add").then(CommandManager.argument("group", StringArgumentType.word()).suggests(CommandClaim::groupSuggestion)
|
|
|
|
.then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()).executes(CommandClaim::addPlayer)
|
2020-08-25 13:43:52 -04:00
|
|
|
.then(CommandManager.literal("overwrite").executes(CommandClaim::forceAddPlayer)))),
|
2020-08-23 17:18:18 -04:00
|
|
|
CommandManager.literal("remove").then(CommandManager.argument("group", StringArgumentType.word()).suggests(CommandClaim::groupSuggestion)
|
|
|
|
.then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()).suggests((context, build) -> {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
List<String> list = Lists.newArrayList();
|
|
|
|
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());
|
|
|
|
if (claim != null && claim.canInteract(src.getPlayer(), EnumPermission.EDITCLAIM, src.getPlayer().getBlockPos())) {
|
|
|
|
list = claim.playersFromGroup(player.getServer(), "");
|
|
|
|
}
|
2020-08-23 17:18:18 -04:00
|
|
|
return CommandSource.suggestMatching(list, build);
|
|
|
|
}).executes(CommandClaim::removePlayer))))
|
2020-08-23 08:52:36 -04:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static LiteralArgumentBuilder<ServerCommandSource> addToMainCommand(LiteralArgumentBuilder<ServerCommandSource> main, ArgumentBuilder... other) {
|
|
|
|
if (other != null)
|
|
|
|
for (ArgumentBuilder o : other)
|
|
|
|
main.then(o);
|
|
|
|
return main;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-08-24 15:03:06 -04:00
|
|
|
Claim claim = PermHelper.checkReturn(player, EnumPermission.EDITPERMS, PermHelper.genericNoPermMessage(player));
|
|
|
|
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-08-25 13:43:52 -04:00
|
|
|
if (sub != null && (claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos()) || sub.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())))
|
2020-08-24 15:03:06 -04:00
|
|
|
ClaimMenuScreenHandler.openClaimMenu(player, sub);
|
2020-08-25 13:43:52 -04:00
|
|
|
else if (claim.canInteract(player, EnumPermission.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-08-23 17:18:18 -04:00
|
|
|
if (claim == null)
|
|
|
|
return 0;
|
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);
|
|
|
|
player.sendMessage(PermHelper.simpleColoredText("==SubclaimInfo==", Formatting.AQUA), false);
|
|
|
|
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-08-25 13:43:52 -04:00
|
|
|
boolean check = PermHelper.check(player, player.getBlockPos(), claim, EnumPermission.EDITCLAIM, b -> {
|
|
|
|
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-08-25 13:43:52 -04:00
|
|
|
boolean check = PermHelper.check(player, player.getBlockPos(), sub, EnumPermission.EDITCLAIM, b -> {
|
|
|
|
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();
|
|
|
|
Claim claim = PermHelper.checkReturn(player, EnumPermission.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-08-23 17:18:18 -04:00
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
Map<World, Collection<Claim>> claims = Maps.newHashMap();
|
|
|
|
for (ServerWorld world : player.getServer().getWorlds()) {
|
|
|
|
ClaimStorage storage = ClaimStorage.get(world);
|
|
|
|
claims.put(world, storage.allClaimsFromPlayer(player.getUuid()));
|
|
|
|
}
|
|
|
|
PlayerClaimData data = PlayerClaimData.get(player);
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.claimBlocksFormat,
|
2020-08-23 17:18:18 -04:00
|
|
|
data.getClaimBlocks(), data.getAdditionalClaims(), data.usedClaimBlocks()), Formatting.GOLD), false);
|
2020-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(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-08-24 15:03:06 -04:00
|
|
|
player.sendMessage(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-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;
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<String> players = Lists.newArrayList();
|
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-08-25 13:43:52 -04:00
|
|
|
private static int setAdminClaim(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;
|
|
|
|
}
|
|
|
|
claim.setAdminClaim();
|
2020-08-24 15:03:06 -04:00
|
|
|
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.setAdminClaim, Formatting.GOLD), true);
|
|
|
|
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-08-25 13:43:52 -04:00
|
|
|
List<String> errors = ClaimStorage.readGriefPreventionData(src.getMinecraftServer());
|
2020-08-24 15:03:06 -04:00
|
|
|
PlayerClaimData.readGriefPreventionPlayerData(src.getMinecraftServer());
|
2020-08-25 13:43:52 -04:00
|
|
|
if (errors == null)
|
|
|
|
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.readGriefpreventionDataSuccess, Formatting.GOLD), true);
|
|
|
|
else
|
|
|
|
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.readGriefpreventionDataFail, errors), Formatting.RED), 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();
|
|
|
|
List<String> players = Lists.newArrayList();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static CompletableFuture<Suggestions> groupSuggestion(CommandContext<ServerCommandSource> context, SuggestionsBuilder build) throws CommandSyntaxException {
|
|
|
|
ServerPlayerEntity player = context.getSource().getPlayer();
|
|
|
|
List<String> list = Lists.newArrayList();
|
|
|
|
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
|
|
|
|
Claim claim = storage.getClaimAt(player.getBlockPos());
|
|
|
|
if (claim != null && claim.canInteract(player, EnumPermission.EDITCLAIM, player.getBlockPos())) {
|
|
|
|
list = claim.groups();
|
|
|
|
}
|
|
|
|
return CommandSource.suggestMatching(list, build);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-08-25 13:43:52 -04:00
|
|
|
} else if (claim.editPerms(player, group, EnumPermission.EDITCLAIM, -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-08-25 13:43:52 -04:00
|
|
|
if (!claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())) {
|
2020-08-24 15:03:06 -04:00
|
|
|
PermHelper.genericNoPermMessage(player);
|
2020-08-23 17:18:18 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
List<String> modified = Lists.newArrayList();
|
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-08-23 08:52:36 -04:00
|
|
|
}
|