Rename command listeners.

This commit is contained in:
Aust1n46 2022-01-15 04:02:46 -06:00
parent 096da4db4d
commit dd419e37ca
4 changed files with 484 additions and 484 deletions

View File

@ -22,11 +22,11 @@ import venture.Aust1n46.chat.VentureChatPluginModule;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.controllers.VentureChatSpigotFlatFileController;
import venture.Aust1n46.chat.initiators.listeners.ChatListener;
import venture.Aust1n46.chat.initiators.listeners.CommandListener;
import venture.Aust1n46.chat.initiators.listeners.PreProcessCommandListener;
import venture.Aust1n46.chat.initiators.listeners.LoginListener;
import venture.Aust1n46.chat.initiators.listeners.PacketListener;
import venture.Aust1n46.chat.initiators.listeners.SignListener;
import venture.Aust1n46.chat.initiators.listeners.VentureCommandExecutor;
import venture.Aust1n46.chat.initiators.listeners.CommandListener;
import venture.Aust1n46.chat.initiators.schedulers.UnmuteScheduler;
import venture.Aust1n46.chat.localization.Localization;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
@ -46,7 +46,7 @@ public class VentureChat extends JavaPlugin implements PluginMessageListener {
@Inject
private SignListener signListener;
@Inject
private CommandListener commandListener;
private PreProcessCommandListener commandListener;
@Inject
private PacketListener packetListener;
@Inject
@ -65,7 +65,7 @@ public class VentureChat extends JavaPlugin implements PluginMessageListener {
final VentureChatPluginModule pluginModule = new VentureChatPluginModule(this);
final Injector injector = Guice.createInjector(pluginModule);
injector.injectMembers(this);
injector.injectMembers(new VentureCommandExecutor());
injector.injectMembers(new CommandListener());
injector.injectMembers(new UnmuteScheduler());
try {

View File

@ -1,290 +1,219 @@
package venture.Aust1n46.chat.initiators.listeners;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.command.TabExecutor;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import me.clip.placeholderapi.PlaceholderAPI;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.controllers.commands.Broadcast;
import venture.Aust1n46.chat.controllers.commands.BungeeToggle;
import venture.Aust1n46.chat.controllers.commands.Channel;
import venture.Aust1n46.chat.controllers.commands.Channelinfo;
import venture.Aust1n46.chat.controllers.commands.Chatinfo;
import venture.Aust1n46.chat.controllers.commands.Chatreload;
import venture.Aust1n46.chat.controllers.commands.Chlist;
import venture.Aust1n46.chat.controllers.commands.Chwho;
import venture.Aust1n46.chat.controllers.commands.Clearchat;
import venture.Aust1n46.chat.controllers.commands.Commandblock;
import venture.Aust1n46.chat.controllers.commands.Commandspy;
import venture.Aust1n46.chat.controllers.commands.Edit;
import venture.Aust1n46.chat.controllers.commands.Filter;
import venture.Aust1n46.chat.controllers.commands.Force;
import venture.Aust1n46.chat.controllers.commands.Forceall;
import venture.Aust1n46.chat.controllers.commands.IgnoreCommandExecutor;
import venture.Aust1n46.chat.controllers.commands.Kickchannel;
import venture.Aust1n46.chat.controllers.commands.Kickchannelall;
import venture.Aust1n46.chat.controllers.commands.Leave;
import venture.Aust1n46.chat.controllers.commands.Listen;
import venture.Aust1n46.chat.controllers.commands.Me;
import venture.Aust1n46.chat.controllers.commands.MessageCommandExecutor;
import venture.Aust1n46.chat.controllers.commands.MessageToggle;
import venture.Aust1n46.chat.controllers.commands.Mute;
import venture.Aust1n46.chat.controllers.commands.Muteall;
import venture.Aust1n46.chat.controllers.commands.Notifications;
import venture.Aust1n46.chat.controllers.commands.Party;
import venture.Aust1n46.chat.controllers.commands.RangedSpy;
import venture.Aust1n46.chat.controllers.commands.Removemessage;
import venture.Aust1n46.chat.controllers.commands.Reply;
import venture.Aust1n46.chat.controllers.commands.Setchannel;
import venture.Aust1n46.chat.controllers.commands.Setchannelall;
import venture.Aust1n46.chat.controllers.commands.Spy;
import venture.Aust1n46.chat.controllers.commands.Unmute;
import venture.Aust1n46.chat.controllers.commands.Unmuteall;
import venture.Aust1n46.chat.controllers.commands.VentureChatGui;
import venture.Aust1n46.chat.controllers.commands.Venturechat;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.Alias;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.GuiSlot;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.utilities.VersionHandler;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatDatabaseService;
import venture.Aust1n46.chat.service.VentureChatFormatService;
import venture.Aust1n46.chat.model.VentureCommand;
//This class listens for commands (Any chat that begins with a /) to use in the command spy and
//in the custom commands such as aliases.
/**
* Class that initializes and executes the plugin's commands.
*/
@Singleton
public class CommandListener implements CommandExecutor, Listener {
public class CommandListener implements TabExecutor {
private Map<String, VentureCommand> commands = new HashMap<String, VentureCommand>();
@Inject
private VentureChat plugin;
@Inject
private VentureChatFormatService formatService;
private MessageCommandExecutor messageCommandExecutor;
@Inject
private VentureChatDatabaseService databaseService;
private IgnoreCommandExecutor ignoreCommandExecutor;
@Inject
private PluginMessageController pluginMessageController;
private Broadcast broadcast;
@Inject
private VentureChatPlayerApiService playerApiService;
private Channel channel;
@Inject
private ConfigService configService;
private Channelinfo channelinfo;
@Inject
private Chatinfo chatinfo;
@Inject
private Chatreload chatreload;
@Inject
private Chlist chlist;
@Inject
private Chwho chwho;
@Inject
private Clearchat clearchat;
@Inject
private Commandblock commandblock;
@Inject
private Commandspy commandspy;
@Inject
private Edit edit;
@Inject
private Filter filter;
@Inject
private Force force;
@Inject
private Forceall forceall;
@Inject
private Kickchannel kickchannel;
@Inject
private Kickchannelall kickchannelall;
@Inject
private Leave leave;
@Inject
private Listen listen;
@Inject
private Me me;
@Inject
private Venturechat venturechat;
@Inject
private Notifications notifications;
@Inject
private Party party;
@Inject
private RangedSpy rangedSpy;
@Inject
private Removemessage removemessage;
@Inject
private Setchannel setchannel;
@Inject
private Setchannelall setchannelall;
@Inject
private Spy spy;
@Inject
private VentureChatGui ventureChatGui;
@Inject
private MessageToggle messageToggle;
@Inject
private BungeeToggle bungeeToggle;
@Inject
private Reply reply;
@Inject
private Mute mute;
@Inject
private Muteall muteall;
@Inject
private Unmute unmute;
@Inject
private Unmuteall unmuteall;
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) throws FileNotFoundException {
if(event.getPlayer() == null) {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Event.getPlayer() returned null in PlayerCommandPreprocessEvent"));
return;
}
ConfigurationSection cs = plugin.getConfig().getConfigurationSection("commandspy");
Boolean wec = cs.getBoolean("worldeditcommands", true);
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(event.getPlayer());
if(!mcp.getPlayer().hasPermission("venturechat.commandspy.override")) {
for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) {
if(p.hasCommandSpy()) {
if(wec) {
p.getPlayer().sendMessage(FormatUtils.FormatStringAll(cs.getString("format").replace("{player}", mcp.getName()).replace("{command}", event.getMessage())));
}
else {
if(!(event.getMessage().toLowerCase().startsWith("//"))) {
p.getPlayer().sendMessage(FormatUtils.FormatStringAll(cs.getString("format").replace("{player}", mcp.getName()).replace("{command}", event.getMessage())));
}
else {
if(!(event.getMessage().toLowerCase().startsWith("//"))) {
p.getPlayer().sendMessage(ChatColor.GOLD + mcp.getName() + ": " + event.getMessage());
}
}
}
}
}
}
String[] blocked = event.getMessage().split(" ");
if(mcp.getBlockedCommands().contains(blocked[0])) {
mcp.getPlayer().sendMessage(LocalizedMessage.BLOCKED_COMMAND.toString()
.replace("{command}", event.getMessage()));
event.setCancelled(true);
return;
}
String message = event.getMessage();
if(databaseService.isEnabled()) {
databaseService.writeVentureChat(mcp.getUuid().toString(), mcp.getName(), "Local", "Command_Component", event.getMessage().replace("'", "''"), "Command");
}
for(Alias a : configService.getAliases()) {
if(message.toLowerCase().substring(1).split(" ")[0].equals(a.getName().toLowerCase())) {
for(String s : a.getComponents()) {
if(!mcp.getPlayer().hasPermission(a.getPermission()) && a.hasPermission()) {
mcp.getPlayer().sendMessage(ChatColor.RED + "You do not have permission for this alias.");
event.setCancelled(true);
return;
}
int num = 1;
if(message.length() < a.getName().length() + 2 || a.getArguments() == 0) num = 0;
int arg = 0;
if(message.substring(a.getName().length() + 1 + num).length() == 0) arg = 1;
String[] args = message.substring(a.getName().length() + 1 + num).split(" ");
String send = "";
if(args.length - arg < a.getArguments()) {
String keyword = "arguments.";
if(a.getArguments() == 1) keyword = "argument.";
mcp.getPlayer().sendMessage(ChatColor.RED + "Invalid arguments for this alias, enter at least " + a.getArguments() + " " + keyword);
event.setCancelled(true);
return;
}
for(int b = 0; b < args.length; b++) {
send += " " + args[b];
}
if(send.length() > 0) send = send.substring(1);
s = FormatUtils.FormatStringAll(s);
if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
send = FormatUtils.FormatStringLegacyColor(send);
}
if(mcp.getPlayer().hasPermission("venturechat.color")) {
send = FormatUtils.FormatStringColor(send);
}
if(mcp.getPlayer().hasPermission("venturechat.format")) {
send = FormatUtils.FormatString(send);
}
if(s.startsWith("Command:")) {
mcp.getPlayer().chat(s.substring(9).replace("$", send));
event.setCancelled(true);
}
if(s.startsWith("Message:")) {
mcp.getPlayer().sendMessage(s.substring(9).replace("$", send));
event.setCancelled(true);
}
if(s.startsWith("Broadcast:")) {
formatService.broadcastToServer(s.substring(11).replace("$", send));
event.setCancelled(true);
}
}
}
}
if(!configService.areAliasesRegisteredAsCommands()) {
for(ChatChannel channel : configService.getChatChannels()) {
if(!channel.hasPermission() || mcp.getPlayer().hasPermission(channel.getPermission())) {
if(message.equals("/" + channel.getAlias())) {
mcp.getPlayer().sendMessage(LocalizedMessage.SET_CHANNEL.toString()
.replace("{channel_color}", channel.getColor() + "")
.replace("{channel_name}", channel.getName()));
if(mcp.hasConversation()) {
for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) {
if(p.isSpy()) {
p.getPlayer().sendMessage(LocalizedMessage.EXIT_PRIVATE_CONVERSATION_SPY.toString()
.replace("{player_sender}", mcp.getName())
.replace("{player_receiver}", playerApiService.getMineverseChatPlayer(mcp.getConversation()).getName()));
}
}
mcp.getPlayer().sendMessage(LocalizedMessage.EXIT_PRIVATE_CONVERSATION.toString()
.replace("{player_receiver}", playerApiService.getMineverseChatPlayer(mcp.getConversation()).getName()));
mcp.setConversation(null);
}
mcp.addListening(channel.getName());
mcp.setCurrentChannel(channel);
if(channel.getBungee()) {
pluginMessageController.synchronize(mcp, true);
}
event.setCancelled(true);
return;
}
if(message.toLowerCase().startsWith("/" + channel.getAlias() + " ")) {
message = message.substring(channel.getAlias().length() + 1);
mcp.addListening(channel.getName());
if(channel.getBungee()) {
pluginMessageController.synchronize(mcp, true);
}
mcp.setQuickChannel(channel);
/*String format = "";
if(plugin.getConfig().getConfigurationSection("channels." + channel.getName()).getString("format").equalsIgnoreCase("Default")) {
format = FormatTags.ChatFormat(ChatColor.valueOf(channel.getColor().toUpperCase()) + "[" + channel.getName() + "] {prefix}{name}" + ChatColor.valueOf(channel.getColor().toUpperCase()) + ":" + ChatColor.valueOf(channel.getChatColor().toUpperCase()), mcp.getPlayer(), plugin, cc, channel, plugin.getConfig().getBoolean("jsonFormat"));
}
else {
format = FormatTags.ChatFormat(plugin.getConfig().getConfigurationSection("channels." + channel.getName()).getString("format"), mcp.getPlayer(), plugin, cc, channel, plugin.getConfig().getBoolean("jsonFormat"));
if(plugin.getConfig().getBoolean("formatcleaner", false)) {
format = format.replace("[]", " ");
format = format.replace(" ", " ").replace(" ", " ").replace(" ", " ");
}
}*/
mcp.setQuickChat(true);
mcp.getPlayer().chat(message);
event.setCancelled(true);
}
}
}
}
}
//old 1.8 command map
@EventHandler
public void onServerCommand(ServerCommandEvent event) {
if (databaseService.isEnabled()) {
databaseService.writeVentureChat("N/A", "Console", "Local", "Command_Component", event.getCommand().replace("'", "''") , "Command");
}
}
/**
* Unused
*/
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
plugin.getServer().getConsoleSender().sendMessage(ChatColor.RED + "This command must be run by a player.");
return true;
}
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender);
for(ChatChannel channel : configService.getChatChannels()) {
if(command.getName().toLowerCase().equals(channel.getAlias())) {
if(args.length == 0) {
mcp.getPlayer().sendMessage(ChatColor.RED + "Invalid command: /" + channel.getAlias() + " message");
return true;
}
mcp.setQuickChat(true);
mcp.setQuickChannel(channel);
mcp.addListening(channel.getName());
if(channel.getBungee()) {
pluginMessageController.synchronize(mcp, true);
}
String msg = "";
for(int x = 0; x < args.length; x++) {
if(args[x].length() > 0) msg += " " + args[x];
}
mcp.getPlayer().chat(msg);
return true;
}
}
return false;
public boolean onCommand(CommandSender sender, Command command, String label, String[] parameters) {
commands.get(command.getName()).execute(sender, command.getName(), parameters);
return true;
}
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOW)
public void InventoryClick(InventoryClickEvent e) {
if(!e.getView().getTitle().contains("VentureChat")) {
return;
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return commands.get(command.getName()).onTabComplete(sender, command, label, args);
}
@Inject
public void postConstruct() {
commands.put("broadcast", broadcast);
commands.put("channel", channel);
commands.put("join", channel);
commands.put("channelinfo", channelinfo);
commands.put("chatinfo", chatinfo);
commands.put("chatreload", chatreload);
commands.put("chlist", chlist);
commands.put("chwho", chwho);
commands.put("clearchat", clearchat);
commands.put("commandblock", commandblock);
commands.put("commandspy", commandspy);
commands.put("edit", edit);
commands.put("filter", filter);
commands.put("force", force);
commands.put("forceall", forceall);
commands.put("kickchannel", kickchannel);
commands.put("kickchannelall", kickchannelall);
commands.put("leave", leave);
commands.put("listen", listen);
commands.put("me", me);
commands.put("venturechat", venturechat);
commands.put("notifications", notifications);
commands.put("party", party);
commands.put("rangedspy", rangedSpy);
commands.put("removemessage", removemessage);
commands.put("setchannel", setchannel);
commands.put("setchannelall", setchannelall);
commands.put("spy", spy);
commands.put("venturechatgui", ventureChatGui);
commands.put("messagetoggle", messageToggle);
commands.put("bungeetoggle", bungeeToggle);
for (String command : commands.keySet()) {
registerCommand(command, this);
}
e.setCancelled(true);
ItemStack item = e.getCurrentItem();
if (item == null) {
return;
}
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) e.getWhoClicked());
String playerName = e.getView().getTitle().replace(" GUI", "").replace("VentureChat: ", "");
VentureChatPlayer target = playerApiService.getMineverseChatPlayer(playerName);
ItemStack skull = e.getInventory().getItem(0);
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
ChatChannel channel = configService.getChannel(ChatColor.stripColor(skullMeta.getLore().get(0)).replace("Channel: ", ""));
int hash = Integer.parseInt(ChatColor.stripColor(skullMeta.getLore().get(1).replace("Hash: ", "")));
if(VersionHandler.is1_7()) {
if(item.getType() == Material.BEDROCK) {
mcp.getPlayer().closeInventory();
}
}
else {
if(item.getType() == Material.BARRIER) {
mcp.getPlayer().closeInventory();
}
}
for(GuiSlot g : configService.getGuiSlots()) {
if(g.getIcon() == item.getType() && g.getDurability() == item.getDurability() && g.getSlot() == e.getSlot()) {
String command = g.getCommand().replace("{channel}", channel.getName()).replace("{hash}", hash + "");
if(target != null) {
command = command.replace("{player_name}", target.getName());
if(target.isOnline()) {
command = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(target.getPlayer(), command));
}
}
else {
command = command.replace("{player_name}", "Discord_Message");
}
mcp.getPlayer().chat(command);
plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
if (plugin.isEnabled()) {
commands.put("reply", reply);
commands.put("r", reply);
registerCommand("reply", this);
registerCommand("r", this);
commands.put("mute", mute);
commands.put("muteall", muteall);
commands.put("unmute", unmute);
commands.put("unmuteall", unmuteall);
registerCommand("mute", this);
registerCommand("muteall", this);
registerCommand("unmute", this);
registerCommand("unmuteall", this);
registerCommand("message", messageCommandExecutor);
registerCommand("msg", messageCommandExecutor);
registerCommand("tell", messageCommandExecutor);
registerCommand("whisper", messageCommandExecutor);
registerCommand("ignore", ignoreCommandExecutor);
}
}, 0);
}
private void registerCommand(String command, CommandExecutor commandExecutor) {
if (plugin.getCommand(command) != null) {
plugin.getCommand(command).setExecutor(commandExecutor);
}
}
}

View File

@ -0,0 +1,290 @@
package venture.Aust1n46.chat.initiators.listeners;
import java.io.FileNotFoundException;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import me.clip.placeholderapi.PlaceholderAPI;
import venture.Aust1n46.chat.controllers.PluginMessageController;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.localization.LocalizedMessage;
import venture.Aust1n46.chat.model.Alias;
import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.GuiSlot;
import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.VentureChatPlayerApiService;
import venture.Aust1n46.chat.utilities.FormatUtils;
import venture.Aust1n46.chat.utilities.VersionHandler;
import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatDatabaseService;
import venture.Aust1n46.chat.service.VentureChatFormatService;
//This class listens for commands (Any chat that begins with a /) to use in the command spy and
//in the custom commands such as aliases.
@Singleton
public class PreProcessCommandListener implements CommandExecutor, Listener {
@Inject
private VentureChat plugin;
@Inject
private VentureChatFormatService formatService;
@Inject
private VentureChatDatabaseService databaseService;
@Inject
private PluginMessageController pluginMessageController;
@Inject
private VentureChatPlayerApiService playerApiService;
@Inject
private ConfigService configService;
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) throws FileNotFoundException {
if(event.getPlayer() == null) {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Event.getPlayer() returned null in PlayerCommandPreprocessEvent"));
return;
}
ConfigurationSection cs = plugin.getConfig().getConfigurationSection("commandspy");
Boolean wec = cs.getBoolean("worldeditcommands", true);
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(event.getPlayer());
if(!mcp.getPlayer().hasPermission("venturechat.commandspy.override")) {
for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) {
if(p.hasCommandSpy()) {
if(wec) {
p.getPlayer().sendMessage(FormatUtils.FormatStringAll(cs.getString("format").replace("{player}", mcp.getName()).replace("{command}", event.getMessage())));
}
else {
if(!(event.getMessage().toLowerCase().startsWith("//"))) {
p.getPlayer().sendMessage(FormatUtils.FormatStringAll(cs.getString("format").replace("{player}", mcp.getName()).replace("{command}", event.getMessage())));
}
else {
if(!(event.getMessage().toLowerCase().startsWith("//"))) {
p.getPlayer().sendMessage(ChatColor.GOLD + mcp.getName() + ": " + event.getMessage());
}
}
}
}
}
}
String[] blocked = event.getMessage().split(" ");
if(mcp.getBlockedCommands().contains(blocked[0])) {
mcp.getPlayer().sendMessage(LocalizedMessage.BLOCKED_COMMAND.toString()
.replace("{command}", event.getMessage()));
event.setCancelled(true);
return;
}
String message = event.getMessage();
if(databaseService.isEnabled()) {
databaseService.writeVentureChat(mcp.getUuid().toString(), mcp.getName(), "Local", "Command_Component", event.getMessage().replace("'", "''"), "Command");
}
for(Alias a : configService.getAliases()) {
if(message.toLowerCase().substring(1).split(" ")[0].equals(a.getName().toLowerCase())) {
for(String s : a.getComponents()) {
if(!mcp.getPlayer().hasPermission(a.getPermission()) && a.hasPermission()) {
mcp.getPlayer().sendMessage(ChatColor.RED + "You do not have permission for this alias.");
event.setCancelled(true);
return;
}
int num = 1;
if(message.length() < a.getName().length() + 2 || a.getArguments() == 0) num = 0;
int arg = 0;
if(message.substring(a.getName().length() + 1 + num).length() == 0) arg = 1;
String[] args = message.substring(a.getName().length() + 1 + num).split(" ");
String send = "";
if(args.length - arg < a.getArguments()) {
String keyword = "arguments.";
if(a.getArguments() == 1) keyword = "argument.";
mcp.getPlayer().sendMessage(ChatColor.RED + "Invalid arguments for this alias, enter at least " + a.getArguments() + " " + keyword);
event.setCancelled(true);
return;
}
for(int b = 0; b < args.length; b++) {
send += " " + args[b];
}
if(send.length() > 0) send = send.substring(1);
s = FormatUtils.FormatStringAll(s);
if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
send = FormatUtils.FormatStringLegacyColor(send);
}
if(mcp.getPlayer().hasPermission("venturechat.color")) {
send = FormatUtils.FormatStringColor(send);
}
if(mcp.getPlayer().hasPermission("venturechat.format")) {
send = FormatUtils.FormatString(send);
}
if(s.startsWith("Command:")) {
mcp.getPlayer().chat(s.substring(9).replace("$", send));
event.setCancelled(true);
}
if(s.startsWith("Message:")) {
mcp.getPlayer().sendMessage(s.substring(9).replace("$", send));
event.setCancelled(true);
}
if(s.startsWith("Broadcast:")) {
formatService.broadcastToServer(s.substring(11).replace("$", send));
event.setCancelled(true);
}
}
}
}
if(!configService.areAliasesRegisteredAsCommands()) {
for(ChatChannel channel : configService.getChatChannels()) {
if(!channel.hasPermission() || mcp.getPlayer().hasPermission(channel.getPermission())) {
if(message.equals("/" + channel.getAlias())) {
mcp.getPlayer().sendMessage(LocalizedMessage.SET_CHANNEL.toString()
.replace("{channel_color}", channel.getColor() + "")
.replace("{channel_name}", channel.getName()));
if(mcp.hasConversation()) {
for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) {
if(p.isSpy()) {
p.getPlayer().sendMessage(LocalizedMessage.EXIT_PRIVATE_CONVERSATION_SPY.toString()
.replace("{player_sender}", mcp.getName())
.replace("{player_receiver}", playerApiService.getMineverseChatPlayer(mcp.getConversation()).getName()));
}
}
mcp.getPlayer().sendMessage(LocalizedMessage.EXIT_PRIVATE_CONVERSATION.toString()
.replace("{player_receiver}", playerApiService.getMineverseChatPlayer(mcp.getConversation()).getName()));
mcp.setConversation(null);
}
mcp.addListening(channel.getName());
mcp.setCurrentChannel(channel);
if(channel.getBungee()) {
pluginMessageController.synchronize(mcp, true);
}
event.setCancelled(true);
return;
}
if(message.toLowerCase().startsWith("/" + channel.getAlias() + " ")) {
message = message.substring(channel.getAlias().length() + 1);
mcp.addListening(channel.getName());
if(channel.getBungee()) {
pluginMessageController.synchronize(mcp, true);
}
mcp.setQuickChannel(channel);
/*String format = "";
if(plugin.getConfig().getConfigurationSection("channels." + channel.getName()).getString("format").equalsIgnoreCase("Default")) {
format = FormatTags.ChatFormat(ChatColor.valueOf(channel.getColor().toUpperCase()) + "[" + channel.getName() + "] {prefix}{name}" + ChatColor.valueOf(channel.getColor().toUpperCase()) + ":" + ChatColor.valueOf(channel.getChatColor().toUpperCase()), mcp.getPlayer(), plugin, cc, channel, plugin.getConfig().getBoolean("jsonFormat"));
}
else {
format = FormatTags.ChatFormat(plugin.getConfig().getConfigurationSection("channels." + channel.getName()).getString("format"), mcp.getPlayer(), plugin, cc, channel, plugin.getConfig().getBoolean("jsonFormat"));
if(plugin.getConfig().getBoolean("formatcleaner", false)) {
format = format.replace("[]", " ");
format = format.replace(" ", " ").replace(" ", " ").replace(" ", " ");
}
}*/
mcp.setQuickChat(true);
mcp.getPlayer().chat(message);
event.setCancelled(true);
}
}
}
}
}
//old 1.8 command map
@EventHandler
public void onServerCommand(ServerCommandEvent event) {
if (databaseService.isEnabled()) {
databaseService.writeVentureChat("N/A", "Console", "Local", "Command_Component", event.getCommand().replace("'", "''") , "Command");
}
}
/**
* Unused
*/
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) {
plugin.getServer().getConsoleSender().sendMessage(ChatColor.RED + "This command must be run by a player.");
return true;
}
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender);
for(ChatChannel channel : configService.getChatChannels()) {
if(command.getName().toLowerCase().equals(channel.getAlias())) {
if(args.length == 0) {
mcp.getPlayer().sendMessage(ChatColor.RED + "Invalid command: /" + channel.getAlias() + " message");
return true;
}
mcp.setQuickChat(true);
mcp.setQuickChannel(channel);
mcp.addListening(channel.getName());
if(channel.getBungee()) {
pluginMessageController.synchronize(mcp, true);
}
String msg = "";
for(int x = 0; x < args.length; x++) {
if(args[x].length() > 0) msg += " " + args[x];
}
mcp.getPlayer().chat(msg);
return true;
}
}
return false;
}
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOW)
public void InventoryClick(InventoryClickEvent e) {
if(!e.getView().getTitle().contains("VentureChat")) {
return;
}
e.setCancelled(true);
ItemStack item = e.getCurrentItem();
if (item == null) {
return;
}
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) e.getWhoClicked());
String playerName = e.getView().getTitle().replace(" GUI", "").replace("VentureChat: ", "");
VentureChatPlayer target = playerApiService.getMineverseChatPlayer(playerName);
ItemStack skull = e.getInventory().getItem(0);
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
ChatChannel channel = configService.getChannel(ChatColor.stripColor(skullMeta.getLore().get(0)).replace("Channel: ", ""));
int hash = Integer.parseInt(ChatColor.stripColor(skullMeta.getLore().get(1).replace("Hash: ", "")));
if(VersionHandler.is1_7()) {
if(item.getType() == Material.BEDROCK) {
mcp.getPlayer().closeInventory();
}
}
else {
if(item.getType() == Material.BARRIER) {
mcp.getPlayer().closeInventory();
}
}
for(GuiSlot g : configService.getGuiSlots()) {
if(g.getIcon() == item.getType() && g.getDurability() == item.getDurability() && g.getSlot() == e.getSlot()) {
String command = g.getCommand().replace("{channel}", channel.getName()).replace("{hash}", hash + "");
if(target != null) {
command = command.replace("{player_name}", target.getName());
if(target.isOnline()) {
command = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(target.getPlayer(), command));
}
}
else {
command = command.replace("{player_name}", "Discord_Message");
}
mcp.getPlayer().chat(command);
}
}
}
}

