1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2024-11-22 07:28:47 +00:00

修复BUG

称号功能完善
This commit is contained in:
GeekFrog 2018-06-18 14:46:01 +08:00
parent d9435886bc
commit 3a9169e30b
22 changed files with 986 additions and 824 deletions

30
pom.xml
View File

@ -34,10 +34,14 @@
<id>bstats-repo</id> <id>bstats-repo</id>
<url>http://repo.bstats.org/content/repositories/releases/</url> <url>http://repo.bstats.org/content/repositories/releases/</url>
</repository> </repository>
<repository> <repository>
<id>placeholderapi</id> <id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url> <url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository> </repository>
<repository>
<id>filoghost-repo</id>
<url>https://ci.filoghost.me/plugin/repository/everything/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
@ -58,17 +62,23 @@
<version>1.6</version> <version>1.6</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>me.clip</groupId> <groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId> <artifactId>placeholderapi</artifactId>
<version>2.0.8</version> <version>LATEST</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>lib.PatPeter.SQLibrary</groupId> <groupId>lib.PatPeter.SQLibrary</groupId>
<artifactId>SQLibrary</artifactId> <artifactId>SQLibrary</artifactId>
<version>7.1</version> <version>7.1</version>
</dependency> </dependency>
<dependency>
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
<artifactId>holographicdisplays-api</artifactId>
<version>2.2.7-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>PermissionsTime-${project.version}</finalName> <finalName>PermissionsTime-${project.version}</finalName>

View File

@ -2,7 +2,8 @@ package gg.frog.mc.permissionstime;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Locale; import java.util.Locale;
import java.util.UUID; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
@ -16,182 +17,196 @@ import gg.frog.mc.permissionstime.config.ConfigManager;
import gg.frog.mc.permissionstime.config.PluginCfg; import gg.frog.mc.permissionstime.config.PluginCfg;
import gg.frog.mc.permissionstime.database.SqlManager; import gg.frog.mc.permissionstime.database.SqlManager;
import gg.frog.mc.permissionstime.listener.MainListener; import gg.frog.mc.permissionstime.listener.MainListener;
import gg.frog.mc.permissionstime.placeholder.TagPlaceholder;
import gg.frog.mc.permissionstime.utils.FileUtil; import gg.frog.mc.permissionstime.utils.FileUtil;
import gg.frog.mc.permissionstime.utils.StrUtil; import gg.frog.mc.permissionstime.utils.StrUtil;
import gg.frog.mc.permissionstime.utils.UpdateCheck; import gg.frog.mc.permissionstime.utils.UpdateCheck;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
public class PluginMain extends JavaPlugin { public class PluginMain extends JavaPlugin {
public String PLUGIN_NAME; public String PLUGIN_NAME;
public String PLUGIN_VERSION; public String PLUGIN_VERSION;
public String PLUGIN_NAME_LOWER_CASE; public String PLUGIN_NAME_LOWER_CASE;
public static final String DEPEND_PLUGIN = "SQLibrary,Vault"; public static final String DEPEND_PLUGIN = "SQLibrary,Vault";
public static final Logger LOG = Logger.getLogger("Minecraft"); public static final Logger LOG = Logger.getLogger("Minecraft");
private ConfigManager cm = null; private ConfigManager cm = null;
private PluginMain pm = null; private PluginMain pm = null;
private SqlManager sm = null; private SqlManager sm = null;
private Permission permission = null; private Permission permission = null;
private Chat chat = null; public static boolean enabledHdPlugin;
public static boolean enabledPlaceholder;
private static Map<String, OfflinePlayer> playerMap = new ConcurrentHashMap<>();
public PluginMain() { public PluginMain() {
PLUGIN_NAME = getDescription().getName(); PLUGIN_NAME = getDescription().getName();
PLUGIN_VERSION = getDescription().getVersion(); PLUGIN_VERSION = getDescription().getVersion();
PLUGIN_NAME_LOWER_CASE = PLUGIN_NAME.toLowerCase(Locale.ENGLISH); PLUGIN_NAME_LOWER_CASE = PLUGIN_NAME.toLowerCase(Locale.ENGLISH);
} }
@Override @Override
public void onEnable() { public void onEnable() {
pm = this; pm = this;
cm = new ConfigManager(pm); cm = new ConfigManager(pm);
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "===============================")); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "==============================="));
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX)); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " " + PLUGIN_NAME + " v" + PLUGIN_VERSION)); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " " + PLUGIN_NAME + " v" + PLUGIN_VERSION));
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " authorGeekFrog QQ324747460")); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " authorGeekFrog QQ324747460"));
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " https://github.com/geekfrog/PermissionsTime/ ")); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + " https://github.com/geekfrog/PermissionsTime/ "));
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX)); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX));
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "===============================")); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "==============================="));
getServer().getScheduler().runTask(pm, new Runnable() { getServer().getScheduler().runTask(pm, new Runnable() {
public void run() { public void run() {
if (!checkPluginDepends()) { if (!checkPluginDepends()) {
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Startup failure!")); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Startup failure!"));
getServer().getPluginManager().disablePlugin(pm); getServer().getPluginManager().disablePlugin(pm);
} else { } else {
registerListeners(); registerListeners();
registerCommands(); registerCommands();
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&2Startup successful!")); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&2Startup successful!"));
} }
if (PluginCfg.IS_METRICS) { if (PluginCfg.IS_METRICS) {
try { try {
new Metrics(pm); new Metrics(pm);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
getServer().getScheduler().runTaskAsynchronously(pm, new UpdateCheck(pm)); getServer().getScheduler().runTaskAsynchronously(pm, new UpdateCheck(pm));
} }
}); });
} }
/** /**
* 注册监听器 <br/> * 注册监听器 <br/>
* 这里可以注册多个 * 这里可以注册多个
*/ */
private void registerListeners() { private void registerListeners() {
pm.getServer().getPluginManager().registerEvents(new MainListener(pm), pm); pm.getServer().getPluginManager().registerEvents(new MainListener(pm), pm);
} }
/** /**
* 注册命令 <br/> * 注册命令 <br/>
* 这里可以注册多个一般注册一个就够用 * 这里可以注册多个一般注册一个就够用
*/ */
private void registerCommands() { private void registerCommands() {
MainCommand mcmd = new MainCommand(pm); MainCommand mcmd = new MainCommand(pm);
if (getDescription().getCommands().containsKey(PLUGIN_NAME_LOWER_CASE)) { if (getDescription().getCommands().containsKey(PLUGIN_NAME_LOWER_CASE)) {
getCommand(PLUGIN_NAME_LOWER_CASE).setExecutor(mcmd); getCommand(PLUGIN_NAME_LOWER_CASE).setExecutor(mcmd);
} }
if (getDescription().getCommands().containsKey("pt")) { if (getDescription().getCommands().containsKey("pt")) {
getCommand("pt").setExecutor(mcmd); getCommand("pt").setExecutor(mcmd);
} }
} }
public ConfigManager getConfigManager() { public ConfigManager getConfigManager() {
return cm; return cm;
} }
public SqlManager getSqlManager() { public SqlManager getSqlManager() {
return sm; return sm;
} }
public Permission getPermission() { public Permission getPermission() {
return permission; return permission;
}
public Chat getChat() {
return chat;
} }
private boolean checkPluginDepends() { private boolean checkPluginDepends() {
boolean needDepend = false; boolean needDepend = false;
for (String name : DEPEND_PLUGIN.split(",")) { for (String name : DEPEND_PLUGIN.split(",")) {
if (getServer().getPluginManager().getPlugin(name) == null) { if (!getServer().getPluginManager().isPluginEnabled(name)) {
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Need depend plugins : " + name)); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Need depend plugins : " + name + "."));
needDepend = true; needDepend = true;
} }
} }
if (!needDepend && !setupPermissions()) { if (!needDepend && !setupPermissions()) {
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t hook vault permission")); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t hook vault permission."));
needDepend = true; needDepend = true;
} }
if (!needDepend && !setupChat()) { if (!needDepend && !setupDatabase()) {
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t hook vault chat")); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t setup database."));
needDepend = true; needDepend = true;
} }
if (!needDepend && !setupDatabase()) { enabledPlaceholder = Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t setup database")); if (!enabledPlaceholder) {
needDepend = true; getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&ePlaceholder is not installed or not enabled."));
} getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&eSome func will be disabled."));
if (needDepend) { } else {
return false; boolean placeholdersHook = false;
} try {
return true; placeholdersHook = new TagPlaceholder(pm).register();
} } catch (Exception e) {
@Override }
public void onDisable() { if (!placeholdersHook) {
getServer().getServicesManager().unregisterAll(pm); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t hook placeholders"));
Bukkit.getScheduler().cancelTasks(pm); getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4The placeholders '%permissionstime_displayname%' Cann''t use."));
try { }
sm.getDb().close(); }
} catch (Exception e) { enabledHdPlugin = Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays");
} if (!enabledHdPlugin) {
} getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&eHolographicDisplays is not installed or not enabled."));
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&eSome func will be disabled."));
}
private boolean setupPermissions() { if (needDepend) {
RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class); return false;
if (permissionProvider != null) { }
permission = permissionProvider.getProvider(); return true;
} }
return (permission != null);
}
private boolean setupChat() { @Override
RegisteredServiceProvider<Chat> chatProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class); public void onDisable() {
if (chatProvider != null) { getServer().getServicesManager().unregisterAll(pm);
chat = chatProvider.getProvider(); Bukkit.getScheduler().cancelTasks(pm);
} try {
return (chat != null); sm.getDb().close();
} } catch (Exception e) {
}
}
private boolean setupDatabase() { private boolean setupPermissions() {
sm = new SqlManager(pm); RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
return sm.updateDatabase(); if (permissionProvider != null) {
} permission = permissionProvider.getProvider();
}
return (permission != null);
}
public UUID getPlayerUUIDByName(String name) { private boolean setupDatabase() {
OfflinePlayer p = getOfflinePlayer(name); sm = new SqlManager(pm);
if (p == null) { return sm.updateDatabase();
return null; }
} else {
return p.getUniqueId();
}
}
public OfflinePlayer getOfflinePlayer(String name) { public String getPlayerUUIDByName(String name) {
for (OfflinePlayer p : getServer().getOfflinePlayers()) { OfflinePlayer p = getOfflinePlayer(name);
if(p==null) if (p == null) {
continue; return null;
if (p.getName().equalsIgnoreCase(name)) { } else {
return p; return p.getUniqueId().toString();
} }
} }
return null;
}
public void writeFailLog(String content, Object... args) { public OfflinePlayer getOfflinePlayer(String name) {
FileUtil.writeOnFile(getDataFolder() + "/failure.log", "[" + StrUtil.nowTimeString() + "] " + MessageFormat.format(content, args)); if (name != null) {
} OfflinePlayer p1 = playerMap.get(name);
if (p1 != null)
return p1;
for (OfflinePlayer p2 : getServer().getOfflinePlayers()) {
if (p2 == null)
continue;
if (p2.getName().equalsIgnoreCase(name)) {
playerMap.put(name, p2);
return p2;
}
}
}
return null;
}
public void writeFailLog(String content, Object... args) {
FileUtil.writeOnFile(getDataFolder() + "/failure.log", "[" + StrUtil.nowTimeString() + "] " + MessageFormat.format(content, args));
}
} }

