Get next message in AutoMessage plugin

Discussion in 'Plugin Development' started by sQuetch, Jun 24, 2021.

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


    Hello everyone,
    I wanted to ask, if it is possible to use something like "getNextElement"? I'm creating an auto-messaging plugin and I would like to be able to send messages one by one, not randomly.
    This is what my current source code looks like:
        private void startBroadcastTimer(BukkitScheduler scheduler) {
            this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                    Set<String> broadcastsList = getConfig().getConfigurationSection("broadcasts").getKeys(false);
                    String broadcastId = getRandomElement(broadcastsList);
                    ConfigurationSection broadcast = getConfig().getConfigurationSection("broadcasts." + broadcastId);
                    for (String message : broadcast.getStringList("messages")) {
                        getServer().broadcastMessage(ChatColor.translateAlternateColorCodes('&', message));
            }, 0L, 300L);
        private String getRandomElement(Set<String> set) {
            int index = new Random().nextInt(set.size());
            Iterator<String> iter = set.iterator();
            for (int i = 0; i < index; i++) {
  2. Offline

    timtower Administrator Administrator Moderator

    @sQuetch Save an index for the list? If index==list size then reset to 0?
  3. Offline


Thread Status:
Not open for further replies.

Share This Page