1
0
mirror of https://e.coding.net/circlecloud/MiaoBoard.git synced 2024-11-25 02:19:07 +00:00

feat: 添加自定义显示时间 添加剩余时间变量

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-08-21 01:04:08 +08:00
parent 96baee6208
commit 8954c688a7
6 changed files with 88 additions and 15 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId> <groupId>pw.yumc</groupId>
<artifactId>MiaoBoard</artifactId> <artifactId>MiaoBoard</artifactId>
<version>1.4.4</version> <version>1.4.5</version>
<name>MiaoBoard</name> <name>MiaoBoard</name>
<build> <build>
<finalName>${project.name}</finalName> <finalName>${project.name}</finalName>

View File

@ -6,6 +6,11 @@ import pw.yumc.MiaoBoard.model.BoardModel;
public class Checker { public class Checker {
public static boolean $(final Player player, final BoardModel model) { public static boolean $(final Player player, final BoardModel model) {
return player.hasPermission(model.permission); return player.hasPermission(model.permission) && dataCheck(model);
}
public static boolean dataCheck(final BoardModel model) {
final long now = System.currentTimeMillis();
return model.time_start != null && model.time_start.getTime() <= now && model.time_end != null && now <= model.time_end.getTime();
} }
} }

View File

@ -1,6 +1,9 @@
package pw.yumc.MiaoBoard.misc; package pw.yumc.MiaoBoard.misc;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -26,6 +29,8 @@ public class Replace {
static class SimpleRelpace { static class SimpleRelpace {
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("[%]([^%]+)[%]"); private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("[%]([^%]+)[%]");
private static final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static final String EMPTY = "";
public static String $(final Player player, String text) { public static String $(final Player player, String text) {
final Matcher m = PLACEHOLDER_PATTERN.matcher(text); final Matcher m = PLACEHOLDER_PATTERN.matcher(text);
@ -44,6 +49,9 @@ public class Replace {
case "plugin": case "plugin":
value = plugin(player, ka[1]); value = plugin(player, ka[1]);
break; break;
case "time":
value = time(player, ka[1]);
break;
} }
text = text.replace("%" + format + "%", Matcher.quoteReplacement(value)); text = text.replace("%" + format + "%", Matcher.quoteReplacement(value));
} }
@ -59,6 +67,10 @@ public class Replace {
return String.valueOf(player.getLocation().getBlockY()); return String.valueOf(player.getLocation().getBlockY());
case "z": case "z":
return String.valueOf(player.getLocation().getBlockZ()); return String.valueOf(player.getLocation().getBlockZ());
case "yaw":
return String.valueOf(Math.round(player.getLocation().getYaw() * 100) / 100);
case "pitch":
return String.valueOf(Math.round(player.getLocation().getPitch() * 100) / 100);
case "world": case "world":
return player.getWorld().getName(); return player.getWorld().getName();
case "name": case "name":
@ -70,7 +82,7 @@ public class Replace {
case "max_health": case "max_health":
return String.valueOf(player.getMaxHealth()); return String.valueOf(player.getMaxHealth());
default: default:
return ""; return EMPTY;
} }
} }
@ -83,7 +95,7 @@ public class Replace {
case "author": case "author":
return Arrays.toString(P.getDescription().getAuthors().toArray()); return Arrays.toString(P.getDescription().getAuthors().toArray());
default: default:
return ""; return EMPTY;
} }
} }
@ -101,8 +113,39 @@ public class Replace {
case "ram_max": case "ram_max":
return String.valueOf(runtime.maxMemory() / 1048576L); return String.valueOf(runtime.maxMemory() / 1048576L);
default: default:
return ""; return EMPTY;
} }
} }
private static String time(final Player player, final String key) {
final Date date = new Date();
if (key.startsWith("left") && key.contains("_")) {
final String time = key.split("_")[1].replace("`", " ");
String value = "解析错误";
try {
final long left = df.parse(time).getTime() - System.currentTimeMillis();
value = String.valueOf(left / 1000);
} catch (final ParseException e) {
}
return value;
}
switch (key) {
case "now":
return df.format(date);
case "year":
return String.valueOf(date.getYear() + 1900);
case "month":
return String.valueOf(date.getMonth() + 1);
case "day":
return String.valueOf(date.getDate());
case "hour":
return String.valueOf(date.getHours() + 1);
case "minute":
return String.valueOf(date.getMinutes());
case "second":
return String.valueOf(date.getSeconds());
}
return EMPTY;
}
} }
} }

View File

