Why useless comments

This commit is contained in:
Indyuce 2022-03-05 15:02:06 +01:00
parent fd7a64f950
commit 912e864578

View File

@ -6,8 +6,6 @@ import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils; import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.ConfigFile; import net.Indyuce.mmoitems.api.ConfigFile;
import net.Indyuce.mmoitems.skill.RegisteredSkill; import net.Indyuce.mmoitems.skill.RegisteredSkill;
import org.apache.commons.lang.Validate;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -25,51 +23,49 @@ import java.util.logging.Level;
* A HUB for skills for them to be readily available within the plugin * A HUB for skills for them to be readily available within the plugin
*/ */
public class SkillManager { public class SkillManager {
private final Map<String, RegisteredSkill> skills = new HashMap<>();
/**
* The list of skills currently loaded.
*/
@NotNull private final HashMap<String, RegisteredSkill> skills = new HashMap<>();
/** /**
* @param id Internal name of the skill you want to fetch. * @param id Internal name of the skill you want to fetch.
*
* @return If a skill is loaded with this name, that skill. * @return If a skill is loaded with this name, that skill.
*/ */
@Nullable public RegisteredSkill getSkill(@Nullable String id) { return skills.get(id); } @Nullable
public RegisteredSkill getSkill(String id) {
return skills.get(id);
}
/** /**
* @param id The internal name of the skill you want to fetch. * @param id The internal name of the skill you want to fetch.
*
* @return The skill that is loaded with this name; NullPointerException if not loaded. * @return The skill that is loaded with this name; NullPointerException if not loaded.
*/ */
@Contract("null -> fail") @NotNull
@NotNull public RegisteredSkill getSkillOrThrow(@Nullable String id) { public RegisteredSkill getSkillOrThrow(String id) {
return Objects.requireNonNull(skills.get(id), "Could not find skill with ID '" + id + "'"); return Objects.requireNonNull(skills.get(id), "Could not find skill with ID '" + id + "'");
} }
/** /**
* @param skill Skill to load * @param skill Skill to load
*/ */
public void registerSkill(@Nullable RegisteredSkill skill) { public void registerSkill(RegisteredSkill skill) {
if (skill == null) { return; } skills.put(Objects.requireNonNull(skill, "Skill cannot be null").getHandler().getId(), skill);
// Include skill
skills.put(skill.getHandler().getId(), skill);
} }
/** /**
* @param id Internal name of the skill you want to fetch. * @param id Internal name of the skill you want to fetch.
*
* @return If a skill of this name is loaded by the plugin. * @return If a skill of this name is loaded by the plugin.
*/ */
public boolean hasSkill(@Nullable String id) { return skills.containsKey(id); } public boolean hasSkill(String id) {
return skills.containsKey(id);
}
/** /**
* @return Collection of all registered skills. It has the same number * @return Collection of all registered skills. It has the same number
* of elements as MythicLib's skill handler registry. * of elements as MythicLib's skill handler registry.
*/ */
@NotNull public Collection<RegisteredSkill> getAll() { return skills.values(); } @NotNull
public Collection<RegisteredSkill> getAll() {
return skills.values();
}
/** /**
* Will load skills from MythicLib as well as generate their configuration * Will load skills from MythicLib as well as generate their configuration
@ -81,12 +77,10 @@ public class SkillManager {
public void initialize(boolean clearBefore) { public void initialize(boolean clearBefore) {
// Clear loaded skills // Clear loaded skills
if (clearBefore) { skills.clear(); } if (clearBefore)
skills.clear();
// Check for default files
File skillFolder = new File(MMOItems.plugin.getDataFolder() + "/skill"); File skillFolder = new File(MMOItems.plugin.getDataFolder() + "/skill");
// Create folder and files
if (!skillFolder.exists()) { if (!skillFolder.exists()) {
try { try {
@ -97,18 +91,18 @@ public class SkillManager {
// Copy example skills // Copy example skills
for (SkillHandler handler : MythicLib.plugin.getSkills().getHandlers()) { for (SkillHandler handler : MythicLib.plugin.getSkills().getHandlers()) {
InputStream res = MMOItems.plugin.getResource("default/skill/" + handler.getLowerCaseId() + ".yml"); InputStream res = MMOItems.plugin.getResource("default/skill/" + handler.getLowerCaseId() + ".yml");
if (res != null) { Files.copy(res, new File(MMOItems.plugin.getDataFolder() + "/skill/" + handler.getLowerCaseId() + ".yml").getAbsoluteFile().toPath()); } } if (res != null)
Files.copy(res, new File(MMOItems.plugin.getDataFolder() + "/skill/" + handler.getLowerCaseId() + ".yml").getAbsoluteFile().toPath());
}
// Should not happen // Should not happen
} catch (IOException exception) { MMOItems.plugin.getLogger().log(Level.WARNING, "Could not save default ability configs: " + exception.getMessage()); } } catch (IOException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not save default ability configs: " + exception.getMessage());
}
} }
// Copy mythiclib skills // Copy MythicLib skills
for (SkillHandler<?> handler : MythicLib.plugin.getSkills().getHandlers()) { for (SkillHandler<?> handler : MythicLib.plugin.getSkills().getHandlers()) {
/*
* Generate skill configuration files
*/
ConfigFile config = new ConfigFile("/skill", handler.getLowerCaseId()); ConfigFile config = new ConfigFile("/skill", handler.getLowerCaseId());
if (!config.exists()) { if (!config.exists()) {
config.getConfig().set("name", MMOUtils.caseOnWords(handler.getId().replace("_", " ").replace("-", " ").toLowerCase())); config.getConfig().set("name", MMOUtils.caseOnWords(handler.getId().replace("_", " ").replace("-", " ").toLowerCase()));
@ -119,16 +113,15 @@ public class SkillManager {
config.save(); config.save();
} }
/*
* Load skill to the plugin
*/
try { try {
// Attempt to register // Attempt to register
skills.put(handler.getId(), new RegisteredSkill(handler, config.getConfig())); skills.put(handler.getId(), new RegisteredSkill(handler, config.getConfig()));
// Fail // Fail
} catch (RuntimeException exception) { MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load skill '" + handler.getId() + "': " + exception.getMessage()); } } catch (RuntimeException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load skill '" + handler.getId() + "': " + exception.getMessage());
}
} }
} }
} }