Skip to content

Commit 4ea1b97

Browse files
committed
Various fixes, Spigot 1.16.3
1 parent 50aeaef commit 4ea1b97

File tree

9 files changed

+88
-50
lines changed

9 files changed

+88
-50
lines changed
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="src-common"/>
4-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
5-
<attributes>
6-
<attribute name="module" value="true"/>
7-
</attributes>
8-
</classpathentry>
94
<classpathentry kind="lib" path="lib-common/jython-standalone-2.7.2.jar"/>
105
<classpathentry kind="lib" path="lib-common/java-websocket-1.4.0.jar"/>
11-
<classpathentry kind="lib" path="lib-spigot/spigot-1.15.2.jar"/>
6+
<classpathentry kind="lib" path="lib-spigot/spigot-1.16.3.jar"/>
7+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
128
<classpathentry kind="output" path="bin"/>
139
</classpath>

ServerPythonInterpreterPlugin/.settings/org.eclipse.jdt.core.prefs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ org.eclipse.jdt.core.compiler.debug.lineNumber=generate
88
org.eclipse.jdt.core.compiler.debug.localVariable=generate
99
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
1010
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
1112
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
13+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
14+
org.eclipse.jdt.core.compiler.release=disabled
1215
org.eclipse.jdt.core.compiler.source=1.8

ServerPythonInterpreterPlugin/lib-spigot/spigot-1.15.2.jar renamed to ServerPythonInterpreterPlugin/lib-spigot/spigot-1.16.3.jar

31 MB
Binary file not shown.

ServerPythonInterpreterPlugin/plugin.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ commands:
1313
pyload:
1414
description: Execute a server-side Python file on Jython interpreter
1515
usage: /pyload file
16+
pyreload:
17+
description: Reload all Jython scripts
18+
usage: /pyreload
1619
permissions:
1720
chatcommands:
1821
default: op
Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.macuyiko.minecraftpyserver;
22

33
import java.io.File;
4+
import java.io.IOException;
45
import java.util.ArrayList;
56
import java.util.List;
67

@@ -12,13 +13,17 @@
1213
import com.macuyiko.minecraftpyserver.jython.JyCommandExecutor;
1314
import com.macuyiko.minecraftpyserver.jython.JyInterpreter;
1415
import com.macuyiko.minecraftpyserver.jython.JyWebSocketServer;
15-
import com.macuyiko.minecraftpyserver.jython.TelnetServer;
16+
import com.macuyiko.minecraftpyserver.jython.JyTelnetServer;
1617

