版本更新至:3.76

调整:开发框架改为 Gradle
新增:Language2 工具新增 [book] 类型
This commit is contained in:
坏黑
2018-03-10 21:13:05 +08:00
parent 6439e4b780
commit ad1a21196f
238 changed files with 1686 additions and 1132 deletions

View File

@@ -0,0 +1,36 @@
package me.skymc.taboolib.timecycle;
import org.bukkit.plugin.Plugin;
import me.skymc.taboolib.other.DateUtils;
public class TimeCycle {
private String name;
private Plugin plugin;
private long cycle;
public TimeCycle(String name, long cycle, Plugin plugin) {
this.name = name;
this.cycle = cycle;
this.plugin = plugin;
long millisHour = DateUtils.getTime(DateUtils.HOUR_OF_DAY) * 60L * 60L * 1000L;
long millisMinute = DateUtils.getTime(DateUtils.MINUTE) * 60L * 1000L;
long time = System.currentTimeMillis() - millisHour - millisMinute;
}
public Plugin getPlugin() {
return plugin;
}
public String getName() {
return name;
}
public long getCycle() {
return cycle;
}
}

View File

@@ -0,0 +1,27 @@
package me.skymc.taboolib.timecycle;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class TimeCycleEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private TimeCycle cycle;
public TimeCycleEvent(TimeCycle cycle) {
super(true);
this.cycle = cycle;
}
public TimeCycle getCycle() {
return this.cycle;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@@ -0,0 +1,45 @@
package me.skymc.taboolib.timecycle;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class TimeCycleInitializeEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private TimeCycle cycle;
private Long time;
public TimeCycleInitializeEvent(TimeCycle cycle, Long time) {
super(true);
this.cycle = cycle;
this.time = time;
}
public TimeCycleInitializeEvent call() {
Bukkit.getPluginManager().callEvent(this);
return this;
}
public Long getTimeline() {
return time;
}
public void setTimeLine(Long time) {
this.time = time;
}
public TimeCycle getCycle() {
return this.cycle;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@@ -0,0 +1,172 @@
package me.skymc.taboolib.timecycle;
import java.util.Collection;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.database.GlobalDataManager;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.playerdata.DataUtils;
public class TimeCycleManager {
/**
* 最后一次更新: 2018年1月16日21:07:49
*
* @author sky
*/
private static ConcurrentHashMap<String, TimeCycle> cycles = new ConcurrentHashMap<>();
/**
* 获取周期管理器
*
* @param name
* @return
*/
public static TimeCycle getTimeCycle(String name) {
return cycles.get(name);
}
/**
* 获取所有周期管理器
*
* @return
*/
public static Collection<TimeCycle> getTimeCycles() {
return cycles.values();
}
/**
* 彻底删除周期数据
*
* @param name
*/
public static void deleteCycleData(String name) {
HashMap<String, String> map = GlobalDataManager.getVariables();
for (String _name : map.keySet()) {
if (_name.startsWith("timecycle")) {
GlobalDataManager.setVariable(name, null);
}
}
}
/**
* 注册周期管理器
*
* @param cycle
*/
public static void register(TimeCycle cycle) {
if (!cycles.containsKey(cycle.getName())) {
cycles.put(cycle.getName(), cycle);
}
else {
MsgUtils.warn("注册周期管理器 §8" + cycle.getName() + "§c 失败, 原因: &4名称重复");
}
}
/**
* 注销周期管理器
*
* @param name
* @return
*/
public static TimeCycle cancel(String name) {
return cycles.remove(name);
}
/**
* 注销插件所有周期管理器
*
* @param plugin
*/
public static void cancel(Plugin plugin) {
cycles.values().forEach(x -> {
if (x.getPlugin().equals(plugin)) {
cycles.remove(x.getName());
}
});
}
/**
* 设置上一次更新事件
*
* @param name
* @param time
*/
public static boolean setTimeline(String name, Long time) {
if (cycles.containsKey(name)) {
GlobalDataManager.setVariable("timecycle:" + name, time.toString());
return true;
}
return false;
}
/**
* 获取下一次刷新时间
*
* @param name
* @return
*/
public static long getAfterTimeline(String name) {
if (cycles.containsKey(name)) {
Long value = Long.valueOf(GlobalDataManager.getVariable("timecycle:" + name, "0"));
return value + cycles.get(name).getCycle();
}
return 0L;
}
/**
* 获取上一次刷新时间
*
* @param name
* @return
*/
public static long getBeforeTimeline(String name) {
if (cycles.containsKey(name)) {
return Long.valueOf(GlobalDataManager.getVariable("timecycle:" + name, "0"));
}
return 0L;
}
public static void load() {
// 注册调度器
new BukkitRunnable() {
@Override
public void run() {
for (TimeCycle cycle : cycles.values()) {
// 调度器没有被执行过
if (!GlobalDataManager.contains("timecycle:" + cycle.getName())) {
long time = new TimeCycleInitializeEvent(cycle, System.currentTimeMillis()).call().getTimeline();
// 初始化
GlobalDataManager.setVariable("timecycle:" + cycle.getName(), String.valueOf(time));
// 触发器
Bukkit.getPluginManager().callEvent(new TimeCycleEvent(cycle));
}
// 如果超出刷新时间
else if (System.currentTimeMillis() >= getAfterTimeline(cycle.getName())) {
long time = System.currentTimeMillis();
// 如果时间差大于 30 秒
if (time - getAfterTimeline(cycle.getName()) > 30000) {
// 初始化
time = new TimeCycleInitializeEvent(cycle, time).call().getTimeline();
}
// 重置
GlobalDataManager.setVariable("timecycle:" + cycle.getName(), String.valueOf(time));
// 触发器
Bukkit.getPluginManager().callEvent(new TimeCycleEvent(cycle));
}
}
}
}.runTaskTimerAsynchronously(Main.getInst(), 0, 20);
}
}