Skip to content

Commit

Permalink
[1.0.6.11] fixed missing potion data class
Browse files Browse the repository at this point in the history
I hate md_5 for removing a class deprecated literally few months ago without providing commodore support
  • Loading branch information
Misat11 committed Apr 25, 2024
1 parent d2d15bf commit e70a457
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 48 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defaultTasks 'clean', 'screamCompile'

allprojects {
group = 'org.screamingsandals.simpleinventories'
version = '1.0.6.10'
version = '1.0.6.11'
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,13 @@ public void potion(String potion) {
} else {
ItemMeta meta = stack.getItemMeta();
if (meta instanceof PotionMeta) {
((PotionMeta) meta).setBasePotionData(PotionTypeSearchEngine.find(potion));
stack.setItemMeta(meta);
if (MaterialSearchEngine.getVersionNumber() > 120 || MaterialSearchEngine.isV1_20_5()) {
PotionTypeSearchEngine1_20_5.setPotionType((PotionMeta) meta, PotionTypeSearchEngine1_20_5.find(potion));
stack.setItemMeta(meta);
} else {
((PotionMeta) meta).setBasePotionData(PotionTypeSearchEngine.find(potion));
stack.setItemMeta(meta);
}
}
}
}
Expand All @@ -130,8 +135,12 @@ public void potion(String potion) {
public void potion(PotionType potion) {
ItemMeta meta = stack.getItemMeta();
if (meta instanceof PotionMeta) {
((PotionMeta) meta).setBasePotionData(new PotionData(potion));
stack.setItemMeta(meta);
if (MaterialSearchEngine.getVersionNumber() > 120 || MaterialSearchEngine.isV1_20_5()) {
PotionTypeSearchEngine1_20_5.setPotionType((PotionMeta) meta, potion);
} else {
((PotionMeta) meta).setBasePotionData(new PotionData(potion));
stack.setItemMeta(meta);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.screamingsandals.simpleinventories.utils;

import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionType;

import java.lang.reflect.InvocationTargetException;
import java.util.Locale;

public class PotionTypeSearchEngine1_20_5 {
public static PotionType find(String potionType) {
String potion = potionType.toUpperCase(Locale.ROOT);

// allow prefixing vanilla stuff with minecraft:
if (potion.startsWith("MINECRAFT:")) {
potion = potion.substring(10);
}

return PotionType.valueOf(potion);
}

public static void setPotionType(PotionMeta meta, PotionType potionType) {
try {
PotionMeta.class.getMethod("setBasePotionType", PotionType.class).invoke(meta, potionType);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,30 @@ public class PotionTypeSearchEngine1_8_8 {
private static final Map<String, String> regular = new HashMap<String, String>() {
{
put("water", "WATER");
if (MaterialSearchEngine.isV1_20_5() || MaterialSearchEngine.getVersionNumber() > 120) {
put("regeneration", "REGENERATION");
put("swiftness", "SWIFTNESS");
} else {
put("regeneration", "REGEN");
put("swiftness", "SPEED");
}
put("regeneration", "REGEN");
put("swiftness", "SPEED");
put("fire_resistance", "FIRE_RESISTANCE");
put("poison", "POISON");
if (MaterialSearchEngine.isV1_20_5() || MaterialSearchEngine.getVersionNumber() > 120) {
put("healing", "HEALING");
} else {
put("healing", "INSTANT_HEAL");
}
put("healing", "INSTANT_HEAL");
put("night_vision", "NIGHT_VISION");
put("weakness", "WEAKNESS");
put("strength", "STRENGTH");
put("slowness", "SLOWNESS");
if (MaterialSearchEngine.isV1_20_5() || MaterialSearchEngine.getVersionNumber() > 120) {
put("leaping", "LEAPING");
put("harming", "HARMING");
} else {
put("leaping", "JUMP");
put("harming", "INSTANT_DAMAGE");
}
put("leaping", "JUMP");
put("harming", "INSTANT_DAMAGE");
put("water_breathing", "WATER_BREATHING");
put("invisibility", "INVISIBILITY");
}
};

private static final Map<String, String> upgradeable = new HashMap<String, String>() {
{
if (MaterialSearchEngine.isV1_20_5() || MaterialSearchEngine.getVersionNumber() > 120) {
put("strong_leaping", "LEAPING");
put("strong_swiftness", "SWIFTNESS");
put("strong_healing", "HEALING");
put("strong_harming", "HARMING");
put("strong_regeneration", "REGENERATION");
} else {
put("strong_leaping", "JUMP");
put("strong_swiftness", "SPEED");
put("strong_healing", "INSTANT_HEAL");
put("strong_harming", "INSTANT_DAMAGE");
put("strong_regeneration", "REGEN");
}
put("strong_leaping", "JUMP");
put("strong_swiftness", "SPEED");
put("strong_healing", "INSTANT_HEAL");
put("strong_harming", "INSTANT_DAMAGE");
put("strong_poison", "POISON");
put("strong_regeneration", "REGEN");
put("strong_strength", "STRENGTH");
put("strong_slowness", "SLOWNESS");
}
Expand All @@ -70,19 +48,13 @@ public class PotionTypeSearchEngine1_8_8 {
{
put("long_night_vision", "NIGHT_VISION");
put("long_invisibility", "INVISIBILITY");
if (MaterialSearchEngine.isV1_20_5() || MaterialSearchEngine.getVersionNumber() > 120) {
put("long_leaping", "LEAPING");
put("long_swiftness", "SWIFTNESS");
put("long_regeneration", "REGENERATION");
} else {
put("long_leaping", "JUMP");
put("long_swiftness", "SPEED");
put("long_regeneration", "REGEN");
}
put("long_leaping", "JUMP");
put("long_fire_resistance", "FIRE_RESISTANCE");
put("long_swiftness", "SPEED");
put("long_slowness", "SLOWNESS");
put("long_water_breathing", "WATER_BREATHING");
put("long_poison", "POISON");
put("long_regeneration", "REGEN");
put("long_strength", "STRENGTH");
put("long_weakness", "WEAKNESS");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,17 @@ public static ItemStack parseLongStack(Map<String, Object> obj) {
return stack; // return earlier
} else {
if (ob instanceof PotionType) {
potion.setBasePotionData(new PotionData((PotionType) ob));
if (MaterialSearchEngine.isV1_20_5() || MaterialSearchEngine.getVersionNumber() > 120) {
PotionTypeSearchEngine1_20_5.setPotionType(potion, (PotionType) ob);
} else {
potion.setBasePotionData(new PotionData((PotionType) ob));
}
} else {
potion.setBasePotionData(PotionTypeSearchEngine.find(ob.toString()));
if (MaterialSearchEngine.isV1_20_5() || MaterialSearchEngine.getVersionNumber() > 120) {
PotionTypeSearchEngine1_20_5.setPotionType(potion, PotionTypeSearchEngine1_20_5.find(ob.toString()));
} else {
potion.setBasePotionData(PotionTypeSearchEngine.find(ob.toString()));
}
}
}
}
Expand Down

0 comments on commit e70a457

Please sign in to comment.