1
1
mirror of https://github.com/geekfrog/PermissionsTime.git synced 2024-11-28 03:48:48 +00:00

权限包到期可执行自定义命令

Signed-off-by: GeekFrog <admin@frog.gg>
This commit is contained in:
GeekFrog 2017-08-01 17:50:44 +08:00
commit 2efc629ea4
8 changed files with 329 additions and 258 deletions

View File

@ -51,6 +51,7 @@
- **提示权限包到期**
- **玩家登录时删除过期的或无效数据**
- **提示剩余时间**
- **权限包到期可执行自定义命令**
- 取消前置插件

View File

@ -42,3 +42,8 @@ packages:
groups:
- group1
- group2:world1
# 权限包过期后执行的控制台命令
# Package expire console commands.
expireCommands:
- 'bc %player% 的权限包到期了.'
- 'bc 请及时续期.'

12
pom.xml
View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>gg.frog.mc</groupId>
<artifactId>permissionstime</artifactId>
<version>0.2.4-SNAPSHOT</version>
<version>0.3.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>PermissionsTime</name>
<description>支持跨服的权限限时插件</description>
@ -34,6 +34,10 @@
<id>bstats-repo</id>
<url>http://repo.bstats.org/content/repositories/releases/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>
<dependencies>
<dependency>
@ -54,6 +58,12 @@
<version>1.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.0.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>lib.PatPeter.SQLibrary</groupId>
<artifactId>SQLibrary</artifactId>

View File

@ -39,6 +39,7 @@ public class PermissionPackageBean implements IConfigBean {
private Boolean global;
private List<String> permissions = new ArrayList<>();
private List<String> groups = new ArrayList<>();
private List<String> expireCommands = new ArrayList<>();
private static Map<String, BukkitTask> taskMap = new ConcurrentHashMap<>();
public String getDisplayName() {
@ -105,6 +106,14 @@ public class PermissionPackageBean implements IConfigBean {
this.groups = groups;
}
public List<String> getExpireCommands() {
return expireCommands;
}
public void setExpireCommands(List<String> expireCommands) {
this.expireCommands = expireCommands;
}
@Override
public YamlConfiguration toConfig() {
YamlConfiguration config = new YamlConfiguration();
@ -116,6 +125,7 @@ public class PermissionPackageBean implements IConfigBean {
config.set("global", global);
config.set("permissions", permissions);
config.set("groups", groups);
config.set("expireCommands", expireCommands);
return config;
}
@ -135,11 +145,14 @@ public class PermissionPackageBean implements IConfigBean {
global = config.getBoolean("global");
permissions = config.getStringList("permissions");
groups = config.getStringList("groups");
expireCommands = config.getStringList("expireCommands");
}
@Override
public String toString() {
return "PermissionPackageBean [displayName=" + displayName + ", id=" + id + ", type=" + type + ", glowing=" + glowing + ", lores=" + lores + ", global=" + global + ", permissions=" + permissions + ", groups=" + groups + "]";
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) {
@ -214,7 +227,8 @@ public class PermissionPackageBean implements IConfigBean {
reloadPlayerPermissions(player, pdbList, plugin, true);
}
public static void reloadPlayerPermissions(OfflinePlayer player, List<PlayerDataBean> pdbList, PluginMain plugin, boolean async) {
public static void reloadPlayerPermissions(OfflinePlayer player, List<PlayerDataBean> pdbList, PluginMain plugin,
boolean async) {
long delay = -1;
long now = new Date().getTime();
PermissionPackageBean addPpb = new PermissionPackageBean();
@ -248,7 +262,8 @@ public class PermissionPackageBean implements IConfigBean {
addPpb.givePlayer(player, plugin.getServer(), plugin.getPermission());
} catch (Exception e) {
e.printStackTrace();
player.getPlayer().sendMessage(StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION));
player.getPlayer().sendMessage(
StrUtil.messageFormat(PluginCfg.PLUGIN_PREFIX + LangCfg.MSG_FAIL_SET_PERMISSION));
}
}
});
@ -298,7 +313,18 @@ public class PermissionPackageBean implements IConfigBean {
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()));
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()) {
try {
commands = StrUtil.messageFormat(player.getPlayer(), commands);
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), commands);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
});

View File

@ -4,9 +4,12 @@ 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.config.LangCfg;
import gg.frog.mc.permissionstime.database.IPlayerDataDao;
import me.clip.placeholderapi.PlaceholderAPI;
public class StrUtil {
@ -14,11 +17,28 @@ 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) {
message = PlaceholderAPI.setPlaceholders(player, message);
}
return message;
}
public static String timestampToString(long time) {
return DateFormatUtils.format(new Date(time), dfs);
}

View File

@ -42,3 +42,8 @@ packages:
groups:
- group1
- group2:world1
# 权限包过期后执行的控制台命令
# Package expire console commands.
expireCommands:
- 'bc %player% 的权限包到期了.'
- 'bc 请及时续期.'

View File

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

View File

