Skip to content

Commit 53a4c79

Browse files
committed
> 4.18.4
> Implemented new system to allow IA items to work in CustomCrafting recipes as ingredients and or as result items. Signed-off-by: petulikan1 <petulikan@gmail.com> Took 6 hours 21 minutes
1 parent e64e916 commit 53a4c79

5 files changed

Lines changed: 26 additions & 3 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
#
2222

2323
group = com.wolfyscript.customcrafting
24-
version = 4.18.3-petu
24+
version = 4.18.4-petu

spigot/src/main/java/me/wolfyscript/customcrafting/configs/MainConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ public boolean isPrettyPrinting() {
144144
return getBoolean("recipes.pretty_printing");
145145
}
146146

147+
public boolean isIaFix(){
148+
return getBoolean("recipes.ia_fix");
149+
}
150+
147151
@Deprecated(forRemoval = true)
148152
public boolean isNMSBasedCrafting() {
149153
return false;

spigot/src/main/java/me/wolfyscript/customcrafting/listeners/crafting/CraftListener.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
import me.wolfyscript.customcrafting.utils.CraftManager;
2828
import org.bukkit.Bukkit;
2929
import org.bukkit.event.EventHandler;
30+
import org.bukkit.event.EventPriority;
31+
import org.bukkit.event.HandlerList;
3032
import org.bukkit.event.Listener;
33+
import org.bukkit.event.inventory.PrepareItemCraftEvent;
34+
import org.bukkit.plugin.RegisteredListener;
3135

3236
public class CraftListener implements Listener {
3337

@@ -37,6 +41,19 @@ public class CraftListener implements Listener {
3741
public CraftListener(CustomCrafting customCrafting) {
3842
this.customCrafting = customCrafting;
3943
this.craftManager = customCrafting.getCraftManager();
44+
45+
if(customCrafting.getConfigHandler().getConfig().isIaFix()) {
46+
HandlerList handlerList = PrepareItemCraftEvent.getHandlerList();
47+
for (RegisteredListener rl : handlerList.getRegisteredListeners()) {
48+
if (rl.getListener().getClass().getCanonicalName().contains("itemsadder")) {
49+
if (rl.getPriority() == EventPriority.MONITOR) {
50+
RegisteredListener newRl = new RegisteredListener(rl.getListener(), rl.getExecutor(), EventPriority.HIGHEST, rl.getPlugin(), rl.isIgnoringCancelled());
51+
handlerList.unregister(rl);
52+
handlerList.register(newRl);
53+
}
54+
}
55+
}
56+
}
4057
Bukkit.getPluginManager().registerEvents(new EventBasedCraftRecipeHandler(customCrafting, craftManager), customCrafting);
4158
}
4259

spigot/src/main/java/me/wolfyscript/customcrafting/recipes/AbstractRecipeShaped.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public void setShape(@NotNull String... shape) {
186186
}
187187
this.shape = keepShapeAsIs ? shape : RecipeUtil.formatShape(shape).toArray(new String[0]);
188188
var flattenShape = String.join("", this.shape);
189-
Preconditions.checkArgument(!flattenShape.isEmpty() && !flattenShape.isBlank(), "Shape must not be empty! (Shape: \"" + Arrays.toString(this.shape) + "\")!");
189+
Preconditions.checkArgument(!flattenShape.isBlank(), "Shape must not be empty! (Shape: \"" + Arrays.toString(this.shape) + "\")!");
190190
Map<Character, Ingredient> newIngredients = new HashMap<>();
191191
flattenShape.chars().mapToObj(value -> (char) value).forEach(character -> newIngredients.put(character, this.mappedIngredients.get(character)));
192192
this.mappedIngredients = newIngredients;
@@ -199,7 +199,7 @@ public Shape getInternalShape() {
199199
private void createFlatIngredients() {
200200
//Create flatten ingredients. This makes it possible to use a key multiple times in one shape.
201201
var flattenShape = String.join("", this.shape);
202-
Preconditions.checkArgument(!flattenShape.isEmpty() && !flattenShape.isBlank(), "Shape must not be empty! (Shape: \"" + Arrays.toString(this.shape) + "\")!");
202+
Preconditions.checkArgument(!flattenShape.isBlank(), "Shape must not be empty! (Shape: \"" + Arrays.toString(this.shape) + "\")!");
203203
this.ingredients = flattenShape.chars().mapToObj(key -> mappedIngredients.getOrDefault((char) key, new Ingredient())).toList();
204204
//Create internal shape, which is more performant when used in checks later on.
205205
this.internalShape = new Shape();

spigot/src/main/resources/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ custom_items:
155155
update: true
156156

157157
recipes:
158+
# Allow ItemsAdder items to be used as ingredient or a result item in recipes. (Might break crafting of ItemsAdder items so if you encounter issues, turn this off)
159+
ia_fix: true
158160
# Toggle the Brewing Recipes. They are off by default to prevent possible duplication issues
159161
brewing: false
160162
# Used to block any kind of custom recipe. If enabled no one will be able to craft any custom recipe anymore.

0 commit comments

Comments
 (0)