View File

@ -2,7 +2,6 @@ package gg.frog.mc.permissionstime.command;
import java.util.List; import java.util.List;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.PluginMain;
@ -32,9 +31,9 @@ public class GetCmd implements Runnable {
public void run() { public void run() {
if (args.length == 2) { if (args.length == 2) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
OfflinePlayer p = pm.getOfflinePlayer(args[1]); String uuid = pm.getPlayerUUIDByName(args[1]);
if (p != null) { if (uuid != null) {
List<PlayerDataBean> ps = sm.getTime(p.getUniqueId().toString()); List<PlayerDataBean> ps = sm.getTime(uuid);
if (ps.size() > 0) { if (ps.size() > 0) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NUM_OF_PACKAGES, sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NUM_OF_PACKAGES,
args[1], ps.size())); args[1], ps.size()));

View File

@ -1,7 +1,6 @@
package gg.frog.mc.permissionstime.command; package gg.frog.mc.permissionstime.command;
import java.util.List; import java.util.List;
import java.util.UUID;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -18,90 +17,90 @@ import gg.frog.mc.permissionstime.utils.StrUtil;
public class GiveCmd implements Runnable { public class GiveCmd implements Runnable {
private PluginMain pm; private PluginMain pm;
private SqlManager sm; private SqlManager sm;
private String[] args; private String[] args;
private CommandSender sender; private CommandSender sender;
public GiveCmd(PluginMain pm, CommandSender sender, String[] args) { public GiveCmd(PluginMain pm, CommandSender sender, String[] args) {
this.pm = pm; this.pm = pm;
this.sm = pm.getSqlManager(); this.sm = pm.getSqlManager();
this.sender = sender; this.sender = sender;
this.args = args; this.args = args;
} }
@Override @Override
public void run() { public void run() {
if (args.length == 5) { if (args.length == 5) {
String playerName = args[1]; String playerName = args[1];
String packageName = args[2]; String packageName = args[2];
String time = args[3]; String time = args[3];
String unit = args[4]; String unit = args[4];
final String unitName; final String unitName;
int minutes = 0; int minutes = 0;
try { try {
minutes = Integer.parseInt(time); minutes = Integer.parseInt(time);
if (minutes == 0) { if (minutes == 0) {
throw new RuntimeException("not a nonzero integer."); throw new RuntimeException("not a nonzero integer.");
} }
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_PARAMETER_INCORRECT)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_PARAMETER_INCORRECT));
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE));
return; return;
} }
if ("d".equalsIgnoreCase(unit)) { if ("d".equalsIgnoreCase(unit)) {
minutes *= 24 * 60; minutes *= 24 * 60;
unitName = LangCfg.TIME_UNIT_D; unitName = LangCfg.TIME_UNIT_D;
} else if ("h".equalsIgnoreCase(unit)) { } else if ("h".equalsIgnoreCase(unit)) {
minutes *= 60; minutes *= 60;
unitName = LangCfg.TIME_UNIT_H; unitName = LangCfg.TIME_UNIT_H;
} else if ("m".equalsIgnoreCase(unit)) { } else if ("m".equalsIgnoreCase(unit)) {
unitName = LangCfg.TIME_UNIT_M; unitName = LangCfg.TIME_UNIT_M;
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_UNIT_PARAMETER_INCORRECT)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_UNIT_PARAMETER_INCORRECT));
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE));
return; return;
} }
PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName);
if (pack != null) { if (pack != null) {
OfflinePlayer player = pm.getOfflinePlayer(playerName); OfflinePlayer player = pm.getOfflinePlayer(playerName);
if (player != null) { if (player != null) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
UUID uuid = player.getUniqueId(); String uuid = player.getUniqueId().toString();
if (PluginCfg.IS_DEBUG) { if (PluginCfg.IS_DEBUG) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time + unitName + ".")); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid + "\n" + pack.toString() + "\n" + time + unitName + "."));
} }
if (sm.giveTime(((PluginCfg.USE_MYSQL && pack.getGlobal()) ? "g:" : "") + uuid.toString(), packageName, minutes)) { if (sm.giveTime(((PluginCfg.USE_MYSQL && pack.getGlobal()) ? "g:" : "") + uuid, packageName, minutes)) {
if (player.isOnline()) { if (player.isOnline()) {
Player p = player.getPlayer(); Player p = player.getPlayer();
try { try {
List<PlayerDataBean> pdbList = sm.getTime(player.getUniqueId().toString()); List<PlayerDataBean> pdbList = sm.getTime(uuid);
PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm); PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION)); p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION));
} }
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_GIVE_PACKAGE, sender.getName(), time + unitName, pack.getDisplayName())); p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_GIVE_PACKAGE, sender.getName(), time + unitName, pack.getDisplayName()));
} }
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_GIVE_PACKAGE, playerName, time + unitName, pack.getDisplayName())); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_GIVE_PACKAGE, playerName, time + unitName, pack.getDisplayName()));
} else { } else {
pm.getServer().getScheduler().runTask(pm, new Runnable() { pm.getServer().getScheduler().runTask(pm, new Runnable() {
@Override @Override
public void run() { public void run() {
pm.writeFailLog("Command execution failed. Give {0}({1}) {2} {3} Executor: {4}", playerName, player.getUniqueId().toString(), time + unitName, pack.getDisplayName(), sender.getName()); pm.writeFailLog("Command execution failed. Give {0}({1}) {2} {3} Executor: {4}", playerName, uuid, time + unitName, pack.getDisplayName(), sender.getName());
} }
}); });
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_GIVE_PACKAGE_FAIL, playerName, time + unitName, pack.getDisplayName())); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_GIVE_PACKAGE_FAIL, playerName, time + unitName, pack.getDisplayName()));
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName));
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PACKAGE, packageName)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PACKAGE, packageName));
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_GIVE, pm.PLUGIN_NAME_LOWER_CASE));
} }
} }
} }

View File

@ -2,7 +2,6 @@ package gg.frog.mc.permissionstime.command;
import java.util.List; import java.util.List;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -16,34 +15,34 @@ import gg.frog.mc.permissionstime.utils.StrUtil;
public class MeCmd implements Runnable { public class MeCmd implements Runnable {
private PluginMain pm; private PluginMain pm;
private SqlManager sm; private SqlManager sm;
private String[] args; private String[] args;
private CommandSender sender; private CommandSender sender;
private boolean isPlayer; private boolean isPlayer;
public MeCmd(PluginMain pm, CommandSender sender, boolean isPlayer, String[] args) { public MeCmd(PluginMain pm, CommandSender sender, boolean isPlayer, String[] args) {
this.pm = pm; this.pm = pm;
this.sm = pm.getSqlManager(); this.sm = pm.getSqlManager();
this.sender = sender; this.sender = sender;
this.isPlayer = isPlayer; this.isPlayer = isPlayer;
this.args = args; this.args = args;
} }
@Override @Override
public void run() { public void run() {
if (isPlayer) { if (isPlayer) {
if (args.length == 1) { if (args.length == 1) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
OfflinePlayer p = this.pm.getOfflinePlayer(sender.getName()); String uuid = pm.getPlayerUUIDByName(sender.getName());
List<PlayerDataBean> ps = sm.getTime(p.getUniqueId().toString()); List<PlayerDataBean> ps = sm.getTime(uuid);
PlayerPermissionShow.show((Player) sender, ps); PlayerPermissionShow.show((Player) sender, ps);
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_ME, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_ME, pm.PLUGIN_NAME_LOWER_CASE));
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Only player can use this command.")); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Only player can use this command."));
} }
} }
} }

View File

@ -1,7 +1,6 @@
package gg.frog.mc.permissionstime.command; package gg.frog.mc.permissionstime.command;
import java.util.List; import java.util.List;
import java.util.UUID;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -17,61 +16,61 @@ import gg.frog.mc.permissionstime.utils.StrUtil;
public class RemoveAllCmd implements Runnable { public class RemoveAllCmd implements Runnable {
private PluginMain pm; private PluginMain pm;
private SqlManager sm; private SqlManager sm;
private String[] args; private String[] args;
private CommandSender sender; private CommandSender sender;
public RemoveAllCmd(PluginMain pm, CommandSender sender, String[] args) { public RemoveAllCmd(PluginMain pm, CommandSender sender, String[] args) {
this.pm = pm; this.pm = pm;
this.sm = pm.getSqlManager(); this.sm = pm.getSqlManager();
this.sender = sender; this.sender = sender;
this.args = args; this.args = args;
} }
@Override @Override
public void run() { public void run() {
if (args.length == 2 || args.length == 3) { if (args.length == 2 || args.length == 3) {
String playerName = args[1]; String playerName = args[1];
boolean delGlobal = false; boolean delGlobal = false;
if (args.length == 3 && "t".equalsIgnoreCase(args[2]) && PluginCfg.USE_MYSQL) { if (args.length == 3 && "t".equalsIgnoreCase(args[2]) && PluginCfg.USE_MYSQL) {
delGlobal = true; delGlobal = true;
} }
OfflinePlayer player = pm.getOfflinePlayer(playerName); OfflinePlayer player = pm.getOfflinePlayer(playerName);
if (player != null) { if (player != null) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
UUID uuid = player.getUniqueId(); String uuid = player.getUniqueId().toString();
if (PluginCfg.IS_DEBUG) { if (PluginCfg.IS_DEBUG) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString())); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid));
} }
if (sm.removeAllTime((delGlobal ? "g:" : "") + uuid.toString())) { if (sm.removeAllTime((delGlobal ? "g:" : "") + uuid)) {
if (player.isOnline()) { if (player.isOnline()) {
Player p = player.getPlayer(); Player p = player.getPlayer();
try { try {
List<PlayerDataBean> pdbList = sm.getTime(player.getUniqueId().toString()); List<PlayerDataBean> pdbList = sm.getTime(uuid);
PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm); PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION)); p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION));
} }
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_DEL_ALL, sender.getName())); p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_DEL_ALL, sender.getName()));
} }
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_ALL, playerName)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_ALL, playerName));
} else { } else {
pm.getServer().getScheduler().runTask(pm, new Runnable() { pm.getServer().getScheduler().runTask(pm, new Runnable() {
@Override @Override
public void run() { public void run() {
pm.writeFailLog("Command execution failed. Delete {0}({1})'s all packages. Executor: {2}", playerName, player.getUniqueId().toString(), sender.getName()); pm.writeFailLog("Command execution failed. Delete {0}({1})'s all packages. Executor: {2}", playerName, uuid, sender.getName());
} }
}); });
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_ALL_FAIL, playerName)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_ALL_FAIL, playerName));
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName));
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVEALL, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVEALL, pm.PLUGIN_NAME_LOWER_CASE));
} }
} }
} }

