Noah Pitogo
📎 1 file 1,748 chars
📄
pasted-code-1792757845260.txt
txt 25 lines
▶
Act as an expert Minecraft PaperMC / Spigot Java developer. Write a complete, ultra-optimized, high-performance Ender Pearl Optimization plugin for Paper 1.20+ / 1.21.

Requirements for the plugin:
1. Precise Landing & Instant Teleportation: 
   - Intercept Ender Pearl entities and track their exact impact location (EnderPearlLandEvent / ProjectileHitEvent).
   - Teleport the player instantly to the exact landing vector/location without default tick-processing desync or vanilla delay.

2. Velocity & Momentum Preservation:
   - Do NOT reset or cancel the player's movement vector upon teleportation.
   - Capture the player's current velocity (and/or pearl velocity vector) prior to teleportation and re-apply it smoothly post-teleport, allowing fluid motion/strafing mid-pvp without stopping the player dead in their tracks.

3. Anti-Clipping & Safety Logic:
   - Check the destination block to prevent players from teleporting inside solid blocks (like obsidian/bedrock) or suffocating in walls. 
   - If the landing point is inside a block, safely adjust the Y-coordinate to the nearest breathable air space.

4. Fast Packet Handling & Cooldown Removal:
   - Bypass default vanilla pearl usage cooldowns or handle them at 0-delay.
   - Use fast vector math to process pearl travel efficiently without dropping server MSPT / TPS.

Please provide the complete project structure including:
- `plugin.yml` (configured for Paper 1.20/1.21 with ProtocolLib or Paper API)
- `pom.xml` (Maven configuration file with all necessary repositories/dependencies)
- The main `FastPearl.java` class with clean, fully commented Java code.

Output the code in standard source code blocks so I can package it directly into a .jar file.
Kodari AI
KodariOct 23 at 12:25 pm 1
FastPearlTeleport
Ultra-optimized PaperMC plugin for precise Ender Pearl teleportation. Intercepts pearl landing events, instantly teleports players to exact impact coordinates while preserving velocity and momentum for fluid mid-PvP movement. Implements anti-clipping safety logic to adjust landing positions away from solid blocks, preventing suffocation. Bypasses vanilla cooldowns for zero-delay usage. Uses efficient vector math to minimize server MSPT/TPS impact. Fully compatible with Paper 1.20+ and 1.21, featuring clean architecture with plugin.yml, pom.xml, and main FastPearl class.
  • Use the native ender-pearl teleport event so the landing is corrected during vanilla’s teleport, without packet hooks or per-tick tracking.

  • Check the destination for player-sized clearance and search vertically for the nearest safe spot.

  • Preserve the player’s velocity after teleport and add the Paper plugin metadata and Maven build file.

Created the FastPearl Maven project with pom.xml, plugin.yml, and FastPearl.java. It adjusts the native pearl teleport to the recorded impact location, searches vertically for player clearance, restores the player’s velocity after teleport, and clears the pearl cooldown on the next tick after launch. It uses event-driven handling without ProtocolLib or per-tick tracking.

Noah Pitogo

so the pearl is now fix the for some reason the head of the player is tilting weirdly on the teleport please patch that tilting head on teleport I want you to do like when teleport the tilt should be the same and make sure to patch the they can spam pearl also

Kodari AI
KodariOct 23 at 12:35 pm 1
  1. Preserve the player’s view orientation during pearl teleport.

  2. Prevent pearl spam by enforcing a launch cooldown.

Preserved the player’s yaw and pitch at the teleport destination, preventing the head tilt. Added a one-second pearl cooldown and blocks repeat pearl launches during that cooldown.

Noah Pitogo

I want you to widen the hitbox of the pearl slightly JUST SLIGHT slight like

Kodari AI
KodariOct 23 at 12:44 pm 1

Paper’s public API doesn’t let plugins resize an ender pearl’s actual hitbox, and this project targets the Paper API rather than version-specific server internals. I haven’t changed the code rather than fake a hitbox adjustment. I can instead add a tiny near-miss collision assist, or use NMS for a specific server version—but NMS won’t be reliably compatible across 1.20 and 1.21.

Noah Pitogo

yes please add it but make sure it is not buggy and still normal playing

Kodari AI
KodariOct 23 at 12:49 pm 1

Plan:

  1. Track each launched pearl only while it is in flight.

  2. Apply one tiny velocity correction only when its path narrowly misses another player’s hitbox.

  3. Keep the existing one-second pearl cooldown unchanged.

Added a very small 0.05-block assist for near misses against other players. It makes at most one slight velocity correction per pearl, only when the pearl’s path narrowly misses the player hitbox; normal collisions and block impacts are unchanged. The existing one-second pearl cooldown remains in place.

Noah Pitogo

I found new problem so when the pearl hit's a half block such as fence or walls the pearl won't work like nothing happens

Kodari AI
KodariOct 23 at 1:29 pm 1
  • Keep the existing vertical safe-landing search as the first choice.

  • If it finds no clear position, search nearby horizontal landing spots around the fence or wall.

  • Keep pearl cooldown, aim assist, and velocity/orientation behavior unchanged.

Updated FastPearl.java: when the impact location and vertical search are blocked, the plugin now checks nearby spots around the collision—up to 2 blocks horizontally and 2 blocks upward—so fence and wall impacts can still find a safe landing. Existing cooldown and pearl behavior are unchanged.

Noah Pitogo

also avoid player from teleporting into the blocks or outside of that blocs

Kodari AI
KodariOct 23 at 1:47 pm 1
  1. Validate the full player-sized hitbox against real block collision shapes.

  2. Reject landing spots that would put any part of the player outside the world border; cancel teleport if no safe spot is found.

Updated FastPearl.java to check the player’s full standing hitbox against actual block collision shapes, including partial blocks like fences. Landing spots that cross the world border are rejected; if no safe spot is found, the pearl teleport is cancelled.

Noah Pitogo

can you do on tp just don't save the yaw and tilt I want you to not touch it no matter what they do just don't move their camera just tp them

Kodari AI
KodariOct 23 at 2:04 pm 1
  • Keep the vanilla pearl teleport’s yaw and pitch unchanged.

  • Adjust only the destination coordinates for the safe landing spot, leaving the camera orientation alone.

Updated FastPearl.java to change only the safe landing coordinates. The teleport now keeps the yaw and pitch from the vanilla pearl destination, so the plugin no longer overrides the player’s camera orientation.

Noah Pitogo

do you think even on half block the player will not go throught

Kodari AI
KodariOct 23 at 2:14 pm 1

It should prevent pearl teleports from placing the player inside a fence, wall, slab, or other block: it checks the player-sized hitbox against block collision shapes and picks a clear nearby spot. If it can’t find one, it cancels the teleport. So the player may land beside the obstacle—or not teleport—rather than be sent through it.

Noah Pitogo

I found another problem so when player got tped on the tight space instead of tping him there the plugin find a larger area and tp the player there resulting to a false teleport for example he threw the pearl below on tight space then he got teleport up which is false

Kodari AI
KodariOct 24 at 5:25 am 1
  1. Stop searching upward and outward for substitute landing spots.

  2. Teleport only at the pearl’s impact location when the full player hitbox fits inside the world and outside collision shapes; otherwise cancel the teleport.

Updated FastPearl.java to stop searching for a higher or wider landing spot. It now teleports only at the pearl’s impact location when the player’s full hitbox fits there and is within the world border; if that exact spot is blocked or too tight, the teleport is cancelled instead.

Noah Pitogo

and also if the teleport cancel I want you to send them a message saying Teleport prevent it went through a block and send the pearl back to their inventory

