From 8997133923ca528d2d96b54b9f7c3aac551b8520 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Tue, 23 Oct 2018 16:24:06 -0500 Subject: [PATCH 1/3] Added logic in CommandPreprocessListener to check if a guest has run the /rules command before doing /apply. --- .../listeners/CommandPreprocessListener.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/etztech/minecraftmanager/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/minecraftmanager/listeners/CommandPreprocessListener.java index fe148b9..df40975 100644 --- a/src/main/java/xyz/etztech/minecraftmanager/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/minecraftmanager/listeners/CommandPreprocessListener.java @@ -1,6 +1,7 @@ package xyz.etztech.minecraftmanager.listeners; import org.apache.commons.lang.StringUtils; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -14,7 +15,7 @@ import xyz.etztech.minecraftmanager.MCMUtil; import xyz.etztech.minecraftmanager.MinecraftManager; import java.util.Arrays; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -22,6 +23,8 @@ public class CommandPreprocessListener implements Listener { MinecraftManager plugin; + private ArrayList hasReadRules = new ArrayList<>(); + public CommandPreprocessListener(MinecraftManager plugin) { this.plugin = plugin; @@ -71,6 +74,16 @@ public class CommandPreprocessListener implements Listener { } } } + else if (sender.hasPermission("minecraftmanager.guest")) { + if ("rules".equalsIgnoreCase(base)) { + hasReadRules.add(sender.getUniqueId().toString()); + } + else if ("apply".equalsIgnoreCase(base)) { + if(!hasReadRules.remove(sender.getUniqueId().toString())) { + sender.spigot().sendMessage(new TextComponent(ChatColor.RED + "Make sure to check /rules before applying!")); + } + } + } } From efb8545e56018b528f534d8c46fe9b20a22315c9 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Tue, 23 Oct 2018 17:35:06 -0500 Subject: [PATCH 2/3] Made changes according to the comments in PR #9 /apply is now cancelled if the user didn't read the rules User is now not removed from the hasReadRules list until restart --- .../minecraftmanager/listeners/CommandPreprocessListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/etztech/minecraftmanager/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/minecraftmanager/listeners/CommandPreprocessListener.java index df40975..736d6bc 100644 --- a/src/main/java/xyz/etztech/minecraftmanager/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/minecraftmanager/listeners/CommandPreprocessListener.java @@ -79,7 +79,8 @@ public class CommandPreprocessListener implements Listener { hasReadRules.add(sender.getUniqueId().toString()); } else if ("apply".equalsIgnoreCase(base)) { - if(!hasReadRules.remove(sender.getUniqueId().toString())) { + if(!hasReadRules.contains(sender.getUniqueId().toString())) { + event.setCancelled(true); sender.spigot().sendMessage(new TextComponent(ChatColor.RED + "Make sure to check /rules before applying!")); } } From bb3f409be58adda5a4df95be6993b2ef30e1c3d0 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Wed, 24 Oct 2018 08:55:24 -0500 Subject: [PATCH 3/3] Changed the hasReadRules list to be a set to avoid duplicate entries. --- .../minecraftmanager/listeners/CommandPreprocessListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/xyz/etztech/minecraftmanager/listeners/CommandPreprocessListener.java b/src/main/java/xyz/etztech/minecraftmanager/listeners/CommandPreprocessListener.java index 736d6bc..e74a388 100644 --- a/src/main/java/xyz/etztech/minecraftmanager/listeners/CommandPreprocessListener.java +++ b/src/main/java/xyz/etztech/minecraftmanager/listeners/CommandPreprocessListener.java @@ -15,7 +15,7 @@ import xyz.etztech.minecraftmanager.MCMUtil; import xyz.etztech.minecraftmanager.MinecraftManager; import java.util.Arrays; -import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -23,7 +23,7 @@ public class CommandPreprocessListener implements Listener { MinecraftManager plugin; - private ArrayList hasReadRules = new ArrayList<>(); + private LinkedHashSet hasReadRules = new LinkedHashSet<>(); public CommandPreprocessListener(MinecraftManager plugin) {