tao cho t 1 plugin co nhung thu tien ich nhu thung rac de bo rac vao va khi bo vao toan bo nhung thu ta bo vao se mat het nhu mot thung rac va no dang block la 1 cai ruong co nametag la thùng rác va khi bo vao no se tu dong chuyen het do ma nguoi choi bo vao 1 ruong nhu 1 kho rac va ruong nay cung co dang la 1 cai ruong co ghi chu la kho rác va neu kho rac full se ko the bo rac vao thung rac nua
Here’s my plan:
TrashPlugin— main class, initializes managersTrashManager— stores locations (config), handles item transfer logicTrashListener— handles inventory open/close eventsTrashCommand—/trash set bin,/trash set storage,/trash remove,/trash list
Plugin hoạt động như sau:
Cách dùng:
Đặt 1 barrel/chest → nhìn vào →
/trash set storage→ đây là kho rácĐặt 1 barrel/chest → nhìn vào →
/trash set bin→ đây là thùng rác
Cơ chế:
Người chơi mở thùng rác → bỏ đồ vào → đóng lại → toàn bộ đồ tự động chuyển sang kho rác
Nếu kho rác đầy, mở thùng rác sẽ bị chặn kèm thông báo
Hỗ trợ nhiều thùng rác liên kết vào 1 kho rác duy nhất
Dữ liệu vị trí lưu trong
config.yml, không mất khi reload server
Lệnh:
Lệnh | Mô tả |
|---|---|
/trash set bin | Đặt block đang nhìn là thùng rác |
/trash set storage | Đặt block đang nhìn là kho rác |
/trash remove bin | Xoá thùng rác |
/trash remove storage | Xoá kho rác |
/trash list | Xem danh sách + trạng thái |
Cần đặt tên cho rương bằng Anvil (
thùng rác/kho rác) theo cách vanilla — plugin nhận diện qua vị trí block được đăng ký bằng lệnh, không phải theo tên.
build sao
Code nhìn qua không có lỗi compile. Vấn đề là project chưa có Gradle Wrapper (gradlew). Tôi sẽ thêm vào và fix luôn một lỗi nhỏ trong build.gradle (thiếu encoding).
Giờ thêm Gradle Wrapper để build không cần cài Gradle sẵn:
Vì gradle-wrapper.jar là binary không thể tạo bằng text, cách dễ nhất để build:
Cách build (chọn 1 trong 2)
Cách 1 — Dùng Gradle cài sẵn (đơn giản nhất)
Cần cài Gradle 8+, sau đó chạy:
gradle build
JAR xuất ra tại: build/libs/TrashBinPlugin-1.0.0.jar
Cách 2 — Dùng IntelliJ IDEA (khuyên dùng)
Mở IntelliJ → Open → chọn thư mục project
IntelliJ tự nhận
build.gradle→ import Gradle projectBên phải panel Gradle →
Tasks > build > buildHoặc terminal trong IntelliJ chạy:
gradle build
Cách 3 — Tạo wrapper thủ công (nếu đã có Gradle)
gradle wrapper
./gradlew build
Lưu ý: Cần JDK 11+ để compile. File .jar sau khi build bỏ vào thư mục plugins/ của server Spigot/Paper 1.13–1.20+.
Provides transitive vulnerable dependency maven:com.google.guava:guava:31.1-jre CVE-2023-2976 5.5 Files or Directories Accessible to External Parties CVE-2020-8908 3.3 Incorrect Permission Assignment for Critical Resource Results powered by Mend.io Consider using 'withType(...).configureEach' to avoid unnecessary configuration
Hai vấn đề:
Guava CVE — spigot-api kéo vào guava 31.1-jre, cần force lên 32.1.1-jre
withTypewarning — đổi thànhconfigureEach
Đã sửa 2 thứ:
resolutionStrategy.forceép toàn bộ transitive dependency dùng guava 32.1.3-jre (đã vá CVE-2023-2976 và CVE-2020-8908)tasks.withType(JavaCompile).configureEachthay vì.withType(...)trực tiếp để tránh warning về eager configuration
gradle build gradle : The term 'gradle' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1 + gradle build + ~~~~~~ + CategoryInfo : ObjectNotFound: (gradle:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\BaoPhuc\Downloads\TrashBinPlugin-1777553483671>
Máy chưa cài Gradle và thiếu gradle-wrapper.jar (file binary không thể tạo bằng text). Có 2 cách fix nhanh:
Cách 1 — Cài Gradle (nhanh nhất)
Vào https://gradle.org/releases/ → tải bản mới nhất binary-only (file
.zip)Giải nén vào ví dụ
C:\Gradle\gradle-8.7Thêm vào PATH:
Tìm kiếm “Environment Variables” trên Windows
System variables → Path → Edit → New
Thêm:
C:\Gradle\gradle-8.7\binBấm OK hết
Mở PowerShell mới (quan trọng — phải mở lại), chạy:
gradle build
Cách 2 — Dùng IntelliJ IDEA (không cần cài gì thêm)
Cài IntelliJ IDEA Community (miễn phí)
Open → chọn thư mục
TrashBinPlugin-1777553483671IntelliJ tự tải Gradle về
Góc phải → panel Gradle →
Tasks → build → build
JAR xuất ra tại: build/libs/TrashBinPlugin-1.0.0.jar
Khuyên dùng Cách 2 nếu bạn hay làm plugin — IntelliJ tự lo hết Gradle, JDK, dependencies.
> Task :help
Welcome to Gradle 8.5.
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see more detail about a task, run gradle help --task <task>
To see a list of command-line options, run gradle --help
For more detail on using Gradle, see https://docs.gradle.org/8.5/userguide/command_line_interface.html
For troubleshooting, visit https://help.gradle.org
BUILD SUCCESSFUL in 867ms 1 actionable task: 1 executed 5:37:56 PM: Execution finished.
Gradle đã nhận project rồi, bạn chạy nhầm task help thay vì build. Chạy lại:
gradle build
JAR sẽ xuất ra tại: build/libs/TrashBinPlugin-1.0.0.jar — bỏ file đó vào thư mục plugins/ của server là xong.
> Task :help
Welcome to Gradle 8.5.
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see more detail about a task, run gradle help --task <task>
To see a list of command-line options, run gradle --help
For more detail on using Gradle, see https://docs.gradle.org/8.5/userguide/command_line_interface.html
For troubleshooting, visit https://help.gradle.org
BUILD SUCCESSFUL in 523ms 1 actionable task: 1 executed 5:39:13 PM: Execution finished. bl=uild rt no ra the nay
IntelliJ đang chạy task help thay vì build. Sửa lại bằng cách:
Trong panel Gradle bên phải:
TrashBinPlugin
└── Tasks
└── build
└── build ← double-click vào đây
Hoặc dùng terminal trong IntelliJ:
gradle build
Gõ trực tiếp vào tab Terminal (góc dưới IntelliJ), không phải chạy qua nút Run.
5:39:32 PM: Executing…
Starting Gradle Daemon...
Connected to the target VM, address: '127.0.0.1:54805', transport: 'socket' Gradle Daemon started in 21 s 753 ms
Thiếu file gradle-wrapper.jar — file binary này không thể tạo bằng text. Cần chạy lệnh này 1 lần trong Terminal của IntelliJ:
gradle wrapper
Sau đó chạy:
gradlew build
JAR xuất ra tại: build/libs/TrashBinPlugin-1.0.0.jar
build r ma
JAR xuất ra tại:
build/libs/TrashBinPlugin-1.0.0.jar
Bỏ file đó vào thư mục plugins/ của server rồi restart là xong.
ko co
Thư mục build/ không hiện trong project view vì IntelliJ ẩn nó. Mở File Explorer vào thẳng:
C:\Users\BaoPhuc\Downloads\TrashBinPlugin-1777553483671\build\libs\
File TrashBinPlugin-1.0.0.jar nằm ở đó.
ko co luon
Build chưa thực sự thành công — lúc trước chỉ thấy Gradle Daemon khởi động, chưa thấy BUILD SUCCESSFUL. Mở Terminal trong IntelliJ và chạy:
gradle build --info 2>&1 | Select-String -Pattern "error|BUILD|FAILED|warning"
Hoặc đơn giản hơn:
gradle build
Sau đó copy toàn bộ output paste vào đây để mình xem lỗi gì.
PS C:\Users\BaoPhuc\Downloads\TrashBinPlugin-1777718470632> gradle build --info 2>&1 | Select-String -Pattern "error|BUILD|FAILED|warning" gradle : The term 'gradle' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1 + gradle build --info 2>&1 | Select-String -Pattern "error|BUILD|FAILED ... + ~~~~~~ + CategoryInfo : ObjectNotFound: (gradle:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
Dùng gradlew (có sẵn trong project), không phải gradle:
.\gradlew build
Paste output vào đây nếu có lỗi.
PS C:\Users\BaoPhuc\Downloads\TrashBinPlugin-1777718470632> .\gradlew build Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain PS C:\Users\BaoPhuc\Downloads\TrashBinPlugin-1777718470632>
Thiếu file gradle/wrapper/gradle-wrapper.jar. Chạy lệnh này để tải về:
Invoke-WebRequest -Uri "https://github.com/gradle/gradle/raw/v8.5.0/gradle/wrapper/gradle-wrapper.jar" -OutFile "gradle/wrapper/gradle-wrapper.jar"
Sau đó chạy lại:
.\gradlew build
thoi bo kieu nay di lam thung rac kieu dang lenh /thungrac hoac cac lenh viet tat de bo rac va neu bo lon thi co lenh de lay lai do vua bo lon
Đọc code hiện tại trước:
Kế hoạch:
Bỏ hệ thống thùng rác vật lý, chuyển sang GUI ảo mở bằng lệnh
/thungrac(alias:/tr,/rac)Khi đóng GUI → đồ chuyển vào kho (hoặc void nếu chưa set kho), lưu vào cache undo per-player
/thungrac layhoặc/trlai→ lấy lại đồ vừa bỏAdmin:
/thungrac set storage,/thungrac remove storage,/thungrac list
Xong. Tóm tắt thay đổi:
Lệnh | Mô tả |
|---|---|
/thungrac hoặc /tr, /rac | Mở GUI thùng rác ảo (27 ô) |
/thungrac lay hoặc /trlai | Lấy lại đồ vừa bỏ lộn |
/thungrac set | Admin: nhìn vào rương để đặt làm kho |
/thungrac remove | Admin: xoá kho rác |
/thungrac list | Admin: xem trạng thái kho |
Nếu có kho: đồ bỏ vào thùng → chuyển vào kho rương
Nếu không có kho: đồ bị void vĩnh viễn (trừ khi dùng
/trlaikịp)/trlaichỉ hoạt động 1 lần cho lần bỏ gần nhất
bo hoan toan thung rac vat li di
[Generation stopped]
bo hoan toan thung rac vat li di va cho moi nguoi mot thung rac rieng va co vo han kho rac co cac nut de qua lai cac kho rac cua minh va nho rang moi nguoi 1 kho
Kế hoạch:
Xoá hoàn toàn hệ thống kho rác vật lý (rương, set/remove/list)
Mỗi player có kho rác riêng, vô hạn trang (45 slot/trang), lưu vào file
players/<uuid>.ymlGUI 54 slot: 45 slot đồ + hàng dưới có nút Trước/Sau/Info
/trlailấy lại đồ vừa bỏ (1 lần undo)
Xong. Tóm tắt:
Xoá hoàn toàn hệ thống rương kho rác vật lý
Mỗi player có kho rác riêng vô hạn trang (45 slot/trang), lưu tại
plugins/TrashBinPlugin/players/<uuid>.ymlGUI có nút ◄ Trang Trước (slot 45) và nút Trang Tiếp ► (slot 53) + info trang ở giữa
/thungrac//tr//rac→ mở kho rác, nhớ trang đang xem/trlaihoặc/thungrac lay→ lấy lại đồ từ trang vừa đóng
package com.trashbin;
import com.trashbin.command.TrashCommand;
import com.trashbin.listener.TrashListener;
import com.trashbin.manager.TrashManager;
import org.bukkit.plugin.java.JavaPlugin;
public class TrashPlugin extends JavaPlugin {
private TrashManager trashManager;
@Override
public void onEnable() {
saveDefaultConfig();
trashManager = new TrashManager(this);
getServer().getPluginManager().registerEvents(new TrashListener(this, trashManager), this);
TrashCommand cmd = new TrashCommand(this, trashManager);
getCommand("thungrac").setExecutor(cmd);
getCommand("thungrac").setTabCompleter(cmd);
getCommand("tr").setExecutor(cmd);
getCommand("tr").setTabCompleter(cmd);
getCommand("rac").setExecutor(cmd);
getCommand("rac").setTabCompleter(cmd);
getCommand("trlai").setExecutor(cmd);
getLogger().info("TrashBinPlugin enabled.");
}
@Override
public void onDisable() {
getLogger().info("TrashBinPlugin disabled.");
}
}