@ -3,7 +3,7 @@
[align=center][table=98%,#4169e1]
[tr][td][align=center][size=6][color=#ffffff][b]唠叨[/b][/color][/size][/align][/td][/tr]
[/table][/align][align=center][table=98%,gray]
[tr][td][align=center][size=4][color=#ffa500][b]这是本人第一个发布的插件, 希望能让大家满意![/b][/color][/size][/align][align=center][size=4][color=#dda0dd][b]本插件需要JAVA8[/b][/color][/size][/align][align=center][size=4][color=#98fb98][b]下载地址在最下面![/b][/color][/size][/align][align=center][size=4][color=#c0c0c0][b]最新版本: [/b][/color][b][color=#8b0000]0.2.3[/color][color=#c0c0c0]推荐大家使用新版本只需替换插件的jar包和语言文件即可[/color][/b][/size][/align][/td][/tr]
[tr][td][align=center][size=4][color=#ffa500][b]这是本人第一个发布的插件, 希望能让大家满意![/b][/color][/size][/align][align=center][size=4][color=#dda0dd][b]本插件需要JAVA8[/b][/color][/size][/align][align=center][size=4][color=#98fb98][b]下载地址在最下面![/b][/color][/size][/align][align=center][size=4][color=#c0c0c0][b]最新版本: [/b][/color][b][color=#8b0000]0.3.0[/color][color=#c0c0c0]推荐大家使用新版本只需替换插件的jar包和语言文件即可[/color][/b][/size][/align][/td][/tr]
[/table][/align][align=center][table=98%,#4169e1]
[tr][td][align=center][size=6][color=#ffffff][b]前言[/b][/color][/size][/align][/td][/tr]
[/table][/align][align=center][table=98%,gray]
@ -197,6 +197,11 @@ cmd:
[tr][td][align=center][size=6][color=#ffffff][b]更新日志[/b][/color][/size][/align][/td][/tr]
[/table][/align][align=center][table=98%,gray]
[tr][td][spoiler][size=4][b][url=http://ci.frog.gg/jenkins/job/PermissionsTime/changes]详细的更新记录[/url]
[color=#ffffff]2017年8月1日 V0.3.0[/color][quote][color=#000000]
1.权限包到期可执行自定义命令[/color][/quote]
[color=#ffffff]2017年7月31日 V0.2.4[/color][quote][color=#000000]
1.插件统计更换成bstats
2.兼容服务端文件夹路径含有空格字符[/color][/quote]
[color=#ffffff]2017年7月27日 V0.2.3[/color][quote][color=#000000]
1.取消保存配置文件
2.语言文件整理[/color][/quote]
@ -221,15 +226,13 @@ cmd:
[/table][/align][align=center][table=98%,#4169e1]
[tr][td][align=center][size=6][color=#ffffff][b]下载地址[/b][/color][/size][/align][/td][/tr]
[/table][/align][align=center][table=98%,gray]
[tr][td][size=4][b][align=center][color=#000] [url=http://ci.frog.gg/jenkins/job/PermissionsTime/57/]V0.2.3版下载地址[/url][/color][/align][align=center][color=#ffffff]前置插件:[/color][color=#000][url=https://dev.bukkit.org/projects/vault/files]vault[/url][/color][color=#000000] , [/color][color=#000][url=https://dev.bukkit.org/projects/sqlibrary/files]sqlibrary[/url][/color][/align][align=center][color=#ffffff]前置插件最好去原站下载适合的版本, 如果无法下载可以在帖内下载。[/color][/align]
[tr][td][size=4][b][align=center][color=#000] [url=http://ci.frog.gg/jenkins/job/PermissionsTime/63/]V0.3.0版下载地址[/url][/color][/align][align=center][color=#ffffff]前置插件:[/color][color=#000][url=https://dev.bukkit.org/projects/vault/files]vault[/url][/color][color=#000000] , [/color][color=#000][url=https://dev.bukkit.org/projects/sqlibrary/files]sqlibrary[/url][/color][/align][align=center][color=#ffffff]前置插件最好去原站下载适合的版本, 如果无法下载可以在帖内下载。[/color][/align]
[align=center][b][color=#ffffff]帖内下载:[/color][/b][/align][align=center][color=#000][attach]1101088[/attach][/color][/align][align=center][color=#000][b][color=#ff0000]前置插件必须安装[/color][/b][/color][/align][align=center][color=#000][attach]1101089[/attach][/color][/align][align=center][color=#000][attach]1101090[/attach][/color][/align][align=center][color=#000][attach]1101110[/attach][/color][/align]
[align=center][color=#000][color=#ff0000][b]如果大家觉得好用就给点金粒吧,如果不好请告诉我,帮助我改进。[/b][/color][/color][/align][align=center][color=#000][b]BUG可以在帖内回复我。[/b][/color][/align][/b][/size][/td][/tr]
[/table][/align][align=center][table=98%,#4169e1]
[tr][td][align=center][size=6][color=#ffffff][b]使用统计[/b][/color][/size][/align][/td][/tr]
[/table][/align][align=center][table=98%,gray]
[tr][td][align=center][b][size=4][color=#ff0000]图片可能经常抽风[/color][/size][/b][/align]
[align=center][img]http://i.mcstats.org/PermissionsTime/Global+Statistics.borderless.png[/img][/align]
[align=center][img]http://i.mcstats.org/PermissionsTime/Version+Demographics.borderless.png[/img][/align][/td][/tr]
[tr][td][align=center][url=https://bstats.org/plugin/bukkit/PermissionsTime][size=4][b]https://bstats.org/plugin/bukkit/PermissionsTime[/b][/size][/url][/align][/td][/tr]
[/table][/align][align=center][table=98%,#4169e1]
[tr][td][align=center][size=6][color=#ffffff][b]此插件已加入我的世界公益插件计划[/b][/color][/size][/align][/td][/tr]
[/table][/align][align=center][table=98%,gray]