View File

@ -1,7 +1,6 @@
package gg.frog.mc.permissionstime.command; package gg.frog.mc.permissionstime.command;
import java.util.List; import java.util.List;
import java.util.UUID;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -18,67 +17,67 @@ import gg.frog.mc.permissionstime.utils.StrUtil;
public class RemoveCmd implements Runnable { public class RemoveCmd implements Runnable {
private PluginMain pm; private PluginMain pm;
private SqlManager sm; private SqlManager sm;
private String[] args; private String[] args;
private CommandSender sender; private CommandSender sender;
public RemoveCmd(PluginMain pm, CommandSender sender, String[] args) { public RemoveCmd(PluginMain pm, CommandSender sender, String[] args) {
this.pm = pm; this.pm = pm;
this.sm = pm.getSqlManager(); this.sm = pm.getSqlManager();
this.sender = sender; this.sender = sender;
this.args = args; this.args = args;
} }
@Override @Override
public void run() { public void run() {
if (args.length == 3 || args.length == 4) { if (args.length == 3 || args.length == 4) {
String playerName = args[1]; String playerName = args[1];
String packageName = args[2]; String packageName = args[2];
boolean delGlobal = false; boolean delGlobal = false;
if (args.length == 4 && "t".equalsIgnoreCase(args[3]) && PluginCfg.USE_MYSQL) { if (args.length == 4 && "t".equalsIgnoreCase(args[3]) && PluginCfg.USE_MYSQL) {
delGlobal = true; delGlobal = true;
} }
PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName);
if (pack != null) { if (pack != null) {
OfflinePlayer player = pm.getOfflinePlayer(playerName); OfflinePlayer player = pm.getOfflinePlayer(playerName);
if (player != null) { if (player != null) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
UUID uuid = player.getUniqueId(); String uuid = player.getUniqueId().toString();
if (PluginCfg.IS_DEBUG) { if (PluginCfg.IS_DEBUG) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString())); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid + "\n" + pack.toString()));
} }
if (sm.removeTime((delGlobal ? "g:" : "") + uuid.toString(), packageName)) { if (sm.removeTime((delGlobal ? "g:" : "") + uuid, packageName)) {
if (player.isOnline()) { if (player.isOnline()) {
Player p = player.getPlayer(); Player p = player.getPlayer();
try { try {
List<PlayerDataBean> pdbList = sm.getTime(player.getUniqueId().toString()); List<PlayerDataBean> pdbList = sm.getTime(uuid);
PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm); PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION)); p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION));
} }
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_DEL_PACKAGE, sender.getName(), pack.getDisplayName())); p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_DEL_PACKAGE, sender.getName(), pack.getDisplayName()));
} }
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_PACKAGE, playerName, pack.getDisplayName())); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_PACKAGE, playerName, pack.getDisplayName()));
} else { } else {
pm.getServer().getScheduler().runTask(pm, new Runnable() { pm.getServer().getScheduler().runTask(pm, new Runnable() {
@Override @Override
public void run() { public void run() {
pm.writeFailLog("Command execution failed. Delete {0}({1})'s packages which be named {2} Executor: {3}", playerName, player.getUniqueId().toString(), pack.getDisplayName(), sender.getName()); pm.writeFailLog("Command execution failed. Delete {0}({1})'s packages which be named {2} Executor: {3}", playerName, uuid, pack.getDisplayName(), sender.getName());
} }
}); });
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_PACKAGE_FAIL, playerName, pack.getDisplayName())); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_DEL_PACKAGE_FAIL, playerName, pack.getDisplayName()));
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName));
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PACKAGE, packageName)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PACKAGE, packageName));
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVE, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_REMOVE, pm.PLUGIN_NAME_LOWER_CASE));
} }
} }
} }

View File

@ -1,7 +1,6 @@
package gg.frog.mc.permissionstime.command; package gg.frog.mc.permissionstime.command;
import java.util.List; import java.util.List;
import java.util.UUID;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -18,90 +17,93 @@ import gg.frog.mc.permissionstime.utils.StrUtil;
public class SetCmd implements Runnable { public class SetCmd implements Runnable {
private PluginMain pm; private PluginMain pm;
private SqlManager sm; private SqlManager sm;
private String[] args; private String[] args;
private CommandSender sender; private CommandSender sender;
public SetCmd(PluginMain pm, CommandSender sender, String[] args) { public SetCmd(PluginMain pm, CommandSender sender, String[] args) {
this.pm = pm; this.pm = pm;
this.sm = pm.getSqlManager(); this.sm = pm.getSqlManager();
this.sender = sender; this.sender = sender;
this.args = args; this.args = args;
} }
@Override @Override
public void run() { public void run() {
if (args.length == 5) { if (args.length == 5) {
String playerName = args[1]; String playerName = args[1];
String packageName = args[2]; String packageName = args[2];
String time = args[3]; String time = args[3];
String unit = args[4]; String unit = args[4];
final String unitName; final String unitName;
int minutes = 0; int minutes = 0;
try { try {
minutes = Integer.parseInt(time); minutes = Integer.parseInt(time);
if (minutes == 0) { if (minutes == 0) {
throw new RuntimeException("not a nonzero integer."); throw new RuntimeException("not a nonzero integer.");
} }
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_PARAMETER_INCORRECT)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_PARAMETER_INCORRECT));
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE));
return; return;
} }
if ("d".equalsIgnoreCase(unit)) { if ("d".equalsIgnoreCase(unit)) {
minutes *= 24 * 60; minutes *= 24 * 60;
unitName = LangCfg.TIME_UNIT_D; unitName = LangCfg.TIME_UNIT_D;
} else if ("h".equalsIgnoreCase(unit)) { } else if ("h".equalsIgnoreCase(unit)) {
minutes *= 60; minutes *= 60;
unitName = LangCfg.TIME_UNIT_H; unitName = LangCfg.TIME_UNIT_H;
} else if ("m".equalsIgnoreCase(unit)) { } else if ("m".equalsIgnoreCase(unit)) {
unitName = LangCfg.TIME_UNIT_M; unitName = LangCfg.TIME_UNIT_M;
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_UNIT_PARAMETER_INCORRECT)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TIME_UNIT_PARAMETER_INCORRECT));
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE));
return; return;
} }
PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName); PermissionPackageBean pack = PackagesCfg.PACKAGES.get(packageName);
if (pack != null) { if (pack != null) {
OfflinePlayer player = pm.getOfflinePlayer(playerName); OfflinePlayer player = pm.getOfflinePlayer(playerName);
if (player != null) { if (player != null) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
UUID uuid = player.getUniqueId(); String uuid = player.getUniqueId().toString();
if (PluginCfg.IS_DEBUG) { if (PluginCfg.IS_DEBUG) {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid.toString() + "\n" + pack.toString() + "\n" + time + unitName + " .")); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + uuid + "\n" + pack.toString() + "\n" + time + unitName + " ."));
} }
if (sm.setTime(((PluginCfg.USE_MYSQL && pack.getGlobal()) ? "g:" : "") + uuid.toString(), packageName, minutes)) { if (sm.setTime(((PluginCfg.USE_MYSQL && pack.getGlobal()) ? "g:" : "") + uuid, packageName, minutes)) {
if (player.isOnline()) { if (player.isOnline()) {
Player p = player.getPlayer(); Player p = player.getPlayer();
try { if (p != null) {
List<PlayerDataBean> pdbList = sm.getTime(player.getUniqueId().toString()); try {
PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm); List<PlayerDataBean> pdbList = sm.getTime(uuid);
} catch (Exception e) { PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm);
e.printStackTrace(); } catch (Exception e) {
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION)); e.printStackTrace();
} p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION));
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_SET_PACKAGE, sender.getName(), time + unitName, pack.getDisplayName())); }
} p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_TELL_SET_PACKAGE, sender.getName(), time + unitName, pack.getDisplayName()));
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_SET_PACKAGE, playerName, time + unitName, pack.getDisplayName())); }
} else {
pm.getServer().getScheduler().runTask(pm, new Runnable() { }
@Override sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_SET_PACKAGE, playerName, time + unitName, pack.getDisplayName()));
public void run() { } else {
pm.writeFailLog("Command execution failed. Set {0}({1}) {2} {3} Executor: {4}", playerName, player.getUniqueId().toString(), time + unitName, pack.getDisplayName(), sender.getName()); pm.getServer().getScheduler().runTask(pm, new Runnable() {
} @Override
}); public void run() {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_SET_PACKAGE_FAIL, playerName, time + unitName, pack.getDisplayName())); pm.writeFailLog("Command execution failed. Set {0}({1}) {2} {3} Executor: {4}", playerName, uuid, time + unitName, pack.getDisplayName(), sender.getName());
} }
} else { });
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_SET_PACKAGE_FAIL, playerName, time + unitName, pack.getDisplayName()));
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PACKAGE, packageName)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PLAYER, playerName));
} }
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_FIND_PACKAGE, packageName));
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE)); }
} } else {
} sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_SET, pm.PLUGIN_NAME_LOWER_CASE));
}
}
} }

View File

@ -6,6 +6,7 @@ import java.util.Map;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.PluginMain;
@ -58,7 +59,10 @@ public class TagCmd implements Runnable {
} }
} }
OfflinePlayer player = pm.getOfflinePlayer(sender.getName()); OfflinePlayer player = pm.getOfflinePlayer(sender.getName());
PlayerTagShow.show(player.getPlayer(), type, itemList); Player p = player.getPlayer();
if (p != null) {
PlayerTagShow.show(p, type, itemList);
}
} else { } else {
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH)); sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_TAG, pm.PLUGIN_NAME_LOWER_CASE)); sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_TAG, pm.PLUGIN_NAME_LOWER_CASE));

View File

