diff --git a/pom.xml b/pom.xml index 78da0ec..e631a26 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ -LOCAL - 2.21.3 + 2.21.4 BentoBoxWorld_Level bentobox-world https://sonarcloud.io diff --git a/src/main/java/world/bentobox/level/Level.java b/src/main/java/world/bentobox/level/Level.java index 2851348..b9fe809 100644 --- a/src/main/java/world/bentobox/level/Level.java +++ b/src/main/java/world/bentobox/level/Level.java @@ -46,58 +46,58 @@ */ public class Level extends Addon { - // The 10 in top ten - public static final int TEN = 10; - - // Settings - private ConfigSettings settings; - private Config configObject = new Config<>(this, ConfigSettings.class); - private BlockConfig blockConfig; - private Pipeliner pipeliner; - private LevelsManager manager; - private boolean stackersEnabled; - private boolean advChestEnabled; - private boolean roseStackersEnabled; - private boolean ultimateStackerEnabled; - private final List registeredGameModes = new ArrayList<>(); - - /** - * Local variable that stores if warpHook is present. - */ - private Warp warpHook; - - /** - * Local variable that stores if visitHook is present. - */ - private VisitAddon visitHook; - - @Override - public void onLoad() { - // Save the default config from config.yml - saveDefaultConfig(); - if (loadSettings()) { - // Disable - logError("Level settings could not load! Addon disabled."); - setState(State.DISABLED); - } else { - configObject.saveConfigObject(settings); - } - - // Save existing panels. - this.saveResource("panels/top_panel.yml", false); - this.saveResource("panels/detail_panel.yml", false); - this.saveResource("panels/value_panel.yml", false); - } - - private boolean loadSettings() { - // Load settings again to get worlds - settings = configObject.loadConfigObject(); - - return settings == null; - } - - @Override - public void onEnable() { + // The 10 in top ten + public static final int TEN = 10; + + // Settings + private ConfigSettings settings; + private Config configObject = new Config<>(this, ConfigSettings.class); + private BlockConfig blockConfig; + private Pipeliner pipeliner; + private LevelsManager manager; + private boolean stackersEnabled; + private boolean advChestEnabled; + private boolean roseStackersEnabled; + private boolean ultimateStackerEnabled; + private final List registeredGameModes = new ArrayList<>(); + + /** + * Local variable that stores if warpHook is present. + */ + private Warp warpHook; + + /** + * Local variable that stores if visitHook is present. + */ + private VisitAddon visitHook; + + @Override + public void onLoad() { + // Save the default config from config.yml + saveDefaultConfig(); + if (loadSettings()) { + // Disable + logError("Level settings could not load! Addon disabled."); + setState(State.DISABLED); + } else { + configObject.saveConfigObject(settings); + } + + // Save existing panels. + this.saveResource("panels/top_panel.yml", false); + this.saveResource("panels/detail_panel.yml", false); + this.saveResource("panels/value_panel.yml", false); + } + + private boolean loadSettings() { + // Load settings again to get worlds + settings = configObject.loadConfigObject(); + + return settings == null; + } + + @Override + public void onEnable() { // Everything waits until allLoaded } @@ -133,12 +133,12 @@ private void registerAllListeners() { private void registerGameModeCommands() { registeredGameModes.clear(); getPlugin().getAddonsManager().getGameModeAddons().stream() - .filter(gm -> !settings.getGameModes().contains(gm.getDescription().getName())).forEach(gm -> { - log("Level hooking into " + gm.getDescription().getName()); - registerCommands(gm); - new PlaceholderManager(this).registerPlaceholders(gm); - registeredGameModes.add(gm); - }); + .filter(gm -> !settings.getGameModes().contains(gm.getDescription().getName())).forEach(gm -> { + log("Level hooking into " + gm.getDescription().getName()); + registerCommands(gm); + new PlaceholderManager(this).registerPlaceholders(gm); + registeredGameModes.add(gm); + }); } private void registerRequestHandlers() { @@ -190,156 +190,158 @@ private void hookUltimateStacker() { if (ultimateStackerEnabled) { log("Hooked into UltimateStacker."); } - } - - /** - * This method tries to hook into addons and plugins - */ - private void hookExtensions() { - // Try to find Visit addon and if it does not exist, display a warning - this.getAddonByName("Visit").ifPresentOrElse(addon -> { - this.visitHook = (VisitAddon) addon; - this.log("Level Addon hooked into Visit addon."); - }, () -> this.visitHook = null); - - // Try to find Warps addon and if it does not exist, display a warning - this.getAddonByName("Warps").ifPresentOrElse(addon -> { - this.warpHook = (Warp) addon; - this.log("Level Addon hooked into Warps addon."); - }, () -> this.warpHook = null); - } - - /** - * Compares versions - * - * @param version1 version 1 - * @param version2 version 2 - * @return {@code <0 if version 1 is older than version 2, =0 if the same, >0 if version 1 is newer than version 2} - */ - public static int compareVersions(String version1, String version2) { - int comparisonResult = 0; - - String[] version1Splits = version1.split("\\."); - String[] version2Splits = version2.split("\\."); - int maxLengthOfVersionSplits = Math.max(version1Splits.length, version2Splits.length); - - for (int i = 0; i < maxLengthOfVersionSplits; i++) { - Integer v1 = i < version1Splits.length ? Integer.parseInt(version1Splits[i]) : 0; - Integer v2 = i < version2Splits.length ? Integer.parseInt(version2Splits[i]) : 0; - int compare = v1.compareTo(v2); - if (compare != 0) { - comparisonResult = compare; - break; - } - } - return comparisonResult; - } - - private void registerCommands(GameModeAddon gm) { - gm.getAdminCommand().ifPresent(adminCommand -> { - new AdminLevelCommand(this, adminCommand); - new AdminTopCommand(this, adminCommand); - new AdminLevelStatusCommand(this, adminCommand); - if (getSettings().isZeroNewIslandLevels()) { - new AdminSetInitialLevelCommand(this, adminCommand); - } - new AdminStatsCommand(this, adminCommand); - }); - gm.getPlayerCommand().ifPresent(playerCmd -> { - new IslandLevelCommand(this, playerCmd); - new IslandTopCommand(this, playerCmd); - new IslandValueCommand(this, playerCmd); + } + + /** + * This method tries to hook into addons and plugins + */ + private void hookExtensions() { + // Try to find Visit addon and if it does not exist, display a warning + this.getAddonByName("Visit").ifPresentOrElse(addon -> { + this.visitHook = (VisitAddon) addon; + this.log("Level Addon hooked into Visit addon."); + }, () -> this.visitHook = null); + + // Try to find Warps addon and if it does not exist, display a warning + this.getAddonByName("Warps").ifPresentOrElse(addon -> { + this.warpHook = (Warp) addon; + this.log("Level Addon hooked into Warps addon."); + }, () -> this.warpHook = null); + } + + /** + * Compares versions + * + * @param version1 version 1 + * @param version2 version 2 + * @return {@code <0 if version 1 is older than version 2, =0 if the same, >0 if version 1 is newer than version 2} + */ + public static int compareVersions(String version1, String version2) { + int comparisonResult = 0; + + String[] version1Splits = version1.split("\\."); + String[] version2Splits = version2.split("\\."); + int maxLengthOfVersionSplits = Math.max(version1Splits.length, version2Splits.length); + + for (int i = 0; i < maxLengthOfVersionSplits; i++) { + Integer v1 = i < version1Splits.length ? Integer.parseInt(version1Splits[i]) : 0; + Integer v2 = i < version2Splits.length ? Integer.parseInt(version2Splits[i]) : 0; + int compare = v1.compareTo(v2); + if (compare != 0) { + comparisonResult = compare; + break; + } + } + return comparisonResult; + } + + private void registerCommands(GameModeAddon gm) { + gm.getAdminCommand().ifPresent(adminCommand -> { + new AdminLevelCommand(this, adminCommand); + new AdminTopCommand(this, adminCommand); + new AdminLevelStatusCommand(this, adminCommand); + if (getSettings().isZeroNewIslandLevels()) { + new AdminSetInitialLevelCommand(this, adminCommand); + } + new AdminStatsCommand(this, adminCommand); + }); + gm.getPlayerCommand().ifPresent(playerCmd -> { + new IslandLevelCommand(this, playerCmd); + new IslandTopCommand(this, playerCmd); + new IslandValueCommand(this, playerCmd); new IslandDetailCommand(this, playerCmd); - }); - } - - @Override - public void onDisable() { - // Stop the pipeline - this.getPipeliner().stop(); - } - - private void loadBlockSettings() { - // Save the default blockconfig.yml - this.saveResource("blockconfig.yml", false); - - YamlConfiguration blockValues = new YamlConfiguration(); - try { - File file = new File(this.getDataFolder(), "blockconfig.yml"); - blockValues.load(file); - // Load the block config class - blockConfig = new BlockConfig(this, blockValues, file); - } catch (IOException | InvalidConfigurationException e) { - // Disable - logError("Level blockconfig.yml settings could not load! Addon disabled."); - setState(State.DISABLED); - } - - } - - /** - * @return the blockConfig - */ - public BlockConfig getBlockConfig() { - return blockConfig; - } - - /** - * @return the settings - */ - public ConfigSettings getSettings() { - return settings; - } - - /** - * @return the pipeliner - */ - public Pipeliner getPipeliner() { - return pipeliner; - } - - /** - * @return the manager - */ - public LevelsManager getManager() { - return manager; - } - - /** - * Set the config settings - used for tests only - * - * @param configSettings - config settings - */ - void setSettings(ConfigSettings configSettings) { - this.settings = configSettings; - - } - - /** - * @return the stackersEnabled - */ - public boolean isStackersEnabled() { - return stackersEnabled; - } - - /** - * @return the advChestEnabled - */ - public boolean isAdvChestEnabled() { - return advChestEnabled; - } - - /** - * Get level from cache for a player. - * - * @param targetPlayer - target player UUID - * @return Level of player or zero if player is unknown or UUID is null - */ - public long getIslandLevel(World world, @Nullable UUID targetPlayer) { - return getManager().getIslandLevel(world, targetPlayer); - } - - /** + }); + } + + @Override + public void onDisable() { + // Stop the pipeline + if (this.pipeliner != null) { + pipeliner.stop(); + } + } + + private void loadBlockSettings() { + // Save the default blockconfig.yml + this.saveResource("blockconfig.yml", false); + + YamlConfiguration blockValues = new YamlConfiguration(); + try { + File file = new File(this.getDataFolder(), "blockconfig.yml"); + blockValues.load(file); + // Load the block config class + blockConfig = new BlockConfig(this, blockValues, file); + } catch (IOException | InvalidConfigurationException e) { + // Disable + logError("Level blockconfig.yml settings could not load! Addon disabled."); + setState(State.DISABLED); + } + + } + + /** + * @return the blockConfig + */ + public BlockConfig getBlockConfig() { + return blockConfig; + } + + /** + * @return the settings + */ + public ConfigSettings getSettings() { + return settings; + } + + /** + * @return the pipeliner + */ + public Pipeliner getPipeliner() { + return pipeliner; + } + + /** + * @return the manager + */ + public LevelsManager getManager() { + return manager; + } + + /** + * Set the config settings - used for tests only + * + * @param configSettings - config settings + */ + void setSettings(ConfigSettings configSettings) { + this.settings = configSettings; + + } + + /** + * @return the stackersEnabled + */ + public boolean isStackersEnabled() { + return stackersEnabled; + } + + /** + * @return the advChestEnabled + */ + public boolean isAdvChestEnabled() { + return advChestEnabled; + } + + /** + * Get level from cache for a player. + * + * @param targetPlayer - target player UUID + * @return Level of player or zero if player is unknown or UUID is null + */ + public long getIslandLevel(World world, @Nullable UUID targetPlayer) { + return getManager().getIslandLevel(world, targetPlayer); + } + + /** * Sets the player's level to a value. This will only last until the player reruns the level command * * @param world - world @@ -347,21 +349,21 @@ public long getIslandLevel(World world, @Nullable UUID targetPlayer) { * @param level - level * @deprecated This is a useless method. */ - public void setIslandLevel(World world, UUID targetPlayer, long level) { - getManager().setIslandLevel(world, targetPlayer, level); - } - - /** - * Zeros the initial island level - * - * @param island - island - * @param level - initial calculated island level - */ + public void setIslandLevel(World world, UUID targetPlayer, long level) { + getManager().setIslandLevel(world, targetPlayer, level); + } + + /** + * Zeros the initial island level + * + * @param island - island + * @param level - initial calculated island level + */ /* TODO public void setInitialIslandLevel(@NonNull Island island, long level) { getManager().setInitialIslandLevel(island, level); } - + /** * Get the initial island level * @@ -383,29 +385,29 @@ public long getInitialIslandCount(@NonNull Island island) { return getManager().getInitialCount(island); } - /** - * Calculates a user's island - * - * @param world - the world where this island is - * @param user - not used! See depecration message - * @param playerUUID - the target island member's UUID - * @deprecated Do not use this anymore. Use - * getManager().calculateLevel(playerUUID, island) - */ - @Deprecated(since = "2.3.0", forRemoval = true) - public void calculateIslandLevel(World world, @Nullable User user, @NonNull UUID playerUUID) { - Island island = getIslands().getIsland(world, playerUUID); - if (island != null) - getManager().calculateLevel(playerUUID, island); - } - - /** - * Provide the levels data for the target player - * - * @param targetPlayer - UUID of target player - * @return LevelsData object or null if not found. Only island levels are set! - * @deprecated Do not use this anymore. Use {@link #getIslandLevel(World, UUID)} - */ + /** + * Calculates a user's island + * + * @param world - the world where this island is + * @param user - not used! See depecration message + * @param playerUUID - the target island member's UUID + * @deprecated Do not use this anymore. Use + * getManager().calculateLevel(playerUUID, island) + */ + @Deprecated(since = "2.3.0", forRemoval = true) + public void calculateIslandLevel(World world, @Nullable User user, @NonNull UUID playerUUID) { + Island island = getIslands().getIsland(world, playerUUID); + if (island != null) + getManager().calculateLevel(playerUUID, island); + } + + /** + * Provide the levels data for the target player + * + * @param targetPlayer - UUID of target player + * @return LevelsData object or null if not found. Only island levels are set! + * @deprecated Do not use this anymore. Use {@link #getIslandLevel(World, UUID)} + */ /* @Deprecated(since = "2.3.0", forRemoval = true) public LevelsData getLevelsData(UUID targetPlayer) { @@ -423,64 +425,64 @@ public LevelsData getLevelsData(UUID targetPlayer) { return ld; }*/ - /** - * @return the registeredGameModes - */ - public List getRegisteredGameModes() { - return registeredGameModes; - } - - /** - * Check if Level addon is active in game mode - * - * @param gm Game Mode Addon - * @return true if active, false if not - */ - public boolean isRegisteredGameMode(GameModeAddon gm) { - return registeredGameModes.contains(gm); - } - - /** - * Checks if Level addon is active in world - * - * @param world world - * @return true if active, false if not - */ - public boolean isRegisteredGameModeWorld(World world) { - return registeredGameModes.stream().map(GameModeAddon::getOverWorld).anyMatch(w -> Util.sameWorld(world, w)); - } - - /** - * @return the roseStackersEnabled - */ - public boolean isRoseStackersEnabled() { - return roseStackersEnabled; - } - - /** - * @return the ultimateStackerEnabled - */ - public boolean isUltimateStackerEnabled() { - return ultimateStackerEnabled; - } - - /** - * Method Level#getVisitHook returns the visitHook of this object. - * - * @return {@code Visit} of this object, {@code null} otherwise. - */ - public VisitAddon getVisitHook() { - return this.visitHook; - } - - /** - * Method Level#getWarpHook returns the warpHook of this object. - * - * @return {@code Warp} of this object, {@code null} otherwise. - */ - public Warp getWarpHook() { - return this.warpHook; - } + /** + * @return the registeredGameModes + */ + public List getRegisteredGameModes() { + return registeredGameModes; + } + + /** + * Check if Level addon is active in game mode + * + * @param gm Game Mode Addon + * @return true if active, false if not + */ + public boolean isRegisteredGameMode(GameModeAddon gm) { + return registeredGameModes.contains(gm); + } + + /** + * Checks if Level addon is active in world + * + * @param world world + * @return true if active, false if not + */ + public boolean isRegisteredGameModeWorld(World world) { + return registeredGameModes.stream().map(GameModeAddon::getOverWorld).anyMatch(w -> Util.sameWorld(world, w)); + } + + /** + * @return the roseStackersEnabled + */ + public boolean isRoseStackersEnabled() { + return roseStackersEnabled; + } + + /** + * @return the ultimateStackerEnabled + */ + public boolean isUltimateStackerEnabled() { + return ultimateStackerEnabled; + } + + /** + * Method Level#getVisitHook returns the visitHook of this object. + * + * @return {@code Visit} of this object, {@code null} otherwise. + */ + public VisitAddon getVisitHook() { + return this.visitHook; + } + + /** + * Method Level#getWarpHook returns the warpHook of this object. + * + * @return {@code Warp} of this object, {@code null} otherwise. + */ + public Warp getWarpHook() { + return this.warpHook; + } public boolean isItemsAdder() { return !getSettings().isDisableItemsAdder() && getPlugin().getHooks().getHook("ItemsAdder").isPresent(); diff --git a/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java b/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java index 639bcdc..a8005bd 100644 --- a/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java +++ b/src/main/java/world/bentobox/level/calculators/IslandLevelCalculator.java @@ -487,9 +487,6 @@ private void scanAsync(ChunkPair cp) { private void processBlock(ChunkPair cp, int x, int y, int z, int globalX, int globalZ) { BlockData blockData = cp.chunkSnapshot.getBlockData(x, y, z); Material m = blockData.getMaterial(); - if (m.isAir()) { - return; - } boolean belowSeaLevel = seaHeight > 0 && y <= seaHeight; Location loc = new Location(cp.world, globalX, y, globalZ); diff --git a/src/main/java/world/bentobox/level/config/BlockConfig.java b/src/main/java/world/bentobox/level/config/BlockConfig.java index 95d1217..eaaff51 100644 --- a/src/main/java/world/bentobox/level/config/BlockConfig.java +++ b/src/main/java/world/bentobox/level/config/BlockConfig.java @@ -19,7 +19,6 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.EntityType; -import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.hooks.ItemsAdderHook; import world.bentobox.level.Level; @@ -198,7 +197,7 @@ public Map> getWorldSpawnerValues() { } /** - * Retrieves the value associated with a spawner in the specified world, + * Retrieves the value associated with a block in the specified world, * using world-specific settings if available, or falling back to baseline values. * * @param world the world context @@ -229,7 +228,6 @@ public Integer getValue(World world, Object obj) { return value; } } - // Fall back to the baseline value return getBlockValues().get(key); } diff --git a/src/main/resources/blockconfig.yml b/src/main/resources/blockconfig.yml index c03d2da..14aa591 100644 --- a/src/main/resources/blockconfig.yml +++ b/src/main/resources/blockconfig.yml @@ -719,7 +719,7 @@ blocks: tube_coral_block: 0 tube_coral_fan: 0 tube_coral_wall_fan: 0 - turtle_egg: 10 + turtle_egg: 0 twisting_vines: 0 twisting_vines_plant: 0 vine: 0