FANDOM


Die Spectate Funktion ermöglicht es einem Spieler einem anderen zu zusehen.

Funktionen:

Funktion Returntype
.spectate(Player player, SpectateMode mode) void
.spectate(Vehicle veh, SpectateMode mode) void


Beispiel:

public void onPlayerCommand(final PlayerCommandEvent event) {
    String command = event.getCommand();
    String[] splits = command.split(" ", 2);
    String operation = splits[0].toLowerCase();
    Queue<String> args = new LinkedList<>();
    if (splits.length > 1) {
        String[] argsArray = splits[1].split(" ");
        args.addAll(Arrays.asList(argsArray));
    }
    if(operation.equals("/spectate")) {
        if(args.size() < 1) {
            event.getPlayer().sendMessage(Color.RED, "Benutzung: /spectate [ID]");
        }
        else {
            Player playerToSpec = getShoebill().getSampObjectStore().getPlayer(Integer.parseInt(args.poll()));
            if(playerToSpec.isInAnyVehicle()) {
                event.getPlayer().spectate(playerToSpec.getVehicle(), SpectateMode.NORMAL);
            } else {
                event.getPlayer().spectate(playerToSpec, SpectateMode.NORMAL);
            }
        }
        event.setProcessed();
    }
}