@ -11,119 +11,122 @@ import gg.frog.mc.permissionstime.utils.config.PluginConfig;
*/ */
public class LangCfg extends PluginConfig { public class LangCfg extends PluginConfig {
public static String INVENTORY_NAME = null; public static String INVENTORY_NAME = null;
public static String TAG_INVENTORY_NAME = null; public static String TAG_INVENTORY_NAME = null;
public static String EXPIRATION_TIME = null; public static String EXPIRATION_TIME = null;
public static String LEFT_TIME = null; public static String LEFT_TIME = null;
public static String TIME_UNIT_D = null; public static String TIME_UNIT_D = null;
public static String TIME_UNIT_H = null; public static String TIME_UNIT_H = null;
public static String TIME_UNIT_M = null; public static String TIME_UNIT_M = null;
public static String TIME_FOREVER = null; public static String TIME_FOREVER = null;
public static String TAG = null; public static String TAG = null;
public static String MSG_PARAMETER_MISMATCH = null; public static String MSG_PARAMETER_MISMATCH = null;
public static String MSG_TIME_PARAMETER_INCORRECT = null; public static String MSG_TIME_PARAMETER_INCORRECT = null;
public static String MSG_TIME_UNIT_PARAMETER_INCORRECT = null; public static String MSG_TIME_UNIT_PARAMETER_INCORRECT = null;
public static String MSG_PROCESSING = null; public static String MSG_PROCESSING = null;
public static String MSG_NO_DATA = null; public static String MSG_NO_DATA = null;
public static String MSG_PACKAGE_NUM = null; public static String MSG_NO_TAG_DATA = null;
public static String MSG_PACKAGE_LIST = null; public static String MSG_PACKAGE_NUM = null;
public static String MSG_PACKAGE_DETAIL = null; public static String MSG_PACKAGE_LIST = null;
public static String MSG_NO_PERMISSION = null; public static String MSG_PACKAGE_DETAIL = null;
public static String MSG_CONFIG_RELOADED = null; public static String MSG_NO_PERMISSION = null;
public static String MSG_FAIL_SET_PERMISSION = null; public static String MSG_CONFIG_RELOADED = null;
public static String MSG_NO_FIND_PLAYER = null; public static String MSG_FAIL_SET_PERMISSION = null;
public static String MSG_NO_FIND_PACKAGE = null; public static String MSG_NO_FIND_PLAYER = null;
public static String MSG_TELL_GIVE_PACKAGE = null; public static String MSG_NO_FIND_PACKAGE = null;
public static String MSG_GIVE_PACKAGE = null; public static String MSG_TELL_GIVE_PACKAGE = null;
public static String MSG_GIVE_PACKAGE_FAIL = null; public static String MSG_GIVE_PACKAGE = null;
public static String MSG_TELL_SET_PACKAGE = null; public static String MSG_GIVE_PACKAGE_FAIL = null;
public static String MSG_SET_PACKAGE = null; public static String MSG_TELL_SET_PACKAGE = null;
public static String MSG_SET_PACKAGE_FAIL = null; public static String MSG_SET_PACKAGE = null;
public static String MSG_TELL_DEL_PACKAGE = null; public static String MSG_SET_PACKAGE_FAIL = null;
public static String MSG_DEL_PACKAGE = null; public static String MSG_TELL_DEL_PACKAGE = null;
public static String MSG_DEL_PACKAGE_FAIL = null; public static String MSG_DEL_PACKAGE = null;
public static String MSG_TELL_DEL_ALL = null; public static String MSG_DEL_PACKAGE_FAIL = null;
public static String MSG_DEL_ALL = null; public static String MSG_TELL_DEL_ALL = null;
public static String MSG_DEL_ALL_FAIL = null; public static String MSG_DEL_ALL = null;
public static String MSG_NUM_OF_PACKAGES = null; public static String MSG_DEL_ALL_FAIL = null;
public static String MSG_EXPIRATION_DATE = null; public static String MSG_NUM_OF_PACKAGES = null;
public static String MSG_UNKNOWN_PACKAGE = null; public static String MSG_EXPIRATION_DATE = null;
public static String MSG_IS_EXPIRATION_DATE = null; public static String MSG_UNKNOWN_PACKAGE = null;
public static String MSG_FUNC_DISABLED = null; public static String MSG_IS_EXPIRATION_DATE = null;
public static String MSG_TAG_SET_SUCCESS = null; public static String MSG_FUNC_DISABLED = null;
public static String MSG_TAG_SET_SUCCESS = null;
public static String CMD_HELP = null; public static String CMD_HELP = null;
public static String CMD_ME = null; public static String CMD_ME = null;
public static String CMD_TAG = null; public static String CMD_TAG = null;
public static String CMD_PACKAGES = null; public static String CMD_PACKAGES = null;
public static String CMD_GET = null; public static String CMD_GET = null;
public static String CMD_GIVE = null; public static String CMD_GIVE = null;
public static String CMD_SET = null; public static String CMD_SET = null;
public static String CMD_REMOVE = null; public static String CMD_REMOVE = null;
public static String CMD_REMOVEALL = null; public static String CMD_REMOVEALL = null;
public static String CMD_RELOAD = null; public static String CMD_RELOAD = null;
public LangCfg(String fileName, PluginMain pm) { public LangCfg(String fileName, PluginMain pm) {
super(fileName, pm); super(fileName, pm);
} }
@Override @Override
protected void init() {} protected void init() {
}
@Override @Override
protected void loadToDo() { protected void loadToDo() {
INVENTORY_NAME = getConfig().getString("inventoryName", "&4===Permissions Packages==="); INVENTORY_NAME = getConfig().getString("inventoryName", "&4===Permissions Packages===");
TAG_INVENTORY_NAME = getConfig().getString("tagInventoryName", "&4===Tag Packages==="); TAG_INVENTORY_NAME = getConfig().getString("tagInventoryName", "&4===Tag Packages===");
EXPIRATION_TIME = getConfig().getString("expirationTime", "&4Expiration time: {0}"); EXPIRATION_TIME = getConfig().getString("expirationTime", "&4Expiration time: {0}");
LEFT_TIME = getConfig().getString("leftTime", "&4Left time: About {0}{1} {2}{3} {4}{5}"); LEFT_TIME = getConfig().getString("leftTime", "&4Left time: About {0}{1} {2}{3} {4}{5}");
TIME_UNIT_D = getConfig().getString("timeUnitD", "day(s)"); TIME_UNIT_D = getConfig().getString("timeUnitD", "day(s)");
TIME_UNIT_H = getConfig().getString("timeUnitH", "hour(s)"); TIME_UNIT_H = getConfig().getString("timeUnitH", "hour(s)");
TIME_UNIT_M = getConfig().getString("timeUnitM", "minute(s)"); TIME_UNIT_M = getConfig().getString("timeUnitM", "minute(s)");
TIME_FOREVER = getConfig().getString("timeForever", "Forever"); TIME_FOREVER = getConfig().getString("timeForever", "Forever");
TAG = getConfig().getString("tag", "Tag/Prefix"); TAG = getConfig().getString("tag", "Tag/Prefix");
MSG_PARAMETER_MISMATCH = getConfig().getString("msg.parameterMismatch", "&4Parameter mismatch."); MSG_PARAMETER_MISMATCH = getConfig().getString("msg.parameterMismatch", "&4Parameter mismatch.");
MSG_TIME_PARAMETER_INCORRECT = getConfig().getString("msg.timeParameterIncorrect", "&4The number of time is incorrect. Please enter a nonzero integer."); MSG_TIME_PARAMETER_INCORRECT = getConfig().getString("msg.timeParameterIncorrect", "&4The number of time is incorrect. Please enter a nonzero integer.");
MSG_TIME_UNIT_PARAMETER_INCORRECT = getConfig().getString("msg.timeUnitParameterIncorrect", "&4The number of time unit is incorrect. Please use d/h/m. (d=day, h=hour, m=minute)"); MSG_TIME_UNIT_PARAMETER_INCORRECT = getConfig().getString("msg.timeUnitParameterIncorrect", "&4The number of time unit is incorrect. Please use d/h/m. (d=day, h=hour, m=minute)");
MSG_PROCESSING = getConfig().getString("msg.processing", "&2Please wait for processing..."); MSG_PROCESSING = getConfig().getString("msg.processing", "&2Please wait for processing...");
MSG_NO_DATA = getConfig().getString("msg.noData", "&4No data for packages."); MSG_NO_DATA = getConfig().getString("msg.noData", "&4No data for packages.");
MSG_PACKAGE_NUM = getConfig().getString("msg.packageNum", "&4There are {0} kinds of permissions packages."); MSG_NO_TAG_DATA = getConfig().getString("msg.noTagData", "&4No data for tag packages.");
MSG_PACKAGE_LIST = getConfig().getString("msg.packageList", "{0}packageName: {1}, displayName: {2}"); MSG_PACKAGE_NUM = getConfig().getString("msg.packageNum", "&4There are {0} kinds of permissions packages.");
MSG_PACKAGE_DETAIL = getConfig().getString("msg.packageDetail", "packageName: {0}, displayName: {1}&r\\nPermissions: {2}\\nGroups: {3}"); MSG_PACKAGE_LIST = getConfig().getString("msg.packageList", "{0}packageName: {1}, displayName: {2}");
MSG_NO_PERMISSION = getConfig().getString("msg.nopermission", "&4You do not have permission to do this."); MSG_PACKAGE_DETAIL = getConfig().getString("msg.packageDetail", "packageName: {0}, displayName: {1}&r\\nPermissions: {2}\\nGroups: {3}");
MSG_CONFIG_RELOADED = getConfig().getString("msg.configReloaded", "&2Configuration overload is complete."); MSG_NO_PERMISSION = getConfig().getString("msg.nopermission", "&4You do not have permission to do this.");
MSG_FAIL_SET_PERMISSION = getConfig().getString("msg.failSetPermission", "&4Failed to modify permissions. Please re-enter the server!"); MSG_CONFIG_RELOADED = getConfig().getString("msg.configReloaded", "&2Configuration overload is complete.");
MSG_NO_FIND_PLAYER = getConfig().getString("msg.noFindPlayer", "&4Can not find player named &2{0}"); MSG_FAIL_SET_PERMISSION = getConfig().getString("msg.failSetPermission", "&4Failed to modify permissions. Please re-enter the server!");
MSG_NO_FIND_PACKAGE = getConfig().getString("msg.noFindPackage", "&4Can not find package named &2{0}"); MSG_NO_FIND_PLAYER = getConfig().getString("msg.noFindPlayer", "&4Can not find player named &2{0}");
MSG_TELL_GIVE_PACKAGE = getConfig().getString("msg.tellGivePackage", "&2{0} give you {1} package of {2}"); MSG_NO_FIND_PACKAGE = getConfig().getString("msg.noFindPackage", "&4Can not find package named &2{0}");
MSG_GIVE_PACKAGE = getConfig().getString("msg.givePackage", "&2Give the player {0} {1} package of {2}"); MSG_TELL_GIVE_PACKAGE = getConfig().getString("msg.tellGivePackage", "&2{0} give you {1} package of {2}");
MSG_GIVE_PACKAGE_FAIL = getConfig().getString("msg.givePackageFail", "&4Failed to give players {0} {1} package of {2}"); MSG_GIVE_PACKAGE = getConfig().getString("msg.givePackage", "&2Give the player {0} {1} package of {2}");
MSG_TELL_SET_PACKAGE = getConfig().getString("msg.tellSetPackage", "&2{0} set your package of {2} to {1}"); MSG_GIVE_PACKAGE_FAIL = getConfig().getString("msg.givePackageFail", "&4Failed to give players {0} {1} package of {2}");
MSG_SET_PACKAGE = getConfig().getString("msg.setPackage", "&2Set the player {0} {1} package of {2}"); MSG_TELL_SET_PACKAGE = getConfig().getString("msg.tellSetPackage", "&2{0} set your package of {2} to {1}");
MSG_SET_PACKAGE_FAIL = getConfig().getString("msg.setPackageFail", "&4Failed to set the player {0} {1} package of {2}"); MSG_SET_PACKAGE = getConfig().getString("msg.setPackage", "&2Set the player {0} {1} package of {2}");
MSG_TELL_DEL_PACKAGE = getConfig().getString("msg.tellDelPackage", "&4{0} deleted your package of {1}"); MSG_SET_PACKAGE_FAIL = getConfig().getString("msg.setPackageFail", "&4Failed to set the player {0} {1} package of {2}");
MSG_DEL_PACKAGE = getConfig().getString("msg.delPackage", "&2Remove package of {1}&2 for player {0}"); MSG_TELL_DEL_PACKAGE = getConfig().getString("msg.tellDelPackage", "&4{0} deleted your package of {1}");
MSG_DEL_PACKAGE_FAIL = getConfig().getString("msg.delPackageFail", "&4Failed to delete package of {1}&2 for player {0}"); MSG_DEL_PACKAGE = getConfig().getString("msg.delPackage", "&2Remove package of {1}&2 for player {0}");
MSG_TELL_DEL_ALL = getConfig().getString("msg.tellDelAll", "&4{0} remove all your packages"); MSG_DEL_PACKAGE_FAIL = getConfig().getString("msg.delPackageFail", "&4Failed to delete package of {1}&2 for player {0}");
MSG_DEL_ALL = getConfig().getString("msg.delAll", "&2Remove all packages for player {0}"); MSG_TELL_DEL_ALL = getConfig().getString("msg.tellDelAll", "&4{0} remove all your packages");
MSG_DEL_ALL_FAIL = getConfig().getString("msg.delAllFail", "&4Failed to remove all packages for player {0}"); MSG_DEL_ALL = getConfig().getString("msg.delAll", "&2Remove all packages for player {0}");
MSG_NUM_OF_PACKAGES = getConfig().getString("msg.numOfPackages", "====={0} has {1} packages====="); MSG_DEL_ALL_FAIL = getConfig().getString("msg.delAllFail", "&4Failed to remove all packages for player {0}");
MSG_EXPIRATION_DATE = getConfig().getString("msg.expirationDate", "{0}packages: {1}({2}), Expiration date: {3}, {4}"); MSG_NUM_OF_PACKAGES = getConfig().getString("msg.numOfPackages", "====={0} has {1} packages=====");
MSG_UNKNOWN_PACKAGE = getConfig().getString("msg.unknownPackage", "Unknown Packages"); MSG_EXPIRATION_DATE = getConfig().getString("msg.expirationDate", "{0}packages: {1}({2}), Expiration date: {3}, {4}");
MSG_IS_EXPIRATION_DATE = getConfig().getString("msg.isExpirationDate", "Your package: {0}({1})&r has expired."); MSG_UNKNOWN_PACKAGE = getConfig().getString("msg.unknownPackage", "Unknown Packages");
MSG_FUNC_DISABLED = getConfig().getString("msg.funcDisabled", "{0} functionality disabled."); MSG_IS_EXPIRATION_DATE = getConfig().getString("msg.isExpirationDate", "Your package: {0}({1})&r has expired.");
MSG_TAG_SET_SUCCESS = getConfig().getString("msg.tagSetSuccess", "&2Tag Set Success."); MSG_FUNC_DISABLED = getConfig().getString("msg.funcDisabled", "{0} functionality disabled.");
MSG_TAG_SET_SUCCESS = getConfig().getString("msg.tagSetSuccess", "&2Tag Set Success.");
CMD_HELP = getConfig().getString("cmd.help", "/{0} help \\n&7 - Show commands."); CMD_HELP = getConfig().getString("cmd.help", "/{0} help \\n&7 - Show commands.");
CMD_ME = getConfig().getString("cmd.me", "&6/{0} me \\n&7 - View your packages."); CMD_ME = getConfig().getString("cmd.me", "&6/{0} me \\n&7 - View your packages.");
CMD_TAG = getConfig().getString("cmd.tag", "&6/{0} tag <c/p/s> \\n&7 - View your color/prefix/suffix tags."); CMD_TAG = getConfig().getString("cmd.tag", "&6/{0} tag <c/p/s> \\n&7 - View your color/prefix/suffix tags.");
CMD_PACKAGES = getConfig().getString("cmd.packages", "&6/{0} packages [packageName] \\n&7 - View packages."); CMD_PACKAGES = getConfig().getString("cmd.packages", "&6/{0} packages [packageName] \\n&7 - View packages.");
CMD_GET = getConfig().getString("cmd.get", "&6/{0} get <playerName> \\n&7 - View player packages."); CMD_GET = getConfig().getString("cmd.get", "&6/{0} get <playerName> \\n&7 - View player packages.");
CMD_GIVE = getConfig().getString("cmd.give", "&6/{0} give <playerName> <packageName> <time> <timeUnit:d/h/m> \\n&7 - Give player package some time. (Time accumulation.) \\n&7 timeUnit: d=day, h=hour, m=minute"); CMD_GIVE = getConfig().getString("cmd.give", "&6/{0} give <playerName> <packageName> <time> <timeUnit:d/h/m> \\n&7 - Give player package some time. (Time accumulation.) \\n&7 timeUnit: d=day, h=hour, m=minute");
CMD_SET = getConfig().getString("cmd.set", "&6/{0} set <playerName> <packageName> <time> <timeUnit:d/h/m> \\n&7 - Set player package some time. \\n&7 timeUnit: d=day, h=hour, m=minute"); CMD_SET = getConfig().getString("cmd.set", "&6/{0} set <playerName> <packageName> <time> <timeUnit:d/h/m> \\n&7 - Set player package some time. \\n&7 timeUnit: d=day, h=hour, m=minute");
CMD_REMOVE = getConfig().getString("cmd.remove", "&6/{0} remove <playerName> <packageName> [t/f] \\n&7 - Remove player package. (t: Delete global package.)"); CMD_REMOVE = getConfig().getString("cmd.remove", "&6/{0} remove <playerName> <packageName> [t/f] \\n&7 - Remove player package. (t: Delete global package.)");
CMD_REMOVEALL = getConfig().getString("cmd.removeall", "&6/{0} removeall <playerName> [t/f] \\n&7 - Remove player all package. (t: Delete global packages.)"); CMD_REMOVEALL = getConfig().getString("cmd.removeall", "&6/{0} removeall <playerName> [t/f] \\n&7 - Remove player all package. (t: Delete global packages.)");
CMD_RELOAD = getConfig().getString("cmd.reload", "&6/{0} reload \\n&7 - Reloads the config file."); CMD_RELOAD = getConfig().getString("cmd.reload", "&6/{0} reload \\n&7 - Reloads the config file.");
} }
} }

