mirror of
https://github.com/geekfrog/PermissionsTime.git
synced 2025-09-06 11:06:58 +00:00
gui显示自己的权限包(可以拿出gui的物品, 有待处理)
This commit is contained in:
@ -24,7 +24,7 @@
|
||||
- **调用vault API 设置玩家权限 -- 登录时(添加 移除)、游戏中(命令添加/移除 延迟移除)、退出时移除**
|
||||
- **mysql保存数据**
|
||||
- **支持跨服**
|
||||
- gui显示自己的权限包
|
||||
- **gui显示自己的权限包**(可以拿出gui的物品, 有待处理)
|
||||
- 手动删除过期的或无效数据
|
||||
- 语言支持整理
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -38,7 +38,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.11.2-R0.1-SNAPSHOT</version>
|
||||
<version>1.12-pre6-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
@ -28,7 +28,7 @@ public class MainCommand implements CommandExecutor {
|
||||
if (sender instanceof Player) {
|
||||
isPlayer = true;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
if (args[0].equalsIgnoreCase("help") || args.length == 0) {
|
||||
getHelp(sender, isPlayer);
|
||||
return true;
|
||||
} else {
|
||||
@ -85,7 +85,7 @@ public class MainCommand implements CommandExecutor {
|
||||
new Thread(packagesCmd).start();
|
||||
}
|
||||
} else {
|
||||
getHelp(sender, isPlayer);
|
||||
sender.sendMessage(StrUtil.messageFormat("/" + pm.PLUGIN_NAME_LOWER_CASE + " help -Show commands."));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -6,10 +6,9 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
import gg.frog.mc.permissionstime.config.PackagesCfg;
|
||||
import gg.frog.mc.permissionstime.config.PluginCfg;
|
||||
import gg.frog.mc.permissionstime.database.SqlManager;
|
||||
import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean;
|
||||
import gg.frog.mc.permissionstime.gui.PlayerPermissionShow;
|
||||
import gg.frog.mc.permissionstime.model.db.PlayerDataBean;
|
||||
import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||
|
||||
@ -38,14 +37,7 @@ public class MeCmd implements Runnable {
|
||||
Player p = (Player) sender;
|
||||
List<PlayerDataBean> ps = sm.getTime(p.getUniqueId().toString());
|
||||
if (ps.size() > 0) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "=====你共有{0}种权限包=====", ps.size()));
|
||||
for (PlayerDataBean pdb : ps) {
|
||||
PermissionPackageBean pc = PackagesCfg.PACKAGES.get(pdb.getPackageName());
|
||||
if (pc != null) {
|
||||
String expireString = StrUtil.timestampToString(pdb.getExpire());
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "{0}权限包: {1}({2}), 到期时间: {3}", pdb.getGlobal() ? "*" : "", pc.getDisplayName(), pdb.getPackageName(), expireString));
|
||||
}
|
||||
}
|
||||
PlayerPermissionShow.show(p, ps);
|
||||
} else {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "暂时无数据"));
|
||||
}
|
||||
|
@ -1,14 +1,22 @@
|
||||
package gg.frog.mc.permissionstime.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean;
|
||||
import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||
import gg.frog.mc.permissionstime.utils.config.PluginConfig;
|
||||
|
||||
public class PackagesCfg extends PluginConfig {
|
||||
@ -16,6 +24,7 @@ public class PackagesCfg extends PluginConfig {
|
||||
public static String PACKAGES_VERSION = null;
|
||||
public static String DEFAULT_GROUP = null;
|
||||
public static Map<String, PermissionPackageBean> PACKAGES = new ConcurrentHashMap<>();
|
||||
public static Map<String, ItemStack> PACKAGE_ITEMS = new ConcurrentHashMap<>();
|
||||
public static Set<String> allPermissions = Collections.synchronizedSet(new HashSet<String>());
|
||||
public static Set<String> allGroups = Collections.synchronizedSet(new HashSet<String>());
|
||||
|
||||
@ -39,9 +48,59 @@ public class PackagesCfg extends PluginConfig {
|
||||
System.out.println(p.getKey() + ":" + p.getValue());
|
||||
}
|
||||
}
|
||||
for (PermissionPackageBean p : PACKAGES.values()) {
|
||||
allPermissions.addAll(p.getPermissions());
|
||||
allGroups.addAll(p.getGroups());
|
||||
PACKAGE_ITEMS.clear();
|
||||
for (Entry<String, PermissionPackageBean> e : PACKAGES.entrySet()) {
|
||||
PACKAGE_ITEMS.put(e.getKey(), getPackageItem(e.getKey(), e.getValue()));
|
||||
allPermissions.addAll(e.getValue().getPermissions());
|
||||
allGroups.addAll(e.getValue().getGroups());
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack getPackageItem(String name, PermissionPackageBean ppb) {
|
||||
if (ppb != null) {
|
||||
Material type = null;
|
||||
int exid = 0;
|
||||
if (ppb.getType() != null) {
|
||||
String[] args = ppb.getType().split(":");
|
||||
try {
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
exid = Integer.parseInt(args[1]);
|
||||
case 1:
|
||||
type = Material.getMaterial(args[0].toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (ppb.getId() != null) {
|
||||
String[] args = ppb.getId().split(":");
|
||||
try {
|
||||
switch (args.length) {
|
||||
case 2:
|
||||
exid = Integer.parseInt(args[1]);
|
||||
case 1:
|
||||
int id = Integer.parseInt(args[0]);
|
||||
type = Material.getMaterial(id);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (type != null) {
|
||||
ItemStack items = new ItemStack(type, 1, (short) 0, (byte) exid);
|
||||
ItemMeta meta = items.getItemMeta();
|
||||
meta.setDisplayName(StrUtil.messageFormat(ppb.getDisplayName() + "&r(" + name + ")"));
|
||||
if (ppb.getLores().size() > 0) {
|
||||
List<String> lores = new ArrayList<String>();
|
||||
for (String lore : ppb.getLores()) {
|
||||
lores.add(StrUtil.messageFormat(lore));
|
||||
}
|
||||
meta.setLore(lores);
|
||||
}
|
||||
items.setItemMeta(meta);
|
||||
return items;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
import gg.frog.mc.permissionstime.config.PackagesCfg;
|
||||
import gg.frog.mc.permissionstime.config.PluginCfg;
|
||||
import gg.frog.mc.permissionstime.database.IPlayerDataDao;
|
||||
import gg.frog.mc.permissionstime.database.SqlManager;
|
||||
@ -195,16 +196,18 @@ public class MySQLPlayerDataDao extends DatabaseUtil implements IPlayerDataDao {
|
||||
List<PlayerDataBean> pdbList = new ArrayList<>();
|
||||
ResultSet rs = getDB().query(sql);
|
||||
while (rs.next()) {
|
||||
long tid = rs.getLong("id");
|
||||
String tuuid = rs.getString("uuid");
|
||||
String tpackageName = rs.getString("packageName");
|
||||
String tserverId = rs.getString("serverId");
|
||||
long texpire = rs.getLong("expire");
|
||||
PlayerDataBean tpd = new PlayerDataBean(tid, tuuid, tpackageName, texpire);
|
||||
if (tserverId == null) {
|
||||
tpd.setGlobal(true);
|
||||
if (PackagesCfg.PACKAGES.containsKey(tpackageName)) {
|
||||
long tid = rs.getLong("id");
|
||||
String tuuid = rs.getString("uuid");
|
||||
String tserverId = rs.getString("serverId");
|
||||
long texpire = rs.getLong("expire");
|
||||
PlayerDataBean tpd = new PlayerDataBean(tid, tuuid, tpackageName, texpire);
|
||||
if (tserverId == null) {
|
||||
tpd.setGlobal(true);
|
||||
}
|
||||
pdbList.add(tpd);
|
||||
}
|
||||
pdbList.add(tpd);
|
||||
}
|
||||
return pdbList;
|
||||
} catch (Exception e) {
|
||||
|
@ -6,6 +6,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
import gg.frog.mc.permissionstime.config.PackagesCfg;
|
||||
import gg.frog.mc.permissionstime.config.PluginCfg;
|
||||
import gg.frog.mc.permissionstime.database.IPlayerDataDao;
|
||||
import gg.frog.mc.permissionstime.database.SqlManager;
|
||||
@ -158,12 +159,14 @@ public class SqlitePlayerDataDao extends DatabaseUtil implements IPlayerDataDao
|
||||
List<PlayerDataBean> pdbList = new ArrayList<>();
|
||||
ResultSet rs = getDB().query(sql);
|
||||
while (rs.next()) {
|
||||
long tid = rs.getLong("id");
|
||||
String tuuid = rs.getString("uuid");
|
||||
String tpackageName = rs.getString("packageName");
|
||||
long texpire = rs.getLong("expire");
|
||||
PlayerDataBean tpd = new PlayerDataBean(tid, tuuid, tpackageName, texpire);
|
||||
pdbList.add(tpd);
|
||||
if (PackagesCfg.PACKAGES.containsKey(tpackageName)) {
|
||||
long tid = rs.getLong("id");
|
||||
String tuuid = rs.getString("uuid");
|
||||
long texpire = rs.getLong("expire");
|
||||
PlayerDataBean tpd = new PlayerDataBean(tid, tuuid, tpackageName, texpire);
|
||||
pdbList.add(tpd);
|
||||
}
|
||||
}
|
||||
return pdbList;
|
||||
} catch (Exception e) {
|
||||
|
@ -0,0 +1,26 @@
|
||||
package gg.frog.mc.permissionstime.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import gg.frog.mc.permissionstime.config.PackagesCfg;
|
||||
import gg.frog.mc.permissionstime.model.db.PlayerDataBean;
|
||||
import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||
|
||||
public class PlayerPermissionShow {
|
||||
|
||||
public static void show(Player p, List<PlayerDataBean> pdbList) {
|
||||
Inventory inventory = Bukkit.createInventory(null, (pdbList.size() % 9 == 0 ? pdbList.size() : (pdbList.size() / 9 + 1) * 9), StrUtil.messageFormat("&4你共有{0}种权限包", pdbList.size()));
|
||||
for (PlayerDataBean pdb : pdbList) {
|
||||
ItemStack item = PackagesCfg.PACKAGE_ITEMS.get(pdb.getPackageName());
|
||||
if (item != null) {
|
||||
inventory.addItem(item);
|
||||
}
|
||||
}
|
||||
p.openInventory(inventory);
|
||||
}
|
||||
}
|
@ -28,6 +28,9 @@ import net.milkbowl.vault.permission.Permission;
|
||||
public class PermissionPackageBean implements IConfigBean {
|
||||
|
||||
private String displayName = null;
|
||||
private String id;
|
||||
private String type;
|
||||
private List<String> lores = new ArrayList<>();
|
||||
private Boolean global = null;
|
||||
private List<String> permissions = new ArrayList<>();
|
||||
private List<String> groups = new ArrayList<>();
|
||||
@ -41,6 +44,30 @@ public class PermissionPackageBean implements IConfigBean {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public List<String> getLores() {
|
||||
return lores;
|
||||
}
|
||||
|
||||
public void setLores(List<String> lores) {
|
||||
this.lores = lores;
|
||||
}
|
||||
|
||||
public Boolean getGlobal() {
|
||||
return global;
|
||||
}
|
||||
@ -69,6 +96,9 @@ public class PermissionPackageBean implements IConfigBean {
|
||||
public YamlConfiguration toConfig() {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
config.set("displayName", displayName);
|
||||
config.set("id", id);
|
||||
config.set("type", type);
|
||||
config.set("lores", lores);
|
||||
config.set("global", global);
|
||||
config.set("permissions", permissions);
|
||||
config.set("groups", groups);
|
||||
@ -81,6 +111,12 @@ public class PermissionPackageBean implements IConfigBean {
|
||||
if (displayName == null) {
|
||||
displayName = "No Name";
|
||||
}
|
||||
id = config.getString("id");
|
||||
type = config.getString("type");
|
||||
if (id == null && type == null) {
|
||||
type = "NETHER_STAR";
|
||||
}
|
||||
lores = config.getStringList("lores");
|
||||
global = config.getBoolean("global");
|
||||
permissions = config.getStringList("permissions");
|
||||
groups = config.getStringList("groups");
|
||||
@ -88,7 +124,7 @@ public class PermissionPackageBean implements IConfigBean {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PermissionPackageBean [displayName=" + displayName + ", global=" + global + ", permissions=" + permissions + ", groups=" + groups + "]";
|
||||
return "PermissionPackageBean [displayName=" + displayName + ", id=" + id + ", type=" + type + ", lores=" + lores + ", global=" + global + ", permissions=" + permissions + ", groups=" + groups + "]";
|
||||
}
|
||||
|
||||
private void givePlayer(OfflinePlayer player, Server server, Permission permission) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package gg.frog.mc.permissionstime.utils.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
@ -9,6 +10,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@ -127,8 +129,18 @@ public abstract class PluginConfig {
|
||||
* 配置重载
|
||||
*/
|
||||
private void reloadConfig(File folder, String fileName, boolean useRes) {
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
YamlConfiguration tempConfig = new YamlConfiguration();
|
||||
try {
|
||||
tempConfig.load(configFile);
|
||||
config = tempConfig;
|
||||
} catch (FileNotFoundException e) {
|
||||
} catch (IOException | InvalidConfigurationException e1) {
|
||||
tempConfig = null;
|
||||
e1.printStackTrace();
|
||||
}
|
||||
if (config == null) {
|
||||
config = new YamlConfiguration();
|
||||
}
|
||||
if (useRes) {
|
||||
final InputStream defConfigStream = pm.getResource(fileName);
|
||||
if (defConfigStream == null) {
|
||||
@ -137,7 +149,9 @@ public abstract class PluginConfig {
|
||||
config.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8)));
|
||||
}
|
||||
loadToDo();
|
||||
saveConfig();
|
||||
if (tempConfig != null) {
|
||||
saveConfig();
|
||||
}
|
||||
}
|
||||
|
||||
protected void saveObj(String path, Map<String, ? extends IConfigBean> o) {
|
||||
|
@ -5,7 +5,12 @@ packages:
|
||||
#权限包名称
|
||||
example1:
|
||||
#权限包显示名称
|
||||
displayName: '权限包模板1'
|
||||
displayName: '&4权限包模板1'
|
||||
#显示的物品类型
|
||||
type: NETHER_STAR
|
||||
#标签
|
||||
lores:
|
||||
- '&2这是权限包模板的标签'
|
||||
#是否跨服权限
|
||||
global: false
|
||||
#权限包含有的权限 world1、world2、world3是赋值给玩家permission2权限的世界
|
||||
|
Reference in New Issue
Block a user