-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cc54a60
Showing
4 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
server-folder: "server" | ||
command: | | ||
java -Xmx1024M -jar server.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: OMGRemote | ||
main: fr.dabsunter.omgremote.Main | ||
version: 1.0.0 | ||
description: Lanceur de serveur paralelle | ||
|
||
commands: | ||
send: | ||
usage: "/<command>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package fr.dabsunter.omgremote; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStreamWriter; | ||
|
||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public class Main extends JavaPlugin { | ||
|
||
public static Process serverProcess; | ||
|
||
@Override | ||
public void onEnable() { | ||
saveDefaultConfig(); | ||
|
||
getCommand("send").setExecutor(new SendExecutor()); | ||
|
||
Runtime runtime = Runtime.getRuntime(); | ||
try { | ||
serverProcess = runtime.exec( | ||
getConfig().getString("command"), | ||
null, | ||
new File(getConfig().getString("server-folder")) | ||
); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
System.exit(0); | ||
} | ||
|
||
new Thread() { | ||
public void run() { | ||
try { | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(serverProcess.getInputStream())); | ||
String line = ""; | ||
try { | ||
while((line = reader.readLine()) != null) { | ||
System.out.println("[Remote Server]" + line); | ||
} | ||
} finally { | ||
reader.close(); | ||
} | ||
} catch(IOException ioe) { | ||
ioe.printStackTrace(); | ||
} | ||
} | ||
}.start(); | ||
|
||
new Thread() { | ||
public void run() { | ||
try { | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(serverProcess.getErrorStream())); | ||
String line = ""; | ||
try { | ||
while((line = reader.readLine()) != null) { | ||
System.out.println("[Remote Server]" + line); | ||
} | ||
} finally { | ||
reader.close(); | ||
} | ||
} catch(IOException ioe) { | ||
ioe.printStackTrace(); | ||
} | ||
} | ||
}.start(); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
try { | ||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(serverProcess.getOutputStream())); | ||
try { | ||
writer.write("stop"); | ||
} finally { | ||
writer.close(); | ||
} | ||
} catch(IOException ioe) { | ||
ioe.printStackTrace(); | ||
} | ||
|
||
try { | ||
serverProcess.waitFor(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package fr.dabsunter.omgremote; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
|
||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandExecutor; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class SendExecutor implements CommandExecutor { | ||
|
||
@Override | ||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { | ||
switch(args.length) { | ||
case 0: | ||
return false; | ||
default: | ||
try { | ||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Main.serverProcess.getOutputStream())); | ||
try { | ||
writer.write(join(args)); | ||
writer.newLine(); | ||
} finally { | ||
writer.flush(); | ||
} | ||
} catch(IOException ioe) { | ||
ioe.printStackTrace(); | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
private String join(String[] args) { | ||
String result = ""; | ||
for(String arg : args) | ||
result += " " + arg; | ||
return result.substring(1); | ||
} | ||
|
||
} |