flan/src/main/java/com/flemmli97/flan/commands/CommandClaim.java

459 lines
27 KiB
Java
Raw Normal View History

2020-08-23 12:52:36 +00: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 19:03:06 +00:00
import com.flemmli97.flan.claim.PermHelper;
2020-08-23 12:52:36 +00:00
import com.flemmli97.flan.config.ConfigHandler;
import com.flemmli97.flan.gui.ClaimMenuScreenHandler;
import com.flemmli97.flan.player.EnumDisplayType;
2020-08-23 12:52:36 +00:00
import com.flemmli97.flan.player.EnumEditMode;
import com.flemmli97.flan.player.OfflinePlayerData;
2020-08-23 12:52:36 +00:00
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.BoolArgumentType;
2020-08-23 12:52:36 +00:00
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
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-09-02 22:00:44 +00:00
import net.minecraft.command.argument.BlockPosArgumentType;
2020-08-23 12:52:36 +00:00
import net.minecraft.command.argument.GameProfileArgumentType;
import net.minecraft.server.MinecraftServer;
2020-08-23 12:52:36 +00: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;
import net.minecraft.util.Formatting;
2020-08-23 12:52:36 +00:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
2020-08-23 12:52:36 +00:00
public class CommandClaim {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, boolean dedicated) {
dispatcher.register(addToMainCommand(CommandManager.literal("flan"),
CommandManager.literal("reload").executes(CommandClaim::reloadConfig),
2020-09-02 22:00:44 +00:00
CommandManager.literal("addClaim").then(CommandManager.argument("from", BlockPosArgumentType.blockPos()).then(CommandManager.argument("to", BlockPosArgumentType.blockPos()).executes(CommandClaim::addClaim))),
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 19:03:06 +00:00
CommandManager.literal("deleteSubClaim").executes(CommandClaim::deleteSubClaim),
CommandManager.literal("deleteAllSubClaims").executes(CommandClaim::deleteAllSubClaim),
2020-09-02 13:36:58 +00:00
CommandManager.literal("list").executes(CommandClaim::listClaims).then(CommandManager.argument("player", GameProfileArgumentType.gameProfile()).requires(src -> src.hasPermissionLevel(ConfigHandler.config.permissionLevel)).executes(cmd -> listClaims(cmd, GameProfileArgumentType.getProfileArgument(cmd, "player")))),
CommandManager.literal("switchMode").executes(CommandClaim::switchClaimMode),
2020-09-02 13:36:05 +00:00
CommandManager.literal("adminMode").requires(src -> src.hasPermissionLevel(ConfigHandler.config.permissionLevel)).executes(CommandClaim::switchAdminMode),
CommandManager.literal("readGriefPrevention").requires(src -> src.hasPermissionLevel(ConfigHandler.config.permissionLevel)).executes(CommandClaim::readGriefPreventionData),
CommandManager.literal("setAdminClaim").requires(src -> src.hasPermissionLevel(ConfigHandler.config.permissionLevel)).then(CommandManager.argument("toggle", BoolArgumentType.bool()).executes(CommandClaim::toggleAdminClaim)),
CommandManager.literal("listAdminClaims").requires(src -> src.hasPermissionLevel(ConfigHandler.config.permissionLevel)).executes(CommandClaim::listAdminClaims),
CommandManager.literal("adminDelete").requires(src -> src.hasPermissionLevel(ConfigHandler.config.permissionLevel)).executes(CommandClaim::adminDelete)
2020-08-25 19:32:00 +00:00
.then(CommandManager.literal("all").then(CommandManager.argument("players", GameProfileArgumentType.gameProfile())
.executes(CommandClaim::adminDeleteAll))),
2020-09-02 13:36:05 +00:00
CommandManager.literal("giveClaimBlocks").requires(src -> src.hasPermissionLevel(ConfigHandler.config.permissionLevel)).then(CommandManager.argument("players", GameProfileArgumentType.gameProfile())
.then(CommandManager.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::giveClaimBlocks))),
2020-08-23 12:52:36 +00:00
addToMainCommand(CommandManager.literal("group"),
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 17:43:52 +00:00
.then(CommandManager.literal("overwrite").executes(CommandClaim::forceAddPlayer)))),
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 17:43:52 +00: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(), "");
}
return CommandSource.suggestMatching(list, build);
}).executes(CommandClaim::removePlayer))))
2020-08-23 12:52:36 +00:00
)));
}
2020-09-02 13:36:58 +00:00
private static <S, T extends ArgumentBuilder<S, T>> T addToMainCommand(T main, ArgumentBuilder<S, T>... other) {
2020-08-23 12:52:36 +00:00
if (other != null)
2020-09-02 13:36:58 +00:00
for (ArgumentBuilder<S, T> o : other)
2020-08-23 12:52:36 +00:00
main.then(o);
return main;
}
2020-08-25 17:43:52 +00:00
private static int reloadConfig(CommandContext<ServerCommandSource> context) {
ConfigHandler.reloadConfigs();
2020-08-25 18:35:38 +00:00
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.configReload), true);
return Command.SINGLE_SUCCESS;
}
2020-09-02 22:00:44 +00: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;
}
private static int openMenu(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerPlayerEntity player = context.getSource().getPlayer();
PlayerClaimData data = PlayerClaimData.get(player);
2020-08-25 17:43:52 +00:00
if (data.getEditMode() == EnumEditMode.DEFAULT) {
2020-08-24 19:03:06 +00:00
Claim claim = PermHelper.checkReturn(player, EnumPermission.EDITPERMS, PermHelper.genericNoPermMessage(player));
if (claim == null)
return 0;
ClaimMenuScreenHandler.openClaimMenu(player, claim);
2020-08-24 20:19:09 +00:00
data.addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
2020-08-25 17:43:52 +00:00
} else {
2020-08-24 19:03:06 +00:00
Claim claim = ClaimStorage.get(player.getServerWorld()).getClaimAt(player.getBlockPos());
Claim sub = claim.getSubClaim(player.getBlockPos());
2020-08-25 17:43:52 +00:00
if (sub != null && (claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos()) || sub.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())))
2020-08-24 19:03:06 +00:00
ClaimMenuScreenHandler.openClaimMenu(player, sub);
2020-08-25 17:43:52 +00:00
else if (claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos()))
2020-08-24 19:03:06 +00:00
ClaimMenuScreenHandler.openClaimMenu(player, claim);
else
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermission, Formatting.DARK_RED), false);
}
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 19:03:06 +00:00
PlayerClaimData data = PlayerClaimData.get(player);
if (claim == null)
return 0;
2020-08-25 17:43:52 +00:00
if (data.getEditMode() == EnumEditMode.SUBCLAIM) {
2020-08-24 19:03:06 +00:00
Claim sub = claim.getSubClaim(player.getBlockPos());
2020-08-25 17:43:52 +00:00
if (sub != null) {
2020-08-24 19:03:06 +00: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;
}
}
List<Text> info = claim.infoString(player);
2020-08-24 19:03:06 +00:00
for (Text text : info)
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 17:43:52 +00:00
boolean check = PermHelper.check(player, player.getBlockPos(), claim, EnumPermission.EDITCLAIM, b -> {
if (!b.isPresent())
2020-08-24 19:03:06 +00:00
PermHelper.noClaimMessage(player);
2020-08-25 17:43:52 +00:00
else if (!b.get())
2020-08-24 19:03:06 +00:00
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaimError, Formatting.DARK_RED), false);
else
2020-08-25 18:35:38 +00:00
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaim, Formatting.RED), false);
});
if (!check)
return 0;
2020-08-24 19:03:06 +00:00
storage.deleteClaim(claim, true, PlayerClaimData.get(player).getEditMode(), player.getServerWorld());
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 17:43:52 +00:00
storage.allClaimsFromPlayer(player.getUuid()).forEach((claim) -> storage.deleteClaim(claim, true, PlayerClaimData.get(player).getEditMode(), player.getServerWorld()));
}
2020-08-24 19:03:06 +00:00
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaim, Formatting.GOLD), false);
data.setConfirmDeleteAll(false);
} else {
data.setConfirmDeleteAll(true);
2020-08-24 19:03:06 +00: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 17:43:52 +00:00
if (claim == null) {
2020-08-24 19:03:06 +00:00
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
return 0;
}
Claim sub = claim.getSubClaim(player.getBlockPos());
2020-08-25 17:43:52 +00:00
if (sub == null) {
2020-08-24 19:03:06 +00:00
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
return 0;
}
2020-08-25 17:43:52 +00:00
boolean check = PermHelper.check(player, player.getBlockPos(), sub, EnumPermission.EDITCLAIM, b -> {
if (!b.isPresent())
2020-08-24 19:03:06 +00:00
PermHelper.noClaimMessage(player);
2020-08-25 17:43:52 +00:00
else if (!b.get())
2020-08-24 19:03:06 +00: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 17:43:52 +00:00
if (claim == null)
2020-08-24 19:03:06 +00:00
return 0;
List<Claim> subs = claim.getAllSubclaims();
subs.forEach(claim::deleteSubClaim);
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteSubClaimAll, Formatting.DARK_RED), false);
return Command.SINGLE_SUCCESS;
}
2020-08-25 17:43:52 +00:00
private static int listClaims(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
return listClaimsFromUUID(context, null);
}
private static int listClaims(CommandContext<ServerCommandSource> context, Collection<GameProfile> profs) throws CommandSyntaxException {
2020-09-02 13:36:58 +00:00
if (profs.size() != 1) {
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.onlyOnePlayer, Formatting.RED), false);
return 0;
}
GameProfile prof = profs.iterator().next();
2020-09-02 13:36:58 +00:00
if (prof == null || prof.getId() == null)
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 13:36:58 +00:00
ServerPlayerEntity player = of == null ? context.getSource().getPlayer() : server.getPlayerManager().getPlayer(of);
Map<World, Collection<Claim>> claims = Maps.newHashMap();
for (ServerWorld world : server.getWorlds()) {
ClaimStorage storage = ClaimStorage.get(world);
2020-09-02 13:36:58 +00:00
claims.put(world, storage.allClaimsFromPlayer(player != null ? player.getUuid() : of));
}
2020-09-02 13:36:58 +00: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);
2020-09-02 13:36:58 +00:00
} 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);
}
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.listClaims, Formatting.GOLD), false);
for (Map.Entry<World, Collection<Claim>> entry : claims.entrySet())
for (Claim claim : entry.getValue())
context.getSource().sendFeedback(PermHelper.simpleColoredText(
entry.getKey().getRegistryKey().getValue().toString() + " # " + claim.formattedClaim(), Formatting.YELLOW), false);
return Command.SINGLE_SUCCESS;
}
2020-08-25 17:43:52 +00:00
private static int switchClaimMode(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerPlayerEntity player = context.getSource().getPlayer();
PlayerClaimData data = PlayerClaimData.get(player);
data.setEditMode(data.getEditMode() == EnumEditMode.DEFAULT ? EnumEditMode.SUBCLAIM : EnumEditMode.DEFAULT);
2020-08-24 19:03:06 +00:00
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.editMode, data.getEditMode()), Formatting.GOLD), false);
return Command.SINGLE_SUCCESS;
}
2020-08-25 17:43:52 +00:00
private static int switchAdminMode(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerPlayerEntity player = context.getSource().getPlayer();
PlayerClaimData data = PlayerClaimData.get(player);
data.setAdminIgnoreClaim(!data.isAdminIgnoreClaim());
2020-08-24 19:03:06 +00:00
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.adminMode, data.isAdminIgnoreClaim()), Formatting.GOLD), false);
return Command.SINGLE_SUCCESS;
}
2020-08-25 17:43:52 +00:00
private static int adminDelete(CommandContext<ServerCommandSource> context) {
ServerCommandSource src = context.getSource();
ClaimStorage storage = ClaimStorage.get(src.getWorld());
Claim claim = storage.getClaimAt(new BlockPos(src.getPosition()));
if (claim == null) {
2020-08-24 19:03:06 +00:00
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
return 0;
}
2020-08-24 19:03:06 +00:00
storage.deleteClaim(claim, true, EnumEditMode.DEFAULT, src.getWorld());
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.deleteClaim, Formatting.RED), true);
return Command.SINGLE_SUCCESS;
}
private static int adminDeleteAll(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerCommandSource src = context.getSource();
2020-08-25 17:43:52 +00:00
if (src.getEntity() instanceof ServerPlayerEntity) {
ServerPlayerEntity player = (ServerPlayerEntity) src.getEntity();
PlayerClaimData data = PlayerClaimData.get(player);
2020-08-25 17:43:52 +00:00
if (!data.confirmedDeleteAll()) {
data.setConfirmDeleteAll(true);
2020-08-24 19:03:06 +00:00
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.deleteAllClaimConfirm, Formatting.DARK_RED), false);
return Command.SINGLE_SUCCESS;
}
}
List<String> players = Lists.newArrayList();
2020-08-25 17:43:52 +00:00
for (GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) {
for (ServerWorld world : src.getWorld().getServer().getWorlds()) {
ClaimStorage storage = ClaimStorage.get(world);
2020-08-25 17:43:52 +00:00
storage.allClaimsFromPlayer(prof.getId()).forEach((claim) -> storage.deleteClaim(claim, true, EnumEditMode.DEFAULT, world));
}
players.add(prof.getName());
}
2020-08-24 19:03:06 +00:00
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.adminDeleteAll, players.toString()), Formatting.GOLD), true);
return Command.SINGLE_SUCCESS;
}
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());
if (claim == null) {
context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.noClaim, Formatting.RED), false);
return 0;
}
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 19:03:06 +00:00
return Command.SINGLE_SUCCESS;
}
2020-08-25 19:06:36 +00:00
private static int listAdminClaims(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
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 17:43:52 +00:00
private static int readGriefPreventionData(CommandContext<ServerCommandSource> context) {
2020-08-24 19:03:06 +00:00
ServerCommandSource src = context.getSource();
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.readGriefpreventionData, Formatting.GOLD), true);
ClaimStorage.readGriefPreventionData(src.getMinecraftServer(), src);
PlayerClaimData.readGriefPreventionPlayerData(src.getMinecraftServer(), src);
src.sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.readGriefpreventionDataSuccess, Formatting.GOLD), true);
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 17:43:52 +00:00
for (GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) {
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 19:03:06 +00:00
src.sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.giveClaimBlocks, players.toString(), amount), Formatting.GOLD), true);
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 19:03:06 +00:00
PermHelper.noClaimMessage(player);
return 0;
}
2020-08-25 17:43:52 +00:00
if (remove) {
if (claim.removePermGroup(player, group))
2020-08-24 19:03:06 +00:00
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.groupRemove, group), Formatting.GOLD), false);
else {
2020-08-24 19:03:06 +00:00
PermHelper.genericNoPermMessage(player);
return 0;
}
2020-08-25 17:43:52 +00:00
} else {
if (claim.groups().contains(group)) {
2020-08-24 19:03:06 +00:00
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.groupExist, group), Formatting.RED), false);
return 0;
2020-08-25 17:43:52 +00:00
} else if (claim.editPerms(player, group, EnumPermission.EDITCLAIM, -1))
2020-08-24 19:03:06 +00:00
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.groupAdd, group), Formatting.GOLD), false);
else {
2020-08-24 19:03:06 +00:00
PermHelper.genericNoPermMessage(player);
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 19:03:06 +00:00
PermHelper.noClaimMessage(player);
return 0;
}
2020-08-25 17:43:52 +00:00
if (!claim.canInteract(player, EnumPermission.EDITPERMS, player.getBlockPos())) {
2020-08-24 19:03:06 +00:00
PermHelper.genericNoPermMessage(player);
return 0;
}
List<String> modified = Lists.newArrayList();
2020-08-25 17:43:52 +00:00
for (GameProfile prof : GameProfileArgumentType.getProfileArgument(context, "players")) {
if (claim.setPlayerGroup(prof.getId(), group, force))
modified.add(prof.getName());
}
2020-08-25 17:43:52 +00:00
if (!modified.isEmpty())
2020-08-24 19:03:06 +00:00
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.playerModify, group, modified), Formatting.GOLD), false);
else
2020-08-24 19:03:06 +00:00
player.sendMessage(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.playerModifyNo, group, modified), Formatting.RED), false);
return Command.SINGLE_SUCCESS;
}
2020-08-23 12:52:36 +00:00
}