acquist_

can you make a 1.21.11 plugin that adds a command /division when u run it u are given an unbreakable fishing rod enchanted with infinity. when you hit an entity with a hitbox (left click), the next time u pull the rod (right click), you and that entity will swap positions and motion and angle you are looking the rod must automatically reel back in once u have swapped and the swap must work player to player aswell

Kodari AI
KodariSep 14 at 4:02 am 2
RodSwap
Adds a /division command granting players an unbreakable fishing rod with Infinity enchantment. When a player left-clicks an entity with the rod, that target is marked. Upon right-clicking (reeling), the player and marked entity instantly swap positions, motion vectors, and viewing angles. Works for both mobs and other players. The rod automatically reels back after each swap, resetting the mark for repeated use. Includes cooldown handling and visual feedback for successful swaps.

I’ll create the Paper 1.21.11 project with the command, marked rod, left-click target tracking, one-click position/motion/rotation swapping, and hook cleanup.

Created the Division plugin project.

Features:

  • /division gives an unbreakable fishing rod with Infinity.

  • Left-click an entity while holding the rod to select it.

  • Right-click swaps you and the target:

    • Position

    • Velocity/motion

    • Looking direction and pitch

  • Works with players and other entities.

  • Fishing hook is automatically removed after the swap.

  • Selected targets are cleared if either player disconnects.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 188
src/main/java/com/kodari/division/DivisionPlugin.java
package com.kodari.division;

import com.cryptomorin.xseries.XEnchantment;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public final class DivisionPlugin extends JavaPlugin implements Listener {

    private final Map<UUID, Entity> selectedTargets = new HashMap<>();
    private NamespacedKey divisionRodKey;

    @Override
    public void onEnable() {
        divisionRodKey = new NamespacedKey(this, "division_rod");
        getServer().getPluginManager().registerEvents(this, this);
        getCommand("division").setExecutor((sender, command, label, args) -> {
            if (!(sender instanceof Player player)) {
                sender.sendMessage("Only players can use this command.");
                return true;
            }

            giveDivisionRod(player);
            player.sendMessage("§dYou received a Division Rod.");
            return true;
        });
    }

    @EventHandler
    public void onPlayerAttackEntity(EntityDamageByEntityEvent event) {
        if (!(event.getDamager() instanceof Player player)) {
            return;
        }

        if (!isDivisionRod(player.getInventory().getItemInMainHand())) {
            return;
        }

        Entity target = event.getEntity();
        if (target.getUniqueId().equals(player.getUniqueId())) {
            return;
        }

        event.setCancelled(true);
        selectedTargets.put(player.getUniqueId(), target);
        player.sendMessage("§aTarget selected. Right-click to divide positions.");
    }

    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent event) {
        if (event.getHand() != EquipmentSlot.HAND || event.getAction() != Action.RIGHT_CLICK_AIR
                && event.getAction() != Action.RIGHT_CLICK_BLOCK) {
            return;
        }

        Player player = event.getPlayer();
        if (!isDivisionRod(event.getItem())) {
            return;
        }

        Entity target = selectedTargets.remove(player.getUniqueId());
        if (target == null) {
            return;
        }

        event.setCancelled(true);
        if (!target.isValid() || target.isDead()) {
            player.sendMessage("§cThat target is no longer available.");
            removeFishingHook(player);
            return;
        }

        swap(player, target);
        removeFishingHook(player);
    }

    @EventHandler
    public void onPlayerQuit(PlayerQuitEvent event) {
        UUID playerId = event.getPlayer().getUniqueId();
        selectedTargets.entrySet().removeIf(entry -> entry.getKey().equals(playerId)
                || entry.getValue().getUniqueId().equals(playerId));
    }

    private void giveDivisionRod(Player player) {
        ItemStack rod = createDivisionRod();
        Map<Integer, ItemStack> leftovers = player.getInventory().addItem(rod);
        leftovers.values().forEach(item -> player.getWorld().dropItemNaturally(player.getLocation(), item));
    }

    private ItemStack createDivisionRod() {
        ItemStack rod = XMaterial.matchXMaterial("FISHING_ROD")
                .map(XMaterial::parseItem)
                .orElseThrow(() -> new IllegalStateException("Fishing rods are unavailable."));
        ItemMeta meta = rod.getItemMeta();
        meta.setDisplayName("§dDivision Rod");
        meta.setUnbreakable(true);
        meta.getPersistentDataContainer().set(divisionRodKey, PersistentDataType.BYTE, (byte) 1);
        XEnchantment.matchXEnchantment("INFINITY")
                .ifPresent(enchantment -> meta.addEnchant(enchantment.getEnchant(), 1, true));
        rod.setItemMeta(meta);
        return rod;
    }

    private boolean isDivisionRod(ItemStack item) {
        if (item == null || !XMaterial.matchXMaterial(item.getType()).name().equals("FISHING_ROD")) {
            return false;
        }

        ItemMeta meta = item.getItemMeta();
        return meta != null && meta.getPersistentDataContainer().has(divisionRodKey, PersistentDataType.BYTE);
    }

    private void swap(Player player, Entity target) {
        var playerLocation = player.getLocation().clone();
        var targetLocation = target.getLocation().clone();
        Vector playerVelocity = player.getVelocity().clone();
        Vector targetVelocity = target.getVelocity().clone();

        target.teleport(playerLocation);
        player.teleport(targetLocation);
        target.setVelocity(playerVelocity);
        player.setVelocity(targetVelocity);
    }

    private void removeFishingHook(Player player) {
        FishHook hook = player.getFishHook();
        if (hook != null) {
            hook.remove();
        }
    }
}