From 09accfc0f0e25033dc53e17aa63632e0b3220989 Mon Sep 17 00:00:00 2001 From: Indyuce Date: Fri, 30 Dec 2022 18:05:51 +0100 Subject: [PATCH] Made combat log damage causes configurable --- .../mmocore/manager/ConfigManager.java | 32 +++++++++++++++---- .../mmocore/listener/PlayerListener.java | 31 ++++++++++++------ MMOCore-Dist/src/main/resources/config.yml | 20 ++++++++++-- 3 files changed, 64 insertions(+), 19 deletions(-) diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index 15a301e4..5ee23906 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -1,6 +1,7 @@ package net.Indyuce.mmocore.manager; import io.lumine.mythic.lib.MythicLib; +import io.lumine.mythic.lib.UtilityMethods; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigFile; import net.Indyuce.mmocore.api.player.PlayerData; @@ -11,11 +12,14 @@ import net.Indyuce.mmocore.command.api.CommandVerbose; import org.bukkit.ChatColor; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.util.Consumer; +import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.util.ArrayList; import java.util.List; import java.util.logging.Level; @@ -26,8 +30,9 @@ public class ConfigManager { public String partyChatPrefix, noSkillBoundPlaceholder; public ChatColor staminaFull, staminaHalf, staminaEmpty; public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown; - public double lootChestsChanceWeight,dropItemsChanceWeight, fishingDropsChanceWeight, partyMaxExpSplitRange; + public double lootChestsChanceWeight, dropItemsChanceWeight, fishingDropsChanceWeight, partyMaxExpSplitRange; public int maxPartyLevelDifference, maxBoundActiveSkills, maxBoundPassiveSkills; + public final List combatLogDamageCauses = new ArrayList<>(); private final FileConfiguration messages; @@ -76,12 +81,12 @@ public class ConfigManager { loadDefaultFile("expcurves", "mining.txt"); } - if(!new File(MMOCore.plugin.getDataFolder()+"/skill-trees").exists()) { - loadDefaultFile("skill-trees","combat.yml"); - loadDefaultFile("skill-trees","mage-arcane-mage.yml"); - loadDefaultFile("skill-trees","rogue-marksman.yml"); - loadDefaultFile("skill-trees","warrior-paladin.yml"); - loadDefaultFile("skill-trees","general.yml"); + if (!new File(MMOCore.plugin.getDataFolder() + "/skill-trees").exists()) { + loadDefaultFile("skill-trees", "combat.yml"); + loadDefaultFile("skill-trees", "mage-arcane-mage.yml"); + loadDefaultFile("skill-trees", "rogue-marksman.yml"); + loadDefaultFile("skill-trees", "warrior-paladin.yml"); + loadDefaultFile("skill-trees", "general.yml"); } loadDefaultFile("attributes.yml"); @@ -102,7 +107,17 @@ public class ConfigManager { messages = new ConfigFile("messages").getConfig(); partyChatPrefix = MMOCore.plugin.getConfig().getString("party.chat-prefix"); + + // Combat log combatLogTimer = MMOCore.plugin.getConfig().getInt("combat-log.timer") * 1000L; + combatLogDamageCauses.clear(); + for (String key : MMOCore.plugin.getConfig().getStringList("combat-log.causes")) + try { + combatLogDamageCauses.add(EntityDamageEvent.DamageCause.valueOf(UtilityMethods.enumName(key))); + } catch (Exception exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, "Could not find damage cause called '" + key + "'"); + } + lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 20; lootChestPlayerCooldown = (long) MMOCore.plugin.getConfig().getDouble("player-cooldown") * 1000L; globalSkillCooldown = MMOCore.plugin.getConfig().getLong("global-skill-cooldown") * 50; @@ -115,9 +130,11 @@ public class ConfigManager { splitProfessionExp = MMOCore.plugin.getConfig().getBoolean("party.profession-exp-split"); disableQuestBossBar = MMOCore.plugin.getConfig().getBoolean("mmocore-quests.disable-boss-bar"); + // Resources staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN); staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN); staminaEmpty = getColorOrDefault("stamina-empty", ChatColor.WHITE); + passiveSkillNeedBound = MMOCore.plugin.getConfig().getBoolean("passive-skill-need-bound"); canCreativeCast = MMOCore.plugin.getConfig().getBoolean("can-creative-cast"); cobbleGeneratorXP = MMOCore.plugin.getConfig().getBoolean("should-cobblestone-generators-give-exp"); @@ -127,6 +144,7 @@ public class ConfigManager { overrideVanillaExp = MMOCore.plugin.getConfig().getBoolean("override-vanilla-exp"); } + @NotNull private ChatColor getColorOrDefault(String key, ChatColor defaultColor) { try { return ChatColor.valueOf(MMOCore.plugin.getConfig().getString("resource-bar-colors." + key).toUpperCase()); diff --git a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java index 4cef1d12..6a18d339 100644 --- a/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java +++ b/MMOCore-Dist/src/main/java/net/Indyuce/mmocore/listener/PlayerListener.java @@ -9,9 +9,11 @@ import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource; import net.Indyuce.mmocore.gui.api.InventoryClickContext; import net.Indyuce.mmocore.gui.api.PluginInventory; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.inventory.InventoryClickEvent; @@ -28,7 +30,7 @@ public class PlayerListener implements Listener { * might rely on its data on startup. */ @EventHandler(priority = EventPriority.LOW) - public void playerLoadingEvent(PlayerJoinEvent event) { + public void loadPlayerData(PlayerJoinEvent event) { MMOCore.plugin.dataProvider.getDataManager().setup(event.getPlayer().getUniqueId()); } @@ -36,7 +38,7 @@ public class PlayerListener implements Listener { * Register custom inventory clicks */ @EventHandler - public void b(InventoryClickEvent event) { + public void registerInventoryClicks(InventoryClickEvent event) { if (event.getInventory().getHolder() instanceof PluginInventory) ((PluginInventory) event.getInventory().getHolder()).whenClicked(new InventoryClickContext(event.getRawSlot(), event.getCurrentItem(), event.getClick(), event, event.getInventory(), (PluginInventory) event.getInventory().getHolder())); } @@ -45,7 +47,7 @@ public class PlayerListener implements Listener { * Register custom inventory close effect */ @EventHandler - public void c(InventoryCloseEvent event) { + public void registerInventoryCloses(InventoryCloseEvent event) { if (event.getInventory().getHolder() instanceof PluginInventory) ((PluginInventory) event.getInventory().getHolder()).whenClosed(event); } @@ -54,13 +56,22 @@ public class PlayerListener implements Listener { * Updates the player's combat log data every time he hits an entity, or * gets hit by an entity or a projectile sent by another entity */ - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void d(PlayerAttackEvent event) { + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void updateCombat(PlayerAttackEvent event) { PlayerData.get(event.getAttacker().getPlayer()).updateCombat(); } + /** + * Updates the player's combat log everytime he gets hit. + */ + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void updateCombat(EntityDamageEvent event) { + if (event.getEntity() instanceof Player && MMOCore.plugin.configManager.combatLogDamageCauses.contains(event.getCause())) + PlayerData.get(event.getEntity().getUniqueId()).updateCombat(); + } + @EventHandler - public void e(PlayerQuitEvent event) { + public void saveDataOnQuit(PlayerQuitEvent event) { PlayerData playerData = PlayerData.get(event.getPlayer()); MMOCore.plugin.dataProvider.getDataManager().unregisterSafe(playerData); } @@ -68,20 +79,20 @@ public class PlayerListener implements Listener { /** * Using the Bukkit health update event is not a good way of * interacting with MMOCore health regeneration. The - * PlayerResourceUpdateEvent should be heavily prioritized if possible. + * PlayerResourceUpdateEvent should be heavily prioritized. *

* This method makes sure that all the plugins which * utilize this event can also communicate with MMOCore */ @EventHandler(priority = EventPriority.HIGH) - public void g(PlayerResourceUpdateEvent event) { + public void resourceBukkitInterface(PlayerResourceUpdateEvent event) { if (event.getResource() == PlayerResource.HEALTH) { - EntityRegainHealthEvent bukkitEvent = new EntityRegainHealthEvent(event.getPlayer(), event.getAmount(), RegainReason.CUSTOM); + final EntityRegainHealthEvent bukkitEvent = new EntityRegainHealthEvent(event.getPlayer(), event.getAmount(), RegainReason.CUSTOM); Bukkit.getPluginManager().callEvent(bukkitEvent); // Update event values - event.setCancelled(bukkitEvent.isCancelled()); event.setAmount(bukkitEvent.getAmount()); + event.setCancelled(bukkitEvent.isCancelled()); } } } diff --git a/MMOCore-Dist/src/main/resources/config.yml b/MMOCore-Dist/src/main/resources/config.yml index 286e3cdb..513dd1dd 100644 --- a/MMOCore-Dist/src/main/resources/config.yml +++ b/MMOCore-Dist/src/main/resources/config.yml @@ -233,10 +233,26 @@ ability-targeting-options: # Prevents mobs spawned from spawners from giving MMO XP points. prevent-spawner-xp: true -# Timer for combat log to expire (in seconds) combat-log: + + # Timer for combat log to expire (in seconds) timer: 10 + # Damage causes that trigger combat when a player is hit + # List: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/EntityDamageEvent.DamageCause.html + causes: + - CRAMMING + - DRAGON_BREATH + - ENTITY_ATTACK + - ENTITY_EXPLOSION + - ENTITY_SWEEP_ATTACK + - MAGIC + - POISON + - PROJECTILE + - SONIC_BOOM + - THORNS + - WITHER + # Whether or not the default class should save information (level, # skills, etc.) when selecting a new class save-default-class-info: false @@ -270,4 +286,4 @@ command-verbose: points: true reset: true resource: true - waypoint: true \ No newline at end of file + waypoint: true