Skip to content

Commit

Permalink
area enter/exit event: patch entity matching
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 6, 2021
1 parent 08c4fda commit c876122
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
@@ -1,6 +1,6 @@
package com.denizenscript.denizen.paper.events;

import com.denizenscript.denizen.events.player.AreaEnterExitScriptEvent;
import com.denizenscript.denizen.events.entity.AreaEnterExitScriptEvent;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizencore.objects.ObjectTag;
Expand Down
Expand Up @@ -539,6 +539,11 @@ else if (isAdvancedMatchable(lower)) {
return true;
}
}
for (PolygonTag polygon : NotableManager.getAllType(PolygonTag.class)) {
if (polygon.doesContainLocation(location) && matcher.doesMatch(polygon.noteName)) {
return true;
}
}
for (World world : Bukkit.getWorlds()) {
if (matcher.doesMatch(CoreUtilities.toLowerCase(world.getName()))) {
return true;
Expand Down
Expand Up @@ -45,6 +45,9 @@ public static void registerMainEvents() {
ScriptEvent.registerScriptEvent(new RedstoneScriptEvent());

// Entity events
if (!Denizen.supportsPaper) {
ScriptEvent.registerScriptEvent(new AreaEnterExitScriptEvent());
}
ScriptEvent.registerScriptEvent(new CreeperPoweredScriptEvent());
ScriptEvent.registerScriptEvent(new DragonPhaseChangeScriptEvent());
ScriptEvent.registerScriptEvent(new EntityAirLevelChangeScriptEvent());
Expand Down Expand Up @@ -111,9 +114,6 @@ public static void registerMainEvents() {
ScriptEvent.registerScriptEvent(new ItemSpawnsScriptEvent());

// Player events
if (!Denizen.supportsPaper) {
ScriptEvent.registerScriptEvent(new AreaEnterExitScriptEvent());
}
ScriptEvent.registerScriptEvent(new BiomeEnterExitScriptEvent());
ScriptEvent.registerScriptEvent(new BlockDropsItemScriptEvent());
ScriptEvent.registerScriptEvent(new ChatScriptEvent());
Expand Down
@@ -1,4 +1,4 @@
package com.denizenscript.denizen.events.player;
package com.denizenscript.denizen.events.entity;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.*;
Expand Down Expand Up @@ -31,7 +31,7 @@ public class AreaEnterExitScriptEvent extends BukkitScriptEvent implements Liste
//
// @Regex ^on [^\s]+ (enters|exits) [^\s]+$
//
// @Group Player
// @Group Entity
//
// @Triggers when an entity enters or exits a noted area (cuboid, ellipsoid, or polygon). On Spigot servers, only fires for players. Paper is required for other mob types.
//
Expand Down Expand Up @@ -108,6 +108,9 @@ else if (areaName.equals("ellipsoid")) {
return false;
}
}
if (!tryEntity(currentEntity, path.eventArgLowerAt(0))) {
return false;
}
return super.matches(path);
}

Expand Down
Expand Up @@ -60,7 +60,6 @@ public TitleCommand() {

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (Argument arg : ArgumentHelper.interpret(scriptEntry, scriptEntry.getOriginalArguments())) {
if (arg.matchesPrefix("title")) {
scriptEntry.addObject("title", arg.asElement());
Expand Down Expand Up @@ -93,38 +92,31 @@ else if (!scriptEntry.hasObject("per_player")
else {
arg.reportUnhandled();
}

}

if (!scriptEntry.hasObject("title") && !scriptEntry.hasObject("subtitle")) {
throw new InvalidArgumentsException("Must have a title or subtitle!");
}

scriptEntry.defaultObject("fade_in", new DurationTag(1)).defaultObject("stay", new DurationTag(3))
.defaultObject("fade_out", new DurationTag(1))
.defaultObject("targets", Arrays.asList(Utilities.getEntryPlayer(scriptEntry)))
.defaultObject("subtitle", new ElementTag("")).defaultObject("title", new ElementTag(""));

}

@Override
public void execute(ScriptEntry scriptEntry) {

String title = scriptEntry.getElement("title").asString();
String subtitle = scriptEntry.getElement("subtitle").asString();
DurationTag fade_in = scriptEntry.getObjectTag("fade_in");
DurationTag stay = scriptEntry.getObjectTag("stay");
DurationTag fade_out = scriptEntry.getObjectTag("fade_out");
List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
ElementTag perPlayerObj = scriptEntry.getElement("per_player");

boolean perPlayer = perPlayerObj != null && perPlayerObj.asBoolean();
BukkitTagContext context = (BukkitTagContext) scriptEntry.getContext();
if (!perPlayer) {
title = TagManager.tag(title, context);
subtitle = TagManager.tag(subtitle, context);
}

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(),
ArgumentHelper.debugObj("title", title)
Expand All @@ -135,7 +127,6 @@ public void execute(ScriptEntry scriptEntry) {
+ ArgumentHelper.debugList("targets", targets)
+ (perPlayerObj != null ? perPlayerObj.debug() : ""));
}

for (PlayerTag player : targets) {
if (player != null) {
if (!player.isOnline()) {
Expand All @@ -155,7 +146,5 @@ public void execute(ScriptEntry scriptEntry) {
Debug.echoError("Sent title to non-existent player!?");
}
}

}

}

0 comments on commit c876122

Please sign in to comment.