Working iteration.

This commit is contained in:
Aust1n46 2022-01-17 03:26:47 -06:00
parent f87817338a
commit 5ff71b4eeb
7 changed files with 247 additions and 287 deletions

View File

@ -1,3 +1 @@
/org.eclipse.jdt.core.prefs
/org.eclipse.core.resources.prefs
/org.eclipse.m2e.core.prefs

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>mineverse.Aust1n46.chat</groupId>
<artifactId>VentureChat</artifactId>
<version>3.2.3</version>
<version>3.3.0</version>
<url>https://bitbucket.org/Aust1n46/venturechat/src/master</url>
<scm>
<url>https://bitbucket.org/Aust1n46/venturechat/src/master</url>

View File

@ -1,13 +1,23 @@
package mineverse.Aust1n46.chat.command;
import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.command.TabExecutor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import mineverse.Aust1n46.chat.MineverseChat;
import mineverse.Aust1n46.chat.command.chat.Broadcast;
@ -38,8 +48,8 @@ import mineverse.Aust1n46.chat.command.chat.Setchannel;
import mineverse.Aust1n46.chat.command.chat.Setchannelall;
import mineverse.Aust1n46.chat.command.chat.VentureChatGui;
import mineverse.Aust1n46.chat.command.chat.Venturechat;
import mineverse.Aust1n46.chat.command.message.IgnoreCommandExecutor;
import mineverse.Aust1n46.chat.command.message.MessageCommandExecutor;
import mineverse.Aust1n46.chat.command.message.Ignore;
import mineverse.Aust1n46.chat.command.message.Message;
import mineverse.Aust1n46.chat.command.message.MessageToggle;
import mineverse.Aust1n46.chat.command.message.Notifications;
import mineverse.Aust1n46.chat.command.message.Reply;
@ -48,18 +58,24 @@ import mineverse.Aust1n46.chat.command.mute.Mute;
import mineverse.Aust1n46.chat.command.mute.Muteall;
import mineverse.Aust1n46.chat.command.mute.Unmute;
import mineverse.Aust1n46.chat.command.mute.Unmuteall;
import mineverse.Aust1n46.chat.utilities.Format;
/**
* Class that initializes and executes the plugin's commands.
*/
public class VentureCommandExecutor implements TabExecutor {
private static Map<String, VentureCommand> commands = new HashMap<String, VentureCommand>();
private static MineverseChat plugin = MineverseChat.getInstance();
private static final String VERSION = "3.3.0";
private static final Map<String, VentureCommand> commands = new HashMap<>();
private static final MineverseChat plugin = MineverseChat.getInstance();
private static VentureCommandExecutor commandExecutor;
private static Map<String, Command> knownCommands;
private static Constructor<PluginCommand> pluginCommandConstructor;
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] parameters) {
commands.get(command.getName()).execute(sender, command.getName(), parameters);
command.execute(sender, label, parameters);
return true;
}
@ -67,12 +83,46 @@ public class VentureCommandExecutor implements TabExecutor {
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return commands.get(command.getName()).onTabComplete(sender, command, label, args);
}
@SuppressWarnings("unchecked")
public static void initialize() {
commandExecutor = new VentureCommandExecutor();
final Server server = plugin.getServer();
final File commandsFile = new File(plugin.getDataFolder().getAbsolutePath(), "commands.yml");
if (!commandsFile.isFile()) {
plugin.saveResource("commands.yml", true);
}
FileConfiguration commandsFileConfiguration = YamlConfiguration.loadConfiguration(commandsFile);
final String fileVersion = commandsFileConfiguration.getString("Version", "null");
if (!fileVersion.equals(VERSION)) {
server.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Version Change Detected! Saving Old commands.yml and Generating Latest File"));
commandsFile.renameTo(new File(plugin.getDataFolder().getAbsolutePath(), "commands_old_" + fileVersion + ".yml"));
plugin.saveResource("commands.yml", true);
commandsFileConfiguration = YamlConfiguration.loadConfiguration(commandsFile);
}
try {
knownCommands = server.getCommandMap().getKnownCommands(); // Paper :)
}
// Spigot :(
catch (final NoSuchMethodError error) {
try {
final Field commandMapField = server.getClass().getDeclaredField("commandMap");
commandMapField.setAccessible(true);
final SimpleCommandMap simpleCommandMap = (SimpleCommandMap) commandMapField.get(server);
final Field knownCommandsField = SimpleCommandMap.class.getDeclaredField("knownCommands");
knownCommandsField.setAccessible(true);
knownCommands = (Map<String, Command>) knownCommandsField.get(simpleCommandMap);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
try {
pluginCommandConstructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
pluginCommandConstructor.setAccessible(true);
} catch (NoSuchMethodException | SecurityException e) {
e.printStackTrace();
}
commands.put("broadcast", new Broadcast());
commands.put("channel", new Channel());
commands.put("join", new Channel());
commands.put("channelinfo", new Channelinfo());
commands.put("chatinfo", new Chatinfo());
commands.put("chatreload", new Chatreload());
@ -102,39 +152,53 @@ public class VentureCommandExecutor implements TabExecutor {
commands.put("venturechatgui", new VentureChatGui());
commands.put("messagetoggle", new MessageToggle());
commands.put("bungeetoggle", new BungeeToggle());
for(String command : commands.keySet()) {
commands.put("mute", new Mute());
commands.put("muteall", new Muteall());
commands.put("unmute", new Unmute());
commands.put("unmuteall", new Unmuteall());
commands.put("reply", new Reply());
commands.put("message", new Message());
commands.put("ignore", new Ignore());
final ConfigurationSection commandsSection = commandsFileConfiguration.getConfigurationSection("commands");
for (final String commandLabel : commandsSection.getKeys(false)) {
final ConfigurationSection commandSection = commandsSection.getConfigurationSection(commandLabel);
final boolean isEnabled = commandSection.getBoolean("enabled", true);
if (!isEnabled) {
commands.remove(commandLabel);
} else {
final VentureCommand command = commands.get(commandLabel);
if (command != null) {
final List<String> aliases = commandSection.getStringList("aliases");
for (final String alias : aliases) {
commands.put(alias, command);
}
commands.put("venturechat:" + commandLabel, command);
}
}
}
commandExecutor = new VentureCommandExecutor();
// Initial registration is required to ensure commands are recognized by the
// server after enabling every plugin
for (final String command : commands.keySet()) {
registerCommand(command, commandExecutor);
}
plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
VentureCommand reply = new Reply();
commands.put("reply", reply);
commands.put("r", reply);
registerCommand("reply", commandExecutor);
registerCommand("r", commandExecutor);
commands.put("mute", new Mute());
commands.put("muteall", new Muteall());
commands.put("unmute", new Unmute());
commands.put("unmuteall", new Unmuteall());
registerCommand("mute", commandExecutor);
registerCommand("muteall", commandExecutor);
registerCommand("unmute", commandExecutor);
registerCommand("unmuteall", commandExecutor);
MessageCommandExecutor messageCommandExecutor = new MessageCommandExecutor();
registerCommand("message", messageCommandExecutor);
registerCommand("msg", messageCommandExecutor);
registerCommand("tell", messageCommandExecutor);
registerCommand("whisper", messageCommandExecutor);
registerCommand("ignore", new IgnoreCommandExecutor());
}, 0);
// Forcibly re-register enabled VentureChat commands on a delay to ensure they
// have priority
server.getScheduler().runTaskLater(plugin, () -> {
for (final String command : commands.keySet()) {
registerCommand(command, commandExecutor);
}
}, 10);
}
private static void registerCommand(String command, CommandExecutor commandExecutor) {
if(plugin.getCommand(command) != null) {
plugin.getCommand(command).setExecutor(commandExecutor);
private static void registerCommand(String command, TabExecutor tabExecutor) {
try {
final PluginCommand pluginCommand = pluginCommandConstructor.newInstance(command, plugin);
pluginCommand.setExecutor(tabExecutor);
pluginCommand.setTabCompleter(tabExecutor);
knownCommands.put(command, pluginCommand);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
}
}

View File

@ -10,28 +10,28 @@ import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import mineverse.Aust1n46.chat.MineverseChat;
import mineverse.Aust1n46.chat.api.MineverseChatAPI;
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
import mineverse.Aust1n46.chat.command.VentureCommand;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
public class IgnoreCommandExecutor implements TabExecutor {
public class Ignore implements VentureCommand {
private MineverseChat plugin = MineverseChat.getInstance();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public void execute(CommandSender sender, String command, String[] args) {
if (!(sender instanceof Player)) {
plugin.getServer().getConsoleSender().sendMessage(LocalizedMessage.COMMAND_MUST_BE_RUN_BY_PLAYER.toString());
return true;
return;
}
MineverseChatPlayer mcp = MineverseChatAPI.getOnlineMineverseChatPlayer((Player) sender);
if (args.length == 0) {
mcp.getPlayer().sendMessage(LocalizedMessage.COMMAND_INVALID_ARGUMENTS_IGNORE.toString());
return true;
return;
}
if (args[0].equalsIgnoreCase("list")) {
String ignoreList = "";
@ -47,11 +47,11 @@ public class IgnoreCommandExecutor implements TabExecutor {
if (ignoreList.length() > 0) {
mcp.getPlayer().sendMessage(ignoreList.substring(0, ignoreList.length() - 2));
}
return true;
return;
}
if (mcp.getName().equalsIgnoreCase(args[0])) {
mcp.getPlayer().sendMessage(LocalizedMessage.IGNORE_YOURSELF.toString());
return true;
return;
}
if (plugin.getConfig().getBoolean("bungeecordmessaging", true)) {
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
@ -66,32 +66,32 @@ public class IgnoreCommandExecutor implements TabExecutor {
} catch (Exception e) {
e.printStackTrace();
}
return true;
return;
}
MineverseChatPlayer player = MineverseChatAPI.getOnlineMineverseChatPlayer(args[0]);
if (player == null) {
mcp.getPlayer().sendMessage(LocalizedMessage.PLAYER_OFFLINE.toString()
.replace("{args}", args[0]));
return true;
return;
}
if (mcp.getIgnores().contains(player.getUUID())) {
mcp.getPlayer().sendMessage(LocalizedMessage.IGNORE_PLAYER_OFF.toString()
.replace("{player}", player.getName()));
mcp.removeIgnore(player.getUUID());
MineverseChat.synchronize(mcp, true);
return true;
return;
}
if (player.getPlayer().hasPermission("venturechat.ignore.bypass")) {
mcp.getPlayer().sendMessage(LocalizedMessage.IGNORE_PLAYER_CANT.toString()
.replace("{player}", player.getName()));
return true;
return;
}
mcp.getPlayer().sendMessage(LocalizedMessage.IGNORE_PLAYER_ON.toString()
.replace("{player}", player.getName()));
mcp.addIgnore(player.getUUID());
MineverseChat.synchronize(mcp, true);
return true;
return;
}
@Override

View File

@ -8,7 +8,6 @@ import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
@ -16,52 +15,53 @@ import me.clip.placeholderapi.PlaceholderAPI;
import mineverse.Aust1n46.chat.MineverseChat;
import mineverse.Aust1n46.chat.api.MineverseChatAPI;
import mineverse.Aust1n46.chat.api.MineverseChatPlayer;
import mineverse.Aust1n46.chat.command.VentureCommand;
import mineverse.Aust1n46.chat.localization.LocalizedMessage;
import mineverse.Aust1n46.chat.utilities.Format;
public class MessageCommandExecutor implements TabExecutor {
public class Message implements VentureCommand {
private MineverseChat plugin = MineverseChat.getInstance();
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
public void execute(CommandSender sender, String command, String[] args) {
if (!(sender instanceof Player)) {
plugin.getServer().getConsoleSender().sendMessage(LocalizedMessage.COMMAND_MUST_BE_RUN_BY_PLAYER.toString());
return true;
return;
}
MineverseChatPlayer mcp = MineverseChatAPI.getOnlineMineverseChatPlayer((Player) sender);
if (args.length == 0) {
mcp.getPlayer().sendMessage(LocalizedMessage.COMMAND_INVALID_ARGUMENTS.toString()
.replace("{command}", "/" + command.getName())
.replace("{command}", "/" + command)
.replace("{args}", "[player] [message]"));
return true;
return;
}
if (plugin.getConfig().getBoolean("bungeecordmessaging", true)) {
sendBungeeCordMessage(mcp, command.getName(), args);
return true;
sendBungeeCordMessage(mcp, command, args);
return;
}
MineverseChatPlayer player = MineverseChatAPI.getOnlineMineverseChatPlayer(args[0]);
if (player == null) {
mcp.getPlayer().sendMessage(LocalizedMessage.PLAYER_OFFLINE.toString()
.replace("{args}", args[0]));
return true;
return;
}
if (!mcp.getPlayer().canSee(player.getPlayer())) {
mcp.getPlayer().sendMessage(LocalizedMessage.PLAYER_OFFLINE.toString()
.replace("{args}", args[0]));
return true;
return;
}
if (player.getIgnores().contains(mcp.getUUID())) {
mcp.getPlayer().sendMessage(LocalizedMessage.IGNORING_MESSAGE.toString()
.replace("{player}", player.getName()));
return true;
return;
}
if (!player.getMessageToggle()) {
mcp.getPlayer().sendMessage(LocalizedMessage.BLOCKING_MESSAGE.toString()
.replace("{player}", player.getName()));
return true;
return;
}
if (args.length >= 2) {
@ -150,7 +150,7 @@ public class MessageCommandExecutor implements TabExecutor {
}
}
}
return true;
return;
}
@Override

View File

@ -0,0 +1,119 @@
Version: 3.3.0
# Restart server after editing this file!!!
# Restart server after editing this file!!!
# Restart server after editing this file!!!
commands:
message:
aliases: [vmessage,msg,tell,whisper,pm]
enabled: true
ignore:
aliases: [vignore]
enabled: true
reply:
aliases: [vreply,r]
enabled: true
spy:
aliases: [vspy]
enabled: true
mute:
aliases: [mp,vmute]
enabled: true
unmute:
aliases: [ump,vunmute]
enabled: true
muteall:
aliases: [mpa,vmuteall]
enabled: true
unmuteall:
aliases: [umpa,vunmuteall]
enabled: true
channel:
aliases: [ch,vchannel,join]
enabled: true
listen:
aliases: [lis,vlisten]
enabled: true
leave:
aliases: [lev,vleave]
enabled: true
chlist:
aliases: [chl,vchlist]
enabled: true
chwho:
aliases: [chw,vchwho]
enabled: true
setchannel:
aliases: [sc,vsetchannel]
enabled: true
kickchannel:
aliases: [kc,vkickchannel]
enabled: true
kickchannelall:
aliases: [kca,vkickchannelall]
enabled: true
setchannelall:
aliases: [sca,vsetchannelall]
enabled: true
force:
aliases: [for,vforce]
enabled: true
forceall:
aliases: [fora,vforceall]
enabled: true
chatreload:
aliases: [cr,vchatreload]
enabled: true
commandspy:
aliases: [comspy,vcommandspy]
enabled: true
chatinfo:
aliases: [ci,vchatinfo]
enabled: true
channelinfo:
aliases: [chi,vchannelinfo]
enabled: true
venturechat:
aliases: [vc]
enabled: true
me:
aliases: [vme]
enabled: true
filter:
aliases: [fil,vfilter]
enabled: true
broadcast:
aliases: [bc,vbroadcast]
enabled: true
commandblock:
aliases: [cb,vcommandblock]
enabled: true
party:
aliases: [p,chatparty,cp,vparty]
enabled: true
clearchat:
aliases: [cc,vclearchat]
enabled: true
notifications:
aliases: [notify,vnotify]
enabled: true
removemessage:
aliases: [rm,vremovemessage]
enabled: true
rangedspy:
aliases: [rspy,vrangedspy]
enabled: true
venturechatgui:
aliases: [vchatgui]
enabled: true
messagetoggle:
aliases: [mtoggle,vmessagetoggle]
enabled: true
bungeetoggle:
aliases: [btoggle,vbungeetoggle]
enabled: true
config:
aliases: [vconfig]
enabled: false
edit:
aliases: [vedit]
enabled: false

View File

@ -7,224 +7,3 @@ softdepend: [Towny, Factions, EssentialsDiscord]
author: Aust1n46
website: https://bitbucket.org/Aust1n46/venturechat/
description: #1 Channels Chat plugin! Spigot + Bungee. Supports PlaceholderAPI + JSON formatting. Moderation GUI!
commands:
mute:
usage: /mute [playername] [channel]
aliases: [mp,vmute]
description: Mutes player in a channel so they cannot talk.
permission-message: You don't have <permission>
unmute:
usage: /unmute [playername] [channel]
aliases: [ump,vunmute]
description: Unmutes player in a channel so they can talk again.
permission-message: You don't have <permission>
msg:
usage: /msg [playername] [msg]
aliases: [vmsg]
description: Send a message to a player
permission-message: You don't have <permission>
tell:
usage: /tell [playername] [msg]
aliases: [vtell]
description: Send a message to a player
permission-message: You don't have <permission>
whisper:
usage: /whisper [playername] [msg]
aliases: [vwhisper,w]
description: Send a message to a player
permission-message: You don't have <permission>
message:
usage: /message [playername] [msg]
aliases: [vmessage,pm]
description: Send a message to a player
permission-message: You don't have <permission>
ignore:
usage: /ignore [playername] or /ignore ? for more information
aliases: [vignore]
description: This allows you to prevent a player from sending you a tell /ignore list to see who you have ignored
permission-message: You don't have <permission>
channel:
usage: /channel [channelname]
aliases: [ch,vchannel]
description: Allows players to add the ability to listen to the channel
permission-message: You don't have <permission>
leave:
usage: /leave [channelname]
aliases: [lev,vleave]
description: Allows players to leave listening to a channel
permission-message: You don't have <permission>
join:
usage: /join [channelname]
aliases: [vjoin]
description: Allows players to join a channel
permission-message: You don't have <permission>
chlist:
usage: /chlist
aliases: [chl,vchlist]
description: Allows players to see a listing of available channels
permission-message: You don't have <permission>
chwho:
usage: /chwho [channelname]
aliases: [chw,vchwho]
description: Allows players to see a listing of who is listening on a channel
permission-message: You don't have <permission>
setchannel:
usage: /setchannel [playername] [channel]
aliases: [sc,vsetchannel]
description: Sets a players channel
permission-message: You don't have <permission>
kickchannel:
usage: /kickchannel [playername] [channel]
aliases: [kc,vkickchannel]
description: Kicks a player out of a channel
permission-message: You don't have <permission>
muteall:
usage: /muteall [playername]
aliases: [mpa,vmuteall]
description: Mute a player in all channels
permission-message: You don't have <permission>
unmuteall:
usage: /unmuteall [playername]
aliases: [umpa,vunmuteall]
description: Unmute a player in all channels
permission-message: You don't have <permission>
kickchannelall:
usage: /kickchannelall [playername]
aliases: [kca,vkickchannelall]
description: Kick a player from all channels
permission-message: You don't have <permission>
setchannelall:
usage: /setchannelall [playername]
aliases: [sca,vsetchannelall]
description: Set a player into all channels
permission-message: You don't have <permission>
force:
usage: /force [playername] [message]
aliases: [for,vforce]
description: Force a player to chat or execute a command
permission-message: You don't have <permission>
forceall:
usage: /forceall [message]
aliases: [fora,vforceall]
description: Force all players to chat or execute a command
permission-message: You don't have <permission>
listen:
usage: /listen [channel]
aliases: [lis,vlisten]
description: Listen to a channel without setting it as the one your chatting in
permission-message: You don't have <permission>
chatreload:
usage: /chatreload
aliases: [cr,vchatreload]
description: Reload the config file
permission-message: You don't have <permission>
reply:
usage: /reply [msg]
aliases: [vreply]
description: Reply to a message
permission-message: You don't have <permission>
r:
usage: /r [msg]
aliases: []
description: Reply to a message
permission-message: You don't have <permission>
spy:
usage: /spy
aliases: [vspy]
description: Spy on tells
permission-message: You don't have <permission>
commandspy:
usage: /commandspy
aliases: [comspy,vcommandspy]
description: Spy on commands
permission-message: You don't have <permission>
chatinfo:
usage: /chatinfo
aliases: [ci,vchatinfo]
description: Check a players chat info
permission-message: You don't have <permission>
channelinfo:
usage: /channelinfo
aliases: [chi,vchannelinfo]
description: Check a channels info
permission-message: You don't have <permission>
venturechat:
usage: /venturechat
aliases: [vc]
description: Check plugin information
permission-message: You don't have <permission>
me:
usage: /me
aliases: [vme]
description: Send an emote
permission-message: You don't have <permission>
filter:
usage: /filter
aliases: [fil,vfilter]
description: Toggle filter on and off
permission-message: You don't have <permission>
broadcast:
usage: /broadcast [msg]
aliases: [bc,vbroadcast]
description: Broadcast a message
permission-message: You don't have <permission>
commandblock:
usage: /commandblock [player] [command]
aliases: [cb,vcommandblock]
description: Toggle a player blocked from entering a command
permission-message: You don't have <permission>
party:
usage: /party help
aliases: [p,chatparty,cp,vparty]
description: Party commands
permission-message: You don't have <permission>
config:
usage: /config help
aliases: [vconfig]
description: Edit commands
permission-message: You don't have <permission>
clearchat:
usage: /clearchat
aliases: [cc,vclearchat]
description: Clear every players chat
permission-message: You don't have <permission>
notifications:
usage: /notifications
aliases: [notify,vnotify]
description: Toggles your notifications
permission-message: You don't have <permission>
removemessage:
usage: /removemessage [hashcode]
aliases: [rm,vremovemessage]
description: Remove a message from the chat
permission-message: You don't have <permission>
edit:
usage: /<command>
aliases: [vedit]
description: Edit your last chat message
permission-message: You don't have <permission>
rangedspy:
usage: /<command>
aliases: [rspy,vrangedspy]
description: Toggle spying on ranged channels
permission-message: You don't have <permission>
buttons:
usage: /<command>
aliases: [vbuttons]
description: Toggle viewing json buttons
permission-message: You don't have <permission>
venturechatgui:
usage: /<command>
aliases: [vchatgui]
description: Opens the chat management gui
permission-message: You don't have <permission>
messagetoggle:
usage: /<command>
aliases: [mtoggle,vmessagetoggle]
description: Toggle receiving messages
permission-message: You don't have <permission>
bungeetoggle:
usage: /<command>
aliases: [btoggle,vbungeetoggle]
description: Toggle receiving BungeeCord chat
permission-message: You don't have <permission>