Skip to content

Commit

Permalink
Merge pull request #78
Browse files Browse the repository at this point in the history
Various Recipe Registration Fixes
  • Loading branch information
WolfyScript authored Feb 28, 2022
2 parents 2709275 + c7f91d6 commit 05f12ca
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<groupId>com.wolfyscript.customcrafting</groupId>
<artifactId>customcrafting-spigot</artifactId>
<version>3.16.2.1</version>
<version>3.16.2.2</version>

<properties>
<!-- Generic properties -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import me.wolfyscript.customcrafting.utils.ChatUtils;
import me.wolfyscript.utilities.util.Pair;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
Expand Down Expand Up @@ -57,7 +58,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull String var3, @N
api.getChat().sendMessage((Player) sender, "$commands.recipes.toggle.disabled$", new Pair<>("%recipe%", args[0]));
customCrafting.getDisableRecipesHandler().getRecipes().add(namespacedKey);
if (namespacedKey != null) {
Bukkit.getOnlinePlayers().forEach(player -> player.undiscoverRecipe(namespacedKey.toBukkit(customCrafting)));
Bukkit.getOnlinePlayers().forEach(player -> player.undiscoverRecipe(new NamespacedKey(namespacedKey.getNamespace(), namespacedKey.getKey())));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private void registerSaveButtons() {
StringUtil.copyPartialMatches(args[0], registryRecipes.folders(NamespacedKeyUtils.NAMESPACE), results);
} else if (args.length == 2) {
results.add("<recipe_name>");
StringUtil.copyPartialMatches(args[1], registryRecipes.get(NamespacedKeyUtils.NAMESPACE, args[0]).stream().filter(recipe -> cache.getRecipeCreatorCache().getRecipeType().isInstance(recipe)).map(recipe -> recipe.getNamespacedKey().getKey()).toList(), results);
StringUtil.copyPartialMatches(args[1], registryRecipes.get(NamespacedKeyUtils.NAMESPACE, args[0]).stream().filter(recipe -> cache.getRecipeCreatorCache().getRecipeType().isInstance(recipe)).map(recipe -> NamespacedKeyUtils.getRelativeKeyObjPath(recipe.getNamespacedKey())).toList(), results);
}
}
Collections.sort(results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void disableRecipe(CustomRecipe<?> recipe) {
var namespacedKey = recipe.getNamespacedKey();
recipes.add(namespacedKey);
if (recipe instanceof ICustomVanillaRecipe<?>) {
Bukkit.removeRecipe(namespacedKey.toBukkit(customCrafting));
Bukkit.removeRecipe(new org.bukkit.NamespacedKey(namespacedKey.getNamespace(), namespacedKey.getKey()));
}
saveDisabledRecipes();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void onPreCraft(PrepareItemCraftEvent e) {
//Vanilla Recipe is available.
//Check for custom recipe that overrides the vanilla recipe
var namespacedKey = NamespacedKey.fromBukkit(((Keyed) e.getRecipe()).getKey());
if (customCrafting.getDisableRecipesHandler().getRecipes().contains(namespacedKey) || customCrafting.getRegistries().getRecipes().getAdvancedCrafting(NamespacedKeyUtils.toInternal(namespacedKey)) != null) {
if (customCrafting.getDisableRecipesHandler().getRecipes().contains(namespacedKey) || customCrafting.getRegistries().getRecipes().getAdvancedCrafting(namespacedKey) != null) {
//Recipe is disabled or it is a custom recipe!
e.getInventory().setResult(ItemUtils.AIR);
Bukkit.getScheduler().runTask(customCrafting, player::updateInventory);
Expand All @@ -136,7 +136,7 @@ public void onPreCraft(PrepareItemCraftEvent e) {
public void onRecipeDiscover(PlayerRecipeDiscoverEvent event) {
org.bukkit.NamespacedKey key = event.getRecipe();
if (key.getNamespace().equals(NamespacedKeyUtils.NAMESPACE)) {
CustomRecipe<?> recipe = customCrafting.getRegistries().getRecipes().get(NamespacedKeyUtils.toInternal(NamespacedKey.fromBukkit(key)));
CustomRecipe<?> recipe = customCrafting.getRegistries().getRecipes().get(NamespacedKey.fromBukkit(key));
if (recipe instanceof ICustomVanillaRecipe<?> vanillaRecipe && vanillaRecipe.isVisibleVanillaBook()) {
event.setCancelled(recipe.isHidden() || recipe.isDisabled());
} else {
Expand All @@ -155,7 +155,7 @@ public void onJoin(PlayerJoinEvent event) {
List<org.bukkit.NamespacedKey> discoveredCustomRecipes = player.getDiscoveredRecipes().stream().filter(namespacedKey -> namespacedKey.getNamespace().equals(NamespacedKeyUtils.NAMESPACE)).toList();
customCrafting.getRegistries().getRecipes().getAvailable(player).stream()
.filter(recipe -> recipe instanceof ICustomVanillaRecipe<?>)
.map(recipe -> recipe.getNamespacedKey().toBukkit(customCrafting))
.map(recipe -> new org.bukkit.NamespacedKey(recipe.getNamespacedKey().getNamespace(), recipe.getNamespacedKey().getKey()))
.filter(namespacedKey -> !discoveredCustomRecipes.contains(namespacedKey))
.forEach(player::discoverRecipe);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public CustomRecipeBlasting(CustomRecipeBlasting customRecipeBlasting) {
@Override
public BlastingRecipe getVanillaRecipe() {
if (!getSource().isEmpty()) {
var recipe = new BlastingRecipe(org.bukkit.NamespacedKey.fromString(getNamespacedKey().toString()), getResult().getChoices().get(0).create(), getRecipeChoice(), getExp(), getCookingTime());
var recipe = new BlastingRecipe(new org.bukkit.NamespacedKey(getNamespacedKey().getNamespace(), getNamespacedKey().getKey()), getResult().getChoices().get(0).create(), getRecipeChoice(), getExp(), getCookingTime());
recipe.setGroup(group);
return recipe;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void init() {
private void registerServerSide() {
recipeFilter = minecraftKey -> {
if (minecraftKey.getPrefix().equals(NamespacedKeyUtils.NAMESPACE)) {
CustomRecipe<?> recipe = plugin.getRegistries().getRecipes().get(NamespacedKeyUtils.toInternal(NamespacedKey.of(minecraftKey.getFullKey())));
CustomRecipe<?> recipe = plugin.getRegistries().getRecipes().get(NamespacedKey.of(minecraftKey.getFullKey()));
if (recipe instanceof ICustomVanillaRecipe<?> vanillaRecipe && vanillaRecipe.isVisibleVanillaBook()) {
return !recipe.isHidden() && !recipe.isDisabled();
}
Expand Down

0 comments on commit 05f12ca

Please sign in to comment.