From 354bb77f9d6f669f0edbf64e82cf5dad4286c4c5 Mon Sep 17 00:00:00 2001 From: benamaurer Date: Thu, 20 May 2021 17:08:15 -0500 Subject: [PATCH] Adding the chat based advancement trigger and trigger criteria to config --- .../qol/listeners/AsyncPlayerChatListener.java | 11 +++++++++++ src/main/resources/config.yml | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/xyz/etztech/qol/listeners/AsyncPlayerChatListener.java b/src/main/java/xyz/etztech/qol/listeners/AsyncPlayerChatListener.java index 08ebfed..d8650de 100644 --- a/src/main/java/xyz/etztech/qol/listeners/AsyncPlayerChatListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/AsyncPlayerChatListener.java @@ -6,6 +6,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.advancement.Advancement; import xyz.etztech.qol.QoL; import java.util.Arrays; @@ -48,6 +49,16 @@ public class AsyncPlayerChatListener implements Listener { String chat = event.getMessage(); boolean escape = false; + //Checking if player has been awarded the chat advancement, if not, message is searched for triggers + Advancement adv = Bukkit.getAdvancement(new Namespacedkey("canopy", "chat_advancement")); + + if (!player.getAdvancementProgress(adv).isDone()) { + List advancementTriggerList = plugin.getConfig().getStringList("chat-advancement-triggers"); + if (advancementTriggerList.stream().anyMatch(t -> chat.toLowerCase().contains(t.toLowerCase()))) { + player.getAdvancementProgress(adv).awardCriteria("win"); + } else{} + } else {} + // Escape if (chat.startsWith("\\")) { escape = true; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 17b14b4..764260f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -104,3 +104,7 @@ dynmap: defaults: map: "surface" zoom: 5 + +# A list of words/phrases which will award the chant advancement to the message author +chat-advancement-triggers: + - chat_advancment_test