mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-29 01:05:40 +01:00
Made combat log damage causes configurable
This commit is contained in:
parent
05264fe30a
commit
09accfc0f0
@ -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;
|
||||
|
||||
@ -28,6 +32,7 @@ public class ConfigManager {
|
||||
public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown;
|
||||
public double lootChestsChanceWeight, dropItemsChanceWeight, fishingDropsChanceWeight, partyMaxExpSplitRange;
|
||||
public int maxPartyLevelDifference, maxBoundActiveSkills, maxBoundPassiveSkills;
|
||||
public final List<EntityDamageEvent.DamageCause> combatLogDamageCauses = new ArrayList<>();
|
||||
|
||||
private final FileConfiguration messages;
|
||||
|
||||
@ -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());
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user