Minestom/src/main/java/net/minestom/server/command/CommandSender.java

85 lines
2.3 KiB
Java
Raw Normal View History

2020-06-21 14:01:03 +02:00
package net.minestom.server.command;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.minestom.server.entity.Player;
2020-11-14 07:06:46 +01:00
import net.minestom.server.permission.PermissionHandler;
2022-03-20 01:47:57 +01:00
import net.minestom.server.tag.Taggable;
2020-10-24 16:58:27 +02:00
import org.jetbrains.annotations.NotNull;
2020-07-21 18:48:15 +02:00
/**
* Represents something which can send commands to the server.
2020-07-21 18:48:15 +02:00
* <p>
* Main implementations are {@link Player} and {@link ConsoleSender}.
2020-07-21 18:48:15 +02:00
*/
2022-03-20 01:47:57 +01:00
public interface CommandSender extends PermissionHandler, Audience, Taggable {
2020-06-21 14:01:03 +02:00
2020-07-21 18:48:15 +02:00
/**
2020-10-15 21:16:31 +02:00
* Sends a raw string message.
2020-07-21 18:48:15 +02:00
*
* @param message the message to send
*/
default void sendMessage(@NotNull String message) {
this.sendMessage(Component.text(message));
}
2020-06-21 14:01:03 +02:00
2020-07-21 18:48:15 +02:00
/**
2020-10-15 21:16:31 +02:00
* Sends multiple raw string messages.
2020-07-21 18:48:15 +02:00
*
* @param messages the messages to send
*/
2021-06-22 13:30:47 +02:00
default void sendMessage(@NotNull String @NotNull [] messages) {
2020-06-21 14:01:03 +02:00
for (String message : messages) {
sendMessage(message);
}
}
2020-07-21 18:48:15 +02:00
/**
2020-10-15 21:16:31 +02:00
* Gets if the sender is a {@link Player}.
* <p>
* Consider using {@code instanceof} instead.
2020-07-21 18:48:15 +02:00
*
* @return true if 'this' is a player, false otherwise
*/
@Deprecated
default boolean isPlayer() {
return false;
}
2020-07-21 18:48:15 +02:00
/**
2020-10-15 21:16:31 +02:00
* Gets if the sender is a {@link ConsoleSender}.
* <p>
* Consider using {@code instanceof} instead.
2020-07-21 18:48:15 +02:00
*
* @return true if 'this' is the console, false otherwise
*/
@Deprecated
default boolean isConsole() {
return false;
}
2020-07-31 22:31:58 +02:00
/**
2020-10-12 02:56:30 +02:00
* Casts this object to a {@link Player}.
* No checks are performed, {@link ClassCastException} can very much happen.
2020-10-11 18:35:32 +02:00
*
* @throws ClassCastException if 'this' is not a player
2020-07-31 22:31:58 +02:00
* @see #isPlayer()
*/
@Deprecated
2020-07-31 22:31:58 +02:00
default Player asPlayer() {
throw new ClassCastException("CommandSender is not a Player");
2020-07-31 22:31:58 +02:00
}
/**
2020-10-12 02:56:30 +02:00
* Casts this object to a {@link ConsoleSender}.
* No checks are performed, {@link ClassCastException} can very much happen.
2020-10-11 18:35:32 +02:00
*
* @throws ClassCastException if 'this' is not a console sender
2020-07-31 22:31:58 +02:00
* @see #isConsole()
*/
@Deprecated
2020-07-31 22:31:58 +02:00
default ConsoleSender asConsole() {
throw new ClassCastException("CommandSender is not the ConsoleSender");
2020-07-31 22:31:58 +02:00
}
2020-06-21 14:01:03 +02:00
}