From 3e8a83ba5c00c5d4f3befb9ff5542fab4b4d455a Mon Sep 17 00:00:00 2001 From: Indyuce Date: Fri, 1 May 2020 19:43:50 +0200 Subject: [PATCH] Added vanilla exp redirection --- .../java/net/Indyuce/mmocore/MMOCore.java | 4 +++ .../listener/option/RedirectVanillaExp.java | 22 ++++++++++++++++ .../option/VanillaExperienceOverride.java | 3 ++- src/main/resources/config.yml | 25 +++++++++++-------- 4 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 src/main/java/net/Indyuce/mmocore/listener/option/RedirectVanillaExp.java diff --git a/src/main/java/net/Indyuce/mmocore/MMOCore.java b/src/main/java/net/Indyuce/mmocore/MMOCore.java index 858ec495..8d9fe626 100644 --- a/src/main/java/net/Indyuce/mmocore/MMOCore.java +++ b/src/main/java/net/Indyuce/mmocore/MMOCore.java @@ -62,6 +62,7 @@ import net.Indyuce.mmocore.listener.WaypointsListener; import net.Indyuce.mmocore.listener.option.DeathExperienceLoss; import net.Indyuce.mmocore.listener.option.HealthScale; import net.Indyuce.mmocore.listener.option.NoSpawnerEXP; +import net.Indyuce.mmocore.listener.option.RedirectVanillaExp; import net.Indyuce.mmocore.listener.option.VanillaExperienceOverride; import net.Indyuce.mmocore.listener.profession.FishingListener; import net.Indyuce.mmocore.listener.profession.PlayerCollectStats; @@ -255,6 +256,9 @@ public class MMOCore extends JavaPlugin { if (getConfig().getBoolean("action-bar.enabled")) new PlayerActionBar(getConfig().getConfigurationSection("action-bar")); + if (getConfig().getBoolean("vanilla-exp-redirection.enabled")) + Bukkit.getPluginManager().registerEvents(new RedirectVanillaExp(getConfig().getDouble("vanilla-exp-redirection.ratio")), this); + /* * enable debug mode for extra debug tools. */ diff --git a/src/main/java/net/Indyuce/mmocore/listener/option/RedirectVanillaExp.java b/src/main/java/net/Indyuce/mmocore/listener/option/RedirectVanillaExp.java new file mode 100644 index 00000000..6e007941 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/listener/option/RedirectVanillaExp.java @@ -0,0 +1,22 @@ +package net.Indyuce.mmocore.listener.option; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerExpChangeEvent; + +import net.Indyuce.mmocore.api.player.PlayerData; + +public class RedirectVanillaExp implements Listener { + private final double ratio; + + public RedirectVanillaExp(double ratio) { + this.ratio = ratio; + } + + @EventHandler + public void a(PlayerExpChangeEvent event) { + int a = (int) (event.getAmount() * ratio); + if (a > 0) + PlayerData.get(event.getPlayer()).giveExperience(a); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/listener/option/VanillaExperienceOverride.java b/src/main/java/net/Indyuce/mmocore/listener/option/VanillaExperienceOverride.java index 79d421c6..8332cadd 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/option/VanillaExperienceOverride.java +++ b/src/main/java/net/Indyuce/mmocore/listener/option/VanillaExperienceOverride.java @@ -2,6 +2,7 @@ package net.Indyuce.mmocore.listener.option; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.enchantment.EnchantItemEvent; import org.bukkit.event.player.PlayerExpChangeEvent; @@ -14,7 +15,7 @@ public class VanillaExperienceOverride implements Listener { /* * when picking up exp orbs or any action like that */ - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void a(PlayerExpChangeEvent event) { event.setAmount(0); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b4852927..d1c7d57e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,11 +1,9 @@ -# Auto-Save feature automatically saves -# playerdata (class, level, etc.) and -# guild data (guild names, members, etc.) -# at a set interval. +# Auto-Save feature automatically saves playerdata +# (class, level, etc.) and guild data +# (guild names, members, etc.) at a set interval. auto-save: enabled: true - # In seconds (1800 = 30 minutes) - interval: 1800 + interval: 1800 # In seconds (1800 = 30 minutes) # MySQL Support mysql: @@ -41,7 +39,8 @@ loot-chest-expire-time: 600 # Settings for the default action bar action-bar: - # Whether or not to use the default action bar. (This doesn't change any other action bars provided by MMOCore.) + # Whether or not to use the default action bar. + # (This doesn't change any other action bars provided by MMOCore.) enabled: true # The decimal format for stats (not including stat formats in stats.yml) @@ -65,6 +64,14 @@ party: # to talk in the party chat. chat-prefix: '@' +# Redirects vanilla experience obtained to MMOCore +# class experience. You can define the % of the vanilla +# experience that is being transfered as MMOCore exp. +# Requires a SERVER reload when changed. +vanilla-exp-redirection: + enabled: false + ratio: 0.8 + # Enable this open to override vanilla EXP and display # level progress on the vanilla experience bar. # Requires a SERVER reload when changed. @@ -93,6 +100,7 @@ display-exp-holograms: true # Players can swap their hotbar with the 9 inventory slots # right above it by pressing [swap items] while crouching. +# THis allows players to have two combat item sets. hotbar-swap: true # Use this option if you're having issue with Anvil GUIs. @@ -109,9 +117,6 @@ combat-log: # Change this to the name of the color you want for # the different resource bar placeholders resource-bar-colors: - mana-whole: 'BLUE' - mana-half: 'AQUA' - mana-empty: 'WHITE' stamina-whole: 'GREEN' stamina-half: 'DARK_GREEN' stamina-empty: 'WHITE'