apexsurvivor0294

web shioter to use to swing like spider man and a tight spider man sui with it

Kodari AI
KodariOct 8 at 3:24 pm 1
WebSlinger
A Minecraft plugin that introduces a web-shooting mechanic allowing players to swing between surfaces like Spider-Man. Players can shoot webs at walls, ceilings, and other solid surfaces to create temporary grappling lines that let them swing through the environment. The plugin features a grappling hook system with realistic physics, momentum preservation, and web-swinging mechanics. Includes a custom Spider-Man suit with enhanced abilities including increased jump height, reduced fall damage, wall-crawling capability, and faster movement speed. The suit provides a tight-fitting appearance with animated web patterns and glowing accents. Players can toggle web-shooting modes for swinging, web-zip, or web-ball attacks. The plugin includes configurable web strength, swing physics, suit abilities, and cooldown timers through a comprehensive settings menu.
  1. Add a /webslinger kit command that gives a web shooter and red/blue leather suit.

  2. Make right-clicking the shooter launch a web projectile that tethers and swings the player on impact.

  3. Add the Bukkit plugin descriptor and register the command and listeners.

Added the /webslinger kit command with a red-and-blue dyed leather suit and a web shooter. Right-clicking the shooter launches a web that tethers you to the hit point and lets you swing.

Kodari can make mistakes. Review important code before using.
Files
src
Code
2 204
src/main/java/com/kodari/webslinger/WebSlingerPlugin.java
package com.kodari.webslinger;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Snowball;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;
import org.bukkit.plugin.java.JavaPlugin;

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

public final class WebSlingerPlugin extends JavaPlugin implements Listener, CommandExecutor {
    private NamespacedKey shooterKey;
    private NamespacedKey webKey;
    private final Map<UUID, BukkitTask> swingTasks = new HashMap<>();

    @Override
    public void onEnable() {
        shooterKey = new NamespacedKey(this, "web_shooter");
        webKey = new NamespacedKey(this, "web_projectile");
        getServer().getPluginManager().registerEvents(this, this);
        getCommand("webslinger").setExecutor(this);
    }

    @Override
    public void onDisable() {
        swingTasks.values().forEach(BukkitTask::cancel);
        swingTasks.clear();
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage("Only players can use this command.");
            return true;
        }

        if (args.length != 1 || !args[0].equalsIgnoreCase("kit")) {
            player.sendMessage(ChatColor.RED + "Usage: /webslinger kit");
            return true;
        }

        giveKit(player);
        return true;
    }

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

        ItemStack item = event.getItem();
        if (item == null || !isWebShooter(item)) {
            return;
        }

        event.setCancelled(true);
        Player player = event.getPlayer();
        Snowball web = player.launchProjectile(Snowball.class);
        web.setVelocity(player.getLocation().getDirection().multiply(2.0));
        web.getPersistentDataContainer().set(webKey, PersistentDataType.BYTE, (byte) 1);
    }

    @EventHandler
    public void onWebHit(ProjectileHitEvent event) {
        Projectile projectile = event.getEntity();
        if (!projectile.getPersistentDataContainer().has(webKey, PersistentDataType.BYTE)
                || !(projectile.getShooter() instanceof Player player)) {
            return;
        }

        Location anchor = projectile.getLocation().clone();
        if (event.getHitBlock() != null) {
            anchor = event.getHitBlock().getLocation().add(0.5, 0.5, 0.5);
        } else if (event.getHitEntity() != null) {
            anchor = event.getHitEntity().getLocation().clone().add(0, 1, 0);
        }

        startSwing(player, anchor);
    }

    private void startSwing(Player player, Location anchor) {
        UUID playerId = player.getUniqueId();
        BukkitTask previousTask = swingTasks.remove(playerId);
        if (previousTask != null) {
            previousTask.cancel();
        }

        double ropeLength = Math.max(4.0, player.getLocation().distance(anchor));
        Vector launch = player.getLocation().getDirection().multiply(0.75).add(new Vector(0, 0.25, 0));
        player.setVelocity(player.getVelocity().add(launch));
        int[] ticks = {0};

        BukkitTask task = getServer().getScheduler().runTaskTimer(this, () -> {
            if (!player.isOnline() || !player.getWorld().equals(anchor.getWorld()) || ++ticks[0] > 100) {
                stopSwing(playerId);
                return;
            }

            Vector offset = player.getLocation().toVector().subtract(anchor.toVector());
            double distance = offset.length();
            if (distance < 2.2) {
                stopSwing(playerId);
                return;
            }

            if (distance > ropeLength) {
                Vector radial = offset.normalize();
                Vector velocity = player.getVelocity();
                double outwardSpeed = velocity.dot(radial);
                if (outwardSpeed > 0) {
                    velocity.subtract(radial.multiply(outwardSpeed));
                }
                velocity.subtract(radial.multiply(Math.min(0.25, (distance - ropeLength) * 0.12)));
                player.setVelocity(velocity);
            }
        }, 1L, 1L);
        swingTasks.put(playerId, task);
    }

    private void stopSwing(UUID playerId) {
        BukkitTask task = swingTasks.remove(playerId);
        if (task != null) {
            task.cancel();
        }
    }

    private boolean isWebShooter(ItemStack item) {
        if (!item.hasItemMeta()) {
            return false;
        }
        return item.getItemMeta().getPersistentDataContainer().has(shooterKey, PersistentDataType.BYTE);
    }

    private void giveKit(Player player) {
        List<ItemStack> kit = new ArrayList<>();
        kit.add(createWebShooter());
        kit.add(createArmor("LEATHER_HELMET", "&cSpider Suit Hood", Color.fromRGB(190, 20, 35)));
        kit.add(createArmor("LEATHER_CHESTPLATE", "&cSpider Suit Top", Color.fromRGB(190, 20, 35)));
        kit.add(createArmor("LEATHER_LEGGINGS", "&9Spider Suit Leggings", Color.fromRGB(25, 55, 150)));
        kit.add(createArmor("LEATHER_BOOTS", "&cSpider Suit Boots", Color.fromRGB(190, 20, 35)));

        for (ItemStack item : kit) {
            Map<Integer, ItemStack> leftovers = player.getInventory().addItem(item);
            leftovers.values().forEach(leftover -> player.getWorld().dropItemNaturally(player.getLocation(), leftover));
        }
        player.sendMessage(ChatColor.RED + "Web-Slinger kit equipped for action! Right-click the shooter to swing.");
    }

    private ItemStack createWebShooter() {
        ItemStack item = XMaterial.matchXMaterial("BLAZE_ROD").map(XMaterial::parseItem).orElseThrow();
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName(ChatColor.RED.toString() + ChatColor.BOLD + "Web Shooter");
        meta.setLore(List.of(ChatColor.GRAY + "Right-click to fire a web and swing."));
        meta.getPersistentDataContainer().set(shooterKey, PersistentDataType.BYTE, (byte) 1);
        item.setItemMeta(meta);
        return item;
    }

    private ItemStack createArmor(String materialName, String name, Color color) {
        ItemStack item = XMaterial.matchXMaterial(materialName).map(XMaterial::parseItem).orElseThrow();
        LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemMeta();
        meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
        meta.setColor(color);
        item.setItemMeta(meta);
        return item;
    }
}