Skip to content

Commit

Permalink
The ChatPromptManager now sanitizes input-messages
Browse files Browse the repository at this point in the history
  • Loading branch information
BlvckBytes committed Nov 8, 2024
1 parent 1ba23ed commit bfc449e
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package me.blvckbytes.quick_shop_search;

import com.tcoded.folialib.impl.PlatformScheduler;
import me.blvckbytes.item_predicate_parser.translation.resolver.TranslationResolver;
import org.bukkit.entity.Player;
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.player.PlayerQuitEvent;
Expand Down Expand Up @@ -46,17 +48,20 @@ public boolean register(Player player, Consumer<String> inputHandler, Runnable t
}
}

@EventHandler
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChat(AsyncPlayerChatEvent event) {
ChatPromptInstance handler;

synchronized (handlerByUuid) {
handler = removeAndCancelIfExists(event.getPlayer());
}

// Might not be the most decoupled solution, but since QSS depends on IPP, we're fine.
var sanitizedMessage = TranslationResolver.sanitize(event.getMessage());

if (handler != null) {
event.setCancelled(true);
handler.handler().accept(event.getMessage());
handler.handler().accept(sanitizedMessage);
}
}

Expand Down

0 comments on commit bfc449e

Please sign in to comment.