Skip to content

Commit 89e2f0f

Browse files
author
magiclu550
committed
[commit] you can close something by jar args
1 parent 2942fc9 commit 89e2f0f

File tree

3 files changed

+55
-30
lines changed

3 files changed

+55
-30
lines changed

JPLS/src/main/java/cn/jsmod2/ServerStarter.java

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,47 @@
66
import cn.jsmod2.core.plugin.SpringContextUtil;
77
import cn.jsmod2.core.utils.Utils;
88

9+
import java.util.Arrays;
910
import java.util.concurrent.CountDownLatch;
1011

12+
import static cn.jsmod2.core.utils.Utils.contains;
13+
14+
/**
15+
* -w -u -lr -lm -github
16+
* -w 关闭web
17+
* -u 关闭ui
18+
* -lr 关闭round的log监听
19+
* -lm 关闭multiAdmin和游戏的log监听
20+
* -github 关闭和Github连接
21+
*/
1122
@ServerApplication(DefaultServer.class)
1223
public class ServerStarter {
1324

1425
public void start(String[] args){
1526
Utils.TryCatch(()->{
1627
CountDownLatch latch = new CountDownLatch(1);
17-
new Thread(()->{
18-
SpringContextUtil.setApplicationContext(Starter.run(args));
19-
latch.countDown();
20-
}).start();
21-
latch.await();
22-
CountDownLatch latch1 = new CountDownLatch(1);
23-
new Thread(()->{
24-
latch1.countDown();
25-
try {
26-
UIStarter.run(args);
27-
}catch (Exception e){
28-
Utils.printException(e);
29-
}
30-
}).start();
31-
latch1.await();
28+
if(!contains(args,"-w")) {
29+
new Thread(() -> {
30+
SpringContextUtil.setApplicationContext(Starter.run(args));
31+
latch.countDown();
32+
}).start();
33+
latch.await();
34+
}
35+
if(!contains(args,"-u")) {
36+
CountDownLatch latch1 = new CountDownLatch(1);
37+
new Thread(() -> {
38+
latch1.countDown();
39+
try {
40+
UIStarter.run(args);
41+
} catch (Exception e) {
42+
Utils.printException(e);
43+
}
44+
}).start();
45+
latch1.await();
46+
}
3247
Application.run(this.getClass(),args);
3348
});
3449
}
50+
51+
3552
}

JPLS/src/main/java/cn/jsmod2/core/Server.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
import java.util.stream.Collectors;
4545

4646
import static cn.jsmod2.core.FileSystem.*;
47-
import static cn.jsmod2.core.utils.Utils.getFullBytes;
48-
import static cn.jsmod2.core.utils.Utils.getLen;
47+
import static cn.jsmod2.core.utils.Utils.*;
4948

5049
/**
5150
* jsmod2 cn.jsmod2.server class
@@ -204,30 +203,34 @@ public void startWatch(Class<?> main,String[] args) {
204203
Utils.TryCatch(()-> {
205204
this.log.multiInfo(this.getClass(),main.getSimpleName() + "::start::" + main.getName(),"","");
206205
this.executeEmerald(args, true);
207-
this.start();
206+
this.start(args);
208207
this.successTime();
209208
});
210209
}
211-
public void start(){
210+
public void start(String[] args){
212211
if(useUDP) {
213212
this.pool.execute(new ListenerThread());
214213
}else{
215214
this.pool.execute(new ListenerThreadTCP());
216215
}
217-
String log = logListener("yyyy-MM-dd HH.mm.ss",this::getMax,SMOD2_LOG_FILE);
218-
if(log != null) {
219-
this.pool.execute(new LogListener(log, Integer.parseInt(serverProp.getProperty(SMOD2_LOG_INTERVAL,"2000")),"yyyy-MM-dd HH.mm.ss",this::getMax,SMOD2_LOG_FILE));
216+
if(!contains(args,"-lr")) {
217+
String log = logListener("yyyy-MM-dd HH.mm.ss", this::getMax, SMOD2_LOG_FILE);
218+
if (log != null) {
219+
this.pool.execute(new LogListener(log, Integer.parseInt(serverProp.getProperty(SMOD2_LOG_INTERVAL, "2000")), "yyyy-MM-dd HH.mm.ss", this::getMax, SMOD2_LOG_FILE));
220+
}
220221
}
221-
String log1 = logListener("yyyy-MM-dd_HH_mm",(format, x1, x2) -> getMultiSCPMax(format,x1,x2,"MA"), Register.CONSOLE_LOG);
222-
if(log1 != null){
223-
this.pool.execute(new LogListener(log1,Integer.parseInt(serverProp.getProperty(SMOD2_LOG_INTERVAL,"2000")),"yyyy-MM-dd_HH_mm",(format, x1, x2) -> getMultiSCPMax(format,x1,x2,"MA"),Register.CONSOLE_LOG));
224-
this.pool.execute(new LogListener(log1,Integer.parseInt(serverProp.getProperty(SMOD2_LOG_INTERVAL,"2000")),"yyyy-MM-dd_HH_mm",(format, x1, x2) -> getMultiSCPMax(format,x1,x2,"SCP"),Register.CONSOLE_LOG));
222+
if(!contains(args,"-lm")) {
223+
String log1 = logListener("yyyy-MM-dd_HH_mm", (format, x1, x2) -> getMultiSCPMax(format, x1, x2, "MA"), Register.CONSOLE_LOG);
224+
if (log1 != null) {
225+
this.pool.execute(new LogListener(log1, Integer.parseInt(serverProp.getProperty(SMOD2_LOG_INTERVAL, "2000")), "yyyy-MM-dd_HH_mm", (format, x1, x2) -> getMultiSCPMax(format, x1, x2, "MA"), Register.CONSOLE_LOG));
226+
this.pool.execute(new LogListener(log1, Integer.parseInt(serverProp.getProperty(SMOD2_LOG_INTERVAL, "2000")), "yyyy-MM-dd_HH_mm", (format, x1, x2) -> getMultiSCPMax(format, x1, x2, "SCP"), Register.CONSOLE_LOG));
227+
}
225228
}
226229

227-
228-
229-
if(Boolean.parseBoolean(serverProp.getProperty(GITHUB))) {
230-
this.pool.execute(new GithubConnectThread());
230+
if(!contains(args,"-github")) {
231+
if (Boolean.parseBoolean(serverProp.getProperty(GITHUB))) {
232+
this.pool.execute(new GithubConnectThread());
233+
}
231234
}
232235
//this.pool.execute(new ServerThread());
233236

JPLS/src/main/java/cn/jsmod2/core/utils/Utils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public class Utils {
3434
messageSender = new Message();
3535
}
3636

37+
public static boolean contains(String[] args,String value){
38+
if(Arrays.toString(args).contains(value))return true;
39+
return false;
40+
}
41+
3742
public static Method getServerMethod(String methodName) throws NoSuchMethodException{
3843
Method method = Server.class.getDeclaredMethod(methodName);
3944
method.setAccessible(true);

0 commit comments

Comments
 (0)