dizziesv3
📎 1 file 6,549 chars
📄
pasted-code-1791050011894.txt
txt 203 lines
▶
Create a Minecraft Java Paper 1.21.11 plugin called MobImmune.

IMPORTANT:
This plugin must be designed specifically for Paper 1.21.11 and use the modern Paper/Bukkit API. Do not use outdated APIs.

PLUGIN PURPOSE:
Allow admins to make specific players completely ignored by ALL mobs.

COMMANDS:

1. /mobimmune 

This toggles complete mob immunity for the specified player.

Example:
 /mobimmune Coldified

When Coldified is enabled:

- NO mob can target Coldified.
- NO mob can attack Coldified.
- NO hostile mob can damage Coldified.
- NO passive/neutral mob can become aggressive toward Coldified.
- This must work for ALL mobs, including vanilla mobs and mobs that use normal Bukkit/Paper targeting.
- If a mob is already targeting Coldified when immunity is enabled, immediately remove its target.
- If a mob tries to target Coldified afterward, immediately prevent it.
- If a mob is already attacking/chasing Coldified, immediately make it stop.
- Continuously ensure mobs cannot retarget Coldified.
- Prevent mob-target events involving Coldified.
- Also handle mobs that use EntityTargetEvent, EntityTargetLivingEntityEvent, or other applicable Paper/Bukkit targeting mechanisms.
- The protection must not affect other players.
- Coldified can still attack and damage mobs normally.
- Coldified can still be damaged by players normally.
- This is NOT Peaceful difficulty.
- Do NOT disable hunger.
- Do NOT change Coldified's game mode.
- Do NOT give Coldified damage immunity from players or environmental damage.
- Only make mobs unable to target, attack, or damage him.

The immunity must persist through:
- relogging
- death
- respawning
- teleporting
- changing worlds
- server restarts

Store immune players by UUID in a config.yml or data file, NOT by username.

2. /despawn

This command is ONLY usable by a player who currently has mob immunity enabled.

When Coldified runs:

 /despawn

Find every mob/entity within a 100-block radius of Coldified and remove them.

IMPORTANT:
- Radius is exactly 100 blocks from Coldified's current location.
- Only remove mobs/entities, NOT players.
- Never remove Coldified.
- Never remove any other player.
- Remove hostile mobs.
- Remove passive mobs.
- Remove neutral mobs.
- Remove animals.
- Remove monsters.
- Remove villagers.
- Remove wandering traders.
- Remove hostile/neutral entities.
- Include mobs currently targeting someone.
- Do not remove dropped items unless explicitly configured.
- Do not remove experience orbs unless explicitly configured.
- Do not remove projectiles unless explicitly configured.
- Do not remove armor stands, item frames, paintings, minecarts, boats, or other non-mob utility entities unless explicitly configured.
- The default behavior should be to remove living mob entities only.
- Do not affect entities outside the 100-block radius.

After executing /despawn, send Coldified a message such as:

"§aRemoved §f §amobs within 100 blocks."

PERMISSIONS:

mobimmune.admin
- Allows /mobimmune 
- Allows admins to toggle immunity for other players.

mobimmune.despawn
- Allows /despawn.

However, also allow /despawn when the player has immunity enabled, even if they don't have mobimmune.admin.

This means Coldified can have:
mobimmune.despawn

without being able to use /mobimmune on other players.

COMMAND BEHAVIOR:

/mobimmune Coldified
→ Enables immunity if disabled.

/mobimmune Coldified
→ Disables immunity if already enabled.

Send clear messages:

Enabled:
"§aMob immunity enabled for §fColdified§a."

Disabled:
"§cMob immunity disabled for §fColdified§c."

/despawn:
"§aRemoved §f §amobs within 100 blocks."

ERROR HANDLING:

If the player doesn't exist:
"§cPlayer not found."

If someone without permission uses /mobimmune:
"§cYou don't have permission."

If someone without permission uses /despawn:
"§cYou don't have permission."

If a player without immunity tries /despawn:
"§cYou must have mob immunity enabled to use this command."

TECHNICAL REQUIREMENTS:

- Paper 1.21.11.
- Java 21.
- Use UUIDs for persistent immunity.
- Thread-safe handling where appropriate.
- Do not use unnecessary repeating tasks every tick.
- Use Bukkit/Paper events to prevent mob targeting efficiently.
- When immunity is enabled, immediately clear targets of nearby mobs.
- Handle EntityTargetEvent and any relevant Paper targeting events.
- Make sure mobs cannot bypass the protection by using different targeting behavior.
- When a mob attempts to target an immune player, cancel/prevent the target.
- When a mob's target is an immune player, set its target to null.
- Do not interfere with normal mob behavior toward other players.
- Avoid performance-heavy operations across the entire server.
- /despawn should only scan the chunk/entity area around the player and only within the 100-block radius.
- Make the 100-block radius configurable in config.yml, defaulting to 100.
- Make the immune-player list persistent across restarts.

