PDA

View Full Version : Restart your server through a command



Kingdomkey01
June 9th, 2011, 19:30
First go to packet 103 (commands), and add this



if (cmd.equalsIgnoreCase("restartserver") && plr.playerRights > 2) {
for (Player p : PlayerHandler.players) {
if (p == null)
continue;
}
System.exit(0);
}


^ This is compatible with my source, if you're having errors, change the red marks accordingly.

Next in your run.bat file, add the red markings:



@echo off
title [SELDOM]: Running server...
:run
CLS
java -Xmx800m -cp bin;deps/poi.jar;libs/mysql.jar;libs/mina.jar;libs/slf4j.jar;deps/slf4j-nop.jar;libs/jython.jar;log4j-1.2.15.jar;libs/mysql-connector-java-5.1.6-bin.jar; seldom.Server
goto run
pause


Don't forget to import your PlayerHandler class if you need too.

Faab234
June 9th, 2011, 19:40
Is the plr variable an instance of the Player class?

Kingdomkey01
June 9th, 2011, 19:58
yes, in my server.

Jon
June 9th, 2011, 20:08
for (Player p : PlayerHandler.players) {
if (p == null)
continue;
plr.saveGame(true);
}

you're saving the player who used the command multiple times.

Kingdomkey01
June 9th, 2011, 20:13
for (Player p : PlayerHandler.players) {
if (p == null)
continue;
plr.saveGame(true);
}

you're saving the player who used the command multiple times.

Fail, just noticed, since plr is an instance of my player class, I'll fix that for me, but I'll remove it for the thread. :D

Thanks again, lul.

Jon
June 9th, 2011, 20:17
Fail, just noticed, since plr is an instance of my player class, I'll fix that for me, but I'll remove it for the thread. :D

Thanks again, lul.

now you're just looping for nothing.

you just needed to change it to p.saveGame(true);

bub456bub
June 9th, 2011, 20:30
Haha, I saw this thread come up,

Knew it was you Kingdomkey01!

Keep up the Good work!

CRAIZYBART
June 27th, 2011, 06:21
Nice tut, keep up the good work! ;)