Solved Plugin repeats command back in chat

Discussion in 'Plugin Development' started by WickedFaction, Feb 17, 2016.

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

    WickedFaction

  2. Offline

    timtower Administrator Administrator Moderator

    @WickedFaction 1. Don't blindly cast to player.
    2. Is your code even running?
     
  3. Offline

    WickedFaction

    I don't know what blindly cast to player means and it was yesterday. Then I went to bed because it started saying /wild in chat after I did something.
     
  4. Offline

    timtower Administrator Administrator Moderator

    @WickedFaction Casting something without checking if it even is that class.
    Please post your plugin.yml
     
  5. Offline

    WickedFaction

    http://pastebin.com/1xgVXrU2

    @timtower Also, doesn't this line eliminate the blindly casting of the player?

    if ((cmd.getName().equalsIgnoreCase("wild") && sender instanceof Player));

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 17, 2016
  6. Offline

    tobiyas

    Bad:
    Code:
    Player player = (Player) sender;
    ... Do your stuff ...
    
    Good:
    Code:
    if(sender instanceof Player){
      Player player = (Player) sender;
      .... Do your stuff ...
    }
    
     
  7. Offline

    WickedFaction

    so this would not do that? if ((cmd.getName().equalsIgnoreCase("wild") && sender instanceof Player)); {
     
  8. Offline

    timtower Administrator Administrator Moderator

    @WickedFaction
    Code:
    final Player player = (Player) sender;
           
            if ((cmd.getName().equalsIgnoreCase("wild") && sender instanceof Player)); {
    Check the order though.
    And the ; after the if would make the code in the block always run.
     
  9. Offline

    WickedFaction

    I'll just rewrite the code later today when I get home, unless there is a quick fix. It's just too confusing right now and I have no time.
     
  10. Offline

    DoggyCode™

    It's simple. Lmao.

    In your plugin yml:
    Code:
    usage: /<command>
    This means that whenever your code returns false, it will tell the player "/<command>". Make sure to remove the usage and make a custom one instead, and/or just return true on everything.

    @timtower
    @WickedFaction
    @tobiyas
     
  11. Offline

    WickedFaction

    I'll try this when I get home, makes sense. Good thing I didn't try anything they said earlier because it was working perfectly fine before I left.
     
  12. Offline

    Xerox262

    @DoggyCode™ You didn't read what he posted, he has it always returning true.

    @WickedFaction are you saying it was teleporting you and stuff? Because if it was then it shouldn't have been sending the message in chat, you have it set to always return true, it didn't register the on command as the plugin's command handler for that command and it's triggering the default, or there should be an error somewhere.

    You do need to fix the problems listed before, even if it doesn't seem like it is changing your plugin, for example, the way you have it now, would be, any time any command is triggered from your plugin, the plugin will assume it's a player, then try to teleport them, even if it's not the teleport command, then it will end the method and you will not know why you can't create any new commands, and why you keep getting "dead code" warnings
     
  13. Offline

    WickedFaction

    Thank you
     
Thread Status:
Not open for further replies.

Share This Page