Help with chat.

Discussion in 'Spigot Plugin Development' started by nickelectron, May 20, 2017.

Thread Status:
Not open for further replies.
  1. May sound like a noobish question but this one stumps me.
    So I have a staff chat feature in my plugin that publishs the message to redis if the player is authorized to use the staff chat and is in staff chat mode (hashset w/ players uuid.).

    Now when I use staff chat w/ the command it works fine (sending, pubing, and subbing). But the listener doesn't work and yes its registered in the main class.

    Code for command and listener.
    Code (Text):

    public class StaffChatCommand implements Listener {

        private final API plugin;

        private Set<UUID> staffChatMap = Sets.newHashSet();

        @Command(name = "staffchat", aliases = {"sc", "ac", "gsc", "lsc"}, inGameOnly = true, permission = "staff")
        public void onCommand(CommandArgs args){
            Player sender = args.getPlayer();
            if (args.length() == 0){
                if (staffChatMap.contains(sender.getUniqueId())){
                    sender.sendMessage(ChatColor.RED + "You have toggled out of staff chat mode.");
                } else {
                    sender.sendMessage(ChatColor.GREEN + "You are now in staff chat mode.");
            if (args.length() > 0){
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < args.length(); ++i){
                    sb.append(String.valueOf(args.getArgs(i)) + " ");
                final String message = sb.toString().trim();
                new StaffChat(sender.getName(), message, plugin.getServer().getServerName());

        @EventHandler(priority = EventPriority.HIGHEST)
        public void onChatSpeak(AsyncPlayerChatEvent event){
            Player player = event.getPlayer();
            String msg = event.getMessage();
            if (staffChatMap.contains(player.getUniqueId())){
                 new StaffChat(player.getName(), msg, plugin.getServer().getServerName());
    Code for constructing a staff chat message:
    Code (Text):

    public class StaffChat {

        private final API plugin = API.getPlugin();

        private String sender;
        private String message;
        private String server;

        public StaffChat(String sender, String message, String server) {
            this.sender = sender;
            this.message = message;
            this.server = server;

        private void createAndSendStaffChat() {
            JsonObject object = new JsonObject();

            JsonObject payload = new JsonObject();
            payload.addProperty("message", message);
            payload.addProperty("sender", sender);
            payload.addProperty("server", server);

            object.add("payload", payload);


            plugin.getLogger().info(plugin.getPrefix() + "Sent " + + " to the API. Payload -> " + object.toString());
    Any help would be appreciated.
  2. Did you register the correct listener in the main class?
  3. Is the event canelling?
  4. Yes

  5. Send us your main class

    Edit: use this HashSet instead Set<UUID> staffChatMap = new HashSet<UUID>();

    If this doesn't work, use debug messages to get your problem.
    #5 SteviePlaysMc4, May 20, 2017
    Last edited: May 20, 2017
  6. Code (Text):

    public class API extends JavaPlugin {

        private static API plugin;
        private final String prefix = "[API Bukkit] -> ";
        private CommandFramework commandFramework;
        private JedisConnection connection;
        private Publisher publisher;

        private JedisSubscriber subscriber;
        private Configuration configuration;

        public void onEnable() {
            plugin = this;
            commandFramework = new CommandFramework(this);

        private void registerCommands() {
            commandFramework.registerCommands(new ReportCommand(this));
            commandFramework.registerCommands(new RequestCommand(this));
            commandFramework.registerCommands(new StaffChatCommand(this));
            getServer().getPluginManager().registerEvents(new StaffChatCommand(this), this);

        private void startHeartbeatTask() {

        private void sendWelcomeMessageToAPI() {

        private void setupJedis() {

        private void sendGoodbyeMessageToAPI() {

        public void onDisable() {
            plugin = null;
  7. Try moving the this after registering the command . So it will look like this

    getServer().getPluginManager().registerEvents(new StaffChatCommand, this);
  8. Mas


    You are creating two instances of the StaffChatCommand class, then you register one as a listener and one as a command.

    Create one instance of the class and pass it to both methods instead.
    • Like Like x 1
Thread Status:
Not open for further replies.