Added Queue implementation

Fixes #23
master
Etzelia 2018-12-08 16:34:57 -06:00
parent 364a2a2bb1
commit b10ea6fdae
4 changed files with 32 additions and 3 deletions

View File

@ -8,8 +8,10 @@ QoL v1.6
Additions
---------
* `Grief Alert`_ - Monitors for actions (starting a fire, dumping lava, or placing TnT) and alerts when encountered
* `Queue Implementation`_ - Allows the server to run a set of commands on login for player wit specific permissions
.. _Grief Alert: https://git.etztech.xyz/Etzelia/QoL/issues/22
.. _Queue Implementation: https://git.etztech.xyz/Etzelia/QoL/issues/23
Bug Fixes
---------

View File

@ -280,7 +280,7 @@ public class QoL extends JavaPlugin {
}
private void runTask(final String command) {
public void runTask(final String command) {
Bukkit.getScheduler().runTask(QoL.instance, () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command));
}

View File

@ -2,6 +2,7 @@ package xyz.etztech.qol.listeners;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@ -9,6 +10,11 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import xyz.etztech.qol.QoL;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class JoinListener implements Listener {
private QoL plugin;
@ -32,9 +38,22 @@ public class JoinListener implements Listener {
}
}
}, 30); // ~1.5 seconds
}
// Queue commands
List<?> queues = plugin.getConfig().getList("queue");
for (int i = 0; i < queues.size(); i++) {
try {
LinkedHashMap queue = (LinkedHashMap) queues.get(i);
String permission = (String) queue.get("permission");
if (player.hasPermission(permission)) {
for (String command : (List<String>) queue.get("commands")) {
plugin.runTask(command.replace("<player>", player.getName()));
}
}
} catch (Exception ignored) {}
}
}
}

View File

@ -24,6 +24,14 @@ list:
plugins:
# - QoL
# A list of permissions to check, followed by a list of commands to run on login if a player has the specified permission
# Special variables are <player> for the player logging in
queue:
# - permission: qol.perm
# commands:
# - msg <player> Command 1
# - msg <player> Command 2
# A list of commands to send to Discord if anyone uses them
audit:
enabled: true