Clean up some Bukkit code
This commit is contained in:
parent
62abfa5e95
commit
a8d3fa7c5e
7 changed files with 82 additions and 6 deletions
|
|
@ -29,6 +29,10 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Command sender that proxies {@link org.bukkit.command.CommandSender}
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public abstract class BukkitCommandSender implements CommandSender {
|
||||
|
||||
private final org.bukkit.command.CommandSender internalSender;
|
||||
|
|
@ -37,16 +41,33 @@ public abstract class BukkitCommandSender implements CommandSender {
|
|||
this.internalSender = internalSender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@link BukkitCommandSender} for a {@link Player}
|
||||
*
|
||||
* @param player Player instance
|
||||
* @return Constructed command sender
|
||||
*/
|
||||
@Nonnull
|
||||
public static BukkitCommandSender player(@Nonnull final Player player) {
|
||||
return new BukkitPlayerSender(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@link BukkitCommandSender} for the Bukkit console
|
||||
*
|
||||
* @return Constructed command sender
|
||||
*/
|
||||
@Nonnull
|
||||
public static BukkitCommandSender console() {
|
||||
return new BukkitConsoleSender();
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@link BukkitCommandSender} from a Bukkit {@link CommandSender}
|
||||
*
|
||||
* @param sender Bukkit command sender
|
||||
* @return Constructed command sender
|
||||
*/
|
||||
@Nonnull
|
||||
public static BukkitCommandSender of(@Nonnull final org.bukkit.command.CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
|
|
@ -72,13 +93,29 @@ public abstract class BukkitCommandSender implements CommandSender {
|
|||
return Objects.hashCode(internalSender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the proxied {@link org.bukkit.command.CommandSender}
|
||||
*
|
||||
* @return Proxied command sneder
|
||||
*/
|
||||
@Nonnull
|
||||
public org.bukkit.command.CommandSender getInternalSender() {
|
||||
return this.internalSender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this sender represents a player
|
||||
*
|
||||
* @return {@code true} if this sender represents a player, {@code false} if not
|
||||
*/
|
||||
public abstract boolean isPlayer();
|
||||
|
||||
/**
|
||||
* Get this sender as a player. This can only safely be done if {@link #isPlayer()}}
|
||||
* returns {@code true}
|
||||
*
|
||||
* @return Player object
|
||||
*/
|
||||
@Nonnull
|
||||
public abstract Player asPlayer();
|
||||
|
||||
|
|
@ -86,4 +123,14 @@ public abstract class BukkitCommandSender implements CommandSender {
|
|||
public boolean hasPermission(@Nonnull final String permission) {
|
||||
return this.internalSender.hasPermission(permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the command sender
|
||||
*
|
||||
* @param message Message to send
|
||||
*/
|
||||
public void sendMessage(@Nonnull final String message) {
|
||||
this.internalSender.sendMessage(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue