diff --git a/pom.xml b/pom.xml
index f2ee8ec..1534788 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
pw.yumc
MenuProtect
- 1.2
+ 1.3
MenuProtect
${project.name}
@@ -57,7 +57,7 @@
http://ci.yumc.pw/job/${project.artifactId}/
-
+ 1.3新版本 支持LoreCommand
DEBUG
UTF-8
diff --git a/src/main/java/pw/yumc/MenuProtect/MenuProtect.java b/src/main/java/pw/yumc/MenuProtect/MenuProtect.java
index b414e72..02933ab 100644
--- a/src/main/java/pw/yumc/MenuProtect/MenuProtect.java
+++ b/src/main/java/pw/yumc/MenuProtect/MenuProtect.java
@@ -1,6 +1,9 @@
package pw.yumc.MenuProtect;
import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.PluginHelper.config.FileConfig;
@@ -10,6 +13,17 @@ import pw.yumc.MenuProtect.utils.MarkUtil;
public class MenuProtect extends JavaPlugin {
FileConfig config;
+ @Override
+ public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
+ if (args.length == 1) {
+ final Player player = Bukkit.getPlayerExact(args[0]);
+ if (player != null) {
+ player.closeInventory();
+ }
+ }
+ return true;
+ }
+
@Override
public void onEnable() {
Bukkit.getPluginManager().registerEvents(new ProtectListener(this), this);
@@ -20,5 +34,6 @@ public class MenuProtect extends JavaPlugin {
public void onLoad() {
config = new FileConfig(this);
MarkUtil.marks = config.getStringList("MarkList");
+ MarkUtil.initCommand(config.getConfigurationSection("LoreCommand"));
}
}
diff --git a/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java b/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java
index 9907eaa..6331830 100644
--- a/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java
+++ b/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java
@@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
+import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.inventory.ItemStack;
@@ -22,6 +23,13 @@ public class ProtectListener implements Listener {
this.plugin = plugin;
}
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onInvClick(final InventoryClickEvent e) {
+ if (e.getWhoClicked() instanceof Player) {
+ handlerPlayerClick((Player) e.getWhoClicked(), e.getCurrentItem());
+ }
+ }
+
@EventHandler(priority = EventPriority.MONITOR)
public void onInvClose(final InventoryCloseEvent e) {
if (e.getPlayer() instanceof Player) {
@@ -47,6 +55,15 @@ public class ProtectListener implements Listener {
return cis;
}
+ private void handlerPlayerClick(final Player p, final ItemStack is) {
+ Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
+ @Override
+ public void run() {
+ MarkUtil.handlerItemClick(p, is);
+ }
+ });
+ }
+
private void handlerPlayerInventory(final Player p) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
diff --git a/src/main/java/pw/yumc/MenuProtect/utils/MarkUtil.java b/src/main/java/pw/yumc/MenuProtect/utils/MarkUtil.java
index 0a7bfda..17c661f 100644
--- a/src/main/java/pw/yumc/MenuProtect/utils/MarkUtil.java
+++ b/src/main/java/pw/yumc/MenuProtect/utils/MarkUtil.java
@@ -1,22 +1,52 @@
package pw.yumc.MenuProtect.utils;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class MarkUtil {
- public static List marks = null;
+ public static List marks = null;
+ public static Map> cmds = new HashMap<>();
- public static boolean hasMark(final ItemStack ci) {
- try {
- for (final String mark : marks) {
- if (ci.getItemMeta().getDisplayName().startsWith(mark)) {
- return true;
- }
- }
- return false;
- } catch (final Exception e) {
- return false;
- }
- }
+ public static void handlerItemClick(final Player p, final ItemStack is) {
+ if (hasMark(is)) {
+ for (final String lore : is.getItemMeta().getLore()) {
+ if (cmds.containsKey(lore)) {
+ for (final String cmd : cmds.get(lore)) {
+ CommandSender sender = Bukkit.getConsoleSender();
+ if (cmd.startsWith("[p]")) {
+ sender = p;
+ }
+ final String rcmd = cmd.replaceAll("%player%", p.getName());
+ Bukkit.dispatchCommand(sender, rcmd.startsWith("[") ? rcmd.substring(3) : rcmd);
+ }
+ }
+ }
+ }
+ }
+
+ public static boolean hasMark(final ItemStack ci) {
+ try {
+ for (final String mark : marks) {
+ if (ci.getItemMeta().getDisplayName().startsWith(mark)) {
+ return true;
+ }
+ }
+ } catch (final Exception e) {
+ }
+ return false;
+ }
+
+ public static void initCommand(final ConfigurationSection cfg) {
+ cmds.clear();
+ for (final String lore : cfg.getKeys(false)) {
+ cmds.put(lore, cfg.getStringList(lore));
+ }
+ }
}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 22cbeb0..567f456 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -1,3 +1,10 @@
+Version: 1.3
+#菜单清除标记
MarkList:
- '§m§p§r'
- '§q§s§6[§b快捷商店§6] §c悬浮物品§r'
+#Lore命令配置([c]=>控制台命令 [p]=>玩家命令 默认为控制台命令)
+LoreCommand:
+ '关闭菜单':
+ - 'mp %player%'
+ - '[p]mp'
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 7d3eca2..e45c070 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -10,7 +10,11 @@ commands:
usage: §b使用/${project.artifactId} help 查看帮助!
permission: ${project.artifactId}.reload
permission-message: §c你没有 的权限来执行此命令!
+ mp:
permissions:
+ ${project.artifactId}.reload:
+ description: 重新载入插件!
+ default: op
${project.artifactId}.reload:
description: 重新载入插件!
default: op
\ No newline at end of file