forked from Upstream/mmocore
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.StaminaMechanic;
|
||||||
import net.Indyuce.mmocore.script.mechanic.StelliumMechanic;
|
import net.Indyuce.mmocore.script.mechanic.StelliumMechanic;
|
||||||
import net.Indyuce.mmocore.skill.cast.SkillCastingMode;
|
import net.Indyuce.mmocore.skill.cast.SkillCastingMode;
|
||||||
|
import net.Indyuce.mmocore.skill.trigger.MMOCoreTriggerType;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -116,6 +117,7 @@ public class MMOCore extends JavaPlugin {
|
|||||||
MythicLib.plugin.getEntities().registerRelationHandler(new PartyRelationHandler());
|
MythicLib.plugin.getEntities().registerRelationHandler(new PartyRelationHandler());
|
||||||
MythicLib.plugin.getEntities().registerRelationHandler(new GuildRelationHandler());
|
MythicLib.plugin.getEntities().registerRelationHandler(new GuildRelationHandler());
|
||||||
MythicLib.plugin.getModifiers().registerModifierType("attribute", configObject -> new AttributeModifier(configObject));
|
MythicLib.plugin.getModifiers().registerModifierType("attribute", configObject -> new AttributeModifier(configObject));
|
||||||
|
MMOCoreTriggerType.registerAll();
|
||||||
|
|
||||||
// Custom scripts
|
// Custom scripts
|
||||||
MythicLib.plugin.getSkills().registerMechanic("mana", config -> new ManaMechanic(config));
|
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.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class CombatHandler implements Closeable {
|
public class CombatHandler implements Closeable {
|
||||||
@ -30,7 +31,7 @@ public class CombatHandler implements Closeable {
|
|||||||
|
|
||||||
// Simply refreshing
|
// Simply refreshing
|
||||||
if (isInCombat()) {
|
if (isInCombat()) {
|
||||||
Bukkit.getScheduler().cancelTask(task.getTaskId());
|
task.cancel();
|
||||||
task = newTask();
|
task = newTask();
|
||||||
|
|
||||||
// Entering combat
|
// Entering combat
|
||||||
@ -42,6 +43,7 @@ public class CombatHandler implements Closeable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private BukkitTask newTask() {
|
private BukkitTask newTask() {
|
||||||
return Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> quit(false), MMOCore.plugin.configManager.combatLogTimer / 50);
|
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) {
|
private void quit(boolean cancelTask) {
|
||||||
Validate.isTrue(isInCombat(), "Player not in combat");
|
Validate.isTrue(isInCombat(), "Player not in combat");
|
||||||
if (cancelTask)
|
if (cancelTask) task.cancel();
|
||||||
Bukkit.getScheduler().cancelTask(task.getTaskId());
|
|
||||||
task = null;
|
task = null;
|
||||||
|
|
||||||
if (player.isOnline()) {
|
if (player.isOnline()) {
|
||||||
@ -114,8 +115,7 @@ public class CombatHandler implements Closeable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
if (isInCombat())
|
if (isInCombat()) quit(true);
|
||||||
quit(true);
|
|
||||||
|
|
||||||
// Necessary steps when entering a town.
|
// Necessary steps when entering a town.
|
||||||
lastHit = 0;
|
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 FishingListener(), plugin);
|
||||||
Bukkit.getPluginManager().registerEvents(new PlayerCollectStats(), plugin);
|
Bukkit.getPluginManager().registerEvents(new PlayerCollectStats(), plugin);
|
||||||
Bukkit.getPluginManager().registerEvents(new PlayerPressKeyListener(), plugin);
|
Bukkit.getPluginManager().registerEvents(new PlayerPressKeyListener(), plugin);
|
||||||
|
Bukkit.getPluginManager().registerEvents(new MMOCoreSkillTriggers(), plugin);
|
||||||
// Bukkit.getPluginManager().registerEvents(new ClassTriggers(), 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