2020-06-21 14:01:03 +02:00
|
|
|
package net.minestom.server.command;
|
|
|
|
|
2021-03-01 16:25:23 +01:00
|
|
|
import net.kyori.adventure.audience.Audience;
|
|
|
|
import net.kyori.adventure.text.Component;
|
2020-06-22 00:48:12 +02:00
|
|
|
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-06-22 00:48:12 +02:00
|
|
|
|
2020-07-21 18:48:15 +02:00
|
|
|
/**
|
2020-10-17 13:24:18 +02:00
|
|
|
* Represents something which can send commands to the server.
|
2020-07-21 18:48:15 +02:00
|
|
|
* <p>
|
2020-10-17 13:24:18 +02:00
|
|
|
* 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
|
|
|
|
*/
|
2021-04-04 15:05:02 +02:00
|
|
|
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}.
|
2021-11-23 20:38:57 +01:00
|
|
|
* <p>
|
|
|
|
* Consider using {@code instanceof} instead.
|
2020-07-21 18:48:15 +02:00
|
|
|
*
|
|
|
|
* @return true if 'this' is a player, false otherwise
|
|
|
|
*/
|
2021-11-23 20:38:57 +01:00
|
|
|
@Deprecated
|
2020-06-22 00:48:12 +02:00
|
|
|
default boolean isPlayer() {
|
2021-04-04 15:10:06 +02:00
|
|
|
return false;
|
2020-06-22 00:48:12 +02:00
|
|
|
}
|
|
|
|
|
2020-07-21 18:48:15 +02:00
|
|
|
/**
|
2020-10-15 21:16:31 +02:00
|
|
|
* Gets if the sender is a {@link ConsoleSender}.
|
2021-11-23 20:38:57 +01:00
|
|
|
* <p>
|
|
|
|
* Consider using {@code instanceof} instead.
|
2020-07-21 18:48:15 +02:00
|
|
|
*
|
|
|
|
* @return true if 'this' is the console, false otherwise
|
|
|
|
*/
|
2021-11-23 20:38:57 +01:00
|
|
|
@Deprecated
|
2020-06-22 00:48:12 +02:00
|
|
|
default boolean isConsole() {
|
2021-04-04 15:10:06 +02:00
|
|
|
return false;
|
2020-06-22 00:48:12 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
*
|
2020-11-14 09:02:29 +01:00
|
|
|
* @throws ClassCastException if 'this' is not a player
|
2020-07-31 22:31:58 +02:00
|
|
|
* @see #isPlayer()
|
|
|
|
*/
|
2021-11-23 20:38:57 +01:00
|
|
|
@Deprecated
|
2020-07-31 22:31:58 +02:00
|
|
|
default Player asPlayer() {
|
2021-04-04 15:10:06 +02:00
|
|
|
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
|
|
|
*
|
2020-11-14 09:02:29 +01:00
|
|
|
* @throws ClassCastException if 'this' is not a console sender
|
2020-07-31 22:31:58 +02:00
|
|
|
* @see #isConsole()
|
|
|
|
*/
|
2021-11-23 20:38:57 +01:00
|
|
|
@Deprecated
|
2020-07-31 22:31:58 +02:00
|
|
|
default ConsoleSender asConsole() {
|
2021-04-04 15:10:06 +02:00
|
|
|
throw new ClassCastException("CommandSender is not the ConsoleSender");
|
2020-07-31 22:31:58 +02:00
|
|
|
}
|
2020-06-21 14:01:03 +02:00
|
|
|
}
|