fixed stat register issue with MMOCore stats

This commit is contained in:
Indyuce 2019-08-29 14:20:37 +02:00
parent be97754168
commit 004ae479b0
3 changed files with 18 additions and 7 deletions

View File

@ -35,8 +35,10 @@ public class MMOCoreHook implements RPGHandler, Listener {
MMOItems.plugin.getStats().register("COOLDOWN_REDUCTION", new DoubleStat(new ItemStack(Material.BOOK), "Skill Cooldown Reduction", new String[] { "(%) Reduces cooldowns of MMOCore skills." }, "skill-cooldown-reduction"));
MMOItems.plugin.getStats().register("ADDITIONAL_EXPERIENCE", new DoubleStat(new ItemStack(Material.EXPERIENCE_BOTTLE), "Additional Experience", new String[] { "Additional % MMOCore main class experience." }, "additional-experience"));
for (DamageType type : DamageType.values())
MMOItems.plugin.getStats().register(type.name() + "_DAMAGE", new DoubleStat(new ItemStack(Material.GRAY_DYE), MMOUtils.caseOnWords(type.name().toLowerCase().replace("_", " ")) + " Damage (MMOCore)", new String[] { "Additional % MMOCore main class experience." }, "additional-experience"));
for (DamageType type : DamageType.values()) {
String name = MMOUtils.caseOnWords(type.name().toLowerCase());
MMOItems.plugin.getStats().register(type.name() + "_DAMAGE", new DoubleStat(new ItemStack(Material.IRON_SWORD), name + " Damage (MMOCore)", new String[] { "Additional " + name + " damage." }, type.getPath() + "-damage"));
}
}
@Override

View File

@ -16,9 +16,9 @@ import net.Indyuce.mmoitems.stat.type.DoubleStat;
import net.Indyuce.mmoitems.stat.type.ItemStat;
public class StatManager {
private Map<String, ItemStat> stats = new LinkedHashMap<>();
private Set<DoubleStat> gem = new HashSet<>();
private Set<AttributeStat> attribute = new HashSet<>();
private final Map<String, ItemStat> stats = new LinkedHashMap<>();
private final Set<DoubleStat> gem = new HashSet<>();
private final Set<AttributeStat> attribute = new HashSet<>();
/*
* load default stats using java reflection, get all public static final
@ -65,6 +65,15 @@ public class StatManager {
if (stat instanceof AttributeStat)
attribute.add((AttributeStat) stat);
/*
* cache stat for every type which may have this stat. really important
* otherwise the stat will NOT be used anywhere in the plugin.
*/
if (MMOItems.plugin.getTypes() != null)
for (Type type : MMOItems.plugin.getTypes().getAll())
if (type.canHave(stat))
type.getAvailableStats().add(stat);
}
public ItemStat get(String str) {
@ -72,6 +81,6 @@ public class StatManager {
}
private boolean isGemStoneStat(ItemStat stat) {
return Type.GEM_STONE.canHaveStat(stat) && stat != ItemStat.REQUIRED_LEVEL && stat != ItemStat.CUSTOM_MODEL_DATA && stat != ItemStat.DURABILITY && stat != ItemStat.MAX_CUSTOM_DURABILITY && stat != ItemStat.SUCCESS_RATE && stat instanceof DoubleStat;
return Type.GEM_STONE.canHave(stat) && stat != ItemStat.REQUIRED_LEVEL && stat != ItemStat.CUSTOM_MODEL_DATA && stat != ItemStat.DURABILITY && stat != ItemStat.MAX_CUSTOM_DURABILITY && stat != ItemStat.SUCCESS_RATE && stat instanceof DoubleStat;
}
}

View File

@ -63,7 +63,7 @@ public class TypeManager {
* both item generation (and GUI) calculations. probably the thing
* which takes the most time when loading item types.
*/
type.cacheAvailableStats(MMOItems.plugin.getStats().getAll().stream().filter(stat -> type.canHaveStat(stat)).collect(Collectors.toList()));
type.cacheAvailableStats(MMOItems.plugin.getStats().getAll().stream().filter(stat -> type.canHave(stat)).collect(Collectors.toList()));
}
}