Skip to content

Commit

Permalink
fix chat triggers throwing extra debug
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 5, 2020
1 parent e8b2ffd commit fb8a1f9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 30 deletions.
Expand Up @@ -58,7 +58,7 @@ public AdvancementCommand() {
// The hidden argument sets whether the advancement should be hidden until it is completed.
// The x and y arguments are offsets based on the size of an advancement icon in the menu. They are required for custom tabs to look reasonable.
//
// WARNING: Failure to re-create advancements on every server start may result in loss of data.
// WARNING: Failure to re-create advancements on every server start may result in loss of data - use <@link event server prestart>.
//
// @Tags
// <PlayerTag.has_advancement[<advancement>]>
Expand All @@ -81,9 +81,7 @@ public AdvancementCommand() {

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

for (Argument arg : scriptEntry.getProcessedArgs()) {

if (!scriptEntry.hasObject("id")
&& arg.matchesPrefix("id")) {
scriptEntry.addObject("id", arg.asElement());
Expand Down Expand Up @@ -161,11 +159,9 @@ else if (!scriptEntry.hasObject("y")
arg.reportUnhandled();
}
}

if (!scriptEntry.hasObject("id")) {
throw new InvalidArgumentsException("Must specify an ID!");
}

scriptEntry.defaultObject("icon", new ItemTag(Material.AIR));
scriptEntry.defaultObject("title", new ElementTag(""));
scriptEntry.defaultObject("description", new ElementTag(""));
Expand All @@ -182,7 +178,6 @@ else if (!scriptEntry.hasObject("y")

@Override
public void execute(ScriptEntry scriptEntry) {

ElementTag id = scriptEntry.getElement("id");
ElementTag parent = scriptEntry.getElement("parent");
ElementTag delete = scriptEntry.getElement("delete");
Expand All @@ -198,7 +193,6 @@ public void execute(ScriptEntry scriptEntry) {
ElementTag hidden = scriptEntry.getElement("hidden");
ElementTag x = scriptEntry.getElement("x");
ElementTag y = scriptEntry.getElement("y");

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, name, id.debug() + (parent != null ? parent.debug() : "")
+ (delete != null ? delete.debug() : "") + (grant != null ? grant.debug() : "")
Expand All @@ -207,11 +201,8 @@ public void execute(ScriptEntry scriptEntry) {
+ (background != null ? background.debug() : "")
+ frame.debug() + toast.debug() + announce.debug() + hidden.debug() + x.debug() + y.debug());
}

final AdvancementHelper advancementHelper = NMSHandler.getAdvancementHelper();

NamespacedKey key = new NamespacedKey(DenizenAPI.getCurrentInstance(), id.asString());

if (delete == null && grant == null && revoke == null) {
NamespacedKey parentKey = null;
NamespacedKey backgroundKey = null;
Expand All @@ -233,12 +224,10 @@ else if (background != null) {
backgroundKey = new NamespacedKey(CoreUtilities.toLowerCase(backgroundSplit.get(0)), CoreUtilities.toLowerCase(backgroundSplit.get(1)));
}
}

final Advancement advancement = new Advancement(false, key, parentKey,
icon.getItemStack(), title.asString(), description.asString(),
backgroundKey, Advancement.Frame.valueOf(frame.asString().toUpperCase()),
toast.asBoolean(), announce.asBoolean(), hidden.asBoolean(), x.asFloat(), y.asFloat());

advancementHelper.register(advancement);
customRegistered.put(key, advancement);
}
Expand Down
Expand Up @@ -48,6 +48,8 @@ public CreateWorldCommand() {
//
// The 'copy_from' argument is ~waitable. Refer to <@link language ~waitable>.
//
// It's often ideal to put this command inside <@link event server prestart>.
//
// @Tags
// <server.world_types>
// <server.worlds>
Expand Down
Expand Up @@ -15,6 +15,7 @@
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.ArgumentHelper;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ScriptTag;
import com.denizenscript.denizencore.scripts.commands.queue.DetermineCommand;
import com.denizenscript.denizencore.tags.TagManager;
import com.denizenscript.denizencore.utilities.CoreUtilities;
Expand Down Expand Up @@ -347,7 +348,7 @@ else if (keyword.equals("*")
if (id != null) {
String hideTriggerMessage = script.getString("STEPS." + step + ".CHAT TRIGGER." + id + ".HIDE TRIGGER MESSAGE", "false");
if (!hideTriggerMessage.equalsIgnoreCase("true")) {
Utilities.talkToNPC(replacementText, denizenPlayer, npc, Settings.chatToNpcOverhearingRange());
Utilities.talkToNPC(replacementText, denizenPlayer, npc, Settings.chatToNpcOverhearingRange(), new ScriptTag(script));
}
parse(npc, denizenPlayer, script, id, context);
if (HyperDebug) {
Expand All @@ -357,7 +358,7 @@ else if (keyword.equals("*")
}
else {
if (!Settings.chatGloballyIfFailedChatTriggers()) {
Utilities.talkToNPC(message, denizenPlayer, npc, Settings.chatToNpcOverhearingRange());
Utilities.talkToNPC(message, denizenPlayer, npc, Settings.chatToNpcOverhearingRange(), new ScriptTag(script));
if (HyperDebug) {
Debug.log("Chat globally");
}
Expand Down
Expand Up @@ -8,6 +8,7 @@
import com.denizenscript.denizen.npc.traits.TriggerTrait;
import com.denizenscript.denizen.tags.BukkitTagContext;
import com.denizenscript.denizen.utilities.blocks.MaterialCompat;
import com.denizenscript.denizencore.objects.core.ScriptTag;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.tags.TagManager;
import com.denizenscript.denizencore.utilities.CoreUtilities;
Expand Down Expand Up @@ -240,17 +241,17 @@ public static boolean isWalkable(Location location) {
* @param npc the npc being talked to
* @param range the range, in blocks, that 'bystanders' will hear he chat
*/
public static void talkToNPC(String message, PlayerTag player, NPCTag npc, double range) {
public static void talkToNPC(String message, PlayerTag player, NPCTag npc, double range, ScriptTag script) {
String replacer = String.valueOf((char) 0x04);
// Get formats from Settings, and fill in <TEXT>
String talkFormat = Settings.chatToNpcFormat()
.replaceAll("(?i)<TEXT>", replacer);
String bystanderFormat = Settings.chatToNpcOverheardFormat()
.replaceAll("(?i)<TEXT>", replacer);

// Fill in tags // TODO: Debug option?
talkFormat = TagManager.tag(talkFormat, new BukkitTagContext(player, npc, null, true, null)).replace(replacer, message);
bystanderFormat = TagManager.tag(bystanderFormat, new BukkitTagContext(player, npc, null, true, null)).replace(replacer, message);
// Fill in tags
talkFormat = TagManager.tag(talkFormat, new BukkitTagContext(player, npc, script)).replace(replacer, message);
bystanderFormat = TagManager.tag(bystanderFormat, new BukkitTagContext(player, npc, script)).replace(replacer, message);

// Send message to player
player.getPlayerEntity().sendMessage(talkFormat);
Expand Down Expand Up @@ -430,16 +431,6 @@ public static String generateRandomColors(int count) {
return ret;
}

private final static String colorsLimited = "0123456789abcdef";

public static String generateRandomColorsWithDots(int count) {
String ret = "";
for (int i = 0; i < count; i++) {
ret += String.valueOf(ChatColor.COLOR_CHAR) + colorsLimited.charAt(CoreUtilities.getRandom().nextInt(colorsLimited.length())) + ".";
}
return ret;
}

public static BukkitScriptEntryData getEntryData(ScriptEntry entry) {
return (BukkitScriptEntryData) entry.entryData;
}
Expand Down
Expand Up @@ -140,8 +140,6 @@ private static GameProfile getGameProfile(PlayerProfile playerProfile) {
return gameProfile;
}

public static Field PLAYER_INFO_PLAYERDATA_LIST = ReflectionHelper.getFields(PacketPlayOutPlayerInfo.class).get("b");

public static final Class playerInfoData;

public static final Field playerInfoData_latency,
Expand Down

0 comments on commit fb8a1f9

Please sign in to comment.