forked from Upstream/mmocore
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}
This commit is contained in:
parent
f172d52cac
commit
dee0536e74
@ -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));
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import net.Indyuce.mmocore.api.player.profess.event.trigger.*;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
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.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 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 {
|
public class ClassManager extends MMOManager {
|
||||||
private final Map<String, PlayerClass> map = new HashMap<>();
|
private final Map<String, PlayerClass> map = new HashMap<>();
|
||||||
@ -46,6 +42,7 @@ public class ClassManager extends MMOManager {
|
|||||||
registerEvent(new ClassChosenEventTrigger());
|
registerEvent(new ClassChosenEventTrigger());
|
||||||
registerEvent(new BlockBrokenTrigger());
|
registerEvent(new BlockBrokenTrigger());
|
||||||
registerEvent(new BlockPlacedTrigger());
|
registerEvent(new BlockPlacedTrigger());
|
||||||
|
registerEvent(new MultipleLevelUpEventTrigger());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerEvent(EventTriggerHandler handler) {
|
public void registerEvent(EventTriggerHandler handler) {
|
||||||
|
Loading…
Reference in New Issue
Block a user