Commits

Aikar authored 64492523a76
Move WorldSaveEvent to proper location

calling CraftWorld.save() currently does not call WorldSaveEvent, and WorldSaveEvent could fire on worlds that have saving disabled. New location will always fire during a world save and only during an actual save.
No tags

nms-patches/MinecraftServer.patch

Modified
1 ---- ../work/decompile-8eb82bde//net/minecraft/server/MinecraftServer.java Sat Nov 29 19:31:45 2014
2 -+++ src/main/java/net/minecraft/server/MinecraftServer.java Sat Nov 29 19:27:57 2014
1 +--- ../decompile-8eb82bde//net/minecraft/server/MinecraftServer.java 2014-12-03 14:33:55.037564649 -0500
2 ++++ src/main/java/net/minecraft/server/MinecraftServer.java 2014-12-03 14:33:47.061564766 -0500
3 3 @@ -37,6 +37,18 @@
4 4 import org.apache.logging.log4j.LogManager;
5 5 import org.apache.logging.log4j.Logger;
6 6
7 7 +// CraftBukkit start
8 8 +import java.io.IOException;
9 9 +
10 10 +import jline.console.ConsoleReader;
11 11 +import joptsimple.OptionSet;
12 12 +
269 269 }
270 270 }
271 271
272 272 + for (WorldServer world : this.worlds) {
273 273 + this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(world.getWorld()));
274 274 + }
275 275 + // CraftBukkit end
276 276 this.q();
277 277 }
278 278
279 -@@ -247,35 +390,42 @@
279 +@@ -247,35 +390,38 @@
280 280 protected void q() {
281 281 this.e = null;
282 282 this.f = 0;
283 283 +
284 284 + this.server.enablePlugins(org.bukkit.plugin.PluginLoadOrder.POSTWORLD); // CraftBukkit
285 285 }
286 286
287 287 - protected void saveChunks(boolean flag) {
288 288 + protected void saveChunks(boolean flag) throws ExceptionWorldConflict { // CraftBukkit - added throws
289 289 if (!this.N) {
302 302 MinecraftServer.LOGGER.info("Saving chunks for level \'" + worldserver.getWorldData().getName() + "\'/" + worldserver.worldProvider.getName());
303 303 }
304 304
305 305 - try {
306 306 - worldserver.save(true, (IProgressUpdate) null);
307 307 - } catch (ExceptionWorldConflict exceptionworldconflict) {
308 308 - MinecraftServer.LOGGER.warn(exceptionworldconflict.getMessage());
309 309 - }
310 310 + worldserver.save(true, (IProgressUpdate) null);
311 311 + worldserver.saveLevel();
312 -+
313 -+ WorldSaveEvent event = new WorldSaveEvent(worldserver.getWorld());
314 -+ this.server.getPluginManager().callEvent(event);
315 -+ // CraftBukkit end
316 312 }
317 313 }
318 314
319 315 }
320 316 }
321 317
322 318 - public void stop() {
323 319 + public void stop() throws ExceptionWorldConflict { // CraftBukkit - added throws
324 320 if (!this.N) {
325 321 MinecraftServer.LOGGER.info("Stopping server");
326 322 + // CraftBukkit start
327 323 + if (this.server != null) {
328 324 + this.server.disablePlugins();
329 325 + }
330 326 + // CraftBukkit end
331 327 if (this.ao() != null) {
332 328 this.ao().b();
333 329 }
334 -@@ -290,11 +440,13 @@
330 +@@ -290,11 +436,13 @@
335 331 MinecraftServer.LOGGER.info("Saving worlds");
336 332 this.saveChunks(false);
337 333
338 334 + /* CraftBukkit start - Handled in saveChunks
339 335 for (int i = 0; i < this.worldServer.length; ++i) {
340 336 WorldServer worldserver = this.worldServer[i];
341 337
342 338 worldserver.saveLevel();
343 339 }
344 340 + // CraftBukkit end */
345 341 }
346 342
347 343 if (this.m.d()) {
348 -@@ -335,6 +487,7 @@
344 +@@ -335,6 +483,7 @@
349 345 long k = j - this.ab;
350 346
351 347 if (k > 2000L && this.ab - this.R >= 15000L) {
352 348 + if (server.getWarnOnOverload()) // CraftBukkit
353 349 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)});
354 350 k = 2000L;
355 351 this.R = this.ab;
356 -@@ -347,11 +500,12 @@
352 +@@ -347,11 +496,12 @@
357 353
358 354 i += k;
359 355 this.ab = j;
360 356 - if (this.worldServer[0].everyoneDeeplySleeping()) {
361 357 + if (this.worlds.get(0).everyoneDeeplySleeping()) { // CraftBukkit
362 358 this.y();
363 359 i = 0L;
364 360 } else {
365 361 while (i > 50L) {
366 362 + MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
367 363 i -= 50L;
368 364 this.y();
369 365 }
370 -@@ -389,6 +543,12 @@
366 +@@ -389,6 +539,12 @@
371 367 } catch (Throwable throwable1) {
372 368 MinecraftServer.LOGGER.error("Exception stopping the server", throwable1);
373 369 } finally {
374 370 + // CraftBukkit start - Restore terminal to original settings
375 371 + try {
376 372 + reader.getTerminal().restore();
377 373 + } catch (Exception ignored) {
378 374 + }
379 375 + // CraftBukkit end
380 376 this.x();
381 377 }
382 378
383 -@@ -428,7 +588,7 @@
379 +@@ -428,7 +584,7 @@
384 380
385 381 protected void x() {}
386 382
387 383 - protected void y() {
388 384 + protected void y() throws ExceptionWorldConflict { // CraftBukkit - added throws
389 385 long i = System.nanoTime();
390 386
391 387 ++this.ticks;
392 -@@ -454,7 +614,7 @@
388 +@@ -454,7 +610,7 @@
393 389 this.r.b().a(agameprofile);
394 390 }
395 391
396 392 - if (this.ticks % 900 == 0) {
397 393 + if (autosavePeriod > 0 && this.ticks % autosavePeriod == 0) { // CraftBukkit
398 394 this.methodProfiler.a("save");
399 395 this.v.savePlayers();
400 396 this.saveChunks(true);
401 -@@ -493,20 +653,40 @@
397 +@@ -493,20 +649,40 @@
402 398
403 399 this.methodProfiler.c("levels");
404 400
405 401 + // CraftBukkit start
406 402 + this.server.getScheduler().mainThreadHeartbeat(this.ticks);
407 403 +
408 404 + // Run tasks that are waiting on processing
409 405 + while (!processQueue.isEmpty()) {
410 406 + processQueue.remove().run();
411 407 + }
435 431 + /* Drop global time updates
436 432 if (this.ticks % 20 == 0) {
437 433 this.methodProfiler.a("timeSync");
438 434 this.v.a(new PacketPlayOutUpdateTime(worldserver.getTime(), worldserver.getDayTime(), worldserver.getGameRules().getBoolean("doDaylightCycle")), worldserver.worldProvider.getDimension());
439 435 this.methodProfiler.b();
440 436 }
441 437 + // CraftBukkit end */
442 438
443 439 this.methodProfiler.a("tick");
444 440
445 -@@ -533,9 +713,9 @@
441 +@@ -533,9 +709,9 @@
446 442 worldserver.getTracker().updatePlayers();
447 443 this.methodProfiler.b();
448 444 this.methodProfiler.b();
449 445 - }
450 446 + // } // CraftBukkit
451 447
452 448 - this.h[i][this.ticks % 100] = System.nanoTime() - j;
453 449 + // this.h[i][this.ticks % 100] = System.nanoTime() - j; // CraftBukkit
454 450 }
455 451
456 452 this.methodProfiler.c("connection");
457 -@@ -559,10 +739,11 @@
453 +@@ -559,10 +735,11 @@
458 454 this.o.add(iupdateplayerlistbox);
459 455 }
460 456
461 457 - public static void main(String[] astring) {
462 458 + public static void main(final OptionSet options) { // CraftBukkit - replaces main(String[] astring)
463 459 DispenserRegistry.c();
464 460
465 461 try {
466 462 + /* CraftBukkit start - Replace everything
467 463 boolean flag = true;
468 464 String s = null;
469 465 String s1 = ".";
470 -@@ -636,6 +817,27 @@
466 +@@ -636,6 +813,27 @@
471 467
472 468 dedicatedserver.B();
473 469 Runtime.getRuntime().addShutdownHook(new ThreadShutdown("Server Shutdown Thread", dedicatedserver));
474 470 + */
475 471 +
476 472 + DedicatedServer dedicatedserver = new DedicatedServer(options);
477 473 +
478 474 + if (options.has("port")) {
479 475 + int port = (Integer) options.valueOf("port");
480 476 + if (port > 0) {
488 484 +
489 485 + if (options.has("world")) {
490 486 + dedicatedserver.setWorld((String) options.valueOf("world"));
491 487 + }
492 488 +
493 489 + dedicatedserver.primaryThread.start();
494 490 + // CraftBukkit end
495 491 } catch (Exception exception) {
496 492 MinecraftServer.LOGGER.fatal("Failed to start the minecraft server", exception);
497 493 }
498 -@@ -643,8 +845,10 @@
494 +@@ -643,8 +841,10 @@
499 495 }
500 496
501 497 public void B() {
502 498 + /* CraftBukkit start - prevent abuse
503 499 this.serverThread = new Thread(this, "Server thread");
504 500 this.serverThread.start();
505 501 + // CraftBukkit end */
506 502 }
507 503
508 504 public File d(String s) {
509 -@@ -660,7 +864,14 @@
505 +@@ -660,7 +860,14 @@
510 506 }
511 507
512 508 public WorldServer getWorldServer(int i) {
513 509 - return i == -1 ? this.worldServer[1] : (i == 1 ? this.worldServer[2] : this.worldServer[0]);
514 510 + // CraftBukkit start
515 511 + for (WorldServer world : worlds) {
516 512 + if (world.dimension == i) {
517 513 + return world;
518 514 + }
519 515 + }
520 516 + return worlds.get(0);
521 517 + // CraftBukkit end
522 518 }
523 519
524 520 public String C() {
525 -@@ -696,17 +907,62 @@
521 +@@ -696,17 +903,62 @@
526 522 }
527 523
528 524 public String getPlugins() {
529 525 - return "";
530 526 - }
531 527 + // CraftBukkit start - Whole method
532 528 + StringBuilder result = new StringBuilder();
533 529 + org.bukkit.plugin.Plugin[] plugins = server.getPluginManager().getPlugins();
534 530 +
535 531 + result.append(server.getName());
585 581 + }
586 582 + // CraftBukkit end
587 583 }
588 584
589 585 public boolean isDebugging() {
590 586 - return false;
591 587 + return this.getPropertyManager().getBoolean("debug", false); // CraftBukkit - don't hardcode
592 588 }
593 589
594 590 public void h(String s) {
595 -@@ -721,7 +977,7 @@
591 +@@ -721,7 +973,7 @@
596 592 }
597 593
598 594 public String getServerModName() {
599 595 - return "vanilla";
600 596 + return server.getName(); // CraftBukkit - cb > vanilla!
601 597 }
602 598
603 599 public CrashReport b(CrashReport crashreport) {
604 -@@ -734,6 +990,7 @@
600 +@@ -734,6 +986,7 @@
605 601 }
606 602
607 603 public List tabCompleteCommand(ICommandListener icommandlistener, String s, BlockPosition blockposition) {
608 604 + /* CraftBukkit start - Allow tab-completion of Bukkit commands
609 605 ArrayList arraylist = Lists.newArrayList();
610 606
611 607 if (s.startsWith("/")) {
612 -@@ -772,6 +1029,9 @@
608 +@@ -772,6 +1025,9 @@
613 609
614 610 return arraylist;
615 611 }
616 612 + */
617 613 + return server.tabComplete(icommandlistener, s);
618 614 + // CraftBukkit end
619 615 }
620 616
621 617 public static MinecraftServer getServer() {
622 -@@ -779,7 +1039,7 @@
618 +@@ -779,7 +1035,7 @@
623 619 }
624 620
625 621 public boolean N() {
626 622 - return this.universe != null;
627 623 + return true; // CraftBukkit
628 624 }
629 625
630 626 public String getName() {
631 -@@ -835,8 +1095,10 @@
627 +@@ -835,8 +1091,10 @@
632 628 }
633 629
634 630 public void a(EnumDifficulty enumdifficulty) {
635 631 - for (int i = 0; i < this.worldServer.length; ++i) {
636 632 - WorldServer worldserver = this.worldServer[i];
637 633 + // CraftBukkit start
638 634 + for (int i = 0; i < this.worlds.size(); ++i) {
639 635 + WorldServer worldserver = this.worlds.get(i);
640 636 + // CraftBukkit end
641 637
642 638 if (worldserver != null) {
643 639 if (worldserver.getWorldData().isHardcore()) {
644 -@@ -878,15 +1140,17 @@
640 +@@ -878,15 +1136,17 @@
645 641 this.N = true;
646 642 this.getConvertable().d();
647 643
648 644 - for (int i = 0; i < this.worldServer.length; ++i) {
649 645 - WorldServer worldserver = this.worldServer[i];
650 646 + // CraftBukkit start
651 647 + for (int i = 0; i < this.worlds.size(); ++i) {
652 648 + WorldServer worldserver = this.worlds.get(i);
653 649 + // CraftBukkit end
654 650
655 651 if (worldserver != null) {
656 652 worldserver.saveLevel();
657 653 }
658 654 }
659 655
660 656 - this.getConvertable().e(this.worldServer[0].getDataManager().g());
661 657 + this.getConvertable().e(this.worlds.get(0).getDataManager().g()); // CraftBukkit
662 658 this.safeShutdown();
663 659 }
664 660
665 -@@ -919,9 +1183,11 @@
661 +@@ -919,9 +1179,11 @@
666 662 int i = 0;
667 663
668 664 if (this.worldServer != null) {
669 665 - for (int j = 0; j < this.worldServer.length; ++j) {
670 666 - if (this.worldServer[j] != null) {
671 667 - WorldServer worldserver = this.worldServer[j];
672 668 + // CraftBukkit start
673 669 + for (int j = 0; j < this.worlds.size(); ++j) {
674 670 + WorldServer worldserver = this.worlds.get(j);
675 671 + if (worldserver != null) {
676 672 + // CraftBukkit end
677 673 WorldData worlddata = worldserver.getWorldData();
678 674
679 675 mojangstatisticsgenerator.a("world[" + i + "][dimension]", Integer.valueOf(worldserver.worldProvider.getDimension()));
680 -@@ -954,7 +1220,7 @@
676 +@@ -954,7 +1216,7 @@
681 677 public abstract boolean ad();
682 678
683 679 public boolean getOnlineMode() {
684 680 - return this.onlineMode;
685 681 + return server.getOnlineMode(); // CraftBukkit
686 682 }
687 683
688 684 public void setOnlineMode(boolean flag) {
689 -@@ -1024,8 +1290,10 @@
685 +@@ -1024,8 +1286,10 @@
690 686 }
691 687
692 688 public void setGamemode(EnumGamemode enumgamemode) {
693 689 - for (int i = 0; i < this.worldServer.length; ++i) {
694 690 - getServer().worldServer[i].getWorldData().setGameType(enumgamemode);
695 691 + // CraftBukkit start
696 692 + for (int i = 0; i < this.worlds.size(); ++i) {
697 693 + getServer().worlds.get(i).getWorldData().setGameType(enumgamemode);
698 694 + // CraftBukkit end
699 695 }
700 696
701 697 }
702 -@@ -1057,7 +1325,7 @@
698 +@@ -1057,7 +1321,7 @@
703 699 }
704 700
705 701 public World getWorld() {
706 702 - return this.worldServer[0];
707 703 + return this.worlds.get(0); // CraftBukkit
708 704 }
709 705
710 706 public Entity f() {
711 -@@ -1125,11 +1393,10 @@
707 +@@ -1125,11 +1389,10 @@
712 708 }
713 709
714 710 public Entity a(UUID uuid) {
715 711 - WorldServer[] aworldserver = this.worldServer;
716 712 - int i = aworldserver.length;
717 713 -
718 714 - for (int j = 0; j < i; ++j) {
719 715 - WorldServer worldserver = aworldserver[j];
720 716 + // CraftBukkit start
721 717 + for (int j = 0; j < worlds.size(); ++j) {
722 718 + WorldServer worldserver = worlds.get(j);
723 719 + // CraftBukkit end
724 720
725 721 if (worldserver != null) {
726 722 Entity entity = worldserver.getEntity(uuid);
727 -@@ -1144,7 +1411,7 @@
723 +@@ -1144,7 +1407,7 @@
728 724 }
729 725
730 726 public boolean getSendCommandFeedback() {
731 727 - return getServer().worldServer[0].getGameRules().getBoolean("sendCommandFeedback");
732 728 + return getServer().worlds.get(0).getGameRules().getBoolean("sendCommandFeedback"); // CraftBukkit
733 729 }
734 730
735 731 public void a(EnumCommandResult enumcommandresult, int i) {}

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

Add shortcut