mirror of
https://github.com/array-in-a-matrix/brainwine.git
synced 2025-04-02 11:11:58 -04:00
Added a broadcast command
This commit is contained in:
parent
29ace472aa
commit
0c2de4136d
3 changed files with 47 additions and 0 deletions
|
@ -6,6 +6,13 @@ import java.util.Map;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import brainwine.gameserver.command.commands.BroadcastCommand;
|
||||
import brainwine.gameserver.command.commands.KickCommand;
|
||||
import brainwine.gameserver.command.commands.RegisterCommand;
|
||||
import brainwine.gameserver.command.commands.SayCommand;
|
||||
import brainwine.gameserver.command.commands.StopCommand;
|
||||
import brainwine.gameserver.command.commands.TeleportCommand;
|
||||
import brainwine.gameserver.command.commands.ThinkCommand;
|
||||
import brainwine.gameserver.entity.player.Player;
|
||||
|
||||
public class CommandManager {
|
||||
|
@ -25,12 +32,14 @@ public class CommandManager {
|
|||
}
|
||||
|
||||
private static void registerCommands() {
|
||||
logger.info("Registering commands ...");
|
||||
registerCommand("stop", new StopCommand());
|
||||
registerCommand("register", new RegisterCommand());
|
||||
registerCommand("tp", new TeleportCommand());
|
||||
registerCommand("kick", new KickCommand());
|
||||
registerCommand("say", new SayCommand());
|
||||
registerCommand("think", new ThinkCommand());
|
||||
registerCommand("bc", new BroadcastCommand());
|
||||
}
|
||||
|
||||
public static void executeCommand(CommandExecutor executor, String commandLine) {
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package brainwine.gameserver.command.commands;
|
||||
|
||||
import brainwine.gameserver.GameServer;
|
||||
import brainwine.gameserver.command.Command;
|
||||
import brainwine.gameserver.command.CommandExecutor;
|
||||
import brainwine.gameserver.entity.player.Player;
|
||||
|
||||
public class BroadcastCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void execute(CommandExecutor executor, String[] args) {
|
||||
if(args.length == 0) {
|
||||
executor.alert("Usage: /broadcast <message>");
|
||||
return;
|
||||
}
|
||||
|
||||
String text = String.join(" ", args);
|
||||
|
||||
// TODO hook the console up to some kind of chat feed?
|
||||
if(executor instanceof GameServer) {
|
||||
executor.alert(text);
|
||||
}
|
||||
|
||||
for(Player player : GameServer.getInstance().getPlayerManager().getPlayers()) {
|
||||
player.notify(text, 9);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresAdmin() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package brainwine.gameserver.entity.player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
@ -153,4 +154,8 @@ public class PlayerManager {
|
|||
public Player getPlayer(Connection connection) {
|
||||
return playersByConnection.get(connection);
|
||||
}
|
||||
|
||||
public Collection<Player> getPlayers() {
|
||||
return playersById.values();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue