mirror of
https://e.coding.net/circlecloud/MenuProtect.git
synced 2024-11-21 10:48:46 +00:00
feat: 添加LoreCommand功能
This commit is contained in:
parent
185921d4b3
commit
3129f63f90
4
pom.xml
4
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>MenuProtect</artifactId>
|
||||
<version>1.2</version>
|
||||
<version>1.3</version>
|
||||
<name>MenuProtect</name>
|
||||
<build>
|
||||
<finalName>${project.name}</finalName>
|
||||
@ -57,7 +57,7 @@
|
||||
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
||||
</ciManagement>
|
||||
<properties>
|
||||
<update.description></update.description>
|
||||
<update.description>1.3新版本 支持LoreCommand</update.description>
|
||||
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -1,11 +1,35 @@
|
||||
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<String> marks = null;
|
||||
public static Map<String, List<String>> cmds = new HashMap<>();
|
||||
|
||||
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 {
|
||||
@ -14,9 +38,15 @@ public class MarkUtil {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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'
|
@ -10,7 +10,11 @@ commands:
|
||||
usage: §b使用/${project.artifactId} help 查看帮助!
|
||||
permission: ${project.artifactId}.reload
|
||||
permission-message: §c你没有 <permission> 的权限来执行此命令!
|
||||
mp:
|
||||
permissions:
|
||||
${project.artifactId}.reload:
|
||||
description: 重新载入插件!
|
||||
default: op
|
||||
${project.artifactId}.reload:
|
||||
description: 重新载入插件!
|
||||
default: op
|
Loading…
Reference in New Issue
Block a user