From b10ea6fdaeb9653a9767241331efc4ae4487cd78 Mon Sep 17 00:00:00 2001 From: Etzelia Date: Sat, 8 Dec 2018 16:34:57 -0600 Subject: [PATCH] Added Queue implementation Fixes #23 --- docs/source/changelog/v1.6.rst | 2 ++ src/main/java/xyz/etztech/qol/QoL.java | 2 +- .../etztech/qol/listeners/JoinListener.java | 23 +++++++++++++++++-- src/main/resources/config.yml | 8 +++++++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/docs/source/changelog/v1.6.rst b/docs/source/changelog/v1.6.rst index b4c06dc..f9e97d4 100644 --- a/docs/source/changelog/v1.6.rst +++ b/docs/source/changelog/v1.6.rst @@ -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 --------- diff --git a/src/main/java/xyz/etztech/qol/QoL.java b/src/main/java/xyz/etztech/qol/QoL.java index 0cfe70a..0782f35 100644 --- a/src/main/java/xyz/etztech/qol/QoL.java +++ b/src/main/java/xyz/etztech/qol/QoL.java @@ -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)); } diff --git a/src/main/java/xyz/etztech/qol/listeners/JoinListener.java b/src/main/java/xyz/etztech/qol/listeners/JoinListener.java index 247cd76..5ce5e4c 100644 --- a/src/main/java/xyz/etztech/qol/listeners/JoinListener.java +++ b/src/main/java/xyz/etztech/qol/listeners/JoinListener.java @@ -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) queue.get("commands")) { + plugin.runTask(command.replace("", player.getName())); + } + } + } catch (Exception ignored) {} + } + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f359ff6..d60c700 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -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 for the player logging in +queue: +# - permission: qol.perm +# commands: +# - msg Command 1 +# - msg Command 2 + # A list of commands to send to Discord if anyone uses them audit: enabled: true