1
0
Files
aetheria-anarchy-plugin/src/main/java/cc/fascinated/commandspy/CommandSpyManager.java
2024-04-03 15:11:36 +01:00

73 lines
2.3 KiB
Java

package cc.fascinated.commandspy;
import cc.fascinated.account.Account;
import cc.fascinated.command.CommandManager;
import cc.fascinated.commandspy.command.CommandSpyCommand;
import cc.fascinated.config.Lang;
import cc.fascinated.utils.Manager;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.ArrayList;
import java.util.List;
public class CommandSpyManager extends Manager {
/**
* The list of accounts that have command spy enabled.
*/
private static final List<Account> COMMAND_SPY_ENABLED = new ArrayList<>();
public CommandSpyManager() {
CommandManager.registerCommand(new CommandSpyCommand());
}
/**
* Toggles command spy for the specified account.
*
* @param account the account
* @return true if command spy is enabled, false otherwise
*/
public static boolean toggleCommandSpy(Account account) {
if (COMMAND_SPY_ENABLED.contains(account)) { // Disable command spy
COMMAND_SPY_ENABLED.remove(account);
return false;
}
COMMAND_SPY_ENABLED.add(account); // Enable command spy
return true;
}
@Override
public void onCommandPreProcess(Account account, PlayerCommandPreprocessEvent event) {
for (Account commandSpyAccount : COMMAND_SPY_ENABLED) {
commandSpyAccount.sendMessage(Lang.COMMAND_SPY_FORMAT.getAsString()
.replace("player-color", account.getPlayerColorProfile().getColor().toString())
.replace("%player%", account.getName())
.replace("%command%", event.getMessage())
);
}
}
@Override
public void onPlayerJoin(Account account, PlayerJoinEvent event) {
if (!account.isOp()) {
return;
}
COMMAND_SPY_ENABLED.add(account); // Add account to command spy list
}
@Override
public void onPlayerQuit(Account account, PlayerQuitEvent event) {
if (!COMMAND_SPY_ENABLED.contains(account)) {
return;
}
COMMAND_SPY_ENABLED.remove(account); // Remove account from command spy list
}
@Override
public void onAetheriaDisable() {
COMMAND_SPY_ENABLED.clear(); // Clear command spy list
}
}