forked from Upstream/mmocore
fixed /mmocore admin level set
This commit is contained in:
parent
d3dd31e605
commit
98801a4870
@ -246,12 +246,13 @@ public class PlayerData extends OfflinePlayerData implements Closable {
|
|||||||
|
|
||||||
public void setLevel(int level) {
|
public void setLevel(int level) {
|
||||||
this.level = Math.max(1, level);
|
this.level = Math.max(1, level);
|
||||||
|
|
||||||
getStats().updateStats();
|
getStats().updateStats();
|
||||||
|
refreshVanillaExp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void takeLevels(int value) {
|
public void takeLevels(int value) {
|
||||||
this.level = Math.max(1, level - value);
|
setLevel(level - value);
|
||||||
getStats().updateStats();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void giveLevels(int value, EXPSource source) {
|
public void giveLevels(int value, EXPSource source) {
|
||||||
|
@ -2,11 +2,8 @@ package net.Indyuce.mmocore.manager;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.Enumeration;
|
import java.util.*;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -21,9 +18,11 @@ import net.Indyuce.mmocore.skill.Skill;
|
|||||||
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
|
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
|
||||||
import net.Indyuce.mmocore.comp.mythicmobs.MythicSkill;
|
import net.Indyuce.mmocore.comp.mythicmobs.MythicSkill;
|
||||||
|
|
||||||
public class SkillManager {
|
public class SkillManager implements MMOCoreManager {
|
||||||
private final Map<String, Skill> skills = new LinkedHashMap<>();
|
private final Map<String, Skill> skills = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
private boolean hasLoadedDefaultSkills;
|
||||||
|
|
||||||
public void register(Skill skill) {
|
public void register(Skill skill) {
|
||||||
skills.put(skill.getId().toUpperCase(), skill);
|
skills.put(skill.getId().toUpperCase(), skill);
|
||||||
}
|
}
|
||||||
@ -48,24 +47,31 @@ public class SkillManager {
|
|||||||
return skills.keySet();
|
return skills.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
@Override
|
||||||
* Skills are initialized when MMOCore enables but SkillManager must be
|
public void initialize(boolean clearBefore) {
|
||||||
* instanced when MMOCore loads so that extra plugins can register skills
|
|
||||||
* before CLASSES are loaded
|
|
||||||
*/
|
|
||||||
public void reload() {
|
|
||||||
|
|
||||||
if (skills.isEmpty())
|
if (clearBefore) {
|
||||||
|
|
||||||
|
// Only remove custom skills
|
||||||
|
Iterator<Skill> ite = skills.values().iterator();
|
||||||
|
while (ite.hasNext()) {
|
||||||
|
Skill next = ite.next();
|
||||||
|
if (next instanceof MythicSkill)
|
||||||
|
ite.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasLoadedDefaultSkills)
|
||||||
try {
|
try {
|
||||||
|
hasLoadedDefaultSkills = true;
|
||||||
JarFile jarFile = new JarFile(MMOCore.plugin.getJarFile());
|
JarFile jarFile = new JarFile(MMOCore.plugin.getJarFile());
|
||||||
JarEntry entry;
|
JarEntry entry;
|
||||||
for (Enumeration<JarEntry> en = jarFile.entries(); en.hasMoreElements();)
|
for (Enumeration<JarEntry> en = jarFile.entries(); en.hasMoreElements();)
|
||||||
if ((entry = en.nextElement()).getName().startsWith("net/Indyuce/mmocore/skill/list/")
|
if ((entry = en.nextElement()).getName().startsWith("net/Indyuce/mmocore/skill/list/")
|
||||||
&& !entry.isDirectory() && !entry.getName().contains("$"))
|
&& !entry.isDirectory() && !entry.getName().contains("$"))
|
||||||
register((Skill) Class.forName(entry.getName().replace("/", ".").replace(".class", ""))
|
register((Skill) Class.forName(entry.getName().replace("/", ".").replace(".class", "")).getDeclaredConstructor().newInstance());
|
||||||
.newInstance());
|
|
||||||
jarFile.close();
|
jarFile.close();
|
||||||
} catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException exception) {
|
} catch (IOException | InstantiationException | IllegalAccessException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
MMOCore.log(Level.WARNING, "Could not load skills! Careful with player data :(");
|
MMOCore.log(Level.WARNING, "Could not load skills! Careful with player data :(");
|
||||||
}
|
}
|
||||||
@ -88,6 +94,7 @@ public class SkillManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load configuration for default skills
|
||||||
for (Skill skill : getAll())
|
for (Skill skill : getAll())
|
||||||
if (!(skill instanceof MythicSkill)) {
|
if (!(skill instanceof MythicSkill)) {
|
||||||
File file = new File(MMOCore.plugin.getDataFolder() + "/skills", skill.getLowerCaseId() + ".yml");
|
File file = new File(MMOCore.plugin.getDataFolder() + "/skills", skill.getLowerCaseId() + ".yml");
|
||||||
@ -98,7 +105,7 @@ public class SkillManager {
|
|||||||
config.getConfig().set("lore", skill.getLore());
|
config.getConfig().set("lore", skill.getLore());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* it does support custom modeled items but it does not
|
* It does support custom modeled items but it does not
|
||||||
* provide default configs for that.
|
* provide default configs for that.
|
||||||
*/
|
*/
|
||||||
config.getConfig().set("material", skill.getIcon().getType().name());
|
config.getConfig().set("material", skill.getIcon().getType().name());
|
||||||
@ -112,10 +119,10 @@ public class SkillManager {
|
|||||||
if (value.hasMin())
|
if (value.hasMin())
|
||||||
config.getConfig().set(mod + ".min", value.getMin());
|
config.getConfig().set(mod + ".min", value.getMin());
|
||||||
}
|
}
|
||||||
|
config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
skill.update(config.getConfig());
|
skill.update(config.getConfig());
|
||||||
config.save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user