View File

@ -8,11 +8,14 @@ import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.scoreboard.Scoreboard;
import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.model.cfg.PlayerTagBean; import gg.frog.mc.permissionstime.model.PlayerTagBean;
import gg.frog.mc.permissionstime.model.cfg.TagPackageBean; import gg.frog.mc.permissionstime.model.cfg.TagPackageBean;
import gg.frog.mc.permissionstime.utils.StrUtil; import gg.frog.mc.permissionstime.utils.StrUtil;
import gg.frog.mc.permissionstime.utils.config.PluginConfig; import gg.frog.mc.permissionstime.utils.config.PluginConfig;
@ -23,6 +26,8 @@ public class TagNameCfg extends PluginConfig {
public static String DEFAULT_NAMECOLOR = null; public static String DEFAULT_NAMECOLOR = null;
public static String DEFAULT_PREFIX = null; public static String DEFAULT_PREFIX = null;
public static String DEFAULT_SUFFIX = null; public static String DEFAULT_SUFFIX = null;
public static boolean USE_HD_PLUGIN = false;
public static Integer REFRESH_TAG_TIME = null;
public static Map<String, TagPackageBean> PACKAGES = new ConcurrentHashMap<>(); public static Map<String, TagPackageBean> PACKAGES = new ConcurrentHashMap<>();
public static Map<String, List<ItemStack>> NAMECOLOR_ITEMS = new ConcurrentHashMap<>(); public static Map<String, List<ItemStack>> NAMECOLOR_ITEMS = new ConcurrentHashMap<>();
@ -35,6 +40,10 @@ public class TagNameCfg extends PluginConfig {
public static Map<String, PlayerTagBean> PLAYER_TAG = new ConcurrentHashMap<>(); public static Map<String, PlayerTagBean> PLAYER_TAG = new ConcurrentHashMap<>();
public static Scoreboard scoreboard = null;
private BukkitTask task = null;
public enum TagType { public enum TagType {
NAMECOLOR_TYPE, PREFIX_TYPE, SUFFIX_TYPE NAMECOLOR_TYPE, PREFIX_TYPE, SUFFIX_TYPE
} }
@ -52,12 +61,15 @@ public class TagNameCfg extends PluginConfig {
DEFAULT_NAMECOLOR = setGetDefault("defaultNamecolor", ""); DEFAULT_NAMECOLOR = setGetDefault("defaultNamecolor", "");
DEFAULT_PREFIX = setGetDefault("defaultPrefix", ""); DEFAULT_PREFIX = setGetDefault("defaultPrefix", "");
DEFAULT_SUFFIX = setGetDefault("defaultSuffix", ""); DEFAULT_SUFFIX = setGetDefault("defaultSuffix", "");
USE_HD_PLUGIN = setGetDefault("useHdPlugin", false);
REFRESH_TAG_TIME = setGetDefault("refreshTagTime", -1);
PACKAGES = getObjMap("packages", TagPackageBean.class); PACKAGES = getObjMap("packages", TagPackageBean.class);
saveObj("packages", PACKAGES); saveObj("packages", PACKAGES);
if (PluginCfg.IS_DEBUG) { if (PluginCfg.IS_DEBUG) {
System.out.println("defaultNamecolor:" + DEFAULT_NAMECOLOR); System.out.println("defaultNamecolor:" + DEFAULT_NAMECOLOR);
System.out.println("defaultPrefix:" + DEFAULT_PREFIX); System.out.println("defaultPrefix:" + DEFAULT_PREFIX);
System.out.println("defaultSuffix:" + DEFAULT_SUFFIX); System.out.println("defaultSuffix:" + DEFAULT_SUFFIX);
System.out.println("useHdPlugin:" + USE_HD_PLUGIN);
for (Entry<String, TagPackageBean> p : PACKAGES.entrySet()) { for (Entry<String, TagPackageBean> p : PACKAGES.entrySet()) {
System.out.println(p.getKey() + ":" + p.getValue()); System.out.println(p.getKey() + ":" + p.getValue());
} }
@ -70,6 +82,8 @@ public class TagNameCfg extends PluginConfig {
PREFIX_PERMISSIONS.clear(); PREFIX_PERMISSIONS.clear();
SUFFIX_PERMISSIONS.clear(); SUFFIX_PERMISSIONS.clear();
PLAYER_TAG.clear();
for (Entry<String, TagPackageBean> e : PACKAGES.entrySet()) { for (Entry<String, TagPackageBean> e : PACKAGES.entrySet()) {
List<ItemStack> items = getTagItem(TagType.NAMECOLOR_TYPE, e.getValue()); List<ItemStack> items = getTagItem(TagType.NAMECOLOR_TYPE, e.getValue());
if (NAMECOLOR_ITEMS.containsKey(e.getValue().getPermissions())) { if (NAMECOLOR_ITEMS.containsKey(e.getValue().getPermissions())) {
@ -90,6 +104,25 @@ public class TagNameCfg extends PluginConfig {
SUFFIX_ITEMS.put(e.getValue().getPermissions(), items); SUFFIX_ITEMS.put(e.getValue().getPermissions(), items);
} }
} }
if (task != null) {
task.cancel();
}
refreshTagTask();
}
private void refreshTagTask() {
for (Player player : pm.getServer().getOnlinePlayers()) {
PlayerTagBean.initPlayerTag(player, pm);
}
if (REFRESH_TAG_TIME > 0) {
task = pm.getServer().getScheduler().runTaskLaterAsynchronously(pm, new Runnable() {
@Override
public void run() {
refreshTagTask();
}
}, REFRESH_TAG_TIME * 20);
}
} }
private List<ItemStack> getTagItem(TagType tagType, TagPackageBean tpb) { private List<ItemStack> getTagItem(TagType tagType, TagPackageBean tpb) {

View File

@ -14,126 +14,133 @@ import lib.PatPeter.SQLibrary.SQLite;
public class SqlManager { public class SqlManager {
private PluginMain pm; private PluginMain pm;
private Database db = null; private Database db = null;
private IPlayerDataDao pds = null; private IPlayerDataDao pds = null;
public SqlManager(PluginMain pm) { public SqlManager(PluginMain pm) {
this.pm = pm; this.pm = pm;
} }
public Database getDb() { public Database getDb() {
return db; return db;
} }
public boolean updateDatabase() { public boolean updateDatabase() {
if (db != null) { if (db != null) {
db.close(); db.close();
} }
if (PluginCfg.USE_MYSQL) { if (PluginCfg.USE_MYSQL) {
db = new MySQL(PluginMain.LOG, "[" + pm.PLUGIN_NAME + "] ", PluginCfg.SQL_HOSTNAME, PluginCfg.SQL_PORT, PluginCfg.SQL_DATABASE, PluginCfg.SQL_USERNAME, PluginCfg.SQL_PASSWORD); db = new MySQL(PluginMain.LOG, "[" + pm.PLUGIN_NAME + "] ", PluginCfg.SQL_HOSTNAME, PluginCfg.SQL_PORT, PluginCfg.SQL_DATABASE, PluginCfg.SQL_USERNAME, PluginCfg.SQL_PASSWORD);
pds = new MySQLPlayerDataDao(pm, this); pds = new MySQLPlayerDataDao(pm, this);
} else { } else {
db = new SQLite(PluginMain.LOG, "[" + pm.PLUGIN_NAME + "] ", pm.getDataFolder().getAbsolutePath(), "playerData", ".db"); db = new SQLite(PluginMain.LOG, "[" + pm.PLUGIN_NAME + "] ", pm.getDataFolder().getAbsolutePath(), "playerData", ".db");
pds = new SqlitePlayerDataDao(pm, this); pds = new SqlitePlayerDataDao(pm, this);
} }
if (db.open()) { if (db.open()) {
try { try {
if (!pds.tableExist()) { if (!pds.tableExist()) {
pds.creatTable(); pds.creatTable();
} }
return true; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
return false; return false;
} }
public List<PlayerDataBean> getAllTime(String uuid) { public List<PlayerDataBean> getAllTime(String uuid) {
for (int i = 0; i < 3; i++) { if (uuid != null)
try { for (int i = 0; i < 3; i++) {
return pds.queryPlayerData(uuid); try {
} catch (Exception e) { return pds.queryPlayerData(uuid);
e.printStackTrace(); } catch (Exception e) {
} e.printStackTrace();
} }
return Collections.emptyList(); }
} return Collections.emptyList();
}
public List<PlayerDataBean> getTime(String uuid) { public List<PlayerDataBean> getTime(String uuid) {
for (int i = 0; i < 3; i++) { if (uuid != null)
try { for (int i = 0; i < 3; i++) {
return pds.queryNotExpirePlayerData(uuid); try {
} catch (Exception e) { return pds.queryNotExpirePlayerData(uuid);
e.printStackTrace(); } catch (Exception e) {
} e.printStackTrace();
} }
return Collections.emptyList(); }
}
public boolean giveTime(String uuid, String packageName, int time) { return Collections.emptyList();
for (int i = 0; i < 3; i++) { }
try {
if (pds.addTime(uuid, packageName, time)) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
public boolean setTime(String uuid, String packageName, int time) { public boolean giveTime(String uuid, String packageName, int time) {
for (int i = 0; i < 3; i++) { if (uuid != null)
try { for (int i = 0; i < 3; i++) {
if (pds.setTime(uuid, packageName, time)) { try {
return true; if (pds.addTime(uuid, packageName, time)) {
} return true;
} catch (Exception e) { }
e.printStackTrace(); } catch (Exception e) {
} e.printStackTrace();
} }
return false; }
} return false;
}
public boolean removeTime(String uuid, String packageName) { public boolean setTime(String uuid, String packageName, int time) {
for (int i = 0; i < 3; i++) { if (uuid != null)
try { for (int i = 0; i < 3; i++) {
if (pds.delPlayData(uuid, packageName)) { try {
return true; if (pds.setTime(uuid, packageName, time)) {
} return true;
} catch (Exception e) { }
e.printStackTrace(); } catch (Exception e) {
} e.printStackTrace();
} }
return false; }
} return false;
}
public boolean removeAllTime(String uuid) { public boolean removeTime(String uuid, String packageName) {
for (int i = 0; i < 3; i++) { if (uuid != null)
try { for (int i = 0; i < 3; i++) {
if (pds.delPlayData(uuid)) { try {
return true; if (pds.delPlayData(uuid, packageName)) {
} return true;
} catch (Exception e) { }
e.printStackTrace(); } catch (Exception e) {
} e.printStackTrace();
} }
return false; }
} return false;
}
public boolean delById(Long id) { public boolean removeAllTime(String uuid) {
for (int i = 0; i < 3; i++) { if (uuid != null)
try { for (int i = 0; i < 3; i++) {
if (pds.delPlayData(id)) { try {
return true; if (pds.delPlayData(uuid)) {
} return true;
} catch (Exception e) { }
e.printStackTrace(); } catch (Exception e) {
} e.printStackTrace();
} }
return false; }
} return false;
}
public boolean delById(Long id) {
for (int i = 0; i < 3; i++) {
try {
if (pds.delPlayData(id)) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
} }

View File

@ -3,7 +3,7 @@ package gg.frog.mc.permissionstime.gui;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
@ -12,37 +12,36 @@ import gg.frog.mc.permissionstime.config.LangCfg;
import gg.frog.mc.permissionstime.config.PluginCfg; import gg.frog.mc.permissionstime.config.PluginCfg;
import gg.frog.mc.permissionstime.config.TagNameCfg; import gg.frog.mc.permissionstime.config.TagNameCfg;
import gg.frog.mc.permissionstime.config.TagNameCfg.TagType; import gg.frog.mc.permissionstime.config.TagNameCfg.TagType;
import gg.frog.mc.permissionstime.model.cfg.PlayerTagBean; import gg.frog.mc.permissionstime.model.PlayerTagBean;
import gg.frog.mc.permissionstime.utils.StrUtil; import gg.frog.mc.permissionstime.utils.StrUtil;
public class PlayerTagShow { public class PlayerTagShow {
public static void show(Player p, TagType tagType, List<ItemStack> itemList) { public static void show(OfflinePlayer p, TagType tagType, List<ItemStack> itemList) {
Inventory inventory = null; Inventory inventory = null;
int size = 0; int size = 0;
if (itemList.size() > 0) { if (itemList.size() > 0) {
inventory = Bukkit.createInventory(null, inventory = Bukkit.createInventory(null, (itemList.size() % 9 == 0 ? itemList.size() : (itemList.size() / 9 + 1) * 9), StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "&r&5&9&2&0&r"));
(itemList.size() % 9 == 0 ? itemList.size() : (itemList.size() / 9 + 1) * 9),
StrUtil.messageFormat(LangCfg.TAG_INVENTORY_NAME + "&r&5&9&2&0&r"));
String uuid = p.getUniqueId().toString(); String uuid = p.getUniqueId().toString();
PlayerTagBean playerTag = null; PlayerTagBean playerTag = null;
if (TagNameCfg.PLAYER_TAG.containsKey(uuid)) { if (TagNameCfg.PLAYER_TAG.containsKey(uuid)) {
playerTag = TagNameCfg.PLAYER_TAG.get(uuid); playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
playerTag = playerTag.clone(); playerTag = playerTag.clone();
if(playerTag != null) { if (playerTag != null) {
for (ItemStack item : itemList) { for (ItemStack item : itemList) {
ItemStack tItem = item.clone(); ItemStack tItem = item.clone();
ItemMeta meta = tItem.getItemMeta(); ItemMeta meta = tItem.getItemMeta();
List<String> lores = meta.getLore(); List<String> lores = meta.getLore();
String tag = lores.get(5); String tag = lores.get(5);
if(tagType == TagType.NAMECOLOR_TYPE) { if (tagType == TagType.NAMECOLOR_TYPE) {
meta.setDisplayName(meta.getDisplayName() + p.getName());
playerTag.setNamecolor(tag); playerTag.setNamecolor(tag);
}else if(tagType == TagType.PREFIX_TYPE) { } else if (tagType == TagType.PREFIX_TYPE) {
playerTag.setPrefix(tag); playerTag.setPrefix(tag);
}else if(tagType == TagType.SUFFIX_TYPE) { } else if (tagType == TagType.SUFFIX_TYPE) {
playerTag.setSuffix(tag); playerTag.setSuffix(tag);
} }
lores.set(1,"效果展示: "+playerTag.getDisplayNameStr(p)); lores.set(1, "效果展示: " + playerTag.getDisplayNameStr(p.getPlayer()));
meta.setLore(lores); meta.setLore(lores);
tItem.setItemMeta(meta); tItem.setItemMeta(meta);
inventory.addItem(tItem); inventory.addItem(tItem);
@ -52,9 +51,9 @@ public class PlayerTagShow {
} }
} }
if (inventory != null && size > 0) { if (inventory != null && size > 0) {
p.openInventory(inventory); p.getPlayer().openInventory(inventory);
} else { } else {
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_DATA)); p.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NO_TAG_DATA));
} }
} }
} }

View File

@ -16,8 +16,8 @@ import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.config.LangCfg; import gg.frog.mc.permissionstime.config.LangCfg;
import gg.frog.mc.permissionstime.config.PluginCfg; import gg.frog.mc.permissionstime.config.PluginCfg;
import gg.frog.mc.permissionstime.config.TagNameCfg; import gg.frog.mc.permissionstime.config.TagNameCfg;
import gg.frog.mc.permissionstime.model.PlayerTagBean;
import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean; import gg.frog.mc.permissionstime.model.cfg.PermissionPackageBean;
import gg.frog.mc.permissionstime.model.cfg.PlayerTagBean;
import gg.frog.mc.permissionstime.model.db.PlayerDataBean; import gg.frog.mc.permissionstime.model.db.PlayerDataBean;
import gg.frog.mc.permissionstime.utils.StrUtil; import gg.frog.mc.permissionstime.utils.StrUtil;
@ -35,23 +35,15 @@ public class MainListener implements Listener {
@Override @Override
public void run() { public void run() {
try { try {
List<PlayerDataBean> pdbList = pm.getSqlManager().getTime(event.getPlayer().getUniqueId().toString()); String uuid = pm.getPlayerUUIDByName(event.getPlayer().getName());
List<PlayerDataBean> pdbList = pm.getSqlManager().getTime(uuid);
PermissionPackageBean.reloadPlayerPermissions(event.getPlayer(), pdbList, pm, false); PermissionPackageBean.reloadPlayerPermissions(event.getPlayer(), pdbList, pm, false);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
event.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION)); event.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION));
} }
if (PluginCfg.TAG_SYSTEM) { if (PluginCfg.TAG_SYSTEM) {
String uuid = event.getPlayer().getUniqueId().toString(); PlayerTagBean.initPlayerTag(event.getPlayer(), pm);
PlayerTagBean playerTag = null;
if (TagNameCfg.PLAYER_TAG.containsKey(uuid)) {
playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
playerTag.setPlayerDisplayName(event.getPlayer());
} else {
playerTag = new PlayerTagBean("playerTag/" + uuid + ".yml", pm);
playerTag.setPlayerDisplayName(event.getPlayer(), true);
}
TagNameCfg.PLAYER_TAG.put(uuid, playerTag);
} }
} }
}).start(); }).start();

View File

@ -1,12 +1,8 @@
package gg.frog.mc.permissionstime.model.cfg; package gg.frog.mc.permissionstime.model;
import java.util.List;
import org.bukkit.World;
import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.PluginMain;
@ -30,6 +26,8 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
private String prefix; private String prefix;
// 后缀 // 后缀
private String suffix; private String suffix;
// 当前显示的名称
private String displayName;
public PlayerTagBean(String fileName, PluginMain pm) { public PlayerTagBean(String fileName, PluginMain pm) {
super(fileName, pm); super(fileName, pm);
@ -57,6 +55,18 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
super.saveConfig(); super.saveConfig();
} }
public static void initPlayerTag(Player player, PluginMain pm) {
String uuid = pm.getPlayerUUIDByName(player.getName());
PlayerTagBean playerTag = null;
if (TagNameCfg.PLAYER_TAG.containsKey(uuid)) {
playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
} else {
playerTag = new PlayerTagBean("playerTag/" + uuid + ".yml", pm);
TagNameCfg.PLAYER_TAG.put(uuid, playerTag);
}
playerTag.setPlayerDisplayName(player, true);
}
public void setPlayerDisplayName(Player player) { public void setPlayerDisplayName(Player player) {
setPlayerDisplayName(player, false); setPlayerDisplayName(player, false);
} }
@ -105,31 +115,59 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
} }
} }
if (forceSet || namecolor_flag || prefix_flag || suffix_flag) { if (forceSet || namecolor_flag || prefix_flag || suffix_flag) {
Scoreboard scoreboard = pm.getServer().getScoreboardManager().getNewScoreboard(); displayName = getDisplayNameStr(player);
Team team = scoreboard.getTeam(player.getName()); player.setDisplayName(displayName);
if (team == null) {
team = scoreboard.registerNewTeam(player.getName());
}
team.setPrefix(StrUtil.messageFormat(player, "&r" + prefix + "&r" + namecolor + "&r"));
team.setSuffix(StrUtil.messageFormat(player, "&r" + suffix + "&r"));
team.addEntry(player.getName());
player.setScoreboard(scoreboard);
List<World> worlds = pm.getServer().getWorlds();
for (World world : worlds) {
pm.getChat().setPlayerInfoString(world.getName(), player, "prefix", StrUtil.messageFormat(player, "&r" + prefix + "&r" + namecolor + "&r"));
pm.getChat().setPlayerInfoString(world.getName(), player, "suffix", StrUtil.messageFormat(player, "&r" + suffix + "&r"));
}
player.setDisplayName(getDisplayNameStr(player));
if (PluginCfg.IS_DEBUG) { if (PluginCfg.IS_DEBUG) {
System.out.println("PlayerTagBean:" + playerTag); System.out.println("PlayerTagBean:" + playerTag);
} }
if (!TagNameCfg.USE_HD_PLUGIN) {
try {
if (TagNameCfg.scoreboard == null) {
TagNameCfg.scoreboard = pm.getServer().getScoreboardManager().getNewScoreboard();
}
Team team = TagNameCfg.scoreboard.getTeam(player.getName());
if (team == null) {
team = TagNameCfg.scoreboard.registerNewTeam(player.getName());
}
String teamPrefix = StrUtil.messageFormat(player, prefix + "&r" + namecolor);
if (PluginCfg.IS_DEBUG)
System.out.println(teamPrefix);
teamPrefix = teamPrefix.length() > 16 ? (teamPrefix.substring(0, 7) + ".." + teamPrefix.substring(teamPrefix.length() - 7)) : teamPrefix;
if (PluginCfg.IS_DEBUG)
System.out.println(teamPrefix);
team.setPrefix(teamPrefix);
String teamSuffix = StrUtil.messageFormat(player, "&r" + suffix);
if (PluginCfg.IS_DEBUG)
System.out.println(teamSuffix);
teamSuffix = teamSuffix.length() > 16 ? (teamSuffix.substring(0, 7) + ".." + teamSuffix.substring(teamSuffix.length() - 7)) : teamSuffix;
if (PluginCfg.IS_DEBUG) {
System.out.println(teamSuffix);
}
team.setSuffix(teamSuffix);
team.addEntry(player.getName());
player.setScoreboard(TagNameCfg.scoreboard);
if (PluginCfg.IS_DEBUG)
for (Team t : TagNameCfg.scoreboard.getTeams()) {
System.out.println(t.getPrefix());
System.out.println(t.getSuffix());
for (String e : t.getEntries()) {
System.out.println(e);
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
//TODO
//player.setCustomNameVisible(false);
}
} }
} }
}); });
} }
public String getDisplayNameStr(Player player) { public String getDisplayNameStr(Player player) {
return StrUtil.messageFormat(player, prefix + namecolor + player.getName() + suffix + "&r"); return StrUtil.messageFormat(player, "&r" + prefix + "&r" + namecolor + player.getName() + "&r" + suffix + "&r");
} }
@Override @Override
@ -167,6 +205,10 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
this.suffix = suffix; this.suffix = suffix;
} }
public String getDisplayName() {
return displayName;
}
@Override @Override
public YamlConfiguration toConfig() { public YamlConfiguration toConfig() {
YamlConfiguration config = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();

View File

@ -11,7 +11,6 @@ import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.configuration.MemorySection; import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import gg.frog.mc.permissionstime.PluginMain; import gg.frog.mc.permissionstime.PluginMain;
@ -153,69 +152,69 @@ public class PermissionPackageBean implements IConfigBean {
return "PermissionPackageBean [displayName=" + displayName + ", id=" + id + ", type=" + type + ", glowing=" + glowing + ", lores=" + lores + ", global=" + global + ", permissions=" + permissions + ", groups=" + groups + ", expireCommands=" + expireCommands + "]"; return "PermissionPackageBean [displayName=" + displayName + ", id=" + id + ", type=" + type + ", glowing=" + glowing + ", lores=" + lores + ", global=" + global + ", permissions=" + permissions + ", groups=" + groups + ", expireCommands=" + expireCommands + "]";
} }
private void givePlayer(OfflinePlayer player, Server server, Permission permission) { private void givePlayer(OfflinePlayer player, Server server, Permission permissionApi) {
List<World> worlds = server.getWorlds(); List<World> worlds = server.getWorlds();
for (String pem : permissions) { for (String pem : this.permissions) {
String[] args = pem.split(":"); String[] args = pem.split(":");
pem = args[0]; pem = args[0];
if (args.length > 1) { if (args.length > 1) {
for (int i = 1; i < args.length; i++) { for (int i = 1; i < args.length; i++) {
String worldName = args[i]; String worldName = args[i];
permission.playerAdd(worldName, player, pem); permissionApi.playerAdd(worldName, player, pem);
} }
} else { } else {
for (World world : worlds) { for (World world : worlds) {
String worldName = world.getName(); String worldName = world.getName();
permission.playerAdd(worldName, player, pem); permissionApi.playerAdd(worldName, player, pem);
} }
} }
} }
for (String groupName : groups) { for (String groupName : this.groups) {
String[] args = groupName.split(":"); String[] args = groupName.split(":");
groupName = args[0]; groupName = args[0];
if (args.length > 1) { if (args.length > 1) {
for (int i = 1; i < args.length; i++) { for (int i = 1; i < args.length; i++) {
String worldName = args[i]; String worldName = args[i];
permission.playerAddGroup(worldName, player, groupName); permissionApi.playerAddGroup(worldName, player, groupName);
} }
} else { } else {
for (World world : worlds) { for (World world : worlds) {
String worldName = world.getName(); String worldName = world.getName();
permission.playerAddGroup(worldName, player, groupName); permissionApi.playerAddGroup(worldName, player, groupName);
} }
} }
} }
} }
private void clearPlayer(OfflinePlayer player, Server server, Permission permission) { private void clearPlayer(OfflinePlayer player, Server server, Permission permissionApi) {
List<World> worlds = server.getWorlds(); List<World> worlds = server.getWorlds();
for (String pem : permissions) { for (String pem : this.permissions) {
String[] args = pem.split(":"); String[] args = pem.split(":");
pem = args[0]; pem = args[0];
if (args.length > 1) { if (args.length > 1) {
for (int i = 1; i < args.length; i++) { for (int i = 1; i < args.length; i++) {
String worldName = args[i]; String worldName = args[i];
permission.playerRemove(worldName, player, pem); permissionApi.playerRemove(worldName, player, pem);
} }
} else { } else {
for (World world : worlds) { for (World world : worlds) {
String worldName = world.getName(); String worldName = world.getName();
permission.playerRemove(worldName, player, pem); permissionApi.playerRemove(worldName, player, pem);
} }
} }
} }
for (String groupName : groups) { for (String groupName : this.groups) {
String[] args = groupName.split(":"); String[] args = groupName.split(":");
groupName = args[0]; groupName = args[0];
if (args.length > 1) { if (args.length > 1) {
for (int i = 1; i < args.length; i++) { for (int i = 1; i < args.length; i++) {
String worldName = args[i]; String worldName = args[i];
permission.playerRemoveGroup(worldName, player, groupName); permissionApi.playerRemoveGroup(worldName, player, groupName);
} }
} else { } else {
for (World world : worlds) { for (World world : worlds) {
String worldName = world.getName(); String worldName = world.getName();
permission.playerRemoveGroup(worldName, player, groupName); permissionApi.playerRemoveGroup(worldName, player, groupName);
} }
} }
} }
@ -268,20 +267,28 @@ public class PermissionPackageBean implements IConfigBean {
addPpb.givePlayer(player, plugin.getServer(), plugin.getPermission()); addPpb.givePlayer(player, plugin.getServer(), plugin.getPermission());
} }
checkExpire(player, plugin); checkExpire(player, plugin);
BukkitTask task = taskMap.get(player.getUniqueId().toString()); String uuid = player.getUniqueId().toString();
BukkitTask task = taskMap.get(uuid);
if (pdbList.size() > 0) { if (pdbList.size() > 0) {
delay = (delay / 1000 + 1) * 20;// 1秒=20ticks delay = (delay / 1000 + 1) * 20;// 1秒=20ticks
task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
List<PlayerDataBean> tpdbList = plugin.getSqlManager().getTime(player.getUniqueId().toString()); List<PlayerDataBean> tpdbList = plugin.getSqlManager().getTime(uuid);
reloadPlayerPermissions(player, tpdbList, plugin); reloadPlayerPermissions(player, tpdbList, plugin);
} }
}, delay); }, delay);
taskMap.put(player.getUniqueId().toString(), task); taskMap.put(uuid, task);
} }
} }
/**
* 清理玩家所有权限包中涉及的权限
*
* @param player
* @param plugin
* @throws Exception
*/
public static void delPlayerAllPermissions(OfflinePlayer player, PluginMain plugin) throws Exception { public static void delPlayerAllPermissions(OfflinePlayer player, PluginMain plugin) throws Exception {
PermissionPackageBean subPpb = new PermissionPackageBean(); PermissionPackageBean subPpb = new PermissionPackageBean();
subPpb.getPermissions().addAll(PackagesCfg.allPermissions); subPpb.getPermissions().addAll(PackagesCfg.allPermissions);
@ -308,17 +315,14 @@ public class PermissionPackageBean implements IConfigBean {
plugin.getServer().getScheduler().runTask(plugin, new Runnable() { plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
Player p = player.getPlayer(); player.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_IS_EXPIRATION_DATE, packageBean != null ? packageBean.getDisplayName() : LangCfg.MSG_UNKNOWN_PACKAGE, playerData.getPackageName()));
if (p != null) { if (packageBean != null) {
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_IS_EXPIRATION_DATE, packageBean != null ? packageBean.getDisplayName() : LangCfg.MSG_UNKNOWN_PACKAGE, playerData.getPackageName())); for (String commands : packageBean.getExpireCommands()) {
if(packageBean !=null) { try {
for (String commands : packageBean.getExpireCommands()) { commands = StrUtil.messageFormat(player.getPlayer(), commands);
try { plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), commands);
commands = StrUtil.messageFormat(player.getPlayer(), commands); } catch (Exception e) {
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), commands); e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
} }
} }
} }

