added all commands

This commit is contained in:
ImproperIssues
2023-04-15 17:32:54 -07:00
parent 16d5b4a5a2
commit 1a06aa228c
14 changed files with 301 additions and 14 deletions

View File

@@ -2,8 +2,8 @@ plugins {
id 'java' id 'java'
} }
group = 'io.github.itzispyder' group = project.plugin_group
version = '1.0' version = project.plugin_version
repositories { repositories {
mavenCentral() mavenCentral()

View File

@@ -0,0 +1,4 @@
# Plugin info
plugin_group= 'io.github.itzispyder'
plugin_version= 2.0.0

View File

@@ -1,10 +1,9 @@
package io.github.itzispyder.ogredupealias; package io.github.itzispyder.ogredupealias;
import io.github.itzispyder.ogredupealias.commands.commands.ConfigCommand; import io.github.itzispyder.ogredupealias.commands.commands.*;
import io.github.itzispyder.ogredupealias.commands.commands.MuteChatCommand;
import io.github.itzispyder.ogredupealias.commands.commands.StaffChatCommand;
import io.github.itzispyder.ogredupealias.data.Config; import io.github.itzispyder.ogredupealias.data.Config;
import io.github.itzispyder.ogredupealias.events.ChatEventListener; import io.github.itzispyder.ogredupealias.events.ChatEventListener;
import io.github.itzispyder.ogredupealias.events.CommandEventListener;
import io.github.itzispyder.ogredupealias.events.PlayerEventListener; import io.github.itzispyder.ogredupealias.events.PlayerEventListener;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
@@ -37,6 +36,7 @@ public final class OgreDupeAlias extends JavaPlugin {
// Events // Events
pm.registerEvents(new ChatEventListener(),this); pm.registerEvents(new ChatEventListener(),this);
pm.registerEvents(new PlayerEventListener(),this); pm.registerEvents(new PlayerEventListener(),this);
pm.registerEvents(new CommandEventListener(),this);
// Commands // Commands
getCommand("config").setExecutor(new ConfigCommand()); getCommand("config").setExecutor(new ConfigCommand());
@@ -45,6 +45,12 @@ public final class OgreDupeAlias extends JavaPlugin {
getCommand("mutechat").setTabCompleter(new MuteChatCommand()); getCommand("mutechat").setTabCompleter(new MuteChatCommand());
getCommand("staffchat").setExecutor(new StaffChatCommand()); getCommand("staffchat").setExecutor(new StaffChatCommand());
getCommand("staffchat").setTabCompleter(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() { public void initConfig() {

View File

@@ -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<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return new ArrayList<>();
}
}

View File

@@ -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<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return new ArrayList<>();
}
}

View File

@@ -2,7 +2,7 @@ package io.github.itzispyder.ogredupealias.commands.commands;
import io.github.itzispyder.ogredupealias.commands.CmdExHandler; import io.github.itzispyder.ogredupealias.commands.CmdExHandler;
import io.github.itzispyder.ogredupealias.commands.TabComplBuilder; 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 io.github.itzispyder.ogredupealias.utils.Text;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;

View File

@@ -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<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return new ArrayList<>();
}
}

View File

@@ -2,14 +2,11 @@ package io.github.itzispyder.ogredupealias.commands.commands;
import io.github.itzispyder.ogredupealias.commands.CmdExHandler; import io.github.itzispyder.ogredupealias.commands.CmdExHandler;
import io.github.itzispyder.ogredupealias.commands.TabComplBuilder; 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.ServerUtils;
import io.github.itzispyder.ogredupealias.utils.Text; import io.github.itzispyder.ogredupealias.utils.Text;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import java.util.List; import java.util.List;
@@ -20,7 +17,7 @@ public class StaffChatCommand implements TabExecutor {
try { try {
String msg = String.join(" ", args); String msg = String.join(" ", args);
ServerUtils.dmEachPlayer(p -> p.hasPermission("oda.commands.staffchat"), Text.builder() 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() .color()
.prefix() .prefix()
.build()); .build());
@@ -35,7 +32,9 @@ public class StaffChatCommand implements TabExecutor {
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return new TabComplBuilder(sender, command, alias, args) return new TabComplBuilder(sender, command, alias, args)
.add(1, ArrayUtils.toNewList(Bukkit.getOnlinePlayers(), Player::getName)) .add(1, new String[]{
"[<message>]"
},args[0].length() == 0)
.build(); .build();
} }
} }

View File

@@ -1,6 +1,6 @@
package io.github.itzispyder.ogredupealias.events; 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.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;

View File

@@ -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<String> 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<no-args>");
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);
});
}
}
}

View File

@@ -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.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.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@@ -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<UUID> recipients;
public RecipientList() {
this.recipients = new HashSet<>();
}
public List<UUID> 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<Player> consumer) {
recipients.forEach(uuid -> {
Player p = Bukkit.getPlayer(uuid);
if (p == null) return;
if (!p.isOnline()) return;
consumer.accept(p);
});
}
}

View File

@@ -26,3 +26,8 @@ player:
server: server:
command-spy-blacklist: command-spy-blacklist:
- /dupe - /dupe
- /msg
- /message
- /w
- /whisper
- /tell

View File

@@ -17,6 +17,15 @@ permissions:
oda.commands.staffchat: oda.commands.staffchat:
description: Access to staffchat. description: Access to staffchat.
default: op 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: oda.chat.bypass:
description: Bypass chat restrictions description: Bypass chat restrictions
default: op default: op
@@ -55,4 +64,23 @@ commands:
permission: oda.commands.staffchat permission: oda.commands.staffchat
aliases: aliases:
- sc - sc
- schat - 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