1
0
mirror of https://e.coding.net/circlecloud/Residence.git synced 2024-10-31 22:38:48 +00:00

fix: 修复GUI刷物品问题 添加GUI开关

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2017-01-16 17:23:09 +08:00
parent e4ef12f7b7
commit 4a33913a9c
6 changed files with 176 additions and 218 deletions

236
pom.xml
View File

@ -1,120 +1,120 @@
<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>Residence</artifactId>
<version>2.8.3.5</version>
<name>Residence</name>
<description>重制版本的领地插件 - 喵♂呜</description>
<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>&amp;6GUI菜单上线(&amp;c测试版本&amp;6)...</update.description>
<update.changes>
&amp;b2.8.3.5 - &amp;c修复世界限制失效问题...;
&amp;b2.8.3.4 - &amp;c圈地世界限制忽略OP和管理...;
&amp;b2.8.3.3 - &amp;c添加圈地世界限制(详见dany.yml)...;
</update.changes>
<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>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>com.earth2me</groupId>
<artifactId>essentials</artifactId>
<version>2.9.6</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/Essentials.jar</systemPath>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>Vault</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>WorldEdit</artifactId>
<version>5.4.5</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/WorldEdit.jar</systemPath>
</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>Residence</artifactId>
<version>2.8.3.6</version>
<name>Residence</name>
<description>重制版本的领地插件 - 喵♂呜</description>
<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>§6GUI菜单完善...</update.description>
<update.changes>
§b2.8.3.6 - §c修复GUI刷物品的问题...;
§b2.8.3.5 - §c修复世界限制失效问题...;
§b2.8.3.4 - §c圈地世界限制忽略OP和管理...;
</update.changes>
<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>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.11.2-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.earth2me</groupId>
<artifactId>essentials</artifactId>
<version>2.9.6</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/Essentials.jar</systemPath>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>Vault</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>WorldEdit</artifactId>
<version>5.4.5</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/WorldEdit.jar</systemPath>
</dependency>
<dependency>
<groupId>cn.citycraft</groupId>
<artifactId>PluginHelper</artifactId>
<type>jar</type>
<version>1.0</version>
</dependency>
</dependencies>
</project>

View File

