Skip to content

Commit

Permalink
Fixes for potiondata 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorfromhell committed Aug 3, 2024
1 parent 4f92c7c commit d94c120
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.tnemc</groupId>
<artifactId>TNIL</artifactId>
<version>0.1.7.6-Pre-12</version>
<version>0.1.7.6-Pre-122</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -107,7 +107,7 @@
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>TNIL-BukkitBase</artifactId>
<version>0.1.7.6-Pre-12</version>
<version>0.1.7.6-Pre-122</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions BukkitBase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.tnemc</groupId>
<artifactId>TNIL</artifactId>
<version>0.1.7.6-Pre-12</version>
<version>0.1.7.6-Pre-122</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -101,7 +101,7 @@
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>TNIL-Core</artifactId>
<version>0.1.7.6-Pre-12</version>
<version>0.1.7.6-Pre-122</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import net.tnemc.item.data.SerialPotionData;
import net.tnemc.item.data.potion.PotionEffectData;
import org.bukkit.Color;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
Expand All @@ -47,9 +49,23 @@ public void of(ItemStack stack) {
if(meta != null) {

if(meta.hasColor()) colorRGB = meta.getColor().asRGB();
type = meta.getBasePotionData().getType().name();
extended = meta.getBasePotionData().isExtended();
upgraded = meta.getBasePotionData().isUpgraded();

try {

if(meta.hasBasePotionType()) {
updated = true;
type = meta.getBasePotionType().getKey().getKey();
extended = meta.getBasePotionType().isExtendable();
upgraded = meta.getBasePotionType().isUpgradeable();
}

} catch(Exception ignore) {
if(meta.getBasePotionData() != null) {
type = meta.getBasePotionData().getType().name();
extended = meta.getBasePotionData().isExtended();
upgraded = meta.getBasePotionData().isUpgraded();
}
}

for(final PotionEffect effect : meta.getCustomEffects()) {

Expand Down Expand Up @@ -82,8 +98,16 @@ public ItemStack apply(ItemStack stack) {
effect.isAmbient(),
effect.hasParticles(),
effect.hasIcon()), true));
final PotionData data = new PotionData(PotionType.valueOf(type), extended, upgraded);
meta.setBasePotionData(data);

if(updated) {
try {
final PotionType potionType = Registry.POTION.get(NamespacedKey.fromString(type));
meta.setBasePotionType(potionType);
} catch(Exception ignore) {}
} else {
final PotionData data = new PotionData(PotionType.valueOf(type), extended, upgraded);
meta.setBasePotionData(data);
}
stack.setItemMeta(meta);
return stack;
}
Expand Down
2 changes: 1 addition & 1 deletion Core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.tnemc</groupId>
<artifactId>TNIL</artifactId>
<version>0.1.7.6-Pre-12</version>
<version>0.1.7.6-Pre-122</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
39 changes: 27 additions & 12 deletions Core/src/net/tnemc/item/data/SerialPotionData.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
public abstract class SerialPotionData<T> implements SerialItemData<T> {

protected final List<PotionEffectData> customEffects = new ArrayList<>();
protected String type;
protected String type = null;
protected int colorRGB = -1;
protected boolean extended;
protected boolean upgraded;
protected boolean updated = false; //magic value for bukkit fuckiness

/**
* Converts the {@link SerialItemData} to a JSON object.
Expand All @@ -45,12 +46,16 @@ public abstract class SerialPotionData<T> implements SerialItemData<T> {
public JSONObject toJSON() {
final JSONObject json = new JSONObject();
json.put("name", "potion");
json.put("type", type);
if(colorRGB != -1) json.put("colour", colorRGB);
json.put("extended", extended);
json.put("upgraded", upgraded);

if(customEffects.size() > 0) {
if(type != null) {
json.put("type", type);
json.put("updated", updated);
json.put("extended", extended);
json.put("upgraded", upgraded);
}

if(!customEffects.isEmpty()) {
final JSONObject effects = new JSONObject();
for(PotionEffectData effect : customEffects) {

Expand All @@ -68,11 +73,17 @@ public JSONObject toJSON() {
*/
@Override
public void readJSON(JSONHelper json) {
type = json.getString("type");

if(json.has("colour")) colorRGB = json.getInteger("colour");
extended = json.getBoolean("extended");
upgraded = json.getBoolean("upgraded");

if(json.has("type")) {
type = json.getString("type");
extended = json.getBoolean("extended");
upgraded = json.getBoolean("upgraded");

if(json.has("updated")) {
updated = json.getBoolean("updated");
}
}

if(json.has("effects")) {
final JSONHelper effects = json.getHelper("effects");
Expand All @@ -94,9 +105,13 @@ public void readJSON(JSONHelper json) {
@Override
public boolean equals(SerialItemData<? extends T> data) {
if(data instanceof SerialPotionData<?> compare) {
return customEffects.equals(compare.customEffects) && type.equalsIgnoreCase(compare.type)
&& colorRGB == compare.colorRGB && extended == compare.extended
&& upgraded == compare.upgraded;

if(type != null) {
return customEffects.equals(compare.customEffects) && type.equalsIgnoreCase(compare.type)
&& colorRGB == compare.colorRGB && extended == compare.extended
&& upgraded == compare.upgraded;
}
return customEffects.equals(compare.customEffects) && colorRGB == compare.colorRGB;
}
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions Paper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>net.tnemc</groupId>
<artifactId>TNIL</artifactId>
<version>0.1.7.6-Pre-12</version>
<version>0.1.7.6-Pre-122</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -108,7 +108,7 @@
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>TNIL-BukkitBase</artifactId>
<version>0.1.7.6-Pre-12</version>
<version>0.1.7.6-Pre-122</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions TNIL-Sponge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>TNIL</artifactId>
<groupId>net.tnemc</groupId>
<version>0.1.7.6-Pre-12</version>
<version>0.1.7.6-Pre-122</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -105,7 +105,7 @@
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>TNIL-Core</artifactId>
<version>0.1.7.6-Pre-12</version>
<version>0.1.7.6-Pre-122</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
4 changes: 2 additions & 2 deletions TNIL-Sponge7/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>TNIL</artifactId>
<groupId>net.tnemc</groupId>
<version>0.1.7.6-Pre-12</version>
<version>0.1.7.6-Pre-122</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -56,7 +56,7 @@
<dependency>
<groupId>net.tnemc</groupId>
<artifactId>TNIL-Core</artifactId>
<version>0.1.7.6-Pre-12</version>
<version>0.1.7.6-Pre-122</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.tnemc</groupId>
<artifactId>TNIL</artifactId>
<version>0.1.7.6-Pre-12</version>
<version>0.1.7.6-Pre-122</version>
<packaging>pom</packaging>
<name>The New Item Library</name>

Expand Down

0 comments on commit d94c120

Please sign in to comment.