Kodari AI
KodariOct 24 at 5:28 am 1
  1. On an unsafe pearl landing, cancel the teleport and tell the player why.

  2. Refund one ender pearl to their inventory, dropping it at their feet only if the inventory is full.

When the plugin cancels an unsafe pearl teleport, it now sends “Teleport prevented: the pearl would have gone through a block.” and returns one ender pearl to the player. If their inventory is full, the pearl drops at their location.

Noah Pitogo

wait imma explain further about the earlier I teleported above false teleport so this is the spot if I threw my pearl there I will get teleport above instead of crawling can you fix that and if really the pearl is going through the blocks cancel it but i want you to make happen the cancel not too often

Kodari AI
KodariOct 24 at 5:32 am 1

I’ll make the landing check use the player’s current hitbox dimensions instead of assuming a standing 1.8-block body. That lets an already-crawling player land in a crawl-height space, while still cancelling if their hitbox actually intersects a block; it won’t search above or move them to another spot.

Updated the landing check to use the player’s current hitbox instead of always requiring standing-height clearance. This should allow a player already crawling to land in a tight space, while still cancelling if their hitbox intersects a block. The destination stays at the pearl’s impact spot—no teleporting above or searching for a larger area.

Noah Pitogo

I found another problem when player die the enderpearl doesn't disappear

Kodari AI
KodariOct 24 at 6:26 am 1
  1. On player death, remove their currently flying ender pearls.

  2. Leave other players’ pearls and all existing teleport/cooldown behavior unchanged.

Added a death handler that removes any in-flight ender pearls shot by the player who died. Pearls thrown by other players are unaffected.

Noah Pitogo

can you fix the pearl now I can't pearl on the blocks can you do the ordinary pearl of the vanilla but keep the precise teleport

Kodari AI
KodariOct 24 at 7:31 am 1
  • Restore vanilla pearl flight and collision so pearls can land on blocks normally.

  • Keep the precise landing validation at teleport time, without changing the destination to a different spot.

  • Preserve the existing cancel message/refund and cooldown behavior.

Restored vanilla pearl flight and destination handling: removed the near-miss trajectory assist and stopped replacing the vanilla teleport destination or velocity. The plugin now checks the exact vanilla landing spot and cancels only if the player’s hitbox would intersect blocks or cross the world border—no relocating them to another spot. The existing cooldown and unsafe-landing pearl refund remain.

Noah Pitogo

I said just rmeove the prevention because I cannot pearl not like I Ccannot use it so useless and just briong back the vanilla thing but keep the precise teleport even it will went throught back just tp him where the pearl landed exactly

Kodari AI
KodariOct 24 at 7:49 am 1
  1. Remove the unsafe-landing cancellation, message, and pearl refund.

  2. Leave the vanilla pearl teleport destination and camera behavior untouched.

  3. Keep the existing launch cooldown and death cleanup.

Removed the landing prevention and refund logic. Ender pearls now use vanilla flight and teleport directly to their exact impact destination, even if that puts the player inside a block. The launch cooldown and pearl cleanup on death remain unchanged.

Noah Pitogo

plasee remove theprevention remove it just tp the person on the pearl where it landed

Kodari AI
KodariOct 24 at 8:02 am 1
  1. Remove the pearl teleport prevention handler and its safety/refund checks.

  2. Keep vanilla’s exact impact teleport, the launch cooldown, and death cleanup.

Removed the teleport-prevention handler and its collision checks, message, and pearl refund. Pearls now use vanilla flight and teleport at their exact impact location; the launch cooldown and death cleanup remain.

Noah Pitogo

but don't remove the precise teleportation ok?

Kodari AI
KodariOct 24 at 8:02 am 1

Yes—the current code leaves pearl teleportation to vanilla, so it still teleports to the pearl’s exact impact location. It does not cancel or redirect the teleport; only the launch cooldown and pearl cleanup on death remain.

Noah Pitogo

when the pearl gets to a unloaded chunks it does not work please fix that make sure the pearl lands even on unloaded chunks

