From dee0536e7437ca94e4afbd01a24aa7907dfd0e61 Mon Sep 17 00:00:00 2001 From: Ethan Date: Fri, 31 Jul 2020 18:27:19 -0400 Subject: [PATCH] Added new level up multiple event triggers. Example: If level = 2 it will trigger every 2 levels. 2,4,6,8... level-up-multiple-{level} level-up-multiple-{profession}-{level} --- .../trigger/MultipleLevelUpEventTrigger.java | 43 +++++++++++++++++++ .../Indyuce/mmocore/manager/ClassManager.java | 7 +-- 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/MultipleLevelUpEventTrigger.java diff --git a/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/MultipleLevelUpEventTrigger.java b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/MultipleLevelUpEventTrigger.java new file mode 100644 index 00000000..bc108e7a --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/api/player/profess/event/trigger/MultipleLevelUpEventTrigger.java @@ -0,0 +1,43 @@ +package net.Indyuce.mmocore.api.player.profess.event.trigger; + +import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.player.profess.PlayerClass; +import net.Indyuce.mmocore.api.player.profess.event.EventTriggerHandler; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +import java.text.DecimalFormat; + +public class MultipleLevelUpEventTrigger implements EventTriggerHandler { + + @Override + public boolean handles(String event) { + return event.startsWith("level-up-multiple"); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void a(PlayerLevelUpEvent event) { + PlayerData player = event.getData(); + PlayerClass profess = player.getProfess(); + for (String t : profess.getEventTriggers()){ + if (t.startsWith("level-up-multiple")) { + String[] split = t.split("-"); + double multiple = Double.parseDouble(split[split.length-1]); + if (event.getNewLevel()/multiple % 1 == 0) { + DecimalFormat f = new DecimalFormat("#"); + if (event.hasProfession()) { + processTrigger(player, profess, "level-up-multiple-" + event.getProfession().getId().toLowerCase() + "-" + f.format(multiple)); + } else { + processTrigger(player, profess, "level-up-multiple-" + f.format(multiple)); + } + } + } + } + + } + + public void processTrigger(PlayerData player, PlayerClass profess, String trigger) { + if(profess.hasEventTriggers(trigger)) profess.getEventTriggers(trigger).getTriggers().forEach(t -> t.apply(player)); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java b/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java index 31905a71..df9eb78a 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ClassManager.java @@ -8,6 +8,7 @@ import java.util.Map; import java.util.Set; import java.util.logging.Level; +import net.Indyuce.mmocore.api.player.profess.event.trigger.*; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -19,11 +20,6 @@ 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; public class ClassManager extends MMOManager { private final Map map = new HashMap<>(); @@ -46,6 +42,7 @@ public class ClassManager extends MMOManager { registerEvent(new ClassChosenEventTrigger()); registerEvent(new BlockBrokenTrigger()); registerEvent(new BlockPlacedTrigger()); + registerEvent(new MultipleLevelUpEventTrigger()); } public void registerEvent(EventTriggerHandler handler) {