mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-28 14:37:31 +02:00
24cc458659
* Implement some Adventure methods into ConsoleSender * Remove getUuid from CommandSender/ConsoleSender * rebase and review fixes Co-authored-by: mworzala <mattheworzala@gmail.com>
86 lines
2.3 KiB
Java
86 lines
2.3 KiB
Java
package net.minestom.server.command;
|
|
|
|
import net.kyori.adventure.audience.Audience;
|
|
import net.kyori.adventure.identity.Identified;
|
|
import net.kyori.adventure.text.Component;
|
|
import net.minestom.server.entity.Player;
|
|
import net.minestom.server.permission.PermissionHandler;
|
|
import net.minestom.server.tag.Taggable;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
/**
|
|
* Represents something which can send commands to the server.
|
|
* <p>
|
|
* Main implementations are {@link Player} and {@link ConsoleSender}.
|
|
*/
|
|
public interface CommandSender extends PermissionHandler, Audience, Taggable, Identified {
|
|
|
|
/**
|
|
* Sends a raw string message.
|
|
*
|
|
* @param message the message to send
|
|
*/
|
|
default void sendMessage(@NotNull String message) {
|
|
this.sendMessage(Component.text(message));
|
|
}
|
|
|
|
/**
|
|
* Sends multiple raw string messages.
|
|
*
|
|
* @param messages the messages to send
|
|
*/
|
|
default void sendMessage(@NotNull String @NotNull [] messages) {
|
|
for (String message : messages) {
|
|
sendMessage(message);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Gets if the sender is a {@link Player}.
|
|
* <p>
|
|
* Consider using {@code instanceof} instead.
|
|
*
|
|
* @return true if 'this' is a player, false otherwise
|
|
*/
|
|
@Deprecated
|
|
default boolean isPlayer() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Gets if the sender is a {@link ConsoleSender}.
|
|
* <p>
|
|
* Consider using {@code instanceof} instead.
|
|
*
|
|
* @return true if 'this' is the console, false otherwise
|
|
*/
|
|
@Deprecated
|
|
default boolean isConsole() {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Casts this object to a {@link Player}.
|
|
* No checks are performed, {@link ClassCastException} can very much happen.
|
|
*
|
|
* @throws ClassCastException if 'this' is not a player
|
|
* @see #isPlayer()
|
|
*/
|
|
@Deprecated
|
|
default Player asPlayer() {
|
|
throw new ClassCastException("CommandSender is not a Player");
|
|
}
|
|
|
|
/**
|
|
* Casts this object to a {@link ConsoleSender}.
|
|
* No checks are performed, {@link ClassCastException} can very much happen.
|
|
*
|
|
* @throws ClassCastException if 'this' is not a console sender
|
|
* @see #isConsole()
|
|
*/
|
|
@Deprecated
|
|
default ConsoleSender asConsole() {
|
|
throw new ClassCastException("CommandSender is not the ConsoleSender");
|
|
}
|
|
}
|