Skip to content

Commit

Permalink
fix: Fix the set season command's season argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveplays28 committed Oct 6, 2024
1 parent eb5926b commit 5cc23a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package io.github.steveplays28.simpleseasons.server.command.season;

import com.mojang.brigadier.context.CommandContext;
import io.github.steveplays28.simpleseasons.SimpleSeasons;
import io.github.steveplays28.simpleseasons.state.world.SeasonTracker;
import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry;
import net.minecraft.command.argument.EnumArgumentType;
import net.minecraft.command.argument.serialize.ConstantArgumentSerializer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;

public class SeasonArgumentType extends EnumArgumentType<SeasonTracker.Seasons> {
public static final String NAME = "season";
private static final String NAME = "season";

SeasonArgumentType() {
super(SeasonTracker.Seasons.CODEC, SeasonTracker.Seasons::values);
Expand All @@ -21,4 +24,8 @@ public static void register() {
ConstantArgumentSerializer.of(SeasonArgumentType::new)
);
}

public static @NotNull SeasonTracker.Seasons getArgument(@NotNull CommandContext<ServerCommandSource> commandContext) {
return commandContext.getArgument(NAME, SeasonTracker.Seasons.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import io.github.steveplays28.simpleseasons.api.SimpleSeasonsApi;
import io.github.steveplays28.simpleseasons.state.world.SeasonTracker;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
Expand All @@ -16,8 +15,8 @@
// TODO: Refactor into a base class that can be overridden and extended
// This reduces duplicate code
public class SetSeasonCommand {
public static final String NAME = "set";
public static final int PERMISSION_LEVEL = 4;
private static final String NAME = "set";
private static final int PERMISSION_LEVEL = 4;

public static @NotNull LiteralArgumentBuilder<ServerCommandSource> register() {
return CommandManager.literal(MOD_NAMESPACE).then(CommandManager.literal(SEASON_COMMAND_CATEGORY).then(
Expand All @@ -31,8 +30,7 @@ public class SetSeasonCommand {
}

public static int execute(@NotNull CommandContext<ServerCommandSource> commandContext, @NotNull ServerCommandSource source) {
var seasonArgument = commandContext.getArgument(NAME, SeasonTracker.Seasons.class);

var seasonArgument = SeasonArgumentType.getArgument(commandContext);
var serverWorld = source.getWorld();
var currentSeason = SimpleSeasonsApi.getSeason(serverWorld);
if (seasonArgument.getId() == currentSeason.getId()) {
Expand All @@ -50,7 +48,6 @@ public static int execute(@NotNull CommandContext<ServerCommandSource> commandCo
"Set season to %s.", seasonArgument.asString()
)
));

return 0;
}
}

0 comments on commit 5cc23a3

Please sign in to comment.