package com.adzel.velocitybroadcast; import java.util.List; import com.adzel.velocitybroadcast.util.DatabaseManager; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.proxy.Player; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.minimessage.MiniMessage; public class BroadcastCommand implements SimpleCommand { private final VelocityBroadcast plugin; private final DatabaseManager databaseManager; public BroadcastCommand(VelocityBroadcast plugin) { this.plugin = plugin; this.databaseManager = plugin.getDatabaseManager(); } @Override public void execute(Invocation invocation) { CommandSource source = invocation.source(); List args = List.of(invocation.arguments()); if (!source.hasPermission("vb.broadcast")) { source.sendMessage(MiniMessage.miniMessage().deserialize("You don't have permission to use this command.")); return; } if (args.isEmpty()) { source.sendMessage(MiniMessage.miniMessage().deserialize("Usage: /vb ")); return; } String messageRaw = String.join(" ", args); String prefix = plugin.getConfigHandler().getPrefix(); String fullMessage = prefix + messageRaw; Component broadcast = MiniMessage.miniMessage().deserialize(fullMessage); plugin.getServer().getAllPlayers().forEach(player -> player.sendMessage(broadcast)); if (plugin.getConfigHandler().isDebugEnabled()) { plugin.getLogger().info("[Broadcast] Sent: " + fullMessage); } // ✅ Log to the database String sender = (source instanceof Player) ? ((Player) source).getUsername() : "Console"; String sourceServer = plugin.getServer().getBoundAddress().toString(); // optional databaseManager.logBroadcast(sender, messageRaw, sourceServer); } }