1718
public class MinecraftPyServerPlugin extends JavaPlugin {
1819

1920
public final static String PLUGIN_NAME = "MinecraftPyServer";
2021

2122
private List<JyInterpreter> pluginInterpreters = new ArrayList<JyInterpreter>();
23+
private JyWebSocketServer webSocketServer;
24+
private JyTelnetServer telnetServer;
25+
private JyChatServer commandServer;
26+
private Thread telnetServerThread;
2227

2328
@Override
2429
public void onEnable() {
@@ -28,41 +33,43 @@ public void onEnable() {
2833

2934
int tcpsocketserverport = getConfig().getInt("pythonconsole.telnetport", 44444);
3035
int websocketserverport = getConfig().getInt("pythonconsole.websocketport", 44445);
31-
boolean enablechatcommands = getConfig().getString("pythonconsole.enablechatcommands", "true").equalsIgnoreCase("true");
36+
boolean enablechatcommands = getConfig().getString("pythonconsole.enablechatcommands", "true")
37+
.equalsIgnoreCase("true");
3238

3339
if (tcpsocketserverport > 0)
34-
startTelnetServer(this, tcpsocketserverport);
40+
telnetServer = startTelnetServer(this, tcpsocketserverport);
3541

3642
if (websocketserverport > 0)
37-
startWebSocketServer(this, websocketserverport);
43+
webSocketServer = startWebSocketServer(this, websocketserverport);
3844

3945
if (enablechatcommands) {
40-
JyChatServer commandServer = startChatServer(this);
46+
commandServer = startChatServer(this);
4147
this.getCommand("py").setExecutor(new JyCommandExecutor(this, commandServer));
4248
this.getCommand("pyrestart").setExecutor(new JyCommandExecutor(this, commandServer));
4349
this.getCommand("pyload").setExecutor(new JyCommandExecutor(this, commandServer));
50+
this.getCommand("pyreload").setExecutor(new JyCommandExecutor(this, commandServer));
4451
}
4552

46-
File pluginDirectory = new File("./python-plugins/");
47-
if (pluginDirectory.exists() && pluginDirectory.isDirectory()) {
48-
File[] files = pluginDirectory.listFiles();
49-
for (int i = 0; i < files.length; i++) {
50-
if (files[i].getName().endsWith(".py")) {
51-
System.err.println("[MinecraftPyServer] Parsing plugin: " + files[i].getName());
52-
JyInterpreter pluginInterpreter = new JyInterpreter(true);
53-
pluginInterpreter.execfile(files[i]);
54-
pluginInterpreters.add(pluginInterpreter);
55-
}
56-
}
57-
}
53+
startPluginInterpreters();
5854
}
5955

6056
public void onDisable() {
6157
log("Unloading MinecraftPyServerPlugin");
6258

63-
for (JyInterpreter pluginInterpreter : pluginInterpreters) {
64-
pluginInterpreter.close();
59+
stopPluginInterpreters();
60+
61+
try {
62+
webSocketServer.stop();
63+
} catch (IOException e) {
64+
} catch (InterruptedException e) {
65+
}
66+
67+
telnetServerThread.interrupt();
68+
try {
69+
telnetServerThread.join(1000);
70+
} catch (InterruptedException e) {
6571
}
72+
telnetServer.close();
6673
}
6774

6875
public void log(String message) {
@@ -78,25 +85,48 @@ public void send(String player, String message) {
7885
send(p, message);
7986
}
8087

81-
public static TelnetServer startTelnetServer(MinecraftPyServerPlugin mainPlugin, int telnetport) {
82-
TelnetServer server = new TelnetServer(mainPlugin, telnetport);
83-
Thread t = new Thread(server);
84-
t.start();
88+
public void restartPluginInterpreters() {
89+
stopPluginInterpreters();
90+
startPluginInterpreters();
91+
}
92+
93+
private void startPluginInterpreters() {
94+
File pluginDirectory = new File("./python-plugins/");
95+
if (pluginDirectory.exists() && pluginDirectory.isDirectory()) {
96+
File[] files = pluginDirectory.listFiles();
97+
for (int i = 0; i < files.length; i++) {
98+
if (files[i].getName().endsWith(".py")) {
99+
System.err.println("[MinecraftPyServer] Parsing plugin: " + files[i].getName());
100+
JyInterpreter pluginInterpreter = new JyInterpreter(true);
101+
pluginInterpreter.execfile(files[i]);
102+
pluginInterpreters.add(pluginInterpreter);
103+
}
104+
}
105+
}
106+
}
107+
108+
private void stopPluginInterpreters() {
109+
for (JyInterpreter pluginInterpreter : pluginInterpreters) {
110+
pluginInterpreter.close();
111+
}
112+
}
113+
114+
public JyTelnetServer startTelnetServer(MinecraftPyServerPlugin mainPlugin, int telnetport) {
115+
JyTelnetServer server = new JyTelnetServer(mainPlugin, telnetport);
116+
telnetServerThread = new Thread(server);
117+
telnetServerThread.start();
85118
return server;
86119
}
87120

88-
public static JyWebSocketServer startWebSocketServer(MinecraftPyServerPlugin mainPlugin, int websocketport) {
121+
public JyWebSocketServer startWebSocketServer(MinecraftPyServerPlugin mainPlugin, int websocketport) {
89122
JyWebSocketServer server = new JyWebSocketServer(mainPlugin, websocketport);
90123
server.start();
91124
return server;
92125
}
93126

94-
public static JyChatServer startChatServer(MinecraftPyServerPlugin mainPlugin) {
127+
public JyChatServer startChatServer(MinecraftPyServerPlugin mainPlugin) {
95128
JyChatServer server = new JyChatServer(mainPlugin);
96129
return server;
97130
}
98-
99-
100-
101131

102132
}

ServerPythonInterpreterPlugin/src-common/com/macuyiko/minecraftpyserver/MinecraftPyServerUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ public static void addURL(ClassLoader loader, URL u) {
154154
}
155155

156156
public static File matchPythonFile(String arg) {
157-
String homePath = javax.swing.filechooser.FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath();
157+
String homePath = javax.swing.filechooser.FileSystemView.getFileSystemView()
158+
.getHomeDirectory().getAbsolutePath();
158159
File asIs = new File(arg);
159160
File onDesktop = new File(homePath, arg);
160161
File asIsPy = new File(arg + ".py");

ServerPythonInterpreterPlugin/src-common/com/macuyiko/minecraftpyserver/jython/JyCommandExecutor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
4343
commandServer.setupInterpreter(player);
4444
plugin.send(player, "Done!\n");
4545
return true;
46+
} else if (cmd.getName().equals("pyreload") && sender instanceof Player) {
47+
plugin.send(player, "Restarting Python scripts. Please wait...");
48+
plugin.restartPluginInterpreters();
49+
plugin.send(player, "Done!\n");
50+
return true;
4651
} else if (cmd.getName().equals("pyload") && sender instanceof Player && args.length == 1) {
4752
File match = MinecraftPyServerUtils.matchPythonFile(args[0]);
4853
if (match != null) {

ServerPythonInterpreterPlugin/src-common/com/macuyiko/minecraftpyserver/jython/TelnetServer.java renamed to ServerPythonInterpreterPlugin/src-common/com/macuyiko/minecraftpyserver/jython/JyTelnetServer.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@
88

99
import com.macuyiko.minecraftpyserver.MinecraftPyServerPlugin;
1010

11-
public class TelnetServer implements Runnable {
11+
public class JyTelnetServer implements Runnable {
1212
private MinecraftPyServerPlugin plugin;
1313
private int port;
1414
private ServerSocket listener;
1515
protected ExecutorService threadPool;
1616

17-
public static void main(String[] args) {
18-
MinecraftPyServerPlugin.startTelnetServer(null, 44444);
19-
}
20-
21-
public TelnetServer(MinecraftPyServerPlugin caller, int port) {
17+
public JyTelnetServer(MinecraftPyServerPlugin caller, int port) {
2218
this.plugin = caller;
2319
this.port = port;
2420
this.threadPool = Executors.newCachedThreadPool();
@@ -28,18 +24,22 @@ public void run() {
2824
try {
2925
listener = new ServerSocket(port);
3026
Socket clientSocket;
31-
while (true) {
27+
while (!Thread.interrupted()) {
3228
clientSocket = listener.accept();
33-
threadPool.execute(new TelnetServerThread(this, clientSocket));
29+
threadPool.execute(new JyTelnetServerThread(this, clientSocket));
3430
}
3531
} catch (IOException ioe) {
3632
System.out.println("IOException on socket listen: " + ioe);
3733
ioe.printStackTrace();
3834
} finally {
39-
try {
40-
listener.close();
41-
} catch (IOException e) {
42-
}
35+
close();
36+
}
37+
}
38+
39+
public void close() {
40+
try {
41+
listener.close();
42+
} catch (IOException e) {
4343
}
4444
}
4545

ServerPythonInterpreterPlugin/src-common/com/macuyiko/minecraftpyserver/jython/TelnetServerThread.java renamed to ServerPythonInterpreterPlugin/src-common/com/macuyiko/minecraftpyserver/jython/JyTelnetServerThread.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
import java.net.Socket;
88

99

10-
public class TelnetServerThread implements Runnable {
11-
private TelnetServer server;
10+
public class JyTelnetServerThread implements Runnable {
11+
private JyTelnetServer server;
1212
private Socket socket;
1313
private JyInterpreter interpreter;
1414
private BufferedReader in;
1515
private PrintStream out;
1616

17-
public TelnetServerThread(TelnetServer socketServer, Socket socket) {
17+
public JyTelnetServerThread(JyTelnetServer socketServer, Socket socket) {
1818
this.server = socketServer;
1919
this.socket = socket;
2020
try {

0 commit comments

Comments
 (0)