View File

@ -1,219 +0,0 @@
package venture.Aust1n46.chat.initiators.listeners;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import venture.Aust1n46.chat.controllers.commands.Broadcast;
import venture.Aust1n46.chat.controllers.commands.BungeeToggle;
import venture.Aust1n46.chat.controllers.commands.Channel;
import venture.Aust1n46.chat.controllers.commands.Channelinfo;
import venture.Aust1n46.chat.controllers.commands.Chatinfo;
import venture.Aust1n46.chat.controllers.commands.Chatreload;
import venture.Aust1n46.chat.controllers.commands.Chlist;
import venture.Aust1n46.chat.controllers.commands.Chwho;
import venture.Aust1n46.chat.controllers.commands.Clearchat;
import venture.Aust1n46.chat.controllers.commands.Commandblock;
import venture.Aust1n46.chat.controllers.commands.Commandspy;
import venture.Aust1n46.chat.controllers.commands.Edit;
import venture.Aust1n46.chat.controllers.commands.Filter;
import venture.Aust1n46.chat.controllers.commands.Force;
import venture.Aust1n46.chat.controllers.commands.Forceall;
import venture.Aust1n46.chat.controllers.commands.IgnoreCommandExecutor;
import venture.Aust1n46.chat.controllers.commands.Kickchannel;
import venture.Aust1n46.chat.controllers.commands.Kickchannelall;
import venture.Aust1n46.chat.controllers.commands.Leave;
import venture.Aust1n46.chat.controllers.commands.Listen;
import venture.Aust1n46.chat.controllers.commands.Me;
import venture.Aust1n46.chat.controllers.commands.MessageCommandExecutor;
import venture.Aust1n46.chat.controllers.commands.MessageToggle;
import venture.Aust1n46.chat.controllers.commands.Mute;
import venture.Aust1n46.chat.controllers.commands.Muteall;
import venture.Aust1n46.chat.controllers.commands.Notifications;
import venture.Aust1n46.chat.controllers.commands.Party;
import venture.Aust1n46.chat.controllers.commands.RangedSpy;
import venture.Aust1n46.chat.controllers.commands.Removemessage;
import venture.Aust1n46.chat.controllers.commands.Reply;
import venture.Aust1n46.chat.controllers.commands.Setchannel;
import venture.Aust1n46.chat.controllers.commands.Setchannelall;
import venture.Aust1n46.chat.controllers.commands.Spy;
import venture.Aust1n46.chat.controllers.commands.Unmute;
import venture.Aust1n46.chat.controllers.commands.Unmuteall;
import venture.Aust1n46.chat.controllers.commands.VentureChatGui;
import venture.Aust1n46.chat.controllers.commands.Venturechat;
import venture.Aust1n46.chat.initiators.application.VentureChat;
import venture.Aust1n46.chat.model.VentureCommand;
/**
* Class that initializes and executes the plugin's commands.
*/
@Singleton
public class VentureCommandExecutor implements TabExecutor {
private Map<String, VentureCommand> commands = new HashMap<String, VentureCommand>();
@Inject
private VentureChat plugin;
@Inject
private MessageCommandExecutor messageCommandExecutor;
@Inject
private IgnoreCommandExecutor ignoreCommandExecutor;
@Inject
private Broadcast broadcast;
@Inject
private Channel channel;
@Inject
private Channelinfo channelinfo;
@Inject
private Chatinfo chatinfo;
@Inject
private Chatreload chatreload;
@Inject
private Chlist chlist;
@Inject
private Chwho chwho;
@Inject
private Clearchat clearchat;
@Inject
private Commandblock commandblock;
@Inject
private Commandspy commandspy;
@Inject
private Edit edit;
@Inject
private Filter filter;
@Inject
private Force force;
@Inject
private Forceall forceall;
@Inject
private Kickchannel kickchannel;
@Inject
private Kickchannelall kickchannelall;
@Inject
private Leave leave;
@Inject
private Listen listen;
@Inject
private Me me;
@Inject
private Venturechat venturechat;
@Inject
private Notifications notifications;
@Inject
private Party party;
@Inject
private RangedSpy rangedSpy;
@Inject
private Removemessage removemessage;
@Inject
private Setchannel setchannel;
@Inject
private Setchannelall setchannelall;
@Inject
private Spy spy;
@Inject
private VentureChatGui ventureChatGui;
@Inject
private MessageToggle messageToggle;
@Inject
private BungeeToggle bungeeToggle;
@Inject
private Reply reply;
@Inject
private Mute mute;
@Inject
private Muteall muteall;
@Inject
private Unmute unmute;
@Inject
private Unmuteall unmuteall;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] parameters) {
commands.get(command.getName()).execute(sender, command.getName(), parameters);
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return commands.get(command.getName()).onTabComplete(sender, command, label, args);
}
@Inject
public void postConstruct() {
commands.put("broadcast", broadcast);
commands.put("channel", channel);
commands.put("join", channel);
commands.put("channelinfo", channelinfo);
commands.put("chatinfo", chatinfo);
commands.put("chatreload", chatreload);
commands.put("chlist", chlist);
commands.put("chwho", chwho);
commands.put("clearchat", clearchat);
commands.put("commandblock", commandblock);
commands.put("commandspy", commandspy);
commands.put("edit", edit);
commands.put("filter", filter);
commands.put("force", force);
commands.put("forceall", forceall);
commands.put("kickchannel", kickchannel);
commands.put("kickchannelall", kickchannelall);
commands.put("leave", leave);
commands.put("listen", listen);
commands.put("me", me);
commands.put("venturechat", venturechat);
commands.put("notifications", notifications);
commands.put("party", party);
commands.put("rangedspy", rangedSpy);
commands.put("removemessage", removemessage);
commands.put("setchannel", setchannel);
commands.put("setchannelall", setchannelall);
commands.put("spy", spy);
commands.put("venturechatgui", ventureChatGui);
commands.put("messagetoggle", messageToggle);
commands.put("bungeetoggle", bungeeToggle);
for (String command : commands.keySet()) {
registerCommand(command, this);
}
plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
if (plugin.isEnabled()) {
commands.put("reply", reply);
commands.put("r", reply);
registerCommand("reply", this);
registerCommand("r", this);
commands.put("mute", mute);
commands.put("muteall", muteall);
commands.put("unmute", unmute);
commands.put("unmuteall", unmuteall);
registerCommand("mute", this);
registerCommand("muteall", this);
registerCommand("unmute", this);
registerCommand("unmuteall", this);
registerCommand("message", messageCommandExecutor);
registerCommand("msg", messageCommandExecutor);
registerCommand("tell", messageCommandExecutor);
registerCommand("whisper", messageCommandExecutor);
registerCommand("ignore", ignoreCommandExecutor);
}
}, 0);
}
private void registerCommand(String command, CommandExecutor commandExecutor) {
if (plugin.getCommand(command) != null) {
plugin.getCommand(command).setExecutor(commandExecutor);
}
}
}