From 80e45aa1a97dee65b272f3e1650b170af11eb3d7 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 24 Apr 2019 23:57:52 +0200 Subject: [PATCH] Added snap command --- .idea/ButtonChat.iml | 28 ------------------- .../java/buttondevteam/chat/PluginMain.java | 2 ++ .../chat/commands/SnapCommand.java | 27 ++++++++++++++++++ 3 files changed, 29 insertions(+), 28 deletions(-) create mode 100644 src/main/java/buttondevteam/chat/commands/SnapCommand.java diff --git a/.idea/ButtonChat.iml b/.idea/ButtonChat.iml index 73ae0d4..3d32cdf 100644 --- a/.idea/ButtonChat.iml +++ b/.idea/ButtonChat.iml @@ -39,33 +39,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index ad7efb5..ba05c44 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -1,6 +1,7 @@ package buttondevteam.chat; import buttondevteam.chat.commands.MWikiCommand; +import buttondevteam.chat.commands.SnapCommand; import buttondevteam.chat.commands.ucmds.HelpCommand; import buttondevteam.chat.commands.ucmds.HistoryCommand; import buttondevteam.chat.commands.ucmds.InfoCommand; @@ -77,6 +78,7 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15 getCommand2MC().registerCommand(new HistoryCommand()); getCommand2MC().registerCommand(new InfoCommand()); getCommand2MC().registerCommand(new MWikiCommand()); + getCommand2MC().registerCommand(new SnapCommand()); } public static Essentials essentials = null; diff --git a/src/main/java/buttondevteam/chat/commands/SnapCommand.java b/src/main/java/buttondevteam/chat/commands/SnapCommand.java new file mode 100644 index 0000000..13d7cad --- /dev/null +++ b/src/main/java/buttondevteam/chat/commands/SnapCommand.java @@ -0,0 +1,27 @@ +package buttondevteam.chat.commands; + +import buttondevteam.lib.chat.Command2; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.ICommand2MC; +import lombok.val; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; + +import java.util.ArrayList; +import java.util.Random; + +@CommandClass(modOnly = true) +public class SnapCommand extends ICommand2MC { + @Command2.Subcommand + public void def(CommandSender sender) { + val pls = new ArrayList<>(Bukkit.getOnlinePlayers()); + int target = pls.size() / 2; + Random rand = new Random(); + //noinspection SuspiciousMethodCalls + if (pls.remove(sender) && target > 0) + target--; //The sender isn't kicked, so kick someone else + while (pls.size() > target) + pls.remove(rand.nextInt(pls.size())).kickPlayer("You were saved by Thanos."); + sender.sendMessage(target + " grateful players remain."); + } +}