Skip to content

Commit

Permalink
Fix profession assigning
Browse files Browse the repository at this point in the history
  • Loading branch information
samolego committed Jan 2, 2022
1 parent 91a8547 commit 3aecc98
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/javadoc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: Javadoc but Dokka
name: Javadoc - Release

on:
release:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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 com.mojang.brigadier.tree.LiteralCommandNode;
Expand All @@ -20,19 +21,27 @@

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;

import static net.minecraft.commands.Commands.argument;
import static net.minecraft.commands.Commands.literal;
import static net.minecraft.commands.arguments.MessageArgument.message;
import static org.samo_lego.taterzens.Taterzens.LEGACY_PROFESSION_TYPES;
import static org.samo_lego.taterzens.Taterzens.PROFESSION_TYPES;
import static org.samo_lego.taterzens.Taterzens.config;
import static org.samo_lego.taterzens.compatibility.LoaderSpecific.permissions$checkPermission;
import static org.samo_lego.taterzens.util.TextUtil.*;
import static org.samo_lego.taterzens.util.TextUtil.errorText;
import static org.samo_lego.taterzens.util.TextUtil.joinText;
import static org.samo_lego.taterzens.util.TextUtil.successText;
import static org.samo_lego.taterzens.util.TextUtil.translate;

public class ProfessionsCommand {


private static final SuggestionProvider<CommandSourceStack> PROFESSION_SUGESTIONS;

public static void registerNode(LiteralCommandNode<CommandSourceStack> editNode) {
LiteralCommandNode<CommandSourceStack> professionsNode = literal("professions")
.requires(src -> permissions$checkPermission(src, "taterzens.npc.edit.professions", config.perms.npcCommandPermissionLevel))
Expand All @@ -46,7 +55,7 @@ public static void registerNode(LiteralCommandNode<CommandSourceStack> editNode)
.then(literal("add")
.requires(src -> permissions$checkPermission(src, "taterzens.npc.edit.professions.add", config.perms.npcCommandPermissionLevel))
.then(argument("profession type", message())
.suggests((context, builder) -> SharedSuggestionProvider.suggest(LEGACY_PROFESSION_TYPES.keySet().stream().map(ResourceLocation::toString), builder))
.suggests(PROFESSION_SUGESTIONS)
.executes(ctx -> setProfession(ctx, new ResourceLocation(MessageArgument.getMessage(ctx, "profession type").getContents())))
)
)
Expand Down Expand Up @@ -104,7 +113,7 @@ private static int removeProfession(CommandContext<CommandSourceStack> context,
private static int setProfession(CommandContext<CommandSourceStack> context, ResourceLocation id) throws CommandSyntaxException {
CommandSourceStack source = context.getSource();
return NpcCommand.selectedTaterzenExecutor(source.getEntityOrException(), taterzen -> {
if(LEGACY_PROFESSION_TYPES.containsKey(id)) {
if(LEGACY_PROFESSION_TYPES.containsKey(id) || PROFESSION_TYPES.containsKey(id)) {
taterzen.addProfession(id);
source.sendSuccess(successText("taterzens.command.profession.add", id.toString()), false);
} else
Expand All @@ -123,4 +132,13 @@ private static CompletableFuture<Suggestions> suggestRemovableProfessions(Comman
}
return SharedSuggestionProvider.suggest(professions.stream().map(ResourceLocation::toString), builder);
}

static {
Set<ResourceLocation> availableProfessions = PROFESSION_TYPES.keySet();
availableProfessions.addAll(LEGACY_PROFESSION_TYPES.keySet());
Stream<String> professionsStream = availableProfessions.stream().map(ResourceLocation::toString);

PROFESSION_SUGESTIONS = (context, builder) ->
SharedSuggestionProvider.suggest(professionsStream, builder);
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fabric_version=0.44.0+1.18
forge_version=39.0.5

# Mod Properties
mod_version = 1.7.0
mod_version = 1.7.1
maven_group = org.samo_lego
archives_base_name = taterzens

Expand Down

0 comments on commit 3aecc98

Please sign in to comment.