diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..0871a5f --- /dev/null +++ b/build.gradle @@ -0,0 +1,26 @@ +apply plugin: 'java' + +//noinspection GroovyUnusedAssignment +sourceCompatibility = 1.8 +version = '2.5' + +repositories { + jcenter() + maven { url 'https://hub.spigotmc.org/nexus/content/groups/public' } + maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } +} + +dependencies { + compile 'org.bukkit:bukkit:1.10-R0.1-SNAPSHOT' + compile 'net.md-5:bungeecord-api:1.10-SNAPSHOT' +} + +ext { + // Placeholders for configuration filtering + resourceTokens = [ 'Version': version ]; +} + +processResources { + include 'plugin.yml', 'config.yml', 'bungee.yml' + filter org.apache.tools.ant.filters.ReplaceTokens, tokens: resourceTokens +} diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..62f4c32 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'CommandSync' diff --git a/src/main/java/com/fuzzoland/CommandSyncClient/ClientThread.java b/src/main/java/com/fuzzoland/CommandSyncClient/ClientThread.java index aeedffd..27cdc5f 100644 --- a/src/main/java/com/fuzzoland/CommandSyncClient/ClientThread.java +++ b/src/main/java/com/fuzzoland/CommandSyncClient/ClientThread.java @@ -8,6 +8,8 @@ import java.net.Socket; import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class ClientThread extends Thread { @@ -60,7 +62,7 @@ public void run() { String[] data = input.split(plugin.spacer); if(data[0].equals("console")) { String command = data[2].replaceAll("\\+", " "); - Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command); + safePerformCommand(Bukkit.getServer().getConsoleSender(), command, plugin); plugin.debugger.debug("Ran command /" + command + "."); } } @@ -116,4 +118,13 @@ private void connect(Boolean sleep) { plugin.debugger.debug("Could not connect to the server."); } } + + public static void safePerformCommand(final CommandSender sender, final String command, CSC plugin) { + // PaperSpigot will complain about async command execution without this. See http://bit.ly/1oSiM6C + if (Bukkit.getServer().isPrimaryThread()){ + Bukkit.getServer().dispatchCommand(sender, command); + } else { + Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getServer().dispatchCommand(sender, command)); // This uses lambdas, in Java 8+ only + } + } } diff --git a/src/main/resources/bungee.yml b/src/main/resources/bungee.yml index 125ee4c..0e1c8e1 100644 --- a/src/main/resources/bungee.yml +++ b/src/main/resources/bungee.yml @@ -1,4 +1,4 @@ name: CommandSync main: com.fuzzoland.CommandSyncServer.CSS -version: 2.4 +version: '@Version@' author: YoFuzzy3 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7a28ffc..5fd7a7c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: CommandSync main: com.fuzzoland.CommandSyncClient.CSC -version: 2.4 +version: '@Version@' author: YoFuzzy3 commands: