Messaging System

Discussion in 'Spigot Plugin Development' started by IJMX, Jun 22, 2016.

Thread Status:
Not open for further replies.
  1. Hi guys,

    I've been working on a messaging system for a server. Everything is currently working except for the reply feature. Below I will place the code and the plugin.yml. If someone could tell me why the reply feature will not work, or give me advice, I'd appreciate it!

    Code:
    http://hastebin.com/otagaxabih.avrasm

    name: BCMsg
    main: com.ij.Main
    version: 1.0

    commands:
    bcmsg:
    usage: /message (name) (message)
    aliases: [msg, m, pm, tell, message]
    bcreply:
    usage: /bcreply (message)
    aliases: [bcr, r, reply]
    permissions:
    bc.staffmsg:
    bc.msgcolor:
     
  2. The issue here is with the reply block being nested within the message block.

    Code (Text):
    if (messaging) {
        ...
        if (replying) {
            ...
        }
    }
     
  3. How would I fix this?
     
  4. Take the replying conditional and put it outside the messaging conditional block.
     
  5. Sorry I'm new to plugin development, can you help me out with this?
     
  6. Edit: This is a java knowledge issue, not a plugin dev issue, an experienced java dev could have issues at the beginning when getting used to the API but once they read the javadocs they will be able to write working plugins.

    There are many resources available online to learn java, you will need it if you have plans on making more reliable and more complex plugins.

    Continuing on:

    Ill give an example method with a nested conditional, hopefully itll explain whats going on:

    public void testMethod(){

    if(!thisBoolean){
    //run when boolean is false
    // between the { and } is your code block
    If(thisBoolean){
    // Problem is here
    }
    }

    }

    If you look at the example above, there is no way for the boolean to run if it ever becomes true because its inside the conditional checking if the booleans false.

    This is what was meant when we say you have a nested conditional, but dont take it as a coding no no, its useful to nest conditionals to do different tasks based on the input, as long as the conditionals you write flow.

    This has been modified to have two blocks checking the state of the boolean:
    In bold and italic, im marking out the changes.

    public void testMethod(){
    if(!thisBoolean){
    //run when boolean is false
    // between the { and } is your code block
    //put the appropriate curly brace:
    } //moved
    if(thisBoolean){
    // run if true.
    }
    }
    }

    Wrote this on my phone, if i missed something be sure to yell out
     
  7. Choco

    Moderator

    • Like Like x 1
  8. better to add hashmap

    Code (Java):
    HashMap<Player, Player> whomtoreply = new HashMap<>();

    any time
    Player toreply = whomtoreply.get((Player)sender);
     
  9. http://hastebin.com/ugumevared.avrasm

    This didn't fix it, could you correct it for me?
     
  10. Never said that was the problem, ill check it out when i get home, i was more responding to the nested conditionals quesion, could be a while though.

    Ive seen some answers further up that will be useful
     
    1. answer your question by doing
    2. run bukkit server at your localhost with the plugin
    3. then check if it's working
    we are not a robot to guess if there are.
     
  11. Choco

    Moderator

    1. No need for those onEnable() and onDisable() methods. Spigot sends enable/disable messages for you. You can delete those methods all-together

    2.
    Code (Java):
    if (commandLabel.equalsIgnoreCase("bcmsg") ||
    commandLabel.equalsIgnoreCase("msg") ||
    commandLabel.equalsIgnoreCase("m") ||
    commandLabel.equalsIgnoreCase("pm") ||
    commandLabel.equalsIgnoreCase("tell") ||
    commandLabel.equalsIgnoreCase("message")) {
    This is why we have command.getName(). ._.

    3.
    Code (Java):
    if (args.length <= 1) {                  
        player.sendMessage(ChatColor.AQUA + "Usage: " + ChatColor.GOLD + "/message (player) (message) -"                          
            + ChatColor.AQUA + " Sends a player a message.");
    } else if (args.length > 1) {
    You can use else in this case rather than else if (args.length > 1).

    4. Do not watch BCBroz. It seems as though you are considering your code quality
     
    #12 Choco, Jun 22, 2016
    Last edited: Jun 22, 2016

  12. also

    plugin.yml
    Code (Java):
       message:
          description: description
          aliases: [bcmsg, msg]
     
  13. after /msg you did this

    Code (Java):
    lastRecieved.put(sender.getName(), targetplayer.getName());
    now the target player or the one who received message cannot do /reply <message>
     
  14. The reply system still doesn't work
     
  15. error or the stacktrace ?

    suggesting you after doing message command
    Code (Java):
    hashmap.put(target, ((Player)sender);
     
  16. The reply block is still nested within the message block as far as I can tell. It is inside line 44 specifically.

    In other words, the reply portion of your plugin is unreachable.
     
  17. Could someone just fix the code for me? This is frustrating
     
  18. It doesn't show an error, it just does nothing
     
  19. btw:

    Code (Text):

    public final Logger logger = Logger.getLogger("Minecraft");
     
    not needed.
     
Thread Status:
Not open for further replies.