Skip to content

Commit

Permalink
Bug fixes and tweaks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
GStefanowich committed Jun 17, 2021
1 parent 24627c1 commit 36644fd
Show file tree
Hide file tree
Showing 26 changed files with 188 additions and 92 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <S> CompletableFuture<Suggestions> suggestNodes(@NotNull CommandContext<S> context, @NotNull SuggestionsBuilder builder) {
return CommandSource.suggestMatching(Permissions.keys(), builder);
}
Expand All @@ -47,7 +54,32 @@ public class ArgumentSuggestions {
}

public static @NotNull <S> CompletableFuture<Suggestions> suggestColors(@NotNull CommandContext<S> 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<Suggestions> suggest(@NotNull Collection<Map.Entry<String, Text>> suggestions, @NotNull SuggestionsBuilder builder) {
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);

for (Map.Entry<String, Text> 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<Suggestions> suggest(@NotNull Stream<Map.Entry<String, Text>> 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();
}
}
6 changes: 3 additions & 3 deletions src/main/java/net/TheElm/project/commands/ModCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private ModCommands() {
}

public static void register(@NotNull CommandDispatcher<ServerCommandSource> 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")
Expand All @@ -63,9 +63,9 @@ public static void register(@NotNull CommandDispatcher<ServerCommandSource> disp
.executes(ModCommands::reloadPermissions)
)
)
.then(CommandManager.literal("fix-shop")
/*.then(CommandManager.literal("fix-shop")
.executes(ModCommands::repairShopSign)
)
)*/
);
}

