Commits

md_5 authored c3730616ee7
SPIGOT-625: Insert a small delay when shutting down to allow packets to have a better chance at sending.
No tags

nms-patches/MinecraftServer.patch

Modified
314 314 if (!this.N) {
315 315 MinecraftServer.LOGGER.info("Stopping server");
316 316 + // CraftBukkit start
317 317 + if (this.server != null) {
318 318 + this.server.disablePlugins();
319 319 + }
320 320 + // CraftBukkit end
321 321 if (this.aq() != null) {
322 322 this.aq().b();
323 323 }
324 -@@ -309,11 +466,13 @@
324 +@@ -303,17 +460,20 @@
325 + MinecraftServer.LOGGER.info("Saving players");
326 + this.v.savePlayers();
327 + this.v.u();
328 ++ try { Thread.sleep(100); } catch (InterruptedException ex) {} // CraftBukkit - SPIGOT-625 - give server at least a chance to send packets
329 + }
330 +
331 + if (this.worldServer != null) {
325 332 MinecraftServer.LOGGER.info("Saving worlds");
326 333 this.saveChunks(false);
327 334
328 335 + /* CraftBukkit start - Handled in saveChunks
329 336 for (int i = 0; i < this.worldServer.length; ++i) {
330 337 WorldServer worldserver = this.worldServer[i];
331 338
332 339 worldserver.saveLevel();
333 340 }
334 341 + // CraftBukkit end */
335 342 }
336 343
337 344 if (this.n.d()) {
338 -@@ -354,6 +513,7 @@
345 +@@ -354,6 +514,7 @@
339 346 long k = j - this.ab;
340 347
341 348 if (k > 2000L && this.ab - this.R >= 15000L) {
342 349 + if (server.getWarnOnOverload()) // CraftBukkit
343 350 MinecraftServer.LOGGER.warn("Can\'t keep up! Did the system time change, or is the server overloaded? Running {}ms behind, skipping {} tick(s)", new Object[] { Long.valueOf(k), Long.valueOf(k / 50L)});
344 351 k = 2000L;
345 352 this.R = this.ab;
346 -@@ -366,11 +526,12 @@
353 +@@ -366,11 +527,12 @@
347 354
348 355 i += k;
349 356 this.ab = j;
350 357 - if (this.worldServer[0].everyoneDeeplySleeping()) {
351 358 + if (this.worlds.get(0).everyoneDeeplySleeping()) { // CraftBukkit
352 359 this.A();
353 360 i = 0L;
354 361 } else {
355 362 while (i > 50L) {
356 363 + MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
357 364 i -= 50L;
358 365 this.A();
359 366 }
360 -@@ -408,6 +569,12 @@
367 +@@ -408,6 +570,12 @@
361 368 } catch (Throwable throwable1) {
362 369 MinecraftServer.LOGGER.error("Exception stopping the server", throwable1);
363 370 } finally {
364 371 + // CraftBukkit start - Restore terminal to original settings
365 372 + try {
366 373 + reader.getTerminal().restore();
367 374 + } catch (Exception ignored) {
368 375 + }
369 376 + // CraftBukkit end
370 377 this.z();
371 378 }
372 379
373 -@@ -447,7 +614,7 @@
380 +@@ -447,7 +615,7 @@
374 381
375 382 protected void z() {}
376 383
377 384 - protected void A() {
378 385 + protected void A() throws ExceptionWorldConflict { // CraftBukkit - added throws
379 386 long i = System.nanoTime();
380 387
381 388 ++this.ticks;
382 -@@ -473,7 +640,7 @@
389 +@@ -473,7 +641,7 @@
383 390 this.r.b().a(agameprofile);
384 391 }
385 392
386 393 - if (this.ticks % 900 == 0) {
387 394 + if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // CraftBukkit
388 395 this.methodProfiler.a("save");
389 396 this.v.savePlayers();
390 397 this.saveChunks(true);
391 -@@ -508,20 +675,40 @@
398 +@@ -508,20 +676,40 @@
392 399
393 400 this.methodProfiler.c("levels");
394 401
395 402 + // CraftBukkit start
396 403 + this.server.getScheduler().mainThreadHeartbeat(this.ticks);
397 404 +
398 405 + // Run tasks that are waiting on processing
399 406 + while (!processQueue.isEmpty()) {
400 407 + processQueue.remove().run();
401 408 + }
425 432 + /* Drop global time updates
426 433 if (this.ticks % 20 == 0) {
427 434 this.methodProfiler.a("timeSync");
428 435 this.v.a(new PacketPlayOutUpdateTime(worldserver.getTime(), worldserver.getDayTime(), worldserver.getGameRules().getBoolean("doDaylightCycle")), worldserver.worldProvider.getDimension());
429 436 this.methodProfiler.b();
430 437 }
431 438 + // CraftBukkit end */
432 439
433 440 this.methodProfiler.a("tick");
434 441
435 -@@ -548,9 +735,9 @@
442 +@@ -548,9 +736,9 @@
436 443 worldserver.getTracker().updatePlayers();
437 444 this.methodProfiler.b();
438 445 this.methodProfiler.b();
439 446 - }
440 447 + // } // CraftBukkit
441 448
442 449 - this.i[i][this.ticks % 100] = System.nanoTime() - j;
443 450 + // this.i[i][this.ticks % 100] = System.nanoTime() - j; // CraftBukkit
444 451 }
445 452
446 453 this.methodProfiler.c("connection");
447 -@@ -574,10 +761,11 @@
454 +@@ -574,10 +762,11 @@
448 455 this.p.add(iupdateplayerlistbox);
449 456 }
450 457
451 458 - public static void main(String[] astring) {
452 459 + public static void main(final OptionSet options) { // CraftBukkit - replaces main(String[] astring)
453 460 DispenserRegistry.c();
454 461
455 462 try {
456 463 + /* CraftBukkit start - Replace everything
457 464 boolean flag = true;
458 465 String s = null;
459 466 String s1 = ".";
460 -@@ -655,15 +843,38 @@
467 +@@ -655,15 +844,38 @@
461 468 dedicatedserver.stop();
462 469 }
463 470 });
464 471 + */
465 472 +
466 473 + DedicatedServer dedicatedserver = new DedicatedServer(options);
467 474 +
468 475 + if (options.has("port")) {
469 476 + int port = (Integer) options.valueOf("port");
470 477 + if (port > 0) {
490 497
491 498 - public void D() {
492 499 + public void C() {
493 500 + /* CraftBukkit start - prevent abuse
494 501 this.serverThread = new Thread(this, "Server thread");
495 502 this.serverThread.start();
496 503 + // CraftBukkit end */
497 504 }
498 505
499 506 public File d(String s) {
500 -@@ -679,7 +890,14 @@
507 +@@ -679,7 +891,14 @@
501 508 }
502 509
503 510 public WorldServer getWorldServer(int i) {
504 511 - return i == -1 ? this.worldServer[1] : (i == 1 ? this.worldServer[2] : this.worldServer[0]);
505 512 + // CraftBukkit start
506 513 + for (WorldServer world : worlds) {
507 514 + if (world.dimension == i) {
508 515 + return world;
509 516 + }
510 517 + }
511 518 + return worlds.get(0);
512 519 + // CraftBukkit end
513 520 }
514 521
515 522 public String E() {
516 -@@ -715,7 +933,7 @@
523 +@@ -715,7 +934,7 @@
517 524 }
518 525
519 526 public boolean isDebugging() {
520 527 - return false;
521 528 + return this.getPropertyManager().getBoolean("debug", false); // CraftBukkit - don't hardcode
522 529 }
523 530
524 531 public void g(String s) {
525 -@@ -730,7 +948,7 @@
532 +@@ -730,7 +949,7 @@
526 533 }
527 534
528 535 public String getServerModName() {
529 536 - return "vanilla";
530 537 + return server.getName(); // CraftBukkit - cb > vanilla!
531 538 }
532 539
533 540 public CrashReport b(CrashReport crashreport) {
534 -@@ -759,6 +977,7 @@
541 +@@ -759,6 +978,7 @@
535 542 }
536 543
537 544 public List<String> tabCompleteCommand(ICommandListener icommandlistener, String s, BlockPosition blockposition) {
538 545 + /* CraftBukkit start - Allow tab-completion of Bukkit commands
539 546 ArrayList arraylist = Lists.newArrayList();
540 547
541 548 if (s.startsWith("/")) {
542 -@@ -797,6 +1016,9 @@
549 +@@ -797,6 +1017,9 @@
543 550
544 551 return arraylist;
545 552 }
546 553 + */
547 554 + return server.tabComplete(icommandlistener, s);
548 555 + // CraftBukkit end
549 556 }
550 557
551 558 public static MinecraftServer getServer() {
552 -@@ -804,7 +1026,7 @@
559 +@@ -804,7 +1027,7 @@
553 560 }
554 561
555 562 public boolean O() {
556 563 - return this.universe != null;
557 564 + return true; // CraftBukkit
558 565 }
559 566
560 567 public String getName() {
561 -@@ -860,8 +1082,10 @@
568 +@@ -860,8 +1083,10 @@
562 569 }
563 570
564 571 public void a(EnumDifficulty enumdifficulty) {
565 572 - for (int i = 0; i < this.worldServer.length; ++i) {
566 573 - WorldServer worldserver = this.worldServer[i];
567 574 + // CraftBukkit start
568 575 + for (int i = 0; i < this.worlds.size(); ++i) {
569 576 + WorldServer worldserver = this.worlds.get(i);
570 577 + // CraftBukkit end
571 578
572 579 if (worldserver != null) {
573 580 if (worldserver.getWorldData().isHardcore()) {
574 -@@ -903,15 +1127,17 @@
581 +@@ -903,15 +1128,17 @@
575 582 this.N = true;
576 583 this.getConvertable().d();
577 584
578 585 - for (int i = 0; i < this.worldServer.length; ++i) {
579 586 - WorldServer worldserver = this.worldServer[i];
580 587 -
581 588 + // CraftBukkit start
582 589 + for (int i = 0; i < this.worlds.size(); ++i) {
583 590 + WorldServer worldserver = this.worlds.get(i);
584 591 + // CraftBukkit end
585 592 +
586 593 if (worldserver != null) {
587 594 worldserver.saveLevel();
588 595 }
589 596 }
590 597
591 598 - this.getConvertable().e(this.worldServer[0].getDataManager().g());
592 599 + this.getConvertable().e(this.worlds.get(0).getDataManager().g()); // CraftBukkit
593 600 this.safeShutdown();
594 601 }
595 602
596 -@@ -944,9 +1170,11 @@
603 +@@ -944,9 +1171,11 @@
597 604 int i = 0;
598 605
599 606 if (this.worldServer != null) {
600 607 - for (int j = 0; j < this.worldServer.length; ++j) {
601 608 - if (this.worldServer[j] != null) {
602 609 - WorldServer worldserver = this.worldServer[j];
603 610 + // CraftBukkit start
604 611 + for (int j = 0; j < this.worlds.size(); ++j) {
605 612 + WorldServer worldserver = this.worlds.get(j);
606 613 + if (worldserver != null) {
607 614 + // CraftBukkit end
608 615 WorldData worlddata = worldserver.getWorldData();
609 616
610 617 mojangstatisticsgenerator.a("world[" + i + "][dimension]", Integer.valueOf(worldserver.worldProvider.getDimension()));
611 -@@ -979,7 +1207,7 @@
618 +@@ -979,7 +1208,7 @@
612 619 public abstract boolean ae();
613 620
614 621 public boolean getOnlineMode() {
615 622 - return this.onlineMode;
616 623 + return server.getOnlineMode(); // CraftBukkit
617 624 }
618 625
619 626 public void setOnlineMode(boolean flag) {
620 -@@ -1051,8 +1279,9 @@
627 +@@ -1051,8 +1280,9 @@
621 628 }
622 629
623 630 public void setGamemode(WorldSettings.EnumGamemode worldsettings_enumgamemode) {
624 631 - for (int i = 0; i < this.worldServer.length; ++i) {
625 632 - getServer().worldServer[i].getWorldData().setGameType(worldsettings_enumgamemode);
626 633 + // CraftBukkit start
627 634 + for (int i = 0; i < this.worlds.size(); ++i) {
628 635 + getServer().worlds.get(i).getWorldData().setGameType(worldsettings_enumgamemode);
629 636 }
630 637
631 638 }
632 -@@ -1084,7 +1313,7 @@
639 +@@ -1084,7 +1314,7 @@
633 640 }
634 641
635 642 public World getWorld() {
636 643 - return this.worldServer[0];
637 644 + return this.worlds.get(0); // CraftBukkit
638 645 }
639 646
640 647 public Entity f() {
641 -@@ -1155,8 +1384,10 @@
648 +@@ -1155,8 +1385,10 @@
642 649 WorldServer[] aworldserver = this.worldServer;
643 650 int i = aworldserver.length;
644 651
645 652 - for (int j = 0; j < i; ++j) {
646 653 - WorldServer worldserver = aworldserver[j];
647 654 + // CraftBukkit start
648 655 + for (int j = 0; j < worlds.size(); ++j) {
649 656 + WorldServer worldserver = worlds.get(j);
650 657 + // CraftBukkit end
651 658
652 659 if (worldserver != null) {
653 660 Entity entity = worldserver.getEntity(uuid);
654 -@@ -1171,7 +1402,7 @@
661 +@@ -1171,7 +1403,7 @@
655 662 }
656 663
657 664 public boolean getSendCommandFeedback() {
658 665 - return getServer().worldServer[0].getGameRules().getBoolean("sendCommandFeedback");
659 666 + return getServer().worlds.get(0).getGameRules().getBoolean("sendCommandFeedback");
660 667 }
661 668
662 669 public void a(CommandObjectiveExecutor.EnumCommandResult commandobjectiveexecutor_enumcommandresult, int i) {}
663 -@@ -1182,7 +1413,7 @@
670 +@@ -1182,7 +1414,7 @@
664 671
665 672 public <V> ListenableFuture<V> a(Callable<V> callable) {
666 673 Validate.notNull(callable);
667 674 - if (!this.isMainThread() && !this.isStopped()) {
668 675 + if (!this.isMainThread()) { // CraftBukkit && !this.isStopped()) {
669 676 ListenableFutureTask listenablefuturetask = ListenableFutureTask.create(callable);
670 677 Queue queue = this.j;
671 678

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut