Solved Stacktrace setting PlayerQuitEvent

Discussion in 'Plugin Development' started by boomboompower, Jan 13, 2016.

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

    boomboompower

    Problem: Every time I leave the game, I get a stacktrace because of hub plugin, have worked with a couple other devs to try and solve cannot solve the problem, the methods are the same as the "getJoinMessage" and "setJoinMessage" which work fine without errors.

    What you can do to recreate the problem:
    Just leave the server.

    Possible problematic line(s):

    Settings Line 120:
    Code:
    public String getQuitMessage(Player player) {
            String quitMessage = "";
            for (String key : plugin.getConfig().getConfigurationSection("quit-messages").getKeys(false)) {
                if (!player.hasPermission("hub.quitmessages." + key)) {
                    continue;
                }
                quitMessage = plugin.getConfig().getString("quit-messages." + key);
            }
            return quitMessage == null ? "" : ChatColor.translateAlternateColorCodes('&', quitMessage);
        }
    
    
    StreamListener Line 80:
    Code:
    @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
        public void setQuitMessage(PlayerQuitEvent event) {
            Player p = event.getPlayer();
            if (plugin.getSettings().getQuitMessage(p).isEmpty()) {
                event.setQuitMessage(null);
            } else {
                event.setQuitMessage(plugin.getSettings().getQuitMessage(p).replace("{PLAYER}", p.getName()));
            }
        }
    
    plugin.yml: here
    config.yml: here

    Error message (If any): http://pastebin.com/2UpFWy8n

    What you have tried:

    A lot of trial and error with other devs, nothing has currently worked, any help with this would be greatly appreciated. Thanks -boom
     
    Last edited: Jan 13, 2016
  2. Offline

    Zombie_Striker

    Caused by: java.lang.NullPointerException
    at org.originmc.hub.Settings.getQuitMessage(Settings.java:120) ~[?:?]

    • Did you test if plugin is null?
    • Did you test if the config section exists?
    • does the quit message return null?
    BTW, which line exactly is line 120?
     
  3. Offline

    Creeperzombi3

    [QUOTE="boomboompower, post: 3311869, member: 91004418](String key : plugin.getConfig().getConfigurationSection("quit-messages").getKeys(false))[/QUOTE]
    You have it as #getKeys(false)... then you name the string key... I'm confused :'(
     
    Zombie_Striker likes this.
  4. Offline

    boomboompower

    @Zombie_Striker @Creeperzombi3
    I know its false, its so the person/owner using the config can add multiple ranks/join messages.

    Line 120: for (String key : plugin.getConfig().getConfigurationSection("quit-messages").getKeys(false)) {

    Example, if in config there was two ranks like this
    Code:
    quit-message:
      default: '&c[-] &3{PLAYER} has left the game.'
      staff: '&c[-]' &3{PLAYER} (Staff) has left the game'
    and the user wanted to add a owner rank, it could easily be done by adding another line
    Code:
    quit-message:
      default: '&c[-] &3{PLAYER} has left the game.'
      staff: '&c[-]' &3{PLAYER} (Staff) has left the game'
      owner: '&c[-]' &4&lOWNER &c&l{PLAYER} has left the game'
     
    Last edited: Jan 13, 2016
  5. Offline

    Xerox262

    @boomboompower
    Code:
    getConfigurationSection("quit-messages")
    Code:
    quit-message:
      default: '&c[+] &3{PLAYER} has left the game.'
      admin: '&c[+] &c{PLAYER} - Admin - has left the game.'
      op: '&c[+] &4&l{PLAYER} &4- OP - has left the game.'
    You added an s in your code, you need to change either the config.yml to contain "quit-messages" or change the code to quit-message.
     
    boomboompower likes this.
  6. Offline

    boomboompower

    @Xerox262
    Thanks, will test now.

    **UPDATE**

    Yep Solved, thanks :D
     
    Last edited: Jan 13, 2016
Thread Status:
Not open for further replies.

Share This Page