View File

@ -0,0 +1,51 @@
package gg.frog.mc.permissionstime.placeholder;
import org.bukkit.entity.Player;
import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.config.PluginCfg;
import gg.frog.mc.permissionstime.config.TagNameCfg;
import gg.frog.mc.permissionstime.model.PlayerTagBean;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
public class TagPlaceholder extends PlaceholderExpansion {
private PluginMain pm;
public TagPlaceholder(PluginMain pm) {
this.pm = pm;
}
public boolean persist() {
return true;
}
public String getIdentifier() {
return pm.PLUGIN_NAME_LOWER_CASE;
}
public String getPlugin() {
return null;
}
public String getAuthor() {
return "GeekFrog";
}
public String getVersion() {
return pm.PLUGIN_VERSION;
}
public String onPlaceholderRequest(Player player, String identifier) {
if (identifier.equalsIgnoreCase("displayname") && PluginCfg.TAG_SYSTEM) {
if (player != null) {
String uuid = pm.getPlayerUUIDByName(player.getName());
PlayerTagBean playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
if (playerTag != null) {
return playerTag.getDisplayName();
}
}
}
return null;
}
}

View File

@ -4,59 +4,50 @@ import java.text.MessageFormat;
import java.util.Date; import java.util.Date;
import org.apache.commons.lang.time.DateFormatUtils; import org.apache.commons.lang.time.DateFormatUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import gg.frog.mc.permissionstime.PluginMain;
import gg.frog.mc.permissionstime.config.LangCfg; import gg.frog.mc.permissionstime.config.LangCfg;
import gg.frog.mc.permissionstime.database.IPlayerDataDao; import gg.frog.mc.permissionstime.database.IPlayerDataDao;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
public class StrUtil { public class StrUtil {
private static final String dfs = "yyyy/MM/dd HH:mm:ss"; private static final String dfs = "yyyy/MM/dd HH:mm:ss";
private static final long dt = 24 * 60 * IPlayerDataDao.TIME_UNIT; private static final long dt = 24 * 60 * IPlayerDataDao.TIME_UNIT;
private static final long ht = 60 * IPlayerDataDao.TIME_UNIT; private static final long ht = 60 * IPlayerDataDao.TIME_UNIT;
private static final long mt = IPlayerDataDao.TIME_UNIT; private static final long mt = IPlayerDataDao.TIME_UNIT;
private static final boolean placeholderAPI;
static { public static String messageFormat(String src, Object... args) {
if(Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) { return MessageFormat.format(src, args).replace("&", "§").replace("\\n", "\n");
placeholderAPI = true; }
}else {
placeholderAPI = false;
}
}
public static String messageFormat(String src, Object... args) { public static String messageFormat(Player player, String src, Object... args) {
return MessageFormat.format(src, args).replace("&", "§").replace("\\n", "\n"); String message = MessageFormat.format(src, args).replace("&", "§").replace("\\n", "\n").replace("%player%", player.getPlayer().getDisplayName());
} if (PluginMain.enabledPlaceholder) {
message = PlaceholderAPI.setPlaceholders(player, message);
}
return message;
}
public static String messageFormat(Player player, String src, Object... args) { public static String timestampToString(long time) {
String message = MessageFormat.format(src, args).replace("&", "§").replace("\\n", "\n").replace("%player%", player.getDisplayName()); return DateFormatUtils.format(new Date(time), dfs);
if(placeholderAPI) { }
message = PlaceholderAPI.setPlaceholders(player, message);
}
return message;
}
public static String timestampToString(long time) { public static String dateToString(Date d) {
return DateFormatUtils.format(new Date(time), dfs); return DateFormatUtils.format(d, dfs);
} }
public static String dateToString(Date d) { public static String nowTimeString() {
return DateFormatUtils.format(d, dfs); return DateFormatUtils.format(new Date(), dfs);
} }
public static String nowTimeString() { public static String getLeftTime(long time) {
return DateFormatUtils.format(new Date(), dfs); long leftTime = time - new Date().getTime();
} long d = leftTime / dt;
long h = (leftTime % dt) / ht;
public static String getLeftTime(long time) { long m = (leftTime % ht) / mt;
long leftTime = time - new Date().getTime(); return messageFormat(LangCfg.LEFT_TIME, d, LangCfg.TIME_UNIT_D, h, LangCfg.TIME_UNIT_H, m, LangCfg.TIME_UNIT_M);
long d = leftTime / dt; }
long h = (leftTime % dt) / ht;
long m = (leftTime % ht) / mt;
return messageFormat(LangCfg.LEFT_TIME, d, LangCfg.TIME_UNIT_D, h, LangCfg.TIME_UNIT_H, m, LangCfg.TIME_UNIT_M);
}
} }

