mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-26 10:44:43 +02:00
fix REGEN potion not loading
This commit is contained in:
@ -71,10 +71,10 @@ public class PotionUtil {
|
||||
* @return The potion type
|
||||
*/
|
||||
public static PotionType matchPotionType(String partialName, boolean isUpgraded, boolean isExtended) {
|
||||
String updatedName = convertLegacyNames(partialName).toUpperCase();
|
||||
if (COMPATIBILITY_MODE == PotionCompatibilityType.PRE_1_20_5) {
|
||||
return matchLegacyPotionType(partialName);
|
||||
return matchLegacyPotionType(updatedName);
|
||||
} else {
|
||||
String updatedName = convertLegacyNames(partialName);
|
||||
return Arrays.stream(PotionType.values())
|
||||
.filter(potionType -> getKeyGetKey(potionType).toUpperCase().contains(partialName)
|
||||
|| 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) {
|
||||
try {
|
||||
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) {
|
||||
String replacementName = legacyName;
|
||||
|
||||
|
@ -1,35 +1,39 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import org.bukkit.potion.PotionType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.gmail.nossr50.util.PotionUtil.convertLegacyNames;
|
||||
import static com.gmail.nossr50.util.PotionUtil.matchPotionType;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class PotionUtilTest {
|
||||
|
||||
// @Test
|
||||
// void testMatchPotionType() {
|
||||
// String potionTypeStr = "UNCRAFTABLE";
|
||||
// PotionType potionType = matchPotionType(potionTypeStr, false, false);
|
||||
// assertEquals(PotionType.WATER, 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
|
||||
void testMatchPotionTypeRegen() {
|
||||
final String potionTypeStr = "REGEN";
|
||||
final PotionType potionType = matchPotionType(potionTypeStr, false, false);
|
||||
assertEquals(PotionType.REGENERATION, potionType);
|
||||
}
|
||||
|
||||
@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 converted = convertLegacyNames(potionTypeStr);
|
||||
assertEquals("MUNDANE", converted);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConvertLegacyNamesRegen() {
|
||||
final String potionTypeStr = "REGEN";
|
||||
final String converted = convertLegacyNames(potionTypeStr);
|
||||
assertEquals("REGENERATION", converted);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user