1
0
mirror of https://e.coding.net/circlecloud/MenuProtect.git synced 2025-10-01 12:37:25 +00:00

feat: 添加名称检测

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
2016-12-21 16:56:26 +08:00
parent 74e30a5295
commit 123ddb1bd5
4 changed files with 105 additions and 110 deletions

181
pom.xml
View File

@ -1,96 +1,89 @@
<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>pw.yumc</groupId>
<artifactId>MenuProtect</artifactId>
<version>1.3.1</version>
<name>MenuProtect</name>
<build>
<finalName>${project.name}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>cn.citycraft:PluginHelper</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>cn.citycraft.PluginHelper</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<ciManagement>
<system>Jenkins</system>
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
</ciManagement>
<properties>
<update.description>1.3.1添加扫地大妈检测</update.description>
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<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.9-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.github.Cnly.WowSuchCleaner</groupId>
<artifactId>WowSuchCleaner</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>cn.citycraft</groupId>
<artifactId>PluginHelper</artifactId>
<type>jar</type>
<version>1.0</version>
</dependency>
</dependencies>
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>pw.yumc</groupId>
<artifactId>MenuProtect</artifactId>
<version>1.4</version>
<name>MenuProtect</name>
<build>
<finalName>${project.name}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>pw.yumc:YumCore</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>pw.yumc:YumCore</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<ciManagement>
<system>Jenkins</system>
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
</ciManagement>
<properties>
<update.description>1.3.1添加扫地大妈检测</update.description>
<env.GIT_COMMIT>DEV</env.GIT_COMMIT>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<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>io.github.Cnly.WowSuchCleaner</groupId>
<artifactId>WowSuchCleaner</artifactId>
<version>1.6.5</version>
</dependency>
<dependency>
<groupId>pw.yumc</groupId>
<artifactId>YumCore</artifactId>
<version>1.5</version>
</dependency>
</dependencies>
</project>

View File

@ -8,10 +8,10 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.PluginHelper.config.FileConfig;
import pw.yumc.MenuProtect.listen.ProtectListener;
import pw.yumc.MenuProtect.listen.WowSuchCleanerListener;
import pw.yumc.MenuProtect.utils.MarkUtil;
import pw.yumc.YumCore.config.FileConfig;
public class MenuProtect extends JavaPlugin {
FileConfig config;
@ -19,6 +19,10 @@ public class MenuProtect extends JavaPlugin {
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (args.length == 1) {
if ("reload".equalsIgnoreCase(args[0])) {
onLoad();
sender.sendMessage("§a配置文件已重载!");
}
final Player player = Bukkit.getPlayerExact(args[0]);
if (player != null) {
player.closeInventory();
@ -33,12 +37,11 @@ public class MenuProtect extends JavaPlugin {
final PluginManager pm = this.getServer().getPluginManager();
final Plugin wsc = pm.getPlugin("WowSuchCleaner");
if (wsc != null && wsc.isEnabled()) {
getLogger().info("发现 WowSuchCleaner 插件 开启相关功能...");
try {
Class.forName("io.github.Cnly.WowSuchCleaner.WowSuchCleaner.ItemPreCleanEvent");
pm.registerEvents(new WowSuchCleanerListener(), this);
} catch (final ClassNotFoundException e) {
getLogger().info("WowSuchCleaner 版本过低 可能造成悬浮物上架...");
getLogger().info("发现 WowSuchCleaner 插件 开启相关功能...");
} catch (final ClassNotFoundException ignored) {
}
}
this.getLogger().info("菜单物品保护已开启!");
@ -46,7 +49,7 @@ public class MenuProtect extends JavaPlugin {
@Override
public void onLoad() {
config = new FileConfig(this);
config = new FileConfig();
MarkUtil.marks = config.getStringList("MarkList");
MarkUtil.initCommand(config.getConfigurationSection("LoreCommand"));
}

View File

@ -11,8 +11,8 @@ import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import cn.citycraft.PluginHelper.kit.PluginKit;
import pw.yumc.MenuProtect.utils.MarkUtil;
import pw.yumc.YumCore.kit.PKit;
public class ProtectListener implements Listener {
@ -49,7 +49,7 @@ public class ProtectListener implements Listener {
}
private void handlerPlayerClick(final Player p, final ItemStack is) {
PluginKit.runTaskAsync(new Runnable() {
PKit.runTaskAsync(new Runnable() {
@Override
public void run() {
MarkUtil.handlerItemClick(p, is);
@ -58,7 +58,7 @@ public class ProtectListener implements Listener {
}
private void handlerPlayerInventory(final Player p) {
PluginKit.runTaskAsync(new Runnable() {
PKit.runTaskAsync(new Runnable() {
@Override
public void run() {
final PlayerInventory inv = p.getInventory();

View File

@ -10,7 +10,8 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import cn.citycraft.PluginHelper.kit.PluginKit;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.kit.PKit;
public class MarkUtil {
public static List<String> marks = null;
@ -19,9 +20,9 @@ public class MarkUtil {
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)) {
if (cmds.containsKey(lore) || (is.getItemMeta().hasDisplayName() && cmds.containsKey(is.getItemMeta().getDisplayName()))) {
for (final String cmd : cmds.get(lore)) {
PluginKit.runTask(new Runnable() {
PKit.runTask(new Runnable() {
@Override
public void run() {
CommandSender sender = Bukkit.getConsoleSender();
@ -41,11 +42,9 @@ public class MarkUtil {
public static boolean hasMark(final ItemStack ci) {
try {
for (final String mark : marks) {
if (ci.getItemMeta().getDisplayName().startsWith(mark)) {
return true;
}
if (ci.getItemMeta().getDisplayName().startsWith(mark)) { return true; }
}
} catch (final Exception e) {
} catch (final Exception ignored) {
}
return false;
}
@ -55,6 +54,6 @@ public class MarkUtil {
for (final String lore : cfg.getKeys(false)) {
cmds.put(lore, cfg.getStringList(lore));
}
PluginKit.getLogger().info("初始化LoreCommand完毕 总计: " + cmds.size() + "条...");
Log.info("初始化LoreCommand完毕 总计: " + cmds.size() + "条...");
}
}