Skip to content

Commit 33d2ad4

Browse files
committed
feat: mÃodernize and fix error for craft with same item
1 parent a0c4bbc commit 33d2ad4

File tree

12 files changed

+294
-100
lines changed

12 files changed

+294
-100
lines changed

.github/workflows/gradle.yml

Lines changed: 23 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,30 @@
1-
# This workflow uses actions that are not certified by GitHub.
2-
# They are provided by a third-party and are governed by
3-
# separate terms of service, privacy policy, and support
4-
# documentation.
5-
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
6-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
7-
8-
name: Java CI with Gradle
1+
name: Build Action
92

103
on:
114
push:
12-
branches: [ "main" ]
5+
branches: [ main, develop ]
136
pull_request:
14-
branches: [ "main" ]
15-
16-
jobs:
17-
build:
18-
19-
runs-on: ubuntu-latest
20-
permissions:
21-
contents: read
22-
23-
steps:
24-
- uses: actions/checkout@v4
25-
- name: Set up JDK 21
26-
uses: actions/setup-java@v4
27-
with:
28-
java-version: '21'
29-
distribution: 'temurin'
7+
types: [ opened, synchronize, reopened ]
8+
workflow_dispatch:
309

31-
# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
32-
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
33-
- name: Setup Gradle
34-
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
35-
- name: Grant Access
36-
run: chmod +x ./gradlew
37-
- name: Build with Gradle Wrapper
38-
run: ./gradlew build
10+
permissions:
11+
contents: read
12+
packages: write
3913

40-
# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html).
41-
# If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version.
42-
#
43-
# - name: Setup Gradle
44-
# uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
45-
# with:
46-
# gradle-version: '8.9'
47-
#
48-
# - name: Build with Gradle 8.9
49-
# run: gradle build
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
5017

51-
dependency-submission:
52-
53-
runs-on: ubuntu-latest
54-
permissions:
55-
contents: write
56-
57-
steps:
58-
- uses: actions/checkout@v4
59-
- name: Set up JDK 21
60-
uses: actions/setup-java@v4
61-
with:
62-
java-version: '21'
63-
distribution: 'temurin'
64-
65-
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
66-
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
67-
- name: Generate and submit dependency graph
68-
uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
18+
jobs:
19+
build:
20+
name: Build and Publish RecipesAPI
21+
uses: GroupeZ-dev/actions/.github/workflows/build.yml@main
22+
with:
23+
project-name: "RecipesAPI"
24+
publish: true
25+
publish-on-discord: false
26+
project-to-publish: "publish"
27+
secrets:
28+
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
29+
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
30+
WEBHOOK_URL: ""

build.gradle

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
plugins {
2-
id 'java'
3-
id 'maven-publish'
2+
id 'java-library'
3+
id 're.alwyn974.groupez.publish' version '1.0.0'
4+
id 'com.gradleup.shadow' version '9.0.0-beta11'
45
}
56

67
group = 'fr.traqueur'
78
version = property("version")
89