Expand Down
38 changes: 19 additions & 19 deletions src/main/java/net/TheElm/project/commands/MoneyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public final class MoneyCommand {

private MoneyCommand() {}

public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
public static void register(@NotNull CommandDispatcher<ServerCommandSource> dispatcher) {
/*
* Player Pay
*/
Expand All @@ -86,24 +86,24 @@ public static void register(CommandDispatcher<ServerCommandSource> 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)
)
)
)
Expand Down Expand Up @@ -147,7 +147,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
/*
* Admin commands
*/
private static int commandAdminGive(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
private static int commandAdminGive(@NotNull CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
// Get the reference of the player to modify
Collection<GameProfile> argumentType = GameProfileArgumentType.getProfileArgument( context, "player" );
GameProfile target = argumentType.stream().findAny().orElseThrow(GameProfileArgumentType.UNKNOWN_PLAYER_EXCEPTION::create);
Expand Down Expand Up @@ -181,7 +181,7 @@ private static int commandAdminGive(CommandContext<ServerCommandSource> context)
return Command.SINGLE_SUCCESS;
}

private static int commandAdminTake(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
private static int commandAdminTake(@NotNull CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
// Get the reference of the player to modify
Collection<GameProfile> argumentType = GameProfileArgumentType.getProfileArgument( context, "player" );
GameProfile target = argumentType.stream().findAny().orElseThrow(GameProfileArgumentType.UNKNOWN_PLAYER_EXCEPTION::create);
Expand Down Expand Up @@ -218,7 +218,7 @@ private static int commandAdminTake(CommandContext<ServerCommandSource> context)
return Command.SINGLE_SUCCESS;
}

private static int commandAdminSet(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
private static int commandAdminSet(@NotNull CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
// Get the reference of the player to modify
Collection<GameProfile> argumentType = GameProfileArgumentType.getProfileArgument( context, "player" );
GameProfile target = argumentType.stream().findAny().orElseThrow(GameProfileArgumentType.UNKNOWN_PLAYER_EXCEPTION::create);
Expand Down Expand Up @@ -252,7 +252,7 @@ private static int commandAdminSet(CommandContext<ServerCommandSource> context)
return Command.SINGLE_SUCCESS;
}

private static int commandAdminReset(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
private static int commandAdminReset(@NotNull CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
// Get the reference of the player to modify
Collection<GameProfile> argumentType = GameProfileArgumentType.getProfileArgument( context, "player" );
GameProfile target = argumentType.stream().findAny().orElseThrow(GameProfileArgumentType.UNKNOWN_PLAYER_EXCEPTION::create);
Expand Down Expand Up @@ -281,7 +281,7 @@ private static int commandAdminReset(CommandContext<ServerCommandSource> context
/*
* Player commands
*/
private static int commandMoneyPay(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
private static int commandMoneyPay(@NotNull CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerCommandSource commandSource = context.getSource();

// Get the reference of the player to pay
Expand Down Expand Up @@ -319,7 +319,7 @@ private static int commandMoneyPay(CommandContext<ServerCommandSource> context)
return MoneyCommand.commandMoneyGet( context );
}

private static int commandMoneyRequest(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
private static int commandMoneyRequest(@NotNull CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerCommandSource source = context.getSource();

// Get the reference of the player to request money from
Expand All @@ -331,7 +331,7 @@ private static int commandMoneyRequest(CommandContext<ServerCommandSource> 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 );
Expand All @@ -354,7 +354,7 @@ private static int commandMoneyRequest(CommandContext<ServerCommandSource> conte
return Command.SINGLE_SUCCESS;
}

private static int commandMoneyGet(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
private static int commandMoneyGet(@NotNull CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
ServerCommandSource commandSource = context.getSource();

// Get our player reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void register(@NotNull CommandDispatcher<ServerCommandSource> disp
.suggests(ArgumentSuggestions::suggestRanks)
.then(CommandManager.argument("permission", StringArgumentType.word())
.suggests(ArgumentSuggestions::suggestNodes)
.executes(PermissionCommand::addNodeToRank )
.executes(PermissionCommand::addNodeToRank)
)
.executes(PermissionCommand::addRank)
)
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/net/TheElm/project/commands/TeleportsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,20 @@ private static int setHomePrimaryCommand(@NotNull CommandContext<ServerCommandSo

private static @NotNull CompletableFuture<Suggestions> playerHomeNames(@NotNull CommandContext<ServerCommandSource> 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<Suggestions> playerHomeNamesOfPlayer(@NotNull CommandContext<ServerCommandSource> 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<GameProfile> 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<ServerCommandSource> context) throws CommandSyntaxException {
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/net/TheElm/project/commands/WaystoneCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -223,13 +224,19 @@ private static int sendPlayersToLocation(@NotNull CommandContext<ServerCommandSo
}

private static @NotNull CompletableFuture<Suggestions> getPlayerEntityLocations(@NotNull CommandContext<ServerCommandSource> 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<Suggestions> getPlayersToLocations(@NotNull CommandContext<ServerCommandSource> context, @NotNull SuggestionsBuilder builder) throws CommandSyntaxException {
Entity entity = context.getSource().getEntity();
UUID untrusted = entity instanceof ServerPlayerEntity ? entity.getUuid() : null;

Collection<GameProfile> 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);
}
}
6 changes: 3 additions & 3 deletions src/main/java/net/TheElm/project/enums/ShopSigns.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -611,7 +611,7 @@ public Either<Text, Boolean> 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),
Expand All @@ -622,7 +622,7 @@ public Either<Text, Boolean> onInteract(@NotNull final ServerPlayerEntity player
// Refund the player
MoneyUtils.givePlayerMoney(player, SewConfig.get(SewConfig.WARP_WAYSTONE_COST));

// Cancel the build
// Cancel the save
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/TheElm/project/mixins/Commands/Me.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public final class Me {
*/
@Overwrite
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(CommandManager.literal( "me" )
dispatcher.register(CommandManager.literal("me")
.then( CommandManager.argument( "action", StringArgumentType.greedyString())
.executes((context) -> {
// Get player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected CatDye(EntityType<? extends TameableEntity> 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)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void onInsertStack(ItemStack itemStack, CallbackInfoReturnable<Boolean> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}

Expand Down
Loading

0 comments on commit 36644fd

Please sign in to comment.