Allow logging chat messages with CommandSender

This commit is contained in:
whitebelyash 2026-02-08 22:04:09 +04:00
parent 2c91899055
commit 38c557fa12
2 changed files with 23 additions and 19 deletions

View file

@ -15,6 +15,7 @@ import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@ -216,48 +217,42 @@ public class CoreProtectAPI extends Queue {
/**
* Logs a chat message for a player.
*
* @param player
* @param sender
* The player who sent the message
* @param message
* The chat message
* @return True if the message was logged
*/
public boolean logChat(Player player, String message) {
public boolean logChat(CommandSender sender, String message) {
Player player = null;
if (sender instanceof Player) {
player = (Player) sender;
if (!isEnabledForPlayer(player) || !Config.getConfig(player.getWorld()).PLAYER_MESSAGES) {
return false;
}
}
if (message == null || message.isEmpty() || message.startsWith("/")) {
return false;
}
long timestamp = System.currentTimeMillis() / 1000L;
Queue.queuePlayerChat(player, message, timestamp);
if(player == null) Queue.queueChat(sender, message, timestamp);
else Queue.queuePlayerChat(player, message, timestamp);
return true;
}
/**
* Logs a componentized chat message for a player.
*
* @param player
* @param sender
* The player who sent the message
* @param component
* The chat message
* @return True if the message was logged
*/
public boolean logChat(Player player, Component component) {
if (!isEnabledForPlayer(player) || !Config.getConfig(player.getWorld()).PLAYER_MESSAGES) {
return false;
}
if (component == null) {
return false;
}
long timestamp = System.currentTimeMillis() / 1000L;
// TODO: proper implementation
Queue.queuePlayerChat(player, component.insertion(), timestamp);
return true;
public boolean logChat(CommandSender sender, Component component) {
return logChat(sender, component.insertion());
}
/**

View file

@ -13,6 +13,7 @@ import org.bukkit.block.data.Bisected;
import org.bukkit.block.data.Bisected.Half;
import org.bukkit.block.data.type.Bed;
import org.bukkit.block.data.type.Bed.Part;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -303,6 +304,14 @@ public class Queue {
queueStandardData(consumerId, currentConsumer, new String[] { player.getName(), null }, new Object[] { timestamp, player.getLocation().clone() });
}
protected static void queueChat(CommandSender sender, String message, long timestamp) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);
addConsumer(currentConsumer, new Object[] { consumerId, Process.PLAYER_CHAT, null, 0, null, 0, 0, null });
Consumer.consumerStrings.get(currentConsumer).put(consumerId, message);
queueStandardData(consumerId, currentConsumer, new String[] { sender.getName(), null }, new Object[] { timestamp, null });
}
protected static void queuePlayerCommand(Player player, String message, long timestamp) {
int currentConsumer = Consumer.currentConsumer;
int consumerId = Consumer.newConsumerId(currentConsumer);