fix REGEN potion not loading

This commit is contained in:
nossr50 2024-05-13 10:59:57 -07:00
parent 291effdbc8
commit 8d2a08c421
4 changed files with 43 additions and 40 deletions

View File

@ -1,6 +1,7 @@
Version 2.2.010 Version 2.2.010
# TODO: Fix not moving mcMMO custom ingredients from hopper -> brewing stand # TODO: Fix not moving mcMMO custom ingredients from hopper -> brewing stand
# TODO: Fix some potions are not rewarding XP ( strength 2, etc ) # TODO: Fix some potions are not rewarding XP ( strength 2, etc )
Fixed being unable to load REGEN potion type on new versions of Paper/Spigot 1.20.6
BrewingStand now remember who owns them, this persists across restarts (see notes) BrewingStand now remember who owns them, this persists across restarts (see notes)
Fixed rare NPE in mcMMO events when player data was unable to be retrieved Fixed rare NPE in mcMMO events when player data was unable to be retrieved
Fixed a NPE that could happen when damaging armor with Axes Fixed a NPE that could happen when damaging armor with Axes
@ -39,7 +40,7 @@ Version 2.2.010
NOTES: NOTES:
You can now use hoppers and brewing stands and not have to worry about having to re-interact with the brewing stand over and over again You can now use hoppers and brewing stands and not have to worry about having to re-interact with the brewing stand over and over again
This is not an exhaustive list of API changes in this update, but most of them should be documented here. This is not an exhaustive list of API changes in this update, but most of the important ones should be documented here.
Version 2.2.009 Version 2.2.009
Fixed a bug that prevented mcMMO from loading on MC versions older than 1.20.6 Fixed a bug that prevented mcMMO from loading on MC versions older than 1.20.6

View File

@ -374,7 +374,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.20.5-R0.1-SNAPSHOT</version> <version>1.20.6-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -71,10 +71,10 @@ public class PotionUtil {
* @return The potion type * @return The potion type
*/ */
public static PotionType matchPotionType(String partialName, boolean isUpgraded, boolean isExtended) { public static PotionType matchPotionType(String partialName, boolean isUpgraded, boolean isExtended) {
String updatedName = convertLegacyNames(partialName).toUpperCase();
if (COMPATIBILITY_MODE == PotionCompatibilityType.PRE_1_20_5) { if (COMPATIBILITY_MODE == PotionCompatibilityType.PRE_1_20_5) {
return matchLegacyPotionType(partialName); return matchLegacyPotionType(updatedName);
} else { } else {
String updatedName = convertLegacyNames(partialName);
return Arrays.stream(PotionType.values()) return Arrays.stream(PotionType.values())
.filter(potionType -> getKeyGetKey(potionType).toUpperCase().contains(partialName) .filter(potionType -> getKeyGetKey(potionType).toUpperCase().contains(partialName)
|| getKeyGetKey(potionType).toUpperCase().contains(convertLegacyNames(updatedName))) || getKeyGetKey(potionType).toUpperCase().contains(convertLegacyNames(updatedName)))
@ -84,6 +84,21 @@ public class PotionUtil {
} }
} }
/**
* Legacy matching for {@link PotionType}
*
* @param name The partial name of the potion
* @return The potion type
*/
private static PotionType matchLegacyPotionType(String name) {
return Arrays.stream(PotionType.values())
.filter(potionType -> getKeyGetKey(potionType).equalsIgnoreCase(name)
|| getKeyGetKey(potionType).equalsIgnoreCase(convertLegacyNames(name))
|| potionType.name().equalsIgnoreCase(name)
|| potionType.name().equalsIgnoreCase(convertLegacyNames(name)))
.findAny().orElse(null);
}
public static String getKeyGetKey(PotionType potionType) { public static String getKeyGetKey(PotionType potionType) {
try { try {
if (getKeyMethod() != null) { if (getKeyMethod() != null) {
@ -201,23 +216,6 @@ public class PotionUtil {
} }
} }
/**
* Legacy matching for {@link PotionType}
*
* @param partialName The partial name of the potion
* @return The potion type
*/
private static PotionType matchLegacyPotionType(String partialName) {
String updatedName = convertLegacyNames(partialName);
return Arrays.stream(PotionType.values())
.filter(potionType -> getKeyGetKey(potionType).equalsIgnoreCase(partialName)
|| getKeyGetKey(potionType).equalsIgnoreCase(convertLegacyNames(updatedName))
|| potionType.name().equalsIgnoreCase(partialName)
|| potionType.name().equalsIgnoreCase(convertLegacyNames(updatedName)))
.findAny().orElse(null);
}
public static String convertPotionConfigName(String legacyName) { public static String convertPotionConfigName(String legacyName) {
String replacementName = legacyName; String replacementName = legacyName;

View File

@ -1,35 +1,39 @@
package com.gmail.nossr50.util; package com.gmail.nossr50.util;
import org.bukkit.potion.PotionType;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static com.gmail.nossr50.util.PotionUtil.convertLegacyNames; import static com.gmail.nossr50.util.PotionUtil.convertLegacyNames;
import static com.gmail.nossr50.util.PotionUtil.matchPotionType;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
class PotionUtilTest { class PotionUtilTest {
// @Test @Test
// void testMatchPotionType() { void testMatchPotionTypeRegen() {
// String potionTypeStr = "UNCRAFTABLE"; final String potionTypeStr = "REGEN";
// PotionType potionType = matchPotionType(potionTypeStr, false, false); final PotionType potionType = matchPotionType(potionTypeStr, false, false);
// assertEquals(PotionType.WATER, potionType); assertEquals(PotionType.REGENERATION, potionType);
// }
// String potionTypeStr2 = "NIGHT_VISION";
// PotionType potionType2 = matchPotionType(potionTypeStr2, false, false);
// assertEquals(PotionType.NIGHT_VISION, potionType2);
//
// String nightVisionLong = "NIGHT_VISION";
// PotionType potionType3 = matchPotionType(nightVisionLong, false, true);
// assertEquals(PotionType.LONG_NIGHT_VISION, potionType3);
//
// nightVisionLong = "LONG_NIGHT_VISION";
// potionType3 = matchPotionType(nightVisionLong, false, true);
// assertEquals(PotionType.LONG_NIGHT_VISION, potionType3);
// }
@Test @Test
void testConvertLegacyNames() { void testMatchPotionTypeUncraftable() {
final String potionTypeStr = "UNCRAFTABLE";
final PotionType potionType = matchPotionType(potionTypeStr, false, false);
assertEquals(PotionType.MUNDANE, potionType);
}
@Test
void testConvertLegacyNamesUncraftable() {
final String potionTypeStr = "UNCRAFTABLE"; final String potionTypeStr = "UNCRAFTABLE";
final String converted = convertLegacyNames(potionTypeStr); final String converted = convertLegacyNames(potionTypeStr);
assertEquals("MUNDANE", converted); assertEquals("MUNDANE", converted);
} }
@Test
void testConvertLegacyNamesRegen() {
final String potionTypeStr = "REGEN";
final String converted = convertLegacyNames(potionTypeStr);
assertEquals("REGENERATION", converted);
}
} }