How can I use a int List from the Config?!

Discussion in 'Plugin Development' started by Mr.Nice1107, Oct 22, 2018.

Thread Status:
Not open for further replies.
  1. Hey guys,
    I create a countdown command and a I create a config.yml.

    example: /countdown 5 10 the server reload...
    10 sec. later...
    Remaining time until: the server reload...: 5
    Remaining time until: the server reload...: 4
    Remaining time until: the server reload...: 3
    Remaining time until: the server reload...: 2
    Remaining time until: the server reload...: 1
    The Countdown has ended!



    ok until here everything works fine,
    but now I down't want the countdown to Broadcast every sec.
    he shold ownly count specific numbers like for example: 120,60,30,20,10,5,4,3,2,1 and not fill up the whole chat.
    These numbers should be set in the config.yml like this:

    How I do this!?
    and I have another question:
    If I'm finish with this problem I want to do the command this
    example: /countdown 5 10 the server reload... /reload
    is this posible that a command can callup a other command!?

    Thank you in advance for reply
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Mr.Nice1107 Make a list for those numbers.
    See if s is in that list.
     
  3. How can I make this List?
    And how can I put the numbers from the Config into this list
     
  4. Offline

    timtower Administrator Administrator Moderator

    Depends on how you input the specific numbers, is that in the arguments or via the config?
     
  5. Config
     
  6. Offline

    timtower Administrator Administrator Moderator

  7. Offline

    timtower Administrator Administrator Moderator

  8. okay and how can I use this list now in my command? sry I'm relativly new in java/bukkit...
     
  9. Offline

    timtower Administrator Administrator Moderator

    @Mr.Nice1107
     
  10. I tried this:
    List<Integer> countdownlist = plugin.getConfig().getIntegerList("Config.messages.countdown");
    Bukkit.broadcastMessage("Countdownlist:" + countdownlist.get(2));

    --
    Config
    --
    Code:
    Config:
      messages:
        countdown: 120,60,30,15,10,5,4,3,2,1
    
    and when I tried the command there comes this:

    [14:56:48] [Server thread/WARN]: Unexpected exception while parsing console command "countdown"
    org.bukkit.command.CommandException: Unhandled exception executing command 'countdown' in plugin TimedEvents v1.0
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_191]
    Caused by: java.lang.NullPointerException
    at de.timedevents.legendzero.commands.CountdownCommand.onCommand(CountdownCommand.java:54) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    ... 8 more
    [14:59:40] [Server thread/INFO]: Stopping the server
     
  11. Offline

    timtower Administrator Administrator Moderator

    @Mr.Nice1107 Because that is not a valid YML list.
    Code:
    Config:
      messages:
        countdown:
        - 120
        - 60
        - 30
        - 15
        - 10
        - 5
    This is a valid list.
    Config block is redundant btw.
     
  12. Still the same Error :'( xD
     
  13. Offline

    timtower Administrator Administrator Moderator

  14. Offline

    timtower Administrator Administrator Moderator

    @Mr.Nice1107 Can you post a screenshot of the config as it is in the plugins folder?
     
  15. /testserver/plugins/TimedEvents/condig.yml
    /testserver/plugins/timedevents.jar

    View attachment 31919
     
    Last edited by a moderator: Oct 22, 2018
  16. Offline

    timtower Administrator Administrator Moderator

    @Mr.Nice1107 plugin is null, it even has a warning to notify you about it.
     
  17. ok and what can I do about it?
     
  18. Offline

    timtower Administrator Administrator Moderator

    You assign it using a constructor.
     
  19. Code:
    public class TimedEvents extends JavaPlugin
    {
        private static TimedEvents plugin;
    
        public void onEnable()
        {
            plugin = this;
            loadConfig();
    
            getCommand( "countdown").setExecutor(new CountdownCommand());
            getCommand( "qcountdown").setExecutor(new QCountdownCommand());
            //getCommand( "delay").setExecutor(new DelayCommand());
    
            this.printPlugin("§aEnabled");
        }
    
        public void onDisable()
        {
    
    
            this.printPlugin("§cDisabled");
        }
        private void printPlugin(String m)
        {
            String pcolor = getConfig().getString("Config.messages.plugincolor");
            final String pluginName = "§7[§" + pcolor /*getConfig().getString("Config.messages.plugincolor")*/ + "TimedEvents§7]: ";
            Bukkit.getConsoleSender().sendMessage(pluginName + m);
        }
        public static TimedEvents getPlugin()
        {
            return plugin;
        }
    
        public void loadConfig()
        {
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
    
    }
    Code:
        public QCountdownCommand(TimedEvents main)
        {
            this.plugin = main;
        }
    Like this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 22, 2018
  20. Offline

    timtower Administrator Administrator Moderator

  21. ok now it works Thank you!!
     
    timtower likes this.
  22. Offline

    KarimAKL

    Remember to change the title prefix to 'Solved'.
     
Thread Status:
Not open for further replies.

Share This Page