mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-27 00:45:40 +01:00
!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.attribute.PlayerAttribute;
|
||||
import net.Indyuce.mmocore.skill.Skill;
|
||||
import net.Indyuce.mmocore.skill.RegisteredSkill;
|
||||
import net.Indyuce.mmocore.manager.data.PlayerDataManager.DefaultPlayerData;
|
||||
|
||||
public class SavedClassInformation {
|
||||
@ -102,16 +102,16 @@ public class SavedClassInformation {
|
||||
return skills.keySet();
|
||||
}
|
||||
|
||||
public int getSkillLevel(Skill skill) {
|
||||
return getSkillLevel(skill.getId());
|
||||
public int getSkillLevel(RegisteredSkill skill) {
|
||||
return getSkillLevel(skill.getHandler().getId());
|
||||
}
|
||||
|
||||
public int getSkillLevel(String id) {
|
||||
return skills.get(id);
|
||||
}
|
||||
|
||||
public void registerSkillLevel(Skill skill, int level) {
|
||||
registerSkillLevel(skill.getId(), level);
|
||||
public void registerSkillLevel(RegisteredSkill skill, int level) {
|
||||
registerSkillLevel(skill.getHandler().getId(), level);
|
||||
}
|
||||
|
||||
public void registerSkillLevel(String attribute, int level) {
|
||||
|
@ -1,121 +1,78 @@
|
||||
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.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.ClassOption;
|
||||
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
||||
import net.Indyuce.mmocore.api.player.profess.event.EventTriggerHandler;
|
||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.AttackEventTrigger;
|
||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.BlockBrokenTrigger;
|
||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.BlockPlacedTrigger;
|
||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.ClassChosenEventTrigger;
|
||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.LevelUpEventTrigger;
|
||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.MultipleLevelUpEventTrigger;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
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
|
||||
* overrides the previous.
|
||||
*/
|
||||
private PlayerClass defaultClass;
|
||||
/**
|
||||
* Cached default class. If there happens to have two default
|
||||
* classes, the last one overrides the previous.
|
||||
*/
|
||||
private PlayerClass defaultClass;
|
||||
|
||||
/*
|
||||
* same different types of trigger events to be able to map them later in
|
||||
* the player class instances.
|
||||
*/
|
||||
private final Set<EventTriggerHandler> triggerHandlers = new HashSet<>();
|
||||
public void register(PlayerClass playerClass) {
|
||||
map.put(playerClass.getId(), playerClass);
|
||||
}
|
||||
|
||||
public ClassManager() {
|
||||
registerEvent(new LevelUpEventTrigger());
|
||||
registerEvent(new AttackEventTrigger());
|
||||
registerEvent(new ClassChosenEventTrigger());
|
||||
registerEvent(new BlockBrokenTrigger());
|
||||
registerEvent(new BlockPlacedTrigger());
|
||||
registerEvent(new MultipleLevelUpEventTrigger());
|
||||
}
|
||||
public boolean has(String id) {
|
||||
return map.containsKey(id);
|
||||
}
|
||||
|
||||
public void registerEvent(EventTriggerHandler handler) {
|
||||
triggerHandlers.add(handler);
|
||||
}
|
||||
public PlayerClass get(String id) {
|
||||
return map.get(id);
|
||||
}
|
||||
|
||||
public void register(PlayerClass playerClass) {
|
||||
map.put(playerClass.getId(), playerClass);
|
||||
}
|
||||
public PlayerClass getOrThrow(String id) {
|
||||
Validate.isTrue(map.containsKey(id), "Could not find class with ID '" + id + "'");
|
||||
return map.get(id);
|
||||
}
|
||||
|
||||
public boolean has(String id) {
|
||||
return map.containsKey(id);
|
||||
}
|
||||
public Collection<PlayerClass> getAll() {
|
||||
return map.values();
|
||||
}
|
||||
|
||||
public PlayerClass get(String id) {
|
||||
return map.get(id);
|
||||
}
|
||||
public PlayerClass getDefaultClass() {
|
||||
return defaultClass;
|
||||
}
|
||||
|
||||
public PlayerClass getOrThrow(String id) {
|
||||
Validate.isTrue(map.containsKey(id), "Could not find class with ID '" + id + "'");
|
||||
return map.get(id);
|
||||
}
|
||||
public void reloadPlayerClasses() {
|
||||
PlayerData.getAll().forEach(data -> data.setClass(get(data.getProfess().getId())));
|
||||
}
|
||||
|
||||
public Collection<PlayerClass> getAll() {
|
||||
return map.values();
|
||||
}
|
||||
@Override
|
||||
public void initialize(boolean clearBefore) {
|
||||
if (clearBefore)
|
||||
map.clear();
|
||||
|
||||
public PlayerClass getDefaultClass() {
|
||||
return defaultClass;
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
public void reloadPlayerClasses() {
|
||||
PlayerData.getAll().forEach(data -> data.setClass(get(data.getProfess().getId())));
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(boolean clearBefore) {
|
||||
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));
|
||||
}
|
||||
defaultClass = map.values().stream().filter(profess -> profess.hasOption(ClassOption.DEFAULT)).findFirst()
|
||||
.orElse(new PlayerClass("HUMAN", "Human", Material.LEATHER_BOOTS));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user