diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml deleted file mode 100644 index f61c073..0000000 --- a/dependency-reduced-pom.xml +++ /dev/null @@ -1,111 +0,0 @@ - - - 4.0.0 - dev.sefiraat - Netheopoiesis - MODIFIED - - ${basedir}/src/main/java - clean package - - - true - ${basedir}/src/main/resources - - **/*.* - tags/*.json - - - - ${project.name} v${project.version} - - - maven-shade-plugin - 3.3.0 - - - package - - shade - - - - - - - org.bstats - dev.sefiraat.netheopoiesis.bstats - - - io.github.bakedlibs.dough - dev.sefiraat.netheopoiesis.dough - - - io.papermc.lib - dev.sefiraat.netheopoiesis.paperlib - - - - - *:* - - META-INF/* - - - - - - - maven-compiler-plugin - 3.10.1 - - 16 - 16 - - - - - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - jitpack.io - https://jitpack.io - - - papermc - https://papermc.io/repo/repository/maven-public/ - - - - - org.spigotmc - spigot-api - 1.19-R0.1-SNAPSHOT - provided - - - com.github.Slimefun - Slimefun4 - 2c4f886 - provided - - - - java:S6206 - ** - e1,e2,e3 - 16 - java:S125 - https://sonarcloud.io - sefiraat - Networks - 16 - UTF-8 - ** - ** - java:S6212 - - diff --git a/src/main/java/dev/sefiraat/netheopoiesis/Netheopoiesis.java b/src/main/java/dev/sefiraat/netheopoiesis/Netheopoiesis.java index f7174db..641adef 100644 --- a/src/main/java/dev/sefiraat/netheopoiesis/Netheopoiesis.java +++ b/src/main/java/dev/sefiraat/netheopoiesis/Netheopoiesis.java @@ -51,9 +51,9 @@ public void onEnable() { getLogger().info("########################################"); saveDefaultConfig(); + this.configManager = new ConfigManager(); tryUpdate(); - this.configManager = new ConfigManager(); this.supportedPluginManager = new SupportedPluginManager(); this.listenerManager = new ListenerManager(); this.runnableManager = new RunnableManager(); @@ -73,9 +73,7 @@ public void onDisable() { } public void tryUpdate() { - if (getConfig().getBoolean("auto-update") - && getDescription().getVersion().startsWith("DEV") - ) { + if (configManager.isAutoUpdate() && getDescription().getVersion().startsWith("DEV")) { String updateLocation = MessageFormat.format("{0}/{1}/{2}", this.username, this.repo, this.branch); GitHubBuildsUpdater updater = new GitHubBuildsUpdater(this, getFile(), updateLocation); updater.start(); diff --git a/src/main/java/dev/sefiraat/netheopoiesis/api/mobs/MobCap.java b/src/main/java/dev/sefiraat/netheopoiesis/api/mobs/MobCap.java index e6e9511..671703e 100644 --- a/src/main/java/dev/sefiraat/netheopoiesis/api/mobs/MobCap.java +++ b/src/main/java/dev/sefiraat/netheopoiesis/api/mobs/MobCap.java @@ -1,5 +1,6 @@ package dev.sefiraat.netheopoiesis.api.mobs; +import dev.sefiraat.netheopoiesis.Netheopoiesis; import org.bukkit.Bukkit; import org.bukkit.entity.Entity; import org.jetbrains.annotations.Unmodifiable; @@ -12,15 +13,50 @@ public class MobCap { - public static final MobCap WATER_AMBIENT = new MobCap(MobCapType.WATER_AMBIENT, 15); - public static final MobCap WATER_ANIMAL = new MobCap(MobCapType.WATER_ANIMAL, 5); - public static final MobCap WATER_HOSTILE = new MobCap(MobCapType.WATER_HOSTILE, 10); - public static final MobCap LAND_AMBIENT = new MobCap(MobCapType.WATER_AMBIENT, 5); - public static final MobCap LAND_ANIMAL = new MobCap(MobCapType.LAND_ANIMAL, 10); - public static final MobCap LAND_HOSTILE = new MobCap(MobCapType.LAND_HOSTILE, 10); - public static final MobCap VILLAGER = new MobCap(MobCapType.VILLAGER, 5); - public static final MobCap PIGLIN_TRADER = new MobCap(MobCapType.PIGLIN_TRADER, 1); - public static final MobCap WANDERING_TRADER = new MobCap(MobCapType.WANDERING_TRADER, 1); + public static final MobCap WATER_AMBIENT = new MobCap( + MobCapType.WATER_AMBIENT, + Netheopoiesis.getConfigManager().getPlayerMobCapWaterAmbient() + ); + + public static final MobCap WATER_ANIMAL = new MobCap( + MobCapType.WATER_ANIMAL, + Netheopoiesis.getConfigManager().getPlayerMobCapWaterAnimal() + ); + + public static final MobCap WATER_HOSTILE = new MobCap( + MobCapType.WATER_HOSTILE, + Netheopoiesis.getConfigManager().getPlayerMobCapWaterHostile() + ); + + public static final MobCap LAND_AMBIENT = new MobCap( + MobCapType.WATER_AMBIENT, + Netheopoiesis.getConfigManager().getPlayerMobCapLandAmbient() + ); + + public static final MobCap LAND_ANIMAL = new MobCap( + MobCapType.LAND_ANIMAL, + Netheopoiesis.getConfigManager().getPlayerMobCapLandAnimal() + ); + + public static final MobCap LAND_HOSTILE = new MobCap( + MobCapType.LAND_HOSTILE, + Netheopoiesis.getConfigManager().getPlayerMobCapLandHostile() + ); + + public static final MobCap VILLAGER = new MobCap( + MobCapType.VILLAGER, + Netheopoiesis.getConfigManager().getPlayerMobCapVillager() + ); + + public static final MobCap PIGLIN_TRADER = new MobCap( + MobCapType.PIGLIN_TRADER, + Netheopoiesis.getConfigManager().getPlayerMobCapPiglinTrader() + ); + + public static final MobCap WANDERING_TRADER = new MobCap( + MobCapType.WANDERING_TRADER, + Netheopoiesis.getConfigManager().getPlayerMobCapWanderingTrader() + ); private final int amountPerPlayer; @Nonnull @@ -35,6 +71,7 @@ public MobCap(@Nonnull MobCapType type, int maxPerPlayer) { /** * Gets the number of mobs currently held in this cap + * * @return The number of mobs currently held in this cap */ public int count() { @@ -43,6 +80,7 @@ public int count() { /** * Checks if there is space in this cap for another mob + * * @return true if there is space */ public boolean hasSpace() { @@ -51,6 +89,7 @@ public boolean hasSpace() { /** * Checks if a given {@link UUID} is contained in this cap + * * @param mobUuid The {@link UUID} for the mob being checked * @return true if contained in the cap */ @@ -61,6 +100,7 @@ public boolean contains(@Nonnull UUID mobUuid) { /** * Adds a new mob to this cap. Does not check for space and can be forced if required. * Check hasSpace() first! + * * @param mobUuid The {@link UUID} of the mob to add */ public void addMob(@Nonnull UUID mobUuid) { @@ -69,6 +109,7 @@ public void addMob(@Nonnull UUID mobUuid) { /** * Removes a mob from this cap if possible + * * @param mobUuid The {@link UUID} of the mob to remove */ public void removeMob(@Nonnull UUID mobUuid) { @@ -77,6 +118,7 @@ public void removeMob(@Nonnull UUID mobUuid) { /** * Kills a mob whilst also removing them from the cap + * * @param mobUuid The {@link UUID} of the mob to kill/remove */ public void killMob(@Nonnull UUID mobUuid) { @@ -102,6 +144,7 @@ public void killAllMobs() { /** * Gets the maximum number of spawns, per player, for this cap. + * * @return The max number of mobs */ public int getMaxAmountPerPlayer() { @@ -110,6 +153,7 @@ public int getMaxAmountPerPlayer() { /** * Gets the maximum number of spawns for this cap (includes the multiplier per-player) + * * @return The max number of mobs */ public int getMaxAmount() { @@ -118,6 +162,7 @@ public int getMaxAmount() { /** * The {@link MobCapType} for this cap + * * @return The {@link MobCapType} for this cap */ @Nonnull @@ -127,6 +172,7 @@ public MobCapType getType() { /** * Gets an immutable list of all mobs contained within this cap + * * @return An immutable list of all mobs contained within this cap */ @Nonnull diff --git a/src/main/java/dev/sefiraat/netheopoiesis/managers/ConfigManager.java b/src/main/java/dev/sefiraat/netheopoiesis/managers/ConfigManager.java index 435e154..76d0643 100644 --- a/src/main/java/dev/sefiraat/netheopoiesis/managers/ConfigManager.java +++ b/src/main/java/dev/sefiraat/netheopoiesis/managers/ConfigManager.java @@ -1,12 +1,20 @@ package dev.sefiraat.netheopoiesis.managers; import dev.sefiraat.netheopoiesis.Netheopoiesis; +import dev.sefiraat.netheopoiesis.api.items.NetherSeed; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; +import org.yaml.snakeyaml.Yaml; import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; import java.io.File; +import java.io.FileReader; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; /** * This class is used to create and manage/save custom configuration files @@ -17,9 +25,48 @@ public class ConfigManager { private final FileConfiguration discoveries; public ConfigManager() { + setupDefaultConfig(); this.discoveries = getConfig("discoveries.yml"); } + private void setupDefaultConfig() { + final Netheopoiesis plugin = Netheopoiesis.getInstance(); + final InputStream inputStream = plugin.getResource("config.yml"); + final File existingFile = new File(plugin.getDataFolder(), "config.yml"); + + if (inputStream == null) { + // Not sure how? Regardless cannot copy over new keys + return; + } + + final Reader reader = new InputStreamReader(inputStream); + final FileConfiguration resourceConfig = YamlConfiguration.loadConfiguration(reader); + final FileConfiguration existingConfig = YamlConfiguration.loadConfiguration(existingFile); + + for (String key : resourceConfig.getKeys(false)) { + checkKey(existingConfig, resourceConfig, key); + } + + try { + existingConfig.save(existingFile); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @ParametersAreNonnullByDefault + private void checkKey(FileConfiguration existingConfig, FileConfiguration resourceConfig, String key) { + final Object currentValue = existingConfig.get(key); + final Object newValue = resourceConfig.get(key); + if (newValue instanceof ConfigurationSection section) { + for (String sectionKey : section.getKeys(false)) { + checkKey(existingConfig, resourceConfig, key + "." + sectionKey); + } + } else if (currentValue == null) { + existingConfig.set(key, newValue); + } + } + @Nonnull @SuppressWarnings("ResultOfMethodCallIgnored") private FileConfiguration getConfig(@Nonnull String fileName) { @@ -54,4 +101,48 @@ private void saveDiscoveries() { public FileConfiguration getDiscoveries() { return discoveries; } + + public boolean isAutoUpdate() { + return Netheopoiesis.getInstance().getConfig().getBoolean("auto-update"); + } + + public boolean isDebugMessages() { + return Netheopoiesis.getInstance().getConfig().getBoolean("debug-messages"); + } + + public int getPlayerMobCapWaterAmbient() { + return Netheopoiesis.getInstance().getConfig().getInt("spawning.player-cap-water-ambient"); + } + + public int getPlayerMobCapWaterAnimal() { + return Netheopoiesis.getInstance().getConfig().getInt("spawning.player-cap-water-animal"); + } + + public int getPlayerMobCapWaterHostile() { + return Netheopoiesis.getInstance().getConfig().getInt("spawning.player-cap-water-hostile"); + } + + public int getPlayerMobCapLandAmbient() { + return Netheopoiesis.getInstance().getConfig().getInt("spawning.player-cap-land-ambient"); + } + + public int getPlayerMobCapLandAnimal() { + return Netheopoiesis.getInstance().getConfig().getInt("spawning.player-cap-land-animal"); + } + + public int getPlayerMobCapLandHostile() { + return Netheopoiesis.getInstance().getConfig().getInt("spawning.player-cap-land-hostile"); + } + + public int getPlayerMobCapVillager() { + return Netheopoiesis.getInstance().getConfig().getInt("spawning.player-cap-villager"); + } + + public int getPlayerMobCapPiglinTrader() { + return Netheopoiesis.getInstance().getConfig().getInt("spawning.player-cap-piglin-trader"); + } + + public int getPlayerMobCapWanderingTrader() { + return Netheopoiesis.getInstance().getConfig().getInt("spawning.player-cap-wandering-trader"); + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f6e6442..cbfa8ac 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,2 +1,16 @@ auto-update: true -debug-messages: false \ No newline at end of file +debug-messages: false +spawning: + player-cap-water-ambient: 15 + player-cap-water-animal: 5 + player-cap-water-hostile: 10 + player-cap-land-ambient: 5 + player-cap-land-animal: 10 + player-cap-land-hostile: 10 + player-cap-villager: 5 + player-cap-piglin-trader: 1 + player-cap-wandering-trader: 1 +speed: + speed-multiplier-crux-spread: 1 + speed-crystalline-crux-spread: 1 + speed-plant-growth-rate: 1