View File

@ -13,6 +13,7 @@ msg:
timeUnitParameterIncorrect: '&4The number of time unit is incorrect. Please use d/h/m. (d=day, h=hour, m=minute)' timeUnitParameterIncorrect: '&4The number of time unit is incorrect. Please use d/h/m. (d=day, h=hour, m=minute)'
processing: '&2Please wait for processing...' processing: '&2Please wait for processing...'
noData: '&4No data for packages.' noData: '&4No data for packages.'
noTagData: '&4No data for tag packages.'
packageNum: '&4There are {0} kinds of permissions packages.' packageNum: '&4There are {0} kinds of permissions packages.'
packageList: '{0}packageName: {1}, displayName: {2}' packageList: '{0}packageName: {1}, displayName: {2}'
packageDetail: 'packageName: {0}, displayName: {1}&r\nPermissions: {2}\nGroups: {3}' packageDetail: 'packageName: {0}, displayName: {1}&r\nPermissions: {2}\nGroups: {3}'

View File

@ -13,6 +13,7 @@ msg:
timeUnitParameterIncorrect: '&4时间单位不正确. 请使用 d或h或m. (d=天, h=小时, m=分钟)' timeUnitParameterIncorrect: '&4时间单位不正确. 请使用 d或h或m. (d=天, h=小时, m=分钟)'
processing: '&2执行中请等待...' processing: '&2执行中请等待...'
noData: '&4暂时无权限包.' noData: '&4暂时无权限包.'
noTagData: '&4暂时无称号包.'
packageNum: '&4共有{0}种权限包.' packageNum: '&4共有{0}种权限包.'
packageList: '{0}权限包名: {1}, 显示名称: {2}' packageList: '{0}权限包名: {1}, 显示名称: {2}'
packageDetail: '权限包名: {0}, 显示名称: {1}&r\n权限: {2}\n权限组: {3}' packageDetail: '权限包名: {0}, 显示名称: {1}&r\n权限: {2}\n权限组: {3}'

