@@ -447,395 +447,5 @@ public VisitAddon getVisitHook() {
447
447
public Warp getWarpHook () {
448
448
return this .warpHook ;
449
449
}
450
- =======
451
- // The 10 in top ten
452
- public static final int TEN = 10 ;
453
-
454
- // Settings
455
- private ConfigSettings settings ;
456
- private Config <ConfigSettings > configObject = new Config <>(this , ConfigSettings .class );
457
- private BlockConfig blockConfig ;
458
- private Pipeliner pipeliner ;
459
- private LevelsManager manager ;
460
- private boolean stackersEnabled ;
461
- private boolean advChestEnabled ;
462
- private boolean roseStackersEnabled ;
463
- private boolean ultimateStackerEnabled ;
464
- private final List <GameModeAddon > registeredGameModes = new ArrayList <>();
465
-
466
- /**
467
- * Local variable that stores if warpHook is present.
468
- */
469
- private Warp warpHook ;
470
-
471
- /**
472
- * Local variable that stores if visitHook is present.
473
- */
474
- private VisitAddon visitHook ;
475
-
476
-
477
- @ Override
478
- public void onLoad () {
479
- // Save the default config from config.yml
480
- saveDefaultConfig ();
481
- if (loadSettings ()) {
482
- // Disable
483
- logError ("Level settings could not load! Addon disabled." );
484
- setState (State .DISABLED );
485
- } else {
486
- configObject .saveConfigObject (settings );
487
- }
488
-
489
- // Save existing panels.
490
- this .saveResource ("panels/top_panel.yml" , false );
491
- this .saveResource ("panels/detail_panel.yml" , false );
492
- this .saveResource ("panels/value_panel.yml" , false );
493
- }
494
-
495
- private boolean loadSettings () {
496
- // Load settings again to get worlds
497
- settings = configObject .loadConfigObject ();
498
-
499
- return settings == null ;
500
- }
501
-
502
- @ Override
503
- public void onEnable () {
504
- loadBlockSettings ();
505
- // Start pipeline
506
- pipeliner = new Pipeliner (this );
507
- // Start Manager
508
- manager = new LevelsManager (this );
509
- // Register listeners
510
- this .registerListener (new IslandActivitiesListeners (this ));
511
- this .registerListener (new JoinLeaveListener (this ));
512
- this .registerListener (new MigrationListener (this ));
513
-
514
- // Register commands for GameModes
515
- registeredGameModes .clear ();
516
- getPlugin ().getAddonsManager ().getGameModeAddons ().stream ()
517
- .filter (gm -> !settings .getGameModes ().contains (gm .getDescription ().getName ()))
518
- .forEach (gm -> {
519
- log ("Level hooking into " + gm .getDescription ().getName ());
520
- registerCommands (gm );
521
- new PlaceholderManager (this ).registerPlaceholders (gm );
522
- registeredGameModes .add (gm );
523
- });
524
- // Register request handlers
525
- registerRequestHandler (new LevelRequestHandler (this ));
526
- registerRequestHandler (new TopTenRequestHandler (this ));
527
-
528
- // Check if WildStackers is enabled on the server
529
- // I only added support for counting blocks into the island level
530
- // Someone else can PR if they want spawners added to the Leveling system :)
531
- stackersEnabled = Bukkit .getPluginManager ().isPluginEnabled ("WildStacker" );
532
- if (stackersEnabled ) {
533
- log ("Hooked into WildStackers." );
534
- }
535
- // Check if AdvancedChests is enabled on the server
536
- Plugin advChest = Bukkit .getPluginManager ().getPlugin ("AdvancedChests" );
537
- advChestEnabled = advChest != null ;
538
- if (advChestEnabled ) {
539
- // Check version
540
- if (compareVersions (advChest .getDescription ().getVersion (), "23.0" ) > 0 ) {
541
- log ("Hooked into AdvancedChests." );
542
- } else {
543
- logError ("Could not hook into AdvancedChests " + advChest .getDescription ().getVersion () + " - requires version 23.0 or later" );
544
- advChestEnabled = false ;
545
- }
546
- }
547
- // Check if RoseStackers is enabled
548
- roseStackersEnabled = Bukkit .getPluginManager ().isPluginEnabled ("RoseStacker" );
549
- if (roseStackersEnabled ) {
550
- log ("Hooked into RoseStackers." );
551
- }
552
-
553
- // Check if UltimateStacker is enabled
554
- ultimateStackerEnabled = Bukkit .getPluginManager ().isPluginEnabled ("UltimateStacker" );
555
- if (ultimateStackerEnabled ) {
556
- log ("Hooked into UltimateStacker." );
557
- }
558
- }
559
-
560
- @ Override
561
- public void allLoaded ()
562
- {
563
- super .allLoaded ();
564
-
565
- if (this .isEnabled ())
566
- {
567
- this .hookExtensions ();
568
- }
569
- }
570
-
571
-
572
- /**
573
- * This method tries to hook into addons and plugins
574
- */
575
- private void hookExtensions ()
576
- {
577
- // Try to find Visit addon and if it does not exist, display a warning
578
- this .getAddonByName ("Visit" ).ifPresentOrElse (addon ->
579
- {
580
- this .visitHook = (VisitAddon ) addon ;
581
- this .log ("Level Addon hooked into Visit addon." );
582
- }, () -> this .visitHook = null );
583
-
584
- // Try to find Warps addon and if it does not exist, display a warning
585
- this .getAddonByName ("Warps" ).ifPresentOrElse (addon ->
586
- {
587
- this .warpHook = (Warp ) addon ;
588
- this .log ("Level Addon hooked into Warps addon." );
589
- }, () -> this .warpHook = null );
590
- }
591
-
592
-
593
- /**
594
- * Compares versions
595
- * @param version1 version 1
596
- * @param version2 version 2
597
- * @return {@code <0 if version 1 is older than version 2, =0 if the same, >0 if version 1 is newer than version 2}
598
- */
599
- public static int compareVersions (String version1 , String version2 ) {
600
- int comparisonResult = 0 ;
601
-
602
- String [] version1Splits = version1 .split ("\\ ." );
603
- String [] version2Splits = version2 .split ("\\ ." );
604
- int maxLengthOfVersionSplits = Math .max (version1Splits .length , version2Splits .length );
605
-
606
- for (int i = 0 ; i < maxLengthOfVersionSplits ; i ++){
607
- Integer v1 = i < version1Splits .length ? Integer .parseInt (version1Splits [i ]) : 0 ;
608
- Integer v2 = i < version2Splits .length ? Integer .parseInt (version2Splits [i ]) : 0 ;
609
- int compare = v1 .compareTo (v2 );
610
- if (compare != 0 ) {
611
- comparisonResult = compare ;
612
- break ;
613
- }
614
- }
615
- return comparisonResult ;
616
- }
617
-
618
- private void registerCommands (GameModeAddon gm ) {
619
- gm .getAdminCommand ().ifPresent (adminCommand -> {
620
- new AdminLevelCommand (this , adminCommand );
621
- new AdminTopCommand (this , adminCommand );
622
- new AdminLevelStatusCommand (this , adminCommand );
623
- if (getSettings ().isZeroNewIslandLevels ()) {
624
- new AdminSetInitialLevelCommand (this , adminCommand );
625
- }
626
- });
627
- gm .getPlayerCommand ().ifPresent (playerCmd -> {
628
- new IslandLevelCommand (this , playerCmd );
629
- new IslandTopCommand (this , playerCmd );
630
- new IslandValueCommand (this , playerCmd );
631
- });
632
- }
633
-
634
- @ Override
635
- public void onDisable () {
636
- // Stop the pipeline
637
- this .getPipeliner ().stop ();
638
- }
639
-
640
- private void loadBlockSettings () {
641
- // Save the default blockconfig.yml
642
- this .saveResource ("blockconfig.yml" , false );
643
-
644
- YamlConfiguration blockValues = new YamlConfiguration ();
645
- try {
646
- File file = new File (this .getDataFolder (), "blockconfig.yml" );
647
- blockValues .load (file );
648
- // Load the block config class
649
- blockConfig = new BlockConfig (this , blockValues , file );
650
- } catch (IOException | InvalidConfigurationException e ) {
651
- // Disable
652
- logError ("Level blockconfig.yml settings could not load! Addon disabled." );
653
- setState (State .DISABLED );
654
- }
655
-
656
- }
657
-
658
-
659
- /**
660
- * @return the blockConfig
661
- */
662
- public BlockConfig getBlockConfig () {
663
- return blockConfig ;
664
- }
665
-
666
- /**
667
- * @return the settings
668
- */
669
- public ConfigSettings getSettings () {
670
- return settings ;
671
- }
672
-
673
- /**
674
- * @return the pipeliner
675
- */
676
- public Pipeliner getPipeliner () {
677
- return pipeliner ;
678
- }
679
-
680
- /**
681
- * @return the manager
682
- */
683
- public LevelsManager getManager () {
684
- return manager ;
685
- }
686
-
687
- /**
688
- * Set the config settings - used for tests only
689
- * @param configSettings - config settings
690
- */
691
- void setSettings (ConfigSettings configSettings ) {
692
- this .settings = configSettings ;
693
-
694
- }
695
-
696
- /**
697
- * @return the stackersEnabled
698
- */
699
- public boolean isStackersEnabled () {
700
- return stackersEnabled ;
701
- }
702
-
703
- /**
704
- * @return the advChestEnabled
705
- */
706
- public boolean isAdvChestEnabled () {
707
- return advChestEnabled ;
708
- }
709
-
710
- /**
711
- * Get level from cache for a player.
712
- * @param targetPlayer - target player UUID
713
- * @return Level of player or zero if player is unknown or UUID is null
714
- */
715
- public long getIslandLevel (World world , @ Nullable UUID targetPlayer ) {
716
- return getManager ().getIslandLevel (world , targetPlayer );
717
- }
718
-
719
- /**
720
- * Sets the player's level to a value
721
- * @param world - world
722
- * @param targetPlayer - target player
723
- * @param level - level
724
- */
725
- public void setIslandLevel (World world , UUID targetPlayer , long level ) {
726
- getManager ().setIslandLevel (world , targetPlayer , level );
727
- }
728
-
729
- /**
730
- * Zeros the initial island level
731
- * @param island - island
732
- * @param level - initial calculated island level
733
- */
734
- public void setInitialIslandLevel (@ NonNull Island island , long level ) {
735
- getManager ().setInitialIslandLevel (island , level );
736
- }
737
-
738
- /**
739
- * Get the initial island level
740
- * @param island - island
741
- * @return level or 0 by default
742
- */
743
- public long getInitialIslandLevel (@ NonNull Island island ) {
744
- return getManager ().getInitialLevel (island );
745
- }
746
-
747
- /**
748
- * Calculates a user's island
749
- * @param world - the world where this island is
750
- * @param user - not used! See depecration message
751
- * @param playerUUID - the target island member's UUID
752
- * @deprecated Do not use this anymore. Use getManager().calculateLevel(playerUUID, island)
753
- */
754
- @ Deprecated (since ="2.3.0" , forRemoval =true )
755
- public void calculateIslandLevel (World world , @ Nullable User user , @ NonNull UUID playerUUID ) {
756
- Island island = getIslands ().getIsland (world , playerUUID );
757
- if (island != null ) getManager ().calculateLevel (playerUUID , island );
758
- }
759
-
760
- /**
761
- * Provide the levels data for the target player
762
- * @param targetPlayer - UUID of target player
763
- * @return LevelsData object or null if not found. Only island levels are set!
764
- * @deprecated Do not use this anymore. Use {@link #getIslandLevel(World, UUID)}
765
- */
766
- @ Deprecated (since ="2.3.0" , forRemoval =true )
767
- public LevelsData getLevelsData (UUID targetPlayer ) {
768
- LevelsData ld = new LevelsData (targetPlayer );
769
- getPlugin ().getAddonsManager ().getGameModeAddons ().stream ()
770
- .filter (gm -> !settings .getGameModes ().contains (gm .getDescription ().getName ()))
771
- .forEach (gm -> {
772
- if (getSettings ().isZeroNewIslandLevels ()) {
773
- Island island = getIslands ().getIsland (gm .getOverWorld (), targetPlayer );
774
- if (island != null ) {
775
- ld .setInitialLevel (gm .getOverWorld (), this .getInitialIslandLevel (island ));
776
- }
777
- }
778
- ld .setLevel (gm .getOverWorld (), this .getIslandLevel (gm .getOverWorld (), targetPlayer ));
779
- });
780
- return ld ;
781
- }
782
-
783
- /**
784
- * @return the registeredGameModes
785
- */
786
- public List <GameModeAddon > getRegisteredGameModes () {
787
- return registeredGameModes ;
788
- }
789
-
790
- /**
791
- * Check if Level addon is active in game mode
792
- * @param gm Game Mode Addon
793
- * @return true if active, false if not
794
- */
795
- public boolean isRegisteredGameMode (GameModeAddon gm ) {
796
- return registeredGameModes .contains (gm );
797
- }
798
-
799
- /**
800
- * Checks if Level addon is active in world
801
- * @param world world
802
- * @return true if active, false if not
803
- */
804
- public boolean isRegisteredGameModeWorld (World world ) {
805
- return registeredGameModes .stream ().map (GameModeAddon ::getOverWorld ).anyMatch (w -> Util .sameWorld (world , w ));
806
- }
807
-
808
- /**
809
- * @return the roseStackersEnabled
810
- */
811
- public boolean isRoseStackersEnabled () {
812
- return roseStackersEnabled ;
813
- }
814
-
815
- /**
816
- * @return the ultimateStackerEnabled
817
- */
818
- public boolean isUltimateStackerEnabled () {
819
- return ultimateStackerEnabled ;
820
- }
821
-
822
- /**
823
- * Method Level#getVisitHook returns the visitHook of this object.
824
- *
825
- * @return {@code Visit} of this object, {@code null} otherwise.
826
- */
827
- public VisitAddon getVisitHook ()
828
- {
829
- return this .visitHook ;
830
- }
831
-
832
- /**
833
- * Method Level#getWarpHook returns the warpHook of this object.
834
- *
835
- * @return {@code Warp} of this object, {@code null} otherwise.
836
- */
837
- public Warp getWarpHook ()
838
- {
839
- return this .warpHook ;
840
- }
450
+
841
451
}
0 commit comments