From 773277cb276706233daa9a117ec0b641b3aecdcb Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 22 Jul 2019 22:23:35 +0200 Subject: [PATCH] A few fixes --- ...Maven__net_bytebuddy_byte_buddy_1_6_11.xml | 13 -- ..._net_bytebuddy_byte_buddy_agent_1_6_11.xml | 13 -- ...Maven__org_mockito_mockito_core_2_7_20.xml | 13 -- .../Maven__org_objenesis_objenesis_2_5.xml | 13 -- BuildConfigUpdater/BuildConfigUpdater.iml | 18 +-- ButtonCore/pom.xml | 2 +- .../buttondevteam/lib/chat/Command2MC.java | 5 +- .../buttondevteam/lib/chat/TBMCChatAPI.java | 122 +++++++++--------- 8 files changed, 65 insertions(+), 134 deletions(-) delete mode 100755 .idea/libraries/Maven__net_bytebuddy_byte_buddy_1_6_11.xml delete mode 100755 .idea/libraries/Maven__net_bytebuddy_byte_buddy_agent_1_6_11.xml delete mode 100755 .idea/libraries/Maven__org_mockito_mockito_core_2_7_20.xml delete mode 100755 .idea/libraries/Maven__org_objenesis_objenesis_2_5.xml diff --git a/.idea/libraries/Maven__net_bytebuddy_byte_buddy_1_6_11.xml b/.idea/libraries/Maven__net_bytebuddy_byte_buddy_1_6_11.xml deleted file mode 100755 index b956618..0000000 --- a/.idea/libraries/Maven__net_bytebuddy_byte_buddy_1_6_11.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__net_bytebuddy_byte_buddy_agent_1_6_11.xml b/.idea/libraries/Maven__net_bytebuddy_byte_buddy_agent_1_6_11.xml deleted file mode 100755 index dbbe456..0000000 --- a/.idea/libraries/Maven__net_bytebuddy_byte_buddy_agent_1_6_11.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_mockito_mockito_core_2_7_20.xml b/.idea/libraries/Maven__org_mockito_mockito_core_2_7_20.xml deleted file mode 100755 index db215ab..0000000 --- a/.idea/libraries/Maven__org_mockito_mockito_core_2_7_20.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_objenesis_objenesis_2_5.xml b/.idea/libraries/Maven__org_objenesis_objenesis_2_5.xml deleted file mode 100755 index 57448b4..0000000 --- a/.idea/libraries/Maven__org_objenesis_objenesis_2_5.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/BuildConfigUpdater/BuildConfigUpdater.iml b/BuildConfigUpdater/BuildConfigUpdater.iml index 15937e7..df2c815 100644 --- a/BuildConfigUpdater/BuildConfigUpdater.iml +++ b/BuildConfigUpdater/BuildConfigUpdater.iml @@ -12,23 +12,13 @@ - - - - - - - - - - - - - - + + + + diff --git a/ButtonCore/pom.xml b/ButtonCore/pom.xml index db16155..568f662 100755 --- a/ButtonCore/pom.xml +++ b/ButtonCore/pom.xml @@ -160,7 +160,7 @@ org.mockito mockito-core - 2.7.20 + 3.0.0 diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java index aac9cc9..ff1b5f1 100644 --- a/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/Command2MC.java @@ -1,7 +1,6 @@ package buttondevteam.lib.chat; import buttondevteam.core.MainPlugin; -import lombok.experimental.var; import lombok.val; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; @@ -127,7 +126,7 @@ public class Command2MC extends Command2 implemen //System.out.println("tab"); for (int i = commandline.length(); i != -1; i = commandline.lastIndexOf(' ', i - 1)) { String subcommand = commandline.substring(0, i).toLowerCase(); - if (subcommand.charAt(0) != '/') subcommand = '/' + subcommand; //Console + if (subcommand.length() == 0 || subcommand.charAt(0) != '/') subcommand = '/' + subcommand; //Console //System.out.println("Subcommand: " + subcommand); SubcommandData sd = subcommands.get(subcommand); //O(1) if (sd == null) continue; @@ -183,7 +182,7 @@ public class Command2MC extends Command2 implemen } } if (paramArr[i1].isVarArgs()) { - params.add(commandline.substring(j + 1).split(" +")); + par0ams.add(commandline.substring(j + 1).split(" +")); continue; } j = commandline.indexOf(' ', j + 1); //End index diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java index f164d91..2ba2190 100755 --- a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java @@ -26,10 +26,11 @@ import java.util.HashMap; import java.util.Map.Entry; import java.util.Set; import java.util.function.Consumer; +import java.util.function.Supplier; public class TBMCChatAPI { - private static final HashMap commands = new HashMap<>(); + private static final HashMap commands = new HashMap<>(); public static HashMap GetCommands() { return commands; @@ -38,10 +39,8 @@ public class TBMCChatAPI { /** * Returns messages formatted for Minecraft chat listing the subcommands of the command. * - * @param command - * The command which we want the subcommands of - * @param sender - * The sender for permissions + * @param command The command which we want the subcommands of + * @param sender The sender for permissions * @return The subcommands */ public static String[] GetSubCommands(TBMCCommandBase command, CommandSender sender) { @@ -52,10 +51,8 @@ public class TBMCChatAPI { * Returns messages formatted for Minecraft chat listing the subcommands of the command.
* Returns a header if subcommands were found, otherwise returns an empty array. * - * @param command - * The command which we want the subcommands of - * @param sender - * The sender for permissions + * @param command The command which we want the subcommands of + * @param sender The sender for permissions * @return The subcommands */ public static String[] GetSubCommands(String command, CommandSender sender) { @@ -69,7 +66,7 @@ public class TBMCChatAPI { if (cmd.getKey().startsWith(command + " ")) { if (cmd.getValue().isPlayerOnly() && !(sender instanceof Player)) continue; - if (cmd.getValue().isModOnly() && (MainPlugin.permission != null ? !MainPlugin.permission.has(sender, "tbmc.admin") : !sender.isOp())) + if (cmd.getValue().isModOnly() && (MainPlugin.permission != null ? !MainPlugin.permission.has(sender, "tbmc.admin") : !sender.isOp())) continue; int ind = cmd.getKey().indexOf(' ', command.length() + 2); if (ind >= 0) { @@ -80,7 +77,7 @@ public class TBMCChatAPI { addToCmds.accept("/" + cmd.getKey()); } } - return cmds.toArray(new String[0]); //Apparently it's faster to use an empty array in modern Java + return cmds.toArray(new String[0]); //Apparently it's faster to use an empty array in modern Java } /** @@ -96,22 +93,20 @@ public class TBMCChatAPI { *

* Using this method after the server is done loading will have no effect. *

- * - * @param plugin - * The caller plugin - * @param acmdclass - * A command's class to get the package name for commands. The provided class's package and subpackages are scanned for commands. + * + * @param plugin The caller plugin + * @param acmdclass A command's class to get the package name for commands. The provided class's package and subpackages are scanned for commands. */ public static synchronized void AddCommands(JavaPlugin plugin, Class acmdclass) { plugin.getLogger().info("Registering commands from " + acmdclass.getPackage().getName()); Reflections rf = new Reflections(new ConfigurationBuilder() - .setUrls(ClasspathHelper.forPackage(acmdclass.getPackage().getName(), - plugin.getClass().getClassLoader())) - .addUrls( - ClasspathHelper.forClass(OptionallyPlayerCommandBase.class, - OptionallyPlayerCommandBase.class.getClassLoader()), - ClasspathHelper.forClass(PlayerCommandBase.class, PlayerCommandBase.class.getClassLoader())) // http://stackoverflow.com/questions/12917417/using-reflections-for-finding-the-transitive-subtypes-of-a-class-when-not-all - .addClassLoader(plugin.getClass().getClassLoader()).addScanners(new SubTypesScanner())); + .setUrls(ClasspathHelper.forPackage(acmdclass.getPackage().getName(), + plugin.getClass().getClassLoader())) + .addUrls( + ClasspathHelper.forClass(OptionallyPlayerCommandBase.class, + OptionallyPlayerCommandBase.class.getClassLoader()), + ClasspathHelper.forClass(PlayerCommandBase.class, PlayerCommandBase.class.getClassLoader())) // http://stackoverflow.com/questions/12917417/using-reflections-for-finding-the-transitive-subtypes-of-a-class-when-not-all + .addClassLoader(plugin.getClass().getClassLoader()).addScanners(new SubTypesScanner())); Set> cmds = rf.getSubTypesOf(TBMCCommandBase.class); for (Class cmd : cmds) { try { @@ -139,19 +134,17 @@ public class TBMCChatAPI { *

* Using this method after the server is done loading will have no effect. *

- * - * @param plugin - * The caller plugin - * @param thecmdclass - * The command's class to create it (because why let you create the command class) + * + * @param plugin The caller plugin + * @param thecmdclass The command's class to create it (because why let you create the command class) */ public static void AddCommand(JavaPlugin plugin, Class thecmdclass, Object... params) { // plugin.getLogger().info("Registering command " + thecmdclass.getSimpleName() + " for " + plugin.getName()); try { TBMCCommandBase c; if (params.length > 0) - c = thecmdclass.getConstructor(Arrays.stream(params).map(Object::getClass).toArray(Class[]::new)) - .newInstance(params); + c = thecmdclass.getConstructor(Arrays.stream(params).map(Object::getClass).toArray(Class[]::new)) + .newInstance(params); else c = thecmdclass.newInstance(); c.plugin = plugin; @@ -173,10 +166,8 @@ public class TBMCChatAPI { * Using this method after the server is done loading will have no effect. *

* - * @param plugin - * The caller plugin - * @param cmd - * The command to add + * @param plugin The caller plugin + * @param cmd The command to add */ public static void AddCommand(JavaPlugin plugin, TBMCCommandBase cmd) { try { @@ -259,14 +250,14 @@ public class TBMCChatAPI { /** * Sends a chat message to Minecraft. Make sure that the channel is registered with {@link #RegisterChatChannel(Channel)}.
- * This will also send the error message to the sender, if they can't send the message. + * This will also send the error message to the sender, if they can't send the message. * - * @param cm The message to send + * @param cm The message to send * @return The event cancelled state */ - public static boolean SendChatMessage(ChatMessage cm) { - return SendChatMessage(cm, cm.getUser().channel().get()); - } + public static boolean SendChatMessage(ChatMessage cm) { + return SendChatMessage(cm, cm.getUser().channel().get()); + } /** * Sends a chat message to Minecraft. Make sure that the channel is registered with {@link #RegisterChatChannel(Channel)}.
@@ -278,36 +269,40 @@ public class TBMCChatAPI { */ public static boolean SendChatMessage(ChatMessage cm, Channel channel) { if (!Channel.getChannelList().contains(channel)) - throw new RuntimeException("Channel " + channel.DisplayName().get() + " not registered!"); + throw new RuntimeException("Channel " + channel.DisplayName().get() + " not registered!"); if (!channel.Enabled().get()) { cm.getSender().sendMessage("§cThe channel '" + channel.DisplayName().get() + "' is disabled!"); return true; //Cancel sending if channel is disabled } - val permcheck = cm.getPermCheck(); - RecipientTestResult rtr = getScoreOrSendError(channel, permcheck); - int score = rtr.score; - if (score == Channel.SCORE_SEND_NOPE || rtr.groupID == null) - return true; - TBMCChatPreprocessEvent eventPre = new TBMCChatPreprocessEvent(cm.getSender(), channel, cm.getMessage()); - Bukkit.getPluginManager().callEvent(eventPre); - if (eventPre.isCancelled()) - return true; - cm.setMessage(eventPre.getMessage()); - TBMCChatEvent event; - event = new TBMCChatEvent(channel, cm, rtr); - Bukkit.getPluginManager().callEvent(event); - return event.isCancelled(); + Supplier task = () -> { + val permcheck = cm.getPermCheck(); + RecipientTestResult rtr = getScoreOrSendError(channel, permcheck); + int score = rtr.score; + if (score == Channel.SCORE_SEND_NOPE || rtr.groupID == null) + return true; + TBMCChatPreprocessEvent eventPre = new TBMCChatPreprocessEvent(cm.getSender(), channel, cm.getMessage()); + Bukkit.getPluginManager().callEvent(eventPre); + if (eventPre.isCancelled()) + return true; + cm.setMessage(eventPre.getMessage()); + TBMCChatEvent event; + event = new TBMCChatEvent(channel, cm, rtr); + Bukkit.getPluginManager().callEvent(event); + return event.isCancelled(); + }; + if (Bukkit.isPrimaryThread()) + Bukkit.getScheduler().runTaskAsynchronously(MainPlugin.Instance, task::get); + else + return task.get(); + return false; //Not cancelled if async } /** * Sends a regular message to Minecraft. Make sure that the channel is registered with {@link #RegisterChatChannel(Channel)}. - * - * @param channel - * The channel to send to - * @param rtr - * The score&group to use to find the group - use {@link RecipientTestResult#ALL} if the channel doesn't have scores - * @param message - * The message to send + * + * @param channel The channel to send to + * @param rtr The score&group to use to find the group - use {@link RecipientTestResult#ALL} if the channel doesn't have scores + * @param message The message to send * @param exceptions Platforms where this message shouldn't be sent (same as {@link ChatMessage#getOrigin()} * @return The event cancelled state */ @@ -332,9 +327,8 @@ public class TBMCChatAPI { /** * Register a chat channel. See {@link Channel#Channel(String, Color, String, java.util.function.Function)} for details. - * - * @param channel - * A new {@link Channel} to register + * + * @param channel A new {@link Channel} to register */ public static void RegisterChatChannel(Channel channel) { Channel.RegisterChannel(channel);