forked from Upstream/mmocore
!removed event triggers
This commit is contained in:
parent
5142437848
commit
63971219a7
@ -13,7 +13,7 @@ import com.google.gson.JsonObject;
|
|||||||
|
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
||||||
import net.Indyuce.mmocore.skill.Skill;
|
import net.Indyuce.mmocore.skill.RegisteredSkill;
|
||||||
import net.Indyuce.mmocore.manager.data.PlayerDataManager.DefaultPlayerData;
|
import net.Indyuce.mmocore.manager.data.PlayerDataManager.DefaultPlayerData;
|
||||||
|
|
||||||
public class SavedClassInformation {
|
public class SavedClassInformation {
|
||||||
@ -102,16 +102,16 @@ public class SavedClassInformation {
|
|||||||
return skills.keySet();
|
return skills.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSkillLevel(Skill skill) {
|
public int getSkillLevel(RegisteredSkill skill) {
|
||||||
return getSkillLevel(skill.getId());
|
return getSkillLevel(skill.getHandler().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSkillLevel(String id) {
|
public int getSkillLevel(String id) {
|
||||||
return skills.get(id);
|
return skills.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerSkillLevel(Skill skill, int level) {
|
public void registerSkillLevel(RegisteredSkill skill, int level) {
|
||||||
registerSkillLevel(skill.getId(), level);
|
registerSkillLevel(skill.getHandler().getId(), level);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerSkillLevel(String attribute, int level) {
|
public void registerSkillLevel(String attribute, int level) {
|
||||||
|
@ -1,121 +1,78 @@
|
|||||||
package net.Indyuce.mmocore.manager;
|
package net.Indyuce.mmocore.manager;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.api.player.profess.ClassOption;
|
import net.Indyuce.mmocore.api.player.profess.ClassOption;
|
||||||
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
||||||
import net.Indyuce.mmocore.api.player.profess.event.EventTriggerHandler;
|
import org.apache.commons.lang.Validate;
|
||||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.AttackEventTrigger;
|
import org.bukkit.Material;
|
||||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.BlockBrokenTrigger;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.BlockPlacedTrigger;
|
|
||||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.ClassChosenEventTrigger;
|
import java.io.File;
|
||||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.LevelUpEventTrigger;
|
import java.util.Collection;
|
||||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.MultipleLevelUpEventTrigger;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class ClassManager implements MMOCoreManager {
|
public class ClassManager implements MMOCoreManager {
|
||||||
private final Map<String, PlayerClass> map = new HashMap<>();
|
private final Map<String, PlayerClass> map = new HashMap<>();
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* cached default class. if there are two default classes, the last one
|
* Cached default class. If there happens to have two default
|
||||||
* overrides the previous.
|
* classes, the last one overrides the previous.
|
||||||
*/
|
*/
|
||||||
private PlayerClass defaultClass;
|
private PlayerClass defaultClass;
|
||||||
|
|
||||||
/*
|
public void register(PlayerClass playerClass) {
|
||||||
* same different types of trigger events to be able to map them later in
|
map.put(playerClass.getId(), playerClass);
|
||||||
* the player class instances.
|
}
|
||||||
*/
|
|
||||||
private final Set<EventTriggerHandler> triggerHandlers = new HashSet<>();
|
|
||||||
|
|
||||||
public ClassManager() {
|
public boolean has(String id) {
|
||||||
registerEvent(new LevelUpEventTrigger());
|
return map.containsKey(id);
|
||||||
registerEvent(new AttackEventTrigger());
|
}
|
||||||
registerEvent(new ClassChosenEventTrigger());
|
|
||||||
registerEvent(new BlockBrokenTrigger());
|
|
||||||
registerEvent(new BlockPlacedTrigger());
|
|
||||||
registerEvent(new MultipleLevelUpEventTrigger());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerEvent(EventTriggerHandler handler) {
|
public PlayerClass get(String id) {
|
||||||
triggerHandlers.add(handler);
|
return map.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(PlayerClass playerClass) {
|
public PlayerClass getOrThrow(String id) {
|
||||||
map.put(playerClass.getId(), playerClass);
|
Validate.isTrue(map.containsKey(id), "Could not find class with ID '" + id + "'");
|
||||||
}
|
return map.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean has(String id) {
|
public Collection<PlayerClass> getAll() {
|
||||||
return map.containsKey(id);
|
return map.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerClass get(String id) {
|
public PlayerClass getDefaultClass() {
|
||||||
return map.get(id);
|
return defaultClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerClass getOrThrow(String id) {
|
public void reloadPlayerClasses() {
|
||||||
Validate.isTrue(map.containsKey(id), "Could not find class with ID '" + id + "'");
|
PlayerData.getAll().forEach(data -> data.setClass(get(data.getProfess().getId())));
|
||||||
return map.get(id);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<PlayerClass> getAll() {
|
@Override
|
||||||
return map.values();
|
public void initialize(boolean clearBefore) {
|
||||||
}
|
if (clearBefore)
|
||||||
|
map.clear();
|
||||||
|
|
||||||
public PlayerClass getDefaultClass() {
|
for (File file : new File(MMOCore.plugin.getDataFolder() + "/classes").listFiles())
|
||||||
return defaultClass;
|
try {
|
||||||
}
|
String id = file.getName().substring(0, file.getName().length() - 4);
|
||||||
|
register(new PlayerClass(id, YamlConfiguration.loadConfiguration(file)));
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load class '" + file.getName() + "': " + exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
public void reloadPlayerClasses() {
|
for (PlayerClass profess : map.values())
|
||||||
PlayerData.getAll().forEach(data -> data.setClass(get(data.getProfess().getId())));
|
try {
|
||||||
}
|
profess.postLoad();
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not post-load class '" + profess.getId() + "': " + exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
defaultClass = map.values().stream().filter(profess -> profess.hasOption(ClassOption.DEFAULT)).findFirst()
|
||||||
public void initialize(boolean clearBefore) {
|
.orElse(new PlayerClass("HUMAN", "Human", Material.LEATHER_BOOTS));
|
||||||
if (clearBefore) {
|
}
|
||||||
map.clear();
|
|
||||||
triggerHandlers.forEach(HandlerList::unregisterAll);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Do not clear the list of trigger listeners, since it's only setup
|
|
||||||
* once the server loads and it is never modified.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
for (File file : new File(MMOCore.plugin.getDataFolder() + "/classes").listFiles())
|
|
||||||
try {
|
|
||||||
String id = file.getName().substring(0, file.getName().length() - 4);
|
|
||||||
register(new PlayerClass(id, YamlConfiguration.loadConfiguration(file)));
|
|
||||||
} catch (IllegalArgumentException exception) {
|
|
||||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load class '" + file.getName() + "': " + exception.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (PlayerClass profess : map.values())
|
|
||||||
try {
|
|
||||||
profess.postLoad();
|
|
||||||
} catch (IllegalArgumentException exception) {
|
|
||||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not post-load class '" + profess.getId() + "': " + exception.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultClass = map.values().stream().filter(profess -> profess.hasOption(ClassOption.DEFAULT)).findFirst()
|
|
||||||
.orElse(new PlayerClass("HUMAN", "Human", Material.LEATHER_BOOTS));
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Register event triggers
|
|
||||||
*/
|
|
||||||
triggerHandlers.forEach(handler -> Bukkit.getPluginManager().registerEvents(handler, MMOCore.plugin));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user