Overall confusion

Discussion in 'Spigot Plugin Development' started by yPedx, May 27, 2018.

  1. I simply can't get this to work properly, nor can I find the issue.

    My plan was to get values from the configs on enable:
    (This is inside onEnable)
    Code (Text):
            Utilities.playerCount = Utilities.getPlayersConfig().getInt("Player-count");
       
            for(String m : Utilities.getMessagesConfig().getStringList("Join-message")) {
           
                Utilities.joinMessage.add(m);
            }
       
            for(String m : Utilities.getPlayersConfig().getStringList("Players")) {
           
                Utilities.playerList.add(m);
            }
    This is in my Utilities class:
    Code (Text):
        public static ArrayList<String> joinMessage = new ArrayList<String>();
     
        public static ArrayList<String> playerList = new ArrayList<String>();
     
        public static int playerCount;
    onDisable:
    Code (Text):
        public void onDisable() {
       
            instance.getConfig().set("Player-count", Utilities.playerCount);
       
            Utilities.getPlayersConfig().set("Players", Utilities.playerList);
        }
    Messages config:
    Code (Text):
    Clearchat-message:
      - '&8&m----&7&m»&8&m-----------+|+-----------&7&m«&8&m----'
      - ''
      - ''
      - '&8» &7Chat has been cleared by &c{sender}'
      - ''
      - ''
      - '&8&m----&7&m»&8&m-----------+|+-----------&7&m«&8&m----'
     
    Join-message:
      - '&8&m----&7&m»&8&m-----------+|+-----------&7&m«&8&m----'
      - ''
      - '&8» &7Welcome to &c&lSome&8Server&7!'
      - ''
      - '&8» &cStore: &7somestore.com'
      - '&8» &cForums: &7somewebsite.com'
      - '&8» &cDiscord: &7somediscordlink.com'
      - ''
      - ''
      - '&8&m----&7&m»&8&m-----------+|+-----------&7&m«&8&m----'
    Main config:
    Code (Text):
    Player-count: 0

    Maintenance-bypass:
      - Accountor
      - Akaria
    Join event class:
    Code (Text):
    package me.flower.core.events;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;

    import me.flower.core.utilities.Utilities;

    public class Join extends Utilities implements Listener {
     
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
       
            Player player = e.getPlayer();
       
            if(!playerList.contains(player.getName()) && !playerList.contains(player.getUniqueId().toString())) {
           
                playerList.add(player.getName()+" - "+player.getUniqueId());
           
                playerCount++;
           
                Bukkit.broadcastMessage("player saved");
            }
       
            Bukkit.broadcastMessage("continues after saving or not saving");
       
            for(String m : joinMessage) {
           
                Bukkit.broadcastMessage("inside loop");
           
                player.sendMessage(ChatColor.translateAlternateColorCodes('&', m));
            }
       
            Bukkit.broadcastMessage("everything is done");
       
            e.setJoinMessage("§8[§a+§8] §a"+player.getName());
       
            return;
        }

    }
     

    Problems
    1. The join message never appears, the only debug message I don't get is "inside the loop" which means the loop obviously isn't running..

    2. Everytime I join and then close the server, my playername and UUID is saved in the players.yml. But the problem is that it continues to do it even though I'm already registered there.

    3. The playercount never increases.

    I also tried just putting in lines on onDisable to save the configs, but that didn't change anything.
    There are no errors and the ymls are confirmed to be there.
     
  2. For issue 1, the list you have doesn't have anything in it, meaning when you add to it, it never adds.

    For issue 2, you aren't succefully grabbing the config and so when you restart the server it doesn't fill the list up again.

    For issue 3, you aren't succefully setting the config, so the player count is never saved.

    Overall the main problem is with how you manage configs. I recommend reworking everything and using debug to see what everything outputs to see if it's actually working.
     
  3. It's been a year since I've been doing this..
    I'm still confused about getting the value from the config, and then saving it to the config only when it disables. There's something missing in my head :unsure:
     
  4. https://bukkit.gamepedia.com/Configuration_API_Reference

    Head to the advanced topics section and scroll down to where they use custom configs. Hopefully that helps
     
  5. Also, I forgot to mention...
    Notice how I make it fetch the list of "Maintenance-bypass" here:
    (I just didn't include it above)
    Code (Text):
            for(String p : instance.getConfig().getStringList("Maintenance-bypass")) {
         
                Utilities.maintenancePlayers.add(p);
            }
     
            Utilities.playerCount = Utilities.getPlayersConfig().getInt("Player-count");
     
            for(String m : Utilities.getMessagesConfig().getStringList("Join-message")) {
         
                Utilities.joinMessage.add(m);
            }
     
            for(String m : Utilities.getPlayersConfig().getStringList("Players")) {
         
                Utilities.playerList.add(m);
            }
    That works completely fine, but the others doesn't. :unsure:
    Does it have something to do whether or not I'm using the main class to fetch the values?
    I feel old knowing that 1 year of inactivity can do this. :confused:

    EDIT:
    Actually nevermind, now none of them work.
    I'll be back later after trying some stuff.
     
    #5 yPedx, May 28, 2018
    Last edited: May 28, 2018