Simple Player Chat event not working

Discussion in 'Plugin Development' started by Bubby4j, Mar 9, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Bubby4j

    I'm trying to just do a simple player chat event but it doesn't seem to be working:
    Code:
    PluginManager pm = getServer().getPluginManager();
    pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Normal, this);
    That's how I'm registering it. But it doesn't seem to work. In my playerlistener java file I have this function:
    Code:
        public void onPlayerChat(PlayerChatEvent event) {
            Player player = event.getPlayer();
            System.out.println(event.getMessage());
        }
    But it never seems to be called.
     
  2. Offline

    xZise

    Where is your playerListener created?

    Fabian
     
  3. Offline

    Bubby4j

    Code:
    private final EasyPluginPlayerListener playerListener = new EasyPluginPlayerListener(this);
    Is that what you mean?
     
  4. Offline

    xZise

    Yep it seems to be created soon enough :p Could you upload your EasyPluginPlayerListener to pastebin.com?

    Fabian
     
  5. Offline

    Bubby4j

  6. Offline

    xZise

    Okay that is strange? Why is in your implementation the onPlayerCommand() method? This super method was deleted many builds ago (the latest two recommend builds don't support this).

    Also a tip: If you override a method write a “@Override” right one line above the header. The java compiler now checks if this method actually overrides a method. If not it will show you an error and mostly this will notify you, that there is “unused” code.
    Code:
    	@Override
    	public void onDisable() {
    	    this.dataConnection.free();
    	}
    Fabian
     
  7. Offline

    Bubby4j

    Thanks for the tip.

    About the function name, I thought it could be anything and I don't know what it should be, I just named it myself. Does each handler need to be specifically named? I wasn't sure how this works. Is there a list of the correct function names?
     
  8. Offline

    xZise

    No no the name has to be a specific one. You simply override the original method which would be called. For player event you can see in the PlayerListener which methods are available. So if you register PLAYER_CHAT you have to use onPlayerChat().

    Fabian
     
  9. Offline

    Bubby4j

    Ah, that makes more sense. It works great! Thanks so much!
     
  10. Offline

    Bubby4j

    Now how do I do commands?
    Code:
    name: QuestSystem
    main: Bubby4j.QuestSystem.QuestSystem
    version: 0.1
    commands:
      qnew:
        description: Create a new quest
        usage: |
               /<command> groupname questname - Creates a quest
      qmodify:
        description: Modifies a quest
        usage: |
               Incorrect usage of /<command>. Examples:
                /<command> - Modifies a quest
    That's my yml file
    Code:
        public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
            String[] split = args;
            String commandName = command.getName().toLowerCase();
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    if (commandName.equals("qnew")) {
                        if (split.length == 0) {
                            player.sendMessage(ChatColor.RED + "Testing testing 123!");
                        }
    
                    }
    
                }
                return true;
            }
    My java function. Do I need to register a function first?
     
Thread Status:
Not open for further replies.

Share This Page