From c0075f6f01f15c1b819ba0cf867216bd85548075 Mon Sep 17 00:00:00 2001
From: tianyu <32282861@qq.com>
Date: Wed, 24 Jul 2024 07:24:38 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=89=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 40 ++++++
pom.xml | 32 +++++
.../Demon/DemonPlayerMail/Api/DMailAPI.java | 47 +++++++
.../DemonPlayerMail/Listener/JoinEvant.java | 36 +++++
.../DemonPlayerMail/Listener/meMail.java | 93 +++++++++++++
.../DemonPlayerMail/Listener/toMail.java | 95 ++++++++++++++
.../java/me/Demon/DemonPlayerMail/Main.java | 124 ++++++++++++++++++
src/main/resources/MailData.yml | 21 +++
src/main/resources/config.yml | 3 +
src/main/resources/plugin.yml | 5 +
10 files changed, 496 insertions(+)
create mode 100644 .gitignore
create mode 100644 pom.xml
create mode 100644 src/main/java/me/Demon/DemonPlayerMail/Api/DMailAPI.java
create mode 100644 src/main/java/me/Demon/DemonPlayerMail/Listener/JoinEvant.java
create mode 100644 src/main/java/me/Demon/DemonPlayerMail/Listener/meMail.java
create mode 100644 src/main/java/me/Demon/DemonPlayerMail/Listener/toMail.java
create mode 100644 src/main/java/me/Demon/DemonPlayerMail/Main.java
create mode 100644 src/main/resources/MailData.yml
create mode 100644 src/main/resources/config.yml
create mode 100644 src/main/resources/plugin.yml
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c037f46
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,40 @@
+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
+/.idea/
+/out/
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..b876998
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,32 @@
+
+
+ 4.0.0
+
+ org.example
+ DemonPlayerMail
+ 1.0-SNAPSHOT
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+
+ public-rpg
+ https://repo.aurora-pixels.com/repository/public-rpg/
+
+
+
+
+
+ org.spigotmc
+ spigot-api
+ 1.12.2
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/me/Demon/DemonPlayerMail/Api/DMailAPI.java b/src/main/java/me/Demon/DemonPlayerMail/Api/DMailAPI.java
new file mode 100644
index 0000000..de319bf
--- /dev/null
+++ b/src/main/java/me/Demon/DemonPlayerMail/Api/DMailAPI.java
@@ -0,0 +1,47 @@
+package me.Demon.DemonPlayerMail.Api;
+
+import me.Demon.DemonPlayerMail.Main;
+import org.bukkit.inventory.ItemStack;
+
+public abstract class DMailAPI {
+
+ //发送物品到玩家邮箱中
+ public static void GiveItem(String playName, ItemStack item) {
+ //获取物品数量
+ int amount = item.getAmount();
+ //设置邮箱物品数量
+ addMailAmount(playName, amount);
+ //获取物品key标识
+ int keyId = Main.getRandomInt(80000, 10000);
+ //设置物品到邮箱
+ Main.mailDataG.set("MailData." + playName + "." + keyId, item);
+ //保存邮箱设置
+ Main.saveMailDataConfig();
+ //保存邮箱日志
+ Main.SaveLogAndSendLog(playName, item, "新增");
+ }
+
+ //获取玩家邮箱有多少个物品
+ public static int getMailAmount(String playName) {
+ return Main.mailDataG.getInt("MailData." + playName + ".amount");
+ }
+
+ //增加玩家邮箱物品数量
+ public static void addMailAmount(String playName, int amount) {
+ int amountPro = getMailAmount(playName);
+ Main.mailDataG.set("MailData." + playName + ".amount", (amountPro + amount));
+ Main.saveMailDataConfig();
+ }
+
+ //设置玩家邮箱物品数量
+ public static void setMailAmount(String playName, int amount) {
+ Main.mailDataG.set("MailData." + playName + ".amount", amount);
+ Main.saveMailDataConfig();
+ }
+
+ //清空玩家的邮箱数据
+ public static void resetMailData(String playName) {
+ Main.mailDataG.set("MailData." + playName, null);
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/me/Demon/DemonPlayerMail/Listener/JoinEvant.java b/src/main/java/me/Demon/DemonPlayerMail/Listener/JoinEvant.java
new file mode 100644
index 0000000..6890835
--- /dev/null
+++ b/src/main/java/me/Demon/DemonPlayerMail/Listener/JoinEvant.java
@@ -0,0 +1,36 @@
+package me.Demon.DemonPlayerMail.Listener;
+
+import me.Demon.DemonPlayerMail.Api.DMailAPI;
+import me.Demon.DemonPlayerMail.Main;
+import net.md_5.bungee.api.chat.ClickEvent;
+import net.md_5.bungee.api.chat.ComponentBuilder;
+import net.md_5.bungee.api.chat.HoverEvent;
+import net.md_5.bungee.api.chat.TextComponent;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.scheduler.BukkitRunnable;
+
+public class JoinEvant implements Listener {
+
+ @EventHandler
+ public void onjoin(PlayerJoinEvent e) {
+ Player p = e.getPlayer();
+ new BukkitRunnable() {
+ public void run() {
+ int MailAmount = DMailAPI.getMailAmount(p.getName());
+ if (MailAmount >= 1) {
+ OpenMail(p, Main.prefix + "你有§a" + MailAmount + "§f封邮件物品尚未签收! §e[点击签收]");
+ }
+ }
+ }.runTaskLater(Main.plugin, 40L);
+ }
+
+ public static void OpenMail(Player player, String message) {
+ TextComponent Click = new TextComponent(message);
+ Click.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§e点击打开邮箱").create()));
+ Click.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/dpmail open"));
+ player.spigot().sendMessage(Click);
+ }
+}
diff --git a/src/main/java/me/Demon/DemonPlayerMail/Listener/meMail.java b/src/main/java/me/Demon/DemonPlayerMail/Listener/meMail.java
new file mode 100644
index 0000000..d48e893
--- /dev/null
+++ b/src/main/java/me/Demon/DemonPlayerMail/Listener/meMail.java
@@ -0,0 +1,93 @@
+package me.Demon.DemonPlayerMail.Listener;
+
+import me.Demon.DemonPlayerMail.Api.DMailAPI;
+import me.Demon.DemonPlayerMail.Main;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.Sound;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class meMail implements Listener {
+
+ public static String inv_title = "§m§a§i§l§r玩家邮箱 - 收件箱[" + Main.serverName + "]";
+
+ @EventHandler
+ public void onclick(InventoryClickEvent e) {
+ Player p = (Player) e.getWhoClicked();
+ if (inv_title.equalsIgnoreCase(e.getView().getTitle())) {
+ e.setCancelled(true);
+ if (e.getRawSlot() == 40) {
+ int amount = DMailAPI.getMailAmount(p.getName());
+ if (amount < 1) {
+ p.sendMessage(Main.prefix + "你没有可签收的物品.");
+ p.playSound(p.getLocation(), Sound.BLOCK_LEVER_CLICK, 1, 2);
+ return;
+ }
+ YamlConfiguration yml = (YamlConfiguration) Main.mailDataG;
+ for (String keyId : yml.getConfigurationSection("MailData." + p.getName()).getKeys(false)) {
+ if (!keyId.equalsIgnoreCase("amount")) {
+ ItemStack item = yml.getItemStack("MailData." + p.getName() + "." + keyId);
+ p.getInventory().addItem(item);
+ yml.set("MailData." + p.getName() + "." + keyId, null);
+ Main.SaveLogAndSendLog(p.getName(), item, "签收");
+ }
+ }
+ OpenGui(p);
+ DMailAPI.setMailAmount(p.getName(), 0);
+ Main.saveMailDataConfig();
+ p.sendMessage(Main.prefix + "成功签收 §a" + amount + " §f样物品.");
+ p.playSound(p.getLocation(), Sound.BLOCK_LEVER_CLICK, 1, 2);
+ }
+ }
+ }
+
+ public static void OpenGui(Player p) {
+ Inventory inv = Bukkit.createInventory(null, 45, inv_title);
+ YamlConfiguration yml = (YamlConfiguration) Main.mailDataG;
+ if (yml.getString("MailData." + p.getName()) != null) {
+ for (String keyId : yml.getConfigurationSection("MailData." + p.getName()).getKeys(false)) {
+ if (!keyId.equalsIgnoreCase("amount")) {
+ ItemStack item = yml.getItemStack("MailData." + p.getName() + "." + keyId);
+ inv.addItem(item);
+ }
+ }
+ }
+ for (int i = 36; i < 45; i++) {
+ inv.setItem(i, glass());
+ }
+ inv.setItem(40, InfoItems());
+ p.openInventory(inv);
+ p.playSound(p.getLocation(), Sound.BLOCK_LEVER_CLICK, 1, 2);
+ }
+
+
+ public static ItemStack glass() {
+ ItemStack item = new ItemStack(160, 1, (short) 15);
+ ItemMeta meta = item.getItemMeta();
+ meta.setDisplayName("§7[§a■□■§7]");
+ item.setItemMeta(meta);
+ return item;
+ }
+
+ public static ItemStack InfoItems() {
+ ItemStack item = new ItemStack(Material.SLIME_BALL);
+ ItemMeta meta = item.getItemMeta();
+ meta.setDisplayName("§a点击一键签收");
+ List lore = new ArrayList<>();
+ lore.add("§e★§7点击将邮件物品全部收取");
+ lore.add("§c★§7请检查背包空位是否充足");
+ meta.setLore(lore);
+ item.setItemMeta(meta);
+ return item;
+ }
+}
diff --git a/src/main/java/me/Demon/DemonPlayerMail/Listener/toMail.java b/src/main/java/me/Demon/DemonPlayerMail/Listener/toMail.java
new file mode 100644
index 0000000..b88450d
--- /dev/null
+++ b/src/main/java/me/Demon/DemonPlayerMail/Listener/toMail.java
@@ -0,0 +1,95 @@
+package me.Demon.DemonPlayerMail.Listener;
+
+import me.Demon.DemonPlayerMail.Api.DMailAPI;
+import me.Demon.DemonPlayerMail.Main;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.Sound;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class toMail implements Listener {
+
+ public static String inv_title = "§m§a§i§l§r管理发件箱 - ";
+
+ @EventHandler
+ public void onclick(InventoryClickEvent e) {
+ Player p = (Player) e.getWhoClicked();
+ Inventory inv = e.getInventory();
+ if (e.getView().getTitle().contains(inv_title)) {
+ if (e.getRawSlot() >= 36 && e.getRawSlot() <= 44) {
+ e.setCancelled(true);
+ if (e.getRawSlot() == 40) {
+ String playName = e.getView().getTitle().replace(inv_title, "");
+ p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2);
+ //清空玩家邮箱数据
+ DMailAPI.resetMailData(playName);
+ int amount = 0;
+ for (int i = 0; i < 36; i++) {
+ ItemStack item = inv.getItem(i);
+ if (!Main.itemIsNull(item)) {
+ amount = amount + item.getAmount();
+ DMailAPI.GiveItem(playName, item);
+ Main.SaveLogAndSendLog(playName, item, "新增");
+ }
+ }
+ if (amount >= 1) {
+ p.closeInventory();
+ DMailAPI.setMailAmount(playName, amount);
+ p.sendMessage(Main.prefix + "成功发送物品到§6" + playName + "§f的游戏邮箱中.");
+ } else {
+ p.closeInventory();
+ p.sendMessage(Main.prefix + "你没有可发送的物品.");
+ }
+ }
+ }
+ }
+ }
+
+ public static void OpenGui(Player p, String playName) {
+ Inventory inv = Bukkit.createInventory(null, 45, inv_title + playName);
+ YamlConfiguration yml = (YamlConfiguration) Main.mailDataG;
+ if (yml.getString("MailData." + playName) != null) {
+ for (String keyId : yml.getConfigurationSection("MailData." + playName).getKeys(false)) {
+ if (!keyId.equalsIgnoreCase("amount")) {
+ ItemStack item = yml.getItemStack("MailData." + playName + "." + keyId);
+ inv.addItem(item);
+ }
+ }
+ }
+ for (int i = 36; i < 45; i++) {
+ inv.setItem(i, glass());
+ }
+ inv.setItem(40, sendOK());
+ p.openInventory(inv);
+ }
+
+
+ public static ItemStack glass() {
+ ItemStack item = new ItemStack(160, 1, (short) 15);
+ ItemMeta meta = item.getItemMeta();
+ meta.setDisplayName("§7[§a■□■§7]");
+ item.setItemMeta(meta);
+ return item;
+ }
+
+ public static ItemStack sendOK() {
+ ItemStack item = new ItemStack(Material.SLIME_BALL);
+ ItemMeta meta = item.getItemMeta();
+ meta.setDisplayName("§6§l确认发货");
+ List lore = new ArrayList<>();
+ lore.add("§7点击发货");
+ meta.setLore(lore);
+ item.setItemMeta(meta);
+ return item;
+ }
+}
diff --git a/src/main/java/me/Demon/DemonPlayerMail/Main.java b/src/main/java/me/Demon/DemonPlayerMail/Main.java
new file mode 100644
index 0000000..665d256
--- /dev/null
+++ b/src/main/java/me/Demon/DemonPlayerMail/Main.java
@@ -0,0 +1,124 @@
+package me.Demon.DemonPlayerMail;
+
+import me.Demon.DemonPlayerMail.Listener.JoinEvant;
+import me.Demon.DemonPlayerMail.Listener.meMail;
+import me.Demon.DemonPlayerMail.Listener.toMail;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+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.inventory.ItemStack;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+public class Main extends JavaPlugin implements Listener {
+
+ public static Main plugin;
+ public static String prefix = "§7[§a§l邮箱§7] §f";
+ public static String serverName = "主城";
+ public static File Datafile = new File("plugins/DemonPlayerMail", "MailData.yml");
+ public static FileConfiguration mailDataG = YamlConfiguration.loadConfiguration(Datafile);
+
+ public static void saveMailDataConfig() {
+ try {
+ mailDataG.save(Datafile);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void onEnable() {
+ plugin = this;
+ saveDefaultConfig();
+ serverName = getConfig().getString("ServerName");
+ Bukkit.getConsoleSender().sendMessage("§b[玩家邮箱] §a插件成功载入Server!");
+ Bukkit.getConsoleSender().sendMessage("§b[玩家邮箱] §a妖魂QQ:1763917516");
+ Bukkit.getPluginManager().registerEvents(this, this);
+ Bukkit.getServer().getPluginManager().registerEvents(new meMail(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new toMail(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new JoinEvant(), plugin);
+ }
+
+ public void onDisable() {
+ Bukkit.getConsoleSender().sendMessage("§b[DemonPlayerMail] §c插件已正常关闭!");
+ }
+
+ public boolean onCommand(CommandSender sender, Command cmd, String Command, String[] args) {
+ if (Command.equalsIgnoreCase("dpmail")) {
+ if (args.length == 2 && args[0].equalsIgnoreCase("to") && sender.isOp()) {
+ if (sender instanceof Player) {
+ String playName = args[1];
+ toMail.OpenGui((Player) sender, playName);
+ }
+ } else if (args.length == 1 && args[0].equalsIgnoreCase("open")) {
+ if (sender instanceof Player) {
+ Player p = (Player) sender;
+ meMail.OpenGui(p);
+ }
+ } else if (args.length == 1 && args[0].equalsIgnoreCase("clearall")) {
+ // 清理日志
+ getConfig().set("MailDataLog", null);
+ saveConfig();
+ // 清理玩家邮箱物品操作
+ int a = 0;
+ FileConfiguration yml = Main.mailDataG;
+ for (String playName : yml.getConfigurationSection("MailData").getKeys(false)) {
+ yml.set("MailData." + playName, null);
+ int size = yml.getConfigurationSection("MailData." + playName).getKeys(false).size();
+ if (size >= 2) {
+ a++;
+ }
+ }
+ Main.saveMailDataConfig();
+ sender.sendMessage(prefix + "操作成功,清理物品[§e" + a + "§f]件.");
+ } else {
+ sender.sendMessage("");
+ sender.sendMessage("§e------- ======= §6魂式系统邮箱 §e======= -------");
+ sender.sendMessage("§2/dpmail open §f- §2打开邮箱");
+ sender.sendMessage("§2/dpmail clearall §f- §2清理邮箱");
+ sender.sendMessage("§2/dpmail to §e[玩家名] §f- §2发送物品");
+ sender.sendMessage("§e------- ======= §6魂式系统邮箱 §e======= -------");
+ }
+ }
+ return true;
+ }
+
+ public static String getTime(String format) {
+ Date date = Calendar.getInstance().getTime();
+ SimpleDateFormat datatime = new SimpleDateFormat(format);
+ return datatime.format(date);
+ }
+
+ public static int getRandomInt(int max, int mix) {
+ return new Random().nextInt(max) + mix;
+ }
+
+ public static boolean itemIsNull(ItemStack item) {
+ return item == null || item.getType() == Material.AIR;
+ }
+
+ public static boolean itemIsLore(ItemStack item) {
+ return item.getItemMeta().getLore() == null;
+ }
+
+ public static List getPlayerLog(String time) {
+ return Main.plugin.getConfig().getStringList("MailDataLog." + time);
+ }
+
+ public static void SaveLogAndSendLog(String playName, ItemStack item, String type) {
+ List list = new ArrayList<>();
+ String time = getTime("yyyy-MM-dd");
+ list.add("[日志] " + Main.getTime("HH:mm") + " 玩家 " + playName + " " + type + "物品 " + item.getItemMeta().getDisplayName() + " 数量:" + item.getAmount());
+ list.addAll(Main.getPlayerLog(playName));
+ Main.plugin.getConfig().set("MailDataLog." + time, list);
+ Main.plugin.saveConfig();
+ }
+}
diff --git a/src/main/resources/MailData.yml b/src/main/resources/MailData.yml
new file mode 100644
index 0000000..5bbd102
--- /dev/null
+++ b/src/main/resources/MailData.yml
@@ -0,0 +1,21 @@
+MailData:
+ 虎牙妖魂吖:
+ amount: 1
+ '116264':
+ ==: org.bukkit.inventory.ItemStack
+ type: PAPER
+ meta:
+ ==: ItemMeta
+ meta-type: UNSPECIFIC
+ display-name: §6§l特价建筑券
+ lore:
+ - §a§l★§7斗罗帝国道具奖券
+ - §7凭借此券可获得建材
+ - ' '
+ - '§7使用方法:'
+ - §7在§e星斗森林§7找NPC兑换
+ enchants:
+ PROTECTION_ENVIRONMENTAL: 1
+ ItemFlags:
+ - HIDE_ENCHANTS
+ internal: H4sIAAAAAAAAAONiYOBgYCkuSa1g4EpOzMzJTMyPNzNhAAAkPOw5FwAAAA==
\ 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..c309a31
--- /dev/null
+++ b/src/main/resources/config.yml
@@ -0,0 +1,3 @@
+ServerName: "主城"
+MailDataLog:
+ 虎牙妖魂吖: 10
\ 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..0abf262
--- /dev/null
+++ b/src/main/resources/plugin.yml
@@ -0,0 +1,5 @@
+name: DemonPlayerMail
+main: me.Demon.DemonPlayerMail.Main
+version: 1.0
+commands:
+ dpmail:
\ No newline at end of file