mirror of
https://e.coding.net/circlecloud/MenuProtect.git
synced 2024-11-23 11:08:47 +00:00
feat: 修复检测逻辑错误
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
123ddb1bd5
commit
3d51867ebd
@ -33,7 +33,7 @@ public class ProtectListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onInvMove(final InventoryMoveItemEvent e) {
|
public void onInvMove(final InventoryMoveItemEvent e) {
|
||||||
final ItemStack ci = e.getItem();
|
final ItemStack ci = e.getItem();
|
||||||
if (MarkUtil.hasMark(ci)) {
|
if (MarkUtil.clearMark(ci) != null) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ public class ProtectListener implements Listener {
|
|||||||
private ItemStack[] handlerItems(final ItemStack[] cis) {
|
private ItemStack[] handlerItems(final ItemStack[] cis) {
|
||||||
for (int i = 0; i < cis.length; i++) {
|
for (int i = 0; i < cis.length; i++) {
|
||||||
final ItemStack itemStack = cis[i];
|
final ItemStack itemStack = cis[i];
|
||||||
if (MarkUtil.hasMark(itemStack)) {
|
if (MarkUtil.clearMark(itemStack) != null) {
|
||||||
cis[i] = new ItemStack(Material.AIR);
|
cis[i] = new ItemStack(Material.AIR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class WowSuchCleanerListener implements Listener {
|
|||||||
final List<ItemStack> list = e.getItemsToAuction();
|
final List<ItemStack> list = e.getItemsToAuction();
|
||||||
final List<ItemStack> needRemove = e.getItemsToAuction();
|
final List<ItemStack> needRemove = e.getItemsToAuction();
|
||||||
for (final ItemStack itemStack : list) {
|
for (final ItemStack itemStack : list) {
|
||||||
if (MarkUtil.hasMark(itemStack)) {
|
if (MarkUtil.clearMark(itemStack) != null) {
|
||||||
needRemove.add(itemStack);
|
needRemove.add(itemStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import pw.yumc.YumCore.bukkit.Log;
|
import pw.yumc.YumCore.bukkit.Log;
|
||||||
import pw.yumc.YumCore.kit.PKit;
|
import pw.yumc.YumCore.kit.PKit;
|
||||||
@ -18,35 +19,45 @@ public class MarkUtil {
|
|||||||
public static Map<String, List<String>> cmds = new HashMap<>();
|
public static Map<String, List<String>> cmds = new HashMap<>();
|
||||||
|
|
||||||
public static void handlerItemClick(final Player p, final ItemStack is) {
|
public static void handlerItemClick(final Player p, final ItemStack is) {
|
||||||
if (hasMark(is) && is.getItemMeta().hasLore()) {
|
String leftName = clearMark(is);
|
||||||
for (final String lore : is.getItemMeta().getLore()) {
|
if (leftName != null) {
|
||||||
if (cmds.containsKey(lore) || (is.getItemMeta().hasDisplayName() && cmds.containsKey(is.getItemMeta().getDisplayName()))) {
|
String key = null;
|
||||||
for (final String cmd : cmds.get(lore)) {
|
ItemMeta im = is.getItemMeta();
|
||||||
PKit.runTask(new Runnable() {
|
if (cmds.containsKey(leftName)) {
|
||||||
@Override
|
key = leftName;
|
||||||
public void run() {
|
} else if (im.hasLore()) {
|
||||||
CommandSender sender = Bukkit.getConsoleSender();
|
for (final String lore : is.getItemMeta().getLore()) {
|
||||||
if (cmd.startsWith("[p]")) {
|
if (cmds.containsKey(lore)) {
|
||||||
sender = p;
|
key = lore;
|
||||||
}
|
|
||||||
final String rcmd = cmd.replaceAll("%player%", p.getName());
|
|
||||||
Bukkit.dispatchCommand(sender, rcmd.startsWith("[") ? rcmd.substring(3) : rcmd);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (key != null) {
|
||||||
|
for (final String cmd : cmds.get(key)) {
|
||||||
|
PKit.runTask(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
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) {
|
public static String clearMark(final ItemStack ci) {
|
||||||
try {
|
try {
|
||||||
for (final String mark : marks) {
|
for (final String mark : marks) {
|
||||||
if (ci.getItemMeta().getDisplayName().startsWith(mark)) { return true; }
|
if (ci.getItemMeta().getDisplayName().startsWith(mark)) { return ci.getItemMeta().getDisplayName().split(mark)[1]; }
|
||||||
}
|
}
|
||||||
} catch (final Exception ignored) {
|
} catch (final Exception ignored) {
|
||||||
}
|
}
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initCommand(final ConfigurationSection cfg) {
|
public static void initCommand(final ConfigurationSection cfg) {
|
||||||
|
Loading…
Reference in New Issue
Block a user