mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 06:28:54 +00:00
Trigger bukkit chat events when using message commands
This commit is contained in:
7 files changed
+45
-2
No files matched your search
@@ -59,6 +59,10 @@ public final class BukkitChatListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerChat(final @NonNull AsyncChatEvent event) {
|
||||
if (event.viewers().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final var playerResult = this.carbonChat.server().player(event.getPlayer().getUniqueId()).join();
|
||||
final @Nullable CarbonPlayer sender = playerResult.player();
|
||||
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
*/
|
||||
package net.draycia.carbon.bukkit.users;
|
||||
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import net.draycia.carbon.api.util.InventorySlot;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.draycia.carbon.common.users.WrappedCarbonPlayer;
|
||||
@@ -30,6 +32,7 @@ import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -128,6 +131,14 @@ public final class CarbonPlayerBukkit extends WrappedCarbonPlayer implements For
|
||||
this.player().ifPresent(player -> player.chat(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean speechPermitted(final String message) {
|
||||
// ...........
|
||||
return new AsyncPlayerChatEvent(!Bukkit.isPrimaryThread(), this.player().get(), message, Set.of()).callEvent()
|
||||
&& new AsyncChatEvent(!Bukkit.isPrimaryThread(), this.player().get(), Set.of(),
|
||||
(player, name, msg, receiver) -> msg, Component.text(message), Component.text(message)).callEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean online() {
|
||||
return this.player().isPresent();
|
||||
|
||||
Reference in new issue
Block a user