1.0
This commit is contained in:
commit
513041608b
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/.idea/
|
||||
/target/
|
||||
/BoxSimulate.iml
|
BIN
lib/AgarthaLib.jar
Normal file
BIN
lib/AgarthaLib.jar
Normal file
Binary file not shown.
BIN
lib/MyItems.jar
Normal file
BIN
lib/MyItems.jar
Normal file
Binary file not shown.
92
pom.xml
Normal file
92
pom.xml
Normal file
|
@ -0,0 +1,92 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.io.yutian</groupId>
|
||||
<artifactId>BoxSimulate</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BoxSimulate</name>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc-repo</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>public-rpg</id>
|
||||
<url>https://repo.aurora-pixels.com/repository/public-rpg/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.destroystokyo.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hamster3.cdapi</groupId>
|
||||
<artifactId>CDTimeAPI</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.yaohun.itemku</groupId>
|
||||
<artifactId>AuItemStackLibrary</artifactId>
|
||||
<version>1.12.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.Demon.DemonPlugin</groupId>
|
||||
<artifactId>DemonAPI</artifactId>
|
||||
<version>1.2.0</version> <scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
72
src/main/java/com/io/yutian/boxsimulate/BoxSimulate.java
Normal file
72
src/main/java/com/io/yutian/boxsimulate/BoxSimulate.java
Normal file
|
@ -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<String, BoxData> 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<String, BoxData> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
21
src/main/java/com/io/yutian/boxsimulate/data/BoxData.java
Normal file
21
src/main/java/com/io/yutian/boxsimulate/data/BoxData.java
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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<Integer, String> cacheItems = new HashMap<>();
|
||||
|
||||
public BoxSimulateGui(Player player) {
|
||||
this.inventory = Bukkit.createInventory(this, 54, "开箱模拟器");
|
||||
this.player = player;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
Map<String, BoxData> boxDatas = BoxSimulate.getBoxDatas();
|
||||
List<BoxData> boxDataList = boxDatas.values().stream().collect(Collectors.toList());
|
||||
int i = 0;
|
||||
for (Map.Entry<String, BoxData> 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;
|
||||
}
|
||||
|
||||
}
|
14
src/main/java/com/io/yutian/boxsimulate/gui/GuiHolder.java
Normal file
14
src/main/java/com/io/yutian/boxsimulate/gui/GuiHolder.java
Normal file
|
@ -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();
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
3
src/main/resources/config.yml
Normal file
3
src/main/resources/config.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
铁质装备箱:
|
||||
need: 100
|
||||
item: 铁质装备箱
|
5
src/main/resources/plugin.yml
Normal file
5
src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
name: BoxSimulate
|
||||
version: '${project.version}'
|
||||
main: com.io.yutian.boxsimulate.BoxSimulate
|
||||
commands:
|
||||
boxsimulate:
|
Loading…
Reference in New Issue
Block a user