Updated Source Files for Version 0.3-Pre

This commit is contained in:
2025-06-07 11:22:22 -07:00
parent 5e5ac05b72
commit 6510c4bf8c
15 changed files with 495 additions and 105 deletions

View File

@@ -2,8 +2,10 @@ 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;
@@ -11,10 +13,12 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
public class VBCommand implements SimpleCommand {
private final VelocityBroadcast plugin;
private final DatabaseManager databaseManager;
private final MiniMessage mm = MiniMessage.miniMessage();
public VBCommand(VelocityBroadcast plugin) {
this.plugin = plugin;
this.databaseManager = plugin.getDatabaseManager();
}
@Override
@@ -22,68 +26,91 @@ public class VBCommand implements SimpleCommand {
CommandSource source = invocation.source();
List<String> args = List.of(invocation.arguments());
if (args.isEmpty() || args.get(0).equalsIgnoreCase("help")) {
source.sendMessage(parseFormatted("<gold><bold>VelocityBroadcast Commands:</bold></gold>"));
source.sendMessage(parseFormatted("<yellow>/vb <message></yellow> <gray>- Broadcast a message to all players</gray>"));
String fullCommand = "/vb" + (args.isEmpty() ? "" : " " + String.join(" ", args));
String username = (source instanceof Player) ? ((Player) source).getUsername() : "Console";
if (source.hasPermission("vb.admin")) {
source.sendMessage(parseFormatted("<yellow>/vb prefix <newPrefix></yellow> <gray>- Change the broadcast prefix</gray>"));
source.sendMessage(parseFormatted("<yellow>/vb reload</yellow> <gray>- Reload the plugin config</gray>"));
boolean success = true;
try {
if (args.isEmpty() || args.get(0).equalsIgnoreCase("help")) {
source.sendMessage(parseFormatted("<gold><bold>VelocityBroadcast Commands:</bold></gold>"));
source.sendMessage(parseFormatted("<yellow>/vb <message></yellow> <gray>- Broadcast a message to all players</gray>"));
if (source.hasPermission("vb.admin")) {
source.sendMessage(parseFormatted("<yellow>/vb prefix <newPrefix></yellow> <gray>- Change the broadcast prefix</gray>"));
source.sendMessage(parseFormatted("<yellow>/vb reload</yellow> <gray>- Reload the plugin config</gray>"));
}
success = false;
return;
}
return;
}
String sub = args.get(0).toLowerCase();
List<String> subArgs = args.subList(1, args.size());
String sub = args.get(0).toLowerCase();
List<String> subArgs = args.subList(1, args.size());
switch (sub) {
case "prefix":
if (!source.hasPermission("vb.admin")) {
source.sendMessage(parseFormatted("<red>You don't have permission to change the broadcast prefix.</red>"));
return;
switch (sub) {
case "prefix" -> {
if (!source.hasPermission("vb.admin")) {
source.sendMessage(parseFormatted("<red>You don't have permission to change the broadcast prefix.</red>"));
success = false;
return;
}
if (subArgs.isEmpty()) {
source.sendMessage(parseFormatted("<red>Usage: /vb prefix <newPrefix></red>"));
success = false;
return;
}
String newPrefix = String.join(" ", subArgs);
plugin.getConfigHandler().setPrefix(newPrefix);
source.sendMessage(parseFormatted("<green>Prefix updated to:</green> <gray>" + newPrefix + "</gray>"));
if (plugin.getConfigHandler().isDebugEnabled()) {
plugin.getLogger().info("[Prefix] Updated prefix to: " + newPrefix);
}
}
if (subArgs.isEmpty()) {
source.sendMessage(parseFormatted("<red>Usage: /vb prefix <newPrefix></red>"));
return;
case "reload" -> {
if (!source.hasPermission("vb.admin")) {
source.sendMessage(parseFormatted("<red>You don't have permission to reload the config.</red>"));
success = false;
return;
}
plugin.getConfigHandler().reload();
source.sendMessage(parseFormatted("<green>VelocityBroadcast config reloaded.</green>"));
if (plugin.getConfigHandler().isDebugEnabled()) {
plugin.getLogger().info("[Reload] Config reloaded by " + source.toString());
}
}
String newPrefix = String.join(" ", subArgs);
plugin.getConfigHandler().setPrefix(newPrefix);
source.sendMessage(parseFormatted("<green>Prefix updated to:</green> <gray>" + newPrefix + "</gray>"));
if (plugin.getConfigHandler().isDebugEnabled()) {
plugin.getLogger().info("[Prefix] Updated prefix to: " + newPrefix);
}
break;
default -> {
// Treat as broadcast message
if (!source.hasPermission("vb.broadcast")) {
source.sendMessage(parseFormatted("<red>You don't have permission to broadcast.</red>"));
success = false;
return;
}
case "reload":
if (!source.hasPermission("vb.admin")) {
source.sendMessage(parseFormatted("<red>You don't have permission to reload the config.</red>"));
return;
}
String fullMessage = plugin.getConfigHandler().getPrefix() + String.join(" ", args);
Component broadcast = parseFormatted(fullMessage);
plugin.getConfigHandler().reload();
source.sendMessage(parseFormatted("<green>VelocityBroadcast config reloaded.</green>"));
if (plugin.getConfigHandler().isDebugEnabled()) {
plugin.getLogger().info("[Reload] Config reloaded by " + source.toString());
}
break;
plugin.getServer().getAllPlayers().forEach(p -> p.sendMessage(broadcast));
default:
// Treat as broadcast message
if (!source.hasPermission("vb.broadcast")) {
source.sendMessage(parseFormatted("<red>You don't have permission to broadcast.</red>"));
return;
if (plugin.getConfigHandler().isDebugEnabled()) {
plugin.getLogger().info("[Broadcast] Sent: " + fullMessage);
}
}
String fullMessage = plugin.getConfigHandler().getPrefix() + String.join(" ", args);
Component broadcast = parseFormatted(fullMessage);
plugin.getServer().getAllPlayers().forEach(p -> p.sendMessage(broadcast));
if (plugin.getConfigHandler().isDebugEnabled()) {
plugin.getLogger().info("[Broadcast] Sent: " + fullMessage);
}
break;
}
} catch (Exception e) {
plugin.getLogger().error("Error executing /vb command", e);
source.sendMessage(parseFormatted("<red>An error occurred while executing the command.</red>"));
success = false;
} finally {
// ✅ Log the command usage
databaseManager.logCommand(username, fullCommand, success);
}
}