10+
ext.targetFolder = file("target/")
11+
ext.classifier = System.getProperty("archive.classifier")
12+
ext.sha = System.getProperty("github.sha")
13+
14+
if (ext.sha) {
15+
version = ext.sha
16+
}
17+
918
repositories {
1019
mavenCentral()
1120
maven {
@@ -24,7 +33,7 @@ repositories {
2433
}
2534

2635
dependencies {
27-
compileOnly "org.spigotmc:spigot-api:1.21.4-R0.1-SNAPSHOT"
36+
compileOnly "org.spigotmc:spigot-api:1.21.8-R0.1-SNAPSHOT"
2837

2938
// Hooks
3039
compileOnly 'io.th0rgal:oraxen:1.181.0'
@@ -43,18 +52,21 @@ tasks.register('generateVersionProperties') {
4352

4453
processResources.dependsOn generateVersionProperties
4554

55+
build.dependsOn shadowJar
56+
57+
shadowJar {
58+
archiveClassifier.set("")
59+
destinationDirectory.set(project.ext.targetFolder)
60+
}
61+
4662
java {
4763
sourceCompatibility = JavaVersion.VERSION_21
4864
targetCompatibility = JavaVersion.VERSION_21
4965
withSourcesJar()
5066
withJavadocJar()
5167
}
5268

53-
54-
publishing {
55-
publications {
56-
maven(MavenPublication) {
57-
from components.java
58-
}
59-
}
60-
}
69+
publishConfig {
70+
githubOwner = "Traqueur-dev"
71+
useRootProjectName = true
72+
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=3.1.1
1+
version=3.2.0

jitpack.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

settings.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
pluginManagement {
2+
repositories {
3+
maven {
4+
name = "groupezReleases"
5+
url = uri("https://repo.groupez.dev/releases")
6+
}
7+
gradlePluginPortal()
8+
}
9+
}
10+
111
rootProject.name = 'RecipesAPI'
212

313
include ':test-plugin'

src/main/java/fr/traqueur/recipes/api/RecipesAPI.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import fr.traqueur.recipes.api.hook.Hook;
44
import fr.traqueur.recipes.impl.PrepareCraftListener;
55
import fr.traqueur.recipes.impl.domains.ItemRecipe;
6+
import fr.traqueur.recipes.impl.domains.recipes.RecipeBuilder;
67
import fr.traqueur.recipes.impl.updater.Updater;
78
import org.bukkit.plugin.Plugin;
89

@@ -135,4 +136,13 @@ public void debug(String message, Object... args) {
135136
public RecipeLoader createLoader() {
136137
return new RecipeLoader(plugin, this);
137138
}
139+
140+
/**
141+
* Create a new blank {@link RecipeBuilder} ready to be configured.
142+
* Shortcut for {@code new RecipeBuilder()}.
143+
* @return a fresh RecipeBuilder
144+
*/
145+
public RecipeBuilder recipe() {
146+
return new RecipeBuilder();
147+
}
138148
}

src/main/java/fr/traqueur/recipes/api/domains/Ingredient.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package fr.traqueur.recipes.api.domains;
22

3+
import fr.traqueur.recipes.api.hook.Hook;
4+
import fr.traqueur.recipes.impl.domains.ingredients.ItemStackIngredient;
5+
import fr.traqueur.recipes.impl.domains.ingredients.MaterialIngredient;
6+
import fr.traqueur.recipes.impl.domains.ingredients.StrictItemStackIngredient;
7+
import fr.traqueur.recipes.impl.domains.ingredients.TagIngredient;
8+
import org.bukkit.Material;
9+
import org.bukkit.Tag;
310
import org.bukkit.inventory.ItemStack;
411
import org.bukkit.inventory.RecipeChoice;
512

@@ -42,4 +49,77 @@ public Character sign() {
4249
* @return The choice of the ingredient.
4350
*/
4451
public abstract RecipeChoice choice();
52+
53+
// ── Factory methods ────────────────────────────────────────────────────────
54+
55+
/** Create a material-based ingredient (matches any item of that type). */
56+
public static Ingredient of(Material material) {
57+
return new MaterialIngredient(material, null);
58+
}
59+
60+
/** Create a material-based ingredient with a shaped-recipe sign. */
61+
public static Ingredient of(Material material, Character sign) {
62+
return new MaterialIngredient(material, sign);
63+
}
64+
65+
/** Create an ItemStack-based ingredient (checks meta, PDC, lore…). */
66+
public static Ingredient of(ItemStack item) {
67+
return new ItemStackIngredient(item, null);
68+
}
69+
70+
/** Create an ItemStack-based ingredient with a shaped-recipe sign. */
71+
public static Ingredient of(ItemStack item, Character sign) {
72+
return new ItemStackIngredient(item, sign);
73+
}
74+
75+
/**
76+
* Create an ItemStack-based ingredient.
77+
* @param strict if true, uses Bukkit's native {@code ItemStack.isSimilar()} (exact meta match)
78+
*/
79+
public static Ingredient of(ItemStack item, boolean strict) {
80+
return strict ? new StrictItemStackIngredient(item, null) : new ItemStackIngredient(item, null);
81+
}
82+
83+
/**
84+
* Create an ItemStack-based ingredient with a shaped-recipe sign.
85+
* @param strict if true, uses Bukkit's native {@code ItemStack.isSimilar()} (exact meta match)
86+
*/
87+
public static Ingredient of(ItemStack item, Character sign, boolean strict) {
88+
return strict ? new StrictItemStackIngredient(item, sign) : new ItemStackIngredient(item, sign);
89+
}
90+
91+
/** Create a tag-based ingredient (matches any item in the given Bukkit tag). */
92+
public static Ingredient of(Tag<Material> tag) {
93+
return new TagIngredient(tag, null);
94+
}
95+
96+
/** Create a tag-based ingredient with a shaped-recipe sign. */
97+
public static Ingredient of(Tag<Material> tag, Character sign) {
98+
return new TagIngredient(tag, sign);
99+
}
100+
101+
/**
102+
* Create an ingredient from a hook plugin (e.g. {@code "oraxen"} or {@code "itemsadder"}).
103+
* The hook must be enabled on the server.
104+
* @param pluginName the hook plugin name (case-insensitive)
105+
* @param itemId the custom item id recognised by that plugin
106+
*/
107+
public static Ingredient ofHook(String pluginName, String itemId) {
108+
return ofHook(pluginName, itemId, null);
109+
}
110+
111+
/**
112+
* Create a hook-based ingredient with a shaped-recipe sign.
113+
* @param pluginName the hook plugin name (case-insensitive)
114+
* @param itemId the custom item id recognised by that plugin
115+
* @param sign the shaped-recipe sign, or {@code null} for shapeless
116+
*/
117+
public static Ingredient ofHook(String pluginName, String itemId, Character sign) {
118+
return Hook.HOOKS.stream()
119+
.filter(Hook::isEnable)
120+
.filter(h -> h.getPluginName().equalsIgnoreCase(pluginName))
121+
.findFirst()
122+
.orElseThrow(() -> new IllegalArgumentException("No enabled hook found for plugin: " + pluginName))
123+
.getIngredient(itemId, sign);
124+
}
45125
}

src/main/java/fr/traqueur/recipes/api/domains/Recipe.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.traqueur.recipes.api.domains;
22

33
import fr.traqueur.recipes.api.RecipeType;
4+
import fr.traqueur.recipes.api.Util;
45
import fr.traqueur.recipes.impl.domains.ItemRecipe;
56
import fr.traqueur.recipes.impl.domains.ingredients.ItemStackIngredient;
67
import fr.traqueur.recipes.impl.domains.ingredients.MaterialIngredient;
@@ -150,6 +151,39 @@ default Recipe addIngredient(Material material, Character sign) {
150151
*/
151152
Recipe addIngredient(Ingredient ingredient);
152153

154+
/**
155+
* Add an ingredient parsed from a string identifier.
156+
* Supports the same formats as YAML config:
157+
* {@code "MATERIAL"}, {@code "material:NAME"}, {@code "item:NAME"},
158+
* {@code "base64:XXX"}, {@code "tag:NAME"}, {@code "oraxen:id"}, {@code "itemsadder:id"}, etc.
159+
* @param itemIdentifier the string identifier
160+
* @return The recipe.
161+
*/
162+
default Recipe addIngredient(String itemIdentifier) {
163+
return addIngredient(Util.parseIngredient(itemIdentifier, null, false));
164+
}
165+
166+
/**
167+
* Add an ingredient parsed from a string identifier with a shaped-recipe sign.
168+
* @param itemIdentifier the string identifier
169+
* @param sign the sign character used in the shaped pattern
170+
* @return The recipe.
171+
*/
172+
default Recipe addIngredient(String itemIdentifier, Character sign) {
173+
return addIngredient(Util.parseIngredient(itemIdentifier, sign, false));
174+
}
175+
176+
/**
177+
* Add an ingredient parsed from a string identifier.
178+
* @param itemIdentifier the string identifier
179+
* @param sign the sign character (null for shapeless)
180+
* @param strict if true, uses strict matching ({@link StrictItemStackIngredient})
181+
* @return The recipe.
182+
*/
183+
default Recipe addIngredient(String itemIdentifier, Character sign, boolean strict) {
184+
return addIngredient(Util.parseIngredient(itemIdentifier, sign, strict));
185+
}
186+
153187
/**
154188
* Set the group of the recipe.
155189
* @param group The group of the recipe.

0 commit comments

Comments
 (0)