测试版
This commit is contained in:
commit
4c9015baca
38
.gitignore
vendored
Normal file
38
.gitignore
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea/modules.xml
|
||||
.idea/jarRepositories.xml
|
||||
.idea/compiler.xml
|
||||
.idea/libraries/
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
37
pom.xml
Normal file
37
pom.xml
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?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>org.example</groupId>
|
||||
<artifactId>DemonTrash</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>public-rpg</id>
|
||||
<url>https://repo.aurora-pixels.com/repository/public-rpg/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.Demon.DemonPlugin</groupId>
|
||||
<artifactId>DemonAPI</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
163
src/main/java/me/Demon/DemonTrash/AdminGui.java
Normal file
163
src/main/java/me/Demon/DemonTrash/AdminGui.java
Normal file
|
@ -0,0 +1,163 @@
|
|||
package me.Demon.DemonTrash;
|
||||
|
||||
import me.Demon.DemonPlugin.DemonAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AdminGui implements Listener {
|
||||
|
||||
public static String inv_Title = "管理员垃圾桶(右键物品即可取出)#";
|
||||
|
||||
@EventHandler
|
||||
public void onclick(InventoryClickEvent e) {
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
if (e.getView().getTitle().contains(inv_Title)) {
|
||||
e.setCancelled(true);
|
||||
int Pages = Integer.parseInt(e.getView().getTitle().replace(inv_Title, ""));
|
||||
if (e.getRawSlot() == 45) {
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_LEVER_CLICK, 1, 2);
|
||||
if (Pages >= 2 && Pages <= 15) {
|
||||
AdminGui.OpenGui(p, Pages - 1);
|
||||
} else {
|
||||
p.sendMessage(Main.prefix + "§c已经是第一页了!");
|
||||
}
|
||||
}
|
||||
if (e.getRawSlot() == 53) {
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_LEVER_CLICK, 1, 2);
|
||||
if (Pages >= 1 && Pages <= 14) {
|
||||
AdminGui.OpenGui(p, Pages + 1);
|
||||
} else {
|
||||
p.sendMessage(Main.prefix + "§c已经是最后一页了!");
|
||||
}
|
||||
}
|
||||
if (e.getRawSlot() >= 0 && e.getRawSlot() <= 44) {
|
||||
if (!DemonAPI.itemIsNull(e.getCurrentItem()) && !DemonAPI.itemIsLore(e.getCurrentItem())) {
|
||||
String playName = null;
|
||||
String keyId = null;
|
||||
ItemStack item = e.getCurrentItem();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
for (String str : meta.getLore()) {
|
||||
if (str.startsWith("§a§l★§7物品主人: §f")) {
|
||||
playName = str.replace("§a§l★§7物品主人: §f", "");
|
||||
}
|
||||
if (str.startsWith("§a§l★§7物品序号: §f")) {
|
||||
keyId = str.replace("§a§l★§7物品序号: §f", "");
|
||||
}
|
||||
}
|
||||
String key = playName + "#" + keyId;
|
||||
if (e.getClick() == ClickType.LEFT) {
|
||||
ItemStack items = Main.DataG.getItemStack("TrashItems." + key + ".Items");
|
||||
p.getInventory().addItem(items);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_LEVER_CLICK, 1, 2);
|
||||
Main.DataG.set("TrashItems." + key, null);
|
||||
Main.KeyList.remove(key);
|
||||
Main.saveDataStatsConfig();
|
||||
AdminGui.OpenGui(p, Pages);
|
||||
}
|
||||
if (e.getClick() == ClickType.SHIFT_RIGHT) {
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_LEVER_CLICK, 1, 2);
|
||||
Main.DataG.set("TrashItems." + key, null);
|
||||
Main.KeyList.remove(key);
|
||||
Main.saveDataStatsConfig();
|
||||
AdminGui.OpenGui(p, Pages);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void OpenGui(Player p, int Paper) {
|
||||
String title = inv_Title + Paper;
|
||||
Inventory inv = Bukkit.createInventory(null, 54, title);
|
||||
for (int i = 46; i < 53; i++) {
|
||||
inv.setItem(i, glass(15, "§7[[§a▧§c▧§a▧§7]]"));
|
||||
}
|
||||
inv.setItem(45, Paper_Butt("§a上一页"));
|
||||
inv.setItem(53, Paper_Butt("§a下一页"));
|
||||
List<String> New_KeyList = Main.KeyList;
|
||||
if (New_KeyList.size() >= 1) {
|
||||
int amount = New_KeyList.size() - 1;
|
||||
int addamount = Paper * 36;
|
||||
if (Paper == 1) {
|
||||
for (int i = amount; i > -1; i--) {
|
||||
if (New_KeyList.get(i) == null) {
|
||||
break;
|
||||
}
|
||||
String key = Main.KeyList.get(i);
|
||||
String str = "TrashItems." + key + ".";
|
||||
String playName = key.split("#")[0];
|
||||
String keyID = key.split("#")[1];
|
||||
String time = Main.DataG.getString(str + "DropTime");
|
||||
ItemStack items = Main.DataG.getItemStack(str + "Items");
|
||||
inv.addItem(ItemsShow(playName, items, keyID, time));
|
||||
}
|
||||
} else {
|
||||
for (int i = amount - (addamount - 9); i > (amount - addamount); i--) {
|
||||
if (i >= 0) {
|
||||
String key = New_KeyList.get(i);
|
||||
String str = "TrashItems." + key + ".";
|
||||
String playName = key.split("#")[0];
|
||||
String keyID = key.split("#")[1];
|
||||
String time = Main.DataG.getString(str + "DropTime");
|
||||
ItemStack items = Main.DataG.getItemStack(str + "Items");
|
||||
inv.addItem(ItemsShow(playName, items, keyID, time));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
|
||||
public static ItemStack ItemsShow(String playName, ItemStack itemStack, String keyID, String time) {
|
||||
ItemStack item = itemStack.clone();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List<String> lore = new ArrayList<>(itemStack.getItemMeta().getLore());
|
||||
lore.add("§7-------------------------");
|
||||
lore.add("§a§l★§7物品主人: §f" + playName);
|
||||
lore.add("§a§l★§7物品序号: §f" + keyID);
|
||||
lore.add("§a§l★§7丢弃时间: §f" + time);
|
||||
lore.add(" ");
|
||||
lore.add("§e§l★§7左键点击取出此物品");
|
||||
lore.add("§e§l★§7SHIFT+右键点击删除此物品");
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
|
||||
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
|
||||
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
public static ItemStack Paper_Butt(String name) {
|
||||
ItemStack item = new ItemStack(Material.ARROW);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("§a§l★ §7点击翻页 §a§l★");
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack glass(int data, String name) {
|
||||
ItemStack item = new ItemStack(160, 1, (short) data);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
}
|
96
src/main/java/me/Demon/DemonTrash/Main.java
Normal file
96
src/main/java/me/Demon/DemonTrash/Main.java
Normal file
|
@ -0,0 +1,96 @@
|
|||
package me.Demon.DemonTrash;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class Main extends JavaPlugin implements Listener {
|
||||
|
||||
public static Main plugin;
|
||||
public static String prefix = "§7[§6废品处理§7] §f";
|
||||
//获取序列号
|
||||
public static List<String> KeyList = new ArrayList<>();
|
||||
public static List<String> BlackNoItemList = new ArrayList<>();
|
||||
public static File Datafile = new File("plugins/DemonTrash", "Data.yml");
|
||||
public static FileConfiguration DataG = YamlConfiguration.loadConfiguration(Datafile);
|
||||
public static void saveDataStatsConfig(){ try { Main.DataG.save(Datafile); }catch (IOException e){e.printStackTrace();} }
|
||||
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
saveDefaultConfig();
|
||||
BlackNoItemList.addAll(getConfig().getStringList("AntiItemsLore"));
|
||||
// 获取今天是否是15号
|
||||
int time = Integer.parseInt(getTime("dd"));
|
||||
if(time == 15){
|
||||
int a = 0;
|
||||
// 清理非本月的所有垃圾
|
||||
FileConfiguration yml = Main.DataG;
|
||||
for (String key : yml.getConfigurationSection("TrashItems").getKeys(false)){
|
||||
String trash_time = yml.getString("TrashItems."+key + ".DropTime");
|
||||
if(!trash_time.split("-")[0].equalsIgnoreCase(getTime("MM"))){
|
||||
yml.set("TrashItems."+key,null);
|
||||
a++;
|
||||
}
|
||||
}
|
||||
Main.saveDataStatsConfig();
|
||||
Bukkit.getConsoleSender().sendMessage("§3[魂式垃圾箱] §e总计清理历史垃圾 §a"+a+"件");
|
||||
}
|
||||
if(Main.DataG.getConfigurationSection("TrashItems") != null) {
|
||||
KeyList.addAll(Main.DataG.getConfigurationSection("TrashItems").getKeys(false));
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new MainGui(), plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new AdminGui(), plugin);
|
||||
Bukkit.getConsoleSender().sendMessage("§3[魂式垃圾箱] §a插件成功载入Server!");
|
||||
Bukkit.getConsoleSender().sendMessage("§3[魂式垃圾箱] §a妖魂QQ:1763917516");
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
Bukkit.getConsoleSender().sendMessage("§3[魂式垃圾箱] §c插件已正常关闭!");
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
|
||||
if (CommandLabel.equalsIgnoreCase("ljt")) {
|
||||
Player p = (Player) sender;
|
||||
MainGui.OpenGui(p);
|
||||
}
|
||||
if (CommandLabel.equalsIgnoreCase("trash")) {
|
||||
if (!sender.isOp()) {
|
||||
sender.sendMessage("§7[§6帝國戰爭§7] §f指令無效.");
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("qingli")) {
|
||||
if (Main.DataG.getConfigurationSection("TrashItems") != null) {
|
||||
for (String key : Main.DataG.getConfigurationSection("TrashItems").getKeys(false)) {
|
||||
Main.DataG.set("TrashItems." + key, null);
|
||||
}
|
||||
Main.saveDataStatsConfig();
|
||||
}
|
||||
sender.sendMessage(prefix + "总计清理 §e" + KeyList.size() + " §f件。");
|
||||
KeyList.clear();
|
||||
} else{
|
||||
AdminGui.OpenGui((Player) sender, 1);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getTime(String format){
|
||||
Date date = Calendar.getInstance().getTime();
|
||||
SimpleDateFormat datatime = new SimpleDateFormat(format);
|
||||
return datatime.format(date);
|
||||
}
|
||||
}
|
51
src/main/java/me/Demon/DemonTrash/MainGui.java
Normal file
51
src/main/java/me/Demon/DemonTrash/MainGui.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
package me.Demon.DemonTrash;
|
||||
|
||||
import me.Demon.DemonPlugin.DemonAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class MainGui implements Listener {
|
||||
|
||||
public static void OpenGui(Player p){
|
||||
String title = "公共垃圾桶(请把不要的物品放进来)";
|
||||
Inventory inv = Bukkit.createInventory(null,18,title);
|
||||
p.openInventory(inv);
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_LEVER_CLICK,1,2);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onclose(InventoryCloseEvent e){
|
||||
Player p = (Player) e.getPlayer();
|
||||
if(e.getView().getTitle().equalsIgnoreCase("公共垃圾桶(请把不要的物品放进来)")){
|
||||
Inventory inv = e.getInventory();
|
||||
Inventory newInv = Bukkit.createInventory(null,18,"公共垃圾桶(请再次确认你要丢弃的物品)");
|
||||
for (int i = 0;i< 18;i++){
|
||||
ItemStack item = inv.getItem(i);
|
||||
if(!DemonAPI.itemIsNull(item)){
|
||||
newInv.addItem(item);
|
||||
}
|
||||
}
|
||||
int amount = 0;
|
||||
for (int i = 0; i < 18; i++) {
|
||||
ItemStack item = newInv.getItem(i);
|
||||
if(!DemonAPI.itemIsNull(item)) {
|
||||
if(!DemonAPI.itemIsLore(item)) {
|
||||
TrashAPI.addItemsTrash(p.getName(), item);
|
||||
}
|
||||
amount = amount + item.getAmount();
|
||||
}
|
||||
}
|
||||
if(amount >= 1) {
|
||||
p.sendMessage(Main.prefix + "本次总计处理§e" + amount + "样§f你丢弃的废品。");
|
||||
p.playSound(p.getLocation(), Sound.BLOCK_LEVER_CLICK, 1, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
32
src/main/java/me/Demon/DemonTrash/TrashAPI.java
Normal file
32
src/main/java/me/Demon/DemonTrash/TrashAPI.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package me.Demon.DemonTrash;
|
||||
|
||||
import me.Demon.DemonPlugin.DemonAPI;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class TrashAPI {
|
||||
//将物品加入垃圾桶
|
||||
public static void addItemsTrash(String playName,ItemStack item){
|
||||
if(!itemIsBind(Objects.requireNonNull(item.getItemMeta()))) {
|
||||
String key = playName + "#" + DemonAPI.getRandomInt(90000, 10000);
|
||||
String time = Main.getTime("MM-dd");
|
||||
Main.DataG.set("TrashItems." + key + ".DropTime", time);
|
||||
Main.DataG.set("TrashItems." + key + ".Items", item);
|
||||
Main.KeyList.add(key);
|
||||
Main.saveDataStatsConfig();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean itemIsBind(ItemMeta meta){
|
||||
String itemName = meta.getDisplayName();
|
||||
for (int i = 0; i < Main.BlackNoItemList.size(); i++) {
|
||||
if (meta.getLore().contains(Main.BlackNoItemList.get(i))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
18
src/main/resources/Data.yml
Normal file
18
src/main/resources/Data.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
TrashItems:
|
||||
Yao_Hun_Ya#10086:
|
||||
DropTime: '2021-01-19'
|
||||
Items:
|
||||
==: org.bukkit.inventory.ItemStack
|
||||
type: DIAMOND_CHESTPLATE
|
||||
meta:
|
||||
==: ItemMeta
|
||||
meta-type: UNSPECIFIC
|
||||
display-name: §b§l钻石甲
|
||||
lore:
|
||||
- '§c§m§l §6§m§l §e§m§l §a§m§l §b§m§l §e§l装备淬炼§b§m§l §a§m§l §e§m§l §6§m§l §c§m§l '
|
||||
- §3§l❂六星淬炼
|
||||
- §e§l淬炼属性:§a附加防御+§610.0
|
||||
- §e§l淬炼属性:§a闪避率+§66.0%
|
||||
enchants:
|
||||
PROTECTION_ENVIRONMENTAL: 4
|
||||
THORNS: 2
|
2
src/main/resources/config.yml
Normal file
2
src/main/resources/config.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
AntiItemsLore:
|
||||
- "§7§o食物"
|
6
src/main/resources/plugin.yml
Normal file
6
src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
name: DemonTrash
|
||||
main: me.Demon.DemonTrash.Main
|
||||
version: 1.0
|
||||
commands:
|
||||
trash:
|
||||
ljt:
|
Loading…
Reference in New Issue
Block a user