public static void registerSkill(Class<? extends SkillTreeSkill> clazz) { if (!SkillInstance.class.isAssignableFrom(clazz)) { MyPetApi.getLogger() .warning(ChatColor.RED + clazz.getName() + " doesn't implements [ISkillInstance]!"); return; } if (!registeredSkillsNames.containsKey(clazz)) { try { // MyPetApi.getLogger().warning("Skill Annotations: " + // Arrays.toString(clazz.getAnnotations())); SkillName sn = clazz.getAnnotation(SkillName.class); if (sn != null) { String skillName = sn.value(); if (!registeredNamesSkills.containsKey(skillName)) { registeredSkillsNames.put(clazz, skillName); // DebugLogger.info("registered skill: " + clazz.getName()); } else { MyPetApi.getLogger() .warning( ChatColor.RED + "There is already a skill registered with the the name " + skillName); } } else { MyPetApi.getLogger() .warning(ChatColor.RED + clazz.getName() + " is not annotated with [SkillName]!"); } } catch (Exception e) { MyPetApi.getLogger().warning(ChatColor.RED + clazz.getName() + " is not a valid skill!"); } } }
public boolean hasSkill(Class<? extends SkillInstance> clazz) { SkillName sn = clazz.getAnnotation(SkillName.class); if (sn == null) { return false; } if (!skillsNamesClass.containsKey(sn.value())) { return false; } return clazz.isInstance(skillsNamesClass.get(sn.value())); }
@SuppressWarnings("unchecked") public <T extends SkillInstance> T getSkill(Class<T> clazz) { SkillName sn = clazz.getAnnotation(SkillName.class); if (sn == null) { return null; } if (!skillsNamesClass.containsKey(sn.value())) { return null; } SkillInstance skill = skillsNamesClass.get(sn.value()); if (!clazz.isInstance(skill)) { return null; } return (T) skill; }