Skip to content

Commit

Permalink
Add Gradle build process, fix Async command warnings on PaperSpigot
Browse files Browse the repository at this point in the history
  • Loading branch information
HeroCC committed Jun 20, 2016
1 parent 032a775 commit dd8c767
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
26 changes: 26 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'CommandSync'
13 changes: 12 additions & 1 deletion src/main/java/com/fuzzoland/CommandSyncClient/ClientThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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 + ".");
}
}
Expand Down Expand Up @@ -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
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/bungee.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CommandSync
main: com.fuzzoland.CommandSyncServer.CSS
version: 2.4
version: '@Version@'
author: YoFuzzy3
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CommandSync
main: com.fuzzoland.CommandSyncClient.CSC
version: 2.4
version: '@Version@'
author: YoFuzzy3

commands:
Expand Down

0 comments on commit dd8c767

Please sign in to comment.