skyy064

corssbow /givec <กี่ไอเทม> <Maxลูกธนูเท่าไร> <ความกระจาย> <debuff>

หลักการ corssbow จะยิงลูกธนูด้วยความเร็วสูงเป็นจำนวน max ของที่บอก max 200 ก็ยิงออกมา 200 ลูกพร้อมกัน อีกทั้งยังติดไฟ จากการยิงทั้งหมดจะมีแค่ลูกเดียวที่เก็บได้ที่เหลือเก็บได้แต่ไม่เข้าตัว การยิงให้ห่างจากหน้าผู้เล่น 0.50 (ครึ่งบล็อก) ไม่ต้องมีข้อความ คลีนคลีน <debuff> เวลารีโหลดต่อ 1 ลูก (วินาที) ระบบจะจำเวลาที่ "แม็กหมด" ล่าสุด แล้วคำนวณว่าตอนนี้รีโหลดกลับมาได้กี่ลูกแล้ว (สูงสุดไม่เกิน max) — ยิงตอนไหนก็ได้ แต่จะออกแค่เท่าที่รีโหลดมา แล้วแม็กจะรีเซ็ตเป็น 0 ใหม่ทุกครั้งที่ยิง

config

  • arrow-speed: (ให้ความเร็วคำนวณดาเมจตาม Minecraft ปกติ)
  • max-arrows-limit: 200

max-reload-debuff-seconds: 60.0 max-spread-degrees: 90.0

ระยะห่างจากหน้าผู้เล่นที่ลูกธนูจะถูกสร้างขึ้น (บล็อก)

spawn-offset: 0.5

Kodari AI
KodariJul 21 at 4:06 am 15
RapidCrossbow
A Minecraft plugin that gives players configurable rapid-fire crossbows through the /givec command. Each crossbow launches a fully reloading magazine of flaming arrows at normal Minecraft velocity, with configurable arrow count, spread, reload delay, and spawn offset. Ammunition regenerates one arrow at a time after firing, while only one projectile from every volley can be collected.
  1. Create the Gradle Paper plugin foundation and command/config declarations.

  2. Add custom-crossbow metadata, silent /givec handling, and reload-state storage.

  3. Add projectile firing, spread, fire, pickup restriction, and configurable limits.

Created RapidCrossbow with configurable rapid crossbows, silent /givec issuing, timed magazine reloads, flaming spread volleys, half-block spawn offset, and one collectible arrow per volley.

skyy064

add Tab-completion

Kodari AI
KodariJul 21 at 4:14 am 4
  • Add a TabCompleter to /givec.

  • Suggest valid values for each of its four arguments.

  • Register the completer alongside the existing executor.

Added /givec tab completion:

  • Item count: 1, 64

  • Maximum arrows: 1, configured max-arrows-limit

  • Spread: 0, configured max-spread-degrees

  • Reload debuff: 1, configured max-reload-debuff-seconds

skyy064

<debuff> จะใส่หรือไม่ใส่ก็ได้ และ ทำงานไม่ถูกต้องเช่นกัน โหลดลูกกระสุนนั่นหมายความว่าสมมุติแม็ก 200 เขียนเป็น 2 ยิงครั้งแรกออก 200 นัดก็จริงแต่ครั้งต่อไปอาจจะออกแค่ 1 เพราะต้องรอคูลดาวน์ใส่ลูกทีละลูก 2 วิเช่นแบบทุกๆ 2 วิก็จะเพิ่มมา 1 ลูกแล้วยิงตอนไหนก็ได้แหละแต่แค่ก็จะอยู่แค่นั้นที่รีโหลดแต่ละลูกต่อ 2 วิเข้าใจไหม ----- แก้การเก็บลูกธนูเก็บแค่ลูกเดียวส่วนที่เหลือเก็บได้แต่ไม่เข้ากระเป็า <ความกระจาย> ทำงานไม่ถูกต้อง

Kodari AI
KodariJul 21 at 4:20 am 9
  1. ทำให้ <debuff> เป็นอาร์กิวเมนต์ไม่บังคับ และแก้แม็กให้รีโหลดเพิ่มทีละ 1 ลูกตามเวลาที่กำหนดหลังยิง

  2. จำกัดการเก็บลูกธนูให้เข้ากระเป๋าได้เพียงลูกเดียวต่อการยิงหนึ่งชุด

  3. แก้การคำนวณความกระจายของลูกธนูให้ใช้ค่าองศาที่ระบุจริง

  1. <debuff> เป็น optional แล้ว — ถ้าไม่ใส่จะใช้ค่าสูงสุดจาก max-reload-debuff-seconds

  2. ระบบแม็กรีโหลดทีละ 1 ลูกตามจำนวนวินาทีของ debuff และทุกครั้งที่ยิงจะรีเซ็ตแม็กเพื่อเริ่มนับใหม่

  3. ลูกธนูที่ไม่ใช่ลูกแรกจะหายเมื่อเก็บ จึงไม่เข้ากระเป๋า; ลูกแรกยังเก็บได้ตามปกติ

  4. ปรับ spread ให้ใช้ค่าองศาที่ระบุเป็นมุมกระจายจริง (ไม่ถูกหารครึ่ง)

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
7 379
src/main/java/com/kodari/rapidcrossbow/RapidCrossbowPlugin.java
package com.kodari.rapidcrossbow;

