1
0
mirror of https://e.coding.net/circlecloud/MenuProtect.git synced 2024-12-26 16:28:48 +00:00

feat: 修复检测逻辑错误

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-12-21 18:15:02 +08:00
parent 123ddb1bd5
commit 3d51867ebd
3 changed files with 32 additions and 21 deletions

View File

@ -33,7 +33,7 @@ public class ProtectListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onInvMove(final InventoryMoveItemEvent e) {
final ItemStack ci = e.getItem();
if (MarkUtil.hasMark(ci)) {
if (MarkUtil.clearMark(ci) != null) {
e.setCancelled(true);
}
}
@ -41,7 +41,7 @@ public class ProtectListener implements Listener {
private ItemStack[] handlerItems(final ItemStack[] cis) {
for (int i = 0; i < cis.length; i++) {
final ItemStack itemStack = cis[i];
if (MarkUtil.hasMark(itemStack)) {
if (MarkUtil.clearMark(itemStack) != null) {
cis[i] = new ItemStack(Material.AIR);
}
}

View File

@ -20,7 +20,7 @@ public class WowSuchCleanerListener implements Listener {
final List<ItemStack> list = e.getItemsToAuction();
final List<ItemStack> needRemove = e.getItemsToAuction();
for (final ItemStack itemStack : list) {
if (MarkUtil.hasMark(itemStack)) {
if (MarkUtil.clearMark(itemStack) != null) {
needRemove.add(itemStack);
}
}

View File

@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.kit.PKit;
@ -18,35 +19,45 @@ public class MarkUtil {
public static Map<String, List<String>> cmds = new HashMap<>();
public static void handlerItemClick(final Player p, final ItemStack is) {
if (hasMark(is) && is.getItemMeta().hasLore()) {
for (final String lore : is.getItemMeta().getLore()) {
if (cmds.containsKey(lore) || (is.getItemMeta().hasDisplayName() && cmds.containsKey(is.getItemMeta().getDisplayName()))) {
for (final String cmd : cmds.get(lore)) {
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);
}
});
String leftName = clearMark(is);
if (leftName != null) {
String key = null;
ItemMeta im = is.getItemMeta();
if (cmds.containsKey(leftName)) {
key = leftName;
} else if (im.hasLore()) {
for (final String lore : is.getItemMeta().getLore()) {
if (cmds.containsKey(lore)) {
key = lore;
}
}
}
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 {
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) {
}
return false;
return null;
}
public static void initCommand(final ConfigurationSection cfg) {