mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 03:34:43 +02:00
Use class names to better find custom entities.
This commit is contained in:
@ -44,17 +44,24 @@ public final class ModUtils {
|
||||
}
|
||||
|
||||
public static CustomEntity getCustomEntity(Entity entity) {
|
||||
if (!CustomEntityConfig.getInstance().customEntityIds.contains(entity.getEntityId()) && !CustomEntityConfig.getInstance().customEntityTypes.contains(entity.getType())) {
|
||||
return null;
|
||||
}
|
||||
CustomEntity customEntity = CustomEntityConfig.getInstance().customEntityTypeMap.get(entity.getType().toString());
|
||||
|
||||
for (CustomEntity customEntity : CustomEntityConfig.getInstance().customEntities) {
|
||||
if ((customEntity.getEntityID() == entity.getEntityId()) && (customEntity.getEntityType() == entity.getType())) {
|
||||
return customEntity;
|
||||
if (customEntity == null) {
|
||||
try {
|
||||
customEntity = CustomEntityConfig.getInstance().customEntityClassMap.get(((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName());
|
||||
}
|
||||
catch (NoSuchFieldException e){
|
||||
return null;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return customEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -158,7 +165,26 @@ public final class ModUtils {
|
||||
}
|
||||
|
||||
public static boolean isCustomEntity(Entity entity) {
|
||||
return customEntitiesEnabled && CustomEntityConfig.getInstance().customEntityIds.contains(entity.getEntityId());
|
||||
if (!customEntitiesEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CustomEntityConfig.getInstance().customEntityTypeMap.containsKey(entity.getType().toString())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
return CustomEntityConfig.getInstance().customEntityClassMap.containsKey(((Class<?>) entity.getClass().getDeclaredField("entityClass").get(entity)).getName());
|
||||
}
|
||||
catch (NoSuchFieldException e){
|
||||
return false;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -453,7 +453,7 @@ public final class CombatUtils {
|
||||
* @param target The defending entity
|
||||
* @param skillType The skill being used
|
||||
*/
|
||||
public static void startGainXp(McMMOPlayer mcMMOPlayer, LivingEntity target, SkillType skillType, double multiplier) {
|
||||
private static void startGainXp(McMMOPlayer mcMMOPlayer, LivingEntity target, SkillType skillType, double multiplier) {
|
||||
double baseXP = 0;
|
||||
|
||||
if (target instanceof Player) {
|
||||
@ -468,13 +468,11 @@ public final class CombatUtils {
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (target instanceof Animals) {
|
||||
if (ModUtils.isCustomEntity(target)) {
|
||||
baseXP = ModUtils.getCustomEntity(target).getXpMultiplier();
|
||||
}
|
||||
else {
|
||||
baseXP = ExperienceConfig.getInstance().getAnimalsXP();
|
||||
}
|
||||
if (ModUtils.isCustomEntity(target)) {
|
||||
baseXP = ModUtils.getCustomEntity(target).getXpMultiplier();
|
||||
}
|
||||
else if (target instanceof Animals) {
|
||||
baseXP = ExperienceConfig.getInstance().getAnimalsXP();
|
||||
}
|
||||
else {
|
||||
EntityType type = target.getType();
|
||||
@ -500,7 +498,6 @@ public final class CombatUtils {
|
||||
baseXP = ExperienceConfig.getInstance().getCombatXP(type);
|
||||
break;
|
||||
|
||||
// Temporary workaround for custom entities
|
||||
case UNKNOWN:
|
||||
baseXP = 1.0;
|
||||
break;
|
||||
@ -523,9 +520,6 @@ public final class CombatUtils {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (ModUtils.isCustomEntity(target)) {
|
||||
baseXP = ModUtils.getCustomEntity(target).getXpMultiplier();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user