mirror of
https://github.com/geekfrog/PermissionsTime.git
synced 2024-11-21 23:08:48 +00:00
修复BUG
称号功能完善
This commit is contained in:
parent
d9435886bc
commit
3a9169e30b
12
pom.xml
12
pom.xml
@ -38,6 +38,10 @@
|
||||
<id>placeholderapi</id>
|
||||
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>filoghost-repo</id>
|
||||
<url>https://ci.filoghost.me/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@ -61,7 +65,7 @@
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.0.8</version>
|
||||
<version>LATEST</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -69,6 +73,12 @@
|
||||
<artifactId>SQLibrary</artifactId>
|
||||
<version>7.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
|
||||
<artifactId>holographicdisplays-api</artifactId>
|
||||
<version>2.2.7-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>PermissionsTime-${project.version}</finalName>
|
||||
|
@ -2,7 +2,8 @@ package gg.frog.mc.permissionstime;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bstats.bukkit.Metrics;
|
||||
@ -16,10 +17,10 @@ import gg.frog.mc.permissionstime.config.ConfigManager;
|
||||
import gg.frog.mc.permissionstime.config.PluginCfg;
|
||||
import gg.frog.mc.permissionstime.database.SqlManager;
|
||||
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.StrUtil;
|
||||
import gg.frog.mc.permissionstime.utils.UpdateCheck;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
public class PluginMain extends JavaPlugin {
|
||||
@ -34,7 +35,9 @@ public class PluginMain extends JavaPlugin {
|
||||
private PluginMain pm = null;
|
||||
private SqlManager sm = 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() {
|
||||
PLUGIN_NAME = getDescription().getName();
|
||||
@ -110,30 +113,44 @@ public class PluginMain extends JavaPlugin {
|
||||
return permission;
|
||||
}
|
||||
|
||||
public Chat getChat() {
|
||||
return chat;
|
||||
}
|
||||
|
||||
private boolean checkPluginDepends() {
|
||||
boolean needDepend = false;
|
||||
for (String name : DEPEND_PLUGIN.split(",")) {
|
||||
if (getServer().getPluginManager().getPlugin(name) == null) {
|
||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Need depend plugins : " + name));
|
||||
if (!getServer().getPluginManager().isPluginEnabled(name)) {
|
||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Need depend plugins : " + name + "."));
|
||||
needDepend = true;
|
||||
}
|
||||
}
|
||||
if (!needDepend && !setupPermissions()) {
|
||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t hook vault permission"));
|
||||
needDepend = true;
|
||||
}
|
||||
if (!needDepend && !setupChat()) {
|
||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t hook vault chat"));
|
||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t hook vault permission."));
|
||||
needDepend = true;
|
||||
}
|
||||
if (!needDepend && !setupDatabase()) {
|
||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t setup database"));
|
||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t setup database."));
|
||||
needDepend = true;
|
||||
}
|
||||
enabledPlaceholder = Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
|
||||
if (!enabledPlaceholder) {
|
||||
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."));
|
||||
} else {
|
||||
boolean placeholdersHook = false;
|
||||
try {
|
||||
placeholdersHook = new TagPlaceholder(pm).register();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
if (!placeholdersHook) {
|
||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4Cann''t hook placeholders"));
|
||||
getServer().getConsoleSender().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + "&4The placeholders '%permissionstime_displayname%' Cann''t use."));
|
||||
}
|
||||
}
|
||||
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."));
|
||||
}
|
||||
|
||||
if (needDepend) {
|
||||
return false;
|
||||
}
|
||||
@ -158,34 +175,32 @@ public class PluginMain extends JavaPlugin {
|
||||
return (permission != null);
|
||||
}
|
||||
|
||||
private boolean setupChat() {
|
||||
RegisteredServiceProvider<Chat> chatProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class);
|
||||
if (chatProvider != null) {
|
||||
chat = chatProvider.getProvider();
|
||||
}
|
||||
return (chat != null);
|
||||
}
|
||||
|
||||
private boolean setupDatabase() {
|
||||
sm = new SqlManager(pm);
|
||||
return sm.updateDatabase();
|
||||
}
|
||||
|
||||
public UUID getPlayerUUIDByName(String name) {
|
||||
public String getPlayerUUIDByName(String name) {
|
||||
OfflinePlayer p = getOfflinePlayer(name);
|
||||
if (p == null) {
|
||||
return null;
|
||||
} else {
|
||||
return p.getUniqueId();
|
||||
return p.getUniqueId().toString();
|
||||
}
|
||||
}
|
||||
|
||||
public OfflinePlayer getOfflinePlayer(String name) {
|
||||
for (OfflinePlayer p : getServer().getOfflinePlayers()) {
|
||||
if(p==null)
|
||||
if (name != null) {
|
||||
OfflinePlayer p1 = playerMap.get(name);
|
||||
if (p1 != null)
|
||||
return p1;
|
||||
for (OfflinePlayer p2 : getServer().getOfflinePlayers()) {
|
||||
if (p2 == null)
|
||||
continue;
|
||||
if (p.getName().equalsIgnoreCase(name)) {
|
||||
return p;
|
||||
if (p2.getName().equalsIgnoreCase(name)) {
|
||||
playerMap.put(name, p2);
|
||||
return p2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -2,7 +2,6 @@ package gg.frog.mc.permissionstime.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
@ -32,9 +31,9 @@ public class GetCmd implements Runnable {
|
||||
public void run() {
|
||||
if (args.length == 2) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
|
||||
OfflinePlayer p = pm.getOfflinePlayer(args[1]);
|
||||
if (p != null) {
|
||||
List<PlayerDataBean> ps = sm.getTime(p.getUniqueId().toString());
|
||||
String uuid = pm.getPlayerUUIDByName(args[1]);
|
||||
if (uuid != null) {
|
||||
List<PlayerDataBean> ps = sm.getTime(uuid);
|
||||
if (ps.size() > 0) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_NUM_OF_PACKAGES,
|
||||
args[1], ps.size()));
|
||||
|
@ -1,7 +1,6 @@
|
||||
package gg.frog.mc.permissionstime.command;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -67,15 +66,15 @@ public class GiveCmd implements Runnable {
|
||||
OfflinePlayer player = pm.getOfflinePlayer(playerName);
|
||||
if (player != null) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
|
||||
UUID uuid = player.getUniqueId();
|
||||
String uuid = player.getUniqueId().toString();
|
||||
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()) {
|
||||
Player p = player.getPlayer();
|
||||
try {
|
||||
List<PlayerDataBean> pdbList = sm.getTime(player.getUniqueId().toString());
|
||||
List<PlayerDataBean> pdbList = sm.getTime(uuid);
|
||||
PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -88,7 +87,7 @@ public class GiveCmd implements Runnable {
|
||||
pm.getServer().getScheduler().runTask(pm, new Runnable() {
|
||||
@Override
|
||||
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()));
|
||||
|
@ -2,7 +2,6 @@ package gg.frog.mc.permissionstime.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -35,8 +34,8 @@ public class MeCmd implements Runnable {
|
||||
if (isPlayer) {
|
||||
if (args.length == 1) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
|
||||
OfflinePlayer p = this.pm.getOfflinePlayer(sender.getName());
|
||||
List<PlayerDataBean> ps = sm.getTime(p.getUniqueId().toString());
|
||||
String uuid = pm.getPlayerUUIDByName(sender.getName());
|
||||
List<PlayerDataBean> ps = sm.getTime(uuid);
|
||||
PlayerPermissionShow.show((Player) sender, ps);
|
||||
} else {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
|
||||
|
@ -1,7 +1,6 @@
|
||||
package gg.frog.mc.permissionstime.command;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -40,15 +39,15 @@ public class RemoveAllCmd implements Runnable {
|
||||
OfflinePlayer player = pm.getOfflinePlayer(playerName);
|
||||
if (player != null) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
|
||||
UUID uuid = player.getUniqueId();
|
||||
String uuid = player.getUniqueId().toString();
|
||||
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()) {
|
||||
Player p = player.getPlayer();
|
||||
try {
|
||||
List<PlayerDataBean> pdbList = sm.getTime(player.getUniqueId().toString());
|
||||
List<PlayerDataBean> pdbList = sm.getTime(uuid);
|
||||
PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -61,7 +60,7 @@ public class RemoveAllCmd implements Runnable {
|
||||
pm.getServer().getScheduler().runTask(pm, new Runnable() {
|
||||
@Override
|
||||
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));
|
||||
|
@ -1,7 +1,6 @@
|
||||
package gg.frog.mc.permissionstime.command;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -44,15 +43,15 @@ public class RemoveCmd implements Runnable {
|
||||
OfflinePlayer player = pm.getOfflinePlayer(playerName);
|
||||
if (player != null) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
|
||||
UUID uuid = player.getUniqueId();
|
||||
String uuid = player.getUniqueId().toString();
|
||||
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()) {
|
||||
Player p = player.getPlayer();
|
||||
try {
|
||||
List<PlayerDataBean> pdbList = sm.getTime(player.getUniqueId().toString());
|
||||
List<PlayerDataBean> pdbList = sm.getTime(uuid);
|
||||
PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -65,7 +64,7 @@ public class RemoveCmd implements Runnable {
|
||||
pm.getServer().getScheduler().runTask(pm, new Runnable() {
|
||||
@Override
|
||||
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()));
|
||||
|
@ -1,7 +1,6 @@
|
||||
package gg.frog.mc.permissionstime.command;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -67,15 +66,16 @@ public class SetCmd implements Runnable {
|
||||
OfflinePlayer player = pm.getOfflinePlayer(playerName);
|
||||
if (player != null) {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PROCESSING));
|
||||
UUID uuid = player.getUniqueId();
|
||||
String uuid = player.getUniqueId().toString();
|
||||
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()) {
|
||||
Player p = player.getPlayer();
|
||||
if (p != null) {
|
||||
try {
|
||||
List<PlayerDataBean> pdbList = sm.getTime(player.getUniqueId().toString());
|
||||
List<PlayerDataBean> pdbList = sm.getTime(uuid);
|
||||
PermissionPackageBean.reloadPlayerPermissions(player, pdbList, pm);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -83,12 +83,14 @@ public class SetCmd implements Runnable {
|
||||
}
|
||||
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
|
||||
public void run() {
|
||||
pm.writeFailLog("Command execution failed. Set {0}({1}) {2} {3} Executor: {4}", playerName, player.getUniqueId().toString(), time + unitName, pack.getDisplayName(), sender.getName());
|
||||
pm.writeFailLog("Command execution failed. Set {0}({1}) {2} {3} Executor: {4}", playerName, uuid, time + unitName, pack.getDisplayName(), sender.getName());
|
||||
}
|
||||
});
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_SET_PACKAGE_FAIL, playerName, time + unitName, pack.getDisplayName()));
|
||||
|
@ -6,6 +6,7 @@ import java.util.Map;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
@ -58,7 +59,10 @@ public class TagCmd implements Runnable {
|
||||
}
|
||||
}
|
||||
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 {
|
||||
sender.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_PARAMETER_MISMATCH));
|
||||
sender.sendMessage(StrUtil.messageFormat(LangCfg.CMD_TAG, pm.PLUGIN_NAME_LOWER_CASE));
|
||||
|
@ -26,6 +26,7 @@ public class LangCfg extends PluginConfig {
|
||||
public static String MSG_TIME_UNIT_PARAMETER_INCORRECT = null;
|
||||
public static String MSG_PROCESSING = null;
|
||||
public static String MSG_NO_DATA = null;
|
||||
public static String MSG_NO_TAG_DATA = null;
|
||||
public static String MSG_PACKAGE_NUM = null;
|
||||
public static String MSG_PACKAGE_LIST = null;
|
||||
public static String MSG_PACKAGE_DETAIL = null;
|
||||
@ -69,7 +70,8 @@ public class LangCfg extends PluginConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {}
|
||||
protected void init() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadToDo() {
|
||||
@ -88,6 +90,7 @@ public class LangCfg extends PluginConfig {
|
||||
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_NO_DATA = getConfig().getString("msg.noData", "&4No data for packages.");
|
||||
MSG_NO_TAG_DATA = getConfig().getString("msg.noTagData", "&4No data for tag packages.");
|
||||
MSG_PACKAGE_NUM = getConfig().getString("msg.packageNum", "&4There are {0} kinds of permissions packages.");
|
||||
MSG_PACKAGE_LIST = getConfig().getString("msg.packageList", "{0}packageName: {1}, displayName: {2}");
|
||||
MSG_PACKAGE_DETAIL = getConfig().getString("msg.packageDetail", "packageName: {0}, displayName: {1}&r\\nPermissions: {2}\\nGroups: {3}");
|
||||
|
@ -8,11 +8,14 @@ import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
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.model.cfg.PlayerTagBean;
|
||||
import gg.frog.mc.permissionstime.model.PlayerTagBean;
|
||||
import gg.frog.mc.permissionstime.model.cfg.TagPackageBean;
|
||||
import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||
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_PREFIX = 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, 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 Scoreboard scoreboard = null;
|
||||
|
||||
private BukkitTask task = null;
|
||||
|
||||
public enum TagType {
|
||||
NAMECOLOR_TYPE, PREFIX_TYPE, SUFFIX_TYPE
|
||||
}
|
||||
@ -52,12 +61,15 @@ public class TagNameCfg extends PluginConfig {
|
||||
DEFAULT_NAMECOLOR = setGetDefault("defaultNamecolor", "");
|
||||
DEFAULT_PREFIX = setGetDefault("defaultPrefix", "");
|
||||
DEFAULT_SUFFIX = setGetDefault("defaultSuffix", "");
|
||||
USE_HD_PLUGIN = setGetDefault("useHdPlugin", false);
|
||||
REFRESH_TAG_TIME = setGetDefault("refreshTagTime", -1);
|
||||
PACKAGES = getObjMap("packages", TagPackageBean.class);
|
||||
saveObj("packages", PACKAGES);
|
||||
if (PluginCfg.IS_DEBUG) {
|
||||
System.out.println("defaultNamecolor:" + DEFAULT_NAMECOLOR);
|
||||
System.out.println("defaultPrefix:" + DEFAULT_PREFIX);
|
||||
System.out.println("defaultSuffix:" + DEFAULT_SUFFIX);
|
||||
System.out.println("useHdPlugin:" + USE_HD_PLUGIN);
|
||||
for (Entry<String, TagPackageBean> p : PACKAGES.entrySet()) {
|
||||
System.out.println(p.getKey() + ":" + p.getValue());
|
||||
}
|
||||
@ -70,6 +82,8 @@ public class TagNameCfg extends PluginConfig {
|
||||
PREFIX_PERMISSIONS.clear();
|
||||
SUFFIX_PERMISSIONS.clear();
|
||||
|
||||
PLAYER_TAG.clear();
|
||||
|
||||
for (Entry<String, TagPackageBean> e : PACKAGES.entrySet()) {
|
||||
List<ItemStack> items = getTagItem(TagType.NAMECOLOR_TYPE, e.getValue());
|
||||
if (NAMECOLOR_ITEMS.containsKey(e.getValue().getPermissions())) {
|
||||
@ -90,6 +104,25 @@ public class TagNameCfg extends PluginConfig {
|
||||
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) {
|
||||
|
@ -51,6 +51,7 @@ public class SqlManager {
|
||||
}
|
||||
|
||||
public List<PlayerDataBean> getAllTime(String uuid) {
|
||||
if (uuid != null)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
return pds.queryPlayerData(uuid);
|
||||
@ -62,6 +63,7 @@ public class SqlManager {
|
||||
}
|
||||
|
||||
public List<PlayerDataBean> getTime(String uuid) {
|
||||
if (uuid != null)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
return pds.queryNotExpirePlayerData(uuid);
|
||||
@ -69,10 +71,12 @@ public class SqlManager {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public boolean giveTime(String uuid, String packageName, int time) {
|
||||
if (uuid != null)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
if (pds.addTime(uuid, packageName, time)) {
|
||||
@ -86,6 +90,7 @@ public class SqlManager {
|
||||
}
|
||||
|
||||
public boolean setTime(String uuid, String packageName, int time) {
|
||||
if (uuid != null)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
if (pds.setTime(uuid, packageName, time)) {
|
||||
@ -99,6 +104,7 @@ public class SqlManager {
|
||||
}
|
||||
|
||||
public boolean removeTime(String uuid, String packageName) {
|
||||
if (uuid != null)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
if (pds.delPlayData(uuid, packageName)) {
|
||||
@ -112,6 +118,7 @@ public class SqlManager {
|
||||
}
|
||||
|
||||
public boolean removeAllTime(String uuid) {
|
||||
if (uuid != null)
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
if (pds.delPlayData(uuid)) {
|
||||
|
@ -3,7 +3,7 @@ package gg.frog.mc.permissionstime.gui;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
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.TagNameCfg;
|
||||
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;
|
||||
|
||||
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;
|
||||
int size = 0;
|
||||
if (itemList.size() > 0) {
|
||||
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"));
|
||||
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"));
|
||||
String uuid = p.getUniqueId().toString();
|
||||
PlayerTagBean playerTag = null;
|
||||
if (TagNameCfg.PLAYER_TAG.containsKey(uuid)) {
|
||||
playerTag = TagNameCfg.PLAYER_TAG.get(uuid);
|
||||
playerTag = playerTag.clone();
|
||||
if(playerTag != null) {
|
||||
if (playerTag != null) {
|
||||
for (ItemStack item : itemList) {
|
||||
ItemStack tItem = item.clone();
|
||||
ItemMeta meta = tItem.getItemMeta();
|
||||
List<String> lores = meta.getLore();
|
||||
String tag = lores.get(5);
|
||||
if(tagType == TagType.NAMECOLOR_TYPE) {
|
||||
if (tagType == TagType.NAMECOLOR_TYPE) {
|
||||
meta.setDisplayName(meta.getDisplayName() + p.getName());
|
||||
playerTag.setNamecolor(tag);
|
||||
}else if(tagType == TagType.PREFIX_TYPE) {
|
||||
} else if (tagType == TagType.PREFIX_TYPE) {
|
||||
playerTag.setPrefix(tag);
|
||||
}else if(tagType == TagType.SUFFIX_TYPE) {
|
||||
} else if (tagType == TagType.SUFFIX_TYPE) {
|
||||
playerTag.setSuffix(tag);
|
||||
}
|
||||
lores.set(1,"效果展示: "+playerTag.getDisplayNameStr(p));
|
||||
lores.set(1, "效果展示: " + playerTag.getDisplayNameStr(p.getPlayer()));
|
||||
meta.setLore(lores);
|
||||
tItem.setItemMeta(meta);
|
||||
inventory.addItem(tItem);
|
||||
@ -52,9 +51,9 @@ public class PlayerTagShow {
|
||||
}
|
||||
}
|
||||
if (inventory != null && size > 0) {
|
||||
p.openInventory(inventory);
|
||||
p.getPlayer().openInventory(inventory);
|
||||
} 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ import gg.frog.mc.permissionstime.PluginMain;
|
||||
import gg.frog.mc.permissionstime.config.LangCfg;
|
||||
import gg.frog.mc.permissionstime.config.PluginCfg;
|
||||
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.PlayerTagBean;
|
||||
import gg.frog.mc.permissionstime.model.db.PlayerDataBean;
|
||||
import gg.frog.mc.permissionstime.utils.StrUtil;
|
||||
|
||||
@ -35,23 +35,15 @@ public class MainListener implements Listener {
|
||||
@Override
|
||||
public void run() {
|
||||
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);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
event.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION));
|
||||
}
|
||||
if (PluginCfg.TAG_SYSTEM) {
|
||||
String uuid = event.getPlayer().getUniqueId().toString();
|
||||
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);
|
||||
PlayerTagBean.initPlayerTag(event.getPlayer(), pm);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
@ -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.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
@ -30,6 +26,8 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
|
||||
private String prefix;
|
||||
// 后缀
|
||||
private String suffix;
|
||||
// 当前显示的名称
|
||||
private String displayName;
|
||||
|
||||
public PlayerTagBean(String fileName, PluginMain pm) {
|
||||
super(fileName, pm);
|
||||
@ -57,6 +55,18 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
|
||||
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) {
|
||||
setPlayerDisplayName(player, false);
|
||||
}
|
||||
@ -105,31 +115,59 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
|
||||
}
|
||||
}
|
||||
if (forceSet || namecolor_flag || prefix_flag || suffix_flag) {
|
||||
Scoreboard scoreboard = pm.getServer().getScoreboardManager().getNewScoreboard();
|
||||
Team team = scoreboard.getTeam(player.getName());
|
||||
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));
|
||||
displayName = getDisplayNameStr(player);
|
||||
player.setDisplayName(displayName);
|
||||
if (PluginCfg.IS_DEBUG) {
|
||||
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) {
|
||||
return StrUtil.messageFormat(player, prefix + namecolor + player.getName() + suffix + "&r");
|
||||
return StrUtil.messageFormat(player, "&r" + prefix + "&r" + namecolor + player.getName() + "&r" + suffix + "&r");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -167,6 +205,10 @@ public class PlayerTagBean extends PluginConfig implements IConfigBean, Cloneabl
|
||||
this.suffix = suffix;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public YamlConfiguration toConfig() {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
@ -11,7 +11,6 @@ import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.MemorySection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
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 + "]";
|
||||
}
|
||||
|
||||
private void givePlayer(OfflinePlayer player, Server server, Permission permission) {
|
||||
private void givePlayer(OfflinePlayer player, Server server, Permission permissionApi) {
|
||||
List<World> worlds = server.getWorlds();
|
||||
for (String pem : permissions) {
|
||||
for (String pem : this.permissions) {
|
||||
String[] args = pem.split(":");
|
||||
pem = args[0];
|
||||
if (args.length > 1) {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
String worldName = args[i];
|
||||
permission.playerAdd(worldName, player, pem);
|
||||
permissionApi.playerAdd(worldName, player, pem);
|
||||
}
|
||||
} else {
|
||||
for (World world : worlds) {
|
||||
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(":");
|
||||
groupName = args[0];
|
||||
if (args.length > 1) {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
String worldName = args[i];
|
||||
permission.playerAddGroup(worldName, player, groupName);
|
||||
permissionApi.playerAddGroup(worldName, player, groupName);
|
||||
}
|
||||
} else {
|
||||
for (World world : worlds) {
|
||||
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();
|
||||
for (String pem : permissions) {
|
||||
for (String pem : this.permissions) {
|
||||
String[] args = pem.split(":");
|
||||
pem = args[0];
|
||||
if (args.length > 1) {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
String worldName = args[i];
|
||||
permission.playerRemove(worldName, player, pem);
|
||||
permissionApi.playerRemove(worldName, player, pem);
|
||||
}
|
||||
} else {
|
||||
for (World world : worlds) {
|
||||
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(":");
|
||||
groupName = args[0];
|
||||
if (args.length > 1) {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
String worldName = args[i];
|
||||
permission.playerRemoveGroup(worldName, player, groupName);
|
||||
permissionApi.playerRemoveGroup(worldName, player, groupName);
|
||||
}
|
||||
} else {
|
||||
for (World world : worlds) {
|
||||
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());
|
||||
}
|
||||
checkExpire(player, plugin);
|
||||
BukkitTask task = taskMap.get(player.getUniqueId().toString());
|
||||
String uuid = player.getUniqueId().toString();
|
||||
BukkitTask task = taskMap.get(uuid);
|
||||
if (pdbList.size() > 0) {
|
||||
delay = (delay / 1000 + 1) * 20;// 1秒=20ticks
|
||||
task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<PlayerDataBean> tpdbList = plugin.getSqlManager().getTime(player.getUniqueId().toString());
|
||||
List<PlayerDataBean> tpdbList = plugin.getSqlManager().getTime(uuid);
|
||||
reloadPlayerPermissions(player, tpdbList, plugin);
|
||||
}
|
||||
}, 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 {
|
||||
PermissionPackageBean subPpb = new PermissionPackageBean();
|
||||
subPpb.getPermissions().addAll(PackagesCfg.allPermissions);
|
||||
@ -308,10 +315,8 @@ public class PermissionPackageBean implements IConfigBean {
|
||||
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Player p = player.getPlayer();
|
||||
if (p != null) {
|
||||
p.sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_IS_EXPIRATION_DATE, packageBean != null ? packageBean.getDisplayName() : LangCfg.MSG_UNKNOWN_PACKAGE, playerData.getPackageName()));
|
||||
if(packageBean !=null) {
|
||||
player.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_IS_EXPIRATION_DATE, packageBean != null ? packageBean.getDisplayName() : LangCfg.MSG_UNKNOWN_PACKAGE, playerData.getPackageName()));
|
||||
if (packageBean != null) {
|
||||
for (String commands : packageBean.getExpireCommands()) {
|
||||
try {
|
||||
commands = StrUtil.messageFormat(player.getPlayer(), commands);
|
||||
@ -322,7 +327,6 @@ public class PermissionPackageBean implements IConfigBean {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
plugin.getSqlManager().delById(playerData.getId());
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -4,9 +4,9 @@ import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang.time.DateFormatUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import gg.frog.mc.permissionstime.PluginMain;
|
||||
import gg.frog.mc.permissionstime.config.LangCfg;
|
||||
import gg.frog.mc.permissionstime.database.IPlayerDataDao;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
@ -17,23 +17,14 @@ public class StrUtil {
|
||||
private static final long dt = 24 * 60 * IPlayerDataDao.TIME_UNIT;
|
||||
private static final long ht = 60 * IPlayerDataDao.TIME_UNIT;
|
||||
private static final long mt = IPlayerDataDao.TIME_UNIT;
|
||||
private static final boolean placeholderAPI;
|
||||
|
||||
static {
|
||||
if(Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
placeholderAPI = true;
|
||||
}else {
|
||||
placeholderAPI = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String messageFormat(String src, Object... args) {
|
||||
return MessageFormat.format(src, args).replace("&", "§").replace("\\n", "\n");
|
||||
}
|
||||
|
||||
public static String messageFormat(Player player, String src, Object... args) {
|
||||
String message = MessageFormat.format(src, args).replace("&", "§").replace("\\n", "\n").replace("%player%", player.getDisplayName());
|
||||
if(placeholderAPI) {
|
||||
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;
|
||||
|
@ -13,6 +13,7 @@ msg:
|
||||
timeUnitParameterIncorrect: '&4The number of time unit is incorrect. Please use d/h/m. (d=day, h=hour, m=minute)'
|
||||
processing: '&2Please wait for processing...'
|
||||
noData: '&4No data for packages.'
|
||||
noTagData: '&4No data for tag packages.'
|
||||
packageNum: '&4There are {0} kinds of permissions packages.'
|
||||
packageList: '{0}packageName: {1}, displayName: {2}'
|
||||
packageDetail: 'packageName: {0}, displayName: {1}&r\nPermissions: {2}\nGroups: {3}'
|
||||
|
@ -13,6 +13,7 @@ msg:
|
||||
timeUnitParameterIncorrect: '&4时间单位不正确. 请使用 d或h或m. (d=天, h=小时, m=分钟)'
|
||||
processing: '&2执行中,请等待...'
|
||||
noData: '&4暂时无权限包.'
|
||||
noTagData: '&4暂时无称号包.'
|
||||
packageNum: '&4共有{0}种权限包.'
|
||||
packageList: '{0}权限包名: {1}, 显示名称: {2}'
|
||||
packageDetail: '权限包名: {0}, 显示名称: {1}&r\n权限: {2}\n权限组: {3}'
|
||||
|
@ -1,11 +1,13 @@
|
||||
name: PermissionsTime
|
||||
version: 0.4.0-SNAPSHOT
|
||||
main: gg.frog.mc.permissionstime.PluginMain
|
||||
author: GeekFrog
|
||||
author:
|
||||
- GeekFrog
|
||||
softdepend:
|
||||
- SQLibrary
|
||||
- Vault
|
||||
- PlaceholderAPI
|
||||
- HolographicDisplays
|
||||
commands:
|
||||
permissionstime:
|
||||
description: Show all commands.
|
||||
|
@ -7,6 +7,16 @@ defaultPrefix: ''
|
||||
# 默认后缀.
|
||||
# Default Suffix.
|
||||
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:
|
||||
# 称号包名称.
|
||||
# Tag package name.
|
||||
|
Loading…
Reference in New Issue
Block a user