diff --git a/pom.xml b/pom.xml index 00a7612..b6a27f5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.justeli.coins Coins - 1.13 + 1.13.1 Coins Coins is a plugin that allows players to collect coins for killing mobs and mining precious blocks. It also comes with the ability to withdraw balance into physical coins. https://www.spigotmc.org/resources/coins.33382/ diff --git a/src/main/java/me/justeli/coins/Coins.java b/src/main/java/me/justeli/coins/Coins.java index f7f5ec8..9fbc173 100644 --- a/src/main/java/me/justeli/coins/Coins.java +++ b/src/main/java/me/justeli/coins/Coins.java @@ -13,6 +13,7 @@ import me.justeli.coins.handler.PickupHandler; import me.justeli.coins.handler.DropHandler; import me.justeli.coins.handler.listener.PaperEventListener; +import me.justeli.coins.hook.levelledmobs.LevelledMobsHandler; import me.justeli.coins.hook.mythicmobs.MMHook; import me.justeli.coins.hook.bstats.Metrics; import me.justeli.coins.config.Config; @@ -109,6 +110,8 @@ else if (mm.isPresent()) } } + this.levelledMobsHandler = new LevelledMobsHandler(); + if (this.disabledReasons.size() == 0) { this.settings = new Settings(this); @@ -298,6 +301,10 @@ public boolean toggleDisabled () private MMHook mmHook; + private LevelledMobsHandler levelledMobsHandler; + + public LevelledMobsHandler getLevelledMobsHandler(){ return this.levelledMobsHandler; } + public Optional mmHook () { return Optional.ofNullable(this.mmHook); diff --git a/src/main/java/me/justeli/coins/config/Config.java b/src/main/java/me/justeli/coins/config/Config.java index 6994dfc..f44020d 100644 --- a/src/main/java/me/justeli/coins/config/Config.java +++ b/src/main/java/me/justeli/coins/config/Config.java @@ -30,6 +30,8 @@ public class Config @ConfigEntry ("drop-with-any-death") public static Boolean DROP_WITH_ANY_DEATH = false; @ConfigEntry ("enchanted-coin") public static Boolean ENCHANTED_COIN = false; @ConfigEntry ("disable-mythic-mob-handling") public static Boolean DISABLE_MYTHIC_MOB_HANDLING = false; + + @ConfigEntry("levelledmobs-level-multiplier") public static Double LEVELLEDMOBS_LEVEL_MULTIPLIER = 0.0; @ConfigEntry (value = "detect-legacy-coins", motivation = "It is recommended that you add this option to the Coins config as soon as you can, " + "AND SET IT TO FALSE. Please note: Keep this option to true if you have withdrawn coins laying around in the server from before Coins " + "version 1.11. Also leave the keys 'name-of-coin' and 'multi-suffix' untouched, if you set 'detect-legacy-coins' to true! Legacy withdrawn " + diff --git a/src/main/java/me/justeli/coins/handler/DropHandler.java b/src/main/java/me/justeli/coins/handler/DropHandler.java index f17c07b..7c0867e 100644 --- a/src/main/java/me/justeli/coins/handler/DropHandler.java +++ b/src/main/java/me/justeli/coins/handler/DropHandler.java @@ -60,6 +60,8 @@ public void onEntityDeath (EntityDeathEvent event) if (Util.isDisabledHere(dead.getWorld())) return; + coins.getLevelledMobsHandler().lastKilledMob = dead; + if (this.coins.mmHook().isPresent() && Config.DISABLE_MYTHIC_MOB_HANDLING && this.coins.mmHook().get().isMythicMob(dead)) return; @@ -274,6 +276,10 @@ private void drop (int amount, @Nullable Player player, @NotNull Location locati amount *= Util.getMultiplier(player); } + double lmMultiplier = coins.getLevelledMobsHandler().getLevelledMobsMultipliedAmount(increment); + if (lmMultiplier > 0.0) + increment = lmMultiplier; + for (int i = 0; i < amount; i++) { location.getWorld().dropItem( diff --git a/src/main/java/me/justeli/coins/hook/levelledmobs/LevelledMobsHandler.java b/src/main/java/me/justeli/coins/hook/levelledmobs/LevelledMobsHandler.java new file mode 100644 index 0000000..0db6163 --- /dev/null +++ b/src/main/java/me/justeli/coins/hook/levelledmobs/LevelledMobsHandler.java @@ -0,0 +1,48 @@ +package me.justeli.coins.hook.levelledmobs; + +import me.justeli.coins.config.Config; +import org.bukkit.Bukkit; +import org.bukkit.NamespacedKey; +import org.bukkit.entity.LivingEntity; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.plugin.Plugin; + +public class LevelledMobsHandler { + public LevelledMobsHandler(){ + Plugin lmPlugin = Bukkit.getPluginManager().getPlugin("LevelledMobs"); + this.isInstalled = lmPlugin != null && Bukkit.getPluginManager().isPluginEnabled("LevelledMobs"); + if (this.isInstalled) + this.levelKey = new NamespacedKey(lmPlugin, "level"); + } + + private final boolean isInstalled; + private NamespacedKey levelKey; + public LivingEntity lastKilledMob; + + public boolean getIsInstalled(){ + return this.isInstalled; + } + + public int getMobLevel(LivingEntity livingEntity){ + if (!this.isInstalled || this.levelKey == null || + !livingEntity.getPersistentDataContainer().has(this.levelKey, PersistentDataType.INTEGER)) + return 0; + + Integer mobLevel = livingEntity.getPersistentDataContainer().get(this.levelKey, PersistentDataType.INTEGER); + + return mobLevel != null ? + mobLevel : 0; + } + + public double getLevelledMobsMultipliedAmount(double increment){ + if (lastKilledMob == null || !getIsInstalled()) + return 0.0; + + if (Config.LEVELLEDMOBS_LEVEL_MULTIPLIER == 0.0) return 0.0; + + int mobLevel = getMobLevel(lastKilledMob); + if (mobLevel <= 1) return 0.0; + + return increment + Config.LEVELLEDMOBS_LEVEL_MULTIPLIER * (double) mobLevel; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 67fcc9a..9d27dbd 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -247,6 +247,11 @@ detect-legacy-coins: false # drops for Mythic Mobs handled by this plugin, under here. disable-mythic-mob-handling: false + +# LevelledMobs :: If the LevelledMobs plugin is installed you can utilize the following +# multiplier so higher level mobs give higher rewards +levelledmobs-level-multiplier: 0.0 + # # # # # # # # Player Death # # # # # # # # diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 68bfc14..6797891 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,7 +5,7 @@ website: '${project.url}' description: '${project.description}' api-version: '1.14' authors: [JustEli] -softdepend: [Vault, Treasury, WorldGuard, mcMMO, MythicMobs] +softdepend: [Vault, Treasury, WorldGuard, mcMMO, MythicMobs, LevelledMobs] commands: coins: description: 'Command for showing all available commands from Coins. Also used for various admin tools.'