mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-23 04:47:34 +01:00
Why useless comments
This commit is contained in:
parent
fd7a64f950
commit
912e864578
@ -6,8 +6,6 @@ import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.MMOUtils;
|
||||
import net.Indyuce.mmoitems.api.ConfigFile;
|
||||
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.Nullable;
|
||||
|
||||
@ -25,51 +23,49 @@ import java.util.logging.Level;
|
||||
* A HUB for skills for them to be readily available within the plugin
|
||||
*/
|
||||
public class SkillManager {
|
||||
|
||||
/**
|
||||
* The list of skills currently loaded.
|
||||
*/
|
||||
@NotNull private final HashMap<String, RegisteredSkill> skills = new HashMap<>();
|
||||
private final Map<String, RegisteredSkill> skills = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @param id Internal name of the skill you want to fetch.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @return The skill that is loaded with this name; NullPointerException if not loaded.
|
||||
*/
|
||||
@Contract("null -> fail")
|
||||
@NotNull public RegisteredSkill getSkillOrThrow(@Nullable String id) {
|
||||
@NotNull
|
||||
public RegisteredSkill getSkillOrThrow(String id) {
|
||||
return Objects.requireNonNull(skills.get(id), "Could not find skill with ID '" + id + "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param skill Skill to load
|
||||
*/
|
||||
public void registerSkill(@Nullable RegisteredSkill skill) {
|
||||
if (skill == null) { return; }
|
||||
|
||||
// Include skill
|
||||
skills.put(skill.getHandler().getId(), skill);
|
||||
public void registerSkill(RegisteredSkill skill) {
|
||||
skills.put(Objects.requireNonNull(skill, "Skill cannot be null").getHandler().getId(), skill);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id Internal name of the skill you want to fetch.
|
||||
*
|
||||
* @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
|
||||
* 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
|
||||
@ -81,12 +77,10 @@ public class SkillManager {
|
||||
public void initialize(boolean clearBefore) {
|
||||
|
||||
// Clear loaded skills
|
||||
if (clearBefore) { skills.clear(); }
|
||||
if (clearBefore)
|
||||
skills.clear();
|
||||
|
||||
// Check for default files
|
||||
File skillFolder = new File(MMOItems.plugin.getDataFolder() + "/skill");
|
||||
|
||||
// Create folder and files
|
||||
if (!skillFolder.exists()) {
|
||||
|
||||
try {
|
||||
@ -97,18 +91,18 @@ public class SkillManager {
|
||||
// Copy example skills
|
||||
for (SkillHandler handler : MythicLib.plugin.getSkills().getHandlers()) {
|
||||
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
|
||||
} catch (IOException exception) { MMOItems.plugin.getLogger().log(Level.WARNING, "Could not save default ability configs: " + exception.getMessage()); }
|
||||
// Should not happen
|
||||
} 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()) {
|
||||
|
||||
/*
|
||||
* Generate skill configuration files
|
||||
*/
|
||||
ConfigFile config = new ConfigFile("/skill", handler.getLowerCaseId());
|
||||
if (!config.exists()) {
|
||||
config.getConfig().set("name", MMOUtils.caseOnWords(handler.getId().replace("_", " ").replace("-", " ").toLowerCase()));
|
||||
@ -119,16 +113,15 @@ public class SkillManager {
|
||||
config.save();
|
||||
}
|
||||
|
||||
/*
|
||||
* Load skill to the plugin
|
||||
*/
|
||||
try {
|
||||
|
||||
// Attempt to register
|
||||
skills.put(handler.getId(), new RegisteredSkill(handler, config.getConfig()));
|
||||
|
||||
// Fail
|
||||
} catch (RuntimeException exception) { MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load skill '" + handler.getId() + "': " + exception.getMessage()); }
|
||||
// Fail
|
||||
} catch (RuntimeException exception) {
|
||||
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load skill '" + handler.getId() + "': " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user