Skip to content

Commit fd43096

Browse files
committed
1.21.4 BABYYY
1 parent e4edb99 commit fd43096

13 files changed

+135
-44
lines changed

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ jobs:
2626
- name: Release
2727
uses: softprops/action-gh-release@v2
2828
with:
29-
tag_name: "latest-1.21"
30-
name: "[1.1.0 for 1.21] Development Build"
29+
tag_name: "latest-1.21.4"
30+
name: "[1.3.0 for 1.21.4] Development Build"
3131
body: "Push-ly development build for Caramel. Updated on every push - ignore the 'commits to master since this release', github works weird."
3232
prerelease: false
3333
files: |

docs/index.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ Caramel is a multipurpose AIO api for PaperAPI plugins. ***Caramel can not and w
1212
- Simply drop in the latest Caramel jarfile from [here](https://github.com/klashdevelopment/Caramel/releases/tag/latest-1.21)
1313

1414
## Quickstart (Developer)
15+
- Make sure you have Paper API 1.21.4 in your pom
1516
- Add Caramel to your maven:
1617

17-
LATEST VERSION: 1.2.0
18-
1918
```xml
2019
<repository>
2120
<id>klashdevelopment</id>
@@ -25,7 +24,7 @@ LATEST VERSION: 1.2.0
2524
<dependency>
2625
<groupId>dev.klash</groupId>
2726
<artifactId>Caramel</artifactId>
28-
<version>VERSION</version>
27+
<version>1.3.1</version>
2928
<scope>provided</scope>
3029
</dependency>
3130
```

docs/items.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ The documentation for items are WIP, but here's a simple implementation while yo
99
public CaramelItemDetail getDetails() {
1010
return CaramelItemDetail.builder()
1111
.id("item_identifier") // Required
12-
.defaultStack(1) // Required
12+
.defaultStack(1) // Optional
1313
.modelData(0) // Optional - Custom Model Data
1414
.itemBase(Material.PAPER) // Required
1515
.itemName(CaramelUtility.colorcomp("<gold><bold>Supports miniMessage")) // Required
1616
.lore(Arrays.asList("Lore <red>is cool<yellow>!")) // Required
17+
.components(...) // Optional, see below
1718
.build();
1819
}
1920

@@ -34,3 +35,15 @@ The documentation for items are WIP, but here's a simple implementation while yo
3435
```
3536

3637
Please see Commands for registering, but use `Caramel.getInstance().items` and define it as a `CaramelItem`.
38+
39+
40+
### Item components
41+
As of caramel 1.3.1 (1.21.4) you can add item components!
42+
43+
```java
44+
/// builder stuff
45+
.components(
46+
CIComponent.of(DataComponentType.EXAMPLE, example), // valued
47+
CIComponent.of(DataComponentType.EXAMPLE) // non valued
48+
)
49+
```

pom.xml

+11-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>dev.klash</groupId>
88
<artifactId>Caramel</artifactId>
9-
<version>1.2.0</version>
9+
<version>1.3.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>Caramel</name>
@@ -28,7 +28,7 @@
2828
<plugin>
2929
<groupId>org.apache.maven.plugins</groupId>
3030
<artifactId>maven-compiler-plugin</artifactId>
31-
<version>3.8.1</version>
31+
<version>3.13.0</version>
3232
<configuration>
3333
<source>21</source>
3434
<target>21</target>
@@ -50,7 +50,7 @@
5050
<relocations>
5151
<relocation>
5252
<pattern>net.wesjd.anvilgui</pattern>
53-
<shadedPattern>dev.klash.dependencies.anvilgui</shadedPattern> <!-- Replace [YOUR_PLUGIN_PACKAGE] with your namespace -->
53+
<shadedPattern>dev.klash.dependencies.anvilgui</shadedPattern>
5454
</relocation>
5555
</relocations>
5656
<filters>
@@ -75,7 +75,7 @@
7575

7676
<repositories>
7777
<repository>
78-
<id>papermc-repo</id>
78+
<id>papermc</id>
7979
<url>https://repo.papermc.io/repository/maven-public/</url>
8080
</repository>
8181
<repository>
@@ -86,24 +86,27 @@
8686
<id>codemc-snapshots</id>
8787
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
8888
</repository>
89+
<repository>
90+
<id>klashdevelopment</id>
91+
<url>https://raw.githubusercontent.com/klashdevelopment/mvn/main/repository/</url>
92+
</repository>
8993
</repositories>
90-
9194
<dependencies>
9295
<dependency>
9396
<groupId>io.papermc.paper</groupId>
9497
<artifactId>paper-api</artifactId>
95-
<version>1.21-R0.1-SNAPSHOT</version>
98+
<version>1.21.4-R0.1-SNAPSHOT</version>
9699
<scope>provided</scope>
97100
</dependency>
98101
<dependency>
99102
<groupId>com.samjakob</groupId>
100103
<artifactId>SpiGUI</artifactId>
101-
<version>1.3.1</version>
104+
<version>1.4.0-recomp</version>
102105
</dependency>
103106
<dependency>
104107
<groupId>net.wesjd</groupId>
105108
<artifactId>anvilgui</artifactId>
106-
<version>1.10.2-SNAPSHOT</version>
109+
<version>1.10.4-SNAPSHOT</version>
107110
</dependency>
108111
</dependencies>
109112
</project>

src/main/java/dev/klash/caramel/items/CaramelFactory.java

+19-9
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33
import com.samjakob.spigui.item.ItemBuilder;
44
import dev.klash.caramel.Caramel;
55
import dev.klash.caramel.CaramelUtility;
6+
import dev.klash.caramel.items.components.CIComponent;
7+
import io.papermc.paper.datacomponent.DataComponentTypes;
68
import org.bukkit.Material;
79
import org.bukkit.NamespacedKey;
810
import org.bukkit.inventory.ItemStack;
911
import org.bukkit.inventory.meta.ItemMeta;
10-
import org.bukkit.inventory.meta.components.FoodComponent;
12+
import io.papermc.paper.datacomponent.item.FoodProperties;
1113
import org.bukkit.persistence.PersistentDataType;
1214

1315
public class CaramelFactory {
16+
// Allow using <T> parameter
17+
private static <T> void setDataHelper(ItemStack i, CIComponent.CIComponentValued<T> component) {
18+
i.setData(component.getComponent(), component.getValue());
19+
}
1420
public static ItemStack build(CaramelItem item) {
1521
ItemStack i = new ItemStack(item.getDetails().itemBase());
1622
ItemMeta m = i.getItemMeta();
@@ -19,15 +25,19 @@ public static ItemStack build(CaramelItem item) {
1925
m.setCustomModelData(item.getDetails().modelData());
2026

2127
if(item.getDetails().food() != null) {
22-
FoodComponent food = m.getFood();
23-
food.setCanAlwaysEat(item.getDetails().food().canAlwaysEat());
24-
food.setNutrition(item.getDetails().food().nutrition());
25-
food.setSaturation(item.getDetails().food().saturation());
26-
food.setEatSeconds(item.getDetails().food().eatTime());
27-
for(FoodEffectProperties fep : item.getDetails().food().effects()) {
28-
food.addEffect(fep.effect(), fep.chance());
28+
FoodProperties food = FoodProperties.food()
29+
.canAlwaysEat(item.getDetails().food().canAlwaysEat())
30+
.nutrition(item.getDetails().food().nutrition())
31+
.saturation(item.getDetails().food().saturation())
32+
.build();
33+
i.setData(DataComponentTypes.FOOD, food);
34+
}
35+
for (CIComponent component : item.getDetails().components()) {
36+
if(component instanceof CIComponent.CIComponentValued<?> valuedComponent) {
37+
setDataHelper(i, valuedComponent);
38+
} else {
39+
i.setData(((CIComponent.CIComponentNonvalued) component).getComponent());
2940
}
30-
m.setFood(food);
3141
}
3242

3343
m.getPersistentDataContainer().set(Caramel.getInstance().isCaramelKey, PersistentDataType.BOOLEAN, true);

src/main/java/dev/klash/caramel/items/CaramelItemDetail.java

+22-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
package dev.klash.caramel.items;
22

3+
import dev.klash.caramel.items.components.CIComponent;
34
import net.kyori.adventure.text.Component;
45
import org.bukkit.Material;
6+
import org.jetbrains.annotations.ApiStatus;
57

8+
import java.util.Arrays;
9+
import java.util.Collections;
610
import java.util.List;
711

8-
public record CaramelItemDetail(String id, Component itemName, List<String> lore, int defaultStack, int modelData, Material itemBase, FoodProperties food) {
9-
12+
public record CaramelItemDetail(String id, Component itemName, List<String> lore, int defaultStack, int modelData, Material itemBase, FoodProperties food, List<CIComponent> components) {
1013
public static class Builder {
1114
private String id;
1215
private Component itemName;
1316
private List<String> lore;
14-
private int defaultStack;
17+
private int defaultStack = 1;
1518
private int modelData;
1619
private Material itemBase;
17-
private FoodProperties food = null;
20+
@ApiStatus.Experimental private FoodProperties food = null;
21+
@ApiStatus.Experimental private List<CIComponent> components = Collections.emptyList();
1822

1923
public Builder id(String id) {
2024
this.id = id;
@@ -36,6 +40,7 @@ public Builder defaultStack(int defaultStack) {
3640
return this;
3741
}
3842

43+
@ApiStatus.Experimental
3944
public Builder food(FoodProperties food) {
4045
this.food = food;
4146
return this;
@@ -51,8 +56,20 @@ public Builder itemBase(Material itemBase) {
5156
return this;
5257
}
5358

59+
@ApiStatus.Experimental
60+
public Builder components(List<CIComponent> components) {
61+
this.components = components;
62+
return this;
63+
}
64+
65+
@ApiStatus.Experimental
66+
public Builder components(CIComponent... components) {
67+
this.components = Arrays.asList(components);
68+
return this;
69+
}
70+
5471
public CaramelItemDetail build() {
55-
return new CaramelItemDetail(id, itemName, lore, defaultStack, modelData, itemBase, food);
72+
return new CaramelItemDetail(id, itemName, lore, defaultStack, modelData, itemBase, food, components);
5673
}
5774
}
5875

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package dev.klash.caramel.items;
22

33
import org.bukkit.potion.PotionEffect;
4+
import org.jetbrains.annotations.ApiStatus;
45

6+
@ApiStatus.Experimental
7+
/*
8+
* This class is a WIP and will be added in a future update
9+
* Do not use this in production, it wont apply to the item as of Caramel 1.21.4 (we swapped to data components)
10+
*/
511
public record FoodEffectProperties(PotionEffect effect, float chance) {
612
}

src/main/java/dev/klash/caramel/items/FoodProperties.java

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package dev.klash.caramel.items;
22

3-
public record FoodProperties(int saturation, int nutrition, boolean canAlwaysEat, float eatTime, FoodEffectProperties... effects) {
3+
import org.jetbrains.annotations.ApiStatus;
4+
5+
@ApiStatus.Experimental
6+
public record FoodProperties(int saturation, int nutrition, boolean canAlwaysEat/*, int eatTime, FoodEffectProperties... effects*/) {
47
public static class Builder {
58
private int saturation = -1;
69
private int nutrition = -1;
710
private boolean canAlwaysEat = false;
8-
private int eatTime = 32;
9-
private FoodEffectProperties[] effects = new FoodEffectProperties[0];
11+
// private int eatTime = 32;
12+
// private FoodEffectProperties[] effects = new FoodEffectProperties[0];
1013

1114
public Builder saturation(int saturation) {
1215
this.saturation = saturation;
@@ -23,21 +26,21 @@ public Builder canAlwaysEat(boolean canAlwaysEat) {
2326
return this;
2427
}
2528

26-
public Builder eatTime(int eatTime) {
27-
this.eatTime = eatTime;
28-
return this;
29-
}
30-
31-
public Builder effects(FoodEffectProperties... effects) {
32-
this.effects = effects;
33-
return this;
34-
}
29+
// public Builder eatTime(int eatTime) {
30+
// this.eatTime = eatTime;
31+
// return this;
32+
// }
33+
//
34+
// public Builder effects(FoodEffectProperties... effects) {
35+
// this.effects = effects;
36+
// return this;
37+
// }
3538

3639
public FoodProperties build() {
3740
if(nutrition == -1 || saturation == -1) {
3841
throw new IllegalStateException("Nutrition and saturation must be set on Caramel food properties");
3942
}
40-
return new FoodProperties(saturation, nutrition, canAlwaysEat, eatTime, effects);
43+
return new FoodProperties(saturation, nutrition, canAlwaysEat/*, eatTime, effects*/);
4144
}
4245
}
4346

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package dev.klash.caramel.items.components;
2+
3+
import io.papermc.paper.datacomponent.DataComponentType;
4+
5+
public abstract class CIComponent {
6+
public static class CIComponentNonvalued extends CIComponent {
7+
private DataComponentType.NonValued component;
8+
private CIComponentNonvalued(DataComponentType.NonValued component) {
9+
this.component = component;
10+
}
11+
public DataComponentType.NonValued getComponent() {
12+
return component;
13+
}
14+
}
15+
public static class CIComponentValued<T> extends CIComponent {
16+
private DataComponentType.Valued<T> component;
17+
private T value;
18+
private CIComponentValued(DataComponentType.Valued<T> component, T value) {
19+
this.component = component;
20+
this.value = value;
21+
}
22+
public DataComponentType.Valued<T> getComponent() {
23+
return component;
24+
}
25+
public T getValue() {
26+
return value;
27+
}
28+
}
29+
public static CIComponent of(DataComponentType.NonValued component) {
30+
return new CIComponentNonvalued(component);
31+
}
32+
public static <T> CIComponent of(DataComponentType.Valued<T> component, T value) {
33+
return new CIComponentValued<T>(component, value);
34+
}
35+
}

src/main/java/dev/klash/caramel/plugin/ImplCaramelDefault.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public void whenAnyRun(CommandSender sender, List<String> args) {
190190
}));
191191
}
192192
((Player)sender).openInventory(menu.getInventory());
193-
}else {
193+
} else {
194194
sender.sendMessage(CaramelUtility.colorcomp(Caramel.getInstance().getPrefix() + " Listing items"));
195195
for(CaramelItem item : Caramel.getInstance().items.getItemList()) {
196196
sender.sendMessage(CaramelUtility.colorcomp(Caramel.getInstance().getPrefix() + "<green> ID <red>" + item.getDetails().id() +" <green> with name <red>" + item.getDetails().itemName()));
@@ -208,7 +208,7 @@ public void whenAnyRun(CommandSender sender, List<String> args) {
208208
}));
209209
}
210210
((Player)sender).openInventory(menu.getInventory());
211-
}else {
211+
} else {
212212
sender.sendMessage(CaramelUtility.colorcomp(Caramel.getInstance().getPrefix() + " Listing guis"));
213213
for(CaramelGui gui : Caramel.getInstance().guis.getGuis()) {
214214
sender.sendMessage(CaramelUtility.colorcomp(Caramel.getInstance().getPrefix() + "<green> Title <red>" + gui.title +" <green> with override <red>" + (gui.override==null?"none":gui.override.name())));

src/main/java/dev/klash/caramel/sql/CaramelSQL.java

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package dev.klash.caramel.sql;
22

3+
import org.jetbrains.annotations.ApiStatus;
4+
35
import java.sql.Connection;
46
import java.sql.DriverManager;
57
import java.sql.SQLException;
68

9+
@ApiStatus.Experimental
710
public class CaramelSQL {
811

912
public String host, port, database, username, password;

src/main/java/dev/klash/caramel/sql/CaramelSQLHelper.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package dev.klash.caramel.sql;
22

33
import org.bukkit.entity.Player;
4+
import org.jetbrains.annotations.ApiStatus;
45

56
import java.sql.PreparedStatement;
67
import java.sql.ResultSet;
78
import java.sql.SQLException;
89
import java.util.UUID;
910

11+
@ApiStatus.Experimental
1012
public class CaramelSQLHelper {
1113

1214
private CaramelSQL sql;

src/main/resources/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
messages:
2-
# If a user is denied permission.
2+
# If a user is denied permission. API forces this to use colorcodes and not minimessage sadly :/
33
no-permission: "&aYou have no permission to use this command."
44
# The caramel prefix only shows on /caramel.
55
caramel-prefix: "<yellow>[<gold>Caramel<yellow>]<green>"

0 commit comments

Comments
 (0)