Skip to content

Commit dd8c767

Browse files
committed
Add Gradle build process, fix Async command warnings on PaperSpigot
1 parent 032a775 commit dd8c767

5 files changed

Lines changed: 41 additions & 3 deletions

File tree

build.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apply plugin: 'java'
2+
3+
//noinspection GroovyUnusedAssignment
4+
sourceCompatibility = 1.8
5+
version = '2.5'
6+
7+
repositories {
8+
jcenter()
9+
maven { url 'https://hub.spigotmc.org/nexus/content/groups/public' }
10+
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
11+
}
12+
13+
dependencies {
14+
compile 'org.bukkit:bukkit:1.10-R0.1-SNAPSHOT'
15+
compile 'net.md-5:bungeecord-api:1.10-SNAPSHOT'
16+
}
17+
18+
ext {
19+
// Placeholders for configuration filtering
20+
resourceTokens = [ 'Version': version ];
21+
}
22+
23+
processResources {
24+
include 'plugin.yml', 'config.yml', 'bungee.yml'
25+
filter org.apache.tools.ant.filters.ReplaceTokens, tokens: resourceTokens
26+
}

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'CommandSync'

src/main/java/com/fuzzoland/CommandSyncClient/ClientThread.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import java.net.Socket;
99

1010
import org.bukkit.Bukkit;
11+
import org.bukkit.command.CommandSender;
12+
import org.bukkit.entity.Player;
1113

1214
public class ClientThread extends Thread {
1315

@@ -60,7 +62,7 @@ public void run() {
6062
String[] data = input.split(plugin.spacer);
6163
if(data[0].equals("console")) {
6264
String command = data[2].replaceAll("\\+", " ");
63-
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command);
65+
safePerformCommand(Bukkit.getServer().getConsoleSender(), command, plugin);
6466
plugin.debugger.debug("Ran command /" + command + ".");
6567
}
6668
}
@@ -116,4 +118,13 @@ private void connect(Boolean sleep) {
116118
plugin.debugger.debug("Could not connect to the server.");
117119
}
118120
}
121+
122+
public static void safePerformCommand(final CommandSender sender, final String command, CSC plugin) {
123+
// PaperSpigot will complain about async command execution without this. See http://bit.ly/1oSiM6C
124+
if (Bukkit.getServer().isPrimaryThread()){
125+
Bukkit.getServer().dispatchCommand(sender, command);
126+
} else {
127+
Bukkit.getScheduler().runTask(plugin, () -> Bukkit.getServer().dispatchCommand(sender, command)); // This uses lambdas, in Java 8+ only
128+
}
129+
}
119130
}

src/main/resources/bungee.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name: CommandSync
22
main: com.fuzzoland.CommandSyncServer.CSS
3-
version: 2.4
3+
version: '@Version@'
44
author: YoFuzzy3

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: CommandSync
22
main: com.fuzzoland.CommandSyncClient.CSC
3-
version: 2.4
3+
version: '@Version@'
44
author: YoFuzzy3
55

66
commands:

0 commit comments

Comments
 (0)