Files
src
build.gradle
Code
8 437
src/main/java/com/proxytimer/commands/TimerCommand.java
package com.proxytimer.commands;
import com.proxytimer.ProxyTimer;
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;
import java.util.List;
public class TimerCommand implements SimpleCommand {
private final ProxyTimer plugin;
private final MiniMessage miniMessage = MiniMessage.miniMessage();
public TimerCommand(ProxyTimer plugin) {
this.plugin = plugin;
}
@Override
public void execute(Invocation invocation) {
var source = invocation.source();
String[] args = invocation.arguments();
if (!source.hasPermission("proxytimer.admin")) {
source.sendMessage(colorize("<red>You don't have permission to use this command!"));
return;
}
if (args.length == 0) {
sendHelp(source);
return;
}
switch (args[0].toLowerCase()) {
case "reload":
plugin.reloadConfiguration();
source.sendMessage(colorize(plugin.getConfigManager().getString("messages.prefix", "") + " " +
plugin.getConfigManager().getString("messages.reload", "<green>Configuration reloaded!")));
break;
case "reset":
plugin.getTimerManager().reset();
source.sendMessage(colorize(plugin.getConfigManager().getString("messages.prefix", "") + " " +
plugin.getConfigManager().getString("messages.timer-reset", "<green>Timer has been reset!")));
break;
case "check":
String time = plugin.getTimerManager().getFormattedTime();
source.sendMessage(colorize(plugin.getConfigManager().getString("messages.prefix", "") + " " +
plugin.getConfigManager().getString("messages.current-time", "<green>Remaining time: <yellow>%time%")
.replace("%time%", time)));
break;
case "sync":
plugin.getMessagingManager().broadcastTimerUpdate(plugin.getTimerManager().getRemainingSeconds());
source.sendMessage(colorize(plugin.getConfigManager().getString("messages.prefix", "") + " " +
plugin.getConfigManager().getString("messages.sync-sent", "<green>Sync request sent!")));
break;
default:
sendHelp(source);
break;
}
}
@Override
public List<String> suggest(Invocation invocation) {
String[] args = invocation.arguments();
if (args.length == 0 || args.length == 1) {
return List.of("reload", "reset", "check", "sync");
}
return List.of();
}
@Override
public boolean hasPermission(Invocation invocation) {
return invocation.source().hasPermission("proxytimer.admin");
}
private void sendHelp(SimpleCommand.Invocation invocation) {
var source = invocation.source();
source.sendMessage(colorize("<dark_gray><strikethrough>------------------------"));
source.sendMessage(colorize("<gold><bold>ProxyTimer Commands"));
source.sendMessage(colorize("<dark_gray><strikethrough>------------------------"));
source.sendMessage(colorize("<yellow>/proxytimer reload <gray>- Reload configuration"));
source.sendMessage(colorize("<yellow>/proxytimer reset <gray>- Reset timer to configured duration"));
source.sendMessage(colorize("<yellow>/proxytimer check <gray>- Check remaining time"));
source.sendMessage(colorize("<yellow>/proxytimer sync <gray>- Sync timer across servers"));
source.sendMessage(colorize("<dark_gray><strikethrough>------------------------"));
}
private Component colorize(String message) {
message = message.replace("&", "<reset>");
message = message.replace("§", "<reset>");
return miniMessage.deserialize(message);
}
}