View File

@ -1,11 +1,13 @@
name: PermissionsTime name: PermissionsTime
version: 0.4.0-SNAPSHOT version: 0.4.0-SNAPSHOT
main: gg.frog.mc.permissionstime.PluginMain main: gg.frog.mc.permissionstime.PluginMain
author: GeekFrog author:
- GeekFrog
softdepend: softdepend:
- SQLibrary - SQLibrary
- Vault - Vault
- PlaceholderAPI - PlaceholderAPI
- HolographicDisplays
commands: commands:
permissionstime: permissionstime:
description: Show all commands. description: Show all commands.

View File

@ -7,6 +7,16 @@ defaultPrefix: ''
# 默认后缀. # 默认后缀.
# Default Suffix. # Default Suffix.
defaultSuffix: '' defaultSuffix: ''
# 使用HolographicDisplays显示称号
# use HolographicDisplays to show Tags
useHdPlugin: false
# 称号刷新周期(秒).
# 如果你你的称号使用了Placeholder请设置此项
# 推荐600秒以上. 设置-1则禁用刷新.
# Title refresh cycle (seconds).
# If you use Placeholder, please set.
# Recommend more than 600s. Set -1 to disable refresh.
refreshTagTime: -1
packages: packages:
# 称号包名称. # 称号包名称.
# Tag package name. # Tag package name.