mirror of
https://e.coding.net/circlecloud/Residence.git
synced 2025-11-26 22:06:07 +00:00
feat: 新增GUI界面管理(测试中)
This commit is contained in:
@@ -19,6 +19,7 @@ import pw.yumc.Residence.chat.ChatManager;
|
|||||||
import pw.yumc.Residence.economy.EconomyInterface;
|
import pw.yumc.Residence.economy.EconomyInterface;
|
||||||
import pw.yumc.Residence.economy.TransactionManager;
|
import pw.yumc.Residence.economy.TransactionManager;
|
||||||
import pw.yumc.Residence.economy.rent.RentManager;
|
import pw.yumc.Residence.economy.rent.RentManager;
|
||||||
|
import pw.yumc.Residence.gui.FlagUtil;
|
||||||
import pw.yumc.Residence.itemlist.WorldItemManager;
|
import pw.yumc.Residence.itemlist.WorldItemManager;
|
||||||
import pw.yumc.Residence.manager.ConfigManager;
|
import pw.yumc.Residence.manager.ConfigManager;
|
||||||
import pw.yumc.Residence.manager.EntityManager;
|
import pw.yumc.Residence.manager.EntityManager;
|
||||||
@@ -29,10 +30,6 @@ import pw.yumc.Residence.text.help.HelpEntry;
|
|||||||
public class Residence {
|
public class Residence {
|
||||||
static ResidenceMain instance;
|
static ResidenceMain instance;
|
||||||
|
|
||||||
public Residence(final ResidenceMain instance) {
|
|
||||||
Residence.instance = instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ChatManager getChatManager() {
|
public static ChatManager getChatManager() {
|
||||||
return instance.getChatManager();
|
return instance.getChatManager();
|
||||||
}
|
}
|
||||||
@@ -57,6 +54,10 @@ public class Residence {
|
|||||||
return instance.getEntityManager();
|
return instance.getEntityManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static FlagUtil getFlagUtilManager() {
|
||||||
|
return instance.getFlagUtilManager();
|
||||||
|
}
|
||||||
|
|
||||||
public static HelpEntry getHelppages() {
|
public static HelpEntry getHelppages() {
|
||||||
return instance.getHelppages();
|
return instance.getHelppages();
|
||||||
}
|
}
|
||||||
@@ -140,4 +141,8 @@ public class Residence {
|
|||||||
public static boolean isUseWorldEdit() {
|
public static boolean isUseWorldEdit() {
|
||||||
return instance.isUseWorldEdit();
|
return instance.isUseWorldEdit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Residence(final ResidenceMain instance) {
|
||||||
|
Residence.instance = instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,156 +1,160 @@
|
|||||||
/*
|
/*
|
||||||
* To change this template, choose Tools | Templates and open the template in the editor.
|
* To change this template, choose Tools | Templates and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.bekvon.bukkit.residence.permissions;
|
package com.bekvon.bukkit.residence.permissions;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.bekvon.bukkit.residence.protection.FlagPermissions;
|
import com.bekvon.bukkit.residence.protection.FlagPermissions;
|
||||||
|
|
||||||
import pw.yumc.Residence.ResidenceMain;
|
import pw.yumc.Residence.ResidenceMain;
|
||||||
import pw.yumc.Residence.vaultinterface.ResidenceVaultAdapter;
|
import pw.yumc.Residence.vaultinterface.ResidenceVaultAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
*/
|
*/
|
||||||
public class PermissionManager {
|
public class PermissionManager {
|
||||||
protected static PermissionsInterface perms;
|
protected static PermissionsInterface perms;
|
||||||
protected FlagPermissions globalFlagPerms;
|
protected FlagPermissions globalFlagPerms;
|
||||||
protected Map<String, PermissionGroup> groups;
|
protected Map<String, PermissionGroup> groups;
|
||||||
protected Map<String, String> playersGroup;
|
protected Map<String, String> playersGroup;
|
||||||
ResidenceMain plugin;
|
ResidenceMain plugin;
|
||||||
|
|
||||||
public PermissionManager(final ResidenceMain plugin) {
|
public PermissionManager(final ResidenceMain plugin) {
|
||||||
try {
|
try {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
groups = Collections.synchronizedMap(new HashMap<String, PermissionGroup>());
|
groups = Collections.synchronizedMap(new HashMap<String, PermissionGroup>());
|
||||||
playersGroup = Collections.synchronizedMap(new HashMap<String, String>());
|
playersGroup = Collections.synchronizedMap(new HashMap<String, String>());
|
||||||
globalFlagPerms = new FlagPermissions();
|
globalFlagPerms = new FlagPermissions();
|
||||||
this.readConfig(plugin.getConfig());
|
this.readConfig(plugin.getConfig());
|
||||||
final boolean enable = plugin.getConfig().getBoolean("Global.EnablePermissions", true);
|
final boolean enable = plugin.getConfig().getBoolean("Global.EnablePermissions", true);
|
||||||
if (enable) {
|
if (enable) {
|
||||||
this.checkPermissions();
|
this.checkPermissions();
|
||||||
}
|
}
|
||||||
} catch (final Exception ex) {
|
} catch (final Exception ex) {
|
||||||
plugin.getLogger().log(Level.SEVERE, "权限管理载入失败,请报告以下错误给作者,谢谢!", ex);
|
plugin.getLogger().log(Level.SEVERE, "权限管理载入失败,请报告以下错误给作者,谢谢!", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PermissionGroup getGroup(final Player player) {
|
public FlagPermissions getAllFlags() {
|
||||||
return groups.get(this.getGroupNameByPlayer(player));
|
return globalFlagPerms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PermissionGroup getGroup(final String player, final String world) {
|
public PermissionGroup getGroup(final Player player) {
|
||||||
return groups.get(this.getGroupNameByPlayer(player, world));
|
return groups.get(this.getGroupNameByPlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
public PermissionGroup getGroupByName(String group) {
|
public PermissionGroup getGroup(final String player, final String world) {
|
||||||
group = group.toLowerCase();
|
return groups.get(this.getGroupNameByPlayer(player, world));
|
||||||
if (!groups.containsKey(group)) {
|
}
|
||||||
return groups.get(plugin.getConfigManager().getDefaultGroup());
|
|
||||||
}
|
public PermissionGroup getGroupByName(String group) {
|
||||||
return groups.get(group);
|
group = group.toLowerCase();
|
||||||
}
|
if (!groups.containsKey(group)) {
|
||||||
|
return groups.get(plugin.getConfigManager().getDefaultGroup());
|
||||||
public String getGroupNameByPlayer(final Player player) {
|
}
|
||||||
return this.getGroupNameByPlayer(player.getName(), player.getWorld().getName());
|
return groups.get(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGroupNameByPlayer(String player, final String world) {
|
public String getGroupNameByPlayer(final Player player) {
|
||||||
player = player.toLowerCase();
|
return this.getGroupNameByPlayer(player.getName(), player.getWorld().getName());
|
||||||
if (playersGroup.containsKey(player)) {
|
}
|
||||||
String group = playersGroup.get(player);
|
|
||||||
if (group != null) {
|
public String getGroupNameByPlayer(String player, final String world) {
|
||||||
group = group.toLowerCase();
|
player = player.toLowerCase();
|
||||||
if (group != null && groups.containsKey(group)) {
|
if (playersGroup.containsKey(player)) {
|
||||||
return group;
|
String group = playersGroup.get(player);
|
||||||
}
|
if (group != null) {
|
||||||
}
|
group = group.toLowerCase();
|
||||||
}
|
if (group != null && groups.containsKey(group)) {
|
||||||
final String group = this.getPermissionsGroup(player, world);
|
return group;
|
||||||
if (group == null || !groups.containsKey(group)) {
|
}
|
||||||
return plugin.getConfigManager().getDefaultGroup().toLowerCase();
|
}
|
||||||
}
|
}
|
||||||
return group;
|
final String group = this.getPermissionsGroup(player, world);
|
||||||
}
|
if (group == null || !groups.containsKey(group)) {
|
||||||
|
return plugin.getConfigManager().getDefaultGroup().toLowerCase();
|
||||||
public String getPermissionsGroup(final Player player) {
|
}
|
||||||
return this.getPermissionsGroup(player.getName(), player.getWorld().getName());
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPermissionsGroup(final String player, final String world) {
|
public String getPermissionsGroup(final Player player) {
|
||||||
if (perms == null) {
|
return this.getPermissionsGroup(player.getName(), player.getWorld().getName());
|
||||||
return plugin.getConfigManager().getDefaultGroup();
|
}
|
||||||
}
|
|
||||||
return perms.getPlayerGroup(player, world);
|
public String getPermissionsGroup(final String player, final String world) {
|
||||||
}
|
if (perms == null) {
|
||||||
|
return plugin.getConfigManager().getDefaultGroup();
|
||||||
public PermissionsInterface getPermissionsPlugin() {
|
}
|
||||||
return perms;
|
return perms.getPlayerGroup(player, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasGroup(String group) {
|
public PermissionsInterface getPermissionsPlugin() {
|
||||||
group = group.toLowerCase();
|
return perms;
|
||||||
return groups.containsKey(group);
|
}
|
||||||
}
|
|
||||||
|
public boolean hasGroup(String group) {
|
||||||
public boolean isResidenceAdmin(final Player player) {
|
group = group.toLowerCase();
|
||||||
return (player.hasPermission("residence.admin") || (player.isOp() && plugin.getConfigManager().getOpsAreAdmins()));
|
return groups.containsKey(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkPermissions() {
|
public boolean isResidenceAdmin(final Player player) {
|
||||||
final Server server = plugin.getServer();
|
return (player.hasPermission("residence.admin") || (player.isOp() && plugin.getConfigManager().getOpsAreAdmins()));
|
||||||
final Plugin p = server.getPluginManager().getPlugin("Vault");
|
}
|
||||||
if (p != null) {
|
|
||||||
final ResidenceVaultAdapter vault = new ResidenceVaultAdapter(server);
|
private void checkPermissions() {
|
||||||
if (vault.permissionsOK()) {
|
final Server server = plugin.getServer();
|
||||||
perms = vault;
|
final Plugin p = server.getPluginManager().getPlugin("Vault");
|
||||||
plugin.getLogger().info("发现 Vault 使用权限系统: " + vault.getPermissionsName());
|
if (p != null) {
|
||||||
return;
|
final ResidenceVaultAdapter vault = new ResidenceVaultAdapter(server);
|
||||||
}
|
if (vault.permissionsOK()) {
|
||||||
plugin.getLogger().info("发现 Vault, 但是 Vault 未找到权限系统...");
|
perms = vault;
|
||||||
}
|
plugin.getLogger().info("发现 Vault 使用权限系统: " + vault.getPermissionsName());
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
private void readConfig(final FileConfiguration config) {
|
plugin.getLogger().info("发现 Vault, 但是 Vault 未找到权限系统...");
|
||||||
final String defaultGroup = plugin.getConfigManager().getDefaultGroup();
|
}
|
||||||
globalFlagPerms = FlagPermissions.parseFromConfigNode("FlagPermission", config.getConfigurationSection("Global"));
|
}
|
||||||
final ConfigurationSection nodes = config.getConfigurationSection("Groups");
|
|
||||||
if (nodes != null) {
|
private void readConfig(final FileConfiguration config) {
|
||||||
final Set<String> entrys = nodes.getKeys(false);
|
final String defaultGroup = plugin.getConfigManager().getDefaultGroup();
|
||||||
for (final String key : entrys) {
|
globalFlagPerms = FlagPermissions.parseFromConfigNode("FlagPermission", config.getConfigurationSection("Global"));
|
||||||
try {
|
final ConfigurationSection nodes = config.getConfigurationSection("Groups");
|
||||||
groups.put(key.toLowerCase(), new PermissionGroup(key.toLowerCase(), nodes.getConfigurationSection(key), globalFlagPerms));
|
if (nodes != null) {
|
||||||
final List<String> mirrors = nodes.getConfigurationSection(key).getStringList("Mirror");
|
final Set<String> entrys = nodes.getKeys(false);
|
||||||
for (final String group : mirrors) {
|
for (final String key : entrys) {
|
||||||
groups.put(group.toLowerCase(), new PermissionGroup(key.toLowerCase(), nodes.getConfigurationSection(key), globalFlagPerms));
|
try {
|
||||||
}
|
groups.put(key.toLowerCase(), new PermissionGroup(key.toLowerCase(), nodes.getConfigurationSection(key), globalFlagPerms));
|
||||||
} catch (final Exception ex) {
|
final List<String> mirrors = nodes.getConfigurationSection(key).getStringList("Mirror");
|
||||||
plugin.getLogger().info("错误 从配置文件读取:" + key + " 抛出异常:" + ex);
|
for (final String group : mirrors) {
|
||||||
}
|
groups.put(group.toLowerCase(), new PermissionGroup(key.toLowerCase(), nodes.getConfigurationSection(key), globalFlagPerms));
|
||||||
}
|
}
|
||||||
}
|
} catch (final Exception ex) {
|
||||||
if (!groups.containsKey(defaultGroup)) {
|
plugin.getLogger().info("错误 从配置文件读取:" + key + " 抛出异常:" + ex);
|
||||||
groups.put(defaultGroup, new PermissionGroup(defaultGroup));
|
}
|
||||||
}
|
}
|
||||||
final Set<String> keys = config.getConfigurationSection("GroupAssignments").getKeys(false);
|
}
|
||||||
if (keys != null) {
|
if (!groups.containsKey(defaultGroup)) {
|
||||||
for (final String key : keys) {
|
groups.put(defaultGroup, new PermissionGroup(defaultGroup));
|
||||||
playersGroup.put(key.toLowerCase(), config.getString("GroupAssignments." + key, defaultGroup).toLowerCase());
|
}
|
||||||
}
|
final Set<String> keys = config.getConfigurationSection("GroupAssignments").getKeys(false);
|
||||||
}
|
if (keys != null) {
|
||||||
}
|
for (final String key : keys) {
|
||||||
}
|
playersGroup.put(key.toLowerCase(), config.getString("GroupAssignments." + key, defaultGroup).toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -57,6 +57,7 @@ import pw.yumc.Residence.economy.EconomyInterface;
|
|||||||
import pw.yumc.Residence.economy.EssentialsEcoAdapter;
|
import pw.yumc.Residence.economy.EssentialsEcoAdapter;
|
||||||
import pw.yumc.Residence.economy.TransactionManager;
|
import pw.yumc.Residence.economy.TransactionManager;
|
||||||
import pw.yumc.Residence.economy.rent.RentManager;
|
import pw.yumc.Residence.economy.rent.RentManager;
|
||||||
|
import pw.yumc.Residence.gui.FlagUtil;
|
||||||
import pw.yumc.Residence.itemlist.WorldItemManager;
|
import pw.yumc.Residence.itemlist.WorldItemManager;
|
||||||
import pw.yumc.Residence.listeners.ResidenceBlockListener;
|
import pw.yumc.Residence.listeners.ResidenceBlockListener;
|
||||||
import pw.yumc.Residence.listeners.ResidenceEntityListener;
|
import pw.yumc.Residence.listeners.ResidenceEntityListener;
|
||||||
@@ -121,6 +122,7 @@ public class ResidenceMain extends JavaPlugin {
|
|||||||
protected TransactionManager tmanager;
|
protected TransactionManager tmanager;
|
||||||
protected boolean useWorldEdit;
|
protected boolean useWorldEdit;
|
||||||
protected WorldFlagManager wmanager;
|
protected WorldFlagManager wmanager;
|
||||||
|
protected FlagUtil fmanager;
|
||||||
|
|
||||||
public static ResidenceMain getInstance() {
|
public static ResidenceMain getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
@@ -173,6 +175,10 @@ public class ResidenceMain extends JavaPlugin {
|
|||||||
return entitymanager;
|
return entitymanager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FlagUtil getFlagUtilManager() {
|
||||||
|
return fmanager;
|
||||||
|
}
|
||||||
|
|
||||||
public HelpEntry getHelppages() {
|
public HelpEntry getHelppages() {
|
||||||
return helppages;
|
return helppages;
|
||||||
}
|
}
|
||||||
@@ -393,6 +399,9 @@ public class ResidenceMain extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fmanager = new FlagUtil(this);
|
||||||
|
getFlagUtilManager().load();
|
||||||
|
gmanager = new PermissionManager(this);
|
||||||
gmanager = new PermissionManager(this);
|
gmanager = new PermissionManager(this);
|
||||||
imanager = new WorldItemManager(this.getConfig());
|
imanager = new WorldItemManager(this.getConfig());
|
||||||
wmanager = new WorldFlagManager(this);
|
wmanager = new WorldFlagManager(this);
|
||||||
@@ -570,7 +579,7 @@ public class ResidenceMain extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void saveConfig() {
|
public void saveConfig() {
|
||||||
config.save();
|
config.save();
|
||||||
}
|
};
|
||||||
|
|
||||||
public synchronized void saveYml() throws IOException {
|
public synchronized void saveYml() throws IOException {
|
||||||
final File saveFolder = new File(dataFolder, "Save");
|
final File saveFolder = new File(dataFolder, "Save");
|
||||||
@@ -677,7 +686,7 @@ public class ResidenceMain extends JavaPlugin {
|
|||||||
if (cmanager.showIntervalMessages()) {
|
if (cmanager.showIntervalMessages()) {
|
||||||
this.getLogger().info(" - 保存插件数据...");
|
this.getLogger().info(" - 保存插件数据...");
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
public void setLanguage(final Language language) {
|
public void setLanguage(final Language language) {
|
||||||
this.language = language;
|
this.language = language;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.bekvon.bukkit.residence.protection.ResidenceManager;
|
|||||||
|
|
||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
import pw.yumc.Residence.ResidenceMain;
|
import pw.yumc.Residence.ResidenceMain;
|
||||||
|
import pw.yumc.Residence.gui.FlagUtil;
|
||||||
import pw.yumc.Residence.text.Language;
|
import pw.yumc.Residence.text.Language;
|
||||||
|
|
||||||
public class CommandPset extends BaseCommand {
|
public class CommandPset extends BaseCommand {
|
||||||
@@ -30,15 +31,20 @@ public class CommandPset extends BaseCommand {
|
|||||||
final boolean resadmin = (command != null);
|
final boolean resadmin = (command != null);
|
||||||
final ResidenceManager rmanager = plugin.getResidenceManager();
|
final ResidenceManager rmanager = plugin.getResidenceManager();
|
||||||
final Language language = plugin.getLanguage();
|
final Language language = plugin.getLanguage();
|
||||||
|
if (args.length == 1) {
|
||||||
if (args.length == 2 && args[1].equalsIgnoreCase("removeall")) {
|
final ClaimedResidence area = rmanager.getByLoc(player.getLocation());
|
||||||
|
if (area != null) {
|
||||||
|
FlagUtil.open(area, player, args[0], resadmin);
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.RED + language.getPhrase("InvalidResidence"));
|
||||||
|
}
|
||||||
|
} else if (args.length == 2 && args[1].equalsIgnoreCase("removeall")) {
|
||||||
final ClaimedResidence area = rmanager.getByLoc(player.getLocation());
|
final ClaimedResidence area = rmanager.getByLoc(player.getLocation());
|
||||||
if (area != null) {
|
if (area != null) {
|
||||||
area.getPermissions().removeAllPlayerFlags(player, args[1], resadmin);
|
area.getPermissions().removeAllPlayerFlags(player, args[1], resadmin);
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.RED + language.getPhrase("InvalidResidence"));
|
player.sendMessage(ChatColor.RED + language.getPhrase("InvalidResidence"));
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
} else if (args.length == 3 && args[2].equalsIgnoreCase("removeall")) {
|
} else if (args.length == 3 && args[2].equalsIgnoreCase("removeall")) {
|
||||||
final ClaimedResidence area = rmanager.getByName(args[0]);
|
final ClaimedResidence area = rmanager.getByName(args[0]);
|
||||||
if (area != null) {
|
if (area != null) {
|
||||||
@@ -46,7 +52,6 @@ public class CommandPset extends BaseCommand {
|
|||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.RED + language.getPhrase("InvalidResidence"));
|
player.sendMessage(ChatColor.RED + language.getPhrase("InvalidResidence"));
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
} else if (args.length == 3) {
|
} else if (args.length == 3) {
|
||||||
final ClaimedResidence area = rmanager.getByLoc(player.getLocation());
|
final ClaimedResidence area = rmanager.getByLoc(player.getLocation());
|
||||||
if (area != null) {
|
if (area != null) {
|
||||||
@@ -54,7 +59,6 @@ public class CommandPset extends BaseCommand {
|
|||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.RED + language.getPhrase("InvalidResidence"));
|
player.sendMessage(ChatColor.RED + language.getPhrase("InvalidResidence"));
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
} else if (args.length == 4) {
|
} else if (args.length == 4) {
|
||||||
final ClaimedResidence area = rmanager.getByName(args[0]);
|
final ClaimedResidence area = rmanager.getByName(args[0]);
|
||||||
if (area != null) {
|
if (area != null) {
|
||||||
@@ -62,8 +66,6 @@ public class CommandPset extends BaseCommand {
|
|||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.RED + language.getPhrase("InvalidResidence"));
|
player.sendMessage(ChatColor.RED + language.getPhrase("InvalidResidence"));
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.bekvon.bukkit.residence.protection.ResidenceManager;
|
|||||||
|
|
||||||
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
import cn.citycraft.PluginHelper.commands.BaseCommand;
|
||||||
import pw.yumc.Residence.ResidenceMain;
|
import pw.yumc.Residence.ResidenceMain;
|
||||||
|
import pw.yumc.Residence.gui.FlagUtil;
|
||||||
import pw.yumc.Residence.text.Language;
|
import pw.yumc.Residence.text.Language;
|
||||||
|
|
||||||
public class CommandSet extends BaseCommand {
|
public class CommandSet extends BaseCommand {
|
||||||
@@ -30,8 +31,14 @@ public class CommandSet extends BaseCommand {
|
|||||||
final boolean resadmin = (command != null);
|
final boolean resadmin = (command != null);
|
||||||
final ResidenceManager rmanager = plugin.getResidenceManager();
|
final ResidenceManager rmanager = plugin.getResidenceManager();
|
||||||
final Language language = plugin.getLanguage();
|
final Language language = plugin.getLanguage();
|
||||||
|
if (args.length == 0 || args.length == 1) {
|
||||||
if (args.length == 2) {
|
final ClaimedResidence area = args.length == 0 ? rmanager.getByLoc(player.getLocation()) : rmanager.getByName(args[0]);
|
||||||
|
if (area != null) {
|
||||||
|
FlagUtil.open(area, player, null, resadmin);
|
||||||
|
} else {
|
||||||
|
player.sendMessage(ChatColor.RED + language.getPhrase("InvalidResidence"));
|
||||||
|
}
|
||||||
|
} else if (args.length == 2) {
|
||||||
final String res = rmanager.getNameByLoc(player.getLocation());
|
final String res = rmanager.getNameByLoc(player.getLocation());
|
||||||
if (res != null) {
|
if (res != null) {
|
||||||
rmanager.getByName(res).getPermissions().setFlag(player, args[0], args[1], resadmin);
|
rmanager.getByName(res).getPermissions().setFlag(player, args[0], args[1], resadmin);
|
||||||
|
|||||||
25
src/main/java/pw/yumc/Residence/gui/FlagData.java
Normal file
25
src/main/java/pw/yumc/Residence/gui/FlagData.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package pw.yumc.Residence.gui;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class FlagData {
|
||||||
|
private final HashMap<String, ItemStack> items = new HashMap<>();
|
||||||
|
|
||||||
|
public void addFlagButton(final String flag, final ItemStack item) {
|
||||||
|
this.items.put(flag, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(final String flag) {
|
||||||
|
return this.items.containsKey(flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getItem(final String flag) {
|
||||||
|
return this.items.get(flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeFlagButton(final String flag, final ItemStack item) {
|
||||||
|
this.items.remove(flag);
|
||||||
|
}
|
||||||
|
}
|
||||||
89
src/main/java/pw/yumc/Residence/gui/FlagUtil.java
Normal file
89
src/main/java/pw/yumc/Residence/gui/FlagUtil.java
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package pw.yumc.Residence.gui;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
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;
|
||||||
|
final static LinkedHashMap<String, List<String>> description = new LinkedHashMap<>();
|
||||||
|
private final FlagData flagData = new FlagData();
|
||||||
|
private final ResidenceMain plugin;
|
||||||
|
protected ItemStack guitrue, guifalse, guiremove;
|
||||||
|
|
||||||
|
public static FileConfig getConfig() {
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void open(final ClaimedResidence area, final Player player, final String target, final boolean resadmin) {
|
||||||
|
final SetFlag flag = new SetFlag(area, player, resadmin);
|
||||||
|
if (StringUtils.isEmpty(target)) {
|
||||||
|
flag.recalculateResidence(area);
|
||||||
|
} else {
|
||||||
|
flag.setTargePlayer(target);
|
||||||
|
flag.recalculatePlayer(area);
|
||||||
|
}
|
||||||
|
ResidenceGUIListener.GUI.put(player.getName(), flag);
|
||||||
|
player.openInventory(flag.getInventory());
|
||||||
|
player.sendMessage("§a已打开领地 " + area.getName() + " 的管理界面!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public FlagUtil(final ResidenceMain plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
conf = new FileConfig(plugin, "gui.yml");
|
||||||
|
guitrue = new ItemStack(conf.getInt("GUI.setFtue.id", 1), 1, (short) conf.getInt("GUI.setFtue.data", 0));
|
||||||
|
guifalse = new ItemStack(conf.getInt("GUI.setFalse.id", 1), 1, (short) conf.getInt("GUI.setFalse.data", 0));
|
||||||
|
guiremove = new ItemStack(conf.getInt("GUI.setRemove.id", 1), 1, (short) conf.getInt("GUI.setRemove.data", 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public FlagData getFlagData() {
|
||||||
|
return this.flagData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getGuiFalse() {
|
||||||
|
return guifalse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getGuiRemove() {
|
||||||
|
return guiremove;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getGuiTrue() {
|
||||||
|
return guitrue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
final Set<String> allFlags = plugin.getConfig().getConfigurationSection("Global.FlagPermission").getKeys(false);
|
||||||
|
for (final String oneFlag : allFlags) {
|
||||||
|
if (conf.contains("FlagGUI." + oneFlag)) {
|
||||||
|
if (conf.contains("FlagGUI." + oneFlag + ".id")) {
|
||||||
|
if (conf.contains("FlagGUI." + oneFlag + ".data")) {
|
||||||
|
final int id = conf.getInt("FlagGUI." + oneFlag + ".id");
|
||||||
|
final int data = conf.getInt("FlagGUI." + oneFlag + ".data");
|
||||||
|
Material Mat = Material.getMaterial(id);
|
||||||
|
if (Mat == null) {
|
||||||
|
Mat = Material.STONE;
|
||||||
|
}
|
||||||
|
final ItemStack item = new ItemStack(Mat, 1, (short) data);
|
||||||
|
this.flagData.addFlagButton(oneFlag.toLowerCase(), item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (conf.contains("FlagGUI." + oneFlag + ".des")) {
|
||||||
|
description.put(oneFlag, conf.getStringList("FlagGUI." + oneFlag + ".des"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
330
src/main/java/pw/yumc/Residence/gui/SetFlag.java
Normal file
330
src/main/java/pw/yumc/Residence/gui/SetFlag.java
Normal file
@@ -0,0 +1,330 @@
|
|||||||
|
package pw.yumc.Residence.gui;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.bukkit.event.inventory.InventoryAction;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import com.bekvon.bukkit.residence.Residence;
|
||||||
|
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
|
||||||
|
|
||||||
|
public class SetFlag {
|
||||||
|
private final ClaimedResidence residence;
|
||||||
|
private final Player player;
|
||||||
|
private String targetPlayer = null;
|
||||||
|
private Inventory inventory;
|
||||||
|
private final LinkedHashMap<String, Integer> permMap = new LinkedHashMap<>();
|
||||||
|
private boolean admin = false;
|
||||||
|
private int page = 1;
|
||||||
|
private int pageCount = 1;
|
||||||
|
final ItemStack prev, next;
|
||||||
|
|
||||||
|
public SetFlag(final ClaimedResidence residence, final Player player, final boolean admin) {
|
||||||
|
this.residence = residence;
|
||||||
|
this.player = player;
|
||||||
|
this.admin = admin;
|
||||||
|
prev = new ItemStack(Material.ARROW);
|
||||||
|
final ItemMeta pmeta = prev.getItemMeta();
|
||||||
|
pmeta.setDisplayName(FlagUtil.getConfig().getMessage("GUI.PrevInfoPage"));
|
||||||
|
prev.setItemMeta(pmeta);
|
||||||
|
next = new ItemStack(Material.ARROW);
|
||||||
|
final ItemMeta nmeta = next.getItemMeta();
|
||||||
|
nmeta.setDisplayName(FlagUtil.getConfig().getMessage("GUI.NextInfoPage"));
|
||||||
|
next.setItemMeta(nmeta);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getFlagLore(final Entry<String, Integer> one) {
|
||||||
|
final List<String> lore = new ArrayList<>();
|
||||||
|
if (FlagUtil.description.containsKey(one.getKey())) {
|
||||||
|
lore.addAll(FlagUtil.description.get(one.getKey()));
|
||||||
|
}
|
||||||
|
switch (one.getValue().intValue()) {
|
||||||
|
case 0:
|
||||||
|
lore.add(ChatColor.GOLD + "权限状态: " + ChatColor.RED + "关闭");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
lore.add(ChatColor.GOLD + "权限状态: " + ChatColor.GREEN + "开启");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
lore.add(ChatColor.GOLD + "权限状态: " + ChatColor.DARK_RED + "未配置");
|
||||||
|
}
|
||||||
|
lore.addAll(FlagUtil.getConfig().getMessageList("GUI.Actions"));
|
||||||
|
return lore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Inventory getInventory() {
|
||||||
|
return this.inventory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return this.player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClaimedResidence getResidence() {
|
||||||
|
return this.residence;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getStatuItem(final Entry<String, Integer> one) {
|
||||||
|
switch (one.getValue().intValue()) {
|
||||||
|
case 0:
|
||||||
|
return Residence.getFlagUtilManager().getGuiFalse();
|
||||||
|
case 1:
|
||||||
|
return Residence.getFlagUtilManager().getGuiTrue();
|
||||||
|
case 2:
|
||||||
|
default:
|
||||||
|
return Residence.getFlagUtilManager().getGuiRemove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAdmin() {
|
||||||
|
return this.admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recalculateInv(final Player player) {
|
||||||
|
if (this.targetPlayer == null) {
|
||||||
|
recalculateResidence(residence);
|
||||||
|
} else {
|
||||||
|
recalculatePlayer(residence);
|
||||||
|
}
|
||||||
|
if (player.getOpenInventory() != null) {
|
||||||
|
player.getOpenInventory().getTopInventory().setContents(this.inventory.getContents());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recalculatePlayer(final ClaimedResidence res) {
|
||||||
|
Map<String, Boolean> globalFlags = Residence.getPermissionManager().getAllFlags().getFlags();
|
||||||
|
final List<String> flags = res.getPermissions().getPosibleFlags(false, this.admin);
|
||||||
|
final Map<String, Boolean> resFlags = new HashMap<>();
|
||||||
|
for (final Entry<String, Boolean> one : res.getPermissions().getFlags().entrySet()) {
|
||||||
|
if (flags.contains(one.getKey())) {
|
||||||
|
resFlags.put(one.getKey(), one.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map<String, Boolean> pFlags = null;
|
||||||
|
if (this.targetPlayer != null) {
|
||||||
|
final ArrayList<String> PosibleResPFlags = res.getPermissions().getposibleFlags();
|
||||||
|
final Map<String, Boolean> temp = new HashMap<>();
|
||||||
|
for (final String one : PosibleResPFlags) {
|
||||||
|
if (globalFlags.containsKey(one)) {
|
||||||
|
temp.put(one, globalFlags.get(one));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
globalFlags = temp;
|
||||||
|
pFlags = res.getPermissions().getPlayerFlags(this.targetPlayer);
|
||||||
|
if (pFlags != null) {
|
||||||
|
for (final Entry<String, Boolean> one : pFlags.entrySet()) {
|
||||||
|
resFlags.put(one.getKey(), one.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final LinkedHashMap<String, Integer> TempPermMap = new LinkedHashMap<>();
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recalculateResidence(final ClaimedResidence res) {
|
||||||
|
final List<String> flags = res.getPermissions().getPosibleFlags(true, this.admin);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAdmin(final boolean state) {
|
||||||
|
this.admin = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPageItem(final Inventory GuiInv) {
|
||||||
|
if (this.page > 1) {
|
||||||
|
GuiInv.setItem(45, prev);
|
||||||
|
}
|
||||||
|
if (this.page < this.pageCount) {
|
||||||
|
GuiInv.setItem(53, next);
|
||||||
|
}
|
||||||
|
this.inventory = GuiInv;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTargePlayer(final String player) {
|
||||||
|
this.targetPlayer = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleFlag(final InventoryClickEvent event) {
|
||||||
|
final Player p = (Player) event.getWhoClicked();
|
||||||
|
final int slot = event.getSlot();
|
||||||
|
final ClickType click = event.getClick();
|
||||||
|
final InventoryAction action = event.getAction();
|
||||||
|
final ItemStack item = this.inventory.getItem(slot);
|
||||||
|
if (item == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (slot == 53) {
|
||||||
|
if (this.page < this.pageCount) {
|
||||||
|
this.page += 1;
|
||||||
|
}
|
||||||
|
recalculateInv(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (slot == 45) {
|
||||||
|
if (this.page > 1) {
|
||||||
|
this.page -= 1;
|
||||||
|
}
|
||||||
|
recalculateInv(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String command = "true";
|
||||||
|
if ((click.isLeftClick()) && (action != InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
|
||||||
|
command = "true";
|
||||||
|
} else if ((click.isRightClick()) && (action != InventoryAction.MOVE_TO_OTHER_INVENTORY)) {
|
||||||
|
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 = "";
|
||||||
|
int i = 0;
|
||||||
|
for (final Entry<String, Integer> one : this.permMap.entrySet()) {
|
||||||
|
flag = one.getKey();
|
||||||
|
if (i == slot) {
|
||||||
|
if (this.targetPlayer == null) {
|
||||||
|
if (this.admin) {
|
||||||
|
Bukkit.dispatchCommand(this.player, "resadmin set " + this.residence.getName() + " " + flag + " " + command);
|
||||||
|
} else {
|
||||||
|
Bukkit.dispatchCommand(this.player, "res set " + this.residence.getName() + " " + flag + " " + command);
|
||||||
|
}
|
||||||
|
} else if (this.admin) {
|
||||||
|
Bukkit.dispatchCommand(this.player, "resadmin pset " + this.residence.getName() + " " + this.targetPlayer + " " + flag + " " + command);
|
||||||
|
} else {
|
||||||
|
Bukkit.dispatchCommand(this.player, "res pset " + this.residence.getName() + " " + this.targetPlayer + " " + flag + " " + command);
|
||||||
|
}
|
||||||
|
recalculateInv(p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
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 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
278
src/main/resources/gui.yml
Normal file
278
src/main/resources/gui.yml
Normal file
@@ -0,0 +1,278 @@
|
|||||||
|
# 图形化界面的按钮显示
|
||||||
|
GUI:
|
||||||
|
setTrue:
|
||||||
|
id: 35
|
||||||
|
data: 13
|
||||||
|
setFalse:
|
||||||
|
id: 35
|
||||||
|
data: 14
|
||||||
|
setRemove:
|
||||||
|
id: 35
|
||||||
|
data: 8
|
||||||
|
PrevInfoPage: '&2<<< &e前一页 &2|'
|
||||||
|
NextInfoPage: '&2| &e后一页 &2>>>'
|
||||||
|
Set:
|
||||||
|
Title: '&3%s 领地权限'
|
||||||
|
Pset:
|
||||||
|
Title: '&3%s 的 %s 领地权限'
|
||||||
|
Actions:
|
||||||
|
- '&b左键 &a开启权限'
|
||||||
|
- '&b右键 &c关闭权限'
|
||||||
|
- '&bShift + 左键 &4移除权限'
|
||||||
|
# Flag标记图形
|
||||||
|
FlagGUI:
|
||||||
|
animalkilling:
|
||||||
|
des:
|
||||||
|
- '动物击杀'
|
||||||
|
id: 365
|
||||||
|
data: 0
|
||||||
|
animals:
|
||||||
|
des:
|
||||||
|
- '动物生成'
|
||||||
|
id: 383
|
||||||
|
data: 90
|
||||||
|
bed:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 355
|
||||||
|
data: 0
|
||||||
|
brew:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 379
|
||||||
|
data: 0
|
||||||
|
bucket:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 325
|
||||||
|
data: 0
|
||||||
|
build:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 45
|
||||||
|
data: 0
|
||||||
|
burn:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 50
|
||||||
|
data: 0
|
||||||
|
button:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 143
|
||||||
|
data: 0
|
||||||
|
cake:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 354
|
||||||
|
data: 0
|
||||||
|
canimals:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 383
|
||||||
|
data: 91
|
||||||
|
chat:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 386
|
||||||
|
data: 0
|
||||||
|
cmonsters:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 383
|
||||||
|
data: 50
|
||||||
|
command:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 137
|
||||||
|
data: 0
|
||||||
|
container:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 342
|
||||||
|
data: 0
|
||||||
|
creeper:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 383
|
||||||
|
data: 50
|
||||||
|
destroy:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 121
|
||||||
|
data: 0
|
||||||
|
diode:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 356
|
||||||
|
data: 0
|
||||||
|
door:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 324
|
||||||
|
data: 0
|
||||||
|
enchant:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 116
|
||||||
|
data: 0
|
||||||
|
explode:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 407
|
||||||
|
data: 0
|
||||||
|
fireball:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 385
|
||||||
|
data: 0
|
||||||
|
firespread:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 377
|
||||||
|
data: 0
|
||||||
|
flow:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 111
|
||||||
|
data: 0
|
||||||
|
healing:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 373
|
||||||
|
data: 0
|
||||||
|
ignite:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 259
|
||||||
|
data: 0
|
||||||
|
lavaflow:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 327
|
||||||
|
data: 0
|
||||||
|
leash:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 420
|
||||||
|
data: 0
|
||||||
|
lever:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 69
|
||||||
|
data: 0
|
||||||
|
mobkilling:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 367
|
||||||
|
data: 0
|
||||||
|
monsters:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 52
|
||||||
|
data: 0
|
||||||
|
move:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 301
|
||||||
|
data: 0
|
||||||
|
nanimals:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 383
|
||||||
|
data: 92
|
||||||
|
nmonsters:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 383
|
||||||
|
data: 51
|
||||||
|
nofly:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 171
|
||||||
|
data: 1
|
||||||
|
nomobs:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 166
|
||||||
|
data: 0
|
||||||
|
note:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 25
|
||||||
|
data: 0
|
||||||
|
piston:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 33
|
||||||
|
data: 0
|
||||||
|
place:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 169
|
||||||
|
data: 0
|
||||||
|
pvp:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 268
|
||||||
|
data: 0
|
||||||
|
sanimals:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 383
|
||||||
|
data: 101
|
||||||
|
shear:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 359
|
||||||
|
data: 0
|
||||||
|
smonsters:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 383
|
||||||
|
data: 54
|
||||||
|
subzone:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 160
|
||||||
|
data: 7
|
||||||
|
table:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 58
|
||||||
|
data: 0
|
||||||
|
tnt:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 46
|
||||||
|
data: 0
|
||||||
|
tp:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 120
|
||||||
|
data: 0
|
||||||
|
trade:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 388
|
||||||
|
data: 0
|
||||||
|
trample:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 3
|
||||||
|
data: 0
|
||||||
|
use:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 70
|
||||||
|
data: 0
|
||||||
|
vehicledestroy:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 328
|
||||||
|
data: 0
|
||||||
|
waterflow:
|
||||||
|
des:
|
||||||
|
- '暂无描述'
|
||||||
|
id: 326
|
||||||
|
data: 0
|
||||||
Reference in New Issue
Block a user