CONFIG:

Create a config.yml like:

mob-immunity:
  persistent: true

despawn:
  radius: 100
  remove-living-mobs-only: true

messages:
  immunity-enabled: "&aMob immunity enabled for &f%player%&a."
  immunity-disabled: "&cMob immunity disabled for &f%player%&c."
  player-not-found: "&cPlayer not found."
  no-permission: "&cYou don't have permission."
  despawn-no-immunity: "&cYou must have mob immunity enabled to use this command."
  despawn-result: "&aRemoved &f%amount% &amobs within &f%radius% &ablocks."

TAB COMPLETION:

Implement tab completion for:
 /mobimmune 
 /despawn

For /mobimmune, suggest online player names.

PLUGIN FILES:

Provide the complete project, including:

- pom.xml OR build.gradle
- src/main/java/.../MobImmunePlugin.java
- all command classes
- event listeners
- persistence/data handling
- plugin.yml
- config.yml

Make sure the project compiles successfully for Paper 1.21.11 with Java 21.

Also explain exactly how to:
1. Compile the plugin.
2. Install the resulting JAR.
3. Give myself mobimmune.admin with LuckPerms.
4. Give Coldified mobimmune.despawn.
5. Enable immunity for Coldified.
6. Use /despawn.

IMPORTANT FINAL TEST:
The finished plugin must guarantee that when Coldified has immunity enabled, mobs will NEVER intentionally target or attack him, regardless of whether the mob was spawned before or after immunity was enabled.
Kodari AI
KodariOct 3 at 6:03 pm 1
  1. Set up a Java 21 Paper 1.21.11 Gradle project and plugin defaults.

  2. Add UUID-based immunity persistence, commands, and tab completion.

  3. Block mob targeting/damage, clear existing targets, and implement configurable-radius despawning.

Created the MobImmune Paper 1.21.11 project. Immunity is stored by UUID, targeting and mob-origin damage are blocked by events, existing targets are cleared on enable and after joining, respawning, or teleporting, and /despawn removes entities within the configured spherical radius. By default, /despawn removes living mobs only; setting despawn.remove-living-mobs-only: false opts into removing other nearby non-player entities too.

Compile and install

  1. On desktop, click Compile in the top bar. On phone, tap ⋮ → Compile Project.

  2. Click Compile in the window that opens, then download the resulting JAR.

  3. Put the JAR in the server’s plugins folder and restart the server.

LuckPerms and commands

Plain Text
/lp user <your-username> permission set mobimmune.admin true
/lp user Coldified permission set mobimmune.despawn true
/mobimmune Coldified

Run /despawn as Coldified. The toggle command currently requires its target to be online.

dizziesv3

can you fix it because they cant damage him but they still target him, make it so they dont even notice him AT ALL

Kodari AI
KodariOct 3 at 6:41 pm 1

Fixed: when a mob targets an immune player, the target event is canceled and the mob’s target is cleared immediately. The plugin also re-clears targets of nearby mobs every 10 ticks to catch mobs that acquire a target through other behavior. This doesn’t affect mobs’ behavior toward other players.

dizziesv3

The wardens are targeting the immune player still

Kodari AI
KodariOct 3 at 6:44 pm 1

Updated Warden handling: wardens use per-player anger in addition to normal mob targets. The plugin now clears their anger toward immune players both when a targeting attempt is blocked and during nearby target cleanup, so they should stop pursuing the immune player.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
9 412
src/main/java/com/kodari/mobimmune/MobImmunePlugin.java
package com.kodari.mobimmune;

import com.kodari.mobimmune.command.DespawnCommand;
import com.kodari.mobimmune.command.MobImmuneCommand;
import com.kodari.mobimmune.listener.MobImmuneListener;
import com.kodari.mobimmune.storage.ImmunityManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;

public final class MobImmunePlugin extends JavaPlugin {
    private ImmunityManager immunityManager;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        immunityManager = new ImmunityManager(this);

        MobImmuneListener listener = new MobImmuneListener(this, immunityManager);
        Bukkit.getPluginManager().registerEvents(listener, this);
        Bukkit.getScheduler().runTaskTimer(this, listener::enforceImmuneTargets, 1L, 10L);

        getCommand("mobimmune").setExecutor(new MobImmuneCommand(this, immunityManager, listener));
        getCommand("mobimmune").setTabCompleter(new MobImmuneCommand(this, immunityManager, listener));
        getCommand("despawn").setExecutor(new DespawnCommand(this, immunityManager));
    }

    public ImmunityManager getImmunityManager() {
        return immunityManager;
    }

    public String getMessage(String key, String... replacements) {
        String message = getConfig().getString("messages." + key, "");
        for (int index = 0; index + 1 < replacements.length; index += 2) {
            message = message.replace(replacements[index], replacements[index + 1]);
        }
        return ChatColor.translateAlternateColorCodes('&', message);
    }
}