Leonardo Pannacci

A GLOK 17

Kodari AI
KodariNov 3 at 2:29 pm 2
Glok17
Glok17 is a Minecraft plugin that introduces a powerful, modular weapon system centered around the iconic Glok 17 pistol. Players can craft, obtain, and customize the Glok 17 with attachments including silencers, extended magazines, and red dot sights. The plugin features realistic recoil patterns, damage falloff based on distance, headshot multipliers, and a full ammo management system with reload mechanics. It includes configurable spawn rates for loot chests, a crafting recipe system, and an API for developers to integrate custom weapons. The plugin supports both PvP and PvE combat scenarios with balanced damage values and particle effects for muzzle flash and bullet impact.
  • Add a /glock command that gives you a Glock 17.

  • Fire projectiles with right-click, with damage and a short cooldown.

Created a Glock 17 plugin. Use /glock to receive one, then right-click to fire. The command is available to operators by default.

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

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSound;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
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.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;

public final class GlockPlugin extends JavaPlugin implements Listener {
    private NamespacedKey glockKey;
    private final Map<UUID, Long> lastShot = new HashMap<>();

    @Override
    public void onEnable() {
        glockKey = new NamespacedKey(this, "glock17");
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage("Only players can receive a Glock 17.");
            return true;
        }
        Player player = (Player) sender;
        ItemStack gun = XMaterial.matchXMaterial("IRON_HORSE_ARMOR")
                .map(XMaterial::parseItem).orElse(null);
        if (gun == null) {
            player.sendMessage(ChatColor.RED + "The Glock item is unavailable on this server.");
            return true;
        }
        ItemMeta meta = gun.getItemMeta();
        meta.setDisplayName(ChatColor.DARK_GRAY + "Glock 17");
        meta.getPersistentDataContainer().set(glockKey, PersistentDataType.BYTE, (byte) 1);
        gun.setItemMeta(meta);
        player.getInventory().addItem(gun).values().forEach(item ->
                player.getWorld().dropItemNaturally(player.getLocation(), item));
        player.sendMessage(ChatColor.GREEN + "You received a Glock 17. Right-click to fire.");
        return true;
    }

    @EventHandler
    public void onInteract(PlayerInteractEvent event) {
        if (event.getHand() != EquipmentSlot.HAND ||
                (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)) {
            return;
        }
        ItemStack item = event.getItem();
        if (item == null || !item.hasItemMeta() || !item.getItemMeta().getPersistentDataContainer()
                .has(glockKey, PersistentDataType.BYTE)) {
            return;
        }
        event.setCancelled(true);
        Player player = event.getPlayer();
        long now = System.currentTimeMillis();
        if (now - lastShot.getOrDefault(player.getUniqueId(), 0L) < 250) {
            return;
        }
        lastShot.put(player.getUniqueId(), now);
        Snowball bullet = player.launchProjectile(Snowball.class);
        bullet.setVelocity(player.getEyeLocation().getDirection().multiply(3));
        bullet.getPersistentDataContainer().set(glockKey, PersistentDataType.BYTE, (byte) 1);
        XSound.matchXSound("ENTITY_GENERIC_EXPLODE").ifPresent(sound -> sound.play(player));
    }

    @EventHandler
    public void onDamage(EntityDamageByEntityEvent event) {
        if (event.getDamager() instanceof Snowball && event.getDamager().getPersistentDataContainer()
                .has(glockKey, PersistentDataType.BYTE)) {
            event.setDamage(6.0);
        }
    }

    @EventHandler
    public void onQuit(PlayerQuitEvent event) {
        lastShot.remove(event.getPlayer().getUniqueId());
    }
}