From 1a06aa228ca65c9e7abd86bdb6087e2f20a8abb6 Mon Sep 17 00:00:00 2001 From: ImproperIssues Date: Sat, 15 Apr 2023 17:32:54 -0700 Subject: [PATCH] added all commands --- build.gradle | 4 +- gradle.properties | 4 ++ .../ogredupealias/OgreDupeAlias.java | 12 +++- .../commands/commands/CommandSpyCommand.java | 42 ++++++++++++ .../commands/commands/IRepairCommand.java | 40 ++++++++++++ .../commands/commands/MuteChatCommand.java | 2 +- .../commands/commands/SocialSpyCommand.java | 42 ++++++++++++ .../commands/commands/StaffChatCommand.java | 9 ++- .../events/ChatEventListener.java | 2 +- .../events/CommandEventListener.java | 65 +++++++++++++++++++ .../{utils => plugin}/ChatConstraints.java | 5 +- .../ogredupealias/plugin/RecipientList.java | 53 +++++++++++++++ src/main/resources/config.yml | 5 ++ src/main/resources/plugin.yml | 30 ++++++++- 14 files changed, 301 insertions(+), 14 deletions(-) create mode 100644 src/main/java/io/github/itzispyder/ogredupealias/commands/commands/CommandSpyCommand.java create mode 100644 src/main/java/io/github/itzispyder/ogredupealias/commands/commands/IRepairCommand.java create mode 100644 src/main/java/io/github/itzispyder/ogredupealias/commands/commands/SocialSpyCommand.java create mode 100644 src/main/java/io/github/itzispyder/ogredupealias/events/CommandEventListener.java rename src/main/java/io/github/itzispyder/ogredupealias/{utils => plugin}/ChatConstraints.java (96%) create mode 100644 src/main/java/io/github/itzispyder/ogredupealias/plugin/RecipientList.java diff --git a/build.gradle b/build.gradle index 028c11a..aea8ace 100644 --- a/build.gradle +++ b/build.gradle @@ -2,8 +2,8 @@ plugins { id 'java' } -group = 'io.github.itzispyder' -version = '1.0' +group = project.plugin_group +version = project.plugin_version repositories { mavenCentral() diff --git a/gradle.properties b/gradle.properties index e69de29..15f68f4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -0,0 +1,4 @@ + +# Plugin info +plugin_group= 'io.github.itzispyder' +plugin_version= 2.0.0 \ No newline at end of file diff --git a/src/main/java/io/github/itzispyder/ogredupealias/OgreDupeAlias.java b/src/main/java/io/github/itzispyder/ogredupealias/OgreDupeAlias.java index 62b8d87..ac6d69a 100644 --- a/src/main/java/io/github/itzispyder/ogredupealias/OgreDupeAlias.java +++ b/src/main/java/io/github/itzispyder/ogredupealias/OgreDupeAlias.java @@ -1,10 +1,9 @@ package io.github.itzispyder.ogredupealias; -import io.github.itzispyder.ogredupealias.commands.commands.ConfigCommand; -import io.github.itzispyder.ogredupealias.commands.commands.MuteChatCommand; -import io.github.itzispyder.ogredupealias.commands.commands.StaffChatCommand; +import io.github.itzispyder.ogredupealias.commands.commands.*; import io.github.itzispyder.ogredupealias.data.Config; import io.github.itzispyder.ogredupealias.events.ChatEventListener; +import io.github.itzispyder.ogredupealias.events.CommandEventListener; import io.github.itzispyder.ogredupealias.events.PlayerEventListener; import org.bukkit.Bukkit; import org.bukkit.plugin.PluginManager; @@ -37,6 +36,7 @@ public final class OgreDupeAlias extends JavaPlugin { // Events pm.registerEvents(new ChatEventListener(),this); pm.registerEvents(new PlayerEventListener(),this); + pm.registerEvents(new CommandEventListener(),this); // Commands getCommand("config").setExecutor(new ConfigCommand()); @@ -45,6 +45,12 @@ public final class OgreDupeAlias extends JavaPlugin { getCommand("mutechat").setTabCompleter(new MuteChatCommand()); getCommand("staffchat").setExecutor(new StaffChatCommand()); getCommand("staffchat").setTabCompleter(new StaffChatCommand()); + getCommand("socialspy").setExecutor(new SocialSpyCommand()); + getCommand("socialspy").setTabCompleter(new SocialSpyCommand()); + getCommand("commandspy").setExecutor(new CommandSpyCommand()); + getCommand("commandspy").setTabCompleter(new CommandSpyCommand()); + getCommand("irepair").setExecutor(new IRepairCommand()); + getCommand("irepair").setTabCompleter(new IRepairCommand()); } public void initConfig() { diff --git a/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/CommandSpyCommand.java b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/CommandSpyCommand.java new file mode 100644 index 0000000..c0b2cfe --- /dev/null +++ b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/CommandSpyCommand.java @@ -0,0 +1,42 @@ +package io.github.itzispyder.ogredupealias.commands.commands; + +import io.github.itzispyder.ogredupealias.commands.CmdExHandler; +import io.github.itzispyder.ogredupealias.events.CommandEventListener; +import io.github.itzispyder.ogredupealias.utils.Text; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class CommandSpyCommand implements TabExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + try { + Player p = (Player) sender; + boolean isRecipient = CommandEventListener.commandSpies.isRecipient(p); + if (isRecipient) CommandEventListener.commandSpies.removeRecipient(p); + else CommandEventListener.commandSpies.addRecipient(p); + isRecipient = CommandEventListener.commandSpies.isRecipient(p); + + sender.sendMessage(Text.builder() + .message("&7[&bCommandSpy&7] &8>> &3You are " + (isRecipient ? "&anow" : "&cno longer") + " &3a recipient!") + .prefix() + .color() + .build()); + } + catch (Exception ex) { + CmdExHandler handler = new CmdExHandler(ex,command); + sender.sendMessage(handler.getHelp()); + } + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + return new ArrayList<>(); + } +} diff --git a/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/IRepairCommand.java b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/IRepairCommand.java new file mode 100644 index 0000000..74c222a --- /dev/null +++ b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/IRepairCommand.java @@ -0,0 +1,40 @@ +package io.github.itzispyder.ogredupealias.commands.commands; + +import io.github.itzispyder.ogredupealias.commands.CmdExHandler; +import io.github.itzispyder.ogredupealias.utils.Text; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +public class IRepairCommand implements TabExecutor { + + @Override + @SuppressWarnings("deprecation") + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + try { + Player p = (Player) sender; + Arrays.stream(p.getInventory().getContents()).filter(Objects::nonNull).forEach(item -> { + item.setDurability(new ItemStack(item.getType()).getDurability()); + item.setAmount(item.getMaxStackSize()); + }); + sender.sendMessage(Text.builder("&3Repaired and restocked your inventory.").prefix().color().build()); + } + catch (Exception ex) { + CmdExHandler handler = new CmdExHandler(ex,command); + sender.sendMessage(handler.getHelp()); + } + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + return new ArrayList<>(); + } +} diff --git a/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/MuteChatCommand.java b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/MuteChatCommand.java index a966bfe..ee3a02d 100644 --- a/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/MuteChatCommand.java +++ b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/MuteChatCommand.java @@ -2,7 +2,7 @@ package io.github.itzispyder.ogredupealias.commands.commands; import io.github.itzispyder.ogredupealias.commands.CmdExHandler; import io.github.itzispyder.ogredupealias.commands.TabComplBuilder; -import io.github.itzispyder.ogredupealias.utils.ChatConstraints; +import io.github.itzispyder.ogredupealias.plugin.ChatConstraints; import io.github.itzispyder.ogredupealias.utils.Text; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; diff --git a/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/SocialSpyCommand.java b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/SocialSpyCommand.java new file mode 100644 index 0000000..84e4ada --- /dev/null +++ b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/SocialSpyCommand.java @@ -0,0 +1,42 @@ +package io.github.itzispyder.ogredupealias.commands.commands; + +import io.github.itzispyder.ogredupealias.commands.CmdExHandler; +import io.github.itzispyder.ogredupealias.events.CommandEventListener; +import io.github.itzispyder.ogredupealias.utils.Text; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public class SocialSpyCommand implements TabExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + try { + Player p = (Player) sender; + boolean isRecipient = CommandEventListener.socialSpies.isRecipient(p); + if (isRecipient) CommandEventListener.socialSpies.removeRecipient(p); + else CommandEventListener.socialSpies.addRecipient(p); + isRecipient = CommandEventListener.socialSpies.isRecipient(p); + + sender.sendMessage(Text.builder() + .message("&7[&bSocialSpy&7] &8>> &3You are " + (isRecipient ? "&anow" : "&cno longer") + " &3a recipient!") + .prefix() + .color() + .build()); + } + catch (Exception ex) { + CmdExHandler handler = new CmdExHandler(ex,command); + sender.sendMessage(handler.getHelp()); + } + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { + return new ArrayList<>(); + } +} diff --git a/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/StaffChatCommand.java b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/StaffChatCommand.java index 42df924..ee22bfa 100644 --- a/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/StaffChatCommand.java +++ b/src/main/java/io/github/itzispyder/ogredupealias/commands/commands/StaffChatCommand.java @@ -2,14 +2,11 @@ package io.github.itzispyder.ogredupealias.commands.commands; import io.github.itzispyder.ogredupealias.commands.CmdExHandler; import io.github.itzispyder.ogredupealias.commands.TabComplBuilder; -import io.github.itzispyder.ogredupealias.utils.ArrayUtils; import io.github.itzispyder.ogredupealias.utils.ServerUtils; import io.github.itzispyder.ogredupealias.utils.Text; -import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; -import org.bukkit.entity.Player; import java.util.List; @@ -20,7 +17,7 @@ public class StaffChatCommand implements TabExecutor { try { String msg = String.join(" ", args); ServerUtils.dmEachPlayer(p -> p.hasPermission("oda.commands.staffchat"), Text.builder() - .message("&7[&bStaffChat&7] &8>> &e" + msg) + .message("&7[&bStaffChat&7] &3" + sender.getName() + " &8>> &e" + msg) .color() .prefix() .build()); @@ -35,7 +32,9 @@ public class StaffChatCommand implements TabExecutor { @Override public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) { return new TabComplBuilder(sender, command, alias, args) - .add(1, ArrayUtils.toNewList(Bukkit.getOnlinePlayers(), Player::getName)) + .add(1, new String[]{ + "[]" + },args[0].length() == 0) .build(); } } diff --git a/src/main/java/io/github/itzispyder/ogredupealias/events/ChatEventListener.java b/src/main/java/io/github/itzispyder/ogredupealias/events/ChatEventListener.java index 52761a2..48e0249 100644 --- a/src/main/java/io/github/itzispyder/ogredupealias/events/ChatEventListener.java +++ b/src/main/java/io/github/itzispyder/ogredupealias/events/ChatEventListener.java @@ -1,6 +1,6 @@ package io.github.itzispyder.ogredupealias.events; -import io.github.itzispyder.ogredupealias.utils.ChatConstraints; +import io.github.itzispyder.ogredupealias.plugin.ChatConstraints; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; diff --git a/src/main/java/io/github/itzispyder/ogredupealias/events/CommandEventListener.java b/src/main/java/io/github/itzispyder/ogredupealias/events/CommandEventListener.java new file mode 100644 index 0000000..aeb99a7 --- /dev/null +++ b/src/main/java/io/github/itzispyder/ogredupealias/events/CommandEventListener.java @@ -0,0 +1,65 @@ +package io.github.itzispyder.ogredupealias.events; + +import io.github.itzispyder.ogredupealias.data.Config; +import io.github.itzispyder.ogredupealias.plugin.RecipientList; +import io.github.itzispyder.ogredupealias.utils.Text; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class CommandEventListener implements Listener { + + public static final RecipientList commandSpies = new RecipientList(); + public static final RecipientList socialSpies = new RecipientList(); + private static final List socialCommands = Arrays.asList( + "/tell", + "/whisper", + "/w", + "/message", + "/msg" + ); + + @EventHandler + public void onPlayerCommand(PlayerCommandPreprocessEvent e) { + final String msg = e.getMessage(); + final Player p = e.getPlayer(); + final String[] words = msg.split(" "); + final String cmd = msg.split(" ")[0]; + final String body = words.length >= 2 ? String.join(" ", new ArrayList<>(Arrays.stream(words).toList()).subList(1, words.length)) : Text.color("&c"); + + if (socialCommands.contains(cmd.toLowerCase())) { + if (words.length <= 2) return; + final Player to = Bukkit.getPlayer(words[1]); + final String context = String.join(" ", new ArrayList<>(Arrays.stream(words).toList()).subList(2, words.length)); + if (to == null || !to.isOnline()) return; + + TextComponent text = new TextComponent(); + text.setText(Text.builder("&7[&bSocialSpy&7] &8>> &3" + p.getName() + " &7messaged &3" + to.getName()).color().prefix().build()); + text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Text.color("&b" + context + "\n&8(click to copy)")))); + text.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, context)); + + socialSpies.forEachRecipient(player -> { + player.spigot().sendMessage(text); + }); + } + else if (!Config.Server.commandSpyBlacklist().contains(cmd.toLowerCase())) { + TextComponent text = new TextComponent(); + text.setText(Text.builder("&7[&bCommandSpy&7] &8>> &3" + p.getName() + " &7used &6" + cmd).color().prefix().build()); + text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Text.color("&6" + cmd + " &e" + body + "\n&8(click to copy)")))); + text.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, msg)); + + commandSpies.forEachRecipient(player -> { + player.spigot().sendMessage(text); + }); + } + } +} diff --git a/src/main/java/io/github/itzispyder/ogredupealias/utils/ChatConstraints.java b/src/main/java/io/github/itzispyder/ogredupealias/plugin/ChatConstraints.java similarity index 96% rename from src/main/java/io/github/itzispyder/ogredupealias/utils/ChatConstraints.java rename to src/main/java/io/github/itzispyder/ogredupealias/plugin/ChatConstraints.java index c76a3cd..ae11fc5 100644 --- a/src/main/java/io/github/itzispyder/ogredupealias/utils/ChatConstraints.java +++ b/src/main/java/io/github/itzispyder/ogredupealias/plugin/ChatConstraints.java @@ -1,6 +1,9 @@ -package io.github.itzispyder.ogredupealias.utils; +package io.github.itzispyder.ogredupealias.plugin; import io.github.itzispyder.ogredupealias.data.Config; +import io.github.itzispyder.ogredupealias.utils.ArrayUtils; +import io.github.itzispyder.ogredupealias.utils.ServerUtils; +import io.github.itzispyder.ogredupealias.utils.Text; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.entity.Player; diff --git a/src/main/java/io/github/itzispyder/ogredupealias/plugin/RecipientList.java b/src/main/java/io/github/itzispyder/ogredupealias/plugin/RecipientList.java new file mode 100644 index 0000000..be5a441 --- /dev/null +++ b/src/main/java/io/github/itzispyder/ogredupealias/plugin/RecipientList.java @@ -0,0 +1,53 @@ +package io.github.itzispyder.ogredupealias.plugin; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +import java.util.*; +import java.util.function.Consumer; + +public class RecipientList { + + private final Set recipients; + + public RecipientList() { + this.recipients = new HashSet<>(); + } + + public List getRecipients() { + return new ArrayList<>(recipients); + } + + public void addRecipient(Player p) { + recipients.add(p.getUniqueId()); + } + + public void removeRecipient(Player p) { + recipients.remove(p.getUniqueId()); + } + + public boolean isRecipient(Player p) { + return recipients.contains(p.getUniqueId()); + } + + public void addRecipient(UUID p) { + recipients.add(p); + } + + public void removeRecipient(UUID p) { + recipients.remove(p); + } + + public boolean isRecipient(UUID p) { + return recipients.contains(p); + } + + public void forEachRecipient(Consumer consumer) { + recipients.forEach(uuid -> { + Player p = Bukkit.getPlayer(uuid); + if (p == null) return; + if (!p.isOnline()) return; + consumer.accept(p); + }); + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2b6a04c..dc109fb 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -26,3 +26,8 @@ player: server: command-spy-blacklist: - /dupe + - /msg + - /message + - /w + - /whisper + - /tell diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index be623a2..3774974 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -17,6 +17,15 @@ permissions: oda.commands.staffchat: description: Access to staffchat. default: op + oda.commands.socialspy: + description: Access to socialspy. + default: op + oda.commands.commandspy: + description: Access to commandspy. + default: op + oda.commands.irepair: + description: Access to irepair. + default: op oda.chat.bypass: description: Bypass chat restrictions default: op @@ -55,4 +64,23 @@ commands: permission: oda.commands.staffchat aliases: - sc - - schat \ No newline at end of file + - schat + socialspy: + description: Spy on private messages + usage: /socialspy + permission: oda.commands.socialspy + aliases: + - sspy + commandspy: + description: Spy on player commands + usage: /commandspy + permission: oda.commands.commandspy + aliases: + - cspy + - cmdspy + irepair: + description: Repairs and restocks your inventory! + usage: /irepair + permission: oda.commands.irepair + aliases: + - ipearlrepair \ No newline at end of file