Kodari AI
KodariOct 24 at 12:48 pm 1
  1. Keep each flying pearl’s current and next chunk loaded with a plugin-owned chunk ticket.

  2. Release tickets when the pearl lands, disappears, its shooter dies, or the plugin shuts down.

  3. Leave vanilla pearl flight and exact landing behavior unchanged.

Updated FastPearl.java to keep each flying pearl’s current and next chunk loaded, so it can continue through chunk boundaries and land normally. The chunk tickets are released when the pearl disappears, its shooter dies, or the plugin shuts down. Vanilla flight and exact impact teleport behavior remain unchanged.

Noah Pitogo

also can you improve the pearl hitbox to a player please

Kodari AI
KodariOct 24 at 1:07 pm 1
  • Add a slightly wider swept hit check for player targets while leaving block collisions vanilla.

  • When a pearl narrowly misses a player, steer it into the player so vanilla handles the actual impact and teleport.

  • Keep the existing exact landing behavior and chunk tracking unchanged.

Added a wider swept hit check for player targets. A pearl that narrowly misses a player is redirected into them so vanilla handles the impact; block collisions still take priority, and the existing landing location behavior is unchanged.

Kodari can make mistakes. Review important code before using.
Files
src
pom.xml
Code
3 309
src/main/java/com/kodari/fastpearl/FastPearl.java
package com.kodari.fastpearl;

import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.Material;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.Player;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.FluidCollisionMode;
import org.bukkit.util.RayTraceResult;
import org.bukkit.util.Vector;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

/** Enforces a short ender-pearl cooldown and removes pearls when their shooter dies. */
public final class FastPearl extends JavaPlugin implements Listener {
    private static final long PEARL_COOLDOWN_TICKS = 20L;

    private final Set<UUID> pearlCooldowns = new HashSet<>();
    private final Map<UUID, PearlTracking> trackedPearls = new HashMap<>();
    private final Map<World, Map<Long, ChunkTicket>> chunkTickets = new HashMap<>();

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

    @Override
    public void onDisable() {
        for (UUID pearlId : new HashSet<>(trackedPearls.keySet())) {
            stopTrackingPearl(pearlId);
        }
    }

