Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1938c56
commit 478c523
Showing
5 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...in/java/com/denizenscript/depenizen/bukkit/events/sentinel/SentinelAttackScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.denizenscript.depenizen.bukkit.events.sentinel; | ||
|
||
import net.aufdemrand.denizen.BukkitScriptEntryData; | ||
import net.aufdemrand.denizen.events.BukkitScriptEvent; | ||
import net.aufdemrand.denizen.objects.dNPC; | ||
import net.aufdemrand.denizen.utilities.DenizenAPI; | ||
import net.aufdemrand.denizencore.objects.dObject; | ||
import net.aufdemrand.denizencore.scripts.ScriptEntryData; | ||
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer; | ||
import net.aufdemrand.denizencore.utilities.CoreUtilities; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.mcmonkey.sentinel.events.SentinelAttackEvent; | ||
|
||
// <--[event] | ||
// @Events | ||
// on sentinel npc attacks | ||
// | ||
// @Regex ^on sentinel npc attacks$ | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a Sentinel-powered NPC attacks a target. | ||
// | ||
// @Context | ||
// <context.entity> returns the NPC that is attacking. | ||
// | ||
// @Plugin DepenizenBukkit, Sentinel | ||
// | ||
// --> | ||
|
||
public class SentinelAttackScriptEvent extends BukkitScriptEvent implements Listener { | ||
|
||
public SentinelAttackScriptEvent() { | ||
instance = this; | ||
} | ||
|
||
public static SentinelAttackScriptEvent instance; | ||
public SentinelAttackEvent event; | ||
public dNPC entity; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptContainer scriptContainer, String s) { | ||
return CoreUtilities.toLowerCase(s).startsWith("sentinel npc attacks"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptContainer scriptContainer, String s) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "SentinelAttack"; | ||
} | ||
|
||
@Override | ||
public void init() { | ||
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance()); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
SentinelAttackEvent.getHandlerList().unregister(this); | ||
} | ||
|
||
@Override | ||
public boolean applyDetermination(ScriptContainer container, String determination) { | ||
return super.applyDetermination(container, determination); | ||
} | ||
|
||
@Override | ||
public ScriptEntryData getScriptEntryData() { | ||
return new BukkitScriptEntryData(null, entity); | ||
} | ||
|
||
@Override | ||
public dObject getContext(String name) { | ||
if (name.startsWith("entity")) { | ||
return entity; | ||
} | ||
return super.getContext(name); | ||
} | ||
|
||
@EventHandler | ||
public void onSentinelAttack(SentinelAttackEvent event) { | ||
entity = new dNPC(event.getNPC()); | ||
cancelled = event.isCancelled(); | ||
this.event = event; | ||
fire(); | ||
event.setCancelled(cancelled); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
bukkit/src/main/java/com/denizenscript/depenizen/bukkit/support/plugins/SentinelSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.denizenscript.depenizen.bukkit.support.plugins; | ||
|
||
import com.denizenscript.depenizen.bukkit.events.sentinel.SentinelAttackScriptEvent; | ||
import com.denizenscript.depenizen.bukkit.support.Support; | ||
|
||
public class SentinelSupport extends Support { | ||
|
||
public SentinelSupport() { | ||
registerScriptEvents(new SentinelAttackScriptEvent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters