mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 02:04:44 +02:00
2.2.012 fix for daze in 1.20.4 and older
This commit is contained in:
@ -19,7 +19,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import static com.gmail.nossr50.util.PotionEffectMapper.getNausea;
|
||||
import static com.gmail.nossr50.util.PotionEffectUtil.getNauseaPotionEffectType;
|
||||
|
||||
public class ArcheryManager extends SkillManager {
|
||||
public ArcheryManager(McMMOPlayer mcMMOPlayer) {
|
||||
@ -97,7 +97,7 @@ public class ArcheryManager extends SkillManager {
|
||||
dazedLocation.setPitch(90 - Misc.getRandom().nextInt(181));
|
||||
|
||||
mcMMO.p.getFoliaLib().getImpl().teleportAsync(defender, dazedLocation);
|
||||
defender.addPotionEffect(new PotionEffect(getNausea(), 20 * 10, 10));
|
||||
defender.addPotionEffect(new PotionEffect(getNauseaPotionEffectType(), 20 * 10, 10));
|
||||
|
||||
if (NotificationManager.doesPlayerUseNotifications(defender)) {
|
||||
NotificationManager.sendPlayerInformation(defender, NotificationType.SUBSKILL_MESSAGE, "Combat.TouchedFuzzy");
|
||||
|
@ -1,142 +0,0 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
final public class PotionEffectMapper {
|
||||
private static final PotionEffectType haste;
|
||||
private static final PotionEffectType nausea;
|
||||
private static final Method potionEffectTypeWrapperGetPotionEffectType;
|
||||
private static final Class<?> classPotionEffectTypeWrapper;
|
||||
|
||||
private PotionEffectMapper() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
static {
|
||||
potionEffectTypeWrapperGetPotionEffectType = getPotionEffectTypeWrapperGetPotionEffectType();
|
||||
classPotionEffectTypeWrapper = getClassPotionEffectTypeWrapper();
|
||||
|
||||
haste = initHaste();
|
||||
nausea = initNausea();
|
||||
}
|
||||
|
||||
private static Method getPotionEffectTypeWrapperGetPotionEffectType() {
|
||||
try {
|
||||
return classPotionEffectTypeWrapper.getMethod("getType");
|
||||
} catch (NoSuchMethodException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Class<?> getClassPotionEffectTypeWrapper() {
|
||||
try {
|
||||
return Class.forName("org.bukkit.potion.PotionEffectTypeWrapper");
|
||||
} catch (ClassNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffectType initNausea() {
|
||||
if (classPotionEffectTypeWrapper != null) {
|
||||
return getNauseaLegacy();
|
||||
} else {
|
||||
return getNauseaModern();
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffectType getNauseaModern() {
|
||||
// PotionEffectType potionEffectType = Registry.EFFECT.match("nausea");
|
||||
// if (potionEffectType != null) {
|
||||
// return potionEffectType;
|
||||
// }
|
||||
//
|
||||
// // Look for the potion effect type by name
|
||||
// for (PotionEffectType pet : Registry.EFFECT) {
|
||||
// if (pet.getKey().getKey().equalsIgnoreCase("CONFUSION")
|
||||
// || pet.getKey().getKey().equalsIgnoreCase("NAUSEA")
|
||||
// || pet.getName().equalsIgnoreCase("CONFUSION")
|
||||
// || pet.getName().equalsIgnoreCase("NAUSEA")) {
|
||||
// return pet;
|
||||
// }
|
||||
// }
|
||||
|
||||
try {
|
||||
return (PotionEffectType) PotionEffectType.class.getField("NAUSEA").get(null);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
mcMMO.p.getLogger().severe("Unable to find the Nausea potion effect type, " +
|
||||
"mcMMO will not function properly.");
|
||||
throw new IllegalStateException("Unable to find the Nausea potion effect type");
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffectType getNauseaLegacy() {
|
||||
try {
|
||||
Object potionEffectTypeWrapper = PotionEffectType.class.getField("CONFUSION").get(null);
|
||||
PotionEffectType potionEffectType = (PotionEffectType) potionEffectTypeWrapperGetPotionEffectType
|
||||
.invoke(potionEffectTypeWrapper);
|
||||
return potionEffectType;
|
||||
} catch (IllegalAccessException | NoSuchFieldException | InvocationTargetException e) {
|
||||
mcMMO.p.getLogger().severe("Unable to find the Nausea potion effect type, " +
|
||||
"mcMMO will not function properly.");
|
||||
throw new IllegalStateException("Unable to find the Nausea potion effect type");
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffectType initHaste() {
|
||||
|
||||
|
||||
mcMMO.p.getLogger().severe("Unable to find the Haste potion effect type, " +
|
||||
"mcMMO will not function properly.");
|
||||
throw new IllegalStateException("Unable to find the Haste potion effect type");
|
||||
}
|
||||
|
||||
private static PotionEffectType getHasteLegacy() {
|
||||
try {
|
||||
Object potionEffectTypeWrapper = PotionEffectType.class.getField("FAST_DIGGING").get(null);
|
||||
PotionEffectType potionEffectType = (PotionEffectType) potionEffectTypeWrapperGetPotionEffectType
|
||||
.invoke(potionEffectTypeWrapper);
|
||||
return potionEffectType;
|
||||
} catch (IllegalAccessException | NoSuchFieldException | InvocationTargetException e) {
|
||||
mcMMO.p.getLogger().severe("Unable to find the Haste potion effect type, " +
|
||||
"mcMMO will not function properly.");
|
||||
throw new IllegalStateException("Unable to find the Haste potion effect type");
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffectType getHasteModern() {
|
||||
// PotionEffectType potionEffectType = Registry.EFFECT.match("haste");
|
||||
// if (potionEffectType != null) {
|
||||
// return potionEffectType;
|
||||
// }
|
||||
//
|
||||
// // Look for the potion effect type by name
|
||||
// for (PotionEffectType pet : Registry.EFFECT) {
|
||||
// if (pet.getKey().getKey().equalsIgnoreCase("HASTE")
|
||||
// || pet.getKey().getKey().equalsIgnoreCase("FAST_DIGGING")
|
||||
// || pet.getName().equalsIgnoreCase("HASTE")
|
||||
// || pet.getName().equalsIgnoreCase("FAST_DIGGING")) {
|
||||
// return pet;
|
||||
// }
|
||||
// }
|
||||
|
||||
try {
|
||||
return (PotionEffectType) PotionEffectType.class.getField("HASTE").get(null);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
mcMMO.p.getLogger().severe("Unable to find the Haste potion effect type, " +
|
||||
"mcMMO will not function properly.");
|
||||
throw new IllegalStateException("Unable to find the Haste potion effect type");
|
||||
}
|
||||
}
|
||||
|
||||
public static PotionEffectType getHaste() {
|
||||
return haste;
|
||||
}
|
||||
|
||||
public static PotionEffectType getNausea() {
|
||||
return nausea;
|
||||
}
|
||||
}
|
92
src/main/java/com/gmail/nossr50/util/PotionEffectUtil.java
Normal file
92
src/main/java/com/gmail/nossr50/util/PotionEffectUtil.java
Normal file
@ -0,0 +1,92 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
/**
|
||||
* This util class is responsible for mapping the correct potion effect types for the server version.
|
||||
* This is necessary because the potion effect types have changed between versions.
|
||||
* This util class will provide the correct potion effect types for the server version.
|
||||
*/
|
||||
final public class PotionEffectUtil {
|
||||
private static final PotionEffectType haste;
|
||||
private static final PotionEffectType nausea;
|
||||
|
||||
static {
|
||||
haste = findHastePotionEffectType();
|
||||
nausea = findNauseaPotionEffectType();
|
||||
}
|
||||
|
||||
private PotionEffectUtil() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
private static PotionEffectType findNauseaPotionEffectType() {
|
||||
if (getNauseaLegacy() != null) {
|
||||
return getNauseaLegacy();
|
||||
} else {
|
||||
return getNauseaModern();
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffectType getNauseaModern() {
|
||||
try {
|
||||
return (PotionEffectType) PotionEffectType.class.getField("NAUSEA").get(null);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffectType getNauseaLegacy() {
|
||||
try {
|
||||
Object potionEffectTypeWrapper = PotionEffectType.class.getField("CONFUSION").get(null);
|
||||
return (PotionEffectType) potionEffectTypeWrapper;
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffectType findHastePotionEffectType() {
|
||||
if (getHasteLegacy() != null) {
|
||||
return getHasteLegacy();
|
||||
} else if (getHasteModern() != null) {
|
||||
return getHasteModern();
|
||||
} else {
|
||||
throw new IllegalStateException("Unable to find the Haste PotionEffectType");
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffectType getHasteLegacy() {
|
||||
try {
|
||||
Object potionEffectTypeWrapper = PotionEffectType.class.getField("FAST_DIGGING").get(null);
|
||||
return (PotionEffectType) potionEffectTypeWrapper;
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static PotionEffectType getHasteModern() {
|
||||
try {
|
||||
return (PotionEffectType) PotionEffectType.class.getField("HASTE").get(null);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Haste potion effect type.
|
||||
* This will return the correct potion effect type for the server version.
|
||||
* @return The Haste potion effect type.
|
||||
*/
|
||||
public static PotionEffectType getHastePotionEffectType() {
|
||||
return haste;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Nausea potion effect type.
|
||||
* This will return the correct potion effect type for the server version.
|
||||
* @return The Nausea potion effect type.
|
||||
*/
|
||||
public static PotionEffectType getNauseaPotionEffectType() {
|
||||
return nausea;
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static com.gmail.nossr50.util.ItemMetadataUtils.*;
|
||||
import static com.gmail.nossr50.util.PotionEffectMapper.getHaste;
|
||||
import static com.gmail.nossr50.util.PotionEffectUtil.getHastePotionEffectType;
|
||||
|
||||
public final class SkillUtils {
|
||||
/**
|
||||
@ -158,9 +158,9 @@ public final class SkillUtils {
|
||||
int duration = 0;
|
||||
int amplifier = 0;
|
||||
|
||||
if (player.hasPotionEffect(getHaste())) {
|
||||
if (player.hasPotionEffect(getHastePotionEffectType())) {
|
||||
for (PotionEffect effect : player.getActivePotionEffects()) {
|
||||
if (effect.getType() == getHaste()) {
|
||||
if (effect.getType() == getHastePotionEffectType()) {
|
||||
duration = effect.getDuration();
|
||||
amplifier = effect.getAmplifier();
|
||||
break;
|
||||
@ -190,7 +190,7 @@ public final class SkillUtils {
|
||||
mcMMO.p.getSkillTools().getSuperAbilityMaxLength(mcMMO.p.getSkillTools().getSuperAbility(skill))) * Misc.TICK_CONVERSION_FACTOR;
|
||||
}
|
||||
|
||||
PotionEffect abilityBuff = new PotionEffect(getHaste(), duration + ticks, amplifier + 10);
|
||||
PotionEffect abilityBuff = new PotionEffect(getHastePotionEffectType(), duration + ticks, amplifier + 10);
|
||||
player.addPotionEffect(abilityBuff, true);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user