Made combat log damage causes configurable

This commit is contained in:
Indyuce 2022-12-30 18:05:51 +01:00
parent 05264fe30a
commit 09accfc0f0
3 changed files with 64 additions and 19 deletions

View File

@ -1,6 +1,7 @@
package net.Indyuce.mmocore.manager; package net.Indyuce.mmocore.manager;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigFile; import net.Indyuce.mmocore.api.ConfigFile;
import net.Indyuce.mmocore.api.player.PlayerData; 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.ChatColor;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.util.Consumer; import org.bukkit.util.Consumer;
import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
@ -26,8 +30,9 @@ public class ConfigManager {
public String partyChatPrefix, noSkillBoundPlaceholder; public String partyChatPrefix, noSkillBoundPlaceholder;
public ChatColor staminaFull, staminaHalf, staminaEmpty; public ChatColor staminaFull, staminaHalf, staminaEmpty;
public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown; public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown;
public double lootChestsChanceWeight,dropItemsChanceWeight, fishingDropsChanceWeight, partyMaxExpSplitRange; public double lootChestsChanceWeight, dropItemsChanceWeight, fishingDropsChanceWeight, partyMaxExpSplitRange;
public int maxPartyLevelDifference, maxBoundActiveSkills, maxBoundPassiveSkills; public int maxPartyLevelDifference, maxBoundActiveSkills, maxBoundPassiveSkills;
public final List<EntityDamageEvent.DamageCause> combatLogDamageCauses = new ArrayList<>();
private final FileConfiguration messages; private final FileConfiguration messages;
@ -76,12 +81,12 @@ public class ConfigManager {
loadDefaultFile("expcurves", "mining.txt"); loadDefaultFile("expcurves", "mining.txt");
} }
if(!new File(MMOCore.plugin.getDataFolder()+"/skill-trees").exists()) { if (!new File(MMOCore.plugin.getDataFolder() + "/skill-trees").exists()) {
loadDefaultFile("skill-trees","combat.yml"); loadDefaultFile("skill-trees", "combat.yml");
loadDefaultFile("skill-trees","mage-arcane-mage.yml"); loadDefaultFile("skill-trees", "mage-arcane-mage.yml");
loadDefaultFile("skill-trees","rogue-marksman.yml"); loadDefaultFile("skill-trees", "rogue-marksman.yml");
loadDefaultFile("skill-trees","warrior-paladin.yml"); loadDefaultFile("skill-trees", "warrior-paladin.yml");
loadDefaultFile("skill-trees","general.yml"); loadDefaultFile("skill-trees", "general.yml");
} }
loadDefaultFile("attributes.yml"); loadDefaultFile("attributes.yml");
@ -102,7 +107,17 @@ public class ConfigManager {
messages = new ConfigFile("messages").getConfig(); messages = new ConfigFile("messages").getConfig();
partyChatPrefix = MMOCore.plugin.getConfig().getString("party.chat-prefix"); partyChatPrefix = MMOCore.plugin.getConfig().getString("party.chat-prefix");
// Combat log
combatLogTimer = MMOCore.plugin.getConfig().getInt("combat-log.timer") * 1000L; 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; lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 20;
lootChestPlayerCooldown = (long) MMOCore.plugin.getConfig().getDouble("player-cooldown") * 1000L; lootChestPlayerCooldown = (long) MMOCore.plugin.getConfig().getDouble("player-cooldown") * 1000L;
globalSkillCooldown = MMOCore.plugin.getConfig().getLong("global-skill-cooldown") * 50; 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"); splitProfessionExp = MMOCore.plugin.getConfig().getBoolean("party.profession-exp-split");
disableQuestBossBar = MMOCore.plugin.getConfig().getBoolean("mmocore-quests.disable-boss-bar"); disableQuestBossBar = MMOCore.plugin.getConfig().getBoolean("mmocore-quests.disable-boss-bar");
// Resources
staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN); staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN);
staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN); staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN);
staminaEmpty = getColorOrDefault("stamina-empty", ChatColor.WHITE); staminaEmpty = getColorOrDefault("stamina-empty", ChatColor.WHITE);
passiveSkillNeedBound = MMOCore.plugin.getConfig().getBoolean("passive-skill-need-bound"); passiveSkillNeedBound = MMOCore.plugin.getConfig().getBoolean("passive-skill-need-bound");
canCreativeCast = MMOCore.plugin.getConfig().getBoolean("can-creative-cast"); canCreativeCast = MMOCore.plugin.getConfig().getBoolean("can-creative-cast");
cobbleGeneratorXP = MMOCore.plugin.getConfig().getBoolean("should-cobblestone-generators-give-exp"); 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"); overrideVanillaExp = MMOCore.plugin.getConfig().getBoolean("override-vanilla-exp");
} }
@NotNull
private ChatColor getColorOrDefault(String key, ChatColor defaultColor) { private ChatColor getColorOrDefault(String key, ChatColor defaultColor) {
try { try {
return ChatColor.valueOf(MMOCore.plugin.getConfig().getString("resource-bar-colors." + key).toUpperCase()); return ChatColor.valueOf(MMOCore.plugin.getConfig().getString("resource-bar-colors." + key).toUpperCase());

View File

@ -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.InventoryClickContext;
import net.Indyuce.mmocore.gui.api.PluginInventory; import net.Indyuce.mmocore.gui.api.PluginInventory;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
@ -28,7 +30,7 @@ public class PlayerListener implements Listener {
* might rely on its data on startup. * might rely on its data on startup.
*/ */
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void playerLoadingEvent(PlayerJoinEvent event) { public void loadPlayerData(PlayerJoinEvent event) {
MMOCore.plugin.dataProvider.getDataManager().setup(event.getPlayer().getUniqueId()); MMOCore.plugin.dataProvider.getDataManager().setup(event.getPlayer().getUniqueId());
} }
@ -36,7 +38,7 @@ public class PlayerListener implements Listener {
* Register custom inventory clicks * Register custom inventory clicks
*/ */
@EventHandler @EventHandler
public void b(InventoryClickEvent event) { public void registerInventoryClicks(InventoryClickEvent event) {
if (event.getInventory().getHolder() instanceof PluginInventory) 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())); ((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 * Register custom inventory close effect
*/ */
@EventHandler @EventHandler
public void c(InventoryCloseEvent event) { public void registerInventoryCloses(InventoryCloseEvent event) {
if (event.getInventory().getHolder() instanceof PluginInventory) if (event.getInventory().getHolder() instanceof PluginInventory)
((PluginInventory) event.getInventory().getHolder()).whenClosed(event); ((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 * 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 * gets hit by an entity or a projectile sent by another entity
*/ */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void d(PlayerAttackEvent event) { public void updateCombat(PlayerAttackEvent event) {
PlayerData.get(event.getAttacker().getPlayer()).updateCombat(); 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 @EventHandler
public void e(PlayerQuitEvent event) { public void saveDataOnQuit(PlayerQuitEvent event) {
PlayerData playerData = PlayerData.get(event.getPlayer()); PlayerData playerData = PlayerData.get(event.getPlayer());
MMOCore.plugin.dataProvider.getDataManager().unregisterSafe(playerData); 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 * Using the Bukkit health update event is not a good way of
* interacting with MMOCore health regeneration. The * interacting with MMOCore health regeneration. The
* PlayerResourceUpdateEvent should be heavily prioritized if possible. * PlayerResourceUpdateEvent should be heavily prioritized.
* <p> * <p>
* This method makes sure that all the plugins which * This method makes sure that all the plugins which
* utilize this event can also communicate with MMOCore * utilize this event can also communicate with MMOCore
*/ */
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void g(PlayerResourceUpdateEvent event) { public void resourceBukkitInterface(PlayerResourceUpdateEvent event) {
if (event.getResource() == PlayerResource.HEALTH) { 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); Bukkit.getPluginManager().callEvent(bukkitEvent);
// Update event values // Update event values
event.setCancelled(bukkitEvent.isCancelled());
event.setAmount(bukkitEvent.getAmount()); event.setAmount(bukkitEvent.getAmount());
event.setCancelled(bukkitEvent.isCancelled());
} }
} }
} }

View File

@ -233,10 +233,26 @@ ability-targeting-options:
# Prevents mobs spawned from spawners from giving MMO XP points. # Prevents mobs spawned from spawners from giving MMO XP points.
prevent-spawner-xp: true prevent-spawner-xp: true
# Timer for combat log to expire (in seconds)
combat-log: combat-log:
# Timer for combat log to expire (in seconds)
timer: 10 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, # Whether or not the default class should save information (level,
# skills, etc.) when selecting a new class # skills, etc.) when selecting a new class
save-default-class-info: false save-default-class-info: false
@ -270,4 +286,4 @@ command-verbose:
points: true points: true
reset: true reset: true
resource: true resource: true
waypoint: true waypoint: true