mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-26 00:35:17 +01:00
Enter/quit combat skill triggers
This commit is contained in:
parent
b8e02c945f
commit
5c185476dd
@ -49,6 +49,7 @@ import net.Indyuce.mmocore.script.mechanic.ManaMechanic;
|
||||
import net.Indyuce.mmocore.script.mechanic.StaminaMechanic;
|
||||
import net.Indyuce.mmocore.script.mechanic.StelliumMechanic;
|
||||
import net.Indyuce.mmocore.skill.cast.SkillCastingMode;
|
||||
import net.Indyuce.mmocore.skill.trigger.MMOCoreTriggerType;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -116,6 +117,7 @@ public class MMOCore extends JavaPlugin {
|
||||
MythicLib.plugin.getEntities().registerRelationHandler(new PartyRelationHandler());
|
||||
MythicLib.plugin.getEntities().registerRelationHandler(new GuildRelationHandler());
|
||||
MythicLib.plugin.getModifiers().registerModifierType("attribute", configObject -> new AttributeModifier(configObject));
|
||||
MMOCoreTriggerType.registerAll();
|
||||
|
||||
// Custom scripts
|
||||
MythicLib.plugin.getSkills().registerMechanic("mana", config -> new ManaMechanic(config));
|
||||
|
@ -8,6 +8,7 @@ import net.Indyuce.mmocore.command.PvpModeCommand;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CombatHandler implements Closeable {
|
||||
@ -30,7 +31,7 @@ public class CombatHandler implements Closeable {
|
||||
|
||||
// Simply refreshing
|
||||
if (isInCombat()) {
|
||||
Bukkit.getScheduler().cancelTask(task.getTaskId());
|
||||
task.cancel();
|
||||
task = newTask();
|
||||
|
||||
// Entering combat
|
||||
@ -42,6 +43,7 @@ public class CombatHandler implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private BukkitTask newTask() {
|
||||
return Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> quit(false), MMOCore.plugin.configManager.combatLogTimer / 50);
|
||||
}
|
||||
@ -102,8 +104,7 @@ public class CombatHandler implements Closeable {
|
||||
*/
|
||||
private void quit(boolean cancelTask) {
|
||||
Validate.isTrue(isInCombat(), "Player not in combat");
|
||||
if (cancelTask)
|
||||
Bukkit.getScheduler().cancelTask(task.getTaskId());
|
||||
if (cancelTask) task.cancel();
|
||||
task = null;
|
||||
|
||||
if (player.isOnline()) {
|
||||
@ -114,8 +115,7 @@ public class CombatHandler implements Closeable {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (isInCombat())
|
||||
quit(true);
|
||||
if (isInCombat()) quit(true);
|
||||
|
||||
// Necessary steps when entering a town.
|
||||
lastHit = 0;
|
||||
|
@ -0,0 +1,23 @@
|
||||
package net.Indyuce.mmocore.skill.trigger;
|
||||
|
||||
import io.lumine.mythic.lib.skill.trigger.TriggerType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MMOCoreTriggerType {
|
||||
|
||||
/**
|
||||
* Called when a player enters combat
|
||||
*/
|
||||
@NotNull
|
||||
public static TriggerType ENTER_COMBAT = new TriggerType("ENTER_COMBAT"),
|
||||
|
||||
/**
|
||||
* Called when a player quits combat
|
||||
*/
|
||||
QUIT_COMBAT = new TriggerType("QUIT_COMBAT");
|
||||
|
||||
public static void registerAll() {
|
||||
TriggerType.register(ENTER_COMBAT);
|
||||
TriggerType.register(QUIT_COMBAT);
|
||||
}
|
||||
}
|
@ -43,6 +43,7 @@ public class MMOCoreBukkit {
|
||||
Bukkit.getPluginManager().registerEvents(new FishingListener(), plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerCollectStats(), plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new PlayerPressKeyListener(), plugin);
|
||||
Bukkit.getPluginManager().registerEvents(new MMOCoreSkillTriggers(), plugin);
|
||||
// Bukkit.getPluginManager().registerEvents(new ClassTriggers(), plugin);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package net.Indyuce.mmocore.listener;
|
||||
|
||||
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
||||
import io.lumine.mythic.lib.skill.trigger.TriggerMetadata;
|
||||
import net.Indyuce.mmocore.api.event.PlayerCombatEvent;
|
||||
import net.Indyuce.mmocore.skill.trigger.MMOCoreTriggerType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class MMOCoreSkillTriggers implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void a(PlayerCombatEvent event) {
|
||||
final MMOPlayerData caster = event.getData().getMMOPlayerData();
|
||||
caster.triggerSkills(new TriggerMetadata(caster, event.entersCombat() ? MMOCoreTriggerType.ENTER_COMBAT : MMOCoreTriggerType.QUIT_COMBAT));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user