From 36644fd3393ae05198d073cf5bd8df83bc6ea8b3 Mon Sep 17 00:00:00 2001 From: 7873930+GStefanowich <7873930+GStefanowich@users.noreply.github.com> Date: Thu, 17 Jun 2021 14:58:22 -0400 Subject: [PATCH] Bug fixes and tweaks Updated the version number Fixed issue with gradient display names not displaying properly in certain places Added command tooltip hints to the "/nick" command colors Changed the "/sewingmachine" command to "/sewing-machine" (Uses the mod ID) Added more @NotNull and @Nullable method attributes "/tpa" command will no longer show coordinates in tooltips if warping is not allowed --- gradle.properties | 2 +- .../ArgumentTypes/ArgumentSuggestions.java | 36 ++++++++++++- .../TheElm/project/commands/ModCommands.java | 6 +-- .../TheElm/project/commands/MoneyCommand.java | 38 +++++++------- .../project/commands/PermissionCommand.java | 2 +- .../project/commands/TeleportsCommand.java | 11 +++- .../project/commands/WaystoneCommand.java | 11 +++- .../net/TheElm/project/enums/ShopSigns.java | 6 +-- .../TheElm/project/mixins/Commands/Me.java | 2 +- .../mixins/Entities/Decorative/CatDye.java | 2 +- .../mixins/Player/ClientInteraction.java | 2 +- .../project/mixins/Player/FullInventory.java | 2 +- .../mixins/Player/Interaction/ItemPickup.java | 6 +-- .../TheElm/project/objects/ChatFormat.java | 8 +-- .../project/objects/PlayerBackpack.java | 2 +- .../protections/claiming/Claimant.java | 7 +-- .../protections/claiming/ClaimantPlayer.java | 4 +- .../TheElm/project/utilities/BlockUtils.java | 11 ++++ .../TheElm/project/utilities/ChunkUtils.java | 20 ++++--- .../TheElm/project/utilities/ColorUtils.java | 4 +- .../project/utilities/DimensionUtils.java | 16 ++++-- .../project/utilities/PlayerNameUtils.java | 13 +++-- .../project/utilities/RegistryUtils.java | 2 +- .../TheElm/project/utilities/SleepUtils.java | 4 +- .../TheElm/project/utilities/WarpUtils.java | 52 ++++++++++++------- .../project/utilities/text/MessageUtils.java | 11 ++-- 26 files changed, 188 insertions(+), 92 deletions(-) diff --git a/gradle.properties b/gradle.properties index 9615c2d..5faa3b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx2G loader_version=0.11.0 # Mod Properties - mod_version = 1.3.2 + mod_version = 1.3.3 maven_group = net.fabricmc archives_base_name = theelm-mod diff --git a/src/main/java/net/TheElm/project/commands/ArgumentTypes/ArgumentSuggestions.java b/src/main/java/net/TheElm/project/commands/ArgumentTypes/ArgumentSuggestions.java index 7c4718b..85a1387 100644 --- a/src/main/java/net/TheElm/project/commands/ArgumentTypes/ArgumentSuggestions.java +++ b/src/main/java/net/TheElm/project/commands/ArgumentTypes/ArgumentSuggestions.java @@ -31,13 +31,20 @@ import net.TheElm.project.enums.Permissions; import net.TheElm.project.utilities.ColorUtils; import net.TheElm.project.utilities.RankUtils; +import net.TheElm.project.utilities.text.StyleApplicator; import net.minecraft.command.CommandSource; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; import org.jetbrains.annotations.NotNull; +import java.util.AbstractMap; +import java.util.Collection; +import java.util.Locale; +import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; public class ArgumentSuggestions { - public static @NotNull CompletableFuture suggestNodes(@NotNull CommandContext context, @NotNull SuggestionsBuilder builder) { return CommandSource.suggestMatching(Permissions.keys(), builder); } @@ -47,7 +54,32 @@ public class ArgumentSuggestions { } public static @NotNull CompletableFuture suggestColors(@NotNull CommandContext context, @NotNull SuggestionsBuilder builder) { - return CommandSource.suggestMatching(ColorUtils.getSuggestedNames(), builder); + return ArgumentSuggestions.suggest(ColorUtils.COLORS.entrySet().stream().map(stringColorEntry -> { + Text tooltip = new LiteralText(stringColorEntry.getKey()) + .styled(new StyleApplicator(ColorUtils.getNearestTextColor(stringColorEntry.getValue()))); + return new AbstractMap.SimpleEntry<>(stringColorEntry.getKey(), tooltip); + }), builder); } + public static @NotNull CompletableFuture suggest(@NotNull Collection> suggestions, @NotNull SuggestionsBuilder builder) { + String remaining = builder.getRemaining().toLowerCase(Locale.ROOT); + + for (Map.Entry suggestion : suggestions) { + String name = suggestion.getKey(); + if (CommandSource.method_27136(remaining, name.toLowerCase(Locale.ROOT))) + builder.suggest(name); + } + + return builder.buildFuture(); + } + public static @NotNull CompletableFuture suggest(@NotNull Stream> suggestions, @NotNull SuggestionsBuilder builder) { + String remaining = builder.getRemaining().toLowerCase(Locale.ROOT); + + suggestions.filter((suggestion) -> { + String name = suggestion.getKey(); + return CommandSource.method_27136(remaining, name.toLowerCase(Locale.ROOT)); + }).forEach(pair -> builder.suggest(pair.getKey(), pair.getValue())); + + return builder.buildFuture(); + } } diff --git a/src/main/java/net/TheElm/project/commands/ModCommands.java b/src/main/java/net/TheElm/project/commands/ModCommands.java index 7628e1c..83aeb70 100644 --- a/src/main/java/net/TheElm/project/commands/ModCommands.java +++ b/src/main/java/net/TheElm/project/commands/ModCommands.java @@ -52,7 +52,7 @@ private ModCommands() { } public static void register(@NotNull CommandDispatcher dispatcher) { - ServerCore.register(dispatcher, "SewingMachine", (builder) -> builder + ServerCore.register(dispatcher, CoreMod.MOD_ID, (builder) -> builder .requires(CommandUtils.requires(OpLevels.STOP)) .then(CommandManager.literal("reload") .then(CommandManager.literal("config") @@ -63,9 +63,9 @@ public static void register(@NotNull CommandDispatcher disp .executes(ModCommands::reloadPermissions) ) ) - .then(CommandManager.literal("fix-shop") + /*.then(CommandManager.literal("fix-shop") .executes(ModCommands::repairShopSign) - ) + )*/ ); } diff --git a/src/main/java/net/TheElm/project/commands/MoneyCommand.java b/src/main/java/net/TheElm/project/commands/MoneyCommand.java index 95acdc5..9985369 100644 --- a/src/main/java/net/TheElm/project/commands/MoneyCommand.java +++ b/src/main/java/net/TheElm/project/commands/MoneyCommand.java @@ -66,7 +66,7 @@ public final class MoneyCommand { private MoneyCommand() {} - public static void register(CommandDispatcher dispatcher) { + public static void register(@NotNull CommandDispatcher dispatcher) { /* * Player Pay */ @@ -86,24 +86,24 @@ public static void register(CommandDispatcher dispatcher) { ServerCore.register(dispatcher, "money", builder -> builder .requires((source) -> SewConfig.get(SewConfig.DO_MONEY)) // Admin GIVE money (Adds money) - .then( CommandManager.literal("give" ) + .then(CommandManager.literal("give") // If player is OP .requires((resource) -> resource.hasPermissionLevel(OpLevels.CHEATING)) - .then( CommandManager.argument( "amount", IntegerArgumentType.integer( 0 ) ) - .then( CommandManager.argument( "player", GameProfileArgumentType.gameProfile() ) - .suggests( CommandUtils::getAllPlayerNames ) - .executes( MoneyCommand::commandAdminGive ) + .then(CommandManager.argument("amount", IntegerArgumentType.integer(0)) + .then(CommandManager.argument("player", GameProfileArgumentType.gameProfile()) + .suggests(CommandUtils::getAllPlayerNames) + .executes(MoneyCommand::commandAdminGive) ) ) ) // Admin TAKES money (Removes money) - .then( CommandManager.literal( "take" ) + .then( CommandManager.literal("take") // If player is OP .requires((resource) -> resource.hasPermissionLevel(OpLevels.CHEATING)) - .then( CommandManager.argument( "amount", IntegerArgumentType.integer( 0 ) ) - .then( CommandManager.argument( "player", GameProfileArgumentType.gameProfile() ) - .suggests( CommandUtils::getAllPlayerNames ) - .executes( MoneyCommand::commandAdminTake ) + .then(CommandManager.argument("amount", IntegerArgumentType.integer(0)) + .then(CommandManager.argument("player", GameProfileArgumentType.gameProfile()) + .suggests(CommandUtils::getAllPlayerNames) + .executes(MoneyCommand::commandAdminTake) ) ) ) @@ -147,7 +147,7 @@ public static void register(CommandDispatcher dispatcher) { /* * Admin commands */ - private static int commandAdminGive(CommandContext context) throws CommandSyntaxException { + private static int commandAdminGive(@NotNull CommandContext context) throws CommandSyntaxException { // Get the reference of the player to modify Collection argumentType = GameProfileArgumentType.getProfileArgument( context, "player" ); GameProfile target = argumentType.stream().findAny().orElseThrow(GameProfileArgumentType.UNKNOWN_PLAYER_EXCEPTION::create); @@ -181,7 +181,7 @@ private static int commandAdminGive(CommandContext context) return Command.SINGLE_SUCCESS; } - private static int commandAdminTake(CommandContext context) throws CommandSyntaxException { + private static int commandAdminTake(@NotNull CommandContext context) throws CommandSyntaxException { // Get the reference of the player to modify Collection argumentType = GameProfileArgumentType.getProfileArgument( context, "player" ); GameProfile target = argumentType.stream().findAny().orElseThrow(GameProfileArgumentType.UNKNOWN_PLAYER_EXCEPTION::create); @@ -218,7 +218,7 @@ private static int commandAdminTake(CommandContext context) return Command.SINGLE_SUCCESS; } - private static int commandAdminSet(CommandContext context) throws CommandSyntaxException { + private static int commandAdminSet(@NotNull CommandContext context) throws CommandSyntaxException { // Get the reference of the player to modify Collection argumentType = GameProfileArgumentType.getProfileArgument( context, "player" ); GameProfile target = argumentType.stream().findAny().orElseThrow(GameProfileArgumentType.UNKNOWN_PLAYER_EXCEPTION::create); @@ -252,7 +252,7 @@ private static int commandAdminSet(CommandContext context) return Command.SINGLE_SUCCESS; } - private static int commandAdminReset(CommandContext context) throws CommandSyntaxException { + private static int commandAdminReset(@NotNull CommandContext context) throws CommandSyntaxException { // Get the reference of the player to modify Collection argumentType = GameProfileArgumentType.getProfileArgument( context, "player" ); GameProfile target = argumentType.stream().findAny().orElseThrow(GameProfileArgumentType.UNKNOWN_PLAYER_EXCEPTION::create); @@ -281,7 +281,7 @@ private static int commandAdminReset(CommandContext context /* * Player commands */ - private static int commandMoneyPay(CommandContext context) throws CommandSyntaxException { + private static int commandMoneyPay(@NotNull CommandContext context) throws CommandSyntaxException { ServerCommandSource commandSource = context.getSource(); // Get the reference of the player to pay @@ -319,7 +319,7 @@ private static int commandMoneyPay(CommandContext context) return MoneyCommand.commandMoneyGet( context ); } - private static int commandMoneyRequest(CommandContext context) throws CommandSyntaxException { + private static int commandMoneyRequest(@NotNull CommandContext context) throws CommandSyntaxException { ServerCommandSource source = context.getSource(); // Get the reference of the player to request money from @@ -331,7 +331,7 @@ private static int commandMoneyRequest(CommandContext conte ServerPlayerEntity target = source.getMinecraftServer().getPlayerManager().getPlayer( targetProfile.getId() ); // Get the amount to request - int amount = IntegerArgumentType.getInteger( context, "amount" ); + int amount = IntegerArgumentType.getInteger(context, "amount"); if (target == null) { // Player not online throw PLAYER_NOT_FOUND.create( player ); @@ -354,7 +354,7 @@ private static int commandMoneyRequest(CommandContext conte return Command.SINGLE_SUCCESS; } - private static int commandMoneyGet(CommandContext context) throws CommandSyntaxException { + private static int commandMoneyGet(@NotNull CommandContext context) throws CommandSyntaxException { ServerCommandSource commandSource = context.getSource(); // Get our player reference diff --git a/src/main/java/net/TheElm/project/commands/PermissionCommand.java b/src/main/java/net/TheElm/project/commands/PermissionCommand.java index ff1054e..7a773fb 100644 --- a/src/main/java/net/TheElm/project/commands/PermissionCommand.java +++ b/src/main/java/net/TheElm/project/commands/PermissionCommand.java @@ -55,7 +55,7 @@ public static void register(@NotNull CommandDispatcher disp .suggests(ArgumentSuggestions::suggestRanks) .then(CommandManager.argument("permission", StringArgumentType.word()) .suggests(ArgumentSuggestions::suggestNodes) - .executes(PermissionCommand::addNodeToRank ) + .executes(PermissionCommand::addNodeToRank) ) .executes(PermissionCommand::addRank) ) diff --git a/src/main/java/net/TheElm/project/commands/TeleportsCommand.java b/src/main/java/net/TheElm/project/commands/TeleportsCommand.java index b1421d6..cc8ef21 100644 --- a/src/main/java/net/TheElm/project/commands/TeleportsCommand.java +++ b/src/main/java/net/TheElm/project/commands/TeleportsCommand.java @@ -272,13 +272,20 @@ private static int setHomePrimaryCommand(@NotNull CommandContext playerHomeNames(@NotNull CommandContext context, @NotNull SuggestionsBuilder builder) throws CommandSyntaxException { ServerCommandSource source = context.getSource(); - return WarpUtils.buildSuggestions(source.getPlayer(), builder); + return WarpUtils.buildSuggestions(source.getPlayer().getUuid(), source.getPlayer(), builder); } private static @NotNull CompletableFuture playerHomeNamesOfPlayer(@NotNull CommandContext context, @NotNull SuggestionsBuilder builder) throws CommandSyntaxException { + // Get the uuid of the executor + Entity entity = context.getSource().getEntity(); + UUID untrusted = entity instanceof ServerPlayerEntity ? entity.getUuid() : null; + + // Get the matching player being looked up Collection profiles = GameProfileArgumentType.getProfileArgument(context, "player"); GameProfile target = profiles.stream().findAny() .orElseThrow(GameProfileArgumentType.UNKNOWN_PLAYER_EXCEPTION::create); - return WarpUtils.buildSuggestions(target.getId(), builder); + + // Build the suggestions + return WarpUtils.buildSuggestions(untrusted, target.getId(), builder); } private static int tpaCommand(@NotNull CommandContext context) throws CommandSyntaxException { diff --git a/src/main/java/net/TheElm/project/commands/WaystoneCommand.java b/src/main/java/net/TheElm/project/commands/WaystoneCommand.java index d2be167..675f5c6 100644 --- a/src/main/java/net/TheElm/project/commands/WaystoneCommand.java +++ b/src/main/java/net/TheElm/project/commands/WaystoneCommand.java @@ -60,6 +60,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.UUID; import java.util.concurrent.CompletableFuture; import static net.TheElm.project.commands.TeleportsCommand.TARGET_NO_WARP; @@ -223,13 +224,19 @@ private static int sendPlayersToLocation(@NotNull CommandContext getPlayerEntityLocations(@NotNull CommandContext context, @NotNull SuggestionsBuilder builder) throws CommandSyntaxException { + Entity entity = context.getSource().getEntity(); + UUID untrusted = entity instanceof ServerPlayerEntity ? entity.getUuid() : null; + ServerPlayerEntity player = EntityArgumentType.getPlayer(context, "player"); - return WarpUtils.buildSuggestions(player, builder); + return WarpUtils.buildSuggestions(untrusted, player, builder); } private static @NotNull CompletableFuture getPlayersToLocations(@NotNull CommandContext context, @NotNull SuggestionsBuilder builder) throws CommandSyntaxException { + Entity entity = context.getSource().getEntity(); + UUID untrusted = entity instanceof ServerPlayerEntity ? entity.getUuid() : null; + Collection profiles = GameProfileArgumentType.getProfileArgument(context, "to"); GameProfile target = profiles.stream().findAny() .orElseThrow(GameProfileArgumentType.UNKNOWN_PLAYER_EXCEPTION::create); - return WarpUtils.buildSuggestions(target.getId(), builder); + return WarpUtils.buildSuggestions(untrusted, target.getId(), builder); } } diff --git a/src/main/java/net/TheElm/project/enums/ShopSigns.java b/src/main/java/net/TheElm/project/enums/ShopSigns.java index c44d474..bb1b578 100644 --- a/src/main/java/net/TheElm/project/enums/ShopSigns.java +++ b/src/main/java/net/TheElm/project/enums/ShopSigns.java @@ -525,7 +525,7 @@ private boolean generateNewWarp(final ServerPlayerEntity player) { WarpUtils newWarp = new WarpUtils(warpName, player, spawnPos); BlockPos warpToPos; - while (((warpToPos = newWarp.getWarpPositionIn(world)) == null) || (!newWarp.build(player, world))); + while (((warpToPos = newWarp.getWarpPositionIn(world)) == null) || (!newWarp.claimAndBuild(player, world))); // Get the distance int distance = warpToPos.getManhattanDistance(spawnPos); @@ -611,7 +611,7 @@ public Either onInteract(@NotNull final ServerPlayerEntity player (new Thread(() -> { WarpUtils warp = new WarpUtils(warpName, player, signPos.down()); - if (!warp.build(player, player.getServerWorld())) { + if (!warp.claimAndBuild(player, player.getServerWorld())) { // Notify the player player.sendMessage( new LiteralText("Can't build that here").formatted(Formatting.RED), @@ -622,7 +622,7 @@ public Either onInteract(@NotNull final ServerPlayerEntity player // Refund the player MoneyUtils.givePlayerMoney(player, SewConfig.get(SewConfig.WARP_WAYSTONE_COST)); - // Cancel the build + // Cancel the save return; } diff --git a/src/main/java/net/TheElm/project/mixins/Commands/Me.java b/src/main/java/net/TheElm/project/mixins/Commands/Me.java index 8b7dfce..3902a92 100644 --- a/src/main/java/net/TheElm/project/mixins/Commands/Me.java +++ b/src/main/java/net/TheElm/project/mixins/Commands/Me.java @@ -26,7 +26,7 @@ public final class Me { */ @Overwrite public static void register(CommandDispatcher dispatcher) { - dispatcher.register(CommandManager.literal( "me" ) + dispatcher.register(CommandManager.literal("me") .then( CommandManager.argument( "action", StringArgumentType.greedyString()) .executes((context) -> { // Get player diff --git a/src/main/java/net/TheElm/project/mixins/Entities/Decorative/CatDye.java b/src/main/java/net/TheElm/project/mixins/Entities/Decorative/CatDye.java index 4bea76b..77e1a93 100644 --- a/src/main/java/net/TheElm/project/mixins/Entities/Decorative/CatDye.java +++ b/src/main/java/net/TheElm/project/mixins/Entities/Decorative/CatDye.java @@ -47,7 +47,7 @@ protected CatDye(EntityType entityType, World world) { @Inject(at = @At("HEAD"), method = "setCollarColor") public void onUpdateCollar(DyeColor dye, CallbackInfo callback) { if (this.hasCustomName()) - this.setCustomName(new LiteralText(this.getCustomName().asString()) + this.setCustomName(new LiteralText(this.getCustomName().getString()) .formatted(ColorUtils.getNearestFormatting(dye))); } diff --git a/src/main/java/net/TheElm/project/mixins/Player/ClientInteraction.java b/src/main/java/net/TheElm/project/mixins/Player/ClientInteraction.java index 395c528..3a30a04 100644 --- a/src/main/java/net/TheElm/project/mixins/Player/ClientInteraction.java +++ b/src/main/java/net/TheElm/project/mixins/Player/ClientInteraction.java @@ -286,7 +286,7 @@ public void showPlayerNewLocation(@NotNull final PlayerEntity player, @Nullable // If player is in spawn protection if (locationOwner.equals(CoreMod.SPAWN_ID)) { popupText.append( - owner.getName( player ) + owner.getName(player) ); return; } diff --git a/src/main/java/net/TheElm/project/mixins/Player/FullInventory.java b/src/main/java/net/TheElm/project/mixins/Player/FullInventory.java index ebbf764..a71e2fa 100644 --- a/src/main/java/net/TheElm/project/mixins/Player/FullInventory.java +++ b/src/main/java/net/TheElm/project/mixins/Player/FullInventory.java @@ -58,7 +58,7 @@ public void onInsertStack(ItemStack itemStack, CallbackInfoReturnable c @Inject(at = @At(value = "INVOKE", target = "net/minecraft/entity/player/PlayerEntity.dropItem(Lnet/minecraft/item/ItemStack;Z)Lnet/minecraft/entity/ItemEntity;"), method = "offerOrDrop", cancellable = true) private void setDropOwner(World world, ItemStack itemStack, CallbackInfo callback) { // Drop the item from the player - ItemEntity drop = this.player.dropItem( itemStack, true ); + ItemEntity drop = this.player.dropItem(itemStack, true); // Set the dropped items owner if ( drop != null ) drop.setOwner(this.player.getUuid()); diff --git a/src/main/java/net/TheElm/project/mixins/Player/Interaction/ItemPickup.java b/src/main/java/net/TheElm/project/mixins/Player/Interaction/ItemPickup.java index 206336d..f6153d9 100644 --- a/src/main/java/net/TheElm/project/mixins/Player/Interaction/ItemPickup.java +++ b/src/main/java/net/TheElm/project/mixins/Player/Interaction/ItemPickup.java @@ -63,7 +63,7 @@ public void attemptPickup(PlayerEntity player, CallbackInfo callback) { if (!this.world.isClient) { if ( this.pickupDelay == 0 ) { // Check if the entity is owned by the player (They dropped it) - if (player.getUuid().equals( this.thrower ) || player.getUuid().equals( this.owner ) || (player.isCreative() && SewConfig.get(SewConfig.CLAIM_CREATIVE_BYPASS))) + if (player.getUuid().equals(this.thrower) || player.getUuid().equals(this.owner) || (player.isCreative() && SewConfig.get(SewConfig.CLAIM_CREATIVE_BYPASS))) return; // Check if the player can pickup items in the chunk @@ -79,9 +79,9 @@ public void onDamage(DamageSource damageSource, float damage, CallbackInfoReturn ItemEntity entity = ((ItemEntity)(Entity)this); ItemStack stack = entity.getStack(); if ((damageSource == DamageSource.LAVA) && (Items.GUNPOWDER.equals(stack.getItem()))) { - float volume = ((float) stack.getCount() / stack.getMaxCount() ); + float volume = ((float) stack.getCount() / stack.getMaxCount()); if (volume > 0) - this.world.playSound( null, this.getBlockPos(), SoundEvents.ENTITY_FIREWORK_ROCKET_BLAST, SoundCategory.MASTER, volume, 1.0f ); + this.world.playSound(null, this.getBlockPos(), SoundEvents.ENTITY_FIREWORK_ROCKET_BLAST, SoundCategory.MASTER, volume, 1.0f); } } diff --git a/src/main/java/net/TheElm/project/objects/ChatFormat.java b/src/main/java/net/TheElm/project/objects/ChatFormat.java index 1142094..5b4e9c2 100644 --- a/src/main/java/net/TheElm/project/objects/ChatFormat.java +++ b/src/main/java/net/TheElm/project/objects/ChatFormat.java @@ -31,10 +31,10 @@ import net.TheElm.project.enums.ChatRooms; import net.TheElm.project.utilities.DimensionUtils; import net.TheElm.project.utilities.text.MessageUtils; +import net.TheElm.project.utilities.text.StyleApplicator; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.MutableText; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; @@ -64,11 +64,11 @@ private Text worldText(@NotNull RegistryKey dimension, boolean showAsLong MutableText shorter = DimensionUtils.shortDimensionName(dimension); // Create the hover event - Formatting formatting = DimensionUtils.dimensionColor(dimension); + StyleApplicator formatting = DimensionUtils.dimensionColor(dimension); return ( showAsLong ? longer : shorter ) - .formatted(formatting) - .styled(MessageUtils.simpleHoverText(longer.formatted(formatting))); + .styled(formatting) + .styled(MessageUtils.simpleHoverText(longer.styled(formatting))); } @Override diff --git a/src/main/java/net/TheElm/project/objects/PlayerBackpack.java b/src/main/java/net/TheElm/project/objects/PlayerBackpack.java index 859831b..0125969 100644 --- a/src/main/java/net/TheElm/project/objects/PlayerBackpack.java +++ b/src/main/java/net/TheElm/project/objects/PlayerBackpack.java @@ -260,7 +260,7 @@ public int getRows() { } public Text getName() { - return new LiteralText(this.player.getDisplayName().asString() + "'s Backpack"); + return new LiteralText(this.player.getDisplayName().getString() + "'s Backpack"); } public @Nullable GenericContainerScreenHandler createContainer(int syncId, @NotNull PlayerInventory playerInventory) { diff --git a/src/main/java/net/TheElm/project/protections/claiming/Claimant.java b/src/main/java/net/TheElm/project/protections/claiming/Claimant.java index 764d5f0..c59930f 100644 --- a/src/main/java/net/TheElm/project/protections/claiming/Claimant.java +++ b/src/main/java/net/TheElm/project/protections/claiming/Claimant.java @@ -39,6 +39,7 @@ import net.minecraft.nbt.Tag; import net.minecraft.network.MessageType; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.LiteralText; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.math.ChunkPos; @@ -124,12 +125,12 @@ public final UUID getId() { return this.id; } public abstract MutableText getName(); - public final MutableText getName(@NotNull PlayerEntity player) { + public final @NotNull MutableText getName(@NotNull PlayerEntity player) { return this.getName(player.getUuid()); } - public final MutableText getName(@Nullable UUID player) { + public final @NotNull MutableText getName(@Nullable UUID player) { ClaimRanks playerRank = this.getFriendRank(player); - return this.getName().formatted( playerRank.getColor() ); + return new LiteralText(this.getName().getString()).formatted(playerRank.getColor()); } /* Send Messages */ diff --git a/src/main/java/net/TheElm/project/protections/claiming/ClaimantPlayer.java b/src/main/java/net/TheElm/project/protections/claiming/ClaimantPlayer.java index 51f32d8..e7c631b 100644 --- a/src/main/java/net/TheElm/project/protections/claiming/ClaimantPlayer.java +++ b/src/main/java/net/TheElm/project/protections/claiming/ClaimantPlayer.java @@ -190,11 +190,11 @@ public final void readCustomDataFromTag(@NotNull CompoundTag tag) { ClaimantPlayer player; // If contained in the cache - if ((player = CoreMod.getFromCache( ClaimantPlayer.class, playerUUID )) != null) + if ((player = CoreMod.getFromCache(ClaimantPlayer.class, playerUUID)) != null) return player; // Create new object - return new ClaimantPlayer( playerUUID ); + return new ClaimantPlayer(playerUUID); } public static @NotNull ClaimantPlayer get(@NotNull GameProfile profile) { return ClaimantPlayer.get(profile.getId()); diff --git a/src/main/java/net/TheElm/project/utilities/BlockUtils.java b/src/main/java/net/TheElm/project/utilities/BlockUtils.java index 79866f1..67f5b31 100644 --- a/src/main/java/net/TheElm/project/utilities/BlockUtils.java +++ b/src/main/java/net/TheElm/project/utilities/BlockUtils.java @@ -81,6 +81,11 @@ private BlockUtils() {} return world.raycast(new RaycastContext( posVec, traceVec, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.ANY, entity)); } + /** + * Find and light nearby campfires + * @param world The world to search in + * @param center The position in which to search + */ public static void igniteNearbyLightSources(@NotNull final ServerWorld world, @NotNull final BlockPos center) { // Get the nearby range BlockRange range = BlockRange.radius(center, 10, 4); @@ -97,6 +102,12 @@ public static void igniteNearbyLightSources(@NotNull final ServerWorld world, @N } }); } + + /** + * Find and extinguish nearby campfires + * @param world The world to search in + * @param center The position in which to search + */ public static void extinguishNearbyLightSources(@NotNull final ServerWorld world, @NotNull final BlockPos center) { // Get the nearby range BlockRange range = BlockRange.radius(center, 10, 4); diff --git a/src/main/java/net/TheElm/project/utilities/ChunkUtils.java b/src/main/java/net/TheElm/project/utilities/ChunkUtils.java index 0254a66..c3c3e4a 100644 --- a/src/main/java/net/TheElm/project/utilities/ChunkUtils.java +++ b/src/main/java/net/TheElm/project/utilities/ChunkUtils.java @@ -171,19 +171,27 @@ public static boolean canPlayerHarvestCrop(@NotNull PlayerEntity player, @NotNul * @param target The destination to teleport to * @return If the player is a high enough rank to teleport to the target */ - public static boolean canPlayerWarpTo(PlayerEntity player, UUID target) { + public static boolean canPlayerWarpTo(@NotNull PlayerEntity player, @NotNull UUID target) { if ((!SewConfig.get(SewConfig.DO_CLAIMS)) || (SewConfig.get(SewConfig.CLAIM_CREATIVE_BYPASS) && (player.isCreative() || player.isSpectator()))) return SewConfig.get(SewConfig.COMMAND_WARP_TPA); - + return ChunkUtils.canPlayerWarpTo(player.getUuid(), target); + } + + /** + * @param player The player that wants to teleport + * @param target The destination to teleport to + * @return If the player is a high enough rank to teleport to the target + */ + public static boolean canPlayerWarpTo(@NotNull UUID player, @NotNull UUID target) { // Check our chunk permissions ClaimantPlayer permissions = ClaimantPlayer.get(target); - + // Get the ranks of the user and the rank required for performing - ClaimRanks userRank = permissions.getFriendRank(player.getUuid()); + ClaimRanks userRank = permissions.getFriendRank(player); ClaimRanks permReq = permissions.getPermissionRankRequirement(ClaimPermissions.WARP); - + // Return the test if the user can perform the action - return permReq.canPerform( userRank ); + return permReq.canPerform(userRank); } public static boolean isSetting(@NotNull ClaimSettings setting, @NotNull World world, @NotNull BlockPos blockPos) { diff --git a/src/main/java/net/TheElm/project/utilities/ColorUtils.java b/src/main/java/net/TheElm/project/utilities/ColorUtils.java index e73cd69..49ecc7a 100644 --- a/src/main/java/net/TheElm/project/utilities/ColorUtils.java +++ b/src/main/java/net/TheElm/project/utilities/ColorUtils.java @@ -42,8 +42,8 @@ import java.util.Set; public final class ColorUtils { - - private static final Map COLORS; + + public static final Map COLORS; private static final Random RANDOM; private ColorUtils() {} diff --git a/src/main/java/net/TheElm/project/utilities/DimensionUtils.java b/src/main/java/net/TheElm/project/utilities/DimensionUtils.java index 489a9ff..832a98a 100644 --- a/src/main/java/net/TheElm/project/utilities/DimensionUtils.java +++ b/src/main/java/net/TheElm/project/utilities/DimensionUtils.java @@ -25,6 +25,7 @@ package net.TheElm.project.utilities; +import net.TheElm.project.utilities.text.StyleApplicator; import net.minecraft.network.Packet; import net.minecraft.network.packet.s2c.play.WorldBorderS2CPacket; import net.minecraft.network.packet.s2c.play.WorldBorderS2CPacket.Type; @@ -43,6 +44,11 @@ public final class DimensionUtils { + private static final StyleApplicator OVERWORLD_APPLICATOR = new StyleApplicator(ColorUtils.getRawTextColor("LightSkyBlue")); + private static final StyleApplicator NETHER_APPLICATOR = new StyleApplicator(ColorUtils.getRawTextColor("FireBrick")); + private static final StyleApplicator END_APPLICATOR = new StyleApplicator(ColorUtils.getRawTextColor("PaleGoldenRod")); + private static final StyleApplicator DEFAULT_APPLICATOR = new StyleApplicator(ColorUtils.getNearestTextColor(Formatting.WHITE)); + private DimensionUtils() {} public static void addWorldBorderListener(@NotNull final ServerWorld world) { @@ -94,14 +100,14 @@ public static boolean isWithinProtectedZone(@NotNull RegistryKey world, B return new LiteralText("E"); return new LiteralText("~"); } - public static @NotNull Formatting dimensionColor(@Nullable RegistryKey world) { + public static @NotNull StyleApplicator dimensionColor(@Nullable RegistryKey world) { if (World.OVERWORLD.equals(world)) - return Formatting.GREEN; + return OVERWORLD_APPLICATOR; if (World.NETHER.equals(world)) - return Formatting.RED; + return NETHER_APPLICATOR; if (World.END.equals(world)) - return Formatting.DARK_GRAY; - return Formatting.WHITE; + return END_APPLICATOR; + return DEFAULT_APPLICATOR; } private static final class IndividualWorldListener implements WorldBorderListener { diff --git a/src/main/java/net/TheElm/project/utilities/PlayerNameUtils.java b/src/main/java/net/TheElm/project/utilities/PlayerNameUtils.java index 3fb7625..68f9357 100644 --- a/src/main/java/net/TheElm/project/utilities/PlayerNameUtils.java +++ b/src/main/java/net/TheElm/project/utilities/PlayerNameUtils.java @@ -40,7 +40,9 @@ import net.TheElm.project.protections.claiming.ClaimantTown; import net.TheElm.project.utilities.nbt.NbtUtils; import net.TheElm.project.utilities.text.MessageUtils; +import net.TheElm.project.utilities.text.StyleApplicator; import net.fabricmc.fabric.api.util.NbtType; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; @@ -118,6 +120,9 @@ private PlayerNameUtils() {} player )); } + public static @NotNull MutableText getPlayerRawName(@NotNull PlayerEntity player) { + return new LiteralText(player.getDisplayName().getString()); + } private static @NotNull MutableText applyPlayerNameStyle(@NotNull MutableText text, @NotNull ServerPlayerEntity player) { final String name = player.getGameProfile().getName(); @@ -138,13 +143,13 @@ private PlayerNameUtils() {} MutableText longer = DimensionUtils.longDimensionName(world); // Create the hover event - Formatting formatting = DimensionUtils.dimensionColor(world); + StyleApplicator formatting = DimensionUtils.dimensionColor(world); return (showAsLong ? longer : DimensionUtils.shortDimensionName(world)) - .formatted(formatting) - .styled(MessageUtils.simpleHoverText(longer.formatted(formatting))); + .styled(formatting) + .styled(MessageUtils.simpleHoverText(longer.styled(formatting))); } - public static @NotNull MutableText formattedChat(ChatRooms chatRoom) { + public static @NotNull MutableText formattedChat(@NotNull ChatRooms chatRoom) { String name = CasingUtils.Sentence( chatRoom.name() ); return new LiteralText( name.substring( 0, 1 ) ) .formatted( Formatting.DARK_GRAY ) diff --git a/src/main/java/net/TheElm/project/utilities/RegistryUtils.java b/src/main/java/net/TheElm/project/utilities/RegistryUtils.java index 9d87216..e30f3e9 100644 --- a/src/main/java/net/TheElm/project/utilities/RegistryUtils.java +++ b/src/main/java/net/TheElm/project/utilities/RegistryUtils.java @@ -43,7 +43,7 @@ public static RegistryKey getFromRegistry(@NotNull MinecraftServer server return server.getRegistryManager().get(registry) .getEntries() .stream() - .filter(registryKeyBiomeEntry -> registryKeyBiomeEntry.getValue().equals(type)) + .filter(entry -> entry.getValue().equals(type)) .map(Map.Entry::getKey) .findFirst() .orElse(null); diff --git a/src/main/java/net/TheElm/project/utilities/SleepUtils.java b/src/main/java/net/TheElm/project/utilities/SleepUtils.java index 0843e85..d4356ad 100644 --- a/src/main/java/net/TheElm/project/utilities/SleepUtils.java +++ b/src/main/java/net/TheElm/project/utilities/SleepUtils.java @@ -57,7 +57,7 @@ public static void playerBedToggle(@NotNull final PlayerEntity player, final boo if ( world.getPlayers().size() > 1 ) { TitleUtils.showPlayerAlert((ServerWorld) player.world, - new LiteralText(player.getDisplayName().asString()).formatted(Formatting.AQUA), + PlayerNameUtils.getPlayerRawName(player).formatted(Formatting.AQUA), new LiteralText(isSleeping ? " is now sleeping (" + percentage + "%)." : " is now in bed") ); } @@ -68,7 +68,7 @@ public static void playerBedToggle(@NotNull final PlayerEntity player, final boo if ( world.getPlayers().size() > 1 ) { TitleUtils.showPlayerAlert((ServerWorld) player.world, - ColorUtils.format(player.getDisplayName(), Formatting.AQUA), + PlayerNameUtils.getPlayerRawName(player).formatted(Formatting.AQUA), new LiteralText(" left their bed.") ); } diff --git a/src/main/java/net/TheElm/project/utilities/WarpUtils.java b/src/main/java/net/TheElm/project/utilities/WarpUtils.java index 0fc1fde..3dbab7c 100644 --- a/src/main/java/net/TheElm/project/utilities/WarpUtils.java +++ b/src/main/java/net/TheElm/project/utilities/WarpUtils.java @@ -59,7 +59,7 @@ import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; +import net.minecraft.text.MutableText; import net.minecraft.util.Formatting; import net.minecraft.util.math.*; import net.minecraft.util.registry.Registry; @@ -180,17 +180,24 @@ private static int getRandom(int position) { && ( world.getBlockState( pos.up() ).isAir() ) ? pos : null; } - public boolean build(final ServerPlayerEntity player, final ServerWorld world) { - return this.build(player, world, true); + public boolean claimAndBuild(@NotNull final ServerPlayerEntity player, @NotNull final ServerWorld world) { + return this.claimAndBuild(player, world, false); } - public boolean build(final ServerPlayerEntity player, final ServerWorld world, final boolean dropBlocks) { + public boolean claimAndBuild(@NotNull final ServerPlayerEntity player, @NotNull final ServerWorld world, final boolean dropBlocks) { // Get the area of blocks to claim if (!ChunkUtils.canPlayerClaimSlices(world, this.region)) return false; - + // Claim the defined slices in the name of Spawn ChunkUtils.claimSlices(world, CoreMod.SPAWN_ID, this.region); - + + return this.build(player, world, dropBlocks); + } + + public boolean build(@NotNull final ServerPlayerEntity player, @NotNull final ServerWorld world) { + return this.build(player, world, true); + } + public boolean build(@NotNull final ServerPlayerEntity player, @NotNull final ServerWorld world, final boolean dropBlocks) { Biome biome = world.getBiome(this.createWarpAt); RegistryKey biomeKey = RegistryUtils.getFromRegistry(world.getServer(), Registry.BIOME_KEY, biome); @@ -204,7 +211,7 @@ public boolean build(final ServerPlayerEntity player, final ServerWorld world, f final BlockState decLight = material.getLightSourceBlock(); final BlockState ovrLight = material.getCoveringBlock(); final BlockState undLight = material.getSupportingBlock(); - BlockPos[] decLightBlocks = new BlockPos[]{ + BlockPos[] decLightBlocks = new BlockPos[] { new BlockPos(this.createWarpAt.getX() + 1, this.createWarpAt.getY(), this.createWarpAt.getZ() + 1), new BlockPos(this.createWarpAt.getX() + 1, this.createWarpAt.getY(), this.createWarpAt.getZ() - 1), new BlockPos(this.createWarpAt.getX() - 1, this.createWarpAt.getY(), this.createWarpAt.getZ() + 1), @@ -606,15 +613,16 @@ private static void teleportPoof(@NotNull final Entity entity) { return new BlockPos(properties.getSpawnX(), properties.getSpawnY(), properties.getSpawnZ()); } - public static CompletableFuture buildSuggestions(@NotNull ServerPlayerEntity player, @NotNull SuggestionsBuilder builder) { - return WarpUtils.buildSuggestions(WarpUtils.getWarps(player), builder); + public static CompletableFuture buildSuggestions(@Nullable UUID untrusted, @NotNull ServerPlayerEntity warpOwner, @NotNull SuggestionsBuilder builder) { + return WarpUtils.buildSuggestions(warpOwner.getUuid(), untrusted, WarpUtils.getWarps(warpOwner), builder); } - public static CompletableFuture buildSuggestions(@NotNull UUID uuid, @NotNull SuggestionsBuilder builder) { - return WarpUtils.buildSuggestions(WarpUtils.getWarps(uuid), builder); + public static CompletableFuture buildSuggestions(@Nullable UUID untrusted, @NotNull UUID warpOwner, @NotNull SuggestionsBuilder builder) { + return WarpUtils.buildSuggestions(warpOwner, untrusted, WarpUtils.getWarps(warpOwner), builder); } - private static CompletableFuture buildSuggestions(@NotNull Map warps, @NotNull SuggestionsBuilder builder) { + private static CompletableFuture buildSuggestions(@NotNull UUID warpOwner, @Nullable UUID untrusted, @NotNull Map warps, @NotNull SuggestionsBuilder builder) { String remainder = builder.getRemaining().toLowerCase(Locale.ROOT); + boolean canViewCoordinates = untrusted != null && (warpOwner.equals(untrusted) || ChunkUtils.canPlayerWarpTo(untrusted, warpOwner)); for (Map.Entry iterator : warps.entrySet()) { String name = iterator.getKey(); if (name.contains(" ")) @@ -622,14 +630,22 @@ private static CompletableFuture buildSuggestions(@NotNull Map MutableText listToTextComponent(@NotNull final Collection list, @NotNull Function function) {