mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-03 06:37:47 +01:00
Fixed trigger type backwards compatibility
This commit is contained in:
parent
426cc906db
commit
9128fe63f9
@ -7,6 +7,7 @@ import io.lumine.mythic.lib.api.item.ItemTag;
|
||||
import io.lumine.mythic.lib.api.item.NBTItem;
|
||||
import io.lumine.mythic.lib.api.item.SupportedNBTTagValues;
|
||||
import io.lumine.mythic.lib.comp.target.InteractionType;
|
||||
import io.lumine.mythic.lib.skill.trigger.TriggerType;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.bukkit.Location;
|
||||
@ -46,6 +47,22 @@ public class MMOUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name The trigger name that may be in old format
|
||||
* @return The trigger type this represents
|
||||
* @throws IllegalArgumentException If this does not match any trigger type
|
||||
*/
|
||||
@NotNull
|
||||
public static TriggerType backwardsCompatibleTriggerType(@Nullable String name) throws IllegalArgumentException {
|
||||
if (name == null) { throw new IllegalArgumentException("Trigger cannot be null"); }
|
||||
|
||||
switch (name) {
|
||||
case "ON_HIT": return TriggerType.ATTACK;
|
||||
case "WHEN_HIT": return TriggerType.DAMAGED;
|
||||
default: return TriggerType.valueOf(name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param item The item stack you are testing.
|
||||
* @param type MMOItem Type you are expecting {@link Type#getId()}
|
||||
|
@ -478,20 +478,7 @@ public class PlayerData {
|
||||
* same tick or something.
|
||||
*/
|
||||
if (!data.containsKey(player)) {
|
||||
|
||||
MMOPlayerData mmo = MMOPlayerData.get(player);
|
||||
if (mmo == null) {
|
||||
|
||||
NullPointerException npe = new NullPointerException("");
|
||||
|
||||
MMOItems.print(Level.SEVERE, "Erroneous initialization of PlayerData. This error is only a result of another one caused EARLIER (probably during server startup).", null);
|
||||
//noinspection CallToPrintStackTrace
|
||||
npe.printStackTrace();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerData playerData = new PlayerData(mmo);
|
||||
PlayerData playerData = new PlayerData(MMOPlayerData.get(player));
|
||||
data.put(player, playerData);
|
||||
playerData.updateInventory();
|
||||
return;
|
||||
|
@ -6,13 +6,12 @@ import io.lumine.mythic.lib.skill.metadata.TriggerMetadata;
|
||||
import io.lumine.mythic.lib.skill.trigger.TriggerType;
|
||||
import io.lumine.mythic.lib.skill.trigger.TriggeredSkill;
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.ability.Ability;
|
||||
import net.Indyuce.mmoitems.api.crafting.trigger.Trigger;
|
||||
import net.Indyuce.mmoitems.api.player.PlayerData;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -54,7 +53,7 @@ public class AbilityData implements MythicSkillInfo, TriggeredSkill {
|
||||
|
||||
public AbilityData(JsonObject object) {
|
||||
ability = MMOItems.plugin.getAbilities().getAbility(object.get("Id").getAsString());
|
||||
triggerType = backwardsCompatibleTriggerType(object.get("CastMode").getAsString());
|
||||
triggerType = MMOUtils.backwardsCompatibleTriggerType(object.get("CastMode").getAsString());
|
||||
|
||||
JsonObject modifiers = object.getAsJsonObject("Modifiers");
|
||||
modifiers.entrySet().forEach(entry -> setModifier(entry.getKey(), entry.getValue().getAsDouble()));
|
||||
@ -68,28 +67,13 @@ public class AbilityData implements MythicSkillInfo, TriggeredSkill {
|
||||
ability = MMOItems.plugin.getAbilities().getAbility(abilityFormat);
|
||||
|
||||
String modeFormat = config.getString("mode").toUpperCase().replace("-", "_").replace(" ", "_");
|
||||
triggerType = backwardsCompatibleTriggerType(modeFormat);
|
||||
triggerType = MMOUtils.backwardsCompatibleTriggerType(modeFormat);
|
||||
|
||||
for (String key : config.getKeys(false))
|
||||
if (!key.equalsIgnoreCase("mode") && !key.equalsIgnoreCase("type") && ability.getModifiers().contains(key))
|
||||
modifiers.put(key, config.getDouble(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name The trigger name that may be in old format
|
||||
* @return The trigger type this represents
|
||||
* @throws IllegalArgumentException If this does not match any trigger type
|
||||
*/
|
||||
@NotNull TriggerType backwardsCompatibleTriggerType(@Nullable String name) throws IllegalArgumentException {
|
||||
if (name == null) { throw new IllegalArgumentException("Trigger cannot be null"); }
|
||||
|
||||
switch (name) {
|
||||
case "ON_HIT": return TriggerType.ATTACK;
|
||||
case "WHEN_HIT": return TriggerType.DAMAGED_BY_ENTITY;
|
||||
default: return TriggerType.valueOf(name);
|
||||
}
|
||||
}
|
||||
|
||||
public AbilityData(Ability ability, TriggerType triggerType) {
|
||||
this.ability = ability;
|
||||
this.triggerType = triggerType;
|
||||
|
@ -5,6 +5,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import io.lumine.mythic.lib.skill.trigger.TriggerType;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
@ -27,7 +28,7 @@ public class RandomAbilityData {
|
||||
ability = MMOItems.plugin.getAbilities().getAbility(abilityFormat);
|
||||
|
||||
String modeFormat = config.getString("mode").toUpperCase().replace("-", "_").replace(" ", "_");
|
||||
triggerType = TriggerType.valueOf(modeFormat);
|
||||
triggerType = MMOUtils.backwardsCompatibleTriggerType(modeFormat);
|
||||
|
||||
for (String key : config.getKeys(false))
|
||||
if (!key.equalsIgnoreCase("mode") && !key.equalsIgnoreCase("type") && ability.getModifiers().contains(key))
|
||||
|
Loading…
Reference in New Issue
Block a user