@ -1,5 +1,6 @@
package pw.yumc.MiaoBoard.model; package pw.yumc.MiaoBoard.model;
import java.util.Date;
import java.util.List; import java.util.List;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -13,7 +14,10 @@ import cn.citycraft.PluginHelper.config.InjectConfigurationSection;
* @author * @author
*/ */
public class BoardModel extends InjectConfigurationSection { public class BoardModel extends InjectConfigurationSection {
public int index; public transient String name;
public Integer index;
public Date time_start;
public Date time_end;
public String title; public String title;
public String permission; public String permission;
public List<String> lines; public List<String> lines;
@ -26,4 +30,16 @@ public class BoardModel extends InjectConfigurationSection {
public BoardModel(final ConfigurationSection config) { public BoardModel(final ConfigurationSection config) {
super(config); super(config);
} }
/**
* 设置模型名称
*
* @param name
* 名称
* @return {@link BoardModel}
*/
public BoardModel setName(final String name) {
this.name = name;
return this;
}
} }

View File

@ -1,8 +1,8 @@
package pw.yumc.MiaoBoard.scoreboard; package pw.yumc.MiaoBoard.scoreboard;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -28,7 +28,7 @@ public class ScoreBoardManager {
public static Status cot = new Status(); public static Status cot = new Status();
public static SidebarBoard sbd = new SidebarBoard(P.instance, new BoardUpdateFunction(new TitleUpdater(), new BodyUpdater())); public static SidebarBoard sbd = new SidebarBoard(P.instance, new BoardUpdateFunction(new TitleUpdater(), new BodyUpdater()));
public static FileConfig config = MiaoBoardConfig.i().getConfig();; public static FileConfig config = MiaoBoardConfig.i().getConfig();;
public static List<BoardModel> bms = new ArrayList<>(); public static List<BoardModel> bms = new LinkedList<>();
public static List<BoardModel> getModels() { public static List<BoardModel> getModels() {
return bms; return bms;
@ -41,7 +41,7 @@ public class ScoreBoardManager {
public static void load() { public static void load() {
bms.clear(); bms.clear();
for (final String bmn : config.getConfigurationSection("Boards").getKeys(false)) { for (final String bmn : config.getConfigurationSection("Boards").getKeys(false)) {
bms.add(new BoardModel(config.getConfigurationSection("Boards." + bmn))); bms.add(new BoardModel(config.getConfigurationSection("Boards." + bmn)).setName(bmn));
} }
Collections.sort(bms, new BoardComparator()); Collections.sort(bms, new BoardComparator());
} }
@ -54,7 +54,7 @@ public class ScoreBoardManager {
} }
public static void start() { public static void start() {
sbd.update(cot, MiaoBoardConfig.UpdateTime); sbd.update(cot.set(true), MiaoBoardConfig.UpdateTime);
for (final Player player : C.Player.getOnlinePlayers()) { for (final Player player : C.Player.getOnlinePlayers()) {
sbd.addTarget(player); sbd.addTarget(player);
} }
@ -63,7 +63,7 @@ public class ScoreBoardManager {
private static class BoardComparator implements Comparator<BoardModel> { private static class BoardComparator implements Comparator<BoardModel> {
@Override @Override
public int compare(final BoardModel o1, final BoardModel o2) { public int compare(final BoardModel o1, final BoardModel o2) {
return o2.index > o1.index ? 1 : 0; return o1.index.compareTo(o2.index);
} }
} }

View File

@ -10,13 +10,19 @@ DisableWorld:
Boards: Boards:
#默认记分板 #默认记分板
default: default:
#记分板顺序(将按照从小到大依次检测 比如 1-5 优先检测 1 符合则显示 不符合 检测 2 ...) #记分板顺序(将按照从小到大依次检测 比如 1-50 优先检测 1 符合则显示 不符合 检测 2 ...)
index: 50 index: 50
#显示时间(格式为yyyy-MM-dd HH:mm:ss)
time:
start: '2016-01-01 00:00:00'
end: '2020-01-01 00:00:00'
#记分板标题 #记分板标题
title: '记分板简介' title: '喵式记分板简介'
#记分板权限 #记分板权限
permission: mb.default permission: mb.default
#记分板内容(不得超过38个字符 包括颜色字符 超过部分自动截取) #记分板内容
#注意 不得超过38个字符 包括颜色字符 超过部分自动截取
#注意 不得超过15行 超出部分 自动忽略
lines: lines:
- '&6插件名称: &a%plugin_name%' - '&6插件名称: &a%plugin_name%'
- '&7------------------------------' - '&7------------------------------'
@ -28,5 +34,8 @@ Boards:
- '&7------------------------------' - '&7------------------------------'
- '&6您所在的位置: &b%player_world% &a%player_x%,%player_y%,%player_z%' - '&6您所在的位置: &b%player_world% &a%player_x%,%player_y%,%player_z%'
- '&7------------------------------' - '&7------------------------------'
- '&6您所在的角度: &bYaw &a%player_yaw% &bPitch &a%player_pitch%'
- '&7------------------------------'
- '&6服务器使用内存: &a%server_ram_used%/%server_ram_total%' - '&6服务器使用内存: &a%server_ram_used%/%server_ram_total%'
- '&7------------------------------' - '&7------------------------------'
- '&6离2017年还剩: &a%time_left_2017-01-01`00:00:00%秒'