import com.kodari.rapidcrossbow.command.GiveCrossbowCommand;
import com.kodari.rapidcrossbow.listener.CrossbowListener;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.command.PluginCommand;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;

public class RapidCrossbowPlugin extends JavaPlugin {

    private NamespacedKey crossbowKey;
    private NamespacedKey maxArrowsKey;
    private NamespacedKey spreadKey;
    private NamespacedKey reloadSecondsKey;
    private NamespacedKey lastEmptyKey;
    private NamespacedKey volleyArrowKey;
    private NamespacedKey collectibleArrowKey;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        crossbowKey = new NamespacedKey(this, "rapid_crossbow");
        maxArrowsKey = new NamespacedKey(this, "max_arrows");
        spreadKey = new NamespacedKey(this, "spread");
        reloadSecondsKey = new NamespacedKey(this, "reload_seconds");
        lastEmptyKey = new NamespacedKey(this, "last_empty");
        volleyArrowKey = new NamespacedKey(this, "volley_arrow");
        collectibleArrowKey = new NamespacedKey(this, "collectible_arrow");

        PluginCommand giveCrossbowCommand = getCommand("givec");
        if (giveCrossbowCommand != null) {
            GiveCrossbowCommand giveCrossbowCommandExecutor = new GiveCrossbowCommand(this);
            giveCrossbowCommand.setExecutor(giveCrossbowCommandExecutor);
            giveCrossbowCommand.setTabCompleter(giveCrossbowCommandExecutor);
        }

        getServer().getPluginManager().registerEvents(new CrossbowListener(this), this);
    }

    public ItemStack createCrossbow(int maxArrows, double spread, double reloadSeconds) {
        Material crossbowMaterial = Material.matchMaterial("CROSSBOW");
        if (crossbowMaterial == null) {
            return null;
        }

        ItemStack crossbow = new ItemStack(crossbowMaterial);
        ItemMeta meta = crossbow.getItemMeta();
        if (meta == null) {
            return null;
        }

        PersistentDataContainer data = meta.getPersistentDataContainer();
        data.set(crossbowKey, PersistentDataType.BYTE, (byte) 1);
        data.set(maxArrowsKey, PersistentDataType.INTEGER, maxArrows);
        data.set(spreadKey, PersistentDataType.DOUBLE, spread);
        data.set(reloadSecondsKey, PersistentDataType.DOUBLE, reloadSeconds);
        crossbow.setItemMeta(meta);
        return crossbow;
    }

    public boolean isRapidCrossbow(ItemStack item) {
        if (item == null || !item.hasItemMeta()) {
            return false;
        }

        return item.getItemMeta().getPersistentDataContainer().has(crossbowKey, PersistentDataType.BYTE);
    }

    public int getMaxArrows(ItemStack item) {
        Integer maxArrows = item.getItemMeta().getPersistentDataContainer().get(maxArrowsKey, PersistentDataType.INTEGER);
        return maxArrows == null ? 1 : Math.max(1, maxArrows);
    }

    public double getSpread(ItemStack item) {
        Double spread = item.getItemMeta().getPersistentDataContainer().get(spreadKey, PersistentDataType.DOUBLE);
        return spread == null ? 0.0 : Math.max(0.0, spread);
    }

    public double getReloadSeconds(ItemStack item) {
        Double reloadSeconds = item.getItemMeta().getPersistentDataContainer().get(reloadSecondsKey, PersistentDataType.DOUBLE);
        return reloadSeconds == null ? 1.0 : Math.max(0.1, reloadSeconds);
    }

    public long getLastEmptyTime(ItemStack item) {
        Long lastEmptyTime = item.getItemMeta().getPersistentDataContainer().get(lastEmptyKey, PersistentDataType.LONG);
        return lastEmptyTime == null ? -1L : lastEmptyTime;
    }

    public void markMagazineEmpty(ItemStack item, long time) {
        ItemMeta meta = item.getItemMeta();
        if (meta == null) {
            return;
        }

        meta.getPersistentDataContainer().set(lastEmptyKey, PersistentDataType.LONG, time);
        item.setItemMeta(meta);
    }

    public int getConfiguredMaxArrows() {
        return Math.max(1, getConfig().getInt("max-arrows-limit", 200));
    }

    public double getConfiguredMaxReloadSeconds() {
        return Math.max(0.1, getConfig().getDouble("max-reload-debuff-seconds", 60.0));
    }

    public double getConfiguredMaxSpread() {
        return Math.max(0.0, getConfig().getDouble("max-spread-degrees", 90.0));
    }

    public double getArrowSpeed() {
        return Math.max(0.1, getConfig().getDouble("arrow-speed", 3.0));
    }

    public double getSpawnOffset() {
        return Math.max(0.0, getConfig().getDouble("spawn-offset", 0.5));
    }

    public NamespacedKey getVolleyArrowKey() {
        return volleyArrowKey;
    }

    public NamespacedKey getCollectibleArrowKey() {
        return collectibleArrowKey;
    }
}