Class CommandSenderAdapter

java.lang.Object
me.remigio07.chatplugin.api.server.util.adapter.user.CommandSenderAdapter

public class CommandSenderAdapter extends Object
Environment indipendent (Bukkit and Sponge) command sender adapter.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Represents the console.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a command sender adapter that accepts one of the following specified as input: CommandSender for Bukkit environments CommandSource for Sponge environments
  • Method Summary

    Modifier and Type
    Method
    Description
    org.bukkit.command.CommandSender
    Gets the command sender adapted for Bukkit environments.
    boolean
    Checks if another object is an instance of CommandSenderAdapter and if the sender specified by the constructor is equal to the other object's one.
    Gets this command sender's name.
    Gets this command sender's UUID.
    int
    Gets this sender's hash code.
    boolean
    hasPermission(String permission)
    Checks if this command sender has the specified permission.
    boolean
    Checks if this command sender is the console or a command block.
    boolean
    Checks if this command sender is a player and loaded.
    boolean
    Checks if this command sender is a player.
    void
    Sends a plain message to this command sender.
    org.spongepowered.api.command.CommandSource
    Gets the command sender adapted for Sponge environments.
    Gets this player's corresponding ChatPluginServerPlayer object.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • CommandSenderAdapter

      public CommandSenderAdapter(Object commandSender)
      Constructs a command sender adapter that accepts one of the following specified as input:
      • CommandSender for Bukkit environments
      • CommandSource for Sponge environments
      Parameters:
      commandSender - Command sender object
  • Method Details

    • bukkitValue

      public org.bukkit.command.CommandSender bukkitValue()
      Gets the command sender adapted for Bukkit environments.
      Returns:
      Bukkit-adapted command sender
      Throws:
      UnsupportedOperationException - If !Environment.isBukkit()
    • spongeValue

      public org.spongepowered.api.command.CommandSource spongeValue()
      Gets the command sender adapted for Sponge environments.
      Returns:
      Sponge-adapted command sender
      Throws:
      UnsupportedOperationException - If !Environment.isSponge()
    • isConsole

      public boolean isConsole()
      Checks if this command sender is the console or a command block.
      Returns:
      Whether this is the console
    • isPlayer

      public boolean isPlayer()
      Checks if this command sender is a player.
      Returns:
      !isConsole()
    • isLoaded

      public boolean isLoaded()
      Checks if this command sender is a player and loaded.
      Returns:
      toServerPlayer() != null
    • getName

      public String getName()
      Gets this command sender's name.
      Returns:
      Command sender's name
    • getUUID

      public UUID getUUID()
      Gets this command sender's UUID.

      Will return null if isConsole().

      Returns:
      Command sender's UUID
    • hasPermission

      public boolean hasPermission(String permission)
      Checks if this command sender has the specified permission.
      Parameters:
      permission - Permission to check
      Returns:
      Whether this command sender has the permission
    • sendMessage

      public void sendMessage(String message)
      Sends a plain message to this command sender.
      Parameters:
      message - Message to send
    • toServerPlayer

      public ChatPluginServerPlayer toServerPlayer()
      Gets this player's corresponding ChatPluginServerPlayer object.

      Will return null if the player is not loaded.

      Returns:
      Corresponding ChatPluginServerPlayer
    • equals

      public boolean equals(Object obj)
      Checks if another object is an instance of CommandSenderAdapter and if the sender specified by the constructor is equal to the other object's one.
      Overrides:
      equals in class Object
      Parameters:
      obj - Object to compare
      Returns:
      Whether the two objects are equal
    • hashCode

      public int hashCode()
      Gets this sender's hash code.

      Will return the hash code of the sender specified by the constructor.

      Overrides:
      hashCode in class Object
      Returns:
      Sender's hash code