    /** Enforces a one-second pearl cooldown and blocks rapid repeat launches. */
    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onPearlLaunch(ProjectileLaunchEvent event) {
        if (!(event.getEntity() instanceof EnderPearl pearl)
                || !(pearl.getShooter() instanceof Player player)) {
            return;
        }

        UUID playerId = player.getUniqueId();
        if (!pearlCooldowns.add(playerId)) {
            event.setCancelled(true);
            return;
        }

        startTrackingPearl(pearl);

        Material pearlMaterial = pearlMaterialInHand(player);
        if (pearlMaterial != null) {
            // Apply after the launch interaction so vanilla cannot overwrite this cooldown.
            Bukkit.getScheduler().runTask(this, () -> {
                if (player.isOnline()) {
                    player.setCooldown(pearlMaterial, (int) PEARL_COOLDOWN_TICKS);
                }
            });
        }

        Bukkit.getScheduler().runTaskLater(this,
                () -> pearlCooldowns.remove(playerId), PEARL_COOLDOWN_TICKS);
    }

    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
        Player player = event.getEntity();
        UUID playerId = player.getUniqueId();
        for (Entity entity : player.getWorld().getEntities()) {
            if (entity instanceof EnderPearl pearl
                    && pearl.getShooter() instanceof Player shooter
                    && shooter.getUniqueId().equals(playerId)) {
                pearl.remove();
                stopTrackingPearl(pearl.getUniqueId());
            }
        }
    }

    private void startTrackingPearl(EnderPearl pearl) {
        UUID pearlId = pearl.getUniqueId();
        if (trackedPearls.containsKey(pearlId)) {
            return;
        }

        PearlTracking tracking = new PearlTracking(pearl);
        trackedPearls.put(pearlId, tracking);
        updatePearlChunkTickets(tracking);
        tracking.task = Bukkit.getScheduler().runTaskTimer(this, () -> {
            if (!pearl.isValid() || pearl.isDead()) {
                stopTrackingPearl(pearlId);
                return;
            }
            redirectNearPlayerHit(tracking);
            updatePearlChunkTickets(tracking);
        }, 1L, 1L);
    }

    private void redirectNearPlayerHit(PearlTracking tracking) {
        EnderPearl pearl = tracking.pearl;
        Location current = pearl.getLocation();
        Location previous = tracking.previousLocation;
        Vector movement = current.toVector().subtract(previous.toVector());
        double distance = movement.length();
        if (distance < 1.0E-6) {
            tracking.previousLocation = current;
            return;
        }

        Vector direction = movement.clone().normalize();
        Player shooter = pearl.getShooter() instanceof Player player ? player : null;
        RayTraceResult entityHit = pearl.getWorld().rayTraceEntities(previous, direction, distance, 0.3,
                entity -> entity instanceof Player target && target.isOnline() && target != shooter);
        tracking.previousLocation = current;
        if (entityHit == null || !(entityHit.getHitEntity() instanceof Player target)) {
            return;
        }

        Vector hitPosition = entityHit.getHitPosition();
        double hitDistance = previous.toVector().distance(hitPosition);
        RayTraceResult blockHit = pearl.getWorld().rayTraceBlocks(previous, direction, hitDistance,
                FluidCollisionMode.NEVER, true);
        if (blockHit != null) {
            return;
        }

        Location pearlLocation = hitPosition.toLocation(pearl.getWorld());
        if (!pearl.teleport(pearlLocation)) {
            return;
        }
        Vector velocity = target.getBoundingBox().getCenter().subtract(hitPosition).normalize();
        pearl.setVelocity(velocity.multiply(Math.max(pearl.getVelocity().length(), 0.1)));
        tracking.previousLocation = pearlLocation;
    }

    private void updatePearlChunkTickets(PearlTracking tracking) {
        EnderPearl pearl = tracking.pearl;
        World world = pearl.getWorld();
        Location location = pearl.getLocation();
        Location nextLocation = location.clone().add(pearl.getVelocity());
        Set<Long> neededChunks = new HashSet<>();
        neededChunks.add(chunkKey(location));
        neededChunks.add(chunkKey(nextLocation));

        for (long key : neededChunks) {
            if (tracking.chunkKeys.add(key)) {
                acquireChunkTicket(world, key);
            }
        }

        Iterator<Long> iterator = tracking.chunkKeys.iterator();
        while (iterator.hasNext()) {
            long key = iterator.next();
            if (!neededChunks.contains(key)) {
                iterator.remove();
                releaseChunkTicket(world, key);
            }
        }
    }

    private void acquireChunkTicket(World world, long key) {
        Map<Long, ChunkTicket> worldTickets = chunkTickets.computeIfAbsent(world, ignored -> new HashMap<>());
        ChunkTicket ticket = worldTickets.get(key);
        if (ticket == null) {
            int chunkX = (int) (key >> 32);
            int chunkZ = (int) key;
            ticket = new ChunkTicket(chunkX, chunkZ, world.addPluginChunkTicket(chunkX, chunkZ, this));
            worldTickets.put(key, ticket);
        }
        ticket.references++;
    }

    private void releaseChunkTicket(World world, long key) {
        Map<Long, ChunkTicket> worldTickets = chunkTickets.get(world);
        if (worldTickets == null) {
            return;
        }

        ChunkTicket ticket = worldTickets.get(key);
        if (ticket == null || --ticket.references > 0) {
            return;
        }

        if (ticket.addedByPlugin) {
            world.removePluginChunkTicket(ticket.chunkX, ticket.chunkZ, this);
        }
        worldTickets.remove(key);
        if (worldTickets.isEmpty()) {