slashbanggun8

Make the effect "hexed" from terramity deal less damage to mobs but deal the same damage against players

Kodari AI
KodariNov 1 at 10:46 am 1
HexedDamageScaling
Adjusts the Terramity "hexed" status effect so it deals reduced damage to mobs while maintaining full damage against players. The plugin intercepts damage events, checks if the source is the hexed effect, and applies a configurable damage multiplier based on whether the target is a player or a non-player entity. Includes a configuration file for tuning the mob damage reduction percentage, ensuring PvP balance remains unchanged while PvE combat becomes more forgiving.

Created a Paper plugin that halves damage from entities with terramity:hexed against mobs, while leaving damage against players unchanged. It also checks projectile owners.

Compatibility caveat: Terramity is a Minecraft mod, and standard Paper cannot load it or access its custom effects. This plugin can detect Hexed only on a hybrid server that exposes the effect through Bukkit; changing the effect in Terramity itself requires a mod project/source.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
3 77
src/main/java/com/kodari/terramityhexedbalance/TerramityHexedBalancePlugin.java
package com.kodari.terramityhexedbalance;

import org.bukkit.NamespacedKey;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffectType;

public final class TerramityHexedBalancePlugin extends JavaPlugin implements Listener {
    private static final NamespacedKey HEXED_KEY = NamespacedKey.fromString("terramity:hexed");
    private static final double MOB_DAMAGE_MULTIPLIER = 0.5;

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
    public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
        if (!(event.getEntity() instanceof LivingEntity target) || target instanceof Player) {
            return;
        }

        LivingEntity attacker = getLivingAttacker(event.getDamager());
        if (attacker == null || HEXED_KEY == null) {
            return;
        }

        PotionEffectType hexed = PotionEffectType.getByKey(HEXED_KEY);
        if (hexed != null && attacker.hasPotionEffect(hexed)) {
            event.setDamage(event.getDamage() * MOB_DAMAGE_MULTIPLIER);
        }
    }

    private LivingEntity getLivingAttacker(Entity damager) {
        if (damager instanceof LivingEntity living) {
            return living;
        }
        if (damager instanceof Projectile projectile && projectile.getShooter() instanceof LivingEntity living) {
            return living;
        }
        return null;
    }
}