commit 513041608b3eea3e07ee254e5d6ab481944d6dc7
Author: YuTian <2953516620@qq.com>
Date: Wed Aug 14 20:37:34 2024 +0800
1.0
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..bd29ea5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/.idea/
+/target/
+/BoxSimulate.iml
diff --git a/lib/AgarthaLib.jar b/lib/AgarthaLib.jar
new file mode 100644
index 0000000..fbd4d03
Binary files /dev/null and b/lib/AgarthaLib.jar differ
diff --git a/lib/MyItems.jar b/lib/MyItems.jar
new file mode 100644
index 0000000..6410d38
Binary files /dev/null and b/lib/MyItems.jar differ
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..f71ba74
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,92 @@
+
+
+ 4.0.0
+
+ com.io.yutian
+ BoxSimulate
+ 1.0-SNAPSHOT
+ jar
+
+ BoxSimulate
+
+
+ 1.8
+ UTF-8
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+
+ ${java.version}
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.2.4
+
+
+ package
+
+ shade
+
+
+
+
+
+
+
+ src/main/resources
+ true
+
+
+
+
+
+
+ papermc-repo
+ https://repo.papermc.io/repository/maven-public/
+
+
+ sonatype
+ https://oss.sonatype.org/content/groups/public/
+
+
+ public-rpg
+ https://repo.aurora-pixels.com/repository/public-rpg/
+
+
+
+
+
+ com.destroystokyo.paper
+ paper-api
+ 1.12.2-R0.1-SNAPSHOT
+ provided
+
+
+ cn.hamster3.cdapi
+ CDTimeAPI
+ 1.0
+ provided
+
+
+ com.yaohun.itemku
+ AuItemStackLibrary
+ 1.12.2
+ provided
+
+
+ me.Demon.DemonPlugin
+ DemonAPI
+ 1.2.0 provided
+
+
+
diff --git a/src/main/java/com/io/yutian/boxsimulate/BoxSimulate.java b/src/main/java/com/io/yutian/boxsimulate/BoxSimulate.java
new file mode 100644
index 0000000..72b2494
--- /dev/null
+++ b/src/main/java/com/io/yutian/boxsimulate/BoxSimulate.java
@@ -0,0 +1,72 @@
+package com.io.yutian.boxsimulate;
+
+import com.io.yutian.boxsimulate.data.BoxData;
+import com.io.yutian.boxsimulate.gui.BoxSimulateGui;
+import com.io.yutian.boxsimulate.gui.GuiHolder;
+import com.io.yutian.boxsimulate.listener.GuiListener;
+import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.InventoryHolder;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public final class BoxSimulate extends JavaPlugin {
+
+ private static BoxSimulate instance;
+
+ private static Map boxDatas = new HashMap<>();
+
+ @Override
+ public void onEnable() {
+ instance = this;
+ reload();
+ Bukkit.getPluginManager().registerEvents(new GuiListener(), this);
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
+ reloadConfig();
+ sender.sendMessage("Config reloaded.");
+ return true;
+ }
+ if (sender instanceof Player) {
+ new BoxSimulateGui((Player) sender).open();
+ }
+ return true;
+ }
+
+ private void reload() {
+ boxDatas.clear();
+ saveDefaultConfig();
+ reloadConfig();
+ FileConfiguration config = getConfig();
+ for (String key : config.getKeys(false)) {
+ int need = config.getInt(key + ".need");
+ String item = config.getString(key + ".item");
+ boxDatas.put(key, new BoxData(need, item));
+ }
+ }
+
+ public static Map getBoxDatas() {
+ return boxDatas;
+ }
+
+ @Override
+ public void onDisable() {
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ if (player.getOpenInventory() != null) {
+ InventoryHolder inventoryHolder = player.getOpenInventory().getTopInventory().getHolder();
+ if (inventoryHolder instanceof GuiHolder) {
+ player.closeInventory();
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/com/io/yutian/boxsimulate/data/BoxData.java b/src/main/java/com/io/yutian/boxsimulate/data/BoxData.java
new file mode 100644
index 0000000..1639493
--- /dev/null
+++ b/src/main/java/com/io/yutian/boxsimulate/data/BoxData.java
@@ -0,0 +1,21 @@
+package com.io.yutian.boxsimulate.data;
+
+public class BoxData {
+
+ private int need;
+ private String item;
+
+ public BoxData(int need, String item) {
+ this.need = need;
+ this.item = item;
+ }
+
+ public int getNeed() {
+ return need;
+ }
+
+ public String getItem() {
+ return item;
+ }
+
+}
diff --git a/src/main/java/com/io/yutian/boxsimulate/gui/BoxSimulateGui.java b/src/main/java/com/io/yutian/boxsimulate/gui/BoxSimulateGui.java
new file mode 100644
index 0000000..4eabf2f
--- /dev/null
+++ b/src/main/java/com/io/yutian/boxsimulate/gui/BoxSimulateGui.java
@@ -0,0 +1,94 @@
+package com.io.yutian.boxsimulate.gui;
+
+import cn.hamster3.cdapi.CDTimeAPI;
+import com.io.yutian.boxsimulate.BoxSimulate;
+import com.io.yutian.boxsimulate.data.BoxData;
+import com.praya.myitems.MyItems;
+import com.yaohun.itemlibrary.api.ItemKuAPI;
+import me.Demon.DemonPlugin.DemonAPI;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryCloseEvent;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.InventoryHolder;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class BoxSimulateGui implements InventoryHolder, GuiHolder {
+
+ private Inventory inventory;
+ private Player player;
+
+ private Map cacheItems = new HashMap<>();
+
+ public BoxSimulateGui(Player player) {
+ this.inventory = Bukkit.createInventory(this, 54, "开箱模拟器");
+ this.player = player;
+ init();
+ }
+
+ private void init() {
+ Map boxDatas = BoxSimulate.getBoxDatas();
+ List boxDataList = boxDatas.values().stream().collect(Collectors.toList());
+ int i = 0;
+ for (Map.Entry entry : boxDatas.entrySet()) {
+ BoxData boxData = boxDataList.get(i);
+ if (!DemonAPI.hasPoints(player, boxData.getNeed())) {
+ continue;
+ }
+ ItemStack itemStack = getBoxItem(boxData.getItem());
+ inventory.setItem(i, itemStack);
+ cacheItems.put(i, entry.getKey());
+ i++;
+ }
+ }
+
+ private ItemStack getBoxItem(String id) {
+ return ItemKuAPI.getItems(id);
+ }
+
+ private ItemStack generateItem(String item) {
+ MyItems myItems = (MyItems) Bukkit.getPluginManager().getPlugin("MyItems");
+ return myItems.getGameManager().getItemGeneratorManager().getItemGenerator(item).generateItem();
+ }
+
+ @Override
+ public void onClick(InventoryClickEvent event) {
+ int slot = event.getRawSlot();
+ event.setCancelled(true);
+ if (slot >= 54) {
+ return;
+ }
+ if (!cacheItems.containsKey(slot)) {
+ return;
+ }
+ String id = cacheItems.get(slot);
+ if (CDTimeAPI.isCD(player.getUniqueId(), "box_simulate_box_"+id)) {
+ player.sendMessage("§8§l[§c§l!§8§l] §7该箱子冷却中...");
+ return;
+ }
+ BoxData boxData = BoxSimulate.getBoxDatas().get(id);
+ inventory.setItem(slot, generateItem(boxData.getItem()));
+ CDTimeAPI.setPlayerCD(player.getUniqueId(), "box_simulate_box_"+id, 1000 * 60 * 60);
+ }
+
+ @Override
+ public void onClose(InventoryCloseEvent event) {
+ }
+
+ @Override
+ public void open() {
+ player.openInventory(inventory);
+ }
+
+ @Override
+ public Inventory getInventory() {
+ return inventory;
+ }
+
+}
diff --git a/src/main/java/com/io/yutian/boxsimulate/gui/GuiHolder.java b/src/main/java/com/io/yutian/boxsimulate/gui/GuiHolder.java
new file mode 100644
index 0000000..29fc1bf
--- /dev/null
+++ b/src/main/java/com/io/yutian/boxsimulate/gui/GuiHolder.java
@@ -0,0 +1,14 @@
+package com.io.yutian.boxsimulate.gui;
+
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryCloseEvent;
+
+public interface GuiHolder {
+
+ void onClick(InventoryClickEvent event);
+
+ void onClose(InventoryCloseEvent event);
+
+ void open();
+
+}
diff --git a/src/main/java/com/io/yutian/boxsimulate/listener/GuiListener.java b/src/main/java/com/io/yutian/boxsimulate/listener/GuiListener.java
new file mode 100644
index 0000000..3ad5f49
--- /dev/null
+++ b/src/main/java/com/io/yutian/boxsimulate/listener/GuiListener.java
@@ -0,0 +1,33 @@
+package com.io.yutian.boxsimulate.listener;
+
+import com.io.yutian.boxsimulate.gui.GuiHolder;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryCloseEvent;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.InventoryHolder;
+
+public class GuiListener implements Listener {
+
+ @EventHandler
+ public void onInventoryClick(InventoryClickEvent event) {
+ Inventory inventory = event.getInventory();
+ InventoryHolder holder = inventory.getHolder();
+ if (holder != null && holder instanceof GuiHolder) {
+ GuiHolder guiHolder = (GuiHolder) holder;
+ guiHolder.onClick(event);
+ }
+ }
+
+ @EventHandler
+ public void onInventoryClose(InventoryCloseEvent event) {
+ Inventory inventory = event.getInventory();
+ InventoryHolder holder = inventory.getHolder();
+ if (holder != null && holder instanceof GuiHolder) {
+ GuiHolder guiHolder = (GuiHolder) holder;
+ guiHolder.onClose(event);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
new file mode 100644
index 0000000..080200c
--- /dev/null
+++ b/src/main/resources/config.yml
@@ -0,0 +1,3 @@
+铁质装备箱:
+ need: 100
+ item: 铁质装备箱
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
new file mode 100644
index 0000000..9bf7a3d
--- /dev/null
+++ b/src/main/resources/plugin.yml
@@ -0,0 +1,5 @@
+name: BoxSimulate
+version: '${project.version}'
+main: com.io.yutian.boxsimulate.BoxSimulate
+commands:
+ boxsimulate:
\ No newline at end of file