Skip to content

Commit

Permalink
a few small bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 3, 2021
1 parent 2344d94 commit a1e9d17
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
Expand Up @@ -2517,11 +2517,6 @@ else if (object.getBukkitEntity() instanceof Hanging) {
});
}

public String describe() {
String escript = getEntityScript();
return "e@" + (escript != null && escript.length() > 0 ? escript : getEntityType().getLowercaseName()) + PropertyParser.getPropertiesString(this);
}

public static ObjectTagProcessor<EntityTag> tagProcessor = new ObjectTagProcessor<>();

public static void registerSpawnedOnlyTag(String name, TagRunnable.ObjectInterface<EntityTag> runnable, String... variants) {
Expand Down
Expand Up @@ -778,7 +778,8 @@ public static void registerTags() {
if (CoreUtilities.equalsIgnoreCase(val, e.getType().name())) {
return true;
}
if (CoreUtilities.equalsIgnoreCase(val, ent.getEntityScript())) {
String script = ent.getEntityScript();
if (script != null && CoreUtilities.equalsIgnoreCase(val, script)) {
return true;
}
EntityTag match = EntityTag.valueOf(val, CoreUtilities.noDebugContext);
Expand Down
Expand Up @@ -4,7 +4,7 @@
import com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer;
import com.denizenscript.denizen.scripts.containers.core.InteractScriptHelper;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.Settings;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.npc.traits.TriggerTrait;
Expand Down Expand Up @@ -37,7 +37,6 @@
public class ChatTrigger extends AbstractTrigger implements Listener {

final static Pattern triggerPattern = Pattern.compile("/([^/]*)/");
final static boolean HyperDebug = false; // TODO: Replace with core->dB.verbose!

// <--[language]
// @name Chat Triggers
Expand Down Expand Up @@ -117,23 +116,23 @@ public ChatContext process(Player player, String message) {
NPCTag npc = Utilities.getClosestNPC_ChatTrigger(player.getLocation(), 25);
PlayerTag denizenPlayer = PlayerTag.mirrorBukkitPlayer(player);

if (HyperDebug) {
if (Debug.verbose) {
Debug.log("Processing chat trigger: valid npc? " + (npc != null));
}
// No NPC? Nothing else to do here.
if (npc == null) {
return new ChatContext(false);
}

if (HyperDebug) {
if (Debug.verbose) {
Debug.log("Has trait? " + npc.getCitizen().hasTrait(TriggerTrait.class));
}
// If the NPC doesn't have triggers, or the triggers are not enabled, then
// just return false.
if (!npc.getCitizen().hasTrait(TriggerTrait.class)) {
return new ChatContext(false);
}
if (HyperDebug) {
if (Debug.verbose) {
Debug.log("enabled? " + npc.getCitizen().getOrAddTrait(TriggerTrait.class).isEnabled(name));
}
if (!npc.getCitizen().getOrAddTrait(TriggerTrait.class).isEnabled(name)) {
Expand All @@ -142,7 +141,7 @@ public ChatContext process(Player player, String message) {

// Check range
if (npc.getTriggerTrait().getRadius(name) < npc.getLocation().distance(player.getLocation())) {
if (HyperDebug) {
if (Debug.verbose) {
Debug.log("Not in range");
}
return new ChatContext(false);
Expand All @@ -155,7 +154,7 @@ public ChatContext process(Player player, String message) {

if (Settings.chatMustSeeNPC()) {
if (!player.hasLineOfSight(npc.getEntity())) {
if (HyperDebug) {
if (Debug.verbose) {
Debug.log("no LOS");
}
return new ChatContext(false);
Expand All @@ -164,7 +163,7 @@ public ChatContext process(Player player, String message) {

if (Settings.chatMustLookAtNPC()) {
if (!NMSHandler.getEntityHelper().isFacingEntity(player, npc.getEntity(), 45)) {
if (HyperDebug) {
if (Debug.verbose) {
Debug.log("Not facing");
}
return new ChatContext(false);
Expand All @@ -190,7 +189,7 @@ public ChatContext process(Player player, String message) {
// Return false if determine cancelled
if (trigger.hasDetermination()) {
if (trigger.getDetermination().equalsIgnoreCase("cancelled")) {
if (HyperDebug) {
if (Debug.verbose) {
Debug.log("Cancelled");
}
// Mark as handled, the event will cancel.
Expand Down Expand Up @@ -219,7 +218,7 @@ public ChatContext process(Player player, String message) {
}

if (script == null) {
if (HyperDebug) {
if (Debug.verbose) {
Debug.log("null script");
}
return new ChatContext(message, false);
Expand All @@ -244,7 +243,7 @@ public ChatContext process(Player player, String message) {
return new ChatContext(false);
}
else {
if (HyperDebug) {
if (Debug.verbose) {
Debug.log("No trigger in step, chatting globally");
}
return new ChatContext(message, ret);
Expand Down Expand Up @@ -366,31 +365,31 @@ else if (messageLow.contains(keywordLow)) {
Utilities.talkToNPC(replacementText, denizenPlayer, npc, Settings.chatToNpcOverhearingRange(), new ScriptTag(script));
}
parse(npc, denizenPlayer, script, id, context);
if (HyperDebug) {
if (Debug.verbose) {
Debug.log("chat to NPC");
}
return new ChatContext(!showNormalChat.equalsIgnoreCase("true"));
}
else {
if (!Settings.chatGloballyIfFailedChatTriggers()) {
Utilities.talkToNPC(message, denizenPlayer, npc, Settings.chatToNpcOverhearingRange(), new ScriptTag(script));
if (HyperDebug) {
if (Debug.verbose) {
Debug.log("Chat globally");
}
return new ChatContext(!showNormalChat.equalsIgnoreCase("true"));
}
// No matching chat triggers, and the config.yml says we
// should just ignore the interaction...
}
if (HyperDebug) {
if (Debug.verbose) {
Debug.log("Finished calculating");
}
return new ChatContext(message, ret);
}

@EventHandler
public void asyncChatTrigger(final AsyncPlayerChatEvent event) {
if (HyperDebug) {
if (Debug.verbose) {
Debug.log("Chat trigger seen, cancelled: " + event.isCancelled()
+ ", chatasync: " + Settings.chatAsynchronous());
}
Expand Down

0 comments on commit a1e9d17

Please sign in to comment.