!removed event triggers

This commit is contained in:
Indyuce 2022-01-01 13:22:43 +01:00
parent 5142437848
commit 63971219a7
2 changed files with 62 additions and 105 deletions

View File

@ -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) {

View File

@ -1,59 +1,28 @@
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<>();
/*
* cached default class. if there are two default classes, the last one
* overrides the previous.
/**
* 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 ClassManager() {
registerEvent(new LevelUpEventTrigger());
registerEvent(new AttackEventTrigger());
registerEvent(new ClassChosenEventTrigger());
registerEvent(new BlockBrokenTrigger());
registerEvent(new BlockPlacedTrigger());
registerEvent(new MultipleLevelUpEventTrigger());
}
public void registerEvent(EventTriggerHandler handler) {
triggerHandlers.add(handler);
}
public void register(PlayerClass playerClass) {
map.put(playerClass.getId(), playerClass);
}
@ -85,15 +54,8 @@ public class ClassManager implements MMOCoreManager {
@Override
public void initialize(boolean clearBefore) {
if (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 {
@ -112,10 +74,5 @@ public class ClassManager implements MMOCoreManager {
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));
}
}