From 8d6442d24aff106185a879ea0931e4ff18bc617f Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Wed, 11 Mar 2020 14:40:04 +0330 Subject: [PATCH 01/85] Updated --- build.gradle | 9 +- .../indicode/fabric/itsmine/ChatColor.java | 347 +++++++ .../github/indicode/fabric/itsmine/Claim.java | 79 +- .../indicode/fabric/itsmine/ClaimCommand.java | 944 ++++++++++++++---- .../indicode/fabric/itsmine/Config.java | 28 +- .../indicode/fabric/itsmine/Messages.java | 111 ++ .../fabric/itsmine/mixin/EntityMixin.java | 31 +- .../itsmine/mixin/PlaceOnUseBlockMixin.java | 2 +- .../itsmine/mixin/PlayerEntityMixin.java | 9 +- .../itsmine/mixin/ProjectileEntityMixin.java | 5 +- .../mixin/ServerPlayNetworkHandlerMixin.java | 5 +- .../ServerPlayerInteractionManagerMixin.java | 31 +- 12 files changed, 1364 insertions(+), 237 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/ChatColor.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/Messages.java diff --git a/build.gradle b/build.gradle index 1241071..f42613c 100644 --- a/build.gradle +++ b/build.gradle @@ -23,12 +23,13 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modCompile "net.fabricmc:fabric-loader:${project.loader_version}" - modImplementation "com.github.giantnuker:TinyConfig:${project.tiny_config_version}" + //modImplementation "com.github.giantnuker:TinyConfig:${project.tiny_config_version}" modImplementation /*"io.github.indicode.fabric:thimble-permissions:0.0.9"//*/"com.github.giantnuker:Thimble-Permissions:${project.thimble_permissions_version}" - modImplementation "com.github.giantnuker:OfflineInfo:${project.offline_info_version}" + //modImplementation "com.github.giantnuker:OfflineInfo:${project.offline_info_version}" - include "com.github.giantnuker:TinyConfig:${project.tiny_config_version}" - //include "com.github.indi-code:Thimble-Permissions:${project.thimble_permissions_version}" + //include "com.github.giantnuker:TinyConfig:${project.tiny_config_version}" + implementation 'org.jetbrains:annotations:15.0' + include "com.github.indi-code:Thimble-Permissions:${project.thimble_permissions_version}" // Fabric API. This is technically optional, but you probably want it anyway. //modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ChatColor.java b/src/main/java/io/github/indicode/fabric/itsmine/ChatColor.java new file mode 100644 index 0000000..f892149 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/ChatColor.java @@ -0,0 +1,347 @@ +package io.github.indicode.fabric.itsmine; + +import com.google.common.collect.Maps; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import org.apache.commons.lang3.Validate; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; +import java.util.regex.Pattern; + +public enum ChatColor { + /** + * Represents black + */ + BLACK('0', 0x00, Formatting.BLACK, "\\u001b[30m"), + /** + * Represents dark blue + */ + DARK_BLUE('1', 0x1, Formatting.DARK_BLUE, "\\u001b[34m"), + /** + * Represents dark green + */ + DARK_GREEN('2', 0x2, Formatting.DARK_GREEN, "\\u001b[32m"), + /** + * Represents dark blue (aqua) + */ + DARK_AQUA('3', 0x3, Formatting.DARK_AQUA, "\\u001b[36m"), + /** + * Represents dark red + */ + DARK_RED('4', 0x4, Formatting.DARK_RED, "\\u001b[31m"), + /** + * Represents dark purple + */ + DARK_PURPLE('5', 0x5, Formatting.DARK_PURPLE, "\\u001b[35m"), + /** + * Represents gold + */ + GOLD('6', 0x6, Formatting.GOLD, "\\u001b[33m"), + /** + * Represents gray + */ + GRAY('7', 0x7, Formatting.GRAY), + /** + * Represents dark gray + */ + DARK_GRAY('8', 0x8, Formatting.DARK_GRAY), + /** + * Represents blue + */ + BLUE('9', 0x9, Formatting.BLUE, "\\u001b[34;1m"), + /** + * Represents green + */ + GREEN('a', 0xA, Formatting.GREEN, "\\u001b[32;1m"), + /** + * Represents aqua + */ + AQUA('b', 0xB, Formatting.AQUA, "\\u001b[36;1m"), + /** + * Represents red + */ + RED('c', 0xC, Formatting.RED, "\\u001b[31;1m"), + /** + * Represents light purple + */ + LIGHT_PURPLE('d', 0xD, Formatting.LIGHT_PURPLE, "\\u001b[35;1m"), + /** + * Represents yellow + */ + YELLOW('e', 0xE, Formatting.YELLOW, "\\u001b[33;1m"), + /** + * Represents white + */ + WHITE('f', 0xF, Formatting.WHITE, "\\u001b[37;1m"), + /** + * Represents magical characters that change around randomly + */ + OBFUSCATED('k', 0x10, Formatting.OBFUSCATED, true), + /** + * Makes the text bold. + */ + BOLD('l', 0x11, Formatting.BOLD ,true, "\\u001b[1m"), + /** + * Makes a line appear through the text. + */ + STRIKETHROUGH('m', 0x12, Formatting.STRIKETHROUGH, true), + /** + * Makes the text appear underlined. + */ + UNDERLINE('n', 0x13, Formatting.UNDERLINE,true, "\\u001b[4m"), + /** + * Makes the text italic. + */ + ITALIC('o', 0x14, Formatting.ITALIC,true), + /** + * Resets all previous events colors or formats. + */ + RESET('r', 0x15, Formatting.RESET), + /** + * Reverses the Text and background color + * @apiNote Console Only + */ + REVERSED('s', 0, null, "\\u001b[7m"); + + private static String[] list() { + return new String[] {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", + "a", "b", "c", "d", "e", "f", "i", "k", "l", "m", "o", "r"}; + } + + public static final char COLOR_CHAR = '\u00A7'; + private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + COLOR_CHAR + "[0-9A-FK-OR]"); + + private final int intCode; + private final char code; + private final boolean isFormat; + private final Formatting formatting; + private final String toString; + private final String ansi; + private static final Map BY_ID = Maps.newHashMap(); + private static final Map BY_CHAR = Maps.newHashMap(); + + ChatColor(char code, int intCode, Formatting formatting, boolean isFormat, String ansi) { + this.code = code; + this.intCode = intCode; + this.isFormat = isFormat; + this.formatting = formatting; + this.toString = new String(new char[] {COLOR_CHAR, code}); + this.ansi = ansi; + } + + ChatColor(char code, int intCode, Formatting formatting, String ansi) { + this(code, intCode, formatting, false, ansi); + } + + ChatColor(char code, int intCode, Formatting formatting) { + this(code, intCode, formatting, false); + } + + ChatColor(char code, int intCode, Formatting formatting, boolean isFormat) { + this(code, intCode, formatting, isFormat, null); + } + + + /** + * Gets the char value associated with this color + * + * @return A char value of this color code + */ + public char getChar() { + return code; + } + + public static String[] getList() { + return ChatColor.list(); + } + + public Formatting getFormattingByChar(char code) { + return formatting; + } + + @NotNull + @Override + public String toString() { + return toString; + } + + /** + * Checks if this code is a format code as opposed to a color code. + * + * @return whether this ChatColor is a format code + */ + public boolean isFormat() { + return isFormat; + } + + /** + * Checks if this code is a color code as opposed to a format code. + * + * @return whether this ChatColor is a color code + */ + public boolean isColor() { + return !isFormat && this != RESET; + } + + /** + * Gets the ANSI code for a TextFormat + * + * @return ANSI Formatting code + */ + public String getAnsiCode() { + return ansi; + } + + /** + * Strips the given message of all color codes + * + * @param input String to strip of color + * @return A copy of the input string, without any coloring + */ + @Contract("!null -> !null; null -> null") + @Nullable + public static String stripColor(@Nullable final String input) { + if (input == null) { + return null; + } + + return STRIP_COLOR_PATTERN.matcher(input).replaceAll(""); + } + + public static Text translateToNMSText(String jsonString) { + return Text.Serializer.fromJson(jsonString); + } + + /** + * Translates a string using an alternate color code character into a + * string that uses the internal ChatColor.COLOR_CODE color code + * character. The alternate color code character will only be replaced if + * it is immediately followed by 0-9, A-F, a-f, K-O, k-o, R or r. + * + * @param altColorChar The alternate color code character to replace. Ex: {@literal &} + * @param textToTranslate Text containing the alternate color code character. + * @return Text containing the ChatColor.COLOR_CODE color code character. + */ + + @NotNull + public static String translateAlternateColorCodes(char altColorChar, @NotNull String textToTranslate) { + Validate.notNull(textToTranslate, "Cannot translate null text"); + char[] b = textToTranslate.toCharArray(); + + for (int i = 0; i < b.length - 1; i++) { + if (b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i+1]) > -1) { + b[i] = ChatColor.COLOR_CHAR; + b[i+1] = Character.toLowerCase(b[i+1]); + } + } + return new String(b); + } + + public static String reverseTranslate(String textToTranslate, char altColorChar) { + Validate.notNull(textToTranslate, "Cannot translate null text"); + char[] b = textToTranslate.toCharArray(); + + for (int i = 0; i < b.length - 1; i++) { + if (b[i] == COLOR_CHAR && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i+1]) > -1) { + b[i] = altColorChar; + b[i+1] = Character.toLowerCase(b[i+1]); + } + } + return new String(b); + } + + @NotNull + public static String translate(String string) { + return translateAlternateColorCodes('&', string); + } + + @NotNull + public static String translate(String string, boolean allowFormats) { + return allowFormats ? translate(string) : ChatColor.removeAlternateColorCodes('&', string); + } + + public static LiteralText translateToLiteralText(char altColorChar, @NotNull String textToTranslate) { + return new LiteralText(translateAlternateColorCodes(altColorChar, textToTranslate)); + } + + public static String removeAlternateColorCodes(char altColorChar, @NotNull String textToTranslate) { + Validate.notNull(textToTranslate, "Cannot translate null text"); + for (char c : "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".toCharArray()) { + textToTranslate = textToTranslate.replace(String.valueOf(ChatColor.COLOR_CHAR) + c, ""); + textToTranslate = textToTranslate.replace(String.valueOf(altColorChar) + c, ""); + } + return textToTranslate; + } + + public static LiteralText removeAlternateToLiteralText(char altColorChar, @NotNull String textToTranslate) { + return new LiteralText(removeAlternateColorCodes(altColorChar, textToTranslate)); + } + + @Nullable + public static ChatColor getByChar(char code) { + return BY_CHAR.get(code); + } + + /** + * Gets the ChatColors used at the end of the given input string. + * + * @param input Input string to retrieve the colors from. + * @return Any remaining ChatColors to pass onto the next line. + */ + @NotNull + public static String getLastColors(@NotNull String input) { + Validate.notNull(input, "Cannot get last colors from null text"); + + String result = ""; + int length = input.length(); + + // Search backwards from the end as it is faster + for (int index = length - 1; index > -1; index--) { + char section = input.charAt(index); + if (section == COLOR_CHAR && index < length - 1) { + char c = input.charAt(index + 1); + ChatColor color = getByChar(c); + + if (color != null) { + result = color.toString() + result; + + // Once we find a color or reset we can stop searching + if (color.isColor() || color.equals(RESET)) { + break; + } + } + } + } + + return result; + } + + public static String getFormattedPing(int i) { + if (i < 200) + return "&a" + i; + if (i > 200 && i < 400) + return "&e" + i; + + return "&c" + i; + } + + public static char getFormattedTPS(double tps) { + if (tps > 15) + return 'a'; + if (tps > 10) + return 'e'; + + return 'c'; + } + + static { + for (ChatColor color : values()) { + BY_ID.put(color.intCode, color); + BY_CHAR.put(color.code, color); + } + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index b1e376b..006c010 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -1,5 +1,6 @@ package io.github.indicode.fabric.itsmine; +import blue.endless.jankson.annotation.Nullable; import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; @@ -23,11 +24,13 @@ public class Claim { public String name; public BlockPos min, max; + public @Nullable BlockPos tpPos; public DimensionType dimension; public List children = new ArrayList<>(); public ClaimSettings settings = new ClaimSettings(); public PermissionManager permissionManager = new PermissionManager(); public UUID claimBlockOwner = null; + public String customOwnerName, enterMessage, leaveMessage; public Claim() { } @@ -35,11 +38,15 @@ public Claim(CompoundTag tag) { fromTag(tag); } public Claim(String name, UUID claimBlockOwner, BlockPos min, BlockPos max, DimensionType dimension) { + this(name, claimBlockOwner, min, max, dimension, null); + } + public Claim(String name, UUID claimBlockOwner, BlockPos min, BlockPos max, DimensionType dimension, @Nullable BlockPos tpPos) { this.claimBlockOwner = claimBlockOwner; this.min = min; this.max = max; this.name = name; this.dimension = dimension; + this.tpPos = tpPos; } public boolean includesPosition(BlockPos pos) { return pos.getX() >= min.getX() && pos.getY() >= min.getY() && pos.getZ() >= min.getZ() && @@ -151,6 +158,8 @@ public boolean shrink(Direction direction, int distance) { public int getArea() { return getSize().getX() * (Config.claims2d ? 1 : getSize().getY()) * getSize().getZ(); } + + public CompoundTag toTag() { CompoundTag tag = new CompoundTag(); { @@ -162,6 +171,11 @@ public CompoundTag toTag() { pos.putInt("maxY", max.getY()); pos.putInt("maxZ", max.getZ()); pos.putString("dimension", DimensionType.getId(dimension).toString()); + if (tpPos != null) { + pos.putInt("tpX", this.tpPos.getX()); + pos.putInt("tpY", this.tpPos.getY()); + pos.putInt("tpZ", this.tpPos.getZ()); + } tag.put("position", pos); } { @@ -174,6 +188,13 @@ public CompoundTag toTag() { tag.put("permissions", permissionManager.toNBT()); if (claimBlockOwner != null) tag.putUuid("top_owner", claimBlockOwner); } + { + CompoundTag meta = new CompoundTag(); + if (this.enterMessage != null) meta.putString("enterMsg", this.enterMessage); + if (this.leaveMessage != null) meta.putString("leaveMsg", this.leaveMessage); + tag.put("meta", meta); + } + if (this.customOwnerName != null) tag.putString("cOwnerName", this.customOwnerName); tag.putString("name", name); return tag; } @@ -189,6 +210,9 @@ public void fromTag(CompoundTag tag) { if (maxY == 0) maxY = 255; this.min = new BlockPos(minX, minY, minZ); this.max = new BlockPos(maxX, maxY, maxZ); + if (pos.contains("tpX") && pos.contains("tpY") && pos.contains("tpZ")) { + this.tpPos = new BlockPos(pos.getInt("tpX"), pos.getInt("tpY"), pos.getInt("tpZ")); + } this.dimension = DimensionType.byId(new Identifier(pos.getString("dimension"))); } { @@ -204,6 +228,12 @@ public void fromTag(CompoundTag tag) { permissionManager.fromNBT(tag.getCompound("permissions")); if (tag.containsUuid("top_owner")) claimBlockOwner = tag.getUuid("top_owner"); } + { + CompoundTag meta = tag.getCompound("meta"); + if (meta.contains("enterMsg")) this.enterMessage = meta.getString("enterMsg"); + if (meta.contains("leaveMsg")) this.leaveMessage = meta.getString("leaveMsg"); + } + if (tag.contains("cOwnerName")) this.customOwnerName = tag.getString("cOwnerName"); name = tag.getString("name"); } @@ -215,19 +245,21 @@ public enum Permission { //Admin DELETE_CLAIM("delete_claim", "Delete Claim"), MODIFY_SIZE("modify_size", "Modify Claim Size"), - CHANGE_FLAGS("modify_flags", "Change Claim Flags"), - CHANGE_PERMISSIONS("modify_permissions", "Change Permissions"), + MODIFY_FLAGS("modify_flags", "Change Claim Flags"), + MODIFY_PERMISSIONS("modify_permissions", "Change Permissions"), //Normal + MODIFY_PROPERTIES("modify_properties", "Modify Claim Properties"), SPAWN_PROTECT("spawn_protect", "Spawn Protection Bypass"), - PLACE_BREAK("place_break", "Place/Break Blocks"), - ACTIVATE_BLOCKS("block_interact", "Right click Blocks"), - USE_ITEMS_ON_BLOCKS("use_block_modifier_items", "Use Block Modifying items"), + BUILD("build", "Place/Break Blocks"), + INTERACT_BLOCKS("interact_blocks", "Interact With Blocks"), + USE_ITEMS_ON_BLOCKS("use_items_on_blocks", "Use Block Modifying items"), PRESS_BUTTONS("press_buttons", "Press Buttons"), USE_LEVERS("use_levers", "Use Levers"), - OPEN_DOORS("open_doors", "Use Doors"), - ENTITY_INTERACT("entity_interact", "Entity Interaction"), - ENTITY_DAMAGE("entity_damage", "Hurt Entities"), - FLY("fly", "Fly"); + INTERACT_DOORS("interact_doors", "Use Doors"), + INTERACT_ENTITY("interact_with_entities", "Entity Interaction"), + DAMAGE_ENTITY("damage_entities", "Hurt Entities"), + FLIGHT("flight", "Flight"), + TELEPORT("teleport", "Player Teleport Access"); String id, name; Permission(String id, String name) { this.id = id; @@ -434,13 +466,16 @@ public CompoundTag toNBT() { } public static class ClaimSettings{ public enum Setting { - FLIGHT_ALLOWED("fly_enabled", "Flying Enabled", true), + FLIGHT_ALLOWED("flight_allowed", "Flying Enabled", true), EXPLOSIONS("explosion_destruction", "Explosions Destroy Blocks", false), FLUID_CROSSES_BORDERS("fluid_crosses_borders", "Fluid Crosses Borders", false), FIRE_CROSSES_BORDERS("fire_crosses_borders", "Fire Crosses Borders", false), PISTON_FROM_INSIDE("pistons_inside_border", "Pistons Cross border from Inside", true), PISTON_FROM_OUTSIDE("pistons_outside_border", "Pistons Cross border from Outside", false), - MOB_SPAWNING("mob_spawn", "Natural mob spawning", true); + MOB_SPAWNING("mob_spawn", "Natural mob spawning", true), + KEEP_INVENTORY("keep_inventory", "Keep Inventory", true), + TELEPORT("teleport", "Global Teleport Access", true), + ENTER_SOUND("enter_sound", "Enter Sound", true); String id, name; boolean defaultValue; @@ -481,4 +516,26 @@ public void fromTag(CompoundTag tag) { }); } } + public enum Event { + ENTER_CLAIM("enter", Config.msg_enter_default), + LEAVE_CLAIM("leave", Config.msg_leave_default); + + String id; + String defaultValue; + Event(String id, String defaultValue) { + this.id = id; + this.defaultValue = defaultValue; + } + + @Nullable + public static Event getById(String id) { + for (Event value : values()) { + if (value.id.equalsIgnoreCase(id)) { + return value; + } + } + + return null; + } + } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index fe8b142..7f96a88 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1,8 +1,8 @@ package io.github.indicode.fabric.itsmine; +import blue.endless.jankson.annotation.Nullable; import com.mojang.authlib.GameProfile; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; @@ -11,58 +11,157 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.suggestion.SuggestionProvider; import io.github.indicode.fabric.itsmine.mixin.BlockUpdatePacketMixin; import io.github.indicode.fabric.permissions.Thimble; import io.github.indicode.fabric.permissions.command.PermissionCommand; -import io.github.voidpointerdev.minecraft.offlineinfo.OfflineInfo; -import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.command.CommandException; import net.minecraft.command.EntitySelector; import net.minecraft.command.arguments.BlockPosArgumentType; import net.minecraft.command.arguments.EntityArgumentType; +import net.minecraft.command.arguments.GameProfileArgumentType; import net.minecraft.command.arguments.PosArgument; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; -import net.minecraft.server.MinecraftServer; 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.text.ClickEvent; -import net.minecraft.text.HoverEvent; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Style; +import net.minecraft.text.*; import net.minecraft.util.Formatting; import net.minecraft.util.Pair; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; +import net.minecraft.util.registry.Registry; import java.util.*; -import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Predicate; /** * @author Indigo Amann */ public class ClaimCommand { - public static final SuggestionProvider DIRECTION_SUGGESTION_BUILDER = (source, builder) -> { + private static void validateCanAccess(ServerPlayerEntity player, Claim claim, boolean admin) throws CommandSyntaxException { + if (claim == null) { + throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); + } + + if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_FLAGS)) { + throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); + } + } + + private static RequiredArgumentBuilder getClaimArgument() { + return CommandManager.argument("claim", StringArgumentType.word()).suggests(CLAIM_PROVIDER); + } + + private static Predicate perm(String str) { + return perm(str, 2); + } + private static Predicate perm(String str, int op) { + return source -> Thimble.hasPermissionOrOp(source, "itsmine." + str, op); + } + private static final Predicate PERMISSION_CHECK_ADMIN = src -> perm("admin").test(src) || perm("admin.modify_balance").test(src) || + perm("admin.infinite_blocks").test(src) || perm("admin.modify").test(src) || + perm("admin.modify_balance").test(src) || perm("admin.ignore_claims").test(src) || + perm("admin.modify_permissions").test(src); + + public static final SuggestionProvider DIRECTION_SUGGESTION_BUILDER = (source, builder) -> { + List strings = new ArrayList<>(); for (Direction direction: Direction.values()) { - builder.suggest(direction.getName()); + if (Config.claims2d && (direction == Direction.DOWN || direction == Direction.UP)) continue; + strings.add(direction.getName()); }; - return builder.buildFuture(); + return CommandSource.suggestMatching(strings, builder); }; public static final SuggestionProvider CLAIM_PROVIDER = (source, builder) -> { - List claims = ClaimManager.INSTANCE.getPlayerClaims(source.getSource().getPlayer().getGameProfile().getId()); + ServerPlayerEntity player = source.getSource().getPlayer(); List names = new ArrayList<>(); - for (Claim claim : claims) { - names.add(claim.name); + Claim current = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.dimension); + if (current != null) names.add(current.name); + for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { + if (claim != null) { + names.add(claim.name); + } } - CommandSource.suggestMatching(names, builder); - return builder.buildFuture(); + return CommandSource.suggestMatching(names, builder); }; + public static final SuggestionProvider PLAYERS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (ServerPlayerEntity player : source.getSource().getMinecraftServer().getPlayerManager().getPlayerList()) { + strings.add(player.getEntityName()); + } + return CommandSource.suggestMatching(strings, builder); + }; + public static final SuggestionProvider SETTINGS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { + strings.add(value.id); + } + for (Claim.Permission value : Claim.Permission.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; + public static final SuggestionProvider PERMISSIONS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.Permission value : Claim.Permission.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; + public static final SuggestionProvider MESSAGE_EVENTS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.Event value : Claim.Event.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; + public static final SuggestionProvider EVENT_MESSAGE_PROVIDER = (source, builder) -> { + if (!builder.getRemaining().isEmpty()) + return builder.buildFuture(); + + List strings = new ArrayList<>(); + strings.add("reset"); + try { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(source, "claim")); + Claim.Event eventType = Claim.Event.getById(StringArgumentType.getString(source, "messageEvent")); + + if (eventType != null && claim != null) { + String message = eventType == Claim.Event.ENTER_CLAIM ? claim.enterMessage : claim.leaveMessage; + if (message != null) strings.add(message); + } + + } catch (Exception ignored) { + } + + return CommandSource.suggestMatching(strings, builder); + }; + + private static void registerHelp(LiteralArgumentBuilder builder, String id, Text[] texts, String title) { + LiteralArgumentBuilder argumentBuilder = CommandManager.literal(id) + .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, title, "/claim help " + id + " %page%")); + RequiredArgumentBuilder pageArgument = CommandManager.argument("page", IntegerArgumentType.integer(1, texts.length)) + .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, IntegerArgumentType.getInteger(context, "page"), title, "/claim help " + id + " %page%")); + + argumentBuilder.then(pageArgument); + builder.then(argumentBuilder); + } + public static void register(CommandDispatcher dispatcher) { - LiteralArgumentBuilder command = CommandManager.literal("claim"); + LiteralArgumentBuilder command = CommandManager.literal("claim") + .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help get_started %page%")); + { + LiteralArgumentBuilder help = CommandManager.literal("help"); + help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); + + registerHelp(help, "commands", Messages.HELP, "Its Mine!"); + registerHelp(help, "get_started", Messages.GET_STARTED, "Get Started"); + command.then(help); + } { LiteralArgumentBuilder create = CommandManager.literal("create"); RequiredArgumentBuilder name = CommandManager.argument("name", StringArgumentType.word()); @@ -78,27 +177,89 @@ public static void register(CommandDispatcher dispatcher) { context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); } else { String cname = StringArgumentType.getString(context, "name"); - if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), false) > 0) { + if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), false, null) > 0) { ClaimManager.INSTANCE.stickPositions.remove(player); } } return 0; }); - ArgumentBuilder min = CommandManager.argument("min", BlockPosArgumentType.blockPos()); + ArgumentBuilder min = CommandManager.argument("min", BlockPosArgumentType.blockPos()); RequiredArgumentBuilder max = CommandManager.argument("max", BlockPosArgumentType.blockPos()); max.executes(context -> createClaim( StringArgumentType.getString(context, "name"), context.getSource(), BlockPosArgumentType.getBlockPos(context, "min"), BlockPosArgumentType.getBlockPos(context, "max"), - false + false, + null )); min.then(max); name.then(min); create.then(name); command.then(create); } + { + LiteralArgumentBuilder rename = CommandManager.literal("rename"); + RequiredArgumentBuilder claimArgument = CommandManager.argument("claim", StringArgumentType.word()) + .suggests(CLAIM_PROVIDER); + RequiredArgumentBuilder nameArgument = CommandManager.argument("name", StringArgumentType.word()); + nameArgument.executes((context) -> rename(context, false)); + claimArgument.then(nameArgument); + rename.then(claimArgument); + command.then(rename); + } + { + LiteralArgumentBuilder message = CommandManager.literal("message"); + RequiredArgumentBuilder claimArgument = getClaimArgument(); + RequiredArgumentBuilder messageEvent = CommandManager.argument("messageEvent", StringArgumentType.word()) + .suggests(MESSAGE_EVENTS_PROVIDER); + RequiredArgumentBuilder messageArgument = CommandManager.argument("message", StringArgumentType.greedyString()) + .suggests(EVENT_MESSAGE_PROVIDER); + + messageArgument.executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + validateCanAccess(player, claim, PERMISSION_CHECK_ADMIN.test(context.getSource())); + Claim.Event event = Claim.Event.getById(StringArgumentType.getString(context, "messageEvent")); + + if (event == null) { + context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); + return -1; + } + + return setEventMessage(context.getSource(), claim, event, StringArgumentType.getString(context, "message")); + }); + + messageEvent.then(messageArgument); + claimArgument.then(messageEvent); + message.then(claimArgument); + command.then(message); + } + { + LiteralArgumentBuilder trusted = CommandManager.literal("trusted"); + RequiredArgumentBuilder claimArgument = getClaimArgument(); + trusted.executes((context)-> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.dimension); + if (claim == null) { + context.getSource().sendError(new LiteralText("That claim does not exist")); + return -1; + } + return showTrustedList(context, claim, false); + }); + + claimArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (claim == null) { + context.getSource().sendError(new LiteralText("That claim does not exist")); + return -1; + } + return showTrustedList(context, claim, false); + }); + trusted.then(claimArgument); + command.then(trusted); + } { LiteralArgumentBuilder stick = CommandManager.literal("stick"); stick.executes(context -> { @@ -128,7 +289,7 @@ public static void register(CommandDispatcher dispatcher) { command.then(hide); } { - LiteralArgumentBuilder check = CommandManager.literal("check_blocks"); + LiteralArgumentBuilder check = CommandManager.literal("blocks"); RequiredArgumentBuilder other = CommandManager.argument("player", EntityArgumentType.player()); other.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.checkothers", 2)); other.executes(ctx -> checkPlayer(ctx.getSource(), EntityArgumentType.getPlayer(ctx, "player").getGameProfile().getId())); @@ -137,8 +298,8 @@ public static void register(CommandDispatcher dispatcher) { command.then(check); } { - LiteralArgumentBuilder delete = CommandManager.literal("destroy"); - RequiredArgumentBuilder claim = CommandManager.argument("claim", StringArgumentType.word()); + LiteralArgumentBuilder delete = CommandManager.literal("remove"); + RequiredArgumentBuilder claim = getClaimArgument(); claim.suggests(CLAIM_PROVIDER); LiteralArgumentBuilder confirm = CommandManager.literal("confirm"); confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); @@ -203,9 +364,8 @@ public static void register(CommandDispatcher dispatcher) { } } { - LiteralArgumentBuilder delete = CommandManager.literal("destroy"); - RequiredArgumentBuilder claim = CommandManager.argument("claim", StringArgumentType.word()); - claim.suggests(CLAIM_PROVIDER); + LiteralArgumentBuilder delete = CommandManager.literal("remove"); + RequiredArgumentBuilder claim = getClaimArgument(); LiteralArgumentBuilder confirm = CommandManager.literal("confirm"); confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); @@ -216,11 +376,26 @@ public static void register(CommandDispatcher dispatcher) { } { LiteralArgumentBuilder transfer = CommandManager.literal("transfer"); - RequiredArgumentBuilder claim = CommandManager.argument("claim", StringArgumentType.word()); - claim.suggests(CLAIM_PROVIDER); + RequiredArgumentBuilder claim = CommandManager.argument("claim", StringArgumentType.word()).suggests(CLAIM_PROVIDER); RequiredArgumentBuilder player = CommandManager.argument("player", EntityArgumentType.player()); LiteralArgumentBuilder confirm = CommandManager.literal("confirm"); - confirm.executes(context -> transfer(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), EntityArgumentType.getPlayer(context, "player"), false)); + confirm.executes(context -> { + final String string = "-accept-"; + ServerPlayerEntity p = EntityArgumentType.getPlayer(context, "player"); + String input = StringArgumentType.getString(context, "claim"); + String claimName = input.replace(string, ""); + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(claimName); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + + if (input.startsWith(string)) { + return acceptTransfer(context.getSource()); + } + + return transfer(context.getSource(), claim1, p, false); + }); player.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), EntityArgumentType.getPlayer(context, "player"), false)); player.then(confirm); claim.then(player); @@ -228,18 +403,9 @@ public static void register(CommandDispatcher dispatcher) { transfer.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), EntityArgumentType.getPlayer(context, "player"), false)); command.then(transfer); } - { - LiteralArgumentBuilder transfer = CommandManager.literal("accept_transfer"); - RequiredArgumentBuilder claim = CommandManager.argument("claim", StringArgumentType.word()); - claim.suggests(CLAIM_PROVIDER); - claim.executes(context -> acceptTransfer(context.getSource())); - transfer.then(claim); - command.then(transfer); - } { LiteralArgumentBuilder info = CommandManager.literal("info"); - RequiredArgumentBuilder claim = CommandManager.argument("claim", StringArgumentType.word()); - claim.suggests(CLAIM_PROVIDER); + RequiredArgumentBuilder claim = getClaimArgument(); info.executes(context -> info( context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()) @@ -255,93 +421,38 @@ public static void register(CommandDispatcher dispatcher) { LiteralArgumentBuilder list = CommandManager.literal("list"); RequiredArgumentBuilder player = CommandManager.argument("player", StringArgumentType.word()); player.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.check_others", 2)); - player.suggests(OfflineInfo.ONLINE_PROVIDER); + player.suggests(PLAYERS_PROVIDER); list.executes(context -> list(context.getSource(), null)); player.executes(context -> list(context.getSource(), StringArgumentType.getString(context, "player"))); list.then(player); command.then(list); } - createExceptionCommand(command, false); { - LiteralArgumentBuilder settings = CommandManager.literal("flags"); - RequiredArgumentBuilder claim = CommandManager.argument("claim", StringArgumentType.word()); - claim.suggests(CLAIM_PROVIDER); - for (Claim.ClaimSettings.Setting setting: Claim.ClaimSettings.Setting.values()) { - LiteralArgumentBuilder arg = CommandManager.literal(setting.id); - arg.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (!claim1.permissionManager.hasPermission(context.getSource().getPlayer().getGameProfile().getId(), Claim.Permission.CHANGE_FLAGS)) { - context.getSource().sendFeedback(new LiteralText("You cannot change flags in this claim").formatted(Formatting.RED), false); - return 0; - } - context.getSource().sendFeedback(new LiteralText(setting.name + " is equal to " + claim1.settings.settings.get(setting)).formatted(Formatting.YELLOW), false); - return 0; - }); - RequiredArgumentBuilder setter = CommandManager.argument("value", BoolArgumentType.bool()); - setter.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (!claim1.permissionManager.hasPermission(context.getSource().getPlayer().getGameProfile().getId(), Claim.Permission.CHANGE_FLAGS)) { - context.getSource().sendFeedback(new LiteralText("You cannot change flags in this claim").formatted(Formatting.RED), false); - return 0; - } - claim1.settings.settings.put(setting, BoolArgumentType.getBool(context, "value")); - context.getSource().sendFeedback(new LiteralText(setting.name + " is now equal to " + BoolArgumentType.getBool(context, "value")).formatted(Formatting.GREEN), false); - return 0; - }); - arg.then(setter); - claim.then(arg); - } - for (Claim.Permission value : Claim.Permission.values()) { - LiteralArgumentBuilder permNode = CommandManager.literal(value.id); - RequiredArgumentBuilder allow = CommandManager.argument("allow", BoolArgumentType.bool()); - allow.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (!claim1.permissionManager.hasPermission(context.getSource().getPlayer().getGameProfile().getId(), Claim.Permission.CHANGE_FLAGS)) { - context.getSource().sendFeedback(new LiteralText("You cannot change flags in this claim").formatted(Formatting.RED), false); - return 0; - } - boolean permission = BoolArgumentType.getBool(context, "allow"); - claim1.permissionManager.defaults.setPermission(value, permission); - context.getSource().sendFeedback(new LiteralText("Players" + (permission ? " now" : " no longer") + " have the permission " + value.name).formatted(Formatting.YELLOW), false); - return 0; - }); - permNode.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (!claim1.permissionManager.hasPermission(context.getSource().getPlayer().getGameProfile().getId(), Claim.Permission.CHANGE_FLAGS)) { - context.getSource().sendFeedback(new LiteralText("You cannot change flags in this claim").formatted(Formatting.RED), false); - return 0; - } - boolean permission = claim1.permissionManager.defaults.hasPermission(value); - context.getSource().sendFeedback(new LiteralText("Players" + (permission ? " do" : " does not") + " have the permission " + value.name).formatted(Formatting.YELLOW), false); - return 0; - }); - permNode.then(allow); - claim.then(permNode); - } - settings.then(claim); - command.then(settings); + LiteralArgumentBuilder trust = CommandManager.literal("trust"); + RequiredArgumentBuilder playerArgument = CommandManager.argument("player", EntityArgumentType.player()); + RequiredArgumentBuilder claimArgument = getClaimArgument(); + + playerArgument.then(claimArgument); + trust.then(playerArgument); + command.then(trust); + } + { + LiteralArgumentBuilder distrust = CommandManager.literal("distrust"); + RequiredArgumentBuilder playerArgument = CommandManager.argument("player", EntityArgumentType.player()); + RequiredArgumentBuilder claimArgument = getClaimArgument(); + + playerArgument.then(claimArgument); + distrust.then(playerArgument); + command.then(distrust); } + + createExceptionCommand(command, false); + { LiteralArgumentBuilder admin = CommandManager.literal("admin"); - //admin.requires(source -> Thimble.hasPermissionChildOrOp(source, "itsmine.admin", 4)); + admin.requires(PERMISSION_CHECK_ADMIN); { - LiteralArgumentBuilder add = CommandManager.literal("add_blocks"); + LiteralArgumentBuilder add = CommandManager.literal("addBlocks"); add.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify_balance", 2)); RequiredArgumentBuilder player = CommandManager.argument("player", EntityArgumentType.players()); RequiredArgumentBuilder amount = CommandManager.argument("amount", IntegerArgumentType.integer()); @@ -355,7 +466,85 @@ public static void register(CommandDispatcher dispatcher) { admin.then(add); } { - LiteralArgumentBuilder remove = CommandManager.literal("remove_blocks"); + LiteralArgumentBuilder set = CommandManager.literal("setOwner"); + RequiredArgumentBuilder newOwner = CommandManager.argument("newOwner", GameProfileArgumentType.gameProfile()); + RequiredArgumentBuilder claimArgument = getClaimArgument(); + + newOwner.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getSenseCenterPos(), context.getSource().getPlayer().dimension); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + + Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); + + if (profiles.size() > 1) { + context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); + return -1; + } + return setOwner(context.getSource(), claim, profiles.iterator().next()); + }); + + claimArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + + Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); + + if (profiles.size() > 1) { + context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); + return -1; + } + return setOwner(context.getSource(), claim, profiles.iterator().next()); + }); + + newOwner.then(claimArgument); + set.then(newOwner); + admin.then(set); + } + { + LiteralArgumentBuilder set = CommandManager.literal("setOwnerName"); + RequiredArgumentBuilder nameArgument = CommandManager.argument("newName", StringArgumentType.word()); + RequiredArgumentBuilder claimArgument = getClaimArgument(); + + nameArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getSenseCenterPos(), context.getSource().getPlayer().dimension); + if (claim == null) { + context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return -1; + } + return setOwnerName(context.getSource(), claim, StringArgumentType.getString(context, "newName")); + }); + + claimArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (claim == null) { + context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return -1; + } + return setOwnerName(context.getSource(), claim, StringArgumentType.getString(context, "newName")); + }); + + nameArgument.then(claimArgument); + set.then(nameArgument); + admin.then(set); + } + { + LiteralArgumentBuilder rename = CommandManager.literal("rename"); + RequiredArgumentBuilder claimArgument = CommandManager.argument("claim", StringArgumentType.word()) + .suggests(CLAIM_PROVIDER); + RequiredArgumentBuilder nameArgument = CommandManager.argument("name", StringArgumentType.word()); + nameArgument.executes((context) -> rename(context, true)); + claimArgument.then(nameArgument); + rename.then(claimArgument); + admin.then(rename); + } + { + LiteralArgumentBuilder remove = CommandManager.literal("removeBlocks"); remove.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify_balance", 2)); RequiredArgumentBuilder player = CommandManager.argument("player", EntityArgumentType.players()); RequiredArgumentBuilder amount = CommandManager.argument("amount", IntegerArgumentType.integer()); @@ -369,7 +558,7 @@ public static void register(CommandDispatcher dispatcher) { admin.then(remove); } { - LiteralArgumentBuilder set = CommandManager.literal("set_blocks"); + LiteralArgumentBuilder set = CommandManager.literal("setBlocks"); set.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify_balance", 2)); RequiredArgumentBuilder player = CommandManager.argument("player", EntityArgumentType.players()); RequiredArgumentBuilder amount = CommandManager.argument("amount", IntegerArgumentType.integer()); @@ -383,10 +572,9 @@ public static void register(CommandDispatcher dispatcher) { admin.then(set); } { - LiteralArgumentBuilder delete = CommandManager.literal("destroy"); + LiteralArgumentBuilder delete = CommandManager.literal("remove"); delete.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify", 4)); - RequiredArgumentBuilder claim = CommandManager.argument("claim", StringArgumentType.word()); - claim.suggests(CLAIM_PROVIDER); + RequiredArgumentBuilder claim = getClaimArgument(); LiteralArgumentBuilder confirm = CommandManager.literal("confirm"); confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), true)); claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), true)); @@ -398,23 +586,60 @@ public static void register(CommandDispatcher dispatcher) { { LiteralArgumentBuilder create = CommandManager.literal("create"); create.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.infinite_claim", 4)); - ArgumentBuilder name = CommandManager.argument("name", StringArgumentType.word()); - ArgumentBuilder min = CommandManager.argument("min", BlockPosArgumentType.blockPos()); + ArgumentBuilder name = CommandManager.argument("name", StringArgumentType.word()); + ArgumentBuilder customOwner = CommandManager.argument("customOwnerName", StringArgumentType.word()); + ArgumentBuilder min = CommandManager.argument("min", BlockPosArgumentType.blockPos()); RequiredArgumentBuilder max = CommandManager.argument("max", BlockPosArgumentType.blockPos()); max.executes(context -> createClaim( StringArgumentType.getString(context, "name"), context.getSource(), BlockPosArgumentType.getBlockPos(context, "min"), BlockPosArgumentType.getBlockPos(context, "max"), - true + true, + null )); + name.executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); + if (selectedPositions == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getLeft() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getRight() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); + } else { + String cname = StringArgumentType.getString(context, "name"); + if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, null) > 0) { + ClaimManager.INSTANCE.stickPositions.remove(player); + } + } + return 0; + }); + customOwner.executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); + if (selectedPositions == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getLeft() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getRight() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); + } else { + String cname = StringArgumentType.getString(context, "name"); + if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, StringArgumentType.getString(context, "customOwnerName")) > 0) { + ClaimManager.INSTANCE.stickPositions.remove(player); + } + } + return 0; + }); min.then(max); + name.then(customOwner); name.then(min); create.then(name); admin.then(create); } { - LiteralArgumentBuilder ignore = CommandManager.literal("ignore_claims"); + LiteralArgumentBuilder ignore = CommandManager.literal("ignoreClaims"); ignore.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.ignore_claims", 4)); ignore.executes(context -> { UUID id = context.getSource().getPlayer().getGameProfile().getId(); @@ -488,18 +713,139 @@ public static void register(CommandDispatcher dispatcher) { dispatcher.register(command); } + private static int sendPage(ServerCommandSource source, Text[] text, int page, String title, String command) { + int prevPage = page - 2; + int thisPage = page - 1; + int nextPage = page + 1; + final String SEPARATOR = "-----------------------------------------------------"; + Text header = new LiteralText("") + .append(new LiteralText("- [ ").formatted(Formatting.GRAY)) + .append(new LiteralText(title).formatted(Formatting.GOLD)) + .append(" ] ") + .append(SEPARATOR.substring(ChatColor.removeAlternateColorCodes('&', title).length() + 4)) + .formatted(Formatting.GRAY); + + Text button_prev = new LiteralText("") + .append(new LiteralText("<-").formatted(Formatting.WHITE, Formatting.BOLD)) + .append(" ").append(new LiteralText("Prev").formatted(Formatting.GOLD)) + .styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); + if (prevPage >= 0) + style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(prevPage)))); + }); + + Text button_next = new LiteralText("") + .append(new LiteralText("Next").formatted(Formatting.GOLD)) + .append(" ").append(new LiteralText("->").formatted(Formatting.WHITE, Formatting.BOLD)).append(" ") + .styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); + if (nextPage < text.length) + style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); + }); + + Text buttons = new LiteralText("") + .append(new LiteralText("[ ").formatted(Formatting.GRAY)) + .append(button_prev) + .append(" ") + .append( + new LiteralText(String.valueOf(page)).formatted(Formatting.GREEN) + .append(new LiteralText("/").formatted(Formatting.GRAY)) + .append(new LiteralText(String.valueOf(text.length)).formatted(Formatting.GREEN)) + ) + .append(" ") + .append(button_next) + .append(new LiteralText("] ").formatted(Formatting.GRAY)); + + Text footer = new LiteralText("- ") + .formatted(Formatting.GRAY) + .append(buttons).append(new LiteralText(" ------------------------------").formatted(Formatting.GRAY)); + + header.append("\n").append(text[thisPage]).append("\n").append(footer); + source.sendFeedback(header, false); + return 1; + } + private static void createExceptionCommand(LiteralArgumentBuilder command, boolean admin) { + { + LiteralArgumentBuilder settings = CommandManager.literal("settings"); + RequiredArgumentBuilder claim = getClaimArgument(); + + if (!admin) { + settings.executes((context) -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Claim claim1 = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.dimension); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return querySettings(context.getSource(), claim1); + }); + + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return querySettings(context.getSource(), claim1); + }); + } + + RequiredArgumentBuilder id = CommandManager.argument("setting", StringArgumentType.word()).suggests(SETTINGS_PROVIDER); + RequiredArgumentBuilder set = CommandManager.argument("set", BoolArgumentType.bool()); + + id.executes((context) -> executeSetting(context.getSource(), StringArgumentType.getString(context, "setting"), null, true, false, admin)); + set.executes((context) -> executeSetting(context.getSource(), StringArgumentType.getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); + claim.executes((context) -> executeSetting(context.getSource(), null, null, false, BoolArgumentType.getBool(context, "set"), admin)); + + id.then(set); + claim.then(id); + settings.then(claim); + command.then(settings); + } + LiteralArgumentBuilder exceptions = CommandManager.literal("permissions"); - if (admin) exceptions.requires(source -> Thimble.hasPermissionOrOp(source, "claim.admin.modify_permissions", 2)); - RequiredArgumentBuilder claim = CommandManager.argument("claim", StringArgumentType.word()); - claim.suggests(CLAIM_PROVIDER); + if (admin) exceptions.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify_permissions", 2)); + RequiredArgumentBuilder claim = getClaimArgument(); + if (!admin) { + exceptions.executes((context) -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Claim claim1 = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.dimension); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim1, true); + }); + + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim1, false); + }); + } + + if (!admin) { + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(new LiteralText("That claim does not exist")); + return -1; + } + return showTrustedList(context, claim1, true); + }); + } + LiteralArgumentBuilder playerLiteral = CommandManager.literal("player"); { RequiredArgumentBuilder player = CommandManager.argument("player", EntityArgumentType.player()); LiteralArgumentBuilder remove = CommandManager.literal("remove"); remove.executes(context -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.CHANGE_PERMISSIONS, context, admin)) { + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); claim1.permissionManager.resetPermissions(player1.getGameProfile().getId()); context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + " no longer has an exception in the claim").formatted(Formatting.YELLOW), false); @@ -511,7 +857,7 @@ private static void createExceptionCommand(LiteralArgumentBuilder allstate = CommandManager.argument("allow", BoolArgumentType.bool()); allstate.executes(context -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.CHANGE_PERMISSIONS, context, admin)) { + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); boolean permission = BoolArgumentType.getBool(context, "allow"); claim1.permissionManager.playerPermissions.put(player1.getGameProfile().getId(), permission ? new Claim.InvertedPermissionMap() : new Claim.DefaultPermissionMap()); @@ -526,7 +872,7 @@ private static void createExceptionCommand(LiteralArgumentBuilder allow = CommandManager.argument("allow", BoolArgumentType.bool()); allow.executes(context -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.CHANGE_PERMISSIONS, context, admin)) { + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); boolean permission = BoolArgumentType.getBool(context, "allow"); modifyException(claim1, player1, value, permission); @@ -536,7 +882,7 @@ private static void createExceptionCommand(LiteralArgumentBuilder { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.CHANGE_PERMISSIONS, context, admin)) { + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); boolean permission = hasPermission(claim1, player1, value); context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); @@ -556,7 +902,7 @@ private static void createExceptionCommand(LiteralArgumentBuilder remove = CommandManager.literal("remove"); remove.executes(context -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.CHANGE_PERMISSIONS, context, admin)) { + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { String group1 = StringArgumentType.getString(context, "group"); verifyGroup(group1); claim1.permissionManager.resetPermissions(group1); @@ -570,7 +916,7 @@ private static void createExceptionCommand(LiteralArgumentBuilder allow = CommandManager.argument("allow", BoolArgumentType.bool()); allow.executes(context -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.CHANGE_PERMISSIONS, context, admin)) { + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { String group1 = StringArgumentType.getString(context, "group"); verifyGroup(group1); boolean permission = BoolArgumentType.getBool(context, "allow"); @@ -581,7 +927,7 @@ private static void createExceptionCommand(LiteralArgumentBuilder { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.CHANGE_PERMISSIONS, context, admin)) { + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { String group1 = StringArgumentType.getString(context, "group"); verifyGroup(group1); boolean permission = hasPermission(claim1, group1, value); @@ -645,7 +991,7 @@ private static int showClaim(ServerCommandSource source, Claim claim, boolean re return 0; } private static void silentHideShow(ServerPlayerEntity player, Claim claim, boolean hide, boolean updateStatus) { - BlockState block = hide ? null : Blocks.LAPIS_BLOCK.getDefaultState(); + BlockState block = hide ? null : Blocks.TARGET.getDefaultState(); int showRange = 5; int closeShowRange = 8; BlockPos pos = hide ? ((ClaimShower)player).getLastShowPos() : player.getSenseCenterPos(); @@ -713,7 +1059,7 @@ private static void sendBlockPacket(ServerPlayerEntity player, BlockPos pos, Blo if (state != null) ((BlockUpdatePacketMixin)packet).setState(state); player.networkHandler.sendPacket(packet); } - private static int createClaim(String name, ServerCommandSource owner, BlockPos posA, BlockPos posB, boolean admin) throws CommandSyntaxException { + private static int createClaim(String name, ServerCommandSource owner, BlockPos posA, BlockPos posB, boolean admin, @Nullable String cOwnerName) throws CommandSyntaxException { UUID ownerID = owner.getPlayer().getGameProfile().getId(); int x, y = 0, z, mx, my = 255, mz; if (posA.getX() > posB.getX()) { @@ -742,10 +1088,11 @@ private static int createClaim(String name, ServerCommandSource owner, BlockPos BlockPos min = new BlockPos(x, y, z); BlockPos max = new BlockPos(mx, my, mz); BlockPos sub = max.subtract(min); - sub = sub.add(1,Config.claims2d ? 0 : 1,1); + sub = sub.add(1, Config.claims2d ? 0 : 1,1); int subInt = sub.getX() * (Config.claims2d ? 1 : sub.getY()) * sub.getZ(); - Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType()); + Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getSenseCenterPos()); + if (cOwnerName != null) claim.customOwnerName = cOwnerName; claim.permissionManager.playerPermissions.put(ownerID, new Claim.InvertedPermissionMap()); if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { if (!ClaimManager.INSTANCE.wouldIntersect(claim)) { @@ -772,8 +1119,8 @@ private static int createClaim(String name, ServerCommandSource owner, BlockPos } private static int checkPlayer(ServerCommandSource ret, UUID player) throws CommandSyntaxException { int blocks = ClaimManager.INSTANCE.getClaimBlocks(player); - ret.sendFeedback(new LiteralText((ret.getPlayer().getGameProfile().getId().equals(player) ? "You have " : "They have ") + ClaimManager.INSTANCE.getClaimBlocks(player) + " blocks left").setStyle(new Style() - .setColor(Formatting.YELLOW).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Area of " + ItsMine.blocksToAreaString(ClaimManager.INSTANCE.getClaimBlocks(player))).formatted(Formatting.YELLOW)))), false); + ret.sendFeedback(new LiteralText((ret.getPlayer().getGameProfile().getId().equals(player) ? "You have " : "They have ") + blocks + " blocks left").setStyle(new Style() + .setColor(Formatting.YELLOW)), false); return 0; } private static int requestDelete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { @@ -831,7 +1178,7 @@ private static int requestTransfer(ServerCommandSource sender, Claim claim, Serv } } sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to transfer ownership of \"" + claim.name + "\" to " + player.getGameProfile().getName() + "? ").formatted(Formatting.GOLD)) - .append(new LiteralText("[I'M SURE]").setStyle(new Style() + .append(new LiteralText("[YES]").setStyle(new Style() .setColor(Formatting.DARK_RED) .setBold(true) .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")))), false); @@ -851,12 +1198,14 @@ private static int transfer(ServerCommandSource sender, Claim claim, ServerPlaye return 0; } } + + GameProfile profile = sender.getWorld().getServer().getUserCache().getByUuid(claim.claimBlockOwner); sender.sendFeedback(new LiteralText("Transferring ownership of the claim \"" + claim.name + "\" to " + player.getGameProfile().getName() + " if they accept").formatted(Formatting.GREEN), claim.claimBlockOwner != player.getGameProfile().getId()); - player.sendMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + OfflineInfo.getNameById(sender.getWorld().getServer().getUserCache(), claim.claimBlockOwner) + "? ").formatted(Formatting.GOLD)) - .append(new LiteralText("[ACCEPT OWNERSHIP]").setStyle(new Style() + player.sendMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) + .append(new LiteralText("[ACCEPT]").setStyle(new Style() .setColor(Formatting.GREEN) .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim accept_transfer " + claim.name))))); + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim transfer -accept-" + claim.name + " " + player.getEntityName() + " confirm"))))); pendingClaimTransfers.put(player.getGameProfile().getId(), claim.name); return 0; } @@ -875,11 +1224,6 @@ public static int acceptTransfer(ServerCommandSource sender) throws CommandSynta claim.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); return 0; } - private static int showClaimInfo(ServerCommandSource sender, Claim claim) { - sender.sendFeedback(new LiteralText("Claim Name: " + claim.name), false); - //sender.sendFeedback(new LiteralText("Owner")); // how to do this... - return 0; - } private static int modifyException(Claim claim, ServerPlayerEntity exception, Claim.Permission permission, boolean allowed) { claim.permissionManager.setPermission(exception.getGameProfile().getId(), permission, allowed); return 0; @@ -957,38 +1301,284 @@ private static int info(ServerCommandSource source, Claim claim) { source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); return 0; } - source.sendFeedback(new LiteralText("").append(new LiteralText("Claim Name: ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)), false); GameProfile owner = claim.claimBlockOwner == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); - source.sendFeedback(new LiteralText("").append(new LiteralText("Claim Owner: ").formatted(Formatting.YELLOW)).append(new LiteralText(owner == null ? "No owner" : owner.getName()).formatted(Formatting.GOLD)), false); BlockPos size = claim.getSize(); - source.sendFeedback(new LiteralText("").append(new LiteralText("Claim Size: ").formatted(Formatting.YELLOW)).append(new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GOLD)), false); - source.sendFeedback(new LiteralText("").append(new LiteralText("Start position: ").formatted(Formatting.YELLOW)).append(new LiteralText("X:" + claim.min.getX() + (claim.is2d() ? "" : " Y:" + claim.min.getY()) + " Z:" + claim.min.getZ()).formatted(Formatting.GOLD)), false); - source.sendFeedback(new LiteralText("").append(new LiteralText("End position: ").formatted(Formatting.YELLOW)).append(new LiteralText("X:" + claim.max.getX() + (claim.is2d() ? "" : " Y:" + claim.max.getY()) + " Z:" + claim.max.getZ()).formatted(Formatting.GOLD)), false); - return 0; + + Text text = new LiteralText("\n"); + text.append(new LiteralText("Claim Info: " + claim.name).formatted(Formatting.GOLD)).append("\n"); + text.append(newInfoLine("Name", new LiteralText(claim.name).formatted(Formatting.WHITE))); + text.append(newInfoLine("Owner", + owner != null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : + claim.customOwnerName != null ? new LiteralText(claim.customOwnerName).formatted(Formatting.GOLD) : + new LiteralText("Not Present").formatted(Formatting.RED, Formatting.ITALIC))); + text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); + + + text.append(new LiteralText("").append(new LiteralText("* Settings:").formatted(Formatting.YELLOW)) + .append(Messages.Command.getSettings(claim)).append("\n")); + Text pos = new LiteralText(""); + Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); + Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); + + if (PERMISSION_CHECK_ADMIN.test(source)) { + String format = "/tp " + source.getName() + (Config.claims2d ? " %s ~ %s" : " %s %s %s"); + min.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, + String.format(format, claim.min.getX(), Config.claims2d ? claim.min.getZ() : claim.min.getY(), claim.min.getZ())))); + max.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, + String.format(format, claim.max.getX(), Config.claims2d ? claim.max.getZ() : claim.max.getY(), claim.max.getZ())))); + } + + pos.append(newInfoLine("Position", new LiteralText("") + .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) + .append(" ") + .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); + text.append(pos); + text.append(newInfoLine("Dimension", new LiteralText(Registry.DIMENSION_TYPE.getId(claim.dimension).getPath()))); + source.sendFeedback(text, false); + return 1; } - private static int list(ServerCommandSource source, String player) { - source.sendFeedback(new LiteralText(player == null ? "Your Claims:" : player + "'s Claims:").formatted(Formatting.YELLOW), false); - try { - UUID id = player == null ? source.getPlayer().getGameProfile().getId() : OfflineInfo.getIdByName(source.getMinecraftServer().getUserCache(), player); - List claims = ClaimManager.INSTANCE.getPlayerClaims(id); - if (claims.isEmpty()) { - source.sendFeedback(new LiteralText("None").formatted(Formatting.YELLOW), false); - return 0; - } - LiteralText feedback = new LiteralText(""); - for (int i = 0; i < claims.size(); i++) { - feedback.append(new LiteralText(claims.get(i).name).setStyle( - new Style().setColor(Formatting.GOLD) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim info " + claims.get(i).name)) - )); - if (i < claims.size() - 1) { - feedback.append(new LiteralText(", ").formatted(Formatting.YELLOW)); + private static Text newPosLine(BlockPos pos, Formatting form1, Formatting form2) { + return new LiteralText("") + .append(new LiteralText(String.valueOf(pos.getX())).formatted(form1)) + .append(" ") + .append(new LiteralText(String.valueOf(pos.getY())).formatted(form2)) + .append(" ") + .append(new LiteralText(String.valueOf(pos.getZ())).formatted(form1)); + } + private static Text newInfoLine(String title, Text text) { + return new LiteralText("").append(new LiteralText("* " + title + ": ").formatted(Formatting.YELLOW)) + .append(text).append("\n"); + } + private static int list(ServerCommandSource source, String target) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + GameProfile profile = target == null ? player.getGameProfile() : source.getMinecraftServer().getUserCache().findByName(target); + + if (profile == null) { + source.sendError(Messages.INVALID_PLAYER); + return -1; + } + + List claims = ClaimManager.INSTANCE.getPlayerClaims(profile.getId()); + if (claims.isEmpty()) { + source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); + return -1; + } + + Text text = new LiteralText("\n").append(new LiteralText("Claims: " + source.getName()).formatted(Formatting.GOLD)).append("\n "); + boolean nextColor = false; + for (Claim claim : claims) { + Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click for more Info").formatted(Formatting.GREEN))); + style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); + }); + + nextColor = !nextColor; + text.append(cText.append(" ")); + } + + source.sendFeedback(text.append("\n"), false); + return 1; + } + private static int rename(CommandContext context, boolean admin) throws CommandSyntaxException { + String name = StringArgumentType.getString(context, "claim"); + String newName = StringArgumentType.getString(context, "name"); + Claim claimToRename = ClaimManager.INSTANCE.claimsByName.get(name); + if (claimToRename == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + if (ClaimManager.INSTANCE.claimsByName.containsKey(newName)) { + context.getSource().sendError(new LiteralText("That name is already taken!")); + return -1; + } + if (!admin && !claimToRename.hasPermission(context.getSource().getPlayer().getUuid(), Claim.Permission.MODIFY_PROPERTIES)) { + context.getSource().sendError(new LiteralText("You don't have permission to modify claim properties!")); + return -1; + } + ClaimManager.INSTANCE.claimsByName.remove(name); + claimToRename.name = newName; + ClaimManager.INSTANCE.addClaim(claimToRename); + claimToRename.name = newName; + context.getSource().sendFeedback(new LiteralText("Renamed Claim " + name + " to " + newName).formatted(Formatting.GOLD), admin); + return -1; + } + private static int showTrustedList(CommandContext context, Claim claim, boolean showSelf) throws CommandSyntaxException { + ServerCommandSource source = context.getSource(); + ServerPlayerEntity player = source.getPlayer(); + int mapSize = claim.permissionManager.playerPermissions.size(); + + if (mapSize == 1 && !showSelf) { + source.sendError(new LiteralText(claim.name + " is not trusting anyone!")); + return -1; + } + + Text text = new LiteralText("\n"); + text.append(new LiteralText("Trusted players for Claim ").formatted(Formatting.YELLOW)) + .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append("\n"); + + AtomicInteger atomicInteger = new AtomicInteger(); + claim.permissionManager.playerPermissions.forEach((uuid, perm) -> { + if (!uuid.equals(player.getUuid())) { + atomicInteger.incrementAndGet(); + Text pText = new LiteralText(""); + GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); + String name = profile != null ? profile.getName() : uuid.toString(); + + pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) + .append(new LiteralText(name).formatted(Formatting.YELLOW)); + + Text hover = new LiteralText(""); + hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); + + int allowed = 0; + int i = 0; + boolean nextColor = false; + for (Claim.Permission value : Claim.Permission.values()) { + if (claim.permissionManager.hasPermission(uuid, value)) { + Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; + hover.append(new LiteralText(value.id).formatted(formatting)).append(" "); + if (i == 3) hover.append("\n"); + allowed++; + i++; + nextColor = !nextColor; } } - source.sendFeedback(feedback, false); - } catch (CommandSyntaxException e) { - source.sendFeedback(new LiteralText("No player is specified").formatted(Formatting.RED), false); + + pText.append(new LiteralText(" ") + .append(new LiteralText("(").formatted(Formatting.GOLD)) + .append(new LiteralText(String.valueOf(allowed)).formatted(Formatting.GREEN)) + .append(new LiteralText("/").formatted(Formatting.GOLD)) + .append(new LiteralText(String.valueOf(Claim.Permission.values().length)).formatted(Formatting.YELLOW)) + .append(new LiteralText(")").formatted(Formatting.GOLD)) + ); + + pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); + text.append(pText); + if (atomicInteger.get() + 1 != mapSize) { + text.append("\n"); + } + } + }); + + text.append("\n"); + source.sendFeedback(text, false); + return 1; + } + private static int setOwnerName(ServerCommandSource source, Claim claim, String name) { + source.sendFeedback(new LiteralText("Set the Custom Owner Name to ") + .formatted(Formatting.YELLOW).append(new LiteralText(name).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) + .append(new LiteralText(claim.customOwnerName == null ? "Not Present" : claim.customOwnerName).formatted(Formatting.GOLD)) + .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) + , false); + claim.customOwnerName = name; + return 1; + } + private static int setOwner(ServerCommandSource source, Claim claim, GameProfile profile) { + GameProfile oldOwner = source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); + source.sendFeedback(new LiteralText("Set the Claim Owner to ") + .formatted(Formatting.YELLOW).append(new LiteralText(profile.getName()).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) + .append(new LiteralText(oldOwner == null ? "(" + claim.claimBlockOwner + ")" : oldOwner.getName()).formatted(Formatting.GOLD)) + .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) + , false); + claim.claimBlockOwner = profile.getId(); + return 1; + } + private static int setEventMessage(ServerCommandSource source, Claim claim, Claim.Event event, String message) { + switch (event) { + case ENTER_CLAIM: + claim.enterMessage = message.equalsIgnoreCase("reset") ? null : message; + break; + case LEAVE_CLAIM: + claim.leaveMessage = message.equalsIgnoreCase("reset") ? null : message; + break; + } + + if (message.equalsIgnoreCase("reset")) { + source.sendFeedback(new LiteralText("Reset ").append(new LiteralText(event.id).formatted(Formatting.GOLD) + .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) + .append(new LiteralText(claim.name).formatted(Formatting.GOLD))).formatted(Formatting.YELLOW) + , false); + return -1; + } + + source.sendFeedback(new LiteralText("Set ").append(new LiteralText(event.id).formatted(Formatting.GOLD) + .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) + .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" to:").formatted(Formatting.YELLOW))) + .append("\n").append(new LiteralText(ChatColor.translate(message))) + .formatted(Formatting.YELLOW) + , false); + return 1; + } + private static int executeSetting(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.dimension) : + ClaimManager.INSTANCE.claimsByName.get(claimName); + if (claim1 == null) { + source.sendError(Messages.INVALID_CLAIM); + return -1; + } + + if (input == null) { + return querySettings(source, claim1); + } + + validateCanAccess(player, claim1, admin); + Claim.ClaimSettings.Setting setting = Claim.ClaimSettings.Setting.byId(input); + Claim.Permission permission = Claim.Permission.byId(input); + + System.out.println(claim1); + System.out.println(permission); + System.out.println(claimName); + + if (setting != null && permission == null) + return !isQuery ? setSetting(source, claim1, setting, value) : querySetting(source, claim1, setting); + + if (setting == null && permission != null) + return !isQuery ? setPermission(source, claim1, permission, value) : queryPermission(source, claim1, permission); + + source.sendError(Messages.INVALID_SETTING); + return -1; + } + private static int executePermission(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.dimension) : + ClaimManager.INSTANCE.claimsByName.get(claimName); + if (claim1 == null) { + source.sendError(Messages.INVALID_CLAIM); + return -1; } + + validateCanAccess(player, claim1, admin); + Claim.Permission permission = Claim.Permission.byId(input); + if (permission != null) + return !isQuery ? setPermission(source, claim1, permission, value) : queryPermission(source, claim1, permission); + + source.sendError(Messages.INVALID_SETTING); + return -1; + } + private static int querySetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting) { + boolean enabled = claim.settings.settings.get(setting); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); + return 1; + } + private static int setSetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting, boolean set) { + claim.settings.settings.put(setting, set); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSet setting &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); return 0; } + private static int queryPermission(ServerCommandSource source, Claim claim, Claim.Permission permission) { + boolean defaultPerm = claim.permissionManager.defaults.hasPermission(permission); + source.sendFeedback(new LiteralText(ChatColor.translate("&ePermission &6" + permission.id + " is set to " + (defaultPerm ? "&a" : "&c") + defaultPerm + "&e for &6" + claim.name)), false); + return 1; + } + private static int setPermission(ServerCommandSource source, Claim claim, Claim.Permission permission, boolean set) { + claim.permissionManager.defaults.setPermission(permission, set); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSet permission &6" + permission.id + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); + return 1; + } + private static int querySettings(ServerCommandSource source, Claim claim) { + source.sendFeedback(new LiteralText("\n").append(new LiteralText("Settings: " + claim.name).formatted(Formatting.YELLOW)) + .append(Messages.Command.getSettings(claim)).append("\n"), false); + return 1; + } } \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/Config.java index 4ac6730..9aeb5f7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Config.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Config.java @@ -1,16 +1,7 @@ package io.github.indicode.fabric.itsmine; -import blue.endless.jankson.JsonArray; -import blue.endless.jankson.JsonPrimitive; -import io.github.indicode.fabric.permissions.Thimble; -import io.github.indicode.fabric.tinyconfig.DefaultedJsonArray; import io.github.indicode.fabric.tinyconfig.ModConfig; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - /** * @author Indigo Amann */ @@ -18,12 +9,31 @@ public class Config { public static int baseClaimBlocks3d = 15625; public static int baseClaimBlocks2d = 2500; public static boolean claims2d = true; + public static String msg_no_perm = "&c&lHey!&r&c Sorry but you don't have permission to do that"; + public static String msg_interact_entity = "&c&lHey!&r&c Sorry but you can't interact with Entities here!"; + public static String msg_interact_block = "&c&lHey!&r&c Sorry but you can't interact with Blocks here!"; + public static String msg_break_block = "&c&lHey!&r&c Sorry but you can't Break Blocks here!"; + public static String msg_place_block = "&c&lHey!&r&c Sorry but you can't Place Blocks here!"; + public static String msg_attack_entity = "&c&lHey!&r&c Sorry but you can't Attack Entities here!"; + public static String msg_enter_default = "&eNow entering claim &6%claim%"; + public static String msg_leave_default = "&eNow leaving claim &6%claim%"; + public static String msg_cant_enter = "&cHey! Sorry but you don't have permission to enter this claim!"; + public static int event_msg_stay_ticks = -1; private static ModConfig modConfig = new ModConfig("itsmine"); static void sync(boolean overwrite) { modConfig.configure(overwrite, config -> { claims2d = config.getBool("2D claims", claims2d, "Claims extending from y 0 to y 256"); baseClaimBlocks2d = config.getInt("2D base claim blocks", baseClaimBlocks2d, "Area Filled: " + ItsMine.blocksToAreaString2d(baseClaimBlocks2d)); baseClaimBlocks3d = config.getInt("3D base claim blocks", baseClaimBlocks3d, "Area Filled: " + ItsMine.blocksToAreaString3d(baseClaimBlocks3d)); + msg_interact_entity = config.getString("msg.interact.entity", msg_interact_entity); + msg_interact_block = config.getString("msg.interact.block", msg_interact_block); + msg_break_block = config.getString("msg.break.block", msg_break_block); + msg_place_block = config.getString("msg.place.block", msg_place_block); + msg_attack_entity = config.getString("msg.attack.entity", msg_attack_entity); + msg_enter_default = config.getString("msg.enter_claim", msg_enter_default, "Variables: %claim% %player%"); + msg_leave_default = config.getString("msg.leave_claim", msg_leave_default, "Variables: %claim% %player%"); + msg_cant_enter = config.getString("msg.cant_enter", msg_cant_enter); + event_msg_stay_ticks = config.getInt("event.msg.stay_ticks", event_msg_stay_ticks, "Sets how many ticks an event message will stay on action bar, Default: -1"); }); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java new file mode 100644 index 0000000..00d59dc --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -0,0 +1,111 @@ +package io.github.indicode.fabric.itsmine; + +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +public class Messages { + public static final Text INVALID_CLAIM = new LiteralText("Can not find a claim with that name").formatted(Formatting.RED); + + public static final Text INVALID_SETTING = new LiteralText("Invalid Claim Setting!").formatted(Formatting.RED); + + public static final Text NO_PERMISSION = new LiteralText(ChatColor.translate(Config.msg_no_perm)); + + public static final Text INVALID_MESSAGE_EVENT = new LiteralText("Invalid Message Event!"); + + public static final Text INVALID_PLAYER = new LiteralText("Can not find a Player with that Name!"); + + public static final Text TOO_MANY_SELECTIONS = new LiteralText("Only one selection is allowed!"); + + public static final Text MSG_PLACE_BLOCK = new LiteralText(ChatColor.translate(Config.msg_place_block)).formatted(Formatting.RED); + + public static final Text MSG_BREAK_BLOCK = new LiteralText(ChatColor.translate(Config.msg_break_block)).formatted(Formatting.RED); + + public static final Text MSG_CANT_ENTER = new LiteralText(ChatColor.translate(Config.msg_cant_enter)).formatted(Formatting.RED); + + public static final Text MSG_INTERACT_ENTITY = new LiteralText(ChatColor.translate(Config.msg_interact_entity)).formatted(Formatting.RED); + + public static final Text MSG_DAMAGE_ENTITY = new LiteralText(ChatColor.translate(Config.msg_attack_entity)).formatted(Formatting.RED); + + public static final Text[] GET_STARTED = new Text[]{ + header("How to Claim (Basics)") + .append(line(1, "Type &6/claim stick&e then Left click with a stick on a block to set the &6first&e corner of your claim")) + .append(line(2, "Right click to set the other corner")) + .append(line(3, "Type &6/claim create &e to create your claim!")) + .append(line(4, "To trust a player in your claim type &6/claim trust ")) + .append(line(5, "To untrust a player in your claim type &6/claim distrust ")), + header("How to Claim (Settings)") + .append(line("Settings allow you to change some properties of your claim, they are basically global permissions").formatted(Formatting.LIGHT_PURPLE)) + .append(line(1, "To change a setting, type ").append(text("/claim settings [true | false]").formatted(Formatting.GOLD))) + .append(line(2, "To check a setting, type ").append(text("/claim settings ").formatted(Formatting.GOLD))) + .append(line(3, "To see a list of settings, type ").append(text("/claim settings").formatted(Formatting.GOLD))), + header("How to Claim (Player Permissions)") + .append(line("You can set different permissions for each trusted player!").formatted(Formatting.LIGHT_PURPLE)) + .append(line(1, "To set a permission, type ").append(text("/claim permissions player [true | false]").formatted(Formatting.GOLD))) + .append(line(2, "To check someone's permission, type ").append(text("/claim permissions player ").formatted(Formatting.GOLD))) + .append(line(3, "To see a list of trusted players, type ").append(text("/claim trusted").formatted(Formatting.GOLD))), + header("How to Claim (Global Permissions)") + .append(line("Global Permissions are just like player permissions and as the name suggests they are global").formatted(Formatting.LIGHT_PURPLE)).formatted(Formatting.RESET) + .append(line(1, "To set a global permission, type ").append(text("/claim permissions global [true | false]").formatted(Formatting.GOLD))) + .append(line(2, "To check someone's permission, type ").append(text("/claim permissions global ").formatted(Formatting.GOLD))) + .append(line(3, "To see a list of trusted players, type ").append(text("/claim trusted").formatted(Formatting.GOLD))), + header("How to resize claim") + .append(line("You can always change the size of your claim if you aren't happy with it!").formatted(Formatting.LIGHT_PURPLE)) + .append(line(1, "To expand your claim in a direction, type ").append(text("/claim expand ").formatted(Formatting.GOLD))) + .append(line(2, "If you want to specify a direction, you can type ").append(text("/claim expand ").formatted(Formatting.GOLD))) + .append(line(3, "To shrink a claim you do the same thing but replace \"expand\" with \"shrink\"")) + }; + + public static final Text[] HELP = new Text[]{ + header("Arguments") + .append(line("&6create ").append(text("&eCreates a claim"))) + .append(line("&6blocks ").append(text("&eShows how many blocks you have left"))) + .append(line("&6claim ").append(text("&eExpands a claim"))), + header("Arguments") + .append(line("&6create ").append(text("&eCreates a claim"))) + .append(line("&6blocks ").append(text("&eShows how many blocks you have left"))) + .append(line("&6claim ").append(text("&eExpands a claim"))) + }; + + private static Text header(String title) { + return new LiteralText("").append(new LiteralText(title + ":").formatted(Formatting.AQUA, Formatting.UNDERLINE)).formatted(Formatting.WHITE).append("\n"); + } + + private static Text line(int num, String string) { + return line("&e" + num + ".&e " + string); + } + + private static Text line(String string) { + return new LiteralText("\n").append(ChatColor.translate(string)).formatted(Formatting.YELLOW); + } + + private static Text text(String text) { + return new LiteralText(text); + } + + public static class Command { + public static Text getSettings(Claim claim) { + Text claimSettings = new LiteralText(""); + boolean nextEnabled = false; + boolean nextDisabled = false; + for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { + boolean enabled = claim.settings.getSetting(value); + Formatting formatting; + if (enabled) { + if (nextEnabled) formatting = Formatting.GREEN; + else formatting = Formatting.DARK_GREEN; + nextEnabled = !nextEnabled; + } else { + if (nextDisabled) formatting = Formatting.RED; + else formatting = Formatting.DARK_RED; + nextDisabled = !nextDisabled; + } + + claimSettings.append(" ").append(new LiteralText(value.id).formatted(formatting)); + } + + return claimSettings; + } + + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index 3abbc4d..60bb1d8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -1,16 +1,18 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Functions; +import io.github.indicode.fabric.itsmine.*; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.packet.s2c.play.PlaySoundIdS2CPacket; import net.minecraft.network.packet.s2c.play.TitleS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvent; +import net.minecraft.sound.SoundEvents; import net.minecraft.text.LiteralText; import net.minecraft.text.Texts; import net.minecraft.util.Formatting; +import net.minecraft.util.registry.Registry; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -40,11 +42,26 @@ public void doPostPosActions(double x, double y, double z, CallbackInfo ci) { if (pclaim != claim && player instanceof ServerPlayerEntity) { ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity)player; if (serverPlayerEntity.networkHandler != null) { - serverPlayerEntity.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText("Now " + (claim == null ? "leaving" : "entering") + " claim ").formatted(Formatting.YELLOW).append(new LiteralText(claim == null ? pclaim.name : claim.name).formatted(Formatting.GOLD)))); - } + String message = null; + if (claim == null && pclaim != null) message = getFormattedEventMessage(player, pclaim, false); + else if (claim != null) message = getFormattedEventMessage(player, claim, true); + + if (message != null) + serverPlayerEntity.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText(ChatColor.translate(message)), -1, Config.event_msg_stay_ticks, -1)); + + if (claim.settings.getSetting(Claim.ClaimSettings.Setting.ENTER_SOUND)) { + serverPlayerEntity.networkHandler.sendPacket(new PlaySoundIdS2CPacket(Registry.SOUND_EVENT.getId(SoundEvents.BLOCK_CONDUIT_ACTIVATE), SoundCategory.MASTER, player.getPos(), 2, 1.2F)); + } } } } } + + private String getFormattedEventMessage(PlayerEntity player, Claim claim, boolean enter) { + String str = enter ? claim.enterMessage : claim.leaveMessage; + return ChatColor.translate(str == null ? (enter ? Config.msg_enter_default : Config.msg_leave_default) : str).replace("%claim%", claim.name) + .replace("%player%", player.getEntityName()); + } + @Inject(method = "tick", at = @At("RETURN")) public void doTickActions(CallbackInfo ci) { if (!world.isClient && (Object)this instanceof PlayerEntity) { @@ -53,11 +70,11 @@ public void doTickActions(CallbackInfo ci) { boolean old = player.abilities.allowFlying; Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.world.dimension.getType()); if (player instanceof ServerPlayerEntity) { - if (player.abilities.allowFlying && ((claim == null || !claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) || !claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLY)) && Functions.isClaimFlying(player.getGameProfile().getId()))) { + if (player.abilities.allowFlying && ((claim == null || !claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) || !claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT)) && Functions.isClaimFlying(player.getGameProfile().getId()))) { player.abilities.allowFlying = false; player.abilities.flying = false; Functions.setClaimFlying(player.getGameProfile().getId(), false); - } else if (!player.abilities.allowFlying && claim != null && claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) && claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLY) && Functions.canClaimFly((ServerPlayerEntity) player)) { + } else if (!player.abilities.allowFlying && claim != null && claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) && claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT) && Functions.canClaimFly((ServerPlayerEntity) player)) { player.abilities.allowFlying = true; Functions.setClaimFlying(player.getGameProfile().getId(), true); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java index 24e3fbf..dfda069 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java @@ -22,7 +22,7 @@ public class PlaceOnUseBlockMixin { public boolean canActuallyModify(World world, PlayerEntity playerEntity_1, BlockPos blockPos_1) { if (!(world instanceof ServerWorld)) return world.canPlayerModifyAt(playerEntity_1, blockPos_1); Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, playerEntity_1.world.getDimension().getType()); - if (claim != null && claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.PLACE_BREAK)) + if (claim != null && claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.BUILD)) return Functions.canPlayerActuallyModifyAt((ServerWorld) world, playerEntity_1, blockPos_1); else { if (Functions.canModifyAtClaimed(playerEntity_1, blockPos_1)) return true; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java index 16f02f0..c8da47a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java @@ -3,6 +3,7 @@ import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.ClaimShower; +import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; @@ -39,8 +40,8 @@ private boolean dontYouDareTouchMe(Entity entity, PlayerEntity playerEntity_1, H if (entity.world.isClient()) return entity.interact(playerEntity_1, hand_1); Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); if (claim != null) { - if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.ENTITY_INTERACT)) { - playerEntity_1.sendMessage(new LiteralText("").append(new LiteralText("You are in a claim that does not allow you to interact with entities").formatted(Formatting.RED)).append(new LiteralText("(Use /claim show to see an outline)").formatted(Formatting.YELLOW))); + if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.INTERACT_ENTITY)) { + playerEntity_1.sendMessage(Messages.MSG_INTERACT_ENTITY); return false; } } @@ -52,8 +53,8 @@ public void hittingIsRude(Entity entity, CallbackInfo ci) { PlayerEntity playerEntity_1 = (PlayerEntity)(Object)this; Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); if (claim != null) { - if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.ENTITY_DAMAGE)) { - playerEntity_1.sendMessage(new LiteralText("").append(new LiteralText("You are in a claim that does not allow you to hurt entities").formatted(Formatting.RED)).append(new LiteralText("(Use /claim show to see an outline)").formatted(Formatting.YELLOW))); + if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY)) { + playerEntity_1.sendMessage(Messages.MSG_INTERACT_ENTITY); ci.cancel(); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java index ca499a6..eca0b71 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java @@ -2,6 +2,7 @@ import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.entity.Entity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.player.PlayerEntity; @@ -30,8 +31,8 @@ public boolean imInvincible(Entity entity, DamageSource damageSource_1, float fl PlayerEntity playerEntity_1 = ((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()); Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); if (claim != null && entity != playerEntity_1) { - if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.ENTITY_DAMAGE)) { - playerEntity_1.sendMessage(new LiteralText("").append(new LiteralText("You are in a claim that does not allow you to hurt entities").formatted(Formatting.RED)).append(new LiteralText("(Use /claim show to see an outline)").formatted(Formatting.YELLOW))); + if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY)) { + playerEntity_1.sendMessage(Messages.MSG_DAMAGE_ENTITY); projectile.kill(); // You do not want an arrow bouncing between two armor stands return false; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java index aa0bba1..96277d6 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java @@ -3,6 +3,7 @@ import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Functions; +import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayNetworkHandler; @@ -27,8 +28,8 @@ public class ServerPlayNetworkHandlerMixin { public ActionResult iSaidDontTouchMe(Entity entity, PlayerEntity playerEntity_1, Vec3d vec3d_1, Hand hand_1) { Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); if (claim != null) { - if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.ENTITY_INTERACT)) { - playerEntity_1.sendMessage(new LiteralText("").append(new LiteralText("You are in a claim that does not allow you to interact with entities").formatted(Formatting.RED)).append(new LiteralText("(Use /claim show to see an outline)").formatted(Formatting.YELLOW))); + if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.INTERACT_ENTITY)) { + playerEntity_1.sendMessage(Messages.MSG_INTERACT_ENTITY); return ActionResult.FAIL; } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index 188b5fc..f32639d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -1,9 +1,6 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Config; -import io.github.indicode.fabric.itsmine.Functions; +import io.github.indicode.fabric.itsmine.*; import net.minecraft.block.AbstractButtonBlock; import net.minecraft.block.BlockState; import net.minecraft.block.DoorBlock; @@ -27,6 +24,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -37,6 +35,8 @@ */ @Mixin(ServerPlayerInteractionManager.class) public class ServerPlayerInteractionManagerMixin { + @Shadow public ServerPlayerEntity player; + @Redirect(method = "interactBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;onUse(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;")) public ActionResult activateIfPossible(BlockState state, World world, PlayerEntity playerEntity_1, Hand hand_1, BlockHitResult blockHitResult_1) { BlockPos pos = blockHitResult_1.getBlockPos(); @@ -44,10 +44,10 @@ public ActionResult activateIfPossible(BlockState state, World world, PlayerEnti if (claim != null) { UUID uuid = playerEntity_1.getGameProfile().getId(); if ( - claim.hasPermission(uuid, Claim.Permission.ACTIVATE_BLOCKS) || + claim.hasPermission(uuid, Claim.Permission.INTERACT_BLOCKS) || (state.getBlock() instanceof AbstractButtonBlock && claim.hasPermission(uuid, Claim.Permission.PRESS_BUTTONS)) || (state.getBlock() instanceof LeverBlock && claim.hasPermission(uuid, Claim.Permission.USE_LEVERS)) || - (state.getBlock() instanceof DoorBlock && claim.hasPermission(uuid, Claim.Permission.OPEN_DOORS)) + (state.getBlock() instanceof DoorBlock && claim.hasPermission(uuid, Claim.Permission.INTERACT_DOORS)) ) return state.onUse(world, playerEntity_1, hand_1, blockHitResult_1); else { if (state.getBlock() instanceof DoorBlock && playerEntity_1 instanceof ServerPlayerEntity) { @@ -69,19 +69,10 @@ public boolean allowItemUse(ItemStack stack, PlayerEntity playerEntity_1, World UUID uuid = playerEntity_1.getGameProfile().getId(); if ( claim.hasPermission(uuid, Claim.Permission.USE_ITEMS_ON_BLOCKS) || - (stack.getItem() instanceof BlockItem && claim.hasPermission(uuid, Claim.Permission.PLACE_BREAK)) || - (stack.getItem() instanceof BucketItem && claim.hasPermission(uuid, Claim.Permission.PLACE_BREAK)) + (stack.getItem() instanceof BlockItem && claim.hasPermission(uuid, Claim.Permission.BUILD)) || + (stack.getItem() instanceof BucketItem && claim.hasPermission(uuid, Claim.Permission.BUILD)) ) return false; - if (stack.getItem() instanceof BlockItem) { - playerEntity_1.sendMessage(new LiteralText("").append(new LiteralText("You cannot place blocks in this claim").formatted(Formatting.RED)).append(new LiteralText("(Use /claim show to see an outline)").formatted(Formatting.YELLOW))); - } - if (stack.getItem() instanceof BucketItem) { - if (!Functions.isBucketEmpty((BucketItem) stack.getItem())) { - playerEntity_1.sendMessage(new LiteralText("").append(new LiteralText("You cannot pick up fluids in this claim").formatted(Formatting.RED)).append(new LiteralText("(Use /claim show to see an outline)").formatted(Formatting.YELLOW))); - } else { - playerEntity_1.sendMessage(new LiteralText("").append(new LiteralText("You cannot place fluids in this claim").formatted(Formatting.RED)).append(new LiteralText("(Use /claim show to see an outline)").formatted(Formatting.YELLOW))); - } - } + playerEntity_1.sendMessage(Messages.MSG_PLACE_BLOCK); return true; } return stack.isEmpty(); @@ -109,9 +100,9 @@ public boolean canBreak(ServerWorld world, PlayerEntity player, BlockPos pos) { if (claim != null) { UUID uuid = player.getGameProfile().getId(); if ( - claim.hasPermission(uuid, Claim.Permission.PLACE_BREAK) + claim.hasPermission(uuid, Claim.Permission.BUILD) ) return Functions.canPlayerActuallyModifyAt(world, player, pos); - player.sendMessage(new LiteralText("").append(new LiteralText("You cannot break blocks in this claim").formatted(Formatting.RED)).append(new LiteralText("(Use /claim show to see an outline)").formatted(Formatting.YELLOW))); + player.sendMessage(Messages.MSG_BREAK_BLOCK); return false; } return world.canPlayerModifyAt(player, pos); From 048b5cad768d056caaa4098f5ffa599a8de18b51 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Wed, 11 Mar 2020 15:28:01 +0330 Subject: [PATCH 02/85] Finally fixed the stuff --- .../indicode/fabric/itsmine/ClaimCommand.java | 9 ++++---- .../indicode/fabric/itsmine/Messages.java | 2 +- .../fabric/itsmine/mixin/EntityMixin.java | 20 ++++++++++++------ src/main/resources/assets/modid/icon.png | Bin 453 -> 0 bytes src/main/resources/fabric.mod.json | 8 +++---- 5 files changed, 22 insertions(+), 17 deletions(-) delete mode 100644 src/main/resources/assets/modid/icon.png diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 7f96a88..01fc1b6 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -731,7 +731,7 @@ private static int sendPage(ServerCommandSource source, Text[] text, int page, S .styled((style) -> { style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); if (prevPage >= 0) - style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(prevPage)))); + style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); }); Text button_next = new LiteralText("") @@ -739,7 +739,7 @@ private static int sendPage(ServerCommandSource source, Text[] text, int page, S .append(" ").append(new LiteralText("->").formatted(Formatting.WHITE, Formatting.BOLD)).append(" ") .styled((style) -> { style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); - if (nextPage < text.length) + if (nextPage <= text.length) style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); }); @@ -794,9 +794,8 @@ private static void createExceptionCommand(LiteralArgumentBuilder id = CommandManager.argument("setting", StringArgumentType.word()).suggests(SETTINGS_PROVIDER); RequiredArgumentBuilder set = CommandManager.argument("set", BoolArgumentType.bool()); - id.executes((context) -> executeSetting(context.getSource(), StringArgumentType.getString(context, "setting"), null, true, false, admin)); + id.executes((context) -> executeSetting(context.getSource(), StringArgumentType.getString(context, "setting"), StringArgumentType.getString(context, "claim"), true, false, admin)); set.executes((context) -> executeSetting(context.getSource(), StringArgumentType.getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); - claim.executes((context) -> executeSetting(context.getSource(), null, null, false, BoolArgumentType.getBool(context, "set"), admin)); id.then(set); claim.then(id); @@ -1577,7 +1576,7 @@ private static int setPermission(ServerCommandSource source, Claim claim, Claim. return 1; } private static int querySettings(ServerCommandSource source, Claim claim) { - source.sendFeedback(new LiteralText("\n").append(new LiteralText("Settings: " + claim.name).formatted(Formatting.YELLOW)) + source.sendFeedback(new LiteralText("\n").append(new LiteralText("Settings: " + claim.name).formatted(Formatting.YELLOW)).append("\n") .append(Messages.Command.getSettings(claim)).append("\n"), false); return 1; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 00d59dc..5c6180b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -5,7 +5,7 @@ import net.minecraft.util.Formatting; public class Messages { - public static final Text INVALID_CLAIM = new LiteralText("Can not find a claim with that name").formatted(Formatting.RED); + public static final Text INVALID_CLAIM = new LiteralText("Can not find a claim with that name or a claim at your position").formatted(Formatting.RED); public static final Text INVALID_SETTING = new LiteralText("Invalid Claim Setting!").formatted(Formatting.RED); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index 60bb1d8..26ae5ab 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -12,6 +12,7 @@ import net.minecraft.text.LiteralText; import net.minecraft.text.Texts; import net.minecraft.util.Formatting; +import net.minecraft.util.math.Vec3d; import net.minecraft.util.registry.Registry; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; @@ -24,6 +25,7 @@ public abstract class EntityMixin { @Shadow public World world; + @Shadow private Vec3d field_22467; private Claim pclaim = null; @Inject(method = "setPos", at = @At("HEAD")) public void doPrePosActions(double x, double y, double z, CallbackInfo ci) { @@ -43,23 +45,29 @@ public void doPostPosActions(double x, double y, double z, CallbackInfo ci) { ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity)player; if (serverPlayerEntity.networkHandler != null) { String message = null; - if (claim == null && pclaim != null) message = getFormattedEventMessage(player, pclaim, false); - else if (claim != null) message = getFormattedEventMessage(player, claim, true); + if (pclaim != null && claim == null) + message = getFormattedEventMessage(player, pclaim, false); + else if (claim != null) + message = getFormattedEventMessage(player, claim, true); if (message != null) serverPlayerEntity.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText(ChatColor.translate(message)), -1, Config.event_msg_stay_ticks, -1)); - if (claim.settings.getSetting(Claim.ClaimSettings.Setting.ENTER_SOUND)) { - serverPlayerEntity.networkHandler.sendPacket(new PlaySoundIdS2CPacket(Registry.SOUND_EVENT.getId(SoundEvents.BLOCK_CONDUIT_ACTIVATE), SoundCategory.MASTER, player.getPos(), 2, 1.2F)); - } } + if (claim != null && claim.settings.getSetting(Claim.ClaimSettings.Setting.ENTER_SOUND)) { + serverPlayerEntity.networkHandler.sendPacket(new PlaySoundIdS2CPacket(Registry.SOUND_EVENT.getId(SoundEvents.BLOCK_CONDUIT_ACTIVATE), SoundCategory.MASTER, this.field_22467, 2, 1.2F)); + } + } } } } private String getFormattedEventMessage(PlayerEntity player, Claim claim, boolean enter) { + if (player == null || claim == null) + return ""; + String str = enter ? claim.enterMessage : claim.leaveMessage; return ChatColor.translate(str == null ? (enter ? Config.msg_enter_default : Config.msg_leave_default) : str).replace("%claim%", claim.name) - .replace("%player%", player.getEntityName()); + .replace("%player%", player.getName().asString()); } @Inject(method = "tick", at = @At("RETURN")) diff --git a/src/main/resources/assets/modid/icon.png b/src/main/resources/assets/modid/icon.png deleted file mode 100644 index 047b91f2347de5cf95f23284476fddbe21ba23fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 453 zcmV;$0XqJPP)QAFYGys`80vegN0XDFh0OXKz&i8?Le#x7{1X)R+00000NkvXXu0mjf73i~T diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index c65b390..01134d1 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -6,15 +6,14 @@ "name": "Its Mine!", "description": "Land claims.", "authors": [ - "Indicode" + "Indicode", + "Maintained by CODY_AI" ], "contact": { - "homepage": "https://fabricmc.net/", - "sources": "https://github.com/FabricMC/fabric-example-mod" + "sources": "https://github.com/GiantNuker/NoGrief/" }, "license": "CC0-1.0", - "icon": "assets/itsmine/icon.png", "environment": "*", "entrypoints": { @@ -30,6 +29,5 @@ "fabricloader": ">=0.4.0" }, "suggests": { - "flamingo": "*" } } From 6963f0284478d3c293d5cd7ac1bfdeb2096faf1b Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Wed, 11 Mar 2020 15:45:59 +0330 Subject: [PATCH 03/85] Added functionallity for '/claim trust' and '/claim distrust' --- .../github/indicode/fabric/itsmine/Claim.java | 4 +- .../indicode/fabric/itsmine/ClaimCommand.java | 39 +++++++++++++++---- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 006c010..c69991d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -473,8 +473,8 @@ public enum Setting { PISTON_FROM_INSIDE("pistons_inside_border", "Pistons Cross border from Inside", true), PISTON_FROM_OUTSIDE("pistons_outside_border", "Pistons Cross border from Outside", false), MOB_SPAWNING("mob_spawn", "Natural mob spawning", true), - KEEP_INVENTORY("keep_inventory", "Keep Inventory", true), - TELEPORT("teleport", "Global Teleport Access", true), +// KEEP_INVENTORY("keep_inventory", "Keep Inventory", true), +// TELEPORT("teleport", "Global Teleport Access", true), ENTER_SOUND("enter_sound", "Enter Sound", true); String id, name; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 01fc1b6..c99f611 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -54,6 +54,10 @@ private static void validateCanAccess(ServerPlayerEntity player, Claim claim, bo } } + private static void validateClaim(Claim claim) throws CommandSyntaxException { + if (claim == null) throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); + } + private static RequiredArgumentBuilder getClaimArgument() { return CommandManager.argument("claim", StringArgumentType.word()).suggests(CLAIM_PROVIDER); } @@ -432,6 +436,9 @@ public static void register(CommandDispatcher dispatcher) { RequiredArgumentBuilder playerArgument = CommandManager.argument("player", EntityArgumentType.player()); RequiredArgumentBuilder claimArgument = getClaimArgument(); + playerArgument.executes((context -> executeTrust(context, EntityArgumentType.getPlayer(context, "player"), true, null))); + claimArgument.executes((context -> executeTrust(context, EntityArgumentType.getPlayer(context, "player"), true, StringArgumentType.getString(context, "claim")))); + playerArgument.then(claimArgument); trust.then(playerArgument); command.then(trust); @@ -441,6 +448,9 @@ public static void register(CommandDispatcher dispatcher) { RequiredArgumentBuilder playerArgument = CommandManager.argument("player", EntityArgumentType.player()); RequiredArgumentBuilder claimArgument = getClaimArgument(); + playerArgument.executes((context -> executeTrust(context, EntityArgumentType.getPlayer(context, "player"), false, null))); + claimArgument.executes((context -> executeTrust(context, EntityArgumentType.getPlayer(context, "player"), false, StringArgumentType.getString(context, "claim")))); + playerArgument.then(claimArgument); distrust.then(playerArgument); command.then(distrust); @@ -856,13 +866,9 @@ private static void createExceptionCommand(LiteralArgumentBuilder allstate = CommandManager.argument("allow", BoolArgumentType.bool()); allstate.executes(context -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - boolean permission = BoolArgumentType.getBool(context, "allow"); - claim1.permissionManager.playerPermissions.put(player1.getGameProfile().getId(), permission ? new Claim.InvertedPermissionMap() : new Claim.DefaultPermissionMap()); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has all the permissions").formatted(Formatting.YELLOW), false); - } - return 0; + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + validateClaim(claim1); + return setTrust(context, claim1, player1, BoolArgumentType.getBool(context, "allow"), admin); }); all.then(allstate); player.then(all); @@ -1580,4 +1586,23 @@ private static int querySettings(ServerCommandSource source, Claim claim) { .append(Messages.Command.getSettings(claim)).append("\n"), false); return 1; } + private static int executeTrust(CommandContext context, ServerPlayerEntity target, boolean set, @Nullable String claimName) throws CommandSyntaxException { + ServerPlayerEntity p = context.getSource().getPlayer(); + Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getSenseCenterPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); + validateClaim(claim1); + + return setTrust(context, claim1, target, set, false); + } + private static int setTrust(CommandContext context, Claim claim, ServerPlayerEntity target, boolean set, boolean admin) throws CommandSyntaxException { + if (verifyPermission(claim, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + claim.permissionManager.playerPermissions.put(target.getGameProfile().getId(), set ? new Claim.InvertedPermissionMap() : new Claim.DefaultPermissionMap()); + context.getSource().sendFeedback(new LiteralText(target.getGameProfile().getName() + (set ? " now" : " no longer") + " has all the permissions").formatted(Formatting.YELLOW), false); + + String message; + if (set) message = "&aTrusted player &6" + target.getEntityName() + "&a in &6" + claim.name + "\n&aThey now have all the default permissions"; + else message = "&cDistrusted player &6" + target.getEntityName() + "&c in &6" + claim.name + "\n&cThey don't have any permissions now"; + context.getSource().sendFeedback(new LiteralText(ChatColor.translate(message)), false); + } + return 1; + } } \ No newline at end of file From 9d83c55321bae208f00a0d54a2f77122c7419e02 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Wed, 11 Mar 2020 16:28:26 +0330 Subject: [PATCH 04/85] Officially finished claims --- .../indicode/fabric/itsmine/ClaimCommand.java | 63 ++++++++++--------- .../indicode/fabric/itsmine/Config.java | 2 + .../indicode/fabric/itsmine/Messages.java | 58 ++++++++++------- 3 files changed, 72 insertions(+), 51 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index c99f611..b24dc20 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -147,9 +147,9 @@ private static Predicate perm(String str, int op) { private static void registerHelp(LiteralArgumentBuilder builder, String id, Text[] texts, String title) { LiteralArgumentBuilder argumentBuilder = CommandManager.literal(id) - .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, title, "/claim help " + id + " %page%")); + .executes((context) -> sendPage(context.getSource(), texts, 1, title, "/claim help " + id + " %page%")); RequiredArgumentBuilder pageArgument = CommandManager.argument("page", IntegerArgumentType.integer(1, texts.length)) - .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, IntegerArgumentType.getInteger(context, "page"), title, "/claim help " + id + " %page%")); + .executes((context) -> sendPage(context.getSource(), texts, IntegerArgumentType.getInteger(context, "page"), title, "/claim help " + id + " %page%")); argumentBuilder.then(pageArgument); builder.then(argumentBuilder); @@ -162,8 +162,8 @@ public static void register(CommandDispatcher dispatcher) { LiteralArgumentBuilder help = CommandManager.literal("help"); help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); - registerHelp(help, "commands", Messages.HELP, "Its Mine!"); registerHelp(help, "get_started", Messages.GET_STARTED, "Get Started"); + registerHelp(help, "commands", Messages.HELP, "Its Mine!"); command.then(help); } { @@ -213,33 +213,6 @@ public static void register(CommandDispatcher dispatcher) { rename.then(claimArgument); command.then(rename); } - { - LiteralArgumentBuilder message = CommandManager.literal("message"); - RequiredArgumentBuilder claimArgument = getClaimArgument(); - RequiredArgumentBuilder messageEvent = CommandManager.argument("messageEvent", StringArgumentType.word()) - .suggests(MESSAGE_EVENTS_PROVIDER); - RequiredArgumentBuilder messageArgument = CommandManager.argument("message", StringArgumentType.greedyString()) - .suggests(EVENT_MESSAGE_PROVIDER); - - messageArgument.executes(context -> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - validateCanAccess(player, claim, PERMISSION_CHECK_ADMIN.test(context.getSource())); - Claim.Event event = Claim.Event.getById(StringArgumentType.getString(context, "messageEvent")); - - if (event == null) { - context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); - return -1; - } - - return setEventMessage(context.getSource(), claim, event, StringArgumentType.getString(context, "message")); - }); - - messageEvent.then(messageArgument); - claimArgument.then(messageEvent); - message.then(claimArgument); - command.then(message); - } { LiteralArgumentBuilder trusted = CommandManager.literal("trusted"); RequiredArgumentBuilder claimArgument = getClaimArgument(); @@ -945,6 +918,36 @@ private static void createExceptionCommand(LiteralArgumentBuilder message = CommandManager.literal("message"); + RequiredArgumentBuilder claimArgument = getClaimArgument(); + RequiredArgumentBuilder messageEvent = CommandManager.argument("messageEvent", StringArgumentType.word()) + .suggests(MESSAGE_EVENTS_PROVIDER); + RequiredArgumentBuilder messageArgument = CommandManager.argument("message", StringArgumentType.greedyString()) + .suggests(EVENT_MESSAGE_PROVIDER); + + messageArgument.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PROPERTIES, context, admin)) { + Claim.Event event = Claim.Event.getById(StringArgumentType.getString(context, "messageEvent")); + + if (event == null) { + context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); + return -1; + } + + return setEventMessage(context.getSource(), claim1, event, StringArgumentType.getString(context, "message")); + } + + return -1; + }); + + messageEvent.then(messageArgument); + claimArgument.then(messageEvent); + message.then(claimArgument); + command.then(message); + } + claim.then(playerLiteral); claim.then(groupLiteral); exceptions.then(claim); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/Config.java index 9aeb5f7..0394dce 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Config.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Config.java @@ -9,6 +9,7 @@ public class Config { public static int baseClaimBlocks3d = 15625; public static int baseClaimBlocks2d = 2500; public static boolean claims2d = true; + public static String prefix = "&8[&aClaims&8]&r "; public static String msg_no_perm = "&c&lHey!&r&c Sorry but you don't have permission to do that"; public static String msg_interact_entity = "&c&lHey!&r&c Sorry but you can't interact with Entities here!"; public static String msg_interact_block = "&c&lHey!&r&c Sorry but you can't interact with Blocks here!"; @@ -25,6 +26,7 @@ static void sync(boolean overwrite) { claims2d = config.getBool("2D claims", claims2d, "Claims extending from y 0 to y 256"); baseClaimBlocks2d = config.getInt("2D base claim blocks", baseClaimBlocks2d, "Area Filled: " + ItsMine.blocksToAreaString2d(baseClaimBlocks2d)); baseClaimBlocks3d = config.getInt("3D base claim blocks", baseClaimBlocks3d, "Area Filled: " + ItsMine.blocksToAreaString3d(baseClaimBlocks3d)); + prefix = config.getString("msg.prefix", prefix); msg_interact_entity = config.getString("msg.interact.entity", msg_interact_entity); msg_interact_block = config.getString("msg.interact.block", msg_interact_block); msg_break_block = config.getString("msg.break.block", msg_break_block); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 5c6180b..78f65ba 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -5,27 +5,29 @@ import net.minecraft.util.Formatting; public class Messages { - public static final Text INVALID_CLAIM = new LiteralText("Can not find a claim with that name or a claim at your position").formatted(Formatting.RED); + public static final Text PREFIX = new LiteralText(ChatColor.translate(Config.prefix)); - public static final Text INVALID_SETTING = new LiteralText("Invalid Claim Setting!").formatted(Formatting.RED); + public static final Text INVALID_CLAIM = PREFIX.copy().append(new LiteralText("Can not find a claim with that name or a claim at your position").formatted(Formatting.RED)); - public static final Text NO_PERMISSION = new LiteralText(ChatColor.translate(Config.msg_no_perm)); + public static final Text INVALID_SETTING = PREFIX.copy().append(new LiteralText("Invalid Claim Setting!").formatted(Formatting.RED)); - public static final Text INVALID_MESSAGE_EVENT = new LiteralText("Invalid Message Event!"); + public static final Text NO_PERMISSION = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_no_perm))); - public static final Text INVALID_PLAYER = new LiteralText("Can not find a Player with that Name!"); + public static final Text INVALID_MESSAGE_EVENT = PREFIX.copy().append(new LiteralText("Invalid Message Event!")); - public static final Text TOO_MANY_SELECTIONS = new LiteralText("Only one selection is allowed!"); + public static final Text INVALID_PLAYER = PREFIX.copy().append(new LiteralText("Can not find a Player with that Name!")); - public static final Text MSG_PLACE_BLOCK = new LiteralText(ChatColor.translate(Config.msg_place_block)).formatted(Formatting.RED); + public static final Text TOO_MANY_SELECTIONS = PREFIX.copy().append(new LiteralText("Only one selection is allowed!")); - public static final Text MSG_BREAK_BLOCK = new LiteralText(ChatColor.translate(Config.msg_break_block)).formatted(Formatting.RED); + public static final Text MSG_PLACE_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_place_block)).formatted(Formatting.RED)); - public static final Text MSG_CANT_ENTER = new LiteralText(ChatColor.translate(Config.msg_cant_enter)).formatted(Formatting.RED); + public static final Text MSG_BREAK_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_break_block)).formatted(Formatting.RED)); - public static final Text MSG_INTERACT_ENTITY = new LiteralText(ChatColor.translate(Config.msg_interact_entity)).formatted(Formatting.RED); + public static final Text MSG_CANT_ENTER = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_enter)).formatted(Formatting.RED)); - public static final Text MSG_DAMAGE_ENTITY = new LiteralText(ChatColor.translate(Config.msg_attack_entity)).formatted(Formatting.RED); + public static final Text MSG_INTERACT_ENTITY = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_interact_entity)).formatted(Formatting.RED)); + + public static final Text MSG_DAMAGE_ENTITY = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_attack_entity)).formatted(Formatting.RED)); public static final Text[] GET_STARTED = new Text[]{ header("How to Claim (Basics)") @@ -44,11 +46,6 @@ public class Messages { .append(line(1, "To set a permission, type ").append(text("/claim permissions player [true | false]").formatted(Formatting.GOLD))) .append(line(2, "To check someone's permission, type ").append(text("/claim permissions player ").formatted(Formatting.GOLD))) .append(line(3, "To see a list of trusted players, type ").append(text("/claim trusted").formatted(Formatting.GOLD))), - header("How to Claim (Global Permissions)") - .append(line("Global Permissions are just like player permissions and as the name suggests they are global").formatted(Formatting.LIGHT_PURPLE)).formatted(Formatting.RESET) - .append(line(1, "To set a global permission, type ").append(text("/claim permissions global [true | false]").formatted(Formatting.GOLD))) - .append(line(2, "To check someone's permission, type ").append(text("/claim permissions global ").formatted(Formatting.GOLD))) - .append(line(3, "To see a list of trusted players, type ").append(text("/claim trusted").formatted(Formatting.GOLD))), header("How to resize claim") .append(line("You can always change the size of your claim if you aren't happy with it!").formatted(Formatting.LIGHT_PURPLE)) .append(line(1, "To expand your claim in a direction, type ").append(text("/claim expand ").formatted(Formatting.GOLD))) @@ -60,11 +57,30 @@ public class Messages { header("Arguments") .append(line("&6create ").append(text("&eCreates a claim"))) .append(line("&6blocks ").append(text("&eShows how many blocks you have left"))) - .append(line("&6claim ").append(text("&eExpands a claim"))), + .append(line("&6trust ").append(text("&eLets you trust a player in your claim"))) + .append(line("&6distrust ").append(text("&eLets you distrust a player in your claim"))) + .append(line("&6trusted ").append(text("&eShows you a list of all the trusted players"))) + .append(line("&6expand ").append(text("&eLets you expand your claim"))), + header("Arguments") - .append(line("&6create ").append(text("&eCreates a claim"))) - .append(line("&6blocks ").append(text("&eShows how many blocks you have left"))) - .append(line("&6claim ").append(text("&eExpands a claim"))) + .append(line("&6shrink ").append(text("&eLets you shrink your claim"))) + .append(line("&6help ").append(text("&eShows this list"))) + .append(line("&6show ").append(text("&eShows the borders of your claim"))) + .append(line("&6hide ").append(text("&eHides the borders of your claim"))) + .append(line("&6info ").append(text("&eShows you some information about a claim"))) + .append(line("&6list ").append(text("&eShows you the list of your claims"))), + + header("Arguments") + .append(line("&6permissions ").append(text("&eLets you modify the permissions of players and add exceptions"))) + .append(line("&6remove ").append(text("&eRemoves your claim"))) + .append(line("&6rename ").append(text("&eLets you rename your claim"))) + .append(line("&6settings ").append(text("&eLets you modify the global permissions and setting of your claim"))) + .append(line("&6message ").append(text("&eLets you modify the different message events"))) + .append(line("&6stick ").append(text("&eEnables/disables the claim stick for marking the positions"))), + + header("Arguments") + .append(line("&6transfer ").append(text("&eLets you transfer the ownership of a claim"))) + .append(line("&6message ").append(text("&eLets you modify the different message events"))) }; private static Text header(String title) { @@ -80,7 +96,7 @@ private static Text line(String string) { } private static Text text(String text) { - return new LiteralText(text); + return new LiteralText(ChatColor.translate(text)); } public static class Command { From a7e7a914fcb113669302d5ee4740ee84445389f4 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Wed, 11 Mar 2020 17:29:03 +0330 Subject: [PATCH 05/85] up --- gradle.properties | 5 +++-- .../java/io/github/indicode/fabric/itsmine/ClaimCommand.java | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index 12e432e..6e8554b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=20w10a+build.6 loader_version=0.7.8+build.186 # Mod Properties - mod_version = 1.3.8 + mod_version = 1.5 maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine @@ -16,5 +16,6 @@ loader_version=0.7.8+build.186 # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api #fabric_version=0.3.2+build.218-1.14 tiny_config_version = 1.1.2 -thimble_permissions_version=26b2bbfb06 +#26b2bbfb06 +thimble_permissions_version=b1e992cba7 offline_info_version=1a3a7fc98b diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index b24dc20..2dbb7a7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1566,7 +1566,7 @@ private static int executePermission(ServerCommandSource source, String input, @ } private static int querySetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting) { boolean enabled = claim.settings.settings.get(setting); - source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); return 1; } private static int setSetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting, boolean set) { @@ -1576,7 +1576,7 @@ private static int setSetting(ServerCommandSource source, Claim claim, Claim.Cla } private static int queryPermission(ServerCommandSource source, Claim claim, Claim.Permission permission) { boolean defaultPerm = claim.permissionManager.defaults.hasPermission(permission); - source.sendFeedback(new LiteralText(ChatColor.translate("&ePermission &6" + permission.id + " is set to " + (defaultPerm ? "&a" : "&c") + defaultPerm + "&e for &6" + claim.name)), false); + source.sendFeedback(new LiteralText(ChatColor.translate("&ePermission &6" + permission.id + "&e is set to " + (defaultPerm ? "&a" : "&c") + defaultPerm + "&e for &6" + claim.name)), false); return 1; } private static int setPermission(ServerCommandSource source, Claim claim, Claim.Permission permission, boolean set) { From d4fc3dbf55e6a59633718993b5f092a9cabecb4d Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Wed, 11 Mar 2020 21:37:00 +0330 Subject: [PATCH 06/85] Updated to 20w11a --- gradle.properties | 8 ++++---- .../java/io/github/indicode/fabric/itsmine/Claim.java | 4 ++-- .../fabric/itsmine/mixin/MinecraftServerMixin.java | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6e8554b..187b740 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=20w10a -yarn_mappings=20w10a+build.6 -loader_version=0.7.8+build.186 +minecraft_version=20w11a +yarn_mappings=20w11a+build.1 +loader_version=0.7.8+build.187 # Mod Properties - mod_version = 1.5 + mod_version = 1.5-20w11a maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index c69991d..1f57477 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -186,7 +186,7 @@ public CompoundTag toTag() { { tag.put("settings", settings.toTag()); tag.put("permissions", permissionManager.toNBT()); - if (claimBlockOwner != null) tag.putUuid("top_owner", claimBlockOwner); + if (claimBlockOwner != null) tag.putUuidNew("top_owner", claimBlockOwner); } { CompoundTag meta = new CompoundTag(); @@ -226,7 +226,7 @@ public void fromTag(CompoundTag tag) { this.settings = new ClaimSettings(tag.getCompound("settings")); permissionManager = new PermissionManager(); permissionManager.fromNBT(tag.getCompound("permissions")); - if (tag.containsUuid("top_owner")) claimBlockOwner = tag.getUuid("top_owner"); + if (tag.containsUuidNew("top_owner")) claimBlockOwner = tag.getUuidNew("top_owner"); } { CompoundTag meta = tag.getCompound("meta"); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java index 704137f..498823b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java @@ -3,6 +3,7 @@ import com.google.gson.JsonElement; import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; +import net.minecraft.class_4952; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtIo; import net.minecraft.server.MinecraftServer; @@ -24,10 +25,10 @@ @Mixin(MinecraftServer.class) public abstract class MinecraftServerMixin { @Inject(method = "loadWorld", at = @At("RETURN")) - private void loadClaims(String string_1, String string_2, long long_1, LevelGeneratorType levelGeneratorType_1, JsonElement jsonElement_1, CallbackInfo ci) { + private void loadClaims(String name, String serverName, long seed, class_4952 arg, CallbackInfo ci) { ClaimManager.INSTANCE = new ClaimManager(); - File claims = new File(gameDir.getPath() + "/" + string_1 + "/claims.dat"); - File claims_old = new File(gameDir.getPath() + "/" + string_1 + "/claims.dat_old"); + File claims = new File(gameDir.getPath() + "/" + name + "/claims.dat"); + File claims_old = new File(gameDir.getPath() + "/" + name + "/claims.dat_old"); if (!claims.exists()) { if (claims_old.exists()) {} else return; From 6c4611569b867c4b8119b51bece4761d8635caac Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Thu, 12 Mar 2020 00:16:29 +0330 Subject: [PATCH 07/85] Updated Thimble Version --- build.gradle | 3 ++- gradle.properties | 2 +- src/main/java/io/github/indicode/fabric/itsmine/Claim.java | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index f42613c..8cd0d08 100644 --- a/build.gradle +++ b/build.gradle @@ -23,8 +23,9 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modCompile "net.fabricmc:fabric-loader:${project.loader_version}" + modImplementation "com.github.OnBlock:Thimble-Permissions:${project.thimble_permissions_version}" //modImplementation "com.github.giantnuker:TinyConfig:${project.tiny_config_version}" - modImplementation /*"io.github.indicode.fabric:thimble-permissions:0.0.9"//*/"com.github.giantnuker:Thimble-Permissions:${project.thimble_permissions_version}" + //modImplementation /*"io.github.indicode.fabric:thimble-permissions:0.0.9"//*/"com.github.giantnuker:Thimble-Permissions:${project.thimble_permissions_version}" //modImplementation "com.github.giantnuker:OfflineInfo:${project.offline_info_version}" //include "com.github.giantnuker:TinyConfig:${project.tiny_config_version}" diff --git a/gradle.properties b/gradle.properties index 187b740..413cbc7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,5 +17,5 @@ loader_version=0.7.8+build.187 #fabric_version=0.3.2+build.218-1.14 tiny_config_version = 1.1.2 #26b2bbfb06 -thimble_permissions_version=b1e992cba7 +thimble_permissions_version=0.0.8.1 offline_info_version=1a3a7fc98b diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 1f57477..09e3367 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -186,7 +186,7 @@ public CompoundTag toTag() { { tag.put("settings", settings.toTag()); tag.put("permissions", permissionManager.toNBT()); - if (claimBlockOwner != null) tag.putUuidNew("top_owner", claimBlockOwner); + if (claimBlockOwner != null) tag.putUuidOld("top_owner", claimBlockOwner); } { CompoundTag meta = new CompoundTag(); @@ -226,7 +226,7 @@ public void fromTag(CompoundTag tag) { this.settings = new ClaimSettings(tag.getCompound("settings")); permissionManager = new PermissionManager(); permissionManager.fromNBT(tag.getCompound("permissions")); - if (tag.containsUuidNew("top_owner")) claimBlockOwner = tag.getUuidNew("top_owner"); + if (tag.containsUuidOld("top_owner")) claimBlockOwner = tag.getUuidOld("top_owner"); } { CompoundTag meta = tag.getCompound("meta"); From 1b74684afb5bbffb2773aae03ab40d892db41c7c Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Thu, 12 Mar 2020 00:22:56 +0330 Subject: [PATCH 08/85] Update build.gradle --- build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 8cd0d08..169fca9 100644 --- a/build.gradle +++ b/build.gradle @@ -23,14 +23,13 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modCompile "net.fabricmc:fabric-loader:${project.loader_version}" - modImplementation "com.github.OnBlock:Thimble-Permissions:${project.thimble_permissions_version}" //modImplementation "com.github.giantnuker:TinyConfig:${project.tiny_config_version}" //modImplementation /*"io.github.indicode.fabric:thimble-permissions:0.0.9"//*/"com.github.giantnuker:Thimble-Permissions:${project.thimble_permissions_version}" //modImplementation "com.github.giantnuker:OfflineInfo:${project.offline_info_version}" //include "com.github.giantnuker:TinyConfig:${project.tiny_config_version}" implementation 'org.jetbrains:annotations:15.0' - include "com.github.indi-code:Thimble-Permissions:${project.thimble_permissions_version}" + modImplementation "com.github.OnBlock:Thimble-Permissions:${project.thimble_permissions_version}" // Fabric API. This is technically optional, but you probably want it anyway. //modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" From 056892b45d3651d9f18633dfb48277dd16872f76 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Thu, 12 Mar 2020 23:29:58 +0330 Subject: [PATCH 09/85] Fixed ExplosionMixin --- gradle.properties | 6 +++--- .../github/indicode/fabric/itsmine/ClaimCommand.java | 12 +++++------- .../fabric/itsmine/mixin/ExplosionMixin.java | 6 ++++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gradle.properties b/gradle.properties index 413cbc7..9e083bf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,14 +8,14 @@ yarn_mappings=20w11a+build.1 loader_version=0.7.8+build.187 # Mod Properties - mod_version = 1.5-20w11a + mod_version = 1.51-20W11A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api #fabric_version=0.3.2+build.218-1.14 -tiny_config_version = 1.1.2 #26b2bbfb06 thimble_permissions_version=0.0.8.1 -offline_info_version=1a3a7fc98b +tiny_config_version = 1.1.2 +#offline_info_version=1a3a7fc98b diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 2dbb7a7..96aa22a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -158,14 +158,12 @@ private static void registerHelp(LiteralArgumentBuilder bui public static void register(CommandDispatcher dispatcher) { LiteralArgumentBuilder command = CommandManager.literal("claim") .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help get_started %page%")); - { - LiteralArgumentBuilder help = CommandManager.literal("help"); - help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); + LiteralArgumentBuilder help = CommandManager.literal("help"); + help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); - registerHelp(help, "get_started", Messages.GET_STARTED, "Get Started"); - registerHelp(help, "commands", Messages.HELP, "Its Mine!"); - command.then(help); - } + registerHelp(help, "get_started", Messages.GET_STARTED, "Get Started"); + registerHelp(help, "commands", Messages.HELP, "Its Mine!"); + command.then(help); { LiteralArgumentBuilder create = CommandManager.literal("create"); RequiredArgumentBuilder name = CommandManager.argument("name", StringArgumentType.word()); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java index a4a55a3..7f4eabd 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java @@ -21,7 +21,8 @@ public class ExplosionMixin { private BlockState theyCallMeBedrock(World world, BlockPos blockPos_1) { Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, world.getDimension().getType()); if (claim != null && !world.isAir(blockPos_1)) { - if (!(Boolean) claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSIONS)) return Blocks.BEDROCK.getDefaultState(); + if (claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSIONS)) + return Blocks.BEDROCK.getDefaultState(); } return world.getBlockState(blockPos_1); } @@ -30,7 +31,8 @@ private boolean claimDeniesExplosion(Entity entity) { BlockPos blockPos_1 = entity.getSenseCenterPos(); Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, entity.world.getDimension().getType()); if (claim != null) { - if (!(Boolean) claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSIONS)) return true; + if (claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSIONS)) + return false; } return entity.isImmuneToExplosion(); } From 8dcd14fe5571576238afb03747977fa8a34720eb Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Fri, 13 Mar 2020 00:30:46 +0330 Subject: [PATCH 10/85] Fixed the IntegratedServerMixin --- gradle.properties | 2 +- .../github/indicode/fabric/itsmine/Claim.java | 2 +- .../indicode/fabric/itsmine/Messages.java | 2 ++ .../fabric/itsmine/mixin/EntityMixin.java | 7 ++++--- .../fabric/itsmine/mixin/FluidMixin.java | 8 ++++---- .../itsmine/mixin/IntegratedServerMixin.java | 7 ++++--- .../fabric/itsmine/mixin/LavaMixin.java | 19 +++++++++++-------- .../itsmine/mixin/MinecraftServerMixin.java | 4 +++- .../itsmine/mixin/PlayerEntityMixin.java | 7 ------- .../ServerPlayerInteractionManagerMixin.java | 2 +- .../itsmine/mixin/ServerWorldMixin.java | 6 ++++-- 11 files changed, 35 insertions(+), 31 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9e083bf..c7036a8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=20w11a+build.1 loader_version=0.7.8+build.187 # Mod Properties - mod_version = 1.51-20W11A + mod_version = 1.6-20W11A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 09e3367..6de1701 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -475,7 +475,7 @@ public enum Setting { MOB_SPAWNING("mob_spawn", "Natural mob spawning", true), // KEEP_INVENTORY("keep_inventory", "Keep Inventory", true), // TELEPORT("teleport", "Global Teleport Access", true), - ENTER_SOUND("enter_sound", "Enter Sound", true); + ENTER_SOUND("enter_sound", "Enter Sound", false); String id, name; boolean defaultValue; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 78f65ba..3af447c 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -27,6 +27,8 @@ public class Messages { public static final Text MSG_INTERACT_ENTITY = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_interact_entity)).formatted(Formatting.RED)); + public static final Text MSG_INTERACT_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_interact_block)).formatted(Formatting.RED)); + public static final Text MSG_DAMAGE_ENTITY = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_attack_entity)).formatted(Formatting.RED)); public static final Text[] GET_STARTED = new Text[]{ diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index 26ae5ab..b6b558b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -74,15 +74,16 @@ private String getFormattedEventMessage(PlayerEntity player, Claim claim, boolea public void doTickActions(CallbackInfo ci) { if (!world.isClient && (Object)this instanceof PlayerEntity) { PlayerEntity player = (PlayerEntity) (Object)this; - if (player.getSenseCenterPos() == null) return; + if (player.getSenseCenterPos() == null) + return; boolean old = player.abilities.allowFlying; Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.world.dimension.getType()); if (player instanceof ServerPlayerEntity) { - if (player.abilities.allowFlying && ((claim == null || !claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) || !claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT)) && Functions.isClaimFlying(player.getGameProfile().getId()))) { + if (player.abilities.allowFlying && !player.isSpectator() && ((claim == null || !claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) || !claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT)) && Functions.isClaimFlying(player.getGameProfile().getId()))) { player.abilities.allowFlying = false; player.abilities.flying = false; Functions.setClaimFlying(player.getGameProfile().getId(), false); - } else if (!player.abilities.allowFlying && claim != null && claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) && claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT) && Functions.canClaimFly((ServerPlayerEntity) player)) { + } else if (!player.abilities.allowFlying && !player.isSpectator() && claim != null && claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) && claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT) && Functions.canClaimFly((ServerPlayerEntity) player)) { player.abilities.allowFlying = true; Functions.setClaimFlying(player.getGameProfile().getId(), true); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java index d7e54f3..85ff82a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java @@ -26,13 +26,13 @@ private void dontFlow(IWorld world, BlockPos newPos, BlockState blockState_1, Di Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!(Boolean) newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); } else if (newClaim == null) { - if (!(Boolean) oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); } else { - if (!(Boolean) oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || - !(Boolean) newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || + !newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); } } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java index 8b47ba8..1aced76 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java @@ -2,6 +2,7 @@ import com.google.gson.JsonElement; import io.github.indicode.fabric.itsmine.ClaimManager; +import net.minecraft.class_4952; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtIo; import net.minecraft.server.MinecraftServer; @@ -23,9 +24,9 @@ @Mixin(IntegratedServer.class) public class IntegratedServerMixin { @Inject(method = "loadWorld", at = @At("RETURN")) - private void loadClaims(String string_1, String string_2, long long_1, LevelGeneratorType levelGeneratorType_1, JsonElement jsonElement_1, CallbackInfo ci) { - File claims = new File(((MinecraftServer)(Object)this).getLevelStorage().getSavesDirectory() + "/" + string_1 + "/claims.dat"); - File claims_old = new File(((MinecraftServer)(Object)this).getLevelStorage().getSavesDirectory() + "/" + string_1 + "/claims.dat_old"); + private void loadClaims(String name, String serverName, long seed, class_4952 arg, CallbackInfo ci) { + File claims = new File(((MinecraftServer)(Object)this).getLevelStorage().getSavesDirectory() + "/" + name + "/claims.dat"); + File claims_old = new File(((MinecraftServer)(Object)this).getLevelStorage().getSavesDirectory() + "/" + name + "/claims.dat_old"); ClaimManager.INSTANCE = new ClaimManager(); if (!claims.exists()) { if (claims_old.exists()) {} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java index 9abcaa1..6abae3b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java @@ -29,13 +29,13 @@ private void dontFlow(IWorld world, BlockPos newPos, BlockState blockState_1, Di Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!(Boolean) newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); } else if (newClaim == null) { - if (!(Boolean) oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); } else { - if (!(Boolean) oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || - !(Boolean) newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || + !newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); } } } @@ -45,13 +45,16 @@ public boolean neverGonnaBurnMeUp(World world, BlockPos newPos, BlockState block Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!(Boolean) newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) return false; + if (!newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) + return false; } else if (newClaim == null) { - if (!(Boolean) oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) return false; + if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) + return false; } else { - if (!(Boolean) oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || - !(Boolean) newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) return false; + if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || + !newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) + return false; } } return world.setBlockState(newPos, blockState_1); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java index 498823b..35f83d9 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java @@ -8,6 +8,7 @@ import net.minecraft.nbt.NbtIo; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.LevelGeneratorType; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -45,11 +46,12 @@ private void loadClaims(String name, String serverName, long seed, class_4952 ar ClaimManager.INSTANCE.fromNBT(NbtIo.readCompressed(new FileInputStream(claims_old))); } catch (IOException e2) { throw new RuntimeException("Could not load claims.dat_old - Crashing server to save data. Remove or fix claims.dat or claims.dat_old to continue"); - } } } } + + @Final @Shadow private File gameDir; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java index c8da47a..bac17dc 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java @@ -8,21 +8,14 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.text.LiteralText; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Formatting; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; /** * @author Indigo Amann diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index f32639d..63b085a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -54,7 +54,7 @@ public ActionResult activateIfPossible(BlockState state, World world, PlayerEnti DoubleBlockHalf half = state.get(DoorBlock.HALF); ((ServerPlayerEntity) playerEntity_1).networkHandler.sendPacket(new BlockUpdateS2CPacket(world, half == DoubleBlockHalf.LOWER ? pos.up() : pos.down(1))); } - //playerEntity_1.sendMessage(new LiteralText("").append(new LiteralText("You are in a claim that does not allow you to use that").formatted(Formatting.RED)).append(new LiteralText("(Use /claim show to see an outline)").formatted(Formatting.YELLOW))); + playerEntity_1.sendMessage(Messages.MSG_INTERACT_BLOCK); return ActionResult.FAIL; } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java index ebad451..ab48936 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java @@ -1,8 +1,10 @@ package io.github.indicode.fabric.itsmine.mixin; +import com.sun.org.apache.xpath.internal.operations.Bool; import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Functions; +import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.Packet; import net.minecraft.server.PlayerManager; @@ -23,12 +25,12 @@ @Mixin(ServerWorld.class) public abstract class ServerWorldMixin { @Inject(method = "canPlayerModifyAt", at = @At("HEAD"), cancellable = true) - private void canMine(PlayerEntity player, BlockPos blockPos_1, CallbackInfoReturnable ci) { + private void canMine(PlayerEntity player, BlockPos blockPos_1, CallbackInfoReturnable ci) { if (player.world.isClient()) return; Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, player.getEntityWorld().getDimension().getType()); if (claim != null) { if (!claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.SPAWN_PROTECT)) { - player.sendMessage(new LiteralText("").append(new LiteralText("You can't use that here. This claim is spawn-protected").formatted(Formatting.RED)).append(new LiteralText("(Use /claim show to see an outline)").formatted(Formatting.YELLOW))); + player.sendMessage(Messages.NO_PERMISSION); ci.setReturnValue(false); } } From b3ee868d20f4bf79d7402d78a8f6b9ffe11868b1 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Fri, 13 Mar 2020 01:26:35 +0330 Subject: [PATCH 11/85] Added Setting: explosion_damage --- .../github/indicode/fabric/itsmine/Claim.java | 41 +++- .../indicode/fabric/itsmine/ClaimCommand.java | 219 ++++++++++-------- .../indicode/fabric/itsmine/ItsMine.java | 4 + .../fabric/itsmine/mixin/ExplosionMixin.java | 6 +- 4 files changed, 158 insertions(+), 112 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 6de1701..343165f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -1,22 +1,15 @@ package io.github.indicode.fabric.itsmine; import blue.endless.jankson.annotation.Nullable; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.arguments.BoolArgumentType; -import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.context.CommandContext; import io.github.indicode.fabric.permissions.Thimble; import net.minecraft.nbt.*; -import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.world.dimension.DimensionType; import java.util.*; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.BiConsumer; -import java.util.function.Consumer; /** * @author Indigo Amann @@ -467,7 +460,8 @@ public CompoundTag toNBT() { public static class ClaimSettings{ public enum Setting { FLIGHT_ALLOWED("flight_allowed", "Flying Enabled", true), - EXPLOSIONS("explosion_destruction", "Explosions Destroy Blocks", false), + EXPLOSION_DESTRUCTION("explosion_destruction", "Explosions Destroy Blocks", false), + EXPLOSION_DAMAGE("explosion_damage", "Expolsions Damage Entities", false), FLUID_CROSSES_BORDERS("fluid_crosses_borders", "Fluid Crosses Borders", false), FIRE_CROSSES_BORDERS("fire_crosses_borders", "Fire Crosses Borders", false), PISTON_FROM_INSIDE("pistons_inside_border", "Pistons Cross border from Inside", true), @@ -538,4 +532,33 @@ public static Event getById(String id) { return null; } } + + public enum HelpBook { + GET_STARTED("getStarted", Messages.GET_STARTED, "Get Started"), + COMMAND("commands", Messages.HELP, "Claim Commands"); + + String id; + String title; + Text[] texts; + HelpBook(String id, Text[] texts, String title) { + this.id = id; + this.title = title; + this.texts = texts; + } + + public String getCommand() { + return "/claim help " + this.id + " %page%"; + } + + @Nullable + public static HelpBook getById(String id) { + for (HelpBook value : values()) { + if (value.id.equalsIgnoreCase(id)) { + return value; + } + } + + return null; + } + } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 96aa22a..7831aa5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -25,7 +25,6 @@ import net.minecraft.command.arguments.GameProfileArgumentType; import net.minecraft.command.arguments.PosArgument; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; -import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandSource; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; @@ -40,6 +39,8 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; +import static net.minecraft.server.command.CommandManager.*; + /** * @author Indigo Amann */ @@ -59,7 +60,7 @@ private static void validateClaim(Claim claim) throws CommandSyntaxException { } private static RequiredArgumentBuilder getClaimArgument() { - return CommandManager.argument("claim", StringArgumentType.word()).suggests(CLAIM_PROVIDER); + return argument("claim", StringArgumentType.word()).suggests(CLAIM_PROVIDER); } private static Predicate perm(String str) { @@ -146,9 +147,9 @@ private static Predicate perm(String str, int op) { }; private static void registerHelp(LiteralArgumentBuilder builder, String id, Text[] texts, String title) { - LiteralArgumentBuilder argumentBuilder = CommandManager.literal(id) + LiteralArgumentBuilder argumentBuilder = literal(id) .executes((context) -> sendPage(context.getSource(), texts, 1, title, "/claim help " + id + " %page%")); - RequiredArgumentBuilder pageArgument = CommandManager.argument("page", IntegerArgumentType.integer(1, texts.length)) + RequiredArgumentBuilder pageArgument = argument("page", IntegerArgumentType.integer(1, texts.length)) .executes((context) -> sendPage(context.getSource(), texts, IntegerArgumentType.getInteger(context, "page"), title, "/claim help " + id + " %page%")); argumentBuilder.then(pageArgument); @@ -156,17 +157,35 @@ private static void registerHelp(LiteralArgumentBuilder bui } public static void register(CommandDispatcher dispatcher) { - LiteralArgumentBuilder command = CommandManager.literal("claim") - .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help get_started %page%")); - LiteralArgumentBuilder help = CommandManager.literal("help"); - help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); - - registerHelp(help, "get_started", Messages.GET_STARTED, "Get Started"); - registerHelp(help, "commands", Messages.HELP, "Its Mine!"); - command.then(help); + LiteralArgumentBuilder command = literal("claim") + .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); + { - LiteralArgumentBuilder create = CommandManager.literal("create"); - RequiredArgumentBuilder name = CommandManager.argument("name", StringArgumentType.word()); + LiteralArgumentBuilder help = literal("help"); + help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); + + RequiredArgumentBuilder id = argument("id", StringArgumentType.word()); + RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); + + page.executes((context) -> { + Claim.HelpBook book = Claim.HelpBook.getById(StringArgumentType.getString(context, "id")); + if (book == null) { + context.getSource().sendError(new LiteralText("Invalid Book!")); + return -1; + } + int p = IntegerArgumentType.getInteger(context, "page"); + + if (p > book.texts.length) p = 1; + return sendPage(context.getSource(), book.texts, p, book.title, book.getCommand()); + }); + + id.then(page); + help.then(id); + command.then(help); + } + { + LiteralArgumentBuilder create = literal("create"); + RequiredArgumentBuilder name = argument("name", StringArgumentType.word()); name.executes(context -> { ServerPlayerEntity player = context.getSource().getPlayer(); @@ -186,8 +205,8 @@ public static void register(CommandDispatcher dispatcher) { return 0; }); - ArgumentBuilder min = CommandManager.argument("min", BlockPosArgumentType.blockPos()); - RequiredArgumentBuilder max = CommandManager.argument("max", BlockPosArgumentType.blockPos()); + ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); + RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); max.executes(context -> createClaim( StringArgumentType.getString(context, "name"), context.getSource(), @@ -202,17 +221,17 @@ public static void register(CommandDispatcher dispatcher) { command.then(create); } { - LiteralArgumentBuilder rename = CommandManager.literal("rename"); - RequiredArgumentBuilder claimArgument = CommandManager.argument("claim", StringArgumentType.word()) + LiteralArgumentBuilder rename = literal("rename"); + RequiredArgumentBuilder claimArgument = argument("claim", StringArgumentType.word()) .suggests(CLAIM_PROVIDER); - RequiredArgumentBuilder nameArgument = CommandManager.argument("name", StringArgumentType.word()); + RequiredArgumentBuilder nameArgument = argument("name", StringArgumentType.word()); nameArgument.executes((context) -> rename(context, false)); claimArgument.then(nameArgument); rename.then(claimArgument); command.then(rename); } { - LiteralArgumentBuilder trusted = CommandManager.literal("trusted"); + LiteralArgumentBuilder trusted = literal("trusted"); RequiredArgumentBuilder claimArgument = getClaimArgument(); trusted.executes((context)-> { ServerPlayerEntity player = context.getSource().getPlayer(); @@ -236,7 +255,7 @@ public static void register(CommandDispatcher dispatcher) { command.then(trusted); } { - LiteralArgumentBuilder stick = CommandManager.literal("stick"); + LiteralArgumentBuilder stick = literal("stick"); stick.executes(context -> { Pair posPair = ClaimManager.INSTANCE.stickPositions.get(context.getSource().getPlayer()); context.getSource().sendFeedback(new LiteralText(posPair == null ? "You can now use a stick to create claims. Run this command again to disable" : "Claim stick disabled. Run this command again to enable").formatted(Formatting.DARK_PURPLE), false); @@ -250,22 +269,22 @@ public static void register(CommandDispatcher dispatcher) { command.then(stick); } { - LiteralArgumentBuilder show = CommandManager.literal("show"); + LiteralArgumentBuilder show = literal("show"); show.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getSenseCenterPos(), context.getSource().getWorld().dimension.getType()), false)); - RequiredArgumentBuilder name = CommandManager.argument("name", StringArgumentType.word()); + RequiredArgumentBuilder name = argument("name", StringArgumentType.word()); name.suggests(CLAIM_PROVIDER); name.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "name")), false)); show.then(name); command.then(show); } { - LiteralArgumentBuilder hide = CommandManager.literal("hide"); + LiteralArgumentBuilder hide = literal("hide"); hide.executes(context -> showClaim(context.getSource(), null, true)); command.then(hide); } { - LiteralArgumentBuilder check = CommandManager.literal("blocks"); - RequiredArgumentBuilder other = CommandManager.argument("player", EntityArgumentType.player()); + LiteralArgumentBuilder check = literal("blocks"); + RequiredArgumentBuilder other = argument("player", EntityArgumentType.player()); other.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.checkothers", 2)); other.executes(ctx -> checkPlayer(ctx.getSource(), EntityArgumentType.getPlayer(ctx, "player").getGameProfile().getId())); check.then(other); @@ -273,10 +292,10 @@ public static void register(CommandDispatcher dispatcher) { command.then(check); } { - LiteralArgumentBuilder delete = CommandManager.literal("remove"); + LiteralArgumentBuilder delete = literal("remove"); RequiredArgumentBuilder claim = getClaimArgument(); claim.suggests(CLAIM_PROVIDER); - LiteralArgumentBuilder confirm = CommandManager.literal("confirm"); + LiteralArgumentBuilder confirm = literal("confirm"); confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); claim.then(confirm); @@ -286,9 +305,9 @@ public static void register(CommandDispatcher dispatcher) { } { { - LiteralArgumentBuilder expand = CommandManager.literal("expand"); - RequiredArgumentBuilder amount = CommandManager.argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = CommandManager.argument("direction", StringArgumentType.word()); + LiteralArgumentBuilder expand = literal("expand"); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); direction.suggests(DIRECTION_SUGGESTION_BUILDER); direction.executes(context -> expand( @@ -312,9 +331,9 @@ public static void register(CommandDispatcher dispatcher) { command.then(expand); } { - LiteralArgumentBuilder shrink = CommandManager.literal("shrink"); - RequiredArgumentBuilder amount = CommandManager.argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = CommandManager.argument("direction", StringArgumentType.word()); + LiteralArgumentBuilder shrink = literal("shrink"); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); direction.suggests(DIRECTION_SUGGESTION_BUILDER); direction.executes(context -> expand( @@ -339,9 +358,9 @@ public static void register(CommandDispatcher dispatcher) { } } { - LiteralArgumentBuilder delete = CommandManager.literal("remove"); + LiteralArgumentBuilder delete = literal("remove"); RequiredArgumentBuilder claim = getClaimArgument(); - LiteralArgumentBuilder confirm = CommandManager.literal("confirm"); + LiteralArgumentBuilder confirm = literal("confirm"); confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); claim.then(confirm); @@ -350,10 +369,10 @@ public static void register(CommandDispatcher dispatcher) { command.then(delete); } { - LiteralArgumentBuilder transfer = CommandManager.literal("transfer"); - RequiredArgumentBuilder claim = CommandManager.argument("claim", StringArgumentType.word()).suggests(CLAIM_PROVIDER); - RequiredArgumentBuilder player = CommandManager.argument("player", EntityArgumentType.player()); - LiteralArgumentBuilder confirm = CommandManager.literal("confirm"); + LiteralArgumentBuilder transfer = literal("transfer"); + RequiredArgumentBuilder claim = argument("claim", StringArgumentType.word()).suggests(CLAIM_PROVIDER); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); + LiteralArgumentBuilder confirm = literal("confirm"); confirm.executes(context -> { final String string = "-accept-"; ServerPlayerEntity p = EntityArgumentType.getPlayer(context, "player"); @@ -379,7 +398,7 @@ public static void register(CommandDispatcher dispatcher) { command.then(transfer); } { - LiteralArgumentBuilder info = CommandManager.literal("info"); + LiteralArgumentBuilder info = literal("info"); RequiredArgumentBuilder claim = getClaimArgument(); info.executes(context -> info( context.getSource(), @@ -393,8 +412,8 @@ public static void register(CommandDispatcher dispatcher) { command.then(info); } { - LiteralArgumentBuilder list = CommandManager.literal("list"); - RequiredArgumentBuilder player = CommandManager.argument("player", StringArgumentType.word()); + LiteralArgumentBuilder list = literal("list"); + RequiredArgumentBuilder player = argument("player", StringArgumentType.word()); player.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.check_others", 2)); player.suggests(PLAYERS_PROVIDER); list.executes(context -> list(context.getSource(), null)); @@ -403,8 +422,8 @@ public static void register(CommandDispatcher dispatcher) { command.then(list); } { - LiteralArgumentBuilder trust = CommandManager.literal("trust"); - RequiredArgumentBuilder playerArgument = CommandManager.argument("player", EntityArgumentType.player()); + LiteralArgumentBuilder trust = literal("trust"); + RequiredArgumentBuilder playerArgument = argument("player", EntityArgumentType.player()); RequiredArgumentBuilder claimArgument = getClaimArgument(); playerArgument.executes((context -> executeTrust(context, EntityArgumentType.getPlayer(context, "player"), true, null))); @@ -415,8 +434,8 @@ public static void register(CommandDispatcher dispatcher) { command.then(trust); } { - LiteralArgumentBuilder distrust = CommandManager.literal("distrust"); - RequiredArgumentBuilder playerArgument = CommandManager.argument("player", EntityArgumentType.player()); + LiteralArgumentBuilder distrust = literal("distrust"); + RequiredArgumentBuilder playerArgument = argument("player", EntityArgumentType.player()); RequiredArgumentBuilder claimArgument = getClaimArgument(); playerArgument.executes((context -> executeTrust(context, EntityArgumentType.getPlayer(context, "player"), false, null))); @@ -430,13 +449,13 @@ public static void register(CommandDispatcher dispatcher) { createExceptionCommand(command, false); { - LiteralArgumentBuilder admin = CommandManager.literal("admin"); + LiteralArgumentBuilder admin = literal("admin"); admin.requires(PERMISSION_CHECK_ADMIN); { - LiteralArgumentBuilder add = CommandManager.literal("addBlocks"); + LiteralArgumentBuilder add = literal("addBlocks"); add.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify_balance", 2)); - RequiredArgumentBuilder player = CommandManager.argument("player", EntityArgumentType.players()); - RequiredArgumentBuilder amount = CommandManager.argument("amount", IntegerArgumentType.integer()); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); + RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); amount.executes(context -> { ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); context.getSource().sendFeedback(new LiteralText("Gave " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); @@ -447,8 +466,8 @@ public static void register(CommandDispatcher dispatcher) { admin.then(add); } { - LiteralArgumentBuilder set = CommandManager.literal("setOwner"); - RequiredArgumentBuilder newOwner = CommandManager.argument("newOwner", GameProfileArgumentType.gameProfile()); + LiteralArgumentBuilder set = literal("setOwner"); + RequiredArgumentBuilder newOwner = argument("newOwner", GameProfileArgumentType.gameProfile()); RequiredArgumentBuilder claimArgument = getClaimArgument(); newOwner.executes((context) -> { @@ -488,8 +507,8 @@ public static void register(CommandDispatcher dispatcher) { admin.then(set); } { - LiteralArgumentBuilder set = CommandManager.literal("setOwnerName"); - RequiredArgumentBuilder nameArgument = CommandManager.argument("newName", StringArgumentType.word()); + LiteralArgumentBuilder set = literal("setOwnerName"); + RequiredArgumentBuilder nameArgument = argument("newName", StringArgumentType.word()); RequiredArgumentBuilder claimArgument = getClaimArgument(); nameArgument.executes((context) -> { @@ -515,20 +534,20 @@ public static void register(CommandDispatcher dispatcher) { admin.then(set); } { - LiteralArgumentBuilder rename = CommandManager.literal("rename"); - RequiredArgumentBuilder claimArgument = CommandManager.argument("claim", StringArgumentType.word()) + LiteralArgumentBuilder rename = literal("rename"); + RequiredArgumentBuilder claimArgument = argument("claim", StringArgumentType.word()) .suggests(CLAIM_PROVIDER); - RequiredArgumentBuilder nameArgument = CommandManager.argument("name", StringArgumentType.word()); + RequiredArgumentBuilder nameArgument = argument("name", StringArgumentType.word()); nameArgument.executes((context) -> rename(context, true)); claimArgument.then(nameArgument); rename.then(claimArgument); admin.then(rename); } { - LiteralArgumentBuilder remove = CommandManager.literal("removeBlocks"); + LiteralArgumentBuilder remove = literal("removeBlocks"); remove.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify_balance", 2)); - RequiredArgumentBuilder player = CommandManager.argument("player", EntityArgumentType.players()); - RequiredArgumentBuilder amount = CommandManager.argument("amount", IntegerArgumentType.integer()); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); + RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); amount.executes(context -> { ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), -IntegerArgumentType.getInteger(context, "amount")); context.getSource().sendFeedback(new LiteralText("Took " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); @@ -539,10 +558,10 @@ public static void register(CommandDispatcher dispatcher) { admin.then(remove); } { - LiteralArgumentBuilder set = CommandManager.literal("setBlocks"); + LiteralArgumentBuilder set = literal("setBlocks"); set.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify_balance", 2)); - RequiredArgumentBuilder player = CommandManager.argument("player", EntityArgumentType.players()); - RequiredArgumentBuilder amount = CommandManager.argument("amount", IntegerArgumentType.integer()); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); + RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); amount.executes(context -> { ClaimManager.INSTANCE.setClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); context.getSource().sendFeedback(new LiteralText("Set claim block amount to " + IntegerArgumentType.getInteger(context, "amount")).formatted(Formatting.GREEN), true); @@ -553,10 +572,10 @@ public static void register(CommandDispatcher dispatcher) { admin.then(set); } { - LiteralArgumentBuilder delete = CommandManager.literal("remove"); + LiteralArgumentBuilder delete = literal("remove"); delete.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify", 4)); RequiredArgumentBuilder claim = getClaimArgument(); - LiteralArgumentBuilder confirm = CommandManager.literal("confirm"); + LiteralArgumentBuilder confirm = literal("confirm"); confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), true)); claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), true)); claim.then(confirm); @@ -565,12 +584,12 @@ public static void register(CommandDispatcher dispatcher) { admin.then(delete); } { - LiteralArgumentBuilder create = CommandManager.literal("create"); + LiteralArgumentBuilder create = literal("create"); create.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.infinite_claim", 4)); - ArgumentBuilder name = CommandManager.argument("name", StringArgumentType.word()); - ArgumentBuilder customOwner = CommandManager.argument("customOwnerName", StringArgumentType.word()); - ArgumentBuilder min = CommandManager.argument("min", BlockPosArgumentType.blockPos()); - RequiredArgumentBuilder max = CommandManager.argument("max", BlockPosArgumentType.blockPos()); + ArgumentBuilder name = argument("name", StringArgumentType.word()); + ArgumentBuilder customOwner = argument("customOwnerName", StringArgumentType.word()); + ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); + RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); max.executes(context -> createClaim( StringArgumentType.getString(context, "name"), context.getSource(), @@ -620,7 +639,7 @@ public static void register(CommandDispatcher dispatcher) { admin.then(create); } { - LiteralArgumentBuilder ignore = CommandManager.literal("ignoreClaims"); + LiteralArgumentBuilder ignore = literal("ignoreClaims"); ignore.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.ignore_claims", 4)); ignore.executes(context -> { UUID id = context.getSource().getPlayer().getGameProfile().getId(); @@ -634,10 +653,10 @@ public static void register(CommandDispatcher dispatcher) { } { { - LiteralArgumentBuilder expand = CommandManager.literal("expand"); + LiteralArgumentBuilder expand = literal("expand"); expand.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.infinite_claim", 4) && Thimble.hasPermissionOrOp(source, "itsmine.admin.modify", 4)); - RequiredArgumentBuilder amount = CommandManager.argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = CommandManager.argument("direction", StringArgumentType.word()); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); direction.suggests(DIRECTION_SUGGESTION_BUILDER); direction.executes(context -> expand( @@ -661,10 +680,10 @@ public static void register(CommandDispatcher dispatcher) { admin.then(expand); } { - LiteralArgumentBuilder shrink = CommandManager.literal("shrink"); + LiteralArgumentBuilder shrink = literal("shrink"); shrink.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.infinite_claim", 4) && Thimble.hasPermissionOrOp(source, "itsmine.admin.modify", 4)); - RequiredArgumentBuilder amount = CommandManager.argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = CommandManager.argument("direction", StringArgumentType.word()); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); direction.suggests(DIRECTION_SUGGESTION_BUILDER); direction.executes(context -> expand( @@ -748,14 +767,14 @@ private static int sendPage(ServerCommandSource source, Text[] text, int page, S private static void createExceptionCommand(LiteralArgumentBuilder command, boolean admin) { { - LiteralArgumentBuilder settings = CommandManager.literal("settings"); + LiteralArgumentBuilder settings = literal("settings"); RequiredArgumentBuilder claim = getClaimArgument(); if (!admin) { settings.executes((context) -> { ServerPlayerEntity player = context.getSource().getPlayer(); Claim claim1 = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.dimension); - if (claim == null) { + if (claim1 == null) { context.getSource().sendError(Messages.INVALID_CLAIM); return -1; } @@ -772,8 +791,8 @@ private static void createExceptionCommand(LiteralArgumentBuilder id = CommandManager.argument("setting", StringArgumentType.word()).suggests(SETTINGS_PROVIDER); - RequiredArgumentBuilder set = CommandManager.argument("set", BoolArgumentType.bool()); + RequiredArgumentBuilder id = argument("setting", StringArgumentType.word()).suggests(SETTINGS_PROVIDER); + RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); id.executes((context) -> executeSetting(context.getSource(), StringArgumentType.getString(context, "setting"), StringArgumentType.getString(context, "claim"), true, false, admin)); set.executes((context) -> executeSetting(context.getSource(), StringArgumentType.getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); @@ -784,7 +803,7 @@ private static void createExceptionCommand(LiteralArgumentBuilder exceptions = CommandManager.literal("permissions"); + LiteralArgumentBuilder exceptions = literal("permissions"); if (admin) exceptions.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify_permissions", 2)); RequiredArgumentBuilder claim = getClaimArgument(); if (!admin) { @@ -819,10 +838,10 @@ private static void createExceptionCommand(LiteralArgumentBuilder playerLiteral = CommandManager.literal("player"); + LiteralArgumentBuilder playerLiteral = literal("player"); { - RequiredArgumentBuilder player = CommandManager.argument("player", EntityArgumentType.player()); - LiteralArgumentBuilder remove = CommandManager.literal("remove"); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); + LiteralArgumentBuilder remove = literal("remove"); remove.executes(context -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { @@ -833,8 +852,8 @@ private static void createExceptionCommand(LiteralArgumentBuilder all = CommandManager.literal("*"); - RequiredArgumentBuilder allstate = CommandManager.argument("allow", BoolArgumentType.bool()); + LiteralArgumentBuilder all = literal("*"); + RequiredArgumentBuilder allstate = argument("allow", BoolArgumentType.bool()); allstate.executes(context -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); @@ -844,8 +863,8 @@ private static void createExceptionCommand(LiteralArgumentBuilder permNode = CommandManager.literal(value.id); - RequiredArgumentBuilder allow = CommandManager.argument("allow", BoolArgumentType.bool()); + LiteralArgumentBuilder permNode = literal(value.id); + RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); allow.executes(context -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { @@ -870,12 +889,12 @@ private static void createExceptionCommand(LiteralArgumentBuilder groupLiteral = CommandManager.literal("group"); + LiteralArgumentBuilder groupLiteral = literal("group"); groupLiteral.requires(sender -> Thimble.hasPermissionOrOp(sender, "itsmine.specify_groups", 2)); { - RequiredArgumentBuilder group = CommandManager.argument("group", StringArgumentType.word()); + RequiredArgumentBuilder group = argument("group", StringArgumentType.word()); group.suggests(PermissionCommand.SUGGESTIONS_BUILDER); - LiteralArgumentBuilder remove = CommandManager.literal("remove"); + LiteralArgumentBuilder remove = literal("remove"); remove.executes(context -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { @@ -888,8 +907,8 @@ private static void createExceptionCommand(LiteralArgumentBuilder permNode = CommandManager.literal(value.id); - RequiredArgumentBuilder allow = CommandManager.argument("allow", BoolArgumentType.bool()); + LiteralArgumentBuilder permNode = literal(value.id); + RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); allow.executes(context -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { @@ -917,11 +936,11 @@ private static void createExceptionCommand(LiteralArgumentBuilder message = CommandManager.literal("message"); + LiteralArgumentBuilder message = literal("message"); RequiredArgumentBuilder claimArgument = getClaimArgument(); - RequiredArgumentBuilder messageEvent = CommandManager.argument("messageEvent", StringArgumentType.word()) + RequiredArgumentBuilder messageEvent = argument("messageEvent", StringArgumentType.word()) .suggests(MESSAGE_EVENTS_PROVIDER); - RequiredArgumentBuilder messageArgument = CommandManager.argument("message", StringArgumentType.greedyString()) + RequiredArgumentBuilder messageArgument = argument("message", StringArgumentType.greedyString()) .suggests(EVENT_MESSAGE_PROVIDER); messageArgument.executes(context -> { @@ -1532,9 +1551,9 @@ private static int executeSetting(ServerCommandSource source, String input, @Nul Claim.ClaimSettings.Setting setting = Claim.ClaimSettings.Setting.byId(input); Claim.Permission permission = Claim.Permission.byId(input); - System.out.println(claim1); + System.out.println(setting); System.out.println(permission); - System.out.println(claimName); + System.out.println(claim1); if (setting != null && permission == null) return !isQuery ? setSetting(source, claim1, setting, value) : querySetting(source, claim1, setting); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java index 5ead88f..ed33340 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java @@ -3,6 +3,7 @@ import io.github.indicode.fabric.permissions.PermChangeBehavior; import io.github.indicode.fabric.permissions.Thimble; import net.fabricmc.api.ModInitializer; +import net.minecraft.SharedConstants; import net.minecraft.server.command.ServerCommandSource; import java.lang.reflect.InvocationTargetException; @@ -27,6 +28,9 @@ public void onInitialize() { map.registerPermission("itsmine.admin.modify_permissions", PermChangeBehavior.UPDATE_COMMAND_TREE); map.registerPermission("itsmine.admin.ignore_claims", PermChangeBehavior.UPDATE_COMMAND_TREE); }); + + //TODO: Remove + SharedConstants.isDevelopment = true; } public static String blocksToAreaString3d(int blocks) { int base = (int) Math.floor(Math.cbrt(blocks)); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java index 7f4eabd..4768171 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java @@ -21,7 +21,7 @@ public class ExplosionMixin { private BlockState theyCallMeBedrock(World world, BlockPos blockPos_1) { Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, world.getDimension().getType()); if (claim != null && !world.isAir(blockPos_1)) { - if (claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSIONS)) + if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) return Blocks.BEDROCK.getDefaultState(); } return world.getBlockState(blockPos_1); @@ -31,8 +31,8 @@ private boolean claimDeniesExplosion(Entity entity) { BlockPos blockPos_1 = entity.getSenseCenterPos(); Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, entity.world.getDimension().getType()); if (claim != null) { - if (claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSIONS)) - return false; + if (claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DAMAGE)) + return true; } return entity.isImmuneToExplosion(); } From 9e6929c4c0f3d5da59b0518744ab3d5b385a2b9c Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Fri, 13 Mar 2020 02:14:23 +0330 Subject: [PATCH 12/85] Added fire_damage setting --- .../github/indicode/fabric/itsmine/Claim.java | 7 ++--- .../indicode/fabric/itsmine/ClaimCommand.java | 8 ++---- .../itsmine/mixin/AbstractFireBlockMixin.java | 26 +++++++++++++++++++ src/main/resources/itsmine.mixins.json | 1 + 4 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 343165f..3d31995 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -460,14 +460,15 @@ public CompoundTag toNBT() { public static class ClaimSettings{ public enum Setting { FLIGHT_ALLOWED("flight_allowed", "Flying Enabled", true), - EXPLOSION_DESTRUCTION("explosion_destruction", "Explosions Destroy Blocks", false), - EXPLOSION_DAMAGE("explosion_damage", "Expolsions Damage Entities", false), + EXPLOSION_DESTRUCTION("explosion_destruction", "Explosion Destroys Blocks", false), + EXPLOSION_DAMAGE("explosion_damage", "Explosion Damages Entities", false), FLUID_CROSSES_BORDERS("fluid_crosses_borders", "Fluid Crosses Borders", false), FIRE_CROSSES_BORDERS("fire_crosses_borders", "Fire Crosses Borders", false), + FIRE_DAMAGE("fire_damage", "Fire Damages Entities", false), PISTON_FROM_INSIDE("pistons_inside_border", "Pistons Cross border from Inside", true), PISTON_FROM_OUTSIDE("pistons_outside_border", "Pistons Cross border from Outside", false), MOB_SPAWNING("mob_spawn", "Natural mob spawning", true), -// KEEP_INVENTORY("keep_inventory", "Keep Inventory", true), + KEEP_INVENTORY("keep_inventory", "Keep Inventory", true), // TELEPORT("teleport", "Global Teleport Access", true), ENTER_SOUND("enter_sound", "Enter Sound", false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 7831aa5..9d02722 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1551,15 +1551,11 @@ private static int executeSetting(ServerCommandSource source, String input, @Nul Claim.ClaimSettings.Setting setting = Claim.ClaimSettings.Setting.byId(input); Claim.Permission permission = Claim.Permission.byId(input); - System.out.println(setting); - System.out.println(permission); - System.out.println(claim1); - if (setting != null && permission == null) - return !isQuery ? setSetting(source, claim1, setting, value) : querySetting(source, claim1, setting); + return isQuery ? querySetting(source, claim1, setting) : setSetting(source, claim1, setting, value); if (setting == null && permission != null) - return !isQuery ? setPermission(source, claim1, permission, value) : queryPermission(source, claim1, permission); + return isQuery ? queryPermission(source, claim1, permission) : setPermission(source, claim1, permission, value); source.sendError(Messages.INVALID_SETTING); return -1; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java new file mode 100644 index 0000000..cfd878b --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java @@ -0,0 +1,26 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import net.minecraft.block.AbstractFireBlock; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(AbstractFireBlock.class) +public abstract class AbstractFireBlockMixin { + + @Redirect(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isFireImmune()Z")) + private boolean neverGonnaBurnYouUp(Entity entity) { + PlayerEntity player = (PlayerEntity) entity; + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.dimension); + if (claim != null && !claim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_DAMAGE)) { + return true; + } + + return entity.isFireImmune(); + } + +} diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index f1db7a0..83be44b 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -20,6 +20,7 @@ "ServerPlayerInteractionManagerMixin", "PlaceOnUseBlockMixin", "FireBlockMixin", + "AbstractFireBlockMixin", "SpawnRestrictionMixin", "OwnedProjectile", From f26611ee941057b5dabf5ee5170fd40693b30770 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 01:52:25 +0330 Subject: [PATCH 13/85] Removed the Spawn Protection permission --- .../github/indicode/fabric/itsmine/Claim.java | 10 ++-- .../indicode/fabric/itsmine/ClaimCommand.java | 55 ++++++++++++++++++- .../indicode/fabric/itsmine/Functions.java | 13 ----- .../fabric/itsmine/mixin/ExplosionMixin.java | 5 +- .../itsmine/mixin/PlaceOnUseBlockMixin.java | 16 +++--- .../itsmine/mixin/PlayerEntityMixin.java | 21 +++++++ .../ServerPlayerInteractionManagerMixin.java | 3 +- .../itsmine/mixin/ServerWorldMixin.java | 5 +- .../itsmine/mixin/SpawnRestrictionMixin.java | 2 +- 9 files changed, 92 insertions(+), 38 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 3d31995..efae9d1 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -242,7 +242,6 @@ public enum Permission { MODIFY_PERMISSIONS("modify_permissions", "Change Permissions"), //Normal MODIFY_PROPERTIES("modify_properties", "Modify Claim Properties"), - SPAWN_PROTECT("spawn_protect", "Spawn Protection Bypass"), BUILD("build", "Place/Break Blocks"), INTERACT_BLOCKS("interact_blocks", "Interact With Blocks"), USE_ITEMS_ON_BLOCKS("use_items_on_blocks", "Use Block Modifying items"), @@ -251,8 +250,7 @@ public enum Permission { INTERACT_DOORS("interact_doors", "Use Doors"), INTERACT_ENTITY("interact_with_entities", "Entity Interaction"), DAMAGE_ENTITY("damage_entities", "Hurt Entities"), - FLIGHT("flight", "Flight"), - TELEPORT("teleport", "Player Teleport Access"); + FLIGHT("flight", "Flight"); String id, name; Permission(String id, String name) { this.id = id; @@ -468,9 +466,9 @@ public enum Setting { PISTON_FROM_INSIDE("pistons_inside_border", "Pistons Cross border from Inside", true), PISTON_FROM_OUTSIDE("pistons_outside_border", "Pistons Cross border from Outside", false), MOB_SPAWNING("mob_spawn", "Natural mob spawning", true), - KEEP_INVENTORY("keep_inventory", "Keep Inventory", true), -// TELEPORT("teleport", "Global Teleport Access", true), - ENTER_SOUND("enter_sound", "Enter Sound", false); +// KEEP_INVENTORY("keep_inventory", "Keep Inventory", true), + ENTER_SOUND("enter_sound", "Enter Sound", false), + PUBLIC_CLAIM("public_claim", "Players see this claim", true); String id, name; boolean defaultValue; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 9d02722..318890d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -420,6 +420,20 @@ public static void register(CommandDispatcher dispatcher) { player.executes(context -> list(context.getSource(), StringArgumentType.getString(context, "player"))); list.then(player); command.then(list); + + LiteralArgumentBuilder claims = literal("claims") + .executes(context -> list(context.getSource(), null)) + .then(player); + dispatcher.register(claims); + } + { + LiteralArgumentBuilder listall = literal("listall"); + RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); + + listall.executes(context -> listAll(context.getSource(), 1)); + page.executes(context -> listAll(context.getSource(), IntegerArgumentType.getInteger(context, "page"))); + listall.then(page); + command.then(listall); } { LiteralArgumentBuilder trust = literal("trust"); @@ -1016,7 +1030,7 @@ private static int showClaim(ServerCommandSource source, Claim claim, boolean re return 0; } private static void silentHideShow(ServerPlayerEntity player, Claim claim, boolean hide, boolean updateStatus) { - BlockState block = hide ? null : Blocks.TARGET.getDefaultState(); + BlockState block = hide ? null : Blocks.SEA_LANTERN.getDefaultState(); int showRange = 5; int closeShowRange = 8; BlockPos pos = hide ? ((ClaimShower)player).getLastShowPos() : player.getSenseCenterPos(); @@ -1326,6 +1340,7 @@ private static int info(ServerCommandSource source, Claim claim) { source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); return 0; } + GameProfile owner = claim.claimBlockOwner == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); BlockPos size = claim.getSize(); @@ -1346,7 +1361,7 @@ private static int info(ServerCommandSource source, Claim claim) { Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); if (PERMISSION_CHECK_ADMIN.test(source)) { - String format = "/tp " + source.getName() + (Config.claims2d ? " %s ~ %s" : " %s %s %s"); + String format = "/execute in " + Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").toString() + " run tp " + source.getName() + (Config.claims2d ? " %s ~ %s" : " %s %s %s"); min.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, String.format(format, claim.min.getX(), Config.claims2d ? claim.min.getZ() : claim.min.getY(), claim.min.getZ())))); max.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, @@ -1389,10 +1404,13 @@ private static int list(ServerCommandSource source, String target) throws Comman return -1; } + Text text = new LiteralText("\n").append(new LiteralText("Claims: " + source.getName()).formatted(Formatting.GOLD)).append("\n "); boolean nextColor = false; for (Claim claim : claims) { Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { + if (claim.settings.getSetting(Claim.ClaimSettings.Setting.PUBLIC_CLAIM)) return; + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click for more Info").formatted(Formatting.GREEN))); style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); }); @@ -1404,6 +1422,37 @@ private static int list(ServerCommandSource source, String target) throws Comman source.sendFeedback(text.append("\n"), false); return 1; } + private static int listAll(ServerCommandSource source, int page) { + List claims = new ArrayList<>(); + ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> claims.add(claim)); + + if (claims.isEmpty()) { + source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); + return -1; + } + + List list = new ArrayList<>();; + for (int i = 0; i < claims.size(); i++) { + Claim claim = claims.get(i); + + Text cText = new LiteralText("").append(new LiteralText(i + ". ").formatted(Formatting.GOLD)) + .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" in ").formatted(Formatting.GRAY)) + .append(new LiteralText(Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").getPath()).formatted(Formatting.WHITE)); + + if (claim.settings.getSetting(Claim.ClaimSettings.Setting.PUBLIC_CLAIM)) { + cText.styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click for more Info").formatted(Formatting.GREEN))); + style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); + }); + } + + list.add(cText.append("\n")); + } + + Text[] texts = new Text[]{}; + texts = list.toArray(texts); + return sendPage(source, texts, page, "Claims", "/claim listall %page%"); + } private static int rename(CommandContext context, boolean admin) throws CommandSyntaxException { String name = StringArgumentType.getString(context, "claim"); String newName = StringArgumentType.getString(context, "name"); @@ -1578,7 +1627,7 @@ private static int executePermission(ServerCommandSource source, String input, @ return -1; } private static int querySetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting) { - boolean enabled = claim.settings.settings.get(setting); + boolean enabled = claim.settings.getSetting(setting); source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); return 1; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index e276625..3b26b50 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -11,11 +11,8 @@ import net.minecraft.network.packet.s2c.play.BlockActionS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.*; @@ -36,16 +33,6 @@ public static void doPistonUpdate(ServerWorld world, Packet packet) { public static boolean canPlayerActuallyModifyAt(ServerWorld world, PlayerEntity playerEntity_1, BlockPos blockPos_1) { return !world.getServer().isSpawnProtected(world, blockPos_1, playerEntity_1) && world.getWorldBorder().contains(blockPos_1); }; - public static boolean canModifyAtClaimed(PlayerEntity player, BlockPos blockPos_1) { - if (player.world.isClient()) return false; - Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, player.getEntityWorld().getDimension().getType()); - if (claim != null) { - if (!claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.SPAWN_PROTECT)) { - return false; - } - } - return true; - } public static boolean isBucketEmpty(BucketItem item) { return ((BucketItemMixin)item).getFluid() != Fluids.EMPTY; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java index 4768171..5d5a9d4 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java @@ -31,9 +31,10 @@ private boolean claimDeniesExplosion(Entity entity) { BlockPos blockPos_1 = entity.getSenseCenterPos(); Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, entity.world.getDimension().getType()); if (claim != null) { - if (claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DAMAGE)) - return true; + if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DAMAGE)) + return false; } + return entity.isImmuneToExplosion(); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java index dfda069..ac4cb1f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java @@ -5,6 +5,7 @@ import io.github.indicode.fabric.itsmine.Functions; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BucketItem; +import net.minecraft.item.Item; import net.minecraft.item.LilyPadItem; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; @@ -17,7 +18,11 @@ * @author Indigo Amann */ @Mixin({BucketItem.class, LilyPadItem.class}) -public class PlaceOnUseBlockMixin { +public class PlaceOnUseBlockMixin extends Item { + public PlaceOnUseBlockMixin(Settings settings) { + super(settings); + } + @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;canPlayerModifyAt(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;)Z")) public boolean canActuallyModify(World world, PlayerEntity playerEntity_1, BlockPos blockPos_1) { if (!(world instanceof ServerWorld)) return world.canPlayerModifyAt(playerEntity_1, blockPos_1); @@ -25,13 +30,10 @@ public boolean canActuallyModify(World world, PlayerEntity playerEntity_1, Block if (claim != null && claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.BUILD)) return Functions.canPlayerActuallyModifyAt((ServerWorld) world, playerEntity_1, blockPos_1); else { - if (Functions.canModifyAtClaimed(playerEntity_1, blockPos_1)) return true; - else { - if ((Object)this instanceof LilyPadItem){ - ((ServerWorld)world).getChunkManager().markForUpdate(blockPos_1); - } - return false; + if ((Object) this instanceof LilyPadItem){ + ((ServerWorld)world).getChunkManager().markForUpdate(blockPos_1); } + return false; } } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java index bac17dc..2777e09 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java @@ -8,10 +8,15 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.screen.PlayerScreenHandler; +import net.minecraft.text.LiteralText; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.GameRules; import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; @@ -22,6 +27,8 @@ */ @Mixin(PlayerEntity.class) public abstract class PlayerEntityMixin extends LivingEntity implements ClaimShower { + @Shadow @Final public PlayerScreenHandler playerScreenHandler; + protected PlayerEntityMixin(EntityType entityType_1, World world_1) { super(entityType_1, world_1); } @@ -53,6 +60,20 @@ public void hittingIsRude(Entity entity, CallbackInfo ci) { } } +// @Redirect(method = "dropInventory", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/GameRules;getBoolean(Lnet/minecraft/world/GameRules$RuleKey;)Z")) +// private boolean dontTakeMyThingies(GameRules gameRules, GameRules.RuleKey rule) { +// PlayerEntity playerEntity_1 = (PlayerEntity)(Object)this; +// Claim claim = ClaimManager.INSTANCE.getClaimAt(playerEntity_1.getSenseCenterPos(), playerEntity_1.world.getDimension().getType()); +// if (claim != null) { +// playerEntity_1.sendMessage(new LiteralText("keep_inventory: " + claim.settings.getSetting(Claim.ClaimSettings.Setting.KEEP_INVENTORY) + " server: " + gameRules.getBoolean(rule))); +// +// if (claim.settings.getSetting(Claim.ClaimSettings.Setting.KEEP_INVENTORY)) +// return true; +// } +// +// return gameRules.getBoolean(rule); +// } + @Override public void setLastShowPos(BlockPos pos) { lastShowPos = pos; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index 63b085a..d3366d3 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -54,7 +54,6 @@ public ActionResult activateIfPossible(BlockState state, World world, PlayerEnti DoubleBlockHalf half = state.get(DoorBlock.HALF); ((ServerPlayerEntity) playerEntity_1).networkHandler.sendPacket(new BlockUpdateS2CPacket(world, half == DoubleBlockHalf.LOWER ? pos.up() : pos.down(1))); } - playerEntity_1.sendMessage(Messages.MSG_INTERACT_BLOCK); return ActionResult.FAIL; } } @@ -72,7 +71,7 @@ public boolean allowItemUse(ItemStack stack, PlayerEntity playerEntity_1, World (stack.getItem() instanceof BlockItem && claim.hasPermission(uuid, Claim.Permission.BUILD)) || (stack.getItem() instanceof BucketItem && claim.hasPermission(uuid, Claim.Permission.BUILD)) ) return false; - playerEntity_1.sendMessage(Messages.MSG_PLACE_BLOCK); + playerEntity_1.sendMessage(Messages.MSG_INTERACT_BLOCK); return true; } return stack.isEmpty(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java index ab48936..19134e9 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java @@ -1,6 +1,5 @@ package io.github.indicode.fabric.itsmine.mixin; -import com.sun.org.apache.xpath.internal.operations.Bool; import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Functions; @@ -9,8 +8,6 @@ import net.minecraft.network.Packet; import net.minecraft.server.PlayerManager; import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.world.dimension.DimensionType; import org.spongepowered.asm.mixin.Mixin; @@ -29,7 +26,7 @@ private void canMine(PlayerEntity player, BlockPos blockPos_1, CallbackInfoRetur if (player.world.isClient()) return; Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, player.getEntityWorld().getDimension().getType()); if (claim != null) { - if (!claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.SPAWN_PROTECT)) { + if (!claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.SPAWN_PROTECTION)) { player.sendMessage(Messages.NO_PERMISSION); ci.setReturnValue(false); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java index 74601b8..11bf34b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java @@ -17,7 +17,7 @@ @Mixin(SpawnRestriction.class) public class SpawnRestrictionMixin { @Inject(method = "canSpawn", at = @At("HEAD"), cancellable = true) - private static void canSpawnInClaim(EntityType type, IWorld world, SpawnType spawnType, BlockPos pos, Random random, CallbackInfoReturnable cir) { + private static void canSpawnInClaim(EntityType type, IWorld world, SpawnType spawnType, BlockPos pos, Random random, CallbackInfoReturnable cir) { if (ClaimManager.INSTANCE == null) { cir.setReturnValue(false); return; From c932b626c203b5fccb91a730160cb2d0d0922c69 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 02:57:01 +0330 Subject: [PATCH 14/85] Added more permissions --- .../indicode/fabric/itsmine/BlockUtils.java | 35 ++++++++ .../github/indicode/fabric/itsmine/Claim.java | 10 ++- .../indicode/fabric/itsmine/ClaimCommand.java | 84 +++++++++---------- .../ServerPlayerInteractionManagerMixin.java | 19 +++-- .../itsmine/mixin/ServerWorldMixin.java | 22 ++--- 5 files changed, 104 insertions(+), 66 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java diff --git a/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java b/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java new file mode 100644 index 0000000..0d233a3 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java @@ -0,0 +1,35 @@ +package io.github.indicode.fabric.itsmine; + +import net.minecraft.block.*; + +public class BlockUtils { + + public static boolean isContainer(Block block) { + return block instanceof AbstractChestBlock || isChest(block) || isEnderchest(block) || isShulkerBox(block); + } + + + public static boolean isChest(Block block) { + return block == Blocks.CHEST || block == Blocks.BARREL; + } + + public static boolean isEnderchest(Block block) { + return block == Blocks.ENDER_CHEST; + } + + public static boolean isShulkerBox(Block block) { + return block == Blocks.SHULKER_BOX; + } + + public static boolean isButton(Block block) { + return block instanceof AbstractButtonBlock; + } + + public static boolean isLever(Block block) { + return block instanceof LeverBlock; + } + + public static boolean isDoor(Block block) { + return block instanceof DoorBlock; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index efae9d1..85dc5ae 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -250,7 +250,12 @@ public enum Permission { INTERACT_DOORS("interact_doors", "Use Doors"), INTERACT_ENTITY("interact_with_entities", "Entity Interaction"), DAMAGE_ENTITY("damage_entities", "Hurt Entities"), - FLIGHT("flight", "Flight"); + FLIGHT("flight", "Flight"), + CONTAINER("container", "Open Containers"), + CONTAINER_ENDERCHEST("container.enderchest", "Open Enderchests"), + CONTAINER_CHEST("container.chest", "Open Chests"), + CONTAINER_SHULKERBOX("container.shulkerbox", "Open Shulker Boxes"); + String id, name; Permission(String id, String name) { this.id = id; @@ -467,8 +472,7 @@ public enum Setting { PISTON_FROM_OUTSIDE("pistons_outside_border", "Pistons Cross border from Outside", false), MOB_SPAWNING("mob_spawn", "Natural mob spawning", true), // KEEP_INVENTORY("keep_inventory", "Keep Inventory", true), - ENTER_SOUND("enter_sound", "Enter Sound", false), - PUBLIC_CLAIM("public_claim", "Players see this claim", true); + ENTER_SOUND("enter_sound", "Enter Sound", false); String id, name; boolean defaultValue; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 318890d..04ce886 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1409,8 +1409,6 @@ private static int list(ServerCommandSource source, String target) throws Comman boolean nextColor = false; for (Claim claim : claims) { Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { - if (claim.settings.getSetting(Claim.ClaimSettings.Setting.PUBLIC_CLAIM)) return; - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click for more Info").formatted(Formatting.GREEN))); style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); }); @@ -1439,12 +1437,10 @@ private static int listAll(ServerCommandSource source, int page) { .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" in ").formatted(Formatting.GRAY)) .append(new LiteralText(Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").getPath()).formatted(Formatting.WHITE)); - if (claim.settings.getSetting(Claim.ClaimSettings.Setting.PUBLIC_CLAIM)) { - cText.styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click for more Info").formatted(Formatting.GREEN))); - style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); - }); - } + cText.styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click for more Info").formatted(Formatting.GREEN))); + style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); + }); list.add(cText.append("\n")); } @@ -1492,46 +1488,44 @@ private static int showTrustedList(CommandContext context, AtomicInteger atomicInteger = new AtomicInteger(); claim.permissionManager.playerPermissions.forEach((uuid, perm) -> { - if (!uuid.equals(player.getUuid())) { - atomicInteger.incrementAndGet(); - Text pText = new LiteralText(""); - GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); - String name = profile != null ? profile.getName() : uuid.toString(); - - pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) - .append(new LiteralText(name).formatted(Formatting.YELLOW)); - - Text hover = new LiteralText(""); - hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); - - int allowed = 0; - int i = 0; - boolean nextColor = false; - for (Claim.Permission value : Claim.Permission.values()) { - if (claim.permissionManager.hasPermission(uuid, value)) { - Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; - hover.append(new LiteralText(value.id).formatted(formatting)).append(" "); - if (i == 3) hover.append("\n"); - allowed++; - i++; - nextColor = !nextColor; - } - } + atomicInteger.incrementAndGet(); + Text pText = new LiteralText(""); + GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); + String name = profile != null ? profile.getName() : uuid.toString(); + + pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) + .append(new LiteralText(name).formatted(Formatting.YELLOW)); + + Text hover = new LiteralText(""); + hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); - pText.append(new LiteralText(" ") - .append(new LiteralText("(").formatted(Formatting.GOLD)) - .append(new LiteralText(String.valueOf(allowed)).formatted(Formatting.GREEN)) - .append(new LiteralText("/").formatted(Formatting.GOLD)) - .append(new LiteralText(String.valueOf(Claim.Permission.values().length)).formatted(Formatting.YELLOW)) - .append(new LiteralText(")").formatted(Formatting.GOLD)) - ); - - pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); - text.append(pText); - if (atomicInteger.get() + 1 != mapSize) { - text.append("\n"); + int allowed = 0; + int i = 0; + boolean nextColor = false; + for (Claim.Permission value : Claim.Permission.values()) { + if (claim.permissionManager.hasPermission(uuid, value)) { + Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; + hover.append(new LiteralText(value.id).formatted(formatting)).append(" "); + if (i == 3) hover.append("\n"); + allowed++; + i++; + nextColor = !nextColor; } } + + pText.append(new LiteralText(" ") + .append(new LiteralText("(").formatted(Formatting.GOLD)) + .append(new LiteralText(String.valueOf(allowed)).formatted(Formatting.GREEN)) + .append(new LiteralText("/").formatted(Formatting.GOLD)) + .append(new LiteralText(String.valueOf(Claim.Permission.values().length)).formatted(Formatting.YELLOW)) + .append(new LiteralText(")").formatted(Formatting.GOLD)) + ); + + pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); + text.append(pText); + if (atomicInteger.get() + 1 != mapSize) { + text.append("\n"); + } }); text.append("\n"); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index d3366d3..6e0f037 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -1,10 +1,9 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.*; -import net.minecraft.block.AbstractButtonBlock; -import net.minecraft.block.BlockState; -import net.minecraft.block.DoorBlock; -import net.minecraft.block.LeverBlock; +import net.minecraft.block.*; +import net.minecraft.block.entity.BarrelBlockEntity; +import net.minecraft.block.entity.LootableContainerBlockEntity; import net.minecraft.block.enums.DoubleBlockHalf; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; @@ -45,9 +44,13 @@ public ActionResult activateIfPossible(BlockState state, World world, PlayerEnti UUID uuid = playerEntity_1.getGameProfile().getId(); if ( claim.hasPermission(uuid, Claim.Permission.INTERACT_BLOCKS) || - (state.getBlock() instanceof AbstractButtonBlock && claim.hasPermission(uuid, Claim.Permission.PRESS_BUTTONS)) || - (state.getBlock() instanceof LeverBlock && claim.hasPermission(uuid, Claim.Permission.USE_LEVERS)) || - (state.getBlock() instanceof DoorBlock && claim.hasPermission(uuid, Claim.Permission.INTERACT_DOORS)) + (BlockUtils.isButton(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.PRESS_BUTTONS)) || + (BlockUtils.isLever(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.USE_LEVERS)) || + (BlockUtils.isDoor(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.INTERACT_DOORS)) || + (BlockUtils.isContainer(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.CONTAINER)) || + (BlockUtils.isChest(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.CONTAINER_CHEST)) || + (BlockUtils.isEnderchest(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.CONTAINER_ENDERCHEST)) || + (BlockUtils.isShulkerBox(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.CONTAINER_SHULKERBOX)) ) return state.onUse(world, playerEntity_1, hand_1, blockHitResult_1); else { if (state.getBlock() instanceof DoorBlock && playerEntity_1 instanceof ServerPlayerEntity) { @@ -60,6 +63,8 @@ public ActionResult activateIfPossible(BlockState state, World world, PlayerEnti return state.onUse(world, playerEntity_1, hand_1, blockHitResult_1); } + + @Redirect(method = "interactBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", ordinal = 2)) public boolean allowItemUse(ItemStack stack, PlayerEntity playerEntity_1, World world_1, ItemStack itemStack_1, Hand hand_1, BlockHitResult blockHitResult_1) { BlockPos pos = blockHitResult_1.getBlockPos().offset(blockHitResult_1.getSide()); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java index 19134e9..52621ca 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java @@ -21,17 +21,17 @@ */ @Mixin(ServerWorld.class) public abstract class ServerWorldMixin { - @Inject(method = "canPlayerModifyAt", at = @At("HEAD"), cancellable = true) - private void canMine(PlayerEntity player, BlockPos blockPos_1, CallbackInfoReturnable ci) { - if (player.world.isClient()) return; - Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, player.getEntityWorld().getDimension().getType()); - if (claim != null) { - if (!claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.SPAWN_PROTECTION)) { - player.sendMessage(Messages.NO_PERMISSION); - ci.setReturnValue(false); - } - } - } +// @Inject(method = "canPlayerModifyAt", at = @At("HEAD"), cancellable = true) +// private void canMine(PlayerEntity player, BlockPos blockPos_1, CallbackInfoReturnable ci) { +// if (player.world.isClient()) return; +// Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, player.getEntityWorld().getDimension().getType()); +// if (claim != null) { +// if (!claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.SPAWN_PROTECTION)) { +// player.sendMessage(Messages.NO_PERMISSION); +// ci.setReturnValue(false); +// } +// } +// } @Redirect(method = "sendBlockActions", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;sendToAround(Lnet/minecraft/entity/player/PlayerEntity;DDDDLnet/minecraft/world/dimension/DimensionType;Lnet/minecraft/network/Packet;)V")) private void sendPistonUpdate(PlayerManager manager, PlayerEntity playerEntity_1, double double_1, double double_2, double double_3, double double_4, DimensionType dimensionType_1, Packet packet_1) { manager.sendToAround(playerEntity_1, double_1, double_2, double_3, double_4, dimensionType_1, packet_1); From 3fd73fbf1f2fa052c59fa94d200f6c0b566b03cf Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 03:01:52 +0330 Subject: [PATCH 15/85] Added more permissions --- .../io/github/indicode/fabric/itsmine/ClaimCommand.java | 6 +----- .../itsmine/mixin/ServerPlayerInteractionManagerMixin.java | 5 ++++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 04ce886..46f587c 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1522,13 +1522,9 @@ private static int showTrustedList(CommandContext context, ); pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); - text.append(pText); - if (atomicInteger.get() + 1 != mapSize) { - text.append("\n"); - } + text.append(pText).append("\n"); }); - text.append("\n"); source.sendFeedback(text, false); return 1; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index 6e0f037..6e0d64c 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -51,12 +51,15 @@ public ActionResult activateIfPossible(BlockState state, World world, PlayerEnti (BlockUtils.isChest(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.CONTAINER_CHEST)) || (BlockUtils.isEnderchest(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.CONTAINER_ENDERCHEST)) || (BlockUtils.isShulkerBox(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.CONTAINER_SHULKERBOX)) - ) return state.onUse(world, playerEntity_1, hand_1, blockHitResult_1); + ) { + return state.onUse(world, playerEntity_1, hand_1, blockHitResult_1); + } else { if (state.getBlock() instanceof DoorBlock && playerEntity_1 instanceof ServerPlayerEntity) { DoubleBlockHalf half = state.get(DoorBlock.HALF); ((ServerPlayerEntity) playerEntity_1).networkHandler.sendPacket(new BlockUpdateS2CPacket(world, half == DoubleBlockHalf.LOWER ? pos.up() : pos.down(1))); } + playerEntity_1.sendMessage(Messages.MSG_INTERACT_BLOCK); return ActionResult.FAIL; } } From a981d0e62188f23552f4be90a6bfefd1b640c633 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 03:57:20 +0330 Subject: [PATCH 16/85] Fixed all the stuff --- .../indicode/fabric/itsmine/ClaimCommand.java | 18 ++++++++++-------- .../github/indicode/fabric/itsmine/Config.java | 2 ++ .../indicode/fabric/itsmine/ItsMine.java | 1 + .../indicode/fabric/itsmine/Messages.java | 6 ++++++ .../ServerPlayerInteractionManagerMixin.java | 13 ++++++++++--- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 46f587c..e50e373 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -427,13 +427,14 @@ public static void register(CommandDispatcher dispatcher) { dispatcher.register(claims); } { - LiteralArgumentBuilder listall = literal("listall"); - RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); - - listall.executes(context -> listAll(context.getSource(), 1)); - page.executes(context -> listAll(context.getSource(), IntegerArgumentType.getInteger(context, "page"))); - listall.then(page); - command.then(listall); + //TODO: FIX THIS +// LiteralArgumentBuilder listall = literal("listall"); +// RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); +// +// listall.executes(context -> listAll(context.getSource(), 1)); +// page.executes(context -> listAll(context.getSource(), IntegerArgumentType.getInteger(context, "page"))); +// listall.then(page); +// command.then(listall); } { LiteralArgumentBuilder trust = literal("trust"); @@ -1429,7 +1430,8 @@ private static int listAll(ServerCommandSource source, int page) { return -1; } - List list = new ArrayList<>();; + List list = new ArrayList<>(claims.size() / 10); + for (int i = 0; i < claims.size(); i++) { Claim claim = claims.get(i); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/Config.java index 0394dce..2fefe1a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Config.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Config.java @@ -13,6 +13,7 @@ public class Config { public static String msg_no_perm = "&c&lHey!&r&c Sorry but you don't have permission to do that"; public static String msg_interact_entity = "&c&lHey!&r&c Sorry but you can't interact with Entities here!"; public static String msg_interact_block = "&c&lHey!&r&c Sorry but you can't interact with Blocks here!"; + public static String msg_open_container = "&c&lHey!&r&c Sorry but you can't open containers here!"; public static String msg_break_block = "&c&lHey!&r&c Sorry but you can't Break Blocks here!"; public static String msg_place_block = "&c&lHey!&r&c Sorry but you can't Place Blocks here!"; public static String msg_attack_entity = "&c&lHey!&r&c Sorry but you can't Attack Entities here!"; @@ -29,6 +30,7 @@ static void sync(boolean overwrite) { prefix = config.getString("msg.prefix", prefix); msg_interact_entity = config.getString("msg.interact.entity", msg_interact_entity); msg_interact_block = config.getString("msg.interact.block", msg_interact_block); + msg_open_container = config.getString("msg.open.container", msg_open_container); msg_break_block = config.getString("msg.break.block", msg_break_block); msg_place_block = config.getString("msg.place.block", msg_place_block); msg_attack_entity = config.getString("msg.attack.entity", msg_attack_entity); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java index ed33340..34e73c5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java @@ -27,6 +27,7 @@ public void onInitialize() { map.registerPermission("itsmine.admin.modify", PermChangeBehavior.UPDATE_COMMAND_TREE); map.registerPermission("itsmine.admin.modify_permissions", PermChangeBehavior.UPDATE_COMMAND_TREE); map.registerPermission("itsmine.admin.ignore_claims", PermChangeBehavior.UPDATE_COMMAND_TREE); + map.registerPermission("itsmine.admin.reload", PermChangeBehavior.UPDATE_COMMAND_TREE); }); //TODO: Remove diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 3af447c..039bfeb 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -29,6 +29,8 @@ public class Messages { public static final Text MSG_INTERACT_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_interact_block)).formatted(Formatting.RED)); + public static final Text MSG_OPEN_CONTAINER = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_open_container)).formatted(Formatting.RED)); + public static final Text MSG_DAMAGE_ENTITY = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_attack_entity)).formatted(Formatting.RED)); public static final Text[] GET_STARTED = new Text[]{ @@ -85,6 +87,10 @@ public class Messages { .append(line("&6message ").append(text("&eLets you modify the different message events"))) }; + public static final Text[] SETTINGS = new Text[]{ + header("&6build ").append(text("")) + }; + private static Text header(String title) { return new LiteralText("").append(new LiteralText(title + ":").formatted(Formatting.AQUA, Formatting.UNDERLINE)).formatted(Formatting.WHITE).append("\n"); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index 6e0d64c..71465bb 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -59,7 +59,11 @@ public ActionResult activateIfPossible(BlockState state, World world, PlayerEnti DoubleBlockHalf half = state.get(DoorBlock.HALF); ((ServerPlayerEntity) playerEntity_1).networkHandler.sendPacket(new BlockUpdateS2CPacket(world, half == DoubleBlockHalf.LOWER ? pos.up() : pos.down(1))); } - playerEntity_1.sendMessage(Messages.MSG_INTERACT_BLOCK); + + if (BlockUtils.isContainer(state.getBlock())) { + playerEntity_1.sendMessage(Messages.MSG_OPEN_CONTAINER); + } + return ActionResult.FAIL; } } @@ -78,8 +82,11 @@ public boolean allowItemUse(ItemStack stack, PlayerEntity playerEntity_1, World claim.hasPermission(uuid, Claim.Permission.USE_ITEMS_ON_BLOCKS) || (stack.getItem() instanceof BlockItem && claim.hasPermission(uuid, Claim.Permission.BUILD)) || (stack.getItem() instanceof BucketItem && claim.hasPermission(uuid, Claim.Permission.BUILD)) - ) return false; - playerEntity_1.sendMessage(Messages.MSG_INTERACT_BLOCK); + ) + return false; + + if (!playerEntity_1.getStackInHand(hand_1).isEmpty()) + playerEntity_1.sendMessage(Messages.MSG_PLACE_BLOCK); return true; } return stack.isEmpty(); From 032b696f3e6409399f2b0b1caa55b07508f04176 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 03:58:29 +0330 Subject: [PATCH 17/85] Added aliases for /claim trust, distrust and trusted --- .../java/io/github/indicode/fabric/itsmine/ClaimCommand.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index e50e373..75ee435 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -253,6 +253,7 @@ public static void register(CommandDispatcher dispatcher) { }); trusted.then(claimArgument); command.then(trusted); + dispatcher.register(trusted); } { LiteralArgumentBuilder stick = literal("stick"); @@ -447,6 +448,7 @@ public static void register(CommandDispatcher dispatcher) { playerArgument.then(claimArgument); trust.then(playerArgument); command.then(trust); + dispatcher.register(trust); } { LiteralArgumentBuilder distrust = literal("distrust"); @@ -459,6 +461,7 @@ public static void register(CommandDispatcher dispatcher) { playerArgument.then(claimArgument); distrust.then(playerArgument); command.then(distrust); + dispatcher.register(distrust); } createExceptionCommand(command, false); From 288d4d6ef0fe55ad36c0bf58486ca16ac2eae4e9 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 04:18:26 +0330 Subject: [PATCH 18/85] Added setting damage_entity.passive and damage_entity.hostile --- .../github/indicode/fabric/itsmine/Claim.java | 2 ++ .../indicode/fabric/itsmine/EntityUtils.java | 14 ++++++++++++++ .../github/indicode/fabric/itsmine/ItsMine.java | 4 ++-- .../indicode/fabric/itsmine/Messages.java | 17 +++++++++++++++-- .../fabric/itsmine/mixin/PlayerEntityMixin.java | 15 +++++++++------ 5 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 85dc5ae..bc7ac55 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -250,6 +250,8 @@ public enum Permission { INTERACT_DOORS("interact_doors", "Use Doors"), INTERACT_ENTITY("interact_with_entities", "Entity Interaction"), DAMAGE_ENTITY("damage_entities", "Hurt Entities"), + DAMAGE_ENTITY_HOSTILE("damage_entities.hostile", "Hurt Hostile Entities"), + DAMAGE_ENTITY_PASSIVE("damage_entities.passive", "Hurt Passive Entities"), FLIGHT("flight", "Flight"), CONTAINER("container", "Open Containers"), CONTAINER_ENDERCHEST("container.enderchest", "Open Enderchests"), diff --git a/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java b/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java new file mode 100644 index 0000000..74e11a8 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java @@ -0,0 +1,14 @@ +package io.github.indicode.fabric.itsmine; + +import net.minecraft.entity.Entity; + +public class EntityUtils { + + public static boolean isPassive(Entity entity) { + return entity.getType().getCategory().isPeaceful(); + } + + public static boolean isHostile(Entity entity) { + return !entity.getType().getCategory().isPeaceful(); + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java index 34e73c5..4fdb7df 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java @@ -30,8 +30,8 @@ public void onInitialize() { map.registerPermission("itsmine.admin.reload", PermChangeBehavior.UPDATE_COMMAND_TREE); }); - //TODO: Remove - SharedConstants.isDevelopment = true; + //TODO: Enable when developing + //SharedConstants.isDevelopment = true; } public static String blocksToAreaString3d(int blocks) { int base = (int) Math.floor(Math.cbrt(blocks)); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 039bfeb..4ca5088 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -87,8 +87,21 @@ public class Messages { .append(line("&6message ").append(text("&eLets you modify the different message events"))) }; - public static final Text[] SETTINGS = new Text[]{ - header("&6build ").append(text("")) + public static final Text[] SETTINGS_AND_PERMISSIONS = new Text[]{ + header("Settings ") + .append(line("&6build ").append(text("&eAllows others to build (place and break blocks)"))) + .append(line("&6interact_blocks ").append(text("Allows others to Interact (Right click) with blocks"))) + .append(line("&6use_items_on_blocks ").append(text("Allows others to use items on blocks (Right click on blocks with an Item)"))) + .append(line("&6press_button ").append(text("Allows others to press Buttons"))) + .append(line("&6use_levers ").append(text("Allows others to ue Levers"))) + .append(line("&6interact_doors ").append(text("Allows others to Interact with Doors"))) + .append(line("&6interact_entity ").append(text("Allows others to Interact with Entities (Right click on Entities)"))) + .append(line("&6damage_entity ").append(text("Allows others to Damage (Attack) Entities"))) + .append(line("&6interact_blocks ").append(text("Allows others to Interact (Right click) with blocks"))) + .append(line("&6interact_blocks ").append(text("Allows others to Interact (Right click) with blocks"))) + + + }; private static Text header(String title) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java index 2777e09..595e8e1 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java @@ -1,10 +1,8 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ClaimShower; -import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.*; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityCategory; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; @@ -12,6 +10,7 @@ import net.minecraft.text.LiteralText; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.registry.Registry; import net.minecraft.world.GameRules; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Final; @@ -53,8 +52,12 @@ public void hittingIsRude(Entity entity, CallbackInfo ci) { PlayerEntity playerEntity_1 = (PlayerEntity)(Object)this; Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); if (claim != null) { - if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY)) { - playerEntity_1.sendMessage(Messages.MSG_INTERACT_ENTITY); + if ( + !claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY) || + (EntityUtils.isHostile(entity) && !claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY_HOSTILE)) || + (EntityUtils.isPassive(entity) && !claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY_PASSIVE)) + ) { + playerEntity_1.sendMessage(Messages.MSG_DAMAGE_ENTITY); ci.cancel(); } } From 7e313ff36848a427e333161eb1d6cf1af6ae4a5f Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 05:04:31 +0330 Subject: [PATCH 19/85] Added help book: permissions and settings --- .../github/indicode/fabric/itsmine/Claim.java | 3 +- .../indicode/fabric/itsmine/ClaimCommand.java | 30 ++++------- .../indicode/fabric/itsmine/Messages.java | 52 ++++++++++++++----- 3 files changed, 52 insertions(+), 33 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index bc7ac55..d0c8416 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -540,7 +540,8 @@ public static Event getById(String id) { public enum HelpBook { GET_STARTED("getStarted", Messages.GET_STARTED, "Get Started"), - COMMAND("commands", Messages.HELP, "Claim Commands"); + COMMAND("commands", Messages.HELP, "Claim Commands"), + PERMS_AND_SETTINGS("perms_and_settings", Messages.SETTINGS_AND_PERMISSIONS, "Claim Permissions and Settings"); String id; String title; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 75ee435..d0ec91f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -82,6 +82,13 @@ private static Predicate perm(String str, int op) { }; return CommandSource.suggestMatching(strings, builder); }; + public static final SuggestionProvider BOOK_SUGGESTIONS = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.HelpBook value : Claim.HelpBook.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; public static final SuggestionProvider CLAIM_PROVIDER = (source, builder) -> { ServerPlayerEntity player = source.getSource().getPlayer(); List names = new ArrayList<>(); @@ -164,7 +171,8 @@ public static void register(CommandDispatcher dispatcher) { LiteralArgumentBuilder help = literal("help"); help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); - RequiredArgumentBuilder id = argument("id", StringArgumentType.word()); + RequiredArgumentBuilder id = argument("id", StringArgumentType.word()) + .suggests(BOOK_SUGGESTIONS); RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); page.executes((context) -> { @@ -789,15 +797,7 @@ private static void createExceptionCommand(LiteralArgumentBuilder claim = getClaimArgument(); if (!admin) { - settings.executes((context) -> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Claim claim1 = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.dimension); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return querySettings(context.getSource(), claim1); - }); + settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); claim.executes((context) -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); @@ -825,15 +825,7 @@ private static void createExceptionCommand(LiteralArgumentBuilder Thimble.hasPermissionOrOp(source, "itsmine.admin.modify_permissions", 2)); RequiredArgumentBuilder claim = getClaimArgument(); if (!admin) { - exceptions.executes((context) -> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Claim claim1 = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.dimension); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return showTrustedList(context, claim1, true); - }); + exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); claim.executes((context) -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 4ca5088..cdb80e4 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -88,20 +88,46 @@ public class Messages { }; public static final Text[] SETTINGS_AND_PERMISSIONS = new Text[]{ - header("Settings ") + header("Permissions") .append(line("&6build ").append(text("&eAllows others to build (place and break blocks)"))) - .append(line("&6interact_blocks ").append(text("Allows others to Interact (Right click) with blocks"))) - .append(line("&6use_items_on_blocks ").append(text("Allows others to use items on blocks (Right click on blocks with an Item)"))) - .append(line("&6press_button ").append(text("Allows others to press Buttons"))) - .append(line("&6use_levers ").append(text("Allows others to ue Levers"))) - .append(line("&6interact_doors ").append(text("Allows others to Interact with Doors"))) - .append(line("&6interact_entity ").append(text("Allows others to Interact with Entities (Right click on Entities)"))) - .append(line("&6damage_entity ").append(text("Allows others to Damage (Attack) Entities"))) - .append(line("&6interact_blocks ").append(text("Allows others to Interact (Right click) with blocks"))) - .append(line("&6interact_blocks ").append(text("Allows others to Interact (Right click) with blocks"))) - - - + .append(line("&6interact_blocks ").append(text("&eAllows others to Interact (Right click) with blocks"))) + .append(line("&6use_items_on_blocks ").append(text("&eAllows others to use items on blocks (Right click on blocks with an Item)"))) + .append(line("&6press_button ").append(text("&eAllows others to press Buttons"))) + .append(line("&6use_levers ").append(text("&eAllows others to ue Levers"))) + .append(line("&6interact_doors ").append(text("&eAllows others to Interact with Doors"))) + .append(line("&6interact_entity ").append(text("&eAllows others to Interact with Entities (Right click on Entities)"))), + + header("Permissions") + .append(line("&6damage_entity ").append(text("&eAllows others to Damage (Attack) Entities"))) + .append(line("&6damage_entity.hostile ").append(text("&eAllows others Damage (Attack) Hostile Entities, e.g: Zombie, Creeper, Skeleton etc"))) + .append(line("&6damage_entity.passive ").append(text("&eAllows others to Damage (Attack) Passive Entities, e.g: Sheep, Cow, Chicken etc"))) + .append(line("&6flight ").append(text("&eEnables Flight in the claim (Only for those who have the Flight permission)"))) + .append(line("&6container ").append(text("&eAllows others to open containers (e.g: Chest, EnderChest etc)"))) + .append(line("&6container ").append(text("&eAllows others to open containers (e.g: Chest, EnderChest etc)"))) + .append(line("&6container.chest ").append(text("&eAllows others to only open chest containers (Chests and Barrels)"))), + + header("Permissions") + .append(line("&6container.enderchest ").append(text("&eAllows others to only open Ender Chest containers"))) + .append(line("&6container.shulkerbox ").append(text("&eAllows others to only open shulkerox container"))) + .append(line("&cmodify_properties ").append(text("&eAllows others to modify the properties of the claim (e.g: Join/leave messages)"))) + + .append( + header("Settings") + .append(line("&6flight_allowed").append(text("Allows others to fly in the claim (Only for those who have the Flight permission)"))) + .append(line("&6flight_allowed").append(text("Allows others to fly in the claim (Only for those who have the Flight permission)"))) + ), + + header("Permissions") + .append(line("&6explosion_destruction").append(text("Explosions destroy blocks"))) + .append(line("&6explosion_damage").append(text("Explosions damage entities"))) + .append(line("&6fluid_crosses_border").append(text("Let fluids go across the borders"))) + .append(line("&6fire_crosses_border").append(text("Let fire to spread across the borders"))) + .append(line("&6fire_damage").append(text("Fire damages entities"))) + .append(line("&6piston_from_inside").append(text("Let pistons to move blocks to outside the claim"))), + + header("Permissions") + .append(line("&6mob_spawning").append(text("Allow mobs to spawn inside the claim"))) + .append(line("&6enter_sound").append(text("Play a sound when entering the claim"))) }; private static Text header(String title) { From 258cb10cbbaf0579d87b4224db80aa1f45d550b1 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 05:14:14 +0330 Subject: [PATCH 20/85] Added ability to reset the custom owner name, and fixed the items getting lost in the client --- .../indicode/fabric/itsmine/ClaimCommand.java | 7 ++-- .../indicode/fabric/itsmine/Messages.java | 38 +++++++++---------- .../mixin/ServerPlayNetworkHandlerMixin.java | 1 + .../ServerPlayerInteractionManagerMixin.java | 2 + 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index d0ec91f..0672ca9 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1525,13 +1525,14 @@ private static int showTrustedList(CommandContext context, source.sendFeedback(text, false); return 1; } - private static int setOwnerName(ServerCommandSource source, Claim claim, String name) { + private static int setOwnerName(ServerCommandSource source, Claim claim, String input) { + String name = input.equals("reset") ? null : input; source.sendFeedback(new LiteralText("Set the Custom Owner Name to ") - .formatted(Formatting.YELLOW).append(new LiteralText(name).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) + .formatted(Formatting.YELLOW).append(new LiteralText(name == null ? "Reset" : name).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) .append(new LiteralText(claim.customOwnerName == null ? "Not Present" : claim.customOwnerName).formatted(Formatting.GOLD)) .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) , false); - claim.customOwnerName = name; + claim.customOwnerName = input; return 1; } private static int setOwner(ServerCommandSource source, Claim claim, GameProfile profile) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index cdb80e4..5e2f202 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -101,33 +101,29 @@ public class Messages { .append(line("&6damage_entity ").append(text("&eAllows others to Damage (Attack) Entities"))) .append(line("&6damage_entity.hostile ").append(text("&eAllows others Damage (Attack) Hostile Entities, e.g: Zombie, Creeper, Skeleton etc"))) .append(line("&6damage_entity.passive ").append(text("&eAllows others to Damage (Attack) Passive Entities, e.g: Sheep, Cow, Chicken etc"))) - .append(line("&6flight ").append(text("&eEnables Flight in the claim (Only for those who have the Flight permission)"))) - .append(line("&6container ").append(text("&eAllows others to open containers (e.g: Chest, EnderChest etc)"))) - .append(line("&6container ").append(text("&eAllows others to open containers (e.g: Chest, EnderChest etc)"))) - .append(line("&6container.chest ").append(text("&eAllows others to only open chest containers (Chests and Barrels)"))), + .append(line("&6flight ").append(text("&eEnables Flight in the claim (Only for those who have the Flight permission)"))), header("Permissions") .append(line("&6container.enderchest ").append(text("&eAllows others to only open Ender Chest containers"))) .append(line("&6container.shulkerbox ").append(text("&eAllows others to only open shulkerox container"))) .append(line("&cmodify_properties ").append(text("&eAllows others to modify the properties of the claim (e.g: Join/leave messages)"))) + .append(line("&6container ").append(text("&eAllows others to open containers (e.g: Chest, EnderChest etc)"))) + .append(line("&6container ").append(text("&eAllows others to open containers (e.g: Chest, EnderChest etc)"))) + .append(line("&6container.chest ").append(text("&eAllows others to only open chest containers (Chests and Barrels)"))), - .append( - header("Settings") - .append(line("&6flight_allowed").append(text("Allows others to fly in the claim (Only for those who have the Flight permission)"))) - .append(line("&6flight_allowed").append(text("Allows others to fly in the claim (Only for those who have the Flight permission)"))) - ), - - header("Permissions") - .append(line("&6explosion_destruction").append(text("Explosions destroy blocks"))) - .append(line("&6explosion_damage").append(text("Explosions damage entities"))) - .append(line("&6fluid_crosses_border").append(text("Let fluids go across the borders"))) - .append(line("&6fire_crosses_border").append(text("Let fire to spread across the borders"))) - .append(line("&6fire_damage").append(text("Fire damages entities"))) - .append(line("&6piston_from_inside").append(text("Let pistons to move blocks to outside the claim"))), - - header("Permissions") - .append(line("&6mob_spawning").append(text("Allow mobs to spawn inside the claim"))) - .append(line("&6enter_sound").append(text("Play a sound when entering the claim"))) + header("Settings") + .append(line("&6flight_allowed ").append(text("Allows others to fly in the claim (Only for those who have the Flight permission)"))) + .append(line("&6flight_allowed ").append(text("Allows others to fly in the claim (Only for those who have the Flight permission)"))) + .append(line("&6explosion_destruction ").append(text("Explosions destroy blocks"))) + .append(line("&6explosion_damage ").append(text("Explosions damage entities"))) + .append(line("&6fluid_crosses_border ").append(text("Let fluids go across the borders"))), + + header("Settings") + .append(line("&6fire_crosses_border ").append(text("Let fire to spread across the borders"))) + .append(line("&6fire_damage ").append(text("Fire damages entities"))) + .append(line("&6piston_from_inside ").append(text("Let pistons to move blocks to outside the claim"))) + .append(line("&6mob_spawning ").append(text("Allow mobs to spawn inside the claim"))) + .append(line("&6enter_sound ").append(text("Play a sound when entering the claim"))), }; private static Text header(String title) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java index 96277d6..f4e523b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java @@ -30,6 +30,7 @@ public ActionResult iSaidDontTouchMe(Entity entity, PlayerEntity playerEntity_1, if (claim != null) { if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.INTERACT_ENTITY)) { playerEntity_1.sendMessage(Messages.MSG_INTERACT_ENTITY); + playerEntity_1.inventory.updateItems(); return ActionResult.FAIL; } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index 71465bb..b813659 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -87,6 +87,8 @@ public boolean allowItemUse(ItemStack stack, PlayerEntity playerEntity_1, World if (!playerEntity_1.getStackInHand(hand_1).isEmpty()) playerEntity_1.sendMessage(Messages.MSG_PLACE_BLOCK); + + playerEntity_1.inventory.updateItems(); return true; } return stack.isEmpty(); From 0af3b06d91c492af2ac4bb1ae2bd1150ff18f18c Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 05:36:57 +0330 Subject: [PATCH 21/85] Updated --- .../io/github/indicode/fabric/itsmine/Functions.java | 3 +++ .../io/github/indicode/fabric/itsmine/Messages.java | 7 +++---- .../itsmine/mixin/ServerPlayNetworkHandlerMixin.java | 6 +++++- .../mixin/ServerPlayerInteractionManagerMixin.java | 10 +++++++--- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index 3b26b50..92a1078 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -59,4 +59,7 @@ public static void setClaimFlying(UUID player, boolean flying) { claimFlyNow.remove(player); } } + public static void updateInventory(ServerPlayerEntity player) { + player.inventory.updateItems(); + } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 5e2f202..72fe02d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -106,20 +106,19 @@ public class Messages { header("Permissions") .append(line("&6container.enderchest ").append(text("&eAllows others to only open Ender Chest containers"))) .append(line("&6container.shulkerbox ").append(text("&eAllows others to only open shulkerox container"))) - .append(line("&cmodify_properties ").append(text("&eAllows others to modify the properties of the claim (e.g: Join/leave messages)"))) + .append(line("&6modify_properties ").append(text("&eAllows others to modify the properties of the claim (e.g: Join/leave messages)"))) .append(line("&6container ").append(text("&eAllows others to open containers (e.g: Chest, EnderChest etc)"))) .append(line("&6container ").append(text("&eAllows others to open containers (e.g: Chest, EnderChest etc)"))) .append(line("&6container.chest ").append(text("&eAllows others to only open chest containers (Chests and Barrels)"))), header("Settings") - .append(line("&6flight_allowed ").append(text("Allows others to fly in the claim (Only for those who have the Flight permission)"))) .append(line("&6flight_allowed ").append(text("Allows others to fly in the claim (Only for those who have the Flight permission)"))) .append(line("&6explosion_destruction ").append(text("Explosions destroy blocks"))) .append(line("&6explosion_damage ").append(text("Explosions damage entities"))) - .append(line("&6fluid_crosses_border ").append(text("Let fluids go across the borders"))), + .append(line("&6fluid_crosses_border ").append(text("Let fluids go across the borders"))) + .append(line("&6fire_crosses_border ").append(text("Let fire to spread across the borders"))), header("Settings") - .append(line("&6fire_crosses_border ").append(text("Let fire to spread across the borders"))) .append(line("&6fire_damage ").append(text("Fire damages entities"))) .append(line("&6piston_from_inside ").append(text("Let pistons to move blocks to outside the claim"))) .append(line("&6mob_spawning ").append(text("Allow mobs to spawn inside the claim"))) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java index f4e523b..da245b0 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java @@ -7,6 +7,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; @@ -16,6 +17,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -24,13 +26,15 @@ */ @Mixin(ServerPlayNetworkHandler.class) public class ServerPlayNetworkHandlerMixin { + @Shadow public ServerPlayerEntity player; + @Redirect(method = "onPlayerInteractEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;interactAt(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;")) public ActionResult iSaidDontTouchMe(Entity entity, PlayerEntity playerEntity_1, Vec3d vec3d_1, Hand hand_1) { Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); if (claim != null) { if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.INTERACT_ENTITY)) { playerEntity_1.sendMessage(Messages.MSG_INTERACT_ENTITY); - playerEntity_1.inventory.updateItems(); + Functions.updateInventory(player); return ActionResult.FAIL; } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index b813659..ffa4f59 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -2,8 +2,6 @@ import io.github.indicode.fabric.itsmine.*; import net.minecraft.block.*; -import net.minecraft.block.entity.BarrelBlockEntity; -import net.minecraft.block.entity.LootableContainerBlockEntity; import net.minecraft.block.enums.DoubleBlockHalf; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; @@ -64,9 +62,13 @@ public ActionResult activateIfPossible(BlockState state, World world, PlayerEnti playerEntity_1.sendMessage(Messages.MSG_OPEN_CONTAINER); } + player.inventory.markDirty(); + player.inventory.updateItems(); return ActionResult.FAIL; } } + + player.inventory.updateItems(); return state.onUse(world, playerEntity_1, hand_1, blockHitResult_1); } @@ -88,9 +90,11 @@ public boolean allowItemUse(ItemStack stack, PlayerEntity playerEntity_1, World if (!playerEntity_1.getStackInHand(hand_1).isEmpty()) playerEntity_1.sendMessage(Messages.MSG_PLACE_BLOCK); - playerEntity_1.inventory.updateItems(); + Functions.updateInventory(player); return true; } + + Functions.updateInventory(player); return stack.isEmpty(); } From 063c406dd5b5ca2976f729f3422fff07b8565e9b Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 07:42:26 +0330 Subject: [PATCH 22/85] Finally fixed the Explosion Flags --- .../itsmine/mixin/AbstractFireBlockMixin.java | 1 - .../fabric/itsmine/mixin/EntityMixin.java | 4 ++-- .../fabric/itsmine/mixin/ExplosionMixin.java | 4 ++-- .../fabric/itsmine/mixin/FireBlockMixin.java | 24 +++++++++---------- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java index cfd878b..a55e74e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java @@ -14,7 +14,6 @@ public abstract class AbstractFireBlockMixin { @Redirect(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isFireImmune()Z")) private boolean neverGonnaBurnYouUp(Entity entity) { - PlayerEntity player = (PlayerEntity) entity; Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.dimension); if (claim != null && !claim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_DAMAGE)) { return true; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index b6b558b..e4c073d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -79,11 +79,11 @@ public void doTickActions(CallbackInfo ci) { boolean old = player.abilities.allowFlying; Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.world.dimension.getType()); if (player instanceof ServerPlayerEntity) { - if (player.abilities.allowFlying && !player.isSpectator() && ((claim == null || !claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) || !claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT)) && Functions.isClaimFlying(player.getGameProfile().getId()))) { + if (player.abilities.allowFlying && !player.isSpectator() && !player.isCreative() && ((claim == null || !claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) || !claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT)) && Functions.isClaimFlying(player.getGameProfile().getId()))) { player.abilities.allowFlying = false; player.abilities.flying = false; Functions.setClaimFlying(player.getGameProfile().getId(), false); - } else if (!player.abilities.allowFlying && !player.isSpectator() && claim != null && claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) && claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT) && Functions.canClaimFly((ServerPlayerEntity) player)) { + } else if (!player.abilities.allowFlying && !player.isSpectator() && !player.isCreative() && claim != null && claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) && claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT) && Functions.canClaimFly((ServerPlayerEntity) player)) { player.abilities.allowFlying = true; Functions.setClaimFlying(player.getGameProfile().getId(), true); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java index 5d5a9d4..83842c8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java @@ -20,7 +20,7 @@ public class ExplosionMixin { @Redirect(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;")) private BlockState theyCallMeBedrock(World world, BlockPos blockPos_1) { Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, world.getDimension().getType()); - if (claim != null && !world.isAir(blockPos_1)) { + if (claim != null && !world.isAir(blockPos_1) && !world.getBlockState(blockPos_1).getBlock().equals(Blocks.TNT)) { if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) return Blocks.BEDROCK.getDefaultState(); } @@ -32,7 +32,7 @@ private boolean claimDeniesExplosion(Entity entity) { Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, entity.world.getDimension().getType()); if (claim != null) { if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DAMAGE)) - return false; + return true; } return entity.isImmuneToExplosion(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java index 449dea6..417575e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java @@ -32,13 +32,13 @@ private void dontBurnClaims(FireBlock fireBlock, World world, BlockPos newPos, i Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!(Boolean) newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; + if (!newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; } else if (newClaim == null) { - if (!(Boolean) oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; + if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; } else { - if (!(Boolean) oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || - !(Boolean) newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; + if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || + !newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; } } trySpreadingFire(world, newPos, int_1, random_1, int_2); @@ -49,14 +49,14 @@ private boolean dontCauseFire2(ServerWorld world, BlockPos newPos, BlockState bl Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!(Boolean) newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) + if (!newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return false; } else if (newClaim == null) { - if (!(Boolean) oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) + if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return false; } else { - if (!(Boolean) oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || - !(Boolean) newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) + if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || + !newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return false; } } @@ -80,13 +80,13 @@ private boolean dontCauseFire(World world, BlockPos oldPos, BlockState blockStat Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!(Boolean) newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); + if (!newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); } else if (newClaim == null) { - if (!(Boolean) oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); + if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); } else { - if (!(Boolean) oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || - !(Boolean) newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); + if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || + !newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); } } } From f8d760f72bbe853767f30d0b6acc4f8e17fb5c8b Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 07:42:52 +0330 Subject: [PATCH 23/85] Update ClaimCommand.java --- .../java/io/github/indicode/fabric/itsmine/ClaimCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 0672ca9..9c25920 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1401,7 +1401,7 @@ private static int list(ServerCommandSource source, String target) throws Comman } - Text text = new LiteralText("\n").append(new LiteralText("Claims: " + source.getName()).formatted(Formatting.GOLD)).append("\n "); + Text text = new LiteralText("\n").append(new LiteralText("Claims: " + target).formatted(Formatting.GOLD)).append("\n "); boolean nextColor = false; for (Claim claim : claims) { Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { From f46a9314c493334772b59cdd6a17d0cf6e17cd0b Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 08:59:10 +0330 Subject: [PATCH 24/85] dummy commit --- .../java/io/github/indicode/fabric/itsmine/ClaimCommand.java | 2 +- src/main/java/io/github/indicode/fabric/itsmine/Functions.java | 2 +- .../github/indicode/fabric/itsmine/mixin/BucketItemMixin.java | 2 +- src/main/resources/itsmine.mixins.json | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 9c25920..e86f957 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1175,7 +1175,7 @@ private static int requestDelete(ServerCommandSource sender, Claim claim, boolea .append(new LiteralText("[I'M SURE]").setStyle(new Style() .setColor(Formatting.DARK_RED) .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " destroy " + claim.name + " confirm")))), false); + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")))), false); return 0; } private static int delete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index 92a1078..e41d054 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -31,7 +31,7 @@ public static void doPistonUpdate(ServerWorld world, Packet packet) { } } public static boolean canPlayerActuallyModifyAt(ServerWorld world, PlayerEntity playerEntity_1, BlockPos blockPos_1) { - return !world.getServer().isSpawnProtected(world, blockPos_1, playerEntity_1) && world.getWorldBorder().contains(blockPos_1); + return !world.getServer().isSpawnProtected(world, blockPos_1, playerEntity_1) && !world.getWorldBorder().contains(blockPos_1); }; public static boolean isBucketEmpty(BucketItem item) { return ((BucketItemMixin)item).getFluid() != Fluids.EMPTY; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BucketItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BucketItemMixin.java index caa36aa..d85d3fa 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BucketItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BucketItemMixin.java @@ -11,5 +11,5 @@ @Mixin(BucketItem.class) public interface BucketItemMixin { @Accessor("fluid") - public Fluid getFluid(); + Fluid getFluid(); } diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index 83be44b..908bb53 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -19,8 +19,7 @@ "PistonBlockMixin", "ServerPlayerInteractionManagerMixin", "PlaceOnUseBlockMixin", - "FireBlockMixin", - "AbstractFireBlockMixin", + "SpawnRestrictionMixin", "OwnedProjectile", From d7fb36fcc6181a74cf8327eb603bf25fca450b71 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 08:59:16 +0330 Subject: [PATCH 25/85] Revert "Update ClaimCommand.java" This reverts commit f8d760f72bbe853767f30d0b6acc4f8e17fb5c8b. --- .../java/io/github/indicode/fabric/itsmine/ClaimCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index e86f957..d0958df 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1401,7 +1401,7 @@ private static int list(ServerCommandSource source, String target) throws Comman } - Text text = new LiteralText("\n").append(new LiteralText("Claims: " + target).formatted(Formatting.GOLD)).append("\n "); + Text text = new LiteralText("\n").append(new LiteralText("Claims: " + source.getName()).formatted(Formatting.GOLD)).append("\n "); boolean nextColor = false; for (Claim claim : claims) { Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { From 17d7acde2a69a8bea8e45a803e673e88a9a829db Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 08:59:23 +0330 Subject: [PATCH 26/85] Revert "Revert "Update ClaimCommand.java"" This reverts commit d7fb36fcc6181a74cf8327eb603bf25fca450b71. --- .../java/io/github/indicode/fabric/itsmine/ClaimCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index d0958df..e86f957 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1401,7 +1401,7 @@ private static int list(ServerCommandSource source, String target) throws Comman } - Text text = new LiteralText("\n").append(new LiteralText("Claims: " + source.getName()).formatted(Formatting.GOLD)).append("\n "); + Text text = new LiteralText("\n").append(new LiteralText("Claims: " + target).formatted(Formatting.GOLD)).append("\n "); boolean nextColor = false; for (Claim claim : claims) { Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { From 224d4c500865f3b517d8683c93a1ac85b9905997 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 08:59:26 +0330 Subject: [PATCH 27/85] Revert "dummy commit" This reverts commit f46a9314c493334772b59cdd6a17d0cf6e17cd0b. --- .../java/io/github/indicode/fabric/itsmine/ClaimCommand.java | 2 +- src/main/java/io/github/indicode/fabric/itsmine/Functions.java | 2 +- .../github/indicode/fabric/itsmine/mixin/BucketItemMixin.java | 2 +- src/main/resources/itsmine.mixins.json | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index e86f957..9c25920 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1175,7 +1175,7 @@ private static int requestDelete(ServerCommandSource sender, Claim claim, boolea .append(new LiteralText("[I'M SURE]").setStyle(new Style() .setColor(Formatting.DARK_RED) .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")))), false); + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " destroy " + claim.name + " confirm")))), false); return 0; } private static int delete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index e41d054..92a1078 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -31,7 +31,7 @@ public static void doPistonUpdate(ServerWorld world, Packet packet) { } } public static boolean canPlayerActuallyModifyAt(ServerWorld world, PlayerEntity playerEntity_1, BlockPos blockPos_1) { - return !world.getServer().isSpawnProtected(world, blockPos_1, playerEntity_1) && !world.getWorldBorder().contains(blockPos_1); + return !world.getServer().isSpawnProtected(world, blockPos_1, playerEntity_1) && world.getWorldBorder().contains(blockPos_1); }; public static boolean isBucketEmpty(BucketItem item) { return ((BucketItemMixin)item).getFluid() != Fluids.EMPTY; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BucketItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BucketItemMixin.java index d85d3fa..caa36aa 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BucketItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BucketItemMixin.java @@ -11,5 +11,5 @@ @Mixin(BucketItem.class) public interface BucketItemMixin { @Accessor("fluid") - Fluid getFluid(); + public Fluid getFluid(); } diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index 908bb53..83be44b 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -19,7 +19,8 @@ "PistonBlockMixin", "ServerPlayerInteractionManagerMixin", "PlaceOnUseBlockMixin", - + "FireBlockMixin", + "AbstractFireBlockMixin", "SpawnRestrictionMixin", "OwnedProjectile", From e5a3ef51a89d1a3069700cfd174e477550d2553c Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 09:05:59 +0330 Subject: [PATCH 28/85] dummy commit --- src/main/java/io/github/indicode/fabric/itsmine/Functions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index 92a1078..e41d054 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -31,7 +31,7 @@ public static void doPistonUpdate(ServerWorld world, Packet packet) { } } public static boolean canPlayerActuallyModifyAt(ServerWorld world, PlayerEntity playerEntity_1, BlockPos blockPos_1) { - return !world.getServer().isSpawnProtected(world, blockPos_1, playerEntity_1) && world.getWorldBorder().contains(blockPos_1); + return !world.getServer().isSpawnProtected(world, blockPos_1, playerEntity_1) && !world.getWorldBorder().contains(blockPos_1); }; public static boolean isBucketEmpty(BucketItem item) { return ((BucketItemMixin)item).getFluid() != Fluids.EMPTY; From cc6609beb6729eea6c7ed8392a77cb81ab9702f1 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 14 Mar 2020 11:36:02 +0330 Subject: [PATCH 29/85] fixing stuff --- .../itsmine/mixin/ServerPlayNetworkHandlerMixin.java | 11 +++++------ .../mixin/ServerPlayerInteractionManagerMixin.java | 6 ------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java index da245b0..b51a58e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java @@ -34,15 +34,14 @@ public ActionResult iSaidDontTouchMe(Entity entity, PlayerEntity playerEntity_1, if (claim != null) { if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.INTERACT_ENTITY)) { playerEntity_1.sendMessage(Messages.MSG_INTERACT_ENTITY); - Functions.updateInventory(player); return ActionResult.FAIL; } } return entity.interactAt(playerEntity_1, vec3d_1, hand_1); } - - @Redirect(method = "onPlayerInteractBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;canPlayerModifyAt(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;)Z")) - private boolean canITouchie(ServerWorld world, PlayerEntity playerEntity_1, BlockPos blockPos_1) { - return Functions.canPlayerActuallyModifyAt(world, playerEntity_1, blockPos_1); - } +// +// @Redirect(method = "onPlayerInteractBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;canPlayerModifyAt(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;)Z")) +// private boolean canITouchie(ServerWorld world, PlayerEntity playerEntity_1, BlockPos blockPos_1) { +// return Functions.canPlayerActuallyModifyAt(world, playerEntity_1, blockPos_1); +// } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index ffa4f59..f2d8e9e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -62,8 +62,6 @@ public ActionResult activateIfPossible(BlockState state, World world, PlayerEnti playerEntity_1.sendMessage(Messages.MSG_OPEN_CONTAINER); } - player.inventory.markDirty(); - player.inventory.updateItems(); return ActionResult.FAIL; } } @@ -72,8 +70,6 @@ public ActionResult activateIfPossible(BlockState state, World world, PlayerEnti return state.onUse(world, playerEntity_1, hand_1, blockHitResult_1); } - - @Redirect(method = "interactBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", ordinal = 2)) public boolean allowItemUse(ItemStack stack, PlayerEntity playerEntity_1, World world_1, ItemStack itemStack_1, Hand hand_1, BlockHitResult blockHitResult_1) { BlockPos pos = blockHitResult_1.getBlockPos().offset(blockHitResult_1.getSide()); @@ -90,11 +86,9 @@ public boolean allowItemUse(ItemStack stack, PlayerEntity playerEntity_1, World if (!playerEntity_1.getStackInHand(hand_1).isEmpty()) playerEntity_1.sendMessage(Messages.MSG_PLACE_BLOCK); - Functions.updateInventory(player); return true; } - Functions.updateInventory(player); return stack.isEmpty(); } From 8414023b343a9079841cc92daf1525ff176577e1 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sun, 15 Mar 2020 07:05:24 +0330 Subject: [PATCH 30/85] Fixed more issues --- .../indicode/fabric/itsmine/BlockUtils.java | 4 + .../github/indicode/fabric/itsmine/Claim.java | 4 +- .../indicode/fabric/itsmine/Functions.java | 23 +++++- .../ServerPlayerInteractionManagerMixin.java | 73 +++++++++---------- 4 files changed, 60 insertions(+), 44 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java b/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java index 0d233a3..bc91f2c 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java @@ -32,4 +32,8 @@ public static boolean isLever(Block block) { public static boolean isDoor(Block block) { return block instanceof DoorBlock; } + + public static boolean isLectern(Block block) { + return block instanceof LecternBlock; + } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index d0c8416..f6e75ac 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -256,7 +256,9 @@ public enum Permission { CONTAINER("container", "Open Containers"), CONTAINER_ENDERCHEST("container.enderchest", "Open Enderchests"), CONTAINER_CHEST("container.chest", "Open Chests"), - CONTAINER_SHULKERBOX("container.shulkerbox", "Open Shulker Boxes"); + CONTAINER_SHULKERBOX("container.shulkerbox", "Open Shulker Boxes"), + USE_LECTERN("use.lectern", "Use Lectern") + ; String id, name; Permission(String id, String name) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index e41d054..b1d49ca 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -3,10 +3,12 @@ import io.github.indicode.fabric.itsmine.mixin.BlockActionPacketMixin; import io.github.indicode.fabric.itsmine.mixin.BucketItemMixin; import io.github.indicode.fabric.permissions.Thimble; -import net.minecraft.block.Blocks; +import net.minecraft.block.*; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.fluid.Fluids; +import net.minecraft.item.BlockItem; import net.minecraft.item.BucketItem; +import net.minecraft.item.Item; import net.minecraft.network.Packet; import net.minecraft.network.packet.s2c.play.BlockActionS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; @@ -59,7 +61,22 @@ public static void setClaimFlying(UUID player, boolean flying) { claimFlyNow.remove(player); } } - public static void updateInventory(ServerPlayerEntity player) { - player.inventory.updateItems(); + + public static boolean canInteractWith(Claim claim, Block block, UUID player) { + return claim.hasPermission(player, Claim.Permission.INTERACT_BLOCKS) || + (BlockUtils.isButton(block) && claim.hasPermission(player, Claim.Permission.PRESS_BUTTONS)) || + (BlockUtils.isLever(block) && claim.hasPermission(player, Claim.Permission.USE_LEVERS)) || + (BlockUtils.isDoor(block) && claim.hasPermission(player, Claim.Permission.INTERACT_DOORS)) || + (BlockUtils.isContainer(block) && claim.hasPermission(player, Claim.Permission.CONTAINER)) || + (BlockUtils.isChest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_CHEST)) || + (BlockUtils.isEnderchest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_ENDERCHEST)) || + (BlockUtils.isShulkerBox(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_SHULKERBOX)) || + (BlockUtils.isLectern(block) && claim.hasPermission(player, Claim.Permission.USE_LECTERN)); + } + + public static boolean canInteractUsingItem(Claim claim, Item item, UUID player) { + return claim.hasPermission(player, Claim.Permission.USE_ITEMS_ON_BLOCKS) || + (item instanceof BlockItem && claim.hasPermission(player, Claim.Permission.BUILD)) || + (item instanceof BucketItem && claim.hasPermission(player, Claim.Permission.BUILD)); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index f2d8e9e..db4b4bf 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -20,6 +20,7 @@ import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import org.omg.PortableInterceptor.SYSTEM_EXCEPTION; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -31,64 +32,56 @@ * @author Indigo Amann */ @Mixin(ServerPlayerInteractionManager.class) -public class ServerPlayerInteractionManagerMixin { +public abstract class ServerPlayerInteractionManagerMixin { @Shadow public ServerPlayerEntity player; + @Shadow public ServerWorld world; - @Redirect(method = "interactBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;onUse(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;")) - public ActionResult activateIfPossible(BlockState state, World world, PlayerEntity playerEntity_1, Hand hand_1, BlockHitResult blockHitResult_1) { - BlockPos pos = blockHitResult_1.getBlockPos(); - Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); - if (claim != null) { - UUID uuid = playerEntity_1.getGameProfile().getId(); - if ( - claim.hasPermission(uuid, Claim.Permission.INTERACT_BLOCKS) || - (BlockUtils.isButton(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.PRESS_BUTTONS)) || - (BlockUtils.isLever(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.USE_LEVERS)) || - (BlockUtils.isDoor(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.INTERACT_DOORS)) || - (BlockUtils.isContainer(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.CONTAINER)) || - (BlockUtils.isChest(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.CONTAINER_CHEST)) || - (BlockUtils.isEnderchest(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.CONTAINER_ENDERCHEST)) || - (BlockUtils.isShulkerBox(state.getBlock()) && claim.hasPermission(uuid, Claim.Permission.CONTAINER_SHULKERBOX)) - ) { - return state.onUse(world, playerEntity_1, hand_1, blockHitResult_1); - } - else { - if (state.getBlock() instanceof DoorBlock && playerEntity_1 instanceof ServerPlayerEntity) { - DoubleBlockHalf half = state.get(DoorBlock.HALF); - ((ServerPlayerEntity) playerEntity_1).networkHandler.sendPacket(new BlockUpdateS2CPacket(world, half == DoubleBlockHalf.LOWER ? pos.up() : pos.down(1))); - } - if (BlockUtils.isContainer(state.getBlock())) { - playerEntity_1.sendMessage(Messages.MSG_OPEN_CONTAINER); - } +// @Shadow public abstract ActionResult interactBlock(PlayerEntity player, World world, ItemStack stack, Hand hand, BlockHitResult hitResult); +// +// @Shadow public abstract ActionResult interactItem(PlayerEntity player, World world, ItemStack stack, Hand hand); + @Redirect(method = "interactBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;onUse(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;")) + private ActionResult interactIfPossible(BlockState blockState, World world, PlayerEntity player, Hand hand, BlockHitResult hit) { + BlockPos pos = hit.getBlockPos(); + Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, player.world.getDimension().getType()); + System.out.println("Checking onUse"); + if (claim != null) { + if (!Functions.canInteractWith(claim, blockState.getBlock(), player.getUuid())) { + player.sendMessage(Messages.MSG_INTERACT_BLOCK); return ActionResult.FAIL; + } else { + if (blockState.getBlock() instanceof DoorBlock && player instanceof ServerPlayerEntity) { + DoubleBlockHalf blockHalf = blockState.get(DoorBlock.HALF); + ((ServerPlayerEntity) player).networkHandler.sendPacket(new BlockUpdateS2CPacket(world, blockHalf == DoubleBlockHalf.LOWER ? pos.up() : pos.down(1))); + } } + + System.out.println("Claim " + claim.name); } - player.inventory.updateItems(); - return state.onUse(world, playerEntity_1, hand_1, blockHitResult_1); + return blockState.onUse(world, player, hand, hit); } @Redirect(method = "interactBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", ordinal = 2)) - public boolean allowItemUse(ItemStack stack, PlayerEntity playerEntity_1, World world_1, ItemStack itemStack_1, Hand hand_1, BlockHitResult blockHitResult_1) { - BlockPos pos = blockHitResult_1.getBlockPos().offset(blockHitResult_1.getSide()); - Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, playerEntity_1.world.getDimension().getType()); + private boolean interactWithItemIfPossible(ItemStack stack, PlayerEntity player, World world, ItemStack itemStack, Hand hand, BlockHitResult hitResult) { + BlockPos pos = hitResult.getBlockPos().offset(hitResult.getSide()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); if (claim != null && !stack.isEmpty()) { - UUID uuid = playerEntity_1.getGameProfile().getId(); - if ( - claim.hasPermission(uuid, Claim.Permission.USE_ITEMS_ON_BLOCKS) || - (stack.getItem() instanceof BlockItem && claim.hasPermission(uuid, Claim.Permission.BUILD)) || - (stack.getItem() instanceof BucketItem && claim.hasPermission(uuid, Claim.Permission.BUILD)) - ) + if (Functions.canInteractUsingItem(claim, stack.getItem(), player.getUuid())) { return false; + } - if (!playerEntity_1.getStackInHand(hand_1).isEmpty()) - playerEntity_1.sendMessage(Messages.MSG_PLACE_BLOCK); + if (stack.getItem() instanceof BlockItem) { + player.sendMessage(Messages.MSG_PLACE_BLOCK); + } else { + player.sendMessage(Messages.MSG_INTERACT_BLOCK); + } return true; } + System.out.println("No Claim, Returning Default"); return stack.isEmpty(); } From 384fb3b99ec3f05ac7d224eb36f536f7aff45b6d Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Mon, 16 Mar 2020 07:17:55 +0330 Subject: [PATCH 31/85] Fixing more stuff Part 2 --- .../itsmine/mixin/PlaceOnUseBlockMixin.java | 6 ++--- .../ServerPlayerInteractionManagerMixin.java | 25 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java index ac4cb1f..5ab83e8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java @@ -27,13 +27,13 @@ public PlaceOnUseBlockMixin(Settings settings) { public boolean canActuallyModify(World world, PlayerEntity playerEntity_1, BlockPos blockPos_1) { if (!(world instanceof ServerWorld)) return world.canPlayerModifyAt(playerEntity_1, blockPos_1); Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, playerEntity_1.world.getDimension().getType()); - if (claim != null && claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.BUILD)) - return Functions.canPlayerActuallyModifyAt((ServerWorld) world, playerEntity_1, blockPos_1); - else { + if (claim != null && !claim.hasPermission(playerEntity_1.getUuid(), Claim.Permission.BUILD)) { if ((Object) this instanceof LilyPadItem){ ((ServerWorld)world).getChunkManager().markForUpdate(blockPos_1); } return false; } + + return world.canPlayerModifyAt(playerEntity_1, blockPos_1); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index db4b4bf..010432c 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -5,7 +5,6 @@ import net.minecraft.block.enums.DoubleBlockHalf; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; -import net.minecraft.item.BucketItem; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; @@ -19,8 +18,8 @@ import net.minecraft.util.Pair; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.registry.Registry; import net.minecraft.world.World; -import org.omg.PortableInterceptor.SYSTEM_EXCEPTION; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -45,8 +44,9 @@ public abstract class ServerPlayerInteractionManagerMixin { private ActionResult interactIfPossible(BlockState blockState, World world, PlayerEntity player, Hand hand, BlockHitResult hit) { BlockPos pos = hit.getBlockPos(); Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, player.world.getDimension().getType()); - System.out.println("Checking onUse"); if (claim != null) { + System.out.println("Can Interact with " + Registry.BLOCK.getId(blockState.getBlock()).toString() + " > " + Functions.canInteractWith(claim, blockState.getBlock(), player.getUuid())); + if (!Functions.canInteractWith(claim, blockState.getBlock(), player.getUuid())) { player.sendMessage(Messages.MSG_INTERACT_BLOCK); return ActionResult.FAIL; @@ -68,20 +68,20 @@ private boolean interactWithItemIfPossible(ItemStack stack, PlayerEntity player, BlockPos pos = hitResult.getBlockPos().offset(hitResult.getSide()); Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); if (claim != null && !stack.isEmpty()) { + + System.out.println("Can Interact using item with " + Registry.ITEM.getId(stack.getItem()).toString() + " > " + Functions.canInteractUsingItem(claim, stack.getItem(), player.getUuid())); + if (Functions.canInteractUsingItem(claim, stack.getItem(), player.getUuid())) { return false; } - if (stack.getItem() instanceof BlockItem) { + if (stack.getItem() instanceof BlockItem) { player.sendMessage(Messages.MSG_PLACE_BLOCK); - } else { - player.sendMessage(Messages.MSG_INTERACT_BLOCK); } return true; } - System.out.println("No Claim, Returning Default"); return stack.isEmpty(); } @@ -106,12 +106,13 @@ public boolean canBreak(ServerWorld world, PlayerEntity player, BlockPos pos) { Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, player.world.getDimension().getType()); if (claim != null) { UUID uuid = player.getGameProfile().getId(); - if ( - claim.hasPermission(uuid, Claim.Permission.BUILD) - ) return Functions.canPlayerActuallyModifyAt(world, player, pos); - player.sendMessage(Messages.MSG_BREAK_BLOCK); - return false; + if (!claim.hasPermission(uuid, Claim.Permission.BUILD)) { + player.sendMessage(Messages.MSG_BREAK_BLOCK); + return false; + } + } + return world.canPlayerModifyAt(player, pos); } } From 4d30e388b33028730d8344eec5003d1d62a4c4a6 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Mon, 16 Mar 2020 07:24:52 +0330 Subject: [PATCH 32/85] Fixed the issue with Fluids --- .../mixin/ServerPlayerInteractionManagerMixin.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index 010432c..7f1aeae 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -35,18 +35,11 @@ public abstract class ServerPlayerInteractionManagerMixin { @Shadow public ServerPlayerEntity player; @Shadow public ServerWorld world; - -// @Shadow public abstract ActionResult interactBlock(PlayerEntity player, World world, ItemStack stack, Hand hand, BlockHitResult hitResult); -// -// @Shadow public abstract ActionResult interactItem(PlayerEntity player, World world, ItemStack stack, Hand hand); - @Redirect(method = "interactBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;onUse(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;")) private ActionResult interactIfPossible(BlockState blockState, World world, PlayerEntity player, Hand hand, BlockHitResult hit) { BlockPos pos = hit.getBlockPos(); Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, player.world.getDimension().getType()); if (claim != null) { - System.out.println("Can Interact with " + Registry.BLOCK.getId(blockState.getBlock()).toString() + " > " + Functions.canInteractWith(claim, blockState.getBlock(), player.getUuid())); - if (!Functions.canInteractWith(claim, blockState.getBlock(), player.getUuid())) { player.sendMessage(Messages.MSG_INTERACT_BLOCK); return ActionResult.FAIL; @@ -56,8 +49,6 @@ private ActionResult interactIfPossible(BlockState blockState, World world, Play ((ServerPlayerEntity) player).networkHandler.sendPacket(new BlockUpdateS2CPacket(world, blockHalf == DoubleBlockHalf.LOWER ? pos.up() : pos.down(1))); } } - - System.out.println("Claim " + claim.name); } return blockState.onUse(world, player, hand, hit); @@ -68,9 +59,6 @@ private boolean interactWithItemIfPossible(ItemStack stack, PlayerEntity player, BlockPos pos = hitResult.getBlockPos().offset(hitResult.getSide()); Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); if (claim != null && !stack.isEmpty()) { - - System.out.println("Can Interact using item with " + Registry.ITEM.getId(stack.getItem()).toString() + " > " + Functions.canInteractUsingItem(claim, stack.getItem(), player.getUuid())); - if (Functions.canInteractUsingItem(claim, stack.getItem(), player.getUuid())) { return false; } From 9e8d2054f96bb23dfe2f203090c9b251a9742975 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Mon, 16 Mar 2020 09:42:40 +0330 Subject: [PATCH 33/85] Lots of new stuff --- .../github/indicode/fabric/itsmine/Claim.java | 7 ++- .../indicode/fabric/itsmine/EntityUtils.java | 2 +- .../indicode/fabric/itsmine/Functions.java | 41 ++++++++++++++ .../itsmine/mixin/EnderPearlItemMixin.java | 52 ++++++++++++++++++ .../itsmine/mixin/ItemFrameEntityMixin.java | 50 +++++++++++++++++ .../itsmine/mixin/ProjectileEntityMixin.java | 43 --------------- .../{ => projectile}/OwnedProjectile.java | 2 +- .../projectile/ProjectileEntityMixin.java | 53 +++++++++++++++++++ .../mixin/projectile/SnowballEntityMixin.java | 24 +++++++++ .../projectile/ThrownEggEntityMixin.java | 24 +++++++++ .../ThrownEnderpearlEntityMixin.java | 24 +++++++++ .../mixin/projectile/TridentEntityMixin.java | 24 +++++++++ src/main/resources/itsmine.mixins.json | 10 ++-- 13 files changed, 306 insertions(+), 50 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/ItemFrameEntityMixin.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java rename src/main/java/io/github/indicode/fabric/itsmine/mixin/{ => projectile}/OwnedProjectile.java (81%) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/SnowballEntityMixin.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEggEntityMixin.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEnderpearlEntityMixin.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/TridentEntityMixin.java diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index f6e75ac..059ec99 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -248,7 +248,8 @@ public enum Permission { PRESS_BUTTONS("press_buttons", "Press Buttons"), USE_LEVERS("use_levers", "Use Levers"), INTERACT_DOORS("interact_doors", "Use Doors"), - INTERACT_ENTITY("interact_with_entities", "Entity Interaction"), + INTERACT_ENTITY("interact_entity", "Entity Interaction"), + INTERACT_ITEM_FRAME("interact_entity.item_frame", "Interact with Item Frame"), DAMAGE_ENTITY("damage_entities", "Hurt Entities"), DAMAGE_ENTITY_HOSTILE("damage_entities.hostile", "Hurt Hostile Entities"), DAMAGE_ENTITY_PASSIVE("damage_entities.passive", "Hurt Passive Entities"), @@ -257,7 +258,9 @@ public enum Permission { CONTAINER_ENDERCHEST("container.enderchest", "Open Enderchests"), CONTAINER_CHEST("container.chest", "Open Chests"), CONTAINER_SHULKERBOX("container.shulkerbox", "Open Shulker Boxes"), - USE_LECTERN("use.lectern", "Use Lectern") + USE_LECTERN("use.lectern", "Use Lectern"), + USE_ITEM_FRAME("use.item_frame", "Use ItemFrame"), + USE_ENDER_PEARL("use.enderpearl", "Use Ender Pearls"), ; String id, name; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java b/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java index 74e11a8..c66baf7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java @@ -9,6 +9,6 @@ public static boolean isPassive(Entity entity) { } public static boolean isHostile(Entity entity) { - return !entity.getType().getCategory().isPeaceful(); + return !isPassive(entity); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index b1d49ca..0c7adac 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -2,15 +2,21 @@ import io.github.indicode.fabric.itsmine.mixin.BlockActionPacketMixin; import io.github.indicode.fabric.itsmine.mixin.BucketItemMixin; +import io.github.indicode.fabric.itsmine.mixin.projectile.OwnedProjectile; import io.github.indicode.fabric.permissions.Thimble; import net.minecraft.block.*; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.projectile.Projectile; +import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.entity.thrown.ThrownItemEntity; import net.minecraft.fluid.Fluids; import net.minecraft.item.BlockItem; import net.minecraft.item.BucketItem; import net.minecraft.item.Item; import net.minecraft.network.Packet; import net.minecraft.network.packet.s2c.play.BlockActionS2CPacket; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; @@ -79,4 +85,39 @@ public static boolean canInteractUsingItem(Claim claim, Item item, UUID player) (item instanceof BlockItem && claim.hasPermission(player, Claim.Permission.BUILD)) || (item instanceof BucketItem && claim.hasPermission(player, Claim.Permission.BUILD)); } + + + public static boolean canDamageWithProjectile(ThrownItemEntity thrownEntity, Entity entity) { + if (checkCanDamageWithProjectile(entity, thrownEntity.getServer(), ((OwnedProjectile) thrownEntity).getOwner())) { + thrownEntity.kill(); + return true; + } + + return false; + } + + public static boolean canDamageWithProjectile(Projectile projectile, Entity entity) { + if (checkCanDamageWithProjectile(entity, projectile.getServer(), ((OwnedProjectile) projectile).getOwner())) { + projectile.kill(); + return true; + } + + return false; + } + + public static boolean checkCanDamageWithProjectile(Entity entity, MinecraftServer server, UUID uuid) { + if (entity.world.isClient) + return true; + + ServerPlayerEntity owner = server.getPlayerManager().getPlayer(uuid); + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); + + if (claim != null && owner != null && !claim.hasPermission(owner.getUuid(), Claim.Permission.DAMAGE_ENTITY)) { + owner.sendMessage(Messages.MSG_DAMAGE_ENTITY); + return false; + } + + return true; + } + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java new file mode 100644 index 0000000..2af5eb8 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java @@ -0,0 +1,52 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import blue.endless.jankson.annotation.Nullable; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.EnderPearlItem; +import net.minecraft.item.ItemStack; +import net.minecraft.stat.Stat; +import net.minecraft.util.Hand; +import net.minecraft.world.ModifiableWorld; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(EnderPearlItem.class) +public class EnderPearlItemMixin { + @Nullable + private Claim cachedClaim = null; + + @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/ModifiableWorld;spawnEntity(Lnet/minecraft/entity/Entity;)Z")) + private boolean canSpawn(ModifiableWorld modifiableWorld, Entity entity, World world, PlayerEntity user, Hand hand) { + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.dimension); + + if (claim != null && !claim.hasPermission(user.getUuid(), Claim.Permission.USE_ENDER_PEARL)) { + cachedClaim = claim; + return false; + } + + return world.spawnEntity(entity); + } + + @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;decrement(I)V")) + private void dontRemoveItFromMyInv(ItemStack itemStack, int amount, Entity entity, World world, PlayerEntity user, Hand hand) { + if (cachedClaim != null && cachedClaim.hasPermission(user.getUuid(), Claim.Permission.USE_ENDER_PEARL)) { + return; + } + + itemStack.decrement(amount); + } + + @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;incrementStat(Lnet/minecraft/stat/Stat;)V")) + private void dontIncreaseStat(PlayerEntity playerEntity, Stat stat, Entity entity, World world, PlayerEntity user, Hand hand) { + if (cachedClaim != null && cachedClaim.hasPermission(user.getUuid(), Claim.Permission.USE_ENDER_PEARL)) { + return; + } + + user.incrementStat(stat); + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ItemFrameEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ItemFrameEntityMixin.java new file mode 100644 index 0000000..b7b189e --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ItemFrameEntityMixin.java @@ -0,0 +1,50 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.decoration.AbstractDecorationEntity; +import net.minecraft.entity.decoration.ItemFrameEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ItemFrameEntity.class) +public abstract class ItemFrameEntityMixin extends AbstractDecorationEntity { + + @Shadow private float itemDropChance; + + protected ItemFrameEntityMixin(EntityType entityType, World world) { + super(entityType, world); + } + + //Don't allow a player without perms to change the item inside + @Redirect(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z")) + private boolean canITochieTheItem(ItemStack itemStack, PlayerEntity player, Hand hand) { + Claim claim = ClaimManager.INSTANCE.getClaimAt(this.getDecorationBlockPos(), this.dimension); + + if (claim != null && !claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_ITEM_FRAME)) { + return false; + } + + return itemStack.isEmpty(); + } + + @Redirect(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ItemFrameEntity;setRotation(I)V")) + private void canIRotate(ItemFrameEntity itemFrameEntity, int value, PlayerEntity player, Hand hand) { + Claim claim = ClaimManager.INSTANCE.getClaimAt(this.getDecorationBlockPos(), this.dimension); + + if (claim != null && claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_ITEM_FRAME)) { + itemFrameEntity.setRotation(value); + } else { + player.sendMessage(Messages.MSG_INTERACT_ENTITY); + } + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java deleted file mode 100644 index eca0b71..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.github.indicode.fabric.itsmine.mixin; - -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Messages; -import net.minecraft.entity.Entity; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.Projectile; -import net.minecraft.entity.projectile.ProjectileEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.util.UUID; - -/** - * @author Indigo Amann - */ -@Mixin(ProjectileEntity.class) -public class ProjectileEntityMixin { - @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")) - public boolean imInvincible(Entity entity, DamageSource damageSource_1, float float_1) { - if (entity.world.isClient()) return entity.damage(damageSource_1, float_1); - ProjectileEntity projectile = (ProjectileEntity)(Object)this; - - if (((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()) != null) { - PlayerEntity playerEntity_1 = ((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()); - Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); - if (claim != null && entity != playerEntity_1) { - if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY)) { - playerEntity_1.sendMessage(Messages.MSG_DAMAGE_ENTITY); - projectile.kill(); // You do not want an arrow bouncing between two armor stands - return false; - } - } - } - return entity.damage(damageSource_1, float_1); - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/OwnedProjectile.java similarity index 81% rename from src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java rename to src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/OwnedProjectile.java index 1af8f84..5fe595d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/OwnedProjectile.java @@ -1,4 +1,4 @@ -package io.github.indicode.fabric.itsmine.mixin; +package io.github.indicode.fabric.itsmine.mixin.projectile; import net.minecraft.entity.projectile.Projectile; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java new file mode 100644 index 0000000..e8df830 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java @@ -0,0 +1,53 @@ +package io.github.indicode.fabric.itsmine.mixin.projectile; + +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Functions; +import io.github.indicode.fabric.itsmine.Messages; +import net.minecraft.entity.Entity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.projectile.Projectile; +import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.server.PlayerManager; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.UUID; + +/** + * @author Indigo Amann + */ +@Mixin(ProjectileEntity.class) +public abstract class ProjectileEntityMixin { + @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")) + private boolean imInvincible(Entity entity, DamageSource source, float amount) { + if (Functions.canDamageWithProjectile((ProjectileEntity) (Object) this, entity)) { + return entity.damage(source, amount); + } + + return false; + } +// public boolean imInvincible(Entity entity, DamageSource damageSource_1, float float_1) { +// if (entity.world.isClient()) return entity.damage(damageSource_1, float_1); +// ProjectileEntity projectile = (ProjectileEntity)(Object)this; +// +// if (((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()) != null) { +// PlayerEntity playerEntity_1 = ((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()); +// Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); +// if (claim != null && entity != playerEntity_1) { +// if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY)) { +// playerEntity_1.sendMessage(Messages.MSG_DAMAGE_ENTITY); +// projectile.kill(); // You do not want an arrow bouncing between two armor stands +// return false; +// } +// } +// } +// return entity.damage(damageSource_1, float_1); +// } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/SnowballEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/SnowballEntityMixin.java new file mode 100644 index 0000000..802ff37 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/SnowballEntityMixin.java @@ -0,0 +1,24 @@ +package io.github.indicode.fabric.itsmine.mixin.projectile; + +import io.github.indicode.fabric.itsmine.Functions; +import net.minecraft.entity.Entity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.thrown.SnowballEntity; +import net.minecraft.entity.thrown.ThrownItemEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(SnowballEntity.class) +public abstract class SnowballEntityMixin { + + @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")) + private boolean imInvincible(Entity entity, DamageSource source, float amount) { + if (Functions.canDamageWithProjectile((ThrownItemEntity) (Object) this, entity)) { + return entity.damage(source, amount); + } + + return false; + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEggEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEggEntityMixin.java new file mode 100644 index 0000000..210b907 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEggEntityMixin.java @@ -0,0 +1,24 @@ +package io.github.indicode.fabric.itsmine.mixin.projectile; + +import io.github.indicode.fabric.itsmine.Functions; +import net.minecraft.entity.Entity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.thrown.ThrownEggEntity; +import net.minecraft.entity.thrown.ThrownItemEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ThrownEggEntity.class) +public abstract class ThrownEggEntityMixin { + + @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")) + private boolean imInvincible(Entity entity, DamageSource source, float amount) { + if (Functions.canDamageWithProjectile((ThrownItemEntity) (Object) this, entity)) { + return entity.damage(source, amount); + } + + return false; + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEnderpearlEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEnderpearlEntityMixin.java new file mode 100644 index 0000000..9d6543a --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEnderpearlEntityMixin.java @@ -0,0 +1,24 @@ +package io.github.indicode.fabric.itsmine.mixin.projectile; + +import io.github.indicode.fabric.itsmine.Functions; +import net.minecraft.entity.Entity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.thrown.ThrownEnderpearlEntity; +import net.minecraft.entity.thrown.ThrownItemEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ThrownEnderpearlEntity.class) +public abstract class ThrownEnderpearlEntityMixin { + + @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")) + private boolean imInvincible(Entity entity, DamageSource source, float amount) { + if (Functions.canDamageWithProjectile((ThrownItemEntity) (Object) this, entity)) { + return entity.damage(source, amount); + } + + return false; + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/TridentEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/TridentEntityMixin.java new file mode 100644 index 0000000..7cd7cd8 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/TridentEntityMixin.java @@ -0,0 +1,24 @@ +package io.github.indicode.fabric.itsmine.mixin.projectile; + +import io.github.indicode.fabric.itsmine.Functions; +import net.minecraft.entity.Entity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.entity.projectile.TridentEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(TridentEntity.class) +public abstract class TridentEntityMixin { + + @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")) + private boolean imInvincible(Entity entity, DamageSource source, float amount) { + if (Functions.canDamageWithProjectile((ProjectileEntity) (Object) this, entity)) { + return entity.damage(source, amount); + } + + return false; + } + +} diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index 83be44b..4582294 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -13,7 +13,6 @@ "ExplosionMixin", "PlayerEntityMixin", "ServerPlayNetworkHandlerMixin", - "ProjectileEntityMixin", "FluidMixin", "LavaMixin", "PistonBlockMixin", @@ -22,8 +21,13 @@ "FireBlockMixin", "AbstractFireBlockMixin", "SpawnRestrictionMixin", - "OwnedProjectile", - + "projectile.OwnedProjectile", + "projectile.ProjectileEntityMixin", + "projectile.TridentEntityMixin", + "projectile.ThrownEggEntityMixin", + "projectile.SnowballEntityMixin", + "projectile.ThrownEnderpearlEntityMixin", + "ItemFrameEntityMixin", "StickClaimItemMixin", "EntityMixin" ], From 5ed04cea07685d7ba6bda0e59524ce3a003a9a9f Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Mon, 16 Mar 2020 10:28:42 +0330 Subject: [PATCH 34/85] Added new Settings --- .../indicode/fabric/itsmine/Config.java | 2 + .../indicode/fabric/itsmine/Messages.java | 2 + .../itsmine/mixin/EnderPearlItemMixin.java | 41 +++++-------------- .../itsmine/mixin/ItemFrameEntityMixin.java | 2 - .../mixin/ServerPlayNetworkHandlerMixin.java | 2 +- .../ServerPlayerInteractionManagerMixin.java | 8 +++- src/main/resources/itsmine.mixins.json | 1 + 7 files changed, 22 insertions(+), 36 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/Config.java index 2fefe1a..44cffd1 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Config.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Config.java @@ -20,6 +20,7 @@ public class Config { public static String msg_enter_default = "&eNow entering claim &6%claim%"; public static String msg_leave_default = "&eNow leaving claim &6%claim%"; public static String msg_cant_enter = "&cHey! Sorry but you don't have permission to enter this claim!"; + public static String msg_cant_use = "&cHey! Sorry but you can't to use that here!"; public static int event_msg_stay_ticks = -1; private static ModConfig modConfig = new ModConfig("itsmine"); static void sync(boolean overwrite) { @@ -37,6 +38,7 @@ static void sync(boolean overwrite) { msg_enter_default = config.getString("msg.enter_claim", msg_enter_default, "Variables: %claim% %player%"); msg_leave_default = config.getString("msg.leave_claim", msg_leave_default, "Variables: %claim% %player%"); msg_cant_enter = config.getString("msg.cant_enter", msg_cant_enter); + msg_cant_use = config.getString("msg.cant_use", msg_cant_use); event_msg_stay_ticks = config.getInt("event.msg.stay_ticks", event_msg_stay_ticks, "Sets how many ticks an event message will stay on action bar, Default: -1"); }); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 72fe02d..0bebbfc 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -33,6 +33,8 @@ public class Messages { public static final Text MSG_DAMAGE_ENTITY = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_attack_entity)).formatted(Formatting.RED)); + public static final Text MSG_CANT_USE = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_use)).formatted(Formatting.RED)); + public static final Text[] GET_STARTED = new Text[]{ header("How to Claim (Basics)") .append(line(1, "Type &6/claim stick&e then Left click with a stick on a block to set the &6first&e corner of your claim")) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java index 2af5eb8..97238ba 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java @@ -1,52 +1,31 @@ package io.github.indicode.fabric.itsmine.mixin; -import blue.endless.jankson.annotation.Nullable; import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import net.minecraft.entity.Entity; +import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.EnderPearlItem; import net.minecraft.item.ItemStack; -import net.minecraft.stat.Stat; import net.minecraft.util.Hand; -import net.minecraft.world.ModifiableWorld; +import net.minecraft.util.TypedActionResult; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(EnderPearlItem.class) public class EnderPearlItemMixin { - @Nullable - private Claim cachedClaim = null; - @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/ModifiableWorld;spawnEntity(Lnet/minecraft/entity/Entity;)Z")) - private boolean canSpawn(ModifiableWorld modifiableWorld, Entity entity, World world, PlayerEntity user, Hand hand) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.dimension); + @Inject(method = "use", at = @At(value = "HEAD")) + private void overrideUse(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> cir) { + ItemStack itemStack = user.getStackInHand(hand); + Claim claim = ClaimManager.INSTANCE.getClaimAt(user.getSenseCenterPos(), user.dimension); if (claim != null && !claim.hasPermission(user.getUuid(), Claim.Permission.USE_ENDER_PEARL)) { - cachedClaim = claim; - return false; + user.sendMessage(Messages.MSG_CANT_USE); + cir.setReturnValue(TypedActionResult.fail(itemStack)); } - - return world.spawnEntity(entity); - } - - @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;decrement(I)V")) - private void dontRemoveItFromMyInv(ItemStack itemStack, int amount, Entity entity, World world, PlayerEntity user, Hand hand) { - if (cachedClaim != null && cachedClaim.hasPermission(user.getUuid(), Claim.Permission.USE_ENDER_PEARL)) { - return; - } - - itemStack.decrement(amount); } - @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;incrementStat(Lnet/minecraft/stat/Stat;)V")) - private void dontIncreaseStat(PlayerEntity playerEntity, Stat stat, Entity entity, World world, PlayerEntity user, Hand hand) { - if (cachedClaim != null && cachedClaim.hasPermission(user.getUuid(), Claim.Permission.USE_ENDER_PEARL)) { - return; - } - - user.incrementStat(stat); - } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ItemFrameEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ItemFrameEntityMixin.java index b7b189e..dfc0a3e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ItemFrameEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ItemFrameEntityMixin.java @@ -42,8 +42,6 @@ private void canIRotate(ItemFrameEntity itemFrameEntity, int value, PlayerEntity if (claim != null && claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_ITEM_FRAME)) { itemFrameEntity.setRotation(value); - } else { - player.sendMessage(Messages.MSG_INTERACT_ENTITY); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java index b51a58e..7eb392b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java @@ -33,7 +33,7 @@ public ActionResult iSaidDontTouchMe(Entity entity, PlayerEntity playerEntity_1, Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); if (claim != null) { if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.INTERACT_ENTITY)) { - playerEntity_1.sendMessage(Messages.MSG_INTERACT_ENTITY); +// playerEntity_1.sendMessage(Messages.MSG_INTERACT_ENTITY); return ActionResult.FAIL; } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index 7f1aeae..36ef5ac 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -35,13 +35,17 @@ public abstract class ServerPlayerInteractionManagerMixin { @Shadow public ServerPlayerEntity player; @Shadow public ServerWorld world; + @Shadow private int startMiningTime; + @Redirect(method = "interactBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;onUse(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;")) - private ActionResult interactIfPossible(BlockState blockState, World world, PlayerEntity player, Hand hand, BlockHitResult hit) { + private ActionResult interactIfPossible(BlockState blockState, World world, PlayerEntity player, Hand hand, BlockHitResult hit, PlayerEntity player1, World world1, ItemStack itemStack, Hand hand1, BlockHitResult hitResult1) { BlockPos pos = hit.getBlockPos(); Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, player.world.getDimension().getType()); if (claim != null) { if (!Functions.canInteractWith(claim, blockState.getBlock(), player.getUuid())) { - player.sendMessage(Messages.MSG_INTERACT_BLOCK); + if (!itemStack.isEmpty() && !(itemStack.getItem() instanceof BlockItem)) { + player.sendMessage(Messages.MSG_INTERACT_BLOCK); + } return ActionResult.FAIL; } else { if (blockState.getBlock() instanceof DoorBlock && player instanceof ServerPlayerEntity) { diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index 4582294..b6ae48c 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -28,6 +28,7 @@ "projectile.SnowballEntityMixin", "projectile.ThrownEnderpearlEntityMixin", "ItemFrameEntityMixin", + "EnderPearlItemMixin", "StickClaimItemMixin", "EntityMixin" ], From c5309c5f41d7765d82b8e0c0c1d1f31a50dbe803 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Mon, 16 Mar 2020 11:17:09 +0330 Subject: [PATCH 35/85] More fixes --- gradle.properties | 2 +- .../indicode/fabric/itsmine/BlockUtils.java | 1 - .../github/indicode/fabric/itsmine/Claim.java | 5 +- .../indicode/fabric/itsmine/EntityUtils.java | 10 ++++ .../indicode/fabric/itsmine/Functions.java | 3 +- .../itsmine/mixin/EnderPearlItemMixin.java | 4 +- .../itsmine/mixin/ItemFrameEntityMixin.java | 48 ------------------- .../itsmine/mixin/PlayerEntityMixin.java | 13 ++--- .../ServerPlayerInteractionManagerMixin.java | 3 ++ src/main/resources/itsmine.mixins.json | 1 - 10 files changed, 22 insertions(+), 68 deletions(-) delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/ItemFrameEntityMixin.java diff --git a/gradle.properties b/gradle.properties index c7036a8..7eb97e1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=20w11a+build.1 loader_version=0.7.8+build.187 # Mod Properties - mod_version = 1.6-20W11A + mod_version = 1.7-20W11A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine diff --git a/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java b/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java index bc91f2c..07aff4d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java @@ -8,7 +8,6 @@ public static boolean isContainer(Block block) { return block instanceof AbstractChestBlock || isChest(block) || isEnderchest(block) || isShulkerBox(block); } - public static boolean isChest(Block block) { return block == Blocks.CHEST || block == Blocks.BARREL; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 059ec99..c2d541f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -246,10 +246,9 @@ public enum Permission { INTERACT_BLOCKS("interact_blocks", "Interact With Blocks"), USE_ITEMS_ON_BLOCKS("use_items_on_blocks", "Use Block Modifying items"), PRESS_BUTTONS("press_buttons", "Press Buttons"), - USE_LEVERS("use_levers", "Use Levers"), + USE_LEVERS("use.levers", "Use Levers"), INTERACT_DOORS("interact_doors", "Use Doors"), INTERACT_ENTITY("interact_entity", "Entity Interaction"), - INTERACT_ITEM_FRAME("interact_entity.item_frame", "Interact with Item Frame"), DAMAGE_ENTITY("damage_entities", "Hurt Entities"), DAMAGE_ENTITY_HOSTILE("damage_entities.hostile", "Hurt Hostile Entities"), DAMAGE_ENTITY_PASSIVE("damage_entities.passive", "Hurt Passive Entities"), @@ -258,8 +257,6 @@ public enum Permission { CONTAINER_ENDERCHEST("container.enderchest", "Open Enderchests"), CONTAINER_CHEST("container.chest", "Open Chests"), CONTAINER_SHULKERBOX("container.shulkerbox", "Open Shulker Boxes"), - USE_LECTERN("use.lectern", "Use Lectern"), - USE_ITEM_FRAME("use.item_frame", "Use ItemFrame"), USE_ENDER_PEARL("use.enderpearl", "Use Ender Pearls"), ; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java b/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java index c66baf7..3cddd92 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java @@ -1,10 +1,20 @@ package io.github.indicode.fabric.itsmine; import net.minecraft.entity.Entity; +import net.minecraft.util.registry.Registry; + +import java.util.UUID; public class EntityUtils { + public static boolean canAttack(UUID player, Claim claim, Entity entity) { + return claim.hasPermission(player, Claim.Permission.DAMAGE_ENTITY) || + (isPassive(entity) && claim.hasPermission(player, Claim.Permission.DAMAGE_ENTITY_PASSIVE) || + (isHostile(entity) && claim.hasPermission(player, Claim.Permission.DAMAGE_ENTITY_HOSTILE))); + } + public static boolean isPassive(Entity entity) { + System.out.println("Is Passive " + Registry.ENTITY_TYPE.getId(entity.getType()).toString() + " " + entity.getType().getCategory().isPeaceful()); return entity.getType().getCategory().isPeaceful(); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index 0c7adac..dea018d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -76,8 +76,7 @@ public static boolean canInteractWith(Claim claim, Block block, UUID player) { (BlockUtils.isContainer(block) && claim.hasPermission(player, Claim.Permission.CONTAINER)) || (BlockUtils.isChest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_CHEST)) || (BlockUtils.isEnderchest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_ENDERCHEST)) || - (BlockUtils.isShulkerBox(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_SHULKERBOX)) || - (BlockUtils.isLectern(block) && claim.hasPermission(player, Claim.Permission.USE_LECTERN)); + (BlockUtils.isShulkerBox(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_SHULKERBOX)); } public static boolean canInteractUsingItem(Claim claim, Item item, UUID player) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java index 97238ba..2f3c2e5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java @@ -17,8 +17,8 @@ @Mixin(EnderPearlItem.class) public class EnderPearlItemMixin { - @Inject(method = "use", at = @At(value = "HEAD")) - private void overrideUse(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> cir) { + @Inject(method = "use", at = @At(value = "HEAD"), cancellable = true) + private void modifyUse(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> cir) { ItemStack itemStack = user.getStackInHand(hand); Claim claim = ClaimManager.INSTANCE.getClaimAt(user.getSenseCenterPos(), user.dimension); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ItemFrameEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ItemFrameEntityMixin.java deleted file mode 100644 index dfc0a3e..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ItemFrameEntityMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -package io.github.indicode.fabric.itsmine.mixin; - -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Messages; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.decoration.AbstractDecorationEntity; -import net.minecraft.entity.decoration.ItemFrameEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Hand; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(ItemFrameEntity.class) -public abstract class ItemFrameEntityMixin extends AbstractDecorationEntity { - - @Shadow private float itemDropChance; - - protected ItemFrameEntityMixin(EntityType entityType, World world) { - super(entityType, world); - } - - //Don't allow a player without perms to change the item inside - @Redirect(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z")) - private boolean canITochieTheItem(ItemStack itemStack, PlayerEntity player, Hand hand) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(this.getDecorationBlockPos(), this.dimension); - - if (claim != null && !claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_ITEM_FRAME)) { - return false; - } - - return itemStack.isEmpty(); - } - - @Redirect(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ItemFrameEntity;setRotation(I)V")) - private void canIRotate(ItemFrameEntity itemFrameEntity, int value, PlayerEntity player, Hand hand) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(this.getDecorationBlockPos(), this.dimension); - - if (claim != null && claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_ITEM_FRAME)) { - itemFrameEntity.setRotation(value); - } - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java index 595e8e1..9c053e0 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java @@ -51,15 +51,10 @@ public void hittingIsRude(Entity entity, CallbackInfo ci) { if (entity.world.isClient()) return; PlayerEntity playerEntity_1 = (PlayerEntity)(Object)this; Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); - if (claim != null) { - if ( - !claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY) || - (EntityUtils.isHostile(entity) && !claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY_HOSTILE)) || - (EntityUtils.isPassive(entity) && !claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY_PASSIVE)) - ) { - playerEntity_1.sendMessage(Messages.MSG_DAMAGE_ENTITY); - ci.cancel(); - } + + if (claim != null && !EntityUtils.canAttack(((PlayerEntity) (Object) this).getUuid(), claim, entity)) { + playerEntity_1.sendMessage(Messages.MSG_DAMAGE_ENTITY); + ci.cancel(); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index 36ef5ac..60af148 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -45,7 +45,10 @@ private ActionResult interactIfPossible(BlockState blockState, World world, Play if (!Functions.canInteractWith(claim, blockState.getBlock(), player.getUuid())) { if (!itemStack.isEmpty() && !(itemStack.getItem() instanceof BlockItem)) { player.sendMessage(Messages.MSG_INTERACT_BLOCK); + } else if (BlockUtils.isContainer(blockState.getBlock())) { + player.sendMessage(Messages.MSG_OPEN_CONTAINER); } + return ActionResult.FAIL; } else { if (blockState.getBlock() instanceof DoorBlock && player instanceof ServerPlayerEntity) { diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index b6ae48c..0718e34 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -27,7 +27,6 @@ "projectile.ThrownEggEntityMixin", "projectile.SnowballEntityMixin", "projectile.ThrownEnderpearlEntityMixin", - "ItemFrameEntityMixin", "EnderPearlItemMixin", "StickClaimItemMixin", "EntityMixin" From ab9c58cb7bc0eb1e0271d9597395c75a6741cfcb Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Mon, 16 Mar 2020 15:20:11 +0330 Subject: [PATCH 36/85] EnderDragon will no longer destory Blocks inside a Claim --- .../github/indicode/fabric/itsmine/Claim.java | 6 ++--- .../indicode/fabric/itsmine/ClaimCommand.java | 10 +++---- .../indicode/fabric/itsmine/EntityUtils.java | 2 -- .../indicode/fabric/itsmine/Functions.java | 3 +-- .../itsmine/mixin/EnderDragonEntityMixin.java | 26 +++++++++++++++++++ src/main/resources/itsmine.mixins.json | 3 ++- 6 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index c2d541f..67da86a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -236,16 +236,15 @@ public boolean is2d() { public enum Permission { //Admin - DELETE_CLAIM("delete_claim", "Delete Claim"), + REMOVE_CLAIM("remove_claim", "Remove Claim"), MODIFY_SIZE("modify_size", "Modify Claim Size"), - MODIFY_FLAGS("modify_flags", "Change Claim Flags"), + MODIFY_SETTINGS("modify_settings", "Change Claim Settings"), MODIFY_PERMISSIONS("modify_permissions", "Change Permissions"), //Normal MODIFY_PROPERTIES("modify_properties", "Modify Claim Properties"), BUILD("build", "Place/Break Blocks"), INTERACT_BLOCKS("interact_blocks", "Interact With Blocks"), USE_ITEMS_ON_BLOCKS("use_items_on_blocks", "Use Block Modifying items"), - PRESS_BUTTONS("press_buttons", "Press Buttons"), USE_LEVERS("use.levers", "Use Levers"), INTERACT_DOORS("interact_doors", "Use Doors"), INTERACT_ENTITY("interact_entity", "Entity Interaction"), @@ -258,6 +257,7 @@ public enum Permission { CONTAINER_CHEST("container.chest", "Open Chests"), CONTAINER_SHULKERBOX("container.shulkerbox", "Open Shulker Boxes"), USE_ENDER_PEARL("use.enderpearl", "Use Ender Pearls"), + USE_BUTTONS("use.button", "Use Buttons"), ; String id, name; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 9c25920..1d30a2e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -50,7 +50,7 @@ private static void validateCanAccess(ServerPlayerEntity player, Claim claim, bo throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); } - if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_FLAGS)) { + if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SETTINGS)) { throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); } } @@ -1163,7 +1163,7 @@ private static int requestDelete(ServerCommandSource sender, Claim claim, boolea sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); return 0; } - if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.DELETE_CLAIM)) { + if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { if (admin && Thimble.hasPermissionOrOp(sender, "itsmine.admin.modify", 4)) { sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); } else { @@ -1175,7 +1175,7 @@ private static int requestDelete(ServerCommandSource sender, Claim claim, boolea .append(new LiteralText("[I'M SURE]").setStyle(new Style() .setColor(Formatting.DARK_RED) .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " destroy " + claim.name + " confirm")))), false); + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")))), false); return 0; } private static int delete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { @@ -1183,7 +1183,7 @@ private static int delete(ServerCommandSource sender, Claim claim, boolean admin sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); return 0; } - if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.DELETE_CLAIM)) { + if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { if (admin && Thimble.hasPermissionOrOp(sender, "itsmine.admin.modify", 4)) { sender.sendFeedback(new LiteralText("Deleting a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); } else { @@ -1196,7 +1196,7 @@ private static int delete(ServerCommandSource sender, Claim claim, boolean admin sender.getWorld().getPlayers().forEach(playerEntity -> { if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true); }); - sender.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.DELETE_CLAIM)); + sender.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)); return 0; } private static int requestTransfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java b/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java index 3cddd92..c113083 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java @@ -1,7 +1,6 @@ package io.github.indicode.fabric.itsmine; import net.minecraft.entity.Entity; -import net.minecraft.util.registry.Registry; import java.util.UUID; @@ -14,7 +13,6 @@ public static boolean canAttack(UUID player, Claim claim, Entity entity) { } public static boolean isPassive(Entity entity) { - System.out.println("Is Passive " + Registry.ENTITY_TYPE.getId(entity.getType()).toString() + " " + entity.getType().getCategory().isPeaceful()); return entity.getType().getCategory().isPeaceful(); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index dea018d..4ecb184 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -8,7 +8,6 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.Projectile; -import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.entity.thrown.ThrownItemEntity; import net.minecraft.fluid.Fluids; import net.minecraft.item.BlockItem; @@ -70,7 +69,7 @@ public static void setClaimFlying(UUID player, boolean flying) { public static boolean canInteractWith(Claim claim, Block block, UUID player) { return claim.hasPermission(player, Claim.Permission.INTERACT_BLOCKS) || - (BlockUtils.isButton(block) && claim.hasPermission(player, Claim.Permission.PRESS_BUTTONS)) || + (BlockUtils.isButton(block) && claim.hasPermission(player, Claim.Permission.USE_BUTTONS)) || (BlockUtils.isLever(block) && claim.hasPermission(player, Claim.Permission.USE_LEVERS)) || (BlockUtils.isDoor(block) && claim.hasPermission(player, Claim.Permission.INTERACT_DOORS)) || (BlockUtils.isContainer(block) && claim.hasPermission(player, Claim.Permission.CONTAINER)) || diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java new file mode 100644 index 0000000..1c0a434 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java @@ -0,0 +1,26 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import net.minecraft.entity.boss.dragon.EnderDragonEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(EnderDragonEntity.class) +public class EnderDragonEntityMixin { + + @Redirect(method = "destroyBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) + private boolean dontTouchieMyBlocksStupidDragon(World world, BlockPos pos, boolean move) { + Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.dimension.getType()); + + if (claim != null && !claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) { + return false; + } + + return world.removeBlock(pos, false); + } + +} diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index 0718e34..2a25518 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -29,7 +29,8 @@ "projectile.ThrownEnderpearlEntityMixin", "EnderPearlItemMixin", "StickClaimItemMixin", - "EntityMixin" + "EntityMixin", + "EnderDragonEntityMixin" ], "client": [ "IntegratedServerMixin" From 95ef90bbb69b99a7f82cdd2eca7b448678029514 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Tue, 17 Mar 2020 10:03:15 +0330 Subject: [PATCH 37/85] Added setting break_crops and permission farm_crops, You can't spawn boats in claims anymroe, --- .../github/indicode/fabric/itsmine/Claim.java | 14 +++--- .../indicode/fabric/itsmine/ClaimCommand.java | 12 ++++- .../indicode/fabric/itsmine/Config.java | 7 ++- .../indicode/fabric/itsmine/Messages.java | 11 +++-- .../fabric/itsmine/mixin/BoatItemMixin.java | 46 +++++++++++++++++++ .../fabric/itsmine/mixin/ExplosionMixin.java | 15 +++--- .../itsmine/mixin/FarmlandBlockMixin.java | 26 +++++++++++ .../ServerPlayerInteractionManagerMixin.java | 6 +-- src/main/resources/itsmine.mixins.json | 4 +- 9 files changed, 116 insertions(+), 25 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 67da86a..fc5b800 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -237,11 +237,11 @@ public boolean is2d() { public enum Permission { //Admin REMOVE_CLAIM("remove_claim", "Remove Claim"), - MODIFY_SIZE("modify_size", "Modify Claim Size"), - MODIFY_SETTINGS("modify_settings", "Change Claim Settings"), - MODIFY_PERMISSIONS("modify_permissions", "Change Permissions"), + MODIFY_SIZE("modify.size", "Modify Claim Size"), + MODIFY_SETTINGS("modify.settings", "Change Claim Settings"), + MODIFY_PERMISSIONS("modify.permissions", "Change Permissions"), //Normal - MODIFY_PROPERTIES("modify_properties", "Modify Claim Properties"), + MODIFY_PROPERTIES("modify.properties", "Modify Claim Properties"), BUILD("build", "Place/Break Blocks"), INTERACT_BLOCKS("interact_blocks", "Interact With Blocks"), USE_ITEMS_ON_BLOCKS("use_items_on_blocks", "Use Block Modifying items"), @@ -257,8 +257,7 @@ public enum Permission { CONTAINER_CHEST("container.chest", "Open Chests"), CONTAINER_SHULKERBOX("container.shulkerbox", "Open Shulker Boxes"), USE_ENDER_PEARL("use.enderpearl", "Use Ender Pearls"), - USE_BUTTONS("use.button", "Use Buttons"), - ; + USE_BUTTONS("use.button", "Use Buttons"); String id, name; Permission(String id, String name) { @@ -476,7 +475,8 @@ public enum Setting { PISTON_FROM_OUTSIDE("pistons_outside_border", "Pistons Cross border from Outside", false), MOB_SPAWNING("mob_spawn", "Natural mob spawning", true), // KEEP_INVENTORY("keep_inventory", "Keep Inventory", true), - ENTER_SOUND("enter_sound", "Enter Sound", false); + ENTER_SOUND("enter_sound", "Enter Sound", true), + BREAK_FARMLANDS("break_farmlands", "Break Farmlands", false); String id, name; boolean defaultValue; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 1d30a2e..1d0ef75 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1499,17 +1499,25 @@ private static int showTrustedList(CommandContext context, int allowed = 0; int i = 0; boolean nextColor = false; + Text perms = new LiteralText(""); + for (Claim.Permission value : Claim.Permission.values()) { if (claim.permissionManager.hasPermission(uuid, value)) { Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; - hover.append(new LiteralText(value.id).formatted(formatting)).append(" "); - if (i == 3) hover.append("\n"); + perms.append(new LiteralText(value.id).formatted(formatting)).append(" "); + if (i == 3) perms.append("\n"); allowed++; i++; nextColor = !nextColor; } } + if (allowed == Claim.Permission.values().length) { + hover.append(new LiteralText("All " + allowed + " Permissions").formatted(Formatting.YELLOW, Formatting.ITALIC)); + } else { + hover.append(perms); + } + pText.append(new LiteralText(" ") .append(new LiteralText("(").formatted(Formatting.GOLD)) .append(new LiteralText(String.valueOf(allowed)).formatted(Formatting.GREEN)) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/Config.java index 44cffd1..7e8639a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Config.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Config.java @@ -19,8 +19,10 @@ public class Config { public static String msg_attack_entity = "&c&lHey!&r&c Sorry but you can't Attack Entities here!"; public static String msg_enter_default = "&eNow entering claim &6%claim%"; public static String msg_leave_default = "&eNow leaving claim &6%claim%"; - public static String msg_cant_enter = "&cHey! Sorry but you don't have permission to enter this claim!"; - public static String msg_cant_use = "&cHey! Sorry but you can't to use that here!"; + public static String msg_cant_enter = "&c&lHey!&r&c Sorry but you don't have permission to enter this claim!"; + public static String msg_cant_use = "&c&lHey!&r&c Sorry but you can't to use that here!"; + public static String msg_cant_farm = "&c&lHey!&r&c Sorry but you can't farm crops here!"; + public static int event_msg_stay_ticks = -1; private static ModConfig modConfig = new ModConfig("itsmine"); static void sync(boolean overwrite) { @@ -39,6 +41,7 @@ static void sync(boolean overwrite) { msg_leave_default = config.getString("msg.leave_claim", msg_leave_default, "Variables: %claim% %player%"); msg_cant_enter = config.getString("msg.cant_enter", msg_cant_enter); msg_cant_use = config.getString("msg.cant_use", msg_cant_use); + msg_cant_farm = config.getString("msg.cant_farm", msg_cant_farm); event_msg_stay_ticks = config.getInt("event.msg.stay_ticks", event_msg_stay_ticks, "Sets how many ticks an event message will stay on action bar, Default: -1"); }); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 0bebbfc..98ee7d2 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -35,6 +35,8 @@ public class Messages { public static final Text MSG_CANT_USE = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_use)).formatted(Formatting.RED)); + public static final Text MSG_CANT_FARM = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_farm)).formatted(Formatting.RED)); + public static final Text[] GET_STARTED = new Text[]{ header("How to Claim (Basics)") .append(line(1, "Type &6/claim stick&e then Left click with a stick on a block to set the &6first&e corner of your claim")) @@ -94,8 +96,8 @@ public class Messages { .append(line("&6build ").append(text("&eAllows others to build (place and break blocks)"))) .append(line("&6interact_blocks ").append(text("&eAllows others to Interact (Right click) with blocks"))) .append(line("&6use_items_on_blocks ").append(text("&eAllows others to use items on blocks (Right click on blocks with an Item)"))) - .append(line("&6press_button ").append(text("&eAllows others to press Buttons"))) - .append(line("&6use_levers ").append(text("&eAllows others to ue Levers"))) + .append(line("&6use.button ").append(text("&eAllows others to press Buttons"))) + .append(line("&6use.levers ").append(text("&eAllows others to ue Levers"))) .append(line("&6interact_doors ").append(text("&eAllows others to Interact with Doors"))) .append(line("&6interact_entity ").append(text("&eAllows others to Interact with Entities (Right click on Entities)"))), @@ -108,7 +110,7 @@ public class Messages { header("Permissions") .append(line("&6container.enderchest ").append(text("&eAllows others to only open Ender Chest containers"))) .append(line("&6container.shulkerbox ").append(text("&eAllows others to only open shulkerox container"))) - .append(line("&6modify_properties ").append(text("&eAllows others to modify the properties of the claim (e.g: Join/leave messages)"))) + .append(line("&6modify.properties ").append(text("&eAllows others to modify the properties of the claim (e.g: Join/leave messages)"))) .append(line("&6container ").append(text("&eAllows others to open containers (e.g: Chest, EnderChest etc)"))) .append(line("&6container ").append(text("&eAllows others to open containers (e.g: Chest, EnderChest etc)"))) .append(line("&6container.chest ").append(text("&eAllows others to only open chest containers (Chests and Barrels)"))), @@ -124,7 +126,8 @@ public class Messages { .append(line("&6fire_damage ").append(text("Fire damages entities"))) .append(line("&6piston_from_inside ").append(text("Let pistons to move blocks to outside the claim"))) .append(line("&6mob_spawning ").append(text("Allow mobs to spawn inside the claim"))) - .append(line("&6enter_sound ").append(text("Play a sound when entering the claim"))), + .append(line("&6enter_sound ").append(text("Play a sound when entering the claim"))) + .append(line("&6break_farmlands ").append(text("Allow turning Farmlands into Dirt by jumping on them"))) }; private static Text header(String title) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java new file mode 100644 index 0000000..3b18bbf --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java @@ -0,0 +1,46 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.BoatItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.ModifiableWorld; +import net.minecraft.world.RayTraceContext; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(BoatItem.class) +public abstract class BoatItemMixin extends Item { + + public BoatItemMixin(Settings settings) { + super(settings); + } + + @Inject(method = "use", at = @At(value = "HEAD"), cancellable = true) + private void dontSpawn(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> cir) { + ItemStack itemStack = user.getStackInHand(hand); + HitResult hitResult = rayTrace(world, user, RayTraceContext.FluidHandling.ANY); + Vec3d pos = hitResult.getPos(); + + Claim claim = ClaimManager.INSTANCE.getClaimAt(new BlockPos(pos.getX(), pos.getY(), pos.getZ()), user.dimension); + + if (claim != null && !claim.hasPermission(user.getUuid(), Claim.Permission.BUILD)) { + user.sendMessage(Messages.NO_PERMISSION); + cir.setReturnValue(TypedActionResult.fail(itemStack)); + } + + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java index 83842c8..23280a3 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java @@ -18,21 +18,24 @@ @Mixin(Explosion.class) public class ExplosionMixin { @Redirect(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;")) - private BlockState theyCallMeBedrock(World world, BlockPos blockPos_1) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, world.getDimension().getType()); - if (claim != null && !world.isAir(blockPos_1) && !world.getBlockState(blockPos_1).getBlock().equals(Blocks.TNT)) { - if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) + private BlockState theyCallMeBedrock(World world, BlockPos pos) { + Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); + if (claim != null && !world.isAir(pos) && !world.getBlockState(pos).getBlock().equals(Blocks.TNT)) { + if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) { return Blocks.BEDROCK.getDefaultState(); + } } - return world.getBlockState(blockPos_1); + return world.getBlockState(pos); } + @Redirect(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isImmuneToExplosion()Z")) private boolean claimDeniesExplosion(Entity entity) { BlockPos blockPos_1 = entity.getSenseCenterPos(); Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, entity.world.getDimension().getType()); if (claim != null) { - if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DAMAGE)) + if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DAMAGE)) { return true; + } } return entity.isImmuneToExplosion(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java new file mode 100644 index 0000000..b92a669 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java @@ -0,0 +1,26 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import net.minecraft.block.FarmlandBlock; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(FarmlandBlock.class) +public abstract class FarmlandBlockMixin { + + @Inject(method = "onLandedUpon", at = @At(value = "HEAD", target = "Lnet/minecraft/block/FarmlandBlock;onLandedUpon(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;F)V")) + private void dontYouDareFarmMe(World world, BlockPos pos, Entity entity, float distance, CallbackInfo ci) { + Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.dimension.getType()); + + if (claim != null && !claim.settings.getSetting(Claim.ClaimSettings.Setting.BREAK_FARMLANDS)) { + ci.cancel(); + } + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index 60af148..cc7a495 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -46,7 +46,7 @@ private ActionResult interactIfPossible(BlockState blockState, World world, Play if (!itemStack.isEmpty() && !(itemStack.getItem() instanceof BlockItem)) { player.sendMessage(Messages.MSG_INTERACT_BLOCK); } else if (BlockUtils.isContainer(blockState.getBlock())) { - player.sendMessage(Messages.MSG_OPEN_CONTAINER); + player.addMessage(Messages.MSG_OPEN_CONTAINER, true); } return ActionResult.FAIL; @@ -71,7 +71,7 @@ private boolean interactWithItemIfPossible(ItemStack stack, PlayerEntity player, } if (stack.getItem() instanceof BlockItem) { - player.sendMessage(Messages.MSG_PLACE_BLOCK); + player.addMessage(Messages.MSG_PLACE_BLOCK, true); } return true; @@ -102,7 +102,7 @@ public boolean canBreak(ServerWorld world, PlayerEntity player, BlockPos pos) { if (claim != null) { UUID uuid = player.getGameProfile().getId(); if (!claim.hasPermission(uuid, Claim.Permission.BUILD)) { - player.sendMessage(Messages.MSG_BREAK_BLOCK); + player.addMessage(Messages.MSG_BREAK_BLOCK, true); return false; } diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index 2a25518..651d634 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -30,7 +30,9 @@ "EnderPearlItemMixin", "StickClaimItemMixin", "EntityMixin", - "EnderDragonEntityMixin" + "EnderDragonEntityMixin", + "FarmlandBlockMixin", + "BoatItemMixin" ], "client": [ "IntegratedServerMixin" From 6d6972102de2be5a7cfe9d84a7757024cd7c9991 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Tue, 17 Mar 2020 10:29:00 +0330 Subject: [PATCH 38/85] up --- gradle.properties | 2 +- .../io/github/indicode/fabric/itsmine/Claim.java | 12 +++++++++--- .../github/indicode/fabric/itsmine/ClaimManager.java | 7 ++++++- .../fabric/itsmine/mixin/FarmlandBlockMixin.java | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 7eb97e1..7a5acc3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=20w11a+build.1 loader_version=0.7.8+build.187 # Mod Properties - mod_version = 1.7-20W11A + mod_version = 1.8-20W11A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index fc5b800..361ca94 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -71,14 +71,20 @@ public boolean intersects(Claim claim, boolean checkOther) { ) return true; else return checkOther && claim.intersects(this, false); } + @Nullable public Claim getZoneCovering(BlockPos pos) { if (includesPosition(pos)) { for (Claim child : children) { Claim value = child.getZoneCovering(pos); - if (value != null) return value; + if (value != null) { + return value; + } } + return this; - } else return null; + } + + return null; } /*public ClaimSettings getSettingsAt(BlockPos pos) { Claim at = getZoneCovering(pos); @@ -475,7 +481,7 @@ public enum Setting { PISTON_FROM_OUTSIDE("pistons_outside_border", "Pistons Cross border from Outside", false), MOB_SPAWNING("mob_spawn", "Natural mob spawning", true), // KEEP_INVENTORY("keep_inventory", "Keep Inventory", true), - ENTER_SOUND("enter_sound", "Enter Sound", true), + ENTER_SOUND("enter_sound", "Enter Sound", false), BREAK_FARMLANDS("break_farmlands", "Break Farmlands", false); String id, name; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java index 77a083a..7d0a256 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java @@ -9,6 +9,7 @@ import net.minecraft.util.Pair; import net.minecraft.util.math.BlockPos; import net.minecraft.world.dimension.DimensionType; +import org.jetbrains.annotations.Nullable; import javax.naming.Name; import java.util.*; @@ -85,10 +86,14 @@ public CompoundTag toNBT() { tag.put("ignoring", ignoring); return tag; } + @Nullable public Claim getClaimAt(BlockPos pos, DimensionType dimension) { for (Claim claim : claimsByName.values()) { - if (claim.dimension.equals(dimension) && claim.includesPosition(pos)) return claim.getZoneCovering(pos); + if (claim.dimension.equals(dimension) && claim.includesPosition(pos)) { + return claim.getZoneCovering(pos); + } } + return null; } public void fromNBT(CompoundTag tag) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java index b92a669..de3271e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java @@ -14,7 +14,7 @@ @Mixin(FarmlandBlock.class) public abstract class FarmlandBlockMixin { - @Inject(method = "onLandedUpon", at = @At(value = "HEAD", target = "Lnet/minecraft/block/FarmlandBlock;onLandedUpon(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;F)V")) + @Inject(method = "onLandedUpon", at = @At(value = "HEAD", target = "Lnet/minecraft/block/FarmlandBlock;onLandedUpon(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;F)V"), cancellable = true) private void dontYouDareFarmMe(World world, BlockPos pos, Entity entity, float distance, CallbackInfo ci) { Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.dimension.getType()); From 2fbfd860c4bdf157186c65f0ecd029a3cb5d15c7 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Fri, 20 Mar 2020 09:47:50 +0100 Subject: [PATCH 39/85] Updated to 20w12a --- gradle.properties | 6 ++-- .../github/indicode/fabric/itsmine/Claim.java | 9 ++++-- .../indicode/fabric/itsmine/NBTUitls.java | 29 +++++++++++++++++++ .../fabric/itsmine/mixin/FireBlockMixin.java | 4 +-- .../itsmine/mixin/IntegratedServerMixin.java | 4 +-- .../itsmine/mixin/MinecraftServerMixin.java | 4 +-- 6 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/NBTUitls.java diff --git a/gradle.properties b/gradle.properties index 7a5acc3..24d5dbc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=20w11a -yarn_mappings=20w11a+build.1 +minecraft_version=20w12a +yarn_mappings=20w12a+build.3 loader_version=0.7.8+build.187 # Mod Properties - mod_version = 1.8-20W11A + mod_version = 1.8-20W12A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 361ca94..b816aa1 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -11,6 +11,8 @@ import java.util.*; +import static io.github.indicode.fabric.itsmine.NBTUitls.*; + /** * @author Indigo Amann */ @@ -185,7 +187,9 @@ public CompoundTag toTag() { { tag.put("settings", settings.toTag()); tag.put("permissions", permissionManager.toNBT()); - if (claimBlockOwner != null) tag.putUuidOld("top_owner", claimBlockOwner); + if(claimBlockOwner != null) putUUID(tag, "top_owner", claimBlockOwner); +// if (claimBlockOwner != null) tag.putUuidNew("top_owner", claimBlockOwner); + } { CompoundTag meta = new CompoundTag(); @@ -225,7 +229,8 @@ public void fromTag(CompoundTag tag) { this.settings = new ClaimSettings(tag.getCompound("settings")); permissionManager = new PermissionManager(); permissionManager.fromNBT(tag.getCompound("permissions")); - if (tag.containsUuidOld("top_owner")) claimBlockOwner = tag.getUuidOld("top_owner"); + if (containsUUID(tag, "top_owner")) claimBlockOwner = getUUID(tag,"top_owner"); + } { CompoundTag meta = tag.getCompound("meta"); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/NBTUitls.java b/src/main/java/io/github/indicode/fabric/itsmine/NBTUitls.java new file mode 100644 index 0000000..61d252f --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/NBTUitls.java @@ -0,0 +1,29 @@ +package io.github.indicode.fabric.itsmine; + + +import net.minecraft.nbt.CompoundTag; + +import java.util.UUID; + +public class NBTUitls { + + public static UUID getUUID(CompoundTag tag, String key){ + if (tag.contains(key + "Least") && tag.contains(key + "Most")) { + final long least = tag.getLong(key + "Least"); + final long most = tag.getLong(key + "Most"); + return new UUID (most, least); + } + + return tag.getUuidNew(key); + } + + public static boolean containsUUID(CompoundTag tag, String key){ + return tag.contains(key + "Least") && tag.contains(key + "Most"); + } + + public static void putUUID(CompoundTag tag, String key, UUID uuid){ + tag.putLong(key + "Least", uuid.getLeastSignificantBits()); + tag.putLong(key + "Most", uuid.getMostSignificantBits()); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java index 417575e..f3bf0fe 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java @@ -26,7 +26,7 @@ public abstract class FireBlockMixin { @Shadow protected abstract void trySpreadingFire(World world_1, BlockPos blockPos_1, int int_1, Random random_1, int int_2); - @Redirect(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/FireBlock;trySpreadingFire(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;ILjava/util/Random;I)V")) + @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/FireBlock;trySpreadingFire(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;ILjava/util/Random;I)V")) private void dontBurnClaims(FireBlock fireBlock, World world, BlockPos newPos, int int_1, Random random_1, int int_2, BlockState blockState_1, ServerWorld serverWorld_1, BlockPos oldPos, Random random_1_) { Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension().getType()); Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); @@ -43,7 +43,7 @@ else if (newClaim == null) { } trySpreadingFire(world, newPos, int_1, random_1, int_2); } - @Redirect(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", ordinal = 1)) + @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", ordinal = 1)) private boolean dontCauseFire2(ServerWorld world, BlockPos newPos, BlockState blockState_1, int int_1, BlockState blockState_1_, ServerWorld serverWorld_1, BlockPos oldPos, Random random_1_) { Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension().getType()); Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java index 1aced76..efb706b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java @@ -2,11 +2,11 @@ import com.google.gson.JsonElement; import io.github.indicode.fabric.itsmine.ClaimManager; -import net.minecraft.class_4952; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtIo; import net.minecraft.server.MinecraftServer; import net.minecraft.server.integrated.IntegratedServer; +import net.minecraft.world.level.LevelGeneratorOptions; import net.minecraft.world.level.LevelGeneratorType; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -24,7 +24,7 @@ @Mixin(IntegratedServer.class) public class IntegratedServerMixin { @Inject(method = "loadWorld", at = @At("RETURN")) - private void loadClaims(String name, String serverName, long seed, class_4952 arg, CallbackInfo ci) { + private void loadClaims(String name, String serverName, long seed, LevelGeneratorOptions arg, CallbackInfo ci) { File claims = new File(((MinecraftServer)(Object)this).getLevelStorage().getSavesDirectory() + "/" + name + "/claims.dat"); File claims_old = new File(((MinecraftServer)(Object)this).getLevelStorage().getSavesDirectory() + "/" + name + "/claims.dat_old"); ClaimManager.INSTANCE = new ClaimManager(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java index 35f83d9..c617e4f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java @@ -3,11 +3,11 @@ import com.google.gson.JsonElement; import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import net.minecraft.class_4952; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.NbtIo; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.LevelGeneratorType; +import net.minecraft.world.level.LevelGeneratorOptions; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -26,7 +26,7 @@ @Mixin(MinecraftServer.class) public abstract class MinecraftServerMixin { @Inject(method = "loadWorld", at = @At("RETURN")) - private void loadClaims(String name, String serverName, long seed, class_4952 arg, CallbackInfo ci) { + private void loadClaims(String name, String serverName, long seed, LevelGeneratorOptions arg, CallbackInfo ci) { ClaimManager.INSTANCE = new ClaimManager(); File claims = new File(gameDir.getPath() + "/" + name + "/claims.dat"); File claims_old = new File(gameDir.getPath() + "/" + name + "/claims.dat_old"); From 4df3e2242c49d51cf87a07c1ed7d4be312a96071 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Fri, 20 Mar 2020 09:48:19 +0100 Subject: [PATCH 40/85] /claims doesnt show null as owner now --- .../io/github/indicode/fabric/itsmine/ClaimCommand.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 1d0ef75..7b86592 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -425,13 +425,13 @@ public static void register(CommandDispatcher dispatcher) { RequiredArgumentBuilder player = argument("player", StringArgumentType.word()); player.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.check_others", 2)); player.suggests(PLAYERS_PROVIDER); - list.executes(context -> list(context.getSource(), null)); + list.executes(context -> list(context.getSource(), context.getSource().getName())); player.executes(context -> list(context.getSource(), StringArgumentType.getString(context, "player"))); list.then(player); command.then(list); LiteralArgumentBuilder claims = literal("claims") - .executes(context -> list(context.getSource(), null)) + .executes(context -> list(context.getSource(), context.getSource().getName())) .then(player); dispatcher.register(claims); } @@ -1401,7 +1401,7 @@ private static int list(ServerCommandSource source, String target) throws Comman } - Text text = new LiteralText("\n").append(new LiteralText("Claims: " + target).formatted(Formatting.GOLD)).append("\n "); + Text text = new LiteralText("\n").append(new LiteralText("Claims (" + target + "): ").formatted(Formatting.GOLD)).append("\n "); boolean nextColor = false; for (Claim claim : claims) { Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { From 15175d82278108672e536d1b3cb1e1b4bed1cb3d Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 21 Mar 2020 01:28:40 +0430 Subject: [PATCH 41/85] ItsMine now supports both Thimble and LuckPerms --- build.gradle | 1 + gradle.properties | 1 + .../indicode/fabric/itsmine/ClaimCommand.java | 36 ++-- .../indicode/fabric/itsmine/Config.java | 2 + .../indicode/fabric/itsmine/ItsMine.java | 9 +- .../indicode/fabric/itsmine/Permissions.java | 175 ++++++++++++++++++ 6 files changed, 205 insertions(+), 19 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/Permissions.java diff --git a/build.gradle b/build.gradle index 169fca9..0043c1a 100644 --- a/build.gradle +++ b/build.gradle @@ -30,6 +30,7 @@ dependencies { //include "com.github.giantnuker:TinyConfig:${project.tiny_config_version}" implementation 'org.jetbrains:annotations:15.0' modImplementation "com.github.OnBlock:Thimble-Permissions:${project.thimble_permissions_version}" + compile "net.luckperms:api:${project.luckperms_version}" // Fabric API. This is technically optional, but you probably want it anyway. //modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" diff --git a/gradle.properties b/gradle.properties index 24d5dbc..203f098 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,4 +18,5 @@ loader_version=0.7.8+build.187 #26b2bbfb06 thimble_permissions_version=0.0.8.1 tiny_config_version = 1.1.2 +luckperms_version=5.0 #offline_info_version=1a3a7fc98b diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 7b86592..7d92d46 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -67,7 +67,7 @@ private static Predicate perm(String str) { return perm(str, 2); } private static Predicate perm(String str, int op) { - return source -> Thimble.hasPermissionOrOp(source, "itsmine." + str, op); + return source -> ItsMine.permissions().hasPermission(source, "itsmine." + str, op); } private static final Predicate PERMISSION_CHECK_ADMIN = src -> perm("admin").test(src) || perm("admin.modify_balance").test(src) || perm("admin.infinite_blocks").test(src) || perm("admin.modify").test(src) || @@ -294,7 +294,7 @@ public static void register(CommandDispatcher dispatcher) { { LiteralArgumentBuilder check = literal("blocks"); RequiredArgumentBuilder other = argument("player", EntityArgumentType.player()); - other.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.checkothers", 2)); + other.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_CHECK_OTHERS, 2)); other.executes(ctx -> checkPlayer(ctx.getSource(), EntityArgumentType.getPlayer(ctx, "player").getGameProfile().getId())); check.then(other); check.executes(ctx -> checkPlayer(ctx.getSource(), ctx.getSource().getPlayer().getGameProfile().getId())); @@ -423,7 +423,7 @@ public static void register(CommandDispatcher dispatcher) { { LiteralArgumentBuilder list = literal("list"); RequiredArgumentBuilder player = argument("player", StringArgumentType.word()); - player.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.check_others", 2)); + player.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_CHECK_OTHERS, 2)); player.suggests(PLAYERS_PROVIDER); list.executes(context -> list(context.getSource(), context.getSource().getName())); player.executes(context -> list(context.getSource(), StringArgumentType.getString(context, "player"))); @@ -479,7 +479,7 @@ public static void register(CommandDispatcher dispatcher) { admin.requires(PERMISSION_CHECK_ADMIN); { LiteralArgumentBuilder add = literal("addBlocks"); - add.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify_balance", 2)); + add.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_BALANCE, 2)); RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); amount.executes(context -> { @@ -571,7 +571,7 @@ public static void register(CommandDispatcher dispatcher) { } { LiteralArgumentBuilder remove = literal("removeBlocks"); - remove.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify_balance", 2)); + remove.requires(source ->ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_BALANCE, 2)); RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); amount.executes(context -> { @@ -585,7 +585,7 @@ public static void register(CommandDispatcher dispatcher) { } { LiteralArgumentBuilder set = literal("setBlocks"); - set.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify_balance", 2)); + set.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_BALANCE, 2)); RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); amount.executes(context -> { @@ -599,7 +599,7 @@ public static void register(CommandDispatcher dispatcher) { } { LiteralArgumentBuilder delete = literal("remove"); - delete.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify", 4)); + delete.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY, 2)); RequiredArgumentBuilder claim = getClaimArgument(); LiteralArgumentBuilder confirm = literal("confirm"); confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), true)); @@ -611,7 +611,7 @@ public static void register(CommandDispatcher dispatcher) { } { LiteralArgumentBuilder create = literal("create"); - create.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.infinite_claim", 4)); + create.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_INFINITE_CLAIM, 2)); ArgumentBuilder name = argument("name", StringArgumentType.word()); ArgumentBuilder customOwner = argument("customOwnerName", StringArgumentType.word()); ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); @@ -666,7 +666,7 @@ public static void register(CommandDispatcher dispatcher) { } { LiteralArgumentBuilder ignore = literal("ignoreClaims"); - ignore.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.ignore_claims", 4)); + ignore.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_IGNORE_CLAIMS, 2)); ignore.executes(context -> { UUID id = context.getSource().getPlayer().getGameProfile().getId(); boolean isIgnoring = ClaimManager.INSTANCE.ignoringClaims.contains(id); @@ -680,7 +680,7 @@ public static void register(CommandDispatcher dispatcher) { { { LiteralArgumentBuilder expand = literal("expand"); - expand.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.infinite_claim", 4) && Thimble.hasPermissionOrOp(source, "itsmine.admin.modify", 4)); + expand.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY, 2)); RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); direction.suggests(DIRECTION_SUGGESTION_BUILDER); @@ -707,7 +707,7 @@ public static void register(CommandDispatcher dispatcher) { } { LiteralArgumentBuilder shrink = literal("shrink"); - shrink.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.infinite_claim", 4) && Thimble.hasPermissionOrOp(source, "itsmine.admin.modify", 4)); + shrink.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY, 2)); RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); direction.suggests(DIRECTION_SUGGESTION_BUILDER); @@ -822,7 +822,7 @@ private static void createExceptionCommand(LiteralArgumentBuilder exceptions = literal("permissions"); - if (admin) exceptions.requires(source -> Thimble.hasPermissionOrOp(source, "itsmine.admin.modify_permissions", 2)); + if (admin) exceptions.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_PERMISSIONS, 2)); RequiredArgumentBuilder claim = getClaimArgument(); if (!admin) { exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); @@ -900,7 +900,7 @@ private static void createExceptionCommand(LiteralArgumentBuilder groupLiteral = literal("group"); - groupLiteral.requires(sender -> Thimble.hasPermissionOrOp(sender, "itsmine.specify_groups", 2)); + groupLiteral.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.SPECIFY_GROUPS, 2)); { RequiredArgumentBuilder group = argument("group", StringArgumentType.word()); group.suggests(PermissionCommand.SUGGESTIONS_BUILDER); @@ -1132,7 +1132,7 @@ private static int createClaim(String name, ServerCommandSource owner, BlockPos if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { if (!ClaimManager.INSTANCE.wouldIntersect(claim)) { // works because only the first statement is evaluated if true - if ((admin && Thimble.hasPermissionOrOp(owner, "itsmine.admin.infinite_blocks", 4)) || ClaimManager.INSTANCE.useClaimBlocks(ownerID, subInt)) { + if ((admin && ItsMine.permissions().hasPermission(owner, Permissions.Command.INFINITE_BLOCKS, 2)) || ClaimManager.INSTANCE.useClaimBlocks(ownerID, subInt)) { ClaimManager.INSTANCE.addClaim(claim); owner.sendFeedback(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)).append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").setStyle(new Style() .setColor(Formatting.GREEN).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))))), false); @@ -1164,7 +1164,7 @@ private static int requestDelete(ServerCommandSource sender, Claim claim, boolea return 0; } if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { - if (admin && Thimble.hasPermissionOrOp(sender, "itsmine.admin.modify", 4)) { + if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); } else { sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); @@ -1184,7 +1184,7 @@ private static int delete(ServerCommandSource sender, Claim claim, boolean admin return 0; } if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { - if (admin && Thimble.hasPermissionOrOp(sender, "itsmine.admin.modify", 4)) { + if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { sender.sendFeedback(new LiteralText("Deleting a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); } else { sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); @@ -1205,7 +1205,7 @@ private static int requestTransfer(ServerCommandSource sender, Claim claim, Serv return 0; } if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { - if (admin && Thimble.hasPermissionOrOp(sender, "itsmine.admin.modify", 4)) { + if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); } else { sender.sendFeedback(new LiteralText("You cannot transfer ownership that claim").formatted(Formatting.RED), false); @@ -1226,7 +1226,7 @@ private static int transfer(ServerCommandSource sender, Claim claim, ServerPlaye return 0; } if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { - if (admin && Thimble.hasPermissionOrOp(sender, "itsmine.admin.modify", 4)) { + if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { sender.sendFeedback(new LiteralText("Transfering ownership of a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); } else { sender.sendFeedback(new LiteralText("You cannot transfer ownership that claim").formatted(Formatting.RED), false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/Config.java index 7e8639a..29cb02b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Config.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Config.java @@ -9,6 +9,7 @@ public class Config { public static int baseClaimBlocks3d = 15625; public static int baseClaimBlocks2d = 2500; public static boolean claims2d = true; + public static String permissionManager = "luckperms"; public static String prefix = "&8[&aClaims&8]&r "; public static String msg_no_perm = "&c&lHey!&r&c Sorry but you don't have permission to do that"; public static String msg_interact_entity = "&c&lHey!&r&c Sorry but you can't interact with Entities here!"; @@ -30,6 +31,7 @@ static void sync(boolean overwrite) { claims2d = config.getBool("2D claims", claims2d, "Claims extending from y 0 to y 256"); baseClaimBlocks2d = config.getInt("2D base claim blocks", baseClaimBlocks2d, "Area Filled: " + ItsMine.blocksToAreaString2d(baseClaimBlocks2d)); baseClaimBlocks3d = config.getInt("3D base claim blocks", baseClaimBlocks3d, "Area Filled: " + ItsMine.blocksToAreaString3d(baseClaimBlocks3d)); + permissionManager = config.getString("permissionManager", permissionManager, "Values: thimble, luckperms"); prefix = config.getString("msg.prefix", prefix); msg_interact_entity = config.getString("msg.interact.entity", msg_interact_entity); msg_interact_block = config.getString("msg.interact.block", msg_interact_block); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java index 4fdb7df..a8b7a14 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java @@ -7,15 +7,20 @@ import net.minecraft.server.command.ServerCommandSource; import java.lang.reflect.InvocationTargetException; +import java.security.Permission; import java.util.UUID; /** * @author Indigo Amann */ public class ItsMine implements ModInitializer { + private static Permissions permissions; + @Override public void onInitialize() { Config.sync(false); + permissions = new Permissions(); + Thimble.permissionWriters.add((map, server) -> { map.registerPermission("itsmine.specify_groups", PermChangeBehavior.UPDATE_COMMAND_TREE); map.registerPermission("itsmine.claim_fly", (enabled, player) -> { @@ -27,12 +32,14 @@ public void onInitialize() { map.registerPermission("itsmine.admin.modify", PermChangeBehavior.UPDATE_COMMAND_TREE); map.registerPermission("itsmine.admin.modify_permissions", PermChangeBehavior.UPDATE_COMMAND_TREE); map.registerPermission("itsmine.admin.ignore_claims", PermChangeBehavior.UPDATE_COMMAND_TREE); - map.registerPermission("itsmine.admin.reload", PermChangeBehavior.UPDATE_COMMAND_TREE); }); //TODO: Enable when developing //SharedConstants.isDevelopment = true; } + public static Permissions permissions() { + return permissions; + } public static String blocksToAreaString3d(int blocks) { int base = (int) Math.floor(Math.cbrt(blocks)); int additionalBlocks = blocks - (int) Math.pow(base, 3); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java new file mode 100644 index 0000000..da98420 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java @@ -0,0 +1,175 @@ +package io.github.indicode.fabric.itsmine; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.permissions.PermChangeBehavior; +import io.github.indicode.fabric.permissions.Thimble; +import net.fabricmc.loader.api.FabricLoader; +import net.luckperms.api.LuckPerms; +import net.luckperms.api.LuckPermsProvider; +import net.luckperms.api.model.user.User; +import net.luckperms.api.query.QueryOptions; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.Logger; +import org.jetbrains.annotations.NotNull; + +import java.util.Locale; + +public class Permissions { + private final Manager manager; + private final boolean present; + + public Permissions() { + Logger logger = (Logger) LogManager.getLogger("ItsMine"); + this.manager = Manager.fromString(Config.permissionManager); + this.present = checkPresent(manager); + + logger.info("Checking " + manager.getName() +" for Availability"); + + if (!present) { + logger.warn("**** " + manager.getName() + " is not Present! Switching to vanilla operator system"); + logger.warn(" You need to install either LuckPerms for Fabric Or Thimble to manage the permissions"); + return; + } + + logger.info("Using " + manager.getName() + " as the Permission Manager"); + + if (manager == Manager.THIMBLE) { + Thimble.permissionWriters.add((map, server) -> { + for (Command value : Command.values()) { + map.registerPermission(value.NODE, PermChangeBehavior.UPDATE_COMMAND_TREE); + } + }); + } + } + + public boolean hasPermission(ServerCommandSource src, Command permission, int opLevel) { + if (present) { + if (manager == Manager.LUCKPERMS) { + return fromLuckPerms(src, permission.getNode(), opLevel); + } + + if (manager == Manager.THIMBLE) { + return fromThimble(src, permission.getNode(), opLevel); + } + } + + return src.hasPermissionLevel(opLevel); + } + + public boolean hasPermission(ServerCommandSource src, String permission, int opLevel) { + if (present) { + if (manager == Manager.LUCKPERMS) { + return fromLuckPerms(src, permission, opLevel); + } + + if (manager == Manager.THIMBLE) { + return fromThimble(src, permission, opLevel); + } + } + + return src.hasPermissionLevel(opLevel); + } + + private boolean fromLuckPerms(ServerCommandSource src, String perm, int op) { + LuckPerms luckPerms = LuckPermsProvider.get(); + + try { + ServerPlayerEntity player = src.getPlayer(); + User user = luckPerms.getUserManager().getUser(player.getUuid()); + + if (user != null) { + QueryOptions options = luckPerms.getContextManager().getQueryOptions(player); + return user.getCachedData().getPermissionData(options).checkPermission(perm).asBoolean(); + } + + } catch (CommandSyntaxException ignored) { + } + + return src.hasPermissionLevel(op); + } + + private boolean fromThimble(ServerCommandSource src, String perm, int op) { + return Thimble.hasPermissionOrOp(src, perm, op); + } + + private boolean checkPresent(Manager manager) { + if (manager == Manager.NONE) { + return false; + } + + try { + if (manager == Manager.LUCKPERMS) { + LuckPermsProvider.get(); + return true; + } + + return FabricLoader.getInstance().getModContainer(manager.getName().toLowerCase(Locale.ROOT)).isPresent(); + } catch (Exception ignored) { + return false; + } + } + + public boolean managerPresent() { + return this.present; + } + + public Manager getManager() { + return this.manager; + } + + public enum Manager { + NONE("none", ""), + LUCKPERMS("LuckPerms", "net.luckperms.api.LuckPerms"), + THIMBLE("Thimble", "io.github.indicode.fabric.permissions.Thimble"); + + private final String name; + private final String classPath; + + Manager(final String name, final String classPath) { + this.name = name; + this.classPath = classPath; + } + + public String getName() { + return this.name; + } + + public final String getClassPath() { + return this.classPath; + } + + @NotNull + public static Manager fromString(String str) { + for (Manager value : Manager.values()) { + if (value.name.equalsIgnoreCase(str)) { + return value; + } + } + + return Manager.NONE; + } + } + + public enum Command { + SPECIFY_GROUPS("specify_groups"), + CLAIM_FLY("claim_fly"), + INFINITE_BLOCKS("infinite_blocks"), + ADMIN_INFINITE_CLAIM("admin.infinite_claim"), + ADMIN_CHECK_OTHERS("admin.check_others"), + ADMIN_MODIFY_BALANCE("admin.modify_balance"), + ADMIN_MODIFY("admin.modify"), + ADMIN_MODIFY_PERMISSIONS("admin.modify_permissions"), + ADMIN_IGNORE_CLAIMS("admin.ignore_claims"); + + private final String NODE; + Command(final String node) { + this.NODE = node; + } + + public String getNode() { + return "itsmine." + this.NODE; + } + } +} From d4b258e8ca4cca2e243ebbb46e98a22103e8d955 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 21 Mar 2020 01:31:18 +0430 Subject: [PATCH 42/85] Claim setting "interact_door" now includes trap doors aswell! --- .../github/indicode/fabric/itsmine/BlockUtils.java | 2 +- .../mixin/ServerPlayerInteractionManagerMixin.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java b/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java index 07aff4d..d53eb11 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java @@ -29,7 +29,7 @@ public static boolean isLever(Block block) { } public static boolean isDoor(Block block) { - return block instanceof DoorBlock; + return block instanceof DoorBlock || block instanceof TrapdoorBlock; } public static boolean isLectern(Block block) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index cc7a495..bf9fafa 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -18,7 +18,6 @@ import net.minecraft.util.Pair; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.registry.Registry; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -50,12 +49,13 @@ private ActionResult interactIfPossible(BlockState blockState, World world, Play } return ActionResult.FAIL; - } else { - if (blockState.getBlock() instanceof DoorBlock && player instanceof ServerPlayerEntity) { - DoubleBlockHalf blockHalf = blockState.get(DoorBlock.HALF); - ((ServerPlayerEntity) player).networkHandler.sendPacket(new BlockUpdateS2CPacket(world, blockHalf == DoubleBlockHalf.LOWER ? pos.up() : pos.down(1))); - } } +// else { +// if (blockState.getBlock() instanceof DoorBlock && player instanceof ServerPlayerEntity) { +// DoubleBlockHalf blockHalf = blockState.get(DoorBlock.HALF); +// ((ServerPlayerEntity) player).networkHandler.sendPacket(new BlockUpdateS2CPacket(world, blockHalf == DoubleBlockHalf.LOWER ? pos.up() : pos.down(1))); +// } +// } } return blockState.onUse(world, player, hand, hit); From bdd59cf6bdb9087314c0f18a53d71e72f493af5b Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 21 Mar 2020 01:31:44 +0430 Subject: [PATCH 43/85] bump version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 203f098..b2fdeee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=20w12a+build.3 loader_version=0.7.8+build.187 # Mod Properties - mod_version = 1.8-20W12A + mod_version = 1.8.1-20W12A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine From 0bae563edacfa915816d1bee4d8fa3871dc29b0d Mon Sep 17 00:00:00 2001 From: DrexHD Date: Sat, 21 Mar 2020 11:18:31 +0100 Subject: [PATCH 44/85] Small Fix --- src/main/java/io/github/indicode/fabric/itsmine/Functions.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index 4ecb184..fb3d008 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -3,7 +3,6 @@ import io.github.indicode.fabric.itsmine.mixin.BlockActionPacketMixin; import io.github.indicode.fabric.itsmine.mixin.BucketItemMixin; import io.github.indicode.fabric.itsmine.mixin.projectile.OwnedProjectile; -import io.github.indicode.fabric.permissions.Thimble; import net.minecraft.block.*; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; @@ -53,7 +52,7 @@ public static boolean canClaimFly(ServerPlayerEntity player) { } } public static void refreshFly(ServerPlayerEntity player) { - flyers.put(player.getGameProfile().getId(), player.world.getServer().getPlayerManager().isOperator(player.getGameProfile()) || Thimble.PERMISSIONS.hasPermission("itsmine.claim_fly", player.getGameProfile().getId())); + flyers.put(player.getGameProfile().getId(), player.world.getServer().getPlayerManager().isOperator(player.getGameProfile()) || ItsMine.permissions().hasPermission(player.getCommandSource(),"itsmine.claim_fly",2)); } private static List claimFlyNow = new ArrayList<>(); public static boolean isClaimFlying(UUID player) { From fee5e4941fc4ec70ad18237f02ddeff0fce5e8f0 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sat, 21 Mar 2020 21:48:27 +0430 Subject: [PATCH 45/85] Fixed permissions --- .../indicode/fabric/itsmine/ClaimCommand.java | 52 +--------------- .../indicode/fabric/itsmine/Config.java | 2 +- .../indicode/fabric/itsmine/ItsMine.java | 13 ---- .../indicode/fabric/itsmine/Permissions.java | 61 ++++++++++++++++--- 4 files changed, 55 insertions(+), 73 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 7d92d46..ed1364f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -848,7 +848,6 @@ private static void createExceptionCommand(LiteralArgumentBuilder playerLiteral = literal("player"); { RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); LiteralArgumentBuilder remove = literal("remove"); @@ -897,53 +896,7 @@ private static void createExceptionCommand(LiteralArgumentBuilder groupLiteral = literal("group"); - groupLiteral.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.SPECIFY_GROUPS, 2)); - { - RequiredArgumentBuilder group = argument("group", StringArgumentType.word()); - group.suggests(PermissionCommand.SUGGESTIONS_BUILDER); - LiteralArgumentBuilder remove = literal("remove"); - remove.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - String group1 = StringArgumentType.getString(context, "group"); - verifyGroup(group1); - claim1.permissionManager.resetPermissions(group1); - context.getSource().sendFeedback(new LiteralText("Members of " + group1 + " no longer have that exception in the claim").formatted(Formatting.YELLOW), false); - } - return 0; - }); - group.then(remove); - for (Claim.Permission value : Claim.Permission.values()) { - LiteralArgumentBuilder permNode = literal(value.id); - RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); - allow.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - String group1 = StringArgumentType.getString(context, "group"); - verifyGroup(group1); - boolean permission = BoolArgumentType.getBool(context, "allow"); - modifyException(claim1, group1, value, permission); - context.getSource().sendFeedback(new LiteralText("Members of " + group1 + (permission ? " now" : " no longer") + " has the permission " + value.name).formatted(Formatting.YELLOW), false); - } - return 0; - }); - permNode.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - String group1 = StringArgumentType.getString(context, "group"); - verifyGroup(group1); - boolean permission = hasPermission(claim1, group1, value); - context.getSource().sendFeedback(new LiteralText("Members of " + group1 + (permission ? " now" : " do not") + " have the permission " + value.name).formatted(Formatting.YELLOW), false); - } - return 0; - }); - permNode.then(allow); - group.then(permNode); - } - groupLiteral.then(group); + claim.then(player); } { LiteralArgumentBuilder message = literal("message"); @@ -975,8 +928,7 @@ private static void createExceptionCommand(LiteralArgumentBuilder { - map.registerPermission("itsmine.specify_groups", PermChangeBehavior.UPDATE_COMMAND_TREE); - map.registerPermission("itsmine.claim_fly", (enabled, player) -> { - Functions.refreshFly(player); - }); - map.registerPermission("itsmine.admin.infinite_claim", PermChangeBehavior.UPDATE_COMMAND_TREE); - map.registerPermission("itsmine.admin.check_others", PermChangeBehavior.UPDATE_COMMAND_TREE); - map.registerPermission("itsmine.admin.modify_balance", PermChangeBehavior.UPDATE_COMMAND_TREE); - map.registerPermission("itsmine.admin.modify", PermChangeBehavior.UPDATE_COMMAND_TREE); - map.registerPermission("itsmine.admin.modify_permissions", PermChangeBehavior.UPDATE_COMMAND_TREE); - map.registerPermission("itsmine.admin.ignore_claims", PermChangeBehavior.UPDATE_COMMAND_TREE); - }); - //TODO: Enable when developing //SharedConstants.isDevelopment = true; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java index da98420..1e7c0d3 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java @@ -15,26 +15,36 @@ import org.jetbrains.annotations.NotNull; import java.util.Locale; +import java.util.UUID; public class Permissions { - private final Manager manager; - private final boolean present; + private Manager manager; + private boolean present; public Permissions() { Logger logger = (Logger) LogManager.getLogger("ItsMine"); + logger.info("Setting up Permissions..."); this.manager = Manager.fromString(Config.permissionManager); - this.present = checkPresent(manager); - logger.info("Checking " + manager.getName() +" for Availability"); + if (manager == Manager.VANILLA) { + this.present = false; + return; + } + + logger.info("Checking " + manager.getName() + " for Availability"); + + this.present = this.checkPresent(); - if (!present) { - logger.warn("**** " + manager.getName() + " is not Present! Switching to vanilla operator system"); + if (!this.present) { + logger.warn("**** " + manager.getName() + " is not present! Switching to vanilla operator system"); logger.warn(" You need to install either LuckPerms for Fabric Or Thimble to manage the permissions"); + this.manager = Manager.NONE; return; } logger.info("Using " + manager.getName() + " as the Permission Manager"); + if (manager == Manager.THIMBLE) { Thimble.permissionWriters.add((map, server) -> { for (Command value : Command.values()) { @@ -72,6 +82,31 @@ public boolean hasPermission(ServerCommandSource src, String permission, int opL return src.hasPermissionLevel(opLevel); } + public boolean hasPermission(UUID uuid, String permission, int opLevel) { + if (present) { + if (manager == Manager.LUCKPERMS) { + LuckPerms luckPerms = LuckPermsProvider.get(); + + try { + User user = luckPerms.getUserManager().getUser(uuid); + + if (user != null) { + QueryOptions options = luckPerms.getContextManager().getQueryOptions(user); + return user.getCachedData().getPermissionData(options).checkPermission(perm).asBoolean(); + } + + } catch (CommandSyntaxException ignored) { + } + } + + if (manager == Manager.THIMBLE) { + return fromThimble(src, permission, opLevel); + } + } + + return src.hasPermissionLevel(opLevel); + } + private boolean fromLuckPerms(ServerCommandSource src, String perm, int op) { LuckPerms luckPerms = LuckPermsProvider.get(); @@ -94,15 +129,22 @@ private boolean fromThimble(ServerCommandSource src, String perm, int op) { return Thimble.hasPermissionOrOp(src, perm, op); } - private boolean checkPresent(Manager manager) { + private boolean checkPresent() { if (manager == Manager.NONE) { return false; } try { if (manager == Manager.LUCKPERMS) { - LuckPermsProvider.get(); - return true; + try { + LuckPermsProvider.get(); + return true; + } catch (Throwable ignored) { + } + } + + if (manager == Manager.THIMBLE) { + Thimble.permissionWriters.get(0); } return FabricLoader.getInstance().getModContainer(manager.getName().toLowerCase(Locale.ROOT)).isPresent(); @@ -120,6 +162,7 @@ public Manager getManager() { } public enum Manager { + VANILLA("Vanilla", ""), NONE("none", ""), LUCKPERMS("LuckPerms", "net.luckperms.api.LuckPerms"), THIMBLE("Thimble", "io.github.indicode.fabric.permissions.Thimble"); From 82982303331bdbc75977491226efa8b2de9e6f0d Mon Sep 17 00:00:00 2001 From: DrexHD Date: Sat, 21 Mar 2020 21:07:21 +0100 Subject: [PATCH 46/85] Remove all Thimble imports --- .../indicode/fabric/itsmine/ClaimCommand.java | 8 ------ .../indicode/fabric/itsmine/Functions.java | 3 +-- .../indicode/fabric/itsmine/ItsMine.java | 8 ------ .../indicode/fabric/itsmine/Permissions.java | 26 ------------------- 4 files changed, 1 insertion(+), 44 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index ed1364f..3535aa8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -14,11 +14,8 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.suggestion.SuggestionProvider; import io.github.indicode.fabric.itsmine.mixin.BlockUpdatePacketMixin; -import io.github.indicode.fabric.permissions.Thimble; -import io.github.indicode.fabric.permissions.command.PermissionCommand; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.command.CommandException; import net.minecraft.command.EntitySelector; import net.minecraft.command.arguments.BlockPosArgumentType; import net.minecraft.command.arguments.EntityArgumentType; @@ -952,11 +949,6 @@ private static boolean verifyExists(Claim claim, CommandContext claimFlyNow = new ArrayList<>(); public static boolean isClaimFlying(UUID player) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java index 09038fb..09710cd 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java @@ -1,14 +1,6 @@ package io.github.indicode.fabric.itsmine; -import io.github.indicode.fabric.permissions.PermChangeBehavior; -import io.github.indicode.fabric.permissions.Thimble; import net.fabricmc.api.ModInitializer; -import net.minecraft.SharedConstants; -import net.minecraft.server.command.ServerCommandSource; - -import java.lang.reflect.InvocationTargetException; -import java.security.Permission; -import java.util.UUID; /** * @author Indigo Amann diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java index 1e7c0d3..a3f9553 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java @@ -81,32 +81,6 @@ public boolean hasPermission(ServerCommandSource src, String permission, int opL return src.hasPermissionLevel(opLevel); } - - public boolean hasPermission(UUID uuid, String permission, int opLevel) { - if (present) { - if (manager == Manager.LUCKPERMS) { - LuckPerms luckPerms = LuckPermsProvider.get(); - - try { - User user = luckPerms.getUserManager().getUser(uuid); - - if (user != null) { - QueryOptions options = luckPerms.getContextManager().getQueryOptions(user); - return user.getCachedData().getPermissionData(options).checkPermission(perm).asBoolean(); - } - - } catch (CommandSyntaxException ignored) { - } - } - - if (manager == Manager.THIMBLE) { - return fromThimble(src, permission, opLevel); - } - } - - return src.hasPermissionLevel(opLevel); - } - private boolean fromLuckPerms(ServerCommandSource src, String perm, int op) { LuckPerms luckPerms = LuckPermsProvider.get(); From ca4b5399ecbb98531048db45240c1207689dfe5e Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Sun, 22 Mar 2020 07:59:54 +0430 Subject: [PATCH 47/85] Fixed some issues --- .../github/indicode/fabric/itsmine/Claim.java | 14 +++++++++----- .../indicode/fabric/itsmine/ClaimCommand.java | 11 ++--------- .../indicode/fabric/itsmine/Permissions.java | 18 +++++++----------- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index b816aa1..f2c3e8b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -1,7 +1,6 @@ package io.github.indicode.fabric.itsmine; import blue.endless.jankson.annotation.Nullable; -import io.github.indicode.fabric.permissions.Thimble; import net.minecraft.nbt.*; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -11,7 +10,7 @@ import java.util.*; -import static io.github.indicode.fabric.itsmine.NBTUitls.*; +import static io.github.indicode.fabric.itsmine.NBTUtil.*; /** * @author Indigo Amann @@ -187,7 +186,7 @@ public CompoundTag toTag() { { tag.put("settings", settings.toTag()); tag.put("permissions", permissionManager.toNBT()); - if(claimBlockOwner != null) putUUID(tag, "top_owner", claimBlockOwner); + if(claimBlockOwner != null) tag.putUuidNew("top_owner", claimBlockOwner); // if (claimBlockOwner != null) tag.putUuidNew("top_owner", claimBlockOwner); } @@ -290,10 +289,15 @@ public boolean isPermissionSet(UUID player, Permission permission) { return playerPermissions.get(player) != null && playerPermissions.get(player).isPermissionSet(permission); } public boolean hasPermission(UUID player, Permission permission) { - if (isPermissionSet(player, permission)) return playerPermissions.get(player).hasPermission(permission); + if (isPermissionSet(player, permission)) + return playerPermissions.get(player).hasPermission(permission); + for (Map.Entry entry : groupPermissions.entrySet()) { - if (Thimble.PERMISSIONS.hasPermission(entry.getKey(), player) && entry.getValue().hasPermission(permission)) return true; +// if (Thimble.PERMISSIONS.hasPermission(entry.getKey(), player) && entry.getValue().hasPermission(permission)) +// return true; + return ItsMine.permissions().hasPermission(player, entry.getKey()) && entry.getValue().hasPermission(permission); } + return defaults.hasPermission(permission); } public void setPermission(UUID player, Permission permission, boolean enabled) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index ed1364f..dd18b5f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -14,11 +14,8 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.suggestion.SuggestionProvider; import io.github.indicode.fabric.itsmine.mixin.BlockUpdatePacketMixin; -import io.github.indicode.fabric.permissions.Thimble; -import io.github.indicode.fabric.permissions.command.PermissionCommand; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; -import net.minecraft.command.CommandException; import net.minecraft.command.EntitySelector; import net.minecraft.command.arguments.BlockPosArgumentType; import net.minecraft.command.arguments.EntityArgumentType; @@ -39,7 +36,8 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; -import static net.minecraft.server.command.CommandManager.*; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; /** * @author Indigo Amann @@ -952,11 +950,6 @@ private static boolean verifyExists(Claim claim, CommandContext Date: Sun, 22 Mar 2020 08:10:52 +0430 Subject: [PATCH 48/85] Updated NBTUtil --- .../fabric/itsmine/{NBTUitls.java => NBTUtil.java} | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) rename src/main/java/io/github/indicode/fabric/itsmine/{NBTUitls.java => NBTUtil.java} (71%) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/NBTUitls.java b/src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java similarity index 71% rename from src/main/java/io/github/indicode/fabric/itsmine/NBTUitls.java rename to src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java index 61d252f..0a2f59e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/NBTUitls.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java @@ -5,7 +5,7 @@ import java.util.UUID; -public class NBTUitls { +public class NBTUtil { public static UUID getUUID(CompoundTag tag, String key){ if (tag.contains(key + "Least") && tag.contains(key + "Most")) { @@ -21,9 +21,4 @@ public static boolean containsUUID(CompoundTag tag, String key){ return tag.contains(key + "Least") && tag.contains(key + "Most"); } - public static void putUUID(CompoundTag tag, String key, UUID uuid){ - tag.putLong(key + "Least", uuid.getLeastSignificantBits()); - tag.putLong(key + "Most", uuid.getMostSignificantBits()); - } - } From 44681e71ab10484587fe8e27c5e490c30ac4a487 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Mon, 23 Mar 2020 07:46:11 +0430 Subject: [PATCH 49/85] Updated to latest Yarn version --- gradle.properties | 2 +- .../github/indicode/fabric/itsmine/Claim.java | 7 +- .../indicode/fabric/itsmine/ClaimCommand.java | 69 +++++----- .../indicode/fabric/itsmine/Config.java | 8 +- .../indicode/fabric/itsmine/ItsMine.java | 11 +- .../indicode/fabric/itsmine/Messages.java | 2 +- .../indicode/fabric/itsmine/Permissions.java | 1 + .../fabric/itsmine/SubzoneCommand.java | 122 ++++++++++++++++++ .../itsmine/mixin/AbstractFireBlockMixin.java | 2 +- .../itsmine/mixin/BlockActionPacketMixin.java | 8 +- .../fabric/itsmine/mixin/BucketItemMixin.java | 2 +- .../itsmine/mixin/EnderPearlItemMixin.java | 2 +- .../fabric/itsmine/mixin/EntityMixin.java | 17 +-- .../fabric/itsmine/mixin/ExplosionMixin.java | 6 +- .../fabric/itsmine/mixin/FireBlockMixin.java | 4 +- .../itsmine/mixin/PistonBlockMixin.java | 8 +- .../itsmine/mixin/PlayerEntityMixin.java | 4 +- .../mixin/ServerPlayNetworkHandlerMixin.java | 2 +- .../ServerPlayerInteractionManagerMixin.java | 3 +- 19 files changed, 206 insertions(+), 74 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java diff --git a/gradle.properties b/gradle.properties index b2fdeee..0caa29d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use minecraft_version=20w12a -yarn_mappings=20w12a+build.3 +yarn_mappings=20w12a+build.18 loader_version=0.7.8+build.187 # Mod Properties diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index f2c3e8b..4bf6fcd 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -25,6 +25,7 @@ public class Claim { public PermissionManager permissionManager = new PermissionManager(); public UUID claimBlockOwner = null; public String customOwnerName, enterMessage, leaveMessage; + public boolean isChild = false; public Claim() { } @@ -221,7 +222,11 @@ public void fromTag(CompoundTag tag) { children = new ArrayList<>(); ListTag subzoneList = (ListTag) tag.get("subzones"); if (subzoneList != null) { - subzoneList.forEach(it -> children.add(new Claim((CompoundTag) it))); + subzoneList.forEach(it -> { + Claim claim = new Claim((CompoundTag) it); + claim.isChild = true; + children.add(claim); + }); } } { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index dd18b5f..2c0a244 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -43,6 +43,7 @@ * @author Indigo Amann */ public class ClaimCommand { + public static final int MAX_NAME_LENGTH = 30; private static void validateCanAccess(ServerPlayerEntity player, Claim claim, boolean admin) throws CommandSyntaxException { if (claim == null) { throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); @@ -90,7 +91,7 @@ private static Predicate perm(String str, int op) { public static final SuggestionProvider CLAIM_PROVIDER = (source, builder) -> { ServerPlayerEntity player = source.getSource().getPlayer(); List names = new ArrayList<>(); - Claim current = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.dimension); + Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); if (current != null) names.add(current.name); for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { if (claim != null) { @@ -151,20 +152,23 @@ private static Predicate perm(String str, int op) { return CommandSource.suggestMatching(strings, builder); }; - private static void registerHelp(LiteralArgumentBuilder builder, String id, Text[] texts, String title) { - LiteralArgumentBuilder argumentBuilder = literal(id) - .executes((context) -> sendPage(context.getSource(), texts, 1, title, "/claim help " + id + " %page%")); - RequiredArgumentBuilder pageArgument = argument("page", IntegerArgumentType.integer(1, texts.length)) - .executes((context) -> sendPage(context.getSource(), texts, IntegerArgumentType.getInteger(context, "page"), title, "/claim help " + id + " %page%")); + public static void register(CommandDispatcher dispatcher) { + LiteralArgumentBuilder main = literal("itsmine") + .requires(src -> ItsMine.permissions().hasPermission(src, Permissions.Command.COMMAND, 2)) + .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); - argumentBuilder.then(pageArgument); - builder.then(argumentBuilder); - } + register(main, dispatcher); - public static void register(CommandDispatcher dispatcher) { - LiteralArgumentBuilder command = literal("claim") + LiteralArgumentBuilder alias = literal("claim").redirect(main.build()) + .requires(src -> ItsMine.permissions().hasPermission(src, Permissions.Command.COMMAND, 2)) .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); + dispatcher.register(main); + dispatcher.register(alias); + } + + private static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { + //SubzoneCommand.register(command, false); { LiteralArgumentBuilder help = literal("help"); help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); @@ -241,9 +245,9 @@ public static void register(CommandDispatcher dispatcher) { RequiredArgumentBuilder claimArgument = getClaimArgument(); trusted.executes((context)-> { ServerPlayerEntity player = context.getSource().getPlayer(); - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.dimension); + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); if (claim == null) { - context.getSource().sendError(new LiteralText("That claim does not exist")); + context.getSource().sendError(Messages.INVALID_CLAIM); return -1; } return showTrustedList(context, claim, false); @@ -252,7 +256,7 @@ public static void register(CommandDispatcher dispatcher) { claimArgument.executes((context) -> { Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); if (claim == null) { - context.getSource().sendError(new LiteralText("That claim does not exist")); + context.getSource().sendError(Messages.INVALID_CLAIM); return -1; } return showTrustedList(context, claim, false); @@ -277,7 +281,7 @@ public static void register(CommandDispatcher dispatcher) { } { LiteralArgumentBuilder show = literal("show"); - show.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getSenseCenterPos(), context.getSource().getWorld().dimension.getType()), false)); + show.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().dimension.getType()), false)); RequiredArgumentBuilder name = argument("name", StringArgumentType.word()); name.suggests(CLAIM_PROVIDER); name.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "name")), false)); @@ -318,7 +322,7 @@ public static void register(CommandDispatcher dispatcher) { direction.suggests(DIRECTION_SUGGESTION_BUILDER); direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getSenseCenterPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), IntegerArgumentType.getInteger(context, "distance"), directionByName(StringArgumentType.getString(context, "direction")), context.getSource(), @@ -326,7 +330,7 @@ public static void register(CommandDispatcher dispatcher) { )); amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getSenseCenterPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), IntegerArgumentType.getInteger(context, "distance"), Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], context.getSource(), @@ -344,7 +348,7 @@ public static void register(CommandDispatcher dispatcher) { direction.suggests(DIRECTION_SUGGESTION_BUILDER); direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getSenseCenterPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -IntegerArgumentType.getInteger(context, "distance"), directionByName(StringArgumentType.getString(context, "direction")), context.getSource(), @@ -352,7 +356,7 @@ public static void register(CommandDispatcher dispatcher) { )); amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getSenseCenterPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -IntegerArgumentType.getInteger(context, "distance"), Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], context.getSource(), @@ -495,7 +499,7 @@ public static void register(CommandDispatcher dispatcher) { RequiredArgumentBuilder claimArgument = getClaimArgument(); newOwner.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getSenseCenterPos(), context.getSource().getPlayer().dimension); + Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); if (claim == null) { context.getSource().sendError(Messages.INVALID_CLAIM); return -1; @@ -536,7 +540,7 @@ public static void register(CommandDispatcher dispatcher) { RequiredArgumentBuilder claimArgument = getClaimArgument(); nameArgument.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getSenseCenterPos(), context.getSource().getPlayer().dimension); + Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); if (claim == null) { context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); return -1; @@ -684,7 +688,7 @@ public static void register(CommandDispatcher dispatcher) { direction.suggests(DIRECTION_SUGGESTION_BUILDER); direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getSenseCenterPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), IntegerArgumentType.getInteger(context, "distance"), directionByName(StringArgumentType.getString(context, "direction")), context.getSource(), @@ -692,7 +696,7 @@ public static void register(CommandDispatcher dispatcher) { )); amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getSenseCenterPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), IntegerArgumentType.getInteger(context, "distance"), Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], context.getSource(), @@ -711,7 +715,7 @@ public static void register(CommandDispatcher dispatcher) { direction.suggests(DIRECTION_SUGGESTION_BUILDER); direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getSenseCenterPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -IntegerArgumentType.getInteger(context, "distance"), directionByName(StringArgumentType.getString(context, "direction")), context.getSource(), @@ -719,7 +723,7 @@ public static void register(CommandDispatcher dispatcher) { )); amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getSenseCenterPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -IntegerArgumentType.getInteger(context, "distance"), Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], context.getSource(), @@ -734,7 +738,6 @@ public static void register(CommandDispatcher dispatcher) { createExceptionCommand(admin, true); command.then(admin); } - dispatcher.register(command); } private static int sendPage(ServerCommandSource source, Text[] text, int page, String title, String command) { @@ -974,7 +977,7 @@ private static void silentHideShow(ServerPlayerEntity player, Claim claim, boole BlockState block = hide ? null : Blocks.SEA_LANTERN.getDefaultState(); int showRange = 5; int closeShowRange = 8; - BlockPos pos = hide ? ((ClaimShower)player).getLastShowPos() : player.getSenseCenterPos(); + BlockPos pos = hide ? ((ClaimShower)player).getLastShowPos() : player.getBlockPos(); ((ClaimShower)player).setLastShowPos(pos); for (int x = claim.min.getX(); x <= claim.min.getX() + showRange; x++) { sendBlockPacket(player, new BlockPos(x, claim.min.getY(), claim.min.getZ()), block); @@ -1040,6 +1043,10 @@ private static void sendBlockPacket(ServerPlayerEntity player, BlockPos pos, Blo player.networkHandler.sendPacket(packet); } private static int createClaim(String name, ServerCommandSource owner, BlockPos posA, BlockPos posB, boolean admin, @Nullable String cOwnerName) throws CommandSyntaxException { + if (name.length() > MAX_NAME_LENGTH) { + owner.sendError(Messages.MSG_LONG_NAME); + return -1; + } UUID ownerID = owner.getPlayer().getGameProfile().getId(); int x, y = 0, z, mx, my = 255, mz; if (posA.getX() > posB.getX()) { @@ -1071,7 +1078,7 @@ private static int createClaim(String name, ServerCommandSource owner, BlockPos sub = sub.add(1, Config.claims2d ? 0 : 1,1); int subInt = sub.getX() * (Config.claims2d ? 1 : sub.getY()) * sub.getZ(); - Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getSenseCenterPos()); + Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos()); if (cOwnerName != null) claim.customOwnerName = cOwnerName; claim.permissionManager.playerPermissions.put(ownerID, new Claim.InvertedPermissionMap()); if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { @@ -1526,7 +1533,7 @@ private static int setEventMessage(ServerCommandSource source, Claim claim, Clai } private static int executeSetting(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { ServerPlayerEntity player = source.getPlayer(); - Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.dimension) : + Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); if (claim1 == null) { source.sendError(Messages.INVALID_CLAIM); @@ -1552,7 +1559,7 @@ private static int executeSetting(ServerCommandSource source, String input, @Nul } private static int executePermission(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { ServerPlayerEntity player = source.getPlayer(); - Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.dimension) : + Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); if (claim1 == null) { source.sendError(Messages.INVALID_CLAIM); @@ -1594,7 +1601,7 @@ private static int querySettings(ServerCommandSource source, Claim claim) { } private static int executeTrust(CommandContext context, ServerPlayerEntity target, boolean set, @Nullable String claimName) throws CommandSyntaxException { ServerPlayerEntity p = context.getSource().getPlayer(); - Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getSenseCenterPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); + Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getBlockPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); validateClaim(claim1); return setTrust(context, claim1, target, set, false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/Config.java index 14b18a7..9a7f602 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Config.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Config.java @@ -22,12 +22,12 @@ public class Config { public static String msg_leave_default = "&eNow leaving claim &6%claim%"; public static String msg_cant_enter = "&c&lHey!&r&c Sorry but you don't have permission to enter this claim!"; public static String msg_cant_use = "&c&lHey!&r&c Sorry but you can't to use that here!"; - public static String msg_cant_farm = "&c&lHey!&r&c Sorry but you can't farm crops here!"; + public static String msg_long_name = "&cThe name of the Claim must be less than 30 characters!"; public static int event_msg_stay_ticks = -1; private static ModConfig modConfig = new ModConfig("itsmine"); - static void sync(boolean overwrite) { - modConfig.configure(overwrite, config -> { + static void sync() { + modConfig.configure(false, config -> { claims2d = config.getBool("2D claims", claims2d, "Claims extending from y 0 to y 256"); baseClaimBlocks2d = config.getInt("2D base claim blocks", baseClaimBlocks2d, "Area Filled: " + ItsMine.blocksToAreaString2d(baseClaimBlocks2d)); baseClaimBlocks3d = config.getInt("3D base claim blocks", baseClaimBlocks3d, "Area Filled: " + ItsMine.blocksToAreaString3d(baseClaimBlocks3d)); @@ -43,7 +43,7 @@ static void sync(boolean overwrite) { msg_leave_default = config.getString("msg.leave_claim", msg_leave_default, "Variables: %claim% %player%"); msg_cant_enter = config.getString("msg.cant_enter", msg_cant_enter); msg_cant_use = config.getString("msg.cant_use", msg_cant_use); - msg_cant_farm = config.getString("msg.cant_farm", msg_cant_farm); + msg_long_name = config.getString("msg.long_name", msg_long_name); event_msg_stay_ticks = config.getInt("event.msg.stay_ticks", event_msg_stay_ticks, "Sets how many ticks an event message will stay on action bar, Default: -1"); }); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java index 09038fb..fff2618 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java @@ -1,14 +1,7 @@ package io.github.indicode.fabric.itsmine; -import io.github.indicode.fabric.permissions.PermChangeBehavior; -import io.github.indicode.fabric.permissions.Thimble; import net.fabricmc.api.ModInitializer; import net.minecraft.SharedConstants; -import net.minecraft.server.command.ServerCommandSource; - -import java.lang.reflect.InvocationTargetException; -import java.security.Permission; -import java.util.UUID; /** * @author Indigo Amann @@ -18,11 +11,11 @@ public class ItsMine implements ModInitializer { @Override public void onInitialize() { - Config.sync(false); + Config.sync(); permissions = new Permissions(); //TODO: Enable when developing - //SharedConstants.isDevelopment = true; + SharedConstants.isDevelopment = true; } public static Permissions permissions() { return permissions; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 98ee7d2..28c3d50 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -35,7 +35,7 @@ public class Messages { public static final Text MSG_CANT_USE = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_use)).formatted(Formatting.RED)); - public static final Text MSG_CANT_FARM = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_farm)).formatted(Formatting.RED)); + public static final Text MSG_LONG_NAME = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_long_name)).formatted(Formatting.RED)); public static final Text[] GET_STARTED = new Text[]{ header("How to Claim (Basics)") diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java index 52a078f..58d91f3 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java @@ -192,6 +192,7 @@ public static Manager fromString(String str) { } public enum Command { + COMMAND("command"), SPECIFY_GROUPS("specify_groups"), CLAIM_FLY("claim_fly"), INFINITE_BLOCKS("infinite_blocks"), diff --git a/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java new file mode 100644 index 0000000..858ad74 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java @@ -0,0 +1,122 @@ +package io.github.indicode.fabric.itsmine; + +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; +import net.minecraft.util.Formatting; +import net.minecraft.util.Pair; +import net.minecraft.util.math.BlockPos; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; + +public class SubzoneCommand { + private static final String SUB_ZONE_NAME_FORMAT = "%s.%s"; + + public static void register(LiteralArgumentBuilder command, boolean admin) { + LiteralArgumentBuilder builder = CommandManager.literal("subzone") + .requires(src -> ItsMine.permissions().hasPermission(src, Permissions.Command.COMMAND, 2)); + + { + LiteralArgumentBuilder add = CommandManager.literal("add"); + + RequiredArgumentBuilder name = CommandManager.argument("name", StringArgumentType.word()) + .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), null, admin)); + + RequiredArgumentBuilder claim = CommandManager.argument("claim", StringArgumentType.word()) + .suggests(ClaimCommand.CLAIM_PROVIDER) + .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), StringArgumentType.getString(ctx, "claim"), admin)); + + name.then(claim); + builder.then(name); + builder.then(add); + } + + command.then(builder); + } + + private static int addZone(ServerCommandSource source, String name, @Nullable String claimName, boolean admin) throws CommandSyntaxException { + if (name.length() > ClaimCommand.MAX_NAME_LENGTH) { + source.sendError(Messages.MSG_LONG_NAME); + return -1; + } + + ServerPlayerEntity player = source.getPlayer(); + Claim claim = validateAndGet(source, claimName); + Claim subZone = null; + + Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); + if (selectedPositions == null) { + source.sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getLeft() == null) { + source.sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getRight() == null) { + source.sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); + } else { + subZone = createSubzone(source, name, selectedPositions.getLeft(), selectedPositions.getRight(), admin); + if (subZone != null) { + ClaimManager.INSTANCE.stickPositions.remove(player); + + + return 1; + } + } + + return 0; + } + + private static Claim createSubzone(ServerCommandSource source, String name, BlockPos posA, BlockPos posB, boolean admin) throws CommandSyntaxException { + UUID ownerID = source.getPlayer().getGameProfile().getId(); + int x, y = 0, z, mx, my = 255, mz; + if (posA.getX() > posB.getX()) { + x = posB.getX(); + mx = posA.getX(); + } else { + x = posA.getX(); + mx = posB.getX(); + } + if (!Config.claims2d) { + if (posA.getY() > posB.getY()) { + y = posB.getY(); + my = posA.getY(); + } else { + y = posA.getY(); + my = posB.getY(); + } + } + if (posA.getZ() > posB.getZ()) { + z = posB.getZ(); + mz = posA.getZ(); + } else { + z = posA.getZ(); + mz = posB.getZ(); + } + BlockPos min = new BlockPos(x, y, z); + BlockPos max = new BlockPos(mx, my, mz); + BlockPos sub = max.subtract(min); + sub = sub.add(1, Config.claims2d ? 0 : 1,1); + + source.sendFeedback(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)).append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").setStyle(new Style().setColor(Formatting.GREEN))), false); + return new Claim(name, admin ? null : ownerID, min, max, source.getWorld().getDimension().getType(), source.getPlayer().getBlockPos()); + } + + private static Claim validateAndGet(ServerCommandSource source, @Nullable String claimName) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + Claim claim = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : + ClaimManager.INSTANCE.claimsByName.get(claimName); + + if (claim == null) { + throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); + } + + return claim; + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java index a55e74e..d1744f9 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java @@ -14,7 +14,7 @@ public abstract class AbstractFireBlockMixin { @Redirect(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isFireImmune()Z")) private boolean neverGonnaBurnYouUp(Entity entity) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.dimension); + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.dimension); if (claim != null && !claim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_DAMAGE)) { return true; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BlockActionPacketMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BlockActionPacketMixin.java index c044f66..e19fcd3 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BlockActionPacketMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BlockActionPacketMixin.java @@ -14,14 +14,14 @@ @Mixin(BlockActionS2CPacket.class) public interface BlockActionPacketMixin { @Accessor("pos") - public BlockPos getPos(); + BlockPos getPos(); @Accessor("type") - public int getType(); + int getType(); @Accessor("data") - public int getData(); + int getData(); @Accessor("block") - public Block getBlock(); + Block getBlock(); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BucketItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BucketItemMixin.java index caa36aa..d85d3fa 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BucketItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BucketItemMixin.java @@ -11,5 +11,5 @@ @Mixin(BucketItem.class) public interface BucketItemMixin { @Accessor("fluid") - public Fluid getFluid(); + Fluid getFluid(); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java index 2f3c2e5..2b5a8e1 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java @@ -20,7 +20,7 @@ public class EnderPearlItemMixin { @Inject(method = "use", at = @At(value = "HEAD"), cancellable = true) private void modifyUse(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> cir) { ItemStack itemStack = user.getStackInHand(hand); - Claim claim = ClaimManager.INSTANCE.getClaimAt(user.getSenseCenterPos(), user.dimension); + Claim claim = ClaimManager.INSTANCE.getClaimAt(user.getBlockPos(), user.dimension); if (claim != null && !claim.hasPermission(user.getUuid(), Claim.Permission.USE_ENDER_PEARL)) { user.sendMessage(Messages.MSG_CANT_USE); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index e4c073d..1b6853f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -25,22 +25,23 @@ public abstract class EntityMixin { @Shadow public World world; - @Shadow private Vec3d field_22467; + @Shadow public abstract Vec3d getPos(); + private Claim pclaim = null; @Inject(method = "setPos", at = @At("HEAD")) public void doPrePosActions(double x, double y, double z, CallbackInfo ci) { if (!world.isClient && (Object)this instanceof PlayerEntity) { PlayerEntity player = (PlayerEntity) (Object) this; - if (player.getSenseCenterPos() == null) return; - pclaim = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.world.dimension.getType()); + if (player.getBlockPos() == null) return; + pclaim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.dimension.getType()); } } @Inject(method = "setPos", at = @At("RETURN")) public void doPostPosActions(double x, double y, double z, CallbackInfo ci) { if (!world.isClient && (Object)this instanceof PlayerEntity) { PlayerEntity player = (PlayerEntity) (Object) this; - if (player.getSenseCenterPos() == null) return; - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.world.dimension.getType()); + if (player.getBlockPos() == null) return; + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.dimension.getType()); if (pclaim != claim && player instanceof ServerPlayerEntity) { ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity)player; if (serverPlayerEntity.networkHandler != null) { @@ -54,7 +55,7 @@ else if (claim != null) serverPlayerEntity.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText(ChatColor.translate(message)), -1, Config.event_msg_stay_ticks, -1)); if (claim != null && claim.settings.getSetting(Claim.ClaimSettings.Setting.ENTER_SOUND)) { - serverPlayerEntity.networkHandler.sendPacket(new PlaySoundIdS2CPacket(Registry.SOUND_EVENT.getId(SoundEvents.BLOCK_CONDUIT_ACTIVATE), SoundCategory.MASTER, this.field_22467, 2, 1.2F)); + serverPlayerEntity.networkHandler.sendPacket(new PlaySoundIdS2CPacket(Registry.SOUND_EVENT.getId(SoundEvents.BLOCK_CONDUIT_ACTIVATE), SoundCategory.MASTER, this.getPos(), 2, 1.2F)); } } } @@ -74,10 +75,10 @@ private String getFormattedEventMessage(PlayerEntity player, Claim claim, boolea public void doTickActions(CallbackInfo ci) { if (!world.isClient && (Object)this instanceof PlayerEntity) { PlayerEntity player = (PlayerEntity) (Object)this; - if (player.getSenseCenterPos() == null) + if (player.getBlockPos() == null) return; boolean old = player.abilities.allowFlying; - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getSenseCenterPos(), player.world.dimension.getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.dimension.getType()); if (player instanceof ServerPlayerEntity) { if (player.abilities.allowFlying && !player.isSpectator() && !player.isCreative() && ((claim == null || !claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) || !claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT)) && Functions.isClaimFlying(player.getGameProfile().getId()))) { player.abilities.allowFlying = false; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java index 23280a3..be3ad40 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java @@ -22,6 +22,8 @@ private BlockState theyCallMeBedrock(World world, BlockPos pos) { Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); if (claim != null && !world.isAir(pos) && !world.getBlockState(pos).getBlock().equals(Blocks.TNT)) { if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) { + System.out.println("Well hello there! a explosion is trying to blowup a block, and the setting is disabled in that claim, so imma just shadow the block as a Bedrock"); + return Blocks.BEDROCK.getDefaultState(); } } @@ -30,10 +32,12 @@ private BlockState theyCallMeBedrock(World world, BlockPos pos) { @Redirect(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isImmuneToExplosion()Z")) private boolean claimDeniesExplosion(Entity entity) { - BlockPos blockPos_1 = entity.getSenseCenterPos(); + BlockPos blockPos_1 = entity.getBlockPos(); Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, entity.world.getDimension().getType()); if (claim != null) { if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DAMAGE)) { + System.out.println("Well hello there! a explosion is trying to damage a entity, and the setting is disabled in that claim, so imma quickly make them immune to explosions"); + return true; } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java index f3bf0fe..417575e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java @@ -26,7 +26,7 @@ public abstract class FireBlockMixin { @Shadow protected abstract void trySpreadingFire(World world_1, BlockPos blockPos_1, int int_1, Random random_1, int int_2); - @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/FireBlock;trySpreadingFire(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;ILjava/util/Random;I)V")) + @Redirect(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/FireBlock;trySpreadingFire(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;ILjava/util/Random;I)V")) private void dontBurnClaims(FireBlock fireBlock, World world, BlockPos newPos, int int_1, Random random_1, int int_2, BlockState blockState_1, ServerWorld serverWorld_1, BlockPos oldPos, Random random_1_) { Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension().getType()); Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); @@ -43,7 +43,7 @@ else if (newClaim == null) { } trySpreadingFire(world, newPos, int_1, random_1, int_2); } - @Redirect(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", ordinal = 1)) + @Redirect(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", ordinal = 1)) private boolean dontCauseFire2(ServerWorld world, BlockPos newPos, BlockState blockState_1, int int_1, BlockState blockState_1_, ServerWorld serverWorld_1, BlockPos oldPos, Random random_1_) { Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension().getType()); Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java index 1322ec6..6b71ac5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java @@ -33,13 +33,13 @@ private static void youCantMoveMe(BlockState blockState_1, World world, BlockPos Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!(Boolean) newClaim.settings.getSetting(Claim.ClaimSettings.Setting.PISTON_FROM_OUTSIDE)) ci.setReturnValue(false); + if (!newClaim.settings.getSetting(Claim.ClaimSettings.Setting.PISTON_FROM_OUTSIDE)) ci.setReturnValue(false); } else if (newClaim == null) { - if (!(Boolean) oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.PISTON_FROM_INSIDE)) ci.setReturnValue(false); + if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.PISTON_FROM_INSIDE)) ci.setReturnValue(false); } else { - if (!(Boolean) oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.PISTON_FROM_INSIDE) || - !(Boolean) newClaim.settings.getSetting(Claim.ClaimSettings.Setting.PISTON_FROM_OUTSIDE)) ci.setReturnValue(false); + if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.PISTON_FROM_INSIDE) || + !newClaim.settings.getSetting(Claim.ClaimSettings.Setting.PISTON_FROM_OUTSIDE)) ci.setReturnValue(false); } } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java index 9c053e0..6f54ede 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java @@ -37,7 +37,7 @@ protected PlayerEntityMixin(EntityType entityType_1, Wor @Redirect(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;interact(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Z")) private boolean dontYouDareTouchMe(Entity entity, PlayerEntity playerEntity_1, Hand hand_1) { if (entity.world.isClient()) return entity.interact(playerEntity_1, hand_1); - Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); if (claim != null) { if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.INTERACT_ENTITY)) { playerEntity_1.sendMessage(Messages.MSG_INTERACT_ENTITY); @@ -50,7 +50,7 @@ private boolean dontYouDareTouchMe(Entity entity, PlayerEntity playerEntity_1, H public void hittingIsRude(Entity entity, CallbackInfo ci) { if (entity.world.isClient()) return; PlayerEntity playerEntity_1 = (PlayerEntity)(Object)this; - Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); if (claim != null && !EntityUtils.canAttack(((PlayerEntity) (Object) this).getUuid(), claim, entity)) { playerEntity_1.sendMessage(Messages.MSG_DAMAGE_ENTITY); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java index 7eb392b..b5c784d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java @@ -30,7 +30,7 @@ public class ServerPlayNetworkHandlerMixin { @Redirect(method = "onPlayerInteractEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;interactAt(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;")) public ActionResult iSaidDontTouchMe(Entity entity, PlayerEntity playerEntity_1, Vec3d vec3d_1, Hand hand_1) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); if (claim != null) { if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.INTERACT_ENTITY)) { // playerEntity_1.sendMessage(Messages.MSG_INTERACT_ENTITY); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index bf9fafa..007dfb6 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -32,9 +32,8 @@ @Mixin(ServerPlayerInteractionManager.class) public abstract class ServerPlayerInteractionManagerMixin { @Shadow public ServerPlayerEntity player; - @Shadow public ServerWorld world; - @Shadow private int startMiningTime; + @Shadow public ServerWorld world; @Redirect(method = "interactBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;onUse(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;")) private ActionResult interactIfPossible(BlockState blockState, World world, PlayerEntity player, Hand hand, BlockHitResult hit, PlayerEntity player1, World world1, ItemStack itemStack, Hand hand1, BlockHitResult hitResult1) { From 6986449e7568472f77308071631dd15e58df596f Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Mon, 23 Mar 2020 09:58:47 +0430 Subject: [PATCH 50/85] Updated to latest Yarn version --- build.gradle | 2 +- .../indicode/fabric/itsmine/ClaimCommand.java | 35 +++++++++++++------ .../indicode/fabric/itsmine/Functions.java | 10 +++--- .../indicode/fabric/itsmine/Permissions.java | 1 - .../fabric/itsmine/SubzoneCommand.java | 4 +-- .../fabric/itsmine/mixin/ExplosionMixin.java | 4 --- .../mixin/projectile/OwnedProjectile.java | 4 +-- .../projectile/ProjectileEntityMixin.java | 30 ++++++++-------- .../mixin/projectile/SnowballEntityMixin.java | 5 ++- .../projectile/ThrownEggEntityMixin.java | 7 ++-- .../ThrownEnderpearlEntityMixin.java | 7 ++-- 11 files changed, 57 insertions(+), 52 deletions(-) diff --git a/build.gradle b/build.gradle index 0043c1a..cba03e6 100644 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ dependencies { //include "com.github.giantnuker:TinyConfig:${project.tiny_config_version}" implementation 'org.jetbrains:annotations:15.0' modImplementation "com.github.OnBlock:Thimble-Permissions:${project.thimble_permissions_version}" - compile "net.luckperms:api:${project.luckperms_version}" + implementation "net.luckperms:api:${project.luckperms_version}" // Fabric API. This is technically optional, but you probably want it anyway. //modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 2c0a244..95456f4 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -21,6 +21,8 @@ import net.minecraft.command.arguments.EntityArgumentType; import net.minecraft.command.arguments.GameProfileArgumentType; import net.minecraft.command.arguments.PosArgument; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; import net.minecraft.server.command.CommandSource; import net.minecraft.server.command.ServerCommandSource; @@ -154,15 +156,15 @@ private static Predicate perm(String str, int op) { public static void register(CommandDispatcher dispatcher) { LiteralArgumentBuilder main = literal("itsmine") - .requires(src -> ItsMine.permissions().hasPermission(src, Permissions.Command.COMMAND, 2)) .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); register(main, dispatcher); - LiteralArgumentBuilder alias = literal("claim").redirect(main.build()) - .requires(src -> ItsMine.permissions().hasPermission(src, Permissions.Command.COMMAND, 2)) + LiteralArgumentBuilder alias = literal("claim") .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); + register(alias, dispatcher); + dispatcher.register(main); dispatcher.register(alias); } @@ -462,11 +464,11 @@ private static void register(LiteralArgumentBuilder command } { LiteralArgumentBuilder distrust = literal("distrust"); - RequiredArgumentBuilder playerArgument = argument("player", EntityArgumentType.player()); + RequiredArgumentBuilder playerArgument = argument("player", EntityArgumentType.entity()); RequiredArgumentBuilder claimArgument = getClaimArgument(); - playerArgument.executes((context -> executeTrust(context, EntityArgumentType.getPlayer(context, "player"), false, null))); - claimArgument.executes((context -> executeTrust(context, EntityArgumentType.getPlayer(context, "player"), false, StringArgumentType.getString(context, "claim")))); + playerArgument.executes((context -> executeTrust(context, EntityArgumentType.getEntity(context, "player"), false, null))); + claimArgument.executes((context -> executeTrust(context, EntityArgumentType.getEntity(context, "player"), false, StringArgumentType.getString(context, "claim")))); playerArgument.then(claimArgument); distrust.then(playerArgument); @@ -1296,7 +1298,7 @@ private static int info(ServerCommandSource source, Claim claim) { text.append(new LiteralText("Claim Info: " + claim.name).formatted(Formatting.GOLD)).append("\n"); text.append(newInfoLine("Name", new LiteralText(claim.name).formatted(Formatting.WHITE))); text.append(newInfoLine("Owner", - owner != null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : + owner != null && claim.customOwnerName == null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : claim.customOwnerName != null ? new LiteralText(claim.customOwnerName).formatted(Formatting.GOLD) : new LiteralText("Not Present").formatted(Formatting.RED, Formatting.ITALIC))); text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); @@ -1439,11 +1441,19 @@ private static int showTrustedList(CommandContext context, claim.permissionManager.playerPermissions.forEach((uuid, perm) -> { atomicInteger.incrementAndGet(); Text pText = new LiteralText(""); + Text owner; GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); - String name = profile != null ? profile.getName() : uuid.toString(); + if (profile != null) { + owner = new LiteralText(profile.getName()); + } else { + owner = new LiteralText(uuid.toString()).styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to Copy"))); + style.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); + }); + } pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) - .append(new LiteralText(name).formatted(Formatting.YELLOW)); + .append(owner.formatted(Formatting.YELLOW)); Text hover = new LiteralText(""); hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); @@ -1599,7 +1609,12 @@ private static int querySettings(ServerCommandSource source, Claim claim) { .append(Messages.Command.getSettings(claim)).append("\n"), false); return 1; } - private static int executeTrust(CommandContext context, ServerPlayerEntity target, boolean set, @Nullable String claimName) throws CommandSyntaxException { + private static int executeTrust(CommandContext context, Entity entity, boolean set, @Nullable String claimName) throws CommandSyntaxException { + if (!(entity instanceof PlayerEntity)) { + context.getSource().sendError(new LiteralText("Only Players!")); + return -1; + } + ServerPlayerEntity target = (ServerPlayerEntity) entity; ServerPlayerEntity p = context.getSource().getPlayer(); Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getBlockPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); validateClaim(claim1); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index 4ecb184..62b8807 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -7,8 +7,8 @@ import net.minecraft.block.*; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.Projectile; -import net.minecraft.entity.thrown.ThrownItemEntity; +import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.entity.projectile.thrown.ThrownEntity; import net.minecraft.fluid.Fluids; import net.minecraft.item.BlockItem; import net.minecraft.item.BucketItem; @@ -85,7 +85,7 @@ public static boolean canInteractUsingItem(Claim claim, Item item, UUID player) } - public static boolean canDamageWithProjectile(ThrownItemEntity thrownEntity, Entity entity) { + public static boolean canDamageWithProjectile(ThrownEntity thrownEntity, Entity entity) { if (checkCanDamageWithProjectile(entity, thrownEntity.getServer(), ((OwnedProjectile) thrownEntity).getOwner())) { thrownEntity.kill(); return true; @@ -94,7 +94,7 @@ public static boolean canDamageWithProjectile(ThrownItemEntity thrownEntity, Ent return false; } - public static boolean canDamageWithProjectile(Projectile projectile, Entity entity) { + public static boolean canDamageWithProjectile(ProjectileEntity projectile, Entity entity) { if (checkCanDamageWithProjectile(entity, projectile.getServer(), ((OwnedProjectile) projectile).getOwner())) { projectile.kill(); return true; @@ -108,7 +108,7 @@ public static boolean checkCanDamageWithProjectile(Entity entity, MinecraftServe return true; ServerPlayerEntity owner = server.getPlayerManager().getPlayer(uuid); - Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); if (claim != null && owner != null && !claim.hasPermission(owner.getUuid(), Claim.Permission.DAMAGE_ENTITY)) { owner.sendMessage(Messages.MSG_DAMAGE_ENTITY); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java index 58d91f3..52a078f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java @@ -192,7 +192,6 @@ public static Manager fromString(String str) { } public enum Command { - COMMAND("command"), SPECIFY_GROUPS("specify_groups"), CLAIM_FLY("claim_fly"), INFINITE_BLOCKS("infinite_blocks"), diff --git a/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java index 858ad74..70fd021 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java @@ -21,9 +21,7 @@ public class SubzoneCommand { private static final String SUB_ZONE_NAME_FORMAT = "%s.%s"; public static void register(LiteralArgumentBuilder command, boolean admin) { - LiteralArgumentBuilder builder = CommandManager.literal("subzone") - .requires(src -> ItsMine.permissions().hasPermission(src, Permissions.Command.COMMAND, 2)); - + LiteralArgumentBuilder builder = CommandManager.literal("subzone"); { LiteralArgumentBuilder add = CommandManager.literal("add"); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java index be3ad40..e8290f2 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java @@ -22,8 +22,6 @@ private BlockState theyCallMeBedrock(World world, BlockPos pos) { Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); if (claim != null && !world.isAir(pos) && !world.getBlockState(pos).getBlock().equals(Blocks.TNT)) { if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) { - System.out.println("Well hello there! a explosion is trying to blowup a block, and the setting is disabled in that claim, so imma just shadow the block as a Bedrock"); - return Blocks.BEDROCK.getDefaultState(); } } @@ -36,8 +34,6 @@ private boolean claimDeniesExplosion(Entity entity) { Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, entity.world.getDimension().getType()); if (claim != null) { if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DAMAGE)) { - System.out.println("Well hello there! a explosion is trying to damage a entity, and the setting is disabled in that claim, so imma quickly make them immune to explosions"); - return true; } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/OwnedProjectile.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/OwnedProjectile.java index 5fe595d..b987b68 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/OwnedProjectile.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/OwnedProjectile.java @@ -1,12 +1,12 @@ package io.github.indicode.fabric.itsmine.mixin.projectile; -import net.minecraft.entity.projectile.Projectile; +import net.minecraft.entity.projectile.ProjectileEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import java.util.UUID; -@Mixin(Projectile.class) +@Mixin(ProjectileEntity.class) public interface OwnedProjectile { @Accessor("ownerUuid") UUID getOwner(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java index e8df830..5b94ac5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java @@ -1,37 +1,37 @@ package io.github.indicode.fabric.itsmine.mixin.projectile; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; +import blue.endless.jankson.annotation.Nullable; import io.github.indicode.fabric.itsmine.Functions; import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.entity.Entity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.Projectile; import net.minecraft.entity.projectile.ProjectileEntity; -import net.minecraft.server.PlayerManager; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; +import net.minecraft.util.hit.EntityHitResult; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import java.util.UUID; - /** * @author Indigo Amann */ @Mixin(ProjectileEntity.class) public abstract class ProjectileEntityMixin { - @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")) - private boolean imInvincible(Entity entity, DamageSource source, float amount) { - if (Functions.canDamageWithProjectile((ProjectileEntity) (Object) this, entity)) { - return entity.damage(source, amount); - } + @Shadow protected abstract void onEntityHit(EntityHitResult entityHitResult); - return false; + @Shadow @Nullable + public abstract Entity getOwner(); + + @Redirect(method = "onCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/projectile/ProjectileEntity;onEntityHit(Lnet/minecraft/util/hit/EntityHitResult;)V")) + private void imInvincible(ProjectileEntity projectileEntity, EntityHitResult entityHitResult) { + if (Functions.canDamageWithProjectile((ProjectileEntity) (Object) this, projectileEntity)) { + this.onEntityHit(entityHitResult); + } else { + if (this.getOwner() instanceof PlayerEntity) { + this.getOwner().sendMessage(Messages.MSG_DAMAGE_ENTITY); + } + } } // public boolean imInvincible(Entity entity, DamageSource damageSource_1, float float_1) { // if (entity.world.isClient()) return entity.damage(damageSource_1, float_1); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/SnowballEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/SnowballEntityMixin.java index 802ff37..a7669ab 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/SnowballEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/SnowballEntityMixin.java @@ -3,8 +3,7 @@ import io.github.indicode.fabric.itsmine.Functions; import net.minecraft.entity.Entity; import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.thrown.SnowballEntity; -import net.minecraft.entity.thrown.ThrownItemEntity; +import net.minecraft.entity.projectile.thrown.SnowballEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -14,7 +13,7 @@ public abstract class SnowballEntityMixin { @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")) private boolean imInvincible(Entity entity, DamageSource source, float amount) { - if (Functions.canDamageWithProjectile((ThrownItemEntity) (Object) this, entity)) { + if (Functions.canDamageWithProjectile((SnowballEntity) (Object) this, entity)) { return entity.damage(source, amount); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEggEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEggEntityMixin.java index 210b907..13351b8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEggEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEggEntityMixin.java @@ -3,18 +3,17 @@ import io.github.indicode.fabric.itsmine.Functions; import net.minecraft.entity.Entity; import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.thrown.ThrownEggEntity; -import net.minecraft.entity.thrown.ThrownItemEntity; +import net.minecraft.entity.projectile.thrown.EggEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -@Mixin(ThrownEggEntity.class) +@Mixin(EggEntity.class) public abstract class ThrownEggEntityMixin { @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")) private boolean imInvincible(Entity entity, DamageSource source, float amount) { - if (Functions.canDamageWithProjectile((ThrownItemEntity) (Object) this, entity)) { + if (Functions.canDamageWithProjectile((EggEntity) (Object) this, entity)) { return entity.damage(source, amount); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEnderpearlEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEnderpearlEntityMixin.java index 9d6543a..2718f52 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEnderpearlEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ThrownEnderpearlEntityMixin.java @@ -3,18 +3,17 @@ import io.github.indicode.fabric.itsmine.Functions; import net.minecraft.entity.Entity; import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.thrown.ThrownEnderpearlEntity; -import net.minecraft.entity.thrown.ThrownItemEntity; +import net.minecraft.entity.projectile.thrown.EnderPearlEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -@Mixin(ThrownEnderpearlEntity.class) +@Mixin(EnderPearlEntity.class) public abstract class ThrownEnderpearlEntityMixin { @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")) private boolean imInvincible(Entity entity, DamageSource source, float amount) { - if (Functions.canDamageWithProjectile((ThrownItemEntity) (Object) this, entity)) { + if (Functions.canDamageWithProjectile((EnderPearlEntity) (Object) this, entity)) { return entity.damage(source, amount); } From 8d8a5ac0c8798a6e56855cf021e71c1df1fb4328 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Mon, 23 Mar 2020 10:01:38 +0430 Subject: [PATCH 51/85] bump version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 0caa29d..921504d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=20w12a+build.18 loader_version=0.7.8+build.187 # Mod Properties - mod_version = 1.8.1-20W12A + mod_version = 1.8.2-20W12A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine From 5a29c34ba6a32c4c79cba9a9ce55c5b8a9114cb3 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Mon, 23 Mar 2020 10:14:33 +0430 Subject: [PATCH 52/85] Fixed permissions --- .../java/io/github/indicode/fabric/itsmine/Permissions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java index 52a078f..d912c89 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java @@ -48,7 +48,7 @@ public Permissions() { if (manager == Manager.THIMBLE) { Thimble.permissionWriters.add((map, server) -> { for (Command value : Command.values()) { - map.registerPermission(value.NODE, PermChangeBehavior.UPDATE_COMMAND_TREE); + map.registerPermission(value.getNode(), PermChangeBehavior.UPDATE_COMMAND_TREE); } }); } From 1d282b0bd92b61e58e43e0f7f7cf882747cf0798 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Mon, 23 Mar 2020 17:27:34 +0430 Subject: [PATCH 53/85] Fixed the issue with NBTUtil --- src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java index 0a2f59e..04e829a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java @@ -18,7 +18,7 @@ public static UUID getUUID(CompoundTag tag, String key){ } public static boolean containsUUID(CompoundTag tag, String key){ - return tag.contains(key + "Least") && tag.contains(key + "Most"); + return (tag.contains(key + "Least") && tag.contains(key + "Most")) || tag.containsUuidNew(key); } } From 5a00066fa39e4bdf10a1c83274502a7cf31c4e19 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Wed, 25 Mar 2020 23:58:35 +0430 Subject: [PATCH 54/85] Updated to 20w13a --- gradle.properties | 8 ++++---- .../java/io/github/indicode/fabric/itsmine/ItsMine.java | 2 +- .../itsmine/mixin/projectile/ProjectileEntityMixin.java | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 921504d..4c27aca 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=20w12a -yarn_mappings=20w12a+build.18 -loader_version=0.7.8+build.187 +minecraft_version=20w13a +yarn_mappings=20w13a+build.1 +loader_version=0.7.8+build.189 # Mod Properties - mod_version = 1.8.2-20W12A + mod_version = 1.8.2-20W13A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java index fff2618..ddab300 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java @@ -15,7 +15,7 @@ public void onInitialize() { permissions = new Permissions(); //TODO: Enable when developing - SharedConstants.isDevelopment = true; + //SharedConstants.isDevelopment = true; } public static Permissions permissions() { return permissions; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java index 5b94ac5..af7542e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java @@ -4,7 +4,6 @@ import io.github.indicode.fabric.itsmine.Functions; import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.entity.Entity; -import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.util.hit.EntityHitResult; From 2a2b59d05e8ec4eb2072b084caa706d2ce11cfbc Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Thu, 26 Mar 2020 01:41:06 +0430 Subject: [PATCH 55/85] Update ClaimCommand.java --- .../java/io/github/indicode/fabric/itsmine/ClaimCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 95456f4..a61a6a2 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1300,7 +1300,7 @@ private static int info(ServerCommandSource source, Claim claim) { text.append(newInfoLine("Owner", owner != null && claim.customOwnerName == null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : claim.customOwnerName != null ? new LiteralText(claim.customOwnerName).formatted(Formatting.GOLD) : - new LiteralText("Not Present").formatted(Formatting.RED, Formatting.ITALIC))); + new LiteralText("No Owner").formatted(Formatting.RED, Formatting.ITALIC))); text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); From 80e3015601eace7e5442de55ae8dc55648294ce7 Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Thu, 26 Mar 2020 03:14:22 +0430 Subject: [PATCH 56/85] Added a command for enableing/disabling the claim fly, you no longer fall fly when you exit a claim while having fly enabled --- .../github/indicode/fabric/itsmine/Claim.java | 18 +++++++ .../indicode/fabric/itsmine/ClaimCommand.java | 27 ++++++++++- .../indicode/fabric/itsmine/Functions.java | 11 +++++ .../fabric/itsmine/mixin/EntityMixin.java | 48 +++++++++++++++++-- 4 files changed, 97 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 4bf6fcd..15e60e6 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -26,6 +26,7 @@ public class Claim { public UUID claimBlockOwner = null; public String customOwnerName, enterMessage, leaveMessage; public boolean isChild = false; + public static List flyers = new ArrayList<>(); public Claim() { } @@ -197,6 +198,15 @@ public CompoundTag toTag() { if (this.leaveMessage != null) meta.putString("leaveMsg", this.leaveMessage); tag.put("meta", meta); } + { + ListTag listTag = new ListTag(); + for (UUID flyer : flyers) { + CompoundTag tag1 = new CompoundTag(); + tag1.putUuidNew("uuid", flyer); + listTag.add(tag1); + } + tag.put("flyers", listTag); + } if (this.customOwnerName != null) tag.putString("cOwnerName", this.customOwnerName); tag.putString("name", name); return tag; @@ -241,6 +251,14 @@ public void fromTag(CompoundTag tag) { if (meta.contains("enterMsg")) this.enterMessage = meta.getString("enterMsg"); if (meta.contains("leaveMsg")) this.leaveMessage = meta.getString("leaveMsg"); } + { + ListTag listTag = tag.getList("flyers", 11); + flyers.clear(); + for (int i = 0; i < listTag.size(); i++) { + CompoundTag tag1 = listTag.getCompound(i); + flyers.add(tag1.getUuidNew("uuid")); + } + } if (tag.contains("cOwnerName")) this.customOwnerName = tag.getString("cOwnerName"); name = tag.getString("name"); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index a61a6a2..e62c453 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -24,6 +24,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; +import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandSource; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; @@ -232,10 +233,20 @@ private static void register(LiteralArgumentBuilder command create.then(name); command.then(create); } + { + LiteralArgumentBuilder fly = literal("fly") + .requires(src -> ItsMine.permissions().hasPermission(src, Permissions.Command.CLAIM_FLY, 2)); + RequiredArgumentBuilder setArgument = CommandManager.argument("set", BoolArgumentType.bool()); + + fly.executes((context) -> setFly(context, !Claim.flyers.contains(context.getSource().getPlayer().getUuid()))); + setArgument.executes((context) -> setFly(context, BoolArgumentType.getBool(context, "set"))); + + fly.then(setArgument); + command.then(fly); + } { LiteralArgumentBuilder rename = literal("rename"); - RequiredArgumentBuilder claimArgument = argument("claim", StringArgumentType.word()) - .suggests(CLAIM_PROVIDER); + RequiredArgumentBuilder claimArgument = getClaimArgument().suggests(CLAIM_PROVIDER); RequiredArgumentBuilder nameArgument = argument("name", StringArgumentType.word()); nameArgument.executes((context) -> rename(context, false)); claimArgument.then(nameArgument); @@ -1633,4 +1644,16 @@ private static int setTrust(CommandContext context, Claim c } return 1; } + private static int setFly(CommandContext context, boolean set) throws CommandSyntaxException { + ServerPlayerEntity player = context.getSource().getPlayer(); + if (set) { + Claim.flyers.add(player.getUuid()); + player.addMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN), false); + return 1; + } + + player.addMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED), false); + Claim.flyers.remove(player.getUuid()); + return -1; + } } \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index 62b8807..a285698 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -20,6 +20,7 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; +import net.minecraft.world.BlockView; import java.util.*; @@ -118,4 +119,14 @@ public static boolean checkCanDamageWithProjectile(Entity entity, MinecraftServe return true; } + public static BlockPos getPosOnGround(BlockPos pos, BlockView view) { + BlockPos blockPos = new BlockPos(pos.getX(), 256.0D, pos.getZ()); + + do { + blockPos = blockPos.down(); + } while (view.getBlockState(blockPos).isAir()); + + return blockPos; + } + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index 1b6853f..72a09c7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -12,6 +12,7 @@ import net.minecraft.text.LiteralText; import net.minecraft.text.Texts; import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.util.registry.Registry; import net.minecraft.world.World; @@ -27,6 +28,9 @@ public abstract class EntityMixin { @Shadow public abstract Vec3d getPos(); + @Shadow public abstract void tick(); + + @Shadow public boolean removed; private Claim pclaim = null; @Inject(method = "setPos", at = @At("HEAD")) public void doPrePosActions(double x, double y, double z, CallbackInfo ci) { @@ -71,23 +75,53 @@ private String getFormattedEventMessage(PlayerEntity player, Claim claim, boolea .replace("%player%", player.getName().asString()); } + private static int tick = 0; + @Inject(method = "tick", at = @At("RETURN")) public void doTickActions(CallbackInfo ci) { - if (!world.isClient && (Object)this instanceof PlayerEntity) { - PlayerEntity player = (PlayerEntity) (Object)this; - if (player.getBlockPos() == null) + tick++; + if (tick >= 5 && !world.isClient && ((Entity) (Object) this instanceof PlayerEntity)) { + tick = 0; + + PlayerEntity player = (PlayerEntity) (Object) this; + if (player.getBlockPos() == null) { return; + } + boolean old = player.abilities.allowFlying; Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.dimension.getType()); + if (player instanceof ServerPlayerEntity) { - if (player.abilities.allowFlying && !player.isSpectator() && !player.isCreative() && ((claim == null || !claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) || !claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT)) && Functions.isClaimFlying(player.getGameProfile().getId()))) { + if ( + player.abilities.allowFlying && + shouldChange(player) && + ( + ( + claim == null || !claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) || + !claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT) + ) + && Functions.isClaimFlying(player.getGameProfile().getId()) + ) + ) { player.abilities.allowFlying = false; player.abilities.flying = false; Functions.setClaimFlying(player.getGameProfile().getId(), false); - } else if (!player.abilities.allowFlying && !player.isSpectator() && !player.isCreative() && claim != null && claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) && claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT) && Functions.canClaimFly((ServerPlayerEntity) player)) { + + BlockPos pos = Functions.getPosOnGround(player.getBlockPos(), player.getEntityWorld()); + player.teleport(pos.getX(), pos.getY(), pos.getZ()); + } else if ( + !player.abilities.allowFlying && + Claim.flyers.contains(player.getUuid()) && + shouldChange(player) && + claim != null && + claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) + && claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT) + && Functions.canClaimFly((ServerPlayerEntity) player) + ) { player.abilities.allowFlying = true; Functions.setClaimFlying(player.getGameProfile().getId(), true); } + if (player.abilities.allowFlying != old) { player.sendAbilitiesUpdate(); } @@ -95,4 +129,8 @@ public void doTickActions(CallbackInfo ci) { } } + + private boolean shouldChange(PlayerEntity player) { + return !player.isSpectator() && !player.isCreative(); + } } From fb1a8e90ed847eff54431eaa517550b6447b2a2f Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Thu, 26 Mar 2020 04:26:17 +0430 Subject: [PATCH 57/85] fixed --- .../github/indicode/fabric/itsmine/Claim.java | 19 +------------------ .../indicode/fabric/itsmine/ClaimCommand.java | 6 +++--- .../indicode/fabric/itsmine/ClaimManager.java | 14 ++++++++++++++ .../indicode/fabric/itsmine/Functions.java | 10 ++++++---- .../fabric/itsmine/mixin/EntityMixin.java | 10 +++++++--- 5 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 15e60e6..08484c9 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -26,7 +26,6 @@ public class Claim { public UUID claimBlockOwner = null; public String customOwnerName, enterMessage, leaveMessage; public boolean isChild = false; - public static List flyers = new ArrayList<>(); public Claim() { } @@ -198,15 +197,7 @@ public CompoundTag toTag() { if (this.leaveMessage != null) meta.putString("leaveMsg", this.leaveMessage); tag.put("meta", meta); } - { - ListTag listTag = new ListTag(); - for (UUID flyer : flyers) { - CompoundTag tag1 = new CompoundTag(); - tag1.putUuidNew("uuid", flyer); - listTag.add(tag1); - } - tag.put("flyers", listTag); - } + if (this.customOwnerName != null) tag.putString("cOwnerName", this.customOwnerName); tag.putString("name", name); return tag; @@ -251,14 +242,6 @@ public void fromTag(CompoundTag tag) { if (meta.contains("enterMsg")) this.enterMessage = meta.getString("enterMsg"); if (meta.contains("leaveMsg")) this.leaveMessage = meta.getString("leaveMsg"); } - { - ListTag listTag = tag.getList("flyers", 11); - flyers.clear(); - for (int i = 0; i < listTag.size(); i++) { - CompoundTag tag1 = listTag.getCompound(i); - flyers.add(tag1.getUuidNew("uuid")); - } - } if (tag.contains("cOwnerName")) this.customOwnerName = tag.getString("cOwnerName"); name = tag.getString("name"); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index e62c453..1cfa1d7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -238,7 +238,7 @@ private static void register(LiteralArgumentBuilder command .requires(src -> ItsMine.permissions().hasPermission(src, Permissions.Command.CLAIM_FLY, 2)); RequiredArgumentBuilder setArgument = CommandManager.argument("set", BoolArgumentType.bool()); - fly.executes((context) -> setFly(context, !Claim.flyers.contains(context.getSource().getPlayer().getUuid()))); + fly.executes((context) -> setFly(context, !ClaimManager.INSTANCE.flyers.contains(context.getSource().getPlayer().getUuid()))); setArgument.executes((context) -> setFly(context, BoolArgumentType.getBool(context, "set"))); fly.then(setArgument); @@ -1647,13 +1647,13 @@ private static int setTrust(CommandContext context, Claim c private static int setFly(CommandContext context, boolean set) throws CommandSyntaxException { ServerPlayerEntity player = context.getSource().getPlayer(); if (set) { - Claim.flyers.add(player.getUuid()); + ClaimManager.INSTANCE.flyers.add(player.getUuid()); player.addMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN), false); return 1; } player.addMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED), false); - Claim.flyers.remove(player.getUuid()); + ClaimManager.INSTANCE.flyers.remove(player.getUuid()); return -1; } } \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java index 7d0a256..8c7db73 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java @@ -22,6 +22,7 @@ public class ClaimManager { public static ClaimManager INSTANCE = null; private HashMap blocksLeft = new HashMap<>(); public List ignoringClaims = new ArrayList<>(); + public List flyers = new ArrayList<>(); public int getClaimBlocks(UUID id) { return blocksLeft.getOrDefault(id, Config.claims2d ? Config.baseClaimBlocks2d : Config.baseClaimBlocks3d); } @@ -83,6 +84,13 @@ public CompoundTag toNBT() { tvargetter.putString("id", id.toString()); ignoring.add(tvargetter.get("id")); }); + ListTag listTag = new ListTag(); + for (UUID flyer : flyers) { + CompoundTag tag1 = new CompoundTag(); + tag1.putUuidNew("uuid", flyer); + listTag.add(tag1); + } + tag.put("flyers", listTag); tag.put("ignoring", ignoring); return tag; } @@ -109,5 +117,11 @@ public void fromNBT(CompoundTag tag) { blocksLeftTag.getKeys().forEach(key -> blocksLeft.put(UUID.fromString(key), blocksLeftTag.getInt(key))); ListTag ignoringTag = (ListTag) tag.get("ignoring"); ignoringTag.forEach(it -> ignoringClaims.add(UUID.fromString(it.asString()))); + ListTag listTag = tag.getList("flyers", 11); + flyers.clear(); + for (int i = 0; i < listTag.size(); i++) { + CompoundTag tag1 = listTag.getCompound(i); + flyers.add(tag1.getUuidNew("uuid")); + } } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index a285698..b4f3f4b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -21,6 +21,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.dimension.DimensionType; import java.util.*; @@ -119,14 +121,14 @@ public static boolean checkCanDamageWithProjectile(Entity entity, MinecraftServe return true; } - public static BlockPos getPosOnGround(BlockPos pos, BlockView view) { - BlockPos blockPos = new BlockPos(pos.getX(), 256.0D, pos.getZ()); + public static BlockPos getPosOnGround(BlockPos pos, World world) { + BlockPos blockPos = new BlockPos(pos.getX(), pos.getY(), pos.getZ()); do { blockPos = blockPos.down(); - } while (view.getBlockState(blockPos).isAir()); + } while (world.getBlockState(blockPos).isAir()); - return blockPos; + return blockPos.up(); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index 72a09c7..63711b0 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -95,6 +95,7 @@ public void doTickActions(CallbackInfo ci) { if ( player.abilities.allowFlying && shouldChange(player) && + ClaimManager.INSTANCE.flyers.contains(player.getUuid()) && ( ( claim == null || !claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) || @@ -107,11 +108,14 @@ public void doTickActions(CallbackInfo ci) { player.abilities.flying = false; Functions.setClaimFlying(player.getGameProfile().getId(), false); - BlockPos pos = Functions.getPosOnGround(player.getBlockPos(), player.getEntityWorld()); - player.teleport(pos.getX(), pos.getY(), pos.getZ()); + World world = player.getEntityWorld(); + if (world.getBlockState(player.getBlockPos().down(4)).isAir() && !player.isOnGround()) { + BlockPos pos = Functions.getPosOnGround(player.getBlockPos(), world); + player.teleport(pos.getX(), pos.getY(), pos.getZ()); + } } else if ( !player.abilities.allowFlying && - Claim.flyers.contains(player.getUuid()) && + ClaimManager.INSTANCE.flyers.contains(player.getUuid()) && shouldChange(player) && claim != null && claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) From 5c64647883aecb9e0deed291179efac187d7cd3b Mon Sep 17 00:00:00 2001 From: OnBlock-Dev <47112191+OnBlock@users.noreply.github.com> Date: Fri, 27 Mar 2020 01:10:06 +0430 Subject: [PATCH 58/85] Fixed "more" --- gradle.properties | 6 ++--- .../github/indicode/fabric/itsmine/Claim.java | 2 +- .../indicode/fabric/itsmine/Functions.java | 10 ++++++++- .../indicode/fabric/itsmine/Permissions.java | 3 ++- .../fabric/itsmine/mixin/EntityMixin.java | 22 +++++++++---------- src/main/resources/fabric.mod.json | 5 ++++- 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/gradle.properties b/gradle.properties index 4c27aca..4f70a7f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=20w13a -yarn_mappings=20w13a+build.1 +minecraft_version=20w13b +yarn_mappings=20w13b+build.4 loader_version=0.7.8+build.189 # Mod Properties - mod_version = 1.8.2-20W13A + mod_version = 1.8.21-20W13B maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 08484c9..f8fd11f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -486,7 +486,7 @@ public CompoundTag toNBT() { } public static class ClaimSettings{ public enum Setting { - FLIGHT_ALLOWED("flight_allowed", "Flying Enabled", true), + FLIGHT_ALLOWED("flight_allowed", "Flying Allowed", true), EXPLOSION_DESTRUCTION("explosion_destruction", "Explosion Destroys Blocks", false), EXPLOSION_DAMAGE("explosion_damage", "Explosion Damages Entities", false), FLUID_CROSSES_BORDERS("fluid_crosses_borders", "Fluid Crosses Borders", false), diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index b4f3f4b..2be983e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -56,7 +56,15 @@ public static boolean canClaimFly(ServerPlayerEntity player) { } } public static void refreshFly(ServerPlayerEntity player) { - flyers.put(player.getGameProfile().getId(), player.world.getServer().getPlayerManager().isOperator(player.getGameProfile()) || Thimble.PERMISSIONS.hasPermission("itsmine.claim_fly", player.getGameProfile().getId())); + flyers.put(player.getGameProfile().getId(), player.world.getServer().getPlayerManager().isOperator(player.getGameProfile()) || ItsMine.permissions().hasPermission(player.getUuid(), "itsmine.claim_fly")); + } + public static boolean canFly(ServerPlayerEntity player) { + boolean op = false; + if (player.world.getServer() != null) { + op = player.world.getServer().getPlayerManager().isOperator(player.getGameProfile()); + } + + return op || ItsMine.permissions().hasPermission(player.getUuid(), "itsmine.claim_fly"); } private static List claimFlyNow = new ArrayList<>(); public static boolean isClaimFlying(UUID player) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java index d912c89..e10ce71 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java @@ -28,6 +28,7 @@ public Permissions() { if (manager == Manager.VANILLA) { this.present = false; + logger.info("Using Vanilla Permissions for Claims"); return; } @@ -140,7 +141,7 @@ private boolean checkPresent() { } if (manager == Manager.THIMBLE) { - Thimble.permissionWriters.get(0); + return true; } return FabricLoader.getInstance().getModContainer(manager.getName().toLowerCase(Locale.ROOT)).isPresent(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index 63711b0..ddb55fa 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -75,14 +75,10 @@ private String getFormattedEventMessage(PlayerEntity player, Claim claim, boolea .replace("%player%", player.getName().asString()); } - private static int tick = 0; @Inject(method = "tick", at = @At("RETURN")) public void doTickActions(CallbackInfo ci) { - tick++; - if (tick >= 5 && !world.isClient && ((Entity) (Object) this instanceof PlayerEntity)) { - tick = 0; - + if (!world.isClient && (Object) this instanceof PlayerEntity) { PlayerEntity player = (PlayerEntity) (Object) this; if (player.getBlockPos() == null) { return; @@ -95,13 +91,14 @@ public void doTickActions(CallbackInfo ci) { if ( player.abilities.allowFlying && shouldChange(player) && - ClaimManager.INSTANCE.flyers.contains(player.getUuid()) && ( ( + !ClaimManager.INSTANCE.flyers.contains(player.getUuid()) || claim == null || !claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) || - !claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT) + !claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT) || + !Functions.canFly((ServerPlayerEntity) player) ) - && Functions.isClaimFlying(player.getGameProfile().getId()) + //&& Functions.isClaimFlying(player.getGameProfile().getId()) ) ) { player.abilities.allowFlying = false; @@ -109,7 +106,7 @@ public void doTickActions(CallbackInfo ci) { Functions.setClaimFlying(player.getGameProfile().getId(), false); World world = player.getEntityWorld(); - if (world.getBlockState(player.getBlockPos().down(4)).isAir() && !player.isOnGround()) { + if (world.getBlockState(player.getBlockPos().down(5)).isAir() && !player.isOnGround()) { BlockPos pos = Functions.getPosOnGround(player.getBlockPos(), world); player.teleport(pos.getX(), pos.getY(), pos.getZ()); } @@ -119,11 +116,12 @@ public void doTickActions(CallbackInfo ci) { shouldChange(player) && claim != null && claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) - && claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT) - && Functions.canClaimFly((ServerPlayerEntity) player) + && claim.hasPermission(player.getUuid(), Claim.Permission.FLIGHT) + && Functions.canFly((ServerPlayerEntity) player) + ///&& Functions.canClaimFly((ServerPlayerEntity) player) ) { player.abilities.allowFlying = true; - Functions.setClaimFlying(player.getGameProfile().getId(), true); + //Functions.setClaimFlying(player.getGameProfile().getId(), true); } if (player.abilities.allowFlying != old) { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 01134d1..98abc6f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -26,8 +26,11 @@ ], "depends": { - "fabricloader": ">=0.4.0" + "fabricloader": ">=0.7.1+build.174", + "thimble": "*" }, "suggests": { + "luckperms": "*", + "thimble": "*" } } From 78ba5e4efa2b0bdcba65275ade7c28ffee9c506f Mon Sep 17 00:00:00 2001 From: DrexHD Date: Sun, 29 Mar 2020 18:37:54 +0200 Subject: [PATCH 59/85] First step towards Subzones --- .../github/indicode/fabric/itsmine/Claim.java | 105 +++++++---- .../indicode/fabric/itsmine/ClaimCommand.java | 168 ++++++++++-------- .../indicode/fabric/itsmine/ClaimManager.java | 55 +++++- .../indicode/fabric/itsmine/Functions.java | 3 +- .../fabric/itsmine/SubzoneCommand.java | 32 ++-- .../itsmine/mixin/CommandManagerMixin.java | 1 + .../ServerPlayerInteractionManagerMixin.java | 2 - 7 files changed, 244 insertions(+), 122 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index f8fd11f..a4b1dd4 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -9,6 +9,7 @@ import net.minecraft.world.dimension.DimensionType; import java.util.*; +import java.util.concurrent.atomic.AtomicReference; import static io.github.indicode.fabric.itsmine.NBTUtil.*; @@ -33,24 +34,25 @@ public Claim(CompoundTag tag) { fromTag(tag); } public Claim(String name, UUID claimBlockOwner, BlockPos min, BlockPos max, DimensionType dimension) { - this(name, claimBlockOwner, min, max, dimension, null); + this(name, claimBlockOwner, min, max, dimension, null, false); } - public Claim(String name, UUID claimBlockOwner, BlockPos min, BlockPos max, DimensionType dimension, @Nullable BlockPos tpPos) { + public Claim(String name, UUID claimBlockOwner, BlockPos min, BlockPos max, DimensionType dimension, @Nullable BlockPos tpPo, boolean isChild) { this.claimBlockOwner = claimBlockOwner; this.min = min; this.max = max; this.name = name; this.dimension = dimension; this.tpPos = tpPos; + this.isChild = isChild; } public boolean includesPosition(BlockPos pos) { return pos.getX() >= min.getX() && pos.getY() >= min.getY() && pos.getZ() >= min.getZ() && pos.getX() <= max.getX() && pos.getY() <= max.getY() && pos.getZ() <= max.getZ(); } public boolean intersects(Claim claim) { - return intersects(claim, true); + return intersects(claim, true, false); } - public boolean intersects(Claim claim, boolean checkOther) { + public boolean intersects(Claim claim, boolean checkOther, boolean checkforsubzone) { if (claim == null) return false; if (!claim.dimension.equals(dimension)) return false; BlockPos a = min, @@ -61,17 +63,25 @@ public boolean intersects(Claim claim, boolean checkOther) { f = new BlockPos(max.getX(), max.getY(), min.getZ()), g = new BlockPos(max.getX(), min.getY(), max.getZ()), h = new BlockPos(min.getX(), max.getY(), max.getZ()); - if ( - claim.includesPosition(a) || - claim.includesPosition(b) || - claim.includesPosition(c) || - claim.includesPosition(d) || - claim.includesPosition(e) || - claim.includesPosition(f) || - claim.includesPosition(g) || - claim.includesPosition(h) - ) return true; - else return checkOther && claim.intersects(this, false); + if(claim.isChild && checkforsubzone || !claim.isChild && !checkforsubzone){ + if( + claim.includesPosition(a) || + claim.includesPosition(b) || + claim.includesPosition(c) || + claim.includesPosition(d) || + claim.includesPosition(e) || + claim.includesPosition(f) || + claim.includesPosition(g) || + claim.includesPosition(h) + ) { + return true; + } + //If the claim is a subzone and checking for subzone is disabled or if the claim isnt a subzone and checking is enabled, instantly return false + }else if (claim.isChild && !checkforsubzone || !claim.isChild && checkforsubzone) { + return false; + } + else return checkOther && claim.intersects(this, false, checkforsubzone); + return false; } @Nullable public Claim getZoneCovering(BlockPos pos) { @@ -107,10 +117,29 @@ public boolean hasPermission(UUID player, Permission permission) { // return player.equals(owner) || ClaimManager.INSTANCE.ignoringClaims.contains(player) || getPermissionsAt(player, pos).hasPermission(permission); //} public void addSubzone(Claim claim) { - if (claim != null && claim.dimension == dimension && includesPosition(claim.min) && includesPosition(claim.max)) { - children.add(claim); - } else throw new IllegalArgumentException("Subzone must be inside the original claim, in the same dimension, and not null"); + children.add(claim); } + + public void removeSubzone(Claim claim) { + children.remove(claim); + } + + @Nullable + AtomicReference atomic = new AtomicReference<>(); + public Claim getParentClaim(Claim subzone){ + if(subzone.isChild){ + ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> { + for(Claim subzone2 : claim.children){ + if(subzone2 == subzone){ + atomic.set(claim); + } + } + }); + return atomic.get(); + } + return null; + } + public void expand(BlockPos min, BlockPos max) { this.min = this.min.add(min); this.max = this.max.add(max); @@ -180,9 +209,11 @@ public CompoundTag toTag() { tag.put("position", pos); } { - ListTag subzoneList = new ListTag(); - children.forEach(it -> subzoneList.add(it.toTag())); - tag.put("subzones", subzoneList); + if(!isChild){ + ListTag subzoneList = new ListTag(); + children.forEach(it -> subzoneList.add(it.toTag())); + tag.put("subzones", subzoneList); + } } { tag.put("settings", settings.toTag()); @@ -220,14 +251,16 @@ public void fromTag(CompoundTag tag) { this.dimension = DimensionType.byId(new Identifier(pos.getString("dimension"))); } { - children = new ArrayList<>(); - ListTag subzoneList = (ListTag) tag.get("subzones"); - if (subzoneList != null) { - subzoneList.forEach(it -> { - Claim claim = new Claim((CompoundTag) it); - claim.isChild = true; - children.add(claim); - }); + if(!isChild){ + children = new ArrayList<>(); + ListTag subzoneList = (ListTag) tag.get("subzones"); + if (subzoneList != null) { + subzoneList.forEach(it -> { + Claim claim = new Claim((CompoundTag) it); + claim.isChild = true; + children.add(claim); + }); + } } } { @@ -317,13 +350,13 @@ public void clearPermission(UUID player, Permission permission) { public void resetPermissions(UUID player) { playerPermissions.remove(player); } - public boolean isPermissionSet(String group, Permission permission) { - return groupPermissions.get(group) != null && groupPermissions.get(group).isPermissionSet(permission); - } - public boolean hasPermission(String group, Permission permission) { - if (isPermissionSet(group, permission)) return groupPermissions.get(group).hasPermission(permission); - return defaults.hasPermission(permission); - } +// public boolean isPermissionSet(String group, Permission permission) { +// return groupPermissions.get(group) != null && groupPermissions.get(group).isPermissionSet(permission); +// } +// public boolean hasPermission(String group, Permission permission) { +// if (isPermissionSet(group, permission)) return groupPermissions.get(group).hasPermission(permission); +// return defaults.hasPermission(permission); +// } public void setPermission(String group, Permission permission, boolean enabled) { if (!groupPermissions.containsKey(group)) groupPermissions.put(group, new DefaultPermissionMap()); groupPermissions.get(group).setPermission(permission, enabled); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 1cfa1d7..606bac9 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -14,6 +14,7 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import com.mojang.brigadier.suggestion.SuggestionProvider; import io.github.indicode.fabric.itsmine.mixin.BlockUpdatePacketMixin; +import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.command.EntitySelector; @@ -24,19 +25,27 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; +import net.minecraft.server.MinecraftServer; 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.*; import net.minecraft.util.Formatting; import net.minecraft.util.Pair; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.registry.Registry; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.dimension.DimensionType; +import java.lang.reflect.Array; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; import static net.minecraft.server.command.CommandManager.argument; @@ -171,7 +180,7 @@ public static void register(CommandDispatcher dispatcher) { } private static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { - //SubzoneCommand.register(command, false); + SubzoneCommand.register(command, false); { LiteralArgumentBuilder help = literal("help"); help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); @@ -437,13 +446,16 @@ private static void register(LiteralArgumentBuilder command } { LiteralArgumentBuilder list = literal("list"); + LiteralArgumentBuilder listall = literal("listall"); RequiredArgumentBuilder player = argument("player", StringArgumentType.word()); player.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_CHECK_OTHERS, 2)); player.suggests(PLAYERS_PROVIDER); list.executes(context -> list(context.getSource(), context.getSource().getName())); + listall.executes(context -> listall(context.getSource())); player.executes(context -> list(context.getSource(), StringArgumentType.getString(context, "player"))); list.then(player); command.then(list); + command.then(listall); LiteralArgumentBuilder claims = literal("claims") .executes(context -> list(context.getSource(), context.getSource().getName())) @@ -987,69 +999,39 @@ private static int showClaim(ServerCommandSource source, Claim claim, boolean re return 0; } private static void silentHideShow(ServerPlayerEntity player, Claim claim, boolean hide, boolean updateStatus) { - BlockState block = hide ? null : Blocks.SEA_LANTERN.getDefaultState(); - int showRange = 5; - int closeShowRange = 8; - BlockPos pos = hide ? ((ClaimShower)player).getLastShowPos() : player.getBlockPos(); - ((ClaimShower)player).setLastShowPos(pos); - for (int x = claim.min.getX(); x <= claim.min.getX() + showRange; x++) { - sendBlockPacket(player, new BlockPos(x, claim.min.getY(), claim.min.getZ()), block); - sendBlockPacket(player, new BlockPos(x, claim.max.getY(), claim.min.getZ()), block); - sendBlockPacket(player, new BlockPos(x, claim.min.getY(), claim.max.getZ()), block); - sendBlockPacket(player, new BlockPos(x, claim.max.getY(), claim.max.getZ()), block); - } - for (int x = claim.max.getX() - showRange; x <= claim.max.getX(); x++) { - sendBlockPacket(player, new BlockPos(x, claim.min.getY(), claim.min.getZ()), block); - sendBlockPacket(player, new BlockPos(x, claim.max.getY(), claim.min.getZ()), block); - sendBlockPacket(player, new BlockPos(x, claim.min.getY(), claim.max.getZ()), block); - sendBlockPacket(player, new BlockPos(x, claim.max.getY(), claim.max.getZ()), block); - } - if (claim.includesPosition(pos)) for (int x = pos.getX() - closeShowRange; x <= pos.getX() + closeShowRange; x++) { - if (x < claim.min.getX() || x > claim.max.getX()) continue; - sendBlockPacket(player, new BlockPos(x, pos.getY(), claim.min.getZ()), block); - sendBlockPacket(player, new BlockPos(x, pos.getY(), claim.max.getZ()), block); - } - for (int y = claim.min.getY(); y <= claim.min.getY() + showRange; y++) { - sendBlockPacket(player, new BlockPos(claim.min.getX(), y, claim.min.getZ()), block); - sendBlockPacket(player, new BlockPos(claim.max.getX(), y, claim.min.getZ()), block); - sendBlockPacket(player, new BlockPos(claim.min.getX(), y, claim.max.getZ()), block); - sendBlockPacket(player, new BlockPos(claim.max.getX(), y, claim.max.getZ()), block); - } - for (int y = claim.max.getY() - showRange; y <= claim.max.getY(); y++) { - sendBlockPacket(player, new BlockPos(claim.min.getX(), y, claim.min.getZ()), block); - sendBlockPacket(player, new BlockPos(claim.max.getX(), y, claim.min.getZ()), block); - sendBlockPacket(player, new BlockPos(claim.min.getX(), y, claim.max.getZ()), block); - sendBlockPacket(player, new BlockPos(claim.max.getX(), y, claim.max.getZ()), block); - } - if (claim.includesPosition(pos)) for (int y = pos.getY() - closeShowRange; y <= pos.getY() + closeShowRange; y++) { - if (y < claim.min.getY() || y > claim.max.getY()) continue; - sendBlockPacket(player, new BlockPos(pos.getX(), y, claim.min.getZ()), block); - sendBlockPacket(player, new BlockPos(claim.max.getX(), y, pos.getZ()), block); - sendBlockPacket(player, new BlockPos(claim.min.getX(), y, pos.getZ()), block); - sendBlockPacket(player, new BlockPos(pos.getX(), y, claim.max.getZ()), block); - } - for (int z = claim.min.getZ(); z <= claim.min.getZ() + showRange; z++) { - sendBlockPacket(player, new BlockPos(claim.min.getX(), claim.min.getY(), z), block); - sendBlockPacket(player, new BlockPos(claim.max.getX(), claim.min.getY(), z), block); - sendBlockPacket(player, new BlockPos(claim.min.getX(), claim.max.getY(), z), block); - sendBlockPacket(player, new BlockPos(claim.max.getX(), claim.max.getY(), z), block); - } - for (int z = claim.max.getZ() - showRange; z <= claim.max.getZ(); z++) { - sendBlockPacket(player, new BlockPos(claim.min.getX(), claim.min.getY(), z), block); - sendBlockPacket(player, new BlockPos(claim.max.getX(), claim.min.getY(), z), block); - sendBlockPacket(player, new BlockPos(claim.min.getX(), claim.max.getY(), z), block); - sendBlockPacket(player, new BlockPos(claim.max.getX(), claim.max.getY(), z), block); - } - if (claim.includesPosition(pos)) for (int z = pos.getZ() - closeShowRange; z <= pos.getZ() + closeShowRange; z++) { - if (z < claim.min.getZ() || z > claim.max.getZ()) continue; - sendBlockPacket(player, new BlockPos(claim.min.getX(), pos.getY(), z), block); - sendBlockPacket(player, new BlockPos(claim.max.getX(), pos.getY(), z), block); - } if (updateStatus) { if (!hide) ((ClaimShower) player).setShownClaim(claim); else ((ClaimShower) player).setShownClaim(null); } + BlockState block = hide ? null : Blocks.GOLD_BLOCK.getDefaultState(); + showCorners(player, claim, hide, block); + if(!claim.isChild){ + block = hide ? null : Blocks.DIAMOND_BLOCK.getDefaultState(); + for(Claim subzone : claim.children){ + showCorners(player, subzone, hide, block); + } + } + } + + private static void showCorners(ServerPlayerEntity player, Claim claim, boolean hide, BlockState state){ + state = hide ? null : state; + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); + + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().south(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().east(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().south(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().north(), state); + + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().east(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().north(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().west(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().west(), state); + } + private static void sendBlockPacket(ServerPlayerEntity player, BlockPos pos, BlockState state) { BlockUpdateS2CPacket packet = new BlockUpdateS2CPacket(player.world, pos); if (state != null) ((BlockUpdatePacketMixin)packet).setState(state); @@ -1091,7 +1073,7 @@ private static int createClaim(String name, ServerCommandSource owner, BlockPos sub = sub.add(1, Config.claims2d ? 0 : 1,1); int subInt = sub.getX() * (Config.claims2d ? 1 : sub.getY()) * sub.getZ(); - Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos()); + Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos(), false); if (cOwnerName != null) claim.customOwnerName = cOwnerName; claim.permissionManager.playerPermissions.put(ownerID, new Claim.InvertedPermissionMap()); if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { @@ -1156,14 +1138,28 @@ private static int delete(ServerCommandSource sender, Claim claim, boolean admin return 0; } } - ClaimManager.INSTANCE.releaseBlocksToOwner(claim); - ClaimManager.INSTANCE.claimsByName.remove(claim.name); + if(!claim.isChild){ + ClaimManager.INSTANCE.releaseBlocksToOwner(claim); + ClaimManager.INSTANCE.claimsByName.remove(claim.name); + for(Claim subzone : claim.children){ + ClaimManager.INSTANCE.claimsByName.remove(subzone.name); + } + }else{ + System.out.println("Parent subzones " + ClaimManager.INSTANCE.claimsByName.remove(claim.name).children.size()); + System.out.println("Deleted claim " + ClaimManager.INSTANCE.claimsByName.remove(claim.name).name); + ClaimManager.INSTANCE.claimsByName.remove(claim.name); + System.out.println("Parent claim " + claim.getParentClaim(claim).name); + claim.removeSubzone(claim.getParentClaim(claim)); + System.out.println("Parent subzones2 " + ClaimManager.INSTANCE.claimsByName.remove(claim.name).children.size()); + } sender.getWorld().getPlayers().forEach(playerEntity -> { if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true); }); sender.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)); return 0; } + + private static int requestTransfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { if (claim == null) { sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); @@ -1235,9 +1231,9 @@ private static int modifyException(Claim claim, String exception, Claim.Permissi private static boolean hasPermission(Claim claim, ServerPlayerEntity exception, Claim.Permission permission) { return claim.permissionManager.hasPermission(exception.getGameProfile().getId(), permission); } - private static boolean hasPermission(Claim claim, String exception, Claim.Permission permission) { - return claim.permissionManager.hasPermission(exception, permission); - } +// private static boolean hasPermission(Claim claim, String exception, Claim.Permission permission) { +// return claim.permissionManager.hasPermission(exception, permission); +// } private static Direction directionByName(String name) { for (Direction direction : Direction.values()) { if (name.equals(direction.getName())) return direction; @@ -1350,6 +1346,26 @@ private static Text newInfoLine(String title, Text text) { return new LiteralText("").append(new LiteralText("* " + title + ": ").formatted(Formatting.YELLOW)) .append(text).append("\n"); } + + private static ArrayList getClaims(){ + ArrayList claims = new ArrayList<>(); + ClaimManager.INSTANCE.claimsByName.forEach((s, claim) -> { + claims.add(claim); + }); + return claims; + } + + private static int listall(ServerCommandSource source){ + List claims = getClaims(); + Text text = new LiteralText("\n").append(new LiteralText("Claims").formatted(Formatting.GOLD)).append("\n "); + for (Claim claim : claims) { + Text cText = new LiteralText(claim.name).formatted(Formatting.GOLD); + text.append(cText.append(" ")); + } + source.sendFeedback(text.append("\n"), false); + return 1; + } + private static int list(ServerCommandSource source, String target) throws CommandSyntaxException { ServerPlayerEntity player = source.getPlayer(); GameProfile profile = target == null ? player.getGameProfile() : source.getMinecraftServer().getUserCache().findByName(target); @@ -1369,13 +1385,23 @@ private static int list(ServerCommandSource source, String target) throws Comman Text text = new LiteralText("\n").append(new LiteralText("Claims (" + target + "): ").formatted(Formatting.GOLD)).append("\n "); boolean nextColor = false; for (Claim claim : claims) { - Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click for more Info").formatted(Formatting.GREEN))); - style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); - }); + if(!claim.isChild) { + Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { + Text hoverText = new LiteralText("Click for more Info").formatted(Formatting.GREEN); + if (claim.children.size() > 0) { + hoverText.append("\n\nSubzones:"); + for (Claim subzone : claim.children) { + hoverText.append("\n- " + subzone.name); + } + } + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); - nextColor = !nextColor; - text.append(cText.append(" ")); + style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); + }); + + nextColor = !nextColor; + text.append(cText.append(" ")); + } } source.sendFeedback(text.append("\n"), false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java index 8c7db73..8b08234 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java @@ -44,6 +44,11 @@ public void useBlocksUntil0(UUID player, int amount) { public void setClaimBlocks(Collection players, int amount) { players.forEach(player -> setClaimBlocks(player.getGameProfile().getId(), -amount)); } + + public Claim getClaim(String name){ + return claimsByName.get(name); + } + public void setClaimBlocks(UUID player, int amount) { blocksLeft.put(player, Math.max(amount, 0)); } @@ -60,7 +65,7 @@ public List getPlayerClaims(UUID id) { } public boolean addClaim(Claim claim) { if (claimsByName.containsKey(claim.name)) return false; - if (wouldIntersect(claim)) return false; + if (wouldIntersect(claim) && !claim.isChild) return false; claimsByName.put(claim.name, claim); return true; } @@ -70,10 +75,24 @@ public boolean wouldIntersect(Claim claim) { } return false; } + + public boolean wouldSubzoneIntersect(Claim claim) { + for (Claim value : claimsByName.values()) { + if(!claim.name.equals(value.name) && claim.intersects(value, true, true)){ + return true; + } + + } + return false; + } public CompoundTag toNBT() { CompoundTag tag = new CompoundTag(); ListTag list = new ListTag(); - claimsByName.values().forEach(claim -> list.add(claim.toTag())); + claimsByName.values().forEach(claim -> { + if(!claim.isChild){ + list.add(claim.toTag()); + } + }); tag.put("claims", list); CompoundTag blocksLeftTag = new CompoundTag(); blocksLeft.forEach((id, amount) -> {if (id != null) blocksLeftTag.putInt(id.toString(), amount);}); @@ -94,10 +113,39 @@ public CompoundTag toNBT() { tag.put("ignoring", ignoring); return tag; } + + public Claim getMainClaimAt(BlockPos pos, DimensionType dimension){ + for (Claim claim : claimsByName.values()) { + if(claim.dimension.equals(dimension) && claim.includesPosition(pos)){ + return claim.getZoneCovering(pos); + } + } + return null; + } + + public Claim getSubzoneClaimAt(BlockPos pos, DimensionType dimension) { + for (Claim claim : claimsByName.values()) { + if (claim.dimension.equals(dimension) && claim.includesPosition(pos)) { + for(Claim subzone : claim.children){ + if(subzone.dimension.equals(dimension) && subzone.includesPosition(pos)){ + return subzone.getZoneCovering(pos); + } + } + return null; + } + } + return null; + } + @Nullable public Claim getClaimAt(BlockPos pos, DimensionType dimension) { for (Claim claim : claimsByName.values()) { if (claim.dimension.equals(dimension) && claim.includesPosition(pos)) { + for(Claim subzone : claim.children){ + if(subzone.dimension.equals(dimension) && subzone.includesPosition(pos)){ + return subzone.getZoneCovering(pos); + } + } return claim.getZoneCovering(pos); } } @@ -111,6 +159,9 @@ public void fromNBT(CompoundTag tag) { Claim claim = new Claim(); claim.fromTag((CompoundTag) it); claimsByName.put(claim.name, claim); + for(Claim subzone : claim.children){ + claimsByName.put(subzone.name, subzone); + } }); CompoundTag blocksLeftTag = tag.getCompound("blocksLeft"); blocksLeft.clear(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index 2be983e..16036a5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -98,10 +98,10 @@ public static boolean canInteractUsingItem(Claim claim, Item item, UUID player) public static boolean canDamageWithProjectile(ThrownEntity thrownEntity, Entity entity) { if (checkCanDamageWithProjectile(entity, thrownEntity.getServer(), ((OwnedProjectile) thrownEntity).getOwner())) { - thrownEntity.kill(); return true; } + thrownEntity.kill(); return false; } @@ -139,4 +139,5 @@ public static BlockPos getPosOnGround(BlockPos pos, World world) { return blockPos.up(); } + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java index 70fd021..402a428 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java @@ -15,6 +15,7 @@ import net.minecraft.util.math.BlockPos; import org.jetbrains.annotations.Nullable; +import java.text.Format; import java.util.UUID; public class SubzoneCommand { @@ -33,7 +34,7 @@ public static void register(LiteralArgumentBuilder command, .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), StringArgumentType.getString(ctx, "claim"), admin)); name.then(claim); - builder.then(name); + add.then(name); builder.then(add); } @@ -58,12 +59,25 @@ private static int addZone(ServerCommandSource source, String name, @Nullable St } else if (selectedPositions.getRight() == null) { source.sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); } else { - subZone = createSubzone(source, name, selectedPositions.getLeft(), selectedPositions.getRight(), admin); - if (subZone != null) { - ClaimManager.INSTANCE.stickPositions.remove(player); - - - return 1; + name = claim.name + "." + name; + subZone = createSubzone(source, name, selectedPositions.getLeft(), selectedPositions.getRight(), admin); + if (subZone.dimension == claim.dimension && claim.includesPosition(subZone.min) && claim.includesPosition(subZone.max) && !claim.isChild){ + if (!ClaimManager.INSTANCE.wouldSubzoneIntersect((subZone))){ + claim.addSubzone(subZone); + ClaimManager.INSTANCE.addClaim(subZone); + subZone.permissionManager = claim.permissionManager; +// subZone.permissionManager.playerPermissions.put(subZone.claimBlockOwner, new Claim.InvertedPermissionMap()); + source.sendFeedback(new LiteralText("").append(new LiteralText("Your subzone was created.").formatted(Formatting.GREEN)), false); + }else{ + player.sendMessage(new LiteralText("Your subzone would overlap with another subzone").formatted(Formatting.RED)); + } + if (subZone != null) { + ClaimManager.INSTANCE.stickPositions.remove(player); + return 1; + } + return 0; + }else{ + player.sendMessage(new LiteralText("Subzone must be inside the original claim, in the same dimension").formatted(Formatting.RED)); } } @@ -100,9 +114,7 @@ private static Claim createSubzone(ServerCommandSource source, String name, Bloc BlockPos max = new BlockPos(mx, my, mz); BlockPos sub = max.subtract(min); sub = sub.add(1, Config.claims2d ? 0 : 1,1); - - source.sendFeedback(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)).append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").setStyle(new Style().setColor(Formatting.GREEN))), false); - return new Claim(name, admin ? null : ownerID, min, max, source.getWorld().getDimension().getType(), source.getPlayer().getBlockPos()); + return new Claim(name, admin ? null : ownerID, min, max, source.getWorld().getDimension().getType(), source.getPlayer().getBlockPos(), true); } private static Claim validateAndGet(ServerCommandSource source, @Nullable String claimName) throws CommandSyntaxException { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java index 6c40133..3123e47 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java @@ -2,6 +2,7 @@ import com.mojang.brigadier.CommandDispatcher; import io.github.indicode.fabric.itsmine.ClaimCommand; +import io.github.indicode.fabric.itsmine.SubzoneCommand; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index 007dfb6..aae0718 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -2,12 +2,10 @@ import io.github.indicode.fabric.itsmine.*; import net.minecraft.block.*; -import net.minecraft.block.enums.DoubleBlockHalf; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerInteractionManager; import net.minecraft.server.world.ServerWorld; From 19e4376bdac4093a22188699a2ee3b68a06315d8 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Mon, 30 Mar 2020 12:01:37 +0200 Subject: [PATCH 60/85] Fixed subzone remove --- src/main/java/io/github/indicode/fabric/itsmine/Claim.java | 1 - .../io/github/indicode/fabric/itsmine/ClaimCommand.java | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index a4b1dd4..22895cd 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -219,7 +219,6 @@ public CompoundTag toTag() { tag.put("settings", settings.toTag()); tag.put("permissions", permissionManager.toNBT()); if(claimBlockOwner != null) tag.putUuidNew("top_owner", claimBlockOwner); -// if (claimBlockOwner != null) tag.putUuidNew("top_owner", claimBlockOwner); } { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 1f50e98..47a2c71 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1145,12 +1145,8 @@ private static int delete(ServerCommandSource sender, Claim claim, boolean admin ClaimManager.INSTANCE.claimsByName.remove(subzone.name); } }else{ - System.out.println("Parent subzones " + ClaimManager.INSTANCE.claimsByName.remove(claim.name).children.size()); - System.out.println("Deleted claim " + ClaimManager.INSTANCE.claimsByName.remove(claim.name).name); + claim.getParentClaim(claim).removeSubzone(claim); ClaimManager.INSTANCE.claimsByName.remove(claim.name); - System.out.println("Parent claim " + claim.getParentClaim(claim).name); - claim.removeSubzone(claim.getParentClaim(claim)); - System.out.println("Parent subzones2 " + ClaimManager.INSTANCE.claimsByName.remove(claim.name).children.size()); } sender.getWorld().getPlayers().forEach(playerEntity -> { if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true); From 167810ec4460ab1d1dae137ffe11c24dbad4ba40 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Mon, 30 Mar 2020 15:23:27 +0200 Subject: [PATCH 61/85] Added 2 new permissions --- .../github/indicode/fabric/itsmine/Claim.java | 5 +++- .../indicode/fabric/itsmine/Config.java | 2 ++ .../indicode/fabric/itsmine/Functions.java | 3 ++- .../indicode/fabric/itsmine/Messages.java | 2 ++ .../fabric/itsmine/mixin/BoatItemMixin.java | 2 +- .../mixin/LecternScreenHandlerMixin.java | 24 +++++++++++++++++++ src/main/resources/itsmine.mixins.json | 3 ++- 7 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 22895cd..6a3113b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -296,6 +296,7 @@ public enum Permission { USE_LEVERS("use.levers", "Use Levers"), INTERACT_DOORS("interact_doors", "Use Doors"), INTERACT_ENTITY("interact_entity", "Entity Interaction"), + INTERACT_LECTERN("interact_lectern", "Lectern Interaction"), DAMAGE_ENTITY("damage_entities", "Hurt Entities"), DAMAGE_ENTITY_HOSTILE("damage_entities.hostile", "Hurt Hostile Entities"), DAMAGE_ENTITY_PASSIVE("damage_entities.passive", "Hurt Passive Entities"), @@ -305,7 +306,9 @@ public enum Permission { CONTAINER_CHEST("container.chest", "Open Chests"), CONTAINER_SHULKERBOX("container.shulkerbox", "Open Shulker Boxes"), USE_ENDER_PEARL("use.enderpearl", "Use Ender Pearls"), - USE_BUTTONS("use.button", "Use Buttons"); + USE_BUTTONS("use.button", "Use Buttons"), + SPAWN_BOAT("spawn.boat", "Spawn Boats"); + String id, name; Permission(String id, String name) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/Config.java index 9a7f602..093e1f1 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Config.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Config.java @@ -23,6 +23,7 @@ public class Config { public static String msg_cant_enter = "&c&lHey!&r&c Sorry but you don't have permission to enter this claim!"; public static String msg_cant_use = "&c&lHey!&r&c Sorry but you can't to use that here!"; public static String msg_long_name = "&cThe name of the Claim must be less than 30 characters!"; + public static String msg_cant_do ="&c&lHey!&r&c Sorry but you can't do that!"; public static int event_msg_stay_ticks = -1; private static ModConfig modConfig = new ModConfig("itsmine"); @@ -44,6 +45,7 @@ static void sync() { msg_cant_enter = config.getString("msg.cant_enter", msg_cant_enter); msg_cant_use = config.getString("msg.cant_use", msg_cant_use); msg_long_name = config.getString("msg.long_name", msg_long_name); + msg_cant_do = config.getString("msg.cant_do", msg_cant_do); event_msg_stay_ticks = config.getInt("event.msg.stay_ticks", event_msg_stay_ticks, "Sets how many ticks an event message will stay on action bar, Default: -1"); }); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index a45ca36..1d3230b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -85,7 +85,8 @@ public static boolean canInteractWith(Claim claim, Block block, UUID player) { (BlockUtils.isContainer(block) && claim.hasPermission(player, Claim.Permission.CONTAINER)) || (BlockUtils.isChest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_CHEST)) || (BlockUtils.isEnderchest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_ENDERCHEST)) || - (BlockUtils.isShulkerBox(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_SHULKERBOX)); + (BlockUtils.isShulkerBox(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_SHULKERBOX)) || + (BlockUtils.isLectern(block) && claim.hasPermission(player, Claim.Permission.INTERACT_LECTERN)); } public static boolean canInteractUsingItem(Claim claim, Item item, UUID player) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 28c3d50..db14075 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -37,6 +37,8 @@ public class Messages { public static final Text MSG_LONG_NAME = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_long_name)).formatted(Formatting.RED)); + public static final Text MSG_CANT_DO = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_do)).formatted(Formatting.RED)); + public static final Text[] GET_STARTED = new Text[]{ header("How to Claim (Basics)") .append(line(1, "Type &6/claim stick&e then Left click with a stick on a block to set the &6first&e corner of your claim")) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java index 3b18bbf..e6ca2c8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java @@ -36,7 +36,7 @@ private void dontSpawn(World world, PlayerEntity user, Hand hand, CallbackInfoRe Claim claim = ClaimManager.INSTANCE.getClaimAt(new BlockPos(pos.getX(), pos.getY(), pos.getZ()), user.dimension); - if (claim != null && !claim.hasPermission(user.getUuid(), Claim.Permission.BUILD)) { + if (claim != null && !claim.hasPermission(user.getUuid(), Claim.Permission.BUILD) || !claim.hasPermission(user.getUuid(), Claim.Permission.SPAWN_BOAT)) { user.sendMessage(Messages.NO_PERMISSION); cir.setReturnValue(TypedActionResult.fail(itemStack)); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java new file mode 100644 index 0000000..98db24b --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java @@ -0,0 +1,24 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.screen.LecternScreenHandler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(LecternScreenHandler.class) +public abstract class LecternScreenHandlerMixin { + @Redirect(method = "onButtonClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/LecternScreenHandler;onButtonClick(Lnet/minecraft/entity/player/PlayerEntity;I)Z")) + private boolean canTake(LecternScreenHandler lecternScreenHandler, PlayerEntity player, int id) { + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + if (claim != null && !claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_LECTERN)) { + player.sendMessage(Messages.MSG_CANT_DO); + return false; + } + return true; + + } +} \ No newline at end of file diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index 651d634..585b8d1 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -32,7 +32,8 @@ "EntityMixin", "EnderDragonEntityMixin", "FarmlandBlockMixin", - "BoatItemMixin" + "BoatItemMixin", + "LecternScreenHandlerMixin" ], "client": [ "IntegratedServerMixin" From 46edcd8b061bad6aab561c69d04e3942f555034a Mon Sep 17 00:00:00 2001 From: DrexHD Date: Mon, 20 Apr 2020 18:11:59 +0200 Subject: [PATCH 62/85] bump version --- build.gradle | 2 +- gradle.properties | 8 +- .../github/indicode/fabric/itsmine/Claim.java | 338 +- .../indicode/fabric/itsmine/ClaimCommand.java | 3513 +++++++++-------- .../indicode/fabric/itsmine/ClaimManager.java | 3 +- .../indicode/fabric/itsmine/Config.java | 2 + .../indicode/fabric/itsmine/Functions.java | 40 +- .../indicode/fabric/itsmine/ItsMine.java | 10 +- .../indicode/fabric/itsmine/Messages.java | 9 +- .../fabric/itsmine/MonitorableWorld.java | 13 + .../fabric/itsmine/command/BlockCommand.java | 43 + .../itsmine/command/CommandManager.java | 45 + .../fabric/itsmine/command/CreateCommand.java | 126 + .../itsmine/command/ExceptionCommand.java | 176 + .../fabric/itsmine/command/ExpandCommand.java | 174 + .../fabric/itsmine/command/FlyCommand.java | 42 + .../fabric/itsmine/command/HelpCommand.java | 102 + .../fabric/itsmine/command/InfoCommand.java | 105 + .../fabric/itsmine/command/ListCommand.java | 30 + .../itsmine/command/PermissionsCommand.java | 49 + .../fabric/itsmine/command/RemoveCommand.java | 93 + .../fabric/itsmine/command/RenameCommand.java | 61 + .../fabric/itsmine/command/RentCommand.java | 94 + .../itsmine/command/RentableCommand.java | 81 + .../itsmine/command/RevenueCommand.java | 87 + .../itsmine/command/SettingsCommand.java | 53 + .../fabric/itsmine/command/ShowCommand.java | 54 + .../fabric/itsmine/command/StickCommand.java | 30 + .../itsmine/command/TransferCommand.java | 147 + .../fabric/itsmine/command/TrustCommand.java | 85 + .../itsmine/command/TrustedCommand.java | 124 + .../itsmine/command/admin/AdminCommand.java | 48 + .../itsmine/command/admin/BlocksCommand.java | 65 + .../itsmine/command/admin/ClaimsCommand.java | 70 + .../itsmine/command/admin/CreateCommand.java | 81 + .../command/admin/EntitiesCommand.java | 42 + .../itsmine/command/admin/ExpandCommand.java | 76 + .../itsmine/command/admin/IgnoreCommand.java | 30 + .../itsmine/command/admin/ListAllCommand.java | 37 + .../itsmine/command/admin/OwnerCommand.java | 114 + .../itsmine/command/admin/RemoveCommand.java | 31 + .../itsmine/command/admin/RenameCommand.java | 23 + .../subzone/CreateCommand.java} | 61 +- .../command/subzone/SubzoneCommand.java | 34 + .../itsmine/mixin/AnimalEntityMixin.java | 49 + .../itsmine/mixin/CommandManagerMixin.java | 8 +- .../fabric/itsmine/mixin/EntityMixin.java | 3 +- .../itsmine/mixin/IntegratedServerMixin.java | 6 +- .../mixin/LecternScreenHandlerMixin.java | 24 +- .../itsmine/mixin/MinecraftServerMixin.java | 9 +- .../fabric/itsmine/mixin/OwnedProjectile.java | 13 + .../itsmine/mixin/PlayerEntityMixin.java | 9 +- .../itsmine/mixin/ProjectileEntityMixin.java | 42 + .../ServerPlayerInteractionManagerMixin.java | 3 +- .../itsmine/mixin/ServerWorldMixin.java | 71 +- .../fabric/itsmine/util/ArgumentUtil.java | 181 + .../{BlockUtils.java => util/BlockUtil.java} | 4 +- .../fabric/itsmine/util/ClaimUtil.java | 200 + .../fabric/itsmine/util/DirectionUtil.java | 12 + .../EntityUtil.java} | 8 +- .../{NBTUtil.java => util/NbtUtil.java} | 4 +- .../PermissionUtil.java} | 7 +- .../fabric/itsmine/util/ShowerUtil.java | 66 + .../fabric/itsmine/util/TimeUtil.java | 130 + src/main/resources/fabric.mod.json | 3 +- src/main/resources/itsmine.mixins.json | 3 +- 66 files changed, 5498 insertions(+), 1808 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/StickCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/BlocksCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/CreateCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/IgnoreCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/RenameCommand.java rename src/main/java/io/github/indicode/fabric/itsmine/{SubzoneCommand.java => command/subzone/CreateCommand.java} (72%) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java rename src/main/java/io/github/indicode/fabric/itsmine/{BlockUtils.java => util/BlockUtil.java} (93%) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/DirectionUtil.java rename src/main/java/io/github/indicode/fabric/itsmine/{EntityUtils.java => util/EntityUtil.java} (84%) rename src/main/java/io/github/indicode/fabric/itsmine/{NBTUtil.java => util/NbtUtil.java} (89%) rename src/main/java/io/github/indicode/fabric/itsmine/{Permissions.java => util/PermissionUtil.java} (97%) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/TimeUtil.java diff --git a/build.gradle b/build.gradle index cba03e6..01d8e83 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.2.6-SNAPSHOT' + id 'fabric-loom' version '0.2.7-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index 4f70a7f..967dbd9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=20w13b -yarn_mappings=20w13b+build.4 -loader_version=0.7.8+build.189 +minecraft_version=20w16a +yarn_mappings=20w16a+build.4 +loader_version=0.7.10+build.191 # Mod Properties - mod_version = 1.8.21-20W13B + mod_version = 1.9.0-20W16A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 6a3113b..c6f5351 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -1,7 +1,11 @@ package io.github.indicode.fabric.itsmine; import blue.endless.jankson.annotation.Nullable; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.*; +import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -11,7 +15,7 @@ import java.util.*; import java.util.concurrent.atomic.AtomicReference; -import static io.github.indicode.fabric.itsmine.NBTUtil.*; +import static io.github.indicode.fabric.itsmine.util.NbtUtil.*; /** * @author Indigo Amann @@ -24,6 +28,7 @@ public class Claim { public List children = new ArrayList<>(); public ClaimSettings settings = new ClaimSettings(); public PermissionManager permissionManager = new PermissionManager(); + public Rent rent = new Rent(); public UUID claimBlockOwner = null; public String customOwnerName, enterMessage, leaveMessage; public boolean isChild = false; @@ -49,9 +54,77 @@ public boolean includesPosition(BlockPos pos) { return pos.getX() >= min.getX() && pos.getY() >= min.getY() && pos.getZ() >= min.getZ() && pos.getX() <= max.getX() && pos.getY() <= max.getY() && pos.getZ() <= max.getZ(); } + + public boolean isInside (Claim claim){ + BlockPos a = min, + b = max, + c = new BlockPos(max.getX(), min.getY(), min.getZ()), + d = new BlockPos(min.getX(), max.getY(), min.getZ()), + e = new BlockPos(min.getX(), min.getY(), max.getZ()), + f = new BlockPos(max.getX(), max.getY(), min.getZ()), + g = new BlockPos(max.getX(), min.getY(), max.getZ()), + h = new BlockPos(min.getX(), max.getY(), max.getZ()); + if( + claim.includesPosition(a) && + claim.includesPosition(b) && + claim.includesPosition(c) && + claim.includesPosition(d) && + claim.includesPosition(e) && + claim.includesPosition(f) && + claim.includesPosition(g) && + claim.includesPosition(h) + ){ + return true; + } + return false; + } + public boolean intersects(Claim claim) { return intersects(claim, true, false); } + + public int getEntities(ServerWorld world){ + AtomicReference entities = new AtomicReference<>(); + entities.set(0); + MonitorableWorld monitorableWorld = (MonitorableWorld) world; + monitorableWorld.EntityList().forEach((uuid, entity) -> { + if(includesPosition(entity.getBlockPos())) { + entities.set(entities.get()+1); + } + }); + + return entities.get(); + } + + public Map getEntitySorted(Map entityMap){ + AtomicReference> entityTypeMap = new AtomicReference<>(new HashMap<>()); + entityMap.forEach((uuid, entity) -> { + if(entityTypeMap.get().containsKey(entity.getType())){ + Map entityTypeIntegerMap = entityTypeMap.get(); + entityTypeIntegerMap.put(entity.getType(), entityTypeIntegerMap.get(entity.getType())+1); + entityTypeMap.set(entityTypeIntegerMap); + } else { + Map entityTypeIntegerMap = entityTypeMap.get(); + entityTypeIntegerMap.put(entity.getType(), 1); + entityTypeMap.set(entityTypeIntegerMap); + } + }); + return Functions.sortByValue(entityTypeMap.get()); + } + + public Map getEntityMap(Claim claim, ServerWorld world){ + AtomicReference> entityMap = new AtomicReference<>(new HashMap<>()); + MonitorableWorld monitorableWorld = (MonitorableWorld) world; + monitorableWorld.EntityList().forEach((uuid, entity) -> { + if(claim.includesPosition(entity.getBlockPos())) { + Map entityList = entityMap.get(); + entityList.put(uuid, entity); + entityMap.set(entityList); + } + }); + return entityMap.get(); + } + public boolean intersects(Claim claim, boolean checkOther, boolean checkforsubzone) { if (claim == null) return false; if (!claim.dimension.equals(dimension)) return false; @@ -98,24 +171,11 @@ public Claim getZoneCovering(BlockPos pos) { return null; } - /*public ClaimSettings getSettingsAt(BlockPos pos) { - Claim at = getZoneCovering(pos); - if (at != null) { - return at.settings; - } else return settings; - } - public ClaimPermissions getPermissionsAt(UUID player, BlockPos pos) { - Claim at = getZoneCovering(pos); - if (at != null) { - return at.getPlayerPermissions(player); - } else return settings; - }*/ + public boolean hasPermission(UUID player, Permission permission) { return ClaimManager.INSTANCE.ignoringClaims.contains(player) || permissionManager.hasPermission(player, permission); } - //public boolean hasPermissionAt(UUID player, ClaimPermissions.Permission permission, BlockPos pos) { - // return player.equals(owner) || ClaimManager.INSTANCE.ignoringClaims.contains(player) || getPermissionsAt(player, pos).hasPermission(permission); - //} + public void addSubzone(Claim claim) { children.add(claim); } @@ -124,66 +184,72 @@ public void removeSubzone(Claim claim) { children.remove(claim); } - @Nullable - AtomicReference atomic = new AtomicReference<>(); - public Claim getParentClaim(Claim subzone){ - if(subzone.isChild){ - ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> { - for(Claim subzone2 : claim.children){ - if(subzone2 == subzone){ - atomic.set(claim); - } - } - }); - return atomic.get(); - } - return null; - } - - public void expand(BlockPos min, BlockPos max) { - this.min = this.min.add(min); - this.max = this.max.add(max); - } public BlockPos getSize() { return max.subtract(min); } + public void expand(BlockPos modifier) { - if (modifier.getX() > 0) max = max.add(modifier.getX(), 0, 0); - else min = min.add(modifier.getX(), 0, 0); - if (modifier.getY() > 0) max = max.add(0, modifier.getY(), 0); - else min = min.add(0, modifier.getY(), 0); - if (modifier.getZ() > 0) max = max.add(0, 0, modifier.getZ()); - else min = min.add(0, 0, modifier.getZ()); - } - public boolean shrink(BlockPos modifier) { + if (modifier.getX() > 0) { + max = max.add(modifier.getX(), 0, 0); + } + else { + min = min.add(modifier.getX(), 0, 0); + } + if (modifier.getY() > 0) { + max = max.add(0, modifier.getY(), 0); + } + else { + min = min.add(0, modifier.getY(), 0); + } + if (modifier.getZ() > 0) { + max = max.add(0, 0, modifier.getZ()); + } + else { + min = min.add(0, 0, modifier.getZ()); + } + } + public void shrink(BlockPos modifier) { if (modifier.getX() < 0) { - if (min.getX() - modifier.getX() > max.getX()) return false; min = min.add(-modifier.getX(), 0, 0); } else { - if (max.getX() - modifier.getX() < min.getX()) return false; max = max.add(-modifier.getX(), 0, 0); } if (modifier.getY() < 0) { - if (min.getY() - modifier.getY() > max.getY()) return false; min = min.add(0, -modifier.getY(), 0); } else { - if (max.getY() - modifier.getY() < min.getY()) return false; max = max.add(0, -modifier.getY(), 0); } if (modifier.getZ() < 0) { - if (min.getZ() - modifier.getZ() > max.getZ()) return false; min = min.add(0, 0, -modifier.getZ()); } else { - if (max.getZ() - modifier.getZ() < min.getZ()) return false; max = max.add(0, 0, -modifier.getZ()); } + } + + public boolean canShrinkWithoutHittingOtherSide(BlockPos modifier){ + if (modifier.getX() < 0) { + if (min.getX() - modifier.getX() > max.getX()) return false; + } else { + if (max.getX() - modifier.getX() < min.getX()) return false; + } + if (modifier.getY() < 0) { + if (min.getY() - modifier.getY() > max.getY()) return false; + } else { + if (max.getY() - modifier.getY() < min.getY()) return false; + } + if (modifier.getZ() < 0) { + if (min.getZ() - modifier.getZ() > max.getZ()) return false; + } else { + if (max.getZ() - modifier.getZ() < min.getZ()) return false; + } return true; } + public void expand(Direction direction, int distance) { expand(new BlockPos(direction.getOffsetX() * distance, direction.getOffsetY() * distance, direction.getOffsetZ() * distance)); } - public boolean shrink(Direction direction, int distance) { - return shrink(new BlockPos(direction.getOffsetX() * distance, direction.getOffsetY() * distance, direction.getOffsetZ() * distance)); + public void shrink(Direction direction, int distance) { + shrink(new BlockPos(direction.getOffsetX() * distance, direction.getOffsetY() * distance, direction.getOffsetZ() * distance)); } public int getArea() { return getSize().getX() * (Config.claims2d ? 1 : getSize().getY()) * getSize().getZ(); @@ -215,6 +281,42 @@ public CompoundTag toTag() { tag.put("subzones", subzoneList); } } + { + CompoundTag rent1 = new CompoundTag(); + { + CompoundTag rented = new CompoundTag(); + if(rent.getTenant() != null) rented.putUuidNew("tenant", rent.getTenant()); + if(rent.getRentedUntil() != 0) rented.putInt("rentedUntil", rent.getRentedUntil()); + + { + if(rent.getRevenue() != null){ + CompoundTag revenue = new CompoundTag(); + int i = 0; + for(ItemStack itemStack : rent.getRevenue()){ + CompoundTag revenueTag = new CompoundTag(); + itemStack.toTag(revenueTag); + i++; + revenue.put(String.valueOf(i), revenueTag); + rent1.put("revenue", revenue); + } + } + } + rent1.put("rented", rented); + } + { + CompoundTag rentable = new CompoundTag(); + rentable.putBoolean("rentable", rent.isRentable()); + CompoundTag currency = new CompoundTag(); + if(rent.getCurrency() != ItemStack.EMPTY) rent.getCurrency().toTag(currency); + if(rent.getRentAbleTime() != 0) rentable.putInt("rentTime", rent.getRentAbleTime()); + if(rent.getMaxrentAbleTime() != 0) rentable.putInt("maxrentTime", rent.getMaxrentAbleTime()); + + rent1.put("rentable", rentable); + rentable.put("currency", currency); + } + tag.put("rent", rent1); + + } { tag.put("settings", settings.toTag()); tag.put("permissions", permissionManager.toNBT()); @@ -262,6 +364,31 @@ public void fromTag(CompoundTag tag) { } } } + { + CompoundTag rent1 = tag.getCompound("rent"); + { + CompoundTag rented = rent1.getCompound("rented"); + if (containsUUID(rented, "tenant")) rent.setTenant(getUUID(rented,"tenant")); + if(rented.contains("rentedUntil")) rent.setRentedUntil(rented.getInt("rentedUntil")); + } + { + CompoundTag rentable = rent1.getCompound("rentable"); + CompoundTag currency = rentable.getCompound("currency"); + if(rentable.contains("rentable")) rent.setRentable(rentable.getBoolean("rentable")); + if(currency != null) rent.setCurrency(ItemStack.fromTag(currency)); + if(rentable.contains("rentTime")) rent.setRentAbleTime(rentable.getInt("rentTime")); + if(rentable.contains("maxrentTime")) rent.setMaxrentAbleTime(rentable.getInt("maxrentTime")); + } + { + CompoundTag revenue = rent1.getCompound("revenue"); + if(!revenue.isEmpty()){ + for(int i = 1; i <= revenue.getSize(); i++){ + CompoundTag revenueTag = revenue.getCompound(String.valueOf(i)); + rent.addRevenue(ItemStack.fromTag(revenueTag)); + } + } + } + } { this.settings = new ClaimSettings(tag.getCompound("settings")); permissionManager = new PermissionManager(); @@ -282,6 +409,12 @@ public boolean is2d() { return min.getY() == 0 && max.getY() == 255; } + public void endRent(){ + permissionManager.playerPermissions.put(rent.getTenant(), new Claim.DefaultPermissionMap()); + rent.setRentedUntil(0); + rent.setTenant(null); + } + public enum Permission { //Admin REMOVE_CLAIM("remove_claim", "Remove Claim"), @@ -290,6 +423,8 @@ public enum Permission { MODIFY_PERMISSIONS("modify.permissions", "Change Permissions"), //Normal MODIFY_PROPERTIES("modify.properties", "Modify Claim Properties"), + MODIFY_SUBZONE("modify.subzone", "Add subzones"), + MOVE("move", "Move inside claim"), BUILD("build", "Place/Break Blocks"), INTERACT_BLOCKS("interact_blocks", "Interact With Blocks"), USE_ITEMS_ON_BLOCKS("use_items_on_blocks", "Use Block Modifying items"), @@ -310,7 +445,8 @@ public enum Permission { SPAWN_BOAT("spawn.boat", "Spawn Boats"); - String id, name; + public String id; + public String name; Permission(String id, String name) { this.id = id; this.name = name; @@ -322,10 +458,92 @@ public static Permission byId(String id) { return null; } } + + public class Rent { + + public UUID tenant = null; + public boolean rentable = false; + + public int rentTime = 0; + public int maxrentTime = 0; + public ArrayList revenue = new ArrayList<>(); + + + public ArrayList getRevenue() { + return revenue; + } + + public void addRevenue(ItemStack revenue) { + this.revenue.add(revenue); + } + + public void clearRevenue() { + revenue.clear(); + } + + //Payement + public ItemStack currency = ItemStack.EMPTY; + + public int rentedUntil = 0; + + public void setRentTime(int rentTime) { this.rentTime = rentTime; } + + //Max rent time + public int getMaxrentAbleTime() { return maxrentTime; } + public boolean isRented() { return rentedUntil != 0; } + + public void setMaxrentAbleTime(int maxrentTime) { this.maxrentTime = maxrentTime; } + + public int getRentedUntil() { + return rentedUntil; + } + + public void setRentedUntil(int rentedUntil) { + this.rentedUntil = rentedUntil; + } + + public int getRentTimeLeft(){ + return rentedUntil - getUnixTime(); + } + + public int getRentAbleTime() { return rentTime; } + + public void setRentAbleTime(int rentTime) { this.rentTime = rentTime; } + + //Returns seconds passed (Unix time) + public int getUnixTime(){ + return (int) (System.currentTimeMillis() / 1000); + } + + public void addRentTimeLeft(int rent){ + rentedUntil = rentedUntil + rent; + } + + public void removeRentTimeLeft(int rent){ addRentTimeLeft(-rent); } + + public void setRentTimeLeft(int time) { rentedUntil = getUnixTime() + time; } + + public UUID getTenant() { return tenant; } + + public void setTenant(UUID tenant) { this.tenant = tenant; } + + public boolean isRentable() { return rentable; } + + public void setRentable(boolean rentable) { this.rentable = rentable; } + + public int getAmount() { return currency.getCount(); } + + public void setAmount(int amount) { currency.setCount(amount); } + + public ItemStack getCurrency() { return currency; } + + public void setCurrency(ItemStack currency) { this.currency = currency; } + } + public static class PermissionManager { public ClaimPermissionMap defaults = new DefaultPermissionMap(); - protected Map playerPermissions = new HashMap<>(); - protected Map groupPermissions = new HashMap<>(); + public Map playerPermissions = new HashMap<>(); + public Map groupPermissions = new HashMap<>(); public boolean isPermissionSet(UUID player, Permission permission) { return playerPermissions.get(player) != null && playerPermissions.get(player).isPermissionSet(permission); } @@ -534,7 +752,7 @@ public enum Setting { ENTER_SOUND("enter_sound", "Enter Sound", false), BREAK_FARMLANDS("break_farmlands", "Break Farmlands", false); - String id, name; + public String id, name; boolean defaultValue; Setting(String id, String name, boolean defaultValue) { this.id = id; @@ -577,7 +795,7 @@ public enum Event { ENTER_CLAIM("enter", Config.msg_enter_default), LEAVE_CLAIM("leave", Config.msg_leave_default); - String id; + public String id; String defaultValue; Event(String id, String defaultValue) { this.id = id; @@ -601,9 +819,9 @@ public enum HelpBook { COMMAND("commands", Messages.HELP, "Claim Commands"), PERMS_AND_SETTINGS("perms_and_settings", Messages.SETTINGS_AND_PERMISSIONS, "Claim Permissions and Settings"); - String id; - String title; - Text[] texts; + public String id; + public String title; + public Text[] texts; HelpBook(String id, Text[] texts, String title) { this.id = id; this.title = title; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 47a2c71..b5cd557 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1,469 +1,439 @@ package io.github.indicode.fabric.itsmine; -import blue.endless.jankson.annotation.Nullable; -import com.mojang.authlib.GameProfile; -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.ArgumentBuilder; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import io.github.indicode.fabric.itsmine.mixin.BlockUpdatePacketMixin; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.command.EntitySelector; -import net.minecraft.command.arguments.BlockPosArgumentType; -import net.minecraft.command.arguments.EntityArgumentType; -import net.minecraft.command.arguments.GameProfileArgumentType; -import net.minecraft.command.arguments.PosArgument; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; -import net.minecraft.server.MinecraftServer; -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.*; -import net.minecraft.util.Formatting; -import net.minecraft.util.Pair; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.dimension.DimensionType; - -import java.lang.reflect.Array; -import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Predicate; - -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - /** * @author Indigo Amann */ -public class ClaimCommand { - public static final int MAX_NAME_LENGTH = 30; - private static void validateCanAccess(ServerPlayerEntity player, Claim claim, boolean admin) throws CommandSyntaxException { - if (claim == null) { - throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); - } - - if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SETTINGS)) { - throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); - } - } - - private static void validateClaim(Claim claim) throws CommandSyntaxException { - if (claim == null) throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); - } - - private static RequiredArgumentBuilder getClaimArgument() { - return argument("claim", StringArgumentType.word()).suggests(CLAIM_PROVIDER); - } - - private static Predicate perm(String str) { - return perm(str, 2); - } - private static Predicate perm(String str, int op) { - return source -> ItsMine.permissions().hasPermission(source, "itsmine." + str, op); - } - private static final Predicate PERMISSION_CHECK_ADMIN = src -> perm("admin").test(src) || perm("admin.modify_balance").test(src) || - perm("admin.infinite_blocks").test(src) || perm("admin.modify").test(src) || - perm("admin.modify_balance").test(src) || perm("admin.ignore_claims").test(src) || - perm("admin.modify_permissions").test(src); - - public static final SuggestionProvider DIRECTION_SUGGESTION_BUILDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (Direction direction: Direction.values()) { - if (Config.claims2d && (direction == Direction.DOWN || direction == Direction.UP)) continue; - strings.add(direction.getName()); - }; - return CommandSource.suggestMatching(strings, builder); - }; - public static final SuggestionProvider BOOK_SUGGESTIONS = (source, builder) -> { - List strings = new ArrayList<>(); - for (Claim.HelpBook value : Claim.HelpBook.values()) { - strings.add(value.id); - } - return CommandSource.suggestMatching(strings, builder); - }; - public static final SuggestionProvider CLAIM_PROVIDER = (source, builder) -> { - ServerPlayerEntity player = source.getSource().getPlayer(); - List names = new ArrayList<>(); - Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); - if (current != null) names.add(current.name); - for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { - if (claim != null) { - names.add(claim.name); - } - } - return CommandSource.suggestMatching(names, builder); - }; - public static final SuggestionProvider PLAYERS_PROVIDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (ServerPlayerEntity player : source.getSource().getMinecraftServer().getPlayerManager().getPlayerList()) { - strings.add(player.getEntityName()); - } - return CommandSource.suggestMatching(strings, builder); - }; - public static final SuggestionProvider SETTINGS_PROVIDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { - strings.add(value.id); - } - for (Claim.Permission value : Claim.Permission.values()) { - strings.add(value.id); - } - return CommandSource.suggestMatching(strings, builder); - }; - public static final SuggestionProvider PERMISSIONS_PROVIDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (Claim.Permission value : Claim.Permission.values()) { - strings.add(value.id); - } - return CommandSource.suggestMatching(strings, builder); - }; - public static final SuggestionProvider MESSAGE_EVENTS_PROVIDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (Claim.Event value : Claim.Event.values()) { - strings.add(value.id); - } - return CommandSource.suggestMatching(strings, builder); - }; - public static final SuggestionProvider EVENT_MESSAGE_PROVIDER = (source, builder) -> { - if (!builder.getRemaining().isEmpty()) - return builder.buildFuture(); - - List strings = new ArrayList<>(); - strings.add("reset"); - try { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(source, "claim")); - Claim.Event eventType = Claim.Event.getById(StringArgumentType.getString(source, "messageEvent")); - - if (eventType != null && claim != null) { - String message = eventType == Claim.Event.ENTER_CLAIM ? claim.enterMessage : claim.leaveMessage; - if (message != null) strings.add(message); - } - - } catch (Exception ignored) { - } - - return CommandSource.suggestMatching(strings, builder); - }; - - public static void register(CommandDispatcher dispatcher) { - LiteralArgumentBuilder main = literal("itsmine") - .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); - - register(main, dispatcher); - - LiteralArgumentBuilder alias = literal("claim") - .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); - - register(alias, dispatcher); - - dispatcher.register(main); - dispatcher.register(alias); - } - - private static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { - SubzoneCommand.register(command, false); - { - LiteralArgumentBuilder help = literal("help"); - help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); - - RequiredArgumentBuilder id = argument("id", StringArgumentType.word()) - .suggests(BOOK_SUGGESTIONS); - RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); - - page.executes((context) -> { - Claim.HelpBook book = Claim.HelpBook.getById(StringArgumentType.getString(context, "id")); - if (book == null) { - context.getSource().sendError(new LiteralText("Invalid Book!")); - return -1; - } - int p = IntegerArgumentType.getInteger(context, "page"); - - if (p > book.texts.length) p = 1; - return sendPage(context.getSource(), book.texts, p, book.title, book.getCommand()); - }); - - id.then(page); - help.then(id); - command.then(help); - } - { - LiteralArgumentBuilder create = literal("create"); - RequiredArgumentBuilder name = argument("name", StringArgumentType.word()); - - name.executes(context -> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); - if (selectedPositions == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getLeft() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getRight() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); - } else { - String cname = StringArgumentType.getString(context, "name"); - if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), false, null) > 0) { - ClaimManager.INSTANCE.stickPositions.remove(player); - } - } - return 0; - }); - - ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); - RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); - max.executes(context -> createClaim( - StringArgumentType.getString(context, "name"), - context.getSource(), - BlockPosArgumentType.getBlockPos(context, "min"), - BlockPosArgumentType.getBlockPos(context, "max"), - false, - null - )); - min.then(max); - name.then(min); - create.then(name); - command.then(create); - } - { - LiteralArgumentBuilder fly = literal("fly") - .requires(src -> ItsMine.permissions().hasPermission(src, Permissions.Command.CLAIM_FLY, 2)); - RequiredArgumentBuilder setArgument = CommandManager.argument("set", BoolArgumentType.bool()); - - fly.executes((context) -> setFly(context, !ClaimManager.INSTANCE.flyers.contains(context.getSource().getPlayer().getUuid()))); - setArgument.executes((context) -> setFly(context, BoolArgumentType.getBool(context, "set"))); - - fly.then(setArgument); - command.then(fly); - } - { - LiteralArgumentBuilder rename = literal("rename"); - RequiredArgumentBuilder claimArgument = getClaimArgument().suggests(CLAIM_PROVIDER); - RequiredArgumentBuilder nameArgument = argument("name", StringArgumentType.word()); - nameArgument.executes((context) -> rename(context, false)); - claimArgument.then(nameArgument); - rename.then(claimArgument); - command.then(rename); - } - { - LiteralArgumentBuilder trusted = literal("trusted"); - RequiredArgumentBuilder claimArgument = getClaimArgument(); - trusted.executes((context)-> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); - if (claim == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return showTrustedList(context, claim, false); - }); - - claimArgument.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return showTrustedList(context, claim, false); - }); - trusted.then(claimArgument); - command.then(trusted); - dispatcher.register(trusted); - } - { - LiteralArgumentBuilder stick = literal("stick"); - stick.executes(context -> { - Pair posPair = ClaimManager.INSTANCE.stickPositions.get(context.getSource().getPlayer()); - context.getSource().sendFeedback(new LiteralText(posPair == null ? "You can now use a stick to create claims. Run this command again to disable" : "Claim stick disabled. Run this command again to enable").formatted(Formatting.DARK_PURPLE), false); - if (posPair == null) { - ClaimManager.INSTANCE.stickPositions.put(context.getSource().getPlayer(), new Pair<>(null, null)); - } else { - ClaimManager.INSTANCE.stickPositions.remove(context.getSource().getPlayer()); - } - return 0; - }); - command.then(stick); - } - { - LiteralArgumentBuilder show = literal("show"); - show.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().dimension.getType()), false)); - RequiredArgumentBuilder name = argument("name", StringArgumentType.word()); - name.suggests(CLAIM_PROVIDER); - name.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "name")), false)); - show.then(name); - command.then(show); - } - { - LiteralArgumentBuilder hide = literal("hide"); - hide.executes(context -> showClaim(context.getSource(), null, true)); - command.then(hide); - } - { - LiteralArgumentBuilder check = literal("blocks"); - RequiredArgumentBuilder other = argument("player", EntityArgumentType.player()); - other.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_CHECK_OTHERS, 2)); - other.executes(ctx -> checkPlayer(ctx.getSource(), EntityArgumentType.getPlayer(ctx, "player").getGameProfile().getId())); - check.then(other); - check.executes(ctx -> checkPlayer(ctx.getSource(), ctx.getSource().getPlayer().getGameProfile().getId())); - command.then(check); - } - { - LiteralArgumentBuilder delete = literal("remove"); - RequiredArgumentBuilder claim = getClaimArgument(); - claim.suggests(CLAIM_PROVIDER); - LiteralArgumentBuilder confirm = literal("confirm"); - confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); - claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); - claim.then(confirm); - delete.then(claim); - delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); - command.then(delete); - } - { - { - LiteralArgumentBuilder expand = literal("expand"); - RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); - direction.suggests(DIRECTION_SUGGESTION_BUILDER); - - direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - IntegerArgumentType.getInteger(context, "distance"), - directionByName(StringArgumentType.getString(context, "direction")), - context.getSource(), - false - )); - - amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - IntegerArgumentType.getInteger(context, "distance"), - Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], - context.getSource(), - false - )); - - amount.then(direction); - expand.then(amount); - command.then(expand); - } - { - LiteralArgumentBuilder shrink = literal("shrink"); - RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); - direction.suggests(DIRECTION_SUGGESTION_BUILDER); - - direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - -IntegerArgumentType.getInteger(context, "distance"), - directionByName(StringArgumentType.getString(context, "direction")), - context.getSource(), - false - )); - - amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - -IntegerArgumentType.getInteger(context, "distance"), - Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], - context.getSource(), - false - )); +//public class ClaimCommand { +// public static final int MAX_NAME_LENGTH = 30; +// private static void validateCanAccess(ServerPlayerEntity player, Claim claim, boolean admin) throws CommandSyntaxException { +// if (claim == null) { +// throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); +// } +// +// if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SETTINGS)) { +// throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); +// } +// } +// +// private static void validateClaim(Claim claim) throws CommandSyntaxException { +// if (claim == null) throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); +// } +// +// +// private static Predicate perm(String str) { +// return perm(str, 2); +// } +// private static Predicate perm(String str, int op) { +// return source -> ItsMine.permissions().hasPermission(source, "itsmine." + str, op); +// } +// private static final Predicate PERMISSION_CHECK_ADMIN = src -> perm("admin").test(src) || perm("admin.modify_balance").test(src) || +// perm("admin.infinite_blocks").test(src) || perm("admin.modify").test(src) || +// perm("admin.modify_balance").test(src) || perm("admin.ignore_claims").test(src) || +// perm("admin.modify_permissions").test(src); +// - amount.then(direction); - shrink.then(amount); - command.then(shrink); - } - } - { - LiteralArgumentBuilder delete = literal("remove"); - RequiredArgumentBuilder claim = getClaimArgument(); - LiteralArgumentBuilder confirm = literal("confirm"); - confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); - claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); - claim.then(confirm); - delete.then(claim); - delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); - command.then(delete); - } - { - LiteralArgumentBuilder transfer = literal("transfer"); - RequiredArgumentBuilder claim = argument("claim", StringArgumentType.word()).suggests(CLAIM_PROVIDER); - RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); - LiteralArgumentBuilder confirm = literal("confirm"); - confirm.executes(context -> { - final String string = "-accept-"; - ServerPlayerEntity p = EntityArgumentType.getPlayer(context, "player"); - String input = StringArgumentType.getString(context, "claim"); - String claimName = input.replace(string, ""); - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(claimName); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } +// public static final SuggestionProvider PLAYERS_PROVIDER = (source, builder) -> { +// List strings = new ArrayList<>(); +// for (ServerPlayerEntity player : source.getSource().getMinecraftServer().getPlayerManager().getPlayerList()) { +// strings.add(player.getEntityName()); +// } +// return CommandSource.suggestMatching(strings, builder); +// }; +// public static final SuggestionProvider SETTINGS_PROVIDER = (source, builder) -> { +// List strings = new ArrayList<>(); +// for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { +// strings.add(value.id); +// } +// for (Claim.Permission value : Claim.Permission.values()) { +// strings.add(value.id); +// } +// return CommandSource.suggestMatching(strings, builder); +// }; +// public static final SuggestionProvider PERMISSIONS_PROVIDER = (source, builder) -> { +// List strings = new ArrayList<>(); +// for (Claim.Permission value : Claim.Permission.values()) { +// strings.add(value.id); +// } +// return CommandSource.suggestMatching(strings, builder); +// }; +// public static final SuggestionProvider MESSAGE_EVENTS_PROVIDER = (source, builder) -> { +// List strings = new ArrayList<>(); +// for (Claim.Event value : Claim.Event.values()) { +// strings.add(value.id); +// } +// return CommandSource.suggestMatching(strings, builder); +// }; +// public static final SuggestionProvider EVENT_MESSAGE_PROVIDER = (source, builder) -> { +// if (!builder.getRemaining().isEmpty()) +// return builder.buildFuture(); +// +// List strings = new ArrayList<>(); +// strings.add("reset"); +// try { +// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(source, "claim")); +// Claim.Event eventType = Claim.Event.getById(getString(source, "messageEvent")); +// +// if (eventType != null && claim != null) { +// String message = eventType == Claim.Event.ENTER_CLAIM ? claim.enterMessage : claim.leaveMessage; +// if (message != null) strings.add(message); +// } +// +// } catch (Exception ignored) { +// } +// +// return CommandSource.suggestMatching(strings, builder); +// }; - if (input.startsWith(string)) { - return acceptTransfer(context.getSource()); - } +// public static void register(CommandDispatcher dispatcher) { +// LiteralArgumentBuilder main = literal("itsmine"); +// main.executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); +// +// register(main, dispatcher); +// +// LiteralArgumentBuilder alias = literal("claim"); +// alias.executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); +// +// register(alias, dispatcher); +// +// dispatcher.register(main); +// dispatcher.register(alias); +// } - return transfer(context.getSource(), claim1, p, false); - }); - player.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), EntityArgumentType.getPlayer(context, "player"), false)); - player.then(confirm); - claim.then(player); - transfer.then(claim); - transfer.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), EntityArgumentType.getPlayer(context, "player"), false)); - command.then(transfer); - } - { - LiteralArgumentBuilder info = literal("info"); - RequiredArgumentBuilder claim = getClaimArgument(); - info.executes(context -> info( - context.getSource(), - ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()) - )); - claim.executes(context -> info( - context.getSource(), - ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")) - )); - info.then(claim); - command.then(info); - } - { - LiteralArgumentBuilder list = literal("list"); - LiteralArgumentBuilder listall = literal("listall"); - RequiredArgumentBuilder player = argument("player", StringArgumentType.word()); - player.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_CHECK_OTHERS, 2)); - player.suggests(PLAYERS_PROVIDER); - list.executes(context -> list(context.getSource(), context.getSource().getName())); - listall.executes(context -> listall(context.getSource())); - player.executes(context -> list(context.getSource(), StringArgumentType.getString(context, "player"))); - list.then(player); - command.then(list); - command.then(listall); +// private static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { +// SubzoneCommand.register(command); - LiteralArgumentBuilder claims = literal("claims") - .executes(context -> list(context.getSource(), context.getSource().getName())) - .then(player); - dispatcher.register(claims); - } - { - //TODO: FIX THIS +// { +// LiteralArgumentBuilder help = literal("help"); +// help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); +// +// RequiredArgumentBuilder id = getHelpId(); +// RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); +// +// page.executes((context) -> { +// Claim.HelpBook book = Claim.HelpBook.getById(getString(context, "id")); +// if (book == null) { +// context.getSource().sendError(new LiteralText("Invalid Book!")); +// return -1; +// } +// int p = IntegerArgumentType.getInteger(context, "page"); +// +// if (p > book.texts.length) p = 1; +// return sendPage(context.getSource(), book.texts, p, book.title, book.getCommand()); +// }); +// +// id.then(page); +// help.then(id); +// command.then(help); +// } +// { +// LiteralArgumentBuilder create = literal("create"); +// RequiredArgumentBuilder name = argument("name", word()); +// +// name.executes(context -> { +// ServerPlayerEntity player = context.getSource().getPlayer(); +// Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); +// if (selectedPositions == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); +// } else if (selectedPositions.getLeft() == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); +// } else if (selectedPositions.getRight() == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); +// } else { +// String cname = getString(context, "name"); +// if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), false, null) > 0) { +// ClaimManager.INSTANCE.stickPositions.remove(player); +// } +// } +// return 0; +// }); +// +// ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); +// RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); +// max.executes(context -> createClaim( +// getString(context, "name"), +// context.getSource(), +// BlockPosArgumentType.getBlockPos(context, "min"), +// BlockPosArgumentType.getBlockPos(context, "max"), +// false, +// null +// )); +// min.then(max); +// name.then(min); +// create.then(name); +// command.then(create); +// } +// { +// LiteralArgumentBuilder fly = literal("fly") +// .requires(src -> ItsMine.permissions().hasPermission(src, PermissionUtil.Command.CLAIM_FLY, 2)); +// RequiredArgumentBuilder setArgument = CommandManager.argument("set", BoolArgumentType.bool()); +// +// fly.executes((context) -> setFly(context, !ClaimManager.INSTANCE.flyers.contains(context.getSource().getPlayer().getUuid()))); +// setArgument.executes((context) -> setFly(context, BoolArgumentType.getBool(context, "set"))); +// +// fly.then(setArgument); +// command.then(fly); +// } +// { +// LiteralArgumentBuilder rename = literal("rename"); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); +// RequiredArgumentBuilder nameArgument = argument("name", word()); +// nameArgument.executes((context) -> rename(context, false)); +// claimArgument.then(nameArgument); +// rename.then(claimArgument); +// command.then(rename); +// } +// { +// LiteralArgumentBuilder trusted = literal("trusted"); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); +// trusted.executes((context)-> { +// ServerPlayerEntity player = context.getSource().getPlayer(); +// Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); +// if (claim == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// return showTrustedList(context, claim, false); +// }); +// +// claimArgument.executes((context) -> { +// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (claim == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// return showTrustedList(context, claim, false); +// }); +// trusted.then(claimArgument); +// command.then(trusted); +// dispatcher.register(trusted); +// } +// { +// LiteralArgumentBuilder stick = literal("stick"); +// stick.executes(context -> { +// Pair posPair = ClaimManager.INSTANCE.stickPositions.get(context.getSource().getPlayer()); +// context.getSource().sendFeedback(new LiteralText(posPair == null ? "You can now use a stick to create claims. Run this command again to disable" : "Claim stick disabled. Run this command again to enable").formatted(Formatting.DARK_PURPLE), false); +// if (posPair == null) { +// ClaimManager.INSTANCE.stickPositions.put(context.getSource().getPlayer(), new Pair<>(null, null)); +// } else { +// ClaimManager.INSTANCE.stickPositions.remove(context.getSource().getPlayer()); +// } +// return 0; +// }); +// command.then(stick); +// } +// { +// LiteralArgumentBuilder show = literal("show"); +// show.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().dimension.getType()), false)); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// claim.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "name")), false)); +// show.then(claim); +// command.then(show); +// } +// { +// LiteralArgumentBuilder hide = literal("hide"); +// hide.executes(context -> showClaim(context.getSource(), null, true)); +// command.then(hide); +// } +// { +// LiteralArgumentBuilder check = literal("blocks"); +// RequiredArgumentBuilder other = argument("player", EntityArgumentType.player()); +// other.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); +// other.executes(ctx -> checkPlayer(ctx.getSource(), EntityArgumentType.getPlayer(ctx, "player").getGameProfile().getId())); +// check.then(other); +// check.executes(ctx -> checkPlayer(ctx.getSource(), ctx.getSource().getPlayer().getGameProfile().getId())); +// command.then(check); +// } +// { +// LiteralArgumentBuilder delete = literal("remove"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// LiteralArgumentBuilder confirm = literal("confirm"); +// confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); +// claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); +// claim.then(confirm); +// delete.then(claim); +// delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); +// command.then(delete); +// } +// { +// { +// LiteralArgumentBuilder expand = literal("expand"); +// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); +// RequiredArgumentBuilder direction = getDirections(); +// +// direction.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// IntegerArgumentType.getInteger(context, "distance"), +// directionByName(getString(context, "direction")), +// context.getSource(), +// false +// )); +// +// amount.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// IntegerArgumentType.getInteger(context, "distance"), +// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], +// context.getSource(), +// false +// )); +// +// amount.then(direction); +// expand.then(amount); +// command.then(expand); +// } +// { +// LiteralArgumentBuilder shrink = literal("shrink"); +// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); +// RequiredArgumentBuilder direction = getDirections(); +// +// direction.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// -IntegerArgumentType.getInteger(context, "distance"), +// directionByName(getString(context, "direction")), +// context.getSource(), +// false +// )); +// +// amount.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// -IntegerArgumentType.getInteger(context, "distance"), +// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], +// context.getSource(), +// false +// )); +// +// amount.then(direction); +// shrink.then(amount); +// command.then(shrink); +// } +// } +// { +// LiteralArgumentBuilder delete = literal("remove"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// LiteralArgumentBuilder confirm = literal("confirm"); +// confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); +// claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); +// claim.then(confirm); +// delete.then(claim); +// delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); +// command.then(delete); +// } +// { +// LiteralArgumentBuilder transfer = literal("transfer"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); +// LiteralArgumentBuilder confirm = literal("confirm"); +// confirm.executes(context -> { +// final String string = "-accept-"; +// ServerPlayerEntity p = EntityArgumentType.getPlayer(context, "player"); +// String input = getString(context, "claim"); +// String claimName = input.replace(string, ""); +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(claimName); +// if (claim1 == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// +// if (input.startsWith(string)) { +// return acceptTransfer(context.getSource()); +// } +// +// return transfer(context.getSource(), claim1, p, false); +// }); +// player.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), EntityArgumentType.getPlayer(context, "player"), false)); +// player.then(confirm); +// claim.then(player); +// transfer.then(claim); +// transfer.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), EntityArgumentType.getPlayer(context, "player"), false)); +// command.then(transfer); +// } +// { +// ///claim rentable [] +// LiteralArgumentBuilder rentable = literal("rentable"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// +// RequiredArgumentBuilder currency = CommandManager.argument("item", ItemStackArgumentType.itemStack()).suggests(ClaimCommand::itemsSuggestion); +// RequiredArgumentBuilder amount = CommandManager.argument("count", IntegerArgumentType.integer(1)); +// RequiredArgumentBuilder days = CommandManager.argument("days", StringArgumentType.string() +// ); +// RequiredArgumentBuilder maxdays = CommandManager.argument("maxdays", string()); +// maxdays.executes(context -> makeRentable(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false), IntegerArgumentType.getInteger(context, "count"), getString(context, "days"), getString(context, "maxdays"))); +// claim.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if(claim1.rent.getCurrency() !=null || claim1.rent.getAmount() != 0 || claim1.rent.getRentAbleTime() != 0 || claim1.rent.getMaxrentAbleTime() != 0 && claim1.rent.isRentable()) { +// context.getSource().sendFeedback(new LiteralText("Can't enable rent for " + claim1.name + ", because no values are set").formatted(Formatting.RED), true); +// return 0; +// } +// if(claim1.rent.getTenant() == null){ +// String state = claim1.rent.isRentable() ? "disabled" : "enabled"; +// claim1.rent.setRentable(!claim1.rent.isRentable()); +// context.getSource().sendFeedback(new LiteralText("Renting for " + claim1.name + " has been " + state).formatted(Formatting.GREEN), true); +// return 1; +// } else { +// context.getSource().sendFeedback(new LiteralText("Can't disable rent for " + claim1.name + ", because it is currently being rented").formatted(Formatting.RED), true); +// return 0; +// } +// }); +// +// days.then(maxdays); +// amount.then(days); +// currency.then(amount); +// claim.then(currency); +// rentable.then(claim); +// command.then(rentable); +// } +// { +// LiteralArgumentBuilder rent = literal("rent"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// RequiredArgumentBuilder days = CommandManager.argument("days", string()); +// days.executes(context -> rent(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), getString(context, "days"))); +// +// claim.then(days); +// rent.then(claim); +// command.then(rent); +// } +// { +// LiteralArgumentBuilder info = literal("info"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// info.executes(context -> info( +// context.getSource(), +// ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()) +// )); +// claim.executes(context -> info(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")) +// )); +// info.then(claim); +// command.then(info); +// } +// { +// LiteralArgumentBuilder revenue = literal("revenue"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// RequiredArgumentBuilder claimRevenue = argument("claimRevenue", BoolArgumentType.bool()); +// revenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); +// claim.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); +// claimRevenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); +// claim.then(claimRevenue); +// revenue.then(claim); +// command.then(revenue); +// } +// { +// LiteralArgumentBuilder list = literal("list"); +// LiteralArgumentBuilder listall = literal("listall"); +// RequiredArgumentBuilder player = argument("player", word()); +// player.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); +// player.suggests(PLAYERS_PROVIDER); +// list.executes(context -> list(context.getSource(), context.getSource().getName())); +// listall.executes(context -> listall(context.getSource())); +// player.executes(context -> list(context.getSource(), getString(context, "player"))); +// list.then(player); +// command.then(list); +// command.then(listall); +// +// LiteralArgumentBuilder claims = literal("claims") +// .executes(context -> list(context.getSource(), context.getSource().getName())) +// .then(player); +// dispatcher.register(claims); +// } +// { +// //TODO: FIX THIS // LiteralArgumentBuilder listall = literal("listall"); // RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); // @@ -471,1211 +441,1466 @@ private static void register(LiteralArgumentBuilder command // page.executes(context -> listAll(context.getSource(), IntegerArgumentType.getInteger(context, "page"))); // listall.then(page); // command.then(listall); - } - { - LiteralArgumentBuilder trust = literal("trust"); - RequiredArgumentBuilder playerArgument = argument("player", EntityArgumentType.player()); - RequiredArgumentBuilder claimArgument = getClaimArgument(); - - playerArgument.executes((context -> executeTrust(context, EntityArgumentType.getPlayer(context, "player"), true, null))); - claimArgument.executes((context -> executeTrust(context, EntityArgumentType.getPlayer(context, "player"), true, StringArgumentType.getString(context, "claim")))); - - playerArgument.then(claimArgument); - trust.then(playerArgument); - command.then(trust); - dispatcher.register(trust); - } - { - LiteralArgumentBuilder distrust = literal("distrust"); - RequiredArgumentBuilder playerArgument = argument("player", EntityArgumentType.entity()); - RequiredArgumentBuilder claimArgument = getClaimArgument(); - - playerArgument.executes((context -> executeTrust(context, EntityArgumentType.getEntity(context, "player"), false, null))); - claimArgument.executes((context -> executeTrust(context, EntityArgumentType.getEntity(context, "player"), false, StringArgumentType.getString(context, "claim")))); - - playerArgument.then(claimArgument); - distrust.then(playerArgument); - command.then(distrust); - dispatcher.register(distrust); - } - - createExceptionCommand(command, false); - - { - LiteralArgumentBuilder admin = literal("admin"); - admin.requires(PERMISSION_CHECK_ADMIN); - { - LiteralArgumentBuilder add = literal("addBlocks"); - add.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_BALANCE, 2)); - RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); - RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); - amount.executes(context -> { - ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); - context.getSource().sendFeedback(new LiteralText("Gave " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); - return 0; - }); - player.then(amount); - add.then(player); - admin.then(add); - } - { - LiteralArgumentBuilder set = literal("setOwner"); - RequiredArgumentBuilder newOwner = argument("newOwner", GameProfileArgumentType.gameProfile()); - RequiredArgumentBuilder claimArgument = getClaimArgument(); - - newOwner.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); - if (claim == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - - Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); - - if (profiles.size() > 1) { - context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); - return -1; - } - return setOwner(context.getSource(), claim, profiles.iterator().next()); - }); - - claimArgument.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - - Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); - - if (profiles.size() > 1) { - context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); - return -1; - } - return setOwner(context.getSource(), claim, profiles.iterator().next()); - }); - - newOwner.then(claimArgument); - set.then(newOwner); - admin.then(set); - } - { - LiteralArgumentBuilder set = literal("setOwnerName"); - RequiredArgumentBuilder nameArgument = argument("newName", StringArgumentType.word()); - RequiredArgumentBuilder claimArgument = getClaimArgument(); - - nameArgument.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); - if (claim == null) { - context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return -1; - } - return setOwnerName(context.getSource(), claim, StringArgumentType.getString(context, "newName")); - }); - - claimArgument.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim == null) { - context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return -1; - } - return setOwnerName(context.getSource(), claim, StringArgumentType.getString(context, "newName")); - }); - - nameArgument.then(claimArgument); - set.then(nameArgument); - admin.then(set); - } - { - LiteralArgumentBuilder rename = literal("rename"); - RequiredArgumentBuilder claimArgument = argument("claim", StringArgumentType.word()) - .suggests(CLAIM_PROVIDER); - RequiredArgumentBuilder nameArgument = argument("name", StringArgumentType.word()); - nameArgument.executes((context) -> rename(context, true)); - claimArgument.then(nameArgument); - rename.then(claimArgument); - admin.then(rename); - } - { - LiteralArgumentBuilder remove = literal("removeBlocks"); - remove.requires(source ->ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_BALANCE, 2)); - RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); - RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); - amount.executes(context -> { - ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), -IntegerArgumentType.getInteger(context, "amount")); - context.getSource().sendFeedback(new LiteralText("Took " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); - return 0; - }); - player.then(amount); - remove.then(player); - admin.then(remove); - } - { - LiteralArgumentBuilder set = literal("setBlocks"); - set.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_BALANCE, 2)); - RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); - RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); - amount.executes(context -> { - ClaimManager.INSTANCE.setClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); - context.getSource().sendFeedback(new LiteralText("Set claim block amount to " + IntegerArgumentType.getInteger(context, "amount")).formatted(Formatting.GREEN), true); - return 0; - }); - player.then(amount); - set.then(player); - admin.then(set); - } - { - LiteralArgumentBuilder delete = literal("remove"); - delete.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY, 2)); - RequiredArgumentBuilder claim = getClaimArgument(); - LiteralArgumentBuilder confirm = literal("confirm"); - confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), true)); - claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), true)); - claim.then(confirm); - delete.then(claim); - delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), true)); - admin.then(delete); - } - { - LiteralArgumentBuilder create = literal("create"); - create.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_INFINITE_CLAIM, 2)); - ArgumentBuilder name = argument("name", StringArgumentType.word()); - ArgumentBuilder customOwner = argument("customOwnerName", StringArgumentType.word()); - ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); - RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); - max.executes(context -> createClaim( - StringArgumentType.getString(context, "name"), - context.getSource(), - BlockPosArgumentType.getBlockPos(context, "min"), - BlockPosArgumentType.getBlockPos(context, "max"), - true, - null - )); - name.executes(context -> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); - if (selectedPositions == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getLeft() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getRight() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); - } else { - String cname = StringArgumentType.getString(context, "name"); - if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, null) > 0) { - ClaimManager.INSTANCE.stickPositions.remove(player); - } - } - return 0; - }); - customOwner.executes(context -> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); - if (selectedPositions == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getLeft() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getRight() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); - } else { - String cname = StringArgumentType.getString(context, "name"); - if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, StringArgumentType.getString(context, "customOwnerName")) > 0) { - ClaimManager.INSTANCE.stickPositions.remove(player); - } - } - return 0; - }); - min.then(max); - name.then(customOwner); - name.then(min); - create.then(name); - admin.then(create); - } - { - LiteralArgumentBuilder ignore = literal("ignoreClaims"); - ignore.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_IGNORE_CLAIMS, 2)); - ignore.executes(context -> { - UUID id = context.getSource().getPlayer().getGameProfile().getId(); - boolean isIgnoring = ClaimManager.INSTANCE.ignoringClaims.contains(id); - if (isIgnoring) ClaimManager.INSTANCE.ignoringClaims.remove(id); - else ClaimManager.INSTANCE.ignoringClaims.add(id); - context.getSource().sendFeedback(new LiteralText("You are " + (isIgnoring ? "no longer" : "now") + " ignoring claims.").formatted(Formatting.GREEN), false); - return 0; - }); - admin.then(ignore); - } - { - { - LiteralArgumentBuilder expand = literal("expand"); - expand.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY, 2)); - RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); - direction.suggests(DIRECTION_SUGGESTION_BUILDER); - - direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - IntegerArgumentType.getInteger(context, "distance"), - directionByName(StringArgumentType.getString(context, "direction")), - context.getSource(), - true - )); - - amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - IntegerArgumentType.getInteger(context, "distance"), - Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], - context.getSource(), - true - )); - - amount.then(direction); - expand.then(amount); - admin.then(expand); - } - { - LiteralArgumentBuilder shrink = literal("shrink"); - shrink.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY, 2)); - RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); - direction.suggests(DIRECTION_SUGGESTION_BUILDER); - - direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - -IntegerArgumentType.getInteger(context, "distance"), - directionByName(StringArgumentType.getString(context, "direction")), - context.getSource(), - true - )); - - amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - -IntegerArgumentType.getInteger(context, "distance"), - Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], - context.getSource(), - true - )); - - amount.then(direction); - shrink.then(amount); - admin.then(shrink); - } - } - createExceptionCommand(admin, true); - command.then(admin); - } - } - - private static int sendPage(ServerCommandSource source, Text[] text, int page, String title, String command) { - int prevPage = page - 2; - int thisPage = page - 1; - int nextPage = page + 1; - final String SEPARATOR = "-----------------------------------------------------"; - Text header = new LiteralText("") - .append(new LiteralText("- [ ").formatted(Formatting.GRAY)) - .append(new LiteralText(title).formatted(Formatting.GOLD)) - .append(" ] ") - .append(SEPARATOR.substring(ChatColor.removeAlternateColorCodes('&', title).length() + 4)) - .formatted(Formatting.GRAY); - - Text button_prev = new LiteralText("") - .append(new LiteralText("<-").formatted(Formatting.WHITE, Formatting.BOLD)) - .append(" ").append(new LiteralText("Prev").formatted(Formatting.GOLD)) - .styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); - if (prevPage >= 0) - style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); - }); - - Text button_next = new LiteralText("") - .append(new LiteralText("Next").formatted(Formatting.GOLD)) - .append(" ").append(new LiteralText("->").formatted(Formatting.WHITE, Formatting.BOLD)).append(" ") - .styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); - if (nextPage <= text.length) - style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); - }); - - Text buttons = new LiteralText("") - .append(new LiteralText("[ ").formatted(Formatting.GRAY)) - .append(button_prev) - .append(" ") - .append( - new LiteralText(String.valueOf(page)).formatted(Formatting.GREEN) - .append(new LiteralText("/").formatted(Formatting.GRAY)) - .append(new LiteralText(String.valueOf(text.length)).formatted(Formatting.GREEN)) - ) - .append(" ") - .append(button_next) - .append(new LiteralText("] ").formatted(Formatting.GRAY)); - - Text footer = new LiteralText("- ") - .formatted(Formatting.GRAY) - .append(buttons).append(new LiteralText(" ------------------------------").formatted(Formatting.GRAY)); - - header.append("\n").append(text[thisPage]).append("\n").append(footer); - source.sendFeedback(header, false); - return 1; - } - - private static void createExceptionCommand(LiteralArgumentBuilder command, boolean admin) { - { - LiteralArgumentBuilder settings = literal("settings"); - RequiredArgumentBuilder claim = getClaimArgument(); - - if (!admin) { - settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); - - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return querySettings(context.getSource(), claim1); - }); - } - - RequiredArgumentBuilder id = argument("setting", StringArgumentType.word()).suggests(SETTINGS_PROVIDER); - RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); - - id.executes((context) -> executeSetting(context.getSource(), StringArgumentType.getString(context, "setting"), StringArgumentType.getString(context, "claim"), true, false, admin)); - set.executes((context) -> executeSetting(context.getSource(), StringArgumentType.getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); - - id.then(set); - claim.then(id); - settings.then(claim); - command.then(settings); - } - - LiteralArgumentBuilder exceptions = literal("permissions"); - if (admin) exceptions.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_PERMISSIONS, 2)); - RequiredArgumentBuilder claim = getClaimArgument(); - if (!admin) { - exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); - - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return showTrustedList(context, claim1, false); - }); - } - - if (!admin) { - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(new LiteralText("That claim does not exist")); - return -1; - } - return showTrustedList(context, claim1, true); - }); - } - - { - RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); - LiteralArgumentBuilder remove = literal("remove"); - remove.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - claim1.permissionManager.resetPermissions(player1.getGameProfile().getId()); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + " no longer has an exception in the claim").formatted(Formatting.YELLOW), false); - } - return 0; - }); - player.then(remove); - LiteralArgumentBuilder all = literal("*"); - RequiredArgumentBuilder allstate = argument("allow", BoolArgumentType.bool()); - allstate.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - validateClaim(claim1); - return setTrust(context, claim1, player1, BoolArgumentType.getBool(context, "allow"), admin); - }); - all.then(allstate); - player.then(all); - for (Claim.Permission value : Claim.Permission.values()) { - LiteralArgumentBuilder permNode = literal(value.id); - RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); - allow.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - boolean permission = BoolArgumentType.getBool(context, "allow"); - modifyException(claim1, player1, value, permission); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has the permission " + value.name).formatted(Formatting.YELLOW), false); - } - return 0; - }); - permNode.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - boolean permission = hasPermission(claim1, player1, value); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); - } - return 0; - }); - permNode.then(allow); - player.then(permNode); - } - claim.then(player); - } - { - LiteralArgumentBuilder message = literal("message"); - RequiredArgumentBuilder claimArgument = getClaimArgument(); - RequiredArgumentBuilder messageEvent = argument("messageEvent", StringArgumentType.word()) - .suggests(MESSAGE_EVENTS_PROVIDER); - RequiredArgumentBuilder messageArgument = argument("message", StringArgumentType.greedyString()) - .suggests(EVENT_MESSAGE_PROVIDER); - - messageArgument.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PROPERTIES, context, admin)) { - Claim.Event event = Claim.Event.getById(StringArgumentType.getString(context, "messageEvent")); - - if (event == null) { - context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); - return -1; - } - - return setEventMessage(context.getSource(), claim1, event, StringArgumentType.getString(context, "message")); - } - - return -1; - }); - - messageEvent.then(messageArgument); - claimArgument.then(messageEvent); - message.then(claimArgument); - command.then(message); - } - - - exceptions.then(claim); - command.then(exceptions); - } - private static boolean verifyPermission(Claim claim, Claim.Permission permission, CommandContext context, boolean admin) throws CommandSyntaxException { - if (verifyExists(claim, context)) { - if (claim.permissionManager.hasPermission(context.getSource().getPlayer().getGameProfile().getId(), permission)) { - return true; - } else { - context.getSource().sendFeedback(new LiteralText(admin ? "You are modifying a claim using admin privileges" : "You cannot modify exceptions for this claim").formatted(admin ? Formatting.DARK_RED : Formatting.RED), false); - return admin; - } - } else { - return false; - } - } - private static boolean verifyExists(Claim claim, CommandContext context) { - if (claim == null) { - context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return false; - } else { - return true; - } - } - +// } +// { +// LiteralArgumentBuilder trust = literal("trust"); +// RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); +// playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, null))); +// claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, getString(context, "claim")))); +// +// playerArgument.then(claimArgument); +// trust.then(playerArgument); +// command.then(trust); +// dispatcher.register(trust); +// } +// { +// LiteralArgumentBuilder distrust = literal("distrust"); +// RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); +// +// playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, null))); +// claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, getString(context, "claim")))); +// +// playerArgument.then(claimArgument); +// distrust.then(playerArgument); +// command.then(distrust); +// dispatcher.register(distrust); +// } - private static int showClaim(ServerCommandSource source, Claim claim, boolean reset) throws CommandSyntaxException { - ServerPlayerEntity player = source.getPlayer(); - if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!Config.claims2d &&((ClaimShower)player).getShownClaim() != claim)) showClaim(source, ((ClaimShower)player).getShownClaim(), true); - if (reset && ((ClaimShower)player).getShownClaim() != null) claim = ((ClaimShower)player).getShownClaim(); - if (claim != null) { - if (!claim.dimension.equals(source.getWorld().getDimension().getType())) { - if (claim == ((ClaimShower)player).getShownClaim()) ((ClaimShower)player).setShownClaim(null); // just so we dont have extra packets on this - source.sendFeedback(new LiteralText("That claim is not in this dimension").formatted(Formatting.RED), false); - return 0; - } - source.sendFeedback(new LiteralText((!reset ? "Showing" : "Hiding") + " claim: " + claim.name).formatted(Formatting.GREEN), false); - silentHideShow(player, claim, reset, true); +// createExceptionCommand(command, false); +// +// { +// LiteralArgumentBuilder admin = literal("admin"); +// admin.requires(PERMISSION_CHECK_ADMIN); +// { +// LiteralArgumentBuilder entity = literal("entities"); +// entity.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// entity.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); +// context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); +// claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { +// context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); +// }); +// return 1; +// }); +// claim.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); +// claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { +// context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); +// }); +// return 1; +// }); +// entity.then(claim); +// admin.then(entity); +// } +// { +// LiteralArgumentBuilder add = literal("addBlocks"); +// add.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); +// RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); +// RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); +// amount.executes(context -> { +// ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); +// context.getSource().sendFeedback(new LiteralText("Gave " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); +// return 0; +// }); +// player.then(amount); +// add.then(player); +// admin.then(add); +// } +// { +// LiteralArgumentBuilder set = literal("setOwner"); +// RequiredArgumentBuilder newOwner = argument("newOwner", GameProfileArgumentType.gameProfile()); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); +// +// newOwner.executes((context) -> { +// Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); +// if (claim == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// +// Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); +// +// if (profiles.size() > 1) { +// context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); +// return -1; +// } +// return setOwner(context.getSource(), claim, profiles.iterator().next()); +// }); +// +// claimArgument.executes((context) -> { +// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (claim == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// +// Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); +// +// if (profiles.size() > 1) { +// context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); +// return -1; +// } +// return setOwner(context.getSource(), claim, profiles.iterator().next()); +// }); +// +// newOwner.then(claimArgument); +// set.then(newOwner); +// admin.then(set); +// } +// { +// LiteralArgumentBuilder set = literal("setOwnerName"); +// RequiredArgumentBuilder nameArgument = argument("newName", word()); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); +// +// nameArgument.executes((context) -> { +// Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); +// if (claim == null) { +// context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return -1; +// } +// return setOwnerName(context.getSource(), claim, getString(context, "newName")); +// }); +// +// claimArgument.executes((context) -> { +// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (claim == null) { +// context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return -1; +// } +// return setOwnerName(context.getSource(), claim, getString(context, "newName")); +// }); +// +// nameArgument.then(claimArgument); +// set.then(nameArgument); +// admin.then(set); +// } +// { +// LiteralArgumentBuilder rename = literal("rename"); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaimsSubzones(); +// RequiredArgumentBuilder nameArgument = argument("name", word()); +// nameArgument.executes((context) -> rename(context, true)); +// claimArgument.then(nameArgument); +// rename.then(claimArgument); +// admin.then(rename); +// } +// { +// LiteralArgumentBuilder remove = literal("removeBlocks"); +// remove.requires(source ->ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); +// RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); +// RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); +// amount.executes(context -> { +// ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), -IntegerArgumentType.getInteger(context, "amount")); +// context.getSource().sendFeedback(new LiteralText("Took " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); +// return 0; +// }); +// player.then(amount); +// remove.then(player); +// admin.then(remove); +// } +// { +// LiteralArgumentBuilder set = literal("setBlocks"); +// set.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); +// RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); +// RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); +// amount.executes(context -> { +// ClaimManager.INSTANCE.setClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); +// context.getSource().sendFeedback(new LiteralText("Set claim block amount to " + IntegerArgumentType.getInteger(context, "amount")).formatted(Formatting.GREEN), true); +// return 0; +// }); +// player.then(amount); +// set.then(player); +// admin.then(set); +// } +// { +// LiteralArgumentBuilder delete = literal("remove"); +// delete.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// LiteralArgumentBuilder confirm = literal("confirm"); +// confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); +// claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); +// claim.then(confirm); +// delete.then(claim); +// delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), true)); +// admin.then(delete); +// } +// { +// LiteralArgumentBuilder create = literal("create"); +// create.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2)); +// ArgumentBuilder name = argument("name", word()); +// ArgumentBuilder customOwner = argument("customOwnerName", word()); +// ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); +// RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); +// max.executes(context -> createClaim( +// getString(context, "name"), +// context.getSource(), +// BlockPosArgumentType.getBlockPos(context, "min"), +// BlockPosArgumentType.getBlockPos(context, "max"), +// true, +// null +// )); +// name.executes(context -> { +// ServerPlayerEntity player = context.getSource().getPlayer(); +// Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); +// if (selectedPositions == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); +// } else if (selectedPositions.getLeft() == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); +// } else if (selectedPositions.getRight() == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); +// } else { +// String cname = getString(context, "name"); +// if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, null) > 0) { +// ClaimManager.INSTANCE.stickPositions.remove(player); +// } +// } +// return 0; +// }); +// customOwner.executes(context -> { +// ServerPlayerEntity player = context.getSource().getPlayer(); +// Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); +// if (selectedPositions == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); +// } else if (selectedPositions.getLeft() == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); +// } else if (selectedPositions.getRight() == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); +// } else { +// String cname = getString(context, "name"); +// if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, getString(context, "customOwnerName")) > 0) { +// ClaimManager.INSTANCE.stickPositions.remove(player); +// } +// } +// return 0; +// }); +// min.then(max); +// name.then(customOwner); +// name.then(min); +// create.then(name); +// admin.then(create); +// } +// { +// LiteralArgumentBuilder ignore = literal("ignoreClaims"); +// ignore.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_IGNORE_CLAIMS, 2)); +// ignore.executes(context -> { +// UUID id = context.getSource().getPlayer().getGameProfile().getId(); +// boolean isIgnoring = ClaimManager.INSTANCE.ignoringClaims.contains(id); +// if (isIgnoring) ClaimManager.INSTANCE.ignoringClaims.remove(id); +// else ClaimManager.INSTANCE.ignoringClaims.add(id); +// context.getSource().sendFeedback(new LiteralText("You are " + (isIgnoring ? "no longer" : "now") + " ignoring claims.").formatted(Formatting.GREEN), false); +// return 0; +// }); +// admin.then(ignore); +// } +// { +// { +// LiteralArgumentBuilder expand = literal("expand"); +// expand.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); +// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); +// RequiredArgumentBuilder direction = getDirections(); +// +// direction.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// IntegerArgumentType.getInteger(context, "distance"), +// directionByName(getString(context, "direction")), +// context.getSource(), +// true +// )); +// +// amount.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// IntegerArgumentType.getInteger(context, "distance"), +// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], +// context.getSource(), +// true +// )); +// +// amount.then(direction); +// expand.then(amount); +// admin.then(expand); +// } +// { +// LiteralArgumentBuilder shrink = literal("shrink"); +// shrink.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); +// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); +// RequiredArgumentBuilder direction = getDirections(); +// +// direction.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// -IntegerArgumentType.getInteger(context, "distance"), +// directionByName(getString(context, "direction")), +// context.getSource(), +// true +// )); +// +// amount.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// -IntegerArgumentType.getInteger(context, "distance"), +// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], +// context.getSource(), +// true +// )); +// +// amount.then(direction); +// shrink.then(amount); +// admin.then(shrink); +// } +// } +// createExceptionCommand(admin, true); +// command.then(admin); +// } +// } - } else { - source.sendFeedback(new LiteralText("That is not a valid claim").formatted(Formatting.RED), false); - } - return 0; - } - private static void silentHideShow(ServerPlayerEntity player, Claim claim, boolean hide, boolean updateStatus) { - if (updateStatus) { - if (!hide) ((ClaimShower) player).setShownClaim(claim); - else ((ClaimShower) player).setShownClaim(null); - } - BlockState block = hide ? null : Blocks.GOLD_BLOCK.getDefaultState(); - showCorners(player, claim, hide, block); - if(!claim.isChild){ - block = hide ? null : Blocks.DIAMOND_BLOCK.getDefaultState(); - for(Claim subzone : claim.children){ - showCorners(player, subzone, hide, block); - } - } +// private static int sendPage(ServerCommandSource source, Text[] text, int page, String title, String command) { +// int prevPage = page - 2; +// int thisPage = page - 1; +// int nextPage = page + 1; +// final String SEPARATOR = "-----------------------------------------------------"; +// Text header = new LiteralText("") +// .append(new LiteralText("- [ ").formatted(Formatting.GRAY)) +// .append(new LiteralText(title).formatted(Formatting.GOLD)) +// .append(" ] ") +// .append(SEPARATOR.substring(ChatColor.removeAlternateColorCodes('&', title).length() + 4)) +// .formatted(Formatting.GRAY); +// +// Text button_prev = new LiteralText("") +// .append(new LiteralText("<-").formatted(Formatting.WHITE, Formatting.BOLD)) +// .append(" ").append(new LiteralText("Prev").formatted(Formatting.GOLD)) +// .styled((style) -> { +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); +// if (prevPage >= 0) +// style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); +// }); +// +// Text button_next = new LiteralText("") +// .append(new LiteralText("Next").formatted(Formatting.GOLD)) +// .append(" ").append(new LiteralText("->").formatted(Formatting.WHITE, Formatting.BOLD)).append(" ") +// .styled((style) -> { +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); +// if (nextPage <= text.length) +// style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); +// }); +// +// Text buttons = new LiteralText("") +// .append(new LiteralText("[ ").formatted(Formatting.GRAY)) +// .append(button_prev) +// .append(" ") +// .append( +// new LiteralText(String.valueOf(page)).formatted(Formatting.GREEN) +// .append(new LiteralText("/").formatted(Formatting.GRAY)) +// .append(new LiteralText(String.valueOf(text.length)).formatted(Formatting.GREEN)) +// ) +// .append(" ") +// .append(button_next) +// .append(new LiteralText("] ").formatted(Formatting.GRAY)); +// +// Text footer = new LiteralText("- ") +// .formatted(Formatting.GRAY) +// .append(buttons).append(new LiteralText(" ------------------------------").formatted(Formatting.GRAY)); +// +// header.append("\n").append(text[thisPage]).append("\n").append(footer); +// source.sendFeedback(header, false); +// return 1; +// } - } +// private static void createExceptionCommand(LiteralArgumentBuilder command, boolean admin) { +// { +// LiteralArgumentBuilder settings = literal("settings"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// +// if (!admin) { +// settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); +// +// claim.executes((context) -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (claim1 == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// return querySettings(context.getSource(), claim1); +// }); +// } +// +// RequiredArgumentBuilder id = argument("setting", word()).suggests(SETTINGS_PROVIDER); +// RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); +// +// id.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), getString(context, "claim"), true, false, admin)); +// set.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); +// +// id.then(set); +// claim.then(id); +// settings.then(claim); +// command.then(settings); +// } +// +// LiteralArgumentBuilder exceptions = literal("permissions"); +// if (admin) exceptions.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_PERMISSIONS, 2)); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// if (!admin) { +// exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); +// +// claim.executes((context) -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (claim1 == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// return showTrustedList(context, claim1, false); +// }); +// } +// +// if (!admin) { +// claim.executes((context) -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (claim1 == null) { +// context.getSource().sendError(new LiteralText("That claim does not exist")); +// return -1; +// } +// return showTrustedList(context, claim1, true); +// }); +// } +// +// { +// RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); +// LiteralArgumentBuilder remove = literal("remove"); +// remove.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { +// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); +// claim1.permissionManager.resetPermissions(player1.getGameProfile().getId()); +// context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + " no longer has an exception in the claim").formatted(Formatting.YELLOW), false); +// } +// return 0; +// }); +// player.then(remove); +// LiteralArgumentBuilder all = literal("*"); +// RequiredArgumentBuilder allstate = argument("allow", BoolArgumentType.bool()); +// allstate.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); +// validateClaim(claim1); +// return setTrust(context, claim1, player1.getGameProfile(), BoolArgumentType.getBool(context, "allow"), admin); +// }); +// all.then(allstate); +// player.then(all); +// for (Claim.Permission value : Claim.Permission.values()) { +// LiteralArgumentBuilder permNode = literal(value.id); +// RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); +// allow.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { +// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); +// boolean permission = BoolArgumentType.getBool(context, "allow"); +// modifyException(claim1, player1, value, permission); +// context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has the permission " + value.name).formatted(Formatting.YELLOW), false); +// } +// return 0; +// }); +// permNode.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { +// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); +// boolean permission = hasPermission(claim1, player1, value); +// context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); +// } +// return 0; +// }); +// permNode.then(allow); +// player.then(permNode); +// } +// claim.then(player); +// } +// { +// LiteralArgumentBuilder message = literal("message"); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); +// RequiredArgumentBuilder messageEvent = argument("messageEvent", word()) +// .suggests(MESSAGE_EVENTS_PROVIDER); +// RequiredArgumentBuilder messageArgument = argument("message", greedyString()) +// .suggests(EVENT_MESSAGE_PROVIDER); +// +// messageArgument.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (verifyPermission(claim1, Claim.Permission.MODIFY_PROPERTIES, context, admin)) { +// Claim.Event event = Claim.Event.getById(getString(context, "messageEvent")); +// +// if (event == null) { +// context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); +// return -1; +// } +// +// return setEventMessage(context.getSource(), claim1, event, getString(context, "message")); +// } +// +// return -1; +// }); +// +// messageEvent.then(messageArgument); +// claimArgument.then(messageEvent); +// message.then(claimArgument); +// command.then(message); +// } +// +// +// exceptions.then(claim); +// command.then(exceptions); +// } +// private static boolean verifyPermission(Claim claim, Claim.Permission permission, CommandContext context, boolean admin) throws CommandSyntaxException { +// if (verifyExists(claim, context)) { +// if (claim.permissionManager.hasPermission(context.getSource().getPlayer().getGameProfile().getId(), permission)) { +// return true; +// } else { +// context.getSource().sendFeedback(new LiteralText(admin ? "You are modifying a claim using admin privileges" : "You cannot modify exceptions for this claim").formatted(admin ? Formatting.DARK_RED : Formatting.RED), false); +// return admin; +// } +// } else { +// return false; +// } +// } +// private static boolean verifyExists(Claim claim, CommandContext context) { +// if (claim == null) { +// context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return false; +// } else { +// return true; +// } +// } - private static void showCorners(ServerPlayerEntity player, Claim claim, boolean hide, BlockState state){ - state = hide ? null : state; - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); +// private static int makeRentable(ServerCommandSource source, Claim claim, ItemStack item, int amount, String rentString, String maxrentString) throws CommandSyntaxException { +// int rentTime = TimeUtil.convertStringtoSeconds(rentString); +// int maxrentTime = TimeUtil.convertStringtoSeconds(maxrentString); +// if(claim != null){ +// if(rentTime <= maxrentTime){ +// Claim.Rent rent = claim.rent; +// rent.setRentable(true); +// item.setCount(amount); +// rent.setCurrency(item); +// rent.setRentAbleTime(rentTime); +// if(maxrentTime > Config.rent_maxseconds) maxrentTime = Config.rent_maxseconds; +// rent.setMaxrentAbleTime(maxrentTime); +// source.sendFeedback(new LiteralText("Claim " + claim.name + " can now be rented for " + amount + " " + item.getName().asString() + " every " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); +// return 1; +// } +// } +// return 0; +// } - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().south(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().east(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().south(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().north(), state); +// private static int rent(ServerCommandSource source, Claim claim, String rentString) throws CommandSyntaxException { +// if(claim == null){ +// source.sendFeedback(Messages.INVALID_CLAIM, true); +// return 0; +// } +// int rentTime = (int) TimeUtil.convertStringtoSeconds(rentString); +// int rentAbleTime = claim.rent.getRentAbleTime(); +// int maxrentAbleTime = claim.rent.getMaxrentAbleTime(); +// ItemStack currency = claim.rent.getCurrency(); +// ItemStack handItem = source.getPlayer().inventory.getMainHandStack(); +// ItemStack revenue = handItem.copy(); +// if(rentTime % claim.rent.getRentAbleTime() != 0){ +// source.sendFeedback(new LiteralText("You have to rent this claim for a time by a multiple of " + TimeUtil.convertSecondsToString(rentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); +// return 0; +// } +// int rentAmount = rentTime / claim.rent.getRentAbleTime(); +// if(currency.getItem() != handItem.getItem() || handItem.getCount() < claim.rent.getAmount() * rentAmount){ +// source.sendFeedback(new LiteralText("You don't have enough " + currency.getName().asString()).formatted(Formatting.RED), true); +// return 0; +// } +// if (!claim.rent.isRentable()) { +// source.sendFeedback(new LiteralText(claim.name + " is not for rent").formatted(Formatting.RED), true); +// return 0; +// } +// if (rentTime > claim.rent.getMaxrentAbleTime()) { +// source.sendFeedback(new LiteralText("You can't rent this claim for longer than " + TimeUtil.convertSecondsToString(maxrentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); +// return 0; +// } +// if(claim.rent.getTenant() == null){ +// //Setup for claim rent +// claim.rent.setTenant(source.getPlayer().getUuid()); +// claim.rent.setRentedUntil(claim.rent.getUnixTime() + rentTime); +// //Remove items from player +// handItem.setCount(handItem.getCount() - claim.rent.getAmount() * rentAmount); +// revenue.setCount(claim.rent.getAmount() * rentAmount); +// claim.rent.addRevenue(revenue); +// //Give Permissions to Tenant +// claim.permissionManager.playerPermissions.put(source.getPlayer().getUuid(), new Claim.InvertedPermissionMap()); +// source.sendFeedback(new LiteralText("Renting " + claim.name + " for " + claim.rent.getAmount() * rentAmount + " " + claim.rent.getCurrency().getName().asString() + " for " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); +// return 1; +// } else if(claim.rent.getTenant().toString().equalsIgnoreCase(source.getPlayer().getUuid().toString())){ +// if (claim.rent.getRentTimeLeft() + rentTime <= maxrentAbleTime) { +// //Setup for claim rent +// claim.rent.setRentedUntil(claim.rent.getUnixTime() + rentTime + claim.rent.getRentTimeLeft()); +// //Remove items from player +// handItem.setCount(handItem.getCount() - claim.rent.getAmount() * rentAmount); +// +// revenue.setCount(claim.rent.getAmount() * rentAmount); +// claim.rent.addRevenue(revenue); +// //Give Permissions to Tenant +// source.sendFeedback(new LiteralText("Extended rent " + claim.name + " by " + TimeUtil.convertSecondsToString(rentTime, '2', 'a') + "for " + claim.rent.getAmount() * rentAmount + " " + claim.rent.getCurrency().getName().asString()).formatted(Formatting.GREEN), true); +// return 1; +// } else { +// source.sendFeedback(new LiteralText("Rent would exceed the limit by " + TimeUtil.convertSecondsToString(claim.rent.getRentTimeLeft() + rentTime - maxrentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); +// return 0; +// } +// } else { +// source.sendFeedback(new LiteralText("This claim is already rented").formatted(Formatting.RED), true); +// return 0; +// } +// } - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().east(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().north(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().west(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().west(), state); - } - private static void sendBlockPacket(ServerPlayerEntity player, BlockPos pos, BlockState state) { - BlockUpdateS2CPacket packet = new BlockUpdateS2CPacket(player.world, pos); - if (state != null) ((BlockUpdatePacketMixin)packet).setState(state); - player.networkHandler.sendPacket(packet); - } - private static int createClaim(String name, ServerCommandSource owner, BlockPos posA, BlockPos posB, boolean admin, @Nullable String cOwnerName) throws CommandSyntaxException { - if (name.length() > MAX_NAME_LENGTH) { - owner.sendError(Messages.MSG_LONG_NAME); - return -1; - } - UUID ownerID = owner.getPlayer().getGameProfile().getId(); - int x, y = 0, z, mx, my = 255, mz; - if (posA.getX() > posB.getX()) { - x = posB.getX(); - mx = posA.getX(); - } else { - x = posA.getX(); - mx = posB.getX(); - } - if (!Config.claims2d) { - if (posA.getY() > posB.getY()) { - y = posB.getY(); - my = posA.getY(); - } else { - y = posA.getY(); - my = posB.getY(); - } - } - if (posA.getZ() > posB.getZ()) { - z = posB.getZ(); - mz = posA.getZ(); - } else { - z = posA.getZ(); - mz = posB.getZ(); - } - BlockPos min = new BlockPos(x, y, z); - BlockPos max = new BlockPos(mx, my, mz); - BlockPos sub = max.subtract(min); - sub = sub.add(1, Config.claims2d ? 0 : 1,1); - int subInt = sub.getX() * (Config.claims2d ? 1 : sub.getY()) * sub.getZ(); - Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos(), false); - if (cOwnerName != null) claim.customOwnerName = cOwnerName; - claim.permissionManager.playerPermissions.put(ownerID, new Claim.InvertedPermissionMap()); - if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { - if (!ClaimManager.INSTANCE.wouldIntersect(claim)) { - // works because only the first statement is evaluated if true - if ((admin && ItsMine.permissions().hasPermission(owner, Permissions.Command.INFINITE_BLOCKS, 2)) || ClaimManager.INSTANCE.useClaimBlocks(ownerID, subInt)) { - ClaimManager.INSTANCE.addClaim(claim); - owner.sendFeedback(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)).append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").setStyle(new Style() - .setColor(Formatting.GREEN).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))))), false); - checkPlayer(owner, owner.getPlayer().getGameProfile().getId()); - showClaim(owner, claim, false); - if (admin) - owner.getMinecraftServer().sendMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); - return 1; - } else { - owner.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + subInt + "(" + (subInt - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); - } - } else { - owner.sendFeedback(new LiteralText("Your claim would overlap with another claim").formatted(Formatting.RED), false); - } - } else { - owner.sendFeedback(new LiteralText("The name \"" + name + "\" is already taken.").formatted(Formatting.RED), false); - } - return 0; - } - private static int checkPlayer(ServerCommandSource ret, UUID player) throws CommandSyntaxException { - int blocks = ClaimManager.INSTANCE.getClaimBlocks(player); - ret.sendFeedback(new LiteralText((ret.getPlayer().getGameProfile().getId().equals(player) ? "You have " : "They have ") + blocks + " blocks left").setStyle(new Style() - .setColor(Formatting.YELLOW)), false); - return 0; - } - private static int requestDelete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { - if (claim == null) { - sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { - if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { - sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); - } else { - sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); - return 0; - } - } - sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to delete the claim \"" + claim.name + "\"? ").formatted(Formatting.GOLD)) - .append(new LiteralText("[I'M SURE]").setStyle(new Style() - .setColor(Formatting.DARK_RED) - .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")))), false); - return 0; - } - private static int delete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { - if (claim == null) { - sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { - if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { - sender.sendFeedback(new LiteralText("Deleting a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); - } else { - sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); - return 0; - } - } - if(!claim.isChild){ - ClaimManager.INSTANCE.releaseBlocksToOwner(claim); - ClaimManager.INSTANCE.claimsByName.remove(claim.name); - for(Claim subzone : claim.children){ - ClaimManager.INSTANCE.claimsByName.remove(subzone.name); - } - }else{ - claim.getParentClaim(claim).removeSubzone(claim); - ClaimManager.INSTANCE.claimsByName.remove(claim.name); - } - sender.getWorld().getPlayers().forEach(playerEntity -> { - if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true); - }); - sender.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)); - return 0; - } +// public static int showClaim(ServerCommandSource source, Claim claim, boolean reset) throws CommandSyntaxException { +// ServerPlayerEntity player = source.getPlayer(); +// if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!Config.claims2d &&((ClaimShower)player).getShownClaim() != claim)) showClaim(source, ((ClaimShower)player).getShownClaim(), true); +// if (reset && ((ClaimShower)player).getShownClaim() != null) claim = ((ClaimShower)player).getShownClaim(); +// if (claim != null) { +// if (!claim.dimension.equals(source.getWorld().getDimension().getType())) { +// if (claim == ((ClaimShower)player).getShownClaim()) ((ClaimShower)player).setShownClaim(null); // just so we dont have extra packets on this +// source.sendFeedback(new LiteralText("That claim is not in this dimension").formatted(Formatting.RED), false); +// return 0; +// } +// source.sendFeedback(new LiteralText((!reset ? "Showing" : "Hiding") + " claim: " + claim.name).formatted(Formatting.GREEN), false); +// if(claim.isChild) silentHideShow(player, ClaimUtil.getParentClaim(claim), reset, true); +// else silentHideShow(player, claim, reset, true); +// +// } else { +// source.sendFeedback(new LiteralText("That is not a valid claim").formatted(Formatting.RED), false); +// } +// return 0; +// } +// private static int createClaim(String name, ServerCommandSource owner, BlockPos posA, BlockPos posB, boolean admin, @Nullable String cOwnerName) throws CommandSyntaxException { +// if (name.length() > MAX_NAME_LENGTH) { +// owner.sendError(Messages.MSG_LONG_NAME); +// return -1; +// } +// if(!name.matches("[A-Za-z0-9]+")){ +// owner.sendError(new LiteralText("Invalid claim name")); +// return -1; +// } +// UUID ownerID = owner.getPlayer().getGameProfile().getId(); +// int x, y = 0, z, mx, my = 255, mz; +// if (posA.getX() > posB.getX()) { +// x = posB.getX(); +// mx = posA.getX(); +// } else { +// x = posA.getX(); +// mx = posB.getX(); +// } +// if (!Config.claims2d) { +// if (posA.getY() > posB.getY()) { +// y = posB.getY(); +// my = posA.getY(); +// } else { +// y = posA.getY(); +// my = posB.getY(); +// } +// } +// if (posA.getZ() > posB.getZ()) { +// z = posB.getZ(); +// mz = posA.getZ(); +// } else { +// z = posA.getZ(); +// mz = posB.getZ(); +// } +// BlockPos min = new BlockPos(x, y, z); +// BlockPos max = new BlockPos(mx, my, mz); +// BlockPos sub = max.subtract(min); +// sub = sub.add(1, Config.claims2d ? 0 : 1,1); +// int subInt = sub.getX() * (Config.claims2d ? 1 : sub.getY()) * sub.getZ(); +// +// Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos(), false); +// if (cOwnerName != null) claim.customOwnerName = cOwnerName; +// claim.permissionManager.playerPermissions.put(ownerID, new Claim.InvertedPermissionMap()); +// if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { +// if (!ClaimManager.INSTANCE.wouldIntersect(claim)) { +// // works because only the first statement is evaluated if true +// if ((admin && ItsMine.permissions().hasPermission(owner, PermissionUtil.Command.INFINITE_BLOCKS, 2)) || ClaimManager.INSTANCE.useClaimBlocks(ownerID, subInt)) { +// ClaimManager.INSTANCE.addClaim(claim); +// owner.sendFeedback(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)).append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").setStyle(new Style() +// .setColor(Formatting.GREEN).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))))), false); +// checkPlayer(owner, owner.getPlayer().getGameProfile().getId()); +// showClaim(owner, claim, false); +// if (admin) +// owner.getMinecraftServer().sendMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); +// return 1; +// } else { +// owner.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + subInt + "(" + (subInt - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); +// } +// } else { +// owner.sendFeedback(new LiteralText("Your claim would overlap with another claim").formatted(Formatting.RED), false); +// } +// } else { +// owner.sendFeedback(new LiteralText("The name \"" + name + "\" is already taken.").formatted(Formatting.RED), false); +// } +// return 0; +// } +// private static int checkPlayer(ServerCommandSource ret, UUID player) throws CommandSyntaxException { +// int blocks = ClaimManager.INSTANCE.getClaimBlocks(player); +// ret.sendFeedback(new LiteralText((ret.getPlayer().getGameProfile().getId().equals(player) ? "You have " : "They have ") + blocks + " blocks left").setStyle(new Style() +// .setColor(Formatting.YELLOW)), false); +// return 0; +// } +// private static int requestDelete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { +// if (claim == null) { +// sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return 0; +// } +// if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { +// if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { +// sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); +// } else { +// sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); +// return 0; +// } +// } +// sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to delete the claim \"" + claim.name + "\"? ").formatted(Formatting.GOLD)) +// .append(new LiteralText("[I'M SURE]").setStyle(new Style() +// .setColor(Formatting.DARK_RED) +// .setBold(true) +// .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")))), false); +// return 0; +// } +// private static int delete(ServerCommandSource source, Claim claim, boolean admin) throws CommandSyntaxException { +// ServerWorld world = source.getWorld(); +// if (claim == null) { +// source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return 0; +// } +// if (!claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { +// if (admin && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)) { +// source.sendFeedback(new LiteralText("Deleting a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); +// } else { +// source.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); +// return 0; +// } +// } +// if(!claim.isChild){ +// ClaimManager.INSTANCE.releaseBlocksToOwner(claim); +// ShowerUtil.update(claim, world, true); +// ClaimManager.INSTANCE.claimsByName.remove(claim.name); +// for(Claim subzone : claim.children){ +// ClaimManager.INSTANCE.claimsByName.remove(subzone.name); +// } +// }else{ +// Claim parent = ClaimUtil.getParentClaim(claim); +// ShowerUtil.update(parent, world, true); +// ClaimUtil.getParentClaim(claim).removeSubzone(claim); +// ClaimManager.INSTANCE.claimsByName.remove(claim.name); +// ShowerUtil.update(parent, world, false); +// } +// source.getWorld().getPlayers().forEach(playerEntity -> { +// if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true); +// }); +// source.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)); +// return 0; +// } - private static int requestTransfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { - if (claim == null) { - sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { - if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { - sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); - } else { - sender.sendFeedback(new LiteralText("You cannot transfer ownership that claim").formatted(Formatting.RED), false); - return 0; - } - } - sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to transfer ownership of \"" + claim.name + "\" to " + player.getGameProfile().getName() + "? ").formatted(Formatting.GOLD)) - .append(new LiteralText("[YES]").setStyle(new Style() - .setColor(Formatting.DARK_RED) - .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")))), false); - return 0; - } - private static Map pendingClaimTransfers = new HashMap<>(); - private static int transfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { - if (claim == null) { - sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { - if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { - sender.sendFeedback(new LiteralText("Transfering ownership of a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); - } else { - sender.sendFeedback(new LiteralText("You cannot transfer ownership that claim").formatted(Formatting.RED), false); - return 0; - } - } - GameProfile profile = sender.getWorld().getServer().getUserCache().getByUuid(claim.claimBlockOwner); - sender.sendFeedback(new LiteralText("Transferring ownership of the claim \"" + claim.name + "\" to " + player.getGameProfile().getName() + " if they accept").formatted(Formatting.GREEN), claim.claimBlockOwner != player.getGameProfile().getId()); - player.sendMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) - .append(new LiteralText("[ACCEPT]").setStyle(new Style() - .setColor(Formatting.GREEN) - .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim transfer -accept-" + claim.name + " " + player.getEntityName() + " confirm"))))); - pendingClaimTransfers.put(player.getGameProfile().getId(), claim.name); - return 0; - } - public static int acceptTransfer(ServerCommandSource sender) throws CommandSyntaxException { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(pendingClaimTransfers.get(sender.getPlayer().getGameProfile().getId())); - if (claim == null) { - sender.sendFeedback(new LiteralText("You have no pending claim transfers").formatted(Formatting.RED), false); - return 0; - } - if (sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner) != null) { - sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); - } - Claim.ClaimPermissionMap op = claim.permissionManager.playerPermissions.get(claim.claimBlockOwner); - claim.permissionManager.playerPermissions.put(claim.claimBlockOwner, claim.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); - claim.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op); - claim.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); - return 0; - } - private static int modifyException(Claim claim, ServerPlayerEntity exception, Claim.Permission permission, boolean allowed) { - claim.permissionManager.setPermission(exception.getGameProfile().getId(), permission, allowed); - return 0; - } - private static int modifyException(Claim claim, String exception, Claim.Permission permission, boolean allowed) { - claim.permissionManager.setPermission(exception, permission, allowed); - return 0; - } - private static boolean hasPermission(Claim claim, ServerPlayerEntity exception, Claim.Permission permission) { - return claim.permissionManager.hasPermission(exception.getGameProfile().getId(), permission); - } +// private static int requestTransfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { +// if (claim == null) { +// sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return 0; +// } +// if(claim.isChild){ +// sender.sendFeedback(new LiteralText("You can't transfer ownership of subzones").formatted(Formatting.RED), false); +// return 0; +// } +// if(sender.getPlayer().getUuidAsString().equalsIgnoreCase(player.getUuidAsString())){ +// sender.sendFeedback(new LiteralText("Huh? That makes no sence").formatted(Formatting.RED), true); +// return 0; +// } +// if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { +// if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { +// sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); +// } else { +// sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); +// return 0; +// } +// } +// sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to transfer ownership of \"" + claim.name + "\" to " + player.getGameProfile().getName() + "? ").formatted(Formatting.GOLD)) +// .append(new LiteralText("[YES]").setStyle(new Style() +// .setColor(Formatting.DARK_RED) +// .setBold(true) +// .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")))), false); +// return 0; +// } +// private static Map pendingClaimTransfers = new HashMap<>(); +// private static int transfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { +// if (claim == null) { +// sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return 0; +// } +// if(claim.isChild){ +// sender.sendFeedback(new LiteralText("You can't transfer ownership of subzones").formatted(Formatting.RED), false); +// return 0; +// } +// if(sender.getPlayer().getUuidAsString().equalsIgnoreCase(player.getUuidAsString())){ +// sender.sendFeedback(new LiteralText("Huh? That makes no sence").formatted(Formatting.RED), true); +// return 0; +// } +// if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { +// if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { +// sender.sendFeedback(new LiteralText("Transfering ownership of a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); +// } else { +// sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); +// return 0; +// } +// } +// +// GameProfile profile = sender.getWorld().getServer().getUserCache().getByUuid(claim.claimBlockOwner); +// sender.sendFeedback(new LiteralText("Transferring ownership of the claim \"" + claim.name + "\" to " + player.getGameProfile().getName() + " if they accept").formatted(Formatting.GREEN), claim.claimBlockOwner != player.getGameProfile().getId()); +// player.sendMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) +// .append(new LiteralText("[ACCEPT]").setStyle(new Style() +// .setColor(Formatting.GREEN) +// .setBold(true) +// .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim transfer -accept-" + claim.name + " " + player.getEntityName() + " confirm"))))); +// pendingClaimTransfers.put(player.getGameProfile().getId(), claim.name); +// return 0; +// } +// public static int acceptTransfer(ServerCommandSource sender) throws CommandSyntaxException { +// Claim claim = ClaimManager.INSTANCE.claimsByName.get(pendingClaimTransfers.get(sender.getPlayer().getGameProfile().getId())); +// if (claim == null) { +// sender.sendFeedback(new LiteralText("You have no pending claim transfers").formatted(Formatting.RED), false); +// return 0; +// } +// if (sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner) != null) { +// sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); +// } +// Claim.ClaimPermissionMap op = claim.permissionManager.playerPermissions.get(claim.claimBlockOwner); +// claim.permissionManager.playerPermissions.put(claim.claimBlockOwner, claim.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); +// claim.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op); +// claim.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); +// claim.children.forEach(subzone -> { +// try { +// Claim.ClaimPermissionMap op1 = subzone.permissionManager.playerPermissions.get(subzone.claimBlockOwner); +// subzone.permissionManager.playerPermissions.put(subzone.claimBlockOwner, subzone.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); +// subzone.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op1); +// subzone.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); +// } catch (CommandSyntaxException e) { +// e.printStackTrace(); +// } +// }); +// return 0; +// } +// private static int modifyException(Claim claim, ServerPlayerEntity exception, Claim.Permission permission, boolean allowed) { +// claim.permissionManager.setPermission(exception.getGameProfile().getId(), permission, allowed); +// return 0; +// } +// private static int modifyException(Claim claim, String exception, Claim.Permission permission, boolean allowed) { +// claim.permissionManager.setPermission(exception, permission, allowed); +// return 0; +// } +// private static boolean hasPermission(Claim claim, ServerPlayerEntity exception, Claim.Permission permission) { +// return claim.permissionManager.hasPermission(exception.getGameProfile().getId(), permission); +// } // private static boolean hasPermission(Claim claim, String exception, Claim.Permission permission) { // return claim.permissionManager.hasPermission(exception, permission); // } - private static Direction directionByName(String name) { - for (Direction direction : Direction.values()) { - if (name.equals(direction.getName())) return direction; - } - return null; - } - private static int expand(Claim claim, int amount, Direction direction, ServerCommandSource source, boolean admin) throws CommandSyntaxException { - UUID ownerID = source.getPlayer().getGameProfile().getId(); - if (claim == null) { - source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (direction == null) { - source.sendFeedback(new LiteralText("That is not a valid direction").formatted(Formatting.RED), false); - return 0; - } - if (!claim.permissionManager.hasPermission(ownerID, Claim.Permission.MODIFY_SIZE)) { - source.sendFeedback(new LiteralText("You do not have border change permissions in that claim").formatted(Formatting.RED), false); - if (!admin) return 0; - } - int oldArea = claim.getArea(); - if (amount > 0) claim.expand(direction, amount); - else { - if (!claim.shrink(direction, amount)) { - source.sendFeedback(new LiteralText("You can't shrink your claim that far. It would pass its opposite wall.").formatted(Formatting.RED), false); - return 0; - } - } - if (ClaimManager.INSTANCE.wouldIntersect(claim)) { - if (amount < 0) claim.expand(direction, amount); - else claim.shrink(direction, amount); - source.sendFeedback(new LiteralText("Expansion would result in hitting another claim").formatted(Formatting.RED), false); - return 0; - } - int newArea = claim.getArea() - oldArea; - if (!admin && claim.claimBlockOwner != null && ClaimManager.INSTANCE.getClaimBlocks(ownerID) < newArea) { - if (amount < 0) claim.expand(direction, amount); - else claim.shrink(direction, amount); - source.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + newArea + "(" + (newArea - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); - checkPlayer(source, ownerID); - return 0; - } else { - if (!admin && claim.claimBlockOwner != null) ClaimManager.INSTANCE.useClaimBlocks(ownerID, newArea); - source.sendFeedback(new LiteralText("Your claim was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); - checkPlayer(source, ownerID); - if (amount < 0) claim.expand(direction, amount); - else claim.shrink(direction, amount); - source.getWorld().getPlayers().forEach(playerEntity -> { - if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, false); - }); - if (amount > 0) claim.expand(direction, amount); - else claim.shrink(direction, -amount); - source.getWorld().getPlayers().forEach(playerEntity -> { - if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, false, false); - }); - } - return 0; - } - private static int info(ServerCommandSource source, Claim claim) { - if (claim == null) { - source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - - GameProfile owner = claim.claimBlockOwner == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); - BlockPos size = claim.getSize(); - - Text text = new LiteralText("\n"); - text.append(new LiteralText("Claim Info: " + claim.name).formatted(Formatting.GOLD)).append("\n"); - text.append(newInfoLine("Name", new LiteralText(claim.name).formatted(Formatting.WHITE))); - text.append(newInfoLine("Owner", - owner != null && claim.customOwnerName == null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : - claim.customOwnerName != null ? new LiteralText(claim.customOwnerName).formatted(Formatting.GOLD) : - new LiteralText("No Owner").formatted(Formatting.RED, Formatting.ITALIC))); - text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); - - - text.append(new LiteralText("").append(new LiteralText("* Settings:").formatted(Formatting.YELLOW)) - .append(Messages.Command.getSettings(claim)).append("\n")); - Text pos = new LiteralText(""); - Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); - Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); - - if (PERMISSION_CHECK_ADMIN.test(source)) { - String format = "/execute in " + Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").toString() + " run tp " + source.getName() + (Config.claims2d ? " %s ~ %s" : " %s %s %s"); - min.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, - String.format(format, claim.min.getX(), Config.claims2d ? claim.min.getZ() : claim.min.getY(), claim.min.getZ())))); - max.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, - String.format(format, claim.max.getX(), Config.claims2d ? claim.max.getZ() : claim.max.getY(), claim.max.getZ())))); - } - - pos.append(newInfoLine("Position", new LiteralText("") - .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) - .append(" ") - .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); - text.append(pos); - text.append(newInfoLine("Dimension", new LiteralText(Registry.DIMENSION_TYPE.getId(claim.dimension).getPath()))); - source.sendFeedback(text, false); - return 1; - } - private static Text newPosLine(BlockPos pos, Formatting form1, Formatting form2) { - return new LiteralText("") - .append(new LiteralText(String.valueOf(pos.getX())).formatted(form1)) - .append(" ") - .append(new LiteralText(String.valueOf(pos.getY())).formatted(form2)) - .append(" ") - .append(new LiteralText(String.valueOf(pos.getZ())).formatted(form1)); - } - private static Text newInfoLine(String title, Text text) { - return new LiteralText("").append(new LiteralText("* " + title + ": ").formatted(Formatting.YELLOW)) - .append(text).append("\n"); - } - - private static ArrayList getClaims(){ - ArrayList claims = new ArrayList<>(); - ClaimManager.INSTANCE.claimsByName.forEach((s, claim) -> { - claims.add(claim); - }); - return claims; - } - - private static int listall(ServerCommandSource source){ - List claims = getClaims(); - Text text = new LiteralText("\n").append(new LiteralText("Claims").formatted(Formatting.GOLD)).append("\n "); - for (Claim claim : claims) { - Text cText = new LiteralText(claim.name).formatted(Formatting.GOLD); - text.append(cText.append(" ")); - } - source.sendFeedback(text.append("\n"), false); - return 1; - } - - private static int list(ServerCommandSource source, String target) throws CommandSyntaxException { - ServerPlayerEntity player = source.getPlayer(); - GameProfile profile = target == null ? player.getGameProfile() : source.getMinecraftServer().getUserCache().findByName(target); - - if (profile == null) { - source.sendError(Messages.INVALID_PLAYER); - return -1; - } - - List claims = ClaimManager.INSTANCE.getPlayerClaims(profile.getId()); - if (claims.isEmpty()) { - source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); - return -1; - } - - - Text text = new LiteralText("\n").append(new LiteralText("Claims (" + target + "): ").formatted(Formatting.GOLD)).append("\n "); - boolean nextColor = false; - for (Claim claim : claims) { - if(!claim.isChild) { - Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { - Text hoverText = new LiteralText("Click for more Info").formatted(Formatting.GREEN); - if (claim.children.size() > 0) { - hoverText.append("\n\nSubzones:"); - for (Claim subzone : claim.children) { - hoverText.append("\n- " + subzone.name); - } - } - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); - - style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); - }); - - nextColor = !nextColor; - text.append(cText.append(" ")); - } - } - - source.sendFeedback(text.append("\n"), false); - return 1; - } - private static int listAll(ServerCommandSource source, int page) { - List claims = new ArrayList<>(); - ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> claims.add(claim)); - - if (claims.isEmpty()) { - source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); - return -1; - } - - List list = new ArrayList<>(claims.size() / 10); - - for (int i = 0; i < claims.size(); i++) { - Claim claim = claims.get(i); - - Text cText = new LiteralText("").append(new LiteralText(i + ". ").formatted(Formatting.GOLD)) - .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" in ").formatted(Formatting.GRAY)) - .append(new LiteralText(Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").getPath()).formatted(Formatting.WHITE)); - - cText.styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click for more Info").formatted(Formatting.GREEN))); - style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); - }); - - list.add(cText.append("\n")); - } - - Text[] texts = new Text[]{}; - texts = list.toArray(texts); - return sendPage(source, texts, page, "Claims", "/claim listall %page%"); - } - private static int rename(CommandContext context, boolean admin) throws CommandSyntaxException { - String name = StringArgumentType.getString(context, "claim"); - String newName = StringArgumentType.getString(context, "name"); - Claim claimToRename = ClaimManager.INSTANCE.claimsByName.get(name); - if (claimToRename == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - if (ClaimManager.INSTANCE.claimsByName.containsKey(newName)) { - context.getSource().sendError(new LiteralText("That name is already taken!")); - return -1; - } - if (!admin && !claimToRename.hasPermission(context.getSource().getPlayer().getUuid(), Claim.Permission.MODIFY_PROPERTIES)) { - context.getSource().sendError(new LiteralText("You don't have permission to modify claim properties!")); - return -1; - } - ClaimManager.INSTANCE.claimsByName.remove(name); - claimToRename.name = newName; - ClaimManager.INSTANCE.addClaim(claimToRename); - claimToRename.name = newName; - context.getSource().sendFeedback(new LiteralText("Renamed Claim " + name + " to " + newName).formatted(Formatting.GOLD), admin); - return -1; - } - private static int showTrustedList(CommandContext context, Claim claim, boolean showSelf) throws CommandSyntaxException { - ServerCommandSource source = context.getSource(); - ServerPlayerEntity player = source.getPlayer(); - int mapSize = claim.permissionManager.playerPermissions.size(); - - if (mapSize == 1 && !showSelf) { - source.sendError(new LiteralText(claim.name + " is not trusting anyone!")); - return -1; - } - - Text text = new LiteralText("\n"); - text.append(new LiteralText("Trusted players for Claim ").formatted(Formatting.YELLOW)) - .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append("\n"); - - AtomicInteger atomicInteger = new AtomicInteger(); - claim.permissionManager.playerPermissions.forEach((uuid, perm) -> { - atomicInteger.incrementAndGet(); - Text pText = new LiteralText(""); - Text owner; - GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); - if (profile != null) { - owner = new LiteralText(profile.getName()); - } else { - owner = new LiteralText(uuid.toString()).styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to Copy"))); - style.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); - }); - } - - pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) - .append(owner.formatted(Formatting.YELLOW)); - - Text hover = new LiteralText(""); - hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); - - int allowed = 0; - int i = 0; - boolean nextColor = false; - Text perms = new LiteralText(""); - - for (Claim.Permission value : Claim.Permission.values()) { - if (claim.permissionManager.hasPermission(uuid, value)) { - Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; - perms.append(new LiteralText(value.id).formatted(formatting)).append(" "); - if (i == 3) perms.append("\n"); - allowed++; - i++; - nextColor = !nextColor; - } - } - - if (allowed == Claim.Permission.values().length) { - hover.append(new LiteralText("All " + allowed + " Permissions").formatted(Formatting.YELLOW, Formatting.ITALIC)); - } else { - hover.append(perms); - } - - pText.append(new LiteralText(" ") - .append(new LiteralText("(").formatted(Formatting.GOLD)) - .append(new LiteralText(String.valueOf(allowed)).formatted(Formatting.GREEN)) - .append(new LiteralText("/").formatted(Formatting.GOLD)) - .append(new LiteralText(String.valueOf(Claim.Permission.values().length)).formatted(Formatting.YELLOW)) - .append(new LiteralText(")").formatted(Formatting.GOLD)) - ); - - pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); - text.append(pText).append("\n"); - }); - - source.sendFeedback(text, false); - return 1; - } - private static int setOwnerName(ServerCommandSource source, Claim claim, String input) { - String name = input.equals("reset") ? null : input; - source.sendFeedback(new LiteralText("Set the Custom Owner Name to ") - .formatted(Formatting.YELLOW).append(new LiteralText(name == null ? "Reset" : name).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) - .append(new LiteralText(claim.customOwnerName == null ? "Not Present" : claim.customOwnerName).formatted(Formatting.GOLD)) - .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) - , false); - claim.customOwnerName = input; - return 1; - } - private static int setOwner(ServerCommandSource source, Claim claim, GameProfile profile) { - GameProfile oldOwner = source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); - source.sendFeedback(new LiteralText("Set the Claim Owner to ") - .formatted(Formatting.YELLOW).append(new LiteralText(profile.getName()).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) - .append(new LiteralText(oldOwner == null ? "(" + claim.claimBlockOwner + ")" : oldOwner.getName()).formatted(Formatting.GOLD)) - .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) - , false); - claim.claimBlockOwner = profile.getId(); - return 1; - } - private static int setEventMessage(ServerCommandSource source, Claim claim, Claim.Event event, String message) { - switch (event) { - case ENTER_CLAIM: - claim.enterMessage = message.equalsIgnoreCase("reset") ? null : message; - break; - case LEAVE_CLAIM: - claim.leaveMessage = message.equalsIgnoreCase("reset") ? null : message; - break; - } - - if (message.equalsIgnoreCase("reset")) { - source.sendFeedback(new LiteralText("Reset ").append(new LiteralText(event.id).formatted(Formatting.GOLD) - .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) - .append(new LiteralText(claim.name).formatted(Formatting.GOLD))).formatted(Formatting.YELLOW) - , false); - return -1; - } - - source.sendFeedback(new LiteralText("Set ").append(new LiteralText(event.id).formatted(Formatting.GOLD) - .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) - .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" to:").formatted(Formatting.YELLOW))) - .append("\n").append(new LiteralText(ChatColor.translate(message))) - .formatted(Formatting.YELLOW) - , false); - return 1; - } - private static int executeSetting(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { - ServerPlayerEntity player = source.getPlayer(); - Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : - ClaimManager.INSTANCE.claimsByName.get(claimName); - if (claim1 == null) { - source.sendError(Messages.INVALID_CLAIM); - return -1; - } - - if (input == null) { - return querySettings(source, claim1); - } - - validateCanAccess(player, claim1, admin); - Claim.ClaimSettings.Setting setting = Claim.ClaimSettings.Setting.byId(input); - Claim.Permission permission = Claim.Permission.byId(input); - - if (setting != null && permission == null) - return isQuery ? querySetting(source, claim1, setting) : setSetting(source, claim1, setting, value); +// private static Direction directionByName(String name) { +// for (Direction direction : Direction.values()) { +// if (name.equals(direction.getName())) return direction; +// } +// return null; +// } - if (setting == null && permission != null) - return isQuery ? queryPermission(source, claim1, permission) : setPermission(source, claim1, permission, value); +// private static CompletableFuture itemsSuggestion(final CommandContext ctx, final SuggestionsBuilder builder) { +// List strings = new ArrayList<>(); +// Registry.ITEM.forEach((item) -> { +// strings.add(Registry.ITEM.getId(item).getPath()); +// }); +// +// return CommandSource.suggestMatching(strings, builder); +// } - source.sendError(Messages.INVALID_SETTING); - return -1; - } - private static int executePermission(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { - ServerPlayerEntity player = source.getPlayer(); - Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : - ClaimManager.INSTANCE.claimsByName.get(claimName); - if (claim1 == null) { - source.sendError(Messages.INVALID_CLAIM); - return -1; - } +// private static void undoExpand(Claim claim, Direction direction, int amount){ +// if (amount < 0) claim.expand(direction, -amount); +// else claim.shrink(direction, amount); +// } +// +// private static void sendSize(Claim claim, ServerCommandSource source){ +// Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); +// Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); +// Text pos = new LiteralText(""); +// pos.append(newInfoLine("Position", new LiteralText("") +// .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) +// .append(" ") +// .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); +// source.sendFeedback(pos, true); +// } +// +// private static int expand(Claim claim, int amount, Direction direction, ServerCommandSource source, boolean admin) throws CommandSyntaxException { +// UUID ownerID = source.getPlayer().getGameProfile().getId(); +// if (claim == null) { +// source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return 0; +// } +// if (direction == null) { +// source.sendFeedback(new LiteralText("That is not a valid direction").formatted(Formatting.RED), false); +// return 0; +// } +// if (!claim.permissionManager.hasPermission(ownerID, Claim.Permission.MODIFY_SIZE)) { +// source.sendFeedback(new LiteralText("You do not have border change permissions in that claim").formatted(Formatting.RED), false); +// if (!admin) return 0; +// } +// int oldArea = claim.getArea(); +// System.out.println("Area1 " + claim.getArea()); +// sendSize(claim, source); +// +// if (amount > 0) { +// claim.expand(direction, amount); +// } +// else { +// claim.shrink(direction, -amount); +// } +// +// System.out.println("Area2 " + claim.getArea()); +// sendSize(claim, source); +// +// if (!claim.canShrinkWithoutHittingOtherSide(new BlockPos(direction.getOffsetX() * amount, direction.getOffsetY() * amount, direction.getOffsetZ() * amount))) { +// source.sendFeedback(new LiteralText("You can't shrink your claim that far. It would pass its opposite wall.").formatted(Formatting.RED), false); +// undoExpand(claim, direction, amount); +// return 0; +// } +// +// if(!claim.isChild){ +// if (ClaimManager.INSTANCE.wouldIntersect(claim)) { +// undoExpand(claim, direction, amount); +// source.sendFeedback(new LiteralText("Expansion would result in hitting another claim").formatted(Formatting.RED), false); +// return 0; +// } +// +// //Check if shrinking would reset a subzone to be outside of its parent claim +// AtomicBoolean returnValue = new AtomicBoolean(); +// returnValue.set(false); +// claim.children.forEach(claim1 -> { +//// System.out.println("IsInside2: " + claim1.isInside(claim)); +// if(!claim1.isInside(claim)){ +// System.out.println("Area3 " + claim.getArea()); +// sendSize(claim, source); +// undoExpand(claim, direction, amount); +// System.out.println("Area4 " + claim.getArea()); +// sendSize(claim, source); +// source.sendFeedback(new LiteralText("Shrinking would result in " + claim1.name + " being outside of " + claim.name).formatted(Formatting.RED), true); +// returnValue.set(true); +// } +// }); +// if(returnValue.get()) return 0; +// +// int newArea = claim.getArea() - oldArea; +// if (!admin && claim.claimBlockOwner != null && ClaimManager.INSTANCE.getClaimBlocks(ownerID) < newArea) { +// undoExpand(claim, direction, amount); +// source.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + newArea + "(" + (newArea - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); +// checkPlayer(source, ownerID); +// return 0; +// } else { +// if (!admin && claim.claimBlockOwner != null) ClaimManager.INSTANCE.useClaimBlocks(ownerID, newArea); +// source.sendFeedback(new LiteralText("Your claim was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); +// checkPlayer(source, ownerID); +// undoExpand(claim, direction, amount); +// ShowerUtil.update(claim, source.getWorld(), true); +// if (amount > 0) claim.expand(direction, amount); +// else claim.shrink(direction, -amount); +// ShowerUtil.update(claim, source.getWorld(), false); +// } +// return 0; +// }else{ +// Claim parent = ClaimUtil.getParentClaim(claim); +// if(!claim.isInside(parent)) { +// source.sendFeedback(new LiteralText("Expansion would result in expanding outside of your main claim").formatted(Formatting.RED), false); +// undoExpand(claim, direction, amount); +// } else if(ClaimManager.INSTANCE.wouldSubzoneIntersect((claim))){ +// source.sendFeedback(new LiteralText("Expansion would result in overlapping with another subzone").formatted(Formatting.RED), false); +// undoExpand(claim, direction, amount); +// }else{ +// source.sendFeedback(new LiteralText("Your subzone was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); +// //The expansion is undone to hide the claimshower +// undoExpand(claim, direction, amount); +// ShowerUtil.update(parent, source.getWorld(), true); +// if (amount > 0) claim.expand(direction, amount); +// else claim.shrink(direction, -amount); +// ShowerUtil.update(parent, source.getWorld(), false); +// } +// } +// return 0; +// } - validateCanAccess(player, claim1, admin); - Claim.Permission permission = Claim.Permission.byId(input); - if (permission != null) - return !isQuery ? setPermission(source, claim1, permission, value) : queryPermission(source, claim1, permission); +// private static int revenue(ServerCommandSource source, Claim claim, boolean claimrevenue) throws CommandSyntaxException { +// //Show subzones (so you can just claim everything in one place) maybe just all claims +// if(claim == null){ +// source.sendFeedback(Messages.INVALID_CLAIM,true); +// return 0; +// } +// if(!claim.claimBlockOwner.toString().equalsIgnoreCase(source.getPlayer().getUuid().toString())){ +// source.sendFeedback(Messages.NO_PERMISSION, true); +// return 0; +// } +// +// if(claimrevenue){ +// for(ItemStack itemStack : claim.rent.getRevenue()){ +// source.getPlayer().inventory.insertStack(itemStack); +// } +// claim.rent.clearRevenue(); +// return 1; +// +// } else { +// if(claim.rent.getRevenue().isEmpty()){ +// source.sendFeedback(new LiteralText("No Revenue").formatted(Formatting.RED), true); +// return 0; +// } +// Text text = new LiteralText("Revenue\n").formatted(Formatting.AQUA); +// HashMap hashMap = new HashMap<>(); +// for(ItemStack itemStack : claim.rent.getRevenue()){ +// Item value = itemStack.getItem(); +// if(hashMap.containsKey(value)){ +// hashMap.put(value, hashMap.get(value) + itemStack.getCount()); +// } else { +// hashMap.put(value, + itemStack.getCount()); +// } +// +// hashMap.forEach((item, integer) -> { +// boolean color = true; +// text.append(new LiteralText(String.valueOf(integer)).append(" ").append(new TranslatableText(item.getTranslationKey())).append(" ").formatted(color ? Formatting.GOLD : Formatting.YELLOW)).styled(style -> { +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to claim revenue!").formatted(Formatting.GREEN))); +// style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim revenue " + claim.name + " true")); +// }); +// color = !color; +// }); +// +// } +// text.append("\n"); +// source.sendFeedback(text, true); +// return 1; +// } +// } - source.sendError(Messages.INVALID_SETTING); - return -1; - } - private static int querySetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting) { - boolean enabled = claim.settings.getSetting(setting); - source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); - return 1; - } - private static int setSetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting, boolean set) { - claim.settings.settings.put(setting, set); - source.sendFeedback(new LiteralText(ChatColor.translate("&eSet setting &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); - return 0; - } - private static int queryPermission(ServerCommandSource source, Claim claim, Claim.Permission permission) { - boolean defaultPerm = claim.permissionManager.defaults.hasPermission(permission); - source.sendFeedback(new LiteralText(ChatColor.translate("&ePermission &6" + permission.id + "&e is set to " + (defaultPerm ? "&a" : "&c") + defaultPerm + "&e for &6" + claim.name)), false); - return 1; - } - private static int setPermission(ServerCommandSource source, Claim claim, Claim.Permission permission, boolean set) { - claim.permissionManager.defaults.setPermission(permission, set); - source.sendFeedback(new LiteralText(ChatColor.translate("&eSet permission &6" + permission.id + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); - return 1; - } - private static int querySettings(ServerCommandSource source, Claim claim) { - source.sendFeedback(new LiteralText("\n").append(new LiteralText("Settings: " + claim.name).formatted(Formatting.YELLOW)).append("\n") - .append(Messages.Command.getSettings(claim)).append("\n"), false); - return 1; - } - private static int executeTrust(CommandContext context, Entity entity, boolean set, @Nullable String claimName) throws CommandSyntaxException { - if (!(entity instanceof PlayerEntity)) { - context.getSource().sendError(new LiteralText("Only Players!")); - return -1; - } - ServerPlayerEntity target = (ServerPlayerEntity) entity; - ServerPlayerEntity p = context.getSource().getPlayer(); - Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getBlockPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); - validateClaim(claim1); +// private static int info(ServerCommandSource source, Claim claim) throws CommandSyntaxException { +// if (claim == null) { +// source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return 0; +// } +// +// GameProfile owner = claim.claimBlockOwner == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); +// BlockPos size = claim.getSize(); +// +// Text text = new LiteralText("\n"); +// text.append(new LiteralText("Claim Info: " + claim.name).formatted(Formatting.GOLD)).append("\n"); +// text.append(newInfoLine("Name", new LiteralText(claim.name).formatted(Formatting.WHITE))); +// text.append(newInfoLine("Entities", new LiteralText(String.valueOf(claim.getEntities(source.getWorld()))).formatted(Formatting.AQUA))); +// text.append(newInfoLine("Owner", +// owner != null && claim.customOwnerName == null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : +// claim.customOwnerName != null ? new LiteralText(claim.customOwnerName).formatted(Formatting.GOLD) : +// new LiteralText("No Owner").formatted(Formatting.RED, Formatting.ITALIC))); +// text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); +// +// +// text.append(new LiteralText("").append(new LiteralText("* Settings:").formatted(Formatting.YELLOW)) +// .append(Messages.Command.getSettings(claim)).append("\n")); +// Text pos = new LiteralText(""); +// Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); +// Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); +// +// +// if (PERMISSION_CHECK_ADMIN.test(source)) { +// String format = "/execute in " + Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").toString() + " run tp " + source.getName() + (Config.claims2d ? " %s ~ %s" : " %s %s %s"); +// min.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, +// String.format(format, claim.min.getX(), Config.claims2d ? claim.min.getZ() : claim.min.getY(), claim.min.getZ())))); +// max.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, +// String.format(format, claim.max.getX(), Config.claims2d ? claim.max.getZ() : claim.max.getY(), claim.max.getZ())))); +// } +// +// pos.append(newInfoLine("Position", new LiteralText("") +// .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) +// .append(" ") +// .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); +// text.append(pos); +// text.append(newInfoLine("Dimension", new LiteralText(Registry.DIMENSION_TYPE.getId(claim.dimension).getPath()))); +// if(claim.rent.isRented()){ +// GameProfile tenant = claim.rent.getTenant() == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.rent.getTenant()); +// text.append(newInfoLine("Status", new LiteralText("Rented").formatted(Formatting.RED).styled(style -> { +// java.util.Date time=new java.util.Date((long) claim.rent.getRentedUntil()*1000); +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Until", new LiteralText(time.toString()).formatted(Formatting.WHITE)).append(newInfoLine("By", new LiteralText(tenant.getName()).formatted(Formatting.WHITE))).append(newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE))))); +// }))); +// } else if (claim.rent.isRentable() && !claim.rent.isRented()){ +// text.append(newInfoLine("Status", new LiteralText("For Rent").formatted(Formatting.GREEN).styled(style -> { +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE)).append(newInfoLine("Max Rent", new LiteralText(claim.rent.getMaxrentAbleTime() / 86400 + " days")).formatted(Formatting.WHITE)))); +// }))); +// +// } else { +// text.append(newInfoLine("Status", new LiteralText("Not For Rent").formatted(Formatting.GREEN))); +// +// } +// source.sendFeedback(text, false); +// return 1; +// } +// private static Text newPosLine(BlockPos pos, Formatting form1, Formatting form2) { +// return new LiteralText("") +// .append(new LiteralText(String.valueOf(pos.getX())).formatted(form1)) +// .append(" ") +// .append(new LiteralText(String.valueOf(pos.getY())).formatted(form2)) +// .append(" ") +// .append(new LiteralText(String.valueOf(pos.getZ())).formatted(form1)); +// } +// private static Text newInfoLine(String title, Text text) { +// return new LiteralText("").append(new LiteralText("* " + title + ": ").formatted(Formatting.YELLOW)) +// .append(text).append("\n"); +// } - return setTrust(context, claim1, target, set, false); - } - private static int setTrust(CommandContext context, Claim claim, ServerPlayerEntity target, boolean set, boolean admin) throws CommandSyntaxException { - if (verifyPermission(claim, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - claim.permissionManager.playerPermissions.put(target.getGameProfile().getId(), set ? new Claim.InvertedPermissionMap() : new Claim.DefaultPermissionMap()); - context.getSource().sendFeedback(new LiteralText(target.getGameProfile().getName() + (set ? " now" : " no longer") + " has all the permissions").formatted(Formatting.YELLOW), false); +// private static ArrayList getClaims(){ +// ArrayList claims = new ArrayList<>(); +// ClaimManager.INSTANCE.claimsByName.forEach((s, claim) -> { +// claims.add(claim); +// }); +// return claims; +// } +// +// private static int listall(ServerCommandSource source){ +// List claims = getClaims(); +// Text text = new LiteralText("\n").append(new LiteralText("Claims").formatted(Formatting.GOLD)).append("\n "); +// for (Claim claim : claims) { +// Text cText = new LiteralText(claim.name).formatted(Formatting.GOLD); +// text.append(cText.append(" ")); +// } +// source.sendFeedback(text.append("\n"), false); +// return 1; +// } - String message; - if (set) message = "&aTrusted player &6" + target.getEntityName() + "&a in &6" + claim.name + "\n&aThey now have all the default permissions"; - else message = "&cDistrusted player &6" + target.getEntityName() + "&c in &6" + claim.name + "\n&cThey don't have any permissions now"; - context.getSource().sendFeedback(new LiteralText(ChatColor.translate(message)), false); - } - return 1; - } - private static int setFly(CommandContext context, boolean set) throws CommandSyntaxException { - ServerPlayerEntity player = context.getSource().getPlayer(); - if (set) { - ClaimManager.INSTANCE.flyers.add(player.getUuid()); - player.addMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN), false); - return 1; - } +// private static int list(ServerCommandSource source, String target) throws CommandSyntaxException { +// ServerPlayerEntity player = source.getPlayer(); +// GameProfile profile = target == null ? player.getGameProfile() : source.getMinecraftServer().getUserCache().findByName(target); +// +// if (profile == null) { +// source.sendError(Messages.INVALID_PLAYER); +// return -1; +// } +// +// List claims = ClaimManager.INSTANCE.getPlayerClaims(profile.getId()); +// if (claims.isEmpty()) { +// source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); +// return -1; +// } +// +// +// Text text = new LiteralText("\n").append(new LiteralText("Claims (" + target + "): ").formatted(Formatting.GOLD)).append("\n "); +// boolean nextColor = false; +// for (Claim claim : claims) { +// if(!claim.isChild) { +// Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { +// Text hoverText = new LiteralText("Click for more Info").formatted(Formatting.GREEN); +// if (claim.children.size() > 0) { +// hoverText.append("\n\nSubzones:"); +// for (Claim subzone : claim.children) { +// hoverText.append("\n- " + subzone.name); +// } +// } +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); +// +// style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); +// }); +// +// nextColor = !nextColor; +// text.append(cText.append(" ")); +// } +// } +// +// source.sendFeedback(text.append("\n"), false); +// return 1; +// } +// private static int listAll(ServerCommandSource source, int page) { +// List claims = new ArrayList<>(); +// ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> claims.add(claim)); +// +// if (claims.isEmpty()) { +// source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); +// return -1; +// } +// +// List list = new ArrayList<>(claims.size() / 10); +// +// for (int i = 0; i < claims.size(); i++) { +// Claim claim = claims.get(i); +// +// Text cText = new LiteralText("").append(new LiteralText(i + ". ").formatted(Formatting.GOLD)) +// .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" in ").formatted(Formatting.GRAY)) +// .append(new LiteralText(Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").getPath()).formatted(Formatting.WHITE)); +// +// cText.styled((style) -> { +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click for more Info").formatted(Formatting.GREEN))); +// style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); +// }); +// +// list.add(cText.append("\n")); +// } +// +// Text[] texts = new Text[]{}; +// texts = list.toArray(texts); +// return sendPage(source, texts, page, "Claims", "/claim listall %page%"); +// } +// private static int rename(CommandContext context, boolean admin) throws CommandSyntaxException { +// String name = getString(context, "claim"); +// String newName = getString(context, "name"); +// if(!newName.matches("[A-Za-z0-9]+")){ +// context.getSource().sendError(new LiteralText("Invalid claim name")); +// return -1; +// } +// Claim claim = ClaimManager.INSTANCE.claimsByName.get(name); +// if (claim == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// if (ClaimManager.INSTANCE.claimsByName.containsKey(newName)) { +// context.getSource().sendError(new LiteralText("That name is already taken!")); +// return -1; +// } +// if (!admin && !claim.hasPermission(context.getSource().getPlayer().getUuid(), Claim.Permission.MODIFY_PROPERTIES)) { +// context.getSource().sendError(new LiteralText("You don't have permission to modify claim properties!")); +// return -1; +// } +// ClaimManager.INSTANCE.claimsByName.remove(name); +// if(claim.isChild) claim.name = ClaimUtil.getParentClaim(claim).name + "." + newName; +// else claim.name = newName; +// ClaimManager.INSTANCE.addClaim(claim); +// context.getSource().sendFeedback(new LiteralText("Renamed Claim " + name + " to " + claim.name).formatted(Formatting.GOLD), admin); +// return -1; +// } +// private static int showTrustedList(CommandContext context, Claim claim, boolean showSelf) throws CommandSyntaxException { +// ServerCommandSource source = context.getSource(); +// ServerPlayerEntity player = source.getPlayer(); +// int mapSize = claim.permissionManager.playerPermissions.size(); +// +// if (mapSize == 1 && !showSelf) { +// source.sendError(new LiteralText(claim.name + " is not trusting anyone!")); +// return -1; +// } +// +// Text text = new LiteralText("\n"); +// text.append(new LiteralText("Trusted players for Claim ").formatted(Formatting.YELLOW)) +// .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append("\n"); +// +// AtomicInteger atomicInteger = new AtomicInteger(); +// claim.permissionManager.playerPermissions.forEach((uuid, perm) -> { +// atomicInteger.incrementAndGet(); +// Text pText = new LiteralText(""); +// Text owner; +// GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); +// if (profile != null) { +// owner = new LiteralText(profile.getName()); +// } else { +// owner = new LiteralText(uuid.toString()).styled((style) -> { +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to Copy"))); +// style.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); +// }); +// } +// +// pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) +// .append(owner.formatted(Formatting.YELLOW)); +// +// Text hover = new LiteralText(""); +// hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); +// +// int allowed = 0; +// int i = 0; +// boolean nextColor = false; +// Text perms = new LiteralText(""); +// +// for (Claim.Permission value : Claim.Permission.values()) { +// if (claim.permissionManager.hasPermission(uuid, value)) { +// Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; +// perms.append(new LiteralText(value.id).formatted(formatting)).append(" "); +// if (i == 3) perms.append("\n"); +// allowed++; +// i++; +// nextColor = !nextColor; +// } +// } +// +// if (allowed == Claim.Permission.values().length) { +// hover.append(new LiteralText("All " + allowed + " Permissions").formatted(Formatting.YELLOW, Formatting.ITALIC)); +// } else { +// hover.append(perms); +// } +// +// pText.append(new LiteralText(" ") +// .append(new LiteralText("(").formatted(Formatting.GOLD)) +// .append(new LiteralText(String.valueOf(allowed)).formatted(Formatting.GREEN)) +// .append(new LiteralText("/").formatted(Formatting.GOLD)) +// .append(new LiteralText(String.valueOf(Claim.Permission.values().length)).formatted(Formatting.YELLOW)) +// .append(new LiteralText(")").formatted(Formatting.GOLD)) +// ); +// +// pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); +// text.append(pText).append("\n"); +// }); +// +// source.sendFeedback(text, false); +// return 1; +// } +// private static int setOwnerName(ServerCommandSource source, Claim claim, String input) { +// String name = input.equals("reset") ? null : input; +// source.sendFeedback(new LiteralText("Set the Custom Owner Name to ") +// .formatted(Formatting.YELLOW).append(new LiteralText(name == null ? "Reset" : name).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) +// .append(new LiteralText(claim.customOwnerName == null ? "Not Present" : claim.customOwnerName).formatted(Formatting.GOLD)) +// .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) +// , false); +// claim.customOwnerName = input; +// return 1; +// } +// private static int setOwner(ServerCommandSource source, Claim claim, GameProfile profile) { +// GameProfile oldOwner = source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); +// source.sendFeedback(new LiteralText("Set the Claim Owner to ") +// .formatted(Formatting.YELLOW).append(new LiteralText(profile.getName()).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) +// .append(new LiteralText(oldOwner == null ? "(" + claim.claimBlockOwner + ")" : oldOwner.getName()).formatted(Formatting.GOLD)) +// .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) +// , false); +// claim.claimBlockOwner = profile.getId(); +// return 1; +// } +// private static int setEventMessage(ServerCommandSource source, Claim claim, Claim.Event event, String message) { +// switch (event) { +// case ENTER_CLAIM: +// claim.enterMessage = message.equalsIgnoreCase("reset") ? null : message; +// break; +// case LEAVE_CLAIM: +// claim.leaveMessage = message.equalsIgnoreCase("reset") ? null : message; +// break; +// } +// +// if (message.equalsIgnoreCase("reset")) { +// source.sendFeedback(new LiteralText("Reset ").append(new LiteralText(event.id).formatted(Formatting.GOLD) +// .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) +// .append(new LiteralText(claim.name).formatted(Formatting.GOLD))).formatted(Formatting.YELLOW) +// , false); +// return -1; +// } +// +// source.sendFeedback(new LiteralText("Set ").append(new LiteralText(event.id).formatted(Formatting.GOLD) +// .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) +// .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" to:").formatted(Formatting.YELLOW))) +// .append("\n").append(new LiteralText(ChatColor.translate(message))) +// .formatted(Formatting.YELLOW) +// , false); +// return 1; +// } +// private static int executeSetting(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { +// ServerPlayerEntity player = source.getPlayer(); +// Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : +// ClaimManager.INSTANCE.claimsByName.get(claimName); +// if (claim1 == null) { +// source.sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// +// if (input == null) { +// return querySettings(source, claim1); +// } +// +// validateCanAccess(player, claim1, admin); +// Claim.ClaimSettings.Setting setting = Claim.ClaimSettings.Setting.byId(input); +// Claim.Permission permission = Claim.Permission.byId(input); +// +// if (setting != null && permission == null) +// return isQuery ? querySetting(source, claim1, setting) : setSetting(source, claim1, setting, value); +// +// if (setting == null && permission != null) +// return isQuery ? queryPermission(source, claim1, permission) : setPermission(source, claim1, permission, value); +// +// source.sendError(Messages.INVALID_SETTING); +// return -1; +// } +// private static int executePermission(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { +// ServerPlayerEntity player = source.getPlayer(); +// Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : +// ClaimManager.INSTANCE.claimsByName.get(claimName); +// if (claim1 == null) { +// source.sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// +// validateCanAccess(player, claim1, admin); +// Claim.Permission permission = Claim.Permission.byId(input); +// if (permission != null) +// return !isQuery ? setPermission(source, claim1, permission, value) : queryPermission(source, claim1, permission); +// +// source.sendError(Messages.INVALID_SETTING); +// return -1; +// } +// private static int querySetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting) { +// boolean enabled = claim.settings.getSetting(setting); +// source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); +// return 1; +// } +// private static int setSetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting, boolean set) { +// claim.settings.settings.put(setting, set); +// source.sendFeedback(new LiteralText(ChatColor.translate("&eSet setting &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); +// return 0; +// } +// private static int queryPermission(ServerCommandSource source, Claim claim, Claim.Permission permission) { +// boolean defaultPerm = claim.permissionManager.defaults.hasPermission(permission); +// source.sendFeedback(new LiteralText(ChatColor.translate("&ePermission &6" + permission.id + "&e is set to " + (defaultPerm ? "&a" : "&c") + defaultPerm + "&e for &6" + claim.name)), false); +// return 1; +// } +// private static int setPermission(ServerCommandSource source, Claim claim, Claim.Permission permission, boolean set) { +// claim.permissionManager.defaults.setPermission(permission, set); +// source.sendFeedback(new LiteralText(ChatColor.translate("&eSet permission &6" + permission.id + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); +// return 1; +// } +// private static int querySettings(ServerCommandSource source, Claim claim) { +// source.sendFeedback(new LiteralText("\n").append(new LiteralText("Settings: " + claim.name).formatted(Formatting.YELLOW)).append("\n") +// .append(Messages.Command.getSettings(claim)).append("\n"), false); +// return 1; +// } +// private static int executeTrust(CommandContext context, Collection targetCollection, boolean set, @Nullable String claimName) throws CommandSyntaxException { +// AtomicInteger integer = new AtomicInteger(); +//// if(targetCollection.size() > 1){ +//// context.getSource().sendFeedback(new LiteralText("Only 1 player allowed").formatted(Formatting.RED), true); +//// return 0; +//// } +// if(targetCollection.isEmpty()){ +// context.getSource().sendFeedback(new LiteralText("No player provided").formatted(Formatting.RED), true); +// return 0; +// } +// ServerPlayerEntity p = context.getSource().getPlayer(); +// Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getBlockPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); +// validateClaim(claim1); +// targetCollection.iterator().forEachRemaining(gameProfile -> { +// try { +// //This is supposed to check if the player has played before :shrug: +// if(context.getSource().getMinecraftServer().getUserCache().getByUuid(gameProfile.getId()) == gameProfile){ +// integer.set(setTrust(context, claim1, gameProfile, set, false)); +// } else { +// context.getSource().sendFeedback(new LiteralText("Unknown player!").formatted(Formatting.RED), true); +// integer.set(0); +// } +// } catch (CommandSyntaxException e) { +// e.printStackTrace(); +// } +// }); +// return integer.get(); +// } +// private static int setTrust(CommandContext context, Claim claim, GameProfile target, boolean set, boolean admin) throws CommandSyntaxException { +// if (verifyPermission(claim, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { +// claim.permissionManager.playerPermissions.put(target.getId(), set ? new Claim.InvertedPermissionMap() : new Claim.DefaultPermissionMap()); +// context.getSource().sendFeedback(new LiteralText(target.getName() + (set ? " now" : " no longer") + " has all the permissions").formatted(Formatting.YELLOW), false); +// } +// return 1; +// } +// private static int setFly(CommandContext context, boolean set) throws CommandSyntaxException { +// ServerPlayerEntity player = context.getSource().getPlayer(); +// if (set) { +// ClaimManager.INSTANCE.flyers.add(player.getUuid()); +// player.addMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN), false); +// return 1; +// } +// +// player.addMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED), false); +// ClaimManager.INSTANCE.flyers.remove(player.getUuid()); +// return -1; +// } - player.addMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED), false); - ClaimManager.INSTANCE.flyers.remove(player.getUuid()); - return -1; - } -} +// +// private static GameProfile getProfile(CommandContext context, String arg) { +// return context.getSource().getMinecraftServer().getUserCache().findByName(getString(context, arg)); +// } +//} \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java index 8b08234..cf9d404 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java @@ -42,7 +42,7 @@ public void useBlocksUntil0(UUID player, int amount) { if (!useClaimBlocks(player, amount)) blocksLeft.put(player, 0); } public void setClaimBlocks(Collection players, int amount) { - players.forEach(player -> setClaimBlocks(player.getGameProfile().getId(), -amount)); + players.forEach(player -> setClaimBlocks(player.getGameProfile().getId(), amount)); } public Claim getClaim(String name){ @@ -63,6 +63,7 @@ public List getPlayerClaims(UUID id) { }); return list; } + public boolean addClaim(Claim claim) { if (claimsByName.containsKey(claim.name)) return false; if (wouldIntersect(claim) && !claim.isChild) return false; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/Config.java index 093e1f1..9152cb6 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Config.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Config.java @@ -9,6 +9,7 @@ public class Config { public static int baseClaimBlocks3d = 15625; public static int baseClaimBlocks2d = 2500; public static boolean claims2d = true; + public static int rent_maxseconds = 7776000; public static String permissionManager = "luckperms"; public static String prefix = "&8[&aClaims&8]&r "; public static String msg_no_perm = "&c&lHey!&r&c Sorry but you don't have permission to do that"; @@ -32,6 +33,7 @@ static void sync() { claims2d = config.getBool("2D claims", claims2d, "Claims extending from y 0 to y 256"); baseClaimBlocks2d = config.getInt("2D base claim blocks", baseClaimBlocks2d, "Area Filled: " + ItsMine.blocksToAreaString2d(baseClaimBlocks2d)); baseClaimBlocks3d = config.getInt("3D base claim blocks", baseClaimBlocks3d, "Area Filled: " + ItsMine.blocksToAreaString3d(baseClaimBlocks3d)); + rent_maxseconds = config.getInt("rent.maxdays", rent_maxseconds, "Maximum rent time in seconds (eg. 90d = 7776000)"); permissionManager = config.getString("permissionManager", permissionManager, "Values: thimble, luckperms, vanilla"); prefix = config.getString("msg.prefix", prefix); msg_interact_entity = config.getString("msg.interact.entity", msg_interact_entity); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index 1d3230b..e3b4944 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -3,6 +3,7 @@ import io.github.indicode.fabric.itsmine.mixin.BlockActionPacketMixin; import io.github.indicode.fabric.itsmine.mixin.BucketItemMixin; import io.github.indicode.fabric.itsmine.mixin.projectile.OwnedProjectile; +import io.github.indicode.fabric.itsmine.util.BlockUtil; import net.minecraft.block.*; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; @@ -19,9 +20,7 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -import net.minecraft.world.BlockView; import net.minecraft.world.World; -import net.minecraft.world.dimension.DimensionType; import java.util.*; @@ -79,14 +78,14 @@ public static void setClaimFlying(UUID player, boolean flying) { public static boolean canInteractWith(Claim claim, Block block, UUID player) { return claim.hasPermission(player, Claim.Permission.INTERACT_BLOCKS) || - (BlockUtils.isButton(block) && claim.hasPermission(player, Claim.Permission.USE_BUTTONS)) || - (BlockUtils.isLever(block) && claim.hasPermission(player, Claim.Permission.USE_LEVERS)) || - (BlockUtils.isDoor(block) && claim.hasPermission(player, Claim.Permission.INTERACT_DOORS)) || - (BlockUtils.isContainer(block) && claim.hasPermission(player, Claim.Permission.CONTAINER)) || - (BlockUtils.isChest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_CHEST)) || - (BlockUtils.isEnderchest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_ENDERCHEST)) || - (BlockUtils.isShulkerBox(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_SHULKERBOX)) || - (BlockUtils.isLectern(block) && claim.hasPermission(player, Claim.Permission.INTERACT_LECTERN)); + (BlockUtil.isButton(block) && claim.hasPermission(player, Claim.Permission.USE_BUTTONS)) || + (BlockUtil.isLever(block) && claim.hasPermission(player, Claim.Permission.USE_LEVERS)) || + (BlockUtil.isDoor(block) && claim.hasPermission(player, Claim.Permission.INTERACT_DOORS)) || + (BlockUtil.isContainer(block) && claim.hasPermission(player, Claim.Permission.CONTAINER)) || + (BlockUtil.isChest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_CHEST)) || + (BlockUtil.isEnderchest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_ENDERCHEST)) || + (BlockUtil.isShulkerBox(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_SHULKERBOX)) || + (BlockUtil.isLectern(block) && claim.hasPermission(player, Claim.Permission.INTERACT_LECTERN)); } public static boolean canInteractUsingItem(Claim claim, Item item, UUID player) { @@ -114,6 +113,18 @@ public static boolean canDamageWithProjectile(ProjectileEntity projectile, Entit return false; } + public static > Map sortByValue(Map map) { + List> list = new ArrayList<>(map.entrySet()); + list.sort(Map.Entry.comparingByValue()); + + Map result = new LinkedHashMap<>(); + for (Map.Entry entry : list) { + result.put(entry.getKey(), entry.getValue()); + } + + return result; + } + public static boolean checkCanDamageWithProjectile(Entity entity, MinecraftServer server, UUID uuid) { if (entity.world.isClient) return true; @@ -129,15 +140,6 @@ public static boolean checkCanDamageWithProjectile(Entity entity, MinecraftServe return true; } - public static BlockPos getPosOnGround(BlockPos pos, World world) { - BlockPos blockPos = new BlockPos(pos.getX(), pos.getY(), pos.getZ()); - - do { - blockPos = blockPos.down(); - } while (world.getBlockState(blockPos).isAir()); - - return blockPos.up(); - } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java index ddab300..ac74472 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java @@ -1,24 +1,24 @@ package io.github.indicode.fabric.itsmine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; import net.fabricmc.api.ModInitializer; -import net.minecraft.SharedConstants; /** * @author Indigo Amann */ public class ItsMine implements ModInitializer { - private static Permissions permissions; + private static PermissionUtil permissionUtil; @Override public void onInitialize() { Config.sync(); - permissions = new Permissions(); + permissionUtil = new PermissionUtil(); //TODO: Enable when developing //SharedConstants.isDevelopment = true; } - public static Permissions permissions() { - return permissions; + public static PermissionUtil permissions() { + return permissionUtil; } public static String blocksToAreaString3d(int blocks) { int base = (int) Math.floor(Math.cbrt(blocks)); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index db14075..904182f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -56,11 +56,16 @@ public class Messages { .append(line(1, "To set a permission, type ").append(text("/claim permissions player [true | false]").formatted(Formatting.GOLD))) .append(line(2, "To check someone's permission, type ").append(text("/claim permissions player ").formatted(Formatting.GOLD))) .append(line(3, "To see a list of trusted players, type ").append(text("/claim trusted").formatted(Formatting.GOLD))), - header("How to resize claim") + header("How to Claim (Resizing)") .append(line("You can always change the size of your claim if you aren't happy with it!").formatted(Formatting.LIGHT_PURPLE)) .append(line(1, "To expand your claim in a direction, type ").append(text("/claim expand ").formatted(Formatting.GOLD))) .append(line(2, "If you want to specify a direction, you can type ").append(text("/claim expand ").formatted(Formatting.GOLD))) - .append(line(3, "To shrink a claim you do the same thing but replace \"expand\" with \"shrink\"")) + .append(line(3, "To shrink a claim you do the same thing but replace \"expand\" with \"shrink\"")), + header("How to Claim (Subzones)") + .append(line("Subzones allow you to have seperate permissions / settings in certain areas of your claim").formatted(Formatting.LIGHT_PURPLE)) + .append(line(1, "To create a subzone, you select an area inside your claim the way you would select a normal claim")) + .append(line(2, "Type ").append("/claim subzone add ").formatted(Formatting.GOLD).append(" to create a subzone").formatted(Formatting.YELLOW)) + .append(line(3,"Done! Everything else works the same way claims work")) }; public static final Text[] HELP = new Text[]{ diff --git a/src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java b/src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java new file mode 100644 index 0000000..be6d40a --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java @@ -0,0 +1,13 @@ +package io.github.indicode.fabric.itsmine; + +import net.minecraft.entity.Entity; + +import java.util.Map; +import java.util.UUID; + +public interface MonitorableWorld { + + int loadedEntities(); + + Map EntityList(); +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java new file mode 100644 index 0000000..14151b1 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java @@ -0,0 +1,43 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.command.EntitySelector; +import net.minecraft.command.arguments.EntityArgumentType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; +import net.minecraft.util.Formatting; + +import java.util.UUID; + +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class BlockCommand { + + static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder check = literal("blocks"); + RequiredArgumentBuilder other = argument("player", EntityArgumentType.player()); + other.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); + other.executes(ctx -> blocksLeft(ctx.getSource(), EntityArgumentType.getPlayer(ctx, "player").getGameProfile().getId())); + check.then(other); + check.executes(ctx -> blocksLeft(ctx.getSource())); + command.then(check); + } + + static int blocksLeft(ServerCommandSource source, UUID player) throws CommandSyntaxException { + int blocks = ClaimManager.INSTANCE.getClaimBlocks(player); + source.sendFeedback(new LiteralText((source.getPlayer().getGameProfile().getId().equals(player) ? "You have " : "They have ") + blocks + " blocks left").setStyle(new Style().setColor(Formatting.YELLOW)), false); + return 1; + } + static int blocksLeft(ServerCommandSource source) throws CommandSyntaxException { + int blocks = ClaimManager.INSTANCE.getClaimBlocks(source.getPlayer().getUuid()); + source.sendFeedback(new LiteralText("You have " + blocks + " blocks left").setStyle(new Style().setColor(Formatting.YELLOW)), false); + return 1; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java new file mode 100644 index 0000000..0c55bd6 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java @@ -0,0 +1,45 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import io.github.indicode.fabric.itsmine.command.admin.AdminCommand; +import io.github.indicode.fabric.itsmine.command.subzone.SubzoneCommand; +import net.minecraft.server.command.ServerCommandSource; + +import static net.minecraft.server.command.CommandManager.literal; + +public class CommandManager { + + public static void register(CommandDispatcher dispatcher) { + LiteralArgumentBuilder main = literal("itsmine"); + LiteralArgumentBuilder alias = literal("claim"); + register(main, dispatcher); + register(alias, dispatcher); + dispatcher.register(main); + dispatcher.register(alias); + } + private static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { + AdminCommand.register(command, dispatcher); + BlockCommand.register(command); + CreateCommand.register(command); + ExceptionCommand.register(command, false, false); + ExpandCommand.register(command); + FlyCommand.register(command); + HelpCommand.register(command); + InfoCommand.register(command); + ListCommand.register(command); + PermissionsCommand.register(command, false); + RemoveCommand.register(command); + RenameCommand.register(command); + RentableCommand.register(command); + RentCommand.register(command); + RevenueCommand.register(command); + SettingsCommand.register(command, false); + ShowCommand.register(command); + StickCommand.register(command); + SubzoneCommand.register(command, dispatcher); + TransferCommand.register(command); + TrustCommand.register(command); + TrustedCommand.register(command); + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java new file mode 100644 index 0000000..1c53fb0 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java @@ -0,0 +1,126 @@ +package io.github.indicode.fabric.itsmine.command; + +import blue.endless.jankson.annotation.Nullable; +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.command.arguments.BlockPosArgumentType; +import net.minecraft.command.arguments.PosArgument; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.HoverEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; +import net.minecraft.util.Formatting; +import net.minecraft.util.Pair; +import net.minecraft.util.math.BlockPos; + +import java.util.UUID; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static io.github.indicode.fabric.itsmine.command.ShowCommand.executeShowClaim; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class CreateCommand { + static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder create = literal("create"); + RequiredArgumentBuilder name = argument("name", word()); + + name.executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); + if (selectedPositions == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getLeft() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getRight() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); + } else { + String cname = getString(context, "name"); + if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), false, null) > 0) { + ClaimManager.INSTANCE.stickPositions.remove(player); + } + } + return 0; + }); + + ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); + RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); + max.executes(context -> createClaim(getString(context, "name"), context.getSource(), BlockPosArgumentType.getBlockPos(context, "min"), BlockPosArgumentType.getBlockPos(context, "max"), false, null)); + min.then(max); + name.then(min); + create.then(name); + command.then(create); + } + + public static int createClaim(String name, ServerCommandSource owner, BlockPos posA, BlockPos posB, boolean admin, @Nullable String cOwnerName) throws CommandSyntaxException { + if (name.length() > 30) { + owner.sendError(Messages.MSG_LONG_NAME); + return -1; + } + if(!name.matches("[A-Za-z0-9]+")){ + owner.sendError(new LiteralText("Invalid claim name")); + return -1; + } + UUID ownerID = owner.getPlayer().getGameProfile().getId(); + int x, y = 0, z, mx, my = 255, mz; + if (posA.getX() > posB.getX()) { + x = posB.getX(); + mx = posA.getX(); + } else { + x = posA.getX(); + mx = posB.getX(); + } + if (!Config.claims2d) { + if (posA.getY() > posB.getY()) { + y = posB.getY(); + my = posA.getY(); + } else { + y = posA.getY(); + my = posB.getY(); + } + } + if (posA.getZ() > posB.getZ()) { + z = posB.getZ(); + mz = posA.getZ(); + } else { + z = posA.getZ(); + mz = posB.getZ(); + } + BlockPos min = new BlockPos(x, y, z); + BlockPos max = new BlockPos(mx, my, mz); + BlockPos sub = max.subtract(min); + sub = sub.add(1, Config.claims2d ? 0 : 1,1); + int subInt = sub.getX() * (Config.claims2d ? 1 : sub.getY()) * sub.getZ(); + + Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos(), false); + if (cOwnerName != null) claim.customOwnerName = cOwnerName; + claim.permissionManager.playerPermissions.put(ownerID, new Claim.InvertedPermissionMap()); + if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { + if (!ClaimManager.INSTANCE.wouldIntersect(claim)) { + // works because only the first statement is evaluated if true + if ((admin && ItsMine.permissions().hasPermission(owner, PermissionUtil.Command.INFINITE_BLOCKS, 2)) || ClaimManager.INSTANCE.useClaimBlocks(ownerID, subInt)) { + ClaimManager.INSTANCE.addClaim(claim); + owner.sendFeedback(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)).append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").setStyle(new Style().setColor(Formatting.GREEN).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))))), false); + BlockCommand.blocksLeft(owner); + executeShowClaim(owner, claim, false); + if (admin) + owner.getMinecraftServer().sendMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); + return 1; + } else { + owner.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + subInt + "(" + (subInt - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); + } + } else { + owner.sendFeedback(new LiteralText("Your claim would overlap with another claim").formatted(Formatting.RED), false); + } + } else { + owner.sendFeedback(new LiteralText("The name \"" + name + "\" is already taken.").formatted(Formatting.RED), false); + } + return 0; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java new file mode 100644 index 0000000..d046f0b --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java @@ -0,0 +1,176 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.sun.org.apache.xpath.internal.Arg; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.command.EntitySelector; +import net.minecraft.command.arguments.EntityArgumentType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.*; +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; +import static io.github.indicode.fabric.itsmine.command.TrustCommand.setTrust; +import static io.github.indicode.fabric.itsmine.command.TrustedCommand.showTrustedList; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.*; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.*; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class ExceptionCommand { + + public static void register(LiteralArgumentBuilder command, boolean admin, boolean subzone) { + { + LiteralArgumentBuilder settings = literal("settings"); + RequiredArgumentBuilder claim; + if(subzone){ + claim = ArgumentUtil.getClaims(); + } else { + claim = ArgumentUtil.getSubzones(); + } + + if (!admin) { + settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); + + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return querySettings(context.getSource(), claim1); + }); + } + + RequiredArgumentBuilder id = argument("setting", word()).suggests(SETTINGS_PROVIDER); + RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); + + id.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), getString(context, "claim"), true, false, admin)); + set.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); + + id.then(set); + claim.then(id); + settings.then(claim); + command.then(settings); + } + + LiteralArgumentBuilder exceptions = literal("permissions"); + if (admin) exceptions.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_PERMISSIONS, 2)); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + if (!admin) { + exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); + + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim1, false); + }); + } + + if (!admin) { + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(new LiteralText("That claim does not exist")); + return -1; + } + return showTrustedList(context, claim1, true); + }); + } + + { + RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); + LiteralArgumentBuilder remove = literal("remove"); + remove.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + claim1.permissionManager.resetPermissions(player1.getGameProfile().getId()); + context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + " no longer has an exception in the claim").formatted(Formatting.YELLOW), false); + } + return 0; + }); + player.then(remove); + LiteralArgumentBuilder all = literal("*"); + RequiredArgumentBuilder allstate = argument("allow", BoolArgumentType.bool()); + allstate.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + validateClaim(claim1); + return setTrust(context, claim1, player1.getGameProfile(), BoolArgumentType.getBool(context, "allow"), admin); + }); + all.then(allstate); + player.then(all); + for (Claim.Permission value : Claim.Permission.values()) { + LiteralArgumentBuilder permNode = literal(value.id); + RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); + allow.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + boolean permission = BoolArgumentType.getBool(context, "allow"); + modifyException(claim1, player1, value, permission); + context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has the permission " + value.name).formatted(Formatting.YELLOW), false); + } + return 0; + }); + permNode.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + boolean permission = hasPermission(claim1, player1, value); + context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); + } + return 0; + }); + permNode.then(allow); + player.then(permNode); + } + claim.then(player); + } + { + LiteralArgumentBuilder message = literal("message"); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + RequiredArgumentBuilder messageEvent = getMessageEvent(); + RequiredArgumentBuilder messageArgument = getEventMessage(); + messageArgument.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PROPERTIES, context, admin)) { + Claim.Event event = Claim.Event.getById(getString(context, "messageEvent")); + + if (event == null) { + context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); + return -1; + } + + return setEventMessage(context.getSource(), claim1, event, getString(context, "message")); + } + + return -1; + }); + + messageEvent.then(messageArgument); + claimArgument.then(messageEvent); + message.then(claimArgument); + command.then(message); + } + + + exceptions.then(claim); + command.then(exceptions); + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java new file mode 100644 index 0000000..7d13134 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java @@ -0,0 +1,174 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; +import io.github.indicode.fabric.itsmine.util.ShowerUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; + +import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.command.BlockCommand.blocksLeft; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getDirections; +import static io.github.indicode.fabric.itsmine.util.DirectionUtil.directionByName; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class ExpandCommand { + + public static void register(LiteralArgumentBuilder command) { + { + LiteralArgumentBuilder expand = literal("expand"); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = getDirections(); + + direction.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + IntegerArgumentType.getInteger(context, "distance"), + directionByName(getString(context, "direction")), + context.getSource(), + false + )); + + amount.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + IntegerArgumentType.getInteger(context, "distance"), + Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], + context.getSource(), + false + )); + + amount.then(direction); + expand.then(amount); + command.then(expand); + } + { + LiteralArgumentBuilder shrink = literal("shrink"); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = getDirections(); + + direction.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + -IntegerArgumentType.getInteger(context, "distance"), + directionByName(getString(context, "direction")), + context.getSource(), + false + )); + + amount.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + -IntegerArgumentType.getInteger(context, "distance"), + Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], + context.getSource(), + false + )); + + amount.then(direction); + shrink.then(amount); + command.then(shrink); + } + } + + private static void undoExpand(Claim claim, Direction direction, int amount){ + if (amount < 0) claim.expand(direction, -amount); + else claim.shrink(direction, amount); + } + + public static int expand(Claim claim, int amount, Direction direction, ServerCommandSource source, boolean admin) throws CommandSyntaxException { + UUID ownerID = source.getPlayer().getGameProfile().getId(); + if (claim == null) { + source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if (direction == null) { + source.sendFeedback(new LiteralText("That is not a valid direction").formatted(Formatting.RED), false); + return 0; + } + if (!claim.permissionManager.hasPermission(ownerID, Claim.Permission.MODIFY_SIZE)) { + source.sendFeedback(new LiteralText("You do not have border change permissions in that claim").formatted(Formatting.RED), false); + if (!admin) return 0; + } + int oldArea = claim.getArea(); + + + if (amount > 0) { + claim.expand(direction, amount); + } + else { + claim.shrink(direction, -amount); + } + + if (!claim.canShrinkWithoutHittingOtherSide(new BlockPos(direction.getOffsetX() * amount, direction.getOffsetY() * amount, direction.getOffsetZ() * amount))) { + source.sendFeedback(new LiteralText("You can't shrink your claim that far. It would pass its opposite wall.").formatted(Formatting.RED), false); + undoExpand(claim, direction, amount); + return 0; + } + + if(!claim.isChild){ + if (ClaimManager.INSTANCE.wouldIntersect(claim)) { + undoExpand(claim, direction, amount); + source.sendFeedback(new LiteralText("Expansion would result in hitting another claim").formatted(Formatting.RED), false); + return 0; + } + + //Check if shrinking would reset a subzone to be outside of its parent claim + AtomicBoolean returnValue = new AtomicBoolean(); + returnValue.set(false); + claim.children.forEach(claim1 -> { + if(!claim1.isInside(claim)){ + undoExpand(claim, direction, amount); + source.sendFeedback(new LiteralText("Shrinking would result in " + claim1.name + " being outside of " + claim.name).formatted(Formatting.RED), true); + returnValue.set(true); + } + }); + if(returnValue.get()) return 0; + + int newArea = claim.getArea() - oldArea; + if (!admin && claim.claimBlockOwner != null && ClaimManager.INSTANCE.getClaimBlocks(ownerID) < newArea) { + undoExpand(claim, direction, amount); + source.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + newArea + "(" + (newArea - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); + blocksLeft(source); + return 0; + } else { + if (!admin && claim.claimBlockOwner != null) ClaimManager.INSTANCE.useClaimBlocks(ownerID, newArea); + source.sendFeedback(new LiteralText("Your claim was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); + blocksLeft(source); + undoExpand(claim, direction, amount); + ShowerUtil.update(claim, source.getWorld(), true); + if (amount > 0) claim.expand(direction, amount); + else claim.shrink(direction, -amount); + ShowerUtil.update(claim, source.getWorld(), false); + } + return 0; + }else{ + Claim parent = ClaimUtil.getParentClaim(claim); + if(!claim.isInside(parent)) { + source.sendFeedback(new LiteralText("Expansion would result in expanding outside of your main claim").formatted(Formatting.RED), false); + undoExpand(claim, direction, amount); + } else if(ClaimManager.INSTANCE.wouldSubzoneIntersect((claim))){ + source.sendFeedback(new LiteralText("Expansion would result in overlapping with another subzone").formatted(Formatting.RED), false); + undoExpand(claim, direction, amount); + }else{ + source.sendFeedback(new LiteralText("Your subzone was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); + //The expansion is undone to hide the claimshower + undoExpand(claim, direction, amount); + ShowerUtil.update(parent, source.getWorld(), true); + if (amount > 0) claim.expand(direction, amount); + else claim.shrink(direction, -amount); + ShowerUtil.update(parent, source.getWorld(), false); + } + } + return 0; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java new file mode 100644 index 0000000..9ad50af --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java @@ -0,0 +1,42 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static net.minecraft.server.command.CommandManager.literal; + +public class FlyCommand { + static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder fly = literal("fly"); + fly.requires(src -> ItsMine.permissions().hasPermission(src, PermissionUtil.Command.CLAIM_FLY, 2)); + RequiredArgumentBuilder setArgument = CommandManager.argument("set", BoolArgumentType.bool()); + fly.executes((context) -> executeSetFly(context, !ClaimManager.INSTANCE.flyers.contains(context.getSource().getPlayer().getUuid()))); + setArgument.executes((context) -> executeSetFly(context, BoolArgumentType.getBool(context, "set"))); + fly.then(setArgument); + command.then(fly); + } + + private static int executeSetFly(CommandContext context, boolean set) throws CommandSyntaxException { + ServerPlayerEntity player = context.getSource().getPlayer(); + if (set) { + ClaimManager.INSTANCE.flyers.add(player.getUuid()); + player.addMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN), false); + return 1; + } + + player.addMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED), false); + ClaimManager.INSTANCE.flyers.remove(player.getUuid()); + return -1; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java new file mode 100644 index 0000000..ac15e93 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java @@ -0,0 +1,102 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.ChatColor; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.Messages; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.HoverEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getHelpId; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class HelpCommand { + + public static void register(LiteralArgumentBuilder command) { + command.executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); + + LiteralArgumentBuilder help = literal("help"); + help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); + + RequiredArgumentBuilder id = getHelpId(); + RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); + + page.executes((context) -> { + Claim.HelpBook book = Claim.HelpBook.getById(getString(context, "id")); + if (book == null) { + context.getSource().sendError(new LiteralText("Invalid Book!")); + return -1; + } + int p = IntegerArgumentType.getInteger(context, "page"); + + if (p > book.texts.length) p = 1; + return sendPage(context.getSource(), book.texts, p, book.title, book.getCommand()); + }); + + id.then(page); + help.then(id); + command.then(help); + } + + public static int sendPage(ServerCommandSource source, Text[] text, int page, String title, String command) { + int prevPage = page - 2; + int thisPage = page - 1; + int nextPage = page + 1; + final String SEPARATOR = "-----------------------------------------------------"; + Text header = new LiteralText("") + .append(new LiteralText("- [ ").formatted(Formatting.GRAY)) + .append(new LiteralText(title).formatted(Formatting.GOLD)) + .append(" ] ") + .append(SEPARATOR.substring(ChatColor.removeAlternateColorCodes('&', title).length() + 4)) + .formatted(Formatting.GRAY); + + Text button_prev = new LiteralText("") + .append(new LiteralText("<-").formatted(Formatting.WHITE, Formatting.BOLD)) + .append(" ").append(new LiteralText("Prev").formatted(Formatting.GOLD)) + .styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); + if (prevPage >= 0) + style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); + }); + + Text button_next = new LiteralText("") + .append(new LiteralText("Next").formatted(Formatting.GOLD)) + .append(" ").append(new LiteralText("->").formatted(Formatting.WHITE, Formatting.BOLD)).append(" ") + .styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); + if (nextPage <= text.length) + style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); + }); + + Text buttons = new LiteralText("") + .append(new LiteralText("[ ").formatted(Formatting.GRAY)) + .append(button_prev) + .append(" ") + .append( + new LiteralText(String.valueOf(page)).formatted(Formatting.GREEN) + .append(new LiteralText("/").formatted(Formatting.GRAY)) + .append(new LiteralText(String.valueOf(text.length)).formatted(Formatting.GREEN)) + ) + .append(" ") + .append(button_next) + .append(new LiteralText("] ").formatted(Formatting.GRAY)); + + Text footer = new LiteralText("- ") + .formatted(Formatting.GRAY) + .append(buttons).append(new LiteralText(" ------------------------------").formatted(Formatting.GRAY)); + + header.append("\n").append(text[thisPage]).append("\n").append(footer); + source.sendFeedback(header, false); + return 1; + } + + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java new file mode 100644 index 0000000..3e6aed0 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java @@ -0,0 +1,105 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Config; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.TimeUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.HoverEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.registry.Registry; + +import java.util.Objects; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static net.minecraft.server.command.CommandManager.literal; + +public class InfoCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder info = literal("info"); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + info.executes(context -> info( + context.getSource(), + ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()) + )); + claim.executes(context -> info(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")) + )); + info.then(claim); + command.then(info); + } + + private static int info(ServerCommandSource source, Claim claim) throws CommandSyntaxException { + if (claim == null) { + source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + + GameProfile owner = claim.claimBlockOwner == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); + BlockPos size = claim.getSize(); + + Text text = new LiteralText("\n"); + text.append(new LiteralText("Claim Info: " + claim.name).formatted(Formatting.GOLD)).append("\n"); + text.append(newInfoLine("Name", new LiteralText(claim.name).formatted(Formatting.WHITE))); + text.append(newInfoLine("Entities", new LiteralText(String.valueOf(claim.getEntities(source.getWorld()))).formatted(Formatting.AQUA))); + text.append(newInfoLine("Owner", + owner != null && claim.customOwnerName == null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : + claim.customOwnerName != null ? new LiteralText(claim.customOwnerName).formatted(Formatting.GOLD) : + new LiteralText("No Owner").formatted(Formatting.RED, Formatting.ITALIC))); + text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); + + + text.append(new LiteralText("").append(new LiteralText("* Settings:").formatted(Formatting.YELLOW)) + .append(Messages.Command.getSettings(claim)).append("\n")); + Text pos = new LiteralText(""); + Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); + Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); + + + pos.append(newInfoLine("Position", new LiteralText("") + .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) + .append(" ") + .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); + text.append(pos); + text.append(newInfoLine("Dimension", new LiteralText(Registry.DIMENSION_TYPE.getId(claim.dimension).getPath()))); + if(claim.rent.isRented()){ + GameProfile tenant = claim.rent.getTenant() == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.rent.getTenant()); + text.append(newInfoLine("Status", new LiteralText("Rented").formatted(Formatting.RED).styled(style -> { + java.util.Date time=new java.util.Date((long) claim.rent.getRentedUntil()*1000); + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Until", new LiteralText(time.toString()).formatted(Formatting.WHITE)).append(newInfoLine("By", new LiteralText(tenant.getName()).formatted(Formatting.WHITE))).append(newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE))))); + }))); + } else if (claim.rent.isRentable() && !claim.rent.isRented()){ + text.append(newInfoLine("Status", new LiteralText("For Rent").formatted(Formatting.GREEN).styled(style -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE)).append(newInfoLine("Max Rent", new LiteralText(claim.rent.getMaxrentAbleTime() / 86400 + " days")).formatted(Formatting.WHITE)))); + }))); + + } else { + text.append(newInfoLine("Status", new LiteralText("Not For Rent").formatted(Formatting.GREEN))); + + } + source.sendFeedback(text, false); + return 1; + } + + private static Text newPosLine(BlockPos pos, Formatting form1, Formatting form2) { + return new LiteralText("") + .append(new LiteralText(String.valueOf(pos.getX())).formatted(form1)) + .append(" ") + .append(new LiteralText(String.valueOf(pos.getY())).formatted(form2)) + .append(" ") + .append(new LiteralText(String.valueOf(pos.getZ())).formatted(form1)); + } + private static Text newInfoLine(String title, Text text) { + return new LiteralText("").append(new LiteralText("* " + title + ": ").formatted(Formatting.YELLOW)) + .append(text).append("\n"); + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java new file mode 100644 index 0000000..9e2c0b1 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java @@ -0,0 +1,30 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.server.command.ServerCommandSource; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static io.github.indicode.fabric.itsmine.command.admin.AdminCommand.PERMISSION_CHECK_ADMIN; +import static io.github.indicode.fabric.itsmine.command.admin.ClaimsCommand.list; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.PLAYERS_PROVIDER; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class ListCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder list = literal("list"); + RequiredArgumentBuilder player = argument("player", word()); + player.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); + player.suggests(PLAYERS_PROVIDER); + list.executes(context -> list(context.getSource(), context.getSource().getName())); + player.requires(PERMISSION_CHECK_ADMIN); + player.executes(context -> list(context.getSource(), getString(context, "player"))); + command.then(list); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java new file mode 100644 index 0000000..2fe9ccf --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java @@ -0,0 +1,49 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; +import static io.github.indicode.fabric.itsmine.command.TrustedCommand.showTrustedList; +import static net.minecraft.server.command.CommandManager.literal; + +public class PermissionsCommand { + public static void register(LiteralArgumentBuilder command, boolean admin) { + LiteralArgumentBuilder exceptions = literal("permissions"); + if (admin) + exceptions.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_PERMISSIONS, 2)); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + if (!admin) { + exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); + + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim1, false); + }); + } + + if (!admin) { + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(new LiteralText("That claim does not exist")); + return -1; + } + return showTrustedList(context, claim1, true); + }); + } + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java new file mode 100644 index 0000000..827e85d --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java @@ -0,0 +1,93 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ClaimShower; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import io.github.indicode.fabric.itsmine.util.ShowerUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.util.ShowerUtil.silentHideShow; +import static net.minecraft.server.command.CommandManager.literal; + +public class RemoveCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder delete = literal("remove"); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + LiteralArgumentBuilder confirm = literal("confirm"); + confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); + claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); + claim.then(confirm); + delete.then(claim); + delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); + command.then(delete); + } + public static int requestDelete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { + if (claim == null) { + sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { + if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { + sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + } else { + sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); + return 0; + } + } + sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to delete the claim \"" + claim.name + "\"? ").formatted(Formatting.GOLD)) + .append(new LiteralText("[I'M SURE]").setStyle(new Style() + .setColor(Formatting.DARK_RED) + .setBold(true) + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")))), false); + return 0; + } + public static int delete(ServerCommandSource source, Claim claim, boolean admin) throws CommandSyntaxException { + ServerWorld world = source.getWorld(); + if (claim == null) { + source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if (!claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { + if (admin && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)) { + source.sendFeedback(new LiteralText("Deleting a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + } else { + source.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); + return 0; + } + } + if(!claim.isChild){ + ClaimManager.INSTANCE.releaseBlocksToOwner(claim); + ShowerUtil.update(claim, world, true); + ClaimManager.INSTANCE.claimsByName.remove(claim.name); + for(Claim subzone : claim.children){ + ClaimManager.INSTANCE.claimsByName.remove(subzone.name); + } + }else{ + Claim parent = ClaimUtil.getParentClaim(claim); + ShowerUtil.update(parent, world, true); + ClaimUtil.getParentClaim(claim).removeSubzone(claim); + ClaimManager.INSTANCE.claimsByName.remove(claim.name); + ShowerUtil.update(parent, world, false); + } + source.getWorld().getPlayers().forEach(playerEntity -> { + if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true); + }); + source.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)); + return 0; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java new file mode 100644 index 0000000..75612dd --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java @@ -0,0 +1,61 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class RenameCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder rename = literal("rename"); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + RequiredArgumentBuilder nameArgument = argument("name", word()); + nameArgument.executes((context) -> rename(context, false)); + claimArgument.then(nameArgument); + rename.then(claimArgument); + command.then(rename); + } + + public static int rename(CommandContext context, boolean admin) throws CommandSyntaxException { + String name = getString(context, "claim"); + String newName = getString(context, "name"); + if(!newName.matches("[A-Za-z0-9]+")){ + context.getSource().sendError(new LiteralText("Invalid claim name")); + return -1; + } + Claim claim = ClaimManager.INSTANCE.claimsByName.get(name); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + if (ClaimManager.INSTANCE.claimsByName.containsKey(newName)) { + context.getSource().sendError(new LiteralText("That name is already taken!")); + return -1; + } + if (!admin && !claim.hasPermission(context.getSource().getPlayer().getUuid(), Claim.Permission.MODIFY_PROPERTIES)) { + context.getSource().sendError(new LiteralText("You don't have permission to modify claim properties!")); + return -1; + } + ClaimManager.INSTANCE.claimsByName.remove(name); + if(claim.isChild) claim.name = ClaimUtil.getParentClaim(claim).name + "." + newName; + else claim.name = newName; + ClaimManager.INSTANCE.addClaim(claim); + context.getSource().sendFeedback(new LiteralText("Renamed Claim " + name + " to " + claim.name).formatted(Formatting.GOLD), admin); + return -1; + } + + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java new file mode 100644 index 0000000..67b3dcd --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java @@ -0,0 +1,94 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.TimeUtil; +import net.minecraft.item.ItemStack; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.string; +import static net.minecraft.server.command.CommandManager.literal; + +public class RentCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder rent = literal("rent"); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + RequiredArgumentBuilder days = CommandManager.argument("days", string()); + days.executes(context -> rent(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), getString(context, "days"))); + + claim.then(days); + rent.then(claim); + command.then(rent); + } + private static int rent(ServerCommandSource source, Claim claim, String rentString) throws CommandSyntaxException { + if(claim == null){ + source.sendFeedback(Messages.INVALID_CLAIM, true); + return 0; + } + int rentTime = (int) TimeUtil.convertStringtoSeconds(rentString); + int rentAbleTime = claim.rent.getRentAbleTime(); + int maxrentAbleTime = claim.rent.getMaxrentAbleTime(); + ItemStack currency = claim.rent.getCurrency(); + ItemStack handItem = source.getPlayer().inventory.getMainHandStack(); + ItemStack revenue = handItem.copy(); + if(rentTime % claim.rent.getRentAbleTime() != 0){ + source.sendFeedback(new LiteralText("You have to rent this claim for a time by a multiple of " + TimeUtil.convertSecondsToString(rentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); + return 0; + } + int rentAmount = rentTime / claim.rent.getRentAbleTime(); + if(currency.getItem() != handItem.getItem() || handItem.getCount() < claim.rent.getAmount() * rentAmount){ + source.sendFeedback(new LiteralText("You don't have enough " + currency.getName().asString()).formatted(Formatting.RED), true); + return 0; + } + if (!claim.rent.isRentable()) { + source.sendFeedback(new LiteralText(claim.name + " is not for rent").formatted(Formatting.RED), true); + return 0; + } + if (rentTime > claim.rent.getMaxrentAbleTime()) { + source.sendFeedback(new LiteralText("You can't rent this claim for longer than " + TimeUtil.convertSecondsToString(maxrentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); + return 0; + } + if(claim.rent.getTenant() == null){ + //Setup for claim rent + claim.rent.setTenant(source.getPlayer().getUuid()); + claim.rent.setRentedUntil(claim.rent.getUnixTime() + rentTime); + //Remove items from player + handItem.setCount(handItem.getCount() - claim.rent.getAmount() * rentAmount); + revenue.setCount(claim.rent.getAmount() * rentAmount); + claim.rent.addRevenue(revenue); + //Give Permissions to Tenant + claim.permissionManager.playerPermissions.put(source.getPlayer().getUuid(), new Claim.InvertedPermissionMap()); + source.sendFeedback(new LiteralText("Renting " + claim.name + " for " + claim.rent.getAmount() * rentAmount + " " + claim.rent.getCurrency().getName().asString() + " for " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); + return 1; + } else if(claim.rent.getTenant().toString().equalsIgnoreCase(source.getPlayer().getUuid().toString())){ + if (claim.rent.getRentTimeLeft() + rentTime <= maxrentAbleTime) { + //Setup for claim rent + claim.rent.setRentedUntil(claim.rent.getUnixTime() + rentTime + claim.rent.getRentTimeLeft()); + //Remove items from player + handItem.setCount(handItem.getCount() - claim.rent.getAmount() * rentAmount); + + revenue.setCount(claim.rent.getAmount() * rentAmount); + claim.rent.addRevenue(revenue); + //Give Permissions to Tenant + source.sendFeedback(new LiteralText("Extended rent " + claim.name + " by " + TimeUtil.convertSecondsToString(rentTime, '2', 'a') + "for " + claim.rent.getAmount() * rentAmount + " " + claim.rent.getCurrency().getName().asString()).formatted(Formatting.GREEN), true); + return 1; + } else { + source.sendFeedback(new LiteralText("Rent would exceed the limit by " + TimeUtil.convertSecondsToString(claim.rent.getRentTimeLeft() + rentTime - maxrentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); + return 0; + } + } else { + source.sendFeedback(new LiteralText("This claim is already rented").formatted(Formatting.RED), true); + return 0; + } + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java new file mode 100644 index 0000000..479404e --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java @@ -0,0 +1,81 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Config; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.TimeUtil; +import net.minecraft.command.arguments.ItemStackArgument; +import net.minecraft.command.arguments.ItemStackArgumentType; +import net.minecraft.item.ItemStack; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.string; +import static net.minecraft.server.command.CommandManager.literal; + +public class RentableCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder rentable = literal("rentable"); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + + RequiredArgumentBuilder currency = net.minecraft.server.command.CommandManager.argument("item", ItemStackArgumentType.itemStack()).suggests(ArgumentUtil::itemsSuggestion); + RequiredArgumentBuilder amount = net.minecraft.server.command.CommandManager.argument("count", IntegerArgumentType.integer(1)); + RequiredArgumentBuilder days = net.minecraft.server.command.CommandManager.argument("days", StringArgumentType.string() + ); + RequiredArgumentBuilder maxdays = CommandManager.argument("maxdays", string()); + maxdays.executes(context -> makeRentable(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false), IntegerArgumentType.getInteger(context, "count"), getString(context, "days"), getString(context, "maxdays"))); + claim.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if(claim1.rent.getCurrency() !=null || claim1.rent.getAmount() != 0 || claim1.rent.getRentAbleTime() != 0 || claim1.rent.getMaxrentAbleTime() != 0 && claim1.rent.isRentable()) { + context.getSource().sendFeedback(new LiteralText("Can't enable rent for " + claim1.name + ", because no values are set").formatted(Formatting.RED), true); + return 0; + } + if(claim1.rent.getTenant() == null){ + String state = claim1.rent.isRentable() ? "disabled" : "enabled"; + claim1.rent.setRentable(!claim1.rent.isRentable()); + context.getSource().sendFeedback(new LiteralText("Renting for " + claim1.name + " has been " + state).formatted(Formatting.GREEN), true); + return 1; + } else { + context.getSource().sendFeedback(new LiteralText("Can't disable rent for " + claim1.name + ", because it is currently being rented").formatted(Formatting.RED), true); + return 0; + } + }); + + days.then(maxdays); + amount.then(days); + currency.then(amount); + claim.then(currency); + rentable.then(claim); + command.then(rentable); + } + + private static int makeRentable(ServerCommandSource source, Claim claim, ItemStack item, int amount, String rentString, String maxrentString) throws CommandSyntaxException { + int rentTime = TimeUtil.convertStringtoSeconds(rentString); + int maxrentTime = TimeUtil.convertStringtoSeconds(maxrentString); + if(claim != null){ + if(rentTime <= maxrentTime){ + Claim.Rent rent = claim.rent; + rent.setRentable(true); + item.setCount(amount); + rent.setCurrency(item); + rent.setRentAbleTime(rentTime); + if(maxrentTime > Config.rent_maxseconds) maxrentTime = Config.rent_maxseconds; + rent.setMaxrentAbleTime(maxrentTime); + source.sendFeedback(new LiteralText("Claim " + claim.name + " can now be rented for " + amount + " " + item.getName().asString() + " every " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); + return 1; + } + } + return 0; + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java new file mode 100644 index 0000000..910be0c --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java @@ -0,0 +1,87 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.*; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; + +import java.util.HashMap; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class RevenueCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder revenue = literal("revenue"); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + RequiredArgumentBuilder claimRevenue = argument("claimRevenue", BoolArgumentType.bool()); + revenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); + claim.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); + claimRevenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); + claim.then(claimRevenue); + revenue.then(claim); + command.then(revenue); + } + + private static int revenue(ServerCommandSource source, Claim claim, boolean claimrevenue) throws CommandSyntaxException { + //Show subzones (so you can just claim everything in one place) maybe just all claims + if(claim == null){ + source.sendFeedback(Messages.INVALID_CLAIM,true); + return 0; + } + if(!claim.claimBlockOwner.toString().equalsIgnoreCase(source.getPlayer().getUuid().toString())){ + source.sendFeedback(Messages.NO_PERMISSION, true); + return 0; + } + + if(claimrevenue){ + for(ItemStack itemStack : claim.rent.getRevenue()){ + source.getPlayer().inventory.insertStack(itemStack); + } + claim.rent.clearRevenue(); + return 1; + + } else { + if(claim.rent.getRevenue().isEmpty()){ + source.sendFeedback(new LiteralText("No Revenue").formatted(Formatting.RED), true); + return 0; + } + Text text = new LiteralText("Revenue\n").formatted(Formatting.AQUA); + HashMap hashMap = new HashMap<>(); + for(ItemStack itemStack : claim.rent.getRevenue()){ + Item value = itemStack.getItem(); + if(hashMap.containsKey(value)){ + hashMap.put(value, hashMap.get(value) + itemStack.getCount()); + } else { + hashMap.put(value, + itemStack.getCount()); + } + + hashMap.forEach((item, integer) -> { + boolean color = true; + text.append(new LiteralText(String.valueOf(integer)).append(" ").append(new TranslatableText(item.getTranslationKey())).append(" ").formatted(color ? Formatting.GOLD : Formatting.YELLOW)).styled(style -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to claim revenue!").formatted(Formatting.GREEN))); + style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim revenue " + claim.name + " true")); + }); + color = !color; + }); + + } + text.append("\n"); + source.sendFeedback(text, true); + return 1; + } + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java new file mode 100644 index 0000000..acdaf05 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java @@ -0,0 +1,53 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import net.minecraft.server.command.ServerCommandSource; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.SETTINGS_PROVIDER; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.executeSetting; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.querySettings; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class SettingsCommand { + + public static void register(LiteralArgumentBuilder command, boolean admin) { + LiteralArgumentBuilder settings = literal("settings"); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + + if (!admin) { + settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); + + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return querySettings(context.getSource(), claim1); + }); + } + + RequiredArgumentBuilder id = argument("setting", word()).suggests(SETTINGS_PROVIDER); + RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); + + id.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), getString(context, "claim"), true, false, admin)); + set.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); + + id.then(set); + claim.then(id); + settings.then(claim); + command.then(settings); + } + + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java new file mode 100644 index 0000000..63df117 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java @@ -0,0 +1,54 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ClaimShower; +import io.github.indicode.fabric.itsmine.Config; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.util.ShowerUtil.silentHideShow; +import static net.minecraft.server.command.CommandManager.literal; + +public class ShowCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder show = literal("show"); + show.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().dimension.getType()), false)); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + claim.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "name")), false)); + show.then(claim); + command.then(show); + + LiteralArgumentBuilder hide = literal("hide"); + hide.executes(context -> executeShowClaim(context.getSource(), null, true)); + command.then(hide); + } + + public static int executeShowClaim(ServerCommandSource source, Claim claim, boolean reset) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!Config.claims2d &&((ClaimShower)player).getShownClaim() != claim)) executeShowClaim(source, ((ClaimShower)player).getShownClaim(), true); + if (reset && ((ClaimShower)player).getShownClaim() != null) claim = ((ClaimShower)player).getShownClaim(); + if (claim != null) { + if (!claim.dimension.equals(source.getWorld().getDimension().getType())) { + if (claim == ((ClaimShower)player).getShownClaim()) ((ClaimShower)player).setShownClaim(null); // just so we dont have extra packets on this + source.sendFeedback(new LiteralText("That claim is not in this dimension").formatted(Formatting.RED), false); + return 0; + } + source.sendFeedback(new LiteralText((!reset ? "Showing" : "Hiding") + " claim: " + claim.name).formatted(Formatting.GREEN), false); + if(claim.isChild) silentHideShow(player, ClaimUtil.getParentClaim(claim), reset, true); + else silentHideShow(player, claim, reset, true); + + } else { + source.sendFeedback(new LiteralText("That is not a valid claim").formatted(Formatting.RED), false); + } + return 0; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/StickCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/StickCommand.java new file mode 100644 index 0000000..46d1e27 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/StickCommand.java @@ -0,0 +1,30 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import io.github.indicode.fabric.itsmine.ClaimManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; +import net.minecraft.util.Pair; +import net.minecraft.util.math.BlockPos; + +import static net.minecraft.server.command.CommandManager.literal; + +public class StickCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder stick = literal("stick"); + stick.executes(context -> { + Pair posPair = ClaimManager.INSTANCE.stickPositions.get(context.getSource().getPlayer()); + context.getSource().sendFeedback(new LiteralText(posPair == null ? "You can now use a stick to create claims. Run this command again to disable" : "Claim stick disabled. Run this command again to enable").formatted(Formatting.DARK_PURPLE), false); + if (posPair == null) { + ClaimManager.INSTANCE.stickPositions.put(context.getSource().getPlayer(), new Pair<>(null, null)); + } else { + ClaimManager.INSTANCE.stickPositions.remove(context.getSource().getPlayer()); + } + return 0; + }); + command.then(stick); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java new file mode 100644 index 0000000..f6d9e07 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java @@ -0,0 +1,147 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.command.EntitySelector; +import net.minecraft.command.arguments.EntityArgumentType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class TransferCommand { + public static void register(LiteralArgumentBuilder command) { + + LiteralArgumentBuilder transfer = literal("transfer"); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); + LiteralArgumentBuilder confirm = literal("confirm"); + confirm.executes(context -> { + final String string = "-accept-"; + ServerPlayerEntity p = EntityArgumentType.getPlayer(context, "player"); + String input = getString(context, "claim"); + String claimName = input.replace(string, ""); + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(claimName); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + if (input.startsWith(string)) { + return acceptTransfer(context.getSource()); + } + return transfer(context.getSource(), claim1, p, false); + }); + player.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), EntityArgumentType.getPlayer(context, "player"), false)); + player.then(confirm); + claim.then(player); + transfer.then(claim); + transfer.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), EntityArgumentType.getPlayer(context, "player"), false)); + command.then(transfer); + } + + public static int acceptTransfer(ServerCommandSource sender) throws CommandSyntaxException { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(pendingClaimTransfers.get(sender.getPlayer().getGameProfile().getId())); + if (claim == null) { + sender.sendFeedback(new LiteralText("You have no pending claim transfers").formatted(Formatting.RED), false); + return 0; + } + if (sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner) != null) { + sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); + } + Claim.ClaimPermissionMap op = claim.permissionManager.playerPermissions.get(claim.claimBlockOwner); + claim.permissionManager.playerPermissions.put(claim.claimBlockOwner, claim.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); + claim.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op); + claim.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); + claim.children.forEach(subzone -> { + try { + Claim.ClaimPermissionMap op1 = subzone.permissionManager.playerPermissions.get(subzone.claimBlockOwner); + subzone.permissionManager.playerPermissions.put(subzone.claimBlockOwner, subzone.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); + subzone.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op1); + subzone.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); + } catch (CommandSyntaxException e) { + e.printStackTrace(); + } + }); + return 0; + } + + private static int requestTransfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { + if (claim == null) { + sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if(claim.isChild){ + sender.sendFeedback(new LiteralText("You can't transfer ownership of subzones").formatted(Formatting.RED), false); + return 0; + } + if(sender.getPlayer().getUuidAsString().equalsIgnoreCase(player.getUuidAsString())){ + sender.sendFeedback(new LiteralText("Huh? That makes no sence").formatted(Formatting.RED), true); + return 0; + } + if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { + if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { + sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + } else { + sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); + return 0; + } + } + sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to transfer ownership of \"" + claim.name + "\" to " + player.getGameProfile().getName() + "? ").formatted(Formatting.GOLD)) + .append(new LiteralText("[YES]").setStyle(new Style() + .setColor(Formatting.DARK_RED) + .setBold(true) + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")))), false); + return 0; + } + private static Map pendingClaimTransfers = new HashMap<>(); + private static int transfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { + if (claim == null) { + sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if (claim.isChild) { + sender.sendFeedback(new LiteralText("You can't transfer ownership of subzones").formatted(Formatting.RED), false); + return 0; + } + if (sender.getPlayer().getUuidAsString().equalsIgnoreCase(player.getUuidAsString())) { + sender.sendFeedback(new LiteralText("Huh? That makes no sence").formatted(Formatting.RED), true); + return 0; + } + if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { + if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { + sender.sendFeedback(new LiteralText("Transfering ownership of a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + } else { + sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); + return 0; + } + } + GameProfile profile = sender.getWorld().getServer().getUserCache().getByUuid(claim.claimBlockOwner); + sender.sendFeedback(new LiteralText("Transferring ownership of the claim \"" + claim.name + "\" to " + player.getGameProfile().getName() + " if they accept").formatted(Formatting.GREEN), claim.claimBlockOwner != player.getGameProfile().getId()); + player.sendMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) + .append(new LiteralText("[ACCEPT]").setStyle(new Style() + .setColor(Formatting.GREEN) + .setBold(true) + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim transfer -accept-" + claim.name + " " + player.getEntityName() + " confirm"))))); + pendingClaimTransfers.put(player.getGameProfile().getId(), claim.name); + return 0; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java new file mode 100644 index 0000000..826a439 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java @@ -0,0 +1,85 @@ +package io.github.indicode.fabric.itsmine.command; + +import blue.endless.jankson.annotation.Nullable; +import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import net.minecraft.command.arguments.GameProfileArgumentType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import java.util.Collection; +import java.util.concurrent.atomic.AtomicInteger; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.validateClaim; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.verifyPermission; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class TrustCommand { + public static void register(LiteralArgumentBuilder command) { + { + LiteralArgumentBuilder trust = literal("trust"); + RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, null))); + claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, getString(context, "claim")))); + + playerArgument.then(claimArgument); + trust.then(playerArgument); + command.then(trust); + } + { + LiteralArgumentBuilder distrust = literal("distrust"); + RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + + playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, null))); + claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, getString(context, "claim")))); + + playerArgument.then(claimArgument); + distrust.then(playerArgument); + command.then(distrust); + } + } + private static int executeTrust(CommandContext context, Collection targetCollection, boolean set, @Nullable String claimName) throws CommandSyntaxException { + AtomicInteger integer = new AtomicInteger(); + + if(targetCollection.isEmpty()){ + context.getSource().sendFeedback(new LiteralText("No player provided").formatted(Formatting.RED), true); + return 0; + } + ServerPlayerEntity p = context.getSource().getPlayer(); + Claim claim = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getBlockPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); + validateClaim(claim); + targetCollection.iterator().forEachRemaining(gameProfile -> { + try { + //This is supposed to check if the player has played before :shrug: + if(context.getSource().getMinecraftServer().getUserCache().getByUuid(gameProfile.getId()) == gameProfile){ + integer.set(setTrust(context, claim, gameProfile, set, false)); + } else { + context.getSource().sendFeedback(new LiteralText("Unknown player!").formatted(Formatting.RED), true); + integer.set(0); + } + } catch (CommandSyntaxException e) { + e.printStackTrace(); + } + }); + return integer.get(); + } + static int setTrust(CommandContext context, Claim claim, GameProfile target, boolean set, boolean admin) throws CommandSyntaxException { + if (verifyPermission(claim, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + claim.permissionManager.playerPermissions.put(target.getId(), set ? new Claim.InvertedPermissionMap() : new Claim.DefaultPermissionMap()); + context.getSource().sendFeedback(new LiteralText(target.getName() + (set ? " now" : " no longer") + " has all the permissions").formatted(Formatting.YELLOW), false); + } + return 1; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java new file mode 100644 index 0000000..092aa45 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java @@ -0,0 +1,124 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.HoverEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +import java.util.concurrent.atomic.AtomicInteger; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static net.minecraft.server.command.CommandManager.literal; + +public class TrustedCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder trusted = literal("trusted"); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + trusted.executes((context)-> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim, false); + }); + + claimArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim, false); + }); + trusted.then(claimArgument); + command.then(trusted); + } + + static int showTrustedList(CommandContext context, Claim claim, boolean showSelf) throws CommandSyntaxException { + ServerCommandSource source = context.getSource(); + ServerPlayerEntity player = source.getPlayer(); + int mapSize = claim.permissionManager.playerPermissions.size(); + + if (mapSize == 1 && !showSelf) { + source.sendError(new LiteralText(claim.name + " is not trusting anyone!")); + return -1; + } + + Text text = new LiteralText("\n"); + text.append(new LiteralText("Trusted players for Claim ").formatted(Formatting.YELLOW)) + .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append("\n"); + + AtomicInteger atomicInteger = new AtomicInteger(); + claim.permissionManager.playerPermissions.forEach((uuid, perm) -> { + atomicInteger.incrementAndGet(); + Text pText = new LiteralText(""); + Text owner; + GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); + if (profile != null) { + owner = new LiteralText(profile.getName()); + } else { + owner = new LiteralText(uuid.toString()).styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to Copy"))); + style.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); + }); + } + + pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) + .append(owner.formatted(Formatting.YELLOW)); + + Text hover = new LiteralText(""); + hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); + + int allowed = 0; + int i = 0; + boolean nextColor = false; + Text perms = new LiteralText(""); + + for (Claim.Permission value : Claim.Permission.values()) { + if (claim.permissionManager.hasPermission(uuid, value)) { + Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; + perms.append(new LiteralText(value.id).formatted(formatting)).append(" "); + if (i == 3) perms.append("\n"); + allowed++; + i++; + nextColor = !nextColor; + } + } + + if (allowed == Claim.Permission.values().length) { + hover.append(new LiteralText("All " + allowed + " Permissions").formatted(Formatting.YELLOW, Formatting.ITALIC)); + } else { + hover.append(perms); + } + + pText.append(new LiteralText(" ") + .append(new LiteralText("(").formatted(Formatting.GOLD)) + .append(new LiteralText(String.valueOf(allowed)).formatted(Formatting.GREEN)) + .append(new LiteralText("/").formatted(Formatting.GOLD)) + .append(new LiteralText(String.valueOf(Claim.Permission.values().length)).formatted(Formatting.YELLOW)) + .append(new LiteralText(")").formatted(Formatting.GOLD)) + ); + + pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); + text.append(pText).append("\n"); + }); + + source.sendFeedback(text, false); + return 1; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java new file mode 100644 index 0000000..4d4df91 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java @@ -0,0 +1,48 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.command.ExceptionCommand; +import io.github.indicode.fabric.itsmine.command.PermissionsCommand; +import io.github.indicode.fabric.itsmine.command.SettingsCommand; +import net.minecraft.server.command.ServerCommandSource; + +import java.util.function.Predicate; + +import static net.minecraft.server.command.CommandManager.literal; + +public class AdminCommand { + + public static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { + LiteralArgumentBuilder admin = literal("admin"); + admin.requires(PERMISSION_CHECK_ADMIN); + registerAdmin(admin, dispatcher); + command.then(admin); + } + + private static void registerAdmin(LiteralArgumentBuilder admin, CommandDispatcher dispatcher) { + BlocksCommand.register(admin); + ClaimsCommand.register(admin, dispatcher); + CreateCommand.register(admin); + EntitiesCommand.register(admin); + ExceptionCommand.register(admin, true, false); + ExpandCommand.register(admin); + IgnoreCommand.register(admin); + ListAllCommand.register(admin); + OwnerCommand.register(admin); + PermissionsCommand.register(admin, true); + RemoveCommand.register(admin); + RenameCommand.register(admin); + SettingsCommand.register(admin, true); + } + + private static Predicate perm(String str) { + return perm(str, 2); + } + private static Predicate perm(String str, int op) { + return source -> ItsMine.permissions().hasPermission(source, "itsmine." + str, op); + } + public static final Predicate PERMISSION_CHECK_ADMIN = src -> perm("admin").test(src); + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/BlocksCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/BlocksCommand.java new file mode 100644 index 0000000..473431a --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/BlocksCommand.java @@ -0,0 +1,65 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.command.EntitySelector; +import net.minecraft.command.arguments.EntityArgumentType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class BlocksCommand { + + public static void register(LiteralArgumentBuilder command) { + { + LiteralArgumentBuilder add = literal("addBlocks"); + add.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); + RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); + amount.executes(context -> { + ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); + context.getSource().sendFeedback(new LiteralText("Gave " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); + return 0; + }); + player.then(amount); + add.then(player); + command.then(add); + } + { + LiteralArgumentBuilder remove = literal("removeBlocks"); + remove.requires(source ->ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); + RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); + amount.executes(context -> { + ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), -IntegerArgumentType.getInteger(context, "amount")); + context.getSource().sendFeedback(new LiteralText("Took " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); + return 0; + }); + player.then(amount); + remove.then(player); + command.then(remove); + } + { + LiteralArgumentBuilder set = literal("setBlocks"); + set.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); + RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); + amount.executes(context -> { + ClaimManager.INSTANCE.setClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); + context.getSource().sendFeedback(new LiteralText("Set claim block amount to " + IntegerArgumentType.getInteger(context, "amount")).formatted(Formatting.GREEN), true); + return 0; + }); + player.then(amount); + set.then(player); + command.then(set); + } + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java new file mode 100644 index 0000000..69de7bf --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java @@ -0,0 +1,70 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.HoverEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +import java.util.List; + +import static net.minecraft.server.command.CommandManager.literal; + +public class ClaimsCommand { + public static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { + LiteralArgumentBuilder claims = literal("claims"); + claims.executes(context -> list(context.getSource(), context.getSource().getName())); + dispatcher.register(claims); + } + + public static int list(ServerCommandSource source, String target) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + GameProfile profile = target == null ? player.getGameProfile() : source.getMinecraftServer().getUserCache().findByName(target); + + if (profile == null) { + source.sendError(Messages.INVALID_PLAYER); + return -1; + } + + List claims = ClaimManager.INSTANCE.getPlayerClaims(profile.getId()); + if (claims.isEmpty()) { + source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); + return -1; + } + + + Text text = new LiteralText("\n").append(new LiteralText("Claims (" + target + "): ").formatted(Formatting.GOLD)).append("\n "); + boolean nextColor = false; + for (Claim claim : claims) { + if(!claim.isChild) { + Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { + Text hoverText = new LiteralText("Click for more Info").formatted(Formatting.GREEN); + if (claim.children.size() > 0) { + hoverText.append("\n\nSubzones:"); + for (Claim subzone : claim.children) { + hoverText.append("\n- " + subzone.name); + } + } + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); + + style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); + }); + + nextColor = !nextColor; + text.append(cText.append(" ")); + } + } + + source.sendFeedback(text.append("\n"), false); + return 1; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/CreateCommand.java new file mode 100644 index 0000000..f7ed03c --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/CreateCommand.java @@ -0,0 +1,81 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.command.arguments.BlockPosArgumentType; +import net.minecraft.command.arguments.PosArgument; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; +import net.minecraft.util.Pair; +import net.minecraft.util.math.BlockPos; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static io.github.indicode.fabric.itsmine.command.CreateCommand.createClaim; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class CreateCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder create = literal("create"); + create.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2)); + ArgumentBuilder name = argument("name", word()); + ArgumentBuilder customOwner = argument("customOwnerName", word()); + ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); + RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); + max.executes(context -> createClaim( + getString(context, "name"), + context.getSource(), + BlockPosArgumentType.getBlockPos(context, "min"), + BlockPosArgumentType.getBlockPos(context, "max"), + true, + null + )); + name.executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); + if (selectedPositions == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getLeft() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getRight() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); + } else { + String cname = getString(context, "name"); + if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, null) > 0) { + ClaimManager.INSTANCE.stickPositions.remove(player); + } + } + return 0; + }); + customOwner.executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); + if (selectedPositions == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getLeft() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getRight() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); + } else { + String cname = getString(context, "name"); + if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, getString(context, "customOwnerName")) > 0) { + ClaimManager.INSTANCE.stickPositions.remove(player); + } + } + return 0; + }); + min.then(max); + name.then(customOwner); + name.then(min); + create.then(name); + command.then(create); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java new file mode 100644 index 0000000..5810829 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java @@ -0,0 +1,42 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static net.minecraft.server.command.CommandManager.literal; + +public class EntitiesCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder entity = literal("entities"); + entity.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + entity.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); + context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); + claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { + context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); + }); + return 1; + }); + claim.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); + claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { + context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); + }); + return 1; + }); + entity.then(claim); + command.then(entity); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java new file mode 100644 index 0000000..86e7b90 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java @@ -0,0 +1,76 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.util.math.Direction; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.command.ExpandCommand.expand; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getDirections; +import static io.github.indicode.fabric.itsmine.util.DirectionUtil.directionByName; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class ExpandCommand { + + public static void register(LiteralArgumentBuilder command) { + { + LiteralArgumentBuilder expand = literal("expand"); + expand.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = getDirections(); + + direction.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + IntegerArgumentType.getInteger(context, "distance"), + directionByName(getString(context, "direction")), + context.getSource(), + true + )); + + amount.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + IntegerArgumentType.getInteger(context, "distance"), + Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], + context.getSource(), + true + )); + + amount.then(direction); + expand.then(amount); + command.then(expand); + } + { + LiteralArgumentBuilder shrink = literal("shrink"); + shrink.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = getDirections(); + + direction.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + -IntegerArgumentType.getInteger(context, "distance"), + directionByName(getString(context, "direction")), + context.getSource(), + true + )); + + amount.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + -IntegerArgumentType.getInteger(context, "distance"), + Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], + context.getSource(), + true + )); + + amount.then(direction); + shrink.then(amount); + command.then(shrink); + } + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/IgnoreCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/IgnoreCommand.java new file mode 100644 index 0000000..5c11385 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/IgnoreCommand.java @@ -0,0 +1,30 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import java.util.UUID; + +import static net.minecraft.server.command.CommandManager.literal; + +public class IgnoreCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder ignore = literal("ignoreClaims"); + ignore.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_IGNORE_CLAIMS, 2)); + ignore.executes(context -> { + UUID id = context.getSource().getPlayer().getGameProfile().getId(); + boolean isIgnoring = ClaimManager.INSTANCE.ignoringClaims.contains(id); + if (isIgnoring) ClaimManager.INSTANCE.ignoringClaims.remove(id); + else ClaimManager.INSTANCE.ignoringClaims.add(id); + context.getSource().sendFeedback(new LiteralText("You are " + (isIgnoring ? "no longer" : "now") + " ignoring claims.").formatted(Formatting.GREEN), false); + return 0; + }); + command.then(ignore); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java new file mode 100644 index 0000000..fd94c46 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java @@ -0,0 +1,37 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.Claim; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +import java.util.List; + +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getPlayers; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.getClaims; +import static net.minecraft.server.command.CommandManager.literal; + +public class ListAllCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder listall = literal("listall"); + RequiredArgumentBuilder player = getPlayers(); + listall.executes(context -> listall(context.getSource())); + command.then(listall); + } + private static int listall(ServerCommandSource source){ + List claims = getClaims(); + Text text = new LiteralText("\n").append(new LiteralText("Claims").formatted(Formatting.GOLD)).append("\n "); + for (Claim claim : claims) { + Text cText = new LiteralText(claim.name).formatted(Formatting.GOLD); + text.append(cText.append(" ")); + } + source.sendFeedback(text.append("\n"), false); + return 1; + } + + + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java new file mode 100644 index 0000000..3d99a42 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java @@ -0,0 +1,114 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import net.minecraft.command.arguments.GameProfileArgumentType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import java.util.Collection; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class OwnerCommand { + public static void register(LiteralArgumentBuilder command) { + { + LiteralArgumentBuilder set = literal("setOwner"); + RequiredArgumentBuilder newOwner = argument("newOwner", GameProfileArgumentType.gameProfile()); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + + newOwner.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + + Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); + + if (profiles.size() > 1) { + context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); + return -1; + } + return setOwner(context.getSource(), claim, profiles.iterator().next()); + }); + + claimArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + + Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); + + if (profiles.size() > 1) { + context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); + return -1; + } + return setOwner(context.getSource(), claim, profiles.iterator().next()); + }); + + newOwner.then(claimArgument); + set.then(newOwner); + command.then(set); + } + + { + LiteralArgumentBuilder set = literal("setOwnerName"); + RequiredArgumentBuilder nameArgument = argument("newName", word()); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + + nameArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); + if (claim == null) { + context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return -1; + } + return setOwnerName(context.getSource(), claim, getString(context, "newName")); + }); + + claimArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim == null) { + context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return -1; + } + return setOwnerName(context.getSource(), claim, getString(context, "newName")); + }); + + nameArgument.then(claimArgument); + set.then(nameArgument); + command.then(set); + } + } + private static int setOwnerName(ServerCommandSource source, Claim claim, String input) { + String name = input.equals("reset") ? null : input; + source.sendFeedback(new LiteralText("Set the Custom Owner Name to ") + .formatted(Formatting.YELLOW).append(new LiteralText(name == null ? "Reset" : name).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) + .append(new LiteralText(claim.customOwnerName == null ? "Not Present" : claim.customOwnerName).formatted(Formatting.GOLD)) + .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) + , false); + claim.customOwnerName = input; + return 1; + } + private static int setOwner(ServerCommandSource source, Claim claim, GameProfile profile) { + GameProfile oldOwner = source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); + source.sendFeedback(new LiteralText("Set the Claim Owner to ") + .formatted(Formatting.YELLOW).append(new LiteralText(profile.getName()).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) + .append(new LiteralText(oldOwner == null ? "(" + claim.claimBlockOwner + ")" : oldOwner.getName()).formatted(Formatting.GOLD)) + .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) + , false); + claim.claimBlockOwner = profile.getId(); + return 1; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java new file mode 100644 index 0000000..5b2f809 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java @@ -0,0 +1,31 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.util.math.BlockPos; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.command.RemoveCommand.delete; +import static io.github.indicode.fabric.itsmine.command.RemoveCommand.requestDelete; +import static net.minecraft.server.command.CommandManager.literal; + +public class RemoveCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder delete = literal("remove"); + delete.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + LiteralArgumentBuilder confirm = literal("confirm"); + confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); + claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); + claim.then(confirm); + delete.then(claim); + delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), true)); + command.then(delete); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RenameCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RenameCommand.java new file mode 100644 index 0000000..1798fcb --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RenameCommand.java @@ -0,0 +1,23 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import net.minecraft.server.command.ServerCommandSource; + +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static io.github.indicode.fabric.itsmine.command.RenameCommand.rename; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class RenameCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder rename = literal("rename"); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + RequiredArgumentBuilder nameArgument = argument("name", word()); + nameArgument.executes((context) -> rename(context, true)); + claimArgument.then(nameArgument); + rename.then(claimArgument); + command.then(rename); + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java similarity index 72% rename from src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java rename to src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java index 402a428..7083946 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java @@ -1,56 +1,68 @@ -package io.github.indicode.fabric.itsmine; +package io.github.indicode.fabric.itsmine.command.subzone; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Config; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; -import net.minecraft.text.Style; import net.minecraft.util.Formatting; import net.minecraft.util.Pair; import net.minecraft.util.math.BlockPos; import org.jetbrains.annotations.Nullable; -import java.text.Format; import java.util.UUID; -public class SubzoneCommand { - private static final String SUB_ZONE_NAME_FORMAT = "%s.%s"; +import static io.github.indicode.fabric.itsmine.command.ShowCommand.executeShowClaim; - public static void register(LiteralArgumentBuilder command, boolean admin) { - LiteralArgumentBuilder builder = CommandManager.literal("subzone"); +public class CreateCommand { + + public static void register(LiteralArgumentBuilder command) { { - LiteralArgumentBuilder add = CommandManager.literal("add"); + LiteralArgumentBuilder create = CommandManager.literal("create"); RequiredArgumentBuilder name = CommandManager.argument("name", StringArgumentType.word()) - .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), null, admin)); + .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), null, false)); - RequiredArgumentBuilder claim = CommandManager.argument("claim", StringArgumentType.word()) - .suggests(ClaimCommand.CLAIM_PROVIDER) - .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), StringArgumentType.getString(ctx, "claim"), admin)); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims() + .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), StringArgumentType.getString(ctx, "claim"), false)); name.then(claim); - add.then(name); - builder.then(add); + create.then(name); + command.then(create); } - - command.then(builder); } private static int addZone(ServerCommandSource source, String name, @Nullable String claimName, boolean admin) throws CommandSyntaxException { - if (name.length() > ClaimCommand.MAX_NAME_LENGTH) { + if (name.length() > 30) { source.sendError(Messages.MSG_LONG_NAME); return -1; } ServerPlayerEntity player = source.getPlayer(); - Claim claim = validateAndGet(source, claimName); + Claim claim = validateAndGet(source, claimName, admin); Claim subZone = null; + if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SUBZONE)) { + throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); + } + if(!name.matches("[A-Za-z0-9]+")){ + source.sendError(new LiteralText("Invalid claim name")); + return -1; + } + + if (ClaimManager.INSTANCE.claimsByName.containsKey(name)) { + source.sendFeedback(new LiteralText("The name \"" + name + "\" is already taken.").formatted(Formatting.RED), false); + return -1; + } Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); if (selectedPositions == null) { source.sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); @@ -59,14 +71,14 @@ private static int addZone(ServerCommandSource source, String name, @Nullable St } else if (selectedPositions.getRight() == null) { source.sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); } else { - name = claim.name + "." + name; - subZone = createSubzone(source, name, selectedPositions.getLeft(), selectedPositions.getRight(), admin); + name = claim.name + "." + name; + subZone = createSubzone(source, name, selectedPositions.getLeft(), selectedPositions.getRight(), admin); if (subZone.dimension == claim.dimension && claim.includesPosition(subZone.min) && claim.includesPosition(subZone.max) && !claim.isChild){ if (!ClaimManager.INSTANCE.wouldSubzoneIntersect((subZone))){ claim.addSubzone(subZone); ClaimManager.INSTANCE.addClaim(subZone); subZone.permissionManager = claim.permissionManager; -// subZone.permissionManager.playerPermissions.put(subZone.claimBlockOwner, new Claim.InvertedPermissionMap()); + executeShowClaim(source, claim, false); source.sendFeedback(new LiteralText("").append(new LiteralText("Your subzone was created.").formatted(Formatting.GREEN)), false); }else{ player.sendMessage(new LiteralText("Your subzone would overlap with another subzone").formatted(Formatting.RED)); @@ -80,7 +92,6 @@ private static int addZone(ServerCommandSource source, String name, @Nullable St player.sendMessage(new LiteralText("Subzone must be inside the original claim, in the same dimension").formatted(Formatting.RED)); } } - return 0; } @@ -117,7 +128,7 @@ private static Claim createSubzone(ServerCommandSource source, String name, Bloc return new Claim(name, admin ? null : ownerID, min, max, source.getWorld().getDimension().getType(), source.getPlayer().getBlockPos(), true); } - private static Claim validateAndGet(ServerCommandSource source, @Nullable String claimName) throws CommandSyntaxException { + private static Claim validateAndGet(ServerCommandSource source, @Nullable String claimName, boolean admin) throws CommandSyntaxException { ServerPlayerEntity player = source.getPlayer(); Claim claim = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); @@ -125,8 +136,10 @@ private static Claim validateAndGet(ServerCommandSource source, @Nullable String if (claim == null) { throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); } + if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SUBZONE)) { + throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); + } return claim; } - } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java new file mode 100644 index 0000000..7d5c8a5 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java @@ -0,0 +1,34 @@ +package io.github.indicode.fabric.itsmine.command.subzone; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import io.github.indicode.fabric.itsmine.command.*; +import net.minecraft.server.command.ServerCommandSource; + +import static net.minecraft.server.command.CommandManager.literal; + +public class SubzoneCommand { + public static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { + LiteralArgumentBuilder subzone = literal("subzone"); + registerSubzone(subzone, dispatcher); + command.then(subzone); + } + + public static void registerSubzone(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { + CreateCommand.register(command); + ExceptionCommand.register(command, false, true); + ExpandCommand.register(command); + InfoCommand.register(command); + PermissionsCommand.register(command, false); + RemoveCommand.register(command); + RenameCommand.register(command); + RentableCommand.register(command); + RentCommand.register(command); + RevenueCommand.register(command); + SettingsCommand.register(command, false); + ShowCommand.register(command); +// SubzoneCommand.register(command, dispatcher); + TrustCommand.register(command); + TrustedCommand.register(command); + } +} \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java new file mode 100644 index 0000000..8c3330a --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java @@ -0,0 +1,49 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import blue.endless.jankson.annotation.Nullable; +import com.mojang.authlib.GameProfile; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; +import net.minecraft.entity.passive.AnimalEntity; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.UUID; + +@Mixin(AnimalEntity.class) +public abstract class AnimalEntityMixin { + + @Shadow private UUID lovingPlayer; + + @Shadow @Nullable + public abstract ServerPlayerEntity getLovingPlayer(); + + @Shadow public abstract void setLoveTicks(int loveTicks); + + @Shadow public abstract void resetLoveTicks(); + + @Inject(method = "canBreedWith", at = @At(value = "HEAD"), cancellable = true) + private void canBreed(AnimalEntity other, CallbackInfoReturnable cir){ + Claim claim = ClaimManager.INSTANCE.getClaimAt(other.getBlockPos(), other.dimension); + if(claim != null){ + if(claim.isChild){ + claim = ClaimUtil.getParentClaim(claim); + } + if(claim.getEntities(other.getEntityWorld().getServer().getWorld(other.getEntityWorld().getDimension().getType())) > 50){ + ServerPlayerEntity player = this.getLovingPlayer(); + if(player != null){ + player.sendMessage(new LiteralText("You reached the entity limit in your claim!").formatted(Formatting.RED)); + } + this.resetLoveTicks(); + cir.setReturnValue(false); + } + } + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java index 3123e47..4829903 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java @@ -1,9 +1,7 @@ package io.github.indicode.fabric.itsmine.mixin; import com.mojang.brigadier.CommandDispatcher; -import io.github.indicode.fabric.itsmine.ClaimCommand; -import io.github.indicode.fabric.itsmine.SubzoneCommand; -import net.minecraft.server.command.CommandManager; +import io.github.indicode.fabric.itsmine.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -14,12 +12,12 @@ /** * @author Indigo Amann */ -@Mixin(CommandManager.class) +@Mixin(net.minecraft.server.command.CommandManager.class) public class CommandManagerMixin { @Shadow private CommandDispatcher dispatcher; @Inject(method = "", at = @At("RETURN")) public void addCommand(boolean bool, CallbackInfo ci) { - ClaimCommand.register(dispatcher); + CommandManager.register(dispatcher); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index ddb55fa..9f5d8ec 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -1,6 +1,7 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.packet.s2c.play.PlaySoundIdS2CPacket; @@ -107,7 +108,7 @@ public void doTickActions(CallbackInfo ci) { World world = player.getEntityWorld(); if (world.getBlockState(player.getBlockPos().down(5)).isAir() && !player.isOnGround()) { - BlockPos pos = Functions.getPosOnGround(player.getBlockPos(), world); + BlockPos pos = ClaimUtil.getPosOnGround(player.getBlockPos(), world); player.teleport(pos.getX(), pos.getY(), pos.getZ()); } } else if ( diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java index efb706b..c6d7d2c 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java @@ -24,9 +24,9 @@ @Mixin(IntegratedServer.class) public class IntegratedServerMixin { @Inject(method = "loadWorld", at = @At("RETURN")) - private void loadClaims(String name, String serverName, long seed, LevelGeneratorOptions arg, CallbackInfo ci) { - File claims = new File(((MinecraftServer)(Object)this).getLevelStorage().getSavesDirectory() + "/" + name + "/claims.dat"); - File claims_old = new File(((MinecraftServer)(Object)this).getLevelStorage().getSavesDirectory() + "/" + name + "/claims.dat_old"); + private void loadClaims(java.lang.String name, long l, LevelGeneratorOptions levelGeneratorOptions, CallbackInfo ci) { + File claims = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat"); + File claims_old = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat_old"); ClaimManager.INSTANCE = new ClaimManager(); if (!claims.exists()) { if (claims_old.exists()) {} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java index 98db24b..b1fa8e0 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java @@ -3,22 +3,26 @@ import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.screen.LecternScreenHandler; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(LecternScreenHandler.class) public abstract class LecternScreenHandlerMixin { - @Redirect(method = "onButtonClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/LecternScreenHandler;onButtonClick(Lnet/minecraft/entity/player/PlayerEntity;I)Z")) - private boolean canTake(LecternScreenHandler lecternScreenHandler, PlayerEntity player, int id) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); - if (claim != null && !claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_LECTERN)) { - player.sendMessage(Messages.MSG_CANT_DO); - return false; - } - return true; - - } + @Inject(method = "onButtonClick", at = @At(value = "HEAD"), cancellable = true) + private void canTake(PlayerEntity player, int id, CallbackInfoReturnable cir){ + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + if(claim != null){ + if(claim.isChild) claim = ClaimUtil.getParentClaim(claim); + if(!claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_LECTERN)){ + player.sendMessage(Messages.MSG_CANT_DO); + cir.setReturnValue(false); + } + } + } } \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java index c617e4f..fc1bfa5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java @@ -26,10 +26,10 @@ @Mixin(MinecraftServer.class) public abstract class MinecraftServerMixin { @Inject(method = "loadWorld", at = @At("RETURN")) - private void loadClaims(String name, String serverName, long seed, LevelGeneratorOptions arg, CallbackInfo ci) { + private void loadClaims(String name, long l, LevelGeneratorOptions levelGeneratorOptions, CallbackInfo ci) { ClaimManager.INSTANCE = new ClaimManager(); - File claims = new File(gameDir.getPath() + "/" + name + "/claims.dat"); - File claims_old = new File(gameDir.getPath() + "/" + name + "/claims.dat_old"); + File claims = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat"); + File claims_old = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat_old"); if (!claims.exists()) { if (claims_old.exists()) {} else return; @@ -51,7 +51,4 @@ private void loadClaims(String name, String serverName, long seed, LevelGenerato } } - @Final - @Shadow - private File gameDir; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java new file mode 100644 index 0000000..02bb931 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java @@ -0,0 +1,13 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import net.minecraft.entity.projectile.ProjectileEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.UUID; + +@Mixin(ProjectileEntity.class) +public interface OwnedProjectile { + @Accessor("ownerUuid") + UUID getOwner(); +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java index 6f54ede..40736c5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java @@ -1,17 +1,14 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.util.EntityUtil; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityCategory; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.screen.PlayerScreenHandler; -import net.minecraft.text.LiteralText; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.GameRules; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -52,12 +49,14 @@ public void hittingIsRude(Entity entity, CallbackInfo ci) { PlayerEntity playerEntity_1 = (PlayerEntity)(Object)this; Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); - if (claim != null && !EntityUtils.canAttack(((PlayerEntity) (Object) this).getUuid(), claim, entity)) { + if (claim != null && !EntityUtil.canAttack(((PlayerEntity) (Object) this).getUuid(), claim, entity)) { playerEntity_1.sendMessage(Messages.MSG_DAMAGE_ENTITY); ci.cancel(); } } + + // @Redirect(method = "dropInventory", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/GameRules;getBoolean(Lnet/minecraft/world/GameRules$RuleKey;)Z")) // private boolean dontTakeMyThingies(GameRules gameRules, GameRules.RuleKey rule) { // PlayerEntity playerEntity_1 = (PlayerEntity)(Object)this; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java new file mode 100644 index 0000000..db8520d --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java @@ -0,0 +1,42 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import net.minecraft.entity.Entity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.UUID; + +/** + * @author Indigo Amann + */ +@Mixin(ProjectileEntity.class) +public class ProjectileEntityMixin { + @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")) + public boolean imInvincible(Entity entity, DamageSource damageSource_1, float float_1) { + if (entity.world.isClient()) return entity.damage(damageSource_1, float_1); + ProjectileEntity projectile = (ProjectileEntity)(Object)this; + + if (((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()) != null) { + PlayerEntity playerEntity_1 = ((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); + if (claim != null && entity != playerEntity_1) { + if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY)) { + playerEntity_1.sendMessage(Messages.MSG_DAMAGE_ENTITY); + projectile.kill(); // You do not want an arrow bouncing between two armor stands + return false; + } + } + } + return entity.damage(damageSource_1, float_1); + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index aae0718..beedc32 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -1,6 +1,7 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.util.BlockUtil; import net.minecraft.block.*; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; @@ -41,7 +42,7 @@ private ActionResult interactIfPossible(BlockState blockState, World world, Play if (!Functions.canInteractWith(claim, blockState.getBlock(), player.getUuid())) { if (!itemStack.isEmpty() && !(itemStack.getItem() instanceof BlockItem)) { player.sendMessage(Messages.MSG_INTERACT_BLOCK); - } else if (BlockUtils.isContainer(blockState.getBlock())) { + } else if (BlockUtil.isContainer(blockState.getBlock())) { player.addMessage(Messages.MSG_OPEN_CONTAINER, true); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java index 52621ca..b8da0b3 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java @@ -1,27 +1,47 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Functions; -import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.*; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.Packet; import net.minecraft.server.PlayerManager; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.sound.SoundCategory; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.world.dimension.DimensionType; +import org.apache.logging.log4j.core.jmx.Server; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BooleanSupplier; + /** * @author Indigo Amann */ @Mixin(ServerWorld.class) -public abstract class ServerWorldMixin { -// @Inject(method = "canPlayerModifyAt", at = @At("HEAD"), cancellable = true) +public abstract class ServerWorldMixin implements MonitorableWorld { + @Shadow + @Final + private Map entitiesByUuid; + + @Shadow public abstract List getPlayers(); + + @Shadow public abstract void playGlobalEvent(int type, BlockPos pos, int data); + + // @Inject(method = "canPlayerModifyAt", at = @At("HEAD"), cancellable = true) // private void canMine(PlayerEntity player, BlockPos blockPos_1, CallbackInfoReturnable ci) { // if (player.world.isClient()) return; // Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, player.getEntityWorld().getDimension().getType()); @@ -37,4 +57,43 @@ private void sendPistonUpdate(PlayerManager manager, PlayerEntity playerEntity_1 manager.sendToAround(playerEntity_1, double_1, double_2, double_3, double_4, dimensionType_1, packet_1); Functions.doPistonUpdate((ServerWorld) (Object)this, packet_1); } + + @Inject(method = "tick", at = @At(value = "RETURN")) + public void tickActions(BooleanSupplier shouldKeepTicking, CallbackInfo ci){ + ClaimManager.INSTANCE.claimsByName.forEach((s, claim) ->{ + if(claim.rent.getRentedUntil() != 0){ + if(claim.rent.getRentTimeLeft() < 0){ + System.out.println("Rent expired -> method call"); + this.getPlayers().forEach(serverPlayerEntity -> { + if(serverPlayerEntity.getUuid() == claim.rent.getTenant()){ + serverPlayerEntity.sendMessage(new LiteralText("Rent expired").formatted(Formatting.RED)); + claim.endRent(); + } + }); + } + } + }); + } + +// AtomicReference atomicReference = new AtomicReference<>(); +// public ServerPlayerEntity getPlayerByUUID(UUID uuid){ +// this.getPlayers().forEach(serverPlayerEntity -> { +// if(serverPlayerEntity.getUuid() == uuid) +// atomicReference.set(serverPlayerEntity); +// }); +// return atomicReference.get(); +// } + + @Override + public int loadedEntities() { + if (this.entitiesByUuid == null) + return -1; + + return this.entitiesByUuid.size(); + } + + @Override + public Map EntityList() { + return entitiesByUuid; + } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java new file mode 100644 index 0000000..8fbb447 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java @@ -0,0 +1,181 @@ +package io.github.indicode.fabric.itsmine.util; + +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Config; +import net.minecraft.server.command.CommandSource; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.math.Direction; +import net.minecraft.util.registry.Registry; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static net.minecraft.server.command.CommandManager.argument; + +public class ArgumentUtil { + + + public static RequiredArgumentBuilder getSubAndClaims() { + return argument("claim", word()).suggests(CLAIM__SUBZONE_PROVIDER); + } + + public static RequiredArgumentBuilder getClaims() { + return argument("claim", word()).suggests(ArgumentUtil::claimProvider); + } + + public static RequiredArgumentBuilder getSubzones() { + return argument("subzone", word()).suggests(ArgumentUtil::subzoneProvider); + } + + public static RequiredArgumentBuilder getDirections() { + return argument("direction", word()).suggests(DIRECTION_PROVIDER); + } + + public static RequiredArgumentBuilder getHelpId() { + return argument("id", word()).suggests(HELPID_PROVIDER); + } + + public static RequiredArgumentBuilder getPlayers(){ + return argument("player", word()).suggests(PLAYERS_PROVIDER); + } + + public static RequiredArgumentBuilder getSettings(){ + return argument("setting", word()).suggests(SETTINGS_PROVIDER); + } + public static RequiredArgumentBuilder getMessageEvent(){ + return argument("messageEvent", word()).suggests(MESSAGE_EVENTS_PROVIDER); + } + + public static RequiredArgumentBuilder getEventMessage(){ + return argument("message", word()).suggests(EVENT_MESSAGE_PROVIDER); + } + + + + private static final SuggestionProvider CLAIM__SUBZONE_PROVIDER = (source, builder) -> { + ServerPlayerEntity player = source.getSource().getPlayer(); + List names = new ArrayList<>(); + Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + if (current != null) names.add(current.name); + for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { + if (claim != null) { + System.out.println("Claim " + claim.name); + names.add(claim.name); + } + } + return CommandSource.suggestMatching(names, builder); + }; + + private static CompletableFuture claimProvider(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { + ServerPlayerEntity player = context.getSource().getPlayer(); + List names = new ArrayList<>(); + Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + if (current != null && !current.isChild) names.add(current.name); + for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { + if (claim != null && !claim.isChild) { + names.add(claim.name); + } + } + return CommandSource.suggestMatching(names, builder); + } + + public static CompletableFuture subzoneProvider(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { + ServerPlayerEntity player = context.getSource().getPlayer(); + List names = new ArrayList<>(); + Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + if (current != null && current.isChild) names.add(current.name); + for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { + if (claim != null && claim.isChild) { + names.add(claim.name); + } + } + names.add("Debug"); + return CommandSource.suggestMatching(names, builder); + } + + + private static final SuggestionProvider DIRECTION_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Direction direction: Direction.values()) { + if (Config.claims2d && (direction == Direction.DOWN || direction == Direction.UP)) continue; + strings.add(direction.getName()); + }; + return CommandSource.suggestMatching(strings, builder); + }; + + public static final SuggestionProvider HELPID_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.HelpBook value : Claim.HelpBook.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; + + public static CompletableFuture itemsSuggestion(final CommandContext ctx, final SuggestionsBuilder builder) { + List strings = new ArrayList<>(); + Registry.ITEM.forEach((item) -> { + strings.add(Registry.ITEM.getId(item).getPath()); + }); + + return CommandSource.suggestMatching(strings, builder); + } + + public static final SuggestionProvider PLAYERS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (ServerPlayerEntity player : source.getSource().getMinecraftServer().getPlayerManager().getPlayerList()) { + strings.add(player.getEntityName()); + } + return CommandSource.suggestMatching(strings, builder); + }; + + public static final SuggestionProvider SETTINGS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { + strings.add(value.id); + } + for (Claim.Permission value : Claim.Permission.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; + + public static final SuggestionProvider MESSAGE_EVENTS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.Event value : Claim.Event.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; + public static final SuggestionProvider EVENT_MESSAGE_PROVIDER = (source, builder) -> { + if (!builder.getRemaining().isEmpty()) + return builder.buildFuture(); + + List strings = new ArrayList<>(); + strings.add("reset"); + try { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(source, "claim")); + Claim.Event eventType = Claim.Event.getById(getString(source, "messageEvent")); + + if (eventType != null && claim != null) { + String message = eventType == Claim.Event.ENTER_CLAIM ? claim.enterMessage : claim.leaveMessage; + if (message != null) strings.add(message); + } + + } catch (Exception ignored) { + } + + return CommandSource.suggestMatching(strings, builder); + }; + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java b/src/main/java/io/github/indicode/fabric/itsmine/util/BlockUtil.java similarity index 93% rename from src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java rename to src/main/java/io/github/indicode/fabric/itsmine/util/BlockUtil.java index d53eb11..2610140 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/BlockUtil.java @@ -1,8 +1,8 @@ -package io.github.indicode.fabric.itsmine; +package io.github.indicode.fabric.itsmine.util; import net.minecraft.block.*; -public class BlockUtils { +public class BlockUtil { public static boolean isContainer(Block block) { return block instanceof AbstractChestBlock || isChest(block) || isEnderchest(block) || isShulkerBox(block); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java new file mode 100644 index 0000000..f8c0137 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java @@ -0,0 +1,200 @@ +package io.github.indicode.fabric.itsmine.util; + +import blue.endless.jankson.annotation.Nullable; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import io.github.indicode.fabric.itsmine.*; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicReference; + +public class ClaimUtil { + public static BlockPos getPosOnGround(BlockPos pos, World world) { + BlockPos blockPos = new BlockPos(pos.getX(), pos.getY(), pos.getZ()); + + do { + blockPos = blockPos.down(); + if(blockPos.getY() < 1){ + return pos; + } + } while (!world.getBlockState(blockPos).isFullCube(world, pos)); + + return blockPos.up(); + } + + public static Claim getParentClaim(Claim subzone){ + AtomicReference parentClaim = new AtomicReference<>(); + if(subzone.isChild){ + ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> { + for(Claim subzone2 : claim.children){ + if(subzone2 == subzone){ + parentClaim.set(claim); + } + } + }); + return parentClaim.get(); + } + return subzone; + } + + public static void validateClaim(Claim claim) throws CommandSyntaxException { + if (claim == null) throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); + } + + public static boolean verifyPermission(Claim claim, Claim.Permission permission, CommandContext context, boolean admin) throws CommandSyntaxException { + if (verifyExists(claim, context)) { + if (claim.permissionManager.hasPermission(context.getSource().getPlayer().getGameProfile().getId(), permission)) { + return true; + } else { + context.getSource().sendFeedback(new LiteralText(admin ? "You are modifying a claim using admin privileges" : "You cannot modify exceptions for this claim").formatted(admin ? Formatting.DARK_RED : Formatting.RED), false); + return admin; + } + } else { + return false; + } + } + private static boolean verifyExists(Claim claim, CommandContext context) { + if (claim == null) { + context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return false; + } else { + return true; + } + } + + public static ArrayList getClaims(){ + ArrayList claims = new ArrayList<>(); + ClaimManager.INSTANCE.claimsByName.forEach((s, claim) -> { + claims.add(claim); + }); + return claims; + } + + public static void validateCanAccess(ServerPlayerEntity player, Claim claim, boolean admin) throws CommandSyntaxException { + if (claim == null) { + throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); + } + + if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SETTINGS)) { + throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); + } + } + + public static int querySetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting) { + boolean enabled = claim.settings.getSetting(setting); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); + return 1; + } + public static int setSetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting, boolean set) { + claim.settings.settings.put(setting, set); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSet setting &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); + return 0; + } + public static int queryPermission(ServerCommandSource source, Claim claim, Claim.Permission permission) { + boolean defaultPerm = claim.permissionManager.defaults.hasPermission(permission); + source.sendFeedback(new LiteralText(ChatColor.translate("&ePermission &6" + permission.id + "&e is set to " + (defaultPerm ? "&a" : "&c") + defaultPerm + "&e for &6" + claim.name)), false); + return 1; + } + public static int setPermission(ServerCommandSource source, Claim claim, Claim.Permission permission, boolean set) { + claim.permissionManager.defaults.setPermission(permission, set); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSet permission &6" + permission.id + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); + return 1; + } + public static int querySettings(ServerCommandSource source, Claim claim) { + source.sendFeedback(new LiteralText("\n").append(new LiteralText("Settings: " + claim.name).formatted(Formatting.YELLOW)).append("\n") + .append(Messages.Command.getSettings(claim)).append("\n"), false); + return 1; + } + public static int executeSetting(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : + ClaimManager.INSTANCE.claimsByName.get(claimName); + if (claim1 == null) { + source.sendError(Messages.INVALID_CLAIM); + return -1; + } + + if (input == null) { + return querySettings(source, claim1); + } + + validateCanAccess(player, claim1, admin); + Claim.ClaimSettings.Setting setting = Claim.ClaimSettings.Setting.byId(input); + Claim.Permission permission = Claim.Permission.byId(input); + + if (setting != null && permission == null) + return isQuery ? querySetting(source, claim1, setting) : setSetting(source, claim1, setting, value); + + if (setting == null && permission != null) + return isQuery ? queryPermission(source, claim1, permission) : setPermission(source, claim1, permission, value); + + source.sendError(Messages.INVALID_SETTING); + return -1; + } + public static int executePermission(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : + ClaimManager.INSTANCE.claimsByName.get(claimName); + if (claim1 == null) { + source.sendError(Messages.INVALID_CLAIM); + return -1; + } + + validateCanAccess(player, claim1, admin); + Claim.Permission permission = Claim.Permission.byId(input); + if (permission != null) + return !isQuery ? setPermission(source, claim1, permission, value) : queryPermission(source, claim1, permission); + + source.sendError(Messages.INVALID_SETTING); + return -1; + } + + public static int modifyException(Claim claim, ServerPlayerEntity exception, Claim.Permission permission, boolean allowed) { + claim.permissionManager.setPermission(exception.getGameProfile().getId(), permission, allowed); + return 0; + } + private static int modifyException(Claim claim, String exception, Claim.Permission permission, boolean allowed) { + claim.permissionManager.setPermission(exception, permission, allowed); + return 0; + } + + public static boolean hasPermission(Claim claim, ServerPlayerEntity exception, Claim.Permission permission) { + return claim.permissionManager.hasPermission(exception.getGameProfile().getId(), permission); + } + + public static int setEventMessage(ServerCommandSource source, Claim claim, Claim.Event event, String message) { + switch (event) { + case ENTER_CLAIM: + claim.enterMessage = message.equalsIgnoreCase("reset") ? null : message; + break; + case LEAVE_CLAIM: + claim.leaveMessage = message.equalsIgnoreCase("reset") ? null : message; + break; + } + + if (message.equalsIgnoreCase("reset")) { + source.sendFeedback(new LiteralText("Reset ").append(new LiteralText(event.id).formatted(Formatting.GOLD) + .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) + .append(new LiteralText(claim.name).formatted(Formatting.GOLD))).formatted(Formatting.YELLOW) + , false); + return -1; + } + + source.sendFeedback(new LiteralText("Set ").append(new LiteralText(event.id).formatted(Formatting.GOLD) + .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) + .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" to:").formatted(Formatting.YELLOW))) + .append("\n").append(new LiteralText(ChatColor.translate(message))) + .formatted(Formatting.YELLOW) + , false); + return 1; + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/DirectionUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/DirectionUtil.java new file mode 100644 index 0000000..0663353 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/DirectionUtil.java @@ -0,0 +1,12 @@ +package io.github.indicode.fabric.itsmine.util; + +import net.minecraft.util.math.Direction; + +public class DirectionUtil { + public static Direction directionByName(String name) { + for (Direction direction : Direction.values()) { + if (name.equals(direction.getName())) return direction; + } + return null; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java b/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java similarity index 84% rename from src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java rename to src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java index c113083..0a4160f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java @@ -1,10 +1,11 @@ -package io.github.indicode.fabric.itsmine; +package io.github.indicode.fabric.itsmine.util; +import io.github.indicode.fabric.itsmine.Claim; import net.minecraft.entity.Entity; import java.util.UUID; -public class EntityUtils { +public class EntityUtil { public static boolean canAttack(UUID player, Claim claim, Entity entity) { return claim.hasPermission(player, Claim.Permission.DAMAGE_ENTITY) || @@ -19,4 +20,7 @@ public static boolean isPassive(Entity entity) { public static boolean isHostile(Entity entity) { return !isPassive(entity); } + + + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/NbtUtil.java similarity index 89% rename from src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java rename to src/main/java/io/github/indicode/fabric/itsmine/util/NbtUtil.java index 04e829a..99d44db 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/NbtUtil.java @@ -1,11 +1,11 @@ -package io.github.indicode.fabric.itsmine; +package io.github.indicode.fabric.itsmine.util; import net.minecraft.nbt.CompoundTag; import java.util.UUID; -public class NBTUtil { +public class NbtUtil { public static UUID getUUID(CompoundTag tag, String key){ if (tag.contains(key + "Least") && tag.contains(key + "Most")) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java b/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java similarity index 97% rename from src/main/java/io/github/indicode/fabric/itsmine/Permissions.java rename to src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java index e10ce71..9fbd7d8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java @@ -1,6 +1,7 @@ -package io.github.indicode.fabric.itsmine; +package io.github.indicode.fabric.itsmine.util; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Config; import io.github.indicode.fabric.permissions.PermChangeBehavior; import io.github.indicode.fabric.permissions.Thimble; import net.fabricmc.loader.api.FabricLoader; @@ -17,11 +18,11 @@ import java.util.Locale; import java.util.UUID; -public class Permissions { +public class PermissionUtil { private Manager manager; private boolean present; - public Permissions() { + public PermissionUtil() { Logger logger = (Logger) LogManager.getLogger("ItsMine"); logger.info("Setting up Permissions..."); this.manager = Manager.fromString(Config.permissionManager); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java new file mode 100644 index 0000000..0c9e109 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java @@ -0,0 +1,66 @@ +package io.github.indicode.fabric.itsmine.util; + +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimShower; +import io.github.indicode.fabric.itsmine.mixin.BlockUpdatePacketMixin; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; + +public class ShowerUtil { + + public static void update(Claim claim, ServerWorld world){ + update(claim, world, false); + update(claim, world, true); + } + public static void update(Claim claim, ServerWorld world, boolean hide){ + world.getPlayers().forEach(playerEntity -> { + ClaimUtil.getParentClaim(claim); + if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, hide, false); + }); + } + + public static void silentHideShow(ServerPlayerEntity player, Claim claim, boolean hide, boolean updateStatus) { + if (updateStatus) { + if (!hide) ((ClaimShower) player).setShownClaim(claim); + else ((ClaimShower) player).setShownClaim(null); + } + BlockState block = hide ? null : Blocks.GOLD_BLOCK.getDefaultState(); + showCorners(player, claim, hide, block); + if(!claim.isChild){ + block = hide ? null : Blocks.DIAMOND_BLOCK.getDefaultState(); + for(Claim subzone : claim.children){ + showCorners(player, subzone, hide, block); + } + } + + } + + private static void showCorners(ServerPlayerEntity player, Claim claim, boolean hide, BlockState state){ + state = hide ? null : state; + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); + + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()).south(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()).east(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()).south(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()).north(), player.getEntityWorld())).down(), state); + + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()).east(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()).north(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()).west(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()).west(), player.getEntityWorld())).down(), state); + } + + private static void sendBlockPacket(ServerPlayerEntity player, BlockPos pos, BlockState state) { + BlockUpdateS2CPacket packet = new BlockUpdateS2CPacket(player.world, pos); + if (state != null) ((BlockUpdatePacketMixin)packet).setState(state); + player.networkHandler.sendPacket(packet); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/TimeUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/TimeUtil.java new file mode 100644 index 0000000..35005d6 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/TimeUtil.java @@ -0,0 +1,130 @@ +package io.github.indicode.fabric.itsmine.util; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class TimeUtil { + + private static Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE); + private static final int maxYears = 100000; + private static SimpleCommandExceptionType TIME_ARGUMENT_INVALID = new SimpleCommandExceptionType(new LiteralText("Invalid time argument").formatted(Formatting.RED)); + + + public static String convertSecondsToString(int seconds, char numFormat, char typeFormat) { + int day = seconds / (24 * 3600); + seconds = seconds % (24 * 3600); + int hour = seconds / 3600; + seconds %= 3600; + int min = seconds / 60; + seconds %= 60; + + return ((day != 0) ? "§" + numFormat + day + "§" + typeFormat + " Days " : "") + + ((hour != 0) ? "§" + numFormat + hour + "§" + typeFormat + " Hours " : "") + + ((min != 0) ? "§" + numFormat + min + "§" + typeFormat + " Minutes " : "") + + ((seconds != 0) ? "§" + numFormat + seconds + "§" + typeFormat + " Seconds " : ""); + } + + public static int convertStringtoSeconds(String time) throws CommandSyntaxException { + Calendar c = new GregorianCalendar(); + int current = (int) (c.getTimeInMillis() / 1000); + int until = convertStringtoUnix(time); + return until - current; + } + + public static int convertStringtoUnix(String time) throws CommandSyntaxException { + Date date = new Date(); + Matcher matcher = timePattern.matcher(time); + int years = 0; + int months = 0; + int weeks = 0; + int days = 0; + int hours = 0; + int minutes = 0; + int seconds = 0; + boolean found = false; + while (matcher.find()) { + if (matcher.group() == null || matcher.group().isEmpty()) + continue; + + for (int i = 0; i < matcher.groupCount(); i++) { + if (matcher.group(i) != null && !matcher.group(i).isEmpty()) { + found = true; + break; + } + } + + if (!found) { + throw TIME_ARGUMENT_INVALID.create(); + } + + if (matcher.group(1) != null && !matcher.group(1).isEmpty()) { + years = Integer.parseInt(matcher.group(1)); + } + if (matcher.group(2) != null && !matcher.group(2).isEmpty()) { + months = Integer.parseInt(matcher.group(2)); + } + if (matcher.group(3) != null && !matcher.group(3).isEmpty()) { + weeks = Integer.parseInt(matcher.group(3)); + } + if (matcher.group(4) != null && !matcher.group(4).isEmpty()) { + days = Integer.parseInt(matcher.group(4)); + } + if (matcher.group(5) != null && !matcher.group(5).isEmpty()) { + hours = Integer.parseInt(matcher.group(5)); + } + if (matcher.group(6) != null && !matcher.group(6).isEmpty()) { + minutes = Integer.parseInt(matcher.group(6)); + } + if (matcher.group(7) != null && !matcher.group(7).isEmpty()) { + seconds = Integer.parseInt(matcher.group(7)); + } + break; + } + + Calendar c = new GregorianCalendar(); + if (years > 0) { + if (years > maxYears) { + years = maxYears; + } + c.add(Calendar.YEAR, years); + } + if (months > 0) { + c.add(Calendar.MONTH, months); + } + if (weeks > 0) { + c.add(Calendar.WEEK_OF_YEAR, weeks); + } + if (days > 0) { + c.add(Calendar.DAY_OF_MONTH, days); + } + if (hours > 0) { + c.add(Calendar.HOUR_OF_DAY, hours); + } + if (minutes > 0) { + c.add(Calendar.MINUTE, minutes); + } + if (seconds > 0) { + c.add(Calendar.SECOND, seconds); + } + Calendar max = new GregorianCalendar(); + max.add(Calendar.YEAR, 10); + if (c.after(max)) { + return (int) max.getTimeInMillis() / 1000; + } + + if (date.getTime() == c.getTimeInMillis()) { + throw TIME_ARGUMENT_INVALID.create(); + } + + return (int) (c.getTimeInMillis() / 1000); + } + +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 98abc6f..5e4eba0 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -7,7 +7,8 @@ "description": "Land claims.", "authors": [ "Indicode", - "Maintained by CODY_AI" + "CODY_AI", + "Maintained by DrexHD" ], "contact": { "sources": "https://github.com/GiantNuker/NoGrief/" diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index 585b8d1..d92caaf 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -3,8 +3,8 @@ "package": "io.github.indicode.fabric.itsmine.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ - "MinecraftServerMixin", "WorldSaveHandlerMixin", + "MinecraftServerMixin", "CommandManagerMixin", "BlockUpdatePacketMixin", "BucketItemMixin", @@ -33,6 +33,7 @@ "EnderDragonEntityMixin", "FarmlandBlockMixin", "BoatItemMixin", + "AnimalEntityMixin", "LecternScreenHandlerMixin" ], "client": [ From 9e08391feea5341580d667ed20cec0563b424b1c Mon Sep 17 00:00:00 2001 From: DrexHD Date: Mon, 20 Apr 2020 18:12:12 +0200 Subject: [PATCH 63/85] Revert "bump version" This reverts commit 46edcd8b061bad6aab561c69d04e3942f555034a. --- build.gradle | 2 +- gradle.properties | 8 +- .../{util/BlockUtil.java => BlockUtils.java} | 4 +- .../github/indicode/fabric/itsmine/Claim.java | 338 +- .../indicode/fabric/itsmine/ClaimCommand.java | 3513 ++++++++--------- .../indicode/fabric/itsmine/ClaimManager.java | 3 +- .../indicode/fabric/itsmine/Config.java | 2 - .../EntityUtil.java => EntityUtils.java} | 8 +- .../indicode/fabric/itsmine/Functions.java | 40 +- .../indicode/fabric/itsmine/ItsMine.java | 10 +- .../indicode/fabric/itsmine/Messages.java | 9 +- .../fabric/itsmine/MonitorableWorld.java | 13 - .../{util/NbtUtil.java => NBTUtil.java} | 4 +- .../PermissionUtil.java => Permissions.java} | 7 +- ...CreateCommand.java => SubzoneCommand.java} | 61 +- .../fabric/itsmine/command/BlockCommand.java | 43 - .../itsmine/command/CommandManager.java | 45 - .../fabric/itsmine/command/CreateCommand.java | 126 - .../itsmine/command/ExceptionCommand.java | 176 - .../fabric/itsmine/command/ExpandCommand.java | 174 - .../fabric/itsmine/command/FlyCommand.java | 42 - .../fabric/itsmine/command/HelpCommand.java | 102 - .../fabric/itsmine/command/InfoCommand.java | 105 - .../fabric/itsmine/command/ListCommand.java | 30 - .../itsmine/command/PermissionsCommand.java | 49 - .../fabric/itsmine/command/RemoveCommand.java | 93 - .../fabric/itsmine/command/RenameCommand.java | 61 - .../fabric/itsmine/command/RentCommand.java | 94 - .../itsmine/command/RentableCommand.java | 81 - .../itsmine/command/RevenueCommand.java | 87 - .../itsmine/command/SettingsCommand.java | 53 - .../fabric/itsmine/command/ShowCommand.java | 54 - .../fabric/itsmine/command/StickCommand.java | 30 - .../itsmine/command/TransferCommand.java | 147 - .../fabric/itsmine/command/TrustCommand.java | 85 - .../itsmine/command/TrustedCommand.java | 124 - .../itsmine/command/admin/AdminCommand.java | 48 - .../itsmine/command/admin/BlocksCommand.java | 65 - .../itsmine/command/admin/ClaimsCommand.java | 70 - .../itsmine/command/admin/CreateCommand.java | 81 - .../command/admin/EntitiesCommand.java | 42 - .../itsmine/command/admin/ExpandCommand.java | 76 - .../itsmine/command/admin/IgnoreCommand.java | 30 - .../itsmine/command/admin/ListAllCommand.java | 37 - .../itsmine/command/admin/OwnerCommand.java | 114 - .../itsmine/command/admin/RemoveCommand.java | 31 - .../itsmine/command/admin/RenameCommand.java | 23 - .../command/subzone/SubzoneCommand.java | 34 - .../itsmine/mixin/AnimalEntityMixin.java | 49 - .../itsmine/mixin/CommandManagerMixin.java | 8 +- .../fabric/itsmine/mixin/EntityMixin.java | 3 +- .../itsmine/mixin/IntegratedServerMixin.java | 6 +- .../mixin/LecternScreenHandlerMixin.java | 24 +- .../itsmine/mixin/MinecraftServerMixin.java | 9 +- .../fabric/itsmine/mixin/OwnedProjectile.java | 13 - .../itsmine/mixin/PlayerEntityMixin.java | 9 +- .../itsmine/mixin/ProjectileEntityMixin.java | 42 - .../ServerPlayerInteractionManagerMixin.java | 3 +- .../itsmine/mixin/ServerWorldMixin.java | 71 +- .../fabric/itsmine/util/ArgumentUtil.java | 181 - .../fabric/itsmine/util/ClaimUtil.java | 200 - .../fabric/itsmine/util/DirectionUtil.java | 12 - .../fabric/itsmine/util/ShowerUtil.java | 66 - .../fabric/itsmine/util/TimeUtil.java | 130 - src/main/resources/fabric.mod.json | 3 +- src/main/resources/itsmine.mixins.json | 3 +- 66 files changed, 1808 insertions(+), 5498 deletions(-) rename src/main/java/io/github/indicode/fabric/itsmine/{util/BlockUtil.java => BlockUtils.java} (93%) rename src/main/java/io/github/indicode/fabric/itsmine/{util/EntityUtil.java => EntityUtils.java} (84%) delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java rename src/main/java/io/github/indicode/fabric/itsmine/{util/NbtUtil.java => NBTUtil.java} (89%) rename src/main/java/io/github/indicode/fabric/itsmine/{util/PermissionUtil.java => Permissions.java} (97%) rename src/main/java/io/github/indicode/fabric/itsmine/{command/subzone/CreateCommand.java => SubzoneCommand.java} (72%) delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/StickCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/BlocksCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/CreateCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/IgnoreCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/RenameCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/DirectionUtil.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/TimeUtil.java diff --git a/build.gradle b/build.gradle index 01d8e83..cba03e6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.2.7-SNAPSHOT' + id 'fabric-loom' version '0.2.6-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index 967dbd9..4f70a7f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=20w16a -yarn_mappings=20w16a+build.4 -loader_version=0.7.10+build.191 +minecraft_version=20w13b +yarn_mappings=20w13b+build.4 +loader_version=0.7.8+build.189 # Mod Properties - mod_version = 1.9.0-20W16A + mod_version = 1.8.21-20W13B maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/BlockUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java similarity index 93% rename from src/main/java/io/github/indicode/fabric/itsmine/util/BlockUtil.java rename to src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java index 2610140..d53eb11 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/BlockUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java @@ -1,8 +1,8 @@ -package io.github.indicode.fabric.itsmine.util; +package io.github.indicode.fabric.itsmine; import net.minecraft.block.*; -public class BlockUtil { +public class BlockUtils { public static boolean isContainer(Block block) { return block instanceof AbstractChestBlock || isChest(block) || isEnderchest(block) || isShulkerBox(block); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index c6f5351..6a3113b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -1,11 +1,7 @@ package io.github.indicode.fabric.itsmine; import blue.endless.jankson.annotation.Nullable; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.*; -import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -15,7 +11,7 @@ import java.util.*; import java.util.concurrent.atomic.AtomicReference; -import static io.github.indicode.fabric.itsmine.util.NbtUtil.*; +import static io.github.indicode.fabric.itsmine.NBTUtil.*; /** * @author Indigo Amann @@ -28,7 +24,6 @@ public class Claim { public List children = new ArrayList<>(); public ClaimSettings settings = new ClaimSettings(); public PermissionManager permissionManager = new PermissionManager(); - public Rent rent = new Rent(); public UUID claimBlockOwner = null; public String customOwnerName, enterMessage, leaveMessage; public boolean isChild = false; @@ -54,77 +49,9 @@ public boolean includesPosition(BlockPos pos) { return pos.getX() >= min.getX() && pos.getY() >= min.getY() && pos.getZ() >= min.getZ() && pos.getX() <= max.getX() && pos.getY() <= max.getY() && pos.getZ() <= max.getZ(); } - - public boolean isInside (Claim claim){ - BlockPos a = min, - b = max, - c = new BlockPos(max.getX(), min.getY(), min.getZ()), - d = new BlockPos(min.getX(), max.getY(), min.getZ()), - e = new BlockPos(min.getX(), min.getY(), max.getZ()), - f = new BlockPos(max.getX(), max.getY(), min.getZ()), - g = new BlockPos(max.getX(), min.getY(), max.getZ()), - h = new BlockPos(min.getX(), max.getY(), max.getZ()); - if( - claim.includesPosition(a) && - claim.includesPosition(b) && - claim.includesPosition(c) && - claim.includesPosition(d) && - claim.includesPosition(e) && - claim.includesPosition(f) && - claim.includesPosition(g) && - claim.includesPosition(h) - ){ - return true; - } - return false; - } - public boolean intersects(Claim claim) { return intersects(claim, true, false); } - - public int getEntities(ServerWorld world){ - AtomicReference entities = new AtomicReference<>(); - entities.set(0); - MonitorableWorld monitorableWorld = (MonitorableWorld) world; - monitorableWorld.EntityList().forEach((uuid, entity) -> { - if(includesPosition(entity.getBlockPos())) { - entities.set(entities.get()+1); - } - }); - - return entities.get(); - } - - public Map getEntitySorted(Map entityMap){ - AtomicReference> entityTypeMap = new AtomicReference<>(new HashMap<>()); - entityMap.forEach((uuid, entity) -> { - if(entityTypeMap.get().containsKey(entity.getType())){ - Map entityTypeIntegerMap = entityTypeMap.get(); - entityTypeIntegerMap.put(entity.getType(), entityTypeIntegerMap.get(entity.getType())+1); - entityTypeMap.set(entityTypeIntegerMap); - } else { - Map entityTypeIntegerMap = entityTypeMap.get(); - entityTypeIntegerMap.put(entity.getType(), 1); - entityTypeMap.set(entityTypeIntegerMap); - } - }); - return Functions.sortByValue(entityTypeMap.get()); - } - - public Map getEntityMap(Claim claim, ServerWorld world){ - AtomicReference> entityMap = new AtomicReference<>(new HashMap<>()); - MonitorableWorld monitorableWorld = (MonitorableWorld) world; - monitorableWorld.EntityList().forEach((uuid, entity) -> { - if(claim.includesPosition(entity.getBlockPos())) { - Map entityList = entityMap.get(); - entityList.put(uuid, entity); - entityMap.set(entityList); - } - }); - return entityMap.get(); - } - public boolean intersects(Claim claim, boolean checkOther, boolean checkforsubzone) { if (claim == null) return false; if (!claim.dimension.equals(dimension)) return false; @@ -171,11 +98,24 @@ public Claim getZoneCovering(BlockPos pos) { return null; } - + /*public ClaimSettings getSettingsAt(BlockPos pos) { + Claim at = getZoneCovering(pos); + if (at != null) { + return at.settings; + } else return settings; + } + public ClaimPermissions getPermissionsAt(UUID player, BlockPos pos) { + Claim at = getZoneCovering(pos); + if (at != null) { + return at.getPlayerPermissions(player); + } else return settings; + }*/ public boolean hasPermission(UUID player, Permission permission) { return ClaimManager.INSTANCE.ignoringClaims.contains(player) || permissionManager.hasPermission(player, permission); } - + //public boolean hasPermissionAt(UUID player, ClaimPermissions.Permission permission, BlockPos pos) { + // return player.equals(owner) || ClaimManager.INSTANCE.ignoringClaims.contains(player) || getPermissionsAt(player, pos).hasPermission(permission); + //} public void addSubzone(Claim claim) { children.add(claim); } @@ -184,72 +124,66 @@ public void removeSubzone(Claim claim) { children.remove(claim); } - public BlockPos getSize() { - return max.subtract(min); + @Nullable + AtomicReference atomic = new AtomicReference<>(); + public Claim getParentClaim(Claim subzone){ + if(subzone.isChild){ + ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> { + for(Claim subzone2 : claim.children){ + if(subzone2 == subzone){ + atomic.set(claim); + } + } + }); + return atomic.get(); + } + return null; } - public void expand(BlockPos modifier) { - if (modifier.getX() > 0) { - max = max.add(modifier.getX(), 0, 0); - } - else { - min = min.add(modifier.getX(), 0, 0); - } - if (modifier.getY() > 0) { - max = max.add(0, modifier.getY(), 0); - } - else { - min = min.add(0, modifier.getY(), 0); - } - if (modifier.getZ() > 0) { - max = max.add(0, 0, modifier.getZ()); - } - else { - min = min.add(0, 0, modifier.getZ()); - } + public void expand(BlockPos min, BlockPos max) { + this.min = this.min.add(min); + this.max = this.max.add(max); } - public void shrink(BlockPos modifier) { - if (modifier.getX() < 0) { - min = min.add(-modifier.getX(), 0, 0); - } else { - max = max.add(-modifier.getX(), 0, 0); - } - if (modifier.getY() < 0) { - min = min.add(0, -modifier.getY(), 0); - } else { - max = max.add(0, -modifier.getY(), 0); - } - if (modifier.getZ() < 0) { - min = min.add(0, 0, -modifier.getZ()); - } else { - max = max.add(0, 0, -modifier.getZ()); - } + public BlockPos getSize() { + return max.subtract(min); } - - public boolean canShrinkWithoutHittingOtherSide(BlockPos modifier){ + public void expand(BlockPos modifier) { + if (modifier.getX() > 0) max = max.add(modifier.getX(), 0, 0); + else min = min.add(modifier.getX(), 0, 0); + if (modifier.getY() > 0) max = max.add(0, modifier.getY(), 0); + else min = min.add(0, modifier.getY(), 0); + if (modifier.getZ() > 0) max = max.add(0, 0, modifier.getZ()); + else min = min.add(0, 0, modifier.getZ()); + } + public boolean shrink(BlockPos modifier) { if (modifier.getX() < 0) { if (min.getX() - modifier.getX() > max.getX()) return false; + min = min.add(-modifier.getX(), 0, 0); } else { if (max.getX() - modifier.getX() < min.getX()) return false; + max = max.add(-modifier.getX(), 0, 0); } if (modifier.getY() < 0) { if (min.getY() - modifier.getY() > max.getY()) return false; + min = min.add(0, -modifier.getY(), 0); } else { if (max.getY() - modifier.getY() < min.getY()) return false; + max = max.add(0, -modifier.getY(), 0); } if (modifier.getZ() < 0) { if (min.getZ() - modifier.getZ() > max.getZ()) return false; + min = min.add(0, 0, -modifier.getZ()); } else { if (max.getZ() - modifier.getZ() < min.getZ()) return false; + max = max.add(0, 0, -modifier.getZ()); } return true; } - public void expand(Direction direction, int distance) { expand(new BlockPos(direction.getOffsetX() * distance, direction.getOffsetY() * distance, direction.getOffsetZ() * distance)); } - public void shrink(Direction direction, int distance) { - shrink(new BlockPos(direction.getOffsetX() * distance, direction.getOffsetY() * distance, direction.getOffsetZ() * distance)); + public boolean shrink(Direction direction, int distance) { + return shrink(new BlockPos(direction.getOffsetX() * distance, direction.getOffsetY() * distance, direction.getOffsetZ() * distance)); } public int getArea() { return getSize().getX() * (Config.claims2d ? 1 : getSize().getY()) * getSize().getZ(); @@ -281,42 +215,6 @@ public CompoundTag toTag() { tag.put("subzones", subzoneList); } } - { - CompoundTag rent1 = new CompoundTag(); - { - CompoundTag rented = new CompoundTag(); - if(rent.getTenant() != null) rented.putUuidNew("tenant", rent.getTenant()); - if(rent.getRentedUntil() != 0) rented.putInt("rentedUntil", rent.getRentedUntil()); - - { - if(rent.getRevenue() != null){ - CompoundTag revenue = new CompoundTag(); - int i = 0; - for(ItemStack itemStack : rent.getRevenue()){ - CompoundTag revenueTag = new CompoundTag(); - itemStack.toTag(revenueTag); - i++; - revenue.put(String.valueOf(i), revenueTag); - rent1.put("revenue", revenue); - } - } - } - rent1.put("rented", rented); - } - { - CompoundTag rentable = new CompoundTag(); - rentable.putBoolean("rentable", rent.isRentable()); - CompoundTag currency = new CompoundTag(); - if(rent.getCurrency() != ItemStack.EMPTY) rent.getCurrency().toTag(currency); - if(rent.getRentAbleTime() != 0) rentable.putInt("rentTime", rent.getRentAbleTime()); - if(rent.getMaxrentAbleTime() != 0) rentable.putInt("maxrentTime", rent.getMaxrentAbleTime()); - - rent1.put("rentable", rentable); - rentable.put("currency", currency); - } - tag.put("rent", rent1); - - } { tag.put("settings", settings.toTag()); tag.put("permissions", permissionManager.toNBT()); @@ -364,31 +262,6 @@ public void fromTag(CompoundTag tag) { } } } - { - CompoundTag rent1 = tag.getCompound("rent"); - { - CompoundTag rented = rent1.getCompound("rented"); - if (containsUUID(rented, "tenant")) rent.setTenant(getUUID(rented,"tenant")); - if(rented.contains("rentedUntil")) rent.setRentedUntil(rented.getInt("rentedUntil")); - } - { - CompoundTag rentable = rent1.getCompound("rentable"); - CompoundTag currency = rentable.getCompound("currency"); - if(rentable.contains("rentable")) rent.setRentable(rentable.getBoolean("rentable")); - if(currency != null) rent.setCurrency(ItemStack.fromTag(currency)); - if(rentable.contains("rentTime")) rent.setRentAbleTime(rentable.getInt("rentTime")); - if(rentable.contains("maxrentTime")) rent.setMaxrentAbleTime(rentable.getInt("maxrentTime")); - } - { - CompoundTag revenue = rent1.getCompound("revenue"); - if(!revenue.isEmpty()){ - for(int i = 1; i <= revenue.getSize(); i++){ - CompoundTag revenueTag = revenue.getCompound(String.valueOf(i)); - rent.addRevenue(ItemStack.fromTag(revenueTag)); - } - } - } - } { this.settings = new ClaimSettings(tag.getCompound("settings")); permissionManager = new PermissionManager(); @@ -409,12 +282,6 @@ public boolean is2d() { return min.getY() == 0 && max.getY() == 255; } - public void endRent(){ - permissionManager.playerPermissions.put(rent.getTenant(), new Claim.DefaultPermissionMap()); - rent.setRentedUntil(0); - rent.setTenant(null); - } - public enum Permission { //Admin REMOVE_CLAIM("remove_claim", "Remove Claim"), @@ -423,8 +290,6 @@ public enum Permission { MODIFY_PERMISSIONS("modify.permissions", "Change Permissions"), //Normal MODIFY_PROPERTIES("modify.properties", "Modify Claim Properties"), - MODIFY_SUBZONE("modify.subzone", "Add subzones"), - MOVE("move", "Move inside claim"), BUILD("build", "Place/Break Blocks"), INTERACT_BLOCKS("interact_blocks", "Interact With Blocks"), USE_ITEMS_ON_BLOCKS("use_items_on_blocks", "Use Block Modifying items"), @@ -445,8 +310,7 @@ public enum Permission { SPAWN_BOAT("spawn.boat", "Spawn Boats"); - public String id; - public String name; + String id, name; Permission(String id, String name) { this.id = id; this.name = name; @@ -458,92 +322,10 @@ public static Permission byId(String id) { return null; } } - - public class Rent { - - public UUID tenant = null; - public boolean rentable = false; - - public int rentTime = 0; - public int maxrentTime = 0; - public ArrayList revenue = new ArrayList<>(); - - - public ArrayList getRevenue() { - return revenue; - } - - public void addRevenue(ItemStack revenue) { - this.revenue.add(revenue); - } - - public void clearRevenue() { - revenue.clear(); - } - - //Payement - public ItemStack currency = ItemStack.EMPTY; - - public int rentedUntil = 0; - - public void setRentTime(int rentTime) { this.rentTime = rentTime; } - - //Max rent time - public int getMaxrentAbleTime() { return maxrentTime; } - public boolean isRented() { return rentedUntil != 0; } - - public void setMaxrentAbleTime(int maxrentTime) { this.maxrentTime = maxrentTime; } - - public int getRentedUntil() { - return rentedUntil; - } - - public void setRentedUntil(int rentedUntil) { - this.rentedUntil = rentedUntil; - } - - public int getRentTimeLeft(){ - return rentedUntil - getUnixTime(); - } - - public int getRentAbleTime() { return rentTime; } - - public void setRentAbleTime(int rentTime) { this.rentTime = rentTime; } - - //Returns seconds passed (Unix time) - public int getUnixTime(){ - return (int) (System.currentTimeMillis() / 1000); - } - - public void addRentTimeLeft(int rent){ - rentedUntil = rentedUntil + rent; - } - - public void removeRentTimeLeft(int rent){ addRentTimeLeft(-rent); } - - public void setRentTimeLeft(int time) { rentedUntil = getUnixTime() + time; } - - public UUID getTenant() { return tenant; } - - public void setTenant(UUID tenant) { this.tenant = tenant; } - - public boolean isRentable() { return rentable; } - - public void setRentable(boolean rentable) { this.rentable = rentable; } - - public int getAmount() { return currency.getCount(); } - - public void setAmount(int amount) { currency.setCount(amount); } - - public ItemStack getCurrency() { return currency; } - - public void setCurrency(ItemStack currency) { this.currency = currency; } - } - public static class PermissionManager { public ClaimPermissionMap defaults = new DefaultPermissionMap(); - public Map playerPermissions = new HashMap<>(); - public Map groupPermissions = new HashMap<>(); + protected Map playerPermissions = new HashMap<>(); + protected Map groupPermissions = new HashMap<>(); public boolean isPermissionSet(UUID player, Permission permission) { return playerPermissions.get(player) != null && playerPermissions.get(player).isPermissionSet(permission); } @@ -752,7 +534,7 @@ public enum Setting { ENTER_SOUND("enter_sound", "Enter Sound", false), BREAK_FARMLANDS("break_farmlands", "Break Farmlands", false); - public String id, name; + String id, name; boolean defaultValue; Setting(String id, String name, boolean defaultValue) { this.id = id; @@ -795,7 +577,7 @@ public enum Event { ENTER_CLAIM("enter", Config.msg_enter_default), LEAVE_CLAIM("leave", Config.msg_leave_default); - public String id; + String id; String defaultValue; Event(String id, String defaultValue) { this.id = id; @@ -819,9 +601,9 @@ public enum HelpBook { COMMAND("commands", Messages.HELP, "Claim Commands"), PERMS_AND_SETTINGS("perms_and_settings", Messages.SETTINGS_AND_PERMISSIONS, "Claim Permissions and Settings"); - public String id; - public String title; - public Text[] texts; + String id; + String title; + Text[] texts; HelpBook(String id, Text[] texts, String title) { this.id = id; this.title = title; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index b5cd557..47a2c71 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1,439 +1,469 @@ package io.github.indicode.fabric.itsmine; +import blue.endless.jankson.annotation.Nullable; +import com.mojang.authlib.GameProfile; +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.ArgumentBuilder; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import io.github.indicode.fabric.itsmine.mixin.BlockUpdatePacketMixin; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.command.EntitySelector; +import net.minecraft.command.arguments.BlockPosArgumentType; +import net.minecraft.command.arguments.EntityArgumentType; +import net.minecraft.command.arguments.GameProfileArgumentType; +import net.minecraft.command.arguments.PosArgument; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; +import net.minecraft.server.MinecraftServer; +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.*; +import net.minecraft.util.Formatting; +import net.minecraft.util.Pair; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.registry.Registry; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.dimension.DimensionType; + +import java.lang.reflect.Array; +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Predicate; + +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + /** * @author Indigo Amann */ -//public class ClaimCommand { -// public static final int MAX_NAME_LENGTH = 30; -// private static void validateCanAccess(ServerPlayerEntity player, Claim claim, boolean admin) throws CommandSyntaxException { -// if (claim == null) { -// throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); -// } -// -// if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SETTINGS)) { -// throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); -// } -// } -// -// private static void validateClaim(Claim claim) throws CommandSyntaxException { -// if (claim == null) throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); -// } -// -// -// private static Predicate perm(String str) { -// return perm(str, 2); -// } -// private static Predicate perm(String str, int op) { -// return source -> ItsMine.permissions().hasPermission(source, "itsmine." + str, op); -// } -// private static final Predicate PERMISSION_CHECK_ADMIN = src -> perm("admin").test(src) || perm("admin.modify_balance").test(src) || -// perm("admin.infinite_blocks").test(src) || perm("admin.modify").test(src) || -// perm("admin.modify_balance").test(src) || perm("admin.ignore_claims").test(src) || -// perm("admin.modify_permissions").test(src); -// +public class ClaimCommand { + public static final int MAX_NAME_LENGTH = 30; + private static void validateCanAccess(ServerPlayerEntity player, Claim claim, boolean admin) throws CommandSyntaxException { + if (claim == null) { + throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); + } -// public static final SuggestionProvider PLAYERS_PROVIDER = (source, builder) -> { -// List strings = new ArrayList<>(); -// for (ServerPlayerEntity player : source.getSource().getMinecraftServer().getPlayerManager().getPlayerList()) { -// strings.add(player.getEntityName()); -// } -// return CommandSource.suggestMatching(strings, builder); -// }; -// public static final SuggestionProvider SETTINGS_PROVIDER = (source, builder) -> { -// List strings = new ArrayList<>(); -// for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { -// strings.add(value.id); -// } -// for (Claim.Permission value : Claim.Permission.values()) { -// strings.add(value.id); -// } -// return CommandSource.suggestMatching(strings, builder); -// }; -// public static final SuggestionProvider PERMISSIONS_PROVIDER = (source, builder) -> { -// List strings = new ArrayList<>(); -// for (Claim.Permission value : Claim.Permission.values()) { -// strings.add(value.id); -// } -// return CommandSource.suggestMatching(strings, builder); -// }; -// public static final SuggestionProvider MESSAGE_EVENTS_PROVIDER = (source, builder) -> { -// List strings = new ArrayList<>(); -// for (Claim.Event value : Claim.Event.values()) { -// strings.add(value.id); -// } -// return CommandSource.suggestMatching(strings, builder); -// }; -// public static final SuggestionProvider EVENT_MESSAGE_PROVIDER = (source, builder) -> { -// if (!builder.getRemaining().isEmpty()) -// return builder.buildFuture(); -// -// List strings = new ArrayList<>(); -// strings.add("reset"); -// try { -// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(source, "claim")); -// Claim.Event eventType = Claim.Event.getById(getString(source, "messageEvent")); -// -// if (eventType != null && claim != null) { -// String message = eventType == Claim.Event.ENTER_CLAIM ? claim.enterMessage : claim.leaveMessage; -// if (message != null) strings.add(message); -// } -// -// } catch (Exception ignored) { -// } -// -// return CommandSource.suggestMatching(strings, builder); -// }; + if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SETTINGS)) { + throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); + } + } -// public static void register(CommandDispatcher dispatcher) { -// LiteralArgumentBuilder main = literal("itsmine"); -// main.executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); -// -// register(main, dispatcher); -// -// LiteralArgumentBuilder alias = literal("claim"); -// alias.executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); -// -// register(alias, dispatcher); -// -// dispatcher.register(main); -// dispatcher.register(alias); -// } + private static void validateClaim(Claim claim) throws CommandSyntaxException { + if (claim == null) throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); + } -// private static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { -// SubzoneCommand.register(command); + private static RequiredArgumentBuilder getClaimArgument() { + return argument("claim", StringArgumentType.word()).suggests(CLAIM_PROVIDER); + } -// { -// LiteralArgumentBuilder help = literal("help"); -// help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); -// -// RequiredArgumentBuilder id = getHelpId(); -// RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); -// -// page.executes((context) -> { -// Claim.HelpBook book = Claim.HelpBook.getById(getString(context, "id")); -// if (book == null) { -// context.getSource().sendError(new LiteralText("Invalid Book!")); -// return -1; -// } -// int p = IntegerArgumentType.getInteger(context, "page"); -// -// if (p > book.texts.length) p = 1; -// return sendPage(context.getSource(), book.texts, p, book.title, book.getCommand()); -// }); -// -// id.then(page); -// help.then(id); -// command.then(help); -// } -// { -// LiteralArgumentBuilder create = literal("create"); -// RequiredArgumentBuilder name = argument("name", word()); -// -// name.executes(context -> { -// ServerPlayerEntity player = context.getSource().getPlayer(); -// Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); -// if (selectedPositions == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); -// } else if (selectedPositions.getLeft() == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); -// } else if (selectedPositions.getRight() == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); -// } else { -// String cname = getString(context, "name"); -// if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), false, null) > 0) { -// ClaimManager.INSTANCE.stickPositions.remove(player); -// } -// } -// return 0; -// }); -// -// ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); -// RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); -// max.executes(context -> createClaim( -// getString(context, "name"), -// context.getSource(), -// BlockPosArgumentType.getBlockPos(context, "min"), -// BlockPosArgumentType.getBlockPos(context, "max"), -// false, -// null -// )); -// min.then(max); -// name.then(min); -// create.then(name); -// command.then(create); -// } -// { -// LiteralArgumentBuilder fly = literal("fly") -// .requires(src -> ItsMine.permissions().hasPermission(src, PermissionUtil.Command.CLAIM_FLY, 2)); -// RequiredArgumentBuilder setArgument = CommandManager.argument("set", BoolArgumentType.bool()); -// -// fly.executes((context) -> setFly(context, !ClaimManager.INSTANCE.flyers.contains(context.getSource().getPlayer().getUuid()))); -// setArgument.executes((context) -> setFly(context, BoolArgumentType.getBool(context, "set"))); -// -// fly.then(setArgument); -// command.then(fly); -// } -// { -// LiteralArgumentBuilder rename = literal("rename"); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); -// RequiredArgumentBuilder nameArgument = argument("name", word()); -// nameArgument.executes((context) -> rename(context, false)); -// claimArgument.then(nameArgument); -// rename.then(claimArgument); -// command.then(rename); -// } -// { -// LiteralArgumentBuilder trusted = literal("trusted"); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); -// trusted.executes((context)-> { -// ServerPlayerEntity player = context.getSource().getPlayer(); -// Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); -// if (claim == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// return showTrustedList(context, claim, false); -// }); -// -// claimArgument.executes((context) -> { -// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (claim == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// return showTrustedList(context, claim, false); -// }); -// trusted.then(claimArgument); -// command.then(trusted); -// dispatcher.register(trusted); -// } -// { -// LiteralArgumentBuilder stick = literal("stick"); -// stick.executes(context -> { -// Pair posPair = ClaimManager.INSTANCE.stickPositions.get(context.getSource().getPlayer()); -// context.getSource().sendFeedback(new LiteralText(posPair == null ? "You can now use a stick to create claims. Run this command again to disable" : "Claim stick disabled. Run this command again to enable").formatted(Formatting.DARK_PURPLE), false); -// if (posPair == null) { -// ClaimManager.INSTANCE.stickPositions.put(context.getSource().getPlayer(), new Pair<>(null, null)); -// } else { -// ClaimManager.INSTANCE.stickPositions.remove(context.getSource().getPlayer()); -// } -// return 0; -// }); -// command.then(stick); -// } -// { -// LiteralArgumentBuilder show = literal("show"); -// show.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().dimension.getType()), false)); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// claim.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "name")), false)); -// show.then(claim); -// command.then(show); -// } -// { -// LiteralArgumentBuilder hide = literal("hide"); -// hide.executes(context -> showClaim(context.getSource(), null, true)); -// command.then(hide); -// } -// { -// LiteralArgumentBuilder check = literal("blocks"); -// RequiredArgumentBuilder other = argument("player", EntityArgumentType.player()); -// other.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); -// other.executes(ctx -> checkPlayer(ctx.getSource(), EntityArgumentType.getPlayer(ctx, "player").getGameProfile().getId())); -// check.then(other); -// check.executes(ctx -> checkPlayer(ctx.getSource(), ctx.getSource().getPlayer().getGameProfile().getId())); -// command.then(check); -// } -// { -// LiteralArgumentBuilder delete = literal("remove"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// LiteralArgumentBuilder confirm = literal("confirm"); -// confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); -// claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); -// claim.then(confirm); -// delete.then(claim); -// delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); -// command.then(delete); -// } -// { -// { -// LiteralArgumentBuilder expand = literal("expand"); -// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); -// RequiredArgumentBuilder direction = getDirections(); -// -// direction.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// IntegerArgumentType.getInteger(context, "distance"), -// directionByName(getString(context, "direction")), -// context.getSource(), -// false -// )); -// -// amount.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// IntegerArgumentType.getInteger(context, "distance"), -// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], -// context.getSource(), -// false -// )); -// -// amount.then(direction); -// expand.then(amount); -// command.then(expand); -// } -// { -// LiteralArgumentBuilder shrink = literal("shrink"); -// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); -// RequiredArgumentBuilder direction = getDirections(); -// -// direction.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// -IntegerArgumentType.getInteger(context, "distance"), -// directionByName(getString(context, "direction")), -// context.getSource(), -// false -// )); -// -// amount.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// -IntegerArgumentType.getInteger(context, "distance"), -// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], -// context.getSource(), -// false -// )); -// -// amount.then(direction); -// shrink.then(amount); -// command.then(shrink); -// } -// } -// { -// LiteralArgumentBuilder delete = literal("remove"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// LiteralArgumentBuilder confirm = literal("confirm"); -// confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); -// claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); -// claim.then(confirm); -// delete.then(claim); -// delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); -// command.then(delete); -// } -// { -// LiteralArgumentBuilder transfer = literal("transfer"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); -// LiteralArgumentBuilder confirm = literal("confirm"); -// confirm.executes(context -> { -// final String string = "-accept-"; -// ServerPlayerEntity p = EntityArgumentType.getPlayer(context, "player"); -// String input = getString(context, "claim"); -// String claimName = input.replace(string, ""); -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(claimName); -// if (claim1 == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// -// if (input.startsWith(string)) { -// return acceptTransfer(context.getSource()); -// } -// -// return transfer(context.getSource(), claim1, p, false); -// }); -// player.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), EntityArgumentType.getPlayer(context, "player"), false)); -// player.then(confirm); -// claim.then(player); -// transfer.then(claim); -// transfer.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), EntityArgumentType.getPlayer(context, "player"), false)); -// command.then(transfer); -// } -// { -// ///claim rentable [] -// LiteralArgumentBuilder rentable = literal("rentable"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// -// RequiredArgumentBuilder currency = CommandManager.argument("item", ItemStackArgumentType.itemStack()).suggests(ClaimCommand::itemsSuggestion); -// RequiredArgumentBuilder amount = CommandManager.argument("count", IntegerArgumentType.integer(1)); -// RequiredArgumentBuilder days = CommandManager.argument("days", StringArgumentType.string() -// ); -// RequiredArgumentBuilder maxdays = CommandManager.argument("maxdays", string()); -// maxdays.executes(context -> makeRentable(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false), IntegerArgumentType.getInteger(context, "count"), getString(context, "days"), getString(context, "maxdays"))); -// claim.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if(claim1.rent.getCurrency() !=null || claim1.rent.getAmount() != 0 || claim1.rent.getRentAbleTime() != 0 || claim1.rent.getMaxrentAbleTime() != 0 && claim1.rent.isRentable()) { -// context.getSource().sendFeedback(new LiteralText("Can't enable rent for " + claim1.name + ", because no values are set").formatted(Formatting.RED), true); -// return 0; -// } -// if(claim1.rent.getTenant() == null){ -// String state = claim1.rent.isRentable() ? "disabled" : "enabled"; -// claim1.rent.setRentable(!claim1.rent.isRentable()); -// context.getSource().sendFeedback(new LiteralText("Renting for " + claim1.name + " has been " + state).formatted(Formatting.GREEN), true); -// return 1; -// } else { -// context.getSource().sendFeedback(new LiteralText("Can't disable rent for " + claim1.name + ", because it is currently being rented").formatted(Formatting.RED), true); -// return 0; -// } -// }); -// -// days.then(maxdays); -// amount.then(days); -// currency.then(amount); -// claim.then(currency); -// rentable.then(claim); -// command.then(rentable); -// } -// { -// LiteralArgumentBuilder rent = literal("rent"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// RequiredArgumentBuilder days = CommandManager.argument("days", string()); -// days.executes(context -> rent(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), getString(context, "days"))); -// -// claim.then(days); -// rent.then(claim); -// command.then(rent); -// } -// { -// LiteralArgumentBuilder info = literal("info"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// info.executes(context -> info( -// context.getSource(), -// ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()) -// )); -// claim.executes(context -> info(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")) -// )); -// info.then(claim); -// command.then(info); -// } -// { -// LiteralArgumentBuilder revenue = literal("revenue"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// RequiredArgumentBuilder claimRevenue = argument("claimRevenue", BoolArgumentType.bool()); -// revenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); -// claim.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); -// claimRevenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); -// claim.then(claimRevenue); -// revenue.then(claim); -// command.then(revenue); -// } -// { -// LiteralArgumentBuilder list = literal("list"); -// LiteralArgumentBuilder listall = literal("listall"); -// RequiredArgumentBuilder player = argument("player", word()); -// player.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); -// player.suggests(PLAYERS_PROVIDER); -// list.executes(context -> list(context.getSource(), context.getSource().getName())); -// listall.executes(context -> listall(context.getSource())); -// player.executes(context -> list(context.getSource(), getString(context, "player"))); -// list.then(player); -// command.then(list); -// command.then(listall); -// -// LiteralArgumentBuilder claims = literal("claims") -// .executes(context -> list(context.getSource(), context.getSource().getName())) -// .then(player); -// dispatcher.register(claims); -// } -// { -// //TODO: FIX THIS + private static Predicate perm(String str) { + return perm(str, 2); + } + private static Predicate perm(String str, int op) { + return source -> ItsMine.permissions().hasPermission(source, "itsmine." + str, op); + } + private static final Predicate PERMISSION_CHECK_ADMIN = src -> perm("admin").test(src) || perm("admin.modify_balance").test(src) || + perm("admin.infinite_blocks").test(src) || perm("admin.modify").test(src) || + perm("admin.modify_balance").test(src) || perm("admin.ignore_claims").test(src) || + perm("admin.modify_permissions").test(src); + + public static final SuggestionProvider DIRECTION_SUGGESTION_BUILDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Direction direction: Direction.values()) { + if (Config.claims2d && (direction == Direction.DOWN || direction == Direction.UP)) continue; + strings.add(direction.getName()); + }; + return CommandSource.suggestMatching(strings, builder); + }; + public static final SuggestionProvider BOOK_SUGGESTIONS = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.HelpBook value : Claim.HelpBook.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; + public static final SuggestionProvider CLAIM_PROVIDER = (source, builder) -> { + ServerPlayerEntity player = source.getSource().getPlayer(); + List names = new ArrayList<>(); + Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + if (current != null) names.add(current.name); + for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { + if (claim != null) { + names.add(claim.name); + } + } + return CommandSource.suggestMatching(names, builder); + }; + public static final SuggestionProvider PLAYERS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (ServerPlayerEntity player : source.getSource().getMinecraftServer().getPlayerManager().getPlayerList()) { + strings.add(player.getEntityName()); + } + return CommandSource.suggestMatching(strings, builder); + }; + public static final SuggestionProvider SETTINGS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { + strings.add(value.id); + } + for (Claim.Permission value : Claim.Permission.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; + public static final SuggestionProvider PERMISSIONS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.Permission value : Claim.Permission.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; + public static final SuggestionProvider MESSAGE_EVENTS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.Event value : Claim.Event.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; + public static final SuggestionProvider EVENT_MESSAGE_PROVIDER = (source, builder) -> { + if (!builder.getRemaining().isEmpty()) + return builder.buildFuture(); + + List strings = new ArrayList<>(); + strings.add("reset"); + try { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(source, "claim")); + Claim.Event eventType = Claim.Event.getById(StringArgumentType.getString(source, "messageEvent")); + + if (eventType != null && claim != null) { + String message = eventType == Claim.Event.ENTER_CLAIM ? claim.enterMessage : claim.leaveMessage; + if (message != null) strings.add(message); + } + + } catch (Exception ignored) { + } + + return CommandSource.suggestMatching(strings, builder); + }; + + public static void register(CommandDispatcher dispatcher) { + LiteralArgumentBuilder main = literal("itsmine") + .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); + + register(main, dispatcher); + + LiteralArgumentBuilder alias = literal("claim") + .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); + + register(alias, dispatcher); + + dispatcher.register(main); + dispatcher.register(alias); + } + + private static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { + SubzoneCommand.register(command, false); + { + LiteralArgumentBuilder help = literal("help"); + help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); + + RequiredArgumentBuilder id = argument("id", StringArgumentType.word()) + .suggests(BOOK_SUGGESTIONS); + RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); + + page.executes((context) -> { + Claim.HelpBook book = Claim.HelpBook.getById(StringArgumentType.getString(context, "id")); + if (book == null) { + context.getSource().sendError(new LiteralText("Invalid Book!")); + return -1; + } + int p = IntegerArgumentType.getInteger(context, "page"); + + if (p > book.texts.length) p = 1; + return sendPage(context.getSource(), book.texts, p, book.title, book.getCommand()); + }); + + id.then(page); + help.then(id); + command.then(help); + } + { + LiteralArgumentBuilder create = literal("create"); + RequiredArgumentBuilder name = argument("name", StringArgumentType.word()); + + name.executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); + if (selectedPositions == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getLeft() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getRight() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); + } else { + String cname = StringArgumentType.getString(context, "name"); + if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), false, null) > 0) { + ClaimManager.INSTANCE.stickPositions.remove(player); + } + } + return 0; + }); + + ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); + RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); + max.executes(context -> createClaim( + StringArgumentType.getString(context, "name"), + context.getSource(), + BlockPosArgumentType.getBlockPos(context, "min"), + BlockPosArgumentType.getBlockPos(context, "max"), + false, + null + )); + min.then(max); + name.then(min); + create.then(name); + command.then(create); + } + { + LiteralArgumentBuilder fly = literal("fly") + .requires(src -> ItsMine.permissions().hasPermission(src, Permissions.Command.CLAIM_FLY, 2)); + RequiredArgumentBuilder setArgument = CommandManager.argument("set", BoolArgumentType.bool()); + + fly.executes((context) -> setFly(context, !ClaimManager.INSTANCE.flyers.contains(context.getSource().getPlayer().getUuid()))); + setArgument.executes((context) -> setFly(context, BoolArgumentType.getBool(context, "set"))); + + fly.then(setArgument); + command.then(fly); + } + { + LiteralArgumentBuilder rename = literal("rename"); + RequiredArgumentBuilder claimArgument = getClaimArgument().suggests(CLAIM_PROVIDER); + RequiredArgumentBuilder nameArgument = argument("name", StringArgumentType.word()); + nameArgument.executes((context) -> rename(context, false)); + claimArgument.then(nameArgument); + rename.then(claimArgument); + command.then(rename); + } + { + LiteralArgumentBuilder trusted = literal("trusted"); + RequiredArgumentBuilder claimArgument = getClaimArgument(); + trusted.executes((context)-> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim, false); + }); + + claimArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim, false); + }); + trusted.then(claimArgument); + command.then(trusted); + dispatcher.register(trusted); + } + { + LiteralArgumentBuilder stick = literal("stick"); + stick.executes(context -> { + Pair posPair = ClaimManager.INSTANCE.stickPositions.get(context.getSource().getPlayer()); + context.getSource().sendFeedback(new LiteralText(posPair == null ? "You can now use a stick to create claims. Run this command again to disable" : "Claim stick disabled. Run this command again to enable").formatted(Formatting.DARK_PURPLE), false); + if (posPair == null) { + ClaimManager.INSTANCE.stickPositions.put(context.getSource().getPlayer(), new Pair<>(null, null)); + } else { + ClaimManager.INSTANCE.stickPositions.remove(context.getSource().getPlayer()); + } + return 0; + }); + command.then(stick); + } + { + LiteralArgumentBuilder show = literal("show"); + show.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().dimension.getType()), false)); + RequiredArgumentBuilder name = argument("name", StringArgumentType.word()); + name.suggests(CLAIM_PROVIDER); + name.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "name")), false)); + show.then(name); + command.then(show); + } + { + LiteralArgumentBuilder hide = literal("hide"); + hide.executes(context -> showClaim(context.getSource(), null, true)); + command.then(hide); + } + { + LiteralArgumentBuilder check = literal("blocks"); + RequiredArgumentBuilder other = argument("player", EntityArgumentType.player()); + other.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_CHECK_OTHERS, 2)); + other.executes(ctx -> checkPlayer(ctx.getSource(), EntityArgumentType.getPlayer(ctx, "player").getGameProfile().getId())); + check.then(other); + check.executes(ctx -> checkPlayer(ctx.getSource(), ctx.getSource().getPlayer().getGameProfile().getId())); + command.then(check); + } + { + LiteralArgumentBuilder delete = literal("remove"); + RequiredArgumentBuilder claim = getClaimArgument(); + claim.suggests(CLAIM_PROVIDER); + LiteralArgumentBuilder confirm = literal("confirm"); + confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); + claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); + claim.then(confirm); + delete.then(claim); + delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); + command.then(delete); + } + { + { + LiteralArgumentBuilder expand = literal("expand"); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); + direction.suggests(DIRECTION_SUGGESTION_BUILDER); + + direction.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + IntegerArgumentType.getInteger(context, "distance"), + directionByName(StringArgumentType.getString(context, "direction")), + context.getSource(), + false + )); + + amount.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + IntegerArgumentType.getInteger(context, "distance"), + Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], + context.getSource(), + false + )); + + amount.then(direction); + expand.then(amount); + command.then(expand); + } + { + LiteralArgumentBuilder shrink = literal("shrink"); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); + direction.suggests(DIRECTION_SUGGESTION_BUILDER); + + direction.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + -IntegerArgumentType.getInteger(context, "distance"), + directionByName(StringArgumentType.getString(context, "direction")), + context.getSource(), + false + )); + + amount.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + -IntegerArgumentType.getInteger(context, "distance"), + Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], + context.getSource(), + false + )); + + amount.then(direction); + shrink.then(amount); + command.then(shrink); + } + } + { + LiteralArgumentBuilder delete = literal("remove"); + RequiredArgumentBuilder claim = getClaimArgument(); + LiteralArgumentBuilder confirm = literal("confirm"); + confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); + claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); + claim.then(confirm); + delete.then(claim); + delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); + command.then(delete); + } + { + LiteralArgumentBuilder transfer = literal("transfer"); + RequiredArgumentBuilder claim = argument("claim", StringArgumentType.word()).suggests(CLAIM_PROVIDER); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); + LiteralArgumentBuilder confirm = literal("confirm"); + confirm.executes(context -> { + final String string = "-accept-"; + ServerPlayerEntity p = EntityArgumentType.getPlayer(context, "player"); + String input = StringArgumentType.getString(context, "claim"); + String claimName = input.replace(string, ""); + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(claimName); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + + if (input.startsWith(string)) { + return acceptTransfer(context.getSource()); + } + + return transfer(context.getSource(), claim1, p, false); + }); + player.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), EntityArgumentType.getPlayer(context, "player"), false)); + player.then(confirm); + claim.then(player); + transfer.then(claim); + transfer.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), EntityArgumentType.getPlayer(context, "player"), false)); + command.then(transfer); + } + { + LiteralArgumentBuilder info = literal("info"); + RequiredArgumentBuilder claim = getClaimArgument(); + info.executes(context -> info( + context.getSource(), + ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()) + )); + claim.executes(context -> info( + context.getSource(), + ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")) + )); + info.then(claim); + command.then(info); + } + { + LiteralArgumentBuilder list = literal("list"); + LiteralArgumentBuilder listall = literal("listall"); + RequiredArgumentBuilder player = argument("player", StringArgumentType.word()); + player.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_CHECK_OTHERS, 2)); + player.suggests(PLAYERS_PROVIDER); + list.executes(context -> list(context.getSource(), context.getSource().getName())); + listall.executes(context -> listall(context.getSource())); + player.executes(context -> list(context.getSource(), StringArgumentType.getString(context, "player"))); + list.then(player); + command.then(list); + command.then(listall); + + LiteralArgumentBuilder claims = literal("claims") + .executes(context -> list(context.getSource(), context.getSource().getName())) + .then(player); + dispatcher.register(claims); + } + { + //TODO: FIX THIS // LiteralArgumentBuilder listall = literal("listall"); // RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); // @@ -441,1466 +471,1211 @@ // page.executes(context -> listAll(context.getSource(), IntegerArgumentType.getInteger(context, "page"))); // listall.then(page); // command.then(listall); -// } -// { -// LiteralArgumentBuilder trust = literal("trust"); -// RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); -// playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, null))); -// claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, getString(context, "claim")))); -// -// playerArgument.then(claimArgument); -// trust.then(playerArgument); -// command.then(trust); -// dispatcher.register(trust); -// } -// { -// LiteralArgumentBuilder distrust = literal("distrust"); -// RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); -// -// playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, null))); -// claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, getString(context, "claim")))); -// -// playerArgument.then(claimArgument); -// distrust.then(playerArgument); -// command.then(distrust); -// dispatcher.register(distrust); -// } + } + { + LiteralArgumentBuilder trust = literal("trust"); + RequiredArgumentBuilder playerArgument = argument("player", EntityArgumentType.player()); + RequiredArgumentBuilder claimArgument = getClaimArgument(); -// createExceptionCommand(command, false); -// -// { -// LiteralArgumentBuilder admin = literal("admin"); -// admin.requires(PERMISSION_CHECK_ADMIN); -// { -// LiteralArgumentBuilder entity = literal("entities"); -// entity.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// entity.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); -// context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); -// claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { -// context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); -// }); -// return 1; -// }); -// claim.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); -// claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { -// context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); -// }); -// return 1; -// }); -// entity.then(claim); -// admin.then(entity); -// } -// { -// LiteralArgumentBuilder add = literal("addBlocks"); -// add.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); -// RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); -// RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); -// amount.executes(context -> { -// ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); -// context.getSource().sendFeedback(new LiteralText("Gave " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); -// return 0; -// }); -// player.then(amount); -// add.then(player); -// admin.then(add); -// } -// { -// LiteralArgumentBuilder set = literal("setOwner"); -// RequiredArgumentBuilder newOwner = argument("newOwner", GameProfileArgumentType.gameProfile()); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); -// -// newOwner.executes((context) -> { -// Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); -// if (claim == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// -// Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); -// -// if (profiles.size() > 1) { -// context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); -// return -1; -// } -// return setOwner(context.getSource(), claim, profiles.iterator().next()); -// }); -// -// claimArgument.executes((context) -> { -// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (claim == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// -// Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); -// -// if (profiles.size() > 1) { -// context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); -// return -1; -// } -// return setOwner(context.getSource(), claim, profiles.iterator().next()); -// }); -// -// newOwner.then(claimArgument); -// set.then(newOwner); -// admin.then(set); -// } -// { -// LiteralArgumentBuilder set = literal("setOwnerName"); -// RequiredArgumentBuilder nameArgument = argument("newName", word()); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); -// -// nameArgument.executes((context) -> { -// Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); -// if (claim == null) { -// context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return -1; -// } -// return setOwnerName(context.getSource(), claim, getString(context, "newName")); -// }); -// -// claimArgument.executes((context) -> { -// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (claim == null) { -// context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return -1; -// } -// return setOwnerName(context.getSource(), claim, getString(context, "newName")); -// }); -// -// nameArgument.then(claimArgument); -// set.then(nameArgument); -// admin.then(set); -// } -// { -// LiteralArgumentBuilder rename = literal("rename"); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaimsSubzones(); -// RequiredArgumentBuilder nameArgument = argument("name", word()); -// nameArgument.executes((context) -> rename(context, true)); -// claimArgument.then(nameArgument); -// rename.then(claimArgument); -// admin.then(rename); -// } -// { -// LiteralArgumentBuilder remove = literal("removeBlocks"); -// remove.requires(source ->ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); -// RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); -// RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); -// amount.executes(context -> { -// ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), -IntegerArgumentType.getInteger(context, "amount")); -// context.getSource().sendFeedback(new LiteralText("Took " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); -// return 0; -// }); -// player.then(amount); -// remove.then(player); -// admin.then(remove); -// } -// { -// LiteralArgumentBuilder set = literal("setBlocks"); -// set.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); -// RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); -// RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); -// amount.executes(context -> { -// ClaimManager.INSTANCE.setClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); -// context.getSource().sendFeedback(new LiteralText("Set claim block amount to " + IntegerArgumentType.getInteger(context, "amount")).formatted(Formatting.GREEN), true); -// return 0; -// }); -// player.then(amount); -// set.then(player); -// admin.then(set); -// } -// { -// LiteralArgumentBuilder delete = literal("remove"); -// delete.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// LiteralArgumentBuilder confirm = literal("confirm"); -// confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); -// claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); -// claim.then(confirm); -// delete.then(claim); -// delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), true)); -// admin.then(delete); -// } -// { -// LiteralArgumentBuilder create = literal("create"); -// create.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2)); -// ArgumentBuilder name = argument("name", word()); -// ArgumentBuilder customOwner = argument("customOwnerName", word()); -// ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); -// RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); -// max.executes(context -> createClaim( -// getString(context, "name"), -// context.getSource(), -// BlockPosArgumentType.getBlockPos(context, "min"), -// BlockPosArgumentType.getBlockPos(context, "max"), -// true, -// null -// )); -// name.executes(context -> { -// ServerPlayerEntity player = context.getSource().getPlayer(); -// Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); -// if (selectedPositions == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); -// } else if (selectedPositions.getLeft() == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); -// } else if (selectedPositions.getRight() == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); -// } else { -// String cname = getString(context, "name"); -// if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, null) > 0) { -// ClaimManager.INSTANCE.stickPositions.remove(player); -// } -// } -// return 0; -// }); -// customOwner.executes(context -> { -// ServerPlayerEntity player = context.getSource().getPlayer(); -// Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); -// if (selectedPositions == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); -// } else if (selectedPositions.getLeft() == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); -// } else if (selectedPositions.getRight() == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); -// } else { -// String cname = getString(context, "name"); -// if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, getString(context, "customOwnerName")) > 0) { -// ClaimManager.INSTANCE.stickPositions.remove(player); -// } -// } -// return 0; -// }); -// min.then(max); -// name.then(customOwner); -// name.then(min); -// create.then(name); -// admin.then(create); -// } -// { -// LiteralArgumentBuilder ignore = literal("ignoreClaims"); -// ignore.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_IGNORE_CLAIMS, 2)); -// ignore.executes(context -> { -// UUID id = context.getSource().getPlayer().getGameProfile().getId(); -// boolean isIgnoring = ClaimManager.INSTANCE.ignoringClaims.contains(id); -// if (isIgnoring) ClaimManager.INSTANCE.ignoringClaims.remove(id); -// else ClaimManager.INSTANCE.ignoringClaims.add(id); -// context.getSource().sendFeedback(new LiteralText("You are " + (isIgnoring ? "no longer" : "now") + " ignoring claims.").formatted(Formatting.GREEN), false); -// return 0; -// }); -// admin.then(ignore); -// } -// { -// { -// LiteralArgumentBuilder expand = literal("expand"); -// expand.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); -// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); -// RequiredArgumentBuilder direction = getDirections(); -// -// direction.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// IntegerArgumentType.getInteger(context, "distance"), -// directionByName(getString(context, "direction")), -// context.getSource(), -// true -// )); -// -// amount.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// IntegerArgumentType.getInteger(context, "distance"), -// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], -// context.getSource(), -// true -// )); -// -// amount.then(direction); -// expand.then(amount); -// admin.then(expand); -// } -// { -// LiteralArgumentBuilder shrink = literal("shrink"); -// shrink.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); -// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); -// RequiredArgumentBuilder direction = getDirections(); -// -// direction.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// -IntegerArgumentType.getInteger(context, "distance"), -// directionByName(getString(context, "direction")), -// context.getSource(), -// true -// )); -// -// amount.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// -IntegerArgumentType.getInteger(context, "distance"), -// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], -// context.getSource(), -// true -// )); -// -// amount.then(direction); -// shrink.then(amount); -// admin.then(shrink); -// } -// } -// createExceptionCommand(admin, true); -// command.then(admin); -// } -// } + playerArgument.executes((context -> executeTrust(context, EntityArgumentType.getPlayer(context, "player"), true, null))); + claimArgument.executes((context -> executeTrust(context, EntityArgumentType.getPlayer(context, "player"), true, StringArgumentType.getString(context, "claim")))); -// private static int sendPage(ServerCommandSource source, Text[] text, int page, String title, String command) { -// int prevPage = page - 2; -// int thisPage = page - 1; -// int nextPage = page + 1; -// final String SEPARATOR = "-----------------------------------------------------"; -// Text header = new LiteralText("") -// .append(new LiteralText("- [ ").formatted(Formatting.GRAY)) -// .append(new LiteralText(title).formatted(Formatting.GOLD)) -// .append(" ] ") -// .append(SEPARATOR.substring(ChatColor.removeAlternateColorCodes('&', title).length() + 4)) -// .formatted(Formatting.GRAY); -// -// Text button_prev = new LiteralText("") -// .append(new LiteralText("<-").formatted(Formatting.WHITE, Formatting.BOLD)) -// .append(" ").append(new LiteralText("Prev").formatted(Formatting.GOLD)) -// .styled((style) -> { -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); -// if (prevPage >= 0) -// style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); -// }); -// -// Text button_next = new LiteralText("") -// .append(new LiteralText("Next").formatted(Formatting.GOLD)) -// .append(" ").append(new LiteralText("->").formatted(Formatting.WHITE, Formatting.BOLD)).append(" ") -// .styled((style) -> { -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); -// if (nextPage <= text.length) -// style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); -// }); -// -// Text buttons = new LiteralText("") -// .append(new LiteralText("[ ").formatted(Formatting.GRAY)) -// .append(button_prev) -// .append(" ") -// .append( -// new LiteralText(String.valueOf(page)).formatted(Formatting.GREEN) -// .append(new LiteralText("/").formatted(Formatting.GRAY)) -// .append(new LiteralText(String.valueOf(text.length)).formatted(Formatting.GREEN)) -// ) -// .append(" ") -// .append(button_next) -// .append(new LiteralText("] ").formatted(Formatting.GRAY)); -// -// Text footer = new LiteralText("- ") -// .formatted(Formatting.GRAY) -// .append(buttons).append(new LiteralText(" ------------------------------").formatted(Formatting.GRAY)); -// -// header.append("\n").append(text[thisPage]).append("\n").append(footer); -// source.sendFeedback(header, false); -// return 1; -// } + playerArgument.then(claimArgument); + trust.then(playerArgument); + command.then(trust); + dispatcher.register(trust); + } + { + LiteralArgumentBuilder distrust = literal("distrust"); + RequiredArgumentBuilder playerArgument = argument("player", EntityArgumentType.entity()); + RequiredArgumentBuilder claimArgument = getClaimArgument(); -// private static void createExceptionCommand(LiteralArgumentBuilder command, boolean admin) { -// { -// LiteralArgumentBuilder settings = literal("settings"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// -// if (!admin) { -// settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); -// -// claim.executes((context) -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (claim1 == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// return querySettings(context.getSource(), claim1); -// }); -// } -// -// RequiredArgumentBuilder id = argument("setting", word()).suggests(SETTINGS_PROVIDER); -// RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); -// -// id.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), getString(context, "claim"), true, false, admin)); -// set.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); -// -// id.then(set); -// claim.then(id); -// settings.then(claim); -// command.then(settings); -// } -// -// LiteralArgumentBuilder exceptions = literal("permissions"); -// if (admin) exceptions.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_PERMISSIONS, 2)); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// if (!admin) { -// exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); -// -// claim.executes((context) -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (claim1 == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// return showTrustedList(context, claim1, false); -// }); -// } -// -// if (!admin) { -// claim.executes((context) -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (claim1 == null) { -// context.getSource().sendError(new LiteralText("That claim does not exist")); -// return -1; -// } -// return showTrustedList(context, claim1, true); -// }); -// } -// -// { -// RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); -// LiteralArgumentBuilder remove = literal("remove"); -// remove.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { -// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); -// claim1.permissionManager.resetPermissions(player1.getGameProfile().getId()); -// context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + " no longer has an exception in the claim").formatted(Formatting.YELLOW), false); -// } -// return 0; -// }); -// player.then(remove); -// LiteralArgumentBuilder all = literal("*"); -// RequiredArgumentBuilder allstate = argument("allow", BoolArgumentType.bool()); -// allstate.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); -// validateClaim(claim1); -// return setTrust(context, claim1, player1.getGameProfile(), BoolArgumentType.getBool(context, "allow"), admin); -// }); -// all.then(allstate); -// player.then(all); -// for (Claim.Permission value : Claim.Permission.values()) { -// LiteralArgumentBuilder permNode = literal(value.id); -// RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); -// allow.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { -// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); -// boolean permission = BoolArgumentType.getBool(context, "allow"); -// modifyException(claim1, player1, value, permission); -// context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has the permission " + value.name).formatted(Formatting.YELLOW), false); -// } -// return 0; -// }); -// permNode.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { -// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); -// boolean permission = hasPermission(claim1, player1, value); -// context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); -// } -// return 0; -// }); -// permNode.then(allow); -// player.then(permNode); -// } -// claim.then(player); -// } -// { -// LiteralArgumentBuilder message = literal("message"); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); -// RequiredArgumentBuilder messageEvent = argument("messageEvent", word()) -// .suggests(MESSAGE_EVENTS_PROVIDER); -// RequiredArgumentBuilder messageArgument = argument("message", greedyString()) -// .suggests(EVENT_MESSAGE_PROVIDER); -// -// messageArgument.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (verifyPermission(claim1, Claim.Permission.MODIFY_PROPERTIES, context, admin)) { -// Claim.Event event = Claim.Event.getById(getString(context, "messageEvent")); -// -// if (event == null) { -// context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); -// return -1; -// } -// -// return setEventMessage(context.getSource(), claim1, event, getString(context, "message")); -// } -// -// return -1; -// }); -// -// messageEvent.then(messageArgument); -// claimArgument.then(messageEvent); -// message.then(claimArgument); -// command.then(message); -// } -// -// -// exceptions.then(claim); -// command.then(exceptions); -// } -// private static boolean verifyPermission(Claim claim, Claim.Permission permission, CommandContext context, boolean admin) throws CommandSyntaxException { -// if (verifyExists(claim, context)) { -// if (claim.permissionManager.hasPermission(context.getSource().getPlayer().getGameProfile().getId(), permission)) { -// return true; -// } else { -// context.getSource().sendFeedback(new LiteralText(admin ? "You are modifying a claim using admin privileges" : "You cannot modify exceptions for this claim").formatted(admin ? Formatting.DARK_RED : Formatting.RED), false); -// return admin; -// } -// } else { -// return false; -// } -// } -// private static boolean verifyExists(Claim claim, CommandContext context) { -// if (claim == null) { -// context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return false; -// } else { -// return true; -// } -// } + playerArgument.executes((context -> executeTrust(context, EntityArgumentType.getEntity(context, "player"), false, null))); + claimArgument.executes((context -> executeTrust(context, EntityArgumentType.getEntity(context, "player"), false, StringArgumentType.getString(context, "claim")))); -// private static int makeRentable(ServerCommandSource source, Claim claim, ItemStack item, int amount, String rentString, String maxrentString) throws CommandSyntaxException { -// int rentTime = TimeUtil.convertStringtoSeconds(rentString); -// int maxrentTime = TimeUtil.convertStringtoSeconds(maxrentString); -// if(claim != null){ -// if(rentTime <= maxrentTime){ -// Claim.Rent rent = claim.rent; -// rent.setRentable(true); -// item.setCount(amount); -// rent.setCurrency(item); -// rent.setRentAbleTime(rentTime); -// if(maxrentTime > Config.rent_maxseconds) maxrentTime = Config.rent_maxseconds; -// rent.setMaxrentAbleTime(maxrentTime); -// source.sendFeedback(new LiteralText("Claim " + claim.name + " can now be rented for " + amount + " " + item.getName().asString() + " every " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); -// return 1; -// } -// } -// return 0; -// } + playerArgument.then(claimArgument); + distrust.then(playerArgument); + command.then(distrust); + dispatcher.register(distrust); + } -// private static int rent(ServerCommandSource source, Claim claim, String rentString) throws CommandSyntaxException { -// if(claim == null){ -// source.sendFeedback(Messages.INVALID_CLAIM, true); -// return 0; -// } -// int rentTime = (int) TimeUtil.convertStringtoSeconds(rentString); -// int rentAbleTime = claim.rent.getRentAbleTime(); -// int maxrentAbleTime = claim.rent.getMaxrentAbleTime(); -// ItemStack currency = claim.rent.getCurrency(); -// ItemStack handItem = source.getPlayer().inventory.getMainHandStack(); -// ItemStack revenue = handItem.copy(); -// if(rentTime % claim.rent.getRentAbleTime() != 0){ -// source.sendFeedback(new LiteralText("You have to rent this claim for a time by a multiple of " + TimeUtil.convertSecondsToString(rentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); -// return 0; -// } -// int rentAmount = rentTime / claim.rent.getRentAbleTime(); -// if(currency.getItem() != handItem.getItem() || handItem.getCount() < claim.rent.getAmount() * rentAmount){ -// source.sendFeedback(new LiteralText("You don't have enough " + currency.getName().asString()).formatted(Formatting.RED), true); -// return 0; -// } -// if (!claim.rent.isRentable()) { -// source.sendFeedback(new LiteralText(claim.name + " is not for rent").formatted(Formatting.RED), true); -// return 0; -// } -// if (rentTime > claim.rent.getMaxrentAbleTime()) { -// source.sendFeedback(new LiteralText("You can't rent this claim for longer than " + TimeUtil.convertSecondsToString(maxrentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); -// return 0; -// } -// if(claim.rent.getTenant() == null){ -// //Setup for claim rent -// claim.rent.setTenant(source.getPlayer().getUuid()); -// claim.rent.setRentedUntil(claim.rent.getUnixTime() + rentTime); -// //Remove items from player -// handItem.setCount(handItem.getCount() - claim.rent.getAmount() * rentAmount); -// revenue.setCount(claim.rent.getAmount() * rentAmount); -// claim.rent.addRevenue(revenue); -// //Give Permissions to Tenant -// claim.permissionManager.playerPermissions.put(source.getPlayer().getUuid(), new Claim.InvertedPermissionMap()); -// source.sendFeedback(new LiteralText("Renting " + claim.name + " for " + claim.rent.getAmount() * rentAmount + " " + claim.rent.getCurrency().getName().asString() + " for " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); -// return 1; -// } else if(claim.rent.getTenant().toString().equalsIgnoreCase(source.getPlayer().getUuid().toString())){ -// if (claim.rent.getRentTimeLeft() + rentTime <= maxrentAbleTime) { -// //Setup for claim rent -// claim.rent.setRentedUntil(claim.rent.getUnixTime() + rentTime + claim.rent.getRentTimeLeft()); -// //Remove items from player -// handItem.setCount(handItem.getCount() - claim.rent.getAmount() * rentAmount); -// -// revenue.setCount(claim.rent.getAmount() * rentAmount); -// claim.rent.addRevenue(revenue); -// //Give Permissions to Tenant -// source.sendFeedback(new LiteralText("Extended rent " + claim.name + " by " + TimeUtil.convertSecondsToString(rentTime, '2', 'a') + "for " + claim.rent.getAmount() * rentAmount + " " + claim.rent.getCurrency().getName().asString()).formatted(Formatting.GREEN), true); -// return 1; -// } else { -// source.sendFeedback(new LiteralText("Rent would exceed the limit by " + TimeUtil.convertSecondsToString(claim.rent.getRentTimeLeft() + rentTime - maxrentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); -// return 0; -// } -// } else { -// source.sendFeedback(new LiteralText("This claim is already rented").formatted(Formatting.RED), true); -// return 0; -// } -// } + createExceptionCommand(command, false); + { + LiteralArgumentBuilder admin = literal("admin"); + admin.requires(PERMISSION_CHECK_ADMIN); + { + LiteralArgumentBuilder add = literal("addBlocks"); + add.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_BALANCE, 2)); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); + RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); + amount.executes(context -> { + ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); + context.getSource().sendFeedback(new LiteralText("Gave " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); + return 0; + }); + player.then(amount); + add.then(player); + admin.then(add); + } + { + LiteralArgumentBuilder set = literal("setOwner"); + RequiredArgumentBuilder newOwner = argument("newOwner", GameProfileArgumentType.gameProfile()); + RequiredArgumentBuilder claimArgument = getClaimArgument(); + newOwner.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } -// public static int showClaim(ServerCommandSource source, Claim claim, boolean reset) throws CommandSyntaxException { -// ServerPlayerEntity player = source.getPlayer(); -// if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!Config.claims2d &&((ClaimShower)player).getShownClaim() != claim)) showClaim(source, ((ClaimShower)player).getShownClaim(), true); -// if (reset && ((ClaimShower)player).getShownClaim() != null) claim = ((ClaimShower)player).getShownClaim(); -// if (claim != null) { -// if (!claim.dimension.equals(source.getWorld().getDimension().getType())) { -// if (claim == ((ClaimShower)player).getShownClaim()) ((ClaimShower)player).setShownClaim(null); // just so we dont have extra packets on this -// source.sendFeedback(new LiteralText("That claim is not in this dimension").formatted(Formatting.RED), false); -// return 0; -// } -// source.sendFeedback(new LiteralText((!reset ? "Showing" : "Hiding") + " claim: " + claim.name).formatted(Formatting.GREEN), false); -// if(claim.isChild) silentHideShow(player, ClaimUtil.getParentClaim(claim), reset, true); -// else silentHideShow(player, claim, reset, true); -// -// } else { -// source.sendFeedback(new LiteralText("That is not a valid claim").formatted(Formatting.RED), false); -// } -// return 0; -// } + Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); -// private static int createClaim(String name, ServerCommandSource owner, BlockPos posA, BlockPos posB, boolean admin, @Nullable String cOwnerName) throws CommandSyntaxException { -// if (name.length() > MAX_NAME_LENGTH) { -// owner.sendError(Messages.MSG_LONG_NAME); -// return -1; -// } -// if(!name.matches("[A-Za-z0-9]+")){ -// owner.sendError(new LiteralText("Invalid claim name")); -// return -1; -// } -// UUID ownerID = owner.getPlayer().getGameProfile().getId(); -// int x, y = 0, z, mx, my = 255, mz; -// if (posA.getX() > posB.getX()) { -// x = posB.getX(); -// mx = posA.getX(); -// } else { -// x = posA.getX(); -// mx = posB.getX(); -// } -// if (!Config.claims2d) { -// if (posA.getY() > posB.getY()) { -// y = posB.getY(); -// my = posA.getY(); -// } else { -// y = posA.getY(); -// my = posB.getY(); -// } -// } -// if (posA.getZ() > posB.getZ()) { -// z = posB.getZ(); -// mz = posA.getZ(); -// } else { -// z = posA.getZ(); -// mz = posB.getZ(); -// } -// BlockPos min = new BlockPos(x, y, z); -// BlockPos max = new BlockPos(mx, my, mz); -// BlockPos sub = max.subtract(min); -// sub = sub.add(1, Config.claims2d ? 0 : 1,1); -// int subInt = sub.getX() * (Config.claims2d ? 1 : sub.getY()) * sub.getZ(); -// -// Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos(), false); -// if (cOwnerName != null) claim.customOwnerName = cOwnerName; -// claim.permissionManager.playerPermissions.put(ownerID, new Claim.InvertedPermissionMap()); -// if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { -// if (!ClaimManager.INSTANCE.wouldIntersect(claim)) { -// // works because only the first statement is evaluated if true -// if ((admin && ItsMine.permissions().hasPermission(owner, PermissionUtil.Command.INFINITE_BLOCKS, 2)) || ClaimManager.INSTANCE.useClaimBlocks(ownerID, subInt)) { -// ClaimManager.INSTANCE.addClaim(claim); -// owner.sendFeedback(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)).append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").setStyle(new Style() -// .setColor(Formatting.GREEN).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))))), false); -// checkPlayer(owner, owner.getPlayer().getGameProfile().getId()); -// showClaim(owner, claim, false); -// if (admin) -// owner.getMinecraftServer().sendMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); -// return 1; -// } else { -// owner.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + subInt + "(" + (subInt - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); -// } -// } else { -// owner.sendFeedback(new LiteralText("Your claim would overlap with another claim").formatted(Formatting.RED), false); -// } -// } else { -// owner.sendFeedback(new LiteralText("The name \"" + name + "\" is already taken.").formatted(Formatting.RED), false); -// } -// return 0; -// } -// private static int checkPlayer(ServerCommandSource ret, UUID player) throws CommandSyntaxException { -// int blocks = ClaimManager.INSTANCE.getClaimBlocks(player); -// ret.sendFeedback(new LiteralText((ret.getPlayer().getGameProfile().getId().equals(player) ? "You have " : "They have ") + blocks + " blocks left").setStyle(new Style() -// .setColor(Formatting.YELLOW)), false); -// return 0; -// } -// private static int requestDelete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { -// if (claim == null) { -// sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return 0; -// } -// if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { -// if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { -// sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); -// } else { -// sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); -// return 0; -// } -// } -// sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to delete the claim \"" + claim.name + "\"? ").formatted(Formatting.GOLD)) -// .append(new LiteralText("[I'M SURE]").setStyle(new Style() -// .setColor(Formatting.DARK_RED) -// .setBold(true) -// .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")))), false); -// return 0; -// } -// private static int delete(ServerCommandSource source, Claim claim, boolean admin) throws CommandSyntaxException { -// ServerWorld world = source.getWorld(); -// if (claim == null) { -// source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return 0; -// } -// if (!claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { -// if (admin && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)) { -// source.sendFeedback(new LiteralText("Deleting a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); -// } else { -// source.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); -// return 0; -// } -// } -// if(!claim.isChild){ -// ClaimManager.INSTANCE.releaseBlocksToOwner(claim); -// ShowerUtil.update(claim, world, true); -// ClaimManager.INSTANCE.claimsByName.remove(claim.name); -// for(Claim subzone : claim.children){ -// ClaimManager.INSTANCE.claimsByName.remove(subzone.name); -// } -// }else{ -// Claim parent = ClaimUtil.getParentClaim(claim); -// ShowerUtil.update(parent, world, true); -// ClaimUtil.getParentClaim(claim).removeSubzone(claim); -// ClaimManager.INSTANCE.claimsByName.remove(claim.name); -// ShowerUtil.update(parent, world, false); -// } -// source.getWorld().getPlayers().forEach(playerEntity -> { -// if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true); -// }); -// source.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)); -// return 0; -// } + if (profiles.size() > 1) { + context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); + return -1; + } + return setOwner(context.getSource(), claim, profiles.iterator().next()); + }); + claimArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } -// private static int requestTransfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { -// if (claim == null) { -// sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return 0; -// } -// if(claim.isChild){ -// sender.sendFeedback(new LiteralText("You can't transfer ownership of subzones").formatted(Formatting.RED), false); -// return 0; -// } -// if(sender.getPlayer().getUuidAsString().equalsIgnoreCase(player.getUuidAsString())){ -// sender.sendFeedback(new LiteralText("Huh? That makes no sence").formatted(Formatting.RED), true); -// return 0; -// } -// if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { -// if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { -// sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); -// } else { -// sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); -// return 0; -// } -// } -// sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to transfer ownership of \"" + claim.name + "\" to " + player.getGameProfile().getName() + "? ").formatted(Formatting.GOLD)) -// .append(new LiteralText("[YES]").setStyle(new Style() -// .setColor(Formatting.DARK_RED) -// .setBold(true) -// .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")))), false); -// return 0; -// } -// private static Map pendingClaimTransfers = new HashMap<>(); -// private static int transfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { -// if (claim == null) { -// sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return 0; -// } -// if(claim.isChild){ -// sender.sendFeedback(new LiteralText("You can't transfer ownership of subzones").formatted(Formatting.RED), false); -// return 0; -// } -// if(sender.getPlayer().getUuidAsString().equalsIgnoreCase(player.getUuidAsString())){ -// sender.sendFeedback(new LiteralText("Huh? That makes no sence").formatted(Formatting.RED), true); -// return 0; -// } -// if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { -// if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { -// sender.sendFeedback(new LiteralText("Transfering ownership of a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); -// } else { -// sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); -// return 0; -// } -// } -// -// GameProfile profile = sender.getWorld().getServer().getUserCache().getByUuid(claim.claimBlockOwner); -// sender.sendFeedback(new LiteralText("Transferring ownership of the claim \"" + claim.name + "\" to " + player.getGameProfile().getName() + " if they accept").formatted(Formatting.GREEN), claim.claimBlockOwner != player.getGameProfile().getId()); -// player.sendMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) -// .append(new LiteralText("[ACCEPT]").setStyle(new Style() -// .setColor(Formatting.GREEN) -// .setBold(true) -// .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim transfer -accept-" + claim.name + " " + player.getEntityName() + " confirm"))))); -// pendingClaimTransfers.put(player.getGameProfile().getId(), claim.name); -// return 0; -// } -// public static int acceptTransfer(ServerCommandSource sender) throws CommandSyntaxException { -// Claim claim = ClaimManager.INSTANCE.claimsByName.get(pendingClaimTransfers.get(sender.getPlayer().getGameProfile().getId())); -// if (claim == null) { -// sender.sendFeedback(new LiteralText("You have no pending claim transfers").formatted(Formatting.RED), false); -// return 0; -// } -// if (sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner) != null) { -// sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); -// } -// Claim.ClaimPermissionMap op = claim.permissionManager.playerPermissions.get(claim.claimBlockOwner); -// claim.permissionManager.playerPermissions.put(claim.claimBlockOwner, claim.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); -// claim.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op); -// claim.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); -// claim.children.forEach(subzone -> { -// try { -// Claim.ClaimPermissionMap op1 = subzone.permissionManager.playerPermissions.get(subzone.claimBlockOwner); -// subzone.permissionManager.playerPermissions.put(subzone.claimBlockOwner, subzone.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); -// subzone.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op1); -// subzone.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); -// } catch (CommandSyntaxException e) { -// e.printStackTrace(); -// } -// }); -// return 0; -// } -// private static int modifyException(Claim claim, ServerPlayerEntity exception, Claim.Permission permission, boolean allowed) { -// claim.permissionManager.setPermission(exception.getGameProfile().getId(), permission, allowed); -// return 0; -// } -// private static int modifyException(Claim claim, String exception, Claim.Permission permission, boolean allowed) { -// claim.permissionManager.setPermission(exception, permission, allowed); -// return 0; -// } -// private static boolean hasPermission(Claim claim, ServerPlayerEntity exception, Claim.Permission permission) { -// return claim.permissionManager.hasPermission(exception.getGameProfile().getId(), permission); -// } + Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); + + if (profiles.size() > 1) { + context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); + return -1; + } + return setOwner(context.getSource(), claim, profiles.iterator().next()); + }); + + newOwner.then(claimArgument); + set.then(newOwner); + admin.then(set); + } + { + LiteralArgumentBuilder set = literal("setOwnerName"); + RequiredArgumentBuilder nameArgument = argument("newName", StringArgumentType.word()); + RequiredArgumentBuilder claimArgument = getClaimArgument(); + + nameArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); + if (claim == null) { + context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return -1; + } + return setOwnerName(context.getSource(), claim, StringArgumentType.getString(context, "newName")); + }); + + claimArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (claim == null) { + context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return -1; + } + return setOwnerName(context.getSource(), claim, StringArgumentType.getString(context, "newName")); + }); + + nameArgument.then(claimArgument); + set.then(nameArgument); + admin.then(set); + } + { + LiteralArgumentBuilder rename = literal("rename"); + RequiredArgumentBuilder claimArgument = argument("claim", StringArgumentType.word()) + .suggests(CLAIM_PROVIDER); + RequiredArgumentBuilder nameArgument = argument("name", StringArgumentType.word()); + nameArgument.executes((context) -> rename(context, true)); + claimArgument.then(nameArgument); + rename.then(claimArgument); + admin.then(rename); + } + { + LiteralArgumentBuilder remove = literal("removeBlocks"); + remove.requires(source ->ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_BALANCE, 2)); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); + RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); + amount.executes(context -> { + ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), -IntegerArgumentType.getInteger(context, "amount")); + context.getSource().sendFeedback(new LiteralText("Took " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); + return 0; + }); + player.then(amount); + remove.then(player); + admin.then(remove); + } + { + LiteralArgumentBuilder set = literal("setBlocks"); + set.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_BALANCE, 2)); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); + RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); + amount.executes(context -> { + ClaimManager.INSTANCE.setClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); + context.getSource().sendFeedback(new LiteralText("Set claim block amount to " + IntegerArgumentType.getInteger(context, "amount")).formatted(Formatting.GREEN), true); + return 0; + }); + player.then(amount); + set.then(player); + admin.then(set); + } + { + LiteralArgumentBuilder delete = literal("remove"); + delete.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY, 2)); + RequiredArgumentBuilder claim = getClaimArgument(); + LiteralArgumentBuilder confirm = literal("confirm"); + confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), true)); + claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), true)); + claim.then(confirm); + delete.then(claim); + delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), true)); + admin.then(delete); + } + { + LiteralArgumentBuilder create = literal("create"); + create.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_INFINITE_CLAIM, 2)); + ArgumentBuilder name = argument("name", StringArgumentType.word()); + ArgumentBuilder customOwner = argument("customOwnerName", StringArgumentType.word()); + ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); + RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); + max.executes(context -> createClaim( + StringArgumentType.getString(context, "name"), + context.getSource(), + BlockPosArgumentType.getBlockPos(context, "min"), + BlockPosArgumentType.getBlockPos(context, "max"), + true, + null + )); + name.executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); + if (selectedPositions == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getLeft() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getRight() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); + } else { + String cname = StringArgumentType.getString(context, "name"); + if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, null) > 0) { + ClaimManager.INSTANCE.stickPositions.remove(player); + } + } + return 0; + }); + customOwner.executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); + if (selectedPositions == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getLeft() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getRight() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); + } else { + String cname = StringArgumentType.getString(context, "name"); + if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, StringArgumentType.getString(context, "customOwnerName")) > 0) { + ClaimManager.INSTANCE.stickPositions.remove(player); + } + } + return 0; + }); + min.then(max); + name.then(customOwner); + name.then(min); + create.then(name); + admin.then(create); + } + { + LiteralArgumentBuilder ignore = literal("ignoreClaims"); + ignore.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_IGNORE_CLAIMS, 2)); + ignore.executes(context -> { + UUID id = context.getSource().getPlayer().getGameProfile().getId(); + boolean isIgnoring = ClaimManager.INSTANCE.ignoringClaims.contains(id); + if (isIgnoring) ClaimManager.INSTANCE.ignoringClaims.remove(id); + else ClaimManager.INSTANCE.ignoringClaims.add(id); + context.getSource().sendFeedback(new LiteralText("You are " + (isIgnoring ? "no longer" : "now") + " ignoring claims.").formatted(Formatting.GREEN), false); + return 0; + }); + admin.then(ignore); + } + { + { + LiteralArgumentBuilder expand = literal("expand"); + expand.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY, 2)); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); + direction.suggests(DIRECTION_SUGGESTION_BUILDER); + + direction.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + IntegerArgumentType.getInteger(context, "distance"), + directionByName(StringArgumentType.getString(context, "direction")), + context.getSource(), + true + )); + + amount.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + IntegerArgumentType.getInteger(context, "distance"), + Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], + context.getSource(), + true + )); + + amount.then(direction); + expand.then(amount); + admin.then(expand); + } + { + LiteralArgumentBuilder shrink = literal("shrink"); + shrink.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY, 2)); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); + direction.suggests(DIRECTION_SUGGESTION_BUILDER); + + direction.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + -IntegerArgumentType.getInteger(context, "distance"), + directionByName(StringArgumentType.getString(context, "direction")), + context.getSource(), + true + )); + + amount.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + -IntegerArgumentType.getInteger(context, "distance"), + Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], + context.getSource(), + true + )); + + amount.then(direction); + shrink.then(amount); + admin.then(shrink); + } + } + createExceptionCommand(admin, true); + command.then(admin); + } + } + + private static int sendPage(ServerCommandSource source, Text[] text, int page, String title, String command) { + int prevPage = page - 2; + int thisPage = page - 1; + int nextPage = page + 1; + final String SEPARATOR = "-----------------------------------------------------"; + Text header = new LiteralText("") + .append(new LiteralText("- [ ").formatted(Formatting.GRAY)) + .append(new LiteralText(title).formatted(Formatting.GOLD)) + .append(" ] ") + .append(SEPARATOR.substring(ChatColor.removeAlternateColorCodes('&', title).length() + 4)) + .formatted(Formatting.GRAY); + + Text button_prev = new LiteralText("") + .append(new LiteralText("<-").formatted(Formatting.WHITE, Formatting.BOLD)) + .append(" ").append(new LiteralText("Prev").formatted(Formatting.GOLD)) + .styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); + if (prevPage >= 0) + style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); + }); + + Text button_next = new LiteralText("") + .append(new LiteralText("Next").formatted(Formatting.GOLD)) + .append(" ").append(new LiteralText("->").formatted(Formatting.WHITE, Formatting.BOLD)).append(" ") + .styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); + if (nextPage <= text.length) + style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); + }); + + Text buttons = new LiteralText("") + .append(new LiteralText("[ ").formatted(Formatting.GRAY)) + .append(button_prev) + .append(" ") + .append( + new LiteralText(String.valueOf(page)).formatted(Formatting.GREEN) + .append(new LiteralText("/").formatted(Formatting.GRAY)) + .append(new LiteralText(String.valueOf(text.length)).formatted(Formatting.GREEN)) + ) + .append(" ") + .append(button_next) + .append(new LiteralText("] ").formatted(Formatting.GRAY)); + + Text footer = new LiteralText("- ") + .formatted(Formatting.GRAY) + .append(buttons).append(new LiteralText(" ------------------------------").formatted(Formatting.GRAY)); + + header.append("\n").append(text[thisPage]).append("\n").append(footer); + source.sendFeedback(header, false); + return 1; + } + + private static void createExceptionCommand(LiteralArgumentBuilder command, boolean admin) { + { + LiteralArgumentBuilder settings = literal("settings"); + RequiredArgumentBuilder claim = getClaimArgument(); + + if (!admin) { + settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); + + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return querySettings(context.getSource(), claim1); + }); + } + + RequiredArgumentBuilder id = argument("setting", StringArgumentType.word()).suggests(SETTINGS_PROVIDER); + RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); + + id.executes((context) -> executeSetting(context.getSource(), StringArgumentType.getString(context, "setting"), StringArgumentType.getString(context, "claim"), true, false, admin)); + set.executes((context) -> executeSetting(context.getSource(), StringArgumentType.getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); + + id.then(set); + claim.then(id); + settings.then(claim); + command.then(settings); + } + + LiteralArgumentBuilder exceptions = literal("permissions"); + if (admin) exceptions.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_PERMISSIONS, 2)); + RequiredArgumentBuilder claim = getClaimArgument(); + if (!admin) { + exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); + + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim1, false); + }); + } + + if (!admin) { + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(new LiteralText("That claim does not exist")); + return -1; + } + return showTrustedList(context, claim1, true); + }); + } + + { + RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); + LiteralArgumentBuilder remove = literal("remove"); + remove.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + claim1.permissionManager.resetPermissions(player1.getGameProfile().getId()); + context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + " no longer has an exception in the claim").formatted(Formatting.YELLOW), false); + } + return 0; + }); + player.then(remove); + LiteralArgumentBuilder all = literal("*"); + RequiredArgumentBuilder allstate = argument("allow", BoolArgumentType.bool()); + allstate.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + validateClaim(claim1); + return setTrust(context, claim1, player1, BoolArgumentType.getBool(context, "allow"), admin); + }); + all.then(allstate); + player.then(all); + for (Claim.Permission value : Claim.Permission.values()) { + LiteralArgumentBuilder permNode = literal(value.id); + RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); + allow.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + boolean permission = BoolArgumentType.getBool(context, "allow"); + modifyException(claim1, player1, value, permission); + context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has the permission " + value.name).formatted(Formatting.YELLOW), false); + } + return 0; + }); + permNode.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + boolean permission = hasPermission(claim1, player1, value); + context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); + } + return 0; + }); + permNode.then(allow); + player.then(permNode); + } + claim.then(player); + } + { + LiteralArgumentBuilder message = literal("message"); + RequiredArgumentBuilder claimArgument = getClaimArgument(); + RequiredArgumentBuilder messageEvent = argument("messageEvent", StringArgumentType.word()) + .suggests(MESSAGE_EVENTS_PROVIDER); + RequiredArgumentBuilder messageArgument = argument("message", StringArgumentType.greedyString()) + .suggests(EVENT_MESSAGE_PROVIDER); + + messageArgument.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PROPERTIES, context, admin)) { + Claim.Event event = Claim.Event.getById(StringArgumentType.getString(context, "messageEvent")); + + if (event == null) { + context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); + return -1; + } + + return setEventMessage(context.getSource(), claim1, event, StringArgumentType.getString(context, "message")); + } + + return -1; + }); + + messageEvent.then(messageArgument); + claimArgument.then(messageEvent); + message.then(claimArgument); + command.then(message); + } + + + exceptions.then(claim); + command.then(exceptions); + } + private static boolean verifyPermission(Claim claim, Claim.Permission permission, CommandContext context, boolean admin) throws CommandSyntaxException { + if (verifyExists(claim, context)) { + if (claim.permissionManager.hasPermission(context.getSource().getPlayer().getGameProfile().getId(), permission)) { + return true; + } else { + context.getSource().sendFeedback(new LiteralText(admin ? "You are modifying a claim using admin privileges" : "You cannot modify exceptions for this claim").formatted(admin ? Formatting.DARK_RED : Formatting.RED), false); + return admin; + } + } else { + return false; + } + } + private static boolean verifyExists(Claim claim, CommandContext context) { + if (claim == null) { + context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return false; + } else { + return true; + } + } + + + private static int showClaim(ServerCommandSource source, Claim claim, boolean reset) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!Config.claims2d &&((ClaimShower)player).getShownClaim() != claim)) showClaim(source, ((ClaimShower)player).getShownClaim(), true); + if (reset && ((ClaimShower)player).getShownClaim() != null) claim = ((ClaimShower)player).getShownClaim(); + if (claim != null) { + if (!claim.dimension.equals(source.getWorld().getDimension().getType())) { + if (claim == ((ClaimShower)player).getShownClaim()) ((ClaimShower)player).setShownClaim(null); // just so we dont have extra packets on this + source.sendFeedback(new LiteralText("That claim is not in this dimension").formatted(Formatting.RED), false); + return 0; + } + source.sendFeedback(new LiteralText((!reset ? "Showing" : "Hiding") + " claim: " + claim.name).formatted(Formatting.GREEN), false); + silentHideShow(player, claim, reset, true); + + } else { + source.sendFeedback(new LiteralText("That is not a valid claim").formatted(Formatting.RED), false); + } + return 0; + } + private static void silentHideShow(ServerPlayerEntity player, Claim claim, boolean hide, boolean updateStatus) { + if (updateStatus) { + if (!hide) ((ClaimShower) player).setShownClaim(claim); + else ((ClaimShower) player).setShownClaim(null); + } + BlockState block = hide ? null : Blocks.GOLD_BLOCK.getDefaultState(); + showCorners(player, claim, hide, block); + if(!claim.isChild){ + block = hide ? null : Blocks.DIAMOND_BLOCK.getDefaultState(); + for(Claim subzone : claim.children){ + showCorners(player, subzone, hide, block); + } + } + + } + + private static void showCorners(ServerPlayerEntity player, Claim claim, boolean hide, BlockState state){ + state = hide ? null : state; + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); + + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().south(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().east(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().south(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().north(), state); + + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().east(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().north(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().west(), state); + sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().west(), state); + } + + private static void sendBlockPacket(ServerPlayerEntity player, BlockPos pos, BlockState state) { + BlockUpdateS2CPacket packet = new BlockUpdateS2CPacket(player.world, pos); + if (state != null) ((BlockUpdatePacketMixin)packet).setState(state); + player.networkHandler.sendPacket(packet); + } + private static int createClaim(String name, ServerCommandSource owner, BlockPos posA, BlockPos posB, boolean admin, @Nullable String cOwnerName) throws CommandSyntaxException { + if (name.length() > MAX_NAME_LENGTH) { + owner.sendError(Messages.MSG_LONG_NAME); + return -1; + } + UUID ownerID = owner.getPlayer().getGameProfile().getId(); + int x, y = 0, z, mx, my = 255, mz; + if (posA.getX() > posB.getX()) { + x = posB.getX(); + mx = posA.getX(); + } else { + x = posA.getX(); + mx = posB.getX(); + } + if (!Config.claims2d) { + if (posA.getY() > posB.getY()) { + y = posB.getY(); + my = posA.getY(); + } else { + y = posA.getY(); + my = posB.getY(); + } + } + if (posA.getZ() > posB.getZ()) { + z = posB.getZ(); + mz = posA.getZ(); + } else { + z = posA.getZ(); + mz = posB.getZ(); + } + BlockPos min = new BlockPos(x, y, z); + BlockPos max = new BlockPos(mx, my, mz); + BlockPos sub = max.subtract(min); + sub = sub.add(1, Config.claims2d ? 0 : 1,1); + int subInt = sub.getX() * (Config.claims2d ? 1 : sub.getY()) * sub.getZ(); + + Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos(), false); + if (cOwnerName != null) claim.customOwnerName = cOwnerName; + claim.permissionManager.playerPermissions.put(ownerID, new Claim.InvertedPermissionMap()); + if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { + if (!ClaimManager.INSTANCE.wouldIntersect(claim)) { + // works because only the first statement is evaluated if true + if ((admin && ItsMine.permissions().hasPermission(owner, Permissions.Command.INFINITE_BLOCKS, 2)) || ClaimManager.INSTANCE.useClaimBlocks(ownerID, subInt)) { + ClaimManager.INSTANCE.addClaim(claim); + owner.sendFeedback(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)).append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").setStyle(new Style() + .setColor(Formatting.GREEN).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))))), false); + checkPlayer(owner, owner.getPlayer().getGameProfile().getId()); + showClaim(owner, claim, false); + if (admin) + owner.getMinecraftServer().sendMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); + return 1; + } else { + owner.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + subInt + "(" + (subInt - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); + } + } else { + owner.sendFeedback(new LiteralText("Your claim would overlap with another claim").formatted(Formatting.RED), false); + } + } else { + owner.sendFeedback(new LiteralText("The name \"" + name + "\" is already taken.").formatted(Formatting.RED), false); + } + return 0; + } + private static int checkPlayer(ServerCommandSource ret, UUID player) throws CommandSyntaxException { + int blocks = ClaimManager.INSTANCE.getClaimBlocks(player); + ret.sendFeedback(new LiteralText((ret.getPlayer().getGameProfile().getId().equals(player) ? "You have " : "They have ") + blocks + " blocks left").setStyle(new Style() + .setColor(Formatting.YELLOW)), false); + return 0; + } + private static int requestDelete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { + if (claim == null) { + sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { + if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { + sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + } else { + sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); + return 0; + } + } + sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to delete the claim \"" + claim.name + "\"? ").formatted(Formatting.GOLD)) + .append(new LiteralText("[I'M SURE]").setStyle(new Style() + .setColor(Formatting.DARK_RED) + .setBold(true) + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")))), false); + return 0; + } + private static int delete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { + if (claim == null) { + sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { + if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { + sender.sendFeedback(new LiteralText("Deleting a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + } else { + sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); + return 0; + } + } + if(!claim.isChild){ + ClaimManager.INSTANCE.releaseBlocksToOwner(claim); + ClaimManager.INSTANCE.claimsByName.remove(claim.name); + for(Claim subzone : claim.children){ + ClaimManager.INSTANCE.claimsByName.remove(subzone.name); + } + }else{ + claim.getParentClaim(claim).removeSubzone(claim); + ClaimManager.INSTANCE.claimsByName.remove(claim.name); + } + sender.getWorld().getPlayers().forEach(playerEntity -> { + if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true); + }); + sender.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)); + return 0; + } + + + private static int requestTransfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { + if (claim == null) { + sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { + if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { + sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + } else { + sender.sendFeedback(new LiteralText("You cannot transfer ownership that claim").formatted(Formatting.RED), false); + return 0; + } + } + sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to transfer ownership of \"" + claim.name + "\" to " + player.getGameProfile().getName() + "? ").formatted(Formatting.GOLD)) + .append(new LiteralText("[YES]").setStyle(new Style() + .setColor(Formatting.DARK_RED) + .setBold(true) + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")))), false); + return 0; + } + private static Map pendingClaimTransfers = new HashMap<>(); + private static int transfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { + if (claim == null) { + sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { + if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { + sender.sendFeedback(new LiteralText("Transfering ownership of a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + } else { + sender.sendFeedback(new LiteralText("You cannot transfer ownership that claim").formatted(Formatting.RED), false); + return 0; + } + } + + GameProfile profile = sender.getWorld().getServer().getUserCache().getByUuid(claim.claimBlockOwner); + sender.sendFeedback(new LiteralText("Transferring ownership of the claim \"" + claim.name + "\" to " + player.getGameProfile().getName() + " if they accept").formatted(Formatting.GREEN), claim.claimBlockOwner != player.getGameProfile().getId()); + player.sendMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) + .append(new LiteralText("[ACCEPT]").setStyle(new Style() + .setColor(Formatting.GREEN) + .setBold(true) + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim transfer -accept-" + claim.name + " " + player.getEntityName() + " confirm"))))); + pendingClaimTransfers.put(player.getGameProfile().getId(), claim.name); + return 0; + } + public static int acceptTransfer(ServerCommandSource sender) throws CommandSyntaxException { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(pendingClaimTransfers.get(sender.getPlayer().getGameProfile().getId())); + if (claim == null) { + sender.sendFeedback(new LiteralText("You have no pending claim transfers").formatted(Formatting.RED), false); + return 0; + } + if (sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner) != null) { + sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); + } + Claim.ClaimPermissionMap op = claim.permissionManager.playerPermissions.get(claim.claimBlockOwner); + claim.permissionManager.playerPermissions.put(claim.claimBlockOwner, claim.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); + claim.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op); + claim.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); + return 0; + } + private static int modifyException(Claim claim, ServerPlayerEntity exception, Claim.Permission permission, boolean allowed) { + claim.permissionManager.setPermission(exception.getGameProfile().getId(), permission, allowed); + return 0; + } + private static int modifyException(Claim claim, String exception, Claim.Permission permission, boolean allowed) { + claim.permissionManager.setPermission(exception, permission, allowed); + return 0; + } + private static boolean hasPermission(Claim claim, ServerPlayerEntity exception, Claim.Permission permission) { + return claim.permissionManager.hasPermission(exception.getGameProfile().getId(), permission); + } // private static boolean hasPermission(Claim claim, String exception, Claim.Permission permission) { // return claim.permissionManager.hasPermission(exception, permission); // } -// private static Direction directionByName(String name) { -// for (Direction direction : Direction.values()) { -// if (name.equals(direction.getName())) return direction; -// } -// return null; -// } + private static Direction directionByName(String name) { + for (Direction direction : Direction.values()) { + if (name.equals(direction.getName())) return direction; + } + return null; + } + private static int expand(Claim claim, int amount, Direction direction, ServerCommandSource source, boolean admin) throws CommandSyntaxException { + UUID ownerID = source.getPlayer().getGameProfile().getId(); + if (claim == null) { + source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if (direction == null) { + source.sendFeedback(new LiteralText("That is not a valid direction").formatted(Formatting.RED), false); + return 0; + } + if (!claim.permissionManager.hasPermission(ownerID, Claim.Permission.MODIFY_SIZE)) { + source.sendFeedback(new LiteralText("You do not have border change permissions in that claim").formatted(Formatting.RED), false); + if (!admin) return 0; + } + int oldArea = claim.getArea(); + if (amount > 0) claim.expand(direction, amount); + else { + if (!claim.shrink(direction, amount)) { + source.sendFeedback(new LiteralText("You can't shrink your claim that far. It would pass its opposite wall.").formatted(Formatting.RED), false); + return 0; + } + } + if (ClaimManager.INSTANCE.wouldIntersect(claim)) { + if (amount < 0) claim.expand(direction, amount); + else claim.shrink(direction, amount); + source.sendFeedback(new LiteralText("Expansion would result in hitting another claim").formatted(Formatting.RED), false); + return 0; + } + int newArea = claim.getArea() - oldArea; + if (!admin && claim.claimBlockOwner != null && ClaimManager.INSTANCE.getClaimBlocks(ownerID) < newArea) { + if (amount < 0) claim.expand(direction, amount); + else claim.shrink(direction, amount); + source.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + newArea + "(" + (newArea - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); + checkPlayer(source, ownerID); + return 0; + } else { + if (!admin && claim.claimBlockOwner != null) ClaimManager.INSTANCE.useClaimBlocks(ownerID, newArea); + source.sendFeedback(new LiteralText("Your claim was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); + checkPlayer(source, ownerID); + if (amount < 0) claim.expand(direction, amount); + else claim.shrink(direction, amount); + source.getWorld().getPlayers().forEach(playerEntity -> { + if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, false); + }); + if (amount > 0) claim.expand(direction, amount); + else claim.shrink(direction, -amount); + source.getWorld().getPlayers().forEach(playerEntity -> { + if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, false, false); + }); + } + return 0; + } + private static int info(ServerCommandSource source, Claim claim) { + if (claim == null) { + source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } -// private static CompletableFuture itemsSuggestion(final CommandContext ctx, final SuggestionsBuilder builder) { -// List strings = new ArrayList<>(); -// Registry.ITEM.forEach((item) -> { -// strings.add(Registry.ITEM.getId(item).getPath()); -// }); -// -// return CommandSource.suggestMatching(strings, builder); -// } + GameProfile owner = claim.claimBlockOwner == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); + BlockPos size = claim.getSize(); -// private static void undoExpand(Claim claim, Direction direction, int amount){ -// if (amount < 0) claim.expand(direction, -amount); -// else claim.shrink(direction, amount); -// } -// -// private static void sendSize(Claim claim, ServerCommandSource source){ -// Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); -// Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); -// Text pos = new LiteralText(""); -// pos.append(newInfoLine("Position", new LiteralText("") -// .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) -// .append(" ") -// .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); -// source.sendFeedback(pos, true); -// } -// -// private static int expand(Claim claim, int amount, Direction direction, ServerCommandSource source, boolean admin) throws CommandSyntaxException { -// UUID ownerID = source.getPlayer().getGameProfile().getId(); -// if (claim == null) { -// source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return 0; -// } -// if (direction == null) { -// source.sendFeedback(new LiteralText("That is not a valid direction").formatted(Formatting.RED), false); -// return 0; -// } -// if (!claim.permissionManager.hasPermission(ownerID, Claim.Permission.MODIFY_SIZE)) { -// source.sendFeedback(new LiteralText("You do not have border change permissions in that claim").formatted(Formatting.RED), false); -// if (!admin) return 0; -// } -// int oldArea = claim.getArea(); -// System.out.println("Area1 " + claim.getArea()); -// sendSize(claim, source); -// -// if (amount > 0) { -// claim.expand(direction, amount); -// } -// else { -// claim.shrink(direction, -amount); -// } -// -// System.out.println("Area2 " + claim.getArea()); -// sendSize(claim, source); -// -// if (!claim.canShrinkWithoutHittingOtherSide(new BlockPos(direction.getOffsetX() * amount, direction.getOffsetY() * amount, direction.getOffsetZ() * amount))) { -// source.sendFeedback(new LiteralText("You can't shrink your claim that far. It would pass its opposite wall.").formatted(Formatting.RED), false); -// undoExpand(claim, direction, amount); -// return 0; -// } -// -// if(!claim.isChild){ -// if (ClaimManager.INSTANCE.wouldIntersect(claim)) { -// undoExpand(claim, direction, amount); -// source.sendFeedback(new LiteralText("Expansion would result in hitting another claim").formatted(Formatting.RED), false); -// return 0; -// } -// -// //Check if shrinking would reset a subzone to be outside of its parent claim -// AtomicBoolean returnValue = new AtomicBoolean(); -// returnValue.set(false); -// claim.children.forEach(claim1 -> { -//// System.out.println("IsInside2: " + claim1.isInside(claim)); -// if(!claim1.isInside(claim)){ -// System.out.println("Area3 " + claim.getArea()); -// sendSize(claim, source); -// undoExpand(claim, direction, amount); -// System.out.println("Area4 " + claim.getArea()); -// sendSize(claim, source); -// source.sendFeedback(new LiteralText("Shrinking would result in " + claim1.name + " being outside of " + claim.name).formatted(Formatting.RED), true); -// returnValue.set(true); -// } -// }); -// if(returnValue.get()) return 0; -// -// int newArea = claim.getArea() - oldArea; -// if (!admin && claim.claimBlockOwner != null && ClaimManager.INSTANCE.getClaimBlocks(ownerID) < newArea) { -// undoExpand(claim, direction, amount); -// source.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + newArea + "(" + (newArea - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); -// checkPlayer(source, ownerID); -// return 0; -// } else { -// if (!admin && claim.claimBlockOwner != null) ClaimManager.INSTANCE.useClaimBlocks(ownerID, newArea); -// source.sendFeedback(new LiteralText("Your claim was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); -// checkPlayer(source, ownerID); -// undoExpand(claim, direction, amount); -// ShowerUtil.update(claim, source.getWorld(), true); -// if (amount > 0) claim.expand(direction, amount); -// else claim.shrink(direction, -amount); -// ShowerUtil.update(claim, source.getWorld(), false); -// } -// return 0; -// }else{ -// Claim parent = ClaimUtil.getParentClaim(claim); -// if(!claim.isInside(parent)) { -// source.sendFeedback(new LiteralText("Expansion would result in expanding outside of your main claim").formatted(Formatting.RED), false); -// undoExpand(claim, direction, amount); -// } else if(ClaimManager.INSTANCE.wouldSubzoneIntersect((claim))){ -// source.sendFeedback(new LiteralText("Expansion would result in overlapping with another subzone").formatted(Formatting.RED), false); -// undoExpand(claim, direction, amount); -// }else{ -// source.sendFeedback(new LiteralText("Your subzone was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); -// //The expansion is undone to hide the claimshower -// undoExpand(claim, direction, amount); -// ShowerUtil.update(parent, source.getWorld(), true); -// if (amount > 0) claim.expand(direction, amount); -// else claim.shrink(direction, -amount); -// ShowerUtil.update(parent, source.getWorld(), false); -// } -// } -// return 0; -// } + Text text = new LiteralText("\n"); + text.append(new LiteralText("Claim Info: " + claim.name).formatted(Formatting.GOLD)).append("\n"); + text.append(newInfoLine("Name", new LiteralText(claim.name).formatted(Formatting.WHITE))); + text.append(newInfoLine("Owner", + owner != null && claim.customOwnerName == null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : + claim.customOwnerName != null ? new LiteralText(claim.customOwnerName).formatted(Formatting.GOLD) : + new LiteralText("No Owner").formatted(Formatting.RED, Formatting.ITALIC))); + text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); -// private static int revenue(ServerCommandSource source, Claim claim, boolean claimrevenue) throws CommandSyntaxException { -// //Show subzones (so you can just claim everything in one place) maybe just all claims -// if(claim == null){ -// source.sendFeedback(Messages.INVALID_CLAIM,true); -// return 0; -// } -// if(!claim.claimBlockOwner.toString().equalsIgnoreCase(source.getPlayer().getUuid().toString())){ -// source.sendFeedback(Messages.NO_PERMISSION, true); -// return 0; -// } -// -// if(claimrevenue){ -// for(ItemStack itemStack : claim.rent.getRevenue()){ -// source.getPlayer().inventory.insertStack(itemStack); -// } -// claim.rent.clearRevenue(); -// return 1; -// -// } else { -// if(claim.rent.getRevenue().isEmpty()){ -// source.sendFeedback(new LiteralText("No Revenue").formatted(Formatting.RED), true); -// return 0; -// } -// Text text = new LiteralText("Revenue\n").formatted(Formatting.AQUA); -// HashMap hashMap = new HashMap<>(); -// for(ItemStack itemStack : claim.rent.getRevenue()){ -// Item value = itemStack.getItem(); -// if(hashMap.containsKey(value)){ -// hashMap.put(value, hashMap.get(value) + itemStack.getCount()); -// } else { -// hashMap.put(value, + itemStack.getCount()); -// } -// -// hashMap.forEach((item, integer) -> { -// boolean color = true; -// text.append(new LiteralText(String.valueOf(integer)).append(" ").append(new TranslatableText(item.getTranslationKey())).append(" ").formatted(color ? Formatting.GOLD : Formatting.YELLOW)).styled(style -> { -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to claim revenue!").formatted(Formatting.GREEN))); -// style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim revenue " + claim.name + " true")); -// }); -// color = !color; -// }); -// -// } -// text.append("\n"); -// source.sendFeedback(text, true); -// return 1; -// } -// } -// private static int info(ServerCommandSource source, Claim claim) throws CommandSyntaxException { -// if (claim == null) { -// source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return 0; -// } -// -// GameProfile owner = claim.claimBlockOwner == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); -// BlockPos size = claim.getSize(); -// -// Text text = new LiteralText("\n"); -// text.append(new LiteralText("Claim Info: " + claim.name).formatted(Formatting.GOLD)).append("\n"); -// text.append(newInfoLine("Name", new LiteralText(claim.name).formatted(Formatting.WHITE))); -// text.append(newInfoLine("Entities", new LiteralText(String.valueOf(claim.getEntities(source.getWorld()))).formatted(Formatting.AQUA))); -// text.append(newInfoLine("Owner", -// owner != null && claim.customOwnerName == null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : -// claim.customOwnerName != null ? new LiteralText(claim.customOwnerName).formatted(Formatting.GOLD) : -// new LiteralText("No Owner").formatted(Formatting.RED, Formatting.ITALIC))); -// text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); -// -// -// text.append(new LiteralText("").append(new LiteralText("* Settings:").formatted(Formatting.YELLOW)) -// .append(Messages.Command.getSettings(claim)).append("\n")); -// Text pos = new LiteralText(""); -// Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); -// Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); -// -// -// if (PERMISSION_CHECK_ADMIN.test(source)) { -// String format = "/execute in " + Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").toString() + " run tp " + source.getName() + (Config.claims2d ? " %s ~ %s" : " %s %s %s"); -// min.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, -// String.format(format, claim.min.getX(), Config.claims2d ? claim.min.getZ() : claim.min.getY(), claim.min.getZ())))); -// max.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, -// String.format(format, claim.max.getX(), Config.claims2d ? claim.max.getZ() : claim.max.getY(), claim.max.getZ())))); -// } -// -// pos.append(newInfoLine("Position", new LiteralText("") -// .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) -// .append(" ") -// .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); -// text.append(pos); -// text.append(newInfoLine("Dimension", new LiteralText(Registry.DIMENSION_TYPE.getId(claim.dimension).getPath()))); -// if(claim.rent.isRented()){ -// GameProfile tenant = claim.rent.getTenant() == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.rent.getTenant()); -// text.append(newInfoLine("Status", new LiteralText("Rented").formatted(Formatting.RED).styled(style -> { -// java.util.Date time=new java.util.Date((long) claim.rent.getRentedUntil()*1000); -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Until", new LiteralText(time.toString()).formatted(Formatting.WHITE)).append(newInfoLine("By", new LiteralText(tenant.getName()).formatted(Formatting.WHITE))).append(newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE))))); -// }))); -// } else if (claim.rent.isRentable() && !claim.rent.isRented()){ -// text.append(newInfoLine("Status", new LiteralText("For Rent").formatted(Formatting.GREEN).styled(style -> { -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE)).append(newInfoLine("Max Rent", new LiteralText(claim.rent.getMaxrentAbleTime() / 86400 + " days")).formatted(Formatting.WHITE)))); -// }))); -// -// } else { -// text.append(newInfoLine("Status", new LiteralText("Not For Rent").formatted(Formatting.GREEN))); -// -// } -// source.sendFeedback(text, false); -// return 1; -// } -// private static Text newPosLine(BlockPos pos, Formatting form1, Formatting form2) { -// return new LiteralText("") -// .append(new LiteralText(String.valueOf(pos.getX())).formatted(form1)) -// .append(" ") -// .append(new LiteralText(String.valueOf(pos.getY())).formatted(form2)) -// .append(" ") -// .append(new LiteralText(String.valueOf(pos.getZ())).formatted(form1)); -// } -// private static Text newInfoLine(String title, Text text) { -// return new LiteralText("").append(new LiteralText("* " + title + ": ").formatted(Formatting.YELLOW)) -// .append(text).append("\n"); -// } + text.append(new LiteralText("").append(new LiteralText("* Settings:").formatted(Formatting.YELLOW)) + .append(Messages.Command.getSettings(claim)).append("\n")); + Text pos = new LiteralText(""); + Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); + Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); -// private static ArrayList getClaims(){ -// ArrayList claims = new ArrayList<>(); -// ClaimManager.INSTANCE.claimsByName.forEach((s, claim) -> { -// claims.add(claim); -// }); -// return claims; -// } -// -// private static int listall(ServerCommandSource source){ -// List claims = getClaims(); -// Text text = new LiteralText("\n").append(new LiteralText("Claims").formatted(Formatting.GOLD)).append("\n "); -// for (Claim claim : claims) { -// Text cText = new LiteralText(claim.name).formatted(Formatting.GOLD); -// text.append(cText.append(" ")); -// } -// source.sendFeedback(text.append("\n"), false); -// return 1; -// } + if (PERMISSION_CHECK_ADMIN.test(source)) { + String format = "/execute in " + Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").toString() + " run tp " + source.getName() + (Config.claims2d ? " %s ~ %s" : " %s %s %s"); + min.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, + String.format(format, claim.min.getX(), Config.claims2d ? claim.min.getZ() : claim.min.getY(), claim.min.getZ())))); + max.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, + String.format(format, claim.max.getX(), Config.claims2d ? claim.max.getZ() : claim.max.getY(), claim.max.getZ())))); + } -// private static int list(ServerCommandSource source, String target) throws CommandSyntaxException { -// ServerPlayerEntity player = source.getPlayer(); -// GameProfile profile = target == null ? player.getGameProfile() : source.getMinecraftServer().getUserCache().findByName(target); -// -// if (profile == null) { -// source.sendError(Messages.INVALID_PLAYER); -// return -1; -// } -// -// List claims = ClaimManager.INSTANCE.getPlayerClaims(profile.getId()); -// if (claims.isEmpty()) { -// source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); -// return -1; -// } -// -// -// Text text = new LiteralText("\n").append(new LiteralText("Claims (" + target + "): ").formatted(Formatting.GOLD)).append("\n "); -// boolean nextColor = false; -// for (Claim claim : claims) { -// if(!claim.isChild) { -// Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { -// Text hoverText = new LiteralText("Click for more Info").formatted(Formatting.GREEN); -// if (claim.children.size() > 0) { -// hoverText.append("\n\nSubzones:"); -// for (Claim subzone : claim.children) { -// hoverText.append("\n- " + subzone.name); -// } -// } -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); -// -// style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); -// }); -// -// nextColor = !nextColor; -// text.append(cText.append(" ")); -// } -// } -// -// source.sendFeedback(text.append("\n"), false); -// return 1; -// } -// private static int listAll(ServerCommandSource source, int page) { -// List claims = new ArrayList<>(); -// ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> claims.add(claim)); -// -// if (claims.isEmpty()) { -// source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); -// return -1; -// } -// -// List list = new ArrayList<>(claims.size() / 10); -// -// for (int i = 0; i < claims.size(); i++) { -// Claim claim = claims.get(i); -// -// Text cText = new LiteralText("").append(new LiteralText(i + ". ").formatted(Formatting.GOLD)) -// .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" in ").formatted(Formatting.GRAY)) -// .append(new LiteralText(Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").getPath()).formatted(Formatting.WHITE)); -// -// cText.styled((style) -> { -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click for more Info").formatted(Formatting.GREEN))); -// style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); -// }); -// -// list.add(cText.append("\n")); -// } -// -// Text[] texts = new Text[]{}; -// texts = list.toArray(texts); -// return sendPage(source, texts, page, "Claims", "/claim listall %page%"); -// } -// private static int rename(CommandContext context, boolean admin) throws CommandSyntaxException { -// String name = getString(context, "claim"); -// String newName = getString(context, "name"); -// if(!newName.matches("[A-Za-z0-9]+")){ -// context.getSource().sendError(new LiteralText("Invalid claim name")); -// return -1; -// } -// Claim claim = ClaimManager.INSTANCE.claimsByName.get(name); -// if (claim == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// if (ClaimManager.INSTANCE.claimsByName.containsKey(newName)) { -// context.getSource().sendError(new LiteralText("That name is already taken!")); -// return -1; -// } -// if (!admin && !claim.hasPermission(context.getSource().getPlayer().getUuid(), Claim.Permission.MODIFY_PROPERTIES)) { -// context.getSource().sendError(new LiteralText("You don't have permission to modify claim properties!")); -// return -1; -// } -// ClaimManager.INSTANCE.claimsByName.remove(name); -// if(claim.isChild) claim.name = ClaimUtil.getParentClaim(claim).name + "." + newName; -// else claim.name = newName; -// ClaimManager.INSTANCE.addClaim(claim); -// context.getSource().sendFeedback(new LiteralText("Renamed Claim " + name + " to " + claim.name).formatted(Formatting.GOLD), admin); -// return -1; -// } -// private static int showTrustedList(CommandContext context, Claim claim, boolean showSelf) throws CommandSyntaxException { -// ServerCommandSource source = context.getSource(); -// ServerPlayerEntity player = source.getPlayer(); -// int mapSize = claim.permissionManager.playerPermissions.size(); -// -// if (mapSize == 1 && !showSelf) { -// source.sendError(new LiteralText(claim.name + " is not trusting anyone!")); -// return -1; -// } -// -// Text text = new LiteralText("\n"); -// text.append(new LiteralText("Trusted players for Claim ").formatted(Formatting.YELLOW)) -// .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append("\n"); -// -// AtomicInteger atomicInteger = new AtomicInteger(); -// claim.permissionManager.playerPermissions.forEach((uuid, perm) -> { -// atomicInteger.incrementAndGet(); -// Text pText = new LiteralText(""); -// Text owner; -// GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); -// if (profile != null) { -// owner = new LiteralText(profile.getName()); -// } else { -// owner = new LiteralText(uuid.toString()).styled((style) -> { -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to Copy"))); -// style.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); -// }); -// } -// -// pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) -// .append(owner.formatted(Formatting.YELLOW)); -// -// Text hover = new LiteralText(""); -// hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); -// -// int allowed = 0; -// int i = 0; -// boolean nextColor = false; -// Text perms = new LiteralText(""); -// -// for (Claim.Permission value : Claim.Permission.values()) { -// if (claim.permissionManager.hasPermission(uuid, value)) { -// Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; -// perms.append(new LiteralText(value.id).formatted(formatting)).append(" "); -// if (i == 3) perms.append("\n"); -// allowed++; -// i++; -// nextColor = !nextColor; -// } -// } -// -// if (allowed == Claim.Permission.values().length) { -// hover.append(new LiteralText("All " + allowed + " Permissions").formatted(Formatting.YELLOW, Formatting.ITALIC)); -// } else { -// hover.append(perms); -// } -// -// pText.append(new LiteralText(" ") -// .append(new LiteralText("(").formatted(Formatting.GOLD)) -// .append(new LiteralText(String.valueOf(allowed)).formatted(Formatting.GREEN)) -// .append(new LiteralText("/").formatted(Formatting.GOLD)) -// .append(new LiteralText(String.valueOf(Claim.Permission.values().length)).formatted(Formatting.YELLOW)) -// .append(new LiteralText(")").formatted(Formatting.GOLD)) -// ); -// -// pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); -// text.append(pText).append("\n"); -// }); -// -// source.sendFeedback(text, false); -// return 1; -// } -// private static int setOwnerName(ServerCommandSource source, Claim claim, String input) { -// String name = input.equals("reset") ? null : input; -// source.sendFeedback(new LiteralText("Set the Custom Owner Name to ") -// .formatted(Formatting.YELLOW).append(new LiteralText(name == null ? "Reset" : name).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) -// .append(new LiteralText(claim.customOwnerName == null ? "Not Present" : claim.customOwnerName).formatted(Formatting.GOLD)) -// .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) -// , false); -// claim.customOwnerName = input; -// return 1; -// } -// private static int setOwner(ServerCommandSource source, Claim claim, GameProfile profile) { -// GameProfile oldOwner = source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); -// source.sendFeedback(new LiteralText("Set the Claim Owner to ") -// .formatted(Formatting.YELLOW).append(new LiteralText(profile.getName()).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) -// .append(new LiteralText(oldOwner == null ? "(" + claim.claimBlockOwner + ")" : oldOwner.getName()).formatted(Formatting.GOLD)) -// .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) -// , false); -// claim.claimBlockOwner = profile.getId(); -// return 1; -// } -// private static int setEventMessage(ServerCommandSource source, Claim claim, Claim.Event event, String message) { -// switch (event) { -// case ENTER_CLAIM: -// claim.enterMessage = message.equalsIgnoreCase("reset") ? null : message; -// break; -// case LEAVE_CLAIM: -// claim.leaveMessage = message.equalsIgnoreCase("reset") ? null : message; -// break; -// } -// -// if (message.equalsIgnoreCase("reset")) { -// source.sendFeedback(new LiteralText("Reset ").append(new LiteralText(event.id).formatted(Formatting.GOLD) -// .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) -// .append(new LiteralText(claim.name).formatted(Formatting.GOLD))).formatted(Formatting.YELLOW) -// , false); -// return -1; -// } -// -// source.sendFeedback(new LiteralText("Set ").append(new LiteralText(event.id).formatted(Formatting.GOLD) -// .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) -// .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" to:").formatted(Formatting.YELLOW))) -// .append("\n").append(new LiteralText(ChatColor.translate(message))) -// .formatted(Formatting.YELLOW) -// , false); -// return 1; -// } -// private static int executeSetting(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { -// ServerPlayerEntity player = source.getPlayer(); -// Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : -// ClaimManager.INSTANCE.claimsByName.get(claimName); -// if (claim1 == null) { -// source.sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// -// if (input == null) { -// return querySettings(source, claim1); -// } -// -// validateCanAccess(player, claim1, admin); -// Claim.ClaimSettings.Setting setting = Claim.ClaimSettings.Setting.byId(input); -// Claim.Permission permission = Claim.Permission.byId(input); -// -// if (setting != null && permission == null) -// return isQuery ? querySetting(source, claim1, setting) : setSetting(source, claim1, setting, value); -// -// if (setting == null && permission != null) -// return isQuery ? queryPermission(source, claim1, permission) : setPermission(source, claim1, permission, value); -// -// source.sendError(Messages.INVALID_SETTING); -// return -1; -// } -// private static int executePermission(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { -// ServerPlayerEntity player = source.getPlayer(); -// Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : -// ClaimManager.INSTANCE.claimsByName.get(claimName); -// if (claim1 == null) { -// source.sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// -// validateCanAccess(player, claim1, admin); -// Claim.Permission permission = Claim.Permission.byId(input); -// if (permission != null) -// return !isQuery ? setPermission(source, claim1, permission, value) : queryPermission(source, claim1, permission); -// -// source.sendError(Messages.INVALID_SETTING); -// return -1; -// } -// private static int querySetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting) { -// boolean enabled = claim.settings.getSetting(setting); -// source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); -// return 1; -// } -// private static int setSetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting, boolean set) { -// claim.settings.settings.put(setting, set); -// source.sendFeedback(new LiteralText(ChatColor.translate("&eSet setting &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); -// return 0; -// } -// private static int queryPermission(ServerCommandSource source, Claim claim, Claim.Permission permission) { -// boolean defaultPerm = claim.permissionManager.defaults.hasPermission(permission); -// source.sendFeedback(new LiteralText(ChatColor.translate("&ePermission &6" + permission.id + "&e is set to " + (defaultPerm ? "&a" : "&c") + defaultPerm + "&e for &6" + claim.name)), false); -// return 1; -// } -// private static int setPermission(ServerCommandSource source, Claim claim, Claim.Permission permission, boolean set) { -// claim.permissionManager.defaults.setPermission(permission, set); -// source.sendFeedback(new LiteralText(ChatColor.translate("&eSet permission &6" + permission.id + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); -// return 1; -// } -// private static int querySettings(ServerCommandSource source, Claim claim) { -// source.sendFeedback(new LiteralText("\n").append(new LiteralText("Settings: " + claim.name).formatted(Formatting.YELLOW)).append("\n") -// .append(Messages.Command.getSettings(claim)).append("\n"), false); -// return 1; -// } -// private static int executeTrust(CommandContext context, Collection targetCollection, boolean set, @Nullable String claimName) throws CommandSyntaxException { -// AtomicInteger integer = new AtomicInteger(); -//// if(targetCollection.size() > 1){ -//// context.getSource().sendFeedback(new LiteralText("Only 1 player allowed").formatted(Formatting.RED), true); -//// return 0; -//// } -// if(targetCollection.isEmpty()){ -// context.getSource().sendFeedback(new LiteralText("No player provided").formatted(Formatting.RED), true); -// return 0; -// } -// ServerPlayerEntity p = context.getSource().getPlayer(); -// Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getBlockPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); -// validateClaim(claim1); -// targetCollection.iterator().forEachRemaining(gameProfile -> { -// try { -// //This is supposed to check if the player has played before :shrug: -// if(context.getSource().getMinecraftServer().getUserCache().getByUuid(gameProfile.getId()) == gameProfile){ -// integer.set(setTrust(context, claim1, gameProfile, set, false)); -// } else { -// context.getSource().sendFeedback(new LiteralText("Unknown player!").formatted(Formatting.RED), true); -// integer.set(0); -// } -// } catch (CommandSyntaxException e) { -// e.printStackTrace(); -// } -// }); -// return integer.get(); -// } -// private static int setTrust(CommandContext context, Claim claim, GameProfile target, boolean set, boolean admin) throws CommandSyntaxException { -// if (verifyPermission(claim, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { -// claim.permissionManager.playerPermissions.put(target.getId(), set ? new Claim.InvertedPermissionMap() : new Claim.DefaultPermissionMap()); -// context.getSource().sendFeedback(new LiteralText(target.getName() + (set ? " now" : " no longer") + " has all the permissions").formatted(Formatting.YELLOW), false); -// } -// return 1; -// } -// private static int setFly(CommandContext context, boolean set) throws CommandSyntaxException { -// ServerPlayerEntity player = context.getSource().getPlayer(); -// if (set) { -// ClaimManager.INSTANCE.flyers.add(player.getUuid()); -// player.addMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN), false); -// return 1; -// } -// -// player.addMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED), false); -// ClaimManager.INSTANCE.flyers.remove(player.getUuid()); -// return -1; -// } + pos.append(newInfoLine("Position", new LiteralText("") + .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) + .append(" ") + .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); + text.append(pos); + text.append(newInfoLine("Dimension", new LiteralText(Registry.DIMENSION_TYPE.getId(claim.dimension).getPath()))); + source.sendFeedback(text, false); + return 1; + } + private static Text newPosLine(BlockPos pos, Formatting form1, Formatting form2) { + return new LiteralText("") + .append(new LiteralText(String.valueOf(pos.getX())).formatted(form1)) + .append(" ") + .append(new LiteralText(String.valueOf(pos.getY())).formatted(form2)) + .append(" ") + .append(new LiteralText(String.valueOf(pos.getZ())).formatted(form1)); + } + private static Text newInfoLine(String title, Text text) { + return new LiteralText("").append(new LiteralText("* " + title + ": ").formatted(Formatting.YELLOW)) + .append(text).append("\n"); + } -// -// private static GameProfile getProfile(CommandContext context, String arg) { -// return context.getSource().getMinecraftServer().getUserCache().findByName(getString(context, arg)); -// } -//} \ No newline at end of file + private static ArrayList getClaims(){ + ArrayList claims = new ArrayList<>(); + ClaimManager.INSTANCE.claimsByName.forEach((s, claim) -> { + claims.add(claim); + }); + return claims; + } + + private static int listall(ServerCommandSource source){ + List claims = getClaims(); + Text text = new LiteralText("\n").append(new LiteralText("Claims").formatted(Formatting.GOLD)).append("\n "); + for (Claim claim : claims) { + Text cText = new LiteralText(claim.name).formatted(Formatting.GOLD); + text.append(cText.append(" ")); + } + source.sendFeedback(text.append("\n"), false); + return 1; + } + + private static int list(ServerCommandSource source, String target) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + GameProfile profile = target == null ? player.getGameProfile() : source.getMinecraftServer().getUserCache().findByName(target); + + if (profile == null) { + source.sendError(Messages.INVALID_PLAYER); + return -1; + } + + List claims = ClaimManager.INSTANCE.getPlayerClaims(profile.getId()); + if (claims.isEmpty()) { + source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); + return -1; + } + + + Text text = new LiteralText("\n").append(new LiteralText("Claims (" + target + "): ").formatted(Formatting.GOLD)).append("\n "); + boolean nextColor = false; + for (Claim claim : claims) { + if(!claim.isChild) { + Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { + Text hoverText = new LiteralText("Click for more Info").formatted(Formatting.GREEN); + if (claim.children.size() > 0) { + hoverText.append("\n\nSubzones:"); + for (Claim subzone : claim.children) { + hoverText.append("\n- " + subzone.name); + } + } + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); + + style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); + }); + + nextColor = !nextColor; + text.append(cText.append(" ")); + } + } + + source.sendFeedback(text.append("\n"), false); + return 1; + } + private static int listAll(ServerCommandSource source, int page) { + List claims = new ArrayList<>(); + ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> claims.add(claim)); + + if (claims.isEmpty()) { + source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); + return -1; + } + + List list = new ArrayList<>(claims.size() / 10); + + for (int i = 0; i < claims.size(); i++) { + Claim claim = claims.get(i); + + Text cText = new LiteralText("").append(new LiteralText(i + ". ").formatted(Formatting.GOLD)) + .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" in ").formatted(Formatting.GRAY)) + .append(new LiteralText(Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").getPath()).formatted(Formatting.WHITE)); + + cText.styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click for more Info").formatted(Formatting.GREEN))); + style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); + }); + + list.add(cText.append("\n")); + } + + Text[] texts = new Text[]{}; + texts = list.toArray(texts); + return sendPage(source, texts, page, "Claims", "/claim listall %page%"); + } + private static int rename(CommandContext context, boolean admin) throws CommandSyntaxException { + String name = StringArgumentType.getString(context, "claim"); + String newName = StringArgumentType.getString(context, "name"); + Claim claimToRename = ClaimManager.INSTANCE.claimsByName.get(name); + if (claimToRename == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + if (ClaimManager.INSTANCE.claimsByName.containsKey(newName)) { + context.getSource().sendError(new LiteralText("That name is already taken!")); + return -1; + } + if (!admin && !claimToRename.hasPermission(context.getSource().getPlayer().getUuid(), Claim.Permission.MODIFY_PROPERTIES)) { + context.getSource().sendError(new LiteralText("You don't have permission to modify claim properties!")); + return -1; + } + ClaimManager.INSTANCE.claimsByName.remove(name); + claimToRename.name = newName; + ClaimManager.INSTANCE.addClaim(claimToRename); + claimToRename.name = newName; + context.getSource().sendFeedback(new LiteralText("Renamed Claim " + name + " to " + newName).formatted(Formatting.GOLD), admin); + return -1; + } + private static int showTrustedList(CommandContext context, Claim claim, boolean showSelf) throws CommandSyntaxException { + ServerCommandSource source = context.getSource(); + ServerPlayerEntity player = source.getPlayer(); + int mapSize = claim.permissionManager.playerPermissions.size(); + + if (mapSize == 1 && !showSelf) { + source.sendError(new LiteralText(claim.name + " is not trusting anyone!")); + return -1; + } + + Text text = new LiteralText("\n"); + text.append(new LiteralText("Trusted players for Claim ").formatted(Formatting.YELLOW)) + .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append("\n"); + + AtomicInteger atomicInteger = new AtomicInteger(); + claim.permissionManager.playerPermissions.forEach((uuid, perm) -> { + atomicInteger.incrementAndGet(); + Text pText = new LiteralText(""); + Text owner; + GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); + if (profile != null) { + owner = new LiteralText(profile.getName()); + } else { + owner = new LiteralText(uuid.toString()).styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to Copy"))); + style.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); + }); + } + + pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) + .append(owner.formatted(Formatting.YELLOW)); + + Text hover = new LiteralText(""); + hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); + + int allowed = 0; + int i = 0; + boolean nextColor = false; + Text perms = new LiteralText(""); + + for (Claim.Permission value : Claim.Permission.values()) { + if (claim.permissionManager.hasPermission(uuid, value)) { + Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; + perms.append(new LiteralText(value.id).formatted(formatting)).append(" "); + if (i == 3) perms.append("\n"); + allowed++; + i++; + nextColor = !nextColor; + } + } + + if (allowed == Claim.Permission.values().length) { + hover.append(new LiteralText("All " + allowed + " Permissions").formatted(Formatting.YELLOW, Formatting.ITALIC)); + } else { + hover.append(perms); + } + + pText.append(new LiteralText(" ") + .append(new LiteralText("(").formatted(Formatting.GOLD)) + .append(new LiteralText(String.valueOf(allowed)).formatted(Formatting.GREEN)) + .append(new LiteralText("/").formatted(Formatting.GOLD)) + .append(new LiteralText(String.valueOf(Claim.Permission.values().length)).formatted(Formatting.YELLOW)) + .append(new LiteralText(")").formatted(Formatting.GOLD)) + ); + + pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); + text.append(pText).append("\n"); + }); + + source.sendFeedback(text, false); + return 1; + } + private static int setOwnerName(ServerCommandSource source, Claim claim, String input) { + String name = input.equals("reset") ? null : input; + source.sendFeedback(new LiteralText("Set the Custom Owner Name to ") + .formatted(Formatting.YELLOW).append(new LiteralText(name == null ? "Reset" : name).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) + .append(new LiteralText(claim.customOwnerName == null ? "Not Present" : claim.customOwnerName).formatted(Formatting.GOLD)) + .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) + , false); + claim.customOwnerName = input; + return 1; + } + private static int setOwner(ServerCommandSource source, Claim claim, GameProfile profile) { + GameProfile oldOwner = source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); + source.sendFeedback(new LiteralText("Set the Claim Owner to ") + .formatted(Formatting.YELLOW).append(new LiteralText(profile.getName()).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) + .append(new LiteralText(oldOwner == null ? "(" + claim.claimBlockOwner + ")" : oldOwner.getName()).formatted(Formatting.GOLD)) + .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) + , false); + claim.claimBlockOwner = profile.getId(); + return 1; + } + private static int setEventMessage(ServerCommandSource source, Claim claim, Claim.Event event, String message) { + switch (event) { + case ENTER_CLAIM: + claim.enterMessage = message.equalsIgnoreCase("reset") ? null : message; + break; + case LEAVE_CLAIM: + claim.leaveMessage = message.equalsIgnoreCase("reset") ? null : message; + break; + } + + if (message.equalsIgnoreCase("reset")) { + source.sendFeedback(new LiteralText("Reset ").append(new LiteralText(event.id).formatted(Formatting.GOLD) + .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) + .append(new LiteralText(claim.name).formatted(Formatting.GOLD))).formatted(Formatting.YELLOW) + , false); + return -1; + } + + source.sendFeedback(new LiteralText("Set ").append(new LiteralText(event.id).formatted(Formatting.GOLD) + .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) + .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" to:").formatted(Formatting.YELLOW))) + .append("\n").append(new LiteralText(ChatColor.translate(message))) + .formatted(Formatting.YELLOW) + , false); + return 1; + } + private static int executeSetting(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : + ClaimManager.INSTANCE.claimsByName.get(claimName); + if (claim1 == null) { + source.sendError(Messages.INVALID_CLAIM); + return -1; + } + + if (input == null) { + return querySettings(source, claim1); + } + + validateCanAccess(player, claim1, admin); + Claim.ClaimSettings.Setting setting = Claim.ClaimSettings.Setting.byId(input); + Claim.Permission permission = Claim.Permission.byId(input); + + if (setting != null && permission == null) + return isQuery ? querySetting(source, claim1, setting) : setSetting(source, claim1, setting, value); + + if (setting == null && permission != null) + return isQuery ? queryPermission(source, claim1, permission) : setPermission(source, claim1, permission, value); + + source.sendError(Messages.INVALID_SETTING); + return -1; + } + private static int executePermission(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : + ClaimManager.INSTANCE.claimsByName.get(claimName); + if (claim1 == null) { + source.sendError(Messages.INVALID_CLAIM); + return -1; + } + + validateCanAccess(player, claim1, admin); + Claim.Permission permission = Claim.Permission.byId(input); + if (permission != null) + return !isQuery ? setPermission(source, claim1, permission, value) : queryPermission(source, claim1, permission); + + source.sendError(Messages.INVALID_SETTING); + return -1; + } + private static int querySetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting) { + boolean enabled = claim.settings.getSetting(setting); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); + return 1; + } + private static int setSetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting, boolean set) { + claim.settings.settings.put(setting, set); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSet setting &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); + return 0; + } + private static int queryPermission(ServerCommandSource source, Claim claim, Claim.Permission permission) { + boolean defaultPerm = claim.permissionManager.defaults.hasPermission(permission); + source.sendFeedback(new LiteralText(ChatColor.translate("&ePermission &6" + permission.id + "&e is set to " + (defaultPerm ? "&a" : "&c") + defaultPerm + "&e for &6" + claim.name)), false); + return 1; + } + private static int setPermission(ServerCommandSource source, Claim claim, Claim.Permission permission, boolean set) { + claim.permissionManager.defaults.setPermission(permission, set); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSet permission &6" + permission.id + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); + return 1; + } + private static int querySettings(ServerCommandSource source, Claim claim) { + source.sendFeedback(new LiteralText("\n").append(new LiteralText("Settings: " + claim.name).formatted(Formatting.YELLOW)).append("\n") + .append(Messages.Command.getSettings(claim)).append("\n"), false); + return 1; + } + private static int executeTrust(CommandContext context, Entity entity, boolean set, @Nullable String claimName) throws CommandSyntaxException { + if (!(entity instanceof PlayerEntity)) { + context.getSource().sendError(new LiteralText("Only Players!")); + return -1; + } + ServerPlayerEntity target = (ServerPlayerEntity) entity; + ServerPlayerEntity p = context.getSource().getPlayer(); + Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getBlockPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); + validateClaim(claim1); + + return setTrust(context, claim1, target, set, false); + } + private static int setTrust(CommandContext context, Claim claim, ServerPlayerEntity target, boolean set, boolean admin) throws CommandSyntaxException { + if (verifyPermission(claim, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + claim.permissionManager.playerPermissions.put(target.getGameProfile().getId(), set ? new Claim.InvertedPermissionMap() : new Claim.DefaultPermissionMap()); + context.getSource().sendFeedback(new LiteralText(target.getGameProfile().getName() + (set ? " now" : " no longer") + " has all the permissions").formatted(Formatting.YELLOW), false); + + String message; + if (set) message = "&aTrusted player &6" + target.getEntityName() + "&a in &6" + claim.name + "\n&aThey now have all the default permissions"; + else message = "&cDistrusted player &6" + target.getEntityName() + "&c in &6" + claim.name + "\n&cThey don't have any permissions now"; + context.getSource().sendFeedback(new LiteralText(ChatColor.translate(message)), false); + } + return 1; + } + private static int setFly(CommandContext context, boolean set) throws CommandSyntaxException { + ServerPlayerEntity player = context.getSource().getPlayer(); + if (set) { + ClaimManager.INSTANCE.flyers.add(player.getUuid()); + player.addMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN), false); + return 1; + } + + player.addMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED), false); + ClaimManager.INSTANCE.flyers.remove(player.getUuid()); + return -1; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java index cf9d404..8b08234 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java @@ -42,7 +42,7 @@ public void useBlocksUntil0(UUID player, int amount) { if (!useClaimBlocks(player, amount)) blocksLeft.put(player, 0); } public void setClaimBlocks(Collection players, int amount) { - players.forEach(player -> setClaimBlocks(player.getGameProfile().getId(), amount)); + players.forEach(player -> setClaimBlocks(player.getGameProfile().getId(), -amount)); } public Claim getClaim(String name){ @@ -63,7 +63,6 @@ public List getPlayerClaims(UUID id) { }); return list; } - public boolean addClaim(Claim claim) { if (claimsByName.containsKey(claim.name)) return false; if (wouldIntersect(claim) && !claim.isChild) return false; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/Config.java index 9152cb6..093e1f1 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Config.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Config.java @@ -9,7 +9,6 @@ public class Config { public static int baseClaimBlocks3d = 15625; public static int baseClaimBlocks2d = 2500; public static boolean claims2d = true; - public static int rent_maxseconds = 7776000; public static String permissionManager = "luckperms"; public static String prefix = "&8[&aClaims&8]&r "; public static String msg_no_perm = "&c&lHey!&r&c Sorry but you don't have permission to do that"; @@ -33,7 +32,6 @@ static void sync() { claims2d = config.getBool("2D claims", claims2d, "Claims extending from y 0 to y 256"); baseClaimBlocks2d = config.getInt("2D base claim blocks", baseClaimBlocks2d, "Area Filled: " + ItsMine.blocksToAreaString2d(baseClaimBlocks2d)); baseClaimBlocks3d = config.getInt("3D base claim blocks", baseClaimBlocks3d, "Area Filled: " + ItsMine.blocksToAreaString3d(baseClaimBlocks3d)); - rent_maxseconds = config.getInt("rent.maxdays", rent_maxseconds, "Maximum rent time in seconds (eg. 90d = 7776000)"); permissionManager = config.getString("permissionManager", permissionManager, "Values: thimble, luckperms, vanilla"); prefix = config.getString("msg.prefix", prefix); msg_interact_entity = config.getString("msg.interact.entity", msg_interact_entity); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java similarity index 84% rename from src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java rename to src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java index 0a4160f..c113083 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java @@ -1,11 +1,10 @@ -package io.github.indicode.fabric.itsmine.util; +package io.github.indicode.fabric.itsmine; -import io.github.indicode.fabric.itsmine.Claim; import net.minecraft.entity.Entity; import java.util.UUID; -public class EntityUtil { +public class EntityUtils { public static boolean canAttack(UUID player, Claim claim, Entity entity) { return claim.hasPermission(player, Claim.Permission.DAMAGE_ENTITY) || @@ -20,7 +19,4 @@ public static boolean isPassive(Entity entity) { public static boolean isHostile(Entity entity) { return !isPassive(entity); } - - - } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index e3b4944..1d3230b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -3,7 +3,6 @@ import io.github.indicode.fabric.itsmine.mixin.BlockActionPacketMixin; import io.github.indicode.fabric.itsmine.mixin.BucketItemMixin; import io.github.indicode.fabric.itsmine.mixin.projectile.OwnedProjectile; -import io.github.indicode.fabric.itsmine.util.BlockUtil; import net.minecraft.block.*; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; @@ -20,7 +19,9 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; +import net.minecraft.world.BlockView; import net.minecraft.world.World; +import net.minecraft.world.dimension.DimensionType; import java.util.*; @@ -78,14 +79,14 @@ public static void setClaimFlying(UUID player, boolean flying) { public static boolean canInteractWith(Claim claim, Block block, UUID player) { return claim.hasPermission(player, Claim.Permission.INTERACT_BLOCKS) || - (BlockUtil.isButton(block) && claim.hasPermission(player, Claim.Permission.USE_BUTTONS)) || - (BlockUtil.isLever(block) && claim.hasPermission(player, Claim.Permission.USE_LEVERS)) || - (BlockUtil.isDoor(block) && claim.hasPermission(player, Claim.Permission.INTERACT_DOORS)) || - (BlockUtil.isContainer(block) && claim.hasPermission(player, Claim.Permission.CONTAINER)) || - (BlockUtil.isChest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_CHEST)) || - (BlockUtil.isEnderchest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_ENDERCHEST)) || - (BlockUtil.isShulkerBox(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_SHULKERBOX)) || - (BlockUtil.isLectern(block) && claim.hasPermission(player, Claim.Permission.INTERACT_LECTERN)); + (BlockUtils.isButton(block) && claim.hasPermission(player, Claim.Permission.USE_BUTTONS)) || + (BlockUtils.isLever(block) && claim.hasPermission(player, Claim.Permission.USE_LEVERS)) || + (BlockUtils.isDoor(block) && claim.hasPermission(player, Claim.Permission.INTERACT_DOORS)) || + (BlockUtils.isContainer(block) && claim.hasPermission(player, Claim.Permission.CONTAINER)) || + (BlockUtils.isChest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_CHEST)) || + (BlockUtils.isEnderchest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_ENDERCHEST)) || + (BlockUtils.isShulkerBox(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_SHULKERBOX)) || + (BlockUtils.isLectern(block) && claim.hasPermission(player, Claim.Permission.INTERACT_LECTERN)); } public static boolean canInteractUsingItem(Claim claim, Item item, UUID player) { @@ -113,18 +114,6 @@ public static boolean canDamageWithProjectile(ProjectileEntity projectile, Entit return false; } - public static > Map sortByValue(Map map) { - List> list = new ArrayList<>(map.entrySet()); - list.sort(Map.Entry.comparingByValue()); - - Map result = new LinkedHashMap<>(); - for (Map.Entry entry : list) { - result.put(entry.getKey(), entry.getValue()); - } - - return result; - } - public static boolean checkCanDamageWithProjectile(Entity entity, MinecraftServer server, UUID uuid) { if (entity.world.isClient) return true; @@ -140,6 +129,15 @@ public static boolean checkCanDamageWithProjectile(Entity entity, MinecraftServe return true; } + public static BlockPos getPosOnGround(BlockPos pos, World world) { + BlockPos blockPos = new BlockPos(pos.getX(), pos.getY(), pos.getZ()); + + do { + blockPos = blockPos.down(); + } while (world.getBlockState(blockPos).isAir()); + + return blockPos.up(); + } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java index ac74472..ddab300 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java @@ -1,24 +1,24 @@ package io.github.indicode.fabric.itsmine; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; import net.fabricmc.api.ModInitializer; +import net.minecraft.SharedConstants; /** * @author Indigo Amann */ public class ItsMine implements ModInitializer { - private static PermissionUtil permissionUtil; + private static Permissions permissions; @Override public void onInitialize() { Config.sync(); - permissionUtil = new PermissionUtil(); + permissions = new Permissions(); //TODO: Enable when developing //SharedConstants.isDevelopment = true; } - public static PermissionUtil permissions() { - return permissionUtil; + public static Permissions permissions() { + return permissions; } public static String blocksToAreaString3d(int blocks) { int base = (int) Math.floor(Math.cbrt(blocks)); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 904182f..db14075 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -56,16 +56,11 @@ public class Messages { .append(line(1, "To set a permission, type ").append(text("/claim permissions player [true | false]").formatted(Formatting.GOLD))) .append(line(2, "To check someone's permission, type ").append(text("/claim permissions player ").formatted(Formatting.GOLD))) .append(line(3, "To see a list of trusted players, type ").append(text("/claim trusted").formatted(Formatting.GOLD))), - header("How to Claim (Resizing)") + header("How to resize claim") .append(line("You can always change the size of your claim if you aren't happy with it!").formatted(Formatting.LIGHT_PURPLE)) .append(line(1, "To expand your claim in a direction, type ").append(text("/claim expand ").formatted(Formatting.GOLD))) .append(line(2, "If you want to specify a direction, you can type ").append(text("/claim expand ").formatted(Formatting.GOLD))) - .append(line(3, "To shrink a claim you do the same thing but replace \"expand\" with \"shrink\"")), - header("How to Claim (Subzones)") - .append(line("Subzones allow you to have seperate permissions / settings in certain areas of your claim").formatted(Formatting.LIGHT_PURPLE)) - .append(line(1, "To create a subzone, you select an area inside your claim the way you would select a normal claim")) - .append(line(2, "Type ").append("/claim subzone add ").formatted(Formatting.GOLD).append(" to create a subzone").formatted(Formatting.YELLOW)) - .append(line(3,"Done! Everything else works the same way claims work")) + .append(line(3, "To shrink a claim you do the same thing but replace \"expand\" with \"shrink\"")) }; public static final Text[] HELP = new Text[]{ diff --git a/src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java b/src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java deleted file mode 100644 index be6d40a..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.github.indicode.fabric.itsmine; - -import net.minecraft.entity.Entity; - -import java.util.Map; -import java.util.UUID; - -public interface MonitorableWorld { - - int loadedEntities(); - - Map EntityList(); -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/NbtUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java similarity index 89% rename from src/main/java/io/github/indicode/fabric/itsmine/util/NbtUtil.java rename to src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java index 99d44db..04e829a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/NbtUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java @@ -1,11 +1,11 @@ -package io.github.indicode.fabric.itsmine.util; +package io.github.indicode.fabric.itsmine; import net.minecraft.nbt.CompoundTag; import java.util.UUID; -public class NbtUtil { +public class NBTUtil { public static UUID getUUID(CompoundTag tag, String key){ if (tag.contains(key + "Least") && tag.contains(key + "Most")) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java similarity index 97% rename from src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java rename to src/main/java/io/github/indicode/fabric/itsmine/Permissions.java index 9fbd7d8..e10ce71 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java @@ -1,7 +1,6 @@ -package io.github.indicode.fabric.itsmine.util; +package io.github.indicode.fabric.itsmine; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Config; import io.github.indicode.fabric.permissions.PermChangeBehavior; import io.github.indicode.fabric.permissions.Thimble; import net.fabricmc.loader.api.FabricLoader; @@ -18,11 +17,11 @@ import java.util.Locale; import java.util.UUID; -public class PermissionUtil { +public class Permissions { private Manager manager; private boolean present; - public PermissionUtil() { + public Permissions() { Logger logger = (Logger) LogManager.getLogger("ItsMine"); logger.info("Setting up Permissions..."); this.manager = Manager.fromString(Config.permissionManager); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java similarity index 72% rename from src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java rename to src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java index 7083946..402a428 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java @@ -1,68 +1,56 @@ -package io.github.indicode.fabric.itsmine.command.subzone; +package io.github.indicode.fabric.itsmine; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Config; -import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; import net.minecraft.util.Formatting; import net.minecraft.util.Pair; import net.minecraft.util.math.BlockPos; import org.jetbrains.annotations.Nullable; +import java.text.Format; import java.util.UUID; -import static io.github.indicode.fabric.itsmine.command.ShowCommand.executeShowClaim; +public class SubzoneCommand { + private static final String SUB_ZONE_NAME_FORMAT = "%s.%s"; -public class CreateCommand { - - public static void register(LiteralArgumentBuilder command) { + public static void register(LiteralArgumentBuilder command, boolean admin) { + LiteralArgumentBuilder builder = CommandManager.literal("subzone"); { - LiteralArgumentBuilder create = CommandManager.literal("create"); + LiteralArgumentBuilder add = CommandManager.literal("add"); RequiredArgumentBuilder name = CommandManager.argument("name", StringArgumentType.word()) - .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), null, false)); + .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), null, admin)); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims() - .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), StringArgumentType.getString(ctx, "claim"), false)); + RequiredArgumentBuilder claim = CommandManager.argument("claim", StringArgumentType.word()) + .suggests(ClaimCommand.CLAIM_PROVIDER) + .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), StringArgumentType.getString(ctx, "claim"), admin)); name.then(claim); - create.then(name); - command.then(create); + add.then(name); + builder.then(add); } + + command.then(builder); } private static int addZone(ServerCommandSource source, String name, @Nullable String claimName, boolean admin) throws CommandSyntaxException { - if (name.length() > 30) { + if (name.length() > ClaimCommand.MAX_NAME_LENGTH) { source.sendError(Messages.MSG_LONG_NAME); return -1; } ServerPlayerEntity player = source.getPlayer(); - Claim claim = validateAndGet(source, claimName, admin); + Claim claim = validateAndGet(source, claimName); Claim subZone = null; - if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SUBZONE)) { - throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); - } - if(!name.matches("[A-Za-z0-9]+")){ - source.sendError(new LiteralText("Invalid claim name")); - return -1; - } - - if (ClaimManager.INSTANCE.claimsByName.containsKey(name)) { - source.sendFeedback(new LiteralText("The name \"" + name + "\" is already taken.").formatted(Formatting.RED), false); - return -1; - } Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); if (selectedPositions == null) { source.sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); @@ -71,14 +59,14 @@ private static int addZone(ServerCommandSource source, String name, @Nullable St } else if (selectedPositions.getRight() == null) { source.sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); } else { - name = claim.name + "." + name; - subZone = createSubzone(source, name, selectedPositions.getLeft(), selectedPositions.getRight(), admin); + name = claim.name + "." + name; + subZone = createSubzone(source, name, selectedPositions.getLeft(), selectedPositions.getRight(), admin); if (subZone.dimension == claim.dimension && claim.includesPosition(subZone.min) && claim.includesPosition(subZone.max) && !claim.isChild){ if (!ClaimManager.INSTANCE.wouldSubzoneIntersect((subZone))){ claim.addSubzone(subZone); ClaimManager.INSTANCE.addClaim(subZone); subZone.permissionManager = claim.permissionManager; - executeShowClaim(source, claim, false); +// subZone.permissionManager.playerPermissions.put(subZone.claimBlockOwner, new Claim.InvertedPermissionMap()); source.sendFeedback(new LiteralText("").append(new LiteralText("Your subzone was created.").formatted(Formatting.GREEN)), false); }else{ player.sendMessage(new LiteralText("Your subzone would overlap with another subzone").formatted(Formatting.RED)); @@ -92,6 +80,7 @@ private static int addZone(ServerCommandSource source, String name, @Nullable St player.sendMessage(new LiteralText("Subzone must be inside the original claim, in the same dimension").formatted(Formatting.RED)); } } + return 0; } @@ -128,7 +117,7 @@ private static Claim createSubzone(ServerCommandSource source, String name, Bloc return new Claim(name, admin ? null : ownerID, min, max, source.getWorld().getDimension().getType(), source.getPlayer().getBlockPos(), true); } - private static Claim validateAndGet(ServerCommandSource source, @Nullable String claimName, boolean admin) throws CommandSyntaxException { + private static Claim validateAndGet(ServerCommandSource source, @Nullable String claimName) throws CommandSyntaxException { ServerPlayerEntity player = source.getPlayer(); Claim claim = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); @@ -136,10 +125,8 @@ private static Claim validateAndGet(ServerCommandSource source, @Nullable String if (claim == null) { throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); } - if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SUBZONE)) { - throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); - } return claim; } + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java deleted file mode 100644 index 14151b1..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.command.EntitySelector; -import net.minecraft.command.arguments.EntityArgumentType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Style; -import net.minecraft.util.Formatting; - -import java.util.UUID; - -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class BlockCommand { - - static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder check = literal("blocks"); - RequiredArgumentBuilder other = argument("player", EntityArgumentType.player()); - other.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); - other.executes(ctx -> blocksLeft(ctx.getSource(), EntityArgumentType.getPlayer(ctx, "player").getGameProfile().getId())); - check.then(other); - check.executes(ctx -> blocksLeft(ctx.getSource())); - command.then(check); - } - - static int blocksLeft(ServerCommandSource source, UUID player) throws CommandSyntaxException { - int blocks = ClaimManager.INSTANCE.getClaimBlocks(player); - source.sendFeedback(new LiteralText((source.getPlayer().getGameProfile().getId().equals(player) ? "You have " : "They have ") + blocks + " blocks left").setStyle(new Style().setColor(Formatting.YELLOW)), false); - return 1; - } - static int blocksLeft(ServerCommandSource source) throws CommandSyntaxException { - int blocks = ClaimManager.INSTANCE.getClaimBlocks(source.getPlayer().getUuid()); - source.sendFeedback(new LiteralText("You have " + blocks + " blocks left").setStyle(new Style().setColor(Formatting.YELLOW)), false); - return 1; - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java deleted file mode 100644 index 0c55bd6..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java +++ /dev/null @@ -1,45 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import io.github.indicode.fabric.itsmine.command.admin.AdminCommand; -import io.github.indicode.fabric.itsmine.command.subzone.SubzoneCommand; -import net.minecraft.server.command.ServerCommandSource; - -import static net.minecraft.server.command.CommandManager.literal; - -public class CommandManager { - - public static void register(CommandDispatcher dispatcher) { - LiteralArgumentBuilder main = literal("itsmine"); - LiteralArgumentBuilder alias = literal("claim"); - register(main, dispatcher); - register(alias, dispatcher); - dispatcher.register(main); - dispatcher.register(alias); - } - private static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { - AdminCommand.register(command, dispatcher); - BlockCommand.register(command); - CreateCommand.register(command); - ExceptionCommand.register(command, false, false); - ExpandCommand.register(command); - FlyCommand.register(command); - HelpCommand.register(command); - InfoCommand.register(command); - ListCommand.register(command); - PermissionsCommand.register(command, false); - RemoveCommand.register(command); - RenameCommand.register(command); - RentableCommand.register(command); - RentCommand.register(command); - RevenueCommand.register(command); - SettingsCommand.register(command, false); - ShowCommand.register(command); - StickCommand.register(command); - SubzoneCommand.register(command, dispatcher); - TransferCommand.register(command); - TrustCommand.register(command); - TrustedCommand.register(command); - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java deleted file mode 100644 index 1c53fb0..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java +++ /dev/null @@ -1,126 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import blue.endless.jankson.annotation.Nullable; -import com.mojang.brigadier.builder.ArgumentBuilder; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.*; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.command.arguments.BlockPosArgumentType; -import net.minecraft.command.arguments.PosArgument; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.HoverEvent; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Style; -import net.minecraft.util.Formatting; -import net.minecraft.util.Pair; -import net.minecraft.util.math.BlockPos; - -import java.util.UUID; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.StringArgumentType.word; -import static io.github.indicode.fabric.itsmine.command.ShowCommand.executeShowClaim; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class CreateCommand { - static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder create = literal("create"); - RequiredArgumentBuilder name = argument("name", word()); - - name.executes(context -> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); - if (selectedPositions == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getLeft() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getRight() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); - } else { - String cname = getString(context, "name"); - if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), false, null) > 0) { - ClaimManager.INSTANCE.stickPositions.remove(player); - } - } - return 0; - }); - - ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); - RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); - max.executes(context -> createClaim(getString(context, "name"), context.getSource(), BlockPosArgumentType.getBlockPos(context, "min"), BlockPosArgumentType.getBlockPos(context, "max"), false, null)); - min.then(max); - name.then(min); - create.then(name); - command.then(create); - } - - public static int createClaim(String name, ServerCommandSource owner, BlockPos posA, BlockPos posB, boolean admin, @Nullable String cOwnerName) throws CommandSyntaxException { - if (name.length() > 30) { - owner.sendError(Messages.MSG_LONG_NAME); - return -1; - } - if(!name.matches("[A-Za-z0-9]+")){ - owner.sendError(new LiteralText("Invalid claim name")); - return -1; - } - UUID ownerID = owner.getPlayer().getGameProfile().getId(); - int x, y = 0, z, mx, my = 255, mz; - if (posA.getX() > posB.getX()) { - x = posB.getX(); - mx = posA.getX(); - } else { - x = posA.getX(); - mx = posB.getX(); - } - if (!Config.claims2d) { - if (posA.getY() > posB.getY()) { - y = posB.getY(); - my = posA.getY(); - } else { - y = posA.getY(); - my = posB.getY(); - } - } - if (posA.getZ() > posB.getZ()) { - z = posB.getZ(); - mz = posA.getZ(); - } else { - z = posA.getZ(); - mz = posB.getZ(); - } - BlockPos min = new BlockPos(x, y, z); - BlockPos max = new BlockPos(mx, my, mz); - BlockPos sub = max.subtract(min); - sub = sub.add(1, Config.claims2d ? 0 : 1,1); - int subInt = sub.getX() * (Config.claims2d ? 1 : sub.getY()) * sub.getZ(); - - Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos(), false); - if (cOwnerName != null) claim.customOwnerName = cOwnerName; - claim.permissionManager.playerPermissions.put(ownerID, new Claim.InvertedPermissionMap()); - if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { - if (!ClaimManager.INSTANCE.wouldIntersect(claim)) { - // works because only the first statement is evaluated if true - if ((admin && ItsMine.permissions().hasPermission(owner, PermissionUtil.Command.INFINITE_BLOCKS, 2)) || ClaimManager.INSTANCE.useClaimBlocks(ownerID, subInt)) { - ClaimManager.INSTANCE.addClaim(claim); - owner.sendFeedback(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)).append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").setStyle(new Style().setColor(Formatting.GREEN).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))))), false); - BlockCommand.blocksLeft(owner); - executeShowClaim(owner, claim, false); - if (admin) - owner.getMinecraftServer().sendMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); - return 1; - } else { - owner.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + subInt + "(" + (subInt - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); - } - } else { - owner.sendFeedback(new LiteralText("Your claim would overlap with another claim").formatted(Formatting.RED), false); - } - } else { - owner.sendFeedback(new LiteralText("The name \"" + name + "\" is already taken.").formatted(Formatting.RED), false); - } - return 0; - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java deleted file mode 100644 index d046f0b..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java +++ /dev/null @@ -1,176 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.arguments.BoolArgumentType; -import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.sun.org.apache.xpath.internal.Arg; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.command.EntitySelector; -import net.minecraft.command.arguments.EntityArgumentType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; - -import static com.mojang.brigadier.arguments.StringArgumentType.*; -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; -import static io.github.indicode.fabric.itsmine.command.TrustCommand.setTrust; -import static io.github.indicode.fabric.itsmine.command.TrustedCommand.showTrustedList; -import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.*; -import static io.github.indicode.fabric.itsmine.util.ClaimUtil.*; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class ExceptionCommand { - - public static void register(LiteralArgumentBuilder command, boolean admin, boolean subzone) { - { - LiteralArgumentBuilder settings = literal("settings"); - RequiredArgumentBuilder claim; - if(subzone){ - claim = ArgumentUtil.getClaims(); - } else { - claim = ArgumentUtil.getSubzones(); - } - - if (!admin) { - settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); - - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return querySettings(context.getSource(), claim1); - }); - } - - RequiredArgumentBuilder id = argument("setting", word()).suggests(SETTINGS_PROVIDER); - RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); - - id.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), getString(context, "claim"), true, false, admin)); - set.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); - - id.then(set); - claim.then(id); - settings.then(claim); - command.then(settings); - } - - LiteralArgumentBuilder exceptions = literal("permissions"); - if (admin) exceptions.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_PERMISSIONS, 2)); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - if (!admin) { - exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); - - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return showTrustedList(context, claim1, false); - }); - } - - if (!admin) { - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(new LiteralText("That claim does not exist")); - return -1; - } - return showTrustedList(context, claim1, true); - }); - } - - { - RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); - LiteralArgumentBuilder remove = literal("remove"); - remove.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - claim1.permissionManager.resetPermissions(player1.getGameProfile().getId()); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + " no longer has an exception in the claim").formatted(Formatting.YELLOW), false); - } - return 0; - }); - player.then(remove); - LiteralArgumentBuilder all = literal("*"); - RequiredArgumentBuilder allstate = argument("allow", BoolArgumentType.bool()); - allstate.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - validateClaim(claim1); - return setTrust(context, claim1, player1.getGameProfile(), BoolArgumentType.getBool(context, "allow"), admin); - }); - all.then(allstate); - player.then(all); - for (Claim.Permission value : Claim.Permission.values()) { - LiteralArgumentBuilder permNode = literal(value.id); - RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); - allow.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - boolean permission = BoolArgumentType.getBool(context, "allow"); - modifyException(claim1, player1, value, permission); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has the permission " + value.name).formatted(Formatting.YELLOW), false); - } - return 0; - }); - permNode.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - boolean permission = hasPermission(claim1, player1, value); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); - } - return 0; - }); - permNode.then(allow); - player.then(permNode); - } - claim.then(player); - } - { - LiteralArgumentBuilder message = literal("message"); - RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); - RequiredArgumentBuilder messageEvent = getMessageEvent(); - RequiredArgumentBuilder messageArgument = getEventMessage(); - messageArgument.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PROPERTIES, context, admin)) { - Claim.Event event = Claim.Event.getById(getString(context, "messageEvent")); - - if (event == null) { - context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); - return -1; - } - - return setEventMessage(context.getSource(), claim1, event, getString(context, "message")); - } - - return -1; - }); - - messageEvent.then(messageArgument); - claimArgument.then(messageEvent); - message.then(claimArgument); - command.then(message); - } - - - exceptions.then(claim); - command.then(exceptions); - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java deleted file mode 100644 index 7d13134..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java +++ /dev/null @@ -1,174 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.arguments.IntegerArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.util.ClaimUtil; -import io.github.indicode.fabric.itsmine.util.ShowerUtil; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; - -import java.util.UUID; -import java.util.concurrent.atomic.AtomicBoolean; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static io.github.indicode.fabric.itsmine.command.BlockCommand.blocksLeft; -import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getDirections; -import static io.github.indicode.fabric.itsmine.util.DirectionUtil.directionByName; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class ExpandCommand { - - public static void register(LiteralArgumentBuilder command) { - { - LiteralArgumentBuilder expand = literal("expand"); - RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = getDirections(); - - direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - IntegerArgumentType.getInteger(context, "distance"), - directionByName(getString(context, "direction")), - context.getSource(), - false - )); - - amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - IntegerArgumentType.getInteger(context, "distance"), - Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], - context.getSource(), - false - )); - - amount.then(direction); - expand.then(amount); - command.then(expand); - } - { - LiteralArgumentBuilder shrink = literal("shrink"); - RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = getDirections(); - - direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - -IntegerArgumentType.getInteger(context, "distance"), - directionByName(getString(context, "direction")), - context.getSource(), - false - )); - - amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - -IntegerArgumentType.getInteger(context, "distance"), - Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], - context.getSource(), - false - )); - - amount.then(direction); - shrink.then(amount); - command.then(shrink); - } - } - - private static void undoExpand(Claim claim, Direction direction, int amount){ - if (amount < 0) claim.expand(direction, -amount); - else claim.shrink(direction, amount); - } - - public static int expand(Claim claim, int amount, Direction direction, ServerCommandSource source, boolean admin) throws CommandSyntaxException { - UUID ownerID = source.getPlayer().getGameProfile().getId(); - if (claim == null) { - source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (direction == null) { - source.sendFeedback(new LiteralText("That is not a valid direction").formatted(Formatting.RED), false); - return 0; - } - if (!claim.permissionManager.hasPermission(ownerID, Claim.Permission.MODIFY_SIZE)) { - source.sendFeedback(new LiteralText("You do not have border change permissions in that claim").formatted(Formatting.RED), false); - if (!admin) return 0; - } - int oldArea = claim.getArea(); - - - if (amount > 0) { - claim.expand(direction, amount); - } - else { - claim.shrink(direction, -amount); - } - - if (!claim.canShrinkWithoutHittingOtherSide(new BlockPos(direction.getOffsetX() * amount, direction.getOffsetY() * amount, direction.getOffsetZ() * amount))) { - source.sendFeedback(new LiteralText("You can't shrink your claim that far. It would pass its opposite wall.").formatted(Formatting.RED), false); - undoExpand(claim, direction, amount); - return 0; - } - - if(!claim.isChild){ - if (ClaimManager.INSTANCE.wouldIntersect(claim)) { - undoExpand(claim, direction, amount); - source.sendFeedback(new LiteralText("Expansion would result in hitting another claim").formatted(Formatting.RED), false); - return 0; - } - - //Check if shrinking would reset a subzone to be outside of its parent claim - AtomicBoolean returnValue = new AtomicBoolean(); - returnValue.set(false); - claim.children.forEach(claim1 -> { - if(!claim1.isInside(claim)){ - undoExpand(claim, direction, amount); - source.sendFeedback(new LiteralText("Shrinking would result in " + claim1.name + " being outside of " + claim.name).formatted(Formatting.RED), true); - returnValue.set(true); - } - }); - if(returnValue.get()) return 0; - - int newArea = claim.getArea() - oldArea; - if (!admin && claim.claimBlockOwner != null && ClaimManager.INSTANCE.getClaimBlocks(ownerID) < newArea) { - undoExpand(claim, direction, amount); - source.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + newArea + "(" + (newArea - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); - blocksLeft(source); - return 0; - } else { - if (!admin && claim.claimBlockOwner != null) ClaimManager.INSTANCE.useClaimBlocks(ownerID, newArea); - source.sendFeedback(new LiteralText("Your claim was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); - blocksLeft(source); - undoExpand(claim, direction, amount); - ShowerUtil.update(claim, source.getWorld(), true); - if (amount > 0) claim.expand(direction, amount); - else claim.shrink(direction, -amount); - ShowerUtil.update(claim, source.getWorld(), false); - } - return 0; - }else{ - Claim parent = ClaimUtil.getParentClaim(claim); - if(!claim.isInside(parent)) { - source.sendFeedback(new LiteralText("Expansion would result in expanding outside of your main claim").formatted(Formatting.RED), false); - undoExpand(claim, direction, amount); - } else if(ClaimManager.INSTANCE.wouldSubzoneIntersect((claim))){ - source.sendFeedback(new LiteralText("Expansion would result in overlapping with another subzone").formatted(Formatting.RED), false); - undoExpand(claim, direction, amount); - }else{ - source.sendFeedback(new LiteralText("Your subzone was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); - //The expansion is undone to hide the claimshower - undoExpand(claim, direction, amount); - ShowerUtil.update(parent, source.getWorld(), true); - if (amount > 0) claim.expand(direction, amount); - else claim.shrink(direction, -amount); - ShowerUtil.update(parent, source.getWorld(), false); - } - } - return 0; - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java deleted file mode 100644 index 9ad50af..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.arguments.BoolArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; - -import static net.minecraft.server.command.CommandManager.literal; - -public class FlyCommand { - static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder fly = literal("fly"); - fly.requires(src -> ItsMine.permissions().hasPermission(src, PermissionUtil.Command.CLAIM_FLY, 2)); - RequiredArgumentBuilder setArgument = CommandManager.argument("set", BoolArgumentType.bool()); - fly.executes((context) -> executeSetFly(context, !ClaimManager.INSTANCE.flyers.contains(context.getSource().getPlayer().getUuid()))); - setArgument.executes((context) -> executeSetFly(context, BoolArgumentType.getBool(context, "set"))); - fly.then(setArgument); - command.then(fly); - } - - private static int executeSetFly(CommandContext context, boolean set) throws CommandSyntaxException { - ServerPlayerEntity player = context.getSource().getPlayer(); - if (set) { - ClaimManager.INSTANCE.flyers.add(player.getUuid()); - player.addMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN), false); - return 1; - } - - player.addMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED), false); - ClaimManager.INSTANCE.flyers.remove(player.getUuid()); - return -1; - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java deleted file mode 100644 index ac15e93..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java +++ /dev/null @@ -1,102 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.arguments.IntegerArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.ChatColor; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.Messages; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.HoverEvent; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getHelpId; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class HelpCommand { - - public static void register(LiteralArgumentBuilder command) { - command.executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); - - LiteralArgumentBuilder help = literal("help"); - help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); - - RequiredArgumentBuilder id = getHelpId(); - RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); - - page.executes((context) -> { - Claim.HelpBook book = Claim.HelpBook.getById(getString(context, "id")); - if (book == null) { - context.getSource().sendError(new LiteralText("Invalid Book!")); - return -1; - } - int p = IntegerArgumentType.getInteger(context, "page"); - - if (p > book.texts.length) p = 1; - return sendPage(context.getSource(), book.texts, p, book.title, book.getCommand()); - }); - - id.then(page); - help.then(id); - command.then(help); - } - - public static int sendPage(ServerCommandSource source, Text[] text, int page, String title, String command) { - int prevPage = page - 2; - int thisPage = page - 1; - int nextPage = page + 1; - final String SEPARATOR = "-----------------------------------------------------"; - Text header = new LiteralText("") - .append(new LiteralText("- [ ").formatted(Formatting.GRAY)) - .append(new LiteralText(title).formatted(Formatting.GOLD)) - .append(" ] ") - .append(SEPARATOR.substring(ChatColor.removeAlternateColorCodes('&', title).length() + 4)) - .formatted(Formatting.GRAY); - - Text button_prev = new LiteralText("") - .append(new LiteralText("<-").formatted(Formatting.WHITE, Formatting.BOLD)) - .append(" ").append(new LiteralText("Prev").formatted(Formatting.GOLD)) - .styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); - if (prevPage >= 0) - style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); - }); - - Text button_next = new LiteralText("") - .append(new LiteralText("Next").formatted(Formatting.GOLD)) - .append(" ").append(new LiteralText("->").formatted(Formatting.WHITE, Formatting.BOLD)).append(" ") - .styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); - if (nextPage <= text.length) - style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); - }); - - Text buttons = new LiteralText("") - .append(new LiteralText("[ ").formatted(Formatting.GRAY)) - .append(button_prev) - .append(" ") - .append( - new LiteralText(String.valueOf(page)).formatted(Formatting.GREEN) - .append(new LiteralText("/").formatted(Formatting.GRAY)) - .append(new LiteralText(String.valueOf(text.length)).formatted(Formatting.GREEN)) - ) - .append(" ") - .append(button_next) - .append(new LiteralText("] ").formatted(Formatting.GRAY)); - - Text footer = new LiteralText("- ") - .formatted(Formatting.GRAY) - .append(buttons).append(new LiteralText(" ------------------------------").formatted(Formatting.GRAY)); - - header.append("\n").append(text[thisPage]).append("\n").append(footer); - source.sendFeedback(header, false); - return 1; - } - - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java deleted file mode 100644 index 3e6aed0..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java +++ /dev/null @@ -1,105 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.authlib.GameProfile; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Config; -import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import io.github.indicode.fabric.itsmine.util.TimeUtil; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.HoverEvent; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.registry.Registry; - -import java.util.Objects; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static net.minecraft.server.command.CommandManager.literal; - -public class InfoCommand { - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder info = literal("info"); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - info.executes(context -> info( - context.getSource(), - ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()) - )); - claim.executes(context -> info(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")) - )); - info.then(claim); - command.then(info); - } - - private static int info(ServerCommandSource source, Claim claim) throws CommandSyntaxException { - if (claim == null) { - source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - - GameProfile owner = claim.claimBlockOwner == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); - BlockPos size = claim.getSize(); - - Text text = new LiteralText("\n"); - text.append(new LiteralText("Claim Info: " + claim.name).formatted(Formatting.GOLD)).append("\n"); - text.append(newInfoLine("Name", new LiteralText(claim.name).formatted(Formatting.WHITE))); - text.append(newInfoLine("Entities", new LiteralText(String.valueOf(claim.getEntities(source.getWorld()))).formatted(Formatting.AQUA))); - text.append(newInfoLine("Owner", - owner != null && claim.customOwnerName == null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : - claim.customOwnerName != null ? new LiteralText(claim.customOwnerName).formatted(Formatting.GOLD) : - new LiteralText("No Owner").formatted(Formatting.RED, Formatting.ITALIC))); - text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); - - - text.append(new LiteralText("").append(new LiteralText("* Settings:").formatted(Formatting.YELLOW)) - .append(Messages.Command.getSettings(claim)).append("\n")); - Text pos = new LiteralText(""); - Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); - Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); - - - pos.append(newInfoLine("Position", new LiteralText("") - .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) - .append(" ") - .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); - text.append(pos); - text.append(newInfoLine("Dimension", new LiteralText(Registry.DIMENSION_TYPE.getId(claim.dimension).getPath()))); - if(claim.rent.isRented()){ - GameProfile tenant = claim.rent.getTenant() == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.rent.getTenant()); - text.append(newInfoLine("Status", new LiteralText("Rented").formatted(Formatting.RED).styled(style -> { - java.util.Date time=new java.util.Date((long) claim.rent.getRentedUntil()*1000); - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Until", new LiteralText(time.toString()).formatted(Formatting.WHITE)).append(newInfoLine("By", new LiteralText(tenant.getName()).formatted(Formatting.WHITE))).append(newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE))))); - }))); - } else if (claim.rent.isRentable() && !claim.rent.isRented()){ - text.append(newInfoLine("Status", new LiteralText("For Rent").formatted(Formatting.GREEN).styled(style -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE)).append(newInfoLine("Max Rent", new LiteralText(claim.rent.getMaxrentAbleTime() / 86400 + " days")).formatted(Formatting.WHITE)))); - }))); - - } else { - text.append(newInfoLine("Status", new LiteralText("Not For Rent").formatted(Formatting.GREEN))); - - } - source.sendFeedback(text, false); - return 1; - } - - private static Text newPosLine(BlockPos pos, Formatting form1, Formatting form2) { - return new LiteralText("") - .append(new LiteralText(String.valueOf(pos.getX())).formatted(form1)) - .append(" ") - .append(new LiteralText(String.valueOf(pos.getY())).formatted(form2)) - .append(" ") - .append(new LiteralText(String.valueOf(pos.getZ())).formatted(form1)); - } - private static Text newInfoLine(String title, Text text) { - return new LiteralText("").append(new LiteralText("* " + title + ": ").formatted(Formatting.YELLOW)) - .append(text).append("\n"); - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java deleted file mode 100644 index 9e2c0b1..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.server.command.ServerCommandSource; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.StringArgumentType.word; -import static io.github.indicode.fabric.itsmine.command.admin.AdminCommand.PERMISSION_CHECK_ADMIN; -import static io.github.indicode.fabric.itsmine.command.admin.ClaimsCommand.list; -import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.PLAYERS_PROVIDER; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class ListCommand { - - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder list = literal("list"); - RequiredArgumentBuilder player = argument("player", word()); - player.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); - player.suggests(PLAYERS_PROVIDER); - list.executes(context -> list(context.getSource(), context.getSource().getName())); - player.requires(PERMISSION_CHECK_ADMIN); - player.executes(context -> list(context.getSource(), getString(context, "player"))); - command.then(list); - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java deleted file mode 100644 index 2fe9ccf..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; -import static io.github.indicode.fabric.itsmine.command.TrustedCommand.showTrustedList; -import static net.minecraft.server.command.CommandManager.literal; - -public class PermissionsCommand { - public static void register(LiteralArgumentBuilder command, boolean admin) { - LiteralArgumentBuilder exceptions = literal("permissions"); - if (admin) - exceptions.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_PERMISSIONS, 2)); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - if (!admin) { - exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); - - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return showTrustedList(context, claim1, false); - }); - } - - if (!admin) { - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(new LiteralText("That claim does not exist")); - return -1; - } - return showTrustedList(context, claim1, true); - }); - } - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java deleted file mode 100644 index 827e85d..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java +++ /dev/null @@ -1,93 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ClaimShower; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import io.github.indicode.fabric.itsmine.util.ClaimUtil; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import io.github.indicode.fabric.itsmine.util.ShowerUtil; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Style; -import net.minecraft.util.Formatting; -import net.minecraft.util.math.BlockPos; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static io.github.indicode.fabric.itsmine.util.ShowerUtil.silentHideShow; -import static net.minecraft.server.command.CommandManager.literal; - -public class RemoveCommand { - - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder delete = literal("remove"); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - LiteralArgumentBuilder confirm = literal("confirm"); - confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); - claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); - claim.then(confirm); - delete.then(claim); - delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); - command.then(delete); - } - public static int requestDelete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { - if (claim == null) { - sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { - if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { - sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); - } else { - sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); - return 0; - } - } - sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to delete the claim \"" + claim.name + "\"? ").formatted(Formatting.GOLD)) - .append(new LiteralText("[I'M SURE]").setStyle(new Style() - .setColor(Formatting.DARK_RED) - .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")))), false); - return 0; - } - public static int delete(ServerCommandSource source, Claim claim, boolean admin) throws CommandSyntaxException { - ServerWorld world = source.getWorld(); - if (claim == null) { - source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (!claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { - if (admin && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)) { - source.sendFeedback(new LiteralText("Deleting a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); - } else { - source.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); - return 0; - } - } - if(!claim.isChild){ - ClaimManager.INSTANCE.releaseBlocksToOwner(claim); - ShowerUtil.update(claim, world, true); - ClaimManager.INSTANCE.claimsByName.remove(claim.name); - for(Claim subzone : claim.children){ - ClaimManager.INSTANCE.claimsByName.remove(subzone.name); - } - }else{ - Claim parent = ClaimUtil.getParentClaim(claim); - ShowerUtil.update(parent, world, true); - ClaimUtil.getParentClaim(claim).removeSubzone(claim); - ClaimManager.INSTANCE.claimsByName.remove(claim.name); - ShowerUtil.update(parent, world, false); - } - source.getWorld().getPlayers().forEach(playerEntity -> { - if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true); - }); - source.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)); - return 0; - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java deleted file mode 100644 index 75612dd..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java +++ /dev/null @@ -1,61 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import io.github.indicode.fabric.itsmine.util.ClaimUtil; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.StringArgumentType.word; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class RenameCommand { - - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder rename = literal("rename"); - RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); - RequiredArgumentBuilder nameArgument = argument("name", word()); - nameArgument.executes((context) -> rename(context, false)); - claimArgument.then(nameArgument); - rename.then(claimArgument); - command.then(rename); - } - - public static int rename(CommandContext context, boolean admin) throws CommandSyntaxException { - String name = getString(context, "claim"); - String newName = getString(context, "name"); - if(!newName.matches("[A-Za-z0-9]+")){ - context.getSource().sendError(new LiteralText("Invalid claim name")); - return -1; - } - Claim claim = ClaimManager.INSTANCE.claimsByName.get(name); - if (claim == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - if (ClaimManager.INSTANCE.claimsByName.containsKey(newName)) { - context.getSource().sendError(new LiteralText("That name is already taken!")); - return -1; - } - if (!admin && !claim.hasPermission(context.getSource().getPlayer().getUuid(), Claim.Permission.MODIFY_PROPERTIES)) { - context.getSource().sendError(new LiteralText("You don't have permission to modify claim properties!")); - return -1; - } - ClaimManager.INSTANCE.claimsByName.remove(name); - if(claim.isChild) claim.name = ClaimUtil.getParentClaim(claim).name + "." + newName; - else claim.name = newName; - ClaimManager.INSTANCE.addClaim(claim); - context.getSource().sendFeedback(new LiteralText("Renamed Claim " + name + " to " + claim.name).formatted(Formatting.GOLD), admin); - return -1; - } - - } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java deleted file mode 100644 index 67b3dcd..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java +++ /dev/null @@ -1,94 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import io.github.indicode.fabric.itsmine.util.TimeUtil; -import net.minecraft.item.ItemStack; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.StringArgumentType.string; -import static net.minecraft.server.command.CommandManager.literal; - -public class RentCommand { - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder rent = literal("rent"); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - RequiredArgumentBuilder days = CommandManager.argument("days", string()); - days.executes(context -> rent(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), getString(context, "days"))); - - claim.then(days); - rent.then(claim); - command.then(rent); - } - private static int rent(ServerCommandSource source, Claim claim, String rentString) throws CommandSyntaxException { - if(claim == null){ - source.sendFeedback(Messages.INVALID_CLAIM, true); - return 0; - } - int rentTime = (int) TimeUtil.convertStringtoSeconds(rentString); - int rentAbleTime = claim.rent.getRentAbleTime(); - int maxrentAbleTime = claim.rent.getMaxrentAbleTime(); - ItemStack currency = claim.rent.getCurrency(); - ItemStack handItem = source.getPlayer().inventory.getMainHandStack(); - ItemStack revenue = handItem.copy(); - if(rentTime % claim.rent.getRentAbleTime() != 0){ - source.sendFeedback(new LiteralText("You have to rent this claim for a time by a multiple of " + TimeUtil.convertSecondsToString(rentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); - return 0; - } - int rentAmount = rentTime / claim.rent.getRentAbleTime(); - if(currency.getItem() != handItem.getItem() || handItem.getCount() < claim.rent.getAmount() * rentAmount){ - source.sendFeedback(new LiteralText("You don't have enough " + currency.getName().asString()).formatted(Formatting.RED), true); - return 0; - } - if (!claim.rent.isRentable()) { - source.sendFeedback(new LiteralText(claim.name + " is not for rent").formatted(Formatting.RED), true); - return 0; - } - if (rentTime > claim.rent.getMaxrentAbleTime()) { - source.sendFeedback(new LiteralText("You can't rent this claim for longer than " + TimeUtil.convertSecondsToString(maxrentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); - return 0; - } - if(claim.rent.getTenant() == null){ - //Setup for claim rent - claim.rent.setTenant(source.getPlayer().getUuid()); - claim.rent.setRentedUntil(claim.rent.getUnixTime() + rentTime); - //Remove items from player - handItem.setCount(handItem.getCount() - claim.rent.getAmount() * rentAmount); - revenue.setCount(claim.rent.getAmount() * rentAmount); - claim.rent.addRevenue(revenue); - //Give Permissions to Tenant - claim.permissionManager.playerPermissions.put(source.getPlayer().getUuid(), new Claim.InvertedPermissionMap()); - source.sendFeedback(new LiteralText("Renting " + claim.name + " for " + claim.rent.getAmount() * rentAmount + " " + claim.rent.getCurrency().getName().asString() + " for " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); - return 1; - } else if(claim.rent.getTenant().toString().equalsIgnoreCase(source.getPlayer().getUuid().toString())){ - if (claim.rent.getRentTimeLeft() + rentTime <= maxrentAbleTime) { - //Setup for claim rent - claim.rent.setRentedUntil(claim.rent.getUnixTime() + rentTime + claim.rent.getRentTimeLeft()); - //Remove items from player - handItem.setCount(handItem.getCount() - claim.rent.getAmount() * rentAmount); - - revenue.setCount(claim.rent.getAmount() * rentAmount); - claim.rent.addRevenue(revenue); - //Give Permissions to Tenant - source.sendFeedback(new LiteralText("Extended rent " + claim.name + " by " + TimeUtil.convertSecondsToString(rentTime, '2', 'a') + "for " + claim.rent.getAmount() * rentAmount + " " + claim.rent.getCurrency().getName().asString()).formatted(Formatting.GREEN), true); - return 1; - } else { - source.sendFeedback(new LiteralText("Rent would exceed the limit by " + TimeUtil.convertSecondsToString(claim.rent.getRentTimeLeft() + rentTime - maxrentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); - return 0; - } - } else { - source.sendFeedback(new LiteralText("This claim is already rented").formatted(Formatting.RED), true); - return 0; - } - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java deleted file mode 100644 index 479404e..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java +++ /dev/null @@ -1,81 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.arguments.IntegerArgumentType; -import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Config; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import io.github.indicode.fabric.itsmine.util.TimeUtil; -import net.minecraft.command.arguments.ItemStackArgument; -import net.minecraft.command.arguments.ItemStackArgumentType; -import net.minecraft.item.ItemStack; -import net.minecraft.server.command.CommandManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.StringArgumentType.string; -import static net.minecraft.server.command.CommandManager.literal; - -public class RentableCommand { - - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder rentable = literal("rentable"); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - - RequiredArgumentBuilder currency = net.minecraft.server.command.CommandManager.argument("item", ItemStackArgumentType.itemStack()).suggests(ArgumentUtil::itemsSuggestion); - RequiredArgumentBuilder amount = net.minecraft.server.command.CommandManager.argument("count", IntegerArgumentType.integer(1)); - RequiredArgumentBuilder days = net.minecraft.server.command.CommandManager.argument("days", StringArgumentType.string() - ); - RequiredArgumentBuilder maxdays = CommandManager.argument("maxdays", string()); - maxdays.executes(context -> makeRentable(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false), IntegerArgumentType.getInteger(context, "count"), getString(context, "days"), getString(context, "maxdays"))); - claim.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if(claim1.rent.getCurrency() !=null || claim1.rent.getAmount() != 0 || claim1.rent.getRentAbleTime() != 0 || claim1.rent.getMaxrentAbleTime() != 0 && claim1.rent.isRentable()) { - context.getSource().sendFeedback(new LiteralText("Can't enable rent for " + claim1.name + ", because no values are set").formatted(Formatting.RED), true); - return 0; - } - if(claim1.rent.getTenant() == null){ - String state = claim1.rent.isRentable() ? "disabled" : "enabled"; - claim1.rent.setRentable(!claim1.rent.isRentable()); - context.getSource().sendFeedback(new LiteralText("Renting for " + claim1.name + " has been " + state).formatted(Formatting.GREEN), true); - return 1; - } else { - context.getSource().sendFeedback(new LiteralText("Can't disable rent for " + claim1.name + ", because it is currently being rented").formatted(Formatting.RED), true); - return 0; - } - }); - - days.then(maxdays); - amount.then(days); - currency.then(amount); - claim.then(currency); - rentable.then(claim); - command.then(rentable); - } - - private static int makeRentable(ServerCommandSource source, Claim claim, ItemStack item, int amount, String rentString, String maxrentString) throws CommandSyntaxException { - int rentTime = TimeUtil.convertStringtoSeconds(rentString); - int maxrentTime = TimeUtil.convertStringtoSeconds(maxrentString); - if(claim != null){ - if(rentTime <= maxrentTime){ - Claim.Rent rent = claim.rent; - rent.setRentable(true); - item.setCount(amount); - rent.setCurrency(item); - rent.setRentAbleTime(rentTime); - if(maxrentTime > Config.rent_maxseconds) maxrentTime = Config.rent_maxseconds; - rent.setMaxrentAbleTime(maxrentTime); - source.sendFeedback(new LiteralText("Claim " + claim.name + " can now be rented for " + amount + " " + item.getName().asString() + " every " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); - return 1; - } - } - return 0; - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java deleted file mode 100644 index 910be0c..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java +++ /dev/null @@ -1,87 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.arguments.BoolArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.*; -import net.minecraft.util.Formatting; -import net.minecraft.util.math.BlockPos; - -import java.util.HashMap; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class RevenueCommand { - - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder revenue = literal("revenue"); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - RequiredArgumentBuilder claimRevenue = argument("claimRevenue", BoolArgumentType.bool()); - revenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); - claim.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); - claimRevenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); - claim.then(claimRevenue); - revenue.then(claim); - command.then(revenue); - } - - private static int revenue(ServerCommandSource source, Claim claim, boolean claimrevenue) throws CommandSyntaxException { - //Show subzones (so you can just claim everything in one place) maybe just all claims - if(claim == null){ - source.sendFeedback(Messages.INVALID_CLAIM,true); - return 0; - } - if(!claim.claimBlockOwner.toString().equalsIgnoreCase(source.getPlayer().getUuid().toString())){ - source.sendFeedback(Messages.NO_PERMISSION, true); - return 0; - } - - if(claimrevenue){ - for(ItemStack itemStack : claim.rent.getRevenue()){ - source.getPlayer().inventory.insertStack(itemStack); - } - claim.rent.clearRevenue(); - return 1; - - } else { - if(claim.rent.getRevenue().isEmpty()){ - source.sendFeedback(new LiteralText("No Revenue").formatted(Formatting.RED), true); - return 0; - } - Text text = new LiteralText("Revenue\n").formatted(Formatting.AQUA); - HashMap hashMap = new HashMap<>(); - for(ItemStack itemStack : claim.rent.getRevenue()){ - Item value = itemStack.getItem(); - if(hashMap.containsKey(value)){ - hashMap.put(value, hashMap.get(value) + itemStack.getCount()); - } else { - hashMap.put(value, + itemStack.getCount()); - } - - hashMap.forEach((item, integer) -> { - boolean color = true; - text.append(new LiteralText(String.valueOf(integer)).append(" ").append(new TranslatableText(item.getTranslationKey())).append(" ").formatted(color ? Formatting.GOLD : Formatting.YELLOW)).styled(style -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to claim revenue!").formatted(Formatting.GREEN))); - style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim revenue " + claim.name + " true")); - }); - color = !color; - }); - - } - text.append("\n"); - source.sendFeedback(text, true); - return 1; - } - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java deleted file mode 100644 index acdaf05..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.arguments.BoolArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import net.minecraft.server.command.ServerCommandSource; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.StringArgumentType.word; -import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; -import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.SETTINGS_PROVIDER; -import static io.github.indicode.fabric.itsmine.util.ClaimUtil.executeSetting; -import static io.github.indicode.fabric.itsmine.util.ClaimUtil.querySettings; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class SettingsCommand { - - public static void register(LiteralArgumentBuilder command, boolean admin) { - LiteralArgumentBuilder settings = literal("settings"); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - - if (!admin) { - settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); - - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return querySettings(context.getSource(), claim1); - }); - } - - RequiredArgumentBuilder id = argument("setting", word()).suggests(SETTINGS_PROVIDER); - RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); - - id.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), getString(context, "claim"), true, false, admin)); - set.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); - - id.then(set); - claim.then(id); - settings.then(claim); - command.then(settings); - } - - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java deleted file mode 100644 index 63df117..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java +++ /dev/null @@ -1,54 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ClaimShower; -import io.github.indicode.fabric.itsmine.Config; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import io.github.indicode.fabric.itsmine.util.ClaimUtil; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static io.github.indicode.fabric.itsmine.util.ShowerUtil.silentHideShow; -import static net.minecraft.server.command.CommandManager.literal; - -public class ShowCommand { - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder show = literal("show"); - show.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().dimension.getType()), false)); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - claim.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "name")), false)); - show.then(claim); - command.then(show); - - LiteralArgumentBuilder hide = literal("hide"); - hide.executes(context -> executeShowClaim(context.getSource(), null, true)); - command.then(hide); - } - - public static int executeShowClaim(ServerCommandSource source, Claim claim, boolean reset) throws CommandSyntaxException { - ServerPlayerEntity player = source.getPlayer(); - if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!Config.claims2d &&((ClaimShower)player).getShownClaim() != claim)) executeShowClaim(source, ((ClaimShower)player).getShownClaim(), true); - if (reset && ((ClaimShower)player).getShownClaim() != null) claim = ((ClaimShower)player).getShownClaim(); - if (claim != null) { - if (!claim.dimension.equals(source.getWorld().getDimension().getType())) { - if (claim == ((ClaimShower)player).getShownClaim()) ((ClaimShower)player).setShownClaim(null); // just so we dont have extra packets on this - source.sendFeedback(new LiteralText("That claim is not in this dimension").formatted(Formatting.RED), false); - return 0; - } - source.sendFeedback(new LiteralText((!reset ? "Showing" : "Hiding") + " claim: " + claim.name).formatted(Formatting.GREEN), false); - if(claim.isChild) silentHideShow(player, ClaimUtil.getParentClaim(claim), reset, true); - else silentHideShow(player, claim, reset, true); - - } else { - source.sendFeedback(new LiteralText("That is not a valid claim").formatted(Formatting.RED), false); - } - return 0; - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/StickCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/StickCommand.java deleted file mode 100644 index 46d1e27..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/StickCommand.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import io.github.indicode.fabric.itsmine.ClaimManager; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; -import net.minecraft.util.Pair; -import net.minecraft.util.math.BlockPos; - -import static net.minecraft.server.command.CommandManager.literal; - -public class StickCommand { - - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder stick = literal("stick"); - stick.executes(context -> { - Pair posPair = ClaimManager.INSTANCE.stickPositions.get(context.getSource().getPlayer()); - context.getSource().sendFeedback(new LiteralText(posPair == null ? "You can now use a stick to create claims. Run this command again to disable" : "Claim stick disabled. Run this command again to enable").formatted(Formatting.DARK_PURPLE), false); - if (posPair == null) { - ClaimManager.INSTANCE.stickPositions.put(context.getSource().getPlayer(), new Pair<>(null, null)); - } else { - ClaimManager.INSTANCE.stickPositions.remove(context.getSource().getPlayer()); - } - return 0; - }); - command.then(stick); - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java deleted file mode 100644 index f6d9e07..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java +++ /dev/null @@ -1,147 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.authlib.GameProfile; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.command.EntitySelector; -import net.minecraft.command.arguments.EntityArgumentType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Style; -import net.minecraft.util.Formatting; -import net.minecraft.util.math.BlockPos; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class TransferCommand { - public static void register(LiteralArgumentBuilder command) { - - LiteralArgumentBuilder transfer = literal("transfer"); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); - LiteralArgumentBuilder confirm = literal("confirm"); - confirm.executes(context -> { - final String string = "-accept-"; - ServerPlayerEntity p = EntityArgumentType.getPlayer(context, "player"); - String input = getString(context, "claim"); - String claimName = input.replace(string, ""); - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(claimName); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - if (input.startsWith(string)) { - return acceptTransfer(context.getSource()); - } - return transfer(context.getSource(), claim1, p, false); - }); - player.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), EntityArgumentType.getPlayer(context, "player"), false)); - player.then(confirm); - claim.then(player); - transfer.then(claim); - transfer.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), EntityArgumentType.getPlayer(context, "player"), false)); - command.then(transfer); - } - - public static int acceptTransfer(ServerCommandSource sender) throws CommandSyntaxException { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(pendingClaimTransfers.get(sender.getPlayer().getGameProfile().getId())); - if (claim == null) { - sender.sendFeedback(new LiteralText("You have no pending claim transfers").formatted(Formatting.RED), false); - return 0; - } - if (sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner) != null) { - sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); - } - Claim.ClaimPermissionMap op = claim.permissionManager.playerPermissions.get(claim.claimBlockOwner); - claim.permissionManager.playerPermissions.put(claim.claimBlockOwner, claim.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); - claim.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op); - claim.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); - claim.children.forEach(subzone -> { - try { - Claim.ClaimPermissionMap op1 = subzone.permissionManager.playerPermissions.get(subzone.claimBlockOwner); - subzone.permissionManager.playerPermissions.put(subzone.claimBlockOwner, subzone.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); - subzone.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op1); - subzone.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); - } catch (CommandSyntaxException e) { - e.printStackTrace(); - } - }); - return 0; - } - - private static int requestTransfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { - if (claim == null) { - sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if(claim.isChild){ - sender.sendFeedback(new LiteralText("You can't transfer ownership of subzones").formatted(Formatting.RED), false); - return 0; - } - if(sender.getPlayer().getUuidAsString().equalsIgnoreCase(player.getUuidAsString())){ - sender.sendFeedback(new LiteralText("Huh? That makes no sence").formatted(Formatting.RED), true); - return 0; - } - if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { - if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { - sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); - } else { - sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); - return 0; - } - } - sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to transfer ownership of \"" + claim.name + "\" to " + player.getGameProfile().getName() + "? ").formatted(Formatting.GOLD)) - .append(new LiteralText("[YES]").setStyle(new Style() - .setColor(Formatting.DARK_RED) - .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")))), false); - return 0; - } - private static Map pendingClaimTransfers = new HashMap<>(); - private static int transfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { - if (claim == null) { - sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (claim.isChild) { - sender.sendFeedback(new LiteralText("You can't transfer ownership of subzones").formatted(Formatting.RED), false); - return 0; - } - if (sender.getPlayer().getUuidAsString().equalsIgnoreCase(player.getUuidAsString())) { - sender.sendFeedback(new LiteralText("Huh? That makes no sence").formatted(Formatting.RED), true); - return 0; - } - if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { - if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { - sender.sendFeedback(new LiteralText("Transfering ownership of a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); - } else { - sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); - return 0; - } - } - GameProfile profile = sender.getWorld().getServer().getUserCache().getByUuid(claim.claimBlockOwner); - sender.sendFeedback(new LiteralText("Transferring ownership of the claim \"" + claim.name + "\" to " + player.getGameProfile().getName() + " if they accept").formatted(Formatting.GREEN), claim.claimBlockOwner != player.getGameProfile().getId()); - player.sendMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) - .append(new LiteralText("[ACCEPT]").setStyle(new Style() - .setColor(Formatting.GREEN) - .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim transfer -accept-" + claim.name + " " + player.getEntityName() + " confirm"))))); - pendingClaimTransfers.put(player.getGameProfile().getId(), claim.name); - return 0; - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java deleted file mode 100644 index 826a439..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java +++ /dev/null @@ -1,85 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import blue.endless.jankson.annotation.Nullable; -import com.mojang.authlib.GameProfile; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import net.minecraft.command.arguments.GameProfileArgumentType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; - -import java.util.Collection; -import java.util.concurrent.atomic.AtomicInteger; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static io.github.indicode.fabric.itsmine.util.ClaimUtil.validateClaim; -import static io.github.indicode.fabric.itsmine.util.ClaimUtil.verifyPermission; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class TrustCommand { - public static void register(LiteralArgumentBuilder command) { - { - LiteralArgumentBuilder trust = literal("trust"); - RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); - RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); - playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, null))); - claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, getString(context, "claim")))); - - playerArgument.then(claimArgument); - trust.then(playerArgument); - command.then(trust); - } - { - LiteralArgumentBuilder distrust = literal("distrust"); - RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); - RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); - - playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, null))); - claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, getString(context, "claim")))); - - playerArgument.then(claimArgument); - distrust.then(playerArgument); - command.then(distrust); - } - } - private static int executeTrust(CommandContext context, Collection targetCollection, boolean set, @Nullable String claimName) throws CommandSyntaxException { - AtomicInteger integer = new AtomicInteger(); - - if(targetCollection.isEmpty()){ - context.getSource().sendFeedback(new LiteralText("No player provided").formatted(Formatting.RED), true); - return 0; - } - ServerPlayerEntity p = context.getSource().getPlayer(); - Claim claim = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getBlockPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); - validateClaim(claim); - targetCollection.iterator().forEachRemaining(gameProfile -> { - try { - //This is supposed to check if the player has played before :shrug: - if(context.getSource().getMinecraftServer().getUserCache().getByUuid(gameProfile.getId()) == gameProfile){ - integer.set(setTrust(context, claim, gameProfile, set, false)); - } else { - context.getSource().sendFeedback(new LiteralText("Unknown player!").formatted(Formatting.RED), true); - integer.set(0); - } - } catch (CommandSyntaxException e) { - e.printStackTrace(); - } - }); - return integer.get(); - } - static int setTrust(CommandContext context, Claim claim, GameProfile target, boolean set, boolean admin) throws CommandSyntaxException { - if (verifyPermission(claim, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - claim.permissionManager.playerPermissions.put(target.getId(), set ? new Claim.InvertedPermissionMap() : new Claim.DefaultPermissionMap()); - context.getSource().sendFeedback(new LiteralText(target.getName() + (set ? " now" : " no longer") + " has all the permissions").formatted(Formatting.YELLOW), false); - } - return 1; - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java deleted file mode 100644 index 092aa45..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java +++ /dev/null @@ -1,124 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.authlib.GameProfile; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.HoverEvent; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; - -import java.util.concurrent.atomic.AtomicInteger; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static net.minecraft.server.command.CommandManager.literal; - -public class TrustedCommand { - - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder trusted = literal("trusted"); - RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); - trusted.executes((context)-> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); - if (claim == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return showTrustedList(context, claim, false); - }); - - claimArgument.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return showTrustedList(context, claim, false); - }); - trusted.then(claimArgument); - command.then(trusted); - } - - static int showTrustedList(CommandContext context, Claim claim, boolean showSelf) throws CommandSyntaxException { - ServerCommandSource source = context.getSource(); - ServerPlayerEntity player = source.getPlayer(); - int mapSize = claim.permissionManager.playerPermissions.size(); - - if (mapSize == 1 && !showSelf) { - source.sendError(new LiteralText(claim.name + " is not trusting anyone!")); - return -1; - } - - Text text = new LiteralText("\n"); - text.append(new LiteralText("Trusted players for Claim ").formatted(Formatting.YELLOW)) - .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append("\n"); - - AtomicInteger atomicInteger = new AtomicInteger(); - claim.permissionManager.playerPermissions.forEach((uuid, perm) -> { - atomicInteger.incrementAndGet(); - Text pText = new LiteralText(""); - Text owner; - GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); - if (profile != null) { - owner = new LiteralText(profile.getName()); - } else { - owner = new LiteralText(uuid.toString()).styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to Copy"))); - style.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); - }); - } - - pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) - .append(owner.formatted(Formatting.YELLOW)); - - Text hover = new LiteralText(""); - hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); - - int allowed = 0; - int i = 0; - boolean nextColor = false; - Text perms = new LiteralText(""); - - for (Claim.Permission value : Claim.Permission.values()) { - if (claim.permissionManager.hasPermission(uuid, value)) { - Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; - perms.append(new LiteralText(value.id).formatted(formatting)).append(" "); - if (i == 3) perms.append("\n"); - allowed++; - i++; - nextColor = !nextColor; - } - } - - if (allowed == Claim.Permission.values().length) { - hover.append(new LiteralText("All " + allowed + " Permissions").formatted(Formatting.YELLOW, Formatting.ITALIC)); - } else { - hover.append(perms); - } - - pText.append(new LiteralText(" ") - .append(new LiteralText("(").formatted(Formatting.GOLD)) - .append(new LiteralText(String.valueOf(allowed)).formatted(Formatting.GREEN)) - .append(new LiteralText("/").formatted(Formatting.GOLD)) - .append(new LiteralText(String.valueOf(Claim.Permission.values().length)).formatted(Formatting.YELLOW)) - .append(new LiteralText(")").formatted(Formatting.GOLD)) - ); - - pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); - text.append(pText).append("\n"); - }); - - source.sendFeedback(text, false); - return 1; - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java deleted file mode 100644 index 4d4df91..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -package io.github.indicode.fabric.itsmine.command.admin; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.command.ExceptionCommand; -import io.github.indicode.fabric.itsmine.command.PermissionsCommand; -import io.github.indicode.fabric.itsmine.command.SettingsCommand; -import net.minecraft.server.command.ServerCommandSource; - -import java.util.function.Predicate; - -import static net.minecraft.server.command.CommandManager.literal; - -public class AdminCommand { - - public static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { - LiteralArgumentBuilder admin = literal("admin"); - admin.requires(PERMISSION_CHECK_ADMIN); - registerAdmin(admin, dispatcher); - command.then(admin); - } - - private static void registerAdmin(LiteralArgumentBuilder admin, CommandDispatcher dispatcher) { - BlocksCommand.register(admin); - ClaimsCommand.register(admin, dispatcher); - CreateCommand.register(admin); - EntitiesCommand.register(admin); - ExceptionCommand.register(admin, true, false); - ExpandCommand.register(admin); - IgnoreCommand.register(admin); - ListAllCommand.register(admin); - OwnerCommand.register(admin); - PermissionsCommand.register(admin, true); - RemoveCommand.register(admin); - RenameCommand.register(admin); - SettingsCommand.register(admin, true); - } - - private static Predicate perm(String str) { - return perm(str, 2); - } - private static Predicate perm(String str, int op) { - return source -> ItsMine.permissions().hasPermission(source, "itsmine." + str, op); - } - public static final Predicate PERMISSION_CHECK_ADMIN = src -> perm("admin").test(src); - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/BlocksCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/BlocksCommand.java deleted file mode 100644 index 473431a..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/BlocksCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -package io.github.indicode.fabric.itsmine.command.admin; - -import com.mojang.brigadier.arguments.IntegerArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.command.EntitySelector; -import net.minecraft.command.arguments.EntityArgumentType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; - -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class BlocksCommand { - - public static void register(LiteralArgumentBuilder command) { - { - LiteralArgumentBuilder add = literal("addBlocks"); - add.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); - RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); - RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); - amount.executes(context -> { - ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); - context.getSource().sendFeedback(new LiteralText("Gave " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); - return 0; - }); - player.then(amount); - add.then(player); - command.then(add); - } - { - LiteralArgumentBuilder remove = literal("removeBlocks"); - remove.requires(source ->ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); - RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); - RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); - amount.executes(context -> { - ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), -IntegerArgumentType.getInteger(context, "amount")); - context.getSource().sendFeedback(new LiteralText("Took " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); - return 0; - }); - player.then(amount); - remove.then(player); - command.then(remove); - } - { - LiteralArgumentBuilder set = literal("setBlocks"); - set.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); - RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); - RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); - amount.executes(context -> { - ClaimManager.INSTANCE.setClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); - context.getSource().sendFeedback(new LiteralText("Set claim block amount to " + IntegerArgumentType.getInteger(context, "amount")).formatted(Formatting.GREEN), true); - return 0; - }); - player.then(amount); - set.then(player); - command.then(set); - } - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java deleted file mode 100644 index 69de7bf..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java +++ /dev/null @@ -1,70 +0,0 @@ -package io.github.indicode.fabric.itsmine.command.admin; - -import com.mojang.authlib.GameProfile; -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Messages; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.HoverEvent; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; - -import java.util.List; - -import static net.minecraft.server.command.CommandManager.literal; - -public class ClaimsCommand { - public static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { - LiteralArgumentBuilder claims = literal("claims"); - claims.executes(context -> list(context.getSource(), context.getSource().getName())); - dispatcher.register(claims); - } - - public static int list(ServerCommandSource source, String target) throws CommandSyntaxException { - ServerPlayerEntity player = source.getPlayer(); - GameProfile profile = target == null ? player.getGameProfile() : source.getMinecraftServer().getUserCache().findByName(target); - - if (profile == null) { - source.sendError(Messages.INVALID_PLAYER); - return -1; - } - - List claims = ClaimManager.INSTANCE.getPlayerClaims(profile.getId()); - if (claims.isEmpty()) { - source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); - return -1; - } - - - Text text = new LiteralText("\n").append(new LiteralText("Claims (" + target + "): ").formatted(Formatting.GOLD)).append("\n "); - boolean nextColor = false; - for (Claim claim : claims) { - if(!claim.isChild) { - Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { - Text hoverText = new LiteralText("Click for more Info").formatted(Formatting.GREEN); - if (claim.children.size() > 0) { - hoverText.append("\n\nSubzones:"); - for (Claim subzone : claim.children) { - hoverText.append("\n- " + subzone.name); - } - } - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); - - style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); - }); - - nextColor = !nextColor; - text.append(cText.append(" ")); - } - } - - source.sendFeedback(text.append("\n"), false); - return 1; - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/CreateCommand.java deleted file mode 100644 index f7ed03c..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/CreateCommand.java +++ /dev/null @@ -1,81 +0,0 @@ -package io.github.indicode.fabric.itsmine.command.admin; - -import com.mojang.brigadier.builder.ArgumentBuilder; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.command.arguments.BlockPosArgumentType; -import net.minecraft.command.arguments.PosArgument; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; -import net.minecraft.util.Pair; -import net.minecraft.util.math.BlockPos; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.StringArgumentType.word; -import static io.github.indicode.fabric.itsmine.command.CreateCommand.createClaim; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class CreateCommand { - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder create = literal("create"); - create.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2)); - ArgumentBuilder name = argument("name", word()); - ArgumentBuilder customOwner = argument("customOwnerName", word()); - ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); - RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); - max.executes(context -> createClaim( - getString(context, "name"), - context.getSource(), - BlockPosArgumentType.getBlockPos(context, "min"), - BlockPosArgumentType.getBlockPos(context, "max"), - true, - null - )); - name.executes(context -> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); - if (selectedPositions == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getLeft() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getRight() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); - } else { - String cname = getString(context, "name"); - if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, null) > 0) { - ClaimManager.INSTANCE.stickPositions.remove(player); - } - } - return 0; - }); - customOwner.executes(context -> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); - if (selectedPositions == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getLeft() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getRight() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); - } else { - String cname = getString(context, "name"); - if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, getString(context, "customOwnerName")) > 0) { - ClaimManager.INSTANCE.stickPositions.remove(player); - } - } - return 0; - }); - min.then(max); - name.then(customOwner); - name.then(min); - create.then(name); - command.then(create); - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java deleted file mode 100644 index 5810829..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.indicode.fabric.itsmine.command.admin; - -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static net.minecraft.server.command.CommandManager.literal; - -public class EntitiesCommand { - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder entity = literal("entities"); - entity.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - entity.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); - context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); - claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { - context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); - }); - return 1; - }); - claim.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); - claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { - context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); - }); - return 1; - }); - entity.then(claim); - command.then(entity); - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java deleted file mode 100644 index 86e7b90..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java +++ /dev/null @@ -1,76 +0,0 @@ -package io.github.indicode.fabric.itsmine.command.admin; - -import com.mojang.brigadier.arguments.IntegerArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.util.math.Direction; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static io.github.indicode.fabric.itsmine.command.ExpandCommand.expand; -import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getDirections; -import static io.github.indicode.fabric.itsmine.util.DirectionUtil.directionByName; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class ExpandCommand { - - public static void register(LiteralArgumentBuilder command) { - { - LiteralArgumentBuilder expand = literal("expand"); - expand.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); - RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = getDirections(); - - direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - IntegerArgumentType.getInteger(context, "distance"), - directionByName(getString(context, "direction")), - context.getSource(), - true - )); - - amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - IntegerArgumentType.getInteger(context, "distance"), - Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], - context.getSource(), - true - )); - - amount.then(direction); - expand.then(amount); - command.then(expand); - } - { - LiteralArgumentBuilder shrink = literal("shrink"); - shrink.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); - RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = getDirections(); - - direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - -IntegerArgumentType.getInteger(context, "distance"), - directionByName(getString(context, "direction")), - context.getSource(), - true - )); - - amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - -IntegerArgumentType.getInteger(context, "distance"), - Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], - context.getSource(), - true - )); - - amount.then(direction); - shrink.then(amount); - command.then(shrink); - } - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/IgnoreCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/IgnoreCommand.java deleted file mode 100644 index 5c11385..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/IgnoreCommand.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.indicode.fabric.itsmine.command.admin; - -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; - -import java.util.UUID; - -import static net.minecraft.server.command.CommandManager.literal; - -public class IgnoreCommand { - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder ignore = literal("ignoreClaims"); - ignore.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_IGNORE_CLAIMS, 2)); - ignore.executes(context -> { - UUID id = context.getSource().getPlayer().getGameProfile().getId(); - boolean isIgnoring = ClaimManager.INSTANCE.ignoringClaims.contains(id); - if (isIgnoring) ClaimManager.INSTANCE.ignoringClaims.remove(id); - else ClaimManager.INSTANCE.ignoringClaims.add(id); - context.getSource().sendFeedback(new LiteralText("You are " + (isIgnoring ? "no longer" : "now") + " ignoring claims.").formatted(Formatting.GREEN), false); - return 0; - }); - command.then(ignore); - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java deleted file mode 100644 index fd94c46..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.indicode.fabric.itsmine.command.admin; - -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.Claim; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; - -import java.util.List; - -import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getPlayers; -import static io.github.indicode.fabric.itsmine.util.ClaimUtil.getClaims; -import static net.minecraft.server.command.CommandManager.literal; - -public class ListAllCommand { - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder listall = literal("listall"); - RequiredArgumentBuilder player = getPlayers(); - listall.executes(context -> listall(context.getSource())); - command.then(listall); - } - private static int listall(ServerCommandSource source){ - List claims = getClaims(); - Text text = new LiteralText("\n").append(new LiteralText("Claims").formatted(Formatting.GOLD)).append("\n "); - for (Claim claim : claims) { - Text cText = new LiteralText(claim.name).formatted(Formatting.GOLD); - text.append(cText.append(" ")); - } - source.sendFeedback(text.append("\n"), false); - return 1; - } - - - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java deleted file mode 100644 index 3d99a42..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java +++ /dev/null @@ -1,114 +0,0 @@ -package io.github.indicode.fabric.itsmine.command.admin; - -import com.mojang.authlib.GameProfile; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import net.minecraft.command.arguments.GameProfileArgumentType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; - -import java.util.Collection; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.StringArgumentType.word; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class OwnerCommand { - public static void register(LiteralArgumentBuilder command) { - { - LiteralArgumentBuilder set = literal("setOwner"); - RequiredArgumentBuilder newOwner = argument("newOwner", GameProfileArgumentType.gameProfile()); - RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); - - newOwner.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); - if (claim == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - - Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); - - if (profiles.size() > 1) { - context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); - return -1; - } - return setOwner(context.getSource(), claim, profiles.iterator().next()); - }); - - claimArgument.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - - Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); - - if (profiles.size() > 1) { - context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); - return -1; - } - return setOwner(context.getSource(), claim, profiles.iterator().next()); - }); - - newOwner.then(claimArgument); - set.then(newOwner); - command.then(set); - } - - { - LiteralArgumentBuilder set = literal("setOwnerName"); - RequiredArgumentBuilder nameArgument = argument("newName", word()); - RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); - - nameArgument.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); - if (claim == null) { - context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return -1; - } - return setOwnerName(context.getSource(), claim, getString(context, "newName")); - }); - - claimArgument.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim == null) { - context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return -1; - } - return setOwnerName(context.getSource(), claim, getString(context, "newName")); - }); - - nameArgument.then(claimArgument); - set.then(nameArgument); - command.then(set); - } - } - private static int setOwnerName(ServerCommandSource source, Claim claim, String input) { - String name = input.equals("reset") ? null : input; - source.sendFeedback(new LiteralText("Set the Custom Owner Name to ") - .formatted(Formatting.YELLOW).append(new LiteralText(name == null ? "Reset" : name).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) - .append(new LiteralText(claim.customOwnerName == null ? "Not Present" : claim.customOwnerName).formatted(Formatting.GOLD)) - .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) - , false); - claim.customOwnerName = input; - return 1; - } - private static int setOwner(ServerCommandSource source, Claim claim, GameProfile profile) { - GameProfile oldOwner = source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); - source.sendFeedback(new LiteralText("Set the Claim Owner to ") - .formatted(Formatting.YELLOW).append(new LiteralText(profile.getName()).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) - .append(new LiteralText(oldOwner == null ? "(" + claim.claimBlockOwner + ")" : oldOwner.getName()).formatted(Formatting.GOLD)) - .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) - , false); - claim.claimBlockOwner = profile.getId(); - return 1; - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java deleted file mode 100644 index 5b2f809..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.indicode.fabric.itsmine.command.admin; - -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.util.math.BlockPos; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static io.github.indicode.fabric.itsmine.command.RemoveCommand.delete; -import static io.github.indicode.fabric.itsmine.command.RemoveCommand.requestDelete; -import static net.minecraft.server.command.CommandManager.literal; - -public class RemoveCommand { - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder delete = literal("remove"); - delete.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - LiteralArgumentBuilder confirm = literal("confirm"); - confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); - claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); - claim.then(confirm); - delete.then(claim); - delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), true)); - command.then(delete); - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RenameCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RenameCommand.java deleted file mode 100644 index 1798fcb..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RenameCommand.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.github.indicode.fabric.itsmine.command.admin; - -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import net.minecraft.server.command.ServerCommandSource; - -import static com.mojang.brigadier.arguments.StringArgumentType.word; -import static io.github.indicode.fabric.itsmine.command.RenameCommand.rename; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class RenameCommand { - public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder rename = literal("rename"); - RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); - RequiredArgumentBuilder nameArgument = argument("name", word()); - nameArgument.executes((context) -> rename(context, true)); - claimArgument.then(nameArgument); - rename.then(claimArgument); - command.then(rename); - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java deleted file mode 100644 index 7d5c8a5..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.indicode.fabric.itsmine.command.subzone; - -import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import io.github.indicode.fabric.itsmine.command.*; -import net.minecraft.server.command.ServerCommandSource; - -import static net.minecraft.server.command.CommandManager.literal; - -public class SubzoneCommand { - public static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { - LiteralArgumentBuilder subzone = literal("subzone"); - registerSubzone(subzone, dispatcher); - command.then(subzone); - } - - public static void registerSubzone(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { - CreateCommand.register(command); - ExceptionCommand.register(command, false, true); - ExpandCommand.register(command); - InfoCommand.register(command); - PermissionsCommand.register(command, false); - RemoveCommand.register(command); - RenameCommand.register(command); - RentableCommand.register(command); - RentCommand.register(command); - RevenueCommand.register(command); - SettingsCommand.register(command, false); - ShowCommand.register(command); -// SubzoneCommand.register(command, dispatcher); - TrustCommand.register(command); - TrustedCommand.register(command); - } -} \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java deleted file mode 100644 index 8c3330a..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java +++ /dev/null @@ -1,49 +0,0 @@ -package io.github.indicode.fabric.itsmine.mixin; - -import blue.endless.jankson.annotation.Nullable; -import com.mojang.authlib.GameProfile; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.util.ClaimUtil; -import net.minecraft.entity.passive.AnimalEntity; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.UUID; - -@Mixin(AnimalEntity.class) -public abstract class AnimalEntityMixin { - - @Shadow private UUID lovingPlayer; - - @Shadow @Nullable - public abstract ServerPlayerEntity getLovingPlayer(); - - @Shadow public abstract void setLoveTicks(int loveTicks); - - @Shadow public abstract void resetLoveTicks(); - - @Inject(method = "canBreedWith", at = @At(value = "HEAD"), cancellable = true) - private void canBreed(AnimalEntity other, CallbackInfoReturnable cir){ - Claim claim = ClaimManager.INSTANCE.getClaimAt(other.getBlockPos(), other.dimension); - if(claim != null){ - if(claim.isChild){ - claim = ClaimUtil.getParentClaim(claim); - } - if(claim.getEntities(other.getEntityWorld().getServer().getWorld(other.getEntityWorld().getDimension().getType())) > 50){ - ServerPlayerEntity player = this.getLovingPlayer(); - if(player != null){ - player.sendMessage(new LiteralText("You reached the entity limit in your claim!").formatted(Formatting.RED)); - } - this.resetLoveTicks(); - cir.setReturnValue(false); - } - } - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java index 4829903..3123e47 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java @@ -1,7 +1,9 @@ package io.github.indicode.fabric.itsmine.mixin; import com.mojang.brigadier.CommandDispatcher; -import io.github.indicode.fabric.itsmine.command.CommandManager; +import io.github.indicode.fabric.itsmine.ClaimCommand; +import io.github.indicode.fabric.itsmine.SubzoneCommand; +import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -12,12 +14,12 @@ /** * @author Indigo Amann */ -@Mixin(net.minecraft.server.command.CommandManager.class) +@Mixin(CommandManager.class) public class CommandManagerMixin { @Shadow private CommandDispatcher dispatcher; @Inject(method = "", at = @At("RETURN")) public void addCommand(boolean bool, CallbackInfo ci) { - CommandManager.register(dispatcher); + ClaimCommand.register(dispatcher); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index 9f5d8ec..ddb55fa 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -1,7 +1,6 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.*; -import io.github.indicode.fabric.itsmine.util.ClaimUtil; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.packet.s2c.play.PlaySoundIdS2CPacket; @@ -108,7 +107,7 @@ public void doTickActions(CallbackInfo ci) { World world = player.getEntityWorld(); if (world.getBlockState(player.getBlockPos().down(5)).isAir() && !player.isOnGround()) { - BlockPos pos = ClaimUtil.getPosOnGround(player.getBlockPos(), world); + BlockPos pos = Functions.getPosOnGround(player.getBlockPos(), world); player.teleport(pos.getX(), pos.getY(), pos.getZ()); } } else if ( diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java index c6d7d2c..efb706b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java @@ -24,9 +24,9 @@ @Mixin(IntegratedServer.class) public class IntegratedServerMixin { @Inject(method = "loadWorld", at = @At("RETURN")) - private void loadClaims(java.lang.String name, long l, LevelGeneratorOptions levelGeneratorOptions, CallbackInfo ci) { - File claims = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat"); - File claims_old = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat_old"); + private void loadClaims(String name, String serverName, long seed, LevelGeneratorOptions arg, CallbackInfo ci) { + File claims = new File(((MinecraftServer)(Object)this).getLevelStorage().getSavesDirectory() + "/" + name + "/claims.dat"); + File claims_old = new File(((MinecraftServer)(Object)this).getLevelStorage().getSavesDirectory() + "/" + name + "/claims.dat_old"); ClaimManager.INSTANCE = new ClaimManager(); if (!claims.exists()) { if (claims_old.exists()) {} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java index b1fa8e0..98db24b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java @@ -3,26 +3,22 @@ import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ClaimUtil; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.screen.LecternScreenHandler; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(LecternScreenHandler.class) public abstract class LecternScreenHandlerMixin { - @Inject(method = "onButtonClick", at = @At(value = "HEAD"), cancellable = true) - private void canTake(PlayerEntity player, int id, CallbackInfoReturnable cir){ - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); - if(claim != null){ - if(claim.isChild) claim = ClaimUtil.getParentClaim(claim); - if(!claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_LECTERN)){ - player.sendMessage(Messages.MSG_CANT_DO); - cir.setReturnValue(false); - } - } - } + @Redirect(method = "onButtonClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/LecternScreenHandler;onButtonClick(Lnet/minecraft/entity/player/PlayerEntity;I)Z")) + private boolean canTake(LecternScreenHandler lecternScreenHandler, PlayerEntity player, int id) { + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + if (claim != null && !claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_LECTERN)) { + player.sendMessage(Messages.MSG_CANT_DO); + return false; + } + return true; + + } } \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java index fc1bfa5..c617e4f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java @@ -26,10 +26,10 @@ @Mixin(MinecraftServer.class) public abstract class MinecraftServerMixin { @Inject(method = "loadWorld", at = @At("RETURN")) - private void loadClaims(String name, long l, LevelGeneratorOptions levelGeneratorOptions, CallbackInfo ci) { + private void loadClaims(String name, String serverName, long seed, LevelGeneratorOptions arg, CallbackInfo ci) { ClaimManager.INSTANCE = new ClaimManager(); - File claims = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat"); - File claims_old = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat_old"); + File claims = new File(gameDir.getPath() + "/" + name + "/claims.dat"); + File claims_old = new File(gameDir.getPath() + "/" + name + "/claims.dat_old"); if (!claims.exists()) { if (claims_old.exists()) {} else return; @@ -51,4 +51,7 @@ private void loadClaims(String name, long l, LevelGeneratorOptions levelGenerato } } + @Final + @Shadow + private File gameDir; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java deleted file mode 100644 index 02bb931..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.github.indicode.fabric.itsmine.mixin; - -import net.minecraft.entity.projectile.ProjectileEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.UUID; - -@Mixin(ProjectileEntity.class) -public interface OwnedProjectile { - @Accessor("ownerUuid") - UUID getOwner(); -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java index 40736c5..6f54ede 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java @@ -1,14 +1,17 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.*; -import io.github.indicode.fabric.itsmine.util.EntityUtil; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityCategory; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.screen.PlayerScreenHandler; +import net.minecraft.text.LiteralText; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.registry.Registry; +import net.minecraft.world.GameRules; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -49,14 +52,12 @@ public void hittingIsRude(Entity entity, CallbackInfo ci) { PlayerEntity playerEntity_1 = (PlayerEntity)(Object)this; Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); - if (claim != null && !EntityUtil.canAttack(((PlayerEntity) (Object) this).getUuid(), claim, entity)) { + if (claim != null && !EntityUtils.canAttack(((PlayerEntity) (Object) this).getUuid(), claim, entity)) { playerEntity_1.sendMessage(Messages.MSG_DAMAGE_ENTITY); ci.cancel(); } } - - // @Redirect(method = "dropInventory", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/GameRules;getBoolean(Lnet/minecraft/world/GameRules$RuleKey;)Z")) // private boolean dontTakeMyThingies(GameRules gameRules, GameRules.RuleKey rule) { // PlayerEntity playerEntity_1 = (PlayerEntity)(Object)this; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java deleted file mode 100644 index db8520d..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.indicode.fabric.itsmine.mixin; - -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Messages; -import net.minecraft.entity.Entity; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.ProjectileEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.util.UUID; - -/** - * @author Indigo Amann - */ -@Mixin(ProjectileEntity.class) -public class ProjectileEntityMixin { - @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")) - public boolean imInvincible(Entity entity, DamageSource damageSource_1, float float_1) { - if (entity.world.isClient()) return entity.damage(damageSource_1, float_1); - ProjectileEntity projectile = (ProjectileEntity)(Object)this; - - if (((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()) != null) { - PlayerEntity playerEntity_1 = ((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()); - Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); - if (claim != null && entity != playerEntity_1) { - if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY)) { - playerEntity_1.sendMessage(Messages.MSG_DAMAGE_ENTITY); - projectile.kill(); // You do not want an arrow bouncing between two armor stands - return false; - } - } - } - return entity.damage(damageSource_1, float_1); - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index beedc32..aae0718 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -1,7 +1,6 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.*; -import io.github.indicode.fabric.itsmine.util.BlockUtil; import net.minecraft.block.*; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; @@ -42,7 +41,7 @@ private ActionResult interactIfPossible(BlockState blockState, World world, Play if (!Functions.canInteractWith(claim, blockState.getBlock(), player.getUuid())) { if (!itemStack.isEmpty() && !(itemStack.getItem() instanceof BlockItem)) { player.sendMessage(Messages.MSG_INTERACT_BLOCK); - } else if (BlockUtil.isContainer(blockState.getBlock())) { + } else if (BlockUtils.isContainer(blockState.getBlock())) { player.addMessage(Messages.MSG_OPEN_CONTAINER, true); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java index b8da0b3..52621ca 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java @@ -1,47 +1,27 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.*; -import net.minecraft.entity.Entity; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Functions; +import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.Packet; import net.minecraft.server.PlayerManager; -import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.sound.SoundCategory; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.world.dimension.DimensionType; -import org.apache.logging.log4j.core.jmx.Server; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.BooleanSupplier; - /** * @author Indigo Amann */ @Mixin(ServerWorld.class) -public abstract class ServerWorldMixin implements MonitorableWorld { - @Shadow - @Final - private Map entitiesByUuid; - - @Shadow public abstract List getPlayers(); - - @Shadow public abstract void playGlobalEvent(int type, BlockPos pos, int data); - - // @Inject(method = "canPlayerModifyAt", at = @At("HEAD"), cancellable = true) +public abstract class ServerWorldMixin { +// @Inject(method = "canPlayerModifyAt", at = @At("HEAD"), cancellable = true) // private void canMine(PlayerEntity player, BlockPos blockPos_1, CallbackInfoReturnable ci) { // if (player.world.isClient()) return; // Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, player.getEntityWorld().getDimension().getType()); @@ -57,43 +37,4 @@ private void sendPistonUpdate(PlayerManager manager, PlayerEntity playerEntity_1 manager.sendToAround(playerEntity_1, double_1, double_2, double_3, double_4, dimensionType_1, packet_1); Functions.doPistonUpdate((ServerWorld) (Object)this, packet_1); } - - @Inject(method = "tick", at = @At(value = "RETURN")) - public void tickActions(BooleanSupplier shouldKeepTicking, CallbackInfo ci){ - ClaimManager.INSTANCE.claimsByName.forEach((s, claim) ->{ - if(claim.rent.getRentedUntil() != 0){ - if(claim.rent.getRentTimeLeft() < 0){ - System.out.println("Rent expired -> method call"); - this.getPlayers().forEach(serverPlayerEntity -> { - if(serverPlayerEntity.getUuid() == claim.rent.getTenant()){ - serverPlayerEntity.sendMessage(new LiteralText("Rent expired").formatted(Formatting.RED)); - claim.endRent(); - } - }); - } - } - }); - } - -// AtomicReference atomicReference = new AtomicReference<>(); -// public ServerPlayerEntity getPlayerByUUID(UUID uuid){ -// this.getPlayers().forEach(serverPlayerEntity -> { -// if(serverPlayerEntity.getUuid() == uuid) -// atomicReference.set(serverPlayerEntity); -// }); -// return atomicReference.get(); -// } - - @Override - public int loadedEntities() { - if (this.entitiesByUuid == null) - return -1; - - return this.entitiesByUuid.size(); - } - - @Override - public Map EntityList() { - return entitiesByUuid; - } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java deleted file mode 100644 index 8fbb447..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java +++ /dev/null @@ -1,181 +0,0 @@ -package io.github.indicode.fabric.itsmine.util; - -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import com.mojang.brigadier.suggestion.Suggestions; -import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Config; -import net.minecraft.server.command.CommandSource; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.math.Direction; -import net.minecraft.util.registry.Registry; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CompletableFuture; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.StringArgumentType.word; -import static net.minecraft.server.command.CommandManager.argument; - -public class ArgumentUtil { - - - public static RequiredArgumentBuilder getSubAndClaims() { - return argument("claim", word()).suggests(CLAIM__SUBZONE_PROVIDER); - } - - public static RequiredArgumentBuilder getClaims() { - return argument("claim", word()).suggests(ArgumentUtil::claimProvider); - } - - public static RequiredArgumentBuilder getSubzones() { - return argument("subzone", word()).suggests(ArgumentUtil::subzoneProvider); - } - - public static RequiredArgumentBuilder getDirections() { - return argument("direction", word()).suggests(DIRECTION_PROVIDER); - } - - public static RequiredArgumentBuilder getHelpId() { - return argument("id", word()).suggests(HELPID_PROVIDER); - } - - public static RequiredArgumentBuilder getPlayers(){ - return argument("player", word()).suggests(PLAYERS_PROVIDER); - } - - public static RequiredArgumentBuilder getSettings(){ - return argument("setting", word()).suggests(SETTINGS_PROVIDER); - } - public static RequiredArgumentBuilder getMessageEvent(){ - return argument("messageEvent", word()).suggests(MESSAGE_EVENTS_PROVIDER); - } - - public static RequiredArgumentBuilder getEventMessage(){ - return argument("message", word()).suggests(EVENT_MESSAGE_PROVIDER); - } - - - - private static final SuggestionProvider CLAIM__SUBZONE_PROVIDER = (source, builder) -> { - ServerPlayerEntity player = source.getSource().getPlayer(); - List names = new ArrayList<>(); - Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); - if (current != null) names.add(current.name); - for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { - if (claim != null) { - System.out.println("Claim " + claim.name); - names.add(claim.name); - } - } - return CommandSource.suggestMatching(names, builder); - }; - - private static CompletableFuture claimProvider(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { - ServerPlayerEntity player = context.getSource().getPlayer(); - List names = new ArrayList<>(); - Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); - if (current != null && !current.isChild) names.add(current.name); - for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { - if (claim != null && !claim.isChild) { - names.add(claim.name); - } - } - return CommandSource.suggestMatching(names, builder); - } - - public static CompletableFuture subzoneProvider(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { - ServerPlayerEntity player = context.getSource().getPlayer(); - List names = new ArrayList<>(); - Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); - if (current != null && current.isChild) names.add(current.name); - for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { - if (claim != null && claim.isChild) { - names.add(claim.name); - } - } - names.add("Debug"); - return CommandSource.suggestMatching(names, builder); - } - - - private static final SuggestionProvider DIRECTION_PROVIDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (Direction direction: Direction.values()) { - if (Config.claims2d && (direction == Direction.DOWN || direction == Direction.UP)) continue; - strings.add(direction.getName()); - }; - return CommandSource.suggestMatching(strings, builder); - }; - - public static final SuggestionProvider HELPID_PROVIDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (Claim.HelpBook value : Claim.HelpBook.values()) { - strings.add(value.id); - } - return CommandSource.suggestMatching(strings, builder); - }; - - public static CompletableFuture itemsSuggestion(final CommandContext ctx, final SuggestionsBuilder builder) { - List strings = new ArrayList<>(); - Registry.ITEM.forEach((item) -> { - strings.add(Registry.ITEM.getId(item).getPath()); - }); - - return CommandSource.suggestMatching(strings, builder); - } - - public static final SuggestionProvider PLAYERS_PROVIDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (ServerPlayerEntity player : source.getSource().getMinecraftServer().getPlayerManager().getPlayerList()) { - strings.add(player.getEntityName()); - } - return CommandSource.suggestMatching(strings, builder); - }; - - public static final SuggestionProvider SETTINGS_PROVIDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { - strings.add(value.id); - } - for (Claim.Permission value : Claim.Permission.values()) { - strings.add(value.id); - } - return CommandSource.suggestMatching(strings, builder); - }; - - public static final SuggestionProvider MESSAGE_EVENTS_PROVIDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (Claim.Event value : Claim.Event.values()) { - strings.add(value.id); - } - return CommandSource.suggestMatching(strings, builder); - }; - public static final SuggestionProvider EVENT_MESSAGE_PROVIDER = (source, builder) -> { - if (!builder.getRemaining().isEmpty()) - return builder.buildFuture(); - - List strings = new ArrayList<>(); - strings.add("reset"); - try { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(source, "claim")); - Claim.Event eventType = Claim.Event.getById(getString(source, "messageEvent")); - - if (eventType != null && claim != null) { - String message = eventType == Claim.Event.ENTER_CLAIM ? claim.enterMessage : claim.leaveMessage; - if (message != null) strings.add(message); - } - - } catch (Exception ignored) { - } - - return CommandSource.suggestMatching(strings, builder); - }; - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java deleted file mode 100644 index f8c0137..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java +++ /dev/null @@ -1,200 +0,0 @@ -package io.github.indicode.fabric.itsmine.util; - -import blue.endless.jankson.annotation.Nullable; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import io.github.indicode.fabric.itsmine.*; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; - -import java.util.ArrayList; -import java.util.concurrent.atomic.AtomicReference; - -public class ClaimUtil { - public static BlockPos getPosOnGround(BlockPos pos, World world) { - BlockPos blockPos = new BlockPos(pos.getX(), pos.getY(), pos.getZ()); - - do { - blockPos = blockPos.down(); - if(blockPos.getY() < 1){ - return pos; - } - } while (!world.getBlockState(blockPos).isFullCube(world, pos)); - - return blockPos.up(); - } - - public static Claim getParentClaim(Claim subzone){ - AtomicReference parentClaim = new AtomicReference<>(); - if(subzone.isChild){ - ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> { - for(Claim subzone2 : claim.children){ - if(subzone2 == subzone){ - parentClaim.set(claim); - } - } - }); - return parentClaim.get(); - } - return subzone; - } - - public static void validateClaim(Claim claim) throws CommandSyntaxException { - if (claim == null) throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); - } - - public static boolean verifyPermission(Claim claim, Claim.Permission permission, CommandContext context, boolean admin) throws CommandSyntaxException { - if (verifyExists(claim, context)) { - if (claim.permissionManager.hasPermission(context.getSource().getPlayer().getGameProfile().getId(), permission)) { - return true; - } else { - context.getSource().sendFeedback(new LiteralText(admin ? "You are modifying a claim using admin privileges" : "You cannot modify exceptions for this claim").formatted(admin ? Formatting.DARK_RED : Formatting.RED), false); - return admin; - } - } else { - return false; - } - } - private static boolean verifyExists(Claim claim, CommandContext context) { - if (claim == null) { - context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return false; - } else { - return true; - } - } - - public static ArrayList getClaims(){ - ArrayList claims = new ArrayList<>(); - ClaimManager.INSTANCE.claimsByName.forEach((s, claim) -> { - claims.add(claim); - }); - return claims; - } - - public static void validateCanAccess(ServerPlayerEntity player, Claim claim, boolean admin) throws CommandSyntaxException { - if (claim == null) { - throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); - } - - if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SETTINGS)) { - throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); - } - } - - public static int querySetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting) { - boolean enabled = claim.settings.getSetting(setting); - source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); - return 1; - } - public static int setSetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting, boolean set) { - claim.settings.settings.put(setting, set); - source.sendFeedback(new LiteralText(ChatColor.translate("&eSet setting &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); - return 0; - } - public static int queryPermission(ServerCommandSource source, Claim claim, Claim.Permission permission) { - boolean defaultPerm = claim.permissionManager.defaults.hasPermission(permission); - source.sendFeedback(new LiteralText(ChatColor.translate("&ePermission &6" + permission.id + "&e is set to " + (defaultPerm ? "&a" : "&c") + defaultPerm + "&e for &6" + claim.name)), false); - return 1; - } - public static int setPermission(ServerCommandSource source, Claim claim, Claim.Permission permission, boolean set) { - claim.permissionManager.defaults.setPermission(permission, set); - source.sendFeedback(new LiteralText(ChatColor.translate("&eSet permission &6" + permission.id + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); - return 1; - } - public static int querySettings(ServerCommandSource source, Claim claim) { - source.sendFeedback(new LiteralText("\n").append(new LiteralText("Settings: " + claim.name).formatted(Formatting.YELLOW)).append("\n") - .append(Messages.Command.getSettings(claim)).append("\n"), false); - return 1; - } - public static int executeSetting(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { - ServerPlayerEntity player = source.getPlayer(); - Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : - ClaimManager.INSTANCE.claimsByName.get(claimName); - if (claim1 == null) { - source.sendError(Messages.INVALID_CLAIM); - return -1; - } - - if (input == null) { - return querySettings(source, claim1); - } - - validateCanAccess(player, claim1, admin); - Claim.ClaimSettings.Setting setting = Claim.ClaimSettings.Setting.byId(input); - Claim.Permission permission = Claim.Permission.byId(input); - - if (setting != null && permission == null) - return isQuery ? querySetting(source, claim1, setting) : setSetting(source, claim1, setting, value); - - if (setting == null && permission != null) - return isQuery ? queryPermission(source, claim1, permission) : setPermission(source, claim1, permission, value); - - source.sendError(Messages.INVALID_SETTING); - return -1; - } - public static int executePermission(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { - ServerPlayerEntity player = source.getPlayer(); - Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : - ClaimManager.INSTANCE.claimsByName.get(claimName); - if (claim1 == null) { - source.sendError(Messages.INVALID_CLAIM); - return -1; - } - - validateCanAccess(player, claim1, admin); - Claim.Permission permission = Claim.Permission.byId(input); - if (permission != null) - return !isQuery ? setPermission(source, claim1, permission, value) : queryPermission(source, claim1, permission); - - source.sendError(Messages.INVALID_SETTING); - return -1; - } - - public static int modifyException(Claim claim, ServerPlayerEntity exception, Claim.Permission permission, boolean allowed) { - claim.permissionManager.setPermission(exception.getGameProfile().getId(), permission, allowed); - return 0; - } - private static int modifyException(Claim claim, String exception, Claim.Permission permission, boolean allowed) { - claim.permissionManager.setPermission(exception, permission, allowed); - return 0; - } - - public static boolean hasPermission(Claim claim, ServerPlayerEntity exception, Claim.Permission permission) { - return claim.permissionManager.hasPermission(exception.getGameProfile().getId(), permission); - } - - public static int setEventMessage(ServerCommandSource source, Claim claim, Claim.Event event, String message) { - switch (event) { - case ENTER_CLAIM: - claim.enterMessage = message.equalsIgnoreCase("reset") ? null : message; - break; - case LEAVE_CLAIM: - claim.leaveMessage = message.equalsIgnoreCase("reset") ? null : message; - break; - } - - if (message.equalsIgnoreCase("reset")) { - source.sendFeedback(new LiteralText("Reset ").append(new LiteralText(event.id).formatted(Formatting.GOLD) - .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) - .append(new LiteralText(claim.name).formatted(Formatting.GOLD))).formatted(Formatting.YELLOW) - , false); - return -1; - } - - source.sendFeedback(new LiteralText("Set ").append(new LiteralText(event.id).formatted(Formatting.GOLD) - .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) - .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" to:").formatted(Formatting.YELLOW))) - .append("\n").append(new LiteralText(ChatColor.translate(message))) - .formatted(Formatting.YELLOW) - , false); - return 1; - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/DirectionUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/DirectionUtil.java deleted file mode 100644 index 0663353..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/DirectionUtil.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.github.indicode.fabric.itsmine.util; - -import net.minecraft.util.math.Direction; - -public class DirectionUtil { - public static Direction directionByName(String name) { - for (Direction direction : Direction.values()) { - if (name.equals(direction.getName())) return direction; - } - return null; - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java deleted file mode 100644 index 0c9e109..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java +++ /dev/null @@ -1,66 +0,0 @@ -package io.github.indicode.fabric.itsmine.util; - -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimShower; -import io.github.indicode.fabric.itsmine.mixin.BlockUpdatePacketMixin; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; - -public class ShowerUtil { - - public static void update(Claim claim, ServerWorld world){ - update(claim, world, false); - update(claim, world, true); - } - public static void update(Claim claim, ServerWorld world, boolean hide){ - world.getPlayers().forEach(playerEntity -> { - ClaimUtil.getParentClaim(claim); - if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, hide, false); - }); - } - - public static void silentHideShow(ServerPlayerEntity player, Claim claim, boolean hide, boolean updateStatus) { - if (updateStatus) { - if (!hide) ((ClaimShower) player).setShownClaim(claim); - else ((ClaimShower) player).setShownClaim(null); - } - BlockState block = hide ? null : Blocks.GOLD_BLOCK.getDefaultState(); - showCorners(player, claim, hide, block); - if(!claim.isChild){ - block = hide ? null : Blocks.DIAMOND_BLOCK.getDefaultState(); - for(Claim subzone : claim.children){ - showCorners(player, subzone, hide, block); - } - } - - } - - private static void showCorners(ServerPlayerEntity player, Claim claim, boolean hide, BlockState state){ - state = hide ? null : state; - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); - - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()).south(), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()).east(), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()).south(), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()).north(), player.getEntityWorld())).down(), state); - - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()).east(), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()).north(), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()).west(), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()).west(), player.getEntityWorld())).down(), state); - } - - private static void sendBlockPacket(ServerPlayerEntity player, BlockPos pos, BlockState state) { - BlockUpdateS2CPacket packet = new BlockUpdateS2CPacket(player.world, pos); - if (state != null) ((BlockUpdatePacketMixin)packet).setState(state); - player.networkHandler.sendPacket(packet); - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/TimeUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/TimeUtil.java deleted file mode 100644 index 35005d6..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/TimeUtil.java +++ /dev/null @@ -1,130 +0,0 @@ -package io.github.indicode.fabric.itsmine.util; - -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; - -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class TimeUtil { - - private static Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE); - private static final int maxYears = 100000; - private static SimpleCommandExceptionType TIME_ARGUMENT_INVALID = new SimpleCommandExceptionType(new LiteralText("Invalid time argument").formatted(Formatting.RED)); - - - public static String convertSecondsToString(int seconds, char numFormat, char typeFormat) { - int day = seconds / (24 * 3600); - seconds = seconds % (24 * 3600); - int hour = seconds / 3600; - seconds %= 3600; - int min = seconds / 60; - seconds %= 60; - - return ((day != 0) ? "§" + numFormat + day + "§" + typeFormat + " Days " : "") + - ((hour != 0) ? "§" + numFormat + hour + "§" + typeFormat + " Hours " : "") + - ((min != 0) ? "§" + numFormat + min + "§" + typeFormat + " Minutes " : "") + - ((seconds != 0) ? "§" + numFormat + seconds + "§" + typeFormat + " Seconds " : ""); - } - - public static int convertStringtoSeconds(String time) throws CommandSyntaxException { - Calendar c = new GregorianCalendar(); - int current = (int) (c.getTimeInMillis() / 1000); - int until = convertStringtoUnix(time); - return until - current; - } - - public static int convertStringtoUnix(String time) throws CommandSyntaxException { - Date date = new Date(); - Matcher matcher = timePattern.matcher(time); - int years = 0; - int months = 0; - int weeks = 0; - int days = 0; - int hours = 0; - int minutes = 0; - int seconds = 0; - boolean found = false; - while (matcher.find()) { - if (matcher.group() == null || matcher.group().isEmpty()) - continue; - - for (int i = 0; i < matcher.groupCount(); i++) { - if (matcher.group(i) != null && !matcher.group(i).isEmpty()) { - found = true; - break; - } - } - - if (!found) { - throw TIME_ARGUMENT_INVALID.create(); - } - - if (matcher.group(1) != null && !matcher.group(1).isEmpty()) { - years = Integer.parseInt(matcher.group(1)); - } - if (matcher.group(2) != null && !matcher.group(2).isEmpty()) { - months = Integer.parseInt(matcher.group(2)); - } - if (matcher.group(3) != null && !matcher.group(3).isEmpty()) { - weeks = Integer.parseInt(matcher.group(3)); - } - if (matcher.group(4) != null && !matcher.group(4).isEmpty()) { - days = Integer.parseInt(matcher.group(4)); - } - if (matcher.group(5) != null && !matcher.group(5).isEmpty()) { - hours = Integer.parseInt(matcher.group(5)); - } - if (matcher.group(6) != null && !matcher.group(6).isEmpty()) { - minutes = Integer.parseInt(matcher.group(6)); - } - if (matcher.group(7) != null && !matcher.group(7).isEmpty()) { - seconds = Integer.parseInt(matcher.group(7)); - } - break; - } - - Calendar c = new GregorianCalendar(); - if (years > 0) { - if (years > maxYears) { - years = maxYears; - } - c.add(Calendar.YEAR, years); - } - if (months > 0) { - c.add(Calendar.MONTH, months); - } - if (weeks > 0) { - c.add(Calendar.WEEK_OF_YEAR, weeks); - } - if (days > 0) { - c.add(Calendar.DAY_OF_MONTH, days); - } - if (hours > 0) { - c.add(Calendar.HOUR_OF_DAY, hours); - } - if (minutes > 0) { - c.add(Calendar.MINUTE, minutes); - } - if (seconds > 0) { - c.add(Calendar.SECOND, seconds); - } - Calendar max = new GregorianCalendar(); - max.add(Calendar.YEAR, 10); - if (c.after(max)) { - return (int) max.getTimeInMillis() / 1000; - } - - if (date.getTime() == c.getTimeInMillis()) { - throw TIME_ARGUMENT_INVALID.create(); - } - - return (int) (c.getTimeInMillis() / 1000); - } - -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 5e4eba0..98abc6f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -7,8 +7,7 @@ "description": "Land claims.", "authors": [ "Indicode", - "CODY_AI", - "Maintained by DrexHD" + "Maintained by CODY_AI" ], "contact": { "sources": "https://github.com/GiantNuker/NoGrief/" diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index d92caaf..585b8d1 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -3,8 +3,8 @@ "package": "io.github.indicode.fabric.itsmine.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ - "WorldSaveHandlerMixin", "MinecraftServerMixin", + "WorldSaveHandlerMixin", "CommandManagerMixin", "BlockUpdatePacketMixin", "BucketItemMixin", @@ -33,7 +33,6 @@ "EnderDragonEntityMixin", "FarmlandBlockMixin", "BoatItemMixin", - "AnimalEntityMixin", "LecternScreenHandlerMixin" ], "client": [ From b36bb97f44c210281d6a0798ec40222eded9aaac Mon Sep 17 00:00:00 2001 From: DrexHD Date: Mon, 20 Apr 2020 18:12:49 +0200 Subject: [PATCH 64/85] Revert "Revert "bump version"" This reverts commit 9e08391feea5341580d667ed20cec0563b424b1c. --- build.gradle | 2 +- gradle.properties | 8 +- .../github/indicode/fabric/itsmine/Claim.java | 338 +- .../indicode/fabric/itsmine/ClaimCommand.java | 3513 +++++++++-------- .../indicode/fabric/itsmine/ClaimManager.java | 3 +- .../indicode/fabric/itsmine/Config.java | 2 + .../indicode/fabric/itsmine/Functions.java | 40 +- .../indicode/fabric/itsmine/ItsMine.java | 10 +- .../indicode/fabric/itsmine/Messages.java | 9 +- .../fabric/itsmine/MonitorableWorld.java | 13 + .../fabric/itsmine/command/BlockCommand.java | 43 + .../itsmine/command/CommandManager.java | 45 + .../fabric/itsmine/command/CreateCommand.java | 126 + .../itsmine/command/ExceptionCommand.java | 176 + .../fabric/itsmine/command/ExpandCommand.java | 174 + .../fabric/itsmine/command/FlyCommand.java | 42 + .../fabric/itsmine/command/HelpCommand.java | 102 + .../fabric/itsmine/command/InfoCommand.java | 105 + .../fabric/itsmine/command/ListCommand.java | 30 + .../itsmine/command/PermissionsCommand.java | 49 + .../fabric/itsmine/command/RemoveCommand.java | 93 + .../fabric/itsmine/command/RenameCommand.java | 61 + .../fabric/itsmine/command/RentCommand.java | 94 + .../itsmine/command/RentableCommand.java | 81 + .../itsmine/command/RevenueCommand.java | 87 + .../itsmine/command/SettingsCommand.java | 53 + .../fabric/itsmine/command/ShowCommand.java | 54 + .../fabric/itsmine/command/StickCommand.java | 30 + .../itsmine/command/TransferCommand.java | 147 + .../fabric/itsmine/command/TrustCommand.java | 85 + .../itsmine/command/TrustedCommand.java | 124 + .../itsmine/command/admin/AdminCommand.java | 48 + .../itsmine/command/admin/BlocksCommand.java | 65 + .../itsmine/command/admin/ClaimsCommand.java | 70 + .../itsmine/command/admin/CreateCommand.java | 81 + .../command/admin/EntitiesCommand.java | 42 + .../itsmine/command/admin/ExpandCommand.java | 76 + .../itsmine/command/admin/IgnoreCommand.java | 30 + .../itsmine/command/admin/ListAllCommand.java | 37 + .../itsmine/command/admin/OwnerCommand.java | 114 + .../itsmine/command/admin/RemoveCommand.java | 31 + .../itsmine/command/admin/RenameCommand.java | 23 + .../subzone/CreateCommand.java} | 61 +- .../command/subzone/SubzoneCommand.java | 34 + .../itsmine/mixin/AnimalEntityMixin.java | 49 + .../itsmine/mixin/CommandManagerMixin.java | 8 +- .../fabric/itsmine/mixin/EntityMixin.java | 3 +- .../itsmine/mixin/IntegratedServerMixin.java | 6 +- .../mixin/LecternScreenHandlerMixin.java | 24 +- .../itsmine/mixin/MinecraftServerMixin.java | 9 +- .../fabric/itsmine/mixin/OwnedProjectile.java | 13 + .../itsmine/mixin/PlayerEntityMixin.java | 9 +- .../itsmine/mixin/ProjectileEntityMixin.java | 42 + .../ServerPlayerInteractionManagerMixin.java | 3 +- .../itsmine/mixin/ServerWorldMixin.java | 71 +- .../fabric/itsmine/util/ArgumentUtil.java | 181 + .../{BlockUtils.java => util/BlockUtil.java} | 4 +- .../fabric/itsmine/util/ClaimUtil.java | 200 + .../fabric/itsmine/util/DirectionUtil.java | 12 + .../EntityUtil.java} | 8 +- .../{NBTUtil.java => util/NbtUtil.java} | 4 +- .../PermissionUtil.java} | 7 +- .../fabric/itsmine/util/ShowerUtil.java | 66 + .../fabric/itsmine/util/TimeUtil.java | 130 + src/main/resources/fabric.mod.json | 3 +- src/main/resources/itsmine.mixins.json | 3 +- 66 files changed, 5498 insertions(+), 1808 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/StickCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/BlocksCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/CreateCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/IgnoreCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/RenameCommand.java rename src/main/java/io/github/indicode/fabric/itsmine/{SubzoneCommand.java => command/subzone/CreateCommand.java} (72%) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java rename src/main/java/io/github/indicode/fabric/itsmine/{BlockUtils.java => util/BlockUtil.java} (93%) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/DirectionUtil.java rename src/main/java/io/github/indicode/fabric/itsmine/{EntityUtils.java => util/EntityUtil.java} (84%) rename src/main/java/io/github/indicode/fabric/itsmine/{NBTUtil.java => util/NbtUtil.java} (89%) rename src/main/java/io/github/indicode/fabric/itsmine/{Permissions.java => util/PermissionUtil.java} (97%) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/TimeUtil.java diff --git a/build.gradle b/build.gradle index cba03e6..01d8e83 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '0.2.6-SNAPSHOT' + id 'fabric-loom' version '0.2.7-SNAPSHOT' id 'maven-publish' } diff --git a/gradle.properties b/gradle.properties index 4f70a7f..967dbd9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=20w13b -yarn_mappings=20w13b+build.4 -loader_version=0.7.8+build.189 +minecraft_version=20w16a +yarn_mappings=20w16a+build.4 +loader_version=0.7.10+build.191 # Mod Properties - mod_version = 1.8.21-20W13B + mod_version = 1.9.0-20W16A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index 6a3113b..c6f5351 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -1,7 +1,11 @@ package io.github.indicode.fabric.itsmine; import blue.endless.jankson.annotation.Nullable; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.*; +import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; @@ -11,7 +15,7 @@ import java.util.*; import java.util.concurrent.atomic.AtomicReference; -import static io.github.indicode.fabric.itsmine.NBTUtil.*; +import static io.github.indicode.fabric.itsmine.util.NbtUtil.*; /** * @author Indigo Amann @@ -24,6 +28,7 @@ public class Claim { public List children = new ArrayList<>(); public ClaimSettings settings = new ClaimSettings(); public PermissionManager permissionManager = new PermissionManager(); + public Rent rent = new Rent(); public UUID claimBlockOwner = null; public String customOwnerName, enterMessage, leaveMessage; public boolean isChild = false; @@ -49,9 +54,77 @@ public boolean includesPosition(BlockPos pos) { return pos.getX() >= min.getX() && pos.getY() >= min.getY() && pos.getZ() >= min.getZ() && pos.getX() <= max.getX() && pos.getY() <= max.getY() && pos.getZ() <= max.getZ(); } + + public boolean isInside (Claim claim){ + BlockPos a = min, + b = max, + c = new BlockPos(max.getX(), min.getY(), min.getZ()), + d = new BlockPos(min.getX(), max.getY(), min.getZ()), + e = new BlockPos(min.getX(), min.getY(), max.getZ()), + f = new BlockPos(max.getX(), max.getY(), min.getZ()), + g = new BlockPos(max.getX(), min.getY(), max.getZ()), + h = new BlockPos(min.getX(), max.getY(), max.getZ()); + if( + claim.includesPosition(a) && + claim.includesPosition(b) && + claim.includesPosition(c) && + claim.includesPosition(d) && + claim.includesPosition(e) && + claim.includesPosition(f) && + claim.includesPosition(g) && + claim.includesPosition(h) + ){ + return true; + } + return false; + } + public boolean intersects(Claim claim) { return intersects(claim, true, false); } + + public int getEntities(ServerWorld world){ + AtomicReference entities = new AtomicReference<>(); + entities.set(0); + MonitorableWorld monitorableWorld = (MonitorableWorld) world; + monitorableWorld.EntityList().forEach((uuid, entity) -> { + if(includesPosition(entity.getBlockPos())) { + entities.set(entities.get()+1); + } + }); + + return entities.get(); + } + + public Map getEntitySorted(Map entityMap){ + AtomicReference> entityTypeMap = new AtomicReference<>(new HashMap<>()); + entityMap.forEach((uuid, entity) -> { + if(entityTypeMap.get().containsKey(entity.getType())){ + Map entityTypeIntegerMap = entityTypeMap.get(); + entityTypeIntegerMap.put(entity.getType(), entityTypeIntegerMap.get(entity.getType())+1); + entityTypeMap.set(entityTypeIntegerMap); + } else { + Map entityTypeIntegerMap = entityTypeMap.get(); + entityTypeIntegerMap.put(entity.getType(), 1); + entityTypeMap.set(entityTypeIntegerMap); + } + }); + return Functions.sortByValue(entityTypeMap.get()); + } + + public Map getEntityMap(Claim claim, ServerWorld world){ + AtomicReference> entityMap = new AtomicReference<>(new HashMap<>()); + MonitorableWorld monitorableWorld = (MonitorableWorld) world; + monitorableWorld.EntityList().forEach((uuid, entity) -> { + if(claim.includesPosition(entity.getBlockPos())) { + Map entityList = entityMap.get(); + entityList.put(uuid, entity); + entityMap.set(entityList); + } + }); + return entityMap.get(); + } + public boolean intersects(Claim claim, boolean checkOther, boolean checkforsubzone) { if (claim == null) return false; if (!claim.dimension.equals(dimension)) return false; @@ -98,24 +171,11 @@ public Claim getZoneCovering(BlockPos pos) { return null; } - /*public ClaimSettings getSettingsAt(BlockPos pos) { - Claim at = getZoneCovering(pos); - if (at != null) { - return at.settings; - } else return settings; - } - public ClaimPermissions getPermissionsAt(UUID player, BlockPos pos) { - Claim at = getZoneCovering(pos); - if (at != null) { - return at.getPlayerPermissions(player); - } else return settings; - }*/ + public boolean hasPermission(UUID player, Permission permission) { return ClaimManager.INSTANCE.ignoringClaims.contains(player) || permissionManager.hasPermission(player, permission); } - //public boolean hasPermissionAt(UUID player, ClaimPermissions.Permission permission, BlockPos pos) { - // return player.equals(owner) || ClaimManager.INSTANCE.ignoringClaims.contains(player) || getPermissionsAt(player, pos).hasPermission(permission); - //} + public void addSubzone(Claim claim) { children.add(claim); } @@ -124,66 +184,72 @@ public void removeSubzone(Claim claim) { children.remove(claim); } - @Nullable - AtomicReference atomic = new AtomicReference<>(); - public Claim getParentClaim(Claim subzone){ - if(subzone.isChild){ - ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> { - for(Claim subzone2 : claim.children){ - if(subzone2 == subzone){ - atomic.set(claim); - } - } - }); - return atomic.get(); - } - return null; - } - - public void expand(BlockPos min, BlockPos max) { - this.min = this.min.add(min); - this.max = this.max.add(max); - } public BlockPos getSize() { return max.subtract(min); } + public void expand(BlockPos modifier) { - if (modifier.getX() > 0) max = max.add(modifier.getX(), 0, 0); - else min = min.add(modifier.getX(), 0, 0); - if (modifier.getY() > 0) max = max.add(0, modifier.getY(), 0); - else min = min.add(0, modifier.getY(), 0); - if (modifier.getZ() > 0) max = max.add(0, 0, modifier.getZ()); - else min = min.add(0, 0, modifier.getZ()); - } - public boolean shrink(BlockPos modifier) { + if (modifier.getX() > 0) { + max = max.add(modifier.getX(), 0, 0); + } + else { + min = min.add(modifier.getX(), 0, 0); + } + if (modifier.getY() > 0) { + max = max.add(0, modifier.getY(), 0); + } + else { + min = min.add(0, modifier.getY(), 0); + } + if (modifier.getZ() > 0) { + max = max.add(0, 0, modifier.getZ()); + } + else { + min = min.add(0, 0, modifier.getZ()); + } + } + public void shrink(BlockPos modifier) { if (modifier.getX() < 0) { - if (min.getX() - modifier.getX() > max.getX()) return false; min = min.add(-modifier.getX(), 0, 0); } else { - if (max.getX() - modifier.getX() < min.getX()) return false; max = max.add(-modifier.getX(), 0, 0); } if (modifier.getY() < 0) { - if (min.getY() - modifier.getY() > max.getY()) return false; min = min.add(0, -modifier.getY(), 0); } else { - if (max.getY() - modifier.getY() < min.getY()) return false; max = max.add(0, -modifier.getY(), 0); } if (modifier.getZ() < 0) { - if (min.getZ() - modifier.getZ() > max.getZ()) return false; min = min.add(0, 0, -modifier.getZ()); } else { - if (max.getZ() - modifier.getZ() < min.getZ()) return false; max = max.add(0, 0, -modifier.getZ()); } + } + + public boolean canShrinkWithoutHittingOtherSide(BlockPos modifier){ + if (modifier.getX() < 0) { + if (min.getX() - modifier.getX() > max.getX()) return false; + } else { + if (max.getX() - modifier.getX() < min.getX()) return false; + } + if (modifier.getY() < 0) { + if (min.getY() - modifier.getY() > max.getY()) return false; + } else { + if (max.getY() - modifier.getY() < min.getY()) return false; + } + if (modifier.getZ() < 0) { + if (min.getZ() - modifier.getZ() > max.getZ()) return false; + } else { + if (max.getZ() - modifier.getZ() < min.getZ()) return false; + } return true; } + public void expand(Direction direction, int distance) { expand(new BlockPos(direction.getOffsetX() * distance, direction.getOffsetY() * distance, direction.getOffsetZ() * distance)); } - public boolean shrink(Direction direction, int distance) { - return shrink(new BlockPos(direction.getOffsetX() * distance, direction.getOffsetY() * distance, direction.getOffsetZ() * distance)); + public void shrink(Direction direction, int distance) { + shrink(new BlockPos(direction.getOffsetX() * distance, direction.getOffsetY() * distance, direction.getOffsetZ() * distance)); } public int getArea() { return getSize().getX() * (Config.claims2d ? 1 : getSize().getY()) * getSize().getZ(); @@ -215,6 +281,42 @@ public CompoundTag toTag() { tag.put("subzones", subzoneList); } } + { + CompoundTag rent1 = new CompoundTag(); + { + CompoundTag rented = new CompoundTag(); + if(rent.getTenant() != null) rented.putUuidNew("tenant", rent.getTenant()); + if(rent.getRentedUntil() != 0) rented.putInt("rentedUntil", rent.getRentedUntil()); + + { + if(rent.getRevenue() != null){ + CompoundTag revenue = new CompoundTag(); + int i = 0; + for(ItemStack itemStack : rent.getRevenue()){ + CompoundTag revenueTag = new CompoundTag(); + itemStack.toTag(revenueTag); + i++; + revenue.put(String.valueOf(i), revenueTag); + rent1.put("revenue", revenue); + } + } + } + rent1.put("rented", rented); + } + { + CompoundTag rentable = new CompoundTag(); + rentable.putBoolean("rentable", rent.isRentable()); + CompoundTag currency = new CompoundTag(); + if(rent.getCurrency() != ItemStack.EMPTY) rent.getCurrency().toTag(currency); + if(rent.getRentAbleTime() != 0) rentable.putInt("rentTime", rent.getRentAbleTime()); + if(rent.getMaxrentAbleTime() != 0) rentable.putInt("maxrentTime", rent.getMaxrentAbleTime()); + + rent1.put("rentable", rentable); + rentable.put("currency", currency); + } + tag.put("rent", rent1); + + } { tag.put("settings", settings.toTag()); tag.put("permissions", permissionManager.toNBT()); @@ -262,6 +364,31 @@ public void fromTag(CompoundTag tag) { } } } + { + CompoundTag rent1 = tag.getCompound("rent"); + { + CompoundTag rented = rent1.getCompound("rented"); + if (containsUUID(rented, "tenant")) rent.setTenant(getUUID(rented,"tenant")); + if(rented.contains("rentedUntil")) rent.setRentedUntil(rented.getInt("rentedUntil")); + } + { + CompoundTag rentable = rent1.getCompound("rentable"); + CompoundTag currency = rentable.getCompound("currency"); + if(rentable.contains("rentable")) rent.setRentable(rentable.getBoolean("rentable")); + if(currency != null) rent.setCurrency(ItemStack.fromTag(currency)); + if(rentable.contains("rentTime")) rent.setRentAbleTime(rentable.getInt("rentTime")); + if(rentable.contains("maxrentTime")) rent.setMaxrentAbleTime(rentable.getInt("maxrentTime")); + } + { + CompoundTag revenue = rent1.getCompound("revenue"); + if(!revenue.isEmpty()){ + for(int i = 1; i <= revenue.getSize(); i++){ + CompoundTag revenueTag = revenue.getCompound(String.valueOf(i)); + rent.addRevenue(ItemStack.fromTag(revenueTag)); + } + } + } + } { this.settings = new ClaimSettings(tag.getCompound("settings")); permissionManager = new PermissionManager(); @@ -282,6 +409,12 @@ public boolean is2d() { return min.getY() == 0 && max.getY() == 255; } + public void endRent(){ + permissionManager.playerPermissions.put(rent.getTenant(), new Claim.DefaultPermissionMap()); + rent.setRentedUntil(0); + rent.setTenant(null); + } + public enum Permission { //Admin REMOVE_CLAIM("remove_claim", "Remove Claim"), @@ -290,6 +423,8 @@ public enum Permission { MODIFY_PERMISSIONS("modify.permissions", "Change Permissions"), //Normal MODIFY_PROPERTIES("modify.properties", "Modify Claim Properties"), + MODIFY_SUBZONE("modify.subzone", "Add subzones"), + MOVE("move", "Move inside claim"), BUILD("build", "Place/Break Blocks"), INTERACT_BLOCKS("interact_blocks", "Interact With Blocks"), USE_ITEMS_ON_BLOCKS("use_items_on_blocks", "Use Block Modifying items"), @@ -310,7 +445,8 @@ public enum Permission { SPAWN_BOAT("spawn.boat", "Spawn Boats"); - String id, name; + public String id; + public String name; Permission(String id, String name) { this.id = id; this.name = name; @@ -322,10 +458,92 @@ public static Permission byId(String id) { return null; } } + + public class Rent { + + public UUID tenant = null; + public boolean rentable = false; + + public int rentTime = 0; + public int maxrentTime = 0; + public ArrayList revenue = new ArrayList<>(); + + + public ArrayList getRevenue() { + return revenue; + } + + public void addRevenue(ItemStack revenue) { + this.revenue.add(revenue); + } + + public void clearRevenue() { + revenue.clear(); + } + + //Payement + public ItemStack currency = ItemStack.EMPTY; + + public int rentedUntil = 0; + + public void setRentTime(int rentTime) { this.rentTime = rentTime; } + + //Max rent time + public int getMaxrentAbleTime() { return maxrentTime; } + public boolean isRented() { return rentedUntil != 0; } + + public void setMaxrentAbleTime(int maxrentTime) { this.maxrentTime = maxrentTime; } + + public int getRentedUntil() { + return rentedUntil; + } + + public void setRentedUntil(int rentedUntil) { + this.rentedUntil = rentedUntil; + } + + public int getRentTimeLeft(){ + return rentedUntil - getUnixTime(); + } + + public int getRentAbleTime() { return rentTime; } + + public void setRentAbleTime(int rentTime) { this.rentTime = rentTime; } + + //Returns seconds passed (Unix time) + public int getUnixTime(){ + return (int) (System.currentTimeMillis() / 1000); + } + + public void addRentTimeLeft(int rent){ + rentedUntil = rentedUntil + rent; + } + + public void removeRentTimeLeft(int rent){ addRentTimeLeft(-rent); } + + public void setRentTimeLeft(int time) { rentedUntil = getUnixTime() + time; } + + public UUID getTenant() { return tenant; } + + public void setTenant(UUID tenant) { this.tenant = tenant; } + + public boolean isRentable() { return rentable; } + + public void setRentable(boolean rentable) { this.rentable = rentable; } + + public int getAmount() { return currency.getCount(); } + + public void setAmount(int amount) { currency.setCount(amount); } + + public ItemStack getCurrency() { return currency; } + + public void setCurrency(ItemStack currency) { this.currency = currency; } + } + public static class PermissionManager { public ClaimPermissionMap defaults = new DefaultPermissionMap(); - protected Map playerPermissions = new HashMap<>(); - protected Map groupPermissions = new HashMap<>(); + public Map playerPermissions = new HashMap<>(); + public Map groupPermissions = new HashMap<>(); public boolean isPermissionSet(UUID player, Permission permission) { return playerPermissions.get(player) != null && playerPermissions.get(player).isPermissionSet(permission); } @@ -534,7 +752,7 @@ public enum Setting { ENTER_SOUND("enter_sound", "Enter Sound", false), BREAK_FARMLANDS("break_farmlands", "Break Farmlands", false); - String id, name; + public String id, name; boolean defaultValue; Setting(String id, String name, boolean defaultValue) { this.id = id; @@ -577,7 +795,7 @@ public enum Event { ENTER_CLAIM("enter", Config.msg_enter_default), LEAVE_CLAIM("leave", Config.msg_leave_default); - String id; + public String id; String defaultValue; Event(String id, String defaultValue) { this.id = id; @@ -601,9 +819,9 @@ public enum HelpBook { COMMAND("commands", Messages.HELP, "Claim Commands"), PERMS_AND_SETTINGS("perms_and_settings", Messages.SETTINGS_AND_PERMISSIONS, "Claim Permissions and Settings"); - String id; - String title; - Text[] texts; + public String id; + public String title; + public Text[] texts; HelpBook(String id, Text[] texts, String title) { this.id = id; this.title = title; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index 47a2c71..b5cd557 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1,469 +1,439 @@ package io.github.indicode.fabric.itsmine; -import blue.endless.jankson.annotation.Nullable; -import com.mojang.authlib.GameProfile; -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.ArgumentBuilder; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import io.github.indicode.fabric.itsmine.mixin.BlockUpdatePacketMixin; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.command.EntitySelector; -import net.minecraft.command.arguments.BlockPosArgumentType; -import net.minecraft.command.arguments.EntityArgumentType; -import net.minecraft.command.arguments.GameProfileArgumentType; -import net.minecraft.command.arguments.PosArgument; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; -import net.minecraft.server.MinecraftServer; -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.*; -import net.minecraft.util.Formatting; -import net.minecraft.util.Pair; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.dimension.DimensionType; - -import java.lang.reflect.Array; -import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Predicate; - -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - /** * @author Indigo Amann */ -public class ClaimCommand { - public static final int MAX_NAME_LENGTH = 30; - private static void validateCanAccess(ServerPlayerEntity player, Claim claim, boolean admin) throws CommandSyntaxException { - if (claim == null) { - throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); - } - - if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SETTINGS)) { - throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); - } - } - - private static void validateClaim(Claim claim) throws CommandSyntaxException { - if (claim == null) throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); - } - - private static RequiredArgumentBuilder getClaimArgument() { - return argument("claim", StringArgumentType.word()).suggests(CLAIM_PROVIDER); - } - - private static Predicate perm(String str) { - return perm(str, 2); - } - private static Predicate perm(String str, int op) { - return source -> ItsMine.permissions().hasPermission(source, "itsmine." + str, op); - } - private static final Predicate PERMISSION_CHECK_ADMIN = src -> perm("admin").test(src) || perm("admin.modify_balance").test(src) || - perm("admin.infinite_blocks").test(src) || perm("admin.modify").test(src) || - perm("admin.modify_balance").test(src) || perm("admin.ignore_claims").test(src) || - perm("admin.modify_permissions").test(src); - - public static final SuggestionProvider DIRECTION_SUGGESTION_BUILDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (Direction direction: Direction.values()) { - if (Config.claims2d && (direction == Direction.DOWN || direction == Direction.UP)) continue; - strings.add(direction.getName()); - }; - return CommandSource.suggestMatching(strings, builder); - }; - public static final SuggestionProvider BOOK_SUGGESTIONS = (source, builder) -> { - List strings = new ArrayList<>(); - for (Claim.HelpBook value : Claim.HelpBook.values()) { - strings.add(value.id); - } - return CommandSource.suggestMatching(strings, builder); - }; - public static final SuggestionProvider CLAIM_PROVIDER = (source, builder) -> { - ServerPlayerEntity player = source.getSource().getPlayer(); - List names = new ArrayList<>(); - Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); - if (current != null) names.add(current.name); - for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { - if (claim != null) { - names.add(claim.name); - } - } - return CommandSource.suggestMatching(names, builder); - }; - public static final SuggestionProvider PLAYERS_PROVIDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (ServerPlayerEntity player : source.getSource().getMinecraftServer().getPlayerManager().getPlayerList()) { - strings.add(player.getEntityName()); - } - return CommandSource.suggestMatching(strings, builder); - }; - public static final SuggestionProvider SETTINGS_PROVIDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { - strings.add(value.id); - } - for (Claim.Permission value : Claim.Permission.values()) { - strings.add(value.id); - } - return CommandSource.suggestMatching(strings, builder); - }; - public static final SuggestionProvider PERMISSIONS_PROVIDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (Claim.Permission value : Claim.Permission.values()) { - strings.add(value.id); - } - return CommandSource.suggestMatching(strings, builder); - }; - public static final SuggestionProvider MESSAGE_EVENTS_PROVIDER = (source, builder) -> { - List strings = new ArrayList<>(); - for (Claim.Event value : Claim.Event.values()) { - strings.add(value.id); - } - return CommandSource.suggestMatching(strings, builder); - }; - public static final SuggestionProvider EVENT_MESSAGE_PROVIDER = (source, builder) -> { - if (!builder.getRemaining().isEmpty()) - return builder.buildFuture(); - - List strings = new ArrayList<>(); - strings.add("reset"); - try { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(source, "claim")); - Claim.Event eventType = Claim.Event.getById(StringArgumentType.getString(source, "messageEvent")); - - if (eventType != null && claim != null) { - String message = eventType == Claim.Event.ENTER_CLAIM ? claim.enterMessage : claim.leaveMessage; - if (message != null) strings.add(message); - } - - } catch (Exception ignored) { - } - - return CommandSource.suggestMatching(strings, builder); - }; - - public static void register(CommandDispatcher dispatcher) { - LiteralArgumentBuilder main = literal("itsmine") - .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); - - register(main, dispatcher); - - LiteralArgumentBuilder alias = literal("claim") - .executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); - - register(alias, dispatcher); - - dispatcher.register(main); - dispatcher.register(alias); - } - - private static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { - SubzoneCommand.register(command, false); - { - LiteralArgumentBuilder help = literal("help"); - help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); - - RequiredArgumentBuilder id = argument("id", StringArgumentType.word()) - .suggests(BOOK_SUGGESTIONS); - RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); - - page.executes((context) -> { - Claim.HelpBook book = Claim.HelpBook.getById(StringArgumentType.getString(context, "id")); - if (book == null) { - context.getSource().sendError(new LiteralText("Invalid Book!")); - return -1; - } - int p = IntegerArgumentType.getInteger(context, "page"); - - if (p > book.texts.length) p = 1; - return sendPage(context.getSource(), book.texts, p, book.title, book.getCommand()); - }); - - id.then(page); - help.then(id); - command.then(help); - } - { - LiteralArgumentBuilder create = literal("create"); - RequiredArgumentBuilder name = argument("name", StringArgumentType.word()); - - name.executes(context -> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); - if (selectedPositions == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getLeft() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getRight() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); - } else { - String cname = StringArgumentType.getString(context, "name"); - if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), false, null) > 0) { - ClaimManager.INSTANCE.stickPositions.remove(player); - } - } - return 0; - }); - - ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); - RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); - max.executes(context -> createClaim( - StringArgumentType.getString(context, "name"), - context.getSource(), - BlockPosArgumentType.getBlockPos(context, "min"), - BlockPosArgumentType.getBlockPos(context, "max"), - false, - null - )); - min.then(max); - name.then(min); - create.then(name); - command.then(create); - } - { - LiteralArgumentBuilder fly = literal("fly") - .requires(src -> ItsMine.permissions().hasPermission(src, Permissions.Command.CLAIM_FLY, 2)); - RequiredArgumentBuilder setArgument = CommandManager.argument("set", BoolArgumentType.bool()); - - fly.executes((context) -> setFly(context, !ClaimManager.INSTANCE.flyers.contains(context.getSource().getPlayer().getUuid()))); - setArgument.executes((context) -> setFly(context, BoolArgumentType.getBool(context, "set"))); - - fly.then(setArgument); - command.then(fly); - } - { - LiteralArgumentBuilder rename = literal("rename"); - RequiredArgumentBuilder claimArgument = getClaimArgument().suggests(CLAIM_PROVIDER); - RequiredArgumentBuilder nameArgument = argument("name", StringArgumentType.word()); - nameArgument.executes((context) -> rename(context, false)); - claimArgument.then(nameArgument); - rename.then(claimArgument); - command.then(rename); - } - { - LiteralArgumentBuilder trusted = literal("trusted"); - RequiredArgumentBuilder claimArgument = getClaimArgument(); - trusted.executes((context)-> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); - if (claim == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return showTrustedList(context, claim, false); - }); - - claimArgument.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return showTrustedList(context, claim, false); - }); - trusted.then(claimArgument); - command.then(trusted); - dispatcher.register(trusted); - } - { - LiteralArgumentBuilder stick = literal("stick"); - stick.executes(context -> { - Pair posPair = ClaimManager.INSTANCE.stickPositions.get(context.getSource().getPlayer()); - context.getSource().sendFeedback(new LiteralText(posPair == null ? "You can now use a stick to create claims. Run this command again to disable" : "Claim stick disabled. Run this command again to enable").formatted(Formatting.DARK_PURPLE), false); - if (posPair == null) { - ClaimManager.INSTANCE.stickPositions.put(context.getSource().getPlayer(), new Pair<>(null, null)); - } else { - ClaimManager.INSTANCE.stickPositions.remove(context.getSource().getPlayer()); - } - return 0; - }); - command.then(stick); - } - { - LiteralArgumentBuilder show = literal("show"); - show.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().dimension.getType()), false)); - RequiredArgumentBuilder name = argument("name", StringArgumentType.word()); - name.suggests(CLAIM_PROVIDER); - name.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "name")), false)); - show.then(name); - command.then(show); - } - { - LiteralArgumentBuilder hide = literal("hide"); - hide.executes(context -> showClaim(context.getSource(), null, true)); - command.then(hide); - } - { - LiteralArgumentBuilder check = literal("blocks"); - RequiredArgumentBuilder other = argument("player", EntityArgumentType.player()); - other.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_CHECK_OTHERS, 2)); - other.executes(ctx -> checkPlayer(ctx.getSource(), EntityArgumentType.getPlayer(ctx, "player").getGameProfile().getId())); - check.then(other); - check.executes(ctx -> checkPlayer(ctx.getSource(), ctx.getSource().getPlayer().getGameProfile().getId())); - command.then(check); - } - { - LiteralArgumentBuilder delete = literal("remove"); - RequiredArgumentBuilder claim = getClaimArgument(); - claim.suggests(CLAIM_PROVIDER); - LiteralArgumentBuilder confirm = literal("confirm"); - confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); - claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); - claim.then(confirm); - delete.then(claim); - delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); - command.then(delete); - } - { - { - LiteralArgumentBuilder expand = literal("expand"); - RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); - direction.suggests(DIRECTION_SUGGESTION_BUILDER); - - direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - IntegerArgumentType.getInteger(context, "distance"), - directionByName(StringArgumentType.getString(context, "direction")), - context.getSource(), - false - )); - - amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - IntegerArgumentType.getInteger(context, "distance"), - Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], - context.getSource(), - false - )); - - amount.then(direction); - expand.then(amount); - command.then(expand); - } - { - LiteralArgumentBuilder shrink = literal("shrink"); - RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); - direction.suggests(DIRECTION_SUGGESTION_BUILDER); - - direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - -IntegerArgumentType.getInteger(context, "distance"), - directionByName(StringArgumentType.getString(context, "direction")), - context.getSource(), - false - )); - - amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - -IntegerArgumentType.getInteger(context, "distance"), - Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], - context.getSource(), - false - )); +//public class ClaimCommand { +// public static final int MAX_NAME_LENGTH = 30; +// private static void validateCanAccess(ServerPlayerEntity player, Claim claim, boolean admin) throws CommandSyntaxException { +// if (claim == null) { +// throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); +// } +// +// if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SETTINGS)) { +// throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); +// } +// } +// +// private static void validateClaim(Claim claim) throws CommandSyntaxException { +// if (claim == null) throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); +// } +// +// +// private static Predicate perm(String str) { +// return perm(str, 2); +// } +// private static Predicate perm(String str, int op) { +// return source -> ItsMine.permissions().hasPermission(source, "itsmine." + str, op); +// } +// private static final Predicate PERMISSION_CHECK_ADMIN = src -> perm("admin").test(src) || perm("admin.modify_balance").test(src) || +// perm("admin.infinite_blocks").test(src) || perm("admin.modify").test(src) || +// perm("admin.modify_balance").test(src) || perm("admin.ignore_claims").test(src) || +// perm("admin.modify_permissions").test(src); +// - amount.then(direction); - shrink.then(amount); - command.then(shrink); - } - } - { - LiteralArgumentBuilder delete = literal("remove"); - RequiredArgumentBuilder claim = getClaimArgument(); - LiteralArgumentBuilder confirm = literal("confirm"); - confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); - claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), false)); - claim.then(confirm); - delete.then(claim); - delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); - command.then(delete); - } - { - LiteralArgumentBuilder transfer = literal("transfer"); - RequiredArgumentBuilder claim = argument("claim", StringArgumentType.word()).suggests(CLAIM_PROVIDER); - RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); - LiteralArgumentBuilder confirm = literal("confirm"); - confirm.executes(context -> { - final String string = "-accept-"; - ServerPlayerEntity p = EntityArgumentType.getPlayer(context, "player"); - String input = StringArgumentType.getString(context, "claim"); - String claimName = input.replace(string, ""); - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(claimName); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } +// public static final SuggestionProvider PLAYERS_PROVIDER = (source, builder) -> { +// List strings = new ArrayList<>(); +// for (ServerPlayerEntity player : source.getSource().getMinecraftServer().getPlayerManager().getPlayerList()) { +// strings.add(player.getEntityName()); +// } +// return CommandSource.suggestMatching(strings, builder); +// }; +// public static final SuggestionProvider SETTINGS_PROVIDER = (source, builder) -> { +// List strings = new ArrayList<>(); +// for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { +// strings.add(value.id); +// } +// for (Claim.Permission value : Claim.Permission.values()) { +// strings.add(value.id); +// } +// return CommandSource.suggestMatching(strings, builder); +// }; +// public static final SuggestionProvider PERMISSIONS_PROVIDER = (source, builder) -> { +// List strings = new ArrayList<>(); +// for (Claim.Permission value : Claim.Permission.values()) { +// strings.add(value.id); +// } +// return CommandSource.suggestMatching(strings, builder); +// }; +// public static final SuggestionProvider MESSAGE_EVENTS_PROVIDER = (source, builder) -> { +// List strings = new ArrayList<>(); +// for (Claim.Event value : Claim.Event.values()) { +// strings.add(value.id); +// } +// return CommandSource.suggestMatching(strings, builder); +// }; +// public static final SuggestionProvider EVENT_MESSAGE_PROVIDER = (source, builder) -> { +// if (!builder.getRemaining().isEmpty()) +// return builder.buildFuture(); +// +// List strings = new ArrayList<>(); +// strings.add("reset"); +// try { +// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(source, "claim")); +// Claim.Event eventType = Claim.Event.getById(getString(source, "messageEvent")); +// +// if (eventType != null && claim != null) { +// String message = eventType == Claim.Event.ENTER_CLAIM ? claim.enterMessage : claim.leaveMessage; +// if (message != null) strings.add(message); +// } +// +// } catch (Exception ignored) { +// } +// +// return CommandSource.suggestMatching(strings, builder); +// }; - if (input.startsWith(string)) { - return acceptTransfer(context.getSource()); - } +// public static void register(CommandDispatcher dispatcher) { +// LiteralArgumentBuilder main = literal("itsmine"); +// main.executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); +// +// register(main, dispatcher); +// +// LiteralArgumentBuilder alias = literal("claim"); +// alias.executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); +// +// register(alias, dispatcher); +// +// dispatcher.register(main); +// dispatcher.register(alias); +// } - return transfer(context.getSource(), claim1, p, false); - }); - player.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), EntityArgumentType.getPlayer(context, "player"), false)); - player.then(confirm); - claim.then(player); - transfer.then(claim); - transfer.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), EntityArgumentType.getPlayer(context, "player"), false)); - command.then(transfer); - } - { - LiteralArgumentBuilder info = literal("info"); - RequiredArgumentBuilder claim = getClaimArgument(); - info.executes(context -> info( - context.getSource(), - ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()) - )); - claim.executes(context -> info( - context.getSource(), - ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")) - )); - info.then(claim); - command.then(info); - } - { - LiteralArgumentBuilder list = literal("list"); - LiteralArgumentBuilder listall = literal("listall"); - RequiredArgumentBuilder player = argument("player", StringArgumentType.word()); - player.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_CHECK_OTHERS, 2)); - player.suggests(PLAYERS_PROVIDER); - list.executes(context -> list(context.getSource(), context.getSource().getName())); - listall.executes(context -> listall(context.getSource())); - player.executes(context -> list(context.getSource(), StringArgumentType.getString(context, "player"))); - list.then(player); - command.then(list); - command.then(listall); +// private static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { +// SubzoneCommand.register(command); - LiteralArgumentBuilder claims = literal("claims") - .executes(context -> list(context.getSource(), context.getSource().getName())) - .then(player); - dispatcher.register(claims); - } - { - //TODO: FIX THIS +// { +// LiteralArgumentBuilder help = literal("help"); +// help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); +// +// RequiredArgumentBuilder id = getHelpId(); +// RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); +// +// page.executes((context) -> { +// Claim.HelpBook book = Claim.HelpBook.getById(getString(context, "id")); +// if (book == null) { +// context.getSource().sendError(new LiteralText("Invalid Book!")); +// return -1; +// } +// int p = IntegerArgumentType.getInteger(context, "page"); +// +// if (p > book.texts.length) p = 1; +// return sendPage(context.getSource(), book.texts, p, book.title, book.getCommand()); +// }); +// +// id.then(page); +// help.then(id); +// command.then(help); +// } +// { +// LiteralArgumentBuilder create = literal("create"); +// RequiredArgumentBuilder name = argument("name", word()); +// +// name.executes(context -> { +// ServerPlayerEntity player = context.getSource().getPlayer(); +// Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); +// if (selectedPositions == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); +// } else if (selectedPositions.getLeft() == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); +// } else if (selectedPositions.getRight() == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); +// } else { +// String cname = getString(context, "name"); +// if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), false, null) > 0) { +// ClaimManager.INSTANCE.stickPositions.remove(player); +// } +// } +// return 0; +// }); +// +// ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); +// RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); +// max.executes(context -> createClaim( +// getString(context, "name"), +// context.getSource(), +// BlockPosArgumentType.getBlockPos(context, "min"), +// BlockPosArgumentType.getBlockPos(context, "max"), +// false, +// null +// )); +// min.then(max); +// name.then(min); +// create.then(name); +// command.then(create); +// } +// { +// LiteralArgumentBuilder fly = literal("fly") +// .requires(src -> ItsMine.permissions().hasPermission(src, PermissionUtil.Command.CLAIM_FLY, 2)); +// RequiredArgumentBuilder setArgument = CommandManager.argument("set", BoolArgumentType.bool()); +// +// fly.executes((context) -> setFly(context, !ClaimManager.INSTANCE.flyers.contains(context.getSource().getPlayer().getUuid()))); +// setArgument.executes((context) -> setFly(context, BoolArgumentType.getBool(context, "set"))); +// +// fly.then(setArgument); +// command.then(fly); +// } +// { +// LiteralArgumentBuilder rename = literal("rename"); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); +// RequiredArgumentBuilder nameArgument = argument("name", word()); +// nameArgument.executes((context) -> rename(context, false)); +// claimArgument.then(nameArgument); +// rename.then(claimArgument); +// command.then(rename); +// } +// { +// LiteralArgumentBuilder trusted = literal("trusted"); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); +// trusted.executes((context)-> { +// ServerPlayerEntity player = context.getSource().getPlayer(); +// Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); +// if (claim == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// return showTrustedList(context, claim, false); +// }); +// +// claimArgument.executes((context) -> { +// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (claim == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// return showTrustedList(context, claim, false); +// }); +// trusted.then(claimArgument); +// command.then(trusted); +// dispatcher.register(trusted); +// } +// { +// LiteralArgumentBuilder stick = literal("stick"); +// stick.executes(context -> { +// Pair posPair = ClaimManager.INSTANCE.stickPositions.get(context.getSource().getPlayer()); +// context.getSource().sendFeedback(new LiteralText(posPair == null ? "You can now use a stick to create claims. Run this command again to disable" : "Claim stick disabled. Run this command again to enable").formatted(Formatting.DARK_PURPLE), false); +// if (posPair == null) { +// ClaimManager.INSTANCE.stickPositions.put(context.getSource().getPlayer(), new Pair<>(null, null)); +// } else { +// ClaimManager.INSTANCE.stickPositions.remove(context.getSource().getPlayer()); +// } +// return 0; +// }); +// command.then(stick); +// } +// { +// LiteralArgumentBuilder show = literal("show"); +// show.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().dimension.getType()), false)); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// claim.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "name")), false)); +// show.then(claim); +// command.then(show); +// } +// { +// LiteralArgumentBuilder hide = literal("hide"); +// hide.executes(context -> showClaim(context.getSource(), null, true)); +// command.then(hide); +// } +// { +// LiteralArgumentBuilder check = literal("blocks"); +// RequiredArgumentBuilder other = argument("player", EntityArgumentType.player()); +// other.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); +// other.executes(ctx -> checkPlayer(ctx.getSource(), EntityArgumentType.getPlayer(ctx, "player").getGameProfile().getId())); +// check.then(other); +// check.executes(ctx -> checkPlayer(ctx.getSource(), ctx.getSource().getPlayer().getGameProfile().getId())); +// command.then(check); +// } +// { +// LiteralArgumentBuilder delete = literal("remove"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// LiteralArgumentBuilder confirm = literal("confirm"); +// confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); +// claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); +// claim.then(confirm); +// delete.then(claim); +// delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); +// command.then(delete); +// } +// { +// { +// LiteralArgumentBuilder expand = literal("expand"); +// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); +// RequiredArgumentBuilder direction = getDirections(); +// +// direction.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// IntegerArgumentType.getInteger(context, "distance"), +// directionByName(getString(context, "direction")), +// context.getSource(), +// false +// )); +// +// amount.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// IntegerArgumentType.getInteger(context, "distance"), +// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], +// context.getSource(), +// false +// )); +// +// amount.then(direction); +// expand.then(amount); +// command.then(expand); +// } +// { +// LiteralArgumentBuilder shrink = literal("shrink"); +// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); +// RequiredArgumentBuilder direction = getDirections(); +// +// direction.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// -IntegerArgumentType.getInteger(context, "distance"), +// directionByName(getString(context, "direction")), +// context.getSource(), +// false +// )); +// +// amount.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// -IntegerArgumentType.getInteger(context, "distance"), +// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], +// context.getSource(), +// false +// )); +// +// amount.then(direction); +// shrink.then(amount); +// command.then(shrink); +// } +// } +// { +// LiteralArgumentBuilder delete = literal("remove"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// LiteralArgumentBuilder confirm = literal("confirm"); +// confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); +// claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); +// claim.then(confirm); +// delete.then(claim); +// delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); +// command.then(delete); +// } +// { +// LiteralArgumentBuilder transfer = literal("transfer"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); +// LiteralArgumentBuilder confirm = literal("confirm"); +// confirm.executes(context -> { +// final String string = "-accept-"; +// ServerPlayerEntity p = EntityArgumentType.getPlayer(context, "player"); +// String input = getString(context, "claim"); +// String claimName = input.replace(string, ""); +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(claimName); +// if (claim1 == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// +// if (input.startsWith(string)) { +// return acceptTransfer(context.getSource()); +// } +// +// return transfer(context.getSource(), claim1, p, false); +// }); +// player.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), EntityArgumentType.getPlayer(context, "player"), false)); +// player.then(confirm); +// claim.then(player); +// transfer.then(claim); +// transfer.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), EntityArgumentType.getPlayer(context, "player"), false)); +// command.then(transfer); +// } +// { +// ///claim rentable [] +// LiteralArgumentBuilder rentable = literal("rentable"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// +// RequiredArgumentBuilder currency = CommandManager.argument("item", ItemStackArgumentType.itemStack()).suggests(ClaimCommand::itemsSuggestion); +// RequiredArgumentBuilder amount = CommandManager.argument("count", IntegerArgumentType.integer(1)); +// RequiredArgumentBuilder days = CommandManager.argument("days", StringArgumentType.string() +// ); +// RequiredArgumentBuilder maxdays = CommandManager.argument("maxdays", string()); +// maxdays.executes(context -> makeRentable(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false), IntegerArgumentType.getInteger(context, "count"), getString(context, "days"), getString(context, "maxdays"))); +// claim.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if(claim1.rent.getCurrency() !=null || claim1.rent.getAmount() != 0 || claim1.rent.getRentAbleTime() != 0 || claim1.rent.getMaxrentAbleTime() != 0 && claim1.rent.isRentable()) { +// context.getSource().sendFeedback(new LiteralText("Can't enable rent for " + claim1.name + ", because no values are set").formatted(Formatting.RED), true); +// return 0; +// } +// if(claim1.rent.getTenant() == null){ +// String state = claim1.rent.isRentable() ? "disabled" : "enabled"; +// claim1.rent.setRentable(!claim1.rent.isRentable()); +// context.getSource().sendFeedback(new LiteralText("Renting for " + claim1.name + " has been " + state).formatted(Formatting.GREEN), true); +// return 1; +// } else { +// context.getSource().sendFeedback(new LiteralText("Can't disable rent for " + claim1.name + ", because it is currently being rented").formatted(Formatting.RED), true); +// return 0; +// } +// }); +// +// days.then(maxdays); +// amount.then(days); +// currency.then(amount); +// claim.then(currency); +// rentable.then(claim); +// command.then(rentable); +// } +// { +// LiteralArgumentBuilder rent = literal("rent"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// RequiredArgumentBuilder days = CommandManager.argument("days", string()); +// days.executes(context -> rent(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), getString(context, "days"))); +// +// claim.then(days); +// rent.then(claim); +// command.then(rent); +// } +// { +// LiteralArgumentBuilder info = literal("info"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// info.executes(context -> info( +// context.getSource(), +// ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()) +// )); +// claim.executes(context -> info(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")) +// )); +// info.then(claim); +// command.then(info); +// } +// { +// LiteralArgumentBuilder revenue = literal("revenue"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// RequiredArgumentBuilder claimRevenue = argument("claimRevenue", BoolArgumentType.bool()); +// revenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); +// claim.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); +// claimRevenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); +// claim.then(claimRevenue); +// revenue.then(claim); +// command.then(revenue); +// } +// { +// LiteralArgumentBuilder list = literal("list"); +// LiteralArgumentBuilder listall = literal("listall"); +// RequiredArgumentBuilder player = argument("player", word()); +// player.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); +// player.suggests(PLAYERS_PROVIDER); +// list.executes(context -> list(context.getSource(), context.getSource().getName())); +// listall.executes(context -> listall(context.getSource())); +// player.executes(context -> list(context.getSource(), getString(context, "player"))); +// list.then(player); +// command.then(list); +// command.then(listall); +// +// LiteralArgumentBuilder claims = literal("claims") +// .executes(context -> list(context.getSource(), context.getSource().getName())) +// .then(player); +// dispatcher.register(claims); +// } +// { +// //TODO: FIX THIS // LiteralArgumentBuilder listall = literal("listall"); // RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); // @@ -471,1211 +441,1466 @@ private static void register(LiteralArgumentBuilder command // page.executes(context -> listAll(context.getSource(), IntegerArgumentType.getInteger(context, "page"))); // listall.then(page); // command.then(listall); - } - { - LiteralArgumentBuilder trust = literal("trust"); - RequiredArgumentBuilder playerArgument = argument("player", EntityArgumentType.player()); - RequiredArgumentBuilder claimArgument = getClaimArgument(); - - playerArgument.executes((context -> executeTrust(context, EntityArgumentType.getPlayer(context, "player"), true, null))); - claimArgument.executes((context -> executeTrust(context, EntityArgumentType.getPlayer(context, "player"), true, StringArgumentType.getString(context, "claim")))); - - playerArgument.then(claimArgument); - trust.then(playerArgument); - command.then(trust); - dispatcher.register(trust); - } - { - LiteralArgumentBuilder distrust = literal("distrust"); - RequiredArgumentBuilder playerArgument = argument("player", EntityArgumentType.entity()); - RequiredArgumentBuilder claimArgument = getClaimArgument(); - - playerArgument.executes((context -> executeTrust(context, EntityArgumentType.getEntity(context, "player"), false, null))); - claimArgument.executes((context -> executeTrust(context, EntityArgumentType.getEntity(context, "player"), false, StringArgumentType.getString(context, "claim")))); - - playerArgument.then(claimArgument); - distrust.then(playerArgument); - command.then(distrust); - dispatcher.register(distrust); - } - - createExceptionCommand(command, false); - - { - LiteralArgumentBuilder admin = literal("admin"); - admin.requires(PERMISSION_CHECK_ADMIN); - { - LiteralArgumentBuilder add = literal("addBlocks"); - add.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_BALANCE, 2)); - RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); - RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); - amount.executes(context -> { - ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); - context.getSource().sendFeedback(new LiteralText("Gave " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); - return 0; - }); - player.then(amount); - add.then(player); - admin.then(add); - } - { - LiteralArgumentBuilder set = literal("setOwner"); - RequiredArgumentBuilder newOwner = argument("newOwner", GameProfileArgumentType.gameProfile()); - RequiredArgumentBuilder claimArgument = getClaimArgument(); - - newOwner.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); - if (claim == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - - Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); - - if (profiles.size() > 1) { - context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); - return -1; - } - return setOwner(context.getSource(), claim, profiles.iterator().next()); - }); - - claimArgument.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - - Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); - - if (profiles.size() > 1) { - context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); - return -1; - } - return setOwner(context.getSource(), claim, profiles.iterator().next()); - }); - - newOwner.then(claimArgument); - set.then(newOwner); - admin.then(set); - } - { - LiteralArgumentBuilder set = literal("setOwnerName"); - RequiredArgumentBuilder nameArgument = argument("newName", StringArgumentType.word()); - RequiredArgumentBuilder claimArgument = getClaimArgument(); - - nameArgument.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); - if (claim == null) { - context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return -1; - } - return setOwnerName(context.getSource(), claim, StringArgumentType.getString(context, "newName")); - }); - - claimArgument.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim == null) { - context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return -1; - } - return setOwnerName(context.getSource(), claim, StringArgumentType.getString(context, "newName")); - }); - - nameArgument.then(claimArgument); - set.then(nameArgument); - admin.then(set); - } - { - LiteralArgumentBuilder rename = literal("rename"); - RequiredArgumentBuilder claimArgument = argument("claim", StringArgumentType.word()) - .suggests(CLAIM_PROVIDER); - RequiredArgumentBuilder nameArgument = argument("name", StringArgumentType.word()); - nameArgument.executes((context) -> rename(context, true)); - claimArgument.then(nameArgument); - rename.then(claimArgument); - admin.then(rename); - } - { - LiteralArgumentBuilder remove = literal("removeBlocks"); - remove.requires(source ->ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_BALANCE, 2)); - RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); - RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); - amount.executes(context -> { - ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), -IntegerArgumentType.getInteger(context, "amount")); - context.getSource().sendFeedback(new LiteralText("Took " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); - return 0; - }); - player.then(amount); - remove.then(player); - admin.then(remove); - } - { - LiteralArgumentBuilder set = literal("setBlocks"); - set.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_BALANCE, 2)); - RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); - RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); - amount.executes(context -> { - ClaimManager.INSTANCE.setClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); - context.getSource().sendFeedback(new LiteralText("Set claim block amount to " + IntegerArgumentType.getInteger(context, "amount")).formatted(Formatting.GREEN), true); - return 0; - }); - player.then(amount); - set.then(player); - admin.then(set); - } - { - LiteralArgumentBuilder delete = literal("remove"); - delete.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY, 2)); - RequiredArgumentBuilder claim = getClaimArgument(); - LiteralArgumentBuilder confirm = literal("confirm"); - confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), true)); - claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")), true)); - claim.then(confirm); - delete.then(claim); - delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), true)); - admin.then(delete); - } - { - LiteralArgumentBuilder create = literal("create"); - create.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_INFINITE_CLAIM, 2)); - ArgumentBuilder name = argument("name", StringArgumentType.word()); - ArgumentBuilder customOwner = argument("customOwnerName", StringArgumentType.word()); - ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); - RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); - max.executes(context -> createClaim( - StringArgumentType.getString(context, "name"), - context.getSource(), - BlockPosArgumentType.getBlockPos(context, "min"), - BlockPosArgumentType.getBlockPos(context, "max"), - true, - null - )); - name.executes(context -> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); - if (selectedPositions == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getLeft() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getRight() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); - } else { - String cname = StringArgumentType.getString(context, "name"); - if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, null) > 0) { - ClaimManager.INSTANCE.stickPositions.remove(player); - } - } - return 0; - }); - customOwner.executes(context -> { - ServerPlayerEntity player = context.getSource().getPlayer(); - Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); - if (selectedPositions == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getLeft() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); - } else if (selectedPositions.getRight() == null) { - context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); - } else { - String cname = StringArgumentType.getString(context, "name"); - if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, StringArgumentType.getString(context, "customOwnerName")) > 0) { - ClaimManager.INSTANCE.stickPositions.remove(player); - } - } - return 0; - }); - min.then(max); - name.then(customOwner); - name.then(min); - create.then(name); - admin.then(create); - } - { - LiteralArgumentBuilder ignore = literal("ignoreClaims"); - ignore.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_IGNORE_CLAIMS, 2)); - ignore.executes(context -> { - UUID id = context.getSource().getPlayer().getGameProfile().getId(); - boolean isIgnoring = ClaimManager.INSTANCE.ignoringClaims.contains(id); - if (isIgnoring) ClaimManager.INSTANCE.ignoringClaims.remove(id); - else ClaimManager.INSTANCE.ignoringClaims.add(id); - context.getSource().sendFeedback(new LiteralText("You are " + (isIgnoring ? "no longer" : "now") + " ignoring claims.").formatted(Formatting.GREEN), false); - return 0; - }); - admin.then(ignore); - } - { - { - LiteralArgumentBuilder expand = literal("expand"); - expand.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY, 2)); - RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); - direction.suggests(DIRECTION_SUGGESTION_BUILDER); - - direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - IntegerArgumentType.getInteger(context, "distance"), - directionByName(StringArgumentType.getString(context, "direction")), - context.getSource(), - true - )); - - amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - IntegerArgumentType.getInteger(context, "distance"), - Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], - context.getSource(), - true - )); - - amount.then(direction); - expand.then(amount); - admin.then(expand); - } - { - LiteralArgumentBuilder shrink = literal("shrink"); - shrink.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY, 2)); - RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); - RequiredArgumentBuilder direction = argument("direction", StringArgumentType.word()); - direction.suggests(DIRECTION_SUGGESTION_BUILDER); - - direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - -IntegerArgumentType.getInteger(context, "distance"), - directionByName(StringArgumentType.getString(context, "direction")), - context.getSource(), - true - )); - - amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), - -IntegerArgumentType.getInteger(context, "distance"), - Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], - context.getSource(), - true - )); - - amount.then(direction); - shrink.then(amount); - admin.then(shrink); - } - } - createExceptionCommand(admin, true); - command.then(admin); - } - } - - private static int sendPage(ServerCommandSource source, Text[] text, int page, String title, String command) { - int prevPage = page - 2; - int thisPage = page - 1; - int nextPage = page + 1; - final String SEPARATOR = "-----------------------------------------------------"; - Text header = new LiteralText("") - .append(new LiteralText("- [ ").formatted(Formatting.GRAY)) - .append(new LiteralText(title).formatted(Formatting.GOLD)) - .append(" ] ") - .append(SEPARATOR.substring(ChatColor.removeAlternateColorCodes('&', title).length() + 4)) - .formatted(Formatting.GRAY); - - Text button_prev = new LiteralText("") - .append(new LiteralText("<-").formatted(Formatting.WHITE, Formatting.BOLD)) - .append(" ").append(new LiteralText("Prev").formatted(Formatting.GOLD)) - .styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); - if (prevPage >= 0) - style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); - }); - - Text button_next = new LiteralText("") - .append(new LiteralText("Next").formatted(Formatting.GOLD)) - .append(" ").append(new LiteralText("->").formatted(Formatting.WHITE, Formatting.BOLD)).append(" ") - .styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); - if (nextPage <= text.length) - style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); - }); - - Text buttons = new LiteralText("") - .append(new LiteralText("[ ").formatted(Formatting.GRAY)) - .append(button_prev) - .append(" ") - .append( - new LiteralText(String.valueOf(page)).formatted(Formatting.GREEN) - .append(new LiteralText("/").formatted(Formatting.GRAY)) - .append(new LiteralText(String.valueOf(text.length)).formatted(Formatting.GREEN)) - ) - .append(" ") - .append(button_next) - .append(new LiteralText("] ").formatted(Formatting.GRAY)); - - Text footer = new LiteralText("- ") - .formatted(Formatting.GRAY) - .append(buttons).append(new LiteralText(" ------------------------------").formatted(Formatting.GRAY)); - - header.append("\n").append(text[thisPage]).append("\n").append(footer); - source.sendFeedback(header, false); - return 1; - } - - private static void createExceptionCommand(LiteralArgumentBuilder command, boolean admin) { - { - LiteralArgumentBuilder settings = literal("settings"); - RequiredArgumentBuilder claim = getClaimArgument(); - - if (!admin) { - settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); - - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return querySettings(context.getSource(), claim1); - }); - } - - RequiredArgumentBuilder id = argument("setting", StringArgumentType.word()).suggests(SETTINGS_PROVIDER); - RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); - - id.executes((context) -> executeSetting(context.getSource(), StringArgumentType.getString(context, "setting"), StringArgumentType.getString(context, "claim"), true, false, admin)); - set.executes((context) -> executeSetting(context.getSource(), StringArgumentType.getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); - - id.then(set); - claim.then(id); - settings.then(claim); - command.then(settings); - } - - LiteralArgumentBuilder exceptions = literal("permissions"); - if (admin) exceptions.requires(source -> ItsMine.permissions().hasPermission(source, Permissions.Command.ADMIN_MODIFY_PERMISSIONS, 2)); - RequiredArgumentBuilder claim = getClaimArgument(); - if (!admin) { - exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); - - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return showTrustedList(context, claim1, false); - }); - } - - if (!admin) { - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(new LiteralText("That claim does not exist")); - return -1; - } - return showTrustedList(context, claim1, true); - }); - } - - { - RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); - LiteralArgumentBuilder remove = literal("remove"); - remove.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - claim1.permissionManager.resetPermissions(player1.getGameProfile().getId()); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + " no longer has an exception in the claim").formatted(Formatting.YELLOW), false); - } - return 0; - }); - player.then(remove); - LiteralArgumentBuilder all = literal("*"); - RequiredArgumentBuilder allstate = argument("allow", BoolArgumentType.bool()); - allstate.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - validateClaim(claim1); - return setTrust(context, claim1, player1, BoolArgumentType.getBool(context, "allow"), admin); - }); - all.then(allstate); - player.then(all); - for (Claim.Permission value : Claim.Permission.values()) { - LiteralArgumentBuilder permNode = literal(value.id); - RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); - allow.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - boolean permission = BoolArgumentType.getBool(context, "allow"); - modifyException(claim1, player1, value, permission); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has the permission " + value.name).formatted(Formatting.YELLOW), false); - } - return 0; - }); - permNode.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - boolean permission = hasPermission(claim1, player1, value); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); - } - return 0; - }); - permNode.then(allow); - player.then(permNode); - } - claim.then(player); - } - { - LiteralArgumentBuilder message = literal("message"); - RequiredArgumentBuilder claimArgument = getClaimArgument(); - RequiredArgumentBuilder messageEvent = argument("messageEvent", StringArgumentType.word()) - .suggests(MESSAGE_EVENTS_PROVIDER); - RequiredArgumentBuilder messageArgument = argument("message", StringArgumentType.greedyString()) - .suggests(EVENT_MESSAGE_PROVIDER); - - messageArgument.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(StringArgumentType.getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PROPERTIES, context, admin)) { - Claim.Event event = Claim.Event.getById(StringArgumentType.getString(context, "messageEvent")); - - if (event == null) { - context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); - return -1; - } - - return setEventMessage(context.getSource(), claim1, event, StringArgumentType.getString(context, "message")); - } - - return -1; - }); - - messageEvent.then(messageArgument); - claimArgument.then(messageEvent); - message.then(claimArgument); - command.then(message); - } - - - exceptions.then(claim); - command.then(exceptions); - } - private static boolean verifyPermission(Claim claim, Claim.Permission permission, CommandContext context, boolean admin) throws CommandSyntaxException { - if (verifyExists(claim, context)) { - if (claim.permissionManager.hasPermission(context.getSource().getPlayer().getGameProfile().getId(), permission)) { - return true; - } else { - context.getSource().sendFeedback(new LiteralText(admin ? "You are modifying a claim using admin privileges" : "You cannot modify exceptions for this claim").formatted(admin ? Formatting.DARK_RED : Formatting.RED), false); - return admin; - } - } else { - return false; - } - } - private static boolean verifyExists(Claim claim, CommandContext context) { - if (claim == null) { - context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return false; - } else { - return true; - } - } - +// } +// { +// LiteralArgumentBuilder trust = literal("trust"); +// RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); +// playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, null))); +// claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, getString(context, "claim")))); +// +// playerArgument.then(claimArgument); +// trust.then(playerArgument); +// command.then(trust); +// dispatcher.register(trust); +// } +// { +// LiteralArgumentBuilder distrust = literal("distrust"); +// RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); +// +// playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, null))); +// claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, getString(context, "claim")))); +// +// playerArgument.then(claimArgument); +// distrust.then(playerArgument); +// command.then(distrust); +// dispatcher.register(distrust); +// } - private static int showClaim(ServerCommandSource source, Claim claim, boolean reset) throws CommandSyntaxException { - ServerPlayerEntity player = source.getPlayer(); - if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!Config.claims2d &&((ClaimShower)player).getShownClaim() != claim)) showClaim(source, ((ClaimShower)player).getShownClaim(), true); - if (reset && ((ClaimShower)player).getShownClaim() != null) claim = ((ClaimShower)player).getShownClaim(); - if (claim != null) { - if (!claim.dimension.equals(source.getWorld().getDimension().getType())) { - if (claim == ((ClaimShower)player).getShownClaim()) ((ClaimShower)player).setShownClaim(null); // just so we dont have extra packets on this - source.sendFeedback(new LiteralText("That claim is not in this dimension").formatted(Formatting.RED), false); - return 0; - } - source.sendFeedback(new LiteralText((!reset ? "Showing" : "Hiding") + " claim: " + claim.name).formatted(Formatting.GREEN), false); - silentHideShow(player, claim, reset, true); +// createExceptionCommand(command, false); +// +// { +// LiteralArgumentBuilder admin = literal("admin"); +// admin.requires(PERMISSION_CHECK_ADMIN); +// { +// LiteralArgumentBuilder entity = literal("entities"); +// entity.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// entity.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); +// context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); +// claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { +// context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); +// }); +// return 1; +// }); +// claim.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); +// claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { +// context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); +// }); +// return 1; +// }); +// entity.then(claim); +// admin.then(entity); +// } +// { +// LiteralArgumentBuilder add = literal("addBlocks"); +// add.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); +// RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); +// RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); +// amount.executes(context -> { +// ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); +// context.getSource().sendFeedback(new LiteralText("Gave " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); +// return 0; +// }); +// player.then(amount); +// add.then(player); +// admin.then(add); +// } +// { +// LiteralArgumentBuilder set = literal("setOwner"); +// RequiredArgumentBuilder newOwner = argument("newOwner", GameProfileArgumentType.gameProfile()); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); +// +// newOwner.executes((context) -> { +// Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); +// if (claim == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// +// Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); +// +// if (profiles.size() > 1) { +// context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); +// return -1; +// } +// return setOwner(context.getSource(), claim, profiles.iterator().next()); +// }); +// +// claimArgument.executes((context) -> { +// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (claim == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// +// Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); +// +// if (profiles.size() > 1) { +// context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); +// return -1; +// } +// return setOwner(context.getSource(), claim, profiles.iterator().next()); +// }); +// +// newOwner.then(claimArgument); +// set.then(newOwner); +// admin.then(set); +// } +// { +// LiteralArgumentBuilder set = literal("setOwnerName"); +// RequiredArgumentBuilder nameArgument = argument("newName", word()); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); +// +// nameArgument.executes((context) -> { +// Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); +// if (claim == null) { +// context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return -1; +// } +// return setOwnerName(context.getSource(), claim, getString(context, "newName")); +// }); +// +// claimArgument.executes((context) -> { +// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (claim == null) { +// context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return -1; +// } +// return setOwnerName(context.getSource(), claim, getString(context, "newName")); +// }); +// +// nameArgument.then(claimArgument); +// set.then(nameArgument); +// admin.then(set); +// } +// { +// LiteralArgumentBuilder rename = literal("rename"); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaimsSubzones(); +// RequiredArgumentBuilder nameArgument = argument("name", word()); +// nameArgument.executes((context) -> rename(context, true)); +// claimArgument.then(nameArgument); +// rename.then(claimArgument); +// admin.then(rename); +// } +// { +// LiteralArgumentBuilder remove = literal("removeBlocks"); +// remove.requires(source ->ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); +// RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); +// RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); +// amount.executes(context -> { +// ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), -IntegerArgumentType.getInteger(context, "amount")); +// context.getSource().sendFeedback(new LiteralText("Took " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); +// return 0; +// }); +// player.then(amount); +// remove.then(player); +// admin.then(remove); +// } +// { +// LiteralArgumentBuilder set = literal("setBlocks"); +// set.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); +// RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); +// RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); +// amount.executes(context -> { +// ClaimManager.INSTANCE.setClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); +// context.getSource().sendFeedback(new LiteralText("Set claim block amount to " + IntegerArgumentType.getInteger(context, "amount")).formatted(Formatting.GREEN), true); +// return 0; +// }); +// player.then(amount); +// set.then(player); +// admin.then(set); +// } +// { +// LiteralArgumentBuilder delete = literal("remove"); +// delete.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// LiteralArgumentBuilder confirm = literal("confirm"); +// confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); +// claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); +// claim.then(confirm); +// delete.then(claim); +// delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), true)); +// admin.then(delete); +// } +// { +// LiteralArgumentBuilder create = literal("create"); +// create.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2)); +// ArgumentBuilder name = argument("name", word()); +// ArgumentBuilder customOwner = argument("customOwnerName", word()); +// ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); +// RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); +// max.executes(context -> createClaim( +// getString(context, "name"), +// context.getSource(), +// BlockPosArgumentType.getBlockPos(context, "min"), +// BlockPosArgumentType.getBlockPos(context, "max"), +// true, +// null +// )); +// name.executes(context -> { +// ServerPlayerEntity player = context.getSource().getPlayer(); +// Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); +// if (selectedPositions == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); +// } else if (selectedPositions.getLeft() == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); +// } else if (selectedPositions.getRight() == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); +// } else { +// String cname = getString(context, "name"); +// if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, null) > 0) { +// ClaimManager.INSTANCE.stickPositions.remove(player); +// } +// } +// return 0; +// }); +// customOwner.executes(context -> { +// ServerPlayerEntity player = context.getSource().getPlayer(); +// Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); +// if (selectedPositions == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); +// } else if (selectedPositions.getLeft() == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); +// } else if (selectedPositions.getRight() == null) { +// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); +// } else { +// String cname = getString(context, "name"); +// if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, getString(context, "customOwnerName")) > 0) { +// ClaimManager.INSTANCE.stickPositions.remove(player); +// } +// } +// return 0; +// }); +// min.then(max); +// name.then(customOwner); +// name.then(min); +// create.then(name); +// admin.then(create); +// } +// { +// LiteralArgumentBuilder ignore = literal("ignoreClaims"); +// ignore.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_IGNORE_CLAIMS, 2)); +// ignore.executes(context -> { +// UUID id = context.getSource().getPlayer().getGameProfile().getId(); +// boolean isIgnoring = ClaimManager.INSTANCE.ignoringClaims.contains(id); +// if (isIgnoring) ClaimManager.INSTANCE.ignoringClaims.remove(id); +// else ClaimManager.INSTANCE.ignoringClaims.add(id); +// context.getSource().sendFeedback(new LiteralText("You are " + (isIgnoring ? "no longer" : "now") + " ignoring claims.").formatted(Formatting.GREEN), false); +// return 0; +// }); +// admin.then(ignore); +// } +// { +// { +// LiteralArgumentBuilder expand = literal("expand"); +// expand.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); +// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); +// RequiredArgumentBuilder direction = getDirections(); +// +// direction.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// IntegerArgumentType.getInteger(context, "distance"), +// directionByName(getString(context, "direction")), +// context.getSource(), +// true +// )); +// +// amount.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// IntegerArgumentType.getInteger(context, "distance"), +// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], +// context.getSource(), +// true +// )); +// +// amount.then(direction); +// expand.then(amount); +// admin.then(expand); +// } +// { +// LiteralArgumentBuilder shrink = literal("shrink"); +// shrink.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); +// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); +// RequiredArgumentBuilder direction = getDirections(); +// +// direction.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// -IntegerArgumentType.getInteger(context, "distance"), +// directionByName(getString(context, "direction")), +// context.getSource(), +// true +// )); +// +// amount.executes(context -> expand( +// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), +// -IntegerArgumentType.getInteger(context, "distance"), +// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], +// context.getSource(), +// true +// )); +// +// amount.then(direction); +// shrink.then(amount); +// admin.then(shrink); +// } +// } +// createExceptionCommand(admin, true); +// command.then(admin); +// } +// } - } else { - source.sendFeedback(new LiteralText("That is not a valid claim").formatted(Formatting.RED), false); - } - return 0; - } - private static void silentHideShow(ServerPlayerEntity player, Claim claim, boolean hide, boolean updateStatus) { - if (updateStatus) { - if (!hide) ((ClaimShower) player).setShownClaim(claim); - else ((ClaimShower) player).setShownClaim(null); - } - BlockState block = hide ? null : Blocks.GOLD_BLOCK.getDefaultState(); - showCorners(player, claim, hide, block); - if(!claim.isChild){ - block = hide ? null : Blocks.DIAMOND_BLOCK.getDefaultState(); - for(Claim subzone : claim.children){ - showCorners(player, subzone, hide, block); - } - } +// private static int sendPage(ServerCommandSource source, Text[] text, int page, String title, String command) { +// int prevPage = page - 2; +// int thisPage = page - 1; +// int nextPage = page + 1; +// final String SEPARATOR = "-----------------------------------------------------"; +// Text header = new LiteralText("") +// .append(new LiteralText("- [ ").formatted(Formatting.GRAY)) +// .append(new LiteralText(title).formatted(Formatting.GOLD)) +// .append(" ] ") +// .append(SEPARATOR.substring(ChatColor.removeAlternateColorCodes('&', title).length() + 4)) +// .formatted(Formatting.GRAY); +// +// Text button_prev = new LiteralText("") +// .append(new LiteralText("<-").formatted(Formatting.WHITE, Formatting.BOLD)) +// .append(" ").append(new LiteralText("Prev").formatted(Formatting.GOLD)) +// .styled((style) -> { +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); +// if (prevPage >= 0) +// style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); +// }); +// +// Text button_next = new LiteralText("") +// .append(new LiteralText("Next").formatted(Formatting.GOLD)) +// .append(" ").append(new LiteralText("->").formatted(Formatting.WHITE, Formatting.BOLD)).append(" ") +// .styled((style) -> { +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); +// if (nextPage <= text.length) +// style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); +// }); +// +// Text buttons = new LiteralText("") +// .append(new LiteralText("[ ").formatted(Formatting.GRAY)) +// .append(button_prev) +// .append(" ") +// .append( +// new LiteralText(String.valueOf(page)).formatted(Formatting.GREEN) +// .append(new LiteralText("/").formatted(Formatting.GRAY)) +// .append(new LiteralText(String.valueOf(text.length)).formatted(Formatting.GREEN)) +// ) +// .append(" ") +// .append(button_next) +// .append(new LiteralText("] ").formatted(Formatting.GRAY)); +// +// Text footer = new LiteralText("- ") +// .formatted(Formatting.GRAY) +// .append(buttons).append(new LiteralText(" ------------------------------").formatted(Formatting.GRAY)); +// +// header.append("\n").append(text[thisPage]).append("\n").append(footer); +// source.sendFeedback(header, false); +// return 1; +// } - } +// private static void createExceptionCommand(LiteralArgumentBuilder command, boolean admin) { +// { +// LiteralArgumentBuilder settings = literal("settings"); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// +// if (!admin) { +// settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); +// +// claim.executes((context) -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (claim1 == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// return querySettings(context.getSource(), claim1); +// }); +// } +// +// RequiredArgumentBuilder id = argument("setting", word()).suggests(SETTINGS_PROVIDER); +// RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); +// +// id.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), getString(context, "claim"), true, false, admin)); +// set.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); +// +// id.then(set); +// claim.then(id); +// settings.then(claim); +// command.then(settings); +// } +// +// LiteralArgumentBuilder exceptions = literal("permissions"); +// if (admin) exceptions.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_PERMISSIONS, 2)); +// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); +// if (!admin) { +// exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); +// +// claim.executes((context) -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (claim1 == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// return showTrustedList(context, claim1, false); +// }); +// } +// +// if (!admin) { +// claim.executes((context) -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (claim1 == null) { +// context.getSource().sendError(new LiteralText("That claim does not exist")); +// return -1; +// } +// return showTrustedList(context, claim1, true); +// }); +// } +// +// { +// RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); +// LiteralArgumentBuilder remove = literal("remove"); +// remove.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { +// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); +// claim1.permissionManager.resetPermissions(player1.getGameProfile().getId()); +// context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + " no longer has an exception in the claim").formatted(Formatting.YELLOW), false); +// } +// return 0; +// }); +// player.then(remove); +// LiteralArgumentBuilder all = literal("*"); +// RequiredArgumentBuilder allstate = argument("allow", BoolArgumentType.bool()); +// allstate.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); +// validateClaim(claim1); +// return setTrust(context, claim1, player1.getGameProfile(), BoolArgumentType.getBool(context, "allow"), admin); +// }); +// all.then(allstate); +// player.then(all); +// for (Claim.Permission value : Claim.Permission.values()) { +// LiteralArgumentBuilder permNode = literal(value.id); +// RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); +// allow.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { +// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); +// boolean permission = BoolArgumentType.getBool(context, "allow"); +// modifyException(claim1, player1, value, permission); +// context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has the permission " + value.name).formatted(Formatting.YELLOW), false); +// } +// return 0; +// }); +// permNode.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { +// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); +// boolean permission = hasPermission(claim1, player1, value); +// context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); +// } +// return 0; +// }); +// permNode.then(allow); +// player.then(permNode); +// } +// claim.then(player); +// } +// { +// LiteralArgumentBuilder message = literal("message"); +// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); +// RequiredArgumentBuilder messageEvent = argument("messageEvent", word()) +// .suggests(MESSAGE_EVENTS_PROVIDER); +// RequiredArgumentBuilder messageArgument = argument("message", greedyString()) +// .suggests(EVENT_MESSAGE_PROVIDER); +// +// messageArgument.executes(context -> { +// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); +// if (verifyPermission(claim1, Claim.Permission.MODIFY_PROPERTIES, context, admin)) { +// Claim.Event event = Claim.Event.getById(getString(context, "messageEvent")); +// +// if (event == null) { +// context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); +// return -1; +// } +// +// return setEventMessage(context.getSource(), claim1, event, getString(context, "message")); +// } +// +// return -1; +// }); +// +// messageEvent.then(messageArgument); +// claimArgument.then(messageEvent); +// message.then(claimArgument); +// command.then(message); +// } +// +// +// exceptions.then(claim); +// command.then(exceptions); +// } +// private static boolean verifyPermission(Claim claim, Claim.Permission permission, CommandContext context, boolean admin) throws CommandSyntaxException { +// if (verifyExists(claim, context)) { +// if (claim.permissionManager.hasPermission(context.getSource().getPlayer().getGameProfile().getId(), permission)) { +// return true; +// } else { +// context.getSource().sendFeedback(new LiteralText(admin ? "You are modifying a claim using admin privileges" : "You cannot modify exceptions for this claim").formatted(admin ? Formatting.DARK_RED : Formatting.RED), false); +// return admin; +// } +// } else { +// return false; +// } +// } +// private static boolean verifyExists(Claim claim, CommandContext context) { +// if (claim == null) { +// context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return false; +// } else { +// return true; +// } +// } - private static void showCorners(ServerPlayerEntity player, Claim claim, boolean hide, BlockState state){ - state = hide ? null : state; - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); +// private static int makeRentable(ServerCommandSource source, Claim claim, ItemStack item, int amount, String rentString, String maxrentString) throws CommandSyntaxException { +// int rentTime = TimeUtil.convertStringtoSeconds(rentString); +// int maxrentTime = TimeUtil.convertStringtoSeconds(maxrentString); +// if(claim != null){ +// if(rentTime <= maxrentTime){ +// Claim.Rent rent = claim.rent; +// rent.setRentable(true); +// item.setCount(amount); +// rent.setCurrency(item); +// rent.setRentAbleTime(rentTime); +// if(maxrentTime > Config.rent_maxseconds) maxrentTime = Config.rent_maxseconds; +// rent.setMaxrentAbleTime(maxrentTime); +// source.sendFeedback(new LiteralText("Claim " + claim.name + " can now be rented for " + amount + " " + item.getName().asString() + " every " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); +// return 1; +// } +// } +// return 0; +// } - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().south(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().east(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().south(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().north(), state); +// private static int rent(ServerCommandSource source, Claim claim, String rentString) throws CommandSyntaxException { +// if(claim == null){ +// source.sendFeedback(Messages.INVALID_CLAIM, true); +// return 0; +// } +// int rentTime = (int) TimeUtil.convertStringtoSeconds(rentString); +// int rentAbleTime = claim.rent.getRentAbleTime(); +// int maxrentAbleTime = claim.rent.getMaxrentAbleTime(); +// ItemStack currency = claim.rent.getCurrency(); +// ItemStack handItem = source.getPlayer().inventory.getMainHandStack(); +// ItemStack revenue = handItem.copy(); +// if(rentTime % claim.rent.getRentAbleTime() != 0){ +// source.sendFeedback(new LiteralText("You have to rent this claim for a time by a multiple of " + TimeUtil.convertSecondsToString(rentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); +// return 0; +// } +// int rentAmount = rentTime / claim.rent.getRentAbleTime(); +// if(currency.getItem() != handItem.getItem() || handItem.getCount() < claim.rent.getAmount() * rentAmount){ +// source.sendFeedback(new LiteralText("You don't have enough " + currency.getName().asString()).formatted(Formatting.RED), true); +// return 0; +// } +// if (!claim.rent.isRentable()) { +// source.sendFeedback(new LiteralText(claim.name + " is not for rent").formatted(Formatting.RED), true); +// return 0; +// } +// if (rentTime > claim.rent.getMaxrentAbleTime()) { +// source.sendFeedback(new LiteralText("You can't rent this claim for longer than " + TimeUtil.convertSecondsToString(maxrentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); +// return 0; +// } +// if(claim.rent.getTenant() == null){ +// //Setup for claim rent +// claim.rent.setTenant(source.getPlayer().getUuid()); +// claim.rent.setRentedUntil(claim.rent.getUnixTime() + rentTime); +// //Remove items from player +// handItem.setCount(handItem.getCount() - claim.rent.getAmount() * rentAmount); +// revenue.setCount(claim.rent.getAmount() * rentAmount); +// claim.rent.addRevenue(revenue); +// //Give Permissions to Tenant +// claim.permissionManager.playerPermissions.put(source.getPlayer().getUuid(), new Claim.InvertedPermissionMap()); +// source.sendFeedback(new LiteralText("Renting " + claim.name + " for " + claim.rent.getAmount() * rentAmount + " " + claim.rent.getCurrency().getName().asString() + " for " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); +// return 1; +// } else if(claim.rent.getTenant().toString().equalsIgnoreCase(source.getPlayer().getUuid().toString())){ +// if (claim.rent.getRentTimeLeft() + rentTime <= maxrentAbleTime) { +// //Setup for claim rent +// claim.rent.setRentedUntil(claim.rent.getUnixTime() + rentTime + claim.rent.getRentTimeLeft()); +// //Remove items from player +// handItem.setCount(handItem.getCount() - claim.rent.getAmount() * rentAmount); +// +// revenue.setCount(claim.rent.getAmount() * rentAmount); +// claim.rent.addRevenue(revenue); +// //Give Permissions to Tenant +// source.sendFeedback(new LiteralText("Extended rent " + claim.name + " by " + TimeUtil.convertSecondsToString(rentTime, '2', 'a') + "for " + claim.rent.getAmount() * rentAmount + " " + claim.rent.getCurrency().getName().asString()).formatted(Formatting.GREEN), true); +// return 1; +// } else { +// source.sendFeedback(new LiteralText("Rent would exceed the limit by " + TimeUtil.convertSecondsToString(claim.rent.getRentTimeLeft() + rentTime - maxrentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); +// return 0; +// } +// } else { +// source.sendFeedback(new LiteralText("This claim is already rented").formatted(Formatting.RED), true); +// return 0; +// } +// } - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().east(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().north(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down().west(), state); - sendBlockPacket(player, new BlockPos(Functions.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down().west(), state); - } - private static void sendBlockPacket(ServerPlayerEntity player, BlockPos pos, BlockState state) { - BlockUpdateS2CPacket packet = new BlockUpdateS2CPacket(player.world, pos); - if (state != null) ((BlockUpdatePacketMixin)packet).setState(state); - player.networkHandler.sendPacket(packet); - } - private static int createClaim(String name, ServerCommandSource owner, BlockPos posA, BlockPos posB, boolean admin, @Nullable String cOwnerName) throws CommandSyntaxException { - if (name.length() > MAX_NAME_LENGTH) { - owner.sendError(Messages.MSG_LONG_NAME); - return -1; - } - UUID ownerID = owner.getPlayer().getGameProfile().getId(); - int x, y = 0, z, mx, my = 255, mz; - if (posA.getX() > posB.getX()) { - x = posB.getX(); - mx = posA.getX(); - } else { - x = posA.getX(); - mx = posB.getX(); - } - if (!Config.claims2d) { - if (posA.getY() > posB.getY()) { - y = posB.getY(); - my = posA.getY(); - } else { - y = posA.getY(); - my = posB.getY(); - } - } - if (posA.getZ() > posB.getZ()) { - z = posB.getZ(); - mz = posA.getZ(); - } else { - z = posA.getZ(); - mz = posB.getZ(); - } - BlockPos min = new BlockPos(x, y, z); - BlockPos max = new BlockPos(mx, my, mz); - BlockPos sub = max.subtract(min); - sub = sub.add(1, Config.claims2d ? 0 : 1,1); - int subInt = sub.getX() * (Config.claims2d ? 1 : sub.getY()) * sub.getZ(); - Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos(), false); - if (cOwnerName != null) claim.customOwnerName = cOwnerName; - claim.permissionManager.playerPermissions.put(ownerID, new Claim.InvertedPermissionMap()); - if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { - if (!ClaimManager.INSTANCE.wouldIntersect(claim)) { - // works because only the first statement is evaluated if true - if ((admin && ItsMine.permissions().hasPermission(owner, Permissions.Command.INFINITE_BLOCKS, 2)) || ClaimManager.INSTANCE.useClaimBlocks(ownerID, subInt)) { - ClaimManager.INSTANCE.addClaim(claim); - owner.sendFeedback(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)).append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").setStyle(new Style() - .setColor(Formatting.GREEN).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))))), false); - checkPlayer(owner, owner.getPlayer().getGameProfile().getId()); - showClaim(owner, claim, false); - if (admin) - owner.getMinecraftServer().sendMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); - return 1; - } else { - owner.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + subInt + "(" + (subInt - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); - } - } else { - owner.sendFeedback(new LiteralText("Your claim would overlap with another claim").formatted(Formatting.RED), false); - } - } else { - owner.sendFeedback(new LiteralText("The name \"" + name + "\" is already taken.").formatted(Formatting.RED), false); - } - return 0; - } - private static int checkPlayer(ServerCommandSource ret, UUID player) throws CommandSyntaxException { - int blocks = ClaimManager.INSTANCE.getClaimBlocks(player); - ret.sendFeedback(new LiteralText((ret.getPlayer().getGameProfile().getId().equals(player) ? "You have " : "They have ") + blocks + " blocks left").setStyle(new Style() - .setColor(Formatting.YELLOW)), false); - return 0; - } - private static int requestDelete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { - if (claim == null) { - sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { - if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { - sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); - } else { - sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); - return 0; - } - } - sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to delete the claim \"" + claim.name + "\"? ").formatted(Formatting.GOLD)) - .append(new LiteralText("[I'M SURE]").setStyle(new Style() - .setColor(Formatting.DARK_RED) - .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")))), false); - return 0; - } - private static int delete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { - if (claim == null) { - sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { - if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { - sender.sendFeedback(new LiteralText("Deleting a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); - } else { - sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); - return 0; - } - } - if(!claim.isChild){ - ClaimManager.INSTANCE.releaseBlocksToOwner(claim); - ClaimManager.INSTANCE.claimsByName.remove(claim.name); - for(Claim subzone : claim.children){ - ClaimManager.INSTANCE.claimsByName.remove(subzone.name); - } - }else{ - claim.getParentClaim(claim).removeSubzone(claim); - ClaimManager.INSTANCE.claimsByName.remove(claim.name); - } - sender.getWorld().getPlayers().forEach(playerEntity -> { - if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true); - }); - sender.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)); - return 0; - } +// public static int showClaim(ServerCommandSource source, Claim claim, boolean reset) throws CommandSyntaxException { +// ServerPlayerEntity player = source.getPlayer(); +// if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!Config.claims2d &&((ClaimShower)player).getShownClaim() != claim)) showClaim(source, ((ClaimShower)player).getShownClaim(), true); +// if (reset && ((ClaimShower)player).getShownClaim() != null) claim = ((ClaimShower)player).getShownClaim(); +// if (claim != null) { +// if (!claim.dimension.equals(source.getWorld().getDimension().getType())) { +// if (claim == ((ClaimShower)player).getShownClaim()) ((ClaimShower)player).setShownClaim(null); // just so we dont have extra packets on this +// source.sendFeedback(new LiteralText("That claim is not in this dimension").formatted(Formatting.RED), false); +// return 0; +// } +// source.sendFeedback(new LiteralText((!reset ? "Showing" : "Hiding") + " claim: " + claim.name).formatted(Formatting.GREEN), false); +// if(claim.isChild) silentHideShow(player, ClaimUtil.getParentClaim(claim), reset, true); +// else silentHideShow(player, claim, reset, true); +// +// } else { +// source.sendFeedback(new LiteralText("That is not a valid claim").formatted(Formatting.RED), false); +// } +// return 0; +// } +// private static int createClaim(String name, ServerCommandSource owner, BlockPos posA, BlockPos posB, boolean admin, @Nullable String cOwnerName) throws CommandSyntaxException { +// if (name.length() > MAX_NAME_LENGTH) { +// owner.sendError(Messages.MSG_LONG_NAME); +// return -1; +// } +// if(!name.matches("[A-Za-z0-9]+")){ +// owner.sendError(new LiteralText("Invalid claim name")); +// return -1; +// } +// UUID ownerID = owner.getPlayer().getGameProfile().getId(); +// int x, y = 0, z, mx, my = 255, mz; +// if (posA.getX() > posB.getX()) { +// x = posB.getX(); +// mx = posA.getX(); +// } else { +// x = posA.getX(); +// mx = posB.getX(); +// } +// if (!Config.claims2d) { +// if (posA.getY() > posB.getY()) { +// y = posB.getY(); +// my = posA.getY(); +// } else { +// y = posA.getY(); +// my = posB.getY(); +// } +// } +// if (posA.getZ() > posB.getZ()) { +// z = posB.getZ(); +// mz = posA.getZ(); +// } else { +// z = posA.getZ(); +// mz = posB.getZ(); +// } +// BlockPos min = new BlockPos(x, y, z); +// BlockPos max = new BlockPos(mx, my, mz); +// BlockPos sub = max.subtract(min); +// sub = sub.add(1, Config.claims2d ? 0 : 1,1); +// int subInt = sub.getX() * (Config.claims2d ? 1 : sub.getY()) * sub.getZ(); +// +// Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos(), false); +// if (cOwnerName != null) claim.customOwnerName = cOwnerName; +// claim.permissionManager.playerPermissions.put(ownerID, new Claim.InvertedPermissionMap()); +// if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { +// if (!ClaimManager.INSTANCE.wouldIntersect(claim)) { +// // works because only the first statement is evaluated if true +// if ((admin && ItsMine.permissions().hasPermission(owner, PermissionUtil.Command.INFINITE_BLOCKS, 2)) || ClaimManager.INSTANCE.useClaimBlocks(ownerID, subInt)) { +// ClaimManager.INSTANCE.addClaim(claim); +// owner.sendFeedback(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)).append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").setStyle(new Style() +// .setColor(Formatting.GREEN).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))))), false); +// checkPlayer(owner, owner.getPlayer().getGameProfile().getId()); +// showClaim(owner, claim, false); +// if (admin) +// owner.getMinecraftServer().sendMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); +// return 1; +// } else { +// owner.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + subInt + "(" + (subInt - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); +// } +// } else { +// owner.sendFeedback(new LiteralText("Your claim would overlap with another claim").formatted(Formatting.RED), false); +// } +// } else { +// owner.sendFeedback(new LiteralText("The name \"" + name + "\" is already taken.").formatted(Formatting.RED), false); +// } +// return 0; +// } +// private static int checkPlayer(ServerCommandSource ret, UUID player) throws CommandSyntaxException { +// int blocks = ClaimManager.INSTANCE.getClaimBlocks(player); +// ret.sendFeedback(new LiteralText((ret.getPlayer().getGameProfile().getId().equals(player) ? "You have " : "They have ") + blocks + " blocks left").setStyle(new Style() +// .setColor(Formatting.YELLOW)), false); +// return 0; +// } +// private static int requestDelete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { +// if (claim == null) { +// sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return 0; +// } +// if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { +// if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { +// sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); +// } else { +// sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); +// return 0; +// } +// } +// sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to delete the claim \"" + claim.name + "\"? ").formatted(Formatting.GOLD)) +// .append(new LiteralText("[I'M SURE]").setStyle(new Style() +// .setColor(Formatting.DARK_RED) +// .setBold(true) +// .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")))), false); +// return 0; +// } +// private static int delete(ServerCommandSource source, Claim claim, boolean admin) throws CommandSyntaxException { +// ServerWorld world = source.getWorld(); +// if (claim == null) { +// source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return 0; +// } +// if (!claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { +// if (admin && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)) { +// source.sendFeedback(new LiteralText("Deleting a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); +// } else { +// source.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); +// return 0; +// } +// } +// if(!claim.isChild){ +// ClaimManager.INSTANCE.releaseBlocksToOwner(claim); +// ShowerUtil.update(claim, world, true); +// ClaimManager.INSTANCE.claimsByName.remove(claim.name); +// for(Claim subzone : claim.children){ +// ClaimManager.INSTANCE.claimsByName.remove(subzone.name); +// } +// }else{ +// Claim parent = ClaimUtil.getParentClaim(claim); +// ShowerUtil.update(parent, world, true); +// ClaimUtil.getParentClaim(claim).removeSubzone(claim); +// ClaimManager.INSTANCE.claimsByName.remove(claim.name); +// ShowerUtil.update(parent, world, false); +// } +// source.getWorld().getPlayers().forEach(playerEntity -> { +// if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true); +// }); +// source.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)); +// return 0; +// } - private static int requestTransfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { - if (claim == null) { - sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { - if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { - sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); - } else { - sender.sendFeedback(new LiteralText("You cannot transfer ownership that claim").formatted(Formatting.RED), false); - return 0; - } - } - sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to transfer ownership of \"" + claim.name + "\" to " + player.getGameProfile().getName() + "? ").formatted(Formatting.GOLD)) - .append(new LiteralText("[YES]").setStyle(new Style() - .setColor(Formatting.DARK_RED) - .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")))), false); - return 0; - } - private static Map pendingClaimTransfers = new HashMap<>(); - private static int transfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { - if (claim == null) { - sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { - if (admin && ItsMine.permissions().hasPermission(sender, Permissions.Command.ADMIN_MODIFY, 2)) { - sender.sendFeedback(new LiteralText("Transfering ownership of a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); - } else { - sender.sendFeedback(new LiteralText("You cannot transfer ownership that claim").formatted(Formatting.RED), false); - return 0; - } - } - GameProfile profile = sender.getWorld().getServer().getUserCache().getByUuid(claim.claimBlockOwner); - sender.sendFeedback(new LiteralText("Transferring ownership of the claim \"" + claim.name + "\" to " + player.getGameProfile().getName() + " if they accept").formatted(Formatting.GREEN), claim.claimBlockOwner != player.getGameProfile().getId()); - player.sendMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) - .append(new LiteralText("[ACCEPT]").setStyle(new Style() - .setColor(Formatting.GREEN) - .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim transfer -accept-" + claim.name + " " + player.getEntityName() + " confirm"))))); - pendingClaimTransfers.put(player.getGameProfile().getId(), claim.name); - return 0; - } - public static int acceptTransfer(ServerCommandSource sender) throws CommandSyntaxException { - Claim claim = ClaimManager.INSTANCE.claimsByName.get(pendingClaimTransfers.get(sender.getPlayer().getGameProfile().getId())); - if (claim == null) { - sender.sendFeedback(new LiteralText("You have no pending claim transfers").formatted(Formatting.RED), false); - return 0; - } - if (sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner) != null) { - sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); - } - Claim.ClaimPermissionMap op = claim.permissionManager.playerPermissions.get(claim.claimBlockOwner); - claim.permissionManager.playerPermissions.put(claim.claimBlockOwner, claim.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); - claim.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op); - claim.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); - return 0; - } - private static int modifyException(Claim claim, ServerPlayerEntity exception, Claim.Permission permission, boolean allowed) { - claim.permissionManager.setPermission(exception.getGameProfile().getId(), permission, allowed); - return 0; - } - private static int modifyException(Claim claim, String exception, Claim.Permission permission, boolean allowed) { - claim.permissionManager.setPermission(exception, permission, allowed); - return 0; - } - private static boolean hasPermission(Claim claim, ServerPlayerEntity exception, Claim.Permission permission) { - return claim.permissionManager.hasPermission(exception.getGameProfile().getId(), permission); - } +// private static int requestTransfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { +// if (claim == null) { +// sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return 0; +// } +// if(claim.isChild){ +// sender.sendFeedback(new LiteralText("You can't transfer ownership of subzones").formatted(Formatting.RED), false); +// return 0; +// } +// if(sender.getPlayer().getUuidAsString().equalsIgnoreCase(player.getUuidAsString())){ +// sender.sendFeedback(new LiteralText("Huh? That makes no sence").formatted(Formatting.RED), true); +// return 0; +// } +// if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { +// if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { +// sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); +// } else { +// sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); +// return 0; +// } +// } +// sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to transfer ownership of \"" + claim.name + "\" to " + player.getGameProfile().getName() + "? ").formatted(Formatting.GOLD)) +// .append(new LiteralText("[YES]").setStyle(new Style() +// .setColor(Formatting.DARK_RED) +// .setBold(true) +// .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")))), false); +// return 0; +// } +// private static Map pendingClaimTransfers = new HashMap<>(); +// private static int transfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { +// if (claim == null) { +// sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return 0; +// } +// if(claim.isChild){ +// sender.sendFeedback(new LiteralText("You can't transfer ownership of subzones").formatted(Formatting.RED), false); +// return 0; +// } +// if(sender.getPlayer().getUuidAsString().equalsIgnoreCase(player.getUuidAsString())){ +// sender.sendFeedback(new LiteralText("Huh? That makes no sence").formatted(Formatting.RED), true); +// return 0; +// } +// if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { +// if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { +// sender.sendFeedback(new LiteralText("Transfering ownership of a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); +// } else { +// sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); +// return 0; +// } +// } +// +// GameProfile profile = sender.getWorld().getServer().getUserCache().getByUuid(claim.claimBlockOwner); +// sender.sendFeedback(new LiteralText("Transferring ownership of the claim \"" + claim.name + "\" to " + player.getGameProfile().getName() + " if they accept").formatted(Formatting.GREEN), claim.claimBlockOwner != player.getGameProfile().getId()); +// player.sendMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) +// .append(new LiteralText("[ACCEPT]").setStyle(new Style() +// .setColor(Formatting.GREEN) +// .setBold(true) +// .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim transfer -accept-" + claim.name + " " + player.getEntityName() + " confirm"))))); +// pendingClaimTransfers.put(player.getGameProfile().getId(), claim.name); +// return 0; +// } +// public static int acceptTransfer(ServerCommandSource sender) throws CommandSyntaxException { +// Claim claim = ClaimManager.INSTANCE.claimsByName.get(pendingClaimTransfers.get(sender.getPlayer().getGameProfile().getId())); +// if (claim == null) { +// sender.sendFeedback(new LiteralText("You have no pending claim transfers").formatted(Formatting.RED), false); +// return 0; +// } +// if (sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner) != null) { +// sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); +// } +// Claim.ClaimPermissionMap op = claim.permissionManager.playerPermissions.get(claim.claimBlockOwner); +// claim.permissionManager.playerPermissions.put(claim.claimBlockOwner, claim.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); +// claim.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op); +// claim.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); +// claim.children.forEach(subzone -> { +// try { +// Claim.ClaimPermissionMap op1 = subzone.permissionManager.playerPermissions.get(subzone.claimBlockOwner); +// subzone.permissionManager.playerPermissions.put(subzone.claimBlockOwner, subzone.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); +// subzone.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op1); +// subzone.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); +// } catch (CommandSyntaxException e) { +// e.printStackTrace(); +// } +// }); +// return 0; +// } +// private static int modifyException(Claim claim, ServerPlayerEntity exception, Claim.Permission permission, boolean allowed) { +// claim.permissionManager.setPermission(exception.getGameProfile().getId(), permission, allowed); +// return 0; +// } +// private static int modifyException(Claim claim, String exception, Claim.Permission permission, boolean allowed) { +// claim.permissionManager.setPermission(exception, permission, allowed); +// return 0; +// } +// private static boolean hasPermission(Claim claim, ServerPlayerEntity exception, Claim.Permission permission) { +// return claim.permissionManager.hasPermission(exception.getGameProfile().getId(), permission); +// } // private static boolean hasPermission(Claim claim, String exception, Claim.Permission permission) { // return claim.permissionManager.hasPermission(exception, permission); // } - private static Direction directionByName(String name) { - for (Direction direction : Direction.values()) { - if (name.equals(direction.getName())) return direction; - } - return null; - } - private static int expand(Claim claim, int amount, Direction direction, ServerCommandSource source, boolean admin) throws CommandSyntaxException { - UUID ownerID = source.getPlayer().getGameProfile().getId(); - if (claim == null) { - source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - if (direction == null) { - source.sendFeedback(new LiteralText("That is not a valid direction").formatted(Formatting.RED), false); - return 0; - } - if (!claim.permissionManager.hasPermission(ownerID, Claim.Permission.MODIFY_SIZE)) { - source.sendFeedback(new LiteralText("You do not have border change permissions in that claim").formatted(Formatting.RED), false); - if (!admin) return 0; - } - int oldArea = claim.getArea(); - if (amount > 0) claim.expand(direction, amount); - else { - if (!claim.shrink(direction, amount)) { - source.sendFeedback(new LiteralText("You can't shrink your claim that far. It would pass its opposite wall.").formatted(Formatting.RED), false); - return 0; - } - } - if (ClaimManager.INSTANCE.wouldIntersect(claim)) { - if (amount < 0) claim.expand(direction, amount); - else claim.shrink(direction, amount); - source.sendFeedback(new LiteralText("Expansion would result in hitting another claim").formatted(Formatting.RED), false); - return 0; - } - int newArea = claim.getArea() - oldArea; - if (!admin && claim.claimBlockOwner != null && ClaimManager.INSTANCE.getClaimBlocks(ownerID) < newArea) { - if (amount < 0) claim.expand(direction, amount); - else claim.shrink(direction, amount); - source.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + newArea + "(" + (newArea - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); - checkPlayer(source, ownerID); - return 0; - } else { - if (!admin && claim.claimBlockOwner != null) ClaimManager.INSTANCE.useClaimBlocks(ownerID, newArea); - source.sendFeedback(new LiteralText("Your claim was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); - checkPlayer(source, ownerID); - if (amount < 0) claim.expand(direction, amount); - else claim.shrink(direction, amount); - source.getWorld().getPlayers().forEach(playerEntity -> { - if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, false); - }); - if (amount > 0) claim.expand(direction, amount); - else claim.shrink(direction, -amount); - source.getWorld().getPlayers().forEach(playerEntity -> { - if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, false, false); - }); - } - return 0; - } - private static int info(ServerCommandSource source, Claim claim) { - if (claim == null) { - source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); - return 0; - } - - GameProfile owner = claim.claimBlockOwner == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); - BlockPos size = claim.getSize(); - - Text text = new LiteralText("\n"); - text.append(new LiteralText("Claim Info: " + claim.name).formatted(Formatting.GOLD)).append("\n"); - text.append(newInfoLine("Name", new LiteralText(claim.name).formatted(Formatting.WHITE))); - text.append(newInfoLine("Owner", - owner != null && claim.customOwnerName == null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : - claim.customOwnerName != null ? new LiteralText(claim.customOwnerName).formatted(Formatting.GOLD) : - new LiteralText("No Owner").formatted(Formatting.RED, Formatting.ITALIC))); - text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); - - - text.append(new LiteralText("").append(new LiteralText("* Settings:").formatted(Formatting.YELLOW)) - .append(Messages.Command.getSettings(claim)).append("\n")); - Text pos = new LiteralText(""); - Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); - Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); - - if (PERMISSION_CHECK_ADMIN.test(source)) { - String format = "/execute in " + Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").toString() + " run tp " + source.getName() + (Config.claims2d ? " %s ~ %s" : " %s %s %s"); - min.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, - String.format(format, claim.min.getX(), Config.claims2d ? claim.min.getZ() : claim.min.getY(), claim.min.getZ())))); - max.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, - String.format(format, claim.max.getX(), Config.claims2d ? claim.max.getZ() : claim.max.getY(), claim.max.getZ())))); - } - - pos.append(newInfoLine("Position", new LiteralText("") - .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) - .append(" ") - .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); - text.append(pos); - text.append(newInfoLine("Dimension", new LiteralText(Registry.DIMENSION_TYPE.getId(claim.dimension).getPath()))); - source.sendFeedback(text, false); - return 1; - } - private static Text newPosLine(BlockPos pos, Formatting form1, Formatting form2) { - return new LiteralText("") - .append(new LiteralText(String.valueOf(pos.getX())).formatted(form1)) - .append(" ") - .append(new LiteralText(String.valueOf(pos.getY())).formatted(form2)) - .append(" ") - .append(new LiteralText(String.valueOf(pos.getZ())).formatted(form1)); - } - private static Text newInfoLine(String title, Text text) { - return new LiteralText("").append(new LiteralText("* " + title + ": ").formatted(Formatting.YELLOW)) - .append(text).append("\n"); - } - - private static ArrayList getClaims(){ - ArrayList claims = new ArrayList<>(); - ClaimManager.INSTANCE.claimsByName.forEach((s, claim) -> { - claims.add(claim); - }); - return claims; - } - - private static int listall(ServerCommandSource source){ - List claims = getClaims(); - Text text = new LiteralText("\n").append(new LiteralText("Claims").formatted(Formatting.GOLD)).append("\n "); - for (Claim claim : claims) { - Text cText = new LiteralText(claim.name).formatted(Formatting.GOLD); - text.append(cText.append(" ")); - } - source.sendFeedback(text.append("\n"), false); - return 1; - } - - private static int list(ServerCommandSource source, String target) throws CommandSyntaxException { - ServerPlayerEntity player = source.getPlayer(); - GameProfile profile = target == null ? player.getGameProfile() : source.getMinecraftServer().getUserCache().findByName(target); - - if (profile == null) { - source.sendError(Messages.INVALID_PLAYER); - return -1; - } - - List claims = ClaimManager.INSTANCE.getPlayerClaims(profile.getId()); - if (claims.isEmpty()) { - source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); - return -1; - } - - - Text text = new LiteralText("\n").append(new LiteralText("Claims (" + target + "): ").formatted(Formatting.GOLD)).append("\n "); - boolean nextColor = false; - for (Claim claim : claims) { - if(!claim.isChild) { - Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { - Text hoverText = new LiteralText("Click for more Info").formatted(Formatting.GREEN); - if (claim.children.size() > 0) { - hoverText.append("\n\nSubzones:"); - for (Claim subzone : claim.children) { - hoverText.append("\n- " + subzone.name); - } - } - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); - - style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); - }); - - nextColor = !nextColor; - text.append(cText.append(" ")); - } - } - - source.sendFeedback(text.append("\n"), false); - return 1; - } - private static int listAll(ServerCommandSource source, int page) { - List claims = new ArrayList<>(); - ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> claims.add(claim)); - - if (claims.isEmpty()) { - source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); - return -1; - } - - List list = new ArrayList<>(claims.size() / 10); - - for (int i = 0; i < claims.size(); i++) { - Claim claim = claims.get(i); - - Text cText = new LiteralText("").append(new LiteralText(i + ". ").formatted(Formatting.GOLD)) - .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" in ").formatted(Formatting.GRAY)) - .append(new LiteralText(Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").getPath()).formatted(Formatting.WHITE)); - - cText.styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click for more Info").formatted(Formatting.GREEN))); - style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); - }); - - list.add(cText.append("\n")); - } - - Text[] texts = new Text[]{}; - texts = list.toArray(texts); - return sendPage(source, texts, page, "Claims", "/claim listall %page%"); - } - private static int rename(CommandContext context, boolean admin) throws CommandSyntaxException { - String name = StringArgumentType.getString(context, "claim"); - String newName = StringArgumentType.getString(context, "name"); - Claim claimToRename = ClaimManager.INSTANCE.claimsByName.get(name); - if (claimToRename == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - if (ClaimManager.INSTANCE.claimsByName.containsKey(newName)) { - context.getSource().sendError(new LiteralText("That name is already taken!")); - return -1; - } - if (!admin && !claimToRename.hasPermission(context.getSource().getPlayer().getUuid(), Claim.Permission.MODIFY_PROPERTIES)) { - context.getSource().sendError(new LiteralText("You don't have permission to modify claim properties!")); - return -1; - } - ClaimManager.INSTANCE.claimsByName.remove(name); - claimToRename.name = newName; - ClaimManager.INSTANCE.addClaim(claimToRename); - claimToRename.name = newName; - context.getSource().sendFeedback(new LiteralText("Renamed Claim " + name + " to " + newName).formatted(Formatting.GOLD), admin); - return -1; - } - private static int showTrustedList(CommandContext context, Claim claim, boolean showSelf) throws CommandSyntaxException { - ServerCommandSource source = context.getSource(); - ServerPlayerEntity player = source.getPlayer(); - int mapSize = claim.permissionManager.playerPermissions.size(); - - if (mapSize == 1 && !showSelf) { - source.sendError(new LiteralText(claim.name + " is not trusting anyone!")); - return -1; - } - - Text text = new LiteralText("\n"); - text.append(new LiteralText("Trusted players for Claim ").formatted(Formatting.YELLOW)) - .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append("\n"); - - AtomicInteger atomicInteger = new AtomicInteger(); - claim.permissionManager.playerPermissions.forEach((uuid, perm) -> { - atomicInteger.incrementAndGet(); - Text pText = new LiteralText(""); - Text owner; - GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); - if (profile != null) { - owner = new LiteralText(profile.getName()); - } else { - owner = new LiteralText(uuid.toString()).styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to Copy"))); - style.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); - }); - } - - pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) - .append(owner.formatted(Formatting.YELLOW)); - - Text hover = new LiteralText(""); - hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); - - int allowed = 0; - int i = 0; - boolean nextColor = false; - Text perms = new LiteralText(""); - - for (Claim.Permission value : Claim.Permission.values()) { - if (claim.permissionManager.hasPermission(uuid, value)) { - Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; - perms.append(new LiteralText(value.id).formatted(formatting)).append(" "); - if (i == 3) perms.append("\n"); - allowed++; - i++; - nextColor = !nextColor; - } - } - - if (allowed == Claim.Permission.values().length) { - hover.append(new LiteralText("All " + allowed + " Permissions").formatted(Formatting.YELLOW, Formatting.ITALIC)); - } else { - hover.append(perms); - } - - pText.append(new LiteralText(" ") - .append(new LiteralText("(").formatted(Formatting.GOLD)) - .append(new LiteralText(String.valueOf(allowed)).formatted(Formatting.GREEN)) - .append(new LiteralText("/").formatted(Formatting.GOLD)) - .append(new LiteralText(String.valueOf(Claim.Permission.values().length)).formatted(Formatting.YELLOW)) - .append(new LiteralText(")").formatted(Formatting.GOLD)) - ); - - pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); - text.append(pText).append("\n"); - }); - - source.sendFeedback(text, false); - return 1; - } - private static int setOwnerName(ServerCommandSource source, Claim claim, String input) { - String name = input.equals("reset") ? null : input; - source.sendFeedback(new LiteralText("Set the Custom Owner Name to ") - .formatted(Formatting.YELLOW).append(new LiteralText(name == null ? "Reset" : name).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) - .append(new LiteralText(claim.customOwnerName == null ? "Not Present" : claim.customOwnerName).formatted(Formatting.GOLD)) - .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) - , false); - claim.customOwnerName = input; - return 1; - } - private static int setOwner(ServerCommandSource source, Claim claim, GameProfile profile) { - GameProfile oldOwner = source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); - source.sendFeedback(new LiteralText("Set the Claim Owner to ") - .formatted(Formatting.YELLOW).append(new LiteralText(profile.getName()).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) - .append(new LiteralText(oldOwner == null ? "(" + claim.claimBlockOwner + ")" : oldOwner.getName()).formatted(Formatting.GOLD)) - .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) - , false); - claim.claimBlockOwner = profile.getId(); - return 1; - } - private static int setEventMessage(ServerCommandSource source, Claim claim, Claim.Event event, String message) { - switch (event) { - case ENTER_CLAIM: - claim.enterMessage = message.equalsIgnoreCase("reset") ? null : message; - break; - case LEAVE_CLAIM: - claim.leaveMessage = message.equalsIgnoreCase("reset") ? null : message; - break; - } - - if (message.equalsIgnoreCase("reset")) { - source.sendFeedback(new LiteralText("Reset ").append(new LiteralText(event.id).formatted(Formatting.GOLD) - .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) - .append(new LiteralText(claim.name).formatted(Formatting.GOLD))).formatted(Formatting.YELLOW) - , false); - return -1; - } - - source.sendFeedback(new LiteralText("Set ").append(new LiteralText(event.id).formatted(Formatting.GOLD) - .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) - .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" to:").formatted(Formatting.YELLOW))) - .append("\n").append(new LiteralText(ChatColor.translate(message))) - .formatted(Formatting.YELLOW) - , false); - return 1; - } - private static int executeSetting(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { - ServerPlayerEntity player = source.getPlayer(); - Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : - ClaimManager.INSTANCE.claimsByName.get(claimName); - if (claim1 == null) { - source.sendError(Messages.INVALID_CLAIM); - return -1; - } - - if (input == null) { - return querySettings(source, claim1); - } - - validateCanAccess(player, claim1, admin); - Claim.ClaimSettings.Setting setting = Claim.ClaimSettings.Setting.byId(input); - Claim.Permission permission = Claim.Permission.byId(input); - - if (setting != null && permission == null) - return isQuery ? querySetting(source, claim1, setting) : setSetting(source, claim1, setting, value); +// private static Direction directionByName(String name) { +// for (Direction direction : Direction.values()) { +// if (name.equals(direction.getName())) return direction; +// } +// return null; +// } - if (setting == null && permission != null) - return isQuery ? queryPermission(source, claim1, permission) : setPermission(source, claim1, permission, value); +// private static CompletableFuture itemsSuggestion(final CommandContext ctx, final SuggestionsBuilder builder) { +// List strings = new ArrayList<>(); +// Registry.ITEM.forEach((item) -> { +// strings.add(Registry.ITEM.getId(item).getPath()); +// }); +// +// return CommandSource.suggestMatching(strings, builder); +// } - source.sendError(Messages.INVALID_SETTING); - return -1; - } - private static int executePermission(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { - ServerPlayerEntity player = source.getPlayer(); - Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : - ClaimManager.INSTANCE.claimsByName.get(claimName); - if (claim1 == null) { - source.sendError(Messages.INVALID_CLAIM); - return -1; - } +// private static void undoExpand(Claim claim, Direction direction, int amount){ +// if (amount < 0) claim.expand(direction, -amount); +// else claim.shrink(direction, amount); +// } +// +// private static void sendSize(Claim claim, ServerCommandSource source){ +// Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); +// Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); +// Text pos = new LiteralText(""); +// pos.append(newInfoLine("Position", new LiteralText("") +// .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) +// .append(" ") +// .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); +// source.sendFeedback(pos, true); +// } +// +// private static int expand(Claim claim, int amount, Direction direction, ServerCommandSource source, boolean admin) throws CommandSyntaxException { +// UUID ownerID = source.getPlayer().getGameProfile().getId(); +// if (claim == null) { +// source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return 0; +// } +// if (direction == null) { +// source.sendFeedback(new LiteralText("That is not a valid direction").formatted(Formatting.RED), false); +// return 0; +// } +// if (!claim.permissionManager.hasPermission(ownerID, Claim.Permission.MODIFY_SIZE)) { +// source.sendFeedback(new LiteralText("You do not have border change permissions in that claim").formatted(Formatting.RED), false); +// if (!admin) return 0; +// } +// int oldArea = claim.getArea(); +// System.out.println("Area1 " + claim.getArea()); +// sendSize(claim, source); +// +// if (amount > 0) { +// claim.expand(direction, amount); +// } +// else { +// claim.shrink(direction, -amount); +// } +// +// System.out.println("Area2 " + claim.getArea()); +// sendSize(claim, source); +// +// if (!claim.canShrinkWithoutHittingOtherSide(new BlockPos(direction.getOffsetX() * amount, direction.getOffsetY() * amount, direction.getOffsetZ() * amount))) { +// source.sendFeedback(new LiteralText("You can't shrink your claim that far. It would pass its opposite wall.").formatted(Formatting.RED), false); +// undoExpand(claim, direction, amount); +// return 0; +// } +// +// if(!claim.isChild){ +// if (ClaimManager.INSTANCE.wouldIntersect(claim)) { +// undoExpand(claim, direction, amount); +// source.sendFeedback(new LiteralText("Expansion would result in hitting another claim").formatted(Formatting.RED), false); +// return 0; +// } +// +// //Check if shrinking would reset a subzone to be outside of its parent claim +// AtomicBoolean returnValue = new AtomicBoolean(); +// returnValue.set(false); +// claim.children.forEach(claim1 -> { +//// System.out.println("IsInside2: " + claim1.isInside(claim)); +// if(!claim1.isInside(claim)){ +// System.out.println("Area3 " + claim.getArea()); +// sendSize(claim, source); +// undoExpand(claim, direction, amount); +// System.out.println("Area4 " + claim.getArea()); +// sendSize(claim, source); +// source.sendFeedback(new LiteralText("Shrinking would result in " + claim1.name + " being outside of " + claim.name).formatted(Formatting.RED), true); +// returnValue.set(true); +// } +// }); +// if(returnValue.get()) return 0; +// +// int newArea = claim.getArea() - oldArea; +// if (!admin && claim.claimBlockOwner != null && ClaimManager.INSTANCE.getClaimBlocks(ownerID) < newArea) { +// undoExpand(claim, direction, amount); +// source.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + newArea + "(" + (newArea - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); +// checkPlayer(source, ownerID); +// return 0; +// } else { +// if (!admin && claim.claimBlockOwner != null) ClaimManager.INSTANCE.useClaimBlocks(ownerID, newArea); +// source.sendFeedback(new LiteralText("Your claim was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); +// checkPlayer(source, ownerID); +// undoExpand(claim, direction, amount); +// ShowerUtil.update(claim, source.getWorld(), true); +// if (amount > 0) claim.expand(direction, amount); +// else claim.shrink(direction, -amount); +// ShowerUtil.update(claim, source.getWorld(), false); +// } +// return 0; +// }else{ +// Claim parent = ClaimUtil.getParentClaim(claim); +// if(!claim.isInside(parent)) { +// source.sendFeedback(new LiteralText("Expansion would result in expanding outside of your main claim").formatted(Formatting.RED), false); +// undoExpand(claim, direction, amount); +// } else if(ClaimManager.INSTANCE.wouldSubzoneIntersect((claim))){ +// source.sendFeedback(new LiteralText("Expansion would result in overlapping with another subzone").formatted(Formatting.RED), false); +// undoExpand(claim, direction, amount); +// }else{ +// source.sendFeedback(new LiteralText("Your subzone was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); +// //The expansion is undone to hide the claimshower +// undoExpand(claim, direction, amount); +// ShowerUtil.update(parent, source.getWorld(), true); +// if (amount > 0) claim.expand(direction, amount); +// else claim.shrink(direction, -amount); +// ShowerUtil.update(parent, source.getWorld(), false); +// } +// } +// return 0; +// } - validateCanAccess(player, claim1, admin); - Claim.Permission permission = Claim.Permission.byId(input); - if (permission != null) - return !isQuery ? setPermission(source, claim1, permission, value) : queryPermission(source, claim1, permission); +// private static int revenue(ServerCommandSource source, Claim claim, boolean claimrevenue) throws CommandSyntaxException { +// //Show subzones (so you can just claim everything in one place) maybe just all claims +// if(claim == null){ +// source.sendFeedback(Messages.INVALID_CLAIM,true); +// return 0; +// } +// if(!claim.claimBlockOwner.toString().equalsIgnoreCase(source.getPlayer().getUuid().toString())){ +// source.sendFeedback(Messages.NO_PERMISSION, true); +// return 0; +// } +// +// if(claimrevenue){ +// for(ItemStack itemStack : claim.rent.getRevenue()){ +// source.getPlayer().inventory.insertStack(itemStack); +// } +// claim.rent.clearRevenue(); +// return 1; +// +// } else { +// if(claim.rent.getRevenue().isEmpty()){ +// source.sendFeedback(new LiteralText("No Revenue").formatted(Formatting.RED), true); +// return 0; +// } +// Text text = new LiteralText("Revenue\n").formatted(Formatting.AQUA); +// HashMap hashMap = new HashMap<>(); +// for(ItemStack itemStack : claim.rent.getRevenue()){ +// Item value = itemStack.getItem(); +// if(hashMap.containsKey(value)){ +// hashMap.put(value, hashMap.get(value) + itemStack.getCount()); +// } else { +// hashMap.put(value, + itemStack.getCount()); +// } +// +// hashMap.forEach((item, integer) -> { +// boolean color = true; +// text.append(new LiteralText(String.valueOf(integer)).append(" ").append(new TranslatableText(item.getTranslationKey())).append(" ").formatted(color ? Formatting.GOLD : Formatting.YELLOW)).styled(style -> { +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to claim revenue!").formatted(Formatting.GREEN))); +// style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim revenue " + claim.name + " true")); +// }); +// color = !color; +// }); +// +// } +// text.append("\n"); +// source.sendFeedback(text, true); +// return 1; +// } +// } - source.sendError(Messages.INVALID_SETTING); - return -1; - } - private static int querySetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting) { - boolean enabled = claim.settings.getSetting(setting); - source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); - return 1; - } - private static int setSetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting, boolean set) { - claim.settings.settings.put(setting, set); - source.sendFeedback(new LiteralText(ChatColor.translate("&eSet setting &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); - return 0; - } - private static int queryPermission(ServerCommandSource source, Claim claim, Claim.Permission permission) { - boolean defaultPerm = claim.permissionManager.defaults.hasPermission(permission); - source.sendFeedback(new LiteralText(ChatColor.translate("&ePermission &6" + permission.id + "&e is set to " + (defaultPerm ? "&a" : "&c") + defaultPerm + "&e for &6" + claim.name)), false); - return 1; - } - private static int setPermission(ServerCommandSource source, Claim claim, Claim.Permission permission, boolean set) { - claim.permissionManager.defaults.setPermission(permission, set); - source.sendFeedback(new LiteralText(ChatColor.translate("&eSet permission &6" + permission.id + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); - return 1; - } - private static int querySettings(ServerCommandSource source, Claim claim) { - source.sendFeedback(new LiteralText("\n").append(new LiteralText("Settings: " + claim.name).formatted(Formatting.YELLOW)).append("\n") - .append(Messages.Command.getSettings(claim)).append("\n"), false); - return 1; - } - private static int executeTrust(CommandContext context, Entity entity, boolean set, @Nullable String claimName) throws CommandSyntaxException { - if (!(entity instanceof PlayerEntity)) { - context.getSource().sendError(new LiteralText("Only Players!")); - return -1; - } - ServerPlayerEntity target = (ServerPlayerEntity) entity; - ServerPlayerEntity p = context.getSource().getPlayer(); - Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getBlockPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); - validateClaim(claim1); +// private static int info(ServerCommandSource source, Claim claim) throws CommandSyntaxException { +// if (claim == null) { +// source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); +// return 0; +// } +// +// GameProfile owner = claim.claimBlockOwner == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); +// BlockPos size = claim.getSize(); +// +// Text text = new LiteralText("\n"); +// text.append(new LiteralText("Claim Info: " + claim.name).formatted(Formatting.GOLD)).append("\n"); +// text.append(newInfoLine("Name", new LiteralText(claim.name).formatted(Formatting.WHITE))); +// text.append(newInfoLine("Entities", new LiteralText(String.valueOf(claim.getEntities(source.getWorld()))).formatted(Formatting.AQUA))); +// text.append(newInfoLine("Owner", +// owner != null && claim.customOwnerName == null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : +// claim.customOwnerName != null ? new LiteralText(claim.customOwnerName).formatted(Formatting.GOLD) : +// new LiteralText("No Owner").formatted(Formatting.RED, Formatting.ITALIC))); +// text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); +// +// +// text.append(new LiteralText("").append(new LiteralText("* Settings:").formatted(Formatting.YELLOW)) +// .append(Messages.Command.getSettings(claim)).append("\n")); +// Text pos = new LiteralText(""); +// Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); +// Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); +// +// +// if (PERMISSION_CHECK_ADMIN.test(source)) { +// String format = "/execute in " + Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").toString() + " run tp " + source.getName() + (Config.claims2d ? " %s ~ %s" : " %s %s %s"); +// min.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, +// String.format(format, claim.min.getX(), Config.claims2d ? claim.min.getZ() : claim.min.getY(), claim.min.getZ())))); +// max.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, +// String.format(format, claim.max.getX(), Config.claims2d ? claim.max.getZ() : claim.max.getY(), claim.max.getZ())))); +// } +// +// pos.append(newInfoLine("Position", new LiteralText("") +// .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) +// .append(" ") +// .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); +// text.append(pos); +// text.append(newInfoLine("Dimension", new LiteralText(Registry.DIMENSION_TYPE.getId(claim.dimension).getPath()))); +// if(claim.rent.isRented()){ +// GameProfile tenant = claim.rent.getTenant() == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.rent.getTenant()); +// text.append(newInfoLine("Status", new LiteralText("Rented").formatted(Formatting.RED).styled(style -> { +// java.util.Date time=new java.util.Date((long) claim.rent.getRentedUntil()*1000); +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Until", new LiteralText(time.toString()).formatted(Formatting.WHITE)).append(newInfoLine("By", new LiteralText(tenant.getName()).formatted(Formatting.WHITE))).append(newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE))))); +// }))); +// } else if (claim.rent.isRentable() && !claim.rent.isRented()){ +// text.append(newInfoLine("Status", new LiteralText("For Rent").formatted(Formatting.GREEN).styled(style -> { +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE)).append(newInfoLine("Max Rent", new LiteralText(claim.rent.getMaxrentAbleTime() / 86400 + " days")).formatted(Formatting.WHITE)))); +// }))); +// +// } else { +// text.append(newInfoLine("Status", new LiteralText("Not For Rent").formatted(Formatting.GREEN))); +// +// } +// source.sendFeedback(text, false); +// return 1; +// } +// private static Text newPosLine(BlockPos pos, Formatting form1, Formatting form2) { +// return new LiteralText("") +// .append(new LiteralText(String.valueOf(pos.getX())).formatted(form1)) +// .append(" ") +// .append(new LiteralText(String.valueOf(pos.getY())).formatted(form2)) +// .append(" ") +// .append(new LiteralText(String.valueOf(pos.getZ())).formatted(form1)); +// } +// private static Text newInfoLine(String title, Text text) { +// return new LiteralText("").append(new LiteralText("* " + title + ": ").formatted(Formatting.YELLOW)) +// .append(text).append("\n"); +// } - return setTrust(context, claim1, target, set, false); - } - private static int setTrust(CommandContext context, Claim claim, ServerPlayerEntity target, boolean set, boolean admin) throws CommandSyntaxException { - if (verifyPermission(claim, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - claim.permissionManager.playerPermissions.put(target.getGameProfile().getId(), set ? new Claim.InvertedPermissionMap() : new Claim.DefaultPermissionMap()); - context.getSource().sendFeedback(new LiteralText(target.getGameProfile().getName() + (set ? " now" : " no longer") + " has all the permissions").formatted(Formatting.YELLOW), false); +// private static ArrayList getClaims(){ +// ArrayList claims = new ArrayList<>(); +// ClaimManager.INSTANCE.claimsByName.forEach((s, claim) -> { +// claims.add(claim); +// }); +// return claims; +// } +// +// private static int listall(ServerCommandSource source){ +// List claims = getClaims(); +// Text text = new LiteralText("\n").append(new LiteralText("Claims").formatted(Formatting.GOLD)).append("\n "); +// for (Claim claim : claims) { +// Text cText = new LiteralText(claim.name).formatted(Formatting.GOLD); +// text.append(cText.append(" ")); +// } +// source.sendFeedback(text.append("\n"), false); +// return 1; +// } - String message; - if (set) message = "&aTrusted player &6" + target.getEntityName() + "&a in &6" + claim.name + "\n&aThey now have all the default permissions"; - else message = "&cDistrusted player &6" + target.getEntityName() + "&c in &6" + claim.name + "\n&cThey don't have any permissions now"; - context.getSource().sendFeedback(new LiteralText(ChatColor.translate(message)), false); - } - return 1; - } - private static int setFly(CommandContext context, boolean set) throws CommandSyntaxException { - ServerPlayerEntity player = context.getSource().getPlayer(); - if (set) { - ClaimManager.INSTANCE.flyers.add(player.getUuid()); - player.addMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN), false); - return 1; - } +// private static int list(ServerCommandSource source, String target) throws CommandSyntaxException { +// ServerPlayerEntity player = source.getPlayer(); +// GameProfile profile = target == null ? player.getGameProfile() : source.getMinecraftServer().getUserCache().findByName(target); +// +// if (profile == null) { +// source.sendError(Messages.INVALID_PLAYER); +// return -1; +// } +// +// List claims = ClaimManager.INSTANCE.getPlayerClaims(profile.getId()); +// if (claims.isEmpty()) { +// source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); +// return -1; +// } +// +// +// Text text = new LiteralText("\n").append(new LiteralText("Claims (" + target + "): ").formatted(Formatting.GOLD)).append("\n "); +// boolean nextColor = false; +// for (Claim claim : claims) { +// if(!claim.isChild) { +// Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { +// Text hoverText = new LiteralText("Click for more Info").formatted(Formatting.GREEN); +// if (claim.children.size() > 0) { +// hoverText.append("\n\nSubzones:"); +// for (Claim subzone : claim.children) { +// hoverText.append("\n- " + subzone.name); +// } +// } +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); +// +// style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); +// }); +// +// nextColor = !nextColor; +// text.append(cText.append(" ")); +// } +// } +// +// source.sendFeedback(text.append("\n"), false); +// return 1; +// } +// private static int listAll(ServerCommandSource source, int page) { +// List claims = new ArrayList<>(); +// ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> claims.add(claim)); +// +// if (claims.isEmpty()) { +// source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); +// return -1; +// } +// +// List list = new ArrayList<>(claims.size() / 10); +// +// for (int i = 0; i < claims.size(); i++) { +// Claim claim = claims.get(i); +// +// Text cText = new LiteralText("").append(new LiteralText(i + ". ").formatted(Formatting.GOLD)) +// .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" in ").formatted(Formatting.GRAY)) +// .append(new LiteralText(Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").getPath()).formatted(Formatting.WHITE)); +// +// cText.styled((style) -> { +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click for more Info").formatted(Formatting.GREEN))); +// style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); +// }); +// +// list.add(cText.append("\n")); +// } +// +// Text[] texts = new Text[]{}; +// texts = list.toArray(texts); +// return sendPage(source, texts, page, "Claims", "/claim listall %page%"); +// } +// private static int rename(CommandContext context, boolean admin) throws CommandSyntaxException { +// String name = getString(context, "claim"); +// String newName = getString(context, "name"); +// if(!newName.matches("[A-Za-z0-9]+")){ +// context.getSource().sendError(new LiteralText("Invalid claim name")); +// return -1; +// } +// Claim claim = ClaimManager.INSTANCE.claimsByName.get(name); +// if (claim == null) { +// context.getSource().sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// if (ClaimManager.INSTANCE.claimsByName.containsKey(newName)) { +// context.getSource().sendError(new LiteralText("That name is already taken!")); +// return -1; +// } +// if (!admin && !claim.hasPermission(context.getSource().getPlayer().getUuid(), Claim.Permission.MODIFY_PROPERTIES)) { +// context.getSource().sendError(new LiteralText("You don't have permission to modify claim properties!")); +// return -1; +// } +// ClaimManager.INSTANCE.claimsByName.remove(name); +// if(claim.isChild) claim.name = ClaimUtil.getParentClaim(claim).name + "." + newName; +// else claim.name = newName; +// ClaimManager.INSTANCE.addClaim(claim); +// context.getSource().sendFeedback(new LiteralText("Renamed Claim " + name + " to " + claim.name).formatted(Formatting.GOLD), admin); +// return -1; +// } +// private static int showTrustedList(CommandContext context, Claim claim, boolean showSelf) throws CommandSyntaxException { +// ServerCommandSource source = context.getSource(); +// ServerPlayerEntity player = source.getPlayer(); +// int mapSize = claim.permissionManager.playerPermissions.size(); +// +// if (mapSize == 1 && !showSelf) { +// source.sendError(new LiteralText(claim.name + " is not trusting anyone!")); +// return -1; +// } +// +// Text text = new LiteralText("\n"); +// text.append(new LiteralText("Trusted players for Claim ").formatted(Formatting.YELLOW)) +// .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append("\n"); +// +// AtomicInteger atomicInteger = new AtomicInteger(); +// claim.permissionManager.playerPermissions.forEach((uuid, perm) -> { +// atomicInteger.incrementAndGet(); +// Text pText = new LiteralText(""); +// Text owner; +// GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); +// if (profile != null) { +// owner = new LiteralText(profile.getName()); +// } else { +// owner = new LiteralText(uuid.toString()).styled((style) -> { +// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to Copy"))); +// style.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); +// }); +// } +// +// pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) +// .append(owner.formatted(Formatting.YELLOW)); +// +// Text hover = new LiteralText(""); +// hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); +// +// int allowed = 0; +// int i = 0; +// boolean nextColor = false; +// Text perms = new LiteralText(""); +// +// for (Claim.Permission value : Claim.Permission.values()) { +// if (claim.permissionManager.hasPermission(uuid, value)) { +// Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; +// perms.append(new LiteralText(value.id).formatted(formatting)).append(" "); +// if (i == 3) perms.append("\n"); +// allowed++; +// i++; +// nextColor = !nextColor; +// } +// } +// +// if (allowed == Claim.Permission.values().length) { +// hover.append(new LiteralText("All " + allowed + " Permissions").formatted(Formatting.YELLOW, Formatting.ITALIC)); +// } else { +// hover.append(perms); +// } +// +// pText.append(new LiteralText(" ") +// .append(new LiteralText("(").formatted(Formatting.GOLD)) +// .append(new LiteralText(String.valueOf(allowed)).formatted(Formatting.GREEN)) +// .append(new LiteralText("/").formatted(Formatting.GOLD)) +// .append(new LiteralText(String.valueOf(Claim.Permission.values().length)).formatted(Formatting.YELLOW)) +// .append(new LiteralText(")").formatted(Formatting.GOLD)) +// ); +// +// pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); +// text.append(pText).append("\n"); +// }); +// +// source.sendFeedback(text, false); +// return 1; +// } +// private static int setOwnerName(ServerCommandSource source, Claim claim, String input) { +// String name = input.equals("reset") ? null : input; +// source.sendFeedback(new LiteralText("Set the Custom Owner Name to ") +// .formatted(Formatting.YELLOW).append(new LiteralText(name == null ? "Reset" : name).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) +// .append(new LiteralText(claim.customOwnerName == null ? "Not Present" : claim.customOwnerName).formatted(Formatting.GOLD)) +// .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) +// , false); +// claim.customOwnerName = input; +// return 1; +// } +// private static int setOwner(ServerCommandSource source, Claim claim, GameProfile profile) { +// GameProfile oldOwner = source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); +// source.sendFeedback(new LiteralText("Set the Claim Owner to ") +// .formatted(Formatting.YELLOW).append(new LiteralText(profile.getName()).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) +// .append(new LiteralText(oldOwner == null ? "(" + claim.claimBlockOwner + ")" : oldOwner.getName()).formatted(Formatting.GOLD)) +// .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) +// , false); +// claim.claimBlockOwner = profile.getId(); +// return 1; +// } +// private static int setEventMessage(ServerCommandSource source, Claim claim, Claim.Event event, String message) { +// switch (event) { +// case ENTER_CLAIM: +// claim.enterMessage = message.equalsIgnoreCase("reset") ? null : message; +// break; +// case LEAVE_CLAIM: +// claim.leaveMessage = message.equalsIgnoreCase("reset") ? null : message; +// break; +// } +// +// if (message.equalsIgnoreCase("reset")) { +// source.sendFeedback(new LiteralText("Reset ").append(new LiteralText(event.id).formatted(Formatting.GOLD) +// .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) +// .append(new LiteralText(claim.name).formatted(Formatting.GOLD))).formatted(Formatting.YELLOW) +// , false); +// return -1; +// } +// +// source.sendFeedback(new LiteralText("Set ").append(new LiteralText(event.id).formatted(Formatting.GOLD) +// .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) +// .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" to:").formatted(Formatting.YELLOW))) +// .append("\n").append(new LiteralText(ChatColor.translate(message))) +// .formatted(Formatting.YELLOW) +// , false); +// return 1; +// } +// private static int executeSetting(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { +// ServerPlayerEntity player = source.getPlayer(); +// Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : +// ClaimManager.INSTANCE.claimsByName.get(claimName); +// if (claim1 == null) { +// source.sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// +// if (input == null) { +// return querySettings(source, claim1); +// } +// +// validateCanAccess(player, claim1, admin); +// Claim.ClaimSettings.Setting setting = Claim.ClaimSettings.Setting.byId(input); +// Claim.Permission permission = Claim.Permission.byId(input); +// +// if (setting != null && permission == null) +// return isQuery ? querySetting(source, claim1, setting) : setSetting(source, claim1, setting, value); +// +// if (setting == null && permission != null) +// return isQuery ? queryPermission(source, claim1, permission) : setPermission(source, claim1, permission, value); +// +// source.sendError(Messages.INVALID_SETTING); +// return -1; +// } +// private static int executePermission(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { +// ServerPlayerEntity player = source.getPlayer(); +// Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : +// ClaimManager.INSTANCE.claimsByName.get(claimName); +// if (claim1 == null) { +// source.sendError(Messages.INVALID_CLAIM); +// return -1; +// } +// +// validateCanAccess(player, claim1, admin); +// Claim.Permission permission = Claim.Permission.byId(input); +// if (permission != null) +// return !isQuery ? setPermission(source, claim1, permission, value) : queryPermission(source, claim1, permission); +// +// source.sendError(Messages.INVALID_SETTING); +// return -1; +// } +// private static int querySetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting) { +// boolean enabled = claim.settings.getSetting(setting); +// source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); +// return 1; +// } +// private static int setSetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting, boolean set) { +// claim.settings.settings.put(setting, set); +// source.sendFeedback(new LiteralText(ChatColor.translate("&eSet setting &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); +// return 0; +// } +// private static int queryPermission(ServerCommandSource source, Claim claim, Claim.Permission permission) { +// boolean defaultPerm = claim.permissionManager.defaults.hasPermission(permission); +// source.sendFeedback(new LiteralText(ChatColor.translate("&ePermission &6" + permission.id + "&e is set to " + (defaultPerm ? "&a" : "&c") + defaultPerm + "&e for &6" + claim.name)), false); +// return 1; +// } +// private static int setPermission(ServerCommandSource source, Claim claim, Claim.Permission permission, boolean set) { +// claim.permissionManager.defaults.setPermission(permission, set); +// source.sendFeedback(new LiteralText(ChatColor.translate("&eSet permission &6" + permission.id + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); +// return 1; +// } +// private static int querySettings(ServerCommandSource source, Claim claim) { +// source.sendFeedback(new LiteralText("\n").append(new LiteralText("Settings: " + claim.name).formatted(Formatting.YELLOW)).append("\n") +// .append(Messages.Command.getSettings(claim)).append("\n"), false); +// return 1; +// } +// private static int executeTrust(CommandContext context, Collection targetCollection, boolean set, @Nullable String claimName) throws CommandSyntaxException { +// AtomicInteger integer = new AtomicInteger(); +//// if(targetCollection.size() > 1){ +//// context.getSource().sendFeedback(new LiteralText("Only 1 player allowed").formatted(Formatting.RED), true); +//// return 0; +//// } +// if(targetCollection.isEmpty()){ +// context.getSource().sendFeedback(new LiteralText("No player provided").formatted(Formatting.RED), true); +// return 0; +// } +// ServerPlayerEntity p = context.getSource().getPlayer(); +// Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getBlockPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); +// validateClaim(claim1); +// targetCollection.iterator().forEachRemaining(gameProfile -> { +// try { +// //This is supposed to check if the player has played before :shrug: +// if(context.getSource().getMinecraftServer().getUserCache().getByUuid(gameProfile.getId()) == gameProfile){ +// integer.set(setTrust(context, claim1, gameProfile, set, false)); +// } else { +// context.getSource().sendFeedback(new LiteralText("Unknown player!").formatted(Formatting.RED), true); +// integer.set(0); +// } +// } catch (CommandSyntaxException e) { +// e.printStackTrace(); +// } +// }); +// return integer.get(); +// } +// private static int setTrust(CommandContext context, Claim claim, GameProfile target, boolean set, boolean admin) throws CommandSyntaxException { +// if (verifyPermission(claim, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { +// claim.permissionManager.playerPermissions.put(target.getId(), set ? new Claim.InvertedPermissionMap() : new Claim.DefaultPermissionMap()); +// context.getSource().sendFeedback(new LiteralText(target.getName() + (set ? " now" : " no longer") + " has all the permissions").formatted(Formatting.YELLOW), false); +// } +// return 1; +// } +// private static int setFly(CommandContext context, boolean set) throws CommandSyntaxException { +// ServerPlayerEntity player = context.getSource().getPlayer(); +// if (set) { +// ClaimManager.INSTANCE.flyers.add(player.getUuid()); +// player.addMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN), false); +// return 1; +// } +// +// player.addMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED), false); +// ClaimManager.INSTANCE.flyers.remove(player.getUuid()); +// return -1; +// } - player.addMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED), false); - ClaimManager.INSTANCE.flyers.remove(player.getUuid()); - return -1; - } -} +// +// private static GameProfile getProfile(CommandContext context, String arg) { +// return context.getSource().getMinecraftServer().getUserCache().findByName(getString(context, arg)); +// } +//} \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java index 8b08234..cf9d404 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java @@ -42,7 +42,7 @@ public void useBlocksUntil0(UUID player, int amount) { if (!useClaimBlocks(player, amount)) blocksLeft.put(player, 0); } public void setClaimBlocks(Collection players, int amount) { - players.forEach(player -> setClaimBlocks(player.getGameProfile().getId(), -amount)); + players.forEach(player -> setClaimBlocks(player.getGameProfile().getId(), amount)); } public Claim getClaim(String name){ @@ -63,6 +63,7 @@ public List getPlayerClaims(UUID id) { }); return list; } + public boolean addClaim(Claim claim) { if (claimsByName.containsKey(claim.name)) return false; if (wouldIntersect(claim) && !claim.isChild) return false; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/Config.java index 093e1f1..9152cb6 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Config.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Config.java @@ -9,6 +9,7 @@ public class Config { public static int baseClaimBlocks3d = 15625; public static int baseClaimBlocks2d = 2500; public static boolean claims2d = true; + public static int rent_maxseconds = 7776000; public static String permissionManager = "luckperms"; public static String prefix = "&8[&aClaims&8]&r "; public static String msg_no_perm = "&c&lHey!&r&c Sorry but you don't have permission to do that"; @@ -32,6 +33,7 @@ static void sync() { claims2d = config.getBool("2D claims", claims2d, "Claims extending from y 0 to y 256"); baseClaimBlocks2d = config.getInt("2D base claim blocks", baseClaimBlocks2d, "Area Filled: " + ItsMine.blocksToAreaString2d(baseClaimBlocks2d)); baseClaimBlocks3d = config.getInt("3D base claim blocks", baseClaimBlocks3d, "Area Filled: " + ItsMine.blocksToAreaString3d(baseClaimBlocks3d)); + rent_maxseconds = config.getInt("rent.maxdays", rent_maxseconds, "Maximum rent time in seconds (eg. 90d = 7776000)"); permissionManager = config.getString("permissionManager", permissionManager, "Values: thimble, luckperms, vanilla"); prefix = config.getString("msg.prefix", prefix); msg_interact_entity = config.getString("msg.interact.entity", msg_interact_entity); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index 1d3230b..e3b4944 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -3,6 +3,7 @@ import io.github.indicode.fabric.itsmine.mixin.BlockActionPacketMixin; import io.github.indicode.fabric.itsmine.mixin.BucketItemMixin; import io.github.indicode.fabric.itsmine.mixin.projectile.OwnedProjectile; +import io.github.indicode.fabric.itsmine.util.BlockUtil; import net.minecraft.block.*; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; @@ -19,9 +20,7 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -import net.minecraft.world.BlockView; import net.minecraft.world.World; -import net.minecraft.world.dimension.DimensionType; import java.util.*; @@ -79,14 +78,14 @@ public static void setClaimFlying(UUID player, boolean flying) { public static boolean canInteractWith(Claim claim, Block block, UUID player) { return claim.hasPermission(player, Claim.Permission.INTERACT_BLOCKS) || - (BlockUtils.isButton(block) && claim.hasPermission(player, Claim.Permission.USE_BUTTONS)) || - (BlockUtils.isLever(block) && claim.hasPermission(player, Claim.Permission.USE_LEVERS)) || - (BlockUtils.isDoor(block) && claim.hasPermission(player, Claim.Permission.INTERACT_DOORS)) || - (BlockUtils.isContainer(block) && claim.hasPermission(player, Claim.Permission.CONTAINER)) || - (BlockUtils.isChest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_CHEST)) || - (BlockUtils.isEnderchest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_ENDERCHEST)) || - (BlockUtils.isShulkerBox(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_SHULKERBOX)) || - (BlockUtils.isLectern(block) && claim.hasPermission(player, Claim.Permission.INTERACT_LECTERN)); + (BlockUtil.isButton(block) && claim.hasPermission(player, Claim.Permission.USE_BUTTONS)) || + (BlockUtil.isLever(block) && claim.hasPermission(player, Claim.Permission.USE_LEVERS)) || + (BlockUtil.isDoor(block) && claim.hasPermission(player, Claim.Permission.INTERACT_DOORS)) || + (BlockUtil.isContainer(block) && claim.hasPermission(player, Claim.Permission.CONTAINER)) || + (BlockUtil.isChest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_CHEST)) || + (BlockUtil.isEnderchest(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_ENDERCHEST)) || + (BlockUtil.isShulkerBox(block) && claim.hasPermission(player, Claim.Permission.CONTAINER_SHULKERBOX)) || + (BlockUtil.isLectern(block) && claim.hasPermission(player, Claim.Permission.INTERACT_LECTERN)); } public static boolean canInteractUsingItem(Claim claim, Item item, UUID player) { @@ -114,6 +113,18 @@ public static boolean canDamageWithProjectile(ProjectileEntity projectile, Entit return false; } + public static > Map sortByValue(Map map) { + List> list = new ArrayList<>(map.entrySet()); + list.sort(Map.Entry.comparingByValue()); + + Map result = new LinkedHashMap<>(); + for (Map.Entry entry : list) { + result.put(entry.getKey(), entry.getValue()); + } + + return result; + } + public static boolean checkCanDamageWithProjectile(Entity entity, MinecraftServer server, UUID uuid) { if (entity.world.isClient) return true; @@ -129,15 +140,6 @@ public static boolean checkCanDamageWithProjectile(Entity entity, MinecraftServe return true; } - public static BlockPos getPosOnGround(BlockPos pos, World world) { - BlockPos blockPos = new BlockPos(pos.getX(), pos.getY(), pos.getZ()); - - do { - blockPos = blockPos.down(); - } while (world.getBlockState(blockPos).isAir()); - - return blockPos.up(); - } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java index ddab300..ac74472 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java @@ -1,24 +1,24 @@ package io.github.indicode.fabric.itsmine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; import net.fabricmc.api.ModInitializer; -import net.minecraft.SharedConstants; /** * @author Indigo Amann */ public class ItsMine implements ModInitializer { - private static Permissions permissions; + private static PermissionUtil permissionUtil; @Override public void onInitialize() { Config.sync(); - permissions = new Permissions(); + permissionUtil = new PermissionUtil(); //TODO: Enable when developing //SharedConstants.isDevelopment = true; } - public static Permissions permissions() { - return permissions; + public static PermissionUtil permissions() { + return permissionUtil; } public static String blocksToAreaString3d(int blocks) { int base = (int) Math.floor(Math.cbrt(blocks)); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index db14075..904182f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -56,11 +56,16 @@ public class Messages { .append(line(1, "To set a permission, type ").append(text("/claim permissions player [true | false]").formatted(Formatting.GOLD))) .append(line(2, "To check someone's permission, type ").append(text("/claim permissions player ").formatted(Formatting.GOLD))) .append(line(3, "To see a list of trusted players, type ").append(text("/claim trusted").formatted(Formatting.GOLD))), - header("How to resize claim") + header("How to Claim (Resizing)") .append(line("You can always change the size of your claim if you aren't happy with it!").formatted(Formatting.LIGHT_PURPLE)) .append(line(1, "To expand your claim in a direction, type ").append(text("/claim expand ").formatted(Formatting.GOLD))) .append(line(2, "If you want to specify a direction, you can type ").append(text("/claim expand ").formatted(Formatting.GOLD))) - .append(line(3, "To shrink a claim you do the same thing but replace \"expand\" with \"shrink\"")) + .append(line(3, "To shrink a claim you do the same thing but replace \"expand\" with \"shrink\"")), + header("How to Claim (Subzones)") + .append(line("Subzones allow you to have seperate permissions / settings in certain areas of your claim").formatted(Formatting.LIGHT_PURPLE)) + .append(line(1, "To create a subzone, you select an area inside your claim the way you would select a normal claim")) + .append(line(2, "Type ").append("/claim subzone add ").formatted(Formatting.GOLD).append(" to create a subzone").formatted(Formatting.YELLOW)) + .append(line(3,"Done! Everything else works the same way claims work")) }; public static final Text[] HELP = new Text[]{ diff --git a/src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java b/src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java new file mode 100644 index 0000000..be6d40a --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java @@ -0,0 +1,13 @@ +package io.github.indicode.fabric.itsmine; + +import net.minecraft.entity.Entity; + +import java.util.Map; +import java.util.UUID; + +public interface MonitorableWorld { + + int loadedEntities(); + + Map EntityList(); +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java new file mode 100644 index 0000000..14151b1 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java @@ -0,0 +1,43 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.command.EntitySelector; +import net.minecraft.command.arguments.EntityArgumentType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; +import net.minecraft.util.Formatting; + +import java.util.UUID; + +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class BlockCommand { + + static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder check = literal("blocks"); + RequiredArgumentBuilder other = argument("player", EntityArgumentType.player()); + other.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); + other.executes(ctx -> blocksLeft(ctx.getSource(), EntityArgumentType.getPlayer(ctx, "player").getGameProfile().getId())); + check.then(other); + check.executes(ctx -> blocksLeft(ctx.getSource())); + command.then(check); + } + + static int blocksLeft(ServerCommandSource source, UUID player) throws CommandSyntaxException { + int blocks = ClaimManager.INSTANCE.getClaimBlocks(player); + source.sendFeedback(new LiteralText((source.getPlayer().getGameProfile().getId().equals(player) ? "You have " : "They have ") + blocks + " blocks left").setStyle(new Style().setColor(Formatting.YELLOW)), false); + return 1; + } + static int blocksLeft(ServerCommandSource source) throws CommandSyntaxException { + int blocks = ClaimManager.INSTANCE.getClaimBlocks(source.getPlayer().getUuid()); + source.sendFeedback(new LiteralText("You have " + blocks + " blocks left").setStyle(new Style().setColor(Formatting.YELLOW)), false); + return 1; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java new file mode 100644 index 0000000..0c55bd6 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java @@ -0,0 +1,45 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import io.github.indicode.fabric.itsmine.command.admin.AdminCommand; +import io.github.indicode.fabric.itsmine.command.subzone.SubzoneCommand; +import net.minecraft.server.command.ServerCommandSource; + +import static net.minecraft.server.command.CommandManager.literal; + +public class CommandManager { + + public static void register(CommandDispatcher dispatcher) { + LiteralArgumentBuilder main = literal("itsmine"); + LiteralArgumentBuilder alias = literal("claim"); + register(main, dispatcher); + register(alias, dispatcher); + dispatcher.register(main); + dispatcher.register(alias); + } + private static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { + AdminCommand.register(command, dispatcher); + BlockCommand.register(command); + CreateCommand.register(command); + ExceptionCommand.register(command, false, false); + ExpandCommand.register(command); + FlyCommand.register(command); + HelpCommand.register(command); + InfoCommand.register(command); + ListCommand.register(command); + PermissionsCommand.register(command, false); + RemoveCommand.register(command); + RenameCommand.register(command); + RentableCommand.register(command); + RentCommand.register(command); + RevenueCommand.register(command); + SettingsCommand.register(command, false); + ShowCommand.register(command); + StickCommand.register(command); + SubzoneCommand.register(command, dispatcher); + TransferCommand.register(command); + TrustCommand.register(command); + TrustedCommand.register(command); + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java new file mode 100644 index 0000000..1c53fb0 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java @@ -0,0 +1,126 @@ +package io.github.indicode.fabric.itsmine.command; + +import blue.endless.jankson.annotation.Nullable; +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.command.arguments.BlockPosArgumentType; +import net.minecraft.command.arguments.PosArgument; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.HoverEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; +import net.minecraft.util.Formatting; +import net.minecraft.util.Pair; +import net.minecraft.util.math.BlockPos; + +import java.util.UUID; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static io.github.indicode.fabric.itsmine.command.ShowCommand.executeShowClaim; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class CreateCommand { + static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder create = literal("create"); + RequiredArgumentBuilder name = argument("name", word()); + + name.executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); + if (selectedPositions == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getLeft() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getRight() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); + } else { + String cname = getString(context, "name"); + if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), false, null) > 0) { + ClaimManager.INSTANCE.stickPositions.remove(player); + } + } + return 0; + }); + + ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); + RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); + max.executes(context -> createClaim(getString(context, "name"), context.getSource(), BlockPosArgumentType.getBlockPos(context, "min"), BlockPosArgumentType.getBlockPos(context, "max"), false, null)); + min.then(max); + name.then(min); + create.then(name); + command.then(create); + } + + public static int createClaim(String name, ServerCommandSource owner, BlockPos posA, BlockPos posB, boolean admin, @Nullable String cOwnerName) throws CommandSyntaxException { + if (name.length() > 30) { + owner.sendError(Messages.MSG_LONG_NAME); + return -1; + } + if(!name.matches("[A-Za-z0-9]+")){ + owner.sendError(new LiteralText("Invalid claim name")); + return -1; + } + UUID ownerID = owner.getPlayer().getGameProfile().getId(); + int x, y = 0, z, mx, my = 255, mz; + if (posA.getX() > posB.getX()) { + x = posB.getX(); + mx = posA.getX(); + } else { + x = posA.getX(); + mx = posB.getX(); + } + if (!Config.claims2d) { + if (posA.getY() > posB.getY()) { + y = posB.getY(); + my = posA.getY(); + } else { + y = posA.getY(); + my = posB.getY(); + } + } + if (posA.getZ() > posB.getZ()) { + z = posB.getZ(); + mz = posA.getZ(); + } else { + z = posA.getZ(); + mz = posB.getZ(); + } + BlockPos min = new BlockPos(x, y, z); + BlockPos max = new BlockPos(mx, my, mz); + BlockPos sub = max.subtract(min); + sub = sub.add(1, Config.claims2d ? 0 : 1,1); + int subInt = sub.getX() * (Config.claims2d ? 1 : sub.getY()) * sub.getZ(); + + Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos(), false); + if (cOwnerName != null) claim.customOwnerName = cOwnerName; + claim.permissionManager.playerPermissions.put(ownerID, new Claim.InvertedPermissionMap()); + if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { + if (!ClaimManager.INSTANCE.wouldIntersect(claim)) { + // works because only the first statement is evaluated if true + if ((admin && ItsMine.permissions().hasPermission(owner, PermissionUtil.Command.INFINITE_BLOCKS, 2)) || ClaimManager.INSTANCE.useClaimBlocks(ownerID, subInt)) { + ClaimManager.INSTANCE.addClaim(claim); + owner.sendFeedback(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)).append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").setStyle(new Style().setColor(Formatting.GREEN).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))))), false); + BlockCommand.blocksLeft(owner); + executeShowClaim(owner, claim, false); + if (admin) + owner.getMinecraftServer().sendMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); + return 1; + } else { + owner.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + subInt + "(" + (subInt - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); + } + } else { + owner.sendFeedback(new LiteralText("Your claim would overlap with another claim").formatted(Formatting.RED), false); + } + } else { + owner.sendFeedback(new LiteralText("The name \"" + name + "\" is already taken.").formatted(Formatting.RED), false); + } + return 0; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java new file mode 100644 index 0000000..d046f0b --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java @@ -0,0 +1,176 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.sun.org.apache.xpath.internal.Arg; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.command.EntitySelector; +import net.minecraft.command.arguments.EntityArgumentType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.*; +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; +import static io.github.indicode.fabric.itsmine.command.TrustCommand.setTrust; +import static io.github.indicode.fabric.itsmine.command.TrustedCommand.showTrustedList; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.*; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.*; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class ExceptionCommand { + + public static void register(LiteralArgumentBuilder command, boolean admin, boolean subzone) { + { + LiteralArgumentBuilder settings = literal("settings"); + RequiredArgumentBuilder claim; + if(subzone){ + claim = ArgumentUtil.getClaims(); + } else { + claim = ArgumentUtil.getSubzones(); + } + + if (!admin) { + settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); + + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return querySettings(context.getSource(), claim1); + }); + } + + RequiredArgumentBuilder id = argument("setting", word()).suggests(SETTINGS_PROVIDER); + RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); + + id.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), getString(context, "claim"), true, false, admin)); + set.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); + + id.then(set); + claim.then(id); + settings.then(claim); + command.then(settings); + } + + LiteralArgumentBuilder exceptions = literal("permissions"); + if (admin) exceptions.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_PERMISSIONS, 2)); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + if (!admin) { + exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); + + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim1, false); + }); + } + + if (!admin) { + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(new LiteralText("That claim does not exist")); + return -1; + } + return showTrustedList(context, claim1, true); + }); + } + + { + RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); + LiteralArgumentBuilder remove = literal("remove"); + remove.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + claim1.permissionManager.resetPermissions(player1.getGameProfile().getId()); + context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + " no longer has an exception in the claim").formatted(Formatting.YELLOW), false); + } + return 0; + }); + player.then(remove); + LiteralArgumentBuilder all = literal("*"); + RequiredArgumentBuilder allstate = argument("allow", BoolArgumentType.bool()); + allstate.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + validateClaim(claim1); + return setTrust(context, claim1, player1.getGameProfile(), BoolArgumentType.getBool(context, "allow"), admin); + }); + all.then(allstate); + player.then(all); + for (Claim.Permission value : Claim.Permission.values()) { + LiteralArgumentBuilder permNode = literal(value.id); + RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); + allow.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + boolean permission = BoolArgumentType.getBool(context, "allow"); + modifyException(claim1, player1, value, permission); + context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has the permission " + value.name).formatted(Formatting.YELLOW), false); + } + return 0; + }); + permNode.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + boolean permission = hasPermission(claim1, player1, value); + context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); + } + return 0; + }); + permNode.then(allow); + player.then(permNode); + } + claim.then(player); + } + { + LiteralArgumentBuilder message = literal("message"); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + RequiredArgumentBuilder messageEvent = getMessageEvent(); + RequiredArgumentBuilder messageArgument = getEventMessage(); + messageArgument.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PROPERTIES, context, admin)) { + Claim.Event event = Claim.Event.getById(getString(context, "messageEvent")); + + if (event == null) { + context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); + return -1; + } + + return setEventMessage(context.getSource(), claim1, event, getString(context, "message")); + } + + return -1; + }); + + messageEvent.then(messageArgument); + claimArgument.then(messageEvent); + message.then(claimArgument); + command.then(message); + } + + + exceptions.then(claim); + command.then(exceptions); + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java new file mode 100644 index 0000000..7d13134 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java @@ -0,0 +1,174 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; +import io.github.indicode.fabric.itsmine.util.ShowerUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; + +import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.command.BlockCommand.blocksLeft; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getDirections; +import static io.github.indicode.fabric.itsmine.util.DirectionUtil.directionByName; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class ExpandCommand { + + public static void register(LiteralArgumentBuilder command) { + { + LiteralArgumentBuilder expand = literal("expand"); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = getDirections(); + + direction.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + IntegerArgumentType.getInteger(context, "distance"), + directionByName(getString(context, "direction")), + context.getSource(), + false + )); + + amount.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + IntegerArgumentType.getInteger(context, "distance"), + Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], + context.getSource(), + false + )); + + amount.then(direction); + expand.then(amount); + command.then(expand); + } + { + LiteralArgumentBuilder shrink = literal("shrink"); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = getDirections(); + + direction.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + -IntegerArgumentType.getInteger(context, "distance"), + directionByName(getString(context, "direction")), + context.getSource(), + false + )); + + amount.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + -IntegerArgumentType.getInteger(context, "distance"), + Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], + context.getSource(), + false + )); + + amount.then(direction); + shrink.then(amount); + command.then(shrink); + } + } + + private static void undoExpand(Claim claim, Direction direction, int amount){ + if (amount < 0) claim.expand(direction, -amount); + else claim.shrink(direction, amount); + } + + public static int expand(Claim claim, int amount, Direction direction, ServerCommandSource source, boolean admin) throws CommandSyntaxException { + UUID ownerID = source.getPlayer().getGameProfile().getId(); + if (claim == null) { + source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if (direction == null) { + source.sendFeedback(new LiteralText("That is not a valid direction").formatted(Formatting.RED), false); + return 0; + } + if (!claim.permissionManager.hasPermission(ownerID, Claim.Permission.MODIFY_SIZE)) { + source.sendFeedback(new LiteralText("You do not have border change permissions in that claim").formatted(Formatting.RED), false); + if (!admin) return 0; + } + int oldArea = claim.getArea(); + + + if (amount > 0) { + claim.expand(direction, amount); + } + else { + claim.shrink(direction, -amount); + } + + if (!claim.canShrinkWithoutHittingOtherSide(new BlockPos(direction.getOffsetX() * amount, direction.getOffsetY() * amount, direction.getOffsetZ() * amount))) { + source.sendFeedback(new LiteralText("You can't shrink your claim that far. It would pass its opposite wall.").formatted(Formatting.RED), false); + undoExpand(claim, direction, amount); + return 0; + } + + if(!claim.isChild){ + if (ClaimManager.INSTANCE.wouldIntersect(claim)) { + undoExpand(claim, direction, amount); + source.sendFeedback(new LiteralText("Expansion would result in hitting another claim").formatted(Formatting.RED), false); + return 0; + } + + //Check if shrinking would reset a subzone to be outside of its parent claim + AtomicBoolean returnValue = new AtomicBoolean(); + returnValue.set(false); + claim.children.forEach(claim1 -> { + if(!claim1.isInside(claim)){ + undoExpand(claim, direction, amount); + source.sendFeedback(new LiteralText("Shrinking would result in " + claim1.name + " being outside of " + claim.name).formatted(Formatting.RED), true); + returnValue.set(true); + } + }); + if(returnValue.get()) return 0; + + int newArea = claim.getArea() - oldArea; + if (!admin && claim.claimBlockOwner != null && ClaimManager.INSTANCE.getClaimBlocks(ownerID) < newArea) { + undoExpand(claim, direction, amount); + source.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + newArea + "(" + (newArea - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); + blocksLeft(source); + return 0; + } else { + if (!admin && claim.claimBlockOwner != null) ClaimManager.INSTANCE.useClaimBlocks(ownerID, newArea); + source.sendFeedback(new LiteralText("Your claim was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); + blocksLeft(source); + undoExpand(claim, direction, amount); + ShowerUtil.update(claim, source.getWorld(), true); + if (amount > 0) claim.expand(direction, amount); + else claim.shrink(direction, -amount); + ShowerUtil.update(claim, source.getWorld(), false); + } + return 0; + }else{ + Claim parent = ClaimUtil.getParentClaim(claim); + if(!claim.isInside(parent)) { + source.sendFeedback(new LiteralText("Expansion would result in expanding outside of your main claim").formatted(Formatting.RED), false); + undoExpand(claim, direction, amount); + } else if(ClaimManager.INSTANCE.wouldSubzoneIntersect((claim))){ + source.sendFeedback(new LiteralText("Expansion would result in overlapping with another subzone").formatted(Formatting.RED), false); + undoExpand(claim, direction, amount); + }else{ + source.sendFeedback(new LiteralText("Your subzone was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); + //The expansion is undone to hide the claimshower + undoExpand(claim, direction, amount); + ShowerUtil.update(parent, source.getWorld(), true); + if (amount > 0) claim.expand(direction, amount); + else claim.shrink(direction, -amount); + ShowerUtil.update(parent, source.getWorld(), false); + } + } + return 0; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java new file mode 100644 index 0000000..9ad50af --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java @@ -0,0 +1,42 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static net.minecraft.server.command.CommandManager.literal; + +public class FlyCommand { + static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder fly = literal("fly"); + fly.requires(src -> ItsMine.permissions().hasPermission(src, PermissionUtil.Command.CLAIM_FLY, 2)); + RequiredArgumentBuilder setArgument = CommandManager.argument("set", BoolArgumentType.bool()); + fly.executes((context) -> executeSetFly(context, !ClaimManager.INSTANCE.flyers.contains(context.getSource().getPlayer().getUuid()))); + setArgument.executes((context) -> executeSetFly(context, BoolArgumentType.getBool(context, "set"))); + fly.then(setArgument); + command.then(fly); + } + + private static int executeSetFly(CommandContext context, boolean set) throws CommandSyntaxException { + ServerPlayerEntity player = context.getSource().getPlayer(); + if (set) { + ClaimManager.INSTANCE.flyers.add(player.getUuid()); + player.addMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN), false); + return 1; + } + + player.addMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED), false); + ClaimManager.INSTANCE.flyers.remove(player.getUuid()); + return -1; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java new file mode 100644 index 0000000..ac15e93 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java @@ -0,0 +1,102 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.ChatColor; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.Messages; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.HoverEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getHelpId; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class HelpCommand { + + public static void register(LiteralArgumentBuilder command) { + command.executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); + + LiteralArgumentBuilder help = literal("help"); + help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); + + RequiredArgumentBuilder id = getHelpId(); + RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); + + page.executes((context) -> { + Claim.HelpBook book = Claim.HelpBook.getById(getString(context, "id")); + if (book == null) { + context.getSource().sendError(new LiteralText("Invalid Book!")); + return -1; + } + int p = IntegerArgumentType.getInteger(context, "page"); + + if (p > book.texts.length) p = 1; + return sendPage(context.getSource(), book.texts, p, book.title, book.getCommand()); + }); + + id.then(page); + help.then(id); + command.then(help); + } + + public static int sendPage(ServerCommandSource source, Text[] text, int page, String title, String command) { + int prevPage = page - 2; + int thisPage = page - 1; + int nextPage = page + 1; + final String SEPARATOR = "-----------------------------------------------------"; + Text header = new LiteralText("") + .append(new LiteralText("- [ ").formatted(Formatting.GRAY)) + .append(new LiteralText(title).formatted(Formatting.GOLD)) + .append(" ] ") + .append(SEPARATOR.substring(ChatColor.removeAlternateColorCodes('&', title).length() + 4)) + .formatted(Formatting.GRAY); + + Text button_prev = new LiteralText("") + .append(new LiteralText("<-").formatted(Formatting.WHITE, Formatting.BOLD)) + .append(" ").append(new LiteralText("Prev").formatted(Formatting.GOLD)) + .styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); + if (prevPage >= 0) + style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); + }); + + Text button_next = new LiteralText("") + .append(new LiteralText("Next").formatted(Formatting.GOLD)) + .append(" ").append(new LiteralText("->").formatted(Formatting.WHITE, Formatting.BOLD)).append(" ") + .styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); + if (nextPage <= text.length) + style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); + }); + + Text buttons = new LiteralText("") + .append(new LiteralText("[ ").formatted(Formatting.GRAY)) + .append(button_prev) + .append(" ") + .append( + new LiteralText(String.valueOf(page)).formatted(Formatting.GREEN) + .append(new LiteralText("/").formatted(Formatting.GRAY)) + .append(new LiteralText(String.valueOf(text.length)).formatted(Formatting.GREEN)) + ) + .append(" ") + .append(button_next) + .append(new LiteralText("] ").formatted(Formatting.GRAY)); + + Text footer = new LiteralText("- ") + .formatted(Formatting.GRAY) + .append(buttons).append(new LiteralText(" ------------------------------").formatted(Formatting.GRAY)); + + header.append("\n").append(text[thisPage]).append("\n").append(footer); + source.sendFeedback(header, false); + return 1; + } + + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java new file mode 100644 index 0000000..3e6aed0 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java @@ -0,0 +1,105 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Config; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.TimeUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.HoverEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.registry.Registry; + +import java.util.Objects; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static net.minecraft.server.command.CommandManager.literal; + +public class InfoCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder info = literal("info"); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + info.executes(context -> info( + context.getSource(), + ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()) + )); + claim.executes(context -> info(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")) + )); + info.then(claim); + command.then(info); + } + + private static int info(ServerCommandSource source, Claim claim) throws CommandSyntaxException { + if (claim == null) { + source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + + GameProfile owner = claim.claimBlockOwner == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); + BlockPos size = claim.getSize(); + + Text text = new LiteralText("\n"); + text.append(new LiteralText("Claim Info: " + claim.name).formatted(Formatting.GOLD)).append("\n"); + text.append(newInfoLine("Name", new LiteralText(claim.name).formatted(Formatting.WHITE))); + text.append(newInfoLine("Entities", new LiteralText(String.valueOf(claim.getEntities(source.getWorld()))).formatted(Formatting.AQUA))); + text.append(newInfoLine("Owner", + owner != null && claim.customOwnerName == null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : + claim.customOwnerName != null ? new LiteralText(claim.customOwnerName).formatted(Formatting.GOLD) : + new LiteralText("No Owner").formatted(Formatting.RED, Formatting.ITALIC))); + text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); + + + text.append(new LiteralText("").append(new LiteralText("* Settings:").formatted(Formatting.YELLOW)) + .append(Messages.Command.getSettings(claim)).append("\n")); + Text pos = new LiteralText(""); + Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); + Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); + + + pos.append(newInfoLine("Position", new LiteralText("") + .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) + .append(" ") + .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); + text.append(pos); + text.append(newInfoLine("Dimension", new LiteralText(Registry.DIMENSION_TYPE.getId(claim.dimension).getPath()))); + if(claim.rent.isRented()){ + GameProfile tenant = claim.rent.getTenant() == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.rent.getTenant()); + text.append(newInfoLine("Status", new LiteralText("Rented").formatted(Formatting.RED).styled(style -> { + java.util.Date time=new java.util.Date((long) claim.rent.getRentedUntil()*1000); + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Until", new LiteralText(time.toString()).formatted(Formatting.WHITE)).append(newInfoLine("By", new LiteralText(tenant.getName()).formatted(Formatting.WHITE))).append(newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE))))); + }))); + } else if (claim.rent.isRentable() && !claim.rent.isRented()){ + text.append(newInfoLine("Status", new LiteralText("For Rent").formatted(Formatting.GREEN).styled(style -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE)).append(newInfoLine("Max Rent", new LiteralText(claim.rent.getMaxrentAbleTime() / 86400 + " days")).formatted(Formatting.WHITE)))); + }))); + + } else { + text.append(newInfoLine("Status", new LiteralText("Not For Rent").formatted(Formatting.GREEN))); + + } + source.sendFeedback(text, false); + return 1; + } + + private static Text newPosLine(BlockPos pos, Formatting form1, Formatting form2) { + return new LiteralText("") + .append(new LiteralText(String.valueOf(pos.getX())).formatted(form1)) + .append(" ") + .append(new LiteralText(String.valueOf(pos.getY())).formatted(form2)) + .append(" ") + .append(new LiteralText(String.valueOf(pos.getZ())).formatted(form1)); + } + private static Text newInfoLine(String title, Text text) { + return new LiteralText("").append(new LiteralText("* " + title + ": ").formatted(Formatting.YELLOW)) + .append(text).append("\n"); + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java new file mode 100644 index 0000000..9e2c0b1 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java @@ -0,0 +1,30 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.server.command.ServerCommandSource; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static io.github.indicode.fabric.itsmine.command.admin.AdminCommand.PERMISSION_CHECK_ADMIN; +import static io.github.indicode.fabric.itsmine.command.admin.ClaimsCommand.list; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.PLAYERS_PROVIDER; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class ListCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder list = literal("list"); + RequiredArgumentBuilder player = argument("player", word()); + player.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); + player.suggests(PLAYERS_PROVIDER); + list.executes(context -> list(context.getSource(), context.getSource().getName())); + player.requires(PERMISSION_CHECK_ADMIN); + player.executes(context -> list(context.getSource(), getString(context, "player"))); + command.then(list); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java new file mode 100644 index 0000000..2fe9ccf --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java @@ -0,0 +1,49 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; +import static io.github.indicode.fabric.itsmine.command.TrustedCommand.showTrustedList; +import static net.minecraft.server.command.CommandManager.literal; + +public class PermissionsCommand { + public static void register(LiteralArgumentBuilder command, boolean admin) { + LiteralArgumentBuilder exceptions = literal("permissions"); + if (admin) + exceptions.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_PERMISSIONS, 2)); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + if (!admin) { + exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); + + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim1, false); + }); + } + + if (!admin) { + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(new LiteralText("That claim does not exist")); + return -1; + } + return showTrustedList(context, claim1, true); + }); + } + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java new file mode 100644 index 0000000..827e85d --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java @@ -0,0 +1,93 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ClaimShower; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import io.github.indicode.fabric.itsmine.util.ShowerUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.util.ShowerUtil.silentHideShow; +import static net.minecraft.server.command.CommandManager.literal; + +public class RemoveCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder delete = literal("remove"); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + LiteralArgumentBuilder confirm = literal("confirm"); + confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); + claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); + claim.then(confirm); + delete.then(claim); + delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); + command.then(delete); + } + public static int requestDelete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { + if (claim == null) { + sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { + if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { + sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + } else { + sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); + return 0; + } + } + sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to delete the claim \"" + claim.name + "\"? ").formatted(Formatting.GOLD)) + .append(new LiteralText("[I'M SURE]").setStyle(new Style() + .setColor(Formatting.DARK_RED) + .setBold(true) + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")))), false); + return 0; + } + public static int delete(ServerCommandSource source, Claim claim, boolean admin) throws CommandSyntaxException { + ServerWorld world = source.getWorld(); + if (claim == null) { + source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if (!claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { + if (admin && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)) { + source.sendFeedback(new LiteralText("Deleting a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + } else { + source.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); + return 0; + } + } + if(!claim.isChild){ + ClaimManager.INSTANCE.releaseBlocksToOwner(claim); + ShowerUtil.update(claim, world, true); + ClaimManager.INSTANCE.claimsByName.remove(claim.name); + for(Claim subzone : claim.children){ + ClaimManager.INSTANCE.claimsByName.remove(subzone.name); + } + }else{ + Claim parent = ClaimUtil.getParentClaim(claim); + ShowerUtil.update(parent, world, true); + ClaimUtil.getParentClaim(claim).removeSubzone(claim); + ClaimManager.INSTANCE.claimsByName.remove(claim.name); + ShowerUtil.update(parent, world, false); + } + source.getWorld().getPlayers().forEach(playerEntity -> { + if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true); + }); + source.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)); + return 0; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java new file mode 100644 index 0000000..75612dd --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java @@ -0,0 +1,61 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class RenameCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder rename = literal("rename"); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + RequiredArgumentBuilder nameArgument = argument("name", word()); + nameArgument.executes((context) -> rename(context, false)); + claimArgument.then(nameArgument); + rename.then(claimArgument); + command.then(rename); + } + + public static int rename(CommandContext context, boolean admin) throws CommandSyntaxException { + String name = getString(context, "claim"); + String newName = getString(context, "name"); + if(!newName.matches("[A-Za-z0-9]+")){ + context.getSource().sendError(new LiteralText("Invalid claim name")); + return -1; + } + Claim claim = ClaimManager.INSTANCE.claimsByName.get(name); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + if (ClaimManager.INSTANCE.claimsByName.containsKey(newName)) { + context.getSource().sendError(new LiteralText("That name is already taken!")); + return -1; + } + if (!admin && !claim.hasPermission(context.getSource().getPlayer().getUuid(), Claim.Permission.MODIFY_PROPERTIES)) { + context.getSource().sendError(new LiteralText("You don't have permission to modify claim properties!")); + return -1; + } + ClaimManager.INSTANCE.claimsByName.remove(name); + if(claim.isChild) claim.name = ClaimUtil.getParentClaim(claim).name + "." + newName; + else claim.name = newName; + ClaimManager.INSTANCE.addClaim(claim); + context.getSource().sendFeedback(new LiteralText("Renamed Claim " + name + " to " + claim.name).formatted(Formatting.GOLD), admin); + return -1; + } + + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java new file mode 100644 index 0000000..67b3dcd --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java @@ -0,0 +1,94 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.TimeUtil; +import net.minecraft.item.ItemStack; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.string; +import static net.minecraft.server.command.CommandManager.literal; + +public class RentCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder rent = literal("rent"); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + RequiredArgumentBuilder days = CommandManager.argument("days", string()); + days.executes(context -> rent(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), getString(context, "days"))); + + claim.then(days); + rent.then(claim); + command.then(rent); + } + private static int rent(ServerCommandSource source, Claim claim, String rentString) throws CommandSyntaxException { + if(claim == null){ + source.sendFeedback(Messages.INVALID_CLAIM, true); + return 0; + } + int rentTime = (int) TimeUtil.convertStringtoSeconds(rentString); + int rentAbleTime = claim.rent.getRentAbleTime(); + int maxrentAbleTime = claim.rent.getMaxrentAbleTime(); + ItemStack currency = claim.rent.getCurrency(); + ItemStack handItem = source.getPlayer().inventory.getMainHandStack(); + ItemStack revenue = handItem.copy(); + if(rentTime % claim.rent.getRentAbleTime() != 0){ + source.sendFeedback(new LiteralText("You have to rent this claim for a time by a multiple of " + TimeUtil.convertSecondsToString(rentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); + return 0; + } + int rentAmount = rentTime / claim.rent.getRentAbleTime(); + if(currency.getItem() != handItem.getItem() || handItem.getCount() < claim.rent.getAmount() * rentAmount){ + source.sendFeedback(new LiteralText("You don't have enough " + currency.getName().asString()).formatted(Formatting.RED), true); + return 0; + } + if (!claim.rent.isRentable()) { + source.sendFeedback(new LiteralText(claim.name + " is not for rent").formatted(Formatting.RED), true); + return 0; + } + if (rentTime > claim.rent.getMaxrentAbleTime()) { + source.sendFeedback(new LiteralText("You can't rent this claim for longer than " + TimeUtil.convertSecondsToString(maxrentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); + return 0; + } + if(claim.rent.getTenant() == null){ + //Setup for claim rent + claim.rent.setTenant(source.getPlayer().getUuid()); + claim.rent.setRentedUntil(claim.rent.getUnixTime() + rentTime); + //Remove items from player + handItem.setCount(handItem.getCount() - claim.rent.getAmount() * rentAmount); + revenue.setCount(claim.rent.getAmount() * rentAmount); + claim.rent.addRevenue(revenue); + //Give Permissions to Tenant + claim.permissionManager.playerPermissions.put(source.getPlayer().getUuid(), new Claim.InvertedPermissionMap()); + source.sendFeedback(new LiteralText("Renting " + claim.name + " for " + claim.rent.getAmount() * rentAmount + " " + claim.rent.getCurrency().getName().asString() + " for " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); + return 1; + } else if(claim.rent.getTenant().toString().equalsIgnoreCase(source.getPlayer().getUuid().toString())){ + if (claim.rent.getRentTimeLeft() + rentTime <= maxrentAbleTime) { + //Setup for claim rent + claim.rent.setRentedUntil(claim.rent.getUnixTime() + rentTime + claim.rent.getRentTimeLeft()); + //Remove items from player + handItem.setCount(handItem.getCount() - claim.rent.getAmount() * rentAmount); + + revenue.setCount(claim.rent.getAmount() * rentAmount); + claim.rent.addRevenue(revenue); + //Give Permissions to Tenant + source.sendFeedback(new LiteralText("Extended rent " + claim.name + " by " + TimeUtil.convertSecondsToString(rentTime, '2', 'a') + "for " + claim.rent.getAmount() * rentAmount + " " + claim.rent.getCurrency().getName().asString()).formatted(Formatting.GREEN), true); + return 1; + } else { + source.sendFeedback(new LiteralText("Rent would exceed the limit by " + TimeUtil.convertSecondsToString(claim.rent.getRentTimeLeft() + rentTime - maxrentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); + return 0; + } + } else { + source.sendFeedback(new LiteralText("This claim is already rented").formatted(Formatting.RED), true); + return 0; + } + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java new file mode 100644 index 0000000..479404e --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java @@ -0,0 +1,81 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Config; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.TimeUtil; +import net.minecraft.command.arguments.ItemStackArgument; +import net.minecraft.command.arguments.ItemStackArgumentType; +import net.minecraft.item.ItemStack; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.string; +import static net.minecraft.server.command.CommandManager.literal; + +public class RentableCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder rentable = literal("rentable"); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + + RequiredArgumentBuilder currency = net.minecraft.server.command.CommandManager.argument("item", ItemStackArgumentType.itemStack()).suggests(ArgumentUtil::itemsSuggestion); + RequiredArgumentBuilder amount = net.minecraft.server.command.CommandManager.argument("count", IntegerArgumentType.integer(1)); + RequiredArgumentBuilder days = net.minecraft.server.command.CommandManager.argument("days", StringArgumentType.string() + ); + RequiredArgumentBuilder maxdays = CommandManager.argument("maxdays", string()); + maxdays.executes(context -> makeRentable(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false), IntegerArgumentType.getInteger(context, "count"), getString(context, "days"), getString(context, "maxdays"))); + claim.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if(claim1.rent.getCurrency() !=null || claim1.rent.getAmount() != 0 || claim1.rent.getRentAbleTime() != 0 || claim1.rent.getMaxrentAbleTime() != 0 && claim1.rent.isRentable()) { + context.getSource().sendFeedback(new LiteralText("Can't enable rent for " + claim1.name + ", because no values are set").formatted(Formatting.RED), true); + return 0; + } + if(claim1.rent.getTenant() == null){ + String state = claim1.rent.isRentable() ? "disabled" : "enabled"; + claim1.rent.setRentable(!claim1.rent.isRentable()); + context.getSource().sendFeedback(new LiteralText("Renting for " + claim1.name + " has been " + state).formatted(Formatting.GREEN), true); + return 1; + } else { + context.getSource().sendFeedback(new LiteralText("Can't disable rent for " + claim1.name + ", because it is currently being rented").formatted(Formatting.RED), true); + return 0; + } + }); + + days.then(maxdays); + amount.then(days); + currency.then(amount); + claim.then(currency); + rentable.then(claim); + command.then(rentable); + } + + private static int makeRentable(ServerCommandSource source, Claim claim, ItemStack item, int amount, String rentString, String maxrentString) throws CommandSyntaxException { + int rentTime = TimeUtil.convertStringtoSeconds(rentString); + int maxrentTime = TimeUtil.convertStringtoSeconds(maxrentString); + if(claim != null){ + if(rentTime <= maxrentTime){ + Claim.Rent rent = claim.rent; + rent.setRentable(true); + item.setCount(amount); + rent.setCurrency(item); + rent.setRentAbleTime(rentTime); + if(maxrentTime > Config.rent_maxseconds) maxrentTime = Config.rent_maxseconds; + rent.setMaxrentAbleTime(maxrentTime); + source.sendFeedback(new LiteralText("Claim " + claim.name + " can now be rented for " + amount + " " + item.getName().asString() + " every " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); + return 1; + } + } + return 0; + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java new file mode 100644 index 0000000..910be0c --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java @@ -0,0 +1,87 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.*; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; + +import java.util.HashMap; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class RevenueCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder revenue = literal("revenue"); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + RequiredArgumentBuilder claimRevenue = argument("claimRevenue", BoolArgumentType.bool()); + revenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); + claim.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); + claimRevenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); + claim.then(claimRevenue); + revenue.then(claim); + command.then(revenue); + } + + private static int revenue(ServerCommandSource source, Claim claim, boolean claimrevenue) throws CommandSyntaxException { + //Show subzones (so you can just claim everything in one place) maybe just all claims + if(claim == null){ + source.sendFeedback(Messages.INVALID_CLAIM,true); + return 0; + } + if(!claim.claimBlockOwner.toString().equalsIgnoreCase(source.getPlayer().getUuid().toString())){ + source.sendFeedback(Messages.NO_PERMISSION, true); + return 0; + } + + if(claimrevenue){ + for(ItemStack itemStack : claim.rent.getRevenue()){ + source.getPlayer().inventory.insertStack(itemStack); + } + claim.rent.clearRevenue(); + return 1; + + } else { + if(claim.rent.getRevenue().isEmpty()){ + source.sendFeedback(new LiteralText("No Revenue").formatted(Formatting.RED), true); + return 0; + } + Text text = new LiteralText("Revenue\n").formatted(Formatting.AQUA); + HashMap hashMap = new HashMap<>(); + for(ItemStack itemStack : claim.rent.getRevenue()){ + Item value = itemStack.getItem(); + if(hashMap.containsKey(value)){ + hashMap.put(value, hashMap.get(value) + itemStack.getCount()); + } else { + hashMap.put(value, + itemStack.getCount()); + } + + hashMap.forEach((item, integer) -> { + boolean color = true; + text.append(new LiteralText(String.valueOf(integer)).append(" ").append(new TranslatableText(item.getTranslationKey())).append(" ").formatted(color ? Formatting.GOLD : Formatting.YELLOW)).styled(style -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to claim revenue!").formatted(Formatting.GREEN))); + style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim revenue " + claim.name + " true")); + }); + color = !color; + }); + + } + text.append("\n"); + source.sendFeedback(text, true); + return 1; + } + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java new file mode 100644 index 0000000..acdaf05 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java @@ -0,0 +1,53 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import net.minecraft.server.command.ServerCommandSource; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.SETTINGS_PROVIDER; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.executeSetting; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.querySettings; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class SettingsCommand { + + public static void register(LiteralArgumentBuilder command, boolean admin) { + LiteralArgumentBuilder settings = literal("settings"); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + + if (!admin) { + settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); + + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return querySettings(context.getSource(), claim1); + }); + } + + RequiredArgumentBuilder id = argument("setting", word()).suggests(SETTINGS_PROVIDER); + RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); + + id.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), getString(context, "claim"), true, false, admin)); + set.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); + + id.then(set); + claim.then(id); + settings.then(claim); + command.then(settings); + } + + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java new file mode 100644 index 0000000..63df117 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java @@ -0,0 +1,54 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ClaimShower; +import io.github.indicode.fabric.itsmine.Config; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.util.ShowerUtil.silentHideShow; +import static net.minecraft.server.command.CommandManager.literal; + +public class ShowCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder show = literal("show"); + show.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().dimension.getType()), false)); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + claim.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "name")), false)); + show.then(claim); + command.then(show); + + LiteralArgumentBuilder hide = literal("hide"); + hide.executes(context -> executeShowClaim(context.getSource(), null, true)); + command.then(hide); + } + + public static int executeShowClaim(ServerCommandSource source, Claim claim, boolean reset) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!Config.claims2d &&((ClaimShower)player).getShownClaim() != claim)) executeShowClaim(source, ((ClaimShower)player).getShownClaim(), true); + if (reset && ((ClaimShower)player).getShownClaim() != null) claim = ((ClaimShower)player).getShownClaim(); + if (claim != null) { + if (!claim.dimension.equals(source.getWorld().getDimension().getType())) { + if (claim == ((ClaimShower)player).getShownClaim()) ((ClaimShower)player).setShownClaim(null); // just so we dont have extra packets on this + source.sendFeedback(new LiteralText("That claim is not in this dimension").formatted(Formatting.RED), false); + return 0; + } + source.sendFeedback(new LiteralText((!reset ? "Showing" : "Hiding") + " claim: " + claim.name).formatted(Formatting.GREEN), false); + if(claim.isChild) silentHideShow(player, ClaimUtil.getParentClaim(claim), reset, true); + else silentHideShow(player, claim, reset, true); + + } else { + source.sendFeedback(new LiteralText("That is not a valid claim").formatted(Formatting.RED), false); + } + return 0; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/StickCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/StickCommand.java new file mode 100644 index 0000000..46d1e27 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/StickCommand.java @@ -0,0 +1,30 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import io.github.indicode.fabric.itsmine.ClaimManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; +import net.minecraft.util.Pair; +import net.minecraft.util.math.BlockPos; + +import static net.minecraft.server.command.CommandManager.literal; + +public class StickCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder stick = literal("stick"); + stick.executes(context -> { + Pair posPair = ClaimManager.INSTANCE.stickPositions.get(context.getSource().getPlayer()); + context.getSource().sendFeedback(new LiteralText(posPair == null ? "You can now use a stick to create claims. Run this command again to disable" : "Claim stick disabled. Run this command again to enable").formatted(Formatting.DARK_PURPLE), false); + if (posPair == null) { + ClaimManager.INSTANCE.stickPositions.put(context.getSource().getPlayer(), new Pair<>(null, null)); + } else { + ClaimManager.INSTANCE.stickPositions.remove(context.getSource().getPlayer()); + } + return 0; + }); + command.then(stick); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java new file mode 100644 index 0000000..f6d9e07 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java @@ -0,0 +1,147 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.command.EntitySelector; +import net.minecraft.command.arguments.EntityArgumentType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class TransferCommand { + public static void register(LiteralArgumentBuilder command) { + + LiteralArgumentBuilder transfer = literal("transfer"); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); + LiteralArgumentBuilder confirm = literal("confirm"); + confirm.executes(context -> { + final String string = "-accept-"; + ServerPlayerEntity p = EntityArgumentType.getPlayer(context, "player"); + String input = getString(context, "claim"); + String claimName = input.replace(string, ""); + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(claimName); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + if (input.startsWith(string)) { + return acceptTransfer(context.getSource()); + } + return transfer(context.getSource(), claim1, p, false); + }); + player.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), EntityArgumentType.getPlayer(context, "player"), false)); + player.then(confirm); + claim.then(player); + transfer.then(claim); + transfer.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), EntityArgumentType.getPlayer(context, "player"), false)); + command.then(transfer); + } + + public static int acceptTransfer(ServerCommandSource sender) throws CommandSyntaxException { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(pendingClaimTransfers.get(sender.getPlayer().getGameProfile().getId())); + if (claim == null) { + sender.sendFeedback(new LiteralText("You have no pending claim transfers").formatted(Formatting.RED), false); + return 0; + } + if (sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner) != null) { + sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); + } + Claim.ClaimPermissionMap op = claim.permissionManager.playerPermissions.get(claim.claimBlockOwner); + claim.permissionManager.playerPermissions.put(claim.claimBlockOwner, claim.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); + claim.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op); + claim.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); + claim.children.forEach(subzone -> { + try { + Claim.ClaimPermissionMap op1 = subzone.permissionManager.playerPermissions.get(subzone.claimBlockOwner); + subzone.permissionManager.playerPermissions.put(subzone.claimBlockOwner, subzone.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); + subzone.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op1); + subzone.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); + } catch (CommandSyntaxException e) { + e.printStackTrace(); + } + }); + return 0; + } + + private static int requestTransfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { + if (claim == null) { + sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if(claim.isChild){ + sender.sendFeedback(new LiteralText("You can't transfer ownership of subzones").formatted(Formatting.RED), false); + return 0; + } + if(sender.getPlayer().getUuidAsString().equalsIgnoreCase(player.getUuidAsString())){ + sender.sendFeedback(new LiteralText("Huh? That makes no sence").formatted(Formatting.RED), true); + return 0; + } + if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { + if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { + sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + } else { + sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); + return 0; + } + } + sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to transfer ownership of \"" + claim.name + "\" to " + player.getGameProfile().getName() + "? ").formatted(Formatting.GOLD)) + .append(new LiteralText("[YES]").setStyle(new Style() + .setColor(Formatting.DARK_RED) + .setBold(true) + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")))), false); + return 0; + } + private static Map pendingClaimTransfers = new HashMap<>(); + private static int transfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { + if (claim == null) { + sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return 0; + } + if (claim.isChild) { + sender.sendFeedback(new LiteralText("You can't transfer ownership of subzones").formatted(Formatting.RED), false); + return 0; + } + if (sender.getPlayer().getUuidAsString().equalsIgnoreCase(player.getUuidAsString())) { + sender.sendFeedback(new LiteralText("Huh? That makes no sence").formatted(Formatting.RED), true); + return 0; + } + if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { + if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { + sender.sendFeedback(new LiteralText("Transfering ownership of a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + } else { + sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); + return 0; + } + } + GameProfile profile = sender.getWorld().getServer().getUserCache().getByUuid(claim.claimBlockOwner); + sender.sendFeedback(new LiteralText("Transferring ownership of the claim \"" + claim.name + "\" to " + player.getGameProfile().getName() + " if they accept").formatted(Formatting.GREEN), claim.claimBlockOwner != player.getGameProfile().getId()); + player.sendMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) + .append(new LiteralText("[ACCEPT]").setStyle(new Style() + .setColor(Formatting.GREEN) + .setBold(true) + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim transfer -accept-" + claim.name + " " + player.getEntityName() + " confirm"))))); + pendingClaimTransfers.put(player.getGameProfile().getId(), claim.name); + return 0; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java new file mode 100644 index 0000000..826a439 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java @@ -0,0 +1,85 @@ +package io.github.indicode.fabric.itsmine.command; + +import blue.endless.jankson.annotation.Nullable; +import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import net.minecraft.command.arguments.GameProfileArgumentType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import java.util.Collection; +import java.util.concurrent.atomic.AtomicInteger; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.validateClaim; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.verifyPermission; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class TrustCommand { + public static void register(LiteralArgumentBuilder command) { + { + LiteralArgumentBuilder trust = literal("trust"); + RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, null))); + claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, getString(context, "claim")))); + + playerArgument.then(claimArgument); + trust.then(playerArgument); + command.then(trust); + } + { + LiteralArgumentBuilder distrust = literal("distrust"); + RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + + playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, null))); + claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, getString(context, "claim")))); + + playerArgument.then(claimArgument); + distrust.then(playerArgument); + command.then(distrust); + } + } + private static int executeTrust(CommandContext context, Collection targetCollection, boolean set, @Nullable String claimName) throws CommandSyntaxException { + AtomicInteger integer = new AtomicInteger(); + + if(targetCollection.isEmpty()){ + context.getSource().sendFeedback(new LiteralText("No player provided").formatted(Formatting.RED), true); + return 0; + } + ServerPlayerEntity p = context.getSource().getPlayer(); + Claim claim = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getBlockPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); + validateClaim(claim); + targetCollection.iterator().forEachRemaining(gameProfile -> { + try { + //This is supposed to check if the player has played before :shrug: + if(context.getSource().getMinecraftServer().getUserCache().getByUuid(gameProfile.getId()) == gameProfile){ + integer.set(setTrust(context, claim, gameProfile, set, false)); + } else { + context.getSource().sendFeedback(new LiteralText("Unknown player!").formatted(Formatting.RED), true); + integer.set(0); + } + } catch (CommandSyntaxException e) { + e.printStackTrace(); + } + }); + return integer.get(); + } + static int setTrust(CommandContext context, Claim claim, GameProfile target, boolean set, boolean admin) throws CommandSyntaxException { + if (verifyPermission(claim, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + claim.permissionManager.playerPermissions.put(target.getId(), set ? new Claim.InvertedPermissionMap() : new Claim.DefaultPermissionMap()); + context.getSource().sendFeedback(new LiteralText(target.getName() + (set ? " now" : " no longer") + " has all the permissions").formatted(Formatting.YELLOW), false); + } + return 1; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java new file mode 100644 index 0000000..092aa45 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java @@ -0,0 +1,124 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.HoverEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +import java.util.concurrent.atomic.AtomicInteger; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static net.minecraft.server.command.CommandManager.literal; + +public class TrustedCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder trusted = literal("trusted"); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + trusted.executes((context)-> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim, false); + }); + + claimArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim, false); + }); + trusted.then(claimArgument); + command.then(trusted); + } + + static int showTrustedList(CommandContext context, Claim claim, boolean showSelf) throws CommandSyntaxException { + ServerCommandSource source = context.getSource(); + ServerPlayerEntity player = source.getPlayer(); + int mapSize = claim.permissionManager.playerPermissions.size(); + + if (mapSize == 1 && !showSelf) { + source.sendError(new LiteralText(claim.name + " is not trusting anyone!")); + return -1; + } + + Text text = new LiteralText("\n"); + text.append(new LiteralText("Trusted players for Claim ").formatted(Formatting.YELLOW)) + .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append("\n"); + + AtomicInteger atomicInteger = new AtomicInteger(); + claim.permissionManager.playerPermissions.forEach((uuid, perm) -> { + atomicInteger.incrementAndGet(); + Text pText = new LiteralText(""); + Text owner; + GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); + if (profile != null) { + owner = new LiteralText(profile.getName()); + } else { + owner = new LiteralText(uuid.toString()).styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to Copy"))); + style.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); + }); + } + + pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) + .append(owner.formatted(Formatting.YELLOW)); + + Text hover = new LiteralText(""); + hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); + + int allowed = 0; + int i = 0; + boolean nextColor = false; + Text perms = new LiteralText(""); + + for (Claim.Permission value : Claim.Permission.values()) { + if (claim.permissionManager.hasPermission(uuid, value)) { + Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; + perms.append(new LiteralText(value.id).formatted(formatting)).append(" "); + if (i == 3) perms.append("\n"); + allowed++; + i++; + nextColor = !nextColor; + } + } + + if (allowed == Claim.Permission.values().length) { + hover.append(new LiteralText("All " + allowed + " Permissions").formatted(Formatting.YELLOW, Formatting.ITALIC)); + } else { + hover.append(perms); + } + + pText.append(new LiteralText(" ") + .append(new LiteralText("(").formatted(Formatting.GOLD)) + .append(new LiteralText(String.valueOf(allowed)).formatted(Formatting.GREEN)) + .append(new LiteralText("/").formatted(Formatting.GOLD)) + .append(new LiteralText(String.valueOf(Claim.Permission.values().length)).formatted(Formatting.YELLOW)) + .append(new LiteralText(")").formatted(Formatting.GOLD)) + ); + + pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); + text.append(pText).append("\n"); + }); + + source.sendFeedback(text, false); + return 1; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java new file mode 100644 index 0000000..4d4df91 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java @@ -0,0 +1,48 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.command.ExceptionCommand; +import io.github.indicode.fabric.itsmine.command.PermissionsCommand; +import io.github.indicode.fabric.itsmine.command.SettingsCommand; +import net.minecraft.server.command.ServerCommandSource; + +import java.util.function.Predicate; + +import static net.minecraft.server.command.CommandManager.literal; + +public class AdminCommand { + + public static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { + LiteralArgumentBuilder admin = literal("admin"); + admin.requires(PERMISSION_CHECK_ADMIN); + registerAdmin(admin, dispatcher); + command.then(admin); + } + + private static void registerAdmin(LiteralArgumentBuilder admin, CommandDispatcher dispatcher) { + BlocksCommand.register(admin); + ClaimsCommand.register(admin, dispatcher); + CreateCommand.register(admin); + EntitiesCommand.register(admin); + ExceptionCommand.register(admin, true, false); + ExpandCommand.register(admin); + IgnoreCommand.register(admin); + ListAllCommand.register(admin); + OwnerCommand.register(admin); + PermissionsCommand.register(admin, true); + RemoveCommand.register(admin); + RenameCommand.register(admin); + SettingsCommand.register(admin, true); + } + + private static Predicate perm(String str) { + return perm(str, 2); + } + private static Predicate perm(String str, int op) { + return source -> ItsMine.permissions().hasPermission(source, "itsmine." + str, op); + } + public static final Predicate PERMISSION_CHECK_ADMIN = src -> perm("admin").test(src); + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/BlocksCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/BlocksCommand.java new file mode 100644 index 0000000..473431a --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/BlocksCommand.java @@ -0,0 +1,65 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.command.EntitySelector; +import net.minecraft.command.arguments.EntityArgumentType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class BlocksCommand { + + public static void register(LiteralArgumentBuilder command) { + { + LiteralArgumentBuilder add = literal("addBlocks"); + add.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); + RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); + amount.executes(context -> { + ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); + context.getSource().sendFeedback(new LiteralText("Gave " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); + return 0; + }); + player.then(amount); + add.then(player); + command.then(add); + } + { + LiteralArgumentBuilder remove = literal("removeBlocks"); + remove.requires(source ->ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); + RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); + amount.executes(context -> { + ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), -IntegerArgumentType.getInteger(context, "amount")); + context.getSource().sendFeedback(new LiteralText("Took " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); + return 0; + }); + player.then(amount); + remove.then(player); + command.then(remove); + } + { + LiteralArgumentBuilder set = literal("setBlocks"); + set.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); + RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); + amount.executes(context -> { + ClaimManager.INSTANCE.setClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); + context.getSource().sendFeedback(new LiteralText("Set claim block amount to " + IntegerArgumentType.getInteger(context, "amount")).formatted(Formatting.GREEN), true); + return 0; + }); + player.then(amount); + set.then(player); + command.then(set); + } + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java new file mode 100644 index 0000000..69de7bf --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java @@ -0,0 +1,70 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.HoverEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +import java.util.List; + +import static net.minecraft.server.command.CommandManager.literal; + +public class ClaimsCommand { + public static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { + LiteralArgumentBuilder claims = literal("claims"); + claims.executes(context -> list(context.getSource(), context.getSource().getName())); + dispatcher.register(claims); + } + + public static int list(ServerCommandSource source, String target) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + GameProfile profile = target == null ? player.getGameProfile() : source.getMinecraftServer().getUserCache().findByName(target); + + if (profile == null) { + source.sendError(Messages.INVALID_PLAYER); + return -1; + } + + List claims = ClaimManager.INSTANCE.getPlayerClaims(profile.getId()); + if (claims.isEmpty()) { + source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); + return -1; + } + + + Text text = new LiteralText("\n").append(new LiteralText("Claims (" + target + "): ").formatted(Formatting.GOLD)).append("\n "); + boolean nextColor = false; + for (Claim claim : claims) { + if(!claim.isChild) { + Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { + Text hoverText = new LiteralText("Click for more Info").formatted(Formatting.GREEN); + if (claim.children.size() > 0) { + hoverText.append("\n\nSubzones:"); + for (Claim subzone : claim.children) { + hoverText.append("\n- " + subzone.name); + } + } + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); + + style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); + }); + + nextColor = !nextColor; + text.append(cText.append(" ")); + } + } + + source.sendFeedback(text.append("\n"), false); + return 1; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/CreateCommand.java new file mode 100644 index 0000000..f7ed03c --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/CreateCommand.java @@ -0,0 +1,81 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.builder.ArgumentBuilder; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.command.arguments.BlockPosArgumentType; +import net.minecraft.command.arguments.PosArgument; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; +import net.minecraft.util.Pair; +import net.minecraft.util.math.BlockPos; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static io.github.indicode.fabric.itsmine.command.CreateCommand.createClaim; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class CreateCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder create = literal("create"); + create.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2)); + ArgumentBuilder name = argument("name", word()); + ArgumentBuilder customOwner = argument("customOwnerName", word()); + ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); + RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); + max.executes(context -> createClaim( + getString(context, "name"), + context.getSource(), + BlockPosArgumentType.getBlockPos(context, "min"), + BlockPosArgumentType.getBlockPos(context, "max"), + true, + null + )); + name.executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); + if (selectedPositions == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getLeft() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getRight() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); + } else { + String cname = getString(context, "name"); + if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, null) > 0) { + ClaimManager.INSTANCE.stickPositions.remove(player); + } + } + return 0; + }); + customOwner.executes(context -> { + ServerPlayerEntity player = context.getSource().getPlayer(); + Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); + if (selectedPositions == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getLeft() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); + } else if (selectedPositions.getRight() == null) { + context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); + } else { + String cname = getString(context, "name"); + if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, getString(context, "customOwnerName")) > 0) { + ClaimManager.INSTANCE.stickPositions.remove(player); + } + } + return 0; + }); + min.then(max); + name.then(customOwner); + name.then(min); + create.then(name); + command.then(create); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java new file mode 100644 index 0000000..5810829 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java @@ -0,0 +1,42 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static net.minecraft.server.command.CommandManager.literal; + +public class EntitiesCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder entity = literal("entities"); + entity.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + entity.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); + context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); + claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { + context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); + }); + return 1; + }); + claim.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); + claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { + context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); + }); + return 1; + }); + entity.then(claim); + command.then(entity); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java new file mode 100644 index 0000000..86e7b90 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java @@ -0,0 +1,76 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.util.math.Direction; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.command.ExpandCommand.expand; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getDirections; +import static io.github.indicode.fabric.itsmine.util.DirectionUtil.directionByName; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class ExpandCommand { + + public static void register(LiteralArgumentBuilder command) { + { + LiteralArgumentBuilder expand = literal("expand"); + expand.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = getDirections(); + + direction.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + IntegerArgumentType.getInteger(context, "distance"), + directionByName(getString(context, "direction")), + context.getSource(), + true + )); + + amount.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + IntegerArgumentType.getInteger(context, "distance"), + Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], + context.getSource(), + true + )); + + amount.then(direction); + expand.then(amount); + command.then(expand); + } + { + LiteralArgumentBuilder shrink = literal("shrink"); + shrink.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); + RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); + RequiredArgumentBuilder direction = getDirections(); + + direction.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + -IntegerArgumentType.getInteger(context, "distance"), + directionByName(getString(context, "direction")), + context.getSource(), + true + )); + + amount.executes(context -> expand( + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + -IntegerArgumentType.getInteger(context, "distance"), + Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], + context.getSource(), + true + )); + + amount.then(direction); + shrink.then(amount); + command.then(shrink); + } + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/IgnoreCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/IgnoreCommand.java new file mode 100644 index 0000000..5c11385 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/IgnoreCommand.java @@ -0,0 +1,30 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import java.util.UUID; + +import static net.minecraft.server.command.CommandManager.literal; + +public class IgnoreCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder ignore = literal("ignoreClaims"); + ignore.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_IGNORE_CLAIMS, 2)); + ignore.executes(context -> { + UUID id = context.getSource().getPlayer().getGameProfile().getId(); + boolean isIgnoring = ClaimManager.INSTANCE.ignoringClaims.contains(id); + if (isIgnoring) ClaimManager.INSTANCE.ignoringClaims.remove(id); + else ClaimManager.INSTANCE.ignoringClaims.add(id); + context.getSource().sendFeedback(new LiteralText("You are " + (isIgnoring ? "no longer" : "now") + " ignoring claims.").formatted(Formatting.GREEN), false); + return 0; + }); + command.then(ignore); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java new file mode 100644 index 0000000..fd94c46 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java @@ -0,0 +1,37 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.Claim; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +import java.util.List; + +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getPlayers; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.getClaims; +import static net.minecraft.server.command.CommandManager.literal; + +public class ListAllCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder listall = literal("listall"); + RequiredArgumentBuilder player = getPlayers(); + listall.executes(context -> listall(context.getSource())); + command.then(listall); + } + private static int listall(ServerCommandSource source){ + List claims = getClaims(); + Text text = new LiteralText("\n").append(new LiteralText("Claims").formatted(Formatting.GOLD)).append("\n "); + for (Claim claim : claims) { + Text cText = new LiteralText(claim.name).formatted(Formatting.GOLD); + text.append(cText.append(" ")); + } + source.sendFeedback(text.append("\n"), false); + return 1; + } + + + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java new file mode 100644 index 0000000..3d99a42 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java @@ -0,0 +1,114 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import net.minecraft.command.arguments.GameProfileArgumentType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import java.util.Collection; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class OwnerCommand { + public static void register(LiteralArgumentBuilder command) { + { + LiteralArgumentBuilder set = literal("setOwner"); + RequiredArgumentBuilder newOwner = argument("newOwner", GameProfileArgumentType.gameProfile()); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + + newOwner.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + + Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); + + if (profiles.size() > 1) { + context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); + return -1; + } + return setOwner(context.getSource(), claim, profiles.iterator().next()); + }); + + claimArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + + Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); + + if (profiles.size() > 1) { + context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); + return -1; + } + return setOwner(context.getSource(), claim, profiles.iterator().next()); + }); + + newOwner.then(claimArgument); + set.then(newOwner); + command.then(set); + } + + { + LiteralArgumentBuilder set = literal("setOwnerName"); + RequiredArgumentBuilder nameArgument = argument("newName", word()); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + + nameArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); + if (claim == null) { + context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return -1; + } + return setOwnerName(context.getSource(), claim, getString(context, "newName")); + }); + + claimArgument.executes((context) -> { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim == null) { + context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return -1; + } + return setOwnerName(context.getSource(), claim, getString(context, "newName")); + }); + + nameArgument.then(claimArgument); + set.then(nameArgument); + command.then(set); + } + } + private static int setOwnerName(ServerCommandSource source, Claim claim, String input) { + String name = input.equals("reset") ? null : input; + source.sendFeedback(new LiteralText("Set the Custom Owner Name to ") + .formatted(Formatting.YELLOW).append(new LiteralText(name == null ? "Reset" : name).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) + .append(new LiteralText(claim.customOwnerName == null ? "Not Present" : claim.customOwnerName).formatted(Formatting.GOLD)) + .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) + , false); + claim.customOwnerName = input; + return 1; + } + private static int setOwner(ServerCommandSource source, Claim claim, GameProfile profile) { + GameProfile oldOwner = source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); + source.sendFeedback(new LiteralText("Set the Claim Owner to ") + .formatted(Formatting.YELLOW).append(new LiteralText(profile.getName()).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) + .append(new LiteralText(oldOwner == null ? "(" + claim.claimBlockOwner + ")" : oldOwner.getName()).formatted(Formatting.GOLD)) + .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) + , false); + claim.claimBlockOwner = profile.getId(); + return 1; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java new file mode 100644 index 0000000..5b2f809 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java @@ -0,0 +1,31 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.util.math.BlockPos; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.command.RemoveCommand.delete; +import static io.github.indicode.fabric.itsmine.command.RemoveCommand.requestDelete; +import static net.minecraft.server.command.CommandManager.literal; + +public class RemoveCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder delete = literal("remove"); + delete.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + LiteralArgumentBuilder confirm = literal("confirm"); + confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); + claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); + claim.then(confirm); + delete.then(claim); + delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), true)); + command.then(delete); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RenameCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RenameCommand.java new file mode 100644 index 0000000..1798fcb --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RenameCommand.java @@ -0,0 +1,23 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import net.minecraft.server.command.ServerCommandSource; + +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static io.github.indicode.fabric.itsmine.command.RenameCommand.rename; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class RenameCommand { + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder rename = literal("rename"); + RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); + RequiredArgumentBuilder nameArgument = argument("name", word()); + nameArgument.executes((context) -> rename(context, true)); + claimArgument.then(nameArgument); + rename.then(claimArgument); + command.then(rename); + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java similarity index 72% rename from src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java rename to src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java index 402a428..7083946 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/SubzoneCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java @@ -1,56 +1,68 @@ -package io.github.indicode.fabric.itsmine; +package io.github.indicode.fabric.itsmine.command.subzone; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Config; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; -import net.minecraft.text.Style; import net.minecraft.util.Formatting; import net.minecraft.util.Pair; import net.minecraft.util.math.BlockPos; import org.jetbrains.annotations.Nullable; -import java.text.Format; import java.util.UUID; -public class SubzoneCommand { - private static final String SUB_ZONE_NAME_FORMAT = "%s.%s"; +import static io.github.indicode.fabric.itsmine.command.ShowCommand.executeShowClaim; - public static void register(LiteralArgumentBuilder command, boolean admin) { - LiteralArgumentBuilder builder = CommandManager.literal("subzone"); +public class CreateCommand { + + public static void register(LiteralArgumentBuilder command) { { - LiteralArgumentBuilder add = CommandManager.literal("add"); + LiteralArgumentBuilder create = CommandManager.literal("create"); RequiredArgumentBuilder name = CommandManager.argument("name", StringArgumentType.word()) - .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), null, admin)); + .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), null, false)); - RequiredArgumentBuilder claim = CommandManager.argument("claim", StringArgumentType.word()) - .suggests(ClaimCommand.CLAIM_PROVIDER) - .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), StringArgumentType.getString(ctx, "claim"), admin)); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims() + .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), StringArgumentType.getString(ctx, "claim"), false)); name.then(claim); - add.then(name); - builder.then(add); + create.then(name); + command.then(create); } - - command.then(builder); } private static int addZone(ServerCommandSource source, String name, @Nullable String claimName, boolean admin) throws CommandSyntaxException { - if (name.length() > ClaimCommand.MAX_NAME_LENGTH) { + if (name.length() > 30) { source.sendError(Messages.MSG_LONG_NAME); return -1; } ServerPlayerEntity player = source.getPlayer(); - Claim claim = validateAndGet(source, claimName); + Claim claim = validateAndGet(source, claimName, admin); Claim subZone = null; + if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SUBZONE)) { + throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); + } + if(!name.matches("[A-Za-z0-9]+")){ + source.sendError(new LiteralText("Invalid claim name")); + return -1; + } + + if (ClaimManager.INSTANCE.claimsByName.containsKey(name)) { + source.sendFeedback(new LiteralText("The name \"" + name + "\" is already taken.").formatted(Formatting.RED), false); + return -1; + } Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); if (selectedPositions == null) { source.sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); @@ -59,14 +71,14 @@ private static int addZone(ServerCommandSource source, String name, @Nullable St } else if (selectedPositions.getRight() == null) { source.sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); } else { - name = claim.name + "." + name; - subZone = createSubzone(source, name, selectedPositions.getLeft(), selectedPositions.getRight(), admin); + name = claim.name + "." + name; + subZone = createSubzone(source, name, selectedPositions.getLeft(), selectedPositions.getRight(), admin); if (subZone.dimension == claim.dimension && claim.includesPosition(subZone.min) && claim.includesPosition(subZone.max) && !claim.isChild){ if (!ClaimManager.INSTANCE.wouldSubzoneIntersect((subZone))){ claim.addSubzone(subZone); ClaimManager.INSTANCE.addClaim(subZone); subZone.permissionManager = claim.permissionManager; -// subZone.permissionManager.playerPermissions.put(subZone.claimBlockOwner, new Claim.InvertedPermissionMap()); + executeShowClaim(source, claim, false); source.sendFeedback(new LiteralText("").append(new LiteralText("Your subzone was created.").formatted(Formatting.GREEN)), false); }else{ player.sendMessage(new LiteralText("Your subzone would overlap with another subzone").formatted(Formatting.RED)); @@ -80,7 +92,6 @@ private static int addZone(ServerCommandSource source, String name, @Nullable St player.sendMessage(new LiteralText("Subzone must be inside the original claim, in the same dimension").formatted(Formatting.RED)); } } - return 0; } @@ -117,7 +128,7 @@ private static Claim createSubzone(ServerCommandSource source, String name, Bloc return new Claim(name, admin ? null : ownerID, min, max, source.getWorld().getDimension().getType(), source.getPlayer().getBlockPos(), true); } - private static Claim validateAndGet(ServerCommandSource source, @Nullable String claimName) throws CommandSyntaxException { + private static Claim validateAndGet(ServerCommandSource source, @Nullable String claimName, boolean admin) throws CommandSyntaxException { ServerPlayerEntity player = source.getPlayer(); Claim claim = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); @@ -125,8 +136,10 @@ private static Claim validateAndGet(ServerCommandSource source, @Nullable String if (claim == null) { throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); } + if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SUBZONE)) { + throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); + } return claim; } - } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java new file mode 100644 index 0000000..7d5c8a5 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java @@ -0,0 +1,34 @@ +package io.github.indicode.fabric.itsmine.command.subzone; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import io.github.indicode.fabric.itsmine.command.*; +import net.minecraft.server.command.ServerCommandSource; + +import static net.minecraft.server.command.CommandManager.literal; + +public class SubzoneCommand { + public static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { + LiteralArgumentBuilder subzone = literal("subzone"); + registerSubzone(subzone, dispatcher); + command.then(subzone); + } + + public static void registerSubzone(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { + CreateCommand.register(command); + ExceptionCommand.register(command, false, true); + ExpandCommand.register(command); + InfoCommand.register(command); + PermissionsCommand.register(command, false); + RemoveCommand.register(command); + RenameCommand.register(command); + RentableCommand.register(command); + RentCommand.register(command); + RevenueCommand.register(command); + SettingsCommand.register(command, false); + ShowCommand.register(command); +// SubzoneCommand.register(command, dispatcher); + TrustCommand.register(command); + TrustedCommand.register(command); + } +} \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java new file mode 100644 index 0000000..8c3330a --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java @@ -0,0 +1,49 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import blue.endless.jankson.annotation.Nullable; +import com.mojang.authlib.GameProfile; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; +import net.minecraft.entity.passive.AnimalEntity; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.UUID; + +@Mixin(AnimalEntity.class) +public abstract class AnimalEntityMixin { + + @Shadow private UUID lovingPlayer; + + @Shadow @Nullable + public abstract ServerPlayerEntity getLovingPlayer(); + + @Shadow public abstract void setLoveTicks(int loveTicks); + + @Shadow public abstract void resetLoveTicks(); + + @Inject(method = "canBreedWith", at = @At(value = "HEAD"), cancellable = true) + private void canBreed(AnimalEntity other, CallbackInfoReturnable cir){ + Claim claim = ClaimManager.INSTANCE.getClaimAt(other.getBlockPos(), other.dimension); + if(claim != null){ + if(claim.isChild){ + claim = ClaimUtil.getParentClaim(claim); + } + if(claim.getEntities(other.getEntityWorld().getServer().getWorld(other.getEntityWorld().getDimension().getType())) > 50){ + ServerPlayerEntity player = this.getLovingPlayer(); + if(player != null){ + player.sendMessage(new LiteralText("You reached the entity limit in your claim!").formatted(Formatting.RED)); + } + this.resetLoveTicks(); + cir.setReturnValue(false); + } + } + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java index 3123e47..4829903 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java @@ -1,9 +1,7 @@ package io.github.indicode.fabric.itsmine.mixin; import com.mojang.brigadier.CommandDispatcher; -import io.github.indicode.fabric.itsmine.ClaimCommand; -import io.github.indicode.fabric.itsmine.SubzoneCommand; -import net.minecraft.server.command.CommandManager; +import io.github.indicode.fabric.itsmine.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -14,12 +12,12 @@ /** * @author Indigo Amann */ -@Mixin(CommandManager.class) +@Mixin(net.minecraft.server.command.CommandManager.class) public class CommandManagerMixin { @Shadow private CommandDispatcher dispatcher; @Inject(method = "", at = @At("RETURN")) public void addCommand(boolean bool, CallbackInfo ci) { - ClaimCommand.register(dispatcher); + CommandManager.register(dispatcher); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index ddb55fa..9f5d8ec 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -1,6 +1,7 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.packet.s2c.play.PlaySoundIdS2CPacket; @@ -107,7 +108,7 @@ public void doTickActions(CallbackInfo ci) { World world = player.getEntityWorld(); if (world.getBlockState(player.getBlockPos().down(5)).isAir() && !player.isOnGround()) { - BlockPos pos = Functions.getPosOnGround(player.getBlockPos(), world); + BlockPos pos = ClaimUtil.getPosOnGround(player.getBlockPos(), world); player.teleport(pos.getX(), pos.getY(), pos.getZ()); } } else if ( diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java index efb706b..c6d7d2c 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java @@ -24,9 +24,9 @@ @Mixin(IntegratedServer.class) public class IntegratedServerMixin { @Inject(method = "loadWorld", at = @At("RETURN")) - private void loadClaims(String name, String serverName, long seed, LevelGeneratorOptions arg, CallbackInfo ci) { - File claims = new File(((MinecraftServer)(Object)this).getLevelStorage().getSavesDirectory() + "/" + name + "/claims.dat"); - File claims_old = new File(((MinecraftServer)(Object)this).getLevelStorage().getSavesDirectory() + "/" + name + "/claims.dat_old"); + private void loadClaims(java.lang.String name, long l, LevelGeneratorOptions levelGeneratorOptions, CallbackInfo ci) { + File claims = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat"); + File claims_old = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat_old"); ClaimManager.INSTANCE = new ClaimManager(); if (!claims.exists()) { if (claims_old.exists()) {} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java index 98db24b..b1fa8e0 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java @@ -3,22 +3,26 @@ import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.screen.LecternScreenHandler; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(LecternScreenHandler.class) public abstract class LecternScreenHandlerMixin { - @Redirect(method = "onButtonClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/LecternScreenHandler;onButtonClick(Lnet/minecraft/entity/player/PlayerEntity;I)Z")) - private boolean canTake(LecternScreenHandler lecternScreenHandler, PlayerEntity player, int id) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); - if (claim != null && !claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_LECTERN)) { - player.sendMessage(Messages.MSG_CANT_DO); - return false; - } - return true; - - } + @Inject(method = "onButtonClick", at = @At(value = "HEAD"), cancellable = true) + private void canTake(PlayerEntity player, int id, CallbackInfoReturnable cir){ + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + if(claim != null){ + if(claim.isChild) claim = ClaimUtil.getParentClaim(claim); + if(!claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_LECTERN)){ + player.sendMessage(Messages.MSG_CANT_DO); + cir.setReturnValue(false); + } + } + } } \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java index c617e4f..fc1bfa5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java @@ -26,10 +26,10 @@ @Mixin(MinecraftServer.class) public abstract class MinecraftServerMixin { @Inject(method = "loadWorld", at = @At("RETURN")) - private void loadClaims(String name, String serverName, long seed, LevelGeneratorOptions arg, CallbackInfo ci) { + private void loadClaims(String name, long l, LevelGeneratorOptions levelGeneratorOptions, CallbackInfo ci) { ClaimManager.INSTANCE = new ClaimManager(); - File claims = new File(gameDir.getPath() + "/" + name + "/claims.dat"); - File claims_old = new File(gameDir.getPath() + "/" + name + "/claims.dat_old"); + File claims = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat"); + File claims_old = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat_old"); if (!claims.exists()) { if (claims_old.exists()) {} else return; @@ -51,7 +51,4 @@ private void loadClaims(String name, String serverName, long seed, LevelGenerato } } - @Final - @Shadow - private File gameDir; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java new file mode 100644 index 0000000..02bb931 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/OwnedProjectile.java @@ -0,0 +1,13 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import net.minecraft.entity.projectile.ProjectileEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.UUID; + +@Mixin(ProjectileEntity.class) +public interface OwnedProjectile { + @Accessor("ownerUuid") + UUID getOwner(); +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java index 6f54ede..40736c5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java @@ -1,17 +1,14 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.util.EntityUtil; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityCategory; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.screen.PlayerScreenHandler; -import net.minecraft.text.LiteralText; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.GameRules; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -52,12 +49,14 @@ public void hittingIsRude(Entity entity, CallbackInfo ci) { PlayerEntity playerEntity_1 = (PlayerEntity)(Object)this; Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); - if (claim != null && !EntityUtils.canAttack(((PlayerEntity) (Object) this).getUuid(), claim, entity)) { + if (claim != null && !EntityUtil.canAttack(((PlayerEntity) (Object) this).getUuid(), claim, entity)) { playerEntity_1.sendMessage(Messages.MSG_DAMAGE_ENTITY); ci.cancel(); } } + + // @Redirect(method = "dropInventory", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/GameRules;getBoolean(Lnet/minecraft/world/GameRules$RuleKey;)Z")) // private boolean dontTakeMyThingies(GameRules gameRules, GameRules.RuleKey rule) { // PlayerEntity playerEntity_1 = (PlayerEntity)(Object)this; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java new file mode 100644 index 0000000..db8520d --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java @@ -0,0 +1,42 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import net.minecraft.entity.Entity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.UUID; + +/** + * @author Indigo Amann + */ +@Mixin(ProjectileEntity.class) +public class ProjectileEntityMixin { + @Redirect(method = "onEntityHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")) + public boolean imInvincible(Entity entity, DamageSource damageSource_1, float float_1) { + if (entity.world.isClient()) return entity.damage(damageSource_1, float_1); + ProjectileEntity projectile = (ProjectileEntity)(Object)this; + + if (((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()) != null) { + PlayerEntity playerEntity_1 = ((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); + if (claim != null && entity != playerEntity_1) { + if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY)) { + playerEntity_1.sendMessage(Messages.MSG_DAMAGE_ENTITY); + projectile.kill(); // You do not want an arrow bouncing between two armor stands + return false; + } + } + } + return entity.damage(damageSource_1, float_1); + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index aae0718..beedc32 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -1,6 +1,7 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.util.BlockUtil; import net.minecraft.block.*; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; @@ -41,7 +42,7 @@ private ActionResult interactIfPossible(BlockState blockState, World world, Play if (!Functions.canInteractWith(claim, blockState.getBlock(), player.getUuid())) { if (!itemStack.isEmpty() && !(itemStack.getItem() instanceof BlockItem)) { player.sendMessage(Messages.MSG_INTERACT_BLOCK); - } else if (BlockUtils.isContainer(blockState.getBlock())) { + } else if (BlockUtil.isContainer(blockState.getBlock())) { player.addMessage(Messages.MSG_OPEN_CONTAINER, true); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java index 52621ca..b8da0b3 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java @@ -1,27 +1,47 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Functions; -import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.*; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.Packet; import net.minecraft.server.PlayerManager; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.sound.SoundCategory; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.world.dimension.DimensionType; +import org.apache.logging.log4j.core.jmx.Server; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BooleanSupplier; + /** * @author Indigo Amann */ @Mixin(ServerWorld.class) -public abstract class ServerWorldMixin { -// @Inject(method = "canPlayerModifyAt", at = @At("HEAD"), cancellable = true) +public abstract class ServerWorldMixin implements MonitorableWorld { + @Shadow + @Final + private Map entitiesByUuid; + + @Shadow public abstract List getPlayers(); + + @Shadow public abstract void playGlobalEvent(int type, BlockPos pos, int data); + + // @Inject(method = "canPlayerModifyAt", at = @At("HEAD"), cancellable = true) // private void canMine(PlayerEntity player, BlockPos blockPos_1, CallbackInfoReturnable ci) { // if (player.world.isClient()) return; // Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, player.getEntityWorld().getDimension().getType()); @@ -37,4 +57,43 @@ private void sendPistonUpdate(PlayerManager manager, PlayerEntity playerEntity_1 manager.sendToAround(playerEntity_1, double_1, double_2, double_3, double_4, dimensionType_1, packet_1); Functions.doPistonUpdate((ServerWorld) (Object)this, packet_1); } + + @Inject(method = "tick", at = @At(value = "RETURN")) + public void tickActions(BooleanSupplier shouldKeepTicking, CallbackInfo ci){ + ClaimManager.INSTANCE.claimsByName.forEach((s, claim) ->{ + if(claim.rent.getRentedUntil() != 0){ + if(claim.rent.getRentTimeLeft() < 0){ + System.out.println("Rent expired -> method call"); + this.getPlayers().forEach(serverPlayerEntity -> { + if(serverPlayerEntity.getUuid() == claim.rent.getTenant()){ + serverPlayerEntity.sendMessage(new LiteralText("Rent expired").formatted(Formatting.RED)); + claim.endRent(); + } + }); + } + } + }); + } + +// AtomicReference atomicReference = new AtomicReference<>(); +// public ServerPlayerEntity getPlayerByUUID(UUID uuid){ +// this.getPlayers().forEach(serverPlayerEntity -> { +// if(serverPlayerEntity.getUuid() == uuid) +// atomicReference.set(serverPlayerEntity); +// }); +// return atomicReference.get(); +// } + + @Override + public int loadedEntities() { + if (this.entitiesByUuid == null) + return -1; + + return this.entitiesByUuid.size(); + } + + @Override + public Map EntityList() { + return entitiesByUuid; + } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java new file mode 100644 index 0000000..8fbb447 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java @@ -0,0 +1,181 @@ +package io.github.indicode.fabric.itsmine.util; + +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Config; +import net.minecraft.server.command.CommandSource; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.math.Direction; +import net.minecraft.util.registry.Registry; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static net.minecraft.server.command.CommandManager.argument; + +public class ArgumentUtil { + + + public static RequiredArgumentBuilder getSubAndClaims() { + return argument("claim", word()).suggests(CLAIM__SUBZONE_PROVIDER); + } + + public static RequiredArgumentBuilder getClaims() { + return argument("claim", word()).suggests(ArgumentUtil::claimProvider); + } + + public static RequiredArgumentBuilder getSubzones() { + return argument("subzone", word()).suggests(ArgumentUtil::subzoneProvider); + } + + public static RequiredArgumentBuilder getDirections() { + return argument("direction", word()).suggests(DIRECTION_PROVIDER); + } + + public static RequiredArgumentBuilder getHelpId() { + return argument("id", word()).suggests(HELPID_PROVIDER); + } + + public static RequiredArgumentBuilder getPlayers(){ + return argument("player", word()).suggests(PLAYERS_PROVIDER); + } + + public static RequiredArgumentBuilder getSettings(){ + return argument("setting", word()).suggests(SETTINGS_PROVIDER); + } + public static RequiredArgumentBuilder getMessageEvent(){ + return argument("messageEvent", word()).suggests(MESSAGE_EVENTS_PROVIDER); + } + + public static RequiredArgumentBuilder getEventMessage(){ + return argument("message", word()).suggests(EVENT_MESSAGE_PROVIDER); + } + + + + private static final SuggestionProvider CLAIM__SUBZONE_PROVIDER = (source, builder) -> { + ServerPlayerEntity player = source.getSource().getPlayer(); + List names = new ArrayList<>(); + Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + if (current != null) names.add(current.name); + for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { + if (claim != null) { + System.out.println("Claim " + claim.name); + names.add(claim.name); + } + } + return CommandSource.suggestMatching(names, builder); + }; + + private static CompletableFuture claimProvider(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { + ServerPlayerEntity player = context.getSource().getPlayer(); + List names = new ArrayList<>(); + Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + if (current != null && !current.isChild) names.add(current.name); + for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { + if (claim != null && !claim.isChild) { + names.add(claim.name); + } + } + return CommandSource.suggestMatching(names, builder); + } + + public static CompletableFuture subzoneProvider(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { + ServerPlayerEntity player = context.getSource().getPlayer(); + List names = new ArrayList<>(); + Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + if (current != null && current.isChild) names.add(current.name); + for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { + if (claim != null && claim.isChild) { + names.add(claim.name); + } + } + names.add("Debug"); + return CommandSource.suggestMatching(names, builder); + } + + + private static final SuggestionProvider DIRECTION_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Direction direction: Direction.values()) { + if (Config.claims2d && (direction == Direction.DOWN || direction == Direction.UP)) continue; + strings.add(direction.getName()); + }; + return CommandSource.suggestMatching(strings, builder); + }; + + public static final SuggestionProvider HELPID_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.HelpBook value : Claim.HelpBook.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; + + public static CompletableFuture itemsSuggestion(final CommandContext ctx, final SuggestionsBuilder builder) { + List strings = new ArrayList<>(); + Registry.ITEM.forEach((item) -> { + strings.add(Registry.ITEM.getId(item).getPath()); + }); + + return CommandSource.suggestMatching(strings, builder); + } + + public static final SuggestionProvider PLAYERS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (ServerPlayerEntity player : source.getSource().getMinecraftServer().getPlayerManager().getPlayerList()) { + strings.add(player.getEntityName()); + } + return CommandSource.suggestMatching(strings, builder); + }; + + public static final SuggestionProvider SETTINGS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { + strings.add(value.id); + } + for (Claim.Permission value : Claim.Permission.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; + + public static final SuggestionProvider MESSAGE_EVENTS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.Event value : Claim.Event.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; + public static final SuggestionProvider EVENT_MESSAGE_PROVIDER = (source, builder) -> { + if (!builder.getRemaining().isEmpty()) + return builder.buildFuture(); + + List strings = new ArrayList<>(); + strings.add("reset"); + try { + Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(source, "claim")); + Claim.Event eventType = Claim.Event.getById(getString(source, "messageEvent")); + + if (eventType != null && claim != null) { + String message = eventType == Claim.Event.ENTER_CLAIM ? claim.enterMessage : claim.leaveMessage; + if (message != null) strings.add(message); + } + + } catch (Exception ignored) { + } + + return CommandSource.suggestMatching(strings, builder); + }; + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java b/src/main/java/io/github/indicode/fabric/itsmine/util/BlockUtil.java similarity index 93% rename from src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java rename to src/main/java/io/github/indicode/fabric/itsmine/util/BlockUtil.java index d53eb11..2610140 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/BlockUtils.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/BlockUtil.java @@ -1,8 +1,8 @@ -package io.github.indicode.fabric.itsmine; +package io.github.indicode.fabric.itsmine.util; import net.minecraft.block.*; -public class BlockUtils { +public class BlockUtil { public static boolean isContainer(Block block) { return block instanceof AbstractChestBlock || isChest(block) || isEnderchest(block) || isShulkerBox(block); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java new file mode 100644 index 0000000..f8c0137 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java @@ -0,0 +1,200 @@ +package io.github.indicode.fabric.itsmine.util; + +import blue.endless.jankson.annotation.Nullable; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import io.github.indicode.fabric.itsmine.*; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicReference; + +public class ClaimUtil { + public static BlockPos getPosOnGround(BlockPos pos, World world) { + BlockPos blockPos = new BlockPos(pos.getX(), pos.getY(), pos.getZ()); + + do { + blockPos = blockPos.down(); + if(blockPos.getY() < 1){ + return pos; + } + } while (!world.getBlockState(blockPos).isFullCube(world, pos)); + + return blockPos.up(); + } + + public static Claim getParentClaim(Claim subzone){ + AtomicReference parentClaim = new AtomicReference<>(); + if(subzone.isChild){ + ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> { + for(Claim subzone2 : claim.children){ + if(subzone2 == subzone){ + parentClaim.set(claim); + } + } + }); + return parentClaim.get(); + } + return subzone; + } + + public static void validateClaim(Claim claim) throws CommandSyntaxException { + if (claim == null) throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); + } + + public static boolean verifyPermission(Claim claim, Claim.Permission permission, CommandContext context, boolean admin) throws CommandSyntaxException { + if (verifyExists(claim, context)) { + if (claim.permissionManager.hasPermission(context.getSource().getPlayer().getGameProfile().getId(), permission)) { + return true; + } else { + context.getSource().sendFeedback(new LiteralText(admin ? "You are modifying a claim using admin privileges" : "You cannot modify exceptions for this claim").formatted(admin ? Formatting.DARK_RED : Formatting.RED), false); + return admin; + } + } else { + return false; + } + } + private static boolean verifyExists(Claim claim, CommandContext context) { + if (claim == null) { + context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); + return false; + } else { + return true; + } + } + + public static ArrayList getClaims(){ + ArrayList claims = new ArrayList<>(); + ClaimManager.INSTANCE.claimsByName.forEach((s, claim) -> { + claims.add(claim); + }); + return claims; + } + + public static void validateCanAccess(ServerPlayerEntity player, Claim claim, boolean admin) throws CommandSyntaxException { + if (claim == null) { + throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); + } + + if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SETTINGS)) { + throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); + } + } + + public static int querySetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting) { + boolean enabled = claim.settings.getSetting(setting); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); + return 1; + } + public static int setSetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting, boolean set) { + claim.settings.settings.put(setting, set); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSet setting &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); + return 0; + } + public static int queryPermission(ServerCommandSource source, Claim claim, Claim.Permission permission) { + boolean defaultPerm = claim.permissionManager.defaults.hasPermission(permission); + source.sendFeedback(new LiteralText(ChatColor.translate("&ePermission &6" + permission.id + "&e is set to " + (defaultPerm ? "&a" : "&c") + defaultPerm + "&e for &6" + claim.name)), false); + return 1; + } + public static int setPermission(ServerCommandSource source, Claim claim, Claim.Permission permission, boolean set) { + claim.permissionManager.defaults.setPermission(permission, set); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSet permission &6" + permission.id + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); + return 1; + } + public static int querySettings(ServerCommandSource source, Claim claim) { + source.sendFeedback(new LiteralText("\n").append(new LiteralText("Settings: " + claim.name).formatted(Formatting.YELLOW)).append("\n") + .append(Messages.Command.getSettings(claim)).append("\n"), false); + return 1; + } + public static int executeSetting(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : + ClaimManager.INSTANCE.claimsByName.get(claimName); + if (claim1 == null) { + source.sendError(Messages.INVALID_CLAIM); + return -1; + } + + if (input == null) { + return querySettings(source, claim1); + } + + validateCanAccess(player, claim1, admin); + Claim.ClaimSettings.Setting setting = Claim.ClaimSettings.Setting.byId(input); + Claim.Permission permission = Claim.Permission.byId(input); + + if (setting != null && permission == null) + return isQuery ? querySetting(source, claim1, setting) : setSetting(source, claim1, setting, value); + + if (setting == null && permission != null) + return isQuery ? queryPermission(source, claim1, permission) : setPermission(source, claim1, permission, value); + + source.sendError(Messages.INVALID_SETTING); + return -1; + } + public static int executePermission(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { + ServerPlayerEntity player = source.getPlayer(); + Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : + ClaimManager.INSTANCE.claimsByName.get(claimName); + if (claim1 == null) { + source.sendError(Messages.INVALID_CLAIM); + return -1; + } + + validateCanAccess(player, claim1, admin); + Claim.Permission permission = Claim.Permission.byId(input); + if (permission != null) + return !isQuery ? setPermission(source, claim1, permission, value) : queryPermission(source, claim1, permission); + + source.sendError(Messages.INVALID_SETTING); + return -1; + } + + public static int modifyException(Claim claim, ServerPlayerEntity exception, Claim.Permission permission, boolean allowed) { + claim.permissionManager.setPermission(exception.getGameProfile().getId(), permission, allowed); + return 0; + } + private static int modifyException(Claim claim, String exception, Claim.Permission permission, boolean allowed) { + claim.permissionManager.setPermission(exception, permission, allowed); + return 0; + } + + public static boolean hasPermission(Claim claim, ServerPlayerEntity exception, Claim.Permission permission) { + return claim.permissionManager.hasPermission(exception.getGameProfile().getId(), permission); + } + + public static int setEventMessage(ServerCommandSource source, Claim claim, Claim.Event event, String message) { + switch (event) { + case ENTER_CLAIM: + claim.enterMessage = message.equalsIgnoreCase("reset") ? null : message; + break; + case LEAVE_CLAIM: + claim.leaveMessage = message.equalsIgnoreCase("reset") ? null : message; + break; + } + + if (message.equalsIgnoreCase("reset")) { + source.sendFeedback(new LiteralText("Reset ").append(new LiteralText(event.id).formatted(Formatting.GOLD) + .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) + .append(new LiteralText(claim.name).formatted(Formatting.GOLD))).formatted(Formatting.YELLOW) + , false); + return -1; + } + + source.sendFeedback(new LiteralText("Set ").append(new LiteralText(event.id).formatted(Formatting.GOLD) + .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) + .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" to:").formatted(Formatting.YELLOW))) + .append("\n").append(new LiteralText(ChatColor.translate(message))) + .formatted(Formatting.YELLOW) + , false); + return 1; + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/DirectionUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/DirectionUtil.java new file mode 100644 index 0000000..0663353 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/DirectionUtil.java @@ -0,0 +1,12 @@ +package io.github.indicode.fabric.itsmine.util; + +import net.minecraft.util.math.Direction; + +public class DirectionUtil { + public static Direction directionByName(String name) { + for (Direction direction : Direction.values()) { + if (name.equals(direction.getName())) return direction; + } + return null; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java b/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java similarity index 84% rename from src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java rename to src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java index c113083..0a4160f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/EntityUtils.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java @@ -1,10 +1,11 @@ -package io.github.indicode.fabric.itsmine; +package io.github.indicode.fabric.itsmine.util; +import io.github.indicode.fabric.itsmine.Claim; import net.minecraft.entity.Entity; import java.util.UUID; -public class EntityUtils { +public class EntityUtil { public static boolean canAttack(UUID player, Claim claim, Entity entity) { return claim.hasPermission(player, Claim.Permission.DAMAGE_ENTITY) || @@ -19,4 +20,7 @@ public static boolean isPassive(Entity entity) { public static boolean isHostile(Entity entity) { return !isPassive(entity); } + + + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/NbtUtil.java similarity index 89% rename from src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java rename to src/main/java/io/github/indicode/fabric/itsmine/util/NbtUtil.java index 04e829a..99d44db 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/NBTUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/NbtUtil.java @@ -1,11 +1,11 @@ -package io.github.indicode.fabric.itsmine; +package io.github.indicode.fabric.itsmine.util; import net.minecraft.nbt.CompoundTag; import java.util.UUID; -public class NBTUtil { +public class NbtUtil { public static UUID getUUID(CompoundTag tag, String key){ if (tag.contains(key + "Least") && tag.contains(key + "Most")) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java b/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java similarity index 97% rename from src/main/java/io/github/indicode/fabric/itsmine/Permissions.java rename to src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java index e10ce71..9fbd7d8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Permissions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java @@ -1,6 +1,7 @@ -package io.github.indicode.fabric.itsmine; +package io.github.indicode.fabric.itsmine.util; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.Config; import io.github.indicode.fabric.permissions.PermChangeBehavior; import io.github.indicode.fabric.permissions.Thimble; import net.fabricmc.loader.api.FabricLoader; @@ -17,11 +18,11 @@ import java.util.Locale; import java.util.UUID; -public class Permissions { +public class PermissionUtil { private Manager manager; private boolean present; - public Permissions() { + public PermissionUtil() { Logger logger = (Logger) LogManager.getLogger("ItsMine"); logger.info("Setting up Permissions..."); this.manager = Manager.fromString(Config.permissionManager); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java new file mode 100644 index 0000000..0c9e109 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java @@ -0,0 +1,66 @@ +package io.github.indicode.fabric.itsmine.util; + +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimShower; +import io.github.indicode.fabric.itsmine.mixin.BlockUpdatePacketMixin; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; + +public class ShowerUtil { + + public static void update(Claim claim, ServerWorld world){ + update(claim, world, false); + update(claim, world, true); + } + public static void update(Claim claim, ServerWorld world, boolean hide){ + world.getPlayers().forEach(playerEntity -> { + ClaimUtil.getParentClaim(claim); + if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, hide, false); + }); + } + + public static void silentHideShow(ServerPlayerEntity player, Claim claim, boolean hide, boolean updateStatus) { + if (updateStatus) { + if (!hide) ((ClaimShower) player).setShownClaim(claim); + else ((ClaimShower) player).setShownClaim(null); + } + BlockState block = hide ? null : Blocks.GOLD_BLOCK.getDefaultState(); + showCorners(player, claim, hide, block); + if(!claim.isChild){ + block = hide ? null : Blocks.DIAMOND_BLOCK.getDefaultState(); + for(Claim subzone : claim.children){ + showCorners(player, subzone, hide, block); + } + } + + } + + private static void showCorners(ServerPlayerEntity player, Claim claim, boolean hide, BlockState state){ + state = hide ? null : state; + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); + + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()).south(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()).east(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()).south(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()).north(), player.getEntityWorld())).down(), state); + + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()).east(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()).north(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()).west(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()).west(), player.getEntityWorld())).down(), state); + } + + private static void sendBlockPacket(ServerPlayerEntity player, BlockPos pos, BlockState state) { + BlockUpdateS2CPacket packet = new BlockUpdateS2CPacket(player.world, pos); + if (state != null) ((BlockUpdatePacketMixin)packet).setState(state); + player.networkHandler.sendPacket(packet); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/TimeUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/TimeUtil.java new file mode 100644 index 0000000..35005d6 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/TimeUtil.java @@ -0,0 +1,130 @@ +package io.github.indicode.fabric.itsmine.util; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class TimeUtil { + + private static Pattern timePattern = Pattern.compile("(?:([0-9]+)\\s*y[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*mo[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*w[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*d[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*h[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*m[a-z]*[,\\s]*)?" + "(?:([0-9]+)\\s*(?:s[a-z]*)?)?", Pattern.CASE_INSENSITIVE); + private static final int maxYears = 100000; + private static SimpleCommandExceptionType TIME_ARGUMENT_INVALID = new SimpleCommandExceptionType(new LiteralText("Invalid time argument").formatted(Formatting.RED)); + + + public static String convertSecondsToString(int seconds, char numFormat, char typeFormat) { + int day = seconds / (24 * 3600); + seconds = seconds % (24 * 3600); + int hour = seconds / 3600; + seconds %= 3600; + int min = seconds / 60; + seconds %= 60; + + return ((day != 0) ? "§" + numFormat + day + "§" + typeFormat + " Days " : "") + + ((hour != 0) ? "§" + numFormat + hour + "§" + typeFormat + " Hours " : "") + + ((min != 0) ? "§" + numFormat + min + "§" + typeFormat + " Minutes " : "") + + ((seconds != 0) ? "§" + numFormat + seconds + "§" + typeFormat + " Seconds " : ""); + } + + public static int convertStringtoSeconds(String time) throws CommandSyntaxException { + Calendar c = new GregorianCalendar(); + int current = (int) (c.getTimeInMillis() / 1000); + int until = convertStringtoUnix(time); + return until - current; + } + + public static int convertStringtoUnix(String time) throws CommandSyntaxException { + Date date = new Date(); + Matcher matcher = timePattern.matcher(time); + int years = 0; + int months = 0; + int weeks = 0; + int days = 0; + int hours = 0; + int minutes = 0; + int seconds = 0; + boolean found = false; + while (matcher.find()) { + if (matcher.group() == null || matcher.group().isEmpty()) + continue; + + for (int i = 0; i < matcher.groupCount(); i++) { + if (matcher.group(i) != null && !matcher.group(i).isEmpty()) { + found = true; + break; + } + } + + if (!found) { + throw TIME_ARGUMENT_INVALID.create(); + } + + if (matcher.group(1) != null && !matcher.group(1).isEmpty()) { + years = Integer.parseInt(matcher.group(1)); + } + if (matcher.group(2) != null && !matcher.group(2).isEmpty()) { + months = Integer.parseInt(matcher.group(2)); + } + if (matcher.group(3) != null && !matcher.group(3).isEmpty()) { + weeks = Integer.parseInt(matcher.group(3)); + } + if (matcher.group(4) != null && !matcher.group(4).isEmpty()) { + days = Integer.parseInt(matcher.group(4)); + } + if (matcher.group(5) != null && !matcher.group(5).isEmpty()) { + hours = Integer.parseInt(matcher.group(5)); + } + if (matcher.group(6) != null && !matcher.group(6).isEmpty()) { + minutes = Integer.parseInt(matcher.group(6)); + } + if (matcher.group(7) != null && !matcher.group(7).isEmpty()) { + seconds = Integer.parseInt(matcher.group(7)); + } + break; + } + + Calendar c = new GregorianCalendar(); + if (years > 0) { + if (years > maxYears) { + years = maxYears; + } + c.add(Calendar.YEAR, years); + } + if (months > 0) { + c.add(Calendar.MONTH, months); + } + if (weeks > 0) { + c.add(Calendar.WEEK_OF_YEAR, weeks); + } + if (days > 0) { + c.add(Calendar.DAY_OF_MONTH, days); + } + if (hours > 0) { + c.add(Calendar.HOUR_OF_DAY, hours); + } + if (minutes > 0) { + c.add(Calendar.MINUTE, minutes); + } + if (seconds > 0) { + c.add(Calendar.SECOND, seconds); + } + Calendar max = new GregorianCalendar(); + max.add(Calendar.YEAR, 10); + if (c.after(max)) { + return (int) max.getTimeInMillis() / 1000; + } + + if (date.getTime() == c.getTimeInMillis()) { + throw TIME_ARGUMENT_INVALID.create(); + } + + return (int) (c.getTimeInMillis() / 1000); + } + +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 98abc6f..5e4eba0 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -7,7 +7,8 @@ "description": "Land claims.", "authors": [ "Indicode", - "Maintained by CODY_AI" + "CODY_AI", + "Maintained by DrexHD" ], "contact": { "sources": "https://github.com/GiantNuker/NoGrief/" diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index 585b8d1..d92caaf 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -3,8 +3,8 @@ "package": "io.github.indicode.fabric.itsmine.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ - "MinecraftServerMixin", "WorldSaveHandlerMixin", + "MinecraftServerMixin", "CommandManagerMixin", "BlockUpdatePacketMixin", "BucketItemMixin", @@ -33,6 +33,7 @@ "EnderDragonEntityMixin", "FarmlandBlockMixin", "BoatItemMixin", + "AnimalEntityMixin", "LecternScreenHandlerMixin" ], "client": [ From 3ed1190a39e8a45cacc198f284570b0de637f946 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Mon, 20 Apr 2020 19:32:08 +0200 Subject: [PATCH 65/85] Update to 20w16a --- gradle.properties | 2 +- .../indicode/fabric/itsmine/ClaimCommand.java | 6 +++--- .../github/indicode/fabric/itsmine/Functions.java | 2 +- .../fabric/itsmine/command/CommandManager.java | 3 ++- .../fabric/itsmine/command/CreateCommand.java | 2 +- .../fabric/itsmine/command/ExceptionCommand.java | 9 ++------- .../fabric/itsmine/command/FlyCommand.java | 4 ++-- .../fabric/itsmine/command/TransferCommand.java | 4 ++-- .../fabric/itsmine/command/admin/AdminCommand.java | 3 ++- .../itsmine/command/subzone/CreateCommand.java | 4 ++-- .../itsmine/command/subzone/SubzoneCommand.java | 3 ++- .../fabric/itsmine/mixin/AnimalEntityMixin.java | 2 +- .../fabric/itsmine/mixin/BoatItemMixin.java | 2 +- .../fabric/itsmine/mixin/EnderPearlItemMixin.java | 2 +- .../itsmine/mixin/LecternScreenHandlerMixin.java | 2 +- .../fabric/itsmine/mixin/PlayerEntityMixin.java | 6 +++--- .../itsmine/mixin/ProjectileEntityMixin.java | 2 +- .../mixin/ServerPlayNetworkHandlerMixin.java | 2 +- .../mixin/ServerPlayerInteractionManagerMixin.java | 14 +++++++------- .../fabric/itsmine/mixin/ServerWorldMixin.java | 4 ++-- .../fabric/itsmine/mixin/StickClaimItemMixin.java | 6 +++--- .../mixin/projectile/ProjectileEntityMixin.java | 4 ++-- 22 files changed, 43 insertions(+), 45 deletions(-) diff --git a/gradle.properties b/gradle.properties index 967dbd9..5f0d277 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use minecraft_version=20w16a -yarn_mappings=20w16a+build.4 +yarn_mappings=20w16a+build.9 loader_version=0.7.10+build.191 # Mod Properties diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java index b5cd557..8366b34 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java @@ -1124,7 +1124,7 @@ // checkPlayer(owner, owner.getPlayer().getGameProfile().getId()); // showClaim(owner, claim, false); // if (admin) -// owner.getMinecraftServer().sendMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); +// owner.getMinecraftServer().sendSystemMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); // return 1; // } else { // owner.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + subInt + "(" + (subInt - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); @@ -1252,7 +1252,7 @@ // // GameProfile profile = sender.getWorld().getServer().getUserCache().getByUuid(claim.claimBlockOwner); // sender.sendFeedback(new LiteralText("Transferring ownership of the claim \"" + claim.name + "\" to " + player.getGameProfile().getName() + " if they accept").formatted(Formatting.GREEN), claim.claimBlockOwner != player.getGameProfile().getId()); -// player.sendMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) +// player.sendSystemMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) // .append(new LiteralText("[ACCEPT]").setStyle(new Style() // .setColor(Formatting.GREEN) // .setBold(true) @@ -1267,7 +1267,7 @@ // return 0; // } // if (sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner) != null) { -// sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); +// sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendSystemMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); // } // Claim.ClaimPermissionMap op = claim.permissionManager.playerPermissions.get(claim.claimBlockOwner); // claim.permissionManager.playerPermissions.put(claim.claimBlockOwner, claim.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index e3b4944..acba598 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -133,7 +133,7 @@ public static boolean checkCanDamageWithProjectile(Entity entity, MinecraftServe Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); if (claim != null && owner != null && !claim.hasPermission(owner.getUuid(), Claim.Permission.DAMAGE_ENTITY)) { - owner.sendMessage(Messages.MSG_DAMAGE_ENTITY); + owner.sendSystemMessage(Messages.MSG_DAMAGE_ENTITY); return false; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java index 0c55bd6..096a64d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java @@ -4,6 +4,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import io.github.indicode.fabric.itsmine.command.admin.AdminCommand; import io.github.indicode.fabric.itsmine.command.subzone.SubzoneCommand; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.server.command.ServerCommandSource; import static net.minecraft.server.command.CommandManager.literal; @@ -22,7 +23,7 @@ private static void register(LiteralArgumentBuilder command AdminCommand.register(command, dispatcher); BlockCommand.register(command); CreateCommand.register(command); - ExceptionCommand.register(command, false, false); + ExceptionCommand.register(command, false, ArgumentUtil.getClaims()); ExpandCommand.register(command); FlyCommand.register(command); HelpCommand.register(command); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java index 1c53fb0..474e334 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java @@ -110,7 +110,7 @@ public static int createClaim(String name, ServerCommandSource owner, BlockPos p BlockCommand.blocksLeft(owner); executeShowClaim(owner, claim, false); if (admin) - owner.getMinecraftServer().sendMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); + owner.getMinecraftServer().sendSystemMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); return 1; } else { owner.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + subInt + "(" + (subInt - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java index d046f0b..4c4c055 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java @@ -30,15 +30,10 @@ public class ExceptionCommand { - public static void register(LiteralArgumentBuilder command, boolean admin, boolean subzone) { + public static void register(LiteralArgumentBuilder command, boolean admin, RequiredArgumentBuilder argumentBuilder) { { LiteralArgumentBuilder settings = literal("settings"); - RequiredArgumentBuilder claim; - if(subzone){ - claim = ArgumentUtil.getClaims(); - } else { - claim = ArgumentUtil.getSubzones(); - } + RequiredArgumentBuilder claim = argumentBuilder; if (!admin) { settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java index 9ad50af..13b6328 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java @@ -31,11 +31,11 @@ private static int executeSetFly(CommandContext context, bo ServerPlayerEntity player = context.getSource().getPlayer(); if (set) { ClaimManager.INSTANCE.flyers.add(player.getUuid()); - player.addMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN), false); + player.sendSystemMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN)); return 1; } - player.addMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED), false); + player.sendSystemMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED)); ClaimManager.INSTANCE.flyers.remove(player.getUuid()); return -1; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java index f6d9e07..0947c59 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java @@ -65,7 +65,7 @@ public static int acceptTransfer(ServerCommandSource sender) throws CommandSynta return 0; } if (sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner) != null) { - sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); + sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendSystemMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); } Claim.ClaimPermissionMap op = claim.permissionManager.playerPermissions.get(claim.claimBlockOwner); claim.permissionManager.playerPermissions.put(claim.claimBlockOwner, claim.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); @@ -136,7 +136,7 @@ private static int transfer(ServerCommandSource sender, Claim claim, ServerPlaye } GameProfile profile = sender.getWorld().getServer().getUserCache().getByUuid(claim.claimBlockOwner); sender.sendFeedback(new LiteralText("Transferring ownership of the claim \"" + claim.name + "\" to " + player.getGameProfile().getName() + " if they accept").formatted(Formatting.GREEN), claim.claimBlockOwner != player.getGameProfile().getId()); - player.sendMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) + player.sendSystemMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) .append(new LiteralText("[ACCEPT]").setStyle(new Style() .setColor(Formatting.GREEN) .setBold(true) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java index 4d4df91..52ab85d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java @@ -6,6 +6,7 @@ import io.github.indicode.fabric.itsmine.command.ExceptionCommand; import io.github.indicode.fabric.itsmine.command.PermissionsCommand; import io.github.indicode.fabric.itsmine.command.SettingsCommand; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.server.command.ServerCommandSource; import java.util.function.Predicate; @@ -26,7 +27,7 @@ private static void registerAdmin(LiteralArgumentBuilder ad ClaimsCommand.register(admin, dispatcher); CreateCommand.register(admin); EntitiesCommand.register(admin); - ExceptionCommand.register(admin, true, false); + ExceptionCommand.register(admin, true, ArgumentUtil.getClaims()); ExpandCommand.register(admin); IgnoreCommand.register(admin); ListAllCommand.register(admin); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java index 7083946..316565b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java @@ -81,7 +81,7 @@ private static int addZone(ServerCommandSource source, String name, @Nullable St executeShowClaim(source, claim, false); source.sendFeedback(new LiteralText("").append(new LiteralText("Your subzone was created.").formatted(Formatting.GREEN)), false); }else{ - player.sendMessage(new LiteralText("Your subzone would overlap with another subzone").formatted(Formatting.RED)); + player.sendSystemMessage(new LiteralText("Your subzone would overlap with another subzone").formatted(Formatting.RED)); } if (subZone != null) { ClaimManager.INSTANCE.stickPositions.remove(player); @@ -89,7 +89,7 @@ private static int addZone(ServerCommandSource source, String name, @Nullable St } return 0; }else{ - player.sendMessage(new LiteralText("Subzone must be inside the original claim, in the same dimension").formatted(Formatting.RED)); + player.sendSystemMessage(new LiteralText("Subzone must be inside the original claim, in the same dimension").formatted(Formatting.RED)); } } return 0; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java index 7d5c8a5..a206975 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java @@ -3,6 +3,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import io.github.indicode.fabric.itsmine.command.*; +import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.server.command.ServerCommandSource; import static net.minecraft.server.command.CommandManager.literal; @@ -16,7 +17,7 @@ public static void register(LiteralArgumentBuilder command, public static void registerSubzone(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { CreateCommand.register(command); - ExceptionCommand.register(command, false, true); + ExceptionCommand.register(command, false, ArgumentUtil.getSubzones()); ExpandCommand.register(command); InfoCommand.register(command); PermissionsCommand.register(command, false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java index 8c3330a..2711e43 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java @@ -39,7 +39,7 @@ private void canBreed(AnimalEntity other, CallbackInfoReturnable cir){ if(claim.getEntities(other.getEntityWorld().getServer().getWorld(other.getEntityWorld().getDimension().getType())) > 50){ ServerPlayerEntity player = this.getLovingPlayer(); if(player != null){ - player.sendMessage(new LiteralText("You reached the entity limit in your claim!").formatted(Formatting.RED)); + player.sendSystemMessage(new LiteralText("You reached the entity limit in your claim!").formatted(Formatting.RED)); } this.resetLoveTicks(); cir.setReturnValue(false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java index e6ca2c8..7dd61b6 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java @@ -37,7 +37,7 @@ private void dontSpawn(World world, PlayerEntity user, Hand hand, CallbackInfoRe Claim claim = ClaimManager.INSTANCE.getClaimAt(new BlockPos(pos.getX(), pos.getY(), pos.getZ()), user.dimension); if (claim != null && !claim.hasPermission(user.getUuid(), Claim.Permission.BUILD) || !claim.hasPermission(user.getUuid(), Claim.Permission.SPAWN_BOAT)) { - user.sendMessage(Messages.NO_PERMISSION); + user.sendSystemMessage(Messages.NO_PERMISSION); cir.setReturnValue(TypedActionResult.fail(itemStack)); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java index 2b5a8e1..f8e5a72 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java @@ -23,7 +23,7 @@ private void modifyUse(World world, PlayerEntity user, Hand hand, CallbackInfoRe Claim claim = ClaimManager.INSTANCE.getClaimAt(user.getBlockPos(), user.dimension); if (claim != null && !claim.hasPermission(user.getUuid(), Claim.Permission.USE_ENDER_PEARL)) { - user.sendMessage(Messages.MSG_CANT_USE); + user.sendSystemMessage(Messages.MSG_CANT_USE); cir.setReturnValue(TypedActionResult.fail(itemStack)); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java index b1fa8e0..b7c6be3 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java @@ -20,7 +20,7 @@ private void canTake(PlayerEntity player, int id, CallbackInfoReturnable(posPair.getLeft(), pos); ClaimManager.INSTANCE.stickPositions.put(player, posPair); - player.sendMessage(new LiteralText("Position #2 set: " + pos.getX() + (Config.claims2d ? "" : " " + pos.getY()) + " " + pos.getZ()).formatted(Formatting.GREEN)); + player.sendSystemMessage(new LiteralText("Position #2 set: " + pos.getX() + (Config.claims2d ? "" : " " + pos.getY()) + " " + pos.getZ()).formatted(Formatting.GREEN)); if (posPair.getLeft() != null) { - player.sendMessage(new LiteralText("Area Selected. Type /claim create to create your claim!").formatted(Formatting.GOLD)); + player.sendSystemMessage(new LiteralText("Area Selected. Type /claim create to create your claim!").formatted(Formatting.GOLD)); if (!Config.claims2d) - player.sendMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE, Formatting.ITALIC)); + player.sendSystemMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE, Formatting.ITALIC)); } return false; } @@ -100,7 +100,7 @@ public boolean canBreak(ServerWorld world, PlayerEntity player, BlockPos pos) { if (claim != null) { UUID uuid = player.getGameProfile().getId(); if (!claim.hasPermission(uuid, Claim.Permission.BUILD)) { - player.addMessage(Messages.MSG_BREAK_BLOCK, true); + player.sendSystemMessage(Messages.MSG_BREAK_BLOCK); return false; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java index b8da0b3..fa903c6 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java @@ -47,7 +47,7 @@ public abstract class ServerWorldMixin implements MonitorableWorld { // Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, player.getEntityWorld().getDimension().getType()); // if (claim != null) { // if (!claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.SPAWN_PROTECTION)) { -// player.sendMessage(Messages.NO_PERMISSION); +// player.sendSystemMessage(Messages.NO_PERMISSION); // ci.setReturnValue(false); // } // } @@ -66,7 +66,7 @@ public void tickActions(BooleanSupplier shouldKeepTicking, CallbackInfo ci){ System.out.println("Rent expired -> method call"); this.getPlayers().forEach(serverPlayerEntity -> { if(serverPlayerEntity.getUuid() == claim.rent.getTenant()){ - serverPlayerEntity.sendMessage(new LiteralText("Rent expired").formatted(Formatting.RED)); + serverPlayerEntity.sendSystemMessage(new LiteralText("Rent expired").formatted(Formatting.RED)); claim.endRent(); } }); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java index 18d7b11..74e5941 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java @@ -29,10 +29,10 @@ private void setStickPositionFirst(ItemUsageContext context, CallbackInfoReturna if (posPair == null) return; else posPair = new Pair<>(context.getBlockPos(), posPair.getRight()); ClaimManager.INSTANCE.stickPositions.put(context.getPlayer(), posPair); - context.getPlayer().sendMessage(new LiteralText("Position #1 set: " + context.getBlockPos().getX() + (Config.claims2d ? "" : " " + context.getBlockPos().getY()) + " " + context.getBlockPos().getZ()).formatted(Formatting.GREEN)); + context.getPlayer().sendSystemMessage(new LiteralText("Position #1 set: " + context.getBlockPos().getX() + (Config.claims2d ? "" : " " + context.getBlockPos().getY()) + " " + context.getBlockPos().getZ()).formatted(Formatting.GREEN)); if (posPair.getRight() != null) { - context.getPlayer().sendMessage(new LiteralText("Area Selected. Type /claim create to create your claim!").formatted(Formatting.GOLD)); - if (!Config.claims2d) context.getPlayer().sendMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE, Formatting.ITALIC)); + context.getPlayer().sendSystemMessage(new LiteralText("Area Selected. Type /claim create to create your claim!").formatted(Formatting.GOLD)); + if (!Config.claims2d) context.getPlayer().sendSystemMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE, Formatting.ITALIC)); } cir.setReturnValue(ActionResult.SUCCESS); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java index af7542e..18f72a7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java @@ -28,7 +28,7 @@ private void imInvincible(ProjectileEntity projectileEntity, EntityHitResult ent this.onEntityHit(entityHitResult); } else { if (this.getOwner() instanceof PlayerEntity) { - this.getOwner().sendMessage(Messages.MSG_DAMAGE_ENTITY); + this.getOwner().sendSystemMessage(Messages.MSG_DAMAGE_ENTITY); } } } @@ -41,7 +41,7 @@ private void imInvincible(ProjectileEntity projectileEntity, EntityHitResult ent // Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); // if (claim != null && entity != playerEntity_1) { // if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY)) { -// playerEntity_1.sendMessage(Messages.MSG_DAMAGE_ENTITY); +// playerEntity_1.sendSystemMessage(Messages.MSG_DAMAGE_ENTITY); // projectile.kill(); // You do not want an arrow bouncing between two armor stands // return false; // } From 0381eaefe1d6923ff48982d8af92a88e9e8f2930 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Sun, 26 Apr 2020 11:02:34 +0200 Subject: [PATCH 66/85] Updated to 20w17a --- gradle.properties | 8 +- .../indicode/fabric/itsmine/ClaimCommand.java | 1906 ----------------- .../indicode/fabric/itsmine/Messages.java | 55 +- .../fabric/itsmine/command/BlockCommand.java | 4 +- .../itsmine/command/CommandManager.java | 24 +- .../fabric/itsmine/command/CreateCommand.java | 17 +- .../itsmine/command/ExceptionCommand.java | 63 +- .../fabric/itsmine/command/ExpandCommand.java | 10 +- .../fabric/itsmine/command/HelpCommand.java | 29 +- .../fabric/itsmine/command/InfoCommand.java | 33 +- .../fabric/itsmine/command/RemoveCommand.java | 23 +- .../fabric/itsmine/command/RenameCommand.java | 4 +- .../fabric/itsmine/command/RentCommand.java | 9 +- .../itsmine/command/RentableCommand.java | 12 +- .../itsmine/command/RevenueCommand.java | 13 +- .../itsmine/command/TransferCommand.java | 24 +- .../fabric/itsmine/command/TrustCommand.java | 20 +- .../itsmine/command/TrustedCommand.java | 30 +- .../itsmine/command/admin/AdminCommand.java | 7 +- .../itsmine/command/admin/ClaimsCommand.java | 14 +- .../command/admin/EntitiesCommand.java | 4 +- .../itsmine/command/admin/ListAllCommand.java | 38 +- .../command/subzone/CreateCommand.java | 4 +- .../command/subzone/SubzoneCommand.java | 33 +- .../fabric/itsmine/mixin/ExplosionMixin.java | 15 + .../itsmine/mixin/IntegratedServerMixin.java | 52 - .../mixin/LevelStorageSessionMixin.java | 71 + .../itsmine/mixin/MinecraftServerMixin.java | 54 - .../ServerPlayerInteractionManagerMixin.java | 2 +- .../itsmine/mixin/ServerWorldMixin.java | 19 - .../itsmine/mixin/StickClaimItemMixin.java | 2 +- .../itsmine/mixin/WorldSaveHandlerMixin.java | 46 - .../fabric/itsmine/util/ArgumentUtil.java | 12 +- .../fabric/itsmine/util/ClaimUtil.java | 6 +- .../fabric/itsmine/util/MessageUtil.java | 55 + src/main/resources/itsmine.mixins.json | 6 +- 36 files changed, 404 insertions(+), 2320 deletions(-) delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/WorldSaveHandlerMixin.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java diff --git a/gradle.properties b/gradle.properties index 5f0d277..75c055f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=20w16a -yarn_mappings=20w16a+build.9 +minecraft_version=20w17a +yarn_mappings=20w17a+build.5 loader_version=0.7.10+build.191 # Mod Properties - mod_version = 1.9.0-20W16A + mod_version = 1.9.0-20W17A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine @@ -16,7 +16,7 @@ loader_version=0.7.10+build.191 # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api #fabric_version=0.3.2+build.218-1.14 #26b2bbfb06 -thimble_permissions_version=0.0.8.1 +thimble_permissions_version=0.2.4-20W17A tiny_config_version = 1.1.2 luckperms_version=5.0 #offline_info_version=1a3a7fc98b diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java deleted file mode 100644 index 8366b34..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimCommand.java +++ /dev/null @@ -1,1906 +0,0 @@ -package io.github.indicode.fabric.itsmine; - -/** - * @author Indigo Amann - */ -//public class ClaimCommand { -// public static final int MAX_NAME_LENGTH = 30; -// private static void validateCanAccess(ServerPlayerEntity player, Claim claim, boolean admin) throws CommandSyntaxException { -// if (claim == null) { -// throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); -// } -// -// if (!admin && !claim.permissionManager.hasPermission(player.getGameProfile().getId(), Claim.Permission.MODIFY_SETTINGS)) { -// throw new SimpleCommandExceptionType(Messages.NO_PERMISSION).create(); -// } -// } -// -// private static void validateClaim(Claim claim) throws CommandSyntaxException { -// if (claim == null) throw new SimpleCommandExceptionType(Messages.INVALID_CLAIM).create(); -// } -// -// -// private static Predicate perm(String str) { -// return perm(str, 2); -// } -// private static Predicate perm(String str, int op) { -// return source -> ItsMine.permissions().hasPermission(source, "itsmine." + str, op); -// } -// private static final Predicate PERMISSION_CHECK_ADMIN = src -> perm("admin").test(src) || perm("admin.modify_balance").test(src) || -// perm("admin.infinite_blocks").test(src) || perm("admin.modify").test(src) || -// perm("admin.modify_balance").test(src) || perm("admin.ignore_claims").test(src) || -// perm("admin.modify_permissions").test(src); -// - -// public static final SuggestionProvider PLAYERS_PROVIDER = (source, builder) -> { -// List strings = new ArrayList<>(); -// for (ServerPlayerEntity player : source.getSource().getMinecraftServer().getPlayerManager().getPlayerList()) { -// strings.add(player.getEntityName()); -// } -// return CommandSource.suggestMatching(strings, builder); -// }; -// public static final SuggestionProvider SETTINGS_PROVIDER = (source, builder) -> { -// List strings = new ArrayList<>(); -// for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { -// strings.add(value.id); -// } -// for (Claim.Permission value : Claim.Permission.values()) { -// strings.add(value.id); -// } -// return CommandSource.suggestMatching(strings, builder); -// }; -// public static final SuggestionProvider PERMISSIONS_PROVIDER = (source, builder) -> { -// List strings = new ArrayList<>(); -// for (Claim.Permission value : Claim.Permission.values()) { -// strings.add(value.id); -// } -// return CommandSource.suggestMatching(strings, builder); -// }; -// public static final SuggestionProvider MESSAGE_EVENTS_PROVIDER = (source, builder) -> { -// List strings = new ArrayList<>(); -// for (Claim.Event value : Claim.Event.values()) { -// strings.add(value.id); -// } -// return CommandSource.suggestMatching(strings, builder); -// }; -// public static final SuggestionProvider EVENT_MESSAGE_PROVIDER = (source, builder) -> { -// if (!builder.getRemaining().isEmpty()) -// return builder.buildFuture(); -// -// List strings = new ArrayList<>(); -// strings.add("reset"); -// try { -// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(source, "claim")); -// Claim.Event eventType = Claim.Event.getById(getString(source, "messageEvent")); -// -// if (eventType != null && claim != null) { -// String message = eventType == Claim.Event.ENTER_CLAIM ? claim.enterMessage : claim.leaveMessage; -// if (message != null) strings.add(message); -// } -// -// } catch (Exception ignored) { -// } -// -// return CommandSource.suggestMatching(strings, builder); -// }; - -// public static void register(CommandDispatcher dispatcher) { -// LiteralArgumentBuilder main = literal("itsmine"); -// main.executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); -// -// register(main, dispatcher); -// -// LiteralArgumentBuilder alias = literal("claim"); -// alias.executes((context) -> sendPage(context.getSource(), Messages.GET_STARTED, 1, "Get Started", "/claim help getStarted %page%")); -// -// register(alias, dispatcher); -// -// dispatcher.register(main); -// dispatcher.register(alias); -// } - -// private static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { -// SubzoneCommand.register(command); - -// { -// LiteralArgumentBuilder help = literal("help"); -// help.executes((context) -> sendPage(context.getSource(), Messages.HELP, 1, "Its Mine!", "/claim help commands %page%")); -// -// RequiredArgumentBuilder id = getHelpId(); -// RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); -// -// page.executes((context) -> { -// Claim.HelpBook book = Claim.HelpBook.getById(getString(context, "id")); -// if (book == null) { -// context.getSource().sendError(new LiteralText("Invalid Book!")); -// return -1; -// } -// int p = IntegerArgumentType.getInteger(context, "page"); -// -// if (p > book.texts.length) p = 1; -// return sendPage(context.getSource(), book.texts, p, book.title, book.getCommand()); -// }); -// -// id.then(page); -// help.then(id); -// command.then(help); -// } -// { -// LiteralArgumentBuilder create = literal("create"); -// RequiredArgumentBuilder name = argument("name", word()); -// -// name.executes(context -> { -// ServerPlayerEntity player = context.getSource().getPlayer(); -// Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); -// if (selectedPositions == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); -// } else if (selectedPositions.getLeft() == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); -// } else if (selectedPositions.getRight() == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); -// } else { -// String cname = getString(context, "name"); -// if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), false, null) > 0) { -// ClaimManager.INSTANCE.stickPositions.remove(player); -// } -// } -// return 0; -// }); -// -// ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); -// RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); -// max.executes(context -> createClaim( -// getString(context, "name"), -// context.getSource(), -// BlockPosArgumentType.getBlockPos(context, "min"), -// BlockPosArgumentType.getBlockPos(context, "max"), -// false, -// null -// )); -// min.then(max); -// name.then(min); -// create.then(name); -// command.then(create); -// } -// { -// LiteralArgumentBuilder fly = literal("fly") -// .requires(src -> ItsMine.permissions().hasPermission(src, PermissionUtil.Command.CLAIM_FLY, 2)); -// RequiredArgumentBuilder setArgument = CommandManager.argument("set", BoolArgumentType.bool()); -// -// fly.executes((context) -> setFly(context, !ClaimManager.INSTANCE.flyers.contains(context.getSource().getPlayer().getUuid()))); -// setArgument.executes((context) -> setFly(context, BoolArgumentType.getBool(context, "set"))); -// -// fly.then(setArgument); -// command.then(fly); -// } -// { -// LiteralArgumentBuilder rename = literal("rename"); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); -// RequiredArgumentBuilder nameArgument = argument("name", word()); -// nameArgument.executes((context) -> rename(context, false)); -// claimArgument.then(nameArgument); -// rename.then(claimArgument); -// command.then(rename); -// } -// { -// LiteralArgumentBuilder trusted = literal("trusted"); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); -// trusted.executes((context)-> { -// ServerPlayerEntity player = context.getSource().getPlayer(); -// Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); -// if (claim == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// return showTrustedList(context, claim, false); -// }); -// -// claimArgument.executes((context) -> { -// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (claim == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// return showTrustedList(context, claim, false); -// }); -// trusted.then(claimArgument); -// command.then(trusted); -// dispatcher.register(trusted); -// } -// { -// LiteralArgumentBuilder stick = literal("stick"); -// stick.executes(context -> { -// Pair posPair = ClaimManager.INSTANCE.stickPositions.get(context.getSource().getPlayer()); -// context.getSource().sendFeedback(new LiteralText(posPair == null ? "You can now use a stick to create claims. Run this command again to disable" : "Claim stick disabled. Run this command again to enable").formatted(Formatting.DARK_PURPLE), false); -// if (posPair == null) { -// ClaimManager.INSTANCE.stickPositions.put(context.getSource().getPlayer(), new Pair<>(null, null)); -// } else { -// ClaimManager.INSTANCE.stickPositions.remove(context.getSource().getPlayer()); -// } -// return 0; -// }); -// command.then(stick); -// } -// { -// LiteralArgumentBuilder show = literal("show"); -// show.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().dimension.getType()), false)); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// claim.executes(context -> showClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "name")), false)); -// show.then(claim); -// command.then(show); -// } -// { -// LiteralArgumentBuilder hide = literal("hide"); -// hide.executes(context -> showClaim(context.getSource(), null, true)); -// command.then(hide); -// } -// { -// LiteralArgumentBuilder check = literal("blocks"); -// RequiredArgumentBuilder other = argument("player", EntityArgumentType.player()); -// other.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); -// other.executes(ctx -> checkPlayer(ctx.getSource(), EntityArgumentType.getPlayer(ctx, "player").getGameProfile().getId())); -// check.then(other); -// check.executes(ctx -> checkPlayer(ctx.getSource(), ctx.getSource().getPlayer().getGameProfile().getId())); -// command.then(check); -// } -// { -// LiteralArgumentBuilder delete = literal("remove"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// LiteralArgumentBuilder confirm = literal("confirm"); -// confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); -// claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); -// claim.then(confirm); -// delete.then(claim); -// delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); -// command.then(delete); -// } -// { -// { -// LiteralArgumentBuilder expand = literal("expand"); -// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); -// RequiredArgumentBuilder direction = getDirections(); -// -// direction.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// IntegerArgumentType.getInteger(context, "distance"), -// directionByName(getString(context, "direction")), -// context.getSource(), -// false -// )); -// -// amount.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// IntegerArgumentType.getInteger(context, "distance"), -// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], -// context.getSource(), -// false -// )); -// -// amount.then(direction); -// expand.then(amount); -// command.then(expand); -// } -// { -// LiteralArgumentBuilder shrink = literal("shrink"); -// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); -// RequiredArgumentBuilder direction = getDirections(); -// -// direction.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// -IntegerArgumentType.getInteger(context, "distance"), -// directionByName(getString(context, "direction")), -// context.getSource(), -// false -// )); -// -// amount.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// -IntegerArgumentType.getInteger(context, "distance"), -// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], -// context.getSource(), -// false -// )); -// -// amount.then(direction); -// shrink.then(amount); -// command.then(shrink); -// } -// } -// { -// LiteralArgumentBuilder delete = literal("remove"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// LiteralArgumentBuilder confirm = literal("confirm"); -// confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); -// claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); -// claim.then(confirm); -// delete.then(claim); -// delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); -// command.then(delete); -// } -// { -// LiteralArgumentBuilder transfer = literal("transfer"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); -// LiteralArgumentBuilder confirm = literal("confirm"); -// confirm.executes(context -> { -// final String string = "-accept-"; -// ServerPlayerEntity p = EntityArgumentType.getPlayer(context, "player"); -// String input = getString(context, "claim"); -// String claimName = input.replace(string, ""); -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(claimName); -// if (claim1 == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// -// if (input.startsWith(string)) { -// return acceptTransfer(context.getSource()); -// } -// -// return transfer(context.getSource(), claim1, p, false); -// }); -// player.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), EntityArgumentType.getPlayer(context, "player"), false)); -// player.then(confirm); -// claim.then(player); -// transfer.then(claim); -// transfer.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), EntityArgumentType.getPlayer(context, "player"), false)); -// command.then(transfer); -// } -// { -// ///claim rentable [] -// LiteralArgumentBuilder rentable = literal("rentable"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// -// RequiredArgumentBuilder currency = CommandManager.argument("item", ItemStackArgumentType.itemStack()).suggests(ClaimCommand::itemsSuggestion); -// RequiredArgumentBuilder amount = CommandManager.argument("count", IntegerArgumentType.integer(1)); -// RequiredArgumentBuilder days = CommandManager.argument("days", StringArgumentType.string() -// ); -// RequiredArgumentBuilder maxdays = CommandManager.argument("maxdays", string()); -// maxdays.executes(context -> makeRentable(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false), IntegerArgumentType.getInteger(context, "count"), getString(context, "days"), getString(context, "maxdays"))); -// claim.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if(claim1.rent.getCurrency() !=null || claim1.rent.getAmount() != 0 || claim1.rent.getRentAbleTime() != 0 || claim1.rent.getMaxrentAbleTime() != 0 && claim1.rent.isRentable()) { -// context.getSource().sendFeedback(new LiteralText("Can't enable rent for " + claim1.name + ", because no values are set").formatted(Formatting.RED), true); -// return 0; -// } -// if(claim1.rent.getTenant() == null){ -// String state = claim1.rent.isRentable() ? "disabled" : "enabled"; -// claim1.rent.setRentable(!claim1.rent.isRentable()); -// context.getSource().sendFeedback(new LiteralText("Renting for " + claim1.name + " has been " + state).formatted(Formatting.GREEN), true); -// return 1; -// } else { -// context.getSource().sendFeedback(new LiteralText("Can't disable rent for " + claim1.name + ", because it is currently being rented").formatted(Formatting.RED), true); -// return 0; -// } -// }); -// -// days.then(maxdays); -// amount.then(days); -// currency.then(amount); -// claim.then(currency); -// rentable.then(claim); -// command.then(rentable); -// } -// { -// LiteralArgumentBuilder rent = literal("rent"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// RequiredArgumentBuilder days = CommandManager.argument("days", string()); -// days.executes(context -> rent(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), getString(context, "days"))); -// -// claim.then(days); -// rent.then(claim); -// command.then(rent); -// } -// { -// LiteralArgumentBuilder info = literal("info"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// info.executes(context -> info( -// context.getSource(), -// ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()) -// )); -// claim.executes(context -> info(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")) -// )); -// info.then(claim); -// command.then(info); -// } -// { -// LiteralArgumentBuilder revenue = literal("revenue"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// RequiredArgumentBuilder claimRevenue = argument("claimRevenue", BoolArgumentType.bool()); -// revenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); -// claim.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); -// claimRevenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); -// claim.then(claimRevenue); -// revenue.then(claim); -// command.then(revenue); -// } -// { -// LiteralArgumentBuilder list = literal("list"); -// LiteralArgumentBuilder listall = literal("listall"); -// RequiredArgumentBuilder player = argument("player", word()); -// player.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); -// player.suggests(PLAYERS_PROVIDER); -// list.executes(context -> list(context.getSource(), context.getSource().getName())); -// listall.executes(context -> listall(context.getSource())); -// player.executes(context -> list(context.getSource(), getString(context, "player"))); -// list.then(player); -// command.then(list); -// command.then(listall); -// -// LiteralArgumentBuilder claims = literal("claims") -// .executes(context -> list(context.getSource(), context.getSource().getName())) -// .then(player); -// dispatcher.register(claims); -// } -// { -// //TODO: FIX THIS -// LiteralArgumentBuilder listall = literal("listall"); -// RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); -// -// listall.executes(context -> listAll(context.getSource(), 1)); -// page.executes(context -> listAll(context.getSource(), IntegerArgumentType.getInteger(context, "page"))); -// listall.then(page); -// command.then(listall); -// } -// { -// LiteralArgumentBuilder trust = literal("trust"); -// RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); -// playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, null))); -// claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, getString(context, "claim")))); -// -// playerArgument.then(claimArgument); -// trust.then(playerArgument); -// command.then(trust); -// dispatcher.register(trust); -// } -// { -// LiteralArgumentBuilder distrust = literal("distrust"); -// RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); -// -// playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, null))); -// claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, getString(context, "claim")))); -// -// playerArgument.then(claimArgument); -// distrust.then(playerArgument); -// command.then(distrust); -// dispatcher.register(distrust); -// } - -// createExceptionCommand(command, false); -// -// { -// LiteralArgumentBuilder admin = literal("admin"); -// admin.requires(PERMISSION_CHECK_ADMIN); -// { -// LiteralArgumentBuilder entity = literal("entities"); -// entity.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// entity.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); -// context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); -// claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { -// context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); -// }); -// return 1; -// }); -// claim.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); -// claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { -// context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); -// }); -// return 1; -// }); -// entity.then(claim); -// admin.then(entity); -// } -// { -// LiteralArgumentBuilder add = literal("addBlocks"); -// add.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); -// RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); -// RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); -// amount.executes(context -> { -// ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); -// context.getSource().sendFeedback(new LiteralText("Gave " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); -// return 0; -// }); -// player.then(amount); -// add.then(player); -// admin.then(add); -// } -// { -// LiteralArgumentBuilder set = literal("setOwner"); -// RequiredArgumentBuilder newOwner = argument("newOwner", GameProfileArgumentType.gameProfile()); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); -// -// newOwner.executes((context) -> { -// Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); -// if (claim == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// -// Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); -// -// if (profiles.size() > 1) { -// context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); -// return -1; -// } -// return setOwner(context.getSource(), claim, profiles.iterator().next()); -// }); -// -// claimArgument.executes((context) -> { -// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (claim == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// -// Collection profiles = GameProfileArgumentType.getProfileArgument(context, "newOwner"); -// -// if (profiles.size() > 1) { -// context.getSource().sendError(Messages.TOO_MANY_SELECTIONS); -// return -1; -// } -// return setOwner(context.getSource(), claim, profiles.iterator().next()); -// }); -// -// newOwner.then(claimArgument); -// set.then(newOwner); -// admin.then(set); -// } -// { -// LiteralArgumentBuilder set = literal("setOwnerName"); -// RequiredArgumentBuilder nameArgument = argument("newName", word()); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); -// -// nameArgument.executes((context) -> { -// Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); -// if (claim == null) { -// context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return -1; -// } -// return setOwnerName(context.getSource(), claim, getString(context, "newName")); -// }); -// -// claimArgument.executes((context) -> { -// Claim claim = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (claim == null) { -// context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return -1; -// } -// return setOwnerName(context.getSource(), claim, getString(context, "newName")); -// }); -// -// nameArgument.then(claimArgument); -// set.then(nameArgument); -// admin.then(set); -// } -// { -// LiteralArgumentBuilder rename = literal("rename"); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaimsSubzones(); -// RequiredArgumentBuilder nameArgument = argument("name", word()); -// nameArgument.executes((context) -> rename(context, true)); -// claimArgument.then(nameArgument); -// rename.then(claimArgument); -// admin.then(rename); -// } -// { -// LiteralArgumentBuilder remove = literal("removeBlocks"); -// remove.requires(source ->ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); -// RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); -// RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); -// amount.executes(context -> { -// ClaimManager.INSTANCE.addClaimBlocks(EntityArgumentType.getPlayers(context, "player"), -IntegerArgumentType.getInteger(context, "amount")); -// context.getSource().sendFeedback(new LiteralText("Took " + IntegerArgumentType.getInteger(context, "amount") + " claim blocks").formatted(Formatting.GREEN), true); -// return 0; -// }); -// player.then(amount); -// remove.then(player); -// admin.then(remove); -// } -// { -// LiteralArgumentBuilder set = literal("setBlocks"); -// set.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_BALANCE, 2)); -// RequiredArgumentBuilder player = argument("player", EntityArgumentType.players()); -// RequiredArgumentBuilder amount = argument("amount", IntegerArgumentType.integer()); -// amount.executes(context -> { -// ClaimManager.INSTANCE.setClaimBlocks(EntityArgumentType.getPlayers(context, "player"), IntegerArgumentType.getInteger(context, "amount")); -// context.getSource().sendFeedback(new LiteralText("Set claim block amount to " + IntegerArgumentType.getInteger(context, "amount")).formatted(Formatting.GREEN), true); -// return 0; -// }); -// player.then(amount); -// set.then(player); -// admin.then(set); -// } -// { -// LiteralArgumentBuilder delete = literal("remove"); -// delete.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// LiteralArgumentBuilder confirm = literal("confirm"); -// confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); -// claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); -// claim.then(confirm); -// delete.then(claim); -// delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), true)); -// admin.then(delete); -// } -// { -// LiteralArgumentBuilder create = literal("create"); -// create.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2)); -// ArgumentBuilder name = argument("name", word()); -// ArgumentBuilder customOwner = argument("customOwnerName", word()); -// ArgumentBuilder min = argument("min", BlockPosArgumentType.blockPos()); -// RequiredArgumentBuilder max = argument("max", BlockPosArgumentType.blockPos()); -// max.executes(context -> createClaim( -// getString(context, "name"), -// context.getSource(), -// BlockPosArgumentType.getBlockPos(context, "min"), -// BlockPosArgumentType.getBlockPos(context, "max"), -// true, -// null -// )); -// name.executes(context -> { -// ServerPlayerEntity player = context.getSource().getPlayer(); -// Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); -// if (selectedPositions == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); -// } else if (selectedPositions.getLeft() == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); -// } else if (selectedPositions.getRight() == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); -// } else { -// String cname = getString(context, "name"); -// if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, null) > 0) { -// ClaimManager.INSTANCE.stickPositions.remove(player); -// } -// } -// return 0; -// }); -// customOwner.executes(context -> { -// ServerPlayerEntity player = context.getSource().getPlayer(); -// Pair selectedPositions = ClaimManager.INSTANCE.stickPositions.get(player); -// if (selectedPositions == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select them with a stick.").formatted(Formatting.RED), false); -// } else if (selectedPositions.getLeft() == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #1(Right Click) with a stick.").formatted(Formatting.RED), false); -// } else if (selectedPositions.getRight() == null) { -// context.getSource().sendFeedback(new LiteralText("You need to specify block positions or select position #2(Left Click) with a stick.").formatted(Formatting.RED), false); -// } else { -// String cname = getString(context, "name"); -// if (createClaim(cname, context.getSource(), selectedPositions.getLeft(), selectedPositions.getRight(), true, getString(context, "customOwnerName")) > 0) { -// ClaimManager.INSTANCE.stickPositions.remove(player); -// } -// } -// return 0; -// }); -// min.then(max); -// name.then(customOwner); -// name.then(min); -// create.then(name); -// admin.then(create); -// } -// { -// LiteralArgumentBuilder ignore = literal("ignoreClaims"); -// ignore.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_IGNORE_CLAIMS, 2)); -// ignore.executes(context -> { -// UUID id = context.getSource().getPlayer().getGameProfile().getId(); -// boolean isIgnoring = ClaimManager.INSTANCE.ignoringClaims.contains(id); -// if (isIgnoring) ClaimManager.INSTANCE.ignoringClaims.remove(id); -// else ClaimManager.INSTANCE.ignoringClaims.add(id); -// context.getSource().sendFeedback(new LiteralText("You are " + (isIgnoring ? "no longer" : "now") + " ignoring claims.").formatted(Formatting.GREEN), false); -// return 0; -// }); -// admin.then(ignore); -// } -// { -// { -// LiteralArgumentBuilder expand = literal("expand"); -// expand.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); -// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); -// RequiredArgumentBuilder direction = getDirections(); -// -// direction.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// IntegerArgumentType.getInteger(context, "distance"), -// directionByName(getString(context, "direction")), -// context.getSource(), -// true -// )); -// -// amount.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// IntegerArgumentType.getInteger(context, "distance"), -// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], -// context.getSource(), -// true -// )); -// -// amount.then(direction); -// expand.then(amount); -// admin.then(expand); -// } -// { -// LiteralArgumentBuilder shrink = literal("shrink"); -// shrink.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_INFINITE_CLAIM, 2) && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); -// RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); -// RequiredArgumentBuilder direction = getDirections(); -// -// direction.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// -IntegerArgumentType.getInteger(context, "distance"), -// directionByName(getString(context, "direction")), -// context.getSource(), -// true -// )); -// -// amount.executes(context -> expand( -// ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), -// -IntegerArgumentType.getInteger(context, "distance"), -// Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], -// context.getSource(), -// true -// )); -// -// amount.then(direction); -// shrink.then(amount); -// admin.then(shrink); -// } -// } -// createExceptionCommand(admin, true); -// command.then(admin); -// } -// } - -// private static int sendPage(ServerCommandSource source, Text[] text, int page, String title, String command) { -// int prevPage = page - 2; -// int thisPage = page - 1; -// int nextPage = page + 1; -// final String SEPARATOR = "-----------------------------------------------------"; -// Text header = new LiteralText("") -// .append(new LiteralText("- [ ").formatted(Formatting.GRAY)) -// .append(new LiteralText(title).formatted(Formatting.GOLD)) -// .append(" ] ") -// .append(SEPARATOR.substring(ChatColor.removeAlternateColorCodes('&', title).length() + 4)) -// .formatted(Formatting.GRAY); -// -// Text button_prev = new LiteralText("") -// .append(new LiteralText("<-").formatted(Formatting.WHITE, Formatting.BOLD)) -// .append(" ").append(new LiteralText("Prev").formatted(Formatting.GOLD)) -// .styled((style) -> { -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); -// if (prevPage >= 0) -// style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); -// }); -// -// Text button_next = new LiteralText("") -// .append(new LiteralText("Next").formatted(Formatting.GOLD)) -// .append(" ").append(new LiteralText("->").formatted(Formatting.WHITE, Formatting.BOLD)).append(" ") -// .styled((style) -> { -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); -// if (nextPage <= text.length) -// style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); -// }); -// -// Text buttons = new LiteralText("") -// .append(new LiteralText("[ ").formatted(Formatting.GRAY)) -// .append(button_prev) -// .append(" ") -// .append( -// new LiteralText(String.valueOf(page)).formatted(Formatting.GREEN) -// .append(new LiteralText("/").formatted(Formatting.GRAY)) -// .append(new LiteralText(String.valueOf(text.length)).formatted(Formatting.GREEN)) -// ) -// .append(" ") -// .append(button_next) -// .append(new LiteralText("] ").formatted(Formatting.GRAY)); -// -// Text footer = new LiteralText("- ") -// .formatted(Formatting.GRAY) -// .append(buttons).append(new LiteralText(" ------------------------------").formatted(Formatting.GRAY)); -// -// header.append("\n").append(text[thisPage]).append("\n").append(footer); -// source.sendFeedback(header, false); -// return 1; -// } - -// private static void createExceptionCommand(LiteralArgumentBuilder command, boolean admin) { -// { -// LiteralArgumentBuilder settings = literal("settings"); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// -// if (!admin) { -// settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); -// -// claim.executes((context) -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (claim1 == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// return querySettings(context.getSource(), claim1); -// }); -// } -// -// RequiredArgumentBuilder id = argument("setting", word()).suggests(SETTINGS_PROVIDER); -// RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); -// -// id.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), getString(context, "claim"), true, false, admin)); -// set.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); -// -// id.then(set); -// claim.then(id); -// settings.then(claim); -// command.then(settings); -// } -// -// LiteralArgumentBuilder exceptions = literal("permissions"); -// if (admin) exceptions.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_PERMISSIONS, 2)); -// RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); -// if (!admin) { -// exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); -// -// claim.executes((context) -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (claim1 == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// return showTrustedList(context, claim1, false); -// }); -// } -// -// if (!admin) { -// claim.executes((context) -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (claim1 == null) { -// context.getSource().sendError(new LiteralText("That claim does not exist")); -// return -1; -// } -// return showTrustedList(context, claim1, true); -// }); -// } -// -// { -// RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); -// LiteralArgumentBuilder remove = literal("remove"); -// remove.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { -// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); -// claim1.permissionManager.resetPermissions(player1.getGameProfile().getId()); -// context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + " no longer has an exception in the claim").formatted(Formatting.YELLOW), false); -// } -// return 0; -// }); -// player.then(remove); -// LiteralArgumentBuilder all = literal("*"); -// RequiredArgumentBuilder allstate = argument("allow", BoolArgumentType.bool()); -// allstate.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); -// validateClaim(claim1); -// return setTrust(context, claim1, player1.getGameProfile(), BoolArgumentType.getBool(context, "allow"), admin); -// }); -// all.then(allstate); -// player.then(all); -// for (Claim.Permission value : Claim.Permission.values()) { -// LiteralArgumentBuilder permNode = literal(value.id); -// RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); -// allow.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { -// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); -// boolean permission = BoolArgumentType.getBool(context, "allow"); -// modifyException(claim1, player1, value, permission); -// context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has the permission " + value.name).formatted(Formatting.YELLOW), false); -// } -// return 0; -// }); -// permNode.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { -// ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); -// boolean permission = hasPermission(claim1, player1, value); -// context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); -// } -// return 0; -// }); -// permNode.then(allow); -// player.then(permNode); -// } -// claim.then(player); -// } -// { -// LiteralArgumentBuilder message = literal("message"); -// RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); -// RequiredArgumentBuilder messageEvent = argument("messageEvent", word()) -// .suggests(MESSAGE_EVENTS_PROVIDER); -// RequiredArgumentBuilder messageArgument = argument("message", greedyString()) -// .suggests(EVENT_MESSAGE_PROVIDER); -// -// messageArgument.executes(context -> { -// Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); -// if (verifyPermission(claim1, Claim.Permission.MODIFY_PROPERTIES, context, admin)) { -// Claim.Event event = Claim.Event.getById(getString(context, "messageEvent")); -// -// if (event == null) { -// context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); -// return -1; -// } -// -// return setEventMessage(context.getSource(), claim1, event, getString(context, "message")); -// } -// -// return -1; -// }); -// -// messageEvent.then(messageArgument); -// claimArgument.then(messageEvent); -// message.then(claimArgument); -// command.then(message); -// } -// -// -// exceptions.then(claim); -// command.then(exceptions); -// } -// private static boolean verifyPermission(Claim claim, Claim.Permission permission, CommandContext context, boolean admin) throws CommandSyntaxException { -// if (verifyExists(claim, context)) { -// if (claim.permissionManager.hasPermission(context.getSource().getPlayer().getGameProfile().getId(), permission)) { -// return true; -// } else { -// context.getSource().sendFeedback(new LiteralText(admin ? "You are modifying a claim using admin privileges" : "You cannot modify exceptions for this claim").formatted(admin ? Formatting.DARK_RED : Formatting.RED), false); -// return admin; -// } -// } else { -// return false; -// } -// } -// private static boolean verifyExists(Claim claim, CommandContext context) { -// if (claim == null) { -// context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return false; -// } else { -// return true; -// } -// } - -// private static int makeRentable(ServerCommandSource source, Claim claim, ItemStack item, int amount, String rentString, String maxrentString) throws CommandSyntaxException { -// int rentTime = TimeUtil.convertStringtoSeconds(rentString); -// int maxrentTime = TimeUtil.convertStringtoSeconds(maxrentString); -// if(claim != null){ -// if(rentTime <= maxrentTime){ -// Claim.Rent rent = claim.rent; -// rent.setRentable(true); -// item.setCount(amount); -// rent.setCurrency(item); -// rent.setRentAbleTime(rentTime); -// if(maxrentTime > Config.rent_maxseconds) maxrentTime = Config.rent_maxseconds; -// rent.setMaxrentAbleTime(maxrentTime); -// source.sendFeedback(new LiteralText("Claim " + claim.name + " can now be rented for " + amount + " " + item.getName().asString() + " every " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); -// return 1; -// } -// } -// return 0; -// } - -// private static int rent(ServerCommandSource source, Claim claim, String rentString) throws CommandSyntaxException { -// if(claim == null){ -// source.sendFeedback(Messages.INVALID_CLAIM, true); -// return 0; -// } -// int rentTime = (int) TimeUtil.convertStringtoSeconds(rentString); -// int rentAbleTime = claim.rent.getRentAbleTime(); -// int maxrentAbleTime = claim.rent.getMaxrentAbleTime(); -// ItemStack currency = claim.rent.getCurrency(); -// ItemStack handItem = source.getPlayer().inventory.getMainHandStack(); -// ItemStack revenue = handItem.copy(); -// if(rentTime % claim.rent.getRentAbleTime() != 0){ -// source.sendFeedback(new LiteralText("You have to rent this claim for a time by a multiple of " + TimeUtil.convertSecondsToString(rentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); -// return 0; -// } -// int rentAmount = rentTime / claim.rent.getRentAbleTime(); -// if(currency.getItem() != handItem.getItem() || handItem.getCount() < claim.rent.getAmount() * rentAmount){ -// source.sendFeedback(new LiteralText("You don't have enough " + currency.getName().asString()).formatted(Formatting.RED), true); -// return 0; -// } -// if (!claim.rent.isRentable()) { -// source.sendFeedback(new LiteralText(claim.name + " is not for rent").formatted(Formatting.RED), true); -// return 0; -// } -// if (rentTime > claim.rent.getMaxrentAbleTime()) { -// source.sendFeedback(new LiteralText("You can't rent this claim for longer than " + TimeUtil.convertSecondsToString(maxrentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); -// return 0; -// } -// if(claim.rent.getTenant() == null){ -// //Setup for claim rent -// claim.rent.setTenant(source.getPlayer().getUuid()); -// claim.rent.setRentedUntil(claim.rent.getUnixTime() + rentTime); -// //Remove items from player -// handItem.setCount(handItem.getCount() - claim.rent.getAmount() * rentAmount); -// revenue.setCount(claim.rent.getAmount() * rentAmount); -// claim.rent.addRevenue(revenue); -// //Give Permissions to Tenant -// claim.permissionManager.playerPermissions.put(source.getPlayer().getUuid(), new Claim.InvertedPermissionMap()); -// source.sendFeedback(new LiteralText("Renting " + claim.name + " for " + claim.rent.getAmount() * rentAmount + " " + claim.rent.getCurrency().getName().asString() + " for " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); -// return 1; -// } else if(claim.rent.getTenant().toString().equalsIgnoreCase(source.getPlayer().getUuid().toString())){ -// if (claim.rent.getRentTimeLeft() + rentTime <= maxrentAbleTime) { -// //Setup for claim rent -// claim.rent.setRentedUntil(claim.rent.getUnixTime() + rentTime + claim.rent.getRentTimeLeft()); -// //Remove items from player -// handItem.setCount(handItem.getCount() - claim.rent.getAmount() * rentAmount); -// -// revenue.setCount(claim.rent.getAmount() * rentAmount); -// claim.rent.addRevenue(revenue); -// //Give Permissions to Tenant -// source.sendFeedback(new LiteralText("Extended rent " + claim.name + " by " + TimeUtil.convertSecondsToString(rentTime, '2', 'a') + "for " + claim.rent.getAmount() * rentAmount + " " + claim.rent.getCurrency().getName().asString()).formatted(Formatting.GREEN), true); -// return 1; -// } else { -// source.sendFeedback(new LiteralText("Rent would exceed the limit by " + TimeUtil.convertSecondsToString(claim.rent.getRentTimeLeft() + rentTime - maxrentAbleTime, 'c', 'c')).formatted(Formatting.RED), true); -// return 0; -// } -// } else { -// source.sendFeedback(new LiteralText("This claim is already rented").formatted(Formatting.RED), true); -// return 0; -// } -// } - - - -// public static int showClaim(ServerCommandSource source, Claim claim, boolean reset) throws CommandSyntaxException { -// ServerPlayerEntity player = source.getPlayer(); -// if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!Config.claims2d &&((ClaimShower)player).getShownClaim() != claim)) showClaim(source, ((ClaimShower)player).getShownClaim(), true); -// if (reset && ((ClaimShower)player).getShownClaim() != null) claim = ((ClaimShower)player).getShownClaim(); -// if (claim != null) { -// if (!claim.dimension.equals(source.getWorld().getDimension().getType())) { -// if (claim == ((ClaimShower)player).getShownClaim()) ((ClaimShower)player).setShownClaim(null); // just so we dont have extra packets on this -// source.sendFeedback(new LiteralText("That claim is not in this dimension").formatted(Formatting.RED), false); -// return 0; -// } -// source.sendFeedback(new LiteralText((!reset ? "Showing" : "Hiding") + " claim: " + claim.name).formatted(Formatting.GREEN), false); -// if(claim.isChild) silentHideShow(player, ClaimUtil.getParentClaim(claim), reset, true); -// else silentHideShow(player, claim, reset, true); -// -// } else { -// source.sendFeedback(new LiteralText("That is not a valid claim").formatted(Formatting.RED), false); -// } -// return 0; -// } - -// private static int createClaim(String name, ServerCommandSource owner, BlockPos posA, BlockPos posB, boolean admin, @Nullable String cOwnerName) throws CommandSyntaxException { -// if (name.length() > MAX_NAME_LENGTH) { -// owner.sendError(Messages.MSG_LONG_NAME); -// return -1; -// } -// if(!name.matches("[A-Za-z0-9]+")){ -// owner.sendError(new LiteralText("Invalid claim name")); -// return -1; -// } -// UUID ownerID = owner.getPlayer().getGameProfile().getId(); -// int x, y = 0, z, mx, my = 255, mz; -// if (posA.getX() > posB.getX()) { -// x = posB.getX(); -// mx = posA.getX(); -// } else { -// x = posA.getX(); -// mx = posB.getX(); -// } -// if (!Config.claims2d) { -// if (posA.getY() > posB.getY()) { -// y = posB.getY(); -// my = posA.getY(); -// } else { -// y = posA.getY(); -// my = posB.getY(); -// } -// } -// if (posA.getZ() > posB.getZ()) { -// z = posB.getZ(); -// mz = posA.getZ(); -// } else { -// z = posA.getZ(); -// mz = posB.getZ(); -// } -// BlockPos min = new BlockPos(x, y, z); -// BlockPos max = new BlockPos(mx, my, mz); -// BlockPos sub = max.subtract(min); -// sub = sub.add(1, Config.claims2d ? 0 : 1,1); -// int subInt = sub.getX() * (Config.claims2d ? 1 : sub.getY()) * sub.getZ(); -// -// Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos(), false); -// if (cOwnerName != null) claim.customOwnerName = cOwnerName; -// claim.permissionManager.playerPermissions.put(ownerID, new Claim.InvertedPermissionMap()); -// if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { -// if (!ClaimManager.INSTANCE.wouldIntersect(claim)) { -// // works because only the first statement is evaluated if true -// if ((admin && ItsMine.permissions().hasPermission(owner, PermissionUtil.Command.INFINITE_BLOCKS, 2)) || ClaimManager.INSTANCE.useClaimBlocks(ownerID, subInt)) { -// ClaimManager.INSTANCE.addClaim(claim); -// owner.sendFeedback(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)).append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").setStyle(new Style() -// .setColor(Formatting.GREEN).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))))), false); -// checkPlayer(owner, owner.getPlayer().getGameProfile().getId()); -// showClaim(owner, claim, false); -// if (admin) -// owner.getMinecraftServer().sendSystemMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); -// return 1; -// } else { -// owner.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + subInt + "(" + (subInt - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); -// } -// } else { -// owner.sendFeedback(new LiteralText("Your claim would overlap with another claim").formatted(Formatting.RED), false); -// } -// } else { -// owner.sendFeedback(new LiteralText("The name \"" + name + "\" is already taken.").formatted(Formatting.RED), false); -// } -// return 0; -// } -// private static int checkPlayer(ServerCommandSource ret, UUID player) throws CommandSyntaxException { -// int blocks = ClaimManager.INSTANCE.getClaimBlocks(player); -// ret.sendFeedback(new LiteralText((ret.getPlayer().getGameProfile().getId().equals(player) ? "You have " : "They have ") + blocks + " blocks left").setStyle(new Style() -// .setColor(Formatting.YELLOW)), false); -// return 0; -// } -// private static int requestDelete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { -// if (claim == null) { -// sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return 0; -// } -// if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { -// if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { -// sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); -// } else { -// sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); -// return 0; -// } -// } -// sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to delete the claim \"" + claim.name + "\"? ").formatted(Formatting.GOLD)) -// .append(new LiteralText("[I'M SURE]").setStyle(new Style() -// .setColor(Formatting.DARK_RED) -// .setBold(true) -// .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")))), false); -// return 0; -// } -// private static int delete(ServerCommandSource source, Claim claim, boolean admin) throws CommandSyntaxException { -// ServerWorld world = source.getWorld(); -// if (claim == null) { -// source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return 0; -// } -// if (!claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { -// if (admin && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)) { -// source.sendFeedback(new LiteralText("Deleting a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); -// } else { -// source.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); -// return 0; -// } -// } -// if(!claim.isChild){ -// ClaimManager.INSTANCE.releaseBlocksToOwner(claim); -// ShowerUtil.update(claim, world, true); -// ClaimManager.INSTANCE.claimsByName.remove(claim.name); -// for(Claim subzone : claim.children){ -// ClaimManager.INSTANCE.claimsByName.remove(subzone.name); -// } -// }else{ -// Claim parent = ClaimUtil.getParentClaim(claim); -// ShowerUtil.update(parent, world, true); -// ClaimUtil.getParentClaim(claim).removeSubzone(claim); -// ClaimManager.INSTANCE.claimsByName.remove(claim.name); -// ShowerUtil.update(parent, world, false); -// } -// source.getWorld().getPlayers().forEach(playerEntity -> { -// if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true); -// }); -// source.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)); -// return 0; -// } - - -// private static int requestTransfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { -// if (claim == null) { -// sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return 0; -// } -// if(claim.isChild){ -// sender.sendFeedback(new LiteralText("You can't transfer ownership of subzones").formatted(Formatting.RED), false); -// return 0; -// } -// if(sender.getPlayer().getUuidAsString().equalsIgnoreCase(player.getUuidAsString())){ -// sender.sendFeedback(new LiteralText("Huh? That makes no sence").formatted(Formatting.RED), true); -// return 0; -// } -// if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { -// if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { -// sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); -// } else { -// sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); -// return 0; -// } -// } -// sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to transfer ownership of \"" + claim.name + "\" to " + player.getGameProfile().getName() + "? ").formatted(Formatting.GOLD)) -// .append(new LiteralText("[YES]").setStyle(new Style() -// .setColor(Formatting.DARK_RED) -// .setBold(true) -// .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")))), false); -// return 0; -// } -// private static Map pendingClaimTransfers = new HashMap<>(); -// private static int transfer(ServerCommandSource sender, Claim claim, ServerPlayerEntity player, boolean admin) throws CommandSyntaxException { -// if (claim == null) { -// sender.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return 0; -// } -// if(claim.isChild){ -// sender.sendFeedback(new LiteralText("You can't transfer ownership of subzones").formatted(Formatting.RED), false); -// return 0; -// } -// if(sender.getPlayer().getUuidAsString().equalsIgnoreCase(player.getUuidAsString())){ -// sender.sendFeedback(new LiteralText("Huh? That makes no sence").formatted(Formatting.RED), true); -// return 0; -// } -// if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { -// if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { -// sender.sendFeedback(new LiteralText("Transfering ownership of a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); -// } else { -// sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); -// return 0; -// } -// } -// -// GameProfile profile = sender.getWorld().getServer().getUserCache().getByUuid(claim.claimBlockOwner); -// sender.sendFeedback(new LiteralText("Transferring ownership of the claim \"" + claim.name + "\" to " + player.getGameProfile().getName() + " if they accept").formatted(Formatting.GREEN), claim.claimBlockOwner != player.getGameProfile().getId()); -// player.sendSystemMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) -// .append(new LiteralText("[ACCEPT]").setStyle(new Style() -// .setColor(Formatting.GREEN) -// .setBold(true) -// .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim transfer -accept-" + claim.name + " " + player.getEntityName() + " confirm"))))); -// pendingClaimTransfers.put(player.getGameProfile().getId(), claim.name); -// return 0; -// } -// public static int acceptTransfer(ServerCommandSource sender) throws CommandSyntaxException { -// Claim claim = ClaimManager.INSTANCE.claimsByName.get(pendingClaimTransfers.get(sender.getPlayer().getGameProfile().getId())); -// if (claim == null) { -// sender.sendFeedback(new LiteralText("You have no pending claim transfers").formatted(Formatting.RED), false); -// return 0; -// } -// if (sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner) != null) { -// sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendSystemMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); -// } -// Claim.ClaimPermissionMap op = claim.permissionManager.playerPermissions.get(claim.claimBlockOwner); -// claim.permissionManager.playerPermissions.put(claim.claimBlockOwner, claim.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); -// claim.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op); -// claim.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); -// claim.children.forEach(subzone -> { -// try { -// Claim.ClaimPermissionMap op1 = subzone.permissionManager.playerPermissions.get(subzone.claimBlockOwner); -// subzone.permissionManager.playerPermissions.put(subzone.claimBlockOwner, subzone.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); -// subzone.permissionManager.playerPermissions.put(sender.getPlayer().getGameProfile().getId(), op1); -// subzone.claimBlockOwner = sender.getPlayer().getGameProfile().getId(); -// } catch (CommandSyntaxException e) { -// e.printStackTrace(); -// } -// }); -// return 0; -// } -// private static int modifyException(Claim claim, ServerPlayerEntity exception, Claim.Permission permission, boolean allowed) { -// claim.permissionManager.setPermission(exception.getGameProfile().getId(), permission, allowed); -// return 0; -// } -// private static int modifyException(Claim claim, String exception, Claim.Permission permission, boolean allowed) { -// claim.permissionManager.setPermission(exception, permission, allowed); -// return 0; -// } -// private static boolean hasPermission(Claim claim, ServerPlayerEntity exception, Claim.Permission permission) { -// return claim.permissionManager.hasPermission(exception.getGameProfile().getId(), permission); -// } -// private static boolean hasPermission(Claim claim, String exception, Claim.Permission permission) { -// return claim.permissionManager.hasPermission(exception, permission); -// } -// private static Direction directionByName(String name) { -// for (Direction direction : Direction.values()) { -// if (name.equals(direction.getName())) return direction; -// } -// return null; -// } - -// private static CompletableFuture itemsSuggestion(final CommandContext ctx, final SuggestionsBuilder builder) { -// List strings = new ArrayList<>(); -// Registry.ITEM.forEach((item) -> { -// strings.add(Registry.ITEM.getId(item).getPath()); -// }); -// -// return CommandSource.suggestMatching(strings, builder); -// } - -// private static void undoExpand(Claim claim, Direction direction, int amount){ -// if (amount < 0) claim.expand(direction, -amount); -// else claim.shrink(direction, amount); -// } -// -// private static void sendSize(Claim claim, ServerCommandSource source){ -// Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); -// Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); -// Text pos = new LiteralText(""); -// pos.append(newInfoLine("Position", new LiteralText("") -// .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) -// .append(" ") -// .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); -// source.sendFeedback(pos, true); -// } -// -// private static int expand(Claim claim, int amount, Direction direction, ServerCommandSource source, boolean admin) throws CommandSyntaxException { -// UUID ownerID = source.getPlayer().getGameProfile().getId(); -// if (claim == null) { -// source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return 0; -// } -// if (direction == null) { -// source.sendFeedback(new LiteralText("That is not a valid direction").formatted(Formatting.RED), false); -// return 0; -// } -// if (!claim.permissionManager.hasPermission(ownerID, Claim.Permission.MODIFY_SIZE)) { -// source.sendFeedback(new LiteralText("You do not have border change permissions in that claim").formatted(Formatting.RED), false); -// if (!admin) return 0; -// } -// int oldArea = claim.getArea(); -// System.out.println("Area1 " + claim.getArea()); -// sendSize(claim, source); -// -// if (amount > 0) { -// claim.expand(direction, amount); -// } -// else { -// claim.shrink(direction, -amount); -// } -// -// System.out.println("Area2 " + claim.getArea()); -// sendSize(claim, source); -// -// if (!claim.canShrinkWithoutHittingOtherSide(new BlockPos(direction.getOffsetX() * amount, direction.getOffsetY() * amount, direction.getOffsetZ() * amount))) { -// source.sendFeedback(new LiteralText("You can't shrink your claim that far. It would pass its opposite wall.").formatted(Formatting.RED), false); -// undoExpand(claim, direction, amount); -// return 0; -// } -// -// if(!claim.isChild){ -// if (ClaimManager.INSTANCE.wouldIntersect(claim)) { -// undoExpand(claim, direction, amount); -// source.sendFeedback(new LiteralText("Expansion would result in hitting another claim").formatted(Formatting.RED), false); -// return 0; -// } -// -// //Check if shrinking would reset a subzone to be outside of its parent claim -// AtomicBoolean returnValue = new AtomicBoolean(); -// returnValue.set(false); -// claim.children.forEach(claim1 -> { -//// System.out.println("IsInside2: " + claim1.isInside(claim)); -// if(!claim1.isInside(claim)){ -// System.out.println("Area3 " + claim.getArea()); -// sendSize(claim, source); -// undoExpand(claim, direction, amount); -// System.out.println("Area4 " + claim.getArea()); -// sendSize(claim, source); -// source.sendFeedback(new LiteralText("Shrinking would result in " + claim1.name + " being outside of " + claim.name).formatted(Formatting.RED), true); -// returnValue.set(true); -// } -// }); -// if(returnValue.get()) return 0; -// -// int newArea = claim.getArea() - oldArea; -// if (!admin && claim.claimBlockOwner != null && ClaimManager.INSTANCE.getClaimBlocks(ownerID) < newArea) { -// undoExpand(claim, direction, amount); -// source.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + newArea + "(" + (newArea - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); -// checkPlayer(source, ownerID); -// return 0; -// } else { -// if (!admin && claim.claimBlockOwner != null) ClaimManager.INSTANCE.useClaimBlocks(ownerID, newArea); -// source.sendFeedback(new LiteralText("Your claim was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); -// checkPlayer(source, ownerID); -// undoExpand(claim, direction, amount); -// ShowerUtil.update(claim, source.getWorld(), true); -// if (amount > 0) claim.expand(direction, amount); -// else claim.shrink(direction, -amount); -// ShowerUtil.update(claim, source.getWorld(), false); -// } -// return 0; -// }else{ -// Claim parent = ClaimUtil.getParentClaim(claim); -// if(!claim.isInside(parent)) { -// source.sendFeedback(new LiteralText("Expansion would result in expanding outside of your main claim").formatted(Formatting.RED), false); -// undoExpand(claim, direction, amount); -// } else if(ClaimManager.INSTANCE.wouldSubzoneIntersect((claim))){ -// source.sendFeedback(new LiteralText("Expansion would result in overlapping with another subzone").formatted(Formatting.RED), false); -// undoExpand(claim, direction, amount); -// }else{ -// source.sendFeedback(new LiteralText("Your subzone was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); -// //The expansion is undone to hide the claimshower -// undoExpand(claim, direction, amount); -// ShowerUtil.update(parent, source.getWorld(), true); -// if (amount > 0) claim.expand(direction, amount); -// else claim.shrink(direction, -amount); -// ShowerUtil.update(parent, source.getWorld(), false); -// } -// } -// return 0; -// } - -// private static int revenue(ServerCommandSource source, Claim claim, boolean claimrevenue) throws CommandSyntaxException { -// //Show subzones (so you can just claim everything in one place) maybe just all claims -// if(claim == null){ -// source.sendFeedback(Messages.INVALID_CLAIM,true); -// return 0; -// } -// if(!claim.claimBlockOwner.toString().equalsIgnoreCase(source.getPlayer().getUuid().toString())){ -// source.sendFeedback(Messages.NO_PERMISSION, true); -// return 0; -// } -// -// if(claimrevenue){ -// for(ItemStack itemStack : claim.rent.getRevenue()){ -// source.getPlayer().inventory.insertStack(itemStack); -// } -// claim.rent.clearRevenue(); -// return 1; -// -// } else { -// if(claim.rent.getRevenue().isEmpty()){ -// source.sendFeedback(new LiteralText("No Revenue").formatted(Formatting.RED), true); -// return 0; -// } -// Text text = new LiteralText("Revenue\n").formatted(Formatting.AQUA); -// HashMap hashMap = new HashMap<>(); -// for(ItemStack itemStack : claim.rent.getRevenue()){ -// Item value = itemStack.getItem(); -// if(hashMap.containsKey(value)){ -// hashMap.put(value, hashMap.get(value) + itemStack.getCount()); -// } else { -// hashMap.put(value, + itemStack.getCount()); -// } -// -// hashMap.forEach((item, integer) -> { -// boolean color = true; -// text.append(new LiteralText(String.valueOf(integer)).append(" ").append(new TranslatableText(item.getTranslationKey())).append(" ").formatted(color ? Formatting.GOLD : Formatting.YELLOW)).styled(style -> { -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to claim revenue!").formatted(Formatting.GREEN))); -// style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim revenue " + claim.name + " true")); -// }); -// color = !color; -// }); -// -// } -// text.append("\n"); -// source.sendFeedback(text, true); -// return 1; -// } -// } - -// private static int info(ServerCommandSource source, Claim claim) throws CommandSyntaxException { -// if (claim == null) { -// source.sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); -// return 0; -// } -// -// GameProfile owner = claim.claimBlockOwner == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); -// BlockPos size = claim.getSize(); -// -// Text text = new LiteralText("\n"); -// text.append(new LiteralText("Claim Info: " + claim.name).formatted(Formatting.GOLD)).append("\n"); -// text.append(newInfoLine("Name", new LiteralText(claim.name).formatted(Formatting.WHITE))); -// text.append(newInfoLine("Entities", new LiteralText(String.valueOf(claim.getEntities(source.getWorld()))).formatted(Formatting.AQUA))); -// text.append(newInfoLine("Owner", -// owner != null && claim.customOwnerName == null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : -// claim.customOwnerName != null ? new LiteralText(claim.customOwnerName).formatted(Formatting.GOLD) : -// new LiteralText("No Owner").formatted(Formatting.RED, Formatting.ITALIC))); -// text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); -// -// -// text.append(new LiteralText("").append(new LiteralText("* Settings:").formatted(Formatting.YELLOW)) -// .append(Messages.Command.getSettings(claim)).append("\n")); -// Text pos = new LiteralText(""); -// Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); -// Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); -// -// -// if (PERMISSION_CHECK_ADMIN.test(source)) { -// String format = "/execute in " + Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").toString() + " run tp " + source.getName() + (Config.claims2d ? " %s ~ %s" : " %s %s %s"); -// min.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, -// String.format(format, claim.min.getX(), Config.claims2d ? claim.min.getZ() : claim.min.getY(), claim.min.getZ())))); -// max.styled(style -> style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, -// String.format(format, claim.max.getX(), Config.claims2d ? claim.max.getZ() : claim.max.getY(), claim.max.getZ())))); -// } -// -// pos.append(newInfoLine("Position", new LiteralText("") -// .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) -// .append(" ") -// .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); -// text.append(pos); -// text.append(newInfoLine("Dimension", new LiteralText(Registry.DIMENSION_TYPE.getId(claim.dimension).getPath()))); -// if(claim.rent.isRented()){ -// GameProfile tenant = claim.rent.getTenant() == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.rent.getTenant()); -// text.append(newInfoLine("Status", new LiteralText("Rented").formatted(Formatting.RED).styled(style -> { -// java.util.Date time=new java.util.Date((long) claim.rent.getRentedUntil()*1000); -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Until", new LiteralText(time.toString()).formatted(Formatting.WHITE)).append(newInfoLine("By", new LiteralText(tenant.getName()).formatted(Formatting.WHITE))).append(newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE))))); -// }))); -// } else if (claim.rent.isRentable() && !claim.rent.isRented()){ -// text.append(newInfoLine("Status", new LiteralText("For Rent").formatted(Formatting.GREEN).styled(style -> { -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE)).append(newInfoLine("Max Rent", new LiteralText(claim.rent.getMaxrentAbleTime() / 86400 + " days")).formatted(Formatting.WHITE)))); -// }))); -// -// } else { -// text.append(newInfoLine("Status", new LiteralText("Not For Rent").formatted(Formatting.GREEN))); -// -// } -// source.sendFeedback(text, false); -// return 1; -// } -// private static Text newPosLine(BlockPos pos, Formatting form1, Formatting form2) { -// return new LiteralText("") -// .append(new LiteralText(String.valueOf(pos.getX())).formatted(form1)) -// .append(" ") -// .append(new LiteralText(String.valueOf(pos.getY())).formatted(form2)) -// .append(" ") -// .append(new LiteralText(String.valueOf(pos.getZ())).formatted(form1)); -// } -// private static Text newInfoLine(String title, Text text) { -// return new LiteralText("").append(new LiteralText("* " + title + ": ").formatted(Formatting.YELLOW)) -// .append(text).append("\n"); -// } - -// private static ArrayList getClaims(){ -// ArrayList claims = new ArrayList<>(); -// ClaimManager.INSTANCE.claimsByName.forEach((s, claim) -> { -// claims.add(claim); -// }); -// return claims; -// } -// -// private static int listall(ServerCommandSource source){ -// List claims = getClaims(); -// Text text = new LiteralText("\n").append(new LiteralText("Claims").formatted(Formatting.GOLD)).append("\n "); -// for (Claim claim : claims) { -// Text cText = new LiteralText(claim.name).formatted(Formatting.GOLD); -// text.append(cText.append(" ")); -// } -// source.sendFeedback(text.append("\n"), false); -// return 1; -// } - -// private static int list(ServerCommandSource source, String target) throws CommandSyntaxException { -// ServerPlayerEntity player = source.getPlayer(); -// GameProfile profile = target == null ? player.getGameProfile() : source.getMinecraftServer().getUserCache().findByName(target); -// -// if (profile == null) { -// source.sendError(Messages.INVALID_PLAYER); -// return -1; -// } -// -// List claims = ClaimManager.INSTANCE.getPlayerClaims(profile.getId()); -// if (claims.isEmpty()) { -// source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); -// return -1; -// } -// -// -// Text text = new LiteralText("\n").append(new LiteralText("Claims (" + target + "): ").formatted(Formatting.GOLD)).append("\n "); -// boolean nextColor = false; -// for (Claim claim : claims) { -// if(!claim.isChild) { -// Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { -// Text hoverText = new LiteralText("Click for more Info").formatted(Formatting.GREEN); -// if (claim.children.size() > 0) { -// hoverText.append("\n\nSubzones:"); -// for (Claim subzone : claim.children) { -// hoverText.append("\n- " + subzone.name); -// } -// } -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); -// -// style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); -// }); -// -// nextColor = !nextColor; -// text.append(cText.append(" ")); -// } -// } -// -// source.sendFeedback(text.append("\n"), false); -// return 1; -// } -// private static int listAll(ServerCommandSource source, int page) { -// List claims = new ArrayList<>(); -// ClaimManager.INSTANCE.claimsByName.forEach((name, claim) -> claims.add(claim)); -// -// if (claims.isEmpty()) { -// source.sendFeedback(new LiteralText("No Claims").formatted(Formatting.RED), false); -// return -1; -// } -// -// List list = new ArrayList<>(claims.size() / 10); -// -// for (int i = 0; i < claims.size(); i++) { -// Claim claim = claims.get(i); -// -// Text cText = new LiteralText("").append(new LiteralText(i + ". ").formatted(Formatting.GOLD)) -// .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" in ").formatted(Formatting.GRAY)) -// .append(new LiteralText(Objects.requireNonNull(Registry.DIMENSION_TYPE.getId(claim.dimension), "Dimension Doesn't Exist!!").getPath()).formatted(Formatting.WHITE)); -// -// cText.styled((style) -> { -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click for more Info").formatted(Formatting.GREEN))); -// style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); -// }); -// -// list.add(cText.append("\n")); -// } -// -// Text[] texts = new Text[]{}; -// texts = list.toArray(texts); -// return sendPage(source, texts, page, "Claims", "/claim listall %page%"); -// } -// private static int rename(CommandContext context, boolean admin) throws CommandSyntaxException { -// String name = getString(context, "claim"); -// String newName = getString(context, "name"); -// if(!newName.matches("[A-Za-z0-9]+")){ -// context.getSource().sendError(new LiteralText("Invalid claim name")); -// return -1; -// } -// Claim claim = ClaimManager.INSTANCE.claimsByName.get(name); -// if (claim == null) { -// context.getSource().sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// if (ClaimManager.INSTANCE.claimsByName.containsKey(newName)) { -// context.getSource().sendError(new LiteralText("That name is already taken!")); -// return -1; -// } -// if (!admin && !claim.hasPermission(context.getSource().getPlayer().getUuid(), Claim.Permission.MODIFY_PROPERTIES)) { -// context.getSource().sendError(new LiteralText("You don't have permission to modify claim properties!")); -// return -1; -// } -// ClaimManager.INSTANCE.claimsByName.remove(name); -// if(claim.isChild) claim.name = ClaimUtil.getParentClaim(claim).name + "." + newName; -// else claim.name = newName; -// ClaimManager.INSTANCE.addClaim(claim); -// context.getSource().sendFeedback(new LiteralText("Renamed Claim " + name + " to " + claim.name).formatted(Formatting.GOLD), admin); -// return -1; -// } -// private static int showTrustedList(CommandContext context, Claim claim, boolean showSelf) throws CommandSyntaxException { -// ServerCommandSource source = context.getSource(); -// ServerPlayerEntity player = source.getPlayer(); -// int mapSize = claim.permissionManager.playerPermissions.size(); -// -// if (mapSize == 1 && !showSelf) { -// source.sendError(new LiteralText(claim.name + " is not trusting anyone!")); -// return -1; -// } -// -// Text text = new LiteralText("\n"); -// text.append(new LiteralText("Trusted players for Claim ").formatted(Formatting.YELLOW)) -// .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append("\n"); -// -// AtomicInteger atomicInteger = new AtomicInteger(); -// claim.permissionManager.playerPermissions.forEach((uuid, perm) -> { -// atomicInteger.incrementAndGet(); -// Text pText = new LiteralText(""); -// Text owner; -// GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); -// if (profile != null) { -// owner = new LiteralText(profile.getName()); -// } else { -// owner = new LiteralText(uuid.toString()).styled((style) -> { -// style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to Copy"))); -// style.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); -// }); -// } -// -// pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) -// .append(owner.formatted(Formatting.YELLOW)); -// -// Text hover = new LiteralText(""); -// hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); -// -// int allowed = 0; -// int i = 0; -// boolean nextColor = false; -// Text perms = new LiteralText(""); -// -// for (Claim.Permission value : Claim.Permission.values()) { -// if (claim.permissionManager.hasPermission(uuid, value)) { -// Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; -// perms.append(new LiteralText(value.id).formatted(formatting)).append(" "); -// if (i == 3) perms.append("\n"); -// allowed++; -// i++; -// nextColor = !nextColor; -// } -// } -// -// if (allowed == Claim.Permission.values().length) { -// hover.append(new LiteralText("All " + allowed + " Permissions").formatted(Formatting.YELLOW, Formatting.ITALIC)); -// } else { -// hover.append(perms); -// } -// -// pText.append(new LiteralText(" ") -// .append(new LiteralText("(").formatted(Formatting.GOLD)) -// .append(new LiteralText(String.valueOf(allowed)).formatted(Formatting.GREEN)) -// .append(new LiteralText("/").formatted(Formatting.GOLD)) -// .append(new LiteralText(String.valueOf(Claim.Permission.values().length)).formatted(Formatting.YELLOW)) -// .append(new LiteralText(")").formatted(Formatting.GOLD)) -// ); -// -// pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); -// text.append(pText).append("\n"); -// }); -// -// source.sendFeedback(text, false); -// return 1; -// } -// private static int setOwnerName(ServerCommandSource source, Claim claim, String input) { -// String name = input.equals("reset") ? null : input; -// source.sendFeedback(new LiteralText("Set the Custom Owner Name to ") -// .formatted(Formatting.YELLOW).append(new LiteralText(name == null ? "Reset" : name).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) -// .append(new LiteralText(claim.customOwnerName == null ? "Not Present" : claim.customOwnerName).formatted(Formatting.GOLD)) -// .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) -// , false); -// claim.customOwnerName = input; -// return 1; -// } -// private static int setOwner(ServerCommandSource source, Claim claim, GameProfile profile) { -// GameProfile oldOwner = source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); -// source.sendFeedback(new LiteralText("Set the Claim Owner to ") -// .formatted(Formatting.YELLOW).append(new LiteralText(profile.getName()).formatted(Formatting.GOLD)).append(new LiteralText(" from ")) -// .append(new LiteralText(oldOwner == null ? "(" + claim.claimBlockOwner + ")" : oldOwner.getName()).formatted(Formatting.GOLD)) -// .append(new LiteralText(" for ").formatted(Formatting.YELLOW)).append(new LiteralText(claim.name).formatted(Formatting.GOLD)) -// , false); -// claim.claimBlockOwner = profile.getId(); -// return 1; -// } -// private static int setEventMessage(ServerCommandSource source, Claim claim, Claim.Event event, String message) { -// switch (event) { -// case ENTER_CLAIM: -// claim.enterMessage = message.equalsIgnoreCase("reset") ? null : message; -// break; -// case LEAVE_CLAIM: -// claim.leaveMessage = message.equalsIgnoreCase("reset") ? null : message; -// break; -// } -// -// if (message.equalsIgnoreCase("reset")) { -// source.sendFeedback(new LiteralText("Reset ").append(new LiteralText(event.id).formatted(Formatting.GOLD) -// .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) -// .append(new LiteralText(claim.name).formatted(Formatting.GOLD))).formatted(Formatting.YELLOW) -// , false); -// return -1; -// } -// -// source.sendFeedback(new LiteralText("Set ").append(new LiteralText(event.id).formatted(Formatting.GOLD) -// .append(new LiteralText(" Event Message for claim ").formatted(Formatting.YELLOW)) -// .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText(" to:").formatted(Formatting.YELLOW))) -// .append("\n").append(new LiteralText(ChatColor.translate(message))) -// .formatted(Formatting.YELLOW) -// , false); -// return 1; -// } -// private static int executeSetting(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { -// ServerPlayerEntity player = source.getPlayer(); -// Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : -// ClaimManager.INSTANCE.claimsByName.get(claimName); -// if (claim1 == null) { -// source.sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// -// if (input == null) { -// return querySettings(source, claim1); -// } -// -// validateCanAccess(player, claim1, admin); -// Claim.ClaimSettings.Setting setting = Claim.ClaimSettings.Setting.byId(input); -// Claim.Permission permission = Claim.Permission.byId(input); -// -// if (setting != null && permission == null) -// return isQuery ? querySetting(source, claim1, setting) : setSetting(source, claim1, setting, value); -// -// if (setting == null && permission != null) -// return isQuery ? queryPermission(source, claim1, permission) : setPermission(source, claim1, permission, value); -// -// source.sendError(Messages.INVALID_SETTING); -// return -1; -// } -// private static int executePermission(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { -// ServerPlayerEntity player = source.getPlayer(); -// Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : -// ClaimManager.INSTANCE.claimsByName.get(claimName); -// if (claim1 == null) { -// source.sendError(Messages.INVALID_CLAIM); -// return -1; -// } -// -// validateCanAccess(player, claim1, admin); -// Claim.Permission permission = Claim.Permission.byId(input); -// if (permission != null) -// return !isQuery ? setPermission(source, claim1, permission, value) : queryPermission(source, claim1, permission); -// -// source.sendError(Messages.INVALID_SETTING); -// return -1; -// } -// private static int querySetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting) { -// boolean enabled = claim.settings.getSetting(setting); -// source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); -// return 1; -// } -// private static int setSetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting, boolean set) { -// claim.settings.settings.put(setting, set); -// source.sendFeedback(new LiteralText(ChatColor.translate("&eSet setting &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); -// return 0; -// } -// private static int queryPermission(ServerCommandSource source, Claim claim, Claim.Permission permission) { -// boolean defaultPerm = claim.permissionManager.defaults.hasPermission(permission); -// source.sendFeedback(new LiteralText(ChatColor.translate("&ePermission &6" + permission.id + "&e is set to " + (defaultPerm ? "&a" : "&c") + defaultPerm + "&e for &6" + claim.name)), false); -// return 1; -// } -// private static int setPermission(ServerCommandSource source, Claim claim, Claim.Permission permission, boolean set) { -// claim.permissionManager.defaults.setPermission(permission, set); -// source.sendFeedback(new LiteralText(ChatColor.translate("&eSet permission &6" + permission.id + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); -// return 1; -// } -// private static int querySettings(ServerCommandSource source, Claim claim) { -// source.sendFeedback(new LiteralText("\n").append(new LiteralText("Settings: " + claim.name).formatted(Formatting.YELLOW)).append("\n") -// .append(Messages.Command.getSettings(claim)).append("\n"), false); -// return 1; -// } -// private static int executeTrust(CommandContext context, Collection targetCollection, boolean set, @Nullable String claimName) throws CommandSyntaxException { -// AtomicInteger integer = new AtomicInteger(); -//// if(targetCollection.size() > 1){ -//// context.getSource().sendFeedback(new LiteralText("Only 1 player allowed").formatted(Formatting.RED), true); -//// return 0; -//// } -// if(targetCollection.isEmpty()){ -// context.getSource().sendFeedback(new LiteralText("No player provided").formatted(Formatting.RED), true); -// return 0; -// } -// ServerPlayerEntity p = context.getSource().getPlayer(); -// Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getBlockPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); -// validateClaim(claim1); -// targetCollection.iterator().forEachRemaining(gameProfile -> { -// try { -// //This is supposed to check if the player has played before :shrug: -// if(context.getSource().getMinecraftServer().getUserCache().getByUuid(gameProfile.getId()) == gameProfile){ -// integer.set(setTrust(context, claim1, gameProfile, set, false)); -// } else { -// context.getSource().sendFeedback(new LiteralText("Unknown player!").formatted(Formatting.RED), true); -// integer.set(0); -// } -// } catch (CommandSyntaxException e) { -// e.printStackTrace(); -// } -// }); -// return integer.get(); -// } -// private static int setTrust(CommandContext context, Claim claim, GameProfile target, boolean set, boolean admin) throws CommandSyntaxException { -// if (verifyPermission(claim, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { -// claim.permissionManager.playerPermissions.put(target.getId(), set ? new Claim.InvertedPermissionMap() : new Claim.DefaultPermissionMap()); -// context.getSource().sendFeedback(new LiteralText(target.getName() + (set ? " now" : " no longer") + " has all the permissions").formatted(Formatting.YELLOW), false); -// } -// return 1; -// } -// private static int setFly(CommandContext context, boolean set) throws CommandSyntaxException { -// ServerPlayerEntity player = context.getSource().getPlayer(); -// if (set) { -// ClaimManager.INSTANCE.flyers.add(player.getUuid()); -// player.addMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN), false); -// return 1; -// } -// -// player.addMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED), false); -// ClaimManager.INSTANCE.flyers.remove(player.getUuid()); -// return -1; -// } - -// -// private static GameProfile getProfile(CommandContext context, String arg) { -// return context.getSource().getMinecraftServer().getUserCache().findByName(getString(context, arg)); -// } -//} \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 904182f..456de69 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -1,45 +1,46 @@ package io.github.indicode.fabric.itsmine; import net.minecraft.text.LiteralText; +import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; public class Messages { - public static final Text PREFIX = new LiteralText(ChatColor.translate(Config.prefix)); + public static final MutableText PREFIX = new LiteralText(ChatColor.translate(Config.prefix)); - public static final Text INVALID_CLAIM = PREFIX.copy().append(new LiteralText("Can not find a claim with that name or a claim at your position").formatted(Formatting.RED)); + public static final Text INVALID_CLAIM = PREFIX.append(new LiteralText("Can not find a claim with that name or a claim at your position").formatted(Formatting.RED)); - public static final Text INVALID_SETTING = PREFIX.copy().append(new LiteralText("Invalid Claim Setting!").formatted(Formatting.RED)); + public static final Text INVALID_SETTING = PREFIX.append(new LiteralText("Invalid Claim Setting!").formatted(Formatting.RED)); - public static final Text NO_PERMISSION = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_no_perm))); + public static final Text NO_PERMISSION = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_no_perm))); - public static final Text INVALID_MESSAGE_EVENT = PREFIX.copy().append(new LiteralText("Invalid Message Event!")); + public static final Text INVALID_MESSAGE_EVENT = PREFIX.append(new LiteralText("Invalid Message Event!")); - public static final Text INVALID_PLAYER = PREFIX.copy().append(new LiteralText("Can not find a Player with that Name!")); + public static final Text INVALID_PLAYER = PREFIX.append(new LiteralText("Can not find a Player with that Name!")); - public static final Text TOO_MANY_SELECTIONS = PREFIX.copy().append(new LiteralText("Only one selection is allowed!")); + public static final Text TOO_MANY_SELECTIONS = PREFIX.append(new LiteralText("Only one selection is allowed!")); - public static final Text MSG_PLACE_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_place_block)).formatted(Formatting.RED)); + public static final Text MSG_PLACE_BLOCK = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_place_block)).formatted(Formatting.RED)); - public static final Text MSG_BREAK_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_break_block)).formatted(Formatting.RED)); + public static final Text MSG_BREAK_BLOCK = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_break_block)).formatted(Formatting.RED)); - public static final Text MSG_CANT_ENTER = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_enter)).formatted(Formatting.RED)); + public static final Text MSG_CANT_ENTER = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_cant_enter)).formatted(Formatting.RED)); - public static final Text MSG_INTERACT_ENTITY = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_interact_entity)).formatted(Formatting.RED)); + public static final Text MSG_INTERACT_ENTITY = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_interact_entity)).formatted(Formatting.RED)); - public static final Text MSG_INTERACT_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_interact_block)).formatted(Formatting.RED)); + public static final Text MSG_INTERACT_BLOCK = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_interact_block)).formatted(Formatting.RED)); - public static final Text MSG_OPEN_CONTAINER = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_open_container)).formatted(Formatting.RED)); + public static final Text MSG_OPEN_CONTAINER = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_open_container)).formatted(Formatting.RED)); - public static final Text MSG_DAMAGE_ENTITY = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_attack_entity)).formatted(Formatting.RED)); + public static final Text MSG_DAMAGE_ENTITY = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_attack_entity)).formatted(Formatting.RED)); - public static final Text MSG_CANT_USE = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_use)).formatted(Formatting.RED)); + public static final Text MSG_CANT_USE = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_cant_use)).formatted(Formatting.RED)); - public static final Text MSG_LONG_NAME = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_long_name)).formatted(Formatting.RED)); + public static final Text MSG_LONG_NAME = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_long_name)).formatted(Formatting.RED)); - public static final Text MSG_CANT_DO = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_do)).formatted(Formatting.RED)); + public static final Text MSG_CANT_DO = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_cant_do)).formatted(Formatting.RED)); - public static final Text[] GET_STARTED = new Text[]{ + public static final Text[] GET_STARTED = new MutableText[]{ header("How to Claim (Basics)") .append(line(1, "Type &6/claim stick&e then Left click with a stick on a block to set the &6first&e corner of your claim")) .append(line(2, "Right click to set the other corner")) @@ -64,7 +65,7 @@ public class Messages { header("How to Claim (Subzones)") .append(line("Subzones allow you to have seperate permissions / settings in certain areas of your claim").formatted(Formatting.LIGHT_PURPLE)) .append(line(1, "To create a subzone, you select an area inside your claim the way you would select a normal claim")) - .append(line(2, "Type ").append("/claim subzone add ").formatted(Formatting.GOLD).append(" to create a subzone").formatted(Formatting.YELLOW)) + .append(line(2, "Type ").append(text("/claim subzone add ")).formatted(Formatting.GOLD).append(text(" to create a subzone")).formatted(Formatting.YELLOW)) .append(line(3,"Done! Everything else works the same way claims work")) }; @@ -137,25 +138,25 @@ public class Messages { .append(line("&6break_farmlands ").append(text("Allow turning Farmlands into Dirt by jumping on them"))) }; - private static Text header(String title) { - return new LiteralText("").append(new LiteralText(title + ":").formatted(Formatting.AQUA, Formatting.UNDERLINE)).formatted(Formatting.WHITE).append("\n"); + private static MutableText header(String title) { + return new LiteralText("").append(new LiteralText(title + ":").formatted(Formatting.AQUA).formatted(Formatting.UNDERLINE)).formatted(Formatting.WHITE).append(new LiteralText("\n")); } - private static Text line(int num, String string) { + private static MutableText line(int num, String string) { return line("&e" + num + ".&e " + string); } - private static Text line(String string) { - return new LiteralText("\n").append(ChatColor.translate(string)).formatted(Formatting.YELLOW); + private static MutableText line(String string) { + return new LiteralText("\n").append(new LiteralText(ChatColor.translate(string))).formatted(Formatting.YELLOW); } - private static Text text(String text) { + private static MutableText text(String text) { return new LiteralText(ChatColor.translate(text)); } public static class Command { public static Text getSettings(Claim claim) { - Text claimSettings = new LiteralText(""); + MutableText claimSettings = new LiteralText(""); boolean nextEnabled = false; boolean nextDisabled = false; for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { @@ -171,7 +172,7 @@ public static Text getSettings(Claim claim) { nextDisabled = !nextDisabled; } - claimSettings.append(" ").append(new LiteralText(value.id).formatted(formatting)); + claimSettings.append(new LiteralText(" ")).append(new LiteralText(value.id).formatted(formatting)); } return claimSettings; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java index 14151b1..7d6bdca 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/BlockCommand.java @@ -32,12 +32,12 @@ static void register(LiteralArgumentBuilder command) { static int blocksLeft(ServerCommandSource source, UUID player) throws CommandSyntaxException { int blocks = ClaimManager.INSTANCE.getClaimBlocks(player); - source.sendFeedback(new LiteralText((source.getPlayer().getGameProfile().getId().equals(player) ? "You have " : "They have ") + blocks + " blocks left").setStyle(new Style().setColor(Formatting.YELLOW)), false); + source.sendFeedback(new LiteralText((source.getPlayer().getGameProfile().getId().equals(player) ? "You have " : "They have ") + blocks + " blocks left").formatted(Formatting.YELLOW), false); return 1; } static int blocksLeft(ServerCommandSource source) throws CommandSyntaxException { int blocks = ClaimManager.INSTANCE.getClaimBlocks(source.getPlayer().getUuid()); - source.sendFeedback(new LiteralText("You have " + blocks + " blocks left").setStyle(new Style().setColor(Formatting.YELLOW)), false); + source.sendFeedback(new LiteralText("You have " + blocks + " blocks left").formatted(Formatting.YELLOW), false); return 1; } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java index 096a64d..998c2c7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java @@ -2,11 +2,13 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.sun.org.apache.xpath.internal.Arg; import io.github.indicode.fabric.itsmine.command.admin.AdminCommand; import io.github.indicode.fabric.itsmine.command.subzone.SubzoneCommand; import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.server.command.ServerCommandSource; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getClaims; import static net.minecraft.server.command.CommandManager.literal; public class CommandManager { @@ -23,24 +25,24 @@ private static void register(LiteralArgumentBuilder command AdminCommand.register(command, dispatcher); BlockCommand.register(command); CreateCommand.register(command); - ExceptionCommand.register(command, false, ArgumentUtil.getClaims()); - ExpandCommand.register(command); + ExceptionCommand.register(command, false, getClaims()); + ExpandCommand.register(command, false); FlyCommand.register(command); HelpCommand.register(command); - InfoCommand.register(command); + InfoCommand.register(command, getClaims()); ListCommand.register(command); PermissionsCommand.register(command, false); - RemoveCommand.register(command); - RenameCommand.register(command); - RentableCommand.register(command); - RentCommand.register(command); - RevenueCommand.register(command); - SettingsCommand.register(command, false); + RemoveCommand.register(command, getClaims(), false); + RenameCommand.register(command, false); + RentableCommand.register(command, getClaims()); + RentCommand.register(command, getClaims()); + RevenueCommand.register(command, getClaims()); +// SettingsCommand.register(command, false); ShowCommand.register(command); StickCommand.register(command); - SubzoneCommand.register(command, dispatcher); + SubzoneCommand.register(command, dispatcher, false); TransferCommand.register(command); - TrustCommand.register(command); + TrustCommand.register(command, getClaims(), false); TrustedCommand.register(command); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java index 474e334..1653eea 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java @@ -13,6 +13,7 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.HoverEvent; import net.minecraft.text.LiteralText; +import net.minecraft.text.MutableText; import net.minecraft.text.Style; import net.minecraft.util.Formatting; import net.minecraft.util.Pair; @@ -106,7 +107,21 @@ public static int createClaim(String name, ServerCommandSource owner, BlockPos p // works because only the first statement is evaluated if true if ((admin && ItsMine.permissions().hasPermission(owner, PermissionUtil.Command.INFINITE_BLOCKS, 2)) || ClaimManager.INSTANCE.useClaimBlocks(ownerID, subInt)) { ClaimManager.INSTANCE.addClaim(claim); - owner.sendFeedback(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)).append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").setStyle(new Style().setColor(Formatting.GREEN).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))))), false); + MutableText message = null; + message.append(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN))); + message.append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").styled(style -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))); + return style; + })); + owner.sendFeedback(message, false); + + MutableText message2 = null; + message2.append(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN))); + message2.append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").styled(style -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))); + return style; + })); + owner.sendFeedback(message2, false); BlockCommand.blocksLeft(owner); executeShowClaim(owner, claim, false); if (admin) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java index 4c4c055..1743fa8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java @@ -30,10 +30,9 @@ public class ExceptionCommand { - public static void register(LiteralArgumentBuilder command, boolean admin, RequiredArgumentBuilder argumentBuilder) { + public static void register(LiteralArgumentBuilder command, boolean admin, RequiredArgumentBuilder claim) { { LiteralArgumentBuilder settings = literal("settings"); - RequiredArgumentBuilder claim = argumentBuilder; if (!admin) { settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); @@ -59,34 +58,35 @@ public static void register(LiteralArgumentBuilder command, settings.then(claim); command.then(settings); } + { + LiteralArgumentBuilder exceptions = literal("permissions"); + if (admin) exceptions.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_PERMISSIONS, 2)); + if (!admin) { + exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); - LiteralArgumentBuilder exceptions = literal("permissions"); - if (admin) exceptions.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_PERMISSIONS, 2)); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - if (!admin) { - exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); - - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return showTrustedList(context, claim1, false); - }); - } + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim1, false); + }); + } - if (!admin) { - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(new LiteralText("That claim does not exist")); - return -1; - } - return showTrustedList(context, claim1, true); - }); + if (!admin) { + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(new LiteralText("That claim does not exist")); + return -1; + } + return showTrustedList(context, claim1, true); + }); + } + exceptions.then(claim); + command.then(exceptions); } - { RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); LiteralArgumentBuilder remove = literal("remove"); @@ -139,7 +139,6 @@ public static void register(LiteralArgumentBuilder command, } { LiteralArgumentBuilder message = literal("message"); - RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); RequiredArgumentBuilder messageEvent = getMessageEvent(); RequiredArgumentBuilder messageArgument = getEventMessage(); messageArgument.executes(context -> { @@ -159,13 +158,9 @@ public static void register(LiteralArgumentBuilder command, }); messageEvent.then(messageArgument); - claimArgument.then(messageEvent); - message.then(claimArgument); + claim.then(messageEvent); + message.then(claim); command.then(message); } - - - exceptions.then(claim); - command.then(exceptions); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java index 7d13134..8a08156 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java @@ -27,7 +27,7 @@ public class ExpandCommand { - public static void register(LiteralArgumentBuilder command) { + public static void register(LiteralArgumentBuilder command, boolean admin) { { LiteralArgumentBuilder expand = literal("expand"); RequiredArgumentBuilder amount = argument("distance", IntegerArgumentType.integer(1, Integer.MAX_VALUE)); @@ -38,7 +38,7 @@ public static void register(LiteralArgumentBuilder command) IntegerArgumentType.getInteger(context, "distance"), directionByName(getString(context, "direction")), context.getSource(), - false + admin )); amount.executes(context -> expand( @@ -46,7 +46,7 @@ public static void register(LiteralArgumentBuilder command) IntegerArgumentType.getInteger(context, "distance"), Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], context.getSource(), - false + admin )); amount.then(direction); @@ -63,7 +63,7 @@ public static void register(LiteralArgumentBuilder command) -IntegerArgumentType.getInteger(context, "distance"), directionByName(getString(context, "direction")), context.getSource(), - false + admin )); amount.executes(context -> expand( @@ -71,7 +71,7 @@ public static void register(LiteralArgumentBuilder command) -IntegerArgumentType.getInteger(context, "distance"), Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], context.getSource(), - false + admin )); amount.then(direction); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java index ac15e93..5dfe18c 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java @@ -7,10 +7,7 @@ import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.HoverEvent; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; +import net.minecraft.text.*; import net.minecraft.util.Formatting; import static com.mojang.brigadier.arguments.StringArgumentType.getString; @@ -51,41 +48,43 @@ public static int sendPage(ServerCommandSource source, Text[] text, int page, St int thisPage = page - 1; int nextPage = page + 1; final String SEPARATOR = "-----------------------------------------------------"; - Text header = new LiteralText("") + MutableText header = new LiteralText("") .append(new LiteralText("- [ ").formatted(Formatting.GRAY)) .append(new LiteralText(title).formatted(Formatting.GOLD)) - .append(" ] ") - .append(SEPARATOR.substring(ChatColor.removeAlternateColorCodes('&', title).length() + 4)) + .append(new LiteralText(" ] ")) + .append(new LiteralText(SEPARATOR.substring(ChatColor.removeAlternateColorCodes('&', title).length() + 4))) .formatted(Formatting.GRAY); Text button_prev = new LiteralText("") - .append(new LiteralText("<-").formatted(Formatting.WHITE, Formatting.BOLD)) - .append(" ").append(new LiteralText("Prev").formatted(Formatting.GOLD)) + .append(new LiteralText("<-").formatted(Formatting.WHITE).formatted(Formatting.BOLD)) + .append(new LiteralText(" ")).append(new LiteralText("Prev").formatted(Formatting.GOLD)) .styled((style) -> { style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); if (prevPage >= 0) - style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); + style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); + return style; }); Text button_next = new LiteralText("") .append(new LiteralText("Next").formatted(Formatting.GOLD)) - .append(" ").append(new LiteralText("->").formatted(Formatting.WHITE, Formatting.BOLD)).append(" ") + .append(new LiteralText(" ")).append(new LiteralText("->").formatted(Formatting.WHITE).formatted(Formatting.BOLD)).append(new LiteralText(" ")) .styled((style) -> { style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); if (nextPage <= text.length) - style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); + style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); + return style; }); Text buttons = new LiteralText("") .append(new LiteralText("[ ").formatted(Formatting.GRAY)) .append(button_prev) - .append(" ") + .append(new LiteralText(" ")) .append( new LiteralText(String.valueOf(page)).formatted(Formatting.GREEN) .append(new LiteralText("/").formatted(Formatting.GRAY)) .append(new LiteralText(String.valueOf(text.length)).formatted(Formatting.GREEN)) ) - .append(" ") + .append(new LiteralText(" ")) .append(button_next) .append(new LiteralText("] ").formatted(Formatting.GRAY)); @@ -93,7 +92,7 @@ public static int sendPage(ServerCommandSource source, Text[] text, int page, St .formatted(Formatting.GRAY) .append(buttons).append(new LiteralText(" ------------------------------").formatted(Formatting.GRAY)); - header.append("\n").append(text[thisPage]).append("\n").append(footer); + header.append(new LiteralText("\n")).append(text[thisPage]).append(new LiteralText("\n")).append(footer); source.sendFeedback(header, false); return 1; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java index 3e6aed0..88a7d04 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java @@ -6,28 +6,23 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Config; import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import io.github.indicode.fabric.itsmine.util.TimeUtil; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.ClickEvent; import net.minecraft.text.HoverEvent; import net.minecraft.text.LiteralText; +import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.util.registry.Registry; -import java.util.Objects; - import static com.mojang.brigadier.arguments.StringArgumentType.getString; import static net.minecraft.server.command.CommandManager.literal; public class InfoCommand { - public static void register(LiteralArgumentBuilder command) { + public static void register(LiteralArgumentBuilder command, RequiredArgumentBuilder claim) { LiteralArgumentBuilder info = literal("info"); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); info.executes(context -> info( context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()) @@ -47,27 +42,27 @@ private static int info(ServerCommandSource source, Claim claim) throws CommandS GameProfile owner = claim.claimBlockOwner == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.claimBlockOwner); BlockPos size = claim.getSize(); - Text text = new LiteralText("\n"); - text.append(new LiteralText("Claim Info: " + claim.name).formatted(Formatting.GOLD)).append("\n"); + MutableText text = new LiteralText("\n"); + text.append(new LiteralText("Claim Info: " + claim.name).formatted(Formatting.GOLD)).append(new LiteralText("\n")); text.append(newInfoLine("Name", new LiteralText(claim.name).formatted(Formatting.WHITE))); text.append(newInfoLine("Entities", new LiteralText(String.valueOf(claim.getEntities(source.getWorld()))).formatted(Formatting.AQUA))); text.append(newInfoLine("Owner", owner != null && claim.customOwnerName == null ? new LiteralText(owner.getName()).formatted(Formatting.GOLD) : claim.customOwnerName != null ? new LiteralText(claim.customOwnerName).formatted(Formatting.GOLD) : - new LiteralText("No Owner").formatted(Formatting.RED, Formatting.ITALIC))); + new LiteralText("No Owner").formatted(Formatting.RED).formatted(Formatting.ITALIC))); text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); text.append(new LiteralText("").append(new LiteralText("* Settings:").formatted(Formatting.YELLOW)) - .append(Messages.Command.getSettings(claim)).append("\n")); - Text pos = new LiteralText(""); + .append(Messages.Command.getSettings(claim)).append(new LiteralText("\n"))); + MutableText pos = new LiteralText(""); Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); pos.append(newInfoLine("Position", new LiteralText("") .append(new LiteralText("Min ").formatted(Formatting.WHITE).append(min)) - .append(" ") + .append(new LiteralText(" ")) .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); text.append(pos); text.append(newInfoLine("Dimension", new LiteralText(Registry.DIMENSION_TYPE.getId(claim.dimension).getPath()))); @@ -76,10 +71,12 @@ private static int info(ServerCommandSource source, Claim claim) throws CommandS text.append(newInfoLine("Status", new LiteralText("Rented").formatted(Formatting.RED).styled(style -> { java.util.Date time=new java.util.Date((long) claim.rent.getRentedUntil()*1000); style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Until", new LiteralText(time.toString()).formatted(Formatting.WHITE)).append(newInfoLine("By", new LiteralText(tenant.getName()).formatted(Formatting.WHITE))).append(newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE))))); + return style; }))); } else if (claim.rent.isRentable() && !claim.rent.isRented()){ text.append(newInfoLine("Status", new LiteralText("For Rent").formatted(Formatting.GREEN).styled(style -> { style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE)).append(newInfoLine("Max Rent", new LiteralText(claim.rent.getMaxrentAbleTime() / 86400 + " days")).formatted(Formatting.WHITE)))); + return style; }))); } else { @@ -90,16 +87,16 @@ private static int info(ServerCommandSource source, Claim claim) throws CommandS return 1; } - private static Text newPosLine(BlockPos pos, Formatting form1, Formatting form2) { + private static MutableText newPosLine(BlockPos pos, Formatting form1, Formatting form2) { return new LiteralText("") .append(new LiteralText(String.valueOf(pos.getX())).formatted(form1)) - .append(" ") + .append(new LiteralText(" ")) .append(new LiteralText(String.valueOf(pos.getY())).formatted(form2)) - .append(" ") + .append(new LiteralText(" ")) .append(new LiteralText(String.valueOf(pos.getZ())).formatted(form1)); } - private static Text newInfoLine(String title, Text text) { + private static MutableText newInfoLine(String title, Text text) { return new LiteralText("").append(new LiteralText("* " + title + ": ").formatted(Formatting.YELLOW)) - .append(text).append("\n"); + .append(text).append(new LiteralText("\n")); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java index 827e85d..d959bd2 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java @@ -25,15 +25,14 @@ public class RemoveCommand { - public static void register(LiteralArgumentBuilder command) { + public static void register(LiteralArgumentBuilder command, RequiredArgumentBuilder claim, boolean admin) { LiteralArgumentBuilder delete = literal("remove"); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); LiteralArgumentBuilder confirm = literal("confirm"); - confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); - claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); + confirm.executes(context -> delete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), admin)); + claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), admin)); claim.then(confirm); delete.then(claim); - delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); + delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), admin)); command.then(delete); } public static int requestDelete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { @@ -43,17 +42,19 @@ public static int requestDelete(ServerCommandSource sender, Claim claim, boolean } if (!claim.permissionManager.hasPermission(sender.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { - sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED).formatted(Formatting.BOLD), false); } else { sender.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); return 0; } } sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to delete the claim \"" + claim.name + "\"? ").formatted(Formatting.GOLD)) - .append(new LiteralText("[I'M SURE]").setStyle(new Style() - .setColor(Formatting.DARK_RED) - .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")))), false); + .append(new LiteralText("[I'M SURE]").styled(style -> { + style.withColor(Formatting.DARK_RED); + style.withBold(true); + style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")); + return style; + })), false); return 0; } public static int delete(ServerCommandSource source, Claim claim, boolean admin) throws CommandSyntaxException { @@ -64,7 +65,7 @@ public static int delete(ServerCommandSource source, Claim claim, boolean admin) } if (!claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)) { if (admin && ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)) { - source.sendFeedback(new LiteralText("Deleting a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + source.sendFeedback(new LiteralText("Deleting a claim belonging to somebody else").formatted(Formatting.DARK_RED).formatted(Formatting.BOLD), false); } else { source.sendFeedback(new LiteralText("You cannot delete that claim").formatted(Formatting.RED), false); return 0; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java index 75612dd..6d0cb51 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java @@ -20,11 +20,11 @@ public class RenameCommand { - public static void register(LiteralArgumentBuilder command) { + public static void register(LiteralArgumentBuilder command, boolean admin) { LiteralArgumentBuilder rename = literal("rename"); RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); RequiredArgumentBuilder nameArgument = argument("name", word()); - nameArgument.executes((context) -> rename(context, false)); + nameArgument.executes((context) -> rename(context, admin)); claimArgument.then(nameArgument); rename.then(claimArgument); command.then(rename); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java index 67b3dcd..e734dd1 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java @@ -14,15 +14,14 @@ import net.minecraft.text.LiteralText; import net.minecraft.util.Formatting; -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.StringArgumentType.string; +import static com.mojang.brigadier.arguments.StringArgumentType.*; +import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; public class RentCommand { - public static void register(LiteralArgumentBuilder command) { + public static void register(LiteralArgumentBuilder command, RequiredArgumentBuilder claim) { LiteralArgumentBuilder rent = literal("rent"); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - RequiredArgumentBuilder days = CommandManager.argument("days", string()); + RequiredArgumentBuilder days = argument("days", word()); days.executes(context -> rent(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), getString(context, "days"))); claim.then(days); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java index 479404e..274d24a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java @@ -1,7 +1,6 @@ package io.github.indicode.fabric.itsmine.command; import com.mojang.brigadier.arguments.IntegerArgumentType; -import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; @@ -18,21 +17,18 @@ import net.minecraft.text.LiteralText; import net.minecraft.util.Formatting; -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.StringArgumentType.string; +import static com.mojang.brigadier.arguments.StringArgumentType.*; import static net.minecraft.server.command.CommandManager.literal; public class RentableCommand { - public static void register(LiteralArgumentBuilder command) { + public static void register(LiteralArgumentBuilder command, RequiredArgumentBuilder claim) { LiteralArgumentBuilder rentable = literal("rentable"); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - RequiredArgumentBuilder currency = net.minecraft.server.command.CommandManager.argument("item", ItemStackArgumentType.itemStack()).suggests(ArgumentUtil::itemsSuggestion); RequiredArgumentBuilder amount = net.minecraft.server.command.CommandManager.argument("count", IntegerArgumentType.integer(1)); - RequiredArgumentBuilder days = net.minecraft.server.command.CommandManager.argument("days", StringArgumentType.string() + RequiredArgumentBuilder days = net.minecraft.server.command.CommandManager.argument("days", word() ); - RequiredArgumentBuilder maxdays = CommandManager.argument("maxdays", string()); + RequiredArgumentBuilder maxdays = CommandManager.argument("maxdays", word()); maxdays.executes(context -> makeRentable(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false), IntegerArgumentType.getInteger(context, "count"), getString(context, "days"), getString(context, "maxdays"))); claim.executes(context -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java index 910be0c..94dc43b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java @@ -7,7 +7,6 @@ import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.server.command.ServerCommandSource; @@ -23,9 +22,8 @@ public class RevenueCommand { - public static void register(LiteralArgumentBuilder command) { + public static void register(LiteralArgumentBuilder command, RequiredArgumentBuilder claim) { LiteralArgumentBuilder revenue = literal("revenue"); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); RequiredArgumentBuilder claimRevenue = argument("claimRevenue", BoolArgumentType.bool()); revenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); claim.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); @@ -58,7 +56,7 @@ private static int revenue(ServerCommandSource source, Claim claim, boolean clai source.sendFeedback(new LiteralText("No Revenue").formatted(Formatting.RED), true); return 0; } - Text text = new LiteralText("Revenue\n").formatted(Formatting.AQUA); + MutableText text = new LiteralText("Revenue\n").formatted(Formatting.AQUA); HashMap hashMap = new HashMap<>(); for(ItemStack itemStack : claim.rent.getRevenue()){ Item value = itemStack.getItem(); @@ -70,15 +68,16 @@ private static int revenue(ServerCommandSource source, Claim claim, boolean clai hashMap.forEach((item, integer) -> { boolean color = true; - text.append(new LiteralText(String.valueOf(integer)).append(" ").append(new TranslatableText(item.getTranslationKey())).append(" ").formatted(color ? Formatting.GOLD : Formatting.YELLOW)).styled(style -> { + text.append(new LiteralText(String.valueOf(integer)).append(new LiteralText(" ")).append(new TranslatableText(item.getTranslationKey())).append(new LiteralText(" ")).formatted(color ? Formatting.GOLD : Formatting.YELLOW)).styled(style -> { style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to claim revenue!").formatted(Formatting.GREEN))); - style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim revenue " + claim.name + " true")); + style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim revenue " + claim.name + " true")); + return style; }); color = !color; }); } - text.append("\n"); + text.append(new LiteralText("\n")); source.sendFeedback(text, true); return 1; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java index 0947c59..e3de687 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java @@ -99,17 +99,19 @@ private static int requestTransfer(ServerCommandSource sender, Claim claim, Serv } if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { - sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + sender.sendFeedback(new LiteralText("WARNING: This is not your claim...").formatted(Formatting.DARK_RED).formatted(Formatting.BOLD), false); } else { sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); return 0; } } sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to transfer ownership of \"" + claim.name + "\" to " + player.getGameProfile().getName() + "? ").formatted(Formatting.GOLD)) - .append(new LiteralText("[YES]").setStyle(new Style() - .setColor(Formatting.DARK_RED) - .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")))), false); + .append(new LiteralText("[YES]").styled(style -> { + style.withColor(Formatting.DARK_RED); + style.withBold(true); + style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")); + return style; + })), false); return 0; } private static Map pendingClaimTransfers = new HashMap<>(); @@ -128,7 +130,7 @@ private static int transfer(ServerCommandSource sender, Claim claim, ServerPlaye } if (!claim.claimBlockOwner.equals(sender.getPlayer().getGameProfile().getId())) { if (admin && ItsMine.permissions().hasPermission(sender, PermissionUtil.Command.ADMIN_MODIFY, 2)) { - sender.sendFeedback(new LiteralText("Transfering ownership of a claim belonging to somebody else").formatted(Formatting.DARK_RED, Formatting.BOLD), false); + sender.sendFeedback(new LiteralText("Transfering ownership of a claim belonging to somebody else").formatted(Formatting.DARK_RED).formatted(Formatting.BOLD), false); } else { sender.sendFeedback(new LiteralText("You can't transfer ownership of that claim").formatted(Formatting.RED), false); return 0; @@ -137,10 +139,12 @@ private static int transfer(ServerCommandSource sender, Claim claim, ServerPlaye GameProfile profile = sender.getWorld().getServer().getUserCache().getByUuid(claim.claimBlockOwner); sender.sendFeedback(new LiteralText("Transferring ownership of the claim \"" + claim.name + "\" to " + player.getGameProfile().getName() + " if they accept").formatted(Formatting.GREEN), claim.claimBlockOwner != player.getGameProfile().getId()); player.sendSystemMessage(new LiteralText("").append(new LiteralText("Do you want to accept ownership of the claim \"" + claim.name + "\" from " + profile == null ? "Not Present" : profile.getName() + "? ").formatted(Formatting.GOLD)) - .append(new LiteralText("[ACCEPT]").setStyle(new Style() - .setColor(Formatting.GREEN) - .setBold(true) - .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim transfer -accept-" + claim.name + " " + player.getEntityName() + " confirm"))))); + .append(new LiteralText("[ACCEPT]").styled(style -> { + style.withColor(Formatting.GREEN); + style.withBold(true); + style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim transfer -accept-" + claim.name + " " + player.getEntityName() + " confirm")); + return style; + }))); pendingClaimTransfers.put(player.getGameProfile().getId(), claim.name); return 0; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java index 826a439..d01eab7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java @@ -25,32 +25,30 @@ import static net.minecraft.server.command.CommandManager.literal; public class TrustCommand { - public static void register(LiteralArgumentBuilder command) { + public static void register(LiteralArgumentBuilder command, RequiredArgumentBuilder claim, boolean admin) { { LiteralArgumentBuilder trust = literal("trust"); RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); - RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); - playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, null))); - claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, getString(context, "claim")))); + playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, null, admin))); + claim.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, getString(context, "claim"), admin))); - playerArgument.then(claimArgument); + playerArgument.then(claim); trust.then(playerArgument); command.then(trust); } { LiteralArgumentBuilder distrust = literal("distrust"); RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); - RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); - playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, null))); - claimArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, getString(context, "claim")))); + playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, null, admin))); + claim.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, getString(context, "claim"), admin))); - playerArgument.then(claimArgument); + playerArgument.then(claim); distrust.then(playerArgument); command.then(distrust); } } - private static int executeTrust(CommandContext context, Collection targetCollection, boolean set, @Nullable String claimName) throws CommandSyntaxException { + private static int executeTrust(CommandContext context, Collection targetCollection, boolean set, @Nullable String claimName, boolean admin) throws CommandSyntaxException { AtomicInteger integer = new AtomicInteger(); if(targetCollection.isEmpty()){ @@ -64,7 +62,7 @@ private static int executeTrust(CommandContext context, Col try { //This is supposed to check if the player has played before :shrug: if(context.getSource().getMinecraftServer().getUserCache().getByUuid(gameProfile.getId()) == gameProfile){ - integer.set(setTrust(context, claim, gameProfile, set, false)); + integer.set(setTrust(context, claim, gameProfile, set, admin)); } else { context.getSource().sendFeedback(new LiteralText("Unknown player!").formatted(Formatting.RED), true); integer.set(0); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java index 092aa45..8f3bb14 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java @@ -11,10 +11,7 @@ import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.HoverEvent; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; +import net.minecraft.text.*; import net.minecraft.util.Formatting; import java.util.concurrent.atomic.AtomicInteger; @@ -59,41 +56,42 @@ static int showTrustedList(CommandContext context, Claim cl return -1; } - Text text = new LiteralText("\n"); + MutableText text = new LiteralText("\n"); text.append(new LiteralText("Trusted players for Claim ").formatted(Formatting.YELLOW)) - .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append("\n"); + .append(new LiteralText(claim.name).formatted(Formatting.GOLD)).append(new LiteralText("\n")); AtomicInteger atomicInteger = new AtomicInteger(); claim.permissionManager.playerPermissions.forEach((uuid, perm) -> { atomicInteger.incrementAndGet(); - Text pText = new LiteralText(""); - Text owner; + MutableText pText = new LiteralText(""); + MutableText owner; GameProfile profile = source.getMinecraftServer().getUserCache().getByUuid(uuid); if (profile != null) { owner = new LiteralText(profile.getName()); } else { owner = new LiteralText(uuid.toString()).styled((style) -> { style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to Copy"))); - style.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); + style.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); + return style; }); } pText.append(new LiteralText(atomicInteger.get() + ". ").formatted(Formatting.GOLD)) .append(owner.formatted(Formatting.YELLOW)); - Text hover = new LiteralText(""); - hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append("\n"); + MutableText hover = new LiteralText(""); + hover.append(new LiteralText("Permissions:").formatted(Formatting.WHITE)).append(new LiteralText("\n")); int allowed = 0; int i = 0; boolean nextColor = false; - Text perms = new LiteralText(""); + MutableText perms = new LiteralText(""); for (Claim.Permission value : Claim.Permission.values()) { if (claim.permissionManager.hasPermission(uuid, value)) { Formatting formatting = nextColor ? Formatting.GREEN : Formatting.DARK_GREEN; - perms.append(new LiteralText(value.id).formatted(formatting)).append(" "); - if (i == 3) perms.append("\n"); + perms.append(new LiteralText(value.id).formatted(formatting)).append(new LiteralText(" ")); + if (i == 3) perms.append(new LiteralText("\n")); allowed++; i++; nextColor = !nextColor; @@ -101,7 +99,7 @@ static int showTrustedList(CommandContext context, Claim cl } if (allowed == Claim.Permission.values().length) { - hover.append(new LiteralText("All " + allowed + " Permissions").formatted(Formatting.YELLOW, Formatting.ITALIC)); + hover.append(new LiteralText("All " + allowed + " Permissions").formatted(Formatting.YELLOW).formatted(Formatting.ITALIC)); } else { hover.append(perms); } @@ -115,7 +113,7 @@ static int showTrustedList(CommandContext context, Claim cl ); pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); - text.append(pText).append("\n"); + text.append(pText).append(new LiteralText("\n")); }); source.sendFeedback(text, false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java index 52ab85d..959fbc9 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java @@ -6,11 +6,13 @@ import io.github.indicode.fabric.itsmine.command.ExceptionCommand; import io.github.indicode.fabric.itsmine.command.PermissionsCommand; import io.github.indicode.fabric.itsmine.command.SettingsCommand; +import io.github.indicode.fabric.itsmine.command.subzone.SubzoneCommand; import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.server.command.ServerCommandSource; import java.util.function.Predicate; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.*; import static net.minecraft.server.command.CommandManager.literal; public class AdminCommand { @@ -27,7 +29,7 @@ private static void registerAdmin(LiteralArgumentBuilder ad ClaimsCommand.register(admin, dispatcher); CreateCommand.register(admin); EntitiesCommand.register(admin); - ExceptionCommand.register(admin, true, ArgumentUtil.getClaims()); + ExceptionCommand.register(admin, true, getClaims()); ExpandCommand.register(admin); IgnoreCommand.register(admin); ListAllCommand.register(admin); @@ -35,7 +37,8 @@ private static void registerAdmin(LiteralArgumentBuilder ad PermissionsCommand.register(admin, true); RemoveCommand.register(admin); RenameCommand.register(admin); - SettingsCommand.register(admin, true); +// SettingsCommand.register(admin, true); + SubzoneCommand.register(admin, dispatcher, true); } private static Predicate perm(String str) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java index 69de7bf..77b8229 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java @@ -9,10 +9,7 @@ import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.HoverEvent; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; +import net.minecraft.text.*; import net.minecraft.util.Formatting; import java.util.List; @@ -42,12 +39,12 @@ public static int list(ServerCommandSource source, String target) throws Command } - Text text = new LiteralText("\n").append(new LiteralText("Claims (" + target + "): ").formatted(Formatting.GOLD)).append("\n "); + MutableText text = new LiteralText("\n").append(new LiteralText("Claims (" + target + "): ").formatted(Formatting.GOLD)).append("\n "); boolean nextColor = false; for (Claim claim : claims) { if(!claim.isChild) { - Text cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { - Text hoverText = new LiteralText("Click for more Info").formatted(Formatting.GREEN); + MutableText cText = new LiteralText(claim.name).formatted(nextColor ? Formatting.YELLOW : Formatting.GOLD).styled((style) -> { + MutableText hoverText = new LiteralText("Click for more Info").formatted(Formatting.GREEN); if (claim.children.size() > 0) { hoverText.append("\n\nSubzones:"); for (Claim subzone : claim.children) { @@ -56,7 +53,8 @@ public static int list(ServerCommandSource source, String target) throws Command } style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); - style.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); + style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); + return style; }); nextColor = !nextColor; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java index 5810829..23b6fd5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java @@ -23,7 +23,7 @@ public static void register(LiteralArgumentBuilder command) Claim claim1 = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { - context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); + context.getSource().sendFeedback(new LiteralText(entityType.getName().asString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); }); return 1; }); @@ -31,7 +31,7 @@ public static void register(LiteralArgumentBuilder command) Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { - context.getSource().sendFeedback(new LiteralText(entityType.getName().asFormattedString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); + context.getSource().sendFeedback(new LiteralText(entityType.getName().asString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); }); return 1; }); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java index fd94c46..36150cd 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java @@ -1,34 +1,58 @@ package io.github.indicode.fabric.itsmine.command.admin; +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.util.MessageUtil; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; import net.minecraft.text.Text; import net.minecraft.util.Formatting; +import java.util.ArrayList; import java.util.List; import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getPlayers; import static io.github.indicode.fabric.itsmine.util.ClaimUtil.getClaims; +import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; public class ListAllCommand { public static void register(LiteralArgumentBuilder command) { LiteralArgumentBuilder listall = literal("listall"); - RequiredArgumentBuilder player = getPlayers(); - listall.executes(context -> listall(context.getSource())); + RequiredArgumentBuilder page = argument("page", IntegerArgumentType.integer(1)); + RequiredArgumentBuilder entries = argument("entries", IntegerArgumentType.integer(1, 100)); + RequiredArgumentBuilder offline = argument("offline", BoolArgumentType.bool()); + entries.executes(context -> listall(context.getSource(), IntegerArgumentType.getInteger(context, "page"), IntegerArgumentType.getInteger(context, "entries"), BoolArgumentType.getBool(context, "offline"))); + page.executes(context -> listall(context.getSource(), IntegerArgumentType.getInteger(context, "page"), 10, BoolArgumentType.getBool(context, "offline"))); + listall.executes(context -> listall(context.getSource(), 1, 10, BoolArgumentType.getBool(context, "offline"))); + page.then(entries); + offline.then(page); + listall.then(offline); command.then(listall); } - private static int listall(ServerCommandSource source){ + private static int listall(ServerCommandSource source, int page, int entries, boolean offline){ List claims = getClaims(); - Text text = new LiteralText("\n").append(new LiteralText("Claims").formatted(Formatting.GOLD)).append("\n "); + Text title = new LiteralText("Claim List:").formatted(Formatting.AQUA).formatted(Formatting.UNDERLINE); + ArrayList claimList = new ArrayList<>(); for (Claim claim : claims) { - Text cText = new LiteralText(claim.name).formatted(Formatting.GOLD); - text.append(cText.append(" ")); + if(offline) { + claimList.add(new LiteralText(claim.name).formatted(Formatting.GOLD).append(new LiteralText(" "))); + } + else { +// source.getMinecraftServer().getPlayerManager(). + source.getMinecraftServer().getPlayerManager().getPlayerList().forEach(serverPlayerEntity -> { + ClaimManager.INSTANCE.getPlayerClaims(serverPlayerEntity.getUuid()).forEach(claim1 -> { + claimList.add(new LiteralText(claim.name).formatted(Formatting.GOLD).append(new LiteralText(" ")).append(new LiteralText(String.valueOf(claim1.getEntities(source.getWorld()))).formatted(Formatting.YELLOW))); + }); + }); + } } - source.sendFeedback(text.append("\n"), false); + MessageUtil.sendPage(source, title, entries, page, "/claim admin listall " + offline + " %page% " + entries, claimList); return 1; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java index 316565b..da6397e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java @@ -25,7 +25,7 @@ public class CreateCommand { - public static void register(LiteralArgumentBuilder command) { + public static void register(LiteralArgumentBuilder command, boolean admin) { { LiteralArgumentBuilder create = CommandManager.literal("create"); @@ -33,7 +33,7 @@ public static void register(LiteralArgumentBuilder command) .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), null, false)); RequiredArgumentBuilder claim = ArgumentUtil.getClaims() - .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), StringArgumentType.getString(ctx, "claim"), false)); + .executes(ctx -> addZone(ctx.getSource(), StringArgumentType.getString(ctx, "name"), StringArgumentType.getString(ctx, "claim"), admin)); name.then(claim); create.then(name); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java index a206975..5d2ab4b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java @@ -3,33 +3,30 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import io.github.indicode.fabric.itsmine.command.*; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.server.command.ServerCommandSource; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getSubzones; import static net.minecraft.server.command.CommandManager.literal; public class SubzoneCommand { - public static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { + public static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher, boolean admin) { LiteralArgumentBuilder subzone = literal("subzone"); - registerSubzone(subzone, dispatcher); + registerSubzone(subzone, dispatcher, admin); command.then(subzone); } - public static void registerSubzone(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { - CreateCommand.register(command); - ExceptionCommand.register(command, false, ArgumentUtil.getSubzones()); - ExpandCommand.register(command); - InfoCommand.register(command); - PermissionsCommand.register(command, false); - RemoveCommand.register(command); - RenameCommand.register(command); - RentableCommand.register(command); - RentCommand.register(command); - RevenueCommand.register(command); - SettingsCommand.register(command, false); - ShowCommand.register(command); -// SubzoneCommand.register(command, dispatcher); - TrustCommand.register(command); + public static void registerSubzone(LiteralArgumentBuilder command, CommandDispatcher dispatcher, boolean admin) { + CreateCommand.register(command, admin); + ExceptionCommand.register(command, admin, getSubzones()); + ExpandCommand.register(command, admin); + InfoCommand.register(command, getSubzones()); + PermissionsCommand.register(command, admin); + RemoveCommand.register(command, getSubzones(), admin); + RenameCommand.register(command, admin); + RentableCommand.register(command, getSubzones()); + RentCommand.register(command, getSubzones()); + RevenueCommand.register(command, getSubzones()); + TrustCommand.register(command, getSubzones(), true); TrustedCommand.register(command); } } \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java index e8290f2..a38d073 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java @@ -8,17 +8,26 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.explosion.Explosion; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; /** * @author Indigo Amann */ @Mixin(Explosion.class) public class ExplosionMixin { + @Shadow @Final private World world; + @Redirect(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;")) private BlockState theyCallMeBedrock(World world, BlockPos pos) { + System.out.println("Running method1"); Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); if (claim != null && !world.isAir(pos) && !world.getBlockState(pos).getBlock().equals(Blocks.TNT)) { if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) { @@ -30,6 +39,7 @@ private BlockState theyCallMeBedrock(World world, BlockPos pos) { @Redirect(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isImmuneToExplosion()Z")) private boolean claimDeniesExplosion(Entity entity) { + System.out.println("Running method2"); BlockPos blockPos_1 = entity.getBlockPos(); Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, entity.world.getDimension().getType()); if (claim != null) { @@ -40,4 +50,9 @@ private boolean claimDeniesExplosion(Entity entity) { return entity.isImmuneToExplosion(); } + + @Inject(method = "getAffectedBlocks", at = @At(value = "HEAD")) + private void dontAffectMe(CallbackInfoReturnable> cir){ + System.out.println("Running method3"); + } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java deleted file mode 100644 index c6d7d2c..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/IntegratedServerMixin.java +++ /dev/null @@ -1,52 +0,0 @@ -package io.github.indicode.fabric.itsmine.mixin; - -import com.google.gson.JsonElement; -import io.github.indicode.fabric.itsmine.ClaimManager; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.NbtIo; -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.integrated.IntegratedServer; -import net.minecraft.world.level.LevelGeneratorOptions; -import net.minecraft.world.level.LevelGeneratorType; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; - -/** - * @author Indigo Amann - */ -@Mixin(IntegratedServer.class) -public class IntegratedServerMixin { - @Inject(method = "loadWorld", at = @At("RETURN")) - private void loadClaims(java.lang.String name, long l, LevelGeneratorOptions levelGeneratorOptions, CallbackInfo ci) { - File claims = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat"); - File claims_old = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat_old"); - ClaimManager.INSTANCE = new ClaimManager(); - if (!claims.exists()) { - if (claims_old.exists()) {} - else return; - } - try { - if (!claims.exists() && claims_old.exists()) throw new FileNotFoundException(); - ClaimManager.INSTANCE.fromNBT(NbtIo.readCompressed(new FileInputStream(claims))); - } catch (IOException e) { - System.err.println("Could not load claims.dat:"); - e.printStackTrace(); - if (claims_old.exists()) { - System.out.println("Attempting to load backup claims..."); - try { - ClaimManager.INSTANCE.fromNBT(NbtIo.readCompressed(new FileInputStream(claims_old))); - } catch (IOException e2) { - throw new RuntimeException("Could not load claims.dat_old - Crashing server to save data. Remove or fix claims.dat or claims.dat_old to continue"); - - } - } - } - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java new file mode 100644 index 0000000..227ddac --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java @@ -0,0 +1,71 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import io.github.indicode.fabric.itsmine.ClaimManager; +import net.minecraft.class_5219; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtIo; +import net.minecraft.world.level.storage.LevelStorage; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.io.*; +import java.nio.file.Path; + +@Mixin(LevelStorage.Session.class) +public class LevelStorageSessionMixin { + @Shadow + @Final + private Path directory; + + @Inject(method = "readLevelProperties", at = @At("HEAD")) + public void readWorldProperties(CallbackInfoReturnable callbackInfo) { + ClaimManager.INSTANCE = new ClaimManager(); + File claims = new File(directory.toFile() + "/claims.dat"); + File claims_old = new File(directory.toFile() + "/claims.dat_old"); + if (!claims.exists()) { + if (claims_old.exists()) {} + else return; + } + try { + if (!claims.exists() && claims_old.exists()) throw new FileNotFoundException(); + ClaimManager.INSTANCE.fromNBT(NbtIo.readCompressed(new FileInputStream(claims))); + } catch (IOException e) { + System.err.println("Could not load claims.dat:"); + e.printStackTrace(); + if (claims_old.exists()) { + System.out.println("Attempting to load backup claims..."); + try { + ClaimManager.INSTANCE.fromNBT(NbtIo.readCompressed(new FileInputStream(claims_old))); + } catch (IOException e2) { + throw new RuntimeException("Could not load claims.dat_old - Crashing server to save data. Remove or fix claims.dat or claims.dat_old to continue"); + } + } + } + } + + @Inject(method = "method_27426", at = @At("HEAD")) + public void saveWorld(class_5219 levelProperties, CompoundTag compoundTag, CallbackInfo info) { + if (ClaimManager.INSTANCE != null) { + File claimDataFile = new File(directory.toFile(), "claims.dat"); + if (claimDataFile.exists()) { + File old = new File(directory.toFile(), "claims.dat_old"); + if (old.exists()) old.delete(); + claimDataFile.renameTo(old); + claimDataFile.delete(); + } + try { + claimDataFile.createNewFile(); + CompoundTag tag = ClaimManager.INSTANCE.toNBT(); + NbtIo.writeCompressed(tag, new FileOutputStream(claimDataFile)); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java deleted file mode 100644 index fc1bfa5..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java +++ /dev/null @@ -1,54 +0,0 @@ -package io.github.indicode.fabric.itsmine.mixin; - -import com.google.gson.JsonElement; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.NbtIo; -import net.minecraft.server.MinecraftServer; -import net.minecraft.world.level.LevelGeneratorType; -import net.minecraft.world.level.LevelGeneratorOptions; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; - -/** - * @author Indigo Amann - */ -@Mixin(MinecraftServer.class) -public abstract class MinecraftServerMixin { - @Inject(method = "loadWorld", at = @At("RETURN")) - private void loadClaims(String name, long l, LevelGeneratorOptions levelGeneratorOptions, CallbackInfo ci) { - ClaimManager.INSTANCE = new ClaimManager(); - File claims = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat"); - File claims_old = new File(((MinecraftServer)(Object)this).getRunDirectory() + "/" + name + "/claims.dat_old"); - if (!claims.exists()) { - if (claims_old.exists()) {} - else return; - } - try { - if (!claims.exists() && claims_old.exists()) throw new FileNotFoundException(); - ClaimManager.INSTANCE.fromNBT(NbtIo.readCompressed(new FileInputStream(claims))); - } catch (IOException e) { - System.err.println("Could not load claims.dat:"); - e.printStackTrace(); - if (claims_old.exists()) { - System.out.println("Attempting to load backup claims..."); - try { - ClaimManager.INSTANCE.fromNBT(NbtIo.readCompressed(new FileInputStream(claims_old))); - } catch (IOException e2) { - throw new RuntimeException("Could not load claims.dat_old - Crashing server to save data. Remove or fix claims.dat or claims.dat_old to continue"); - } - } - } - } - -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index f6f8b14..8e854fe 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -90,7 +90,7 @@ public boolean canBreak(ServerWorld world, PlayerEntity player, BlockPos pos) { if (posPair.getLeft() != null) { player.sendSystemMessage(new LiteralText("Area Selected. Type /claim create to create your claim!").formatted(Formatting.GOLD)); if (!Config.claims2d) - player.sendSystemMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE, Formatting.ITALIC)); + player.sendSystemMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE).formatted(Formatting.ITALIC)); } return false; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java index fa903c6..0b166f9 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java @@ -41,17 +41,6 @@ public abstract class ServerWorldMixin implements MonitorableWorld { @Shadow public abstract void playGlobalEvent(int type, BlockPos pos, int data); - // @Inject(method = "canPlayerModifyAt", at = @At("HEAD"), cancellable = true) -// private void canMine(PlayerEntity player, BlockPos blockPos_1, CallbackInfoReturnable ci) { -// if (player.world.isClient()) return; -// Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, player.getEntityWorld().getDimension().getType()); -// if (claim != null) { -// if (!claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.SPAWN_PROTECTION)) { -// player.sendSystemMessage(Messages.NO_PERMISSION); -// ci.setReturnValue(false); -// } -// } -// } @Redirect(method = "sendBlockActions", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;sendToAround(Lnet/minecraft/entity/player/PlayerEntity;DDDDLnet/minecraft/world/dimension/DimensionType;Lnet/minecraft/network/Packet;)V")) private void sendPistonUpdate(PlayerManager manager, PlayerEntity playerEntity_1, double double_1, double double_2, double double_3, double double_4, DimensionType dimensionType_1, Packet packet_1) { manager.sendToAround(playerEntity_1, double_1, double_2, double_3, double_4, dimensionType_1, packet_1); @@ -75,14 +64,6 @@ public void tickActions(BooleanSupplier shouldKeepTicking, CallbackInfo ci){ }); } -// AtomicReference atomicReference = new AtomicReference<>(); -// public ServerPlayerEntity getPlayerByUUID(UUID uuid){ -// this.getPlayers().forEach(serverPlayerEntity -> { -// if(serverPlayerEntity.getUuid() == uuid) -// atomicReference.set(serverPlayerEntity); -// }); -// return atomicReference.get(); -// } @Override public int loadedEntities() { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java index 74e5941..fc137d1 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java @@ -32,7 +32,7 @@ private void setStickPositionFirst(ItemUsageContext context, CallbackInfoReturna context.getPlayer().sendSystemMessage(new LiteralText("Position #1 set: " + context.getBlockPos().getX() + (Config.claims2d ? "" : " " + context.getBlockPos().getY()) + " " + context.getBlockPos().getZ()).formatted(Formatting.GREEN)); if (posPair.getRight() != null) { context.getPlayer().sendSystemMessage(new LiteralText("Area Selected. Type /claim create to create your claim!").formatted(Formatting.GOLD)); - if (!Config.claims2d) context.getPlayer().sendSystemMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE, Formatting.ITALIC)); + if (!Config.claims2d) context.getPlayer().sendSystemMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE).formatted(Formatting.ITALIC)); } cir.setReturnValue(ActionResult.SUCCESS); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/WorldSaveHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/WorldSaveHandlerMixin.java deleted file mode 100644 index 16bcdfd..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/WorldSaveHandlerMixin.java +++ /dev/null @@ -1,46 +0,0 @@ -package io.github.indicode.fabric.itsmine.mixin; - -import io.github.indicode.fabric.itsmine.ClaimManager; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.NbtIo; -import net.minecraft.world.WorldSaveHandler; -import net.minecraft.world.level.LevelProperties; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; - -/** - * @author Indigo Amann - */ -@Mixin(WorldSaveHandler.class) -public class WorldSaveHandlerMixin { - @Inject(method = "saveWorld(Lnet/minecraft/world/level/LevelProperties;Lnet/minecraft/nbt/CompoundTag;)V", at = @At("RETURN")) - private void onSaveWorld(LevelProperties levelProperties_1, CompoundTag compoundTag_1, CallbackInfo ci) { - if (ClaimManager.INSTANCE != null) { - File claimDataFile = new File(worldDir, "claims.dat"); - if (claimDataFile.exists()) { - File old = new File(worldDir, "claims.dat_old"); - if (old.exists()) old.delete(); - claimDataFile.renameTo(old); - claimDataFile.delete(); - } - try { - claimDataFile.createNewFile(); - CompoundTag tag = ClaimManager.INSTANCE.toNBT(); - NbtIo.writeCompressed(tag, new FileOutputStream(claimDataFile)); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - @Shadow - private File worldDir; -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java index 8fbb447..031f31a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java @@ -27,7 +27,7 @@ public class ArgumentUtil { public static RequiredArgumentBuilder getSubAndClaims() { - return argument("claim", word()).suggests(CLAIM__SUBZONE_PROVIDER); + return argument("claim", word()).suggests(ArgumentUtil::claimSubzoneProvider); } public static RequiredArgumentBuilder getClaims() { @@ -35,7 +35,7 @@ public static RequiredArgumentBuilder getClaims() { } public static RequiredArgumentBuilder getSubzones() { - return argument("subzone", word()).suggests(ArgumentUtil::subzoneProvider); + return argument("claim", word()).suggests(ArgumentUtil::subzoneProvider); } public static RequiredArgumentBuilder getDirections() { @@ -63,14 +63,13 @@ public static RequiredArgumentBuilder getEventMessa - private static final SuggestionProvider CLAIM__SUBZONE_PROVIDER = (source, builder) -> { - ServerPlayerEntity player = source.getSource().getPlayer(); + private static CompletableFuture claimSubzoneProvider(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { + ServerPlayerEntity player = context.getSource().getPlayer(); List names = new ArrayList<>(); Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); if (current != null) names.add(current.name); for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { if (claim != null) { - System.out.println("Claim " + claim.name); names.add(claim.name); } } @@ -90,7 +89,7 @@ private static CompletableFuture claimProvider(CommandContext subzoneProvider(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { + private static CompletableFuture subzoneProvider(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { ServerPlayerEntity player = context.getSource().getPlayer(); List names = new ArrayList<>(); Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); @@ -100,7 +99,6 @@ public static CompletableFuture subzoneProvider(CommandContext content){ + int pages = Math.floorDiv(content.size(), entrys); + if(content.size() % entrys != 0) pages++; + if(page < 1) return; + if(page > pages) return; + LiteralText message = new LiteralText(""); + message.append(header).append(new LiteralText("\n\n")); + + for(int i = (entrys * (page - 1) + 1); i <= page * entrys; i++) message.append(content.get(i-1)).append(new LiteralText("\n")); + message.append(new LiteralText("\n")); + Text button_prev = new LiteralText("") + .append(new LiteralText("<-").formatted(Formatting.WHITE).formatted(Formatting.BOLD)) + .append(new LiteralText(" ")).append(new LiteralText("Prev").formatted(Formatting.GOLD)) + .styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((page - 1 >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); + if (page - 1 >= 0) { + style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); + } + return style; + }).append(new LiteralText(" ")); + int finalPages = pages; + Text button_next = new LiteralText(" ") + .append(new LiteralText("Next").formatted(Formatting.GOLD)) + .append(new LiteralText(" ")).append(new LiteralText("->").formatted(Formatting.WHITE).formatted(Formatting.BOLD)).append(new LiteralText(" ")) + .styled((style) -> { + style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((page + 1 <= finalPages) ? ">>>" : ">|").formatted(Formatting.GRAY))); + if (page + 1 <= finalPages) + style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page + 1)))); + return style; + }); + Text center = new LiteralText("").append(new LiteralText(String.valueOf(page)).formatted(Formatting.GREEN).append(new LiteralText("/").formatted(Formatting.GRAY)).append(new LiteralText(String.valueOf(pages)).formatted(Formatting.GREEN))); + if(page > 1) message.append(button_prev); + message.append(center); + if(page < pages) message.append(button_next); + sendText(source, message); + } + + public static void sendText(ServerCommandSource source, LiteralText text){ + source.sendFeedback(text, false); + } + + + +} diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index d92caaf..9df5a3c 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -3,8 +3,7 @@ "package": "io.github.indicode.fabric.itsmine.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ - "WorldSaveHandlerMixin", - "MinecraftServerMixin", + "LevelStorageSessionMixin", "CommandManagerMixin", "BlockUpdatePacketMixin", "BucketItemMixin", @@ -36,9 +35,6 @@ "AnimalEntityMixin", "LecternScreenHandlerMixin" ], - "client": [ - "IntegratedServerMixin" - ], "injectors": { "defaultRequire": 1 } From 668cc5b9ef1a316a06db1d6ebf26b3876d837f59 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Tue, 28 Apr 2020 14:35:17 +0200 Subject: [PATCH 67/85] Fix CreateCommand NPE --- .../github/indicode/fabric/itsmine/Claim.java | 1 - .../indicode/fabric/itsmine/ClaimManager.java | 1 + .../indicode/fabric/itsmine/Config.java | 2 + .../indicode/fabric/itsmine/Messages.java | 40 ++--- .../fabric/itsmine/MonitorableWorld.java | 1 + .../itsmine/command/CommandManager.java | 23 +-- .../fabric/itsmine/command/CreateCommand.java | 15 +- .../itsmine/command/ExceptionCommand.java | 166 ------------------ .../fabric/itsmine/command/HelpCommand.java | 16 +- .../fabric/itsmine/command/InfoCommand.java | 6 +- .../itsmine/command/MessageCommand.java | 45 +++++ .../itsmine/command/PermissionCommand.java | 109 ++++++++++++ .../itsmine/command/PermissionsCommand.java | 49 ------ .../fabric/itsmine/command/RemoveCommand.java | 5 +- .../fabric/itsmine/command/RentCommand.java | 3 +- .../itsmine/command/RentableCommand.java | 5 +- .../itsmine/command/RevenueCommand.java | 6 +- .../itsmine/command/SettingsCommand.java | 6 +- .../itsmine/command/TransferCommand.java | 5 +- .../itsmine/command/TrustedCommand.java | 8 +- .../itsmine/command/admin/AdminCommand.java | 13 +- .../itsmine/command/admin/ClaimsCommand.java | 5 +- .../command/admin/EntitiesCommand.java | 67 +++++-- .../itsmine/command/admin/ListAllCommand.java | 26 ++- .../command/subzone/SubzoneCommand.java | 7 +- .../itsmine/mixin/AnimalEntityMixin.java | 11 +- .../itsmine/mixin/CommandManagerMixin.java | 3 +- .../fabric/itsmine/mixin/ExplosionMixin.java | 7 - .../mixin/LecternScreenHandlerMixin.java | 31 +++- .../mixin/ServerCommandOutputMixin.java | 18 ++ .../itsmine/mixin/ServerWorldMixin.java | 4 +- .../fabric/itsmine/util/ArgumentUtil.java | 15 ++ .../fabric/itsmine/util/BlockUtil.java | 2 +- .../fabric/itsmine/util/EntityUtil.java | 44 +++++ .../fabric/itsmine/util/MessageUtil.java | 39 ++-- .../fabric/itsmine/util/PermissionUtil.java | 4 + .../fabric/itsmine/util/WorldUtil.java | 13 ++ src/main/resources/itsmine.mixins.json | 3 +- 38 files changed, 446 insertions(+), 378 deletions(-) delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/MessageCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/PermissionCommand.java delete mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerCommandOutputMixin.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/WorldUtil.java diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java index c6f5351..0356eb0 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Claim.java @@ -92,7 +92,6 @@ public int getEntities(ServerWorld world){ entities.set(entities.get()+1); } }); - return entities.get(); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java index cf9d404..1367d15 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java @@ -23,6 +23,7 @@ public class ClaimManager { private HashMap blocksLeft = new HashMap<>(); public List ignoringClaims = new ArrayList<>(); public List flyers = new ArrayList<>(); + public MinecraftServer server; public int getClaimBlocks(UUID id) { return blocksLeft.getOrDefault(id, Config.claims2d ? Config.baseClaimBlocks2d : Config.baseClaimBlocks3d); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/Config.java index 9152cb6..49aae0e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Config.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Config.java @@ -10,6 +10,7 @@ public class Config { public static int baseClaimBlocks2d = 2500; public static boolean claims2d = true; public static int rent_maxseconds = 7776000; + public static int claim_max_entities_passive = 100; public static String permissionManager = "luckperms"; public static String prefix = "&8[&aClaims&8]&r "; public static String msg_no_perm = "&c&lHey!&r&c Sorry but you don't have permission to do that"; @@ -34,6 +35,7 @@ static void sync() { baseClaimBlocks2d = config.getInt("2D base claim blocks", baseClaimBlocks2d, "Area Filled: " + ItsMine.blocksToAreaString2d(baseClaimBlocks2d)); baseClaimBlocks3d = config.getInt("3D base claim blocks", baseClaimBlocks3d, "Area Filled: " + ItsMine.blocksToAreaString3d(baseClaimBlocks3d)); rent_maxseconds = config.getInt("rent.maxdays", rent_maxseconds, "Maximum rent time in seconds (eg. 90d = 7776000)"); + claim_max_entities_passive = config.getInt("claim.max.passive", claim_max_entities_passive, "Maximum allowed passive entities per claim"); permissionManager = config.getString("permissionManager", permissionManager, "Values: thimble, luckperms, vanilla"); prefix = config.getString("msg.prefix", prefix); msg_interact_entity = config.getString("msg.interact.entity", msg_interact_entity); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 456de69..6551b1e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -8,37 +8,37 @@ public class Messages { public static final MutableText PREFIX = new LiteralText(ChatColor.translate(Config.prefix)); - public static final Text INVALID_CLAIM = PREFIX.append(new LiteralText("Can not find a claim with that name or a claim at your position").formatted(Formatting.RED)); + public static final Text INVALID_CLAIM = PREFIX.copy().append(new LiteralText("Can not find a claim with that name or a claim at your position").formatted(Formatting.RED)); - public static final Text INVALID_SETTING = PREFIX.append(new LiteralText("Invalid Claim Setting!").formatted(Formatting.RED)); + public static final Text INVALID_SETTING = PREFIX.copy().append(new LiteralText("Invalid Claim Setting!").formatted(Formatting.RED)); - public static final Text NO_PERMISSION = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_no_perm))); + public static final Text NO_PERMISSION = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_no_perm))); - public static final Text INVALID_MESSAGE_EVENT = PREFIX.append(new LiteralText("Invalid Message Event!")); + public static final Text INVALID_MESSAGE_EVENT = PREFIX.copy().append(new LiteralText("Invalid Message Event!")); - public static final Text INVALID_PLAYER = PREFIX.append(new LiteralText("Can not find a Player with that Name!")); + public static final Text INVALID_PLAYER = PREFIX.copy().append(new LiteralText("Can not find a Player with that Name!")); - public static final Text TOO_MANY_SELECTIONS = PREFIX.append(new LiteralText("Only one selection is allowed!")); + public static final Text TOO_MANY_SELECTIONS = PREFIX.copy().append(new LiteralText("Only one selection is allowed!")); - public static final Text MSG_PLACE_BLOCK = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_place_block)).formatted(Formatting.RED)); + public static final Text MSG_PLACE_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_place_block)).formatted(Formatting.RED)); - public static final Text MSG_BREAK_BLOCK = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_break_block)).formatted(Formatting.RED)); + public static final Text MSG_BREAK_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_break_block)).formatted(Formatting.RED)); - public static final Text MSG_CANT_ENTER = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_cant_enter)).formatted(Formatting.RED)); + public static final Text MSG_CANT_ENTER = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_enter)).formatted(Formatting.RED)); - public static final Text MSG_INTERACT_ENTITY = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_interact_entity)).formatted(Formatting.RED)); + public static final Text MSG_INTERACT_ENTITY = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_interact_entity)).formatted(Formatting.RED)); - public static final Text MSG_INTERACT_BLOCK = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_interact_block)).formatted(Formatting.RED)); + public static final Text MSG_INTERACT_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_interact_block)).formatted(Formatting.RED)); - public static final Text MSG_OPEN_CONTAINER = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_open_container)).formatted(Formatting.RED)); + public static final Text MSG_OPEN_CONTAINER = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_open_container)).formatted(Formatting.RED)); - public static final Text MSG_DAMAGE_ENTITY = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_attack_entity)).formatted(Formatting.RED)); + public static final Text MSG_DAMAGE_ENTITY = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_attack_entity)).formatted(Formatting.RED)); - public static final Text MSG_CANT_USE = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_cant_use)).formatted(Formatting.RED)); + public static final Text MSG_CANT_USE = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_use)).formatted(Formatting.RED)); - public static final Text MSG_LONG_NAME = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_long_name)).formatted(Formatting.RED)); + public static final Text MSG_LONG_NAME = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_long_name)).formatted(Formatting.RED)); - public static final Text MSG_CANT_DO = PREFIX.append(new LiteralText(ChatColor.translate(Config.msg_cant_do)).formatted(Formatting.RED)); + public static final Text MSG_CANT_DO = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_do)).formatted(Formatting.RED)); public static final Text[] GET_STARTED = new MutableText[]{ header("How to Claim (Basics)") @@ -138,19 +138,19 @@ public class Messages { .append(line("&6break_farmlands ").append(text("Allow turning Farmlands into Dirt by jumping on them"))) }; - private static MutableText header(String title) { + public static MutableText header(String title) { return new LiteralText("").append(new LiteralText(title + ":").formatted(Formatting.AQUA).formatted(Formatting.UNDERLINE)).formatted(Formatting.WHITE).append(new LiteralText("\n")); } - private static MutableText line(int num, String string) { + public static MutableText line(int num, String string) { return line("&e" + num + ".&e " + string); } - private static MutableText line(String string) { + public static MutableText line(String string) { return new LiteralText("\n").append(new LiteralText(ChatColor.translate(string))).formatted(Formatting.YELLOW); } - private static MutableText text(String text) { + public static MutableText text(String text) { return new LiteralText(ChatColor.translate(text)); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java b/src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java index be6d40a..f367c72 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/MonitorableWorld.java @@ -2,6 +2,7 @@ import net.minecraft.entity.Entity; +import java.util.ArrayList; import java.util.Map; import java.util.UUID; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java index 998c2c7..c943654 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java @@ -2,42 +2,45 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.sun.org.apache.xpath.internal.Arg; import io.github.indicode.fabric.itsmine.command.admin.AdminCommand; import io.github.indicode.fabric.itsmine.command.subzone.SubzoneCommand; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.server.command.ServerCommandSource; import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getClaims; -import static net.minecraft.server.command.CommandManager.literal; + public class CommandManager { - public static void register(CommandDispatcher dispatcher) { - LiteralArgumentBuilder main = literal("itsmine"); - LiteralArgumentBuilder alias = literal("claim"); + public static CommandDispatcher dispatcher; + + + public static void register() { + LiteralArgumentBuilder main = LiteralArgumentBuilder.literal("itsmine"); + LiteralArgumentBuilder alias = LiteralArgumentBuilder.literal("claim"); register(main, dispatcher); register(alias, dispatcher); dispatcher.register(main); dispatcher.register(alias); } - private static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { + + + public static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher) { AdminCommand.register(command, dispatcher); BlockCommand.register(command); CreateCommand.register(command); - ExceptionCommand.register(command, false, getClaims()); ExpandCommand.register(command, false); FlyCommand.register(command); HelpCommand.register(command); InfoCommand.register(command, getClaims()); ListCommand.register(command); - PermissionsCommand.register(command, false); + MessageCommand.register(command, false, getClaims()); + PermissionCommand.register(command, false, getClaims()); RemoveCommand.register(command, getClaims(), false); RenameCommand.register(command, false); RentableCommand.register(command, getClaims()); RentCommand.register(command, getClaims()); RevenueCommand.register(command, getClaims()); -// SettingsCommand.register(command, false); + SettingsCommand.register(command, false, getClaims()); ShowCommand.register(command); StickCommand.register(command); SubzoneCommand.register(command, dispatcher, false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java index 1653eea..6b2fef1 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java @@ -107,21 +107,12 @@ public static int createClaim(String name, ServerCommandSource owner, BlockPos p // works because only the first statement is evaluated if true if ((admin && ItsMine.permissions().hasPermission(owner, PermissionUtil.Command.INFINITE_BLOCKS, 2)) || ClaimManager.INSTANCE.useClaimBlocks(ownerID, subInt)) { ClaimManager.INSTANCE.addClaim(claim); - MutableText message = null; - message.append(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN))); + MutableText message = new LiteralText(""); + message.append(new LiteralText("Your claim was created").formatted(Formatting.GREEN)); message.append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").styled(style -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))); - return style; + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))); })); owner.sendFeedback(message, false); - - MutableText message2 = null; - message2.append(new LiteralText("").append(new LiteralText("Your claim was created").formatted(Formatting.GREEN))); - message2.append(new LiteralText("(Area: " + sub.getX() + "x" + sub.getY() + "x" + sub.getZ() + ")").styled(style -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(subInt + " blocks").formatted(Formatting.YELLOW))); - return style; - })); - owner.sendFeedback(message2, false); BlockCommand.blocksLeft(owner); executeShowClaim(owner, claim, false); if (admin) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java deleted file mode 100644 index 1743fa8..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ExceptionCommand.java +++ /dev/null @@ -1,166 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.arguments.BoolArgumentType; -import com.mojang.brigadier.arguments.StringArgumentType; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.sun.org.apache.xpath.internal.Arg; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.command.EntitySelector; -import net.minecraft.command.arguments.EntityArgumentType; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; - -import static com.mojang.brigadier.arguments.StringArgumentType.*; -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; -import static io.github.indicode.fabric.itsmine.command.TrustCommand.setTrust; -import static io.github.indicode.fabric.itsmine.command.TrustedCommand.showTrustedList; -import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.*; -import static io.github.indicode.fabric.itsmine.util.ClaimUtil.*; -import static net.minecraft.server.command.CommandManager.argument; -import static net.minecraft.server.command.CommandManager.literal; - -public class ExceptionCommand { - - public static void register(LiteralArgumentBuilder command, boolean admin, RequiredArgumentBuilder claim) { - { - LiteralArgumentBuilder settings = literal("settings"); - - if (!admin) { - settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); - - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return querySettings(context.getSource(), claim1); - }); - } - - RequiredArgumentBuilder id = argument("setting", word()).suggests(SETTINGS_PROVIDER); - RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); - - id.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), getString(context, "claim"), true, false, admin)); - set.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); - - id.then(set); - claim.then(id); - settings.then(claim); - command.then(settings); - } - { - LiteralArgumentBuilder exceptions = literal("permissions"); - if (admin) exceptions.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_PERMISSIONS, 2)); - if (!admin) { - exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); - - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return showTrustedList(context, claim1, false); - }); - } - - if (!admin) { - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(new LiteralText("That claim does not exist")); - return -1; - } - return showTrustedList(context, claim1, true); - }); - } - exceptions.then(claim); - command.then(exceptions); - } - { - RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); - LiteralArgumentBuilder remove = literal("remove"); - remove.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - claim1.permissionManager.resetPermissions(player1.getGameProfile().getId()); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + " no longer has an exception in the claim").formatted(Formatting.YELLOW), false); - } - return 0; - }); - player.then(remove); - LiteralArgumentBuilder all = literal("*"); - RequiredArgumentBuilder allstate = argument("allow", BoolArgumentType.bool()); - allstate.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - validateClaim(claim1); - return setTrust(context, claim1, player1.getGameProfile(), BoolArgumentType.getBool(context, "allow"), admin); - }); - all.then(allstate); - player.then(all); - for (Claim.Permission value : Claim.Permission.values()) { - LiteralArgumentBuilder permNode = literal(value.id); - RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); - allow.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - boolean permission = BoolArgumentType.getBool(context, "allow"); - modifyException(claim1, player1, value, permission); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has the permission " + value.name).formatted(Formatting.YELLOW), false); - } - return 0; - }); - permNode.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - boolean permission = hasPermission(claim1, player1, value); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); - } - return 0; - }); - permNode.then(allow); - player.then(permNode); - } - claim.then(player); - } - { - LiteralArgumentBuilder message = literal("message"); - RequiredArgumentBuilder messageEvent = getMessageEvent(); - RequiredArgumentBuilder messageArgument = getEventMessage(); - messageArgument.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PROPERTIES, context, admin)) { - Claim.Event event = Claim.Event.getById(getString(context, "messageEvent")); - - if (event == null) { - context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); - return -1; - } - - return setEventMessage(context.getSource(), claim1, event, getString(context, "message")); - } - - return -1; - }); - - messageEvent.then(messageArgument); - claim.then(messageEvent); - message.then(claim); - command.then(message); - } - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java index 5dfe18c..19729c2 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java @@ -59,20 +59,20 @@ public static int sendPage(ServerCommandSource source, Text[] text, int page, St .append(new LiteralText("<-").formatted(Formatting.WHITE).formatted(Formatting.BOLD)) .append(new LiteralText(" ")).append(new LiteralText("Prev").formatted(Formatting.GOLD)) .styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); - if (prevPage >= 0) - style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); - return style; + if (prevPage >= 0){ + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); + } + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((prevPage >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); }); Text button_next = new LiteralText("") .append(new LiteralText("Next").formatted(Formatting.GOLD)) .append(new LiteralText(" ")).append(new LiteralText("->").formatted(Formatting.WHITE).formatted(Formatting.BOLD)).append(new LiteralText(" ")) .styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); - if (nextPage <= text.length) - style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); - return style; + if (nextPage <= text.length){ + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(nextPage)))); + } + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((nextPage <= text.length) ? ">>>" : ">|").formatted(Formatting.GRAY))); }); Text buttons = new LiteralText("") diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java index 88a7d04..3b3f3c1 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java @@ -70,13 +70,11 @@ private static int info(ServerCommandSource source, Claim claim) throws CommandS GameProfile tenant = claim.rent.getTenant() == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.rent.getTenant()); text.append(newInfoLine("Status", new LiteralText("Rented").formatted(Formatting.RED).styled(style -> { java.util.Date time=new java.util.Date((long) claim.rent.getRentedUntil()*1000); - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Until", new LiteralText(time.toString()).formatted(Formatting.WHITE)).append(newInfoLine("By", new LiteralText(tenant.getName()).formatted(Formatting.WHITE))).append(newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE))))); - return style; + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Until", new LiteralText(time.toString()).formatted(Formatting.WHITE)).append(newInfoLine("By", new LiteralText(tenant.getName()).formatted(Formatting.WHITE))).append(newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE))))); }))); } else if (claim.rent.isRentable() && !claim.rent.isRented()){ text.append(newInfoLine("Status", new LiteralText("For Rent").formatted(Formatting.GREEN).styled(style -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE)).append(newInfoLine("Max Rent", new LiteralText(claim.rent.getMaxrentAbleTime() / 86400 + " days")).formatted(Formatting.WHITE)))); - return style; + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, newInfoLine("Price", new LiteralText(claim.rent.getAmount() + " " + claim.rent.getCurrency().getName().asString() + " every " + TimeUtil.convertSecondsToString(claim.rent.getRentAbleTime(),'f', 'f')).formatted(Formatting.WHITE)).append(newInfoLine("Max Rent", new LiteralText(claim.rent.getMaxrentAbleTime() / 86400 + " days")).formatted(Formatting.WHITE)))); }))); } else { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/MessageCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/MessageCommand.java new file mode 100644 index 0000000..ccf9611 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/MessageCommand.java @@ -0,0 +1,45 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Messages; +import net.minecraft.server.command.ServerCommandSource; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getEventMessage; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getMessageEvent; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.setEventMessage; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.verifyPermission; +import static net.minecraft.server.command.CommandManager.literal; + +public class MessageCommand { + + public static void register(LiteralArgumentBuilder command, boolean admin, RequiredArgumentBuilder claim) { + LiteralArgumentBuilder message = literal("message"); + RequiredArgumentBuilder messageEvent = getMessageEvent(); + RequiredArgumentBuilder messageArgument = getEventMessage(); + messageArgument.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PROPERTIES, context, admin)) { + Claim.Event event = Claim.Event.getById(getString(context, "messageEvent")); + + if (event == null) { + context.getSource().sendError(Messages.INVALID_MESSAGE_EVENT); + return -1; + } + + return setEventMessage(context.getSource(), claim1, event, getString(context, "message")); + } + + return -1; + }); + + messageEvent.then(messageArgument); + claim.then(messageEvent); + message.then(claim); + command.then(message); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionCommand.java new file mode 100644 index 0000000..0ae7885 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionCommand.java @@ -0,0 +1,109 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import net.minecraft.command.EntitySelector; +import net.minecraft.command.arguments.EntityArgumentType; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; +import static io.github.indicode.fabric.itsmine.command.TrustCommand.setTrust; +import static io.github.indicode.fabric.itsmine.command.TrustedCommand.showTrustedList; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getPermissions; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.*; +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public class PermissionCommand { + + public static void register(LiteralArgumentBuilder command, boolean admin, RequiredArgumentBuilder claim) { + LiteralArgumentBuilder exception = literal("permissions"); + RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); + LiteralArgumentBuilder remove = literal("remove"); + LiteralArgumentBuilder all = literal("*"); + RequiredArgumentBuilder allstate = argument("allow", BoolArgumentType.bool()); + RequiredArgumentBuilder permNode = getPermissions(); + RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); + + exception.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(Messages.INVALID_CLAIM); + return -1; + } + return showTrustedList(context, claim1, false); + }); + + claim.executes((context) -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (claim1 == null) { + context.getSource().sendError(new LiteralText("That claim does not exist")); + return -1; + } + return showTrustedList(context, claim1, true); + }); + + remove.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + claim1.permissionManager.resetPermissions(player1.getGameProfile().getId()); + context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + " no longer has an exception in the claim").formatted(Formatting.YELLOW), false); + } + return 0; + }); + + allstate.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + validateClaim(claim1); + return setTrust(context, claim1, player1.getGameProfile(), BoolArgumentType.getBool(context, "allow"), admin); + }); + + allow.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + boolean permission = BoolArgumentType.getBool(context, "allow"); + Claim.Permission value = Claim.Permission.byId(StringArgumentType.getString(context, "permission")); + modifyException(claim1, player1, value, permission); + context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has the permission " + value.name).formatted(Formatting.YELLOW), false); + } + return 0; + }); + + permNode.executes(context -> { + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + Claim.Permission value = Claim.Permission.byId(StringArgumentType.getString(context, "permission")); + boolean permission = hasPermission(claim1, player1, value); + context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); + } + return 0; + }); + + + all.then(allstate); + permNode.then(allow); + player.then(permNode); + player.then(all); + player.then(remove); + claim.then(player); + exception.then(claim); + command.then(exception); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java deleted file mode 100644 index 2fe9ccf..0000000 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionsCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -package io.github.indicode.fabric.itsmine.command; - -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.LiteralText; - -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; -import static io.github.indicode.fabric.itsmine.command.TrustedCommand.showTrustedList; -import static net.minecraft.server.command.CommandManager.literal; - -public class PermissionsCommand { - public static void register(LiteralArgumentBuilder command, boolean admin) { - LiteralArgumentBuilder exceptions = literal("permissions"); - if (admin) - exceptions.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY_PERMISSIONS, 2)); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - if (!admin) { - exceptions.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); - - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(Messages.INVALID_CLAIM); - return -1; - } - return showTrustedList(context, claim1, false); - }); - } - - if (!admin) { - claim.executes((context) -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (claim1 == null) { - context.getSource().sendError(new LiteralText("That claim does not exist")); - return -1; - } - return showTrustedList(context, claim1, true); - }); - } - } -} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java index d959bd2..4dc31be 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java @@ -50,10 +50,7 @@ public static int requestDelete(ServerCommandSource sender, Claim claim, boolean } sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to delete the claim \"" + claim.name + "\"? ").formatted(Formatting.GOLD)) .append(new LiteralText("[I'M SURE]").styled(style -> { - style.withColor(Formatting.DARK_RED); - style.withBold(true); - style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")); - return style; + return style.withColor(Formatting.DARK_RED).withBold(true).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " remove " + claim.name + " confirm")); })), false); return 0; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java index e734dd1..10add3a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java @@ -15,6 +15,7 @@ import net.minecraft.util.Formatting; import static com.mojang.brigadier.arguments.StringArgumentType.*; +import static io.github.indicode.fabric.itsmine.command.admin.AdminCommand.PERMISSION_CHECK_ADMIN; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; @@ -23,7 +24,7 @@ public static void register(LiteralArgumentBuilder command, LiteralArgumentBuilder rent = literal("rent"); RequiredArgumentBuilder days = argument("days", word()); days.executes(context -> rent(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), getString(context, "days"))); - + rent.requires(PERMISSION_CHECK_ADMIN); claim.then(days); rent.then(claim); command.then(rent); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java index 274d24a..3358b9f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java @@ -18,6 +18,7 @@ import net.minecraft.util.Formatting; import static com.mojang.brigadier.arguments.StringArgumentType.*; +import static io.github.indicode.fabric.itsmine.command.admin.AdminCommand.PERMISSION_CHECK_ADMIN; import static net.minecraft.server.command.CommandManager.literal; public class RentableCommand { @@ -26,10 +27,10 @@ public static void register(LiteralArgumentBuilder command, LiteralArgumentBuilder rentable = literal("rentable"); RequiredArgumentBuilder currency = net.minecraft.server.command.CommandManager.argument("item", ItemStackArgumentType.itemStack()).suggests(ArgumentUtil::itemsSuggestion); RequiredArgumentBuilder amount = net.minecraft.server.command.CommandManager.argument("count", IntegerArgumentType.integer(1)); - RequiredArgumentBuilder days = net.minecraft.server.command.CommandManager.argument("days", word() - ); + RequiredArgumentBuilder days = net.minecraft.server.command.CommandManager.argument("days", word()); RequiredArgumentBuilder maxdays = CommandManager.argument("maxdays", word()); maxdays.executes(context -> makeRentable(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false), IntegerArgumentType.getInteger(context, "count"), getString(context, "days"), getString(context, "maxdays"))); + rentable.requires(PERMISSION_CHECK_ADMIN); claim.executes(context -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); if(claim1.rent.getCurrency() !=null || claim1.rent.getAmount() != 0 || claim1.rent.getRentAbleTime() != 0 || claim1.rent.getMaxrentAbleTime() != 0 && claim1.rent.isRentable()) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java index 94dc43b..600a329 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java @@ -17,6 +17,7 @@ import java.util.HashMap; import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.command.admin.AdminCommand.PERMISSION_CHECK_ADMIN; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; @@ -26,6 +27,7 @@ public static void register(LiteralArgumentBuilder command, LiteralArgumentBuilder revenue = literal("revenue"); RequiredArgumentBuilder claimRevenue = argument("claimRevenue", BoolArgumentType.bool()); revenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); + revenue.requires(PERMISSION_CHECK_ADMIN); claim.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); claimRevenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); claim.then(claimRevenue); @@ -69,9 +71,7 @@ private static int revenue(ServerCommandSource source, Claim claim, boolean clai hashMap.forEach((item, integer) -> { boolean color = true; text.append(new LiteralText(String.valueOf(integer)).append(new LiteralText(" ")).append(new TranslatableText(item.getTranslationKey())).append(new LiteralText(" ")).formatted(color ? Formatting.GOLD : Formatting.YELLOW)).styled(style -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to claim revenue!").formatted(Formatting.GREEN))); - style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim revenue " + claim.name + " true")); - return style; + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to claim revenue!").formatted(Formatting.GREEN))).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim revenue " + claim.name + " true")); }); color = !color; }); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java index acdaf05..acd8c97 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java @@ -13,6 +13,7 @@ import static com.mojang.brigadier.arguments.StringArgumentType.word; import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.SETTINGS_PROVIDER; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getSettings; import static io.github.indicode.fabric.itsmine.util.ClaimUtil.executeSetting; import static io.github.indicode.fabric.itsmine.util.ClaimUtil.querySettings; import static net.minecraft.server.command.CommandManager.argument; @@ -20,9 +21,8 @@ public class SettingsCommand { - public static void register(LiteralArgumentBuilder command, boolean admin) { + public static void register(LiteralArgumentBuilder command, boolean admin, RequiredArgumentBuilder claim) { LiteralArgumentBuilder settings = literal("settings"); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); if (!admin) { settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); @@ -37,7 +37,7 @@ public static void register(LiteralArgumentBuilder command, }); } - RequiredArgumentBuilder id = argument("setting", word()).suggests(SETTINGS_PROVIDER); + RequiredArgumentBuilder id = getSettings(); RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); id.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), getString(context, "claim"), true, false, admin)); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java index e3de687..8e67b99 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java @@ -107,10 +107,7 @@ private static int requestTransfer(ServerCommandSource sender, Claim claim, Serv } sender.sendFeedback(new LiteralText("").append(new LiteralText("Are you sure you want to transfer ownership of \"" + claim.name + "\" to " + player.getGameProfile().getName() + "? ").formatted(Formatting.GOLD)) .append(new LiteralText("[YES]").styled(style -> { - style.withColor(Formatting.DARK_RED); - style.withBold(true); - style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")); - return style; + return style.withColor(Formatting.DARK_RED).withBold(true).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, (admin ? "/claim admin" : "/claim") + " transfer " + claim.name + " " + player.getGameProfile().getName() + " confirm")); })), false); return 0; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java index 8f3bb14..8ff0c6b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java @@ -70,9 +70,7 @@ static int showTrustedList(CommandContext context, Claim cl owner = new LiteralText(profile.getName()); } else { owner = new LiteralText(uuid.toString()).styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to Copy"))); - style.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); - return style; + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to Copy"))).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, uuid.toString())); }); } @@ -112,7 +110,9 @@ static int showTrustedList(CommandContext context, Claim cl .append(new LiteralText(")").formatted(Formatting.GOLD)) ); - pText.styled((style) -> style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover))); + pText.styled((style) -> { + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover)); + }); text.append(pText).append(new LiteralText("\n")); }); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java index 959fbc9..027310d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java @@ -3,16 +3,15 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.command.ExceptionCommand; -import io.github.indicode.fabric.itsmine.command.PermissionsCommand; +import io.github.indicode.fabric.itsmine.command.MessageCommand; +import io.github.indicode.fabric.itsmine.command.PermissionCommand; import io.github.indicode.fabric.itsmine.command.SettingsCommand; import io.github.indicode.fabric.itsmine.command.subzone.SubzoneCommand; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.server.command.ServerCommandSource; import java.util.function.Predicate; -import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.*; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getClaims; import static net.minecraft.server.command.CommandManager.literal; public class AdminCommand { @@ -29,15 +28,15 @@ private static void registerAdmin(LiteralArgumentBuilder ad ClaimsCommand.register(admin, dispatcher); CreateCommand.register(admin); EntitiesCommand.register(admin); - ExceptionCommand.register(admin, true, getClaims()); ExpandCommand.register(admin); IgnoreCommand.register(admin); ListAllCommand.register(admin); + MessageCommand.register(admin, true, getClaims()); OwnerCommand.register(admin); - PermissionsCommand.register(admin, true); + PermissionCommand.register(admin, true, getClaims()); RemoveCommand.register(admin); RenameCommand.register(admin); -// SettingsCommand.register(admin, true); + SettingsCommand.register(admin, true, getClaims()); SubzoneCommand.register(admin, dispatcher, true); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java index 77b8229..5d8c250 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java @@ -51,10 +51,7 @@ public static int list(ServerCommandSource source, String target) throws Command hoverText.append("\n- " + subzone.name); } } - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); - - style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)); - return style; + return style.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/claim info " + claim.name)).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)); }); nextColor = !nextColor; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java index 23b6fd5..45ccf30 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java @@ -1,17 +1,34 @@ package io.github.indicode.fabric.itsmine.command.admin; +import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; +import com.mojang.brigadier.context.CommandContext; +import io.github.indicode.fabric.itsmine.*; import io.github.indicode.fabric.itsmine.util.ArgumentUtil; +import io.github.indicode.fabric.itsmine.util.EntityUtil; import io.github.indicode.fabric.itsmine.util.PermissionUtil; +import io.github.indicode.fabric.itsmine.util.WorldUtil; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityCategory; +import net.minecraft.entity.EntityType; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.HoverEvent; import net.minecraft.text.LiteralText; +import net.minecraft.text.MutableText; +import net.minecraft.text.Style; import net.minecraft.util.Formatting; +import net.minecraft.world.World; + +import java.awt.*; +import java.util.ArrayList; +import java.util.Map; +import java.util.UUID; import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.Messages.header; +import static io.github.indicode.fabric.itsmine.Messages.text; +import static io.github.indicode.fabric.itsmine.util.EntityUtil.*; import static net.minecraft.server.command.CommandManager.literal; public class EntitiesCommand { @@ -19,24 +36,36 @@ public static void register(LiteralArgumentBuilder command) LiteralArgumentBuilder entity = literal("entities"); entity.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - entity.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); - context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); - claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { - context.getSource().sendFeedback(new LiteralText(entityType.getName().asString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); - }); - return 1; - }); - claim.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - context.getSource().sendFeedback(new LiteralText("Entities (" + claim1.name + "): ").formatted(Formatting.GOLD).append(new LiteralText(String.valueOf(claim1.getEntities(context.getSource().getWorld()))).formatted(Formatting.AQUA)), true); - claim1.getEntitySorted(claim1.getEntityMap(claim1, context.getSource().getWorld())).forEach((entityType, integer) -> { - context.getSource().sendFeedback(new LiteralText(entityType.getName().asString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer)).formatted(Formatting.GOLD)), true); - }); - return 1; - }); + entity.executes(context -> execute(context, ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension))); + claim.executes(context -> execute(context, ClaimManager.INSTANCE.getClaim(StringArgumentType.getString(context, "claim")))); entity.then(claim); command.then(entity); } + public static int execute(CommandContext context, Claim claim){ + ServerCommandSource source = context.getSource(); + if(claim == null){ + source.sendError(Messages.INVALID_CLAIM); + return 1; + } + + ArrayList entityList = getEntities(claim); + MutableText message = header("Entities (" + claim.name +") - " + entityList.size()).append(new LiteralText("\n\n")); + for(EntityCategory entityCategory : EntityCategory.values()){ + MutableText entities = new LiteralText(""); + Map entityMap = sortByType(filterByCategory(entityList, entityCategory)); + entityMap.forEach((entityType, integer) -> { + entities.append(entityType.getName().getString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer))).formatted(Formatting.GOLD).append("\n"); + + }); + if(entityMap.size() > 0){ + message.append(new LiteralText(entityCategory.getName()).styled(style -> { + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, entities)).withFormatting(Formatting.GOLD); + }).append(" ")); + } + } + source.sendFeedback(message, false); + return 1; + } + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java index 36150cd..b1c4f63 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java @@ -8,15 +8,14 @@ import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.util.MessageUtil; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; -import net.minecraft.text.Style; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import java.util.ArrayList; import java.util.List; -import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getPlayers; import static io.github.indicode.fabric.itsmine.util.ClaimUtil.getClaims; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; @@ -29,7 +28,8 @@ public static void register(LiteralArgumentBuilder command) RequiredArgumentBuilder offline = argument("offline", BoolArgumentType.bool()); entries.executes(context -> listall(context.getSource(), IntegerArgumentType.getInteger(context, "page"), IntegerArgumentType.getInteger(context, "entries"), BoolArgumentType.getBool(context, "offline"))); page.executes(context -> listall(context.getSource(), IntegerArgumentType.getInteger(context, "page"), 10, BoolArgumentType.getBool(context, "offline"))); - listall.executes(context -> listall(context.getSource(), 1, 10, BoolArgumentType.getBool(context, "offline"))); + listall.executes(context -> listall(context.getSource(), 1, 10, true)); + offline.executes(context -> listall(context.getSource(), 1, 10, BoolArgumentType.getBool(context, "offline"))); page.then(entries); offline.then(page); listall.then(offline); @@ -39,22 +39,20 @@ private static int listall(ServerCommandSource source, int page, int entries, bo List claims = getClaims(); Text title = new LiteralText("Claim List:").formatted(Formatting.AQUA).formatted(Formatting.UNDERLINE); ArrayList claimList = new ArrayList<>(); - for (Claim claim : claims) { - if(offline) { - claimList.add(new LiteralText(claim.name).formatted(Formatting.GOLD).append(new LiteralText(" "))); + if(!offline){ + for(ServerPlayerEntity serverPlayerEntity : source.getMinecraftServer().getPlayerManager().getPlayerList()){ + for(Claim claim : ClaimManager.INSTANCE.getPlayerClaims(serverPlayerEntity.getUuid())){ + claimList.add(new LiteralText(claim.name).formatted(Formatting.GOLD).append(new LiteralText(" ")).append(new LiteralText(String.valueOf(claim.getEntities(source.getWorld()))).formatted(Formatting.YELLOW))); + } } - else { -// source.getMinecraftServer().getPlayerManager(). - source.getMinecraftServer().getPlayerManager().getPlayerList().forEach(serverPlayerEntity -> { - ClaimManager.INSTANCE.getPlayerClaims(serverPlayerEntity.getUuid()).forEach(claim1 -> { - claimList.add(new LiteralText(claim.name).formatted(Formatting.GOLD).append(new LiteralText(" ")).append(new LiteralText(String.valueOf(claim1.getEntities(source.getWorld()))).formatted(Formatting.YELLOW))); - }); - }); + } else { + for (Claim claim : claims) { + claimList.add(new LiteralText(claim.name).formatted(Formatting.GOLD).append(new LiteralText(" "))); } } MessageUtil.sendPage(source, title, entries, page, "/claim admin listall " + offline + " %page% " + entries, claimList); return 1; - } + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java index 5d2ab4b..30cf864 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java @@ -17,16 +17,17 @@ public static void register(LiteralArgumentBuilder command, public static void registerSubzone(LiteralArgumentBuilder command, CommandDispatcher dispatcher, boolean admin) { CreateCommand.register(command, admin); - ExceptionCommand.register(command, admin, getSubzones()); ExpandCommand.register(command, admin); InfoCommand.register(command, getSubzones()); - PermissionsCommand.register(command, admin); + MessageCommand.register(command, admin, getSubzones()); + PermissionCommand.register(command, admin, getSubzones()); RemoveCommand.register(command, getSubzones(), admin); RenameCommand.register(command, admin); RentableCommand.register(command, getSubzones()); RentCommand.register(command, getSubzones()); RevenueCommand.register(command, getSubzones()); - TrustCommand.register(command, getSubzones(), true); + SettingsCommand.register(command, admin, getSubzones()); + TrustCommand.register(command, getSubzones(), admin); TrustedCommand.register(command); } } \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java index 2711e43..1f68f7f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java @@ -1,14 +1,16 @@ package io.github.indicode.fabric.itsmine.mixin; import blue.endless.jankson.annotation.Nullable; -import com.mojang.authlib.GameProfile; import io.github.indicode.fabric.itsmine.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Config; import io.github.indicode.fabric.itsmine.util.ClaimUtil; import net.minecraft.entity.passive.AnimalEntity; +import net.minecraft.network.packet.s2c.play.TitleS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; import net.minecraft.util.Formatting; +import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -20,17 +22,14 @@ @Mixin(AnimalEntity.class) public abstract class AnimalEntityMixin { - @Shadow private UUID lovingPlayer; - @Shadow @Nullable public abstract ServerPlayerEntity getLovingPlayer(); - @Shadow public abstract void setLoveTicks(int loveTicks); - @Shadow public abstract void resetLoveTicks(); @Inject(method = "canBreedWith", at = @At(value = "HEAD"), cancellable = true) private void canBreed(AnimalEntity other, CallbackInfoReturnable cir){ + World world = other.getEntityWorld(); Claim claim = ClaimManager.INSTANCE.getClaimAt(other.getBlockPos(), other.dimension); if(claim != null){ if(claim.isChild){ @@ -39,7 +38,7 @@ private void canBreed(AnimalEntity other, CallbackInfoReturnable cir){ if(claim.getEntities(other.getEntityWorld().getServer().getWorld(other.getEntityWorld().getDimension().getType())) > 50){ ServerPlayerEntity player = this.getLovingPlayer(); if(player != null){ - player.sendSystemMessage(new LiteralText("You reached the entity limit in your claim!").formatted(Formatting.RED)); + player.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText("You reached the entity limit in your claim!").formatted(Formatting.RED), -1, Config.event_msg_stay_ticks, -1)); } this.resetLoveTicks(); cir.setReturnValue(false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java index 4829903..800fd8f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/CommandManagerMixin.java @@ -18,6 +18,7 @@ public class CommandManagerMixin { private CommandDispatcher dispatcher; @Inject(method = "", at = @At("RETURN")) public void addCommand(boolean bool, CallbackInfo ci) { - CommandManager.register(dispatcher); + CommandManager.dispatcher = this.dispatcher; + CommandManager.register(); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java index a38d073..c389413 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java @@ -27,7 +27,6 @@ public class ExplosionMixin { @Redirect(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;")) private BlockState theyCallMeBedrock(World world, BlockPos pos) { - System.out.println("Running method1"); Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); if (claim != null && !world.isAir(pos) && !world.getBlockState(pos).getBlock().equals(Blocks.TNT)) { if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) { @@ -39,7 +38,6 @@ private BlockState theyCallMeBedrock(World world, BlockPos pos) { @Redirect(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isImmuneToExplosion()Z")) private boolean claimDeniesExplosion(Entity entity) { - System.out.println("Running method2"); BlockPos blockPos_1 = entity.getBlockPos(); Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, entity.world.getDimension().getType()); if (claim != null) { @@ -50,9 +48,4 @@ private boolean claimDeniesExplosion(Entity entity) { return entity.isImmuneToExplosion(); } - - @Inject(method = "getAffectedBlocks", at = @At(value = "HEAD")) - private void dontAffectMe(CallbackInfoReturnable> cir){ - System.out.println("Running method3"); - } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java index b7c6be3..7ec21ad 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java @@ -6,6 +6,8 @@ import io.github.indicode.fabric.itsmine.util.ClaimUtil; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.screen.LecternScreenHandler; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -14,15 +16,26 @@ @Mixin(LecternScreenHandler.class) public abstract class LecternScreenHandlerMixin { + @Inject(method = "canUse", at = @At(value = "HEAD"), cancellable = true) + private void canUseLectern(PlayerEntity player, CallbackInfoReturnable cir){ + + } + @Inject(method = "onButtonClick", at = @At(value = "HEAD"), cancellable = true) - private void canTake(PlayerEntity player, int id, CallbackInfoReturnable cir){ - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); - if(claim != null){ - if(claim.isChild) claim = ClaimUtil.getParentClaim(claim); - if(!claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_LECTERN)){ - player.sendSystemMessage(Messages.MSG_CANT_DO); - cir.setReturnValue(false); - } - } + private void canTake(PlayerEntity player, int id, CallbackInfoReturnable cir){ + player.sendSystemMessage(new LiteralText("onButtonClick")); + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + player.sendSystemMessage(new LiteralText(claim.name)); + if(claim != null){ + if(claim.isChild) claim = ClaimUtil.getParentClaim(claim); + player.sendSystemMessage(new LiteralText(claim.name)); + if(!claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_LECTERN)){ + player.sendSystemMessage(new LiteralText("You dont have permission to do that").formatted(Formatting.RED)); + cir.setReturnValue(true); + } else { + player.sendSystemMessage(new LiteralText("You have permission to do that").formatted(Formatting.GREEN)); + cir.setReturnValue(false); } + } + } } \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerCommandOutputMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerCommandOutputMixin.java new file mode 100644 index 0000000..80652fc --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerCommandOutputMixin.java @@ -0,0 +1,18 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import io.github.indicode.fabric.itsmine.ClaimManager; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.dedicated.ServerCommandOutput; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ServerCommandOutput.class) +public abstract class ServerCommandOutputMixin { + + @Inject(method = "", at = @At("RETURN")) + private void saveInstance(MinecraftServer server, CallbackInfo ci) { + ClaimManager.INSTANCE.server = server; + } +} \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java index 0b166f9..6e9c259 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java @@ -22,6 +22,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; @@ -39,8 +40,6 @@ public abstract class ServerWorldMixin implements MonitorableWorld { @Shadow public abstract List getPlayers(); - @Shadow public abstract void playGlobalEvent(int type, BlockPos pos, int data); - @Redirect(method = "sendBlockActions", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;sendToAround(Lnet/minecraft/entity/player/PlayerEntity;DDDDLnet/minecraft/world/dimension/DimensionType;Lnet/minecraft/network/Packet;)V")) private void sendPistonUpdate(PlayerManager manager, PlayerEntity playerEntity_1, double double_1, double double_2, double double_3, double double_4, DimensionType dimensionType_1, Packet packet_1) { manager.sendToAround(playerEntity_1, double_1, double_2, double_3, double_4, dimensionType_1, packet_1); @@ -69,7 +68,6 @@ public void tickActions(BooleanSupplier shouldKeepTicking, CallbackInfo ci){ public int loadedEntities() { if (this.entitiesByUuid == null) return -1; - return this.entitiesByUuid.size(); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java index 031f31a..e7aa66e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java @@ -53,6 +53,10 @@ public static RequiredArgumentBuilder getPlayers(){ public static RequiredArgumentBuilder getSettings(){ return argument("setting", word()).suggests(SETTINGS_PROVIDER); } + public static RequiredArgumentBuilder getPermissions(){ + return argument("permission", word()).suggests(SETTINGS_PROVIDER); + } + public static RequiredArgumentBuilder getMessageEvent(){ return argument("messageEvent", word()).suggests(MESSAGE_EVENTS_PROVIDER); } @@ -148,6 +152,17 @@ public static CompletableFuture itemsSuggestion(final CommandContex return CommandSource.suggestMatching(strings, builder); }; + public static final SuggestionProvider PERMISSIONS_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + for (Claim.Permission value : Claim.Permission.values()) { + strings.add(value.id); + } + for (Claim.Permission value : Claim.Permission.values()) { + strings.add(value.id); + } + return CommandSource.suggestMatching(strings, builder); + }; + public static final SuggestionProvider MESSAGE_EVENTS_PROVIDER = (source, builder) -> { List strings = new ArrayList<>(); for (Claim.Event value : Claim.Event.values()) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/BlockUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/BlockUtil.java index 2610140..50f85a8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/BlockUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/BlockUtil.java @@ -17,7 +17,7 @@ public static boolean isEnderchest(Block block) { } public static boolean isShulkerBox(Block block) { - return block == Blocks.SHULKER_BOX; + return block == Blocks.SHULKER_BOX || block == Blocks.WHITE_SHULKER_BOX || block == Blocks.ORANGE_SHULKER_BOX || block == Blocks.MAGENTA_SHULKER_BOX || block == Blocks.LIGHT_BLUE_SHULKER_BOX || block == Blocks.YELLOW_SHULKER_BOX || block == Blocks.LIME_SHULKER_BOX || block == Blocks.PINK_SHULKER_BOX || block == Blocks.GRAY_SHULKER_BOX || block == Blocks.LIGHT_GRAY_SHULKER_BOX || block == Blocks.CYAN_SHULKER_BOX || block == Blocks.PURPLE_SHULKER_BOX || block == Blocks.BLUE_SHULKER_BOX || block == Blocks.BROWN_SHULKER_BOX || block == Blocks.GREEN_SHULKER_BOX || block == Blocks.RED_SHULKER_BOX || block == Blocks.BLACK_SHULKER_BOX; } public static boolean isButton(Block block) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java index 0a4160f..8eb5ff2 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java @@ -1,9 +1,24 @@ package io.github.indicode.fabric.itsmine.util; +import com.mojang.datafixers.types.Func; import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.Functions; +import io.github.indicode.fabric.itsmine.MonitorableWorld; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityCategory; +import net.minecraft.entity.EntityType; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; +import java.util.concurrent.atomic.AtomicReference; + +import static io.github.indicode.fabric.itsmine.util.WorldUtil.getServerWorld; public class EntityUtil { @@ -21,6 +36,35 @@ public static boolean isHostile(Entity entity) { return !isPassive(entity); } + public static ArrayList getEntities(Claim claim){ + ArrayList entityList = new ArrayList<>(); + ServerWorld world = getServerWorld(claim.dimension); + MonitorableWorld monitorableWorld = (MonitorableWorld) world; + monitorableWorld.EntityList().forEach((uuid, entity) -> { + if(claim.includesPosition(entity.getBlockPos())) entityList.add(entity); + }); + return entityList; + } + + public static ArrayList filterByCategory(ArrayList entityList, EntityCategory entityCategory){ + ArrayList filteredEntityList = new ArrayList<>(); + for(Entity entity : entityList) if(entity.getType().getCategory() == entityCategory) filteredEntityList.add(entity); + return filteredEntityList; + } + + public static Map sortByType(ArrayList entityList){ + Map entityMap = new HashMap<>(); + for(Entity entity : entityList) { + EntityType entityType = entity.getType(); + if (entityMap.containsKey(entityType)) { + entityMap.put(entityType, entityMap.get(entityType)+1); + } else { + entityMap.put(entityType, 1); + } + } + return Functions.sortByValue(entityMap); + } + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java index 42b6d97..4a061f7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java @@ -9,40 +9,55 @@ public class MessageUtil { - public static void sendPage(ServerCommandSource source, Text header, int entrys, int page, String command, ArrayList content){ - int pages = Math.floorDiv(content.size(), entrys); - if(content.size() % entrys != 0) pages++; + public static void sendPage(ServerCommandSource source, Text header, int entries, int page, String command, ArrayList content){ + System.out.println(1); + //1 + //10 max entries + //3 entries + int pages = Math.floorDiv(content.size(), entries); + if(content.size() % entries != 0) pages++; + System.out.println("pages: " + pages); if(page < 1) return; + System.out.println(2); if(page > pages) return; + System.out.println(3); LiteralText message = new LiteralText(""); + System.out.println(4); message.append(header).append(new LiteralText("\n\n")); - - for(int i = (entrys * (page - 1) + 1); i <= page * entrys; i++) message.append(content.get(i-1)).append(new LiteralText("\n")); + System.out.println(5); + for(int i = (entries * (page - 1) + 1); i < (page * entries); i++) { + System.out.println("i: " + i); + message.append(content.get(i-1)).append(new LiteralText("\n")); + } + System.out.println(6); message.append(new LiteralText("\n")); + System.out.println(7); Text button_prev = new LiteralText("") .append(new LiteralText("<-").formatted(Formatting.WHITE).formatted(Formatting.BOLD)) .append(new LiteralText(" ")).append(new LiteralText("Prev").formatted(Formatting.GOLD)) .styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((page - 1 >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); if (page - 1 >= 0) { - style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((page - 1 >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page - 1)))); } - return style; + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((page - 1 >= 0) ? "<<<" : "|<").formatted(Formatting.GRAY))); + }).append(new LiteralText(" ")); int finalPages = pages; Text button_next = new LiteralText(" ") .append(new LiteralText("Next").formatted(Formatting.GOLD)) .append(new LiteralText(" ")).append(new LiteralText("->").formatted(Formatting.WHITE).formatted(Formatting.BOLD)).append(new LiteralText(" ")) .styled((style) -> { - style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((page + 1 <= finalPages) ? ">>>" : ">|").formatted(Formatting.GRAY))); - if (page + 1 <= finalPages) - style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page + 1)))); - return style; + if (page + 1 <= finalPages){ + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((page + 1 <= finalPages) ? ">>>" : ">|").formatted(Formatting.GRAY))).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command.replace("%page%", String.valueOf(page + 1)))); + } + return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText((page + 1 <= finalPages) ? ">>>" : ">|").formatted(Formatting.GRAY))); }); Text center = new LiteralText("").append(new LiteralText(String.valueOf(page)).formatted(Formatting.GREEN).append(new LiteralText("/").formatted(Formatting.GRAY)).append(new LiteralText(String.valueOf(pages)).formatted(Formatting.GREEN))); + System.out.println(8); if(page > 1) message.append(button_prev); message.append(center); if(page < pages) message.append(button_next); + System.out.println(10); sendText(source, message); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java index 9fbd7d8..7f7fa4f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java @@ -2,6 +2,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import io.github.indicode.fabric.itsmine.Config; +import io.github.indicode.fabric.itsmine.ItsMine; import io.github.indicode.fabric.permissions.PermChangeBehavior; import io.github.indicode.fabric.permissions.Thimble; import net.fabricmc.loader.api.FabricLoader; @@ -17,6 +18,7 @@ import java.util.Locale; import java.util.UUID; +import java.util.function.Predicate; public class PermissionUtil { private Manager manager; @@ -213,4 +215,6 @@ public String getNode() { return "itsmine." + this.NODE; } } + + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/WorldUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/WorldUtil.java new file mode 100644 index 0000000..3bce1e0 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/WorldUtil.java @@ -0,0 +1,13 @@ +package io.github.indicode.fabric.itsmine.util; + +import io.github.indicode.fabric.itsmine.ClaimManager; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.world.dimension.DimensionType; + +public class WorldUtil { + + public static ServerWorld getServerWorld(DimensionType dimensionType){ + return ClaimManager.INSTANCE.server.getWorld(dimensionType); + } + +} diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index 9df5a3c..d2e9be0 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -33,7 +33,8 @@ "FarmlandBlockMixin", "BoatItemMixin", "AnimalEntityMixin", - "LecternScreenHandlerMixin" + "LecternScreenHandlerMixin", + "ServerCommandOutputMixin" ], "injectors": { "defaultRequire": 1 From 9dcd546b2068389b94079d1824e3e6dc078092ef Mon Sep 17 00:00:00 2001 From: DrexHD Date: Thu, 30 Apr 2020 14:52:34 +0200 Subject: [PATCH 68/85] Fix LecternScreenHandler --- .../mixin/LecternScreenHandlerMixin.java | 81 +++++++++---------- src/main/resources/itsmine.mixins.json | 1 - 2 files changed, 40 insertions(+), 42 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java index 7ec21ad..e432f1a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java @@ -1,41 +1,40 @@ -package io.github.indicode.fabric.itsmine.mixin; - -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ClaimUtil; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.screen.LecternScreenHandler; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(LecternScreenHandler.class) -public abstract class LecternScreenHandlerMixin { - @Inject(method = "canUse", at = @At(value = "HEAD"), cancellable = true) - private void canUseLectern(PlayerEntity player, CallbackInfoReturnable cir){ - - } - - @Inject(method = "onButtonClick", at = @At(value = "HEAD"), cancellable = true) - private void canTake(PlayerEntity player, int id, CallbackInfoReturnable cir){ - player.sendSystemMessage(new LiteralText("onButtonClick")); - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); - player.sendSystemMessage(new LiteralText(claim.name)); - if(claim != null){ - if(claim.isChild) claim = ClaimUtil.getParentClaim(claim); - player.sendSystemMessage(new LiteralText(claim.name)); - if(!claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_LECTERN)){ - player.sendSystemMessage(new LiteralText("You dont have permission to do that").formatted(Formatting.RED)); - cir.setReturnValue(true); - } else { - player.sendSystemMessage(new LiteralText("You have permission to do that").formatted(Formatting.GREEN)); - cir.setReturnValue(false); - } - } - } -} \ No newline at end of file +//package io.github.indicode.fabric.itsmine.mixin; +// +//import io.github.indicode.fabric.itsmine.Claim; +//import io.github.indicode.fabric.itsmine.ClaimManager; +//import io.github.indicode.fabric.itsmine.util.ClaimUtil; +//import net.minecraft.entity.player.PlayerEntity; +//import net.minecraft.screen.LecternScreenHandler; +//import net.minecraft.text.LiteralText; +//import net.minecraft.util.Formatting; +//import org.spongepowered.asm.mixin.Mixin; +//import org.spongepowered.asm.mixin.Shadow; +//import org.spongepowered.asm.mixin.injection.At; +//import org.spongepowered.asm.mixin.injection.Inject; +//import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +// +//@Mixin(LecternScreenHandler.class) +//public abstract class LecternScreenHandlerMixin { +// +// +// @Inject(method = "onButtonClick", at = @At(value = "HEAD")) +// private void canTake(PlayerEntity player, int id, CallbackInfoReturnable cir){ +// player.sendSystemMessage(new LiteralText("onButtonClick")); +// cir.setReturnValue(true); +// cir.setReturnValue(false); +// Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); +// if(claim != null){ +// if(claim.isChild) claim = ClaimUtil.getParentClaim(claim); +// if(!claim.hasPermission(player.getUuid(), Claim.Permission.INTERACT_LECTERN)){ +// player.sendSystemMessage(new LiteralText("return true").formatted(Formatting.GREEN)); +// cir.setReturnValue(true); +// } else { +// player.sendSystemMessage(new LiteralText("return false").formatted(Formatting.GREEN)); +// cir.setReturnValue(false); +// } +// } else { +// player.sendSystemMessage(new LiteralText("return true").formatted(Formatting.GREEN)); +// cir.setReturnValue(true); +// } +// } +//} \ No newline at end of file diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index d2e9be0..dab9907 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -33,7 +33,6 @@ "FarmlandBlockMixin", "BoatItemMixin", "AnimalEntityMixin", - "LecternScreenHandlerMixin", "ServerCommandOutputMixin" ], "injectors": { From 8267b1cb68aaa65469b4dbd3d172afcff5bb3ecb Mon Sep 17 00:00:00 2001 From: DrexHD Date: Thu, 30 Apr 2020 14:53:18 +0200 Subject: [PATCH 69/85] Fix message command --- .../io/github/indicode/fabric/itsmine/util/ArgumentUtil.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java index e7aa66e..5a671f7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java @@ -19,8 +19,7 @@ import java.util.List; import java.util.concurrent.CompletableFuture; -import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static com.mojang.brigadier.arguments.StringArgumentType.*; import static net.minecraft.server.command.CommandManager.argument; public class ArgumentUtil { @@ -62,7 +61,7 @@ public static RequiredArgumentBuilder getMessageEve } public static RequiredArgumentBuilder getEventMessage(){ - return argument("message", word()).suggests(EVENT_MESSAGE_PROVIDER); + return argument("message", greedyString()).suggests(EVENT_MESSAGE_PROVIDER); } From f29bcae58f0ff4346de7933890f2640802582351 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Thu, 30 Apr 2020 14:53:47 +0200 Subject: [PATCH 70/85] Readd /trust --- .../fabric/itsmine/command/CommandManager.java | 2 +- .../indicode/fabric/itsmine/command/TrustCommand.java | 10 +++++++--- .../fabric/itsmine/command/subzone/SubzoneCommand.java | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java index c943654..961878f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java @@ -45,7 +45,7 @@ public static void register(LiteralArgumentBuilder command, StickCommand.register(command); SubzoneCommand.register(command, dispatcher, false); TransferCommand.register(command); - TrustCommand.register(command, getClaims(), false); + TrustCommand.register(command, dispatcher, getClaims(), false); TrustedCommand.register(command); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java index d01eab7..c2f62f5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java @@ -2,6 +2,7 @@ import blue.endless.jankson.annotation.Nullable; import com.mojang.authlib.GameProfile; +import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.context.CommandContext; @@ -19,26 +20,28 @@ import java.util.concurrent.atomic.AtomicInteger; import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.PLAYERS_PROVIDER; import static io.github.indicode.fabric.itsmine.util.ClaimUtil.validateClaim; import static io.github.indicode.fabric.itsmine.util.ClaimUtil.verifyPermission; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; public class TrustCommand { - public static void register(LiteralArgumentBuilder command, RequiredArgumentBuilder claim, boolean admin) { + public static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher, RequiredArgumentBuilder claim, boolean admin) { { LiteralArgumentBuilder trust = literal("trust"); - RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); + RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()).suggests(PLAYERS_PROVIDER); playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, null, admin))); claim.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), true, getString(context, "claim"), admin))); playerArgument.then(claim); trust.then(playerArgument); command.then(trust); + dispatcher.register(trust); } { LiteralArgumentBuilder distrust = literal("distrust"); - RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()); + RequiredArgumentBuilder playerArgument = argument("player", GameProfileArgumentType.gameProfile()).suggests(PLAYERS_PROVIDER); playerArgument.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, null, admin))); claim.executes((context -> executeTrust(context, GameProfileArgumentType.getProfileArgument(context, "player"), false, getString(context, "claim"), admin))); @@ -46,6 +49,7 @@ public static void register(LiteralArgumentBuilder command, playerArgument.then(claim); distrust.then(playerArgument); command.then(distrust); + dispatcher.register(distrust); } } private static int executeTrust(CommandContext context, Collection targetCollection, boolean set, @Nullable String claimName, boolean admin) throws CommandSyntaxException { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java index 30cf864..55c6d9a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java @@ -27,7 +27,7 @@ public static void registerSubzone(LiteralArgumentBuilder c RentCommand.register(command, getSubzones()); RevenueCommand.register(command, getSubzones()); SettingsCommand.register(command, admin, getSubzones()); - TrustCommand.register(command, getSubzones(), admin); + TrustCommand.register(command, dispatcher, getSubzones(), admin); TrustedCommand.register(command); } } \ No newline at end of file From 78db0ea62ad8a46b545aa08d58ca0db560590843 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Thu, 30 Apr 2020 14:54:11 +0200 Subject: [PATCH 71/85] Update to 20w18a --- gradle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 75c055f..59ffb40 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=20w17a -yarn_mappings=20w17a+build.5 +minecraft_version=20w18a +yarn_mappings=20w18a+build.1 loader_version=0.7.10+build.191 # Mod Properties - mod_version = 1.9.0-20W17A + mod_version = 1.9.0-20W18A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine From 996b5a24e70d103fa59539bf955ec365126f8d2f Mon Sep 17 00:00:00 2001 From: DrexHD Date: Thu, 30 Apr 2020 14:54:49 +0200 Subject: [PATCH 72/85] Adjust Entity limit + fix boat place bug --- .../java/io/github/indicode/fabric/itsmine/Config.java | 2 +- .../fabric/itsmine/mixin/AnimalEntityMixin.java | 4 ++-- .../indicode/fabric/itsmine/mixin/BoatItemMixin.java | 10 ++++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/Config.java index 49aae0e..aa9b87d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Config.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Config.java @@ -10,7 +10,7 @@ public class Config { public static int baseClaimBlocks2d = 2500; public static boolean claims2d = true; public static int rent_maxseconds = 7776000; - public static int claim_max_entities_passive = 100; + public static int claim_max_entities_passive = 75; public static String permissionManager = "luckperms"; public static String prefix = "&8[&aClaims&8]&r "; public static String msg_no_perm = "&c&lHey!&r&c Sorry but you don't have permission to do that"; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java index 1f68f7f..c7dd14b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java @@ -35,10 +35,10 @@ private void canBreed(AnimalEntity other, CallbackInfoReturnable cir){ if(claim.isChild){ claim = ClaimUtil.getParentClaim(claim); } - if(claim.getEntities(other.getEntityWorld().getServer().getWorld(other.getEntityWorld().getDimension().getType())) > 50){ + if(claim.getEntities(other.getEntityWorld().getServer().getWorld(other.getEntityWorld().getDimension().getType())) > Config.claim_max_entities_passive){ ServerPlayerEntity player = this.getLovingPlayer(); if(player != null){ - player.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText("You reached the entity limit in your claim!").formatted(Formatting.RED), -1, Config.event_msg_stay_ticks, -1)); + player.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText("You reached the passive entity limit in your claim!").formatted(Formatting.RED), -1, Config.event_msg_stay_ticks, -1)); } this.resetLoveTicks(); cir.setReturnValue(false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java index 7dd61b6..7ee4c96 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java @@ -20,6 +20,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.CancellationException; @Mixin(BoatItem.class) public abstract class BoatItemMixin extends Item { @@ -33,12 +34,13 @@ private void dontSpawn(World world, PlayerEntity user, Hand hand, CallbackInfoRe ItemStack itemStack = user.getStackInHand(hand); HitResult hitResult = rayTrace(world, user, RayTraceContext.FluidHandling.ANY); Vec3d pos = hitResult.getPos(); - Claim claim = ClaimManager.INSTANCE.getClaimAt(new BlockPos(pos.getX(), pos.getY(), pos.getZ()), user.dimension); - if (claim != null && !claim.hasPermission(user.getUuid(), Claim.Permission.BUILD) || !claim.hasPermission(user.getUuid(), Claim.Permission.SPAWN_BOAT)) { - user.sendSystemMessage(Messages.NO_PERMISSION); - cir.setReturnValue(TypedActionResult.fail(itemStack)); + if (claim != null){ + if(!claim.hasPermission(user.getUuid(), Claim.Permission.BUILD) || !claim.hasPermission(user.getUuid(), Claim.Permission.SPAWN_BOAT)){ + user.sendSystemMessage(Messages.NO_PERMISSION); + cir.setReturnValue(TypedActionResult.fail(itemStack)); + } } } From e3e4c181281470ddf457b8df3bed6ca12a5846e8 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Thu, 30 Apr 2020 14:55:07 +0200 Subject: [PATCH 73/85] Improve file backup --- .../itsmine/mixin/LevelStorageSessionMixin.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java index 227ddac..5fcfada 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java @@ -35,7 +35,7 @@ public void readWorldProperties(CallbackInfoReturnable callbackInfo) if (!claims.exists() && claims_old.exists()) throw new FileNotFoundException(); ClaimManager.INSTANCE.fromNBT(NbtIo.readCompressed(new FileInputStream(claims))); } catch (IOException e) { - System.err.println("Could not load claims.dat:"); + System.out.println("Could not load " + claims.getName() + ":"); e.printStackTrace(); if (claims_old.exists()) { System.out.println("Attempting to load backup claims..."); @@ -54,15 +54,22 @@ public void saveWorld(class_5219 levelProperties, CompoundTag compoundTag, Callb File claimDataFile = new File(directory.toFile(), "claims.dat"); if (claimDataFile.exists()) { File old = new File(directory.toFile(), "claims.dat_old"); - if (old.exists()) old.delete(); - claimDataFile.renameTo(old); - claimDataFile.delete(); + System.out.println("Saving NBT File: " + claimDataFile.getName() + " " + claimDataFile.length()+ "b " + claimDataFile.getAbsolutePath()); + if(claimDataFile.length() > 45){ + System.out.println("Creating backup of NBT File: " + claimDataFile.getName()); + if (old.exists()) old.delete(); + claimDataFile.renameTo(old); + claimDataFile.delete(); + } else { + System.out.println("Backup failed!" + claimDataFile.getName() + " may be broken, keeping " + old.getName()); + } } try { claimDataFile.createNewFile(); CompoundTag tag = ClaimManager.INSTANCE.toNBT(); NbtIo.writeCompressed(tag, new FileOutputStream(claimDataFile)); } catch (IOException e) { + System.out.println("Could not save " + claimDataFile.getName() + ":"); e.printStackTrace(); } } From 6fd4ce7278883ba9d481bec5a8edb3cf79aa0bce Mon Sep 17 00:00:00 2001 From: DrexHD Date: Fri, 1 May 2020 16:14:44 +0200 Subject: [PATCH 74/85] Fixed /claim list --- .../itsmine/command/{admin => }/ClaimsCommand.java | 2 +- .../fabric/itsmine/command/CommandManager.java | 1 + .../indicode/fabric/itsmine/command/ListCommand.java | 10 ++++------ .../fabric/itsmine/command/admin/AdminCommand.java | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) rename src/main/java/io/github/indicode/fabric/itsmine/command/{admin => }/ClaimsCommand.java (98%) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ClaimsCommand.java similarity index 98% rename from src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java rename to src/main/java/io/github/indicode/fabric/itsmine/command/ClaimsCommand.java index 5d8c250..195238a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ClaimsCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ClaimsCommand.java @@ -1,4 +1,4 @@ -package io.github.indicode.fabric.itsmine.command.admin; +package io.github.indicode.fabric.itsmine.command; import com.mojang.authlib.GameProfile; import com.mojang.brigadier.CommandDispatcher; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java index 961878f..bfae8fc 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java @@ -28,6 +28,7 @@ public static void register(LiteralArgumentBuilder command, AdminCommand.register(command, dispatcher); BlockCommand.register(command); CreateCommand.register(command); + ClaimsCommand.register(command, dispatcher); ExpandCommand.register(command, false); FlyCommand.register(command); HelpCommand.register(command); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java index 9e2c0b1..55ed653 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ListCommand.java @@ -7,23 +7,21 @@ import net.minecraft.server.command.ServerCommandSource; import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.StringArgumentType.word; +import static io.github.indicode.fabric.itsmine.command.ClaimsCommand.list; import static io.github.indicode.fabric.itsmine.command.admin.AdminCommand.PERMISSION_CHECK_ADMIN; -import static io.github.indicode.fabric.itsmine.command.admin.ClaimsCommand.list; -import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.PLAYERS_PROVIDER; -import static net.minecraft.server.command.CommandManager.argument; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getPlayers; import static net.minecraft.server.command.CommandManager.literal; public class ListCommand { public static void register(LiteralArgumentBuilder command) { LiteralArgumentBuilder list = literal("list"); - RequiredArgumentBuilder player = argument("player", word()); + RequiredArgumentBuilder player = getPlayers(); player.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_CHECK_OTHERS, 2)); - player.suggests(PLAYERS_PROVIDER); list.executes(context -> list(context.getSource(), context.getSource().getName())); player.requires(PERMISSION_CHECK_ADMIN); player.executes(context -> list(context.getSource(), getString(context, "player"))); + list.then(player); command.then(list); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java index 027310d..be730f4 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java @@ -3,6 +3,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.command.ClaimsCommand; import io.github.indicode.fabric.itsmine.command.MessageCommand; import io.github.indicode.fabric.itsmine.command.PermissionCommand; import io.github.indicode.fabric.itsmine.command.SettingsCommand; @@ -25,7 +26,6 @@ public static void register(LiteralArgumentBuilder command, private static void registerAdmin(LiteralArgumentBuilder admin, CommandDispatcher dispatcher) { BlocksCommand.register(admin); - ClaimsCommand.register(admin, dispatcher); CreateCommand.register(admin); EntitiesCommand.register(admin); ExpandCommand.register(admin); From f6f4b198c2928c04998148ebc3303b21826fcf56 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Fri, 1 May 2020 16:15:33 +0200 Subject: [PATCH 75/85] Added more options to /claim show --- .../indicode/fabric/itsmine/ClaimShower.java | 2 + .../fabric/itsmine/command/RemoveCommand.java | 2 +- .../fabric/itsmine/command/ShowCommand.java | 39 ++++++--- .../itsmine/mixin/PlayerEntityMixin.java | 7 +- .../fabric/itsmine/util/ArgumentUtil.java | 12 +++ .../fabric/itsmine/util/ClaimUtil.java | 2 +- .../fabric/itsmine/util/ShowerUtil.java | 81 ++++++++++++++----- 7 files changed, 110 insertions(+), 35 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimShower.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimShower.java index a7da63d..c97f880 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimShower.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimShower.java @@ -8,6 +8,8 @@ public interface ClaimShower { void setLastShowPos(BlockPos pos); void setShownClaim(Claim claim); + void setShowMode(String mode); Claim getShownClaim(); + String getMode(); BlockPos getLastShowPos(); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java index 4dc31be..826d449 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java @@ -83,7 +83,7 @@ public static int delete(ServerCommandSource source, Claim claim, boolean admin) ShowerUtil.update(parent, world, false); } source.getWorld().getPlayers().forEach(playerEntity -> { - if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true); + if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true, ((ClaimShower)playerEntity).getMode()); }); source.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)); return 0; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java index 63df117..7349d28 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java @@ -1,5 +1,6 @@ package io.github.indicode.fabric.itsmine.command; +import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; @@ -15,26 +16,44 @@ import net.minecraft.util.Formatting; import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getShowMode; import static io.github.indicode.fabric.itsmine.util.ShowerUtil.silentHideShow; import static net.minecraft.server.command.CommandManager.literal; public class ShowCommand { public static void register(LiteralArgumentBuilder command) { - LiteralArgumentBuilder show = literal("show"); - show.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().dimension.getType()), false)); - RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - claim.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "name")), false)); - show.then(claim); - command.then(show); + { + RequiredArgumentBuilder mode = getShowMode(); + LiteralArgumentBuilder show = literal("show"); + show.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().dimension.getType()), false)); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + claim.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); + mode.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false, StringArgumentType.getString(context, "mode"))); + claim.then(mode); + show.then(claim); + command.then(show); + } + { + LiteralArgumentBuilder hide = literal("hide"); + hide.executes(context -> executeShowClaim(context.getSource(), null, true)); + RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); + claim.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); + hide.then(claim); + command.then(hide); + } + LiteralArgumentBuilder hide = literal("hide"); hide.executes(context -> executeShowClaim(context.getSource(), null, true)); command.then(hide); } - public static int executeShowClaim(ServerCommandSource source, Claim claim, boolean reset) throws CommandSyntaxException { + return executeShowClaim(source, claim, reset, null); + } + + public static int executeShowClaim(ServerCommandSource source, Claim claim, boolean reset, String mode) throws CommandSyntaxException { ServerPlayerEntity player = source.getPlayer(); - if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!Config.claims2d &&((ClaimShower)player).getShownClaim() != claim)) executeShowClaim(source, ((ClaimShower)player).getShownClaim(), true); + if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!Config.claims2d &&((ClaimShower)player).getShownClaim() != claim)) executeShowClaim(source, ((ClaimShower)player).getShownClaim(), true, ((ClaimShower)player).getMode()); if (reset && ((ClaimShower)player).getShownClaim() != null) claim = ((ClaimShower)player).getShownClaim(); if (claim != null) { if (!claim.dimension.equals(source.getWorld().getDimension().getType())) { @@ -43,8 +62,8 @@ public static int executeShowClaim(ServerCommandSource source, Claim claim, bool return 0; } source.sendFeedback(new LiteralText((!reset ? "Showing" : "Hiding") + " claim: " + claim.name).formatted(Formatting.GREEN), false); - if(claim.isChild) silentHideShow(player, ClaimUtil.getParentClaim(claim), reset, true); - else silentHideShow(player, claim, reset, true); + if(claim.isChild) silentHideShow(player, ClaimUtil.getParentClaim(claim), reset, true, mode); + else silentHideShow(player, claim, reset, true, mode); } else { source.sendFeedback(new LiteralText("That is not a valid claim").formatted(Formatting.RED), false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java index fab0f5e..b768e24 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java @@ -30,6 +30,7 @@ protected PlayerEntityMixin(EntityType entityType_1, Wor } private Claim shownClaim = null; private BlockPos lastShowPos = null; + private String showmode = null; @Redirect(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;interact(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Z")) private boolean dontYouDareTouchMe(Entity entity, PlayerEntity playerEntity_1, Hand hand_1) { @@ -91,9 +92,13 @@ public void setShownClaim(Claim claim) { public Claim getShownClaim() { return shownClaim; } - @Override public BlockPos getLastShowPos() { return lastShowPos; } + @Override + public void setShowMode(String mode){showmode = mode;} + @Override + public String getMode(){return showmode;} + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java index 5a671f7..70f9540 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java @@ -64,6 +64,10 @@ public static RequiredArgumentBuilder getEventMessa return argument("message", greedyString()).suggests(EVENT_MESSAGE_PROVIDER); } + public static RequiredArgumentBuilder getShowMode(){ + return argument("mode", greedyString()).suggests(SHOW_MODE_PROVIDER); + } + private static CompletableFuture claimSubzoneProvider(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { @@ -190,4 +194,12 @@ public static CompletableFuture itemsSuggestion(final CommandContex return CommandSource.suggestMatching(strings, builder); }; + public static final SuggestionProvider SHOW_MODE_PROVIDER = (source, builder) -> { + List strings = new ArrayList<>(); + strings.add("outline"); + strings.add("corner"); +// strings.add("old"); + return CommandSource.suggestMatching(strings, builder); + }; + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java index 176cd97..2586f20 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java @@ -18,7 +18,7 @@ public class ClaimUtil { public static BlockPos getPosOnGround(BlockPos pos, World world) { - BlockPos blockPos = new BlockPos(pos.getX(), pos.getY(), pos.getZ()); + BlockPos blockPos = new BlockPos(pos.getX(), 256, pos.getZ()); do { blockPos = blockPos.down(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java index 0c9e109..917cf84 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java @@ -8,53 +8,90 @@ import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; +import java.text.Format; + public class ShowerUtil { - public static void update(Claim claim, ServerWorld world){ - update(claim, world, false); - update(claim, world, true); - } + public static void update(Claim claim, ServerWorld world, boolean hide){ world.getPlayers().forEach(playerEntity -> { ClaimUtil.getParentClaim(claim); - if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, hide, false); + if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, hide, false, ((ClaimShower) playerEntity).getMode()); }); } - public static void silentHideShow(ServerPlayerEntity player, Claim claim, boolean hide, boolean updateStatus) { + public static void silentHideShow(ServerPlayerEntity player, Claim claim, boolean hide, boolean updateStatus, String mode) { if (updateStatus) { - if (!hide) ((ClaimShower) player).setShownClaim(claim); + if (!hide) { + ((ClaimShower) player).setShownClaim(claim); + ((ClaimShower) player).setShowMode(mode); + } else ((ClaimShower) player).setShownClaim(null); } BlockState block = hide ? null : Blocks.GOLD_BLOCK.getDefaultState(); - showCorners(player, claim, hide, block); + show(player, claim, hide, block, mode); if(!claim.isChild){ block = hide ? null : Blocks.DIAMOND_BLOCK.getDefaultState(); for(Claim subzone : claim.children){ - showCorners(player, subzone, hide, block); + show(player, subzone, hide, block, mode); } } } - private static void showCorners(ServerPlayerEntity player, Claim claim, boolean hide, BlockState state){ + private static void show(ServerPlayerEntity player, Claim claim, boolean hide, BlockState state, String mode){ state = hide ? null : state; - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()), player.getEntityWorld())).down(), state); + if(mode == null) mode = ((ClaimShower)player).getMode() == null ? "outline" : ((ClaimShower)player).getMode(); + + switch (mode){ + case "outline": { + showOutline(player, claim, state);break; + } + case "corner": { + showCorner(player, claim, state);break; + } + default: { + player.sendSystemMessage(new LiteralText("Unknown mode").formatted(Formatting.RED)); + } + } + } + + private static void showOutline(ServerPlayerEntity player, Claim claim, BlockState state){ + int y = player.getBlockPos().getY(); + for(int i = claim.min.getX(); i < claim.max.getX(); i++){ + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(i, y, claim.min.getZ()), player.getEntityWorld())).down(), state); + } + for(int i = claim.min.getZ(); i < claim.max.getZ(); i++){ + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), y, i), player.getEntityWorld())).down(), state); + } + for(int i = claim.max.getX(); i > claim.min.getX(); i--){ + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(i, y, claim.max.getZ()), player.getEntityWorld())).down(), state); + } + for(int i = claim.max.getZ(); i > claim.min.getZ(); i--){ + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), y, i), player.getEntityWorld())).down(), state); + } + } + + private static void showCorner(ServerPlayerEntity player, Claim claim, BlockState state){ + int y = player.getBlockPos().getY(); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), y, claim.min.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), y, claim.max.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), y, claim.min.getZ()), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), y, claim.max.getZ()), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()).south(), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()).east(), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()).south(), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()).north(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), y, claim.min.getZ()).south(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), y, claim.max.getZ()).east(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), y, claim.min.getZ()).south(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), y, claim.max.getZ()).north(), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.min.getZ()).east(), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), 256, claim.max.getZ()).north(), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.min.getZ()).west(), player.getEntityWorld())).down(), state); - sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), 256, claim.max.getZ()).west(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), y, claim.min.getZ()).east(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.min.getX(), y, claim.max.getZ()).north(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), y, claim.min.getZ()).west(), player.getEntityWorld())).down(), state); + sendBlockPacket(player, new BlockPos(ClaimUtil.getPosOnGround(new BlockPos(claim.max.getX(), y, claim.max.getZ()).west(), player.getEntityWorld())).down(), state); } private static void sendBlockPacket(ServerPlayerEntity player, BlockPos pos, BlockState state) { From b81e17a2f566d5ab9265401d8366747095d7f4c7 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Fri, 1 May 2020 16:16:55 +0200 Subject: [PATCH 76/85] Fix tridents disappearing --- .../java/io/github/indicode/fabric/itsmine/Functions.java | 4 ++-- .../itsmine/mixin/projectile/ProjectileEntityMixin.java | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index acba598..f64b81e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -100,13 +100,13 @@ public static boolean canDamageWithProjectile(ThrownEntity thrownEntity, Entity return true; } - thrownEntity.kill(); +// thrownEntity.kill(); return false; } public static boolean canDamageWithProjectile(ProjectileEntity projectile, Entity entity) { if (checkCanDamageWithProjectile(entity, projectile.getServer(), ((OwnedProjectile) projectile).getOwner())) { - projectile.kill(); +// projectile.kill(); return true; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java index 18f72a7..857b044 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java @@ -4,7 +4,9 @@ import io.github.indicode.fabric.itsmine.Functions; import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.projectile.ArrowEntity; import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.util.hit.EntityHitResult; import org.spongepowered.asm.mixin.Mixin; @@ -31,7 +33,11 @@ private void imInvincible(ProjectileEntity projectileEntity, EntityHitResult ent this.getOwner().sendSystemMessage(Messages.MSG_DAMAGE_ENTITY); } } + if(projectileEntity.getType() == EntityType.ARROW){ + projectileEntity.kill(); + } } + // public boolean imInvincible(Entity entity, DamageSource damageSource_1, float float_1) { // if (entity.world.isClient()) return entity.damage(damageSource_1, float_1); // ProjectileEntity projectile = (ProjectileEntity)(Object)this; From 3fee3436c4a26aae683245dd85fddf151c0ad638 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Fri, 1 May 2020 16:17:13 +0200 Subject: [PATCH 77/85] Fixed pageUtil --- .../fabric/itsmine/util/MessageUtil.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java index 4a061f7..e4600b8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java @@ -10,28 +10,24 @@ public class MessageUtil { public static void sendPage(ServerCommandSource source, Text header, int entries, int page, String command, ArrayList content){ - System.out.println(1); - //1 - //10 max entries - //3 entries + + for (int i=0; i < content.size(); i += entries) { + System.out.println(content.subList(i, Math.min(content.size(), i + entries))); + } + int pages = Math.floorDiv(content.size(), entries); if(content.size() % entries != 0) pages++; - System.out.println("pages: " + pages); if(page < 1) return; - System.out.println(2); if(page > pages) return; - System.out.println(3); LiteralText message = new LiteralText(""); - System.out.println(4); message.append(header).append(new LiteralText("\n\n")); - System.out.println(5); - for(int i = (entries * (page - 1) + 1); i < (page * entries); i++) { - System.out.println("i: " + i); - message.append(content.get(i-1)).append(new LiteralText("\n")); + for (int i = 0; i < content.size(); i += entries) { + content.subList(i, Math.min(content.size(), i + entries)).forEach(text -> { + message.append(text).append(new LiteralText("\n")); + }); } - System.out.println(6); + message.append(new LiteralText("\n")); - System.out.println(7); Text button_prev = new LiteralText("") .append(new LiteralText("<-").formatted(Formatting.WHITE).formatted(Formatting.BOLD)) .append(new LiteralText(" ")).append(new LiteralText("Prev").formatted(Formatting.GOLD)) From 1f4b10a88830b1260de8375e1a45de5a9411f7f2 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Fri, 1 May 2020 16:17:21 +0200 Subject: [PATCH 78/85] Removed entity bread limit --- src/main/resources/itsmine.mixins.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index dab9907..36a21d1 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -32,7 +32,6 @@ "EnderDragonEntityMixin", "FarmlandBlockMixin", "BoatItemMixin", - "AnimalEntityMixin", "ServerCommandOutputMixin" ], "injectors": { From 77d48d229b1f10dc846475115f62f16870defeda Mon Sep 17 00:00:00 2001 From: DrexHD Date: Sat, 2 May 2020 20:10:37 +0200 Subject: [PATCH 79/85] Moved Claim and ClaimSettings --- gradle.properties | 2 +- .../indicode/fabric/itsmine/ClaimShower.java | 1 + .../indicode/fabric/itsmine/Functions.java | 2 +- .../indicode/fabric/itsmine/Messages.java | 6 +- .../fabric/itsmine/{ => claim}/Claim.java | 57 +---------------- .../fabric/itsmine/claim/ClaimSettings.java | 62 +++++++++++++++++++ .../fabric/itsmine/command/ClaimsCommand.java | 2 +- .../fabric/itsmine/command/CreateCommand.java | 2 +- .../fabric/itsmine/command/ExpandCommand.java | 3 +- .../fabric/itsmine/command/HelpCommand.java | 2 +- .../fabric/itsmine/command/InfoCommand.java | 2 +- .../itsmine/command/MessageCommand.java | 2 +- .../fabric/itsmine/command/RemoveCommand.java | 4 +- .../fabric/itsmine/command/RenameCommand.java | 2 +- .../fabric/itsmine/command/RentCommand.java | 4 +- .../itsmine/command/RentableCommand.java | 2 +- .../itsmine/command/RevenueCommand.java | 2 +- .../itsmine/command/SettingsCommand.java | 5 +- .../fabric/itsmine/command/ShowCommand.java | 2 +- .../itsmine/command/TransferCommand.java | 3 +- .../fabric/itsmine/command/TrustCommand.java | 3 +- .../itsmine/command/TrustedCommand.java | 2 +- .../command/admin/EntitiesCommand.java | 9 +-- .../itsmine/command/admin/ListAllCommand.java | 2 +- .../itsmine/command/admin/OwnerCommand.java | 2 +- .../command/subzone/CreateCommand.java | 2 +- .../command/subzone/SubzoneCommand.java | 2 + .../itsmine/mixin/AbstractFireBlockMixin.java | 6 +- .../itsmine/mixin/AnimalEntityMixin.java | 4 +- .../fabric/itsmine/mixin/BoatItemMixin.java | 5 +- .../itsmine/mixin/EnderDragonEntityMixin.java | 5 +- .../itsmine/mixin/EnderPearlItemMixin.java | 2 +- .../fabric/itsmine/mixin/EntityMixin.java | 11 ++-- .../fabric/itsmine/mixin/ExplosionMixin.java | 11 ++-- .../itsmine/mixin/FarmlandBlockMixin.java | 5 +- .../fabric/itsmine/mixin/FireBlockMixin.java | 27 ++++---- .../fabric/itsmine/mixin/FluidMixin.java | 12 ++-- .../fabric/itsmine/mixin/LavaMixin.java | 19 +++--- .../mixin/LecternScreenHandlerMixin.java | 2 +- .../itsmine/mixin/PistonBlockMixin.java | 14 ++--- .../itsmine/mixin/PlaceOnUseBlockMixin.java | 3 +- .../itsmine/mixin/PlayerEntityMixin.java | 25 +------- .../itsmine/mixin/ProjectileEntityMixin.java | 7 +-- .../mixin/ServerPlayNetworkHandlerMixin.java | 9 +-- .../ServerPlayerInteractionManagerMixin.java | 1 + .../itsmine/mixin/SpawnRestrictionMixin.java | 5 +- .../fabric/itsmine/util/ClaimUtil.java | 9 +-- .../fabric/itsmine/util/EntityUtil.java | 7 +-- .../fabric/itsmine/util/ShowerUtil.java | 4 +- 49 files changed, 167 insertions(+), 215 deletions(-) rename src/main/java/io/github/indicode/fabric/itsmine/{ => claim}/Claim.java (92%) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/claim/ClaimSettings.java diff --git a/gradle.properties b/gradle.properties index 59ffb40..898d632 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=20w18a+build.1 loader_version=0.7.10+build.191 # Mod Properties - mod_version = 1.9.0-20W18A + mod_version = 1.9.1-20W18A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimShower.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimShower.java index c97f880..760762d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimShower.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimShower.java @@ -1,5 +1,6 @@ package io.github.indicode.fabric.itsmine; +import io.github.indicode.fabric.itsmine.claim.Claim; import net.minecraft.util.math.BlockPos; /** diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index f64b81e..9eed74d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -1,5 +1,6 @@ package io.github.indicode.fabric.itsmine; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.mixin.BlockActionPacketMixin; import io.github.indicode.fabric.itsmine.mixin.BucketItemMixin; import io.github.indicode.fabric.itsmine.mixin.projectile.OwnedProjectile; @@ -20,7 +21,6 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -import net.minecraft.world.World; import java.util.*; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 6551b1e..8e49c02 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -1,5 +1,7 @@ package io.github.indicode.fabric.itsmine; +import io.github.indicode.fabric.itsmine.claim.Claim; +import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import net.minecraft.text.LiteralText; import net.minecraft.text.MutableText; import net.minecraft.text.Text; @@ -12,6 +14,8 @@ public class Messages { public static final Text INVALID_SETTING = PREFIX.copy().append(new LiteralText("Invalid Claim Setting!").formatted(Formatting.RED)); + public static final Text INVALID_PERMISSION = PREFIX.copy().append(new LiteralText("Invalid Claim Permission!")); + public static final Text NO_PERMISSION = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_no_perm))); public static final Text INVALID_MESSAGE_EVENT = PREFIX.copy().append(new LiteralText("Invalid Message Event!")); @@ -159,7 +163,7 @@ public static Text getSettings(Claim claim) { MutableText claimSettings = new LiteralText(""); boolean nextEnabled = false; boolean nextDisabled = false; - for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { + for (ClaimSettings.Setting value : ClaimSettings.Setting.values()) { boolean enabled = claim.settings.getSetting(value); Formatting formatting; if (enabled) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java similarity index 92% rename from src/main/java/io/github/indicode/fabric/itsmine/Claim.java rename to src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java index 0356eb0..e4174c5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java @@ -1,6 +1,7 @@ -package io.github.indicode.fabric.itsmine; +package io.github.indicode.fabric.itsmine.claim; import blue.endless.jankson.annotation.Nullable; +import io.github.indicode.fabric.itsmine.*; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.item.ItemStack; @@ -736,60 +737,6 @@ public CompoundTag toNBT() { return tag; } } - public static class ClaimSettings{ - public enum Setting { - FLIGHT_ALLOWED("flight_allowed", "Flying Allowed", true), - EXPLOSION_DESTRUCTION("explosion_destruction", "Explosion Destroys Blocks", false), - EXPLOSION_DAMAGE("explosion_damage", "Explosion Damages Entities", false), - FLUID_CROSSES_BORDERS("fluid_crosses_borders", "Fluid Crosses Borders", false), - FIRE_CROSSES_BORDERS("fire_crosses_borders", "Fire Crosses Borders", false), - FIRE_DAMAGE("fire_damage", "Fire Damages Entities", false), - PISTON_FROM_INSIDE("pistons_inside_border", "Pistons Cross border from Inside", true), - PISTON_FROM_OUTSIDE("pistons_outside_border", "Pistons Cross border from Outside", false), - MOB_SPAWNING("mob_spawn", "Natural mob spawning", true), -// KEEP_INVENTORY("keep_inventory", "Keep Inventory", true), - ENTER_SOUND("enter_sound", "Enter Sound", false), - BREAK_FARMLANDS("break_farmlands", "Break Farmlands", false); - - public String id, name; - boolean defaultValue; - Setting(String id, String name, boolean defaultValue) { - this.id = id; - this.name = name; - this.defaultValue = defaultValue; - } - public static ClaimSettings.Setting byId(String id) { - for (ClaimSettings.Setting permission: values()) { - if (permission.id.equals(id)) return permission; - } - return null; - } - } - public Map settings = new HashMap<>(); - public ClaimSettings(CompoundTag tag) { - fromTag(tag); - } - public ClaimSettings() { - } - public boolean getSetting(Setting setting) { - return settings.getOrDefault(setting, setting.defaultValue); - } - public CompoundTag toTag() { - CompoundTag tag = new CompoundTag(); - this.settings.forEach((setting, data) -> { - tag.putBoolean(setting.id, data); - }); - return tag; - } - public void fromTag(CompoundTag tag) { - settings.clear(); - tag.getKeys().forEach(key -> { - Setting setting = Setting.byId(key); - if (setting == null) return; - this.settings.put(setting, tag.getBoolean(key)); - }); - } - } public enum Event { ENTER_CLAIM("enter", Config.msg_enter_default), LEAVE_CLAIM("leave", Config.msg_leave_default); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/claim/ClaimSettings.java b/src/main/java/io/github/indicode/fabric/itsmine/claim/ClaimSettings.java new file mode 100644 index 0000000..d015fee --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/claim/ClaimSettings.java @@ -0,0 +1,62 @@ +package io.github.indicode.fabric.itsmine.claim; + +import net.minecraft.nbt.CompoundTag; + +import java.util.HashMap; +import java.util.Map; + +public class ClaimSettings{ + public enum Setting { + FLIGHT_ALLOWED("flight_allowed", "Flying Allowed", true), + EXPLOSION_DESTRUCTION("explosion_destruction", "Explosion Destroys Blocks", false), + EXPLOSION_DAMAGE("explosion_damage", "Explosion Damages Entities", false), + FLUID_CROSSES_BORDERS("fluid_crosses_borders", "Fluid Crosses Borders", false), + FIRE_CROSSES_BORDERS("fire_crosses_borders", "Fire Crosses Borders", false), + FIRE_DAMAGE("fire_damage", "Fire Damages Entities", false), + PISTON_FROM_INSIDE("pistons_inside_border", "Pistons Cross border from Inside", true), + PISTON_FROM_OUTSIDE("pistons_outside_border", "Pistons Cross border from Outside", false), + MOB_SPAWNING("mob_spawn", "Natural mob spawning", true), + // KEEP_INVENTORY("keep_inventory", "Keep Inventory", true), + ENTER_SOUND("enter_sound", "Enter Sound", false), + BREAK_FARMLANDS("break_farmlands", "Break Farmlands", false); + + public String id, name; + boolean defaultValue; + + Setting(String id, String name, boolean defaultValue) { + this.id = id; + this.name = name; + this.defaultValue = defaultValue; + } + public static Setting byId(String id) { + for (Setting permission: values()) { + if (permission.id.equals(id)) return permission; + } + return null; + } + } + public Map settings = new HashMap<>(); + public ClaimSettings(CompoundTag tag) { + fromTag(tag); + } + public ClaimSettings() { + } + public boolean getSetting(Setting setting) { + return settings.getOrDefault(setting, setting.defaultValue); + } + public CompoundTag toTag() { + CompoundTag tag = new CompoundTag(); + this.settings.forEach((setting, data) -> { + tag.putBoolean(setting.id, data); + }); + return tag; + } + public void fromTag(CompoundTag tag) { + settings.clear(); + tag.getKeys().forEach(key -> { + Setting setting = Setting.byId(key); + if (setting == null) return; + this.settings.put(setting, tag.getBoolean(key)); + }); + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ClaimsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ClaimsCommand.java index 195238a..f037a56 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ClaimsCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ClaimsCommand.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.server.command.ServerCommandSource; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java index 6b2fef1..d4d555c 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java @@ -6,6 +6,7 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.util.PermissionUtil; import net.minecraft.command.arguments.BlockPosArgumentType; import net.minecraft.command.arguments.PosArgument; @@ -14,7 +15,6 @@ import net.minecraft.text.HoverEvent; import net.minecraft.text.LiteralText; import net.minecraft.text.MutableText; -import net.minecraft.text.Style; import net.minecraft.util.Formatting; import net.minecraft.util.Pair; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java index 8a08156..c243c81 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java @@ -4,13 +4,12 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.util.ClaimUtil; import io.github.indicode.fabric.itsmine.util.ShowerUtil; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java index 19729c2..1073dfb 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import io.github.indicode.fabric.itsmine.ChatColor; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.*; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java index 3b3f3c1..910d45b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; import io.github.indicode.fabric.itsmine.util.TimeUtil; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/MessageCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/MessageCommand.java index ccf9611..b037bde 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/MessageCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/MessageCommand.java @@ -2,7 +2,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.server.command.ServerCommandSource; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java index 826d449..b256d3a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java @@ -3,11 +3,10 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.ClaimShower; import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import io.github.indicode.fabric.itsmine.util.ClaimUtil; import io.github.indicode.fabric.itsmine.util.PermissionUtil; import io.github.indicode.fabric.itsmine.util.ShowerUtil; @@ -15,7 +14,6 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.text.ClickEvent; import net.minecraft.text.LiteralText; -import net.minecraft.text.Style; import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java index 6d0cb51..fc31fdf 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RenameCommand.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; import io.github.indicode.fabric.itsmine.util.ArgumentUtil; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java index 10add3a..59aec59 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RentCommand.java @@ -3,13 +3,11 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import io.github.indicode.fabric.itsmine.util.TimeUtil; import net.minecraft.item.ItemStack; -import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.LiteralText; import net.minecraft.util.Formatting; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java index 3358b9f..ad78df0 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Config; import io.github.indicode.fabric.itsmine.util.ArgumentUtil; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java index 600a329..8ea93dc 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.item.Item; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java index acd8c97..2201a30 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java @@ -3,16 +3,13 @@ import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.server.command.ServerCommandSource; import static com.mojang.brigadier.arguments.StringArgumentType.getString; -import static com.mojang.brigadier.arguments.StringArgumentType.word; import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; -import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.SETTINGS_PROVIDER; import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getSettings; import static io.github.indicode.fabric.itsmine.util.ClaimUtil.executeSetting; import static io.github.indicode.fabric.itsmine.util.ClaimUtil.querySettings; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java index 7349d28..1103930 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.ClaimShower; import io.github.indicode.fabric.itsmine.Config; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java index 8e67b99..69c4d3c 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.ItsMine; import io.github.indicode.fabric.itsmine.Messages; @@ -16,7 +16,6 @@ import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.ClickEvent; import net.minecraft.text.LiteralText; -import net.minecraft.text.Style; import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java index c2f62f5..14a86fb 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java @@ -7,9 +7,8 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.command.arguments.GameProfileArgumentType; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java index 8ff0c6b..db16f5f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java @@ -5,7 +5,7 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; import io.github.indicode.fabric.itsmine.util.ArgumentUtil; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java index 45ccf30..ccfb5a0 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java @@ -5,10 +5,9 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.util.ArgumentUtil; -import io.github.indicode.fabric.itsmine.util.EntityUtil; import io.github.indicode.fabric.itsmine.util.PermissionUtil; -import io.github.indicode.fabric.itsmine.util.WorldUtil; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityCategory; import net.minecraft.entity.EntityType; @@ -16,18 +15,12 @@ import net.minecraft.text.HoverEvent; import net.minecraft.text.LiteralText; import net.minecraft.text.MutableText; -import net.minecraft.text.Style; import net.minecraft.util.Formatting; -import net.minecraft.world.World; -import java.awt.*; import java.util.ArrayList; import java.util.Map; -import java.util.UUID; -import static com.mojang.brigadier.arguments.StringArgumentType.getString; import static io.github.indicode.fabric.itsmine.Messages.header; -import static io.github.indicode.fabric.itsmine.Messages.text; import static io.github.indicode.fabric.itsmine.util.EntityUtil.*; import static net.minecraft.server.command.CommandManager.literal; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java index b1c4f63..10461a8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ListAllCommand.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.util.MessageUtil; import net.minecraft.server.command.ServerCommandSource; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java index 3d99a42..3c04349 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java @@ -3,7 +3,7 @@ import com.mojang.authlib.GameProfile; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; import io.github.indicode.fabric.itsmine.util.ArgumentUtil; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java index da6397e..6b76924 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java @@ -5,7 +5,7 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Config; import io.github.indicode.fabric.itsmine.Messages; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java index 55c6d9a..922bb0b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java @@ -5,12 +5,14 @@ import io.github.indicode.fabric.itsmine.command.*; import net.minecraft.server.command.ServerCommandSource; +import static io.github.indicode.fabric.itsmine.command.admin.AdminCommand.PERMISSION_CHECK_ADMIN; import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getSubzones; import static net.minecraft.server.command.CommandManager.literal; public class SubzoneCommand { public static void register(LiteralArgumentBuilder command, CommandDispatcher dispatcher, boolean admin) { LiteralArgumentBuilder subzone = literal("subzone"); + subzone.requires(PERMISSION_CHECK_ADMIN); registerSubzone(subzone, dispatcher, admin); command.then(subzone); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java index d1744f9..b1d07e6 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java @@ -1,10 +1,10 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import net.minecraft.block.AbstractFireBlock; import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -15,7 +15,7 @@ public abstract class AbstractFireBlockMixin { @Redirect(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isFireImmune()Z")) private boolean neverGonnaBurnYouUp(Entity entity) { Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.dimension); - if (claim != null && !claim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_DAMAGE)) { + if (claim != null && !claim.settings.getSetting(ClaimSettings.Setting.FIRE_DAMAGE)) { return true; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java index c7dd14b..f2e3eea 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java @@ -1,7 +1,7 @@ package io.github.indicode.fabric.itsmine.mixin; import blue.endless.jankson.annotation.Nullable; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Config; import io.github.indicode.fabric.itsmine.util.ClaimUtil; @@ -17,8 +17,6 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.util.UUID; - @Mixin(AnimalEntity.class) public abstract class AnimalEntityMixin { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java index 7ee4c96..465b30a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java @@ -1,9 +1,8 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; -import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BoatItem; import net.minecraft.item.Item; @@ -13,14 +12,12 @@ import net.minecraft.util.hit.HitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; -import net.minecraft.world.ModifiableWorld; import net.minecraft.world.RayTraceContext; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.CancellationException; @Mixin(BoatItem.class) public abstract class BoatItemMixin extends Item { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java index 1c0a434..3952fa2 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java @@ -1,7 +1,8 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import net.minecraft.entity.boss.dragon.EnderDragonEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -16,7 +17,7 @@ public class EnderDragonEntityMixin { private boolean dontTouchieMyBlocksStupidDragon(World world, BlockPos pos, boolean move) { Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.dimension.getType()); - if (claim != null && !claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) { + if (claim != null && !claim.settings.getSetting(ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) { return false; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java index f8e5a72..bc7faf5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java @@ -1,6 +1,6 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.entity.player.PlayerEntity; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index 9f5d8ec..62b1f27 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -1,6 +1,8 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.claim.Claim; +import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import io.github.indicode.fabric.itsmine.util.ClaimUtil; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; @@ -8,11 +10,8 @@ import net.minecraft.network.packet.s2c.play.TitleS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.sound.SoundCategory; -import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvents; import net.minecraft.text.LiteralText; -import net.minecraft.text.Texts; -import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.util.registry.Registry; @@ -59,7 +58,7 @@ else if (claim != null) if (message != null) serverPlayerEntity.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText(ChatColor.translate(message)), -1, Config.event_msg_stay_ticks, -1)); - if (claim != null && claim.settings.getSetting(Claim.ClaimSettings.Setting.ENTER_SOUND)) { + if (claim != null && claim.settings.getSetting(ClaimSettings.Setting.ENTER_SOUND)) { serverPlayerEntity.networkHandler.sendPacket(new PlaySoundIdS2CPacket(Registry.SOUND_EVENT.getId(SoundEvents.BLOCK_CONDUIT_ACTIVATE), SoundCategory.MASTER, this.getPos(), 2, 1.2F)); } } @@ -95,7 +94,7 @@ public void doTickActions(CallbackInfo ci) { ( ( !ClaimManager.INSTANCE.flyers.contains(player.getUuid()) || - claim == null || !claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) || + claim == null || !claim.settings.getSetting(ClaimSettings.Setting.FLIGHT_ALLOWED) || !claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT) || !Functions.canFly((ServerPlayerEntity) player) ) @@ -116,7 +115,7 @@ public void doTickActions(CallbackInfo ci) { ClaimManager.INSTANCE.flyers.contains(player.getUuid()) && shouldChange(player) && claim != null && - claim.settings.getSetting(Claim.ClaimSettings.Setting.FLIGHT_ALLOWED) + claim.settings.getSetting(ClaimSettings.Setting.FLIGHT_ALLOWED) && claim.hasPermission(player.getUuid(), Claim.Permission.FLIGHT) && Functions.canFly((ServerPlayerEntity) player) ///&& Functions.canClaimFly((ServerPlayerEntity) player) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java index c389413..16d243f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java @@ -1,7 +1,8 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; @@ -12,11 +13,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.List; /** * @author Indigo Amann @@ -29,7 +26,7 @@ public class ExplosionMixin { private BlockState theyCallMeBedrock(World world, BlockPos pos) { Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); if (claim != null && !world.isAir(pos) && !world.getBlockState(pos).getBlock().equals(Blocks.TNT)) { - if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) { + if (!claim.settings.getSetting(ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) { return Blocks.BEDROCK.getDefaultState(); } } @@ -41,7 +38,7 @@ private boolean claimDeniesExplosion(Entity entity) { BlockPos blockPos_1 = entity.getBlockPos(); Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, entity.world.getDimension().getType()); if (claim != null) { - if (!claim.settings.getSetting(Claim.ClaimSettings.Setting.EXPLOSION_DAMAGE)) { + if (!claim.settings.getSetting(ClaimSettings.Setting.EXPLOSION_DAMAGE)) { return true; } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java index de3271e..971a9e3 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java @@ -1,7 +1,8 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import net.minecraft.block.FarmlandBlock; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; @@ -18,7 +19,7 @@ public abstract class FarmlandBlockMixin { private void dontYouDareFarmMe(World world, BlockPos pos, Entity entity, float distance, CallbackInfo ci) { Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.dimension.getType()); - if (claim != null && !claim.settings.getSetting(Claim.ClaimSettings.Setting.BREAK_FARMLANDS)) { + if (claim != null && !claim.settings.getSetting(ClaimSettings.Setting.BREAK_FARMLANDS)) { ci.cancel(); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java index 417575e..c5cc7ec 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java @@ -1,7 +1,8 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.FireBlock; @@ -32,13 +33,13 @@ private void dontBurnClaims(FireBlock fireBlock, World world, BlockPos newPos, i Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; + if (!newClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; } else if (newClaim == null) { - if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; + if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; } else { - if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || - !newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; + if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || + !newClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; } } trySpreadingFire(world, newPos, int_1, random_1, int_2); @@ -49,14 +50,14 @@ private boolean dontCauseFire2(ServerWorld world, BlockPos newPos, BlockState bl Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) + if (!newClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return false; } else if (newClaim == null) { - if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) + if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return false; } else { - if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || - !newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) + if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || + !newClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return false; } } @@ -80,13 +81,13 @@ private boolean dontCauseFire(World world, BlockPos oldPos, BlockState blockStat Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); + if (!newClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); } else if (newClaim == null) { - if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); + if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); } else { - if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || - !newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); + if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || + !newClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); } } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java index 85ff82a..5698efa 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java @@ -1,11 +1,11 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import net.minecraft.block.BlockState; import net.minecraft.fluid.BaseFluid; import net.minecraft.fluid.FluidState; -import net.minecraft.fluid.LavaFluid; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.world.IWorld; @@ -26,13 +26,13 @@ private void dontFlow(IWorld world, BlockPos newPos, BlockState blockState_1, Di Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!newClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); } else if (newClaim == null) { - if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); } else { - if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || - !newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || + !newClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); } } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java index 6abae3b..688e73d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java @@ -1,7 +1,8 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import net.minecraft.block.BlockState; import net.minecraft.fluid.FluidState; import net.minecraft.fluid.LavaFluid; @@ -29,13 +30,13 @@ private void dontFlow(IWorld world, BlockPos newPos, BlockState blockState_1, Di Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!newClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); } else if (newClaim == null) { - if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); } else { - if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || - !newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || + !newClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); } } } @@ -45,15 +46,15 @@ public boolean neverGonnaBurnMeUp(World world, BlockPos newPos, BlockState block Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) + if (!newClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) return false; } else if (newClaim == null) { - if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) + if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) return false; } else { - if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || - !newClaim.settings.getSetting(Claim.ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) + if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || + !newClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) return false; } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java index e432f1a..86ae657 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LecternScreenHandlerMixin.java @@ -1,6 +1,6 @@ //package io.github.indicode.fabric.itsmine.mixin; // -//import io.github.indicode.fabric.itsmine.Claim; +//import io.github.indicode.fabric.itsmine.claim.Claim; //import io.github.indicode.fabric.itsmine.ClaimManager; //import io.github.indicode.fabric.itsmine.util.ClaimUtil; //import net.minecraft.entity.player.PlayerEntity; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java index 6b71ac5..092326d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java @@ -1,12 +1,11 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import net.minecraft.block.Block; +import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import net.minecraft.block.BlockState; import net.minecraft.block.PistonBlock; import net.minecraft.block.piston.PistonHandler; -import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.world.World; @@ -16,7 +15,6 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.util.ArrayList; import java.util.List; /** @@ -33,13 +31,13 @@ private static void youCantMoveMe(BlockState blockState_1, World world, BlockPos Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!newClaim.settings.getSetting(Claim.ClaimSettings.Setting.PISTON_FROM_OUTSIDE)) ci.setReturnValue(false); + if (!newClaim.settings.getSetting(ClaimSettings.Setting.PISTON_FROM_OUTSIDE)) ci.setReturnValue(false); } else if (newClaim == null) { - if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.PISTON_FROM_INSIDE)) ci.setReturnValue(false); + if (!oldClaim.settings.getSetting(ClaimSettings.Setting.PISTON_FROM_INSIDE)) ci.setReturnValue(false); } else { - if (!oldClaim.settings.getSetting(Claim.ClaimSettings.Setting.PISTON_FROM_INSIDE) || - !newClaim.settings.getSetting(Claim.ClaimSettings.Setting.PISTON_FROM_OUTSIDE)) ci.setReturnValue(false); + if (!oldClaim.settings.getSetting(ClaimSettings.Setting.PISTON_FROM_INSIDE) || + !newClaim.settings.getSetting(ClaimSettings.Setting.PISTON_FROM_OUTSIDE)) ci.setReturnValue(false); } } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java index 5ab83e8..0a37bbe 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java @@ -1,8 +1,7 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Functions; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BucketItem; import net.minecraft.item.Item; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java index b768e24..2f1f723 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java @@ -1,6 +1,7 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.util.EntityUtil; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -55,35 +56,11 @@ public void hittingIsRude(Entity entity, CallbackInfo ci) { ci.cancel(); } } - - - -// @Redirect(method = "dropInventory", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/GameRules;getBoolean(Lnet/minecraft/world/GameRules$RuleKey;)Z")) -// private boolean dontTakeMyThingies(GameRules gameRules, GameRules.RuleKey rule) { -// PlayerEntity playerEntity_1 = (PlayerEntity)(Object)this; -// Claim claim = ClaimManager.INSTANCE.getClaimAt(playerEntity_1.getSenseCenterPos(), playerEntity_1.world.getDimension().getType()); -// if (claim != null) { -// playerEntity_1.sendSystemMessage(new LiteralText("keep_inventory: " + claim.settings.getSetting(Claim.ClaimSettings.Setting.KEEP_INVENTORY) + " server: " + gameRules.getBoolean(rule))); -// -// if (claim.settings.getSetting(Claim.ClaimSettings.Setting.KEEP_INVENTORY)) -// return true; -// } -// -// return gameRules.getBoolean(rule); -// } - @Override public void setLastShowPos(BlockPos pos) { lastShowPos = pos; } - /*@Inject(method = "canPlaceOn", at = @At("HEAD")) - public void iDontWantYerStuff(BlockPos blockPos_1, Direction direction_1, ItemStack itemStack_1, CallbackInfoReturnable cir) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, world.getDimension().getType()); - if (claim != null) { - cir.setReturnValue(false); - } - }*/ // Replace with specific undos on certain methods(buttons, containers, etc) @Override public void setShownClaim(Claim claim) { shownClaim = claim; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java index aaeff8b..4960e85 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java @@ -1,21 +1,16 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.entity.Entity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.ProjectileEntity; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import java.util.UUID; - /** * @author Indigo Amann */ diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java index 0e4db34..b59acd7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java @@ -1,20 +1,13 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Functions; -import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.network.ServerPlayNetworkHandler; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; import net.minecraft.util.ActionResult; -import net.minecraft.util.Formatting; import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index 8e854fe..6da3101 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -1,6 +1,7 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.util.BlockUtil; import net.minecraft.block.*; import net.minecraft.entity.player.PlayerEntity; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java index 11bf34b..d54bd11 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java @@ -1,7 +1,8 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import net.minecraft.entity.EntityType; import net.minecraft.entity.SpawnRestriction; import net.minecraft.entity.SpawnType; @@ -23,7 +24,7 @@ private static void canSpawnInClaim(EntityType type, IWorld world, SpawnType return; } Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); - if (claim != null && !claim.settings.getSetting(Claim.ClaimSettings.Setting.MOB_SPAWNING)) { + if (claim != null && !claim.settings.getSetting(ClaimSettings.Setting.MOB_SPAWNING)) { cir.setReturnValue(false); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java index 2586f20..5074b10 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java @@ -5,9 +5,10 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.claim.Claim; +import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; import net.minecraft.text.LiteralText; import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; @@ -88,12 +89,12 @@ public static void validateCanAccess(ServerPlayerEntity player, Claim claim, boo } } - public static int querySetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting) { + public static int querySetting(ServerCommandSource source, Claim claim, ClaimSettings.Setting setting) { boolean enabled = claim.settings.getSetting(setting); source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); return 1; } - public static int setSetting(ServerCommandSource source, Claim claim, Claim.ClaimSettings.Setting setting, boolean set) { + public static int setSetting(ServerCommandSource source, Claim claim, ClaimSettings.Setting setting, boolean set) { claim.settings.settings.put(setting, set); source.sendFeedback(new LiteralText(ChatColor.translate("&eSet setting &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); return 0; @@ -127,7 +128,7 @@ public static int executeSetting(ServerCommandSource source, String input, @Null } validateCanAccess(player, claim1, admin); - Claim.ClaimSettings.Setting setting = Claim.ClaimSettings.Setting.byId(input); + ClaimSettings.Setting setting = ClaimSettings.Setting.byId(input); Claim.Permission permission = Claim.Permission.byId(input); if (setting != null && permission == null) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java index 8eb5ff2..51819b9 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java @@ -1,22 +1,17 @@ package io.github.indicode.fabric.itsmine.util; -import com.mojang.datafixers.types.Func; -import io.github.indicode.fabric.itsmine.Claim; -import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.Functions; import io.github.indicode.fabric.itsmine.MonitorableWorld; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityCategory; import net.minecraft.entity.EntityType; import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.LiteralText; -import net.minecraft.util.Formatting; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.UUID; -import java.util.concurrent.atomic.AtomicReference; import static io.github.indicode.fabric.itsmine.util.WorldUtil.getServerWorld; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java index 917cf84..a0aba8e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java @@ -1,6 +1,6 @@ package io.github.indicode.fabric.itsmine.util; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimShower; import io.github.indicode.fabric.itsmine.mixin.BlockUpdatePacketMixin; import net.minecraft.block.BlockState; @@ -12,8 +12,6 @@ import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; -import java.text.Format; - public class ShowerUtil { From 0d5035ba13b9207ae24dca2742114072127d1b4c Mon Sep 17 00:00:00 2001 From: DrexHD Date: Sat, 2 May 2020 20:11:02 +0200 Subject: [PATCH 80/85] Fixed bugs --- .../indicode/fabric/itsmine/ClaimManager.java | 5 +- .../itsmine/command/PermissionCommand.java | 79 ++++++++++--------- .../fabric/itsmine/util/ArgumentUtil.java | 13 +-- 3 files changed, 46 insertions(+), 51 deletions(-) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java index 1367d15..8d13c2d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java @@ -1,9 +1,9 @@ package io.github.indicode.fabric.itsmine; +import io.github.indicode.fabric.itsmine.claim.Claim; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.StringTag; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Pair; @@ -11,7 +11,6 @@ import net.minecraft.world.dimension.DimensionType; import org.jetbrains.annotations.Nullable; -import javax.naming.Name; import java.util.*; /** @@ -73,7 +72,7 @@ public boolean addClaim(Claim claim) { } public boolean wouldIntersect(Claim claim) { for (Claim value : claimsByName.values()) { - if(!claim.name.equals(value.name) && claim.intersects(value)) return true; + if(!value.isChild && !claim.name.equals(value.name) && (claim.intersects(value) || value.intersects(claim))) return true; } return false; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionCommand.java index 0ae7885..db5afcb 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionCommand.java @@ -4,11 +4,11 @@ import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.Claim; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; import io.github.indicode.fabric.itsmine.Messages; -import io.github.indicode.fabric.itsmine.util.PermissionUtil; import net.minecraft.command.EntitySelector; import net.minecraft.command.arguments.EntityArgumentType; import net.minecraft.server.command.ServerCommandSource; @@ -30,7 +30,6 @@ public class PermissionCommand { public static void register(LiteralArgumentBuilder command, boolean admin, RequiredArgumentBuilder claim) { LiteralArgumentBuilder exception = literal("permissions"); RequiredArgumentBuilder player = argument("player", EntityArgumentType.player()); - LiteralArgumentBuilder remove = literal("remove"); LiteralArgumentBuilder all = literal("*"); RequiredArgumentBuilder allstate = argument("allow", BoolArgumentType.bool()); RequiredArgumentBuilder permNode = getPermissions(); @@ -55,16 +54,6 @@ public static void register(LiteralArgumentBuilder command, return showTrustedList(context, claim1, true); }); - remove.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - claim1.permissionManager.resetPermissions(player1.getGameProfile().getId()); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + " no longer has an exception in the claim").formatted(Formatting.YELLOW), false); - } - return 0; - }); - allstate.executes(context -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); @@ -72,38 +61,50 @@ public static void register(LiteralArgumentBuilder command, return setTrust(context, claim1, player1.getGameProfile(), BoolArgumentType.getBool(context, "allow"), admin); }); - allow.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - boolean permission = BoolArgumentType.getBool(context, "allow"); - Claim.Permission value = Claim.Permission.byId(StringArgumentType.getString(context, "permission")); - modifyException(claim1, player1, value, permission); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has the permission " + value.name).formatted(Formatting.YELLOW), false); - } - return 0; - }); - - permNode.executes(context -> { - Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); - if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { - ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); - Claim.Permission value = Claim.Permission.byId(StringArgumentType.getString(context, "permission")); - boolean permission = hasPermission(claim1, player1, value); - context.getSource().sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); - } - return 0; - }); - - + allow.executes(context -> allow(context, admin, BoolArgumentType.getBool(context, "allow"))); + permNode.executes(context -> query(context, admin)); all.then(allstate); permNode.then(allow); player.then(permNode); player.then(all); - player.then(remove); claim.then(player); exception.then(claim); command.then(exception); } + private static int allow(CommandContext context, boolean admin, boolean allow) throws CommandSyntaxException { + ServerCommandSource source = context.getSource(); + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + boolean permission = BoolArgumentType.getBool(context, "allow"); + Claim.Permission value = Claim.Permission.byId(StringArgumentType.getString(context, "permission")); + if(value == null) { + source.sendError(Messages.INVALID_PERMISSION); + return 0; + } + modifyException(claim1, player1, value, permission); + source.sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " now" : " no longer") + " has the permission " + value).formatted(Formatting.YELLOW), false); + return 1; + } + return 0; + } + + private static int query(CommandContext context, boolean admin) throws CommandSyntaxException { + ServerCommandSource source = context.getSource(); + Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); + if (verifyPermission(claim1, Claim.Permission.MODIFY_PERMISSIONS, context, admin)) { + ServerPlayerEntity player1 = EntityArgumentType.getPlayer(context, "player"); + Claim.Permission value = Claim.Permission.byId(StringArgumentType.getString(context, "permission")); + if(value == null) { + source.sendError(Messages.INVALID_PERMISSION); + return 0; + } + boolean permission = hasPermission(claim1, player1, value); + source.sendFeedback(new LiteralText(player1.getGameProfile().getName() + (permission ? " has" : " does not have") + " the permission " + value.name).formatted(Formatting.YELLOW), false); + return 1; + } + return 0; + } + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java index 70f9540..f4095e2 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java @@ -6,9 +6,10 @@ import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import io.github.indicode.fabric.itsmine.Claim; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Config; +import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import net.minecraft.server.command.CommandSource; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; @@ -53,7 +54,7 @@ public static RequiredArgumentBuilder getSettings() return argument("setting", word()).suggests(SETTINGS_PROVIDER); } public static RequiredArgumentBuilder getPermissions(){ - return argument("permission", word()).suggests(SETTINGS_PROVIDER); + return argument("permission", word()).suggests(PERMISSIONS_PROVIDER); } public static RequiredArgumentBuilder getMessageEvent(){ @@ -146,10 +147,7 @@ public static CompletableFuture itemsSuggestion(final CommandContex public static final SuggestionProvider SETTINGS_PROVIDER = (source, builder) -> { List strings = new ArrayList<>(); - for (Claim.ClaimSettings.Setting value : Claim.ClaimSettings.Setting.values()) { - strings.add(value.id); - } - for (Claim.Permission value : Claim.Permission.values()) { + for (ClaimSettings.Setting value : ClaimSettings.Setting.values()) { strings.add(value.id); } return CommandSource.suggestMatching(strings, builder); @@ -160,9 +158,6 @@ public static CompletableFuture itemsSuggestion(final CommandContex for (Claim.Permission value : Claim.Permission.values()) { strings.add(value.id); } - for (Claim.Permission value : Claim.Permission.values()) { - strings.add(value.id); - } return CommandSource.suggestMatching(strings, builder); }; From f688b214a99c8881476636a62d5683d5a4c87f0b Mon Sep 17 00:00:00 2001 From: DrexHD Date: Wed, 6 May 2020 21:57:58 +0200 Subject: [PATCH 81/85] Updated to 20w19a Updated to 20w19a Fixed a bug with piercing enchantment --- gradle.properties | 6 +++--- .../java/io/github/indicode/fabric/itsmine/Functions.java | 4 ++-- .../indicode/fabric/itsmine/command/ExpandCommand.java | 2 +- .../indicode/fabric/itsmine/command/RemoveCommand.java | 1 + .../fabric/itsmine/mixin/BlockActionPacketMixin.java | 6 ++---- .../io/github/indicode/fabric/itsmine/mixin/FluidMixin.java | 4 ++-- .../indicode/fabric/itsmine/mixin/ServerWorldMixin.java | 2 +- .../itsmine/mixin/projectile/ProjectileEntityMixin.java | 6 +++--- 8 files changed, 15 insertions(+), 16 deletions(-) diff --git a/gradle.properties b/gradle.properties index 898d632..4102b77 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=20w18a -yarn_mappings=20w18a+build.1 +minecraft_version=20w19a +yarn_mappings=20w19a+build.1 loader_version=0.7.10+build.191 # Mod Properties - mod_version = 1.9.1-20W18A + mod_version = 1.9.2-20W19A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index 9eed74d..b00d9d9 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -15,7 +15,7 @@ import net.minecraft.item.BucketItem; import net.minecraft.item.Item; import net.minecraft.network.Packet; -import net.minecraft.network.packet.s2c.play.BlockActionS2CPacket; +import net.minecraft.network.packet.s2c.play.BlockEventS2CPacket; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; @@ -29,7 +29,7 @@ */ public class Functions { public static void doPistonUpdate(ServerWorld world, Packet packet) { - if (packet instanceof BlockActionS2CPacket) { + if (packet instanceof BlockEventS2CPacket) { BlockActionPacketMixin accessor = (BlockActionPacketMixin) packet; if ((accessor.getBlock() == Blocks.PISTON || accessor.getBlock() == Blocks.PISTON_HEAD || accessor.getBlock() == Blocks.STICKY_PISTON)) { Direction direction = Direction.byId(accessor.getData()); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java index c243c81..4c70e75 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java @@ -141,7 +141,7 @@ public static int expand(Claim claim, int amount, Direction direction, ServerCom return 0; } else { if (!admin && claim.claimBlockOwner != null) ClaimManager.INSTANCE.useClaimBlocks(ownerID, newArea); - source.sendFeedback(new LiteralText("Your claim was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + " blocks " + direction.getName()).formatted(Formatting.GREEN), false); + source.sendFeedback(new LiteralText("Your claim was " + (amount > 0 ? "expanded" : "shrunk") + " by " + (amount < 0 ? -amount : amount) + (amount == 1 ? " block " : " blocks ") + direction.getName()).formatted(Formatting.GREEN), false); blocksLeft(source); undoExpand(claim, direction, amount); ShowerUtil.update(claim, source.getWorld(), true); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java index b256d3a..19ee119 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java @@ -83,6 +83,7 @@ public static int delete(ServerCommandSource source, Claim claim, boolean admin) source.getWorld().getPlayers().forEach(playerEntity -> { if (((ClaimShower)playerEntity).getShownClaim() != null && ((ClaimShower)playerEntity).getShownClaim().name.equals(claim.name)) silentHideShow(playerEntity, claim, true, true, ((ClaimShower)playerEntity).getMode()); }); + source.sendFeedback(new LiteralText("Deleted the claim \"" + claim.name + "\"").formatted(Formatting.GREEN), !claim.permissionManager.hasPermission(source.getPlayer().getGameProfile().getId(), Claim.Permission.REMOVE_CLAIM)); return 0; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BlockActionPacketMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BlockActionPacketMixin.java index e19fcd3..7c78304 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BlockActionPacketMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BlockActionPacketMixin.java @@ -1,9 +1,7 @@ package io.github.indicode.fabric.itsmine.mixin; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.minecraft.block.Block; -import net.minecraft.network.packet.s2c.play.BlockActionS2CPacket; +import net.minecraft.network.packet.s2c.play.BlockEventS2CPacket; import net.minecraft.util.math.BlockPos; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; @@ -11,7 +9,7 @@ /** * @author Indigo Amann */ -@Mixin(BlockActionS2CPacket.class) +@Mixin(BlockEventS2CPacket.class) public interface BlockActionPacketMixin { @Accessor("pos") BlockPos getPos(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java index 5698efa..e435e5f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java @@ -4,7 +4,7 @@ import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import net.minecraft.block.BlockState; -import net.minecraft.fluid.BaseFluid; +import net.minecraft.fluid.FlowableFluid; import net.minecraft.fluid.FluidState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -17,7 +17,7 @@ /** * @author Indigo Amann */ -@Mixin(BaseFluid.class) +@Mixin(FlowableFluid.class) public class FluidMixin { @Inject(method = "flow", at = @At("HEAD"), cancellable = true) private void dontFlow(IWorld world, BlockPos newPos, BlockState blockState_1, Direction direction, FluidState fluidState_1, CallbackInfo ci) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java index 6e9c259..bc99532 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java @@ -40,7 +40,7 @@ public abstract class ServerWorldMixin implements MonitorableWorld { @Shadow public abstract List getPlayers(); - @Redirect(method = "sendBlockActions", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;sendToAround(Lnet/minecraft/entity/player/PlayerEntity;DDDDLnet/minecraft/world/dimension/DimensionType;Lnet/minecraft/network/Packet;)V")) + @Redirect(method = "processSyncedBlockEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;sendToAround(Lnet/minecraft/entity/player/PlayerEntity;DDDDLnet/minecraft/world/dimension/DimensionType;Lnet/minecraft/network/Packet;)V")) private void sendPistonUpdate(PlayerManager manager, PlayerEntity playerEntity_1, double double_1, double double_2, double double_3, double double_4, DimensionType dimensionType_1, Packet packet_1) { manager.sendToAround(playerEntity_1, double_1, double_2, double_3, double_4, dimensionType_1, packet_1); Functions.doPistonUpdate((ServerWorld) (Object)this, packet_1); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java index 857b044..a16494f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java @@ -31,11 +31,11 @@ private void imInvincible(ProjectileEntity projectileEntity, EntityHitResult ent } else { if (this.getOwner() instanceof PlayerEntity) { this.getOwner().sendSystemMessage(Messages.MSG_DAMAGE_ENTITY); + if(projectileEntity.getType() == EntityType.ARROW){ + projectileEntity.kill(); + } } } - if(projectileEntity.getType() == EntityType.ARROW){ - projectileEntity.kill(); - } } // public boolean imInvincible(Entity entity, DamageSource damageSource_1, float float_1) { From cfa650d7342314e653af4aec4a07910cb55a7d43 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Fri, 8 May 2020 11:49:39 +0200 Subject: [PATCH 82/85] Config --- build.gradle | 3 + gradle.properties | 17 +++--- .../indicode/fabric/itsmine/ClaimManager.java | 2 +- .../fabric/itsmine/ClaimPlayerEntity.java | 9 +++ .../indicode/fabric/itsmine/Config.java | 6 +- .../indicode/fabric/itsmine/ItsMine.java | 44 ++++++++------ .../fabric/itsmine/ItsMineConfig.java | 60 +++++++++++++++++++ .../indicode/fabric/itsmine/Messages.java | 25 ++++---- .../indicode/fabric/itsmine/claim/Claim.java | 6 +- .../itsmine/command/CommandManager.java | 4 +- .../fabric/itsmine/command/CreateCommand.java | 6 +- .../fabric/itsmine/command/DebugCommand.java | 28 +++++++++ ...SettingsCommand.java => FlagsCommand.java} | 6 +- .../fabric/itsmine/command/HelpCommand.java | 2 +- .../itsmine/command/RentableCommand.java | 5 +- .../fabric/itsmine/command/ShowCommand.java | 7 ++- .../itsmine/command/admin/AdminCommand.java | 6 +- .../itsmine/command/admin/ReloadCommand.java | 34 +++++++++++ .../command/subzone/CreateCommand.java | 9 +-- .../command/subzone/SubzoneCommand.java | 2 +- .../fabric/itsmine/config/Config.java | 49 +++++++++++++++ .../sections/DefaultClaimBlockSection.java | 16 +++++ .../config/sections/MessageSection.java | 52 ++++++++++++++++ .../itsmine/config/sections/RentSection.java | 12 ++++ .../itsmine/mixin/AnimalEntityMixin.java | 7 ++- .../fabric/itsmine/mixin/EntityMixin.java | 5 +- .../mixin/LevelStorageSessionMixin.java | 1 + .../itsmine/mixin/PlayerEntityMixin.java | 33 +++++++++- .../ServerPlayerInteractionManagerMixin.java | 7 ++- .../itsmine/mixin/ServerWorldMixin.java | 4 ++ .../itsmine/mixin/StickClaimItemMixin.java | 9 +-- .../fabric/itsmine/util/ArgumentUtil.java | 10 +++- .../fabric/itsmine/{ => util}/ChatColor.java | 21 ++++++- .../fabric/itsmine/util/ClaimUtil.java | 4 +- .../fabric/itsmine/util/MessageUtil.java | 20 +++++-- .../fabric/itsmine/util/Messenger.java | 12 ++++ .../fabric/itsmine/util/PermissionUtil.java | 4 +- 37 files changed, 455 insertions(+), 92 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/ClaimPlayerEntity.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/ItsMineConfig.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/DebugCommand.java rename src/main/java/io/github/indicode/fabric/itsmine/command/{SettingsCommand.java => FlagsCommand.java} (95%) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/command/admin/ReloadCommand.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/config/Config.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/config/sections/DefaultClaimBlockSection.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/config/sections/MessageSection.java create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/config/sections/RentSection.java rename src/main/java/io/github/indicode/fabric/itsmine/{ => util}/ChatColor.java (91%) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/util/Messenger.java diff --git a/build.gradle b/build.gradle index 01d8e83..4365cbb 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ minecraft { } repositories { mavenLocal() + maven { url 'https://repo.spongepowered.org/maven'} maven { url 'https://jitpack.io' } maven { url 'http://server.bbkr.space:8081/artifactory/libs-release' } } @@ -23,6 +24,8 @@ dependencies { mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" modCompile "net.fabricmc:fabric-loader:${project.loader_version}" + compile "org.spongepowered:configurate-hocon:${project.configurate_version}" + //modImplementation "com.github.giantnuker:TinyConfig:${project.tiny_config_version}" //modImplementation /*"io.github.indicode.fabric:thimble-permissions:0.0.9"//*/"com.github.giantnuker:Thimble-Permissions:${project.thimble_permissions_version}" //modImplementation "com.github.giantnuker:OfflineInfo:${project.offline_info_version}" diff --git a/gradle.properties b/gradle.properties index 4102b77..ae6d0a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,21 +2,20 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties - # check these on https://fabricmc.net/use minecraft_version=20w19a yarn_mappings=20w19a+build.1 loader_version=0.7.10+build.191 # Mod Properties - mod_version = 1.9.2-20W19A - maven_group = io.github.indicode.fabric.itsmine - archives_base_name = itsmine +mod_version = 1.9.2-20W19A +maven_group = io.github.indicode.fabric.itsmine +archives_base_name = itsmine + + +configurate_version = 3.6.1 + + -# Dependencies - # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api - #fabric_version=0.3.2+build.218-1.14 -#26b2bbfb06 thimble_permissions_version=0.2.4-20W17A tiny_config_version = 1.1.2 luckperms_version=5.0 -#offline_info_version=1a3a7fc98b diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java index 8d13c2d..0fc27be 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java @@ -24,7 +24,7 @@ public class ClaimManager { public List flyers = new ArrayList<>(); public MinecraftServer server; public int getClaimBlocks(UUID id) { - return blocksLeft.getOrDefault(id, Config.claims2d ? Config.baseClaimBlocks2d : Config.baseClaimBlocks3d); + return blocksLeft.getOrDefault(id, ItsMineConfig.main().claims2d ? ItsMineConfig.main().claimBlock().default2D : ItsMineConfig.main().claimBlock().default3D); } public boolean useClaimBlocks(UUID player, int amount) { int blocks = getClaimBlocks(player) - amount; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimPlayerEntity.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimPlayerEntity.java new file mode 100644 index 0000000..7ceb19d --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimPlayerEntity.java @@ -0,0 +1,9 @@ +package io.github.indicode.fabric.itsmine; + +public interface ClaimPlayerEntity { + void tickMessageCooldown(); + int getMessageCooldown(); + boolean shouldMessage(); + void setMessageCooldown(); + void setMessageCooldown(int cooldown); +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/Config.java index aa9b87d..b8f665b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Config.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Config.java @@ -1,10 +1,13 @@ +/* package io.github.indicode.fabric.itsmine; import io.github.indicode.fabric.tinyconfig.ModConfig; +*/ /** * @author Indigo Amann - */ + *//* + public class Config { public static int baseClaimBlocks3d = 15625; public static int baseClaimBlocks2d = 2500; @@ -55,3 +58,4 @@ static void sync() { } } +*/ diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java index ac74472..d4e4ac4 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java @@ -1,8 +1,11 @@ package io.github.indicode.fabric.itsmine; +import io.github.indicode.fabric.itsmine.config.Config; import io.github.indicode.fabric.itsmine.util.PermissionUtil; import net.fabricmc.api.ModInitializer; +import java.nio.file.Path; + /** * @author Indigo Amann */ @@ -11,30 +14,37 @@ public class ItsMine implements ModInitializer { @Override public void onInitialize() { - Config.sync(); + new ItsMineConfig(); permissionUtil = new PermissionUtil(); + //TODO: Enable when developing //SharedConstants.isDevelopment = true; } + public static PermissionUtil permissions() { return permissionUtil; } - public static String blocksToAreaString3d(int blocks) { - int base = (int) Math.floor(Math.cbrt(blocks)); - int additionalBlocks = blocks - (int) Math.pow(base, 3); - int extraRows = (int) Math.floor(Math.cbrt(Math.floor((float)additionalBlocks / base))); - int leftoverBlocks = additionalBlocks % base; - return (base + extraRows) + "x" + base + "x" + base + "(+" + leftoverBlocks + ")"; - } - public static String blocksToAreaString2d(int blocks) { - int base = (int) Math.floor(Math.sqrt(blocks)); - int additionalBlocks = blocks - (int) Math.pow(base, 2); - int extraRows = (int) Math.floor((float)additionalBlocks / base); - int leftoverBlocks = additionalBlocks % base; - return (base + extraRows) + "x" + base + "(+" + leftoverBlocks + ")"; - } - public static String blocksToAreaString(int blocks) { - return Config.claims2d ? blocksToAreaString2d(blocks) : blocksToAreaString3d(blocks); + + public static String getDirectory(){ + return System.getProperty("user.dir"); } + +// public static String blocksToAreaString3d(int blocks) { +// int base = (int) Math.floor(Math.cbrt(blocks)); +// int additionalBlocks = blocks - (int) Math.pow(base, 3); +// int extraRows = (int) Math.floor(Math.cbrt(Math.floor((float)additionalBlocks / base))); +// int leftoverBlocks = additionalBlocks % base; +// return (base + extraRows) + "x" + base + "x" + base + "(+" + leftoverBlocks + ")"; +// } +// public static String blocksToAreaString2d(int blocks) { +// int base = (int) Math.floor(Math.sqrt(blocks)); +// int additionalBlocks = blocks - (int) Math.pow(base, 2); +// int extraRows = (int) Math.floor((float)additionalBlocks / base); +// int leftoverBlocks = additionalBlocks % base; +// return (base + extraRows) + "x" + base + "(+" + leftoverBlocks + ")"; +// } +// public String blocksToAreaString(int blocks) { +// return config.claims2d ? blocksToAreaString2d(blocks) : blocksToAreaString3d(blocks); +// } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ItsMineConfig.java b/src/main/java/io/github/indicode/fabric/itsmine/ItsMineConfig.java new file mode 100644 index 0000000..5c8ad8d --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/ItsMineConfig.java @@ -0,0 +1,60 @@ +package io.github.indicode.fabric.itsmine; + +import com.google.common.reflect.TypeToken; +import io.github.indicode.fabric.itsmine.config.Config; +import ninja.leaping.configurate.ConfigurationNode; +import ninja.leaping.configurate.ConfigurationOptions; +import ninja.leaping.configurate.commented.CommentedConfigurationNode; +import ninja.leaping.configurate.hocon.HoconConfigurationLoader; +import ninja.leaping.configurate.loader.ConfigurationLoader; +import ninja.leaping.configurate.objectmapping.DefaultObjectMapperFactory; +import ninja.leaping.configurate.objectmapping.ObjectMappingException; + +import java.io.File; +import java.io.IOException; + +public class ItsMineConfig { + private static Config config; + private static ConfigurationNode mainNode; + + public ItsMineConfig() { + try { + File CONFIG_FILE = new File(ItsMine.getDirectory() + "/config/itsmine.hocon"); + + ConfigurationLoader mainLoader = HoconConfigurationLoader.builder() + .setFile(CONFIG_FILE).build(); + + + CONFIG_FILE.createNewFile(); + + mainNode = mainLoader.load(configurationOptions()); + + config = mainNode.getValue(TypeToken.of(Config.class), new Config()); + + mainLoader.save(mainNode); + } catch (IOException | ObjectMappingException e) { + System.out.println("Exception loading config file"); + e.printStackTrace(); + } + } + + public static Config main() { + return config; + } + + public static ConfigurationNode getMainNode() { + return mainNode; + } + + + public static void reload() { + new ItsMineConfig(); + } + + public static ConfigurationOptions configurationOptions() { + return ConfigurationOptions.defaults() + .setHeader(Config.HEADER) + .setObjectMapperFactory(DefaultObjectMapperFactory.getInstance()) + .setShouldCopyDefaults(true); + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 8e49c02..6e5ec09 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -2,13 +2,14 @@ import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.util.ChatColor; import net.minecraft.text.LiteralText; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; public class Messages { - public static final MutableText PREFIX = new LiteralText(ChatColor.translate(Config.prefix)); + public static final MutableText PREFIX = new LiteralText(ChatColor.translate(ItsMineConfig.main().prefix)); public static final Text INVALID_CLAIM = PREFIX.copy().append(new LiteralText("Can not find a claim with that name or a claim at your position").formatted(Formatting.RED)); @@ -16,7 +17,7 @@ public class Messages { public static final Text INVALID_PERMISSION = PREFIX.copy().append(new LiteralText("Invalid Claim Permission!")); - public static final Text NO_PERMISSION = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_no_perm))); + public static final Text NO_PERMISSION = PREFIX.copy().append(new LiteralText(ChatColor.translate(ItsMineConfig.main().message().noPermission))); public static final Text INVALID_MESSAGE_EVENT = PREFIX.copy().append(new LiteralText("Invalid Message Event!")); @@ -24,25 +25,25 @@ public class Messages { public static final Text TOO_MANY_SELECTIONS = PREFIX.copy().append(new LiteralText("Only one selection is allowed!")); - public static final Text MSG_PLACE_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_place_block)).formatted(Formatting.RED)); + public static final Text MSG_PLACE_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(ItsMineConfig.main().message().placeBlock))); - public static final Text MSG_BREAK_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_break_block)).formatted(Formatting.RED)); + public static final Text MSG_BREAK_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(ItsMineConfig.main().message().breakBlock)).formatted(Formatting.RED)); - public static final Text MSG_CANT_ENTER = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_enter)).formatted(Formatting.RED)); + public static final Text MSG_CANT_ENTER = PREFIX.copy().append(new LiteralText(ChatColor.translate(ItsMineConfig.main().message().cantEnter)).formatted(Formatting.RED)); - public static final Text MSG_INTERACT_ENTITY = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_interact_entity)).formatted(Formatting.RED)); + public static final Text MSG_INTERACT_ENTITY = PREFIX.copy().append(new LiteralText(ChatColor.translate(ItsMineConfig.main().message().interactEntity)).formatted(Formatting.RED)); - public static final Text MSG_INTERACT_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_interact_block)).formatted(Formatting.RED)); + public static final Text MSG_INTERACT_BLOCK = PREFIX.copy().append(new LiteralText(ChatColor.translate(ItsMineConfig.main().message().interactBlock)).formatted(Formatting.RED)); - public static final Text MSG_OPEN_CONTAINER = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_open_container)).formatted(Formatting.RED)); + public static final Text MSG_OPEN_CONTAINER = PREFIX.copy().append(new LiteralText(ChatColor.translate(ItsMineConfig.main().message().openContainer)).formatted(Formatting.RED)); - public static final Text MSG_DAMAGE_ENTITY = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_attack_entity)).formatted(Formatting.RED)); + public static final Text MSG_DAMAGE_ENTITY = PREFIX.copy().append(new LiteralText(ChatColor.translate(ItsMineConfig.main().message().attackEntity)).formatted(Formatting.RED)); - public static final Text MSG_CANT_USE = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_use)).formatted(Formatting.RED)); + public static final Text MSG_CANT_USE = PREFIX.copy().append(new LiteralText(ChatColor.translate(ItsMineConfig.main().message().cantUse)).formatted(Formatting.RED)); - public static final Text MSG_LONG_NAME = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_long_name)).formatted(Formatting.RED)); + public static final Text MSG_LONG_NAME = PREFIX.copy().append(new LiteralText(ChatColor.translate(ItsMineConfig.main().message().longName)).formatted(Formatting.RED)); - public static final Text MSG_CANT_DO = PREFIX.copy().append(new LiteralText(ChatColor.translate(Config.msg_cant_do)).formatted(Formatting.RED)); + public static final Text MSG_CANT_DO = PREFIX.copy().append(new LiteralText(ChatColor.translate(ItsMineConfig.main().message().cantDo)).formatted(Formatting.RED)); public static final Text[] GET_STARTED = new MutableText[]{ header("How to Claim (Basics)") diff --git a/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java index e4174c5..037f8b2 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java @@ -252,7 +252,7 @@ public void shrink(Direction direction, int distance) { shrink(new BlockPos(direction.getOffsetX() * distance, direction.getOffsetY() * distance, direction.getOffsetZ() * distance)); } public int getArea() { - return getSize().getX() * (Config.claims2d ? 1 : getSize().getY()) * getSize().getZ(); + return getSize().getX() * (ItsMineConfig.main().claims2d ? 1 : getSize().getY()) * getSize().getZ(); } @@ -738,8 +738,8 @@ public CompoundTag toNBT() { } } public enum Event { - ENTER_CLAIM("enter", Config.msg_enter_default), - LEAVE_CLAIM("leave", Config.msg_leave_default); + ENTER_CLAIM("enter", ItsMineConfig.main().message().enterDefault), + LEAVE_CLAIM("leave", ItsMineConfig.main().message().leaveDefault); public String id; String defaultValue; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java index bfae8fc..cc53305 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java @@ -2,6 +2,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import io.github.indicode.fabric.itsmine.ItsMineConfig; import io.github.indicode.fabric.itsmine.command.admin.AdminCommand; import io.github.indicode.fabric.itsmine.command.subzone.SubzoneCommand; import net.minecraft.server.command.ServerCommandSource; @@ -29,6 +30,7 @@ public static void register(LiteralArgumentBuilder command, BlockCommand.register(command); CreateCommand.register(command); ClaimsCommand.register(command, dispatcher); + DebugCommand.register(command); ExpandCommand.register(command, false); FlyCommand.register(command); HelpCommand.register(command); @@ -41,7 +43,7 @@ public static void register(LiteralArgumentBuilder command, RentableCommand.register(command, getClaims()); RentCommand.register(command, getClaims()); RevenueCommand.register(command, getClaims()); - SettingsCommand.register(command, false, getClaims()); + FlagsCommand.register(command, false, getClaims()); ShowCommand.register(command); StickCommand.register(command); SubzoneCommand.register(command, dispatcher, false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java index d4d555c..531e753 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java @@ -77,7 +77,7 @@ public static int createClaim(String name, ServerCommandSource owner, BlockPos p x = posA.getX(); mx = posB.getX(); } - if (!Config.claims2d) { + if (!ItsMineConfig.main().claims2d) { if (posA.getY() > posB.getY()) { y = posB.getY(); my = posA.getY(); @@ -96,8 +96,8 @@ public static int createClaim(String name, ServerCommandSource owner, BlockPos p BlockPos min = new BlockPos(x, y, z); BlockPos max = new BlockPos(mx, my, mz); BlockPos sub = max.subtract(min); - sub = sub.add(1, Config.claims2d ? 0 : 1,1); - int subInt = sub.getX() * (Config.claims2d ? 1 : sub.getY()) * sub.getZ(); + sub = sub.add(1, ItsMineConfig.main().claims2d ? 0 : 1,1); + int subInt = sub.getX() * (ItsMineConfig.main().claims2d ? 1 : sub.getY()) * sub.getZ(); Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos(), false); if (cOwnerName != null) claim.customOwnerName = cOwnerName; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/DebugCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/DebugCommand.java new file mode 100644 index 0000000..5b64e8a --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/DebugCommand.java @@ -0,0 +1,28 @@ +package io.github.indicode.fabric.itsmine.command; + +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.builder.RequiredArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.server.command.ServerCommandSource; + +import static io.github.indicode.fabric.itsmine.util.ChatColor.translateStringToText; + +public class DebugCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder debug = LiteralArgumentBuilder.literal("debug"); + RequiredArgumentBuilder string = RequiredArgumentBuilder.argument("string", StringArgumentType.greedyString()); + string.executes(DebugCommand::execute); + debug.then(string); + command.then(debug); + + } + + private static int execute(CommandContext context) throws CommandSyntaxException { + context.getSource().getPlayer().sendSystemMessage(translateStringToText('&', StringArgumentType.getString(context, "string"))); + return 1; + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/FlagsCommand.java similarity index 95% rename from src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java rename to src/main/java/io/github/indicode/fabric/itsmine/command/FlagsCommand.java index 2201a30..1c3790b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/SettingsCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/FlagsCommand.java @@ -16,13 +16,13 @@ import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; -public class SettingsCommand { +public class FlagsCommand { public static void register(LiteralArgumentBuilder command, boolean admin, RequiredArgumentBuilder claim) { - LiteralArgumentBuilder settings = literal("settings"); + LiteralArgumentBuilder settings = literal("flags"); if (!admin) { - settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); + settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Flags", "/claim help perms_and_settings %page%")); claim.executes((context) -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java index 1073dfb..97c223d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/HelpCommand.java @@ -3,7 +3,7 @@ import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import io.github.indicode.fabric.itsmine.ChatColor; +import io.github.indicode.fabric.itsmine.util.ChatColor; import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.Messages; import net.minecraft.server.command.ServerCommandSource; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java index ad78df0..3f5b2b6 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RentableCommand.java @@ -4,9 +4,10 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.ItsMineConfig; import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Config; import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import io.github.indicode.fabric.itsmine.util.TimeUtil; import net.minecraft.command.arguments.ItemStackArgument; @@ -66,7 +67,7 @@ private static int makeRentable(ServerCommandSource source, Claim claim, ItemSta item.setCount(amount); rent.setCurrency(item); rent.setRentAbleTime(rentTime); - if(maxrentTime > Config.rent_maxseconds) maxrentTime = Config.rent_maxseconds; + if(maxrentTime > ItsMineConfig.main().rent().maxRentTime) maxrentTime = ItsMineConfig.main().rent().maxRentTime; rent.setMaxrentAbleTime(maxrentTime); source.sendFeedback(new LiteralText("Claim " + claim.name + " can now be rented for " + amount + " " + item.getName().asString() + " every " + TimeUtil.convertSecondsToString(rentTime, '2', 'a')).formatted(Formatting.GREEN), true); return 1; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java index 1103930..71326f1 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java @@ -4,10 +4,11 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.ClaimShower; -import io.github.indicode.fabric.itsmine.Config; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.ItsMineConfig; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import io.github.indicode.fabric.itsmine.util.ClaimUtil; import net.minecraft.server.command.ServerCommandSource; @@ -53,7 +54,7 @@ public static int executeShowClaim(ServerCommandSource source, Claim claim, bool public static int executeShowClaim(ServerCommandSource source, Claim claim, boolean reset, String mode) throws CommandSyntaxException { ServerPlayerEntity player = source.getPlayer(); - if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!Config.claims2d &&((ClaimShower)player).getShownClaim() != claim)) executeShowClaim(source, ((ClaimShower)player).getShownClaim(), true, ((ClaimShower)player).getMode()); + if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!ItsMineConfig.main().claims2d &&((ClaimShower)player).getShownClaim() != claim)) executeShowClaim(source, ((ClaimShower)player).getShownClaim(), true, ((ClaimShower)player).getMode()); if (reset && ((ClaimShower)player).getShownClaim() != null) claim = ((ClaimShower)player).getShownClaim(); if (claim != null) { if (!claim.dimension.equals(source.getWorld().getDimension().getType())) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java index be730f4..bdb4f59 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/AdminCommand.java @@ -3,10 +3,9 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import io.github.indicode.fabric.itsmine.ItsMine; -import io.github.indicode.fabric.itsmine.command.ClaimsCommand; import io.github.indicode.fabric.itsmine.command.MessageCommand; import io.github.indicode.fabric.itsmine.command.PermissionCommand; -import io.github.indicode.fabric.itsmine.command.SettingsCommand; +import io.github.indicode.fabric.itsmine.command.FlagsCommand; import io.github.indicode.fabric.itsmine.command.subzone.SubzoneCommand; import net.minecraft.server.command.ServerCommandSource; @@ -34,9 +33,10 @@ private static void registerAdmin(LiteralArgumentBuilder ad MessageCommand.register(admin, true, getClaims()); OwnerCommand.register(admin); PermissionCommand.register(admin, true, getClaims()); + ReloadCommand.register(admin); RemoveCommand.register(admin); RenameCommand.register(admin); - SettingsCommand.register(admin, true, getClaims()); + FlagsCommand.register(admin, true, getClaims()); SubzoneCommand.register(admin, dispatcher, true); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ReloadCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ReloadCommand.java new file mode 100644 index 0000000..de7dff0 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ReloadCommand.java @@ -0,0 +1,34 @@ +package io.github.indicode.fabric.itsmine.command.admin; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.ItsMineConfig; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.util.Formatting; +import org.apache.commons.lang3.time.StopWatch; + +import java.text.DecimalFormat; +import java.util.concurrent.TimeUnit; + +public class ReloadCommand { + + public static void register(LiteralArgumentBuilder command) { + LiteralArgumentBuilder reload = LiteralArgumentBuilder.literal("reload"); + reload.executes(ReloadCommand::execute); + command.then(reload); + } + + + public static int execute(CommandContext context) throws CommandSyntaxException { + StopWatch watch = new StopWatch(); + watch.start(); + ItsMineConfig.reload(); + watch.stop(); + String timeElapsed = new DecimalFormat("##.##").format(watch.getTime(TimeUnit.MICROSECONDS)); + context.getSource().getPlayer().sendSystemMessage(new LiteralText("Reloaded! Took " + timeElapsed + "μs").formatted(Formatting.YELLOW)); + return 1; + } +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java index 6b76924..b6b91f4 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java @@ -5,10 +5,11 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; -import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Config; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.ItsMineConfig; import io.github.indicode.fabric.itsmine.Messages; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; @@ -105,7 +106,7 @@ private static Claim createSubzone(ServerCommandSource source, String name, Bloc x = posA.getX(); mx = posB.getX(); } - if (!Config.claims2d) { + if (!ItsMineConfig.main().claims2d) { if (posA.getY() > posB.getY()) { y = posB.getY(); my = posA.getY(); @@ -124,7 +125,7 @@ private static Claim createSubzone(ServerCommandSource source, String name, Bloc BlockPos min = new BlockPos(x, y, z); BlockPos max = new BlockPos(mx, my, mz); BlockPos sub = max.subtract(min); - sub = sub.add(1, Config.claims2d ? 0 : 1,1); + sub = sub.add(1, ItsMineConfig.main().claims2d ? 0 : 1,1); return new Claim(name, admin ? null : ownerID, min, max, source.getWorld().getDimension().getType(), source.getPlayer().getBlockPos(), true); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java index 922bb0b..c3d3569 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/SubzoneCommand.java @@ -28,7 +28,7 @@ public static void registerSubzone(LiteralArgumentBuilder c RentableCommand.register(command, getSubzones()); RentCommand.register(command, getSubzones()); RevenueCommand.register(command, getSubzones()); - SettingsCommand.register(command, admin, getSubzones()); + FlagsCommand.register(command, admin, getSubzones()); TrustCommand.register(command, dispatcher, getSubzones(), admin); TrustedCommand.register(command); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/config/Config.java b/src/main/java/io/github/indicode/fabric/itsmine/config/Config.java new file mode 100644 index 0000000..06abccc --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/config/Config.java @@ -0,0 +1,49 @@ +package io.github.indicode.fabric.itsmine.config; + +import io.github.indicode.fabric.itsmine.config.sections.DefaultClaimBlockSection; +import io.github.indicode.fabric.itsmine.config.sections.MessageSection; +import io.github.indicode.fabric.itsmine.config.sections.RentSection; +import ninja.leaping.configurate.objectmapping.Setting; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; + + +@ConfigSerializable +public class Config { + + public static final String HEADER = "ItsMine! Main Configuration File"; + + @Setting(value = "debug") + public boolean debug = false; + + @Setting(value = "prefix") + public String prefix = "&f[&aClaims&f] "; + + @Setting(value = "permissionManager", comment = "Values: thimble, luckperms, vanilla") + public String permissionManager = "luckperms"; + + @Setting(value = "claims2d", comment = "If this is enabled, claims reach from 0 to 256 (claim blocks ignore the y-axis)") + public boolean claims2d = true; + + @Setting(value = "defaultClaimBlocks", comment = "Adjust the amount of claimblocks players get upon joining") + public DefaultClaimBlockSection defaultClaimBlockSection = new DefaultClaimBlockSection(); + + @Setting(value = "messages") + private MessageSection messageSection = new MessageSection(); + + @Setting(value = "rent") + private RentSection rentSection = new RentSection(); + + + public MessageSection message(){ + return messageSection; + } + + public DefaultClaimBlockSection claimBlock(){ + return defaultClaimBlockSection; + } + + public RentSection rent(){ + return rentSection; + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/config/sections/DefaultClaimBlockSection.java b/src/main/java/io/github/indicode/fabric/itsmine/config/sections/DefaultClaimBlockSection.java new file mode 100644 index 0000000..4ded101 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/config/sections/DefaultClaimBlockSection.java @@ -0,0 +1,16 @@ +package io.github.indicode.fabric.itsmine.config.sections; + +import ninja.leaping.configurate.objectmapping.Setting; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; + +@ConfigSerializable +public class DefaultClaimBlockSection { + + @Setting(value = "default2D", comment = "2D base claim blocks") + public int default2D = 15625; + + @Setting(value = "default3D", comment = "3D base claim blocks") + public int default3D = 2500; + + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/config/sections/MessageSection.java b/src/main/java/io/github/indicode/fabric/itsmine/config/sections/MessageSection.java new file mode 100644 index 0000000..9852017 --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/config/sections/MessageSection.java @@ -0,0 +1,52 @@ +package io.github.indicode.fabric.itsmine.config.sections; + +import ninja.leaping.configurate.objectmapping.Setting; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; + +@ConfigSerializable +public class MessageSection { + @Setting(value = "messageCooldown") + public int messageCooldown = 20; + + @Setting(value = "eventStayTicks", comment = "Sets how many ticks an event message will stay on action bar, Default: -1") + public int eventStayTicks = -1; + + @Setting(value = "noPermission") + public String noPermission = "&cSorry but you don't have permission to do that"; + + @Setting(value = "interactEntity") + public String interactEntity = "&cSorry but you can't interact with Entities here!"; + + @Setting(value = "interactBlock") + public String interactBlock = "&cSorry but you can't interact with Blocks here!"; + + @Setting(value = "openContainer") + public String openContainer = "&cSorry but you can't open containers here!"; + + @Setting(value = "breakBlock") + public String breakBlock = "&cSorry but you can't Break Blocks here!"; + + @Setting(value = "placeBlock") + public String placeBlock = "&cSorry but you can't Place Blocks here!"; + + @Setting(value = "attackEntity") + public String attackEntity = "&cSorry but you can't Attack Entities here!"; + + @Setting(value = "enterDefault", comment = "Variables: %claim% %player%") + public String enterDefault = "&eNow entering claim &6%claim%"; + + @Setting(value = "leaveDefault", comment = "Variables: %claim% %player%") + public String leaveDefault = "&eNow leaving claim &6%claim%"; + + @Setting(value = "cantEnter") + public String cantEnter = "&cSorry but you don't have permission to enter this claim!"; + + @Setting(value = "cantUse") + public String cantUse = "&cSorry but you can't to use that here!"; + + @Setting(value = "longName") + public String longName = "&cThe name of the claim must be less than 30 characters!"; + + @Setting(value = "cantDo") + public String cantDo ="&cSorry but you can't do that!"; +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/config/sections/RentSection.java b/src/main/java/io/github/indicode/fabric/itsmine/config/sections/RentSection.java new file mode 100644 index 0000000..8edb63f --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/config/sections/RentSection.java @@ -0,0 +1,12 @@ +package io.github.indicode.fabric.itsmine.config.sections; + +import ninja.leaping.configurate.objectmapping.Setting; +import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; + +@ConfigSerializable +public class RentSection { + + @Setting(value = "maxRentTime", comment = "Default: 7776000 (90d)") + public int maxRentTime = 7776000; + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java index f2e3eea..81dc142 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java @@ -1,9 +1,10 @@ package io.github.indicode.fabric.itsmine.mixin; import blue.endless.jankson.annotation.Nullable; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.ItsMineConfig; import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Config; import io.github.indicode.fabric.itsmine.util.ClaimUtil; import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.network.packet.s2c.play.TitleS2CPacket; @@ -33,10 +34,10 @@ private void canBreed(AnimalEntity other, CallbackInfoReturnable cir){ if(claim.isChild){ claim = ClaimUtil.getParentClaim(claim); } - if(claim.getEntities(other.getEntityWorld().getServer().getWorld(other.getEntityWorld().getDimension().getType())) > Config.claim_max_entities_passive){ + if(claim.getEntities(other.getEntityWorld().getServer().getWorld(other.getEntityWorld().getDimension().getType())) > 100){ ServerPlayerEntity player = this.getLovingPlayer(); if(player != null){ - player.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText("You reached the passive entity limit in your claim!").formatted(Formatting.RED), -1, Config.event_msg_stay_ticks, -1)); + player.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText("You reached the passive entity limit in your claim!").formatted(Formatting.RED), -1, ItsMineConfig.main().message().eventStayTicks, -1)); } this.resetLoveTicks(); cir.setReturnValue(false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index 62b1f27..caefebf 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -3,6 +3,7 @@ import io.github.indicode.fabric.itsmine.*; import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.util.ChatColor; import io.github.indicode.fabric.itsmine.util.ClaimUtil; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; @@ -56,7 +57,7 @@ else if (claim != null) message = getFormattedEventMessage(player, claim, true); if (message != null) - serverPlayerEntity.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText(ChatColor.translate(message)), -1, Config.event_msg_stay_ticks, -1)); + serverPlayerEntity.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText(ChatColor.translate(message)), -1, ItsMineConfig.main().message().eventStayTicks, -1)); if (claim != null && claim.settings.getSetting(ClaimSettings.Setting.ENTER_SOUND)) { serverPlayerEntity.networkHandler.sendPacket(new PlaySoundIdS2CPacket(Registry.SOUND_EVENT.getId(SoundEvents.BLOCK_CONDUIT_ACTIVATE), SoundCategory.MASTER, this.getPos(), 2, 1.2F)); @@ -71,7 +72,7 @@ private String getFormattedEventMessage(PlayerEntity player, Claim claim, boolea return ""; String str = enter ? claim.enterMessage : claim.leaveMessage; - return ChatColor.translate(str == null ? (enter ? Config.msg_enter_default : Config.msg_leave_default) : str).replace("%claim%", claim.name) + return ChatColor.translate(str == null ? (enter ? ItsMineConfig.main().message().enterDefault : ItsMineConfig.main().message().leaveDefault) : str).replace("%claim%", claim.name) .replace("%player%", player.getName().asString()); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java index 5fcfada..139bb4c 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java @@ -1,6 +1,7 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ItsMine; import net.minecraft.class_5219; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtIo; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java index 2f1f723..2b131ee 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java @@ -23,12 +23,12 @@ * @author Indigo Amann */ @Mixin(PlayerEntity.class) -public abstract class PlayerEntityMixin extends LivingEntity implements ClaimShower { - @Shadow @Final public PlayerScreenHandler playerScreenHandler; +public abstract class PlayerEntityMixin extends LivingEntity implements ClaimShower, ClaimPlayerEntity { protected PlayerEntityMixin(EntityType entityType_1, World world_1) { super(entityType_1, world_1); } + private int messageCooldown = 0; private Claim shownClaim = null; private BlockPos lastShowPos = null; private String showmode = null; @@ -56,11 +56,38 @@ public void hittingIsRude(Entity entity, CallbackInfo ci) { ci.cancel(); } } + + @Override + public void setMessageCooldown(){ + messageCooldown = ItsMineConfig.main().message().messageCooldown; + } + + @Override + public void setMessageCooldown(int cooldown){ + messageCooldown = cooldown; + } + + @Override + public void tickMessageCooldown(){ + if(messageCooldown > 0){ + messageCooldown--; + } + } + + @Override + public int getMessageCooldown(){ + return messageCooldown; + } + + @Override + public boolean shouldMessage(){ + return messageCooldown == 0; + } + @Override public void setLastShowPos(BlockPos pos) { lastShowPos = pos; } - @Override public void setShownClaim(Claim claim) { shownClaim = claim; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index 6da3101..2ebd94f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -3,6 +3,7 @@ import io.github.indicode.fabric.itsmine.*; import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.util.BlockUtil; +import io.github.indicode.fabric.itsmine.util.MessageUtil; import net.minecraft.block.*; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; @@ -26,6 +27,7 @@ import java.util.UUID; + /** * @author Indigo Amann */ @@ -87,10 +89,10 @@ public boolean canBreak(ServerWorld world, PlayerEntity player, BlockPos pos) { if (posPair != null) { posPair = new Pair<>(posPair.getLeft(), pos); ClaimManager.INSTANCE.stickPositions.put(player, posPair); - player.sendSystemMessage(new LiteralText("Position #2 set: " + pos.getX() + (Config.claims2d ? "" : " " + pos.getY()) + " " + pos.getZ()).formatted(Formatting.GREEN)); + player.sendSystemMessage(new LiteralText("Position #2 set: " + pos.getX() + (ItsMineConfig.main().claims2d ? "" : " " + pos.getY()) + " " + pos.getZ()).formatted(Formatting.GREEN)); if (posPair.getLeft() != null) { player.sendSystemMessage(new LiteralText("Area Selected. Type /claim create to create your claim!").formatted(Formatting.GOLD)); - if (!Config.claims2d) + if (!ItsMineConfig.main().claims2d) player.sendSystemMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE).formatted(Formatting.ITALIC)); } return false; @@ -101,6 +103,7 @@ public boolean canBreak(ServerWorld world, PlayerEntity player, BlockPos pos) { if (claim != null) { UUID uuid = player.getGameProfile().getId(); if (!claim.hasPermission(uuid, Claim.Permission.BUILD)) { +// MessageUtil.sendText(ItsMineConfig.main().message().breakBlock); player.sendSystemMessage(Messages.MSG_BREAK_BLOCK); return false; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java index bc99532..8f0f71b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java @@ -61,6 +61,10 @@ public void tickActions(BooleanSupplier shouldKeepTicking, CallbackInfo ci){ } } }); + this.getPlayers().forEach(playerEntity -> { + ((ClaimPlayerEntity) playerEntity).tickMessageCooldown(); + }); + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java index fc137d1..48481f4 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java @@ -1,9 +1,7 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Config; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; +import io.github.indicode.fabric.itsmine.ItsMineConfig; import net.minecraft.item.Item; import net.minecraft.item.ItemUsageContext; import net.minecraft.item.Items; @@ -12,7 +10,6 @@ import net.minecraft.util.Formatting; import net.minecraft.util.Pair; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -29,10 +26,10 @@ private void setStickPositionFirst(ItemUsageContext context, CallbackInfoReturna if (posPair == null) return; else posPair = new Pair<>(context.getBlockPos(), posPair.getRight()); ClaimManager.INSTANCE.stickPositions.put(context.getPlayer(), posPair); - context.getPlayer().sendSystemMessage(new LiteralText("Position #1 set: " + context.getBlockPos().getX() + (Config.claims2d ? "" : " " + context.getBlockPos().getY()) + " " + context.getBlockPos().getZ()).formatted(Formatting.GREEN)); + context.getPlayer().sendSystemMessage(new LiteralText("Position #1 set: " + context.getBlockPos().getX() + (ItsMineConfig.main().claims2d ? "" : " " + context.getBlockPos().getY()) + " " + context.getBlockPos().getZ()).formatted(Formatting.GREEN)); if (posPair.getRight() != null) { context.getPlayer().sendSystemMessage(new LiteralText("Area Selected. Type /claim create to create your claim!").formatted(Formatting.GOLD)); - if (!Config.claims2d) context.getPlayer().sendSystemMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE).formatted(Formatting.ITALIC)); + if (!ItsMineConfig.main().claims2d) context.getPlayer().sendSystemMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE).formatted(Formatting.ITALIC)); } cir.setReturnValue(ActionResult.SUCCESS); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java index f4095e2..b1aaac6 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java @@ -6,9 +6,10 @@ import com.mojang.brigadier.suggestion.SuggestionProvider; import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.Config; +import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.ItsMineConfig; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.claim.ClaimSettings; import net.minecraft.server.command.CommandSource; import net.minecraft.server.command.ServerCommandSource; @@ -114,7 +115,7 @@ private static CompletableFuture subzoneProvider(CommandContext DIRECTION_PROVIDER = (source, builder) -> { List strings = new ArrayList<>(); for (Direction direction: Direction.values()) { - if (Config.claims2d && (direction == Direction.DOWN || direction == Direction.UP)) continue; + if (ItsMineConfig.main().claims2d && (direction == Direction.DOWN || direction == Direction.UP)) continue; strings.add(direction.getName()); }; return CommandSource.suggestMatching(strings, builder); @@ -150,6 +151,9 @@ public static CompletableFuture itemsSuggestion(final CommandContex for (ClaimSettings.Setting value : ClaimSettings.Setting.values()) { strings.add(value.id); } + for (Claim.Permission value : Claim.Permission.values()) { + strings.add(value.id); + } return CommandSource.suggestMatching(strings, builder); }; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ChatColor.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ChatColor.java similarity index 91% rename from src/main/java/io/github/indicode/fabric/itsmine/ChatColor.java rename to src/main/java/io/github/indicode/fabric/itsmine/util/ChatColor.java index f892149..545fd82 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ChatColor.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ChatColor.java @@ -1,7 +1,8 @@ -package io.github.indicode.fabric.itsmine; +package io.github.indicode.fabric.itsmine.util; import com.google.common.collect.Maps; import net.minecraft.text.LiteralText; +import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import org.apache.commons.lang3.Validate; @@ -9,6 +10,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.Map; import java.util.regex.Pattern; @@ -241,6 +243,23 @@ public static String translateAlternateColorCodes(char altColorChar, @NotNull St return new String(b); } + public static Text translateStringToText(char altColorChar, String input) { + String[] strings = input.split("(?=((\\&([0-9]|[a-f])){1}(\\&(k|l|m|n|o|r)){0,5}))"); + MutableText text = new LiteralText(""); + for(String string : strings) { + char[] b = string.toCharArray(); + for (int i = 0; i < b.length - 1; i++) { + ArrayList formattings = new ArrayList<>(); + if(b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i+1]) > -1){ + ChatColor color = getByChar(b[i+1]); + formattings.add(color.getFormattingByChar(b[i+1])); + text.append(new LiteralText(removeAlternateColorCodes('&', string)).formatted(formattings.toArray(new Formatting[formattings.size()]))); + } + } + } + return text; + } + public static String reverseTranslate(String textToTranslate, char altColorChar) { Validate.notNull(textToTranslate, "Cannot translate null text"); char[] b = textToTranslate.toCharArray(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java index 5074b10..f8f17f7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java @@ -91,12 +91,12 @@ public static void validateCanAccess(ServerPlayerEntity player, Claim claim, boo public static int querySetting(ServerCommandSource source, Claim claim, ClaimSettings.Setting setting) { boolean enabled = claim.settings.getSetting(setting); - source.sendFeedback(new LiteralText(ChatColor.translate("&eSetting &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); + source.sendFeedback(new LiteralText(ChatColor.translate("&eFlag &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); return 1; } public static int setSetting(ServerCommandSource source, Claim claim, ClaimSettings.Setting setting, boolean set) { claim.settings.settings.put(setting, set); - source.sendFeedback(new LiteralText(ChatColor.translate("&eSet setting &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSet flag &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); return 0; } public static int queryPermission(ServerCommandSource source, Claim claim, Claim.Permission permission) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java index e4600b8..623ca7d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java @@ -1,6 +1,10 @@ package io.github.indicode.fabric.itsmine.util; import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.ClaimPlayerEntity; +import io.github.indicode.fabric.itsmine.ItsMineConfig; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.*; import net.minecraft.util.Formatting; @@ -9,7 +13,7 @@ public class MessageUtil { - public static void sendPage(ServerCommandSource source, Text header, int entries, int page, String command, ArrayList content){ + public static void sendPage(ServerCommandSource source, Text header, int entries, int page, String command, ArrayList content) { for (int i=0; i < content.size(); i += entries) { System.out.println(content.subList(i, Math.min(content.size(), i + entries))); @@ -57,10 +61,18 @@ public static void sendPage(ServerCommandSource source, Text header, int entries sendText(source, message); } - public static void sendText(ServerCommandSource source, LiteralText text){ - source.sendFeedback(text, false); + public static void sendText(ServerCommandSource source, LiteralText text) { +// if(((ClaimPlayerEntity) source.getPlayer()).shouldMessage()){ + source.sendFeedback(text, false); +// ((ClaimPlayerEntity) source.getPlayer()).setMessageCooldown(); +// } } - +// public static void sendText(PlayerEntity player, LiteralText text) throws CommandSyntaxException { +// if(((ClaimPlayerEntity) player).shouldMessage()){ +// player.sendSystemMessage(new LiteralText(ItsMineConfig.main().prefix).append(text)); +// ((ClaimPlayerEntity) player).setMessageCooldown(); +// } +// } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/Messenger.java b/src/main/java/io/github/indicode/fabric/itsmine/util/Messenger.java new file mode 100644 index 0000000..a918c9a --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/Messenger.java @@ -0,0 +1,12 @@ +package io.github.indicode.fabric.itsmine.util; + +import net.minecraft.text.LiteralText; +import net.minecraft.text.MutableText; + +public class Messenger { + + public static MutableText toText(String text) { + return new LiteralText(ChatColor.translate(text)); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java index 7f7fa4f..1401a81 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java @@ -1,8 +1,8 @@ package io.github.indicode.fabric.itsmine.util; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.Config; import io.github.indicode.fabric.itsmine.ItsMine; +import io.github.indicode.fabric.itsmine.ItsMineConfig; import io.github.indicode.fabric.permissions.PermChangeBehavior; import io.github.indicode.fabric.permissions.Thimble; import net.fabricmc.loader.api.FabricLoader; @@ -27,7 +27,7 @@ public class PermissionUtil { public PermissionUtil() { Logger logger = (Logger) LogManager.getLogger("ItsMine"); logger.info("Setting up Permissions..."); - this.manager = Manager.fromString(Config.permissionManager); + this.manager = Manager.fromString(ItsMineConfig.main().permissionManager); if (manager == Manager.VANILLA) { this.present = false; From 83094e2eedfda22c5179537545233782286e4a9f Mon Sep 17 00:00:00 2001 From: DrexHD Date: Fri, 8 May 2020 12:00:24 +0200 Subject: [PATCH 83/85] Renamed Settings -> Flags --- .../indicode/fabric/itsmine/Messages.java | 34 +++++++++---------- .../indicode/fabric/itsmine/claim/Claim.java | 10 +++--- .../{ClaimSettings.java => ClaimFlags.java} | 32 ++++++++--------- .../fabric/itsmine/command/FlagsCommand.java | 22 ++++++------ .../fabric/itsmine/command/InfoCommand.java | 4 +-- .../itsmine/command/PermissionCommand.java | 2 +- .../itsmine/mixin/AbstractFireBlockMixin.java | 4 +-- .../itsmine/mixin/EnderDragonEntityMixin.java | 4 +-- .../fabric/itsmine/mixin/EntityMixin.java | 8 ++--- .../fabric/itsmine/mixin/ExplosionMixin.java | 6 ++-- .../itsmine/mixin/FarmlandBlockMixin.java | 4 +-- .../fabric/itsmine/mixin/FireBlockMixin.java | 26 +++++++------- .../fabric/itsmine/mixin/FluidMixin.java | 10 +++--- .../fabric/itsmine/mixin/LavaMixin.java | 18 +++++----- .../itsmine/mixin/PistonBlockMixin.java | 10 +++--- .../itsmine/mixin/SpawnRestrictionMixin.java | 4 +-- .../fabric/itsmine/util/ArgumentUtil.java | 8 ++--- .../fabric/itsmine/util/ClaimUtil.java | 32 ++++++++--------- .../fabric/itsmine/util/MessageUtil.java | 10 +++--- 19 files changed, 123 insertions(+), 125 deletions(-) rename src/main/java/io/github/indicode/fabric/itsmine/claim/{ClaimSettings.java => ClaimFlags.java} (68%) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java index 6e5ec09..3ced3e8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Messages.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Messages.java @@ -1,7 +1,7 @@ package io.github.indicode.fabric.itsmine; import io.github.indicode.fabric.itsmine.claim.Claim; -import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import io.github.indicode.fabric.itsmine.util.ChatColor; import net.minecraft.text.LiteralText; import net.minecraft.text.MutableText; @@ -13,7 +13,7 @@ public class Messages { public static final Text INVALID_CLAIM = PREFIX.copy().append(new LiteralText("Can not find a claim with that name or a claim at your position").formatted(Formatting.RED)); - public static final Text INVALID_SETTING = PREFIX.copy().append(new LiteralText("Invalid Claim Setting!").formatted(Formatting.RED)); + public static final Text INVALID_SETTING = PREFIX.copy().append(new LiteralText("Invalid Claim Flag!").formatted(Formatting.RED)); public static final Text INVALID_PERMISSION = PREFIX.copy().append(new LiteralText("Invalid Claim Permission!")); @@ -52,11 +52,11 @@ public class Messages { .append(line(3, "Type &6/claim create &e to create your claim!")) .append(line(4, "To trust a player in your claim type &6/claim trust ")) .append(line(5, "To untrust a player in your claim type &6/claim distrust ")), - header("How to Claim (Settings)") - .append(line("Settings allow you to change some properties of your claim, they are basically global permissions").formatted(Formatting.LIGHT_PURPLE)) - .append(line(1, "To change a setting, type ").append(text("/claim settings [true | false]").formatted(Formatting.GOLD))) - .append(line(2, "To check a setting, type ").append(text("/claim settings ").formatted(Formatting.GOLD))) - .append(line(3, "To see a list of settings, type ").append(text("/claim settings").formatted(Formatting.GOLD))), + header("How to Claim (Flags)") + .append(line("Flags allow you to change some properties of your claim, they are basically global permissions").formatted(Formatting.LIGHT_PURPLE)) + .append(line(1, "To change a flag, type ").append(text("/claim flags [true | false]").formatted(Formatting.GOLD))) + .append(line(2, "To check a flag, type ").append(text("/claim flags ").formatted(Formatting.GOLD))) + .append(line(3, "To see a list of flags, type ").append(text("/claim flags").formatted(Formatting.GOLD))), header("How to Claim (Player Permissions)") .append(line("You can set different permissions for each trusted player!").formatted(Formatting.LIGHT_PURPLE)) .append(line(1, "To set a permission, type ").append(text("/claim permissions player [true | false]").formatted(Formatting.GOLD))) @@ -68,7 +68,7 @@ public class Messages { .append(line(2, "If you want to specify a direction, you can type ").append(text("/claim expand ").formatted(Formatting.GOLD))) .append(line(3, "To shrink a claim you do the same thing but replace \"expand\" with \"shrink\"")), header("How to Claim (Subzones)") - .append(line("Subzones allow you to have seperate permissions / settings in certain areas of your claim").formatted(Formatting.LIGHT_PURPLE)) + .append(line("Subzones allow you to have seperate permissions / flags in certain areas of your claim").formatted(Formatting.LIGHT_PURPLE)) .append(line(1, "To create a subzone, you select an area inside your claim the way you would select a normal claim")) .append(line(2, "Type ").append(text("/claim subzone add ")).formatted(Formatting.GOLD).append(text(" to create a subzone")).formatted(Formatting.YELLOW)) .append(line(3,"Done! Everything else works the same way claims work")) @@ -95,7 +95,7 @@ public class Messages { .append(line("&6permissions ").append(text("&eLets you modify the permissions of players and add exceptions"))) .append(line("&6remove ").append(text("&eRemoves your claim"))) .append(line("&6rename ").append(text("&eLets you rename your claim"))) - .append(line("&6settings ").append(text("&eLets you modify the global permissions and setting of your claim"))) + .append(line("&6flags ").append(text("&eLets you modify the global permissions and flag of your claim"))) .append(line("&6message ").append(text("&eLets you modify the different message events"))) .append(line("&6stick ").append(text("&eEnables/disables the claim stick for marking the positions"))), @@ -128,14 +128,14 @@ public class Messages { .append(line("&6container ").append(text("&eAllows others to open containers (e.g: Chest, EnderChest etc)"))) .append(line("&6container.chest ").append(text("&eAllows others to only open chest containers (Chests and Barrels)"))), - header("Settings") + header("Flags") .append(line("&6flight_allowed ").append(text("Allows others to fly in the claim (Only for those who have the Flight permission)"))) .append(line("&6explosion_destruction ").append(text("Explosions destroy blocks"))) .append(line("&6explosion_damage ").append(text("Explosions damage entities"))) .append(line("&6fluid_crosses_border ").append(text("Let fluids go across the borders"))) .append(line("&6fire_crosses_border ").append(text("Let fire to spread across the borders"))), - header("Settings") + header("Flags") .append(line("&6fire_damage ").append(text("Fire damages entities"))) .append(line("&6piston_from_inside ").append(text("Let pistons to move blocks to outside the claim"))) .append(line("&6mob_spawning ").append(text("Allow mobs to spawn inside the claim"))) @@ -160,12 +160,12 @@ public static MutableText text(String text) { } public static class Command { - public static Text getSettings(Claim claim) { - MutableText claimSettings = new LiteralText(""); + public static Text getFlags(Claim claim) { + MutableText claimFlags = new LiteralText(""); boolean nextEnabled = false; boolean nextDisabled = false; - for (ClaimSettings.Setting value : ClaimSettings.Setting.values()) { - boolean enabled = claim.settings.getSetting(value); + for (ClaimFlags.Flag value : ClaimFlags.Flag.values()) { + boolean enabled = claim.flags.getFlag(value); Formatting formatting; if (enabled) { if (nextEnabled) formatting = Formatting.GREEN; @@ -177,10 +177,10 @@ public static Text getSettings(Claim claim) { nextDisabled = !nextDisabled; } - claimSettings.append(new LiteralText(" ")).append(new LiteralText(value.id).formatted(formatting)); + claimFlags.append(new LiteralText(" ")).append(new LiteralText(value.id).formatted(formatting)); } - return claimSettings; + return claimFlags; } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java index 037f8b2..5163c62 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java @@ -27,7 +27,7 @@ public class Claim { public @Nullable BlockPos tpPos; public DimensionType dimension; public List children = new ArrayList<>(); - public ClaimSettings settings = new ClaimSettings(); + public ClaimFlags flags = new ClaimFlags(); public PermissionManager permissionManager = new PermissionManager(); public Rent rent = new Rent(); public UUID claimBlockOwner = null; @@ -318,7 +318,7 @@ public CompoundTag toTag() { } { - tag.put("settings", settings.toTag()); + tag.put("flags", flags.toTag()); tag.put("permissions", permissionManager.toNBT()); if(claimBlockOwner != null) tag.putUuidNew("top_owner", claimBlockOwner); @@ -390,7 +390,7 @@ public void fromTag(CompoundTag tag) { } } { - this.settings = new ClaimSettings(tag.getCompound("settings")); + this.flags = new ClaimFlags(tag.getCompound("flags")); permissionManager = new PermissionManager(); permissionManager.fromNBT(tag.getCompound("permissions")); if (containsUUID(tag, "top_owner")) claimBlockOwner = getUUID(tag,"top_owner"); @@ -419,7 +419,7 @@ public enum Permission { //Admin REMOVE_CLAIM("remove_claim", "Remove Claim"), MODIFY_SIZE("modify.size", "Modify Claim Size"), - MODIFY_SETTINGS("modify.settings", "Change Claim Settings"), + MODIFY_SETTINGS("modify.flags", "Change Claim Flags"), MODIFY_PERMISSIONS("modify.permissions", "Change Permissions"), //Normal MODIFY_PROPERTIES("modify.properties", "Modify Claim Properties"), @@ -763,7 +763,7 @@ public static Event getById(String id) { public enum HelpBook { GET_STARTED("getStarted", Messages.GET_STARTED, "Get Started"), COMMAND("commands", Messages.HELP, "Claim Commands"), - PERMS_AND_SETTINGS("perms_and_settings", Messages.SETTINGS_AND_PERMISSIONS, "Claim Permissions and Settings"); + PERMS_AND_SETTINGS("perms_and_flags", Messages.SETTINGS_AND_PERMISSIONS, "Claim Permissions and Flags"); public String id; public String title; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/claim/ClaimSettings.java b/src/main/java/io/github/indicode/fabric/itsmine/claim/ClaimFlags.java similarity index 68% rename from src/main/java/io/github/indicode/fabric/itsmine/claim/ClaimSettings.java rename to src/main/java/io/github/indicode/fabric/itsmine/claim/ClaimFlags.java index d015fee..9b5994a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/claim/ClaimSettings.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/claim/ClaimFlags.java @@ -5,8 +5,8 @@ import java.util.HashMap; import java.util.Map; -public class ClaimSettings{ - public enum Setting { +public class ClaimFlags{ + public enum Flag { FLIGHT_ALLOWED("flight_allowed", "Flying Allowed", true), EXPLOSION_DESTRUCTION("explosion_destruction", "Explosion Destroys Blocks", false), EXPLOSION_DAMAGE("explosion_damage", "Explosion Damages Entities", false), @@ -23,40 +23,40 @@ public enum Setting { public String id, name; boolean defaultValue; - Setting(String id, String name, boolean defaultValue) { + Flag(String id, String name, boolean defaultValue) { this.id = id; this.name = name; this.defaultValue = defaultValue; } - public static Setting byId(String id) { - for (Setting permission: values()) { + public static Flag byId(String id) { + for (Flag permission: values()) { if (permission.id.equals(id)) return permission; } return null; } } - public Map settings = new HashMap<>(); - public ClaimSettings(CompoundTag tag) { + public Map flags = new HashMap<>(); + public ClaimFlags(CompoundTag tag) { fromTag(tag); } - public ClaimSettings() { + public ClaimFlags() { } - public boolean getSetting(Setting setting) { - return settings.getOrDefault(setting, setting.defaultValue); + public boolean getFlag(Flag flag) { + return flags.getOrDefault(flag, flag.defaultValue); } public CompoundTag toTag() { CompoundTag tag = new CompoundTag(); - this.settings.forEach((setting, data) -> { - tag.putBoolean(setting.id, data); + this.flags.forEach((flag, data) -> { + tag.putBoolean(flag.id, data); }); return tag; } public void fromTag(CompoundTag tag) { - settings.clear(); + flags.clear(); tag.getKeys().forEach(key -> { - Setting setting = Setting.byId(key); - if (setting == null) return; - this.settings.put(setting, tag.getBoolean(key)); + Flag flag = Flag.byId(key); + if (flag == null) return; + this.flags.put(flag, tag.getBoolean(key)); }); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/FlagsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/FlagsCommand.java index 1c3790b..ba11e23 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/FlagsCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/FlagsCommand.java @@ -10,19 +10,19 @@ import static com.mojang.brigadier.arguments.StringArgumentType.getString; import static io.github.indicode.fabric.itsmine.command.HelpCommand.sendPage; -import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getSettings; -import static io.github.indicode.fabric.itsmine.util.ClaimUtil.executeSetting; -import static io.github.indicode.fabric.itsmine.util.ClaimUtil.querySettings; +import static io.github.indicode.fabric.itsmine.util.ArgumentUtil.getFlags; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.executeFlag; +import static io.github.indicode.fabric.itsmine.util.ClaimUtil.queryFlags; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; public class FlagsCommand { public static void register(LiteralArgumentBuilder command, boolean admin, RequiredArgumentBuilder claim) { - LiteralArgumentBuilder settings = literal("flags"); + LiteralArgumentBuilder flags = literal("flags"); if (!admin) { - settings.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Flags", "/claim help perms_and_settings %page%")); + flags.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Flags", "/claim help perms_and_flags %page%")); claim.executes((context) -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); @@ -30,20 +30,20 @@ public static void register(LiteralArgumentBuilder command, context.getSource().sendError(Messages.INVALID_CLAIM); return -1; } - return querySettings(context.getSource(), claim1); + return queryFlags(context.getSource(), claim1); }); } - RequiredArgumentBuilder id = getSettings(); + RequiredArgumentBuilder id = getFlags(); RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); - id.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), getString(context, "claim"), true, false, admin)); - set.executes((context) -> executeSetting(context.getSource(), getString(context, "setting"), null, false, BoolArgumentType.getBool(context, "set"), admin)); + id.executes((context) -> executeFlag(context.getSource(), getString(context, "flag"), getString(context, "claim"), true, false, admin)); + set.executes((context) -> executeFlag(context.getSource(), getString(context, "flag"), null, false, BoolArgumentType.getBool(context, "set"), admin)); id.then(set); claim.then(id); - settings.then(claim); - command.then(settings); + flags.then(claim); + command.then(flags); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java index 910d45b..09b193b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java @@ -53,8 +53,8 @@ private static int info(ServerCommandSource source, Claim claim) throws CommandS text.append(newInfoLine("Size", new LiteralText(size.getX() + (claim.is2d() ? "x" : ("x" + size.getY() + "x")) + size.getZ()).formatted(Formatting.GREEN))); - text.append(new LiteralText("").append(new LiteralText("* Settings:").formatted(Formatting.YELLOW)) - .append(Messages.Command.getSettings(claim)).append(new LiteralText("\n"))); + text.append(new LiteralText("").append(new LiteralText("* Flags:").formatted(Formatting.YELLOW)) + .append(Messages.Command.getFlags(claim)).append(new LiteralText("\n"))); MutableText pos = new LiteralText(""); Text min = newPosLine(claim.min, Formatting.AQUA, Formatting.DARK_AQUA); Text max = newPosLine(claim.max, Formatting.LIGHT_PURPLE, Formatting.DARK_PURPLE); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionCommand.java index db5afcb..df2f3df 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/PermissionCommand.java @@ -35,7 +35,7 @@ public static void register(LiteralArgumentBuilder command, RequiredArgumentBuilder permNode = getPermissions(); RequiredArgumentBuilder allow = argument("allow", BoolArgumentType.bool()); - exception.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Settings", "/claim help perms_and_settings %page%")); + exception.executes((context) -> sendPage(context.getSource(), Messages.SETTINGS_AND_PERMISSIONS, 1, "Claim Permissions and Flags", "/claim help perms_and_flags %page%")); claim.executes((context) -> { Claim claim1 = ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")); if (claim1 == null) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java index b1d07e6..084872f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java @@ -2,7 +2,7 @@ import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import net.minecraft.block.AbstractFireBlock; import net.minecraft.entity.Entity; import org.spongepowered.asm.mixin.Mixin; @@ -15,7 +15,7 @@ public abstract class AbstractFireBlockMixin { @Redirect(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isFireImmune()Z")) private boolean neverGonnaBurnYouUp(Entity entity) { Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.dimension); - if (claim != null && !claim.settings.getSetting(ClaimSettings.Setting.FIRE_DAMAGE)) { + if (claim != null && !claim.flags.getFlag(ClaimFlags.Flag.FIRE_DAMAGE)) { return true; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java index 3952fa2..9db2a6b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java @@ -2,7 +2,7 @@ import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import net.minecraft.entity.boss.dragon.EnderDragonEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -17,7 +17,7 @@ public class EnderDragonEntityMixin { private boolean dontTouchieMyBlocksStupidDragon(World world, BlockPos pos, boolean move) { Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.dimension.getType()); - if (claim != null && !claim.settings.getSetting(ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) { + if (claim != null && !claim.flags.getFlag(ClaimFlags.Flag.EXPLOSION_DESTRUCTION)) { return false; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index caefebf..b9dc5f6 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -2,7 +2,7 @@ import io.github.indicode.fabric.itsmine.*; import io.github.indicode.fabric.itsmine.claim.Claim; -import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import io.github.indicode.fabric.itsmine.util.ChatColor; import io.github.indicode.fabric.itsmine.util.ClaimUtil; import net.minecraft.entity.Entity; @@ -59,7 +59,7 @@ else if (claim != null) if (message != null) serverPlayerEntity.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText(ChatColor.translate(message)), -1, ItsMineConfig.main().message().eventStayTicks, -1)); - if (claim != null && claim.settings.getSetting(ClaimSettings.Setting.ENTER_SOUND)) { + if (claim != null && claim.flags.getFlag(ClaimFlags.Flag.ENTER_SOUND)) { serverPlayerEntity.networkHandler.sendPacket(new PlaySoundIdS2CPacket(Registry.SOUND_EVENT.getId(SoundEvents.BLOCK_CONDUIT_ACTIVATE), SoundCategory.MASTER, this.getPos(), 2, 1.2F)); } } @@ -95,7 +95,7 @@ public void doTickActions(CallbackInfo ci) { ( ( !ClaimManager.INSTANCE.flyers.contains(player.getUuid()) || - claim == null || !claim.settings.getSetting(ClaimSettings.Setting.FLIGHT_ALLOWED) || + claim == null || !claim.flags.getFlag(ClaimFlags.Flag.FLIGHT_ALLOWED) || !claim.hasPermission(player.getGameProfile().getId(), Claim.Permission.FLIGHT) || !Functions.canFly((ServerPlayerEntity) player) ) @@ -116,7 +116,7 @@ public void doTickActions(CallbackInfo ci) { ClaimManager.INSTANCE.flyers.contains(player.getUuid()) && shouldChange(player) && claim != null && - claim.settings.getSetting(ClaimSettings.Setting.FLIGHT_ALLOWED) + claim.flags.getFlag(ClaimFlags.Flag.FLIGHT_ALLOWED) && claim.hasPermission(player.getUuid(), Claim.Permission.FLIGHT) && Functions.canFly((ServerPlayerEntity) player) ///&& Functions.canClaimFly((ServerPlayerEntity) player) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java index 16d243f..36e224e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java @@ -2,7 +2,7 @@ import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; @@ -26,7 +26,7 @@ public class ExplosionMixin { private BlockState theyCallMeBedrock(World world, BlockPos pos) { Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); if (claim != null && !world.isAir(pos) && !world.getBlockState(pos).getBlock().equals(Blocks.TNT)) { - if (!claim.settings.getSetting(ClaimSettings.Setting.EXPLOSION_DESTRUCTION)) { + if (!claim.flags.getFlag(ClaimFlags.Flag.EXPLOSION_DESTRUCTION)) { return Blocks.BEDROCK.getDefaultState(); } } @@ -38,7 +38,7 @@ private boolean claimDeniesExplosion(Entity entity) { BlockPos blockPos_1 = entity.getBlockPos(); Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, entity.world.getDimension().getType()); if (claim != null) { - if (!claim.settings.getSetting(ClaimSettings.Setting.EXPLOSION_DAMAGE)) { + if (!claim.flags.getFlag(ClaimFlags.Flag.EXPLOSION_DAMAGE)) { return true; } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java index 971a9e3..0d80de1 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java @@ -2,7 +2,7 @@ import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import net.minecraft.block.FarmlandBlock; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; @@ -19,7 +19,7 @@ public abstract class FarmlandBlockMixin { private void dontYouDareFarmMe(World world, BlockPos pos, Entity entity, float distance, CallbackInfo ci) { Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.dimension.getType()); - if (claim != null && !claim.settings.getSetting(ClaimSettings.Setting.BREAK_FARMLANDS)) { + if (claim != null && !claim.flags.getFlag(ClaimFlags.Flag.BREAK_FARMLANDS)) { ci.cancel(); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java index c5cc7ec..7a9f7e8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java @@ -2,7 +2,7 @@ import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.FireBlock; @@ -33,13 +33,13 @@ private void dontBurnClaims(FireBlock fireBlock, World world, BlockPos newPos, i Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!newClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; + if (!newClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS)) return; } else if (newClaim == null) { - if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; + if (!oldClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS)) return; } else { - if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || - !newClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) return; + if (!oldClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS) || + !newClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS)) return; } } trySpreadingFire(world, newPos, int_1, random_1, int_2); @@ -50,14 +50,14 @@ private boolean dontCauseFire2(ServerWorld world, BlockPos newPos, BlockState bl Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!newClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) + if (!newClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS)) return false; } else if (newClaim == null) { - if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) + if (!oldClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS)) return false; } else { - if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || - !newClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) + if (!oldClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS) || + !newClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS)) return false; } } @@ -81,13 +81,13 @@ private boolean dontCauseFire(World world, BlockPos oldPos, BlockState blockStat Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!newClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); + if (!newClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS)) iterator.remove(); } else if (newClaim == null) { - if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); + if (!oldClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS)) iterator.remove(); } else { - if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS) || - !newClaim.settings.getSetting(ClaimSettings.Setting.FIRE_CROSSES_BORDERS)) iterator.remove(); + if (!oldClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS) || + !newClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS)) iterator.remove(); } } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java index e435e5f..b4fa8f0 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java @@ -2,7 +2,7 @@ import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import net.minecraft.block.BlockState; import net.minecraft.fluid.FlowableFluid; import net.minecraft.fluid.FluidState; @@ -26,13 +26,13 @@ private void dontFlow(IWorld world, BlockPos newPos, BlockState blockState_1, Di Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!newClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!newClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS)) ci.cancel(); } else if (newClaim == null) { - if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!oldClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS)) ci.cancel(); } else { - if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || - !newClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!oldClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS) || + !newClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS)) ci.cancel(); } } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java index 688e73d..7dc5e4a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java @@ -2,7 +2,7 @@ import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import net.minecraft.block.BlockState; import net.minecraft.fluid.FluidState; import net.minecraft.fluid.LavaFluid; @@ -30,13 +30,13 @@ private void dontFlow(IWorld world, BlockPos newPos, BlockState blockState_1, Di Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!newClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!newClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS)) ci.cancel(); } else if (newClaim == null) { - if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!oldClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS)) ci.cancel(); } else { - if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || - !newClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) ci.cancel(); + if (!oldClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS) || + !newClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS)) ci.cancel(); } } } @@ -46,15 +46,15 @@ public boolean neverGonnaBurnMeUp(World world, BlockPos newPos, BlockState block Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!newClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) + if (!newClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS)) return false; } else if (newClaim == null) { - if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) + if (!oldClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS)) return false; } else { - if (!oldClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS) || - !newClaim.settings.getSetting(ClaimSettings.Setting.FLUID_CROSSES_BORDERS)) + if (!oldClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS) || + !newClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS)) return false; } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java index 092326d..24f0d73 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java @@ -2,7 +2,7 @@ import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import net.minecraft.block.BlockState; import net.minecraft.block.PistonBlock; import net.minecraft.block.piston.PistonHandler; @@ -31,13 +31,13 @@ private static void youCantMoveMe(BlockState blockState_1, World world, BlockPos Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); if (oldClaim != newClaim) { if (oldClaim == null) { - if (!newClaim.settings.getSetting(ClaimSettings.Setting.PISTON_FROM_OUTSIDE)) ci.setReturnValue(false); + if (!newClaim.flags.getFlag(ClaimFlags.Flag.PISTON_FROM_OUTSIDE)) ci.setReturnValue(false); } else if (newClaim == null) { - if (!oldClaim.settings.getSetting(ClaimSettings.Setting.PISTON_FROM_INSIDE)) ci.setReturnValue(false); + if (!oldClaim.flags.getFlag(ClaimFlags.Flag.PISTON_FROM_INSIDE)) ci.setReturnValue(false); } else { - if (!oldClaim.settings.getSetting(ClaimSettings.Setting.PISTON_FROM_INSIDE) || - !newClaim.settings.getSetting(ClaimSettings.Setting.PISTON_FROM_OUTSIDE)) ci.setReturnValue(false); + if (!oldClaim.flags.getFlag(ClaimFlags.Flag.PISTON_FROM_INSIDE) || + !newClaim.flags.getFlag(ClaimFlags.Flag.PISTON_FROM_OUTSIDE)) ci.setReturnValue(false); } } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java index d54bd11..26da587 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java @@ -2,7 +2,7 @@ import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import net.minecraft.entity.EntityType; import net.minecraft.entity.SpawnRestriction; import net.minecraft.entity.SpawnType; @@ -24,7 +24,7 @@ private static void canSpawnInClaim(EntityType type, IWorld world, SpawnType return; } Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); - if (claim != null && !claim.settings.getSetting(ClaimSettings.Setting.MOB_SPAWNING)) { + if (claim != null && !claim.flags.getFlag(ClaimFlags.Flag.MOB_SPAWNING)) { cir.setReturnValue(false); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java index b1aaac6..183f7b7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java @@ -10,7 +10,7 @@ import io.github.indicode.fabric.itsmine.ItsMine; import io.github.indicode.fabric.itsmine.ItsMineConfig; import io.github.indicode.fabric.itsmine.claim.Claim; -import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import net.minecraft.server.command.CommandSource; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; @@ -51,8 +51,8 @@ public static RequiredArgumentBuilder getPlayers(){ return argument("player", word()).suggests(PLAYERS_PROVIDER); } - public static RequiredArgumentBuilder getSettings(){ - return argument("setting", word()).suggests(SETTINGS_PROVIDER); + public static RequiredArgumentBuilder getFlags(){ + return argument("flag", word()).suggests(SETTINGS_PROVIDER); } public static RequiredArgumentBuilder getPermissions(){ return argument("permission", word()).suggests(PERMISSIONS_PROVIDER); @@ -148,7 +148,7 @@ public static CompletableFuture itemsSuggestion(final CommandContex public static final SuggestionProvider SETTINGS_PROVIDER = (source, builder) -> { List strings = new ArrayList<>(); - for (ClaimSettings.Setting value : ClaimSettings.Setting.values()) { + for (ClaimFlags.Flag value : ClaimFlags.Flag.values()) { strings.add(value.id); } for (Claim.Permission value : Claim.Permission.values()) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java index f8f17f7..2d8d61e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java @@ -6,7 +6,7 @@ import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import io.github.indicode.fabric.itsmine.*; import io.github.indicode.fabric.itsmine.claim.Claim; -import io.github.indicode.fabric.itsmine.claim.ClaimSettings; +import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; @@ -89,14 +89,14 @@ public static void validateCanAccess(ServerPlayerEntity player, Claim claim, boo } } - public static int querySetting(ServerCommandSource source, Claim claim, ClaimSettings.Setting setting) { - boolean enabled = claim.settings.getSetting(setting); - source.sendFeedback(new LiteralText(ChatColor.translate("&eFlag &6" + setting.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); + public static int queryFlag(ServerCommandSource source, Claim claim, ClaimFlags.Flag flag) { + boolean enabled = claim.flags.getFlag(flag); + source.sendFeedback(new LiteralText(ChatColor.translate("&eFlag &6" + flag.name + " &e is set to " + (enabled ? "&a" : "&c") + enabled + "&e for &6" + claim.name)), false); return 1; } - public static int setSetting(ServerCommandSource source, Claim claim, ClaimSettings.Setting setting, boolean set) { - claim.settings.settings.put(setting, set); - source.sendFeedback(new LiteralText(ChatColor.translate("&eSet flag &6" + setting.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); + public static int setFlag(ServerCommandSource source, Claim claim, ClaimFlags.Flag flag, boolean set) { + claim.flags.flags.put(flag, set); + source.sendFeedback(new LiteralText(ChatColor.translate("&eSet flag &6" + flag.name + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); return 0; } public static int queryPermission(ServerCommandSource source, Claim claim, Claim.Permission permission) { @@ -109,12 +109,12 @@ public static int setPermission(ServerCommandSource source, Claim claim, Claim.P source.sendFeedback(new LiteralText(ChatColor.translate("&eSet permission &6" + permission.id + "&e to " + (set ? "&a" : "&c") + set + "&e for &6" + claim.name)), false); return 1; } - public static int querySettings(ServerCommandSource source, Claim claim) { - source.sendFeedback(new LiteralText("\n").append(new LiteralText("Settings: " + claim.name).formatted(Formatting.YELLOW)).append(new LiteralText("\n")) - .append(Messages.Command.getSettings(claim)).append(new LiteralText("\n")), false); + public static int queryFlags(ServerCommandSource source, Claim claim) { + source.sendFeedback(new LiteralText("\n").append(new LiteralText("Flags: " + claim.name).formatted(Formatting.YELLOW)).append(new LiteralText("\n")) + .append(Messages.Command.getFlags(claim)).append(new LiteralText("\n")), false); return 1; } - public static int executeSetting(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { + public static int executeFlag(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { ServerPlayerEntity player = source.getPlayer(); Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); @@ -124,17 +124,17 @@ public static int executeSetting(ServerCommandSource source, String input, @Null } if (input == null) { - return querySettings(source, claim1); + return queryFlags(source, claim1); } validateCanAccess(player, claim1, admin); - ClaimSettings.Setting setting = ClaimSettings.Setting.byId(input); + ClaimFlags.Flag flag = ClaimFlags.Flag.byId(input); Claim.Permission permission = Claim.Permission.byId(input); - if (setting != null && permission == null) - return isQuery ? querySetting(source, claim1, setting) : setSetting(source, claim1, setting, value); + if (flag != null && permission == null) + return isQuery ? queryFlag(source, claim1, flag) : setFlag(source, claim1, flag, value); - if (setting == null && permission != null) + if (flag == null && permission != null) return isQuery ? queryPermission(source, claim1, permission) : setPermission(source, claim1, permission, value); source.sendError(Messages.INVALID_SETTING); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java index 623ca7d..8b16bf5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/MessageUtil.java @@ -1,12 +1,10 @@ package io.github.indicode.fabric.itsmine.util; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.indicode.fabric.itsmine.ClaimPlayerEntity; -import io.github.indicode.fabric.itsmine.ItsMineConfig; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.text.*; +import net.minecraft.text.ClickEvent; +import net.minecraft.text.HoverEvent; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; import net.minecraft.util.Formatting; import java.util.ArrayList; From c9f1aa029f952fe67af76efe0bfca011beca4373 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Wed, 20 May 2020 22:05:28 +0200 Subject: [PATCH 84/85] 20w21a - 1 --- build.gradle | 14 ++++ gradle.properties | 6 +- .../indicode/fabric/itsmine/ClaimManager.java | 19 +++-- .../indicode/fabric/itsmine/ItsMine.java | 10 +++ .../indicode/fabric/itsmine/claim/Claim.java | 46 ++++-------- .../itsmine/command/CommandManager.java | 2 +- .../fabric/itsmine/command/CreateCommand.java | 4 +- .../fabric/itsmine/command/DebugCommand.java | 9 ++- .../fabric/itsmine/command/FlagsCommand.java | 2 +- .../fabric/itsmine/command/ShowCommand.java | 2 +- .../command/admin/EntitiesCommand.java | 8 +-- .../itsmine/command/admin/ReloadCommand.java | 2 +- .../itsmine/mixin/EnderDragonEntityMixin.java | 2 +- .../fabric/itsmine/mixin/EntityMixin.java | 72 ++++++++++--------- .../itsmine/mixin/FarmlandBlockMixin.java | 2 +- .../fabric/itsmine/mixin/FluidMixin.java | 7 +- .../fabric/itsmine/mixin/LavaMixin.java | 6 +- .../mixin/LevelStorageSessionMixin.java | 2 +- .../ServerPlayerInteractionManagerMixin.java | 23 ++++-- .../itsmine/mixin/ServerWorldMixin.java | 28 +++++--- .../itsmine/mixin/SpawnRestrictionMixin.java | 6 +- .../itsmine/mixin/StickClaimItemMixin.java | 1 + .../fabric/itsmine/util/ArgumentUtil.java | 2 +- .../fabric/itsmine/util/ChatColor.java | 12 +++- .../fabric/itsmine/util/EntityUtil.java | 8 +-- .../fabric/itsmine/util/PermissionUtil.java | 4 ++ 26 files changed, 174 insertions(+), 125 deletions(-) diff --git a/build.gradle b/build.gradle index 4365cbb..ee5b522 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ plugins { id 'fabric-loom' version '0.2.7-SNAPSHOT' id 'maven-publish' + id 'com.github.johnrengelman.shadow' version '5.1.0' } sourceCompatibility = JavaVersion.VERSION_1_8 @@ -18,6 +19,18 @@ repositories { maven { url 'https://jitpack.io' } maven { url 'http://server.bbkr.space:8081/artifactory/libs-release' } } + +shadowJar { + classifier = "shadow" + configurations = [project.configurations.shadow] +} + +tasks.jar.archiveClassifier = "compile" + +task remapJar(type: net.fabricmc.loom.task.RemapJarTask, overwrite: true) { + from zipTree(shadowJar.archiveFile) dependsOn shadowJar +} + dependencies { //to change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" @@ -25,6 +38,7 @@ dependencies { modCompile "net.fabricmc:fabric-loader:${project.loader_version}" compile "org.spongepowered:configurate-hocon:${project.configurate_version}" + shadow "org.spongepowered:configurate-hocon:${project.configurate_version}" //modImplementation "com.github.giantnuker:TinyConfig:${project.tiny_config_version}" //modImplementation /*"io.github.indicode.fabric:thimble-permissions:0.0.9"//*/"com.github.giantnuker:Thimble-Permissions:${project.thimble_permissions_version}" diff --git a/gradle.properties b/gradle.properties index ae6d0a6..70cd618 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,12 +2,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties -minecraft_version=20w19a -yarn_mappings=20w19a+build.1 +minecraft_version=20w21a +yarn_mappings=20w21a+build.2 loader_version=0.7.10+build.191 # Mod Properties -mod_version = 1.9.2-20W19A +mod_version = 1.9.5-20W21A maven_group = io.github.indicode.fabric.itsmine archives_base_name = itsmine diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java index 0fc27be..ae53c26 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java @@ -115,7 +115,7 @@ public CompoundTag toNBT() { return tag; } - public Claim getMainClaimAt(BlockPos pos, DimensionType dimension){ +/* public Claim getMainClaimAt(BlockPos pos, DimensionType dimension){ for (Claim claim : claimsByName.values()) { if(claim.dimension.equals(dimension) && claim.includesPosition(pos)){ return claim.getZoneCovering(pos); @@ -137,22 +137,27 @@ public Claim getSubzoneClaimAt(BlockPos pos, DimensionType dimension) { } return null; } + */ @Nullable public Claim getClaimAt(BlockPos pos, DimensionType dimension) { for (Claim claim : claimsByName.values()) { - if (claim.dimension.equals(dimension) && claim.includesPosition(pos)) { - for(Claim subzone : claim.children){ - if(subzone.dimension.equals(dimension) && subzone.includesPosition(pos)){ - return subzone.getZoneCovering(pos); + if (claim.dimension.equals(dimension)) { + if(claim.includesPosition(pos)) { + for(Claim subzone : claim.children) { + if(subzone.dimension.equals(dimension)) { + if(subzone.includesPosition(pos)){ + return subzone; + } + } } + return claim; } - return claim.getZoneCovering(pos); } } - return null; } + public void fromNBT(CompoundTag tag) { ListTag list = (ListTag) tag.get("claims"); claimsByName.clear(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java index d4e4ac4..c3ff19e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ItsMine.java @@ -3,6 +3,8 @@ import io.github.indicode.fabric.itsmine.config.Config; import io.github.indicode.fabric.itsmine.util.PermissionUtil; import net.fabricmc.api.ModInitializer; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.Logger; import java.nio.file.Path; @@ -11,6 +13,9 @@ */ public class ItsMine implements ModInitializer { private static PermissionUtil permissionUtil; + public static int time = 0; + public static int executed = 0; + @Override public void onInitialize() { @@ -22,6 +27,11 @@ public void onInitialize() { //SharedConstants.isDevelopment = true; } + public static void reload(){ + ItsMineConfig.reload(); +// PermissionUtil.reload(); + } + public static PermissionUtil permissions() { return permissionUtil; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java index 5163c62..3379610 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java @@ -34,8 +34,8 @@ public class Claim { public String customOwnerName, enterMessage, leaveMessage; public boolean isChild = false; public Claim() { - } + public Claim(CompoundTag tag) { fromTag(tag); } @@ -96,34 +96,6 @@ public int getEntities(ServerWorld world){ return entities.get(); } - public Map getEntitySorted(Map entityMap){ - AtomicReference> entityTypeMap = new AtomicReference<>(new HashMap<>()); - entityMap.forEach((uuid, entity) -> { - if(entityTypeMap.get().containsKey(entity.getType())){ - Map entityTypeIntegerMap = entityTypeMap.get(); - entityTypeIntegerMap.put(entity.getType(), entityTypeIntegerMap.get(entity.getType())+1); - entityTypeMap.set(entityTypeIntegerMap); - } else { - Map entityTypeIntegerMap = entityTypeMap.get(); - entityTypeIntegerMap.put(entity.getType(), 1); - entityTypeMap.set(entityTypeIntegerMap); - } - }); - return Functions.sortByValue(entityTypeMap.get()); - } - - public Map getEntityMap(Claim claim, ServerWorld world){ - AtomicReference> entityMap = new AtomicReference<>(new HashMap<>()); - MonitorableWorld monitorableWorld = (MonitorableWorld) world; - monitorableWorld.EntityList().forEach((uuid, entity) -> { - if(claim.includesPosition(entity.getBlockPos())) { - Map entityList = entityMap.get(); - entityList.put(uuid, entity); - entityMap.set(entityList); - } - }); - return entityMap.get(); - } public boolean intersects(Claim claim, boolean checkOther, boolean checkforsubzone) { if (claim == null) return false; @@ -156,6 +128,8 @@ public boolean intersects(Claim claim, boolean checkOther, boolean checkforsubzo else return checkOther && claim.intersects(this, false, checkforsubzone); return false; } + +/* @Nullable public Claim getZoneCovering(BlockPos pos) { if (includesPosition(pos)) { @@ -171,7 +145,7 @@ public Claim getZoneCovering(BlockPos pos) { return null; } - +*/ public boolean hasPermission(UUID player, Permission permission) { return ClaimManager.INSTANCE.ignoringClaims.contains(player) || permissionManager.hasPermission(player, permission); } @@ -349,7 +323,8 @@ public void fromTag(CompoundTag tag) { if (pos.contains("tpX") && pos.contains("tpY") && pos.contains("tpZ")) { this.tpPos = new BlockPos(pos.getInt("tpX"), pos.getInt("tpY"), pos.getInt("tpZ")); } - this.dimension = DimensionType.byId(new Identifier(pos.getString("dimension"))); +// this.dimension = DimensionType.byId(new Identifier(pos.getString("dimension"))); + this.dimension = DimensionType.method_28514(); } { if(!isChild){ @@ -390,7 +365,14 @@ public void fromTag(CompoundTag tag) { } } { - this.flags = new ClaimFlags(tag.getCompound("flags")); + CompoundTag flags = tag.getCompound("flags"); + if(!flags.isEmpty()){ + this.flags = new ClaimFlags(flags); + } + CompoundTag settings = tag.getCompound("settings"); + if(!settings.isEmpty()){ + this.flags = new ClaimFlags(settings); + } permissionManager = new PermissionManager(); permissionManager.fromNBT(tag.getCompound("permissions")); if (containsUUID(tag, "top_owner")) claimBlockOwner = getUUID(tag,"top_owner"); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java index cc53305..9f76f6a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CommandManager.java @@ -30,7 +30,7 @@ public static void register(LiteralArgumentBuilder command, BlockCommand.register(command); CreateCommand.register(command); ClaimsCommand.register(command, dispatcher); - DebugCommand.register(command); +// DebugCommand.register(command); ExpandCommand.register(command, false); FlyCommand.register(command); HelpCommand.register(command); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java index 531e753..ba50dc5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/CreateCommand.java @@ -99,7 +99,7 @@ public static int createClaim(String name, ServerCommandSource owner, BlockPos p sub = sub.add(1, ItsMineConfig.main().claims2d ? 0 : 1,1); int subInt = sub.getX() * (ItsMineConfig.main().claims2d ? 1 : sub.getY()) * sub.getZ(); - Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension().getType(), owner.getPlayer().getBlockPos(), false); + Claim claim = new Claim(name, admin ? null : ownerID, min, max, owner.getWorld().getDimension(), owner.getPlayer().getBlockPos(), false); if (cOwnerName != null) claim.customOwnerName = cOwnerName; claim.permissionManager.playerPermissions.put(ownerID, new Claim.InvertedPermissionMap()); if (!ClaimManager.INSTANCE.claimsByName.containsKey(name)) { @@ -116,7 +116,7 @@ public static int createClaim(String name, ServerCommandSource owner, BlockPos p BlockCommand.blocksLeft(owner); executeShowClaim(owner, claim, false); if (admin) - owner.getMinecraftServer().sendSystemMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command.")); + owner.getMinecraftServer().sendSystemMessage(new LiteralText(owner.getPlayer().getGameProfile().getName() + " Has created a new claim(" + claim.name + ") using the admin command."), owner.getPlayer().getUuid()); return 1; } else { owner.sendFeedback(new LiteralText("You don't have enough claim blocks. You have " + ClaimManager.INSTANCE.getClaimBlocks(ownerID) + ", you need " + subInt + "(" + (subInt - ClaimManager.INSTANCE.getClaimBlocks(ownerID)) + " more)").formatted(Formatting.RED), false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/DebugCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/DebugCommand.java index 5b64e8a..0448329 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/DebugCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/DebugCommand.java @@ -5,6 +5,7 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.indicode.fabric.itsmine.ItsMine; import net.minecraft.server.command.ServerCommandSource; import static io.github.indicode.fabric.itsmine.util.ChatColor.translateStringToText; @@ -14,14 +15,18 @@ public class DebugCommand { public static void register(LiteralArgumentBuilder command) { LiteralArgumentBuilder debug = LiteralArgumentBuilder.literal("debug"); RequiredArgumentBuilder string = RequiredArgumentBuilder.argument("string", StringArgumentType.greedyString()); - string.executes(DebugCommand::execute); + debug.executes(DebugCommand::execute); debug.then(string); command.then(debug); } private static int execute(CommandContext context) throws CommandSyntaxException { - context.getSource().getPlayer().sendSystemMessage(translateStringToText('&', StringArgumentType.getString(context, "string"))); +// context.getSource().getPlayer().sendSystemMessage(translateStringToText('&', StringArgumentType.getString(context, "string"))); + context.getSource().getPlayer().sendSystemMessage(translateStringToText('&', "&eTime elapsed: &6" + ItsMine.time + "μs")); + context.getSource().getPlayer().sendSystemMessage(translateStringToText('&', "&eExecuted: &6" + ItsMine.executed)); + context.getSource().getPlayer().sendSystemMessage(translateStringToText('&', "&eAverage: &6" + ItsMine.time / ItsMine.executed + "μs")); + return 1; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/FlagsCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/FlagsCommand.java index ba11e23..fdffe23 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/FlagsCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/FlagsCommand.java @@ -38,7 +38,7 @@ public static void register(LiteralArgumentBuilder command, RequiredArgumentBuilder set = argument("set", BoolArgumentType.bool()); id.executes((context) -> executeFlag(context.getSource(), getString(context, "flag"), getString(context, "claim"), true, false, admin)); - set.executes((context) -> executeFlag(context.getSource(), getString(context, "flag"), null, false, BoolArgumentType.getBool(context, "set"), admin)); + set.executes((context) -> executeFlag(context.getSource(), getString(context, "flag"), getString(context, "claim"), false, BoolArgumentType.getBool(context, "set"), admin)); id.then(set); claim.then(id); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java index 71326f1..9d3a554 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java @@ -26,7 +26,7 @@ public static void register(LiteralArgumentBuilder command) { RequiredArgumentBuilder mode = getShowMode(); LiteralArgumentBuilder show = literal("show"); - show.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().dimension.getType()), false)); + show.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), false)); RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); claim.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); mode.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false, StringArgumentType.getString(context, "mode"))); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java index ccfb5a0..62afdc0 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java @@ -9,8 +9,8 @@ import io.github.indicode.fabric.itsmine.util.ArgumentUtil; import io.github.indicode.fabric.itsmine.util.PermissionUtil; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityCategory; import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnGroup; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.HoverEvent; import net.minecraft.text.LiteralText; @@ -44,15 +44,15 @@ public static int execute(CommandContext context, Claim cla ArrayList entityList = getEntities(claim); MutableText message = header("Entities (" + claim.name +") - " + entityList.size()).append(new LiteralText("\n\n")); - for(EntityCategory entityCategory : EntityCategory.values()){ + for(SpawnGroup spawnGroup : SpawnGroup.values()){ MutableText entities = new LiteralText(""); - Map entityMap = sortByType(filterByCategory(entityList, entityCategory)); + Map entityMap = sortByType(filterByCategory(entityList, spawnGroup)); entityMap.forEach((entityType, integer) -> { entities.append(entityType.getName().getString() + ": ").formatted(Formatting.YELLOW).append(new LiteralText(String.valueOf(integer))).formatted(Formatting.GOLD).append("\n"); }); if(entityMap.size() > 0){ - message.append(new LiteralText(entityCategory.getName()).styled(style -> { + message.append(new LiteralText(spawnGroup.getName()).styled(style -> { return style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, entities)).withFormatting(Formatting.GOLD); }).append(" ")); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ReloadCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ReloadCommand.java index de7dff0..e7674f7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ReloadCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ReloadCommand.java @@ -25,7 +25,7 @@ public static void register(LiteralArgumentBuilder command) public static int execute(CommandContext context) throws CommandSyntaxException { StopWatch watch = new StopWatch(); watch.start(); - ItsMineConfig.reload(); + ItsMine.reload(); watch.stop(); String timeElapsed = new DecimalFormat("##.##").format(watch.getTime(TimeUnit.MICROSECONDS)); context.getSource().getPlayer().sendSystemMessage(new LiteralText("Reloaded! Took " + timeElapsed + "μs").formatted(Formatting.YELLOW)); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java index 9db2a6b..42d7ad2 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java @@ -15,7 +15,7 @@ public class EnderDragonEntityMixin { @Redirect(method = "destroyBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) private boolean dontTouchieMyBlocksStupidDragon(World world, BlockPos pos, boolean move) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.dimension.getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); if (claim != null && !claim.flags.getFlag(ClaimFlags.Flag.EXPLOSION_DESTRUCTION)) { return false; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index b9dc5f6..5f70cd0 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -32,40 +32,42 @@ public abstract class EntityMixin { @Shadow public abstract void tick(); @Shadow public boolean removed; - private Claim pclaim = null; - @Inject(method = "setPos", at = @At("HEAD")) - public void doPrePosActions(double x, double y, double z, CallbackInfo ci) { - if (!world.isClient && (Object)this instanceof PlayerEntity) { - PlayerEntity player = (PlayerEntity) (Object) this; - if (player.getBlockPos() == null) return; - pclaim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.dimension.getType()); - } - } - @Inject(method = "setPos", at = @At("RETURN")) - public void doPostPosActions(double x, double y, double z, CallbackInfo ci) { - if (!world.isClient && (Object)this instanceof PlayerEntity) { - PlayerEntity player = (PlayerEntity) (Object) this; - if (player.getBlockPos() == null) return; - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.dimension.getType()); - if (pclaim != claim && player instanceof ServerPlayerEntity) { - ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity)player; - if (serverPlayerEntity.networkHandler != null) { - String message = null; - if (pclaim != null && claim == null) - message = getFormattedEventMessage(player, pclaim, false); - else if (claim != null) - message = getFormattedEventMessage(player, claim, true); - - if (message != null) - serverPlayerEntity.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText(ChatColor.translate(message)), -1, ItsMineConfig.main().message().eventStayTicks, -1)); - - if (claim != null && claim.flags.getFlag(ClaimFlags.Flag.ENTER_SOUND)) { - serverPlayerEntity.networkHandler.sendPacket(new PlaySoundIdS2CPacket(Registry.SOUND_EVENT.getId(SoundEvents.BLOCK_CONDUIT_ACTIVATE), SoundCategory.MASTER, this.getPos(), 2, 1.2F)); - } - } - } - } - } + +// private Claim pclaim = null; +// @Inject(method = "setPos", at = @At("HEAD")) +// public void doPrePosActions(double x, double y, double z, CallbackInfo ci) { +// if (!world.isClient && (Object)this instanceof PlayerEntity) { +// PlayerEntity player = (PlayerEntity) (Object) this; +// if (player.getBlockPos() == null) return; +// pclaim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension().getType()); +// } +// } +// @Inject(method = "setPos", at = @At("RETURN")) +// public void doPostPosActions(double x, double y, double z, CallbackInfo ci) { +// if (!world.isClient && (Object)this instanceof PlayerEntity) { +// PlayerEntity player = (PlayerEntity) (Object) this; +// if (player.getBlockPos() == null) return; +// Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension().getType()); +// if (pclaim != claim && player instanceof ServerPlayerEntity) { +// ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity)player; +// if (serverPlayerEntity.networkHandler != null) { +// String message = null; +// if (pclaim != null && claim == null) +// message = getFormattedEventMessage(player, pclaim, false); +// else if (claim != null) +// message = getFormattedEventMessage(player, claim, true); +// +// if (message != null) +// serverPlayerEntity.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText(ChatColor.translate(message)), -1, ItsMineConfig.main().message().eventStayTicks, -1)); +// +// if (claim != null && claim.flags.getFlag(ClaimFlags.Flag.ENTER_SOUND)) { +// serverPlayerEntity.networkHandler.sendPacket(new PlaySoundIdS2CPacket(Registry.SOUND_EVENT.getId(SoundEvents.BLOCK_CONDUIT_ACTIVATE), SoundCategory.MASTER, this.getPos(), 2, 1.2F)); +// } +// } +// } +// } +// } + private String getFormattedEventMessage(PlayerEntity player, Claim claim, boolean enter) { if (player == null || claim == null) @@ -86,7 +88,7 @@ public void doTickActions(CallbackInfo ci) { } boolean old = player.abilities.allowFlying; - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.dimension.getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension().getType()); if (player instanceof ServerPlayerEntity) { if ( diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java index 0d80de1..fe146c4 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java @@ -17,7 +17,7 @@ public abstract class FarmlandBlockMixin { @Inject(method = "onLandedUpon", at = @At(value = "HEAD", target = "Lnet/minecraft/block/FarmlandBlock;onLandedUpon(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;F)V"), cancellable = true) private void dontYouDareFarmMe(World world, BlockPos pos, Entity entity, float distance, CallbackInfo ci) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.dimension.getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); if (claim != null && !claim.flags.getFlag(ClaimFlags.Flag.BREAK_FARMLANDS)) { ci.cancel(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java index b4fa8f0..e0b814c 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java @@ -1,18 +1,19 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import net.minecraft.block.BlockState; import net.minecraft.fluid.FlowableFluid; import net.minecraft.fluid.FluidState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -import net.minecraft.world.IWorld; +import net.minecraft.world.WorldAccess; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CancellationException; /** * @author Indigo Amann @@ -20,7 +21,7 @@ @Mixin(FlowableFluid.class) public class FluidMixin { @Inject(method = "flow", at = @At("HEAD"), cancellable = true) - private void dontFlow(IWorld world, BlockPos newPos, BlockState blockState_1, Direction direction, FluidState fluidState_1, CallbackInfo ci) { + private void dontFlow(WorldAccess world, BlockPos newPos, BlockState state, Direction direction, FluidState fluidState, CallbackInfo ci) { BlockPos oldPos = newPos.offset(direction.getOpposite()); Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension().getType()); Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java index 7dc5e4a..8cbbf8e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java @@ -1,15 +1,15 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import net.minecraft.block.BlockState; import net.minecraft.fluid.FluidState; import net.minecraft.fluid.LavaFluid; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -import net.minecraft.world.IWorld; import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -24,7 +24,7 @@ @Mixin(LavaFluid.class) public class LavaMixin { @Inject(method = "flow", at = @At("HEAD"), cancellable = true) - private void dontFlow(IWorld world, BlockPos newPos, BlockState blockState_1, Direction direction, FluidState fluidState_1, CallbackInfo ci) { + private void dontFlow(WorldAccess world, BlockPos newPos, BlockState state, Direction direction, FluidState fluidState, CallbackInfo ci) { BlockPos oldPos = newPos.offset(direction.getOpposite()); Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension().getType()); Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java index 139bb4c..7c987f7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java @@ -62,7 +62,7 @@ public void saveWorld(class_5219 levelProperties, CompoundTag compoundTag, Callb claimDataFile.renameTo(old); claimDataFile.delete(); } else { - System.out.println("Backup failed!" + claimDataFile.getName() + " may be broken, keeping " + old.getName()); + System.out.println("Aborting backup!" + claimDataFile.getName() + " may be broken, keeping " + old.getName()); } } try { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index 2ebd94f..bf30d00 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -23,7 +23,9 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.UUID; @@ -37,9 +39,20 @@ public abstract class ServerPlayerInteractionManagerMixin { @Shadow public ServerWorld world; + public BlockPos blockPos; + + @Shadow private boolean mining; + + @Inject(method = "interactBlock", at = @At(value = "HEAD")) + private void getBlock(ServerPlayerEntity serverPlayerEntity, World world, ItemStack stack, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable cir){ + blockPos = hitResult.getBlockPos(); + } + @Redirect(method = "interactBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;onUse(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;")) - private ActionResult interactIfPossible(BlockState blockState, World world, PlayerEntity player, Hand hand, BlockHitResult hit, PlayerEntity player1, World world1, ItemStack itemStack, Hand hand1, BlockHitResult hitResult1) { +// private ActionResult interactIfPossible(BlockState blockState, World world, PlayerEntity player, Hand hand, BlockHitResult hit, PlayerEntity player1, World world1, ItemStack itemStack, Hand hand1, BlockHitResult hitResult1) { + private ActionResult interactIfPossible(BlockState blockState, World world, PlayerEntity player, Hand hand, BlockHitResult hit){ BlockPos pos = hit.getBlockPos(); + ItemStack itemStack = player.getMainHandStack(); Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, player.world.getDimension().getType()); if (claim != null) { if (!Functions.canInteractWith(claim, blockState.getBlock(), player.getUuid())) { @@ -63,14 +76,14 @@ private ActionResult interactIfPossible(BlockState blockState, World world, Play } @Redirect(method = "interactBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", ordinal = 2)) - private boolean interactWithItemIfPossible(ItemStack stack, PlayerEntity player, World world, ItemStack itemStack, Hand hand, BlockHitResult hitResult) { - BlockPos pos = hitResult.getBlockPos().offset(hitResult.getSide()); - Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); + private boolean interactWithItemIfPossible(ItemStack stack) { +// BlockPos pos = hitResult.getBlockPos().offset(hitResult.getSide()); +// System.out.println(blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos, world.getDimension().getType()); if (claim != null && !stack.isEmpty()) { if (Functions.canInteractUsingItem(claim, stack.getItem(), player.getUuid())) { return false; } - if (stack.getItem() instanceof BlockItem) { player.sendSystemMessage(Messages.MSG_PLACE_BLOCK); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java index 8f0f71b..7134902 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java @@ -1,18 +1,22 @@ package io.github.indicode.fabric.itsmine.mixin; -import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.ClaimPlayerEntity; +import io.github.indicode.fabric.itsmine.Functions; +import io.github.indicode.fabric.itsmine.MonitorableWorld; +import net.minecraft.class_5269; +import net.minecraft.class_5321; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.Packet; import net.minecraft.server.PlayerManager; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; -import net.minecraft.sound.SoundCategory; import net.minecraft.text.LiteralText; import net.minecraft.util.Formatting; -import net.minecraft.util.math.BlockPos; +import net.minecraft.util.profiler.Profiler; +import net.minecraft.world.World; import net.minecraft.world.dimension.DimensionType; -import org.apache.logging.log4j.core.jmx.Server; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -20,29 +24,31 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.concurrent.atomic.AtomicReference; import java.util.function.BooleanSupplier; +import java.util.function.Supplier; /** * @author Indigo Amann */ @Mixin(ServerWorld.class) -public abstract class ServerWorldMixin implements MonitorableWorld { +public abstract class ServerWorldMixin extends World implements MonitorableWorld { @Shadow @Final private Map entitiesByUuid; + protected ServerWorldMixin(class_5269 arg, DimensionType dimensionType, Supplier supplier, boolean bl, boolean bl2, long l) { + super(arg, dimensionType, supplier, bl, bl2, l); + } + @Shadow public abstract List getPlayers(); @Redirect(method = "processSyncedBlockEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;sendToAround(Lnet/minecraft/entity/player/PlayerEntity;DDDDLnet/minecraft/world/dimension/DimensionType;Lnet/minecraft/network/Packet;)V")) - private void sendPistonUpdate(PlayerManager manager, PlayerEntity playerEntity_1, double double_1, double double_2, double double_3, double double_4, DimensionType dimensionType_1, Packet packet_1) { - manager.sendToAround(playerEntity_1, double_1, double_2, double_3, double_4, dimensionType_1, packet_1); + private void sendPistonUpdate(PlayerManager manager, PlayerEntity playerEntity_1, double double_1, double double_2, double double_3, double double_4, class_5321 dimensionType_1, Packet packet_1) { + manager.sendToAround(playerEntity_1, double_1, double_2, double_3, double_4, this.method_27983(), packet_1); Functions.doPistonUpdate((ServerWorld) (Object)this, packet_1); } @@ -54,7 +60,7 @@ public void tickActions(BooleanSupplier shouldKeepTicking, CallbackInfo ci){ System.out.println("Rent expired -> method call"); this.getPlayers().forEach(serverPlayerEntity -> { if(serverPlayerEntity.getUuid() == claim.rent.getTenant()){ - serverPlayerEntity.sendSystemMessage(new LiteralText("Rent expired").formatted(Formatting.RED)); + serverPlayerEntity.sendSystemMessage(new LiteralText("Rent expired").formatted(Formatting.RED), serverPlayerEntity.getUuid()); claim.endRent(); } }); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java index 26da587..f78b20f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java @@ -4,10 +4,10 @@ import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.claim.ClaimFlags; import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnReason; import net.minecraft.entity.SpawnRestriction; -import net.minecraft.entity.SpawnType; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; +import net.minecraft.world.WorldAccess; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -18,7 +18,7 @@ @Mixin(SpawnRestriction.class) public class SpawnRestrictionMixin { @Inject(method = "canSpawn", at = @At("HEAD"), cancellable = true) - private static void canSpawnInClaim(EntityType type, IWorld world, SpawnType spawnType, BlockPos pos, Random random, CallbackInfoReturnable cir) { + private static void canSpawnInClaim(EntityType type, WorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random, CallbackInfoReturnable cir) { if (ClaimManager.INSTANCE == null) { cir.setReturnValue(false); return; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java index 48481f4..cd03568 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java @@ -18,6 +18,7 @@ @Mixin(Item.class) public class StickClaimItemMixin { @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) +// private void setStickPositionFirst(ItemUsageContext context, CallbackInfoReturnable cir) { private void setStickPositionFirst(ItemUsageContext context, CallbackInfoReturnable cir) { if (context.getWorld().isClient) return; if (!context.getPlayer().isSneaking()) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java index 183f7b7..dd7b2f9 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java @@ -75,7 +75,7 @@ public static RequiredArgumentBuilder getShowMode() private static CompletableFuture claimSubzoneProvider(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { ServerPlayerEntity player = context.getSource().getPlayer(); List names = new ArrayList<>(); - Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension()); if (current != null) names.add(current.name); for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { if (claim != null) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ChatColor.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ChatColor.java index 545fd82..93f665c 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ChatColor.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ChatColor.java @@ -1,6 +1,7 @@ package io.github.indicode.fabric.itsmine.util; import com.google.common.collect.Maps; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; import net.minecraft.text.LiteralText; import net.minecraft.text.MutableText; import net.minecraft.text.Text; @@ -244,18 +245,23 @@ public static String translateAlternateColorCodes(char altColorChar, @NotNull St } public static Text translateStringToText(char altColorChar, String input) { - String[] strings = input.split("(?=((\\&([0-9]|[a-f])){1}(\\&(k|l|m|n|o|r)){0,5}))"); + String[] strings = input.split("(?=(((\\&([0-9]|[a-f])){1}(\\&(k|l|m|n|o|r)){0,5}))|^(\\&([0-9]|[a-f]))?(\\&(k|l|m|n|o|r)){1,5})"); MutableText text = new LiteralText(""); for(String string : strings) { + System.out.println(string); char[] b = string.toCharArray(); + ArrayList formattings = new ArrayList<>(); for (int i = 0; i < b.length - 1; i++) { - ArrayList formattings = new ArrayList<>(); if(b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i+1]) > -1){ ChatColor color = getByChar(b[i+1]); formattings.add(color.getFormattingByChar(b[i+1])); - text.append(new LiteralText(removeAlternateColorCodes('&', string)).formatted(formattings.toArray(new Formatting[formattings.size()]))); } } + MutableText part = new LiteralText(removeAlternateColorCodes('&', string))/*.formatted(formattings.get(0))*/; + for(Formatting formatting : formattings){ + part.formatted(formatting); + } + text.append(part/*new LiteralText(removeAlternateColorCodes('&', string)).formatted(formattings.toArray(new Formatting[formattings.size()]))*/); } return text; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java index 51819b9..7c3ad9c 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java @@ -4,8 +4,8 @@ import io.github.indicode.fabric.itsmine.Functions; import io.github.indicode.fabric.itsmine.MonitorableWorld; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityCategory; import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnGroup; import net.minecraft.server.world.ServerWorld; import java.util.ArrayList; @@ -24,7 +24,7 @@ public static boolean canAttack(UUID player, Claim claim, Entity entity) { } public static boolean isPassive(Entity entity) { - return entity.getType().getCategory().isPeaceful(); + return entity.getType().getSpawnGroup().isPeaceful(); } public static boolean isHostile(Entity entity) { @@ -41,9 +41,9 @@ public static ArrayList getEntities(Claim claim){ return entityList; } - public static ArrayList filterByCategory(ArrayList entityList, EntityCategory entityCategory){ + public static ArrayList filterByCategory(ArrayList entityList, SpawnGroup spawnGroup){ ArrayList filteredEntityList = new ArrayList<>(); - for(Entity entity : entityList) if(entity.getType().getCategory() == entityCategory) filteredEntityList.add(entity); + for(Entity entity : entityList) if(entity.getType().getSpawnGroup() == spawnGroup) filteredEntityList.add(entity); return filteredEntityList; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java index 1401a81..fefba5b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/PermissionUtil.java @@ -58,6 +58,10 @@ public PermissionUtil() { } } + public static void reload(){ + new PermissionUtil(); + } + public boolean hasPermission(ServerCommandSource src, Command permission, int opLevel) { if (present) { if (manager == Manager.LUCKPERMS) { From 5c254ba7ec6028b674d53ebb06d625bee91a24f4 Mon Sep 17 00:00:00 2001 From: DrexHD Date: Fri, 22 May 2020 21:53:11 +0200 Subject: [PATCH 85/85] 20w21a - 2 --- gradle.properties | 2 +- .../indicode/fabric/itsmine/ClaimManager.java | 4 +- .../indicode/fabric/itsmine/Functions.java | 4 +- .../indicode/fabric/itsmine/claim/Claim.java | 10 ++- .../fabric/itsmine/command/DebugCommand.java | 8 +- .../fabric/itsmine/command/ExpandCommand.java | 8 +- .../fabric/itsmine/command/FlyCommand.java | 4 +- .../fabric/itsmine/command/InfoCommand.java | 5 +- .../fabric/itsmine/command/RemoveCommand.java | 2 +- .../itsmine/command/RevenueCommand.java | 2 +- .../fabric/itsmine/command/ShowCommand.java | 4 +- .../itsmine/command/TransferCommand.java | 9 ++- .../fabric/itsmine/command/TrustCommand.java | 2 +- .../itsmine/command/TrustedCommand.java | 2 +- .../command/admin/EntitiesCommand.java | 2 +- .../itsmine/command/admin/ExpandCommand.java | 8 +- .../itsmine/command/admin/OwnerCommand.java | 4 +- .../itsmine/command/admin/ReloadCommand.java | 4 +- .../itsmine/command/admin/RemoveCommand.java | 2 +- .../command/subzone/CreateCommand.java | 8 +- .../itsmine/mixin/AbstractFireBlockMixin.java | 2 +- .../itsmine/mixin/AnimalEntityMixin.java | 6 +- .../fabric/itsmine/mixin/BoatItemMixin.java | 4 +- .../itsmine/mixin/EnderDragonEntityMixin.java | 2 +- .../itsmine/mixin/EnderPearlItemMixin.java | 4 +- .../fabric/itsmine/mixin/EntityMixin.java | 6 +- .../fabric/itsmine/mixin/ExplosionMixin.java | 4 +- .../itsmine/mixin/FarmlandBlockMixin.java | 2 +- .../fabric/itsmine/mixin/FireBlockMixin.java | 12 +-- .../fabric/itsmine/mixin/FluidMixin.java | 4 +- .../fabric/itsmine/mixin/LavaMixin.java | 8 +- .../mixin/LevelStorageSessionMixin.java | 56 +++++++------ .../itsmine/mixin/MinecraftServerMixin.java | 19 +++++ .../itsmine/mixin/PistonBlockMixin.java | 4 +- .../itsmine/mixin/PlaceOnUseBlockMixin.java | 2 +- .../itsmine/mixin/PlayerEntityMixin.java | 8 +- .../itsmine/mixin/ProjectileEntityMixin.java | 4 +- .../mixin/ServerCommandOutputMixin.java | 3 + .../mixin/ServerPlayNetworkHandlerMixin.java | 2 +- .../ServerPlayerInteractionManagerMixin.java | 20 ++--- .../itsmine/mixin/ServerWorldMixin.java | 15 ++-- .../itsmine/mixin/SpawnRestrictionMixin.java | 2 +- .../itsmine/mixin/StickClaimItemMixin.java | 11 ++- .../projectile/ProjectileEntityMixin.java | 4 +- .../fabric/itsmine/util/ArgumentUtil.java | 4 +- .../fabric/itsmine/util/ClaimUtil.java | 33 +++++++- .../fabric/itsmine/util/EntityUtil.java | 3 +- .../fabric/itsmine/util/ShowerUtil.java | 2 +- .../fabric/itsmine/util/WorldUtil.java | 79 ++++++++++++++++++- src/main/resources/itsmine.mixins.json | 3 +- 50 files changed, 287 insertions(+), 135 deletions(-) create mode 100644 src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java diff --git a/gradle.properties b/gradle.properties index 70cd618..890c4c4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties minecraft_version=20w21a -yarn_mappings=20w21a+build.2 +yarn_mappings=20w21a+build.15 loader_version=0.7.10+build.191 # Mod Properties diff --git a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java index ae53c26..038f6c7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/ClaimManager.java @@ -22,7 +22,7 @@ public class ClaimManager { private HashMap blocksLeft = new HashMap<>(); public List ignoringClaims = new ArrayList<>(); public List flyers = new ArrayList<>(); - public MinecraftServer server; + public static MinecraftServer server; public int getClaimBlocks(UUID id) { return blocksLeft.getOrDefault(id, ItsMineConfig.main().claims2d ? ItsMineConfig.main().claimBlock().default2D : ItsMineConfig.main().claimBlock().default3D); } @@ -159,7 +159,9 @@ public Claim getClaimAt(BlockPos pos, DimensionType dimension) { } public void fromNBT(CompoundTag tag) { + System.out.println("fromNBT"); ListTag list = (ListTag) tag.get("claims"); + System.out.println(list.size()); claimsByName.clear(); list.forEach(it -> { Claim claim = new Claim(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java index b00d9d9..d8f546d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/Functions.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/Functions.java @@ -130,10 +130,10 @@ public static boolean checkCanDamageWithProjectile(Entity entity, MinecraftServe return true; ServerPlayerEntity owner = server.getPlayerManager().getPlayer(uuid); - Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension()); if (claim != null && owner != null && !claim.hasPermission(owner.getUuid(), Claim.Permission.DAMAGE_ENTITY)) { - owner.sendSystemMessage(Messages.MSG_DAMAGE_ENTITY); + owner.sendSystemMessage(Messages.MSG_DAMAGE_ENTITY, owner.getUuid()); return false; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java b/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java index 3379610..0ecf5af 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/claim/Claim.java @@ -2,6 +2,7 @@ import blue.endless.jankson.annotation.Nullable; import io.github.indicode.fabric.itsmine.*; +import io.github.indicode.fabric.itsmine.util.WorldUtil; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.item.ItemStack; @@ -11,6 +12,8 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; +import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.dimension.DimensionType; import java.util.*; @@ -240,7 +243,7 @@ public CompoundTag toTag() { pos.putInt("maxX", max.getX()); pos.putInt("maxY", max.getY()); pos.putInt("maxZ", max.getZ()); - pos.putString("dimension", DimensionType.getId(dimension).toString()); + pos.putString("dimension", WorldUtil.getDimensionNameWithNameSpace(dimension)); if (tpPos != null) { pos.putInt("tpX", this.tpPos.getX()); pos.putInt("tpY", this.tpPos.getY()); @@ -309,6 +312,7 @@ public CompoundTag toTag() { return tag; } public void fromTag(CompoundTag tag) { + System.out.println("Loading claim"); { CompoundTag pos = tag.getCompound("position"); int minX = pos.getInt("minX"); @@ -323,8 +327,8 @@ public void fromTag(CompoundTag tag) { if (pos.contains("tpX") && pos.contains("tpY") && pos.contains("tpZ")) { this.tpPos = new BlockPos(pos.getInt("tpX"), pos.getInt("tpY"), pos.getInt("tpZ")); } -// this.dimension = DimensionType.byId(new Identifier(pos.getString("dimension"))); - this.dimension = DimensionType.method_28514(); + + this.dimension = WorldUtil.getDimensionType(pos.getString("dimension")); } { if(!isChild){ diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/DebugCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/DebugCommand.java index 0448329..c0f1354 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/DebugCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/DebugCommand.java @@ -7,6 +7,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import io.github.indicode.fabric.itsmine.ItsMine; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; import static io.github.indicode.fabric.itsmine.util.ChatColor.translateStringToText; @@ -23,9 +24,10 @@ public static void register(LiteralArgumentBuilder command) private static int execute(CommandContext context) throws CommandSyntaxException { // context.getSource().getPlayer().sendSystemMessage(translateStringToText('&', StringArgumentType.getString(context, "string"))); - context.getSource().getPlayer().sendSystemMessage(translateStringToText('&', "&eTime elapsed: &6" + ItsMine.time + "μs")); - context.getSource().getPlayer().sendSystemMessage(translateStringToText('&', "&eExecuted: &6" + ItsMine.executed)); - context.getSource().getPlayer().sendSystemMessage(translateStringToText('&', "&eAverage: &6" + ItsMine.time / ItsMine.executed + "μs")); + ServerPlayerEntity player = context.getSource().getPlayer(); + player.sendSystemMessage(translateStringToText('&', "&eTime elapsed: &6" + ItsMine.time + "μs"), player.getUuid()); + player.sendSystemMessage(translateStringToText('&', "&eExecuted: &6" + ItsMine.executed), player.getUuid()); + player.sendSystemMessage(translateStringToText('&', "&eAverage: &6" + ItsMine.time / ItsMine.executed + "μs"), player.getUuid()); return 1; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java index 4c70e75..4f07d40 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ExpandCommand.java @@ -33,7 +33,7 @@ public static void register(LiteralArgumentBuilder command, RequiredArgumentBuilder direction = getDirections(); direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension()), IntegerArgumentType.getInteger(context, "distance"), directionByName(getString(context, "direction")), context.getSource(), @@ -41,7 +41,7 @@ public static void register(LiteralArgumentBuilder command, )); amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension()), IntegerArgumentType.getInteger(context, "distance"), Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], context.getSource(), @@ -58,7 +58,7 @@ public static void register(LiteralArgumentBuilder command, RequiredArgumentBuilder direction = getDirections(); direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension()), -IntegerArgumentType.getInteger(context, "distance"), directionByName(getString(context, "direction")), context.getSource(), @@ -66,7 +66,7 @@ public static void register(LiteralArgumentBuilder command, )); amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension()), -IntegerArgumentType.getInteger(context, "distance"), Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], context.getSource(), diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java index 13b6328..c8e829e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/FlyCommand.java @@ -31,11 +31,11 @@ private static int executeSetFly(CommandContext context, bo ServerPlayerEntity player = context.getSource().getPlayer(); if (set) { ClaimManager.INSTANCE.flyers.add(player.getUuid()); - player.sendSystemMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN)); + player.sendSystemMessage(new LiteralText("Enabled Ability to fly in Claims").formatted(Formatting.GREEN), player.getUuid()); return 1; } - player.sendSystemMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED)); + player.sendSystemMessage(new LiteralText("Disabled Ability to fly in Claims").formatted(Formatting.RED), player.getUuid()); ClaimManager.INSTANCE.flyers.remove(player.getUuid()); return -1; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java index 09b193b..6e0ec94 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/InfoCommand.java @@ -8,6 +8,7 @@ import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.Messages; import io.github.indicode.fabric.itsmine.util.TimeUtil; +import io.github.indicode.fabric.itsmine.util.WorldUtil; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.HoverEvent; import net.minecraft.text.LiteralText; @@ -25,7 +26,7 @@ public static void register(LiteralArgumentBuilder command, LiteralArgumentBuilder info = literal("info"); info.executes(context -> info( context.getSource(), - ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()) + ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension()) )); claim.executes(context -> info(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")) )); @@ -65,7 +66,7 @@ private static int info(ServerCommandSource source, Claim claim) throws CommandS .append(new LiteralText(" ")) .append(new LiteralText("Max ").formatted(Formatting.WHITE).append(max)))); text.append(pos); - text.append(newInfoLine("Dimension", new LiteralText(Registry.DIMENSION_TYPE.getId(claim.dimension).getPath()))); + text.append(newInfoLine("Dimension", new LiteralText(WorldUtil.getDimensionName(claim.dimension)))); if(claim.rent.isRented()){ GameProfile tenant = claim.rent.getTenant() == null ? null : source.getMinecraftServer().getUserCache().getByUuid(claim.rent.getTenant()); text.append(newInfoLine("Status", new LiteralText("Rented").formatted(Formatting.RED).styled(style -> { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java index 19ee119..5b50c63 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RemoveCommand.java @@ -30,7 +30,7 @@ public static void register(LiteralArgumentBuilder command, claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), admin)); claim.then(confirm); delete.then(claim); - delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), admin)); + delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension()), admin)); command.then(delete); } public static int requestDelete(ServerCommandSource sender, Claim claim, boolean admin) throws CommandSyntaxException { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java index 8ea93dc..e561704 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/RevenueCommand.java @@ -26,7 +26,7 @@ public class RevenueCommand { public static void register(LiteralArgumentBuilder command, RequiredArgumentBuilder claim) { LiteralArgumentBuilder revenue = literal("revenue"); RequiredArgumentBuilder claimRevenue = argument("claimRevenue", BoolArgumentType.bool()); - revenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), false)); + revenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension()), false)); revenue.requires(PERMISSION_CHECK_ADMIN); claim.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); claimRevenue.executes(context -> revenue(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java index 9d3a554..35fa22e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/ShowCommand.java @@ -26,7 +26,7 @@ public static void register(LiteralArgumentBuilder command) { RequiredArgumentBuilder mode = getShowMode(); LiteralArgumentBuilder show = literal("show"); - show.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), false)); + show.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension()), false)); RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); claim.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false)); mode.executes(context -> executeShowClaim(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), false, StringArgumentType.getString(context, "mode"))); @@ -57,7 +57,7 @@ public static int executeShowClaim(ServerCommandSource source, Claim claim, bool if (!reset && ((ClaimShower)player).getShownClaim() != null && !(!ItsMineConfig.main().claims2d &&((ClaimShower)player).getShownClaim() != claim)) executeShowClaim(source, ((ClaimShower)player).getShownClaim(), true, ((ClaimShower)player).getMode()); if (reset && ((ClaimShower)player).getShownClaim() != null) claim = ((ClaimShower)player).getShownClaim(); if (claim != null) { - if (!claim.dimension.equals(source.getWorld().getDimension().getType())) { + if (!claim.dimension.equals(source.getWorld().getDimension())) { if (claim == ((ClaimShower)player).getShownClaim()) ((ClaimShower)player).setShownClaim(null); // just so we dont have extra packets on this source.sendFeedback(new LiteralText("That claim is not in this dimension").formatted(Formatting.RED), false); return 0; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java index 69c4d3c..699657a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TransferCommand.java @@ -53,7 +53,7 @@ public static void register(LiteralArgumentBuilder command) player.then(confirm); claim.then(player); transfer.then(claim); - transfer.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), EntityArgumentType.getPlayer(context, "player"), false)); + transfer.executes(context -> requestTransfer(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension()), EntityArgumentType.getPlayer(context, "player"), false)); command.then(transfer); } @@ -63,8 +63,9 @@ public static int acceptTransfer(ServerCommandSource sender) throws CommandSynta sender.sendFeedback(new LiteralText("You have no pending claim transfers").formatted(Formatting.RED), false); return 0; } - if (sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner) != null) { - sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner).sendSystemMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW))); + ServerPlayerEntity player = sender.getMinecraftServer().getPlayerManager().getPlayer(claim.claimBlockOwner); + if (player != null) { + player.sendSystemMessage(new LiteralText("").append(new LiteralText(sender.getPlayer().getGameProfile().getName() + " has taken ownership of the claim \"" + claim.name + "\"").formatted(Formatting.YELLOW)), player.getUuid()); } Claim.ClaimPermissionMap op = claim.permissionManager.playerPermissions.get(claim.claimBlockOwner); claim.permissionManager.playerPermissions.put(claim.claimBlockOwner, claim.permissionManager.playerPermissions.get(sender.getPlayer().getGameProfile().getId())); @@ -140,7 +141,7 @@ private static int transfer(ServerCommandSource sender, Claim claim, ServerPlaye style.withBold(true); style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/claim transfer -accept-" + claim.name + " " + player.getEntityName() + " confirm")); return style; - }))); + })), player.getUuid()); pendingClaimTransfers.put(player.getGameProfile().getId(), claim.name); return 0; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java index 14a86fb..5791b33 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustCommand.java @@ -59,7 +59,7 @@ private static int executeTrust(CommandContext context, Col return 0; } ServerPlayerEntity p = context.getSource().getPlayer(); - Claim claim = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getBlockPos(), p.dimension) : ClaimManager.INSTANCE.claimsByName.get(claimName); + Claim claim = claimName == null ? ClaimManager.INSTANCE.getClaimAt(p.getBlockPos(), p.world.getDimension()) : ClaimManager.INSTANCE.claimsByName.get(claimName); validateClaim(claim); targetCollection.iterator().forEachRemaining(gameProfile -> { try { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java index db16f5f..e126dec 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/TrustedCommand.java @@ -26,7 +26,7 @@ public static void register(LiteralArgumentBuilder command) RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); trusted.executes((context)-> { ServerPlayerEntity player = context.getSource().getPlayer(); - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension()); if (claim == null) { context.getSource().sendError(Messages.INVALID_CLAIM); return -1; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java index 62afdc0..59dd894 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/EntitiesCommand.java @@ -29,7 +29,7 @@ public static void register(LiteralArgumentBuilder command) LiteralArgumentBuilder entity = literal("entities"); entity.requires(source -> ItsMine.permissions().hasPermission(source, PermissionUtil.Command.ADMIN_MODIFY, 2)); RequiredArgumentBuilder claim = ArgumentUtil.getClaims(); - entity.executes(context -> execute(context, ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension))); + entity.executes(context -> execute(context, ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().world.getDimension()))); claim.executes(context -> execute(context, ClaimManager.INSTANCE.getClaim(StringArgumentType.getString(context, "claim")))); entity.then(claim); command.then(entity); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java index 86e7b90..1b49151 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ExpandCommand.java @@ -26,7 +26,7 @@ public static void register(LiteralArgumentBuilder command) RequiredArgumentBuilder direction = getDirections(); direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension()), IntegerArgumentType.getInteger(context, "distance"), directionByName(getString(context, "direction")), context.getSource(), @@ -34,7 +34,7 @@ public static void register(LiteralArgumentBuilder command) )); amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension()), IntegerArgumentType.getInteger(context, "distance"), Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], context.getSource(), @@ -52,7 +52,7 @@ public static void register(LiteralArgumentBuilder command) RequiredArgumentBuilder direction = getDirections(); direction.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension()), -IntegerArgumentType.getInteger(context, "distance"), directionByName(getString(context, "direction")), context.getSource(), @@ -60,7 +60,7 @@ public static void register(LiteralArgumentBuilder command) )); amount.executes(context -> expand( - ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension().getType()), + ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getWorld().getDimension()), -IntegerArgumentType.getInteger(context, "distance"), Direction.getEntityFacingOrder(context.getSource().getPlayer())[0], context.getSource(), diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java index 3c04349..9bd1196 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/OwnerCommand.java @@ -27,7 +27,7 @@ public static void register(LiteralArgumentBuilder command) RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); newOwner.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); + Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().world.getDimension()); if (claim == null) { context.getSource().sendError(Messages.INVALID_CLAIM); return -1; @@ -69,7 +69,7 @@ public static void register(LiteralArgumentBuilder command) RequiredArgumentBuilder claimArgument = ArgumentUtil.getClaims(); nameArgument.executes((context) -> { - Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().dimension); + Claim claim = ClaimManager.INSTANCE.getClaimAt(context.getSource().getPlayer().getBlockPos(), context.getSource().getPlayer().world.getDimension()); if (claim == null) { context.getSource().sendFeedback(new LiteralText("That claim does not exist").formatted(Formatting.RED), false); return -1; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ReloadCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ReloadCommand.java index e7674f7..0c37e5a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ReloadCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/ReloadCommand.java @@ -6,6 +6,7 @@ import io.github.indicode.fabric.itsmine.ItsMine; import io.github.indicode.fabric.itsmine.ItsMineConfig; import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; import net.minecraft.util.Formatting; import org.apache.commons.lang3.time.StopWatch; @@ -23,12 +24,13 @@ public static void register(LiteralArgumentBuilder command) public static int execute(CommandContext context) throws CommandSyntaxException { + ServerPlayerEntity player = context.getSource().getPlayer(); StopWatch watch = new StopWatch(); watch.start(); ItsMine.reload(); watch.stop(); String timeElapsed = new DecimalFormat("##.##").format(watch.getTime(TimeUnit.MICROSECONDS)); - context.getSource().getPlayer().sendSystemMessage(new LiteralText("Reloaded! Took " + timeElapsed + "μs").formatted(Formatting.YELLOW)); + player.sendSystemMessage(new LiteralText("Reloaded! Took " + timeElapsed + "μs").formatted(Formatting.YELLOW), player.getUuid()); return 1; } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java index 5b2f809..20d2ac7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/admin/RemoveCommand.java @@ -24,7 +24,7 @@ public static void register(LiteralArgumentBuilder command) claim.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.claimsByName.get(getString(context, "claim")), true)); claim.then(confirm); delete.then(claim); - delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension().getType()), true)); + delete.executes(context -> requestDelete(context.getSource(), ClaimManager.INSTANCE.getClaimAt(new BlockPos(context.getSource().getPosition()), context.getSource().getWorld().getDimension()), true)); command.then(delete); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java index b6b91f4..186cebe 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/command/subzone/CreateCommand.java @@ -82,7 +82,7 @@ private static int addZone(ServerCommandSource source, String name, @Nullable St executeShowClaim(source, claim, false); source.sendFeedback(new LiteralText("").append(new LiteralText("Your subzone was created.").formatted(Formatting.GREEN)), false); }else{ - player.sendSystemMessage(new LiteralText("Your subzone would overlap with another subzone").formatted(Formatting.RED)); + player.sendSystemMessage(new LiteralText("Your subzone would overlap with another subzone").formatted(Formatting.RED), player.getUuid()); } if (subZone != null) { ClaimManager.INSTANCE.stickPositions.remove(player); @@ -90,7 +90,7 @@ private static int addZone(ServerCommandSource source, String name, @Nullable St } return 0; }else{ - player.sendSystemMessage(new LiteralText("Subzone must be inside the original claim, in the same dimension").formatted(Formatting.RED)); + player.sendSystemMessage(new LiteralText("Subzone must be inside the original claim, in the same dimension").formatted(Formatting.RED), player.getUuid()); } } return 0; @@ -126,12 +126,12 @@ private static Claim createSubzone(ServerCommandSource source, String name, Bloc BlockPos max = new BlockPos(mx, my, mz); BlockPos sub = max.subtract(min); sub = sub.add(1, ItsMineConfig.main().claims2d ? 0 : 1,1); - return new Claim(name, admin ? null : ownerID, min, max, source.getWorld().getDimension().getType(), source.getPlayer().getBlockPos(), true); + return new Claim(name, admin ? null : ownerID, min, max, source.getWorld().getDimension(), source.getPlayer().getBlockPos(), true); } private static Claim validateAndGet(ServerCommandSource source, @Nullable String claimName, boolean admin) throws CommandSyntaxException { ServerPlayerEntity player = source.getPlayer(); - Claim claim = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : + Claim claim = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension()) : ClaimManager.INSTANCE.claimsByName.get(claimName); if (claim == null) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java index 084872f..bfb739a 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AbstractFireBlockMixin.java @@ -14,7 +14,7 @@ public abstract class AbstractFireBlockMixin { @Redirect(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isFireImmune()Z")) private boolean neverGonnaBurnYouUp(Entity entity) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.dimension); + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension()); if (claim != null && !claim.flags.getFlag(ClaimFlags.Flag.FIRE_DAMAGE)) { return true; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java index 81dc142..35bd1bf 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/AnimalEntityMixin.java @@ -6,6 +6,7 @@ import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.util.ClaimUtil; +import io.github.indicode.fabric.itsmine.util.WorldUtil; import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.network.packet.s2c.play.TitleS2CPacket; import net.minecraft.server.network.ServerPlayerEntity; @@ -29,12 +30,13 @@ public abstract class AnimalEntityMixin { @Inject(method = "canBreedWith", at = @At(value = "HEAD"), cancellable = true) private void canBreed(AnimalEntity other, CallbackInfoReturnable cir){ World world = other.getEntityWorld(); - Claim claim = ClaimManager.INSTANCE.getClaimAt(other.getBlockPos(), other.dimension); + Claim claim = ClaimManager.INSTANCE.getClaimAt(other.getBlockPos(), other.world.getDimension()); if(claim != null){ if(claim.isChild){ claim = ClaimUtil.getParentClaim(claim); } - if(claim.getEntities(other.getEntityWorld().getServer().getWorld(other.getEntityWorld().getDimension().getType())) > 100){ +// if(claim.getEntities(other.getEntityWorld().getServer().getWorld(other.getEntityWorld().getDimension())) > 100){ + if(claim.getEntities(WorldUtil.getServerWorld(other.getEntityWorld().getDimension())) > 100){ ServerPlayerEntity player = this.getLovingPlayer(); if(player != null){ player.networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText("You reached the passive entity limit in your claim!").formatted(Formatting.RED), -1, ItsMineConfig.main().message().eventStayTicks, -1)); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java index 465b30a..67f8af0 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/BoatItemMixin.java @@ -31,11 +31,11 @@ private void dontSpawn(World world, PlayerEntity user, Hand hand, CallbackInfoRe ItemStack itemStack = user.getStackInHand(hand); HitResult hitResult = rayTrace(world, user, RayTraceContext.FluidHandling.ANY); Vec3d pos = hitResult.getPos(); - Claim claim = ClaimManager.INSTANCE.getClaimAt(new BlockPos(pos.getX(), pos.getY(), pos.getZ()), user.dimension); + Claim claim = ClaimManager.INSTANCE.getClaimAt(new BlockPos(pos.getX(), pos.getY(), pos.getZ()), user.world.getDimension()); if (claim != null){ if(!claim.hasPermission(user.getUuid(), Claim.Permission.BUILD) || !claim.hasPermission(user.getUuid(), Claim.Permission.SPAWN_BOAT)){ - user.sendSystemMessage(Messages.NO_PERMISSION); + user.sendSystemMessage(Messages.NO_PERMISSION, user.getUuid()); cir.setReturnValue(TypedActionResult.fail(itemStack)); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java index 42d7ad2..e29b880 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderDragonEntityMixin.java @@ -15,7 +15,7 @@ public class EnderDragonEntityMixin { @Redirect(method = "destroyBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) private boolean dontTouchieMyBlocksStupidDragon(World world, BlockPos pos, boolean move) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension()); if (claim != null && !claim.flags.getFlag(ClaimFlags.Flag.EXPLOSION_DESTRUCTION)) { return false; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java index bc7faf5..498c9eb 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EnderPearlItemMixin.java @@ -20,10 +20,10 @@ public class EnderPearlItemMixin { @Inject(method = "use", at = @At(value = "HEAD"), cancellable = true) private void modifyUse(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> cir) { ItemStack itemStack = user.getStackInHand(hand); - Claim claim = ClaimManager.INSTANCE.getClaimAt(user.getBlockPos(), user.dimension); + Claim claim = ClaimManager.INSTANCE.getClaimAt(user.getBlockPos(), user.world.getDimension()); if (claim != null && !claim.hasPermission(user.getUuid(), Claim.Permission.USE_ENDER_PEARL)) { - user.sendSystemMessage(Messages.MSG_CANT_USE); + user.sendSystemMessage(Messages.MSG_CANT_USE, user.getUuid()); cir.setReturnValue(TypedActionResult.fail(itemStack)); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java index 5f70cd0..f24ad2e 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/EntityMixin.java @@ -39,7 +39,7 @@ public abstract class EntityMixin { // if (!world.isClient && (Object)this instanceof PlayerEntity) { // PlayerEntity player = (PlayerEntity) (Object) this; // if (player.getBlockPos() == null) return; -// pclaim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension().getType()); +// pclaim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension()); // } // } // @Inject(method = "setPos", at = @At("RETURN")) @@ -47,7 +47,7 @@ public abstract class EntityMixin { // if (!world.isClient && (Object)this instanceof PlayerEntity) { // PlayerEntity player = (PlayerEntity) (Object) this; // if (player.getBlockPos() == null) return; -// Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension().getType()); +// Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension()); // if (pclaim != claim && player instanceof ServerPlayerEntity) { // ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity)player; // if (serverPlayerEntity.networkHandler != null) { @@ -88,7 +88,7 @@ public void doTickActions(CallbackInfo ci) { } boolean old = player.abilities.allowFlying; - Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension()); if (player instanceof ServerPlayerEntity) { if ( diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java index 36e224e..4447711 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ExplosionMixin.java @@ -24,7 +24,7 @@ public class ExplosionMixin { @Redirect(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;")) private BlockState theyCallMeBedrock(World world, BlockPos pos) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension()); if (claim != null && !world.isAir(pos) && !world.getBlockState(pos).getBlock().equals(Blocks.TNT)) { if (!claim.flags.getFlag(ClaimFlags.Flag.EXPLOSION_DESTRUCTION)) { return Blocks.BEDROCK.getDefaultState(); @@ -36,7 +36,7 @@ private BlockState theyCallMeBedrock(World world, BlockPos pos) { @Redirect(method = "collectBlocksAndDamageEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isImmuneToExplosion()Z")) private boolean claimDeniesExplosion(Entity entity) { BlockPos blockPos_1 = entity.getBlockPos(); - Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, entity.world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, entity.world.getDimension()); if (claim != null) { if (!claim.flags.getFlag(ClaimFlags.Flag.EXPLOSION_DAMAGE)) { return true; diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java index fe146c4..d3b3fa8 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FarmlandBlockMixin.java @@ -17,7 +17,7 @@ public abstract class FarmlandBlockMixin { @Inject(method = "onLandedUpon", at = @At(value = "HEAD", target = "Lnet/minecraft/block/FarmlandBlock;onLandedUpon(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;F)V"), cancellable = true) private void dontYouDareFarmMe(World world, BlockPos pos, Entity entity, float distance, CallbackInfo ci) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension()); if (claim != null && !claim.flags.getFlag(ClaimFlags.Flag.BREAK_FARMLANDS)) { ci.cancel(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java index 7a9f7e8..4ec5b1f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FireBlockMixin.java @@ -29,8 +29,8 @@ public abstract class FireBlockMixin { @Redirect(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/FireBlock;trySpreadingFire(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;ILjava/util/Random;I)V")) private void dontBurnClaims(FireBlock fireBlock, World world, BlockPos newPos, int int_1, Random random_1, int int_2, BlockState blockState_1, ServerWorld serverWorld_1, BlockPos oldPos, Random random_1_) { - Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension().getType()); - Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); + Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension()); + Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension()); if (oldClaim != newClaim) { if (oldClaim == null) { if (!newClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS)) return; @@ -46,8 +46,8 @@ else if (newClaim == null) { } @Redirect(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", ordinal = 1)) private boolean dontCauseFire2(ServerWorld world, BlockPos newPos, BlockState blockState_1, int int_1, BlockState blockState_1_, ServerWorld serverWorld_1, BlockPos oldPos, Random random_1_) { - Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension().getType()); - Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); + Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension()); + Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension()); if (oldClaim != newClaim) { if (oldClaim == null) { if (!newClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS)) @@ -74,11 +74,11 @@ private boolean dontCauseFire(World world, BlockPos oldPos, BlockState blockStat if (directions.isEmpty()) { return world.setBlockState(oldPos, blockState_1, int_1); } - Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension().getType()); + Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension()); Iterator iterator = directions.iterator(); for (Direction direction = iterator.next(); iterator.hasNext(); direction = iterator.next()) { BlockPos newPos = oldPos.offset(direction); - Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); + Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension()); if (oldClaim != newClaim) { if (oldClaim == null) { if (!newClaim.flags.getFlag(ClaimFlags.Flag.FIRE_CROSSES_BORDERS)) iterator.remove(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java index e0b814c..c46ed2f 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/FluidMixin.java @@ -23,8 +23,8 @@ public class FluidMixin { @Inject(method = "flow", at = @At("HEAD"), cancellable = true) private void dontFlow(WorldAccess world, BlockPos newPos, BlockState state, Direction direction, FluidState fluidState, CallbackInfo ci) { BlockPos oldPos = newPos.offset(direction.getOpposite()); - Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension().getType()); - Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); + Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension()); + Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension()); if (oldClaim != newClaim) { if (oldClaim == null) { if (!newClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS)) ci.cancel(); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java index 8cbbf8e..a85ce70 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LavaMixin.java @@ -26,8 +26,8 @@ public class LavaMixin { @Inject(method = "flow", at = @At("HEAD"), cancellable = true) private void dontFlow(WorldAccess world, BlockPos newPos, BlockState state, Direction direction, FluidState fluidState, CallbackInfo ci) { BlockPos oldPos = newPos.offset(direction.getOpposite()); - Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension().getType()); - Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); + Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension()); + Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension()); if (oldClaim != newClaim) { if (oldClaim == null) { if (!newClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS)) ci.cancel(); @@ -42,8 +42,8 @@ else if (newClaim == null) { } @Redirect(method = "onRandomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) public boolean neverGonnaBurnMeUp(World world, BlockPos newPos, BlockState blockState_1, World world_1, BlockPos oldPos, FluidState fluidState_1, Random random_1) { - Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension().getType()); - Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); + Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension()); + Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension()); if (oldClaim != newClaim) { if (oldClaim == null) { if (!newClaim.flags.getFlag(ClaimFlags.Flag.FLUID_CROSSES_BORDERS)) diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java index 7c987f7..09380e1 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/LevelStorageSessionMixin.java @@ -1,10 +1,9 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.ClaimManager; -import io.github.indicode.fabric.itsmine.ItsMine; -import net.minecraft.class_5219; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtIo; +import net.minecraft.world.SaveProperties; import net.minecraft.world.level.storage.LevelStorage; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -24,33 +23,38 @@ public class LevelStorageSessionMixin { private Path directory; @Inject(method = "readLevelProperties", at = @At("HEAD")) - public void readWorldProperties(CallbackInfoReturnable callbackInfo) { - ClaimManager.INSTANCE = new ClaimManager(); - File claims = new File(directory.toFile() + "/claims.dat"); - File claims_old = new File(directory.toFile() + "/claims.dat_old"); - if (!claims.exists()) { - if (claims_old.exists()) {} - else return; - } - try { - if (!claims.exists() && claims_old.exists()) throw new FileNotFoundException(); - ClaimManager.INSTANCE.fromNBT(NbtIo.readCompressed(new FileInputStream(claims))); - } catch (IOException e) { - System.out.println("Could not load " + claims.getName() + ":"); - e.printStackTrace(); - if (claims_old.exists()) { - System.out.println("Attempting to load backup claims..."); - try { - ClaimManager.INSTANCE.fromNBT(NbtIo.readCompressed(new FileInputStream(claims_old))); - } catch (IOException e2) { - throw new RuntimeException("Could not load claims.dat_old - Crashing server to save data. Remove or fix claims.dat or claims.dat_old to continue"); - } - } - } + public void readWorldProperties(CallbackInfoReturnable cir) { + System.out.println("LevelStorage.Session"); } + // @Inject(method = "readLevelProperties", at = @At("HEAD")) +// public void readWorldProperties() { +// ClaimManager.INSTANCE = new ClaimManager(); +// File claims = new File(directory.toFile() + "/claims.dat"); +// File claims_old = new File(directory.toFile() + "/claims.dat_old"); +// if (!claims.exists()) { +// if (claims_old.exists()) {} +// else return; +// } +// try { +// if (!claims.exists() && claims_old.exists()) throw new FileNotFoundException(); +// ClaimManager.INSTANCE.fromNBT(NbtIo.readCompressed(new FileInputStream(claims))); +// } catch (IOException e) { +// System.out.println("Could not load " + claims.getName() + ":"); +// e.printStackTrace(); +// if (claims_old.exists()) { +// System.out.println("Attempting to load backup claims..."); +// try { +// ClaimManager.INSTANCE.fromNBT(NbtIo.readCompressed(new FileInputStream(claims_old))); +// } catch (IOException e2) { +// throw new RuntimeException("Could not load claims.dat_old - Crashing server to save data. Remove or fix claims.dat or claims.dat_old to continue"); +// } +// } +// } +// } + @Inject(method = "method_27426", at = @At("HEAD")) - public void saveWorld(class_5219 levelProperties, CompoundTag compoundTag, CallbackInfo info) { + public void saveWorld(SaveProperties levelProperties, CompoundTag compoundTag, CallbackInfo info) { if (ClaimManager.INSTANCE != null) { File claimDataFile = new File(directory.toFile(), "claims.dat"); if (claimDataFile.exists()) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java new file mode 100644 index 0000000..1082f6a --- /dev/null +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/MinecraftServerMixin.java @@ -0,0 +1,19 @@ +package io.github.indicode.fabric.itsmine.mixin; + +import io.github.indicode.fabric.itsmine.util.ClaimUtil; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.WorldGenerationProgressListener; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(MinecraftServer.class) +public class MinecraftServerMixin { + + @Inject(method = "createWorlds", at = @At(value = "RETURN")) + private void loadClaims(WorldGenerationProgressListener worldGenerationProgressListener, CallbackInfo ci){ + ClaimUtil.readWorldProperties(); + } + +} diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java index 24f0d73..a9909eb 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PistonBlockMixin.java @@ -27,8 +27,8 @@ public class PistonBlockMixin { private static void youCantMoveMe(BlockState blockState_1, World world, BlockPos newPos, Direction direction, boolean boolean_1, Direction direction_2, CallbackInfoReturnable ci) { boolean pushing = direction == direction_2; BlockPos oldPos = newPos.offset(direction_2.getOpposite()); - Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension().getType()); - Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension().getType()); + Claim oldClaim = ClaimManager.INSTANCE.getClaimAt(oldPos, world.getDimension()); + Claim newClaim = ClaimManager.INSTANCE.getClaimAt(newPos, world.getDimension()); if (oldClaim != newClaim) { if (oldClaim == null) { if (!newClaim.flags.getFlag(ClaimFlags.Flag.PISTON_FROM_OUTSIDE)) ci.setReturnValue(false); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java index 0a37bbe..4e94c69 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlaceOnUseBlockMixin.java @@ -25,7 +25,7 @@ public PlaceOnUseBlockMixin(Settings settings) { @Redirect(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;canPlayerModifyAt(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;)Z")) public boolean canActuallyModify(World world, PlayerEntity playerEntity_1, BlockPos blockPos_1) { if (!(world instanceof ServerWorld)) return world.canPlayerModifyAt(playerEntity_1, blockPos_1); - Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, playerEntity_1.world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos_1, playerEntity_1.world.getDimension()); if (claim != null && !claim.hasPermission(playerEntity_1.getUuid(), Claim.Permission.BUILD)) { if ((Object) this instanceof LilyPadItem){ ((ServerWorld)world).getChunkManager().markForUpdate(blockPos_1); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java index 2b131ee..5fd1736 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/PlayerEntityMixin.java @@ -36,10 +36,10 @@ protected PlayerEntityMixin(EntityType entityType_1, Wor @Redirect(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;interact(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Z")) private boolean dontYouDareTouchMe(Entity entity, PlayerEntity playerEntity_1, Hand hand_1) { if (entity.world.isClient()) return entity.interact(playerEntity_1, hand_1); - Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension()); if (claim != null) { if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.INTERACT_ENTITY)) { - playerEntity_1.sendSystemMessage(Messages.MSG_INTERACT_ENTITY); + playerEntity_1.sendSystemMessage(Messages.MSG_INTERACT_ENTITY, playerEntity_1.getUuid()); return false; } } @@ -49,10 +49,10 @@ private boolean dontYouDareTouchMe(Entity entity, PlayerEntity playerEntity_1, H public void hittingIsRude(Entity entity, CallbackInfo ci) { if (entity.world.isClient()) return; PlayerEntity playerEntity_1 = (PlayerEntity)(Object)this; - Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension()); if (claim != null && !EntityUtil.canAttack(((PlayerEntity) (Object) this).getUuid(), claim, entity)) { - playerEntity_1.sendSystemMessage(Messages.MSG_DAMAGE_ENTITY); + playerEntity_1.sendSystemMessage(Messages.MSG_DAMAGE_ENTITY, playerEntity_1.getUuid()); ci.cancel(); } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java index 4960e85..8ae63f0 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ProjectileEntityMixin.java @@ -23,10 +23,10 @@ public boolean imInvincible(Entity entity, DamageSource damageSource_1, float fl if (((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()) != null) { PlayerEntity playerEntity_1 = ((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()); - Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension()); if (claim != null && entity != playerEntity_1) { if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY)) { - playerEntity_1.sendSystemMessage(Messages.MSG_DAMAGE_ENTITY); + playerEntity_1.sendSystemMessage(Messages.MSG_DAMAGE_ENTITY, playerEntity_1.getUuid()); projectile.kill(); // You do not want an arrow bouncing between two armor stands return false; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerCommandOutputMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerCommandOutputMixin.java index 80652fc..f7be583 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerCommandOutputMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerCommandOutputMixin.java @@ -1,6 +1,7 @@ package io.github.indicode.fabric.itsmine.mixin; import io.github.indicode.fabric.itsmine.ClaimManager; +import io.github.indicode.fabric.itsmine.util.ClaimUtil; import net.minecraft.server.MinecraftServer; import net.minecraft.server.dedicated.ServerCommandOutput; import org.spongepowered.asm.mixin.Mixin; @@ -13,6 +14,8 @@ public abstract class ServerCommandOutputMixin { @Inject(method = "", at = @At("RETURN")) private void saveInstance(MinecraftServer server, CallbackInfo ci) { + System.out.println("ServerCommandOutput"); + ClaimManager.INSTANCE = new ClaimManager(); ClaimManager.INSTANCE.server = server; } } \ No newline at end of file diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java index b59acd7..164707b 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayNetworkHandlerMixin.java @@ -23,7 +23,7 @@ public class ServerPlayNetworkHandlerMixin { @Redirect(method = "onPlayerInteractEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;interactAt(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;")) public ActionResult iSaidDontTouchMe(Entity entity, PlayerEntity playerEntity_1, Vec3d vec3d_1, Hand hand_1) { - Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getBlockPos(), entity.world.getDimension()); if (claim != null) { if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.INTERACT_ENTITY)) { // playerEntity_1.sendSystemMessage(Messages.MSG_INTERACT_ENTITY); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java index bf30d00..86b6089 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerPlayerInteractionManagerMixin.java @@ -53,13 +53,13 @@ private void getBlock(ServerPlayerEntity serverPlayerEntity, World world, ItemSt private ActionResult interactIfPossible(BlockState blockState, World world, PlayerEntity player, Hand hand, BlockHitResult hit){ BlockPos pos = hit.getBlockPos(); ItemStack itemStack = player.getMainHandStack(); - Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, player.world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, player.world.getDimension()); if (claim != null) { if (!Functions.canInteractWith(claim, blockState.getBlock(), player.getUuid())) { if (!itemStack.isEmpty() && !(itemStack.getItem() instanceof BlockItem)) { - player.sendSystemMessage(Messages.MSG_INTERACT_BLOCK); + player.sendSystemMessage(Messages.MSG_INTERACT_BLOCK, player.getUuid()); } else if (BlockUtil.isContainer(blockState.getBlock())) { - player.sendSystemMessage(Messages.MSG_OPEN_CONTAINER); + player.sendSystemMessage(Messages.MSG_OPEN_CONTAINER, player.getUuid()); } return ActionResult.FAIL; @@ -79,13 +79,13 @@ private ActionResult interactIfPossible(BlockState blockState, World world, Play private boolean interactWithItemIfPossible(ItemStack stack) { // BlockPos pos = hitResult.getBlockPos().offset(hitResult.getSide()); // System.out.println(blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ()); - Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos, world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(blockPos, world.getDimension()); if (claim != null && !stack.isEmpty()) { if (Functions.canInteractUsingItem(claim, stack.getItem(), player.getUuid())) { return false; } if (stack.getItem() instanceof BlockItem) { - player.sendSystemMessage(Messages.MSG_PLACE_BLOCK); + player.sendSystemMessage(Messages.MSG_PLACE_BLOCK, player.getUuid()); } return true; @@ -102,22 +102,22 @@ public boolean canBreak(ServerWorld world, PlayerEntity player, BlockPos pos) { if (posPair != null) { posPair = new Pair<>(posPair.getLeft(), pos); ClaimManager.INSTANCE.stickPositions.put(player, posPair); - player.sendSystemMessage(new LiteralText("Position #2 set: " + pos.getX() + (ItsMineConfig.main().claims2d ? "" : " " + pos.getY()) + " " + pos.getZ()).formatted(Formatting.GREEN)); + player.sendSystemMessage(new LiteralText("Position #2 set: " + pos.getX() + (ItsMineConfig.main().claims2d ? "" : " " + pos.getY()) + " " + pos.getZ()).formatted(Formatting.GREEN), player.getUuid()); if (posPair.getLeft() != null) { - player.sendSystemMessage(new LiteralText("Area Selected. Type /claim create to create your claim!").formatted(Formatting.GOLD)); + player.sendSystemMessage(new LiteralText("Area Selected. Type /claim create to create your claim!").formatted(Formatting.GOLD), player.getUuid()); if (!ItsMineConfig.main().claims2d) - player.sendSystemMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE).formatted(Formatting.ITALIC)); + player.sendSystemMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE).formatted(Formatting.ITALIC), player.getUuid()); } return false; } } } - Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, player.world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, player.world.getDimension()); if (claim != null) { UUID uuid = player.getGameProfile().getId(); if (!claim.hasPermission(uuid, Claim.Permission.BUILD)) { // MessageUtil.sendText(ItsMineConfig.main().message().breakBlock); - player.sendSystemMessage(Messages.MSG_BREAK_BLOCK); + player.sendSystemMessage(Messages.MSG_BREAK_BLOCK, player.getUuid()); return false; } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java index 7134902..4ed0d03 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/ServerWorldMixin.java @@ -4,8 +4,6 @@ import io.github.indicode.fabric.itsmine.ClaimPlayerEntity; import io.github.indicode.fabric.itsmine.Functions; import io.github.indicode.fabric.itsmine.MonitorableWorld; -import net.minecraft.class_5269; -import net.minecraft.class_5321; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.Packet; @@ -15,6 +13,8 @@ import net.minecraft.text.LiteralText; import net.minecraft.util.Formatting; import net.minecraft.util.profiler.Profiler; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.MutableWorldProperties; import net.minecraft.world.World; import net.minecraft.world.dimension.DimensionType; import org.spongepowered.asm.mixin.Final; @@ -40,18 +40,21 @@ public abstract class ServerWorldMixin extends World implements MonitorableWorld @Final private Map entitiesByUuid; - protected ServerWorldMixin(class_5269 arg, DimensionType dimensionType, Supplier supplier, boolean bl, boolean bl2, long l) { - super(arg, dimensionType, supplier, bl, bl2, l); + protected ServerWorldMixin(MutableWorldProperties mutableWorldProperties, DimensionType dimensionType, Supplier supplier, boolean bl, boolean bl2, long l) { + super(mutableWorldProperties, dimensionType, supplier, bl, bl2, l); } + @Shadow public abstract List getPlayers(); - @Redirect(method = "processSyncedBlockEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;sendToAround(Lnet/minecraft/entity/player/PlayerEntity;DDDDLnet/minecraft/world/dimension/DimensionType;Lnet/minecraft/network/Packet;)V")) - private void sendPistonUpdate(PlayerManager manager, PlayerEntity playerEntity_1, double double_1, double double_2, double double_3, double double_4, class_5321 dimensionType_1, Packet packet_1) { + @Redirect(method = "processSyncedBlockEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;sendToAround(Lnet/minecraft/entity/player/PlayerEntity;DDDDLnet/minecraft/util/registry/RegistryKey;Lnet/minecraft/network/Packet;)V")) + private void sendPistonUpdate(PlayerManager manager, PlayerEntity playerEntity_1, double double_1, double double_2, double double_3, double double_4, RegistryKey dimensionType_1, Packet packet_1) { manager.sendToAround(playerEntity_1, double_1, double_2, double_3, double_4, this.method_27983(), packet_1); Functions.doPistonUpdate((ServerWorld) (Object)this, packet_1); } + + @Inject(method = "tick", at = @At(value = "RETURN")) public void tickActions(BooleanSupplier shouldKeepTicking, CallbackInfo ci){ ClaimManager.INSTANCE.claimsByName.forEach((s, claim) ->{ diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java index f78b20f..937804d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/SpawnRestrictionMixin.java @@ -23,7 +23,7 @@ private static void canSpawnInClaim(EntityType type, WorldAccess world, Spawn cir.setReturnValue(false); return; } - Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension().getType()); + Claim claim = ClaimManager.INSTANCE.getClaimAt(pos, world.getDimension()); if (claim != null && !claim.flags.getFlag(ClaimFlags.Flag.MOB_SPAWNING)) { cir.setReturnValue(false); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java index cd03568..3c3ccb5 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/StickClaimItemMixin.java @@ -2,9 +2,11 @@ import io.github.indicode.fabric.itsmine.ClaimManager; import io.github.indicode.fabric.itsmine.ItsMineConfig; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemUsageContext; import net.minecraft.item.Items; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; import net.minecraft.util.ActionResult; import net.minecraft.util.Formatting; @@ -20,17 +22,18 @@ public class StickClaimItemMixin { @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) // private void setStickPositionFirst(ItemUsageContext context, CallbackInfoReturnable cir) { private void setStickPositionFirst(ItemUsageContext context, CallbackInfoReturnable cir) { + PlayerEntity player = context.getPlayer(); if (context.getWorld().isClient) return; - if (!context.getPlayer().isSneaking()) { + if (!player.isSneaking()) { if ((Object)this == Items.STICK) { Pair posPair = ClaimManager.INSTANCE.stickPositions.get(context.getPlayer()); if (posPair == null) return; else posPair = new Pair<>(context.getBlockPos(), posPair.getRight()); ClaimManager.INSTANCE.stickPositions.put(context.getPlayer(), posPair); - context.getPlayer().sendSystemMessage(new LiteralText("Position #1 set: " + context.getBlockPos().getX() + (ItsMineConfig.main().claims2d ? "" : " " + context.getBlockPos().getY()) + " " + context.getBlockPos().getZ()).formatted(Formatting.GREEN)); + context.getPlayer().sendSystemMessage(new LiteralText("Position #1 set: " + context.getBlockPos().getX() + (ItsMineConfig.main().claims2d ? "" : " " + context.getBlockPos().getY()) + " " + context.getBlockPos().getZ()).formatted(Formatting.GREEN), player.getUuid()); if (posPair.getRight() != null) { - context.getPlayer().sendSystemMessage(new LiteralText("Area Selected. Type /claim create to create your claim!").formatted(Formatting.GOLD)); - if (!ItsMineConfig.main().claims2d) context.getPlayer().sendSystemMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE).formatted(Formatting.ITALIC)); + player.sendSystemMessage(new LiteralText("Area Selected. Type /claim create to create your claim!").formatted(Formatting.GOLD), player.getUuid()); + if (!ItsMineConfig.main().claims2d) player.sendSystemMessage(new LiteralText("Remember that claims are three dimensional. Don't forget to expand up/down or select a big enough area...").formatted(Formatting.LIGHT_PURPLE).formatted(Formatting.ITALIC), player.getUuid()); } cir.setReturnValue(ActionResult.SUCCESS); } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java index a16494f..e6f9c15 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/mixin/projectile/ProjectileEntityMixin.java @@ -30,7 +30,7 @@ private void imInvincible(ProjectileEntity projectileEntity, EntityHitResult ent this.onEntityHit(entityHitResult); } else { if (this.getOwner() instanceof PlayerEntity) { - this.getOwner().sendSystemMessage(Messages.MSG_DAMAGE_ENTITY); + this.getOwner().sendSystemMessage(Messages.MSG_DAMAGE_ENTITY, this.getOwner().getUuid()); if(projectileEntity.getType() == EntityType.ARROW){ projectileEntity.kill(); } @@ -44,7 +44,7 @@ private void imInvincible(ProjectileEntity projectileEntity, EntityHitResult ent // // if (((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()) != null) { // PlayerEntity playerEntity_1 = ((ProjectileEntity)(Object)this).getServer().getPlayerManager().getPlayer(((OwnedProjectile)projectile).getOwner()); -// Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension().getType()); +// Claim claim = ClaimManager.INSTANCE.getClaimAt(entity.getSenseCenterPos(), entity.world.getDimension()); // if (claim != null && entity != playerEntity_1) { // if (!claim.hasPermission(playerEntity_1.getGameProfile().getId(), Claim.Permission.DAMAGE_ENTITY)) { // playerEntity_1.sendSystemMessage(Messages.MSG_DAMAGE_ENTITY); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java index dd7b2f9..60b632d 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ArgumentUtil.java @@ -88,7 +88,7 @@ private static CompletableFuture claimSubzoneProvider(CommandContex private static CompletableFuture claimProvider(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { ServerPlayerEntity player = context.getSource().getPlayer(); List names = new ArrayList<>(); - Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension()); if (current != null && !current.isChild) names.add(current.name); for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { if (claim != null && !claim.isChild) { @@ -101,7 +101,7 @@ private static CompletableFuture claimProvider(CommandContext subzoneProvider(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { ServerPlayerEntity player = context.getSource().getPlayer(); List names = new ArrayList<>(); - Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension); + Claim current = ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension()); if (current != null && current.isChild) names.add(current.name); for (Claim claim : ClaimManager.INSTANCE.getPlayerClaims(player.getGameProfile().getId())) { if (claim != null && claim.isChild) { diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java index 2d8d61e..8b7a0e9 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ClaimUtil.java @@ -7,6 +7,7 @@ import io.github.indicode.fabric.itsmine.*; import io.github.indicode.fabric.itsmine.claim.Claim; import io.github.indicode.fabric.itsmine.claim.ClaimFlags; +import net.minecraft.nbt.NbtIo; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.LiteralText; @@ -14,6 +15,10 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicReference; @@ -116,7 +121,7 @@ public static int queryFlags(ServerCommandSource source, Claim claim) { } public static int executeFlag(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { ServerPlayerEntity player = source.getPlayer(); - Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : + Claim claim1 = claimName == null || claimName.isEmpty() ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension()) : ClaimManager.INSTANCE.claimsByName.get(claimName); if (claim1 == null) { source.sendError(Messages.INVALID_CLAIM); @@ -142,7 +147,7 @@ public static int executeFlag(ServerCommandSource source, String input, @Nullabl } public static int executePermission(ServerCommandSource source, String input, @Nullable String claimName, boolean isQuery, boolean value, boolean admin) throws CommandSyntaxException { ServerPlayerEntity player = source.getPlayer(); - Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.dimension) : + Claim claim1 = claimName == null ? ClaimManager.INSTANCE.getClaimAt(player.getBlockPos(), player.world.getDimension()) : ClaimManager.INSTANCE.claimsByName.get(claimName); if (claim1 == null) { source.sendError(Messages.INVALID_CLAIM); @@ -198,4 +203,28 @@ public static int setEventMessage(ServerCommandSource source, Claim claim, Claim return 1; } + public static void readWorldProperties() { + File claims = new File(ItsMine.getDirectory() + "/world/claims.dat"); + File claims_old = new File(ItsMine.getDirectory() + "/world/claims.dat_old"); + if (!claims.exists()) { + if (claims_old.exists()) {} + else return; + } + try { + if (!claims.exists() && claims_old.exists()) throw new FileNotFoundException(); + ClaimManager.INSTANCE.fromNBT(NbtIo.readCompressed(new FileInputStream(claims))); + } catch (IOException e) { + System.out.println("Could not load " + claims.getName() + ":"); + e.printStackTrace(); + if (claims_old.exists()) { + System.out.println("Attempting to load backup claims..."); + try { + ClaimManager.INSTANCE.fromNBT(NbtIo.readCompressed(new FileInputStream(claims_old))); + } catch (IOException e2) { + throw new RuntimeException("Could not load claims.dat_old - Crashing server to save data. Remove or fix claims.dat or claims.dat_old to continue"); + } + } + } + } + } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java index 7c3ad9c..36ddcc7 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/EntityUtil.java @@ -13,7 +13,6 @@ import java.util.Map; import java.util.UUID; -import static io.github.indicode.fabric.itsmine.util.WorldUtil.getServerWorld; public class EntityUtil { @@ -33,7 +32,7 @@ public static boolean isHostile(Entity entity) { public static ArrayList getEntities(Claim claim){ ArrayList entityList = new ArrayList<>(); - ServerWorld world = getServerWorld(claim.dimension); + ServerWorld world = WorldUtil.getServerWorld(claim.dimension); MonitorableWorld monitorableWorld = (MonitorableWorld) world; monitorableWorld.EntityList().forEach((uuid, entity) -> { if(claim.includesPosition(entity.getBlockPos())) entityList.add(entity); diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java index a0aba8e..2526cd9 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/ShowerUtil.java @@ -53,7 +53,7 @@ private static void show(ServerPlayerEntity player, Claim claim, boolean hide, B showCorner(player, claim, state);break; } default: { - player.sendSystemMessage(new LiteralText("Unknown mode").formatted(Formatting.RED)); + player.sendSystemMessage(new LiteralText("Unknown mode").formatted(Formatting.RED), player.getUuid()); } } } diff --git a/src/main/java/io/github/indicode/fabric/itsmine/util/WorldUtil.java b/src/main/java/io/github/indicode/fabric/itsmine/util/WorldUtil.java index 3bce1e0..7613530 100644 --- a/src/main/java/io/github/indicode/fabric/itsmine/util/WorldUtil.java +++ b/src/main/java/io/github/indicode/fabric/itsmine/util/WorldUtil.java @@ -1,13 +1,90 @@ package io.github.indicode.fabric.itsmine.util; +import com.google.common.collect.Lists; import io.github.indicode.fabric.itsmine.ClaimManager; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.dimension.DimensionType; +import java.util.ArrayList; +import java.util.List; + public class WorldUtil { + private static MinecraftServer server(){ + return ClaimManager.INSTANCE.server; + } + private static final List> registryKeys = Lists.newArrayList(); + + private static RegistryKey DEFAULT = DimensionType.OVERWORLD_REGISTRY_KEY; + private static DimensionType DEFAULT_DIMENSION = DimensionType.getDefaultDimensionType(); + public static ServerWorld getServerWorld(DimensionType dimensionType){ - return ClaimManager.INSTANCE.server.getWorld(dimensionType); + return server().getWorld(getRegistry(dimensionType)); + } + + + public static String getDimensionName(DimensionType dimensionType){ + return getRegistry(dimensionType).getValue().getPath(); + } + + public static String getDimensionNameWithNameSpace(DimensionType dimensionType){ + return getRegistry(dimensionType).getValue().getNamespace() + ":" + getDimensionName(dimensionType); + } + + public static String[] getNameSpaceAndName(String string){ + return string.split(":"); + } + + + public static DimensionType getDimensionType(String dimension){ +/* if(dimension.matches("[a-z_]+:[a-z_]+")){ + System.out.println("Trying to convert " + dimension); + return getDimensionType(getNameSpaceAndName(dimension)[1]); + } else {*/ + for(RegistryKey registryKey : getDimensionKeys()){ + System.out.println(registryKey); + if(dimension.equalsIgnoreCase(registryKey.getValue().getNamespace() + ":" + registryKey.getValue().getPath())){ + DimensionType dimensionType = server().getWorld(registryKey).getDimension(); + return dimensionType; + } else { + } + } + /*}*/ + return DEFAULT_DIMENSION; + } + + public static RegistryKey getRegistry(DimensionType dimensionType){ + for(RegistryKey registryKey : getDimensionKeys()){ + DimensionType dimension = server().getWorld(registryKey).getDimension(); + if(dimension.equals(dimensionType)){ + return registryKey; + } + } + return DEFAULT; + } + +/* public static ArrayList> getRegistries(){ + ArrayList> registryKeys = new ArrayList<>(); + System.out.println("getRegistries"); + server().method_29174().getRegistry().getIds().forEach(identifier -> { + System.out.println("Identfier " + identifier); + registryKeys.add(RegistryKey.of(Registry.DIMENSION_TYPE_KEY, identifier)); + }); + return registryKeys; + }*/ + + public static List> getDimensionKeys() { + return registryKeys; + } + + static { + for (Identifier id : server().method_29174().getRegistry().getIds()) { + registryKeys.add(RegistryKey.of(Registry.DIMENSION_TYPE_KEY, id)); + } } } diff --git a/src/main/resources/itsmine.mixins.json b/src/main/resources/itsmine.mixins.json index 36a21d1..89a17cb 100644 --- a/src/main/resources/itsmine.mixins.json +++ b/src/main/resources/itsmine.mixins.json @@ -32,7 +32,8 @@ "EnderDragonEntityMixin", "FarmlandBlockMixin", "BoatItemMixin", - "ServerCommandOutputMixin" + "ServerCommandOutputMixin", + "MinecraftServerMixin" ], "injectors": { "defaultRequire": 1