Updated Source Code for Version 0.3.5
This commit is contained in:
@@ -14,6 +14,7 @@ public class BroadcastCommand implements SimpleCommand {
|
||||
|
||||
private final VelocityBroadcast plugin;
|
||||
private final DatabaseManager databaseManager;
|
||||
private final MiniMessage mm = MiniMessage.miniMessage();
|
||||
|
||||
public BroadcastCommand(VelocityBroadcast plugin) {
|
||||
this.plugin = plugin;
|
||||
@@ -26,12 +27,12 @@ public class BroadcastCommand implements SimpleCommand {
|
||||
List<String> args = List.of(invocation.arguments());
|
||||
|
||||
if (!source.hasPermission("vb.broadcast")) {
|
||||
source.sendMessage(MiniMessage.miniMessage().deserialize("<red>You don't have permission to use this command.</red>"));
|
||||
source.sendMessage(mm.deserialize("<red>You don't have permission to use this command.</red>"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.isEmpty()) {
|
||||
source.sendMessage(MiniMessage.miniMessage().deserialize("<red>Usage: /vb <message></red>"));
|
||||
source.sendMessage(mm.deserialize("<red>Usage: /vb <message></red>"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,20 +40,19 @@ public class BroadcastCommand implements SimpleCommand {
|
||||
String prefix = plugin.getConfigHandler().getPrefix();
|
||||
String fullMessage = prefix + messageRaw;
|
||||
|
||||
Component broadcast = MiniMessage.miniMessage().deserialize(fullMessage);
|
||||
|
||||
Component broadcast = mm.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
|
||||
// ✅ Log to the database with proper sender
|
||||
String sender = (source instanceof Player player) ? player.getUsername() : "Console";
|
||||
String sourceServer = plugin.getServer().getBoundAddress().toString();
|
||||
databaseManager.logBroadcast(sender, messageRaw, sourceServer);
|
||||
|
||||
// Optional feedback to source
|
||||
source.sendMessage(mm.deserialize("<green>Broadcast sent.</green>"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,17 +16,19 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
|
||||
@Plugin(
|
||||
id = "velocitybroadcast",
|
||||
name = "VelocityBroadcast",
|
||||
version = "0.3-pre",
|
||||
version = "0.3.5",
|
||||
description = "A proxy-wide broadcast plugin for Velocity.",
|
||||
authors = {"Adzel"}
|
||||
)
|
||||
public class VelocityBroadcast {
|
||||
|
||||
public static final String PLUGIN_VERSION = "0.3-pre";
|
||||
public static final String PLUGIN_VERSION = "0.3.5";
|
||||
public static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
|
||||
|
||||
private final ProxyServer server;
|
||||
@@ -35,6 +37,7 @@ public class VelocityBroadcast {
|
||||
|
||||
private ConfigHandler config;
|
||||
private DatabaseManager databaseManager;
|
||||
private LuckPerms luckPerms;
|
||||
|
||||
@Inject
|
||||
public VelocityBroadcast(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) {
|
||||
@@ -53,6 +56,15 @@ public class VelocityBroadcast {
|
||||
logger.info("[VelocityBroadcast] Debug mode is enabled.");
|
||||
}
|
||||
|
||||
// Initialize LuckPerms
|
||||
try {
|
||||
this.luckPerms = LuckPermsProvider.get();
|
||||
logger.info("[VelocityBroadcast] Successfully hooked into LuckPerms.");
|
||||
} catch (IllegalStateException e) {
|
||||
logger.error("[VelocityBroadcast] LuckPerms is not loaded! This plugin requires LuckPerms.");
|
||||
return; // Prevent plugin from loading if LP is not available
|
||||
}
|
||||
|
||||
// Initialize database manager
|
||||
java.util.logging.Logger jdkLogger = java.util.logging.Logger.getLogger("VelocityBroadcast");
|
||||
this.databaseManager = new DatabaseManager(config, jdkLogger, dataDirectory);
|
||||
@@ -68,10 +80,10 @@ public class VelocityBroadcast {
|
||||
}
|
||||
});
|
||||
|
||||
// ✅ Register login listener with DatabaseManager
|
||||
// Register login listener
|
||||
server.getEventManager().register(this, new LoginListener(server, PLUGIN_VERSION, updateChecker, databaseManager));
|
||||
|
||||
// Register root command
|
||||
// Register command
|
||||
server.getCommandManager().register(
|
||||
server.getCommandManager().metaBuilder("vb").plugin(this).build(),
|
||||
new VBCommand(this)
|
||||
@@ -104,4 +116,8 @@ public class VelocityBroadcast {
|
||||
public DatabaseManager getDatabaseManager() {
|
||||
return databaseManager;
|
||||
}
|
||||
|
||||
public LuckPerms getLuckPerms() {
|
||||
return luckPerms;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user