@ -13,7 +13,6 @@ import com.bekvon.bukkit.residence.protection.ClaimedResidence;
import cn.citycraft.PluginHelper.config.FileConfig;
import pw.yumc.Residence.ResidenceMain;
import pw.yumc.Residence.listeners.ResidenceGUIListener;
public class FlagUtil {
public static FileConfig conf;
@ -27,6 +26,9 @@ public class FlagUtil {
}
public static void open(final ClaimedResidence area, final Player player, final String target, final boolean resadmin) {
if (!conf.getBoolean("Enable")) {
return; }
final SetFlag flag = new SetFlag(area, player, resadmin);
if (StringUtils.isEmpty(target)) {
flag.recalculateResidence(area);
@ -34,7 +36,6 @@ public class FlagUtil {
flag.setTargePlayer(target);
flag.recalculatePlayer(area);
}
ResidenceGUIListener.GUI.put(player.getName(), flag);
player.openInventory(flag.getInventory());
player.sendMessage("§a已打开领地 " + area.getName() + " 的管理界面!");
}

View File

@ -0,0 +1,21 @@
package pw.yumc.Residence.gui;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
public class GuiHolder implements InventoryHolder {
SetFlag flag;
public GuiHolder(SetFlag flag) {
this.flag = flag;
}
public SetFlag getFlag() {
return flag;
}
@Override
public Inventory getInventory() {
return null;
}
}

View File

@ -52,7 +52,7 @@ public class SetFlag {
if (FlagUtil.description.containsKey(one.getKey())) {
lore.addAll(FlagUtil.description.get(one.getKey()));
}
switch (one.getValue().intValue()) {
switch (one.getValue()) {
case 0:
lore.add(ChatColor.GOLD + "权限状态: " + ChatColor.RED + "关闭");
break;
@ -79,7 +79,7 @@ public class SetFlag {
}
public ItemStack getStatuItem(final Entry<String, Integer> one) {
switch (one.getValue().intValue()) {
switch (one.getValue()) {
case 0:
return Residence.getFlagUtilManager().getGuiFalse();
case 1:
@ -114,7 +114,7 @@ public class SetFlag {
resFlags.put(one.getKey(), one.getValue());
}
}
Map<String, Boolean> pFlags = null;
Map<String, Boolean> pFlags;
if (this.targetPlayer != null) {
final ArrayList<String> PosibleResPFlags = res.getPermissions().getposibleFlags();
final Map<String, Boolean> temp = new HashMap<>();
@ -131,22 +131,30 @@ public class SetFlag {
}
}
}
String title = String.format(FlagUtil.getConfig().getMessage("GUI.Pset.Title"), this.targetPlayer, res.getName());
recalculate(title, globalFlags, resFlags, res.getPermissions().getFlags(), flags);
}
public void recalculate(String title, Map<String, Boolean> globalFlags, Map<String, Boolean> resFlags, Map<String, Boolean> resPerm, List<String> flags) {
final LinkedHashMap<String, Integer> TempPermMap = new LinkedHashMap<>();
for (final Entry<String, Boolean> one : resPerm.entrySet()) {
if (flags.contains(one.getKey())) {
resFlags.put(one.getKey(), one.getValue());
}
}
for (final Entry<String, Boolean> one : globalFlags.entrySet()) {
if (flags.contains(one.getKey())) {
if (resFlags.containsKey(one.getKey())) {
TempPermMap.put(one.getKey(), resFlags.get(one.getKey()) ? 1 : 0);
} else {
TempPermMap.put(one.getKey(), Integer.valueOf(2));
TempPermMap.put(one.getKey(), 2);
}
}
}
String title = "";
title = String.format(FlagUtil.getConfig().getMessage("GUI.Pset.Title"), this.targetPlayer, res.getName());
if (title.length() > 32) {
title = title.substring(0, Math.min(title.length(), 32));
}
final Inventory GuiInv = Bukkit.createInventory(null, 54, title);
final Inventory GuiInv = Bukkit.createInventory(new GuiHolder(this), 54, title);
final FlagData flagData = Residence.getFlagUtilManager().getFlagData();
this.pageCount = ((int) Math.ceil(TempPermMap.size() / 45.0D));
final int start = this.page * 45 - 45;
@ -168,7 +176,7 @@ public class SetFlag {
if (flagData.contains(one.getKey())) {
MiscInfo = flagData.getItem(one.getKey());
}
if (one.getValue().intValue() == 1) {
if (one.getValue() == 1) {
final ItemMeta im = MiscInfo.getItemMeta();
im.addEnchant(Enchantment.LUCK, 1, true);
MiscInfo.setItemMeta(im);
@ -193,65 +201,8 @@ public class SetFlag {
final Map<String, Boolean> globalFlags = Residence.getPermissionManager().getAllFlags().getFlags();
final Map<String, Boolean> resFlags = new HashMap<>();
final LinkedHashMap<String, Integer> TempPermMap = new LinkedHashMap<>();
for (final Entry<String, Boolean> one : res.getPermissions().getFlags().entrySet()) {
if (flags.contains(one.getKey())) {
resFlags.put(one.getKey(), one.getValue());
}
}
for (final Entry<String, Boolean> one : globalFlags.entrySet()) {
if (flags.contains(one.getKey())) {
if (resFlags.containsKey(one.getKey())) {
TempPermMap.put(one.getKey(), resFlags.get(one.getKey()) ? 1 : 0);
} else {
TempPermMap.put(one.getKey(), 2);
}
}
}
String title = "";
title = String.format(FlagUtil.getConfig().getMessage("GUI.Set.Title"), res.getName());
if (title.length() > 32) {
title = title.substring(0, Math.min(title.length(), 32));
}
final Inventory GuiInv = Bukkit.createInventory(null, 54, title);
final FlagData flagData = Residence.getFlagUtilManager().getFlagData();
this.pageCount = ((int) Math.ceil(TempPermMap.size() / 45.0D));
final int start = this.page * 45 - 45;
final int end = this.page * 45;
int count = -1;
this.permMap.clear();
for (final Entry<String, Integer> one : TempPermMap.entrySet()) {
count++;
if (count >= end) {
break;
}
if (count >= start) {
this.permMap.put(one.getKey(), one.getValue());
}
}
int i = 0;
for (final Entry<String, Integer> one : this.permMap.entrySet()) {
ItemStack MiscInfo = getStatuItem(one);
if (flagData.contains(one.getKey())) {
MiscInfo = flagData.getItem(one.getKey());
}
if (one.getValue().intValue() == 1) {
final ItemMeta im = MiscInfo.getItemMeta();
im.addEnchant(Enchantment.LUCK, 1, true);
MiscInfo.setItemMeta(im);
} else {
MiscInfo.removeEnchantment(Enchantment.LUCK);
}
final ItemMeta MiscInfoMeta = MiscInfo.getItemMeta();
MiscInfoMeta.setDisplayName(ChatColor.GREEN + one.getKey());
MiscInfoMeta.setLore(getFlagLore(one));
MiscInfo.setItemMeta(MiscInfoMeta);
GuiInv.setItem(i, MiscInfo);
i++;
if (i > 53) {
break;
}
}
setPageItem(GuiInv);
String title = String.format(FlagUtil.getConfig().getMessage("GUI.Set.Title"), res.getName());
recalculate(title, globalFlags, resFlags, res.getPermissions().getFlags(), flags);
}
public void setAdmin(final boolean state) {
@ -278,9 +229,7 @@ public class SetFlag {
final ClickType click = event.getClick();
final InventoryAction action = event.getAction();
final ItemStack item = this.inventory.getItem(slot);
if (item == null) {
return;
}
if (item == null) { return; }
if (slot == 53) {
if (this.page < this.pageCount) {
this.page += 1;
@ -302,13 +251,10 @@ public class SetFlag {
command = "false";
} else if ((click.isLeftClick()) && (action == InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
command = "remove";
} else if ((click.isRightClick()) && (action == InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
return;
}
String flag = "";
} else if ((click.isRightClick()) && (action == InventoryAction.MOVE_TO_OTHER_INVENTORY)) { return; }
int i = 0;
for (final Entry<String, Integer> one : this.permMap.entrySet()) {
flag = one.getKey();
String flag = one.getKey();
if (i == slot) {
if (this.targetPlayer == null) {
if (this.admin) {

View File

@ -1,39 +1,25 @@
package pw.yumc.Residence.listeners;
import java.util.HashMap;
import java.util.Map;
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.inventory.InventoryHolder;
import pw.yumc.Residence.gui.GuiHolder;
import pw.yumc.Residence.gui.SetFlag;
public class ResidenceGUIListener implements Listener {
public static Map<String, SetFlag> GUI = new HashMap<>();
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onFlagGuiClick(final InventoryClickEvent event) {
final String player = event.getWhoClicked().getName();
if (GUI.size() == 0 || !GUI.containsKey(player)) {
return;
}
event.setCancelled(true);
final int slot = event.getRawSlot();
if ((slot > 53) || (slot < 0)) {
return;
}
final SetFlag setFlag = GUI.get(player);
setFlag.toggleFlag(event);
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onFlagGuiClose(final InventoryCloseEvent event) {
final String player = event.getPlayer().getName();
if (GUI.size() != 0 & GUI.containsKey(player)) {
GUI.remove(player);
InventoryHolder guiHolder = event.getInventory().getHolder();
if (guiHolder instanceof GuiHolder) {
event.setCancelled(true);
final int slot = event.getRawSlot();
if ((slot > 53) || (slot < 0)) { return; }
final SetFlag setFlag = ((GuiHolder) guiHolder).getFlag();
setFlag.toggleFlag(event);
}
}
}

View File

@ -1,3 +1,7 @@
Version: 1.0
#是否开启领地GUI
Enable: true
# 图形化界面的按钮显示
GUI:
setTrue: