mirror of
https://e.coding.net/circlecloud/MenuProtect.git
synced 2024-12-27 16:38:48 +00:00
feat: 添加关闭菜单时的检测
This commit is contained in:
parent
bea6e4867d
commit
ae49309f29
28
pom.xml
28
pom.xml
@ -1,9 +1,9 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cn.citycraft</groupId>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>MenuProtect</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>1.1</version>
|
||||
<name>MenuProtect</name>
|
||||
<build>
|
||||
<finalName>${project.name}</finalName>
|
||||
@ -52,28 +52,34 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<ciManagement>
|
||||
<system>Jenkins</system>
|
||||
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
||||
</ciManagement>
|
||||
<properties>
|
||||
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
|
||||
<update.description></update.description>
|
||||
<env.BUILD_NUMBER>1</env.BUILD_NUMBER>
|
||||
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>citycraft-repo</id>
|
||||
<url>${jenkins.url}/plugin/repository/everything/</url>
|
||||
<id>yumc-repo</id>
|
||||
<url>http://repo.yumc.pw/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>jtb</id>
|
||||
<name>YUMC</name>
|
||||
<url>http://repo.yumc.pw/content/repositories/yumcenter/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||
<version>1.9-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.citycraft</groupId>
|
||||
|
@ -1,94 +0,0 @@
|
||||
package cn.citycraft.MenuProtect.listen;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
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.InventoryMoveItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import cn.citycraft.MenuProtect.MenuProtect;
|
||||
import cn.citycraft.MenuProtect.utils.MarkUtil;
|
||||
|
||||
public class ProtectListener implements Listener {
|
||||
|
||||
private final MenuProtect plugin;
|
||||
|
||||
public ProtectListener(final MenuProtect plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInvMove(final InventoryMoveItemEvent e) {
|
||||
final ItemStack ci = e.getItem();
|
||||
if (MarkUtil.hasMark(ci)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInvPickup(final InventoryPickupItemEvent e) {
|
||||
final ItemStack ci = e.getItem().getItemStack();
|
||||
if (MarkUtil.hasMark(ci)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onItemClick(final InventoryClickEvent e) {
|
||||
final Player p = (Player) e.getWhoClicked();
|
||||
final ItemStack ci = e.getCurrentItem();
|
||||
final Inventory inv = e.getInventory();
|
||||
if (inv.getHolder() == null) {
|
||||
return;
|
||||
}
|
||||
final int solt = e.getSlot();
|
||||
try {
|
||||
if (MarkUtil.hasMark(ci)) {
|
||||
inv.setItem(solt, new ItemStack(Material.AIR));
|
||||
p.closeInventory();
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerHandlerItem(final PlayerItemHeldEvent e) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Player p = e.getPlayer();
|
||||
final PlayerInventory inv = p.getInventory();
|
||||
final ItemStack[] cis = inv.getArmorContents();
|
||||
for (int i = 0; i < cis.length; i++) {
|
||||
final ItemStack itemStack = cis[i];
|
||||
if (MarkUtil.hasMark(itemStack)) {
|
||||
cis[i] = new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
inv.setArmorContents(cis);
|
||||
final int newslot = e.getNewSlot();
|
||||
final ItemStack newItem = inv.getItem(newslot);
|
||||
if (MarkUtil.hasMark(newItem)) {
|
||||
inv.setItem(newslot, new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerPickup(final PlayerPickupItemEvent e) {
|
||||
final ItemStack ci = e.getItem().getItemStack();
|
||||
if (MarkUtil.hasMark(ci)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
package cn.citycraft.MenuProtect;
|
||||
package pw.yumc.MenuProtect;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.MenuProtect.listen.ProtectListener;
|
||||
import cn.citycraft.MenuProtect.utils.MarkUtil;
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
import pw.yumc.MenuProtect.listen.ProtectListener;
|
||||
import pw.yumc.MenuProtect.utils.MarkUtil;
|
||||
|
||||
public class MenuProtect extends JavaPlugin {
|
||||
FileConfig config;
|
105
src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java
Normal file
105
src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java
Normal file
@ -0,0 +1,105 @@
|
||||
package pw.yumc.MenuProtect.listen;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
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.event.inventory.InventoryPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import pw.yumc.MenuProtect.MenuProtect;
|
||||
import pw.yumc.MenuProtect.utils.MarkUtil;
|
||||
|
||||
public class ProtectListener implements Listener {
|
||||
|
||||
private final MenuProtect plugin;
|
||||
|
||||
public ProtectListener(final MenuProtect plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInvClose(final InventoryCloseEvent e) {
|
||||
if (e.getPlayer() instanceof Player) {
|
||||
handlerPlayerInventory((Player) e.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInvMove(final InventoryMoveItemEvent e) {
|
||||
final ItemStack ci = e.getItem();
|
||||
if (MarkUtil.hasMark(ci)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onInvPickup(final InventoryPickupItemEvent e) {
|
||||
final ItemStack ci = e.getItem().getItemStack();
|
||||
if (MarkUtil.hasMark(ci)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onItemClick(final InventoryClickEvent e) {
|
||||
final Player p = (Player) e.getWhoClicked();
|
||||
final ItemStack ci = e.getCurrentItem();
|
||||
final Inventory inv = e.getInventory();
|
||||
if (inv.getHolder() == null) {
|
||||
return;
|
||||
}
|
||||
final int solt = e.getSlot();
|
||||
try {
|
||||
if (MarkUtil.hasMark(ci)) {
|
||||
inv.setItem(solt, new ItemStack(Material.AIR));
|
||||
p.closeInventory();
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerHandlerItem(final PlayerItemHeldEvent e) {
|
||||
final PlayerInventory inv = e.getPlayer().getInventory();
|
||||
final int newslot = e.getNewSlot();
|
||||
final ItemStack newItem = inv.getItem(newslot);
|
||||
if (MarkUtil.hasMark(newItem)) {
|
||||
inv.setItem(newslot, new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerPickup(final PlayerPickupItemEvent e) {
|
||||
final ItemStack ci = e.getItem().getItemStack();
|
||||
if (MarkUtil.hasMark(ci)) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void handlerPlayerInventory(final Player p) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final PlayerInventory inv = p.getInventory();
|
||||
final ItemStack[] cis = inv.getArmorContents();
|
||||
for (int i = 0; i < cis.length; i++) {
|
||||
final ItemStack itemStack = cis[i];
|
||||
if (MarkUtil.hasMark(itemStack)) {
|
||||
cis[i] = new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
inv.setArmorContents(cis);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cn.citycraft.MenuProtect.utils;
|
||||
package pw.yumc.MenuProtect.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,9 +1,9 @@
|
||||
name: ${project.artifactId}
|
||||
description: ${project.description}
|
||||
main: ${project.groupId}.${project.artifactId}.${project.artifactId}
|
||||
version: ${project.version}-Build#${env.BUILD_NUMBER}
|
||||
version: ${project.version}-git-${env.GIT_COMMIT}
|
||||
author: 喵♂呜
|
||||
website: ${jenkins.url}/job/${project.artifactId}/
|
||||
website: ${ciManagement.url}
|
||||
commands:
|
||||
${project.artifactId}:
|
||||
description: ${project.artifactId} - ${project.description}
|
||||
|
Loading…
Reference in New Issue
Block a user