level-up triggers now work when leveling up more than 1 level at once

This commit is contained in:
ASangarin 2020-11-01 16:25:15 +01:00
parent 7b16bced13
commit ecf31ff8ee
2 changed files with 30 additions and 26 deletions

View File

@ -3,7 +3,6 @@ package net.Indyuce.mmocore.api.player.profess.event.trigger;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent; import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.PlayerClass; import net.Indyuce.mmocore.api.player.profess.PlayerClass;
@ -21,19 +20,20 @@ public class LevelUpEventTrigger implements EventTriggerHandler {
PlayerData player = event.getData(); PlayerData player = event.getData();
PlayerClass profess = player.getProfess(); PlayerClass profess = player.getProfess();
for(int i = event.getOldLevel(); i < event.getNewLevel(); i++) {
int level = i + 1;
if(event.hasProfession()) { if(event.hasProfession()) {
String prof = event.getProfession().getId().toLowerCase(); String prof = event.getProfession().getId().toLowerCase();
MMOCore.debug(2, "[DEBUG] Looking for triggers: level-up-" + prof);
processTrigger(player, profess, "level-up-" + prof); processTrigger(player, profess, "level-up-" + prof);
processTrigger(player, profess, "level-up-" + prof + "-" + event.getNewLevel()); processTrigger(player, profess, "level-up-" + prof + "-" + level);
} else { } else {
MMOCore.debug(2, "[DEBUG] Normal level up trigger.");
processTrigger(player, profess, "level-up"); processTrigger(player, profess, "level-up");
processTrigger(player, profess, "level-up-" + event.getNewLevel()); processTrigger(player, profess, "level-up-" + level);
if(profess.getMaxLevel() == event.getNewLevel()) if(profess.getMaxLevel() == level)
processTrigger(player, profess, "level-up-max"); processTrigger(player, profess, "level-up-max");
} }
} }
}
public void processTrigger(PlayerData player, PlayerClass profess, String trigger) { public void processTrigger(PlayerData player, PlayerClass profess, String trigger) {
if(profess.hasEventTriggers(trigger)) profess.getEventTriggers(trigger).getTriggers().forEach(t -> t.apply(player)); if(profess.hasEventTriggers(trigger)) profess.getEventTriggers(trigger).getTriggers().forEach(t -> t.apply(player));

View File

@ -20,11 +20,15 @@ public class MultipleLevelUpEventTrigger implements EventTriggerHandler {
public void a(PlayerLevelUpEvent event) { public void a(PlayerLevelUpEvent event) {
PlayerData player = event.getData(); PlayerData player = event.getData();
PlayerClass profess = player.getProfess(); PlayerClass profess = player.getProfess();
for(int i = event.getOldLevel(); i < event.getNewLevel(); i++) {
int level = i + 1;
for (String t : profess.getEventTriggers()){ for (String t : profess.getEventTriggers()){
if (t.startsWith("level-up-multiple")) { if (t.startsWith("level-up-multiple")) {
String[] split = t.split("-"); String[] split = t.split("-");
double multiple = Double.parseDouble(split[split.length-1]); double multiple = Double.parseDouble(split[split.length-1]);
if (event.getNewLevel()/multiple % 1 == 0) { if (level / multiple % 1 == 0) {
DecimalFormat f = new DecimalFormat("#"); DecimalFormat f = new DecimalFormat("#");
if (event.hasProfession()) { if (event.hasProfession()) {
processTrigger(player, profess, "level-up-multiple-" + event.getProfession().getId().toLowerCase() + "-" + f.format(multiple)); processTrigger(player, profess, "level-up-multiple-" + event.getProfession().getId().toLowerCase() + "-" + f.format(multiple));
@ -34,7 +38,7 @@ public class MultipleLevelUpEventTrigger implements EventTriggerHandler {
} }
} }
} }
}
} }
public void processTrigger(PlayerData player, PlayerClass profess, String trigger) { public void processTrigger(PlayerData player, PlayerClass profess, String trigger) {