版本更新至 3.56

调整:命令 /lang2 提示调整
调整:命令 /tlib 提示改为 JSON 形式
调整:命令 /tlm 需要独立的权限才能列出帮助,子命令的执行不需要列出帮助的权限
新增:命令 /taboo cycle list 列出所有已注册的时间周期
新增:命令 /taboo cycle info 查询已注册的时间周期
新增:命令 /taboo cycle reset 初始化已注册的时间周期
新增:命令 /taboo cycle update 更新已注册的时间周期
新增:Language2 工具新增 send(CommandSender) 方法
新增:PlaceholderAPI 变量 %taboolib_tlm_kit_礼包名% 用于获取礼包状态
新增:TLM 框架新增 Kits 模块,用于管理礼包的发放
新增:命令 /tlm kit reward 领取礼包
新增:命令 /tlm kit reset 刷新礼包
新增:TLM 框架新增语言文件 "language2/zh_CN.yml"
This commit is contained in:
坏黑 2018-02-18 16:37:22 +08:00
parent 4f10fb502f
commit 3984c81658
21 changed files with 906 additions and 71 deletions

View File

@ -15,6 +15,7 @@ import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.commands.sub.AttributesCommand;
import me.skymc.taboolib.commands.sub.EnchantCommand;
import me.skymc.taboolib.commands.sub.FlagCommand;
import me.skymc.taboolib.commands.sub.HelpCommand;
import me.skymc.taboolib.commands.sub.ImportCommand;
import me.skymc.taboolib.commands.sub.InfoCommand;
import me.skymc.taboolib.commands.sub.ItemCommand;
@ -23,6 +24,7 @@ import me.skymc.taboolib.commands.sub.SaveCommand;
import me.skymc.taboolib.commands.sub.SlotCommand;
import me.skymc.taboolib.commands.sub.VariableGetCommand;
import me.skymc.taboolib.commands.sub.VariableSetCommand;
import me.skymc.taboolib.commands.sub.cycle.CycleCommand;
import me.skymc.taboolib.commands.sub.itemlist.ItemListCommand;
import me.skymc.taboolib.commands.sub.shell.ShellCommand;
import me.skymc.taboolib.inventory.ItemUtils;
@ -32,30 +34,8 @@ public class MainCommands implements CommandExecutor{
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (args.length == 0) {
sender.sendMessage("§f");
sender.sendMessage("§b§l----- §3§lTaooLib Commands §b§l-----");
sender.sendMessage("§f");
sender.sendMessage("§7 /taboolib save [名称] §f- §8保存手中物品");
sender.sendMessage("§7 /taboolib item/i [物品] <玩家> <数量> §f- §8给予玩家物品");
sender.sendMessage("§7 /taboolib iteminfo §f- §8查看物品信息");
sender.sendMessage("§7 /taboolib itemlist §f- §8查看所有物品");
sender.sendMessage("§7 /taboolib itemreload/ireload §f- §8重载物品缓存");
sender.sendMessage("§f");
sender.sendMessage("§7 /taboolib attributes §f- §8查看所有属性");
sender.sendMessage("§7 /taboolib enchants §f- §8查看所有附魔");
sender.sendMessage("§7 /taboolib potions §f- §8查看所有药水");
sender.sendMessage("§7 /taboolib flags §f- §8查看所有标签");
sender.sendMessage("§7 /taboolib slots §f- §8查看所有部位");
sender.sendMessage("§f");
sender.sendMessage("§7 /taboolib getvariable [-s|a] [键] §f- §8查看变量");
sender.sendMessage("§7 /taboolib setvariable [-s|a] [键] [值] §f- §8更改变量");
sender.sendMessage("§f");
sender.sendMessage("§7 /taboolib shell/s load [脚本] §f- §8载入某个脚本");
sender.sendMessage("§7 /taboolib shell/s unload [脚本] §f- §8卸载某个脚本");
sender.sendMessage("§f");
sender.sendMessage("§c /taboolib importdata §f- §4向数据库导入本地数据 §8(该操作将会清空数据库)");
sender.sendMessage("§f");
if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
new HelpCommand(sender, args);
}
else if (args[0].equalsIgnoreCase("itemreload") || args[0].equalsIgnoreCase("ireload")) {
ItemUtils.reloadItemCache();
@ -101,6 +81,9 @@ public class MainCommands implements CommandExecutor{
else if (args[0].equalsIgnoreCase("shell") || args[0].equalsIgnoreCase("s")) {
new ShellCommand(sender, args);
}
else if (args[0].equalsIgnoreCase("cycle") || args[0].equalsIgnoreCase("c")) {
new CycleCommand(sender, args);
}
else {
MsgUtils.send(sender, "&4Ö¸Áî´íÎó");
}

View File

@ -21,10 +21,10 @@ public class Language2Command implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (args.length == 0) {
sender.sendMessage("¡ìf");
sender.sendMessage("§b§l----- §3§lTabooLib Commands §b§l-----");
sender.sendMessage("§b§l----- §3§lLanguage2 Commands §b§l-----");
sender.sendMessage("¡ìf");
sender.sendMessage("§7 /language2 reload §f- §8重载语言库");
sender.sendMessage("§7 /language2 send [玩家] [语言] <变量> §f- §8发送语言提示");
sender.sendMessage("§f /language2 send §8[§7玩家§8] §8[§7语言§8] §8<§7变量§8> §6- §e发送语言提示");
sender.sendMessage("§f /language2 reload §6- §e重载语言库");
sender.sendMessage("¡ìf");
}
else if (args[0].equalsIgnoreCase("reload")) {

View File

@ -0,0 +1,80 @@
package me.skymc.taboolib.commands.sub;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.jsonformatter.JSONFormatter;
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
public class HelpCommand extends SubCommand {
public HelpCommand(CommandSender sender, String[] args) {
super(sender, args);
HashMap<String, String> helps = new LinkedHashMap<>();
helps.put("/taboolib save §8[§7名称§8]", "§e保存手中物品");
helps.put("/taboolib item §8[§7名称§8] §8<§7玩家§8> §8<§7数量§8>", "§e给予玩家物品");
helps.put("/taboolib iteminfo", "§e查看物品信息");
helps.put("/taboolib itemlist", "§e查看所有物品");
helps.put("/taboolib itemreload", "§e重载物品缓存");
helps.put("§a", null);
helps.put("/taboolib attributes", "§e查看所有属性");
helps.put("/taboolib enchants", "§e查看所有附魔");
helps.put("/taboolib potions", "§e查看所有药水");
helps.put("/taboolib flags", "§e查看所有标签");
helps.put("/taboolib slots", "§e查看所有部位");
helps.put("§b", null);
helps.put("/taboolib getvariable §8[§7-s|a§8] §8[§7键§8]", "§e查看变量");
helps.put("/taboolib setvariable §8[§7-s|a§8] §8[§7键§8] §8[§7值§8]", "§e更改变量");
helps.put("§c", null);
helps.put("/taboolib cycle list", "§e列出所有时间检查器");
helps.put("/taboolib cycle info §8[§7名称§8]", "§e查询检查器信息");
helps.put("/taboolib cycle reset §8[§7名称§8]", "§e初始化时间检查器");
helps.put("/taboolib cycle update §8[§7名称§8]", "§e更新时间检查器");
helps.put("§d", null);
helps.put("/taboolib shell load §8[§7名称§8]", "§e载入某个脚本");
helps.put("/taboolib shell unload §8[§7名称§8]", "§e卸载某个脚本");
helps.put("§e", null);
helps.put("/taboolib importdata", "§4向数据库导入本地数据 §8(该操作将会清空数据库)");
if (sender instanceof ConsoleCommandSender || TabooLib.getVerint() < 10800) {
sender.sendMessage("§f");
sender.sendMessage("§b§l----- §3§lTaooLib Commands §b§l-----");
sender.sendMessage("§f");
// 遍历命令
for (Entry<String, String> entry : helps.entrySet()) {
if (entry.getValue() == null) {
sender.sendMessage("§f");
} else {
sender.sendMessage("§f " + entry.getKey() + " §6- " + entry.getValue());
}
}
sender.sendMessage("§f");
}
else if (sender instanceof Player) {
JSONFormatter json = new JSONFormatter();
json.append("§f"); json.newLine();
json.append("§b§l----- §3§lTaooLib Commands §b§l-----"); json.newLine();
json.append("§f"); json.newLine();
// 遍历命令
for (Entry<String, String> entry : helps.entrySet()) {
if (entry.getValue() == null) {
json.append("§f"); json.newLine();
} else {
json.appendHoverClick("§f " + entry.getKey() + " §6- " + entry.getValue(), new ShowTextEvent("§f点击复制指令"), new SuggestCommandEvent(entry.getKey().split("§")[0])); json.newLine();
}
}
json.append("§f");
json.send((Player) sender);
}
}
}

View File

@ -0,0 +1,39 @@
package me.skymc.taboolib.commands.sub.cycle;
import java.io.File;
import org.bukkit.command.CommandSender;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.javashell.JavaShell;
import me.skymc.taboolib.message.MsgUtils;
public class CycleCommand extends SubCommand {
public CycleCommand(CommandSender sender, String[] args) {
super(sender, args);
if (args.length > 1) {
if (args[1].equalsIgnoreCase("list")) {
new CycleListCommand(sender, args);
}
else if (args[1].equalsIgnoreCase("info")) {
new CycleInfoCommand(sender, args);
}
else if (args[1].equalsIgnoreCase("reset")) {
new CycleResetCommand(sender, args);
}
else if (args[1].equalsIgnoreCase("update")) {
new CycleUpdateCommand(sender, args);
}
}
else {
MsgUtils.send(sender, "&4Ö¸Áî´íÎó");
}
}
@Override
public boolean command() {
return true;
}
}

View File

@ -0,0 +1,58 @@
package me.skymc.taboolib.commands.sub.cycle;
import java.util.concurrent.TimeUnit;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.database.GlobalDataManager;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.other.DateUtils;
import me.skymc.taboolib.timecycle.TimeCycle;
import me.skymc.taboolib.timecycle.TimeCycleEvent;
import me.skymc.taboolib.timecycle.TimeCycleInitializeEvent;
import me.skymc.taboolib.timecycle.TimeCycleManager;
public class CycleInfoCommand extends SubCommand {
public CycleInfoCommand(CommandSender sender, String[] args) {
super(sender, args);
if (args.length < 3) {
MsgUtils.send(sender, "&c请输入正确的检查器名称");
return;
}
TimeCycle cycle = TimeCycleManager.getTimeCycle(args[2]);
if (cycle == null) {
MsgUtils.send(sender, "&c检查器 &4" + args[2] + " &c不存在");
return;
}
sender.sendMessage("§f");
sender.sendMessage("§b§l----- §3§lTimeCycle Info §b§l-----");
sender.sendMessage("§f");
sender.sendMessage(" §f- §7注册周期: §f" + asString(cycle.getCycle() / 1000L));
sender.sendMessage(" §f- §7注册插件: §f" + cycle.getPlugin().getName());
sender.sendMessage("§f");
sender.sendMessage(" §f- §7上次刷新时间: §f" + DateUtils.CH_ALL.format(TimeCycleManager.getBeforeTimeline(cycle.getName())));
sender.sendMessage(" §f- §7下次刷新时间: §f" + DateUtils.CH_ALL.format(TimeCycleManager.getAfterTimeline(cycle.getName())));
sender.sendMessage("§f");
}
public String asString(long seconds) {
long day = TimeUnit.SECONDS.toDays(seconds);
long hours = TimeUnit.SECONDS.toHours(seconds) - day * 24;
long minute = TimeUnit.SECONDS.toMinutes(seconds) - TimeUnit.SECONDS.toHours(seconds) * 60L;
long second = TimeUnit.SECONDS.toSeconds(seconds) - TimeUnit.SECONDS.toMinutes(seconds) * 60L;
return "§f" + day + "§7 天, §f" + hours + "§7 小时, §f" + minute + "§7 分钟, §f" + second + "§7 秒";
}
@Override
public boolean command() {
return true;
}
}

View File

@ -0,0 +1,47 @@
package me.skymc.taboolib.commands.sub.cycle;
import java.io.File;
import java.util.concurrent.TimeUnit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.javashell.JavaShell;
import me.skymc.taboolib.jsonformatter.JSONFormatter;
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.timecycle.TimeCycle;
import me.skymc.taboolib.timecycle.TimeCycleManager;
public class CycleListCommand extends SubCommand {
public CycleListCommand(CommandSender sender, String[] args) {
super(sender, args);
sender.sendMessage("§f");
sender.sendMessage("§b§l----- §3§lTimeCycle List §b§l-----");
sender.sendMessage("§f");
for (TimeCycle cycle : TimeCycleManager.getTimeCycles()) {
if (isPlayer()) {
JSONFormatter json = new JSONFormatter();
json.append(" §7- §f" + cycle.getName());
json.appendHoverClick(" §8(点击复制)", new ShowTextEvent("§f点击复制"), new SuggestCommandEvent(cycle.getName()));
json.send((Player) sender);
}
else {
sender.sendMessage(" §7- §f" + cycle.getName());
}
}
sender.sendMessage("§f");
}
@Override
public boolean command() {
return true;
}
}

View File

@ -0,0 +1,51 @@
package me.skymc.taboolib.commands.sub.cycle;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.database.GlobalDataManager;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.timecycle.TimeCycle;
import me.skymc.taboolib.timecycle.TimeCycleEvent;
import me.skymc.taboolib.timecycle.TimeCycleInitializeEvent;
import me.skymc.taboolib.timecycle.TimeCycleManager;
public class CycleResetCommand extends SubCommand {
public CycleResetCommand(CommandSender sender, String[] args) {
super(sender, args);
if (args.length < 3) {
MsgUtils.send(sender, "&c请输入正确的检查器名称");
return;
}
TimeCycle cycle = TimeCycleManager.getTimeCycle(args[2]);
if (cycle == null) {
MsgUtils.send(sender, "&c检查器 &4" + args[2] + " &c不存在");
return;
}
new BukkitRunnable() {
@Override
public void run() {
long time = new TimeCycleInitializeEvent(cycle, System.currentTimeMillis()).call().getTimeline();
// 初始化
GlobalDataManager.setVariable("timecycle:" + cycle.getName(), String.valueOf(time));
// 触发器
Bukkit.getPluginManager().callEvent(new TimeCycleEvent(cycle));
// 提示
MsgUtils.send(sender, "检查器 &f" + args[2] + " &7初始化完成");
}
}.runTaskAsynchronously(Main.getInst());
}
@Override
public boolean command() {
return true;
}
}

View File

@ -0,0 +1,50 @@
package me.skymc.taboolib.commands.sub.cycle;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.database.GlobalDataManager;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.timecycle.TimeCycle;
import me.skymc.taboolib.timecycle.TimeCycleEvent;
import me.skymc.taboolib.timecycle.TimeCycleInitializeEvent;
import me.skymc.taboolib.timecycle.TimeCycleManager;
public class CycleUpdateCommand extends SubCommand {
public CycleUpdateCommand(CommandSender sender, String[] args) {
super(sender, args);
if (args.length < 3) {
MsgUtils.send(sender, "&c请输入正确的检查器名称");
return;
}
TimeCycle cycle = TimeCycleManager.getTimeCycle(args[2]);
if (cycle == null) {
MsgUtils.send(sender, "&c检查器 &4" + args[2] + " &c不存在");
return;
}
new BukkitRunnable() {
@Override
public void run() {
// 重置
GlobalDataManager.setVariable("timecycle:" + cycle.getName(), String.valueOf(System.currentTimeMillis()));
// 触发器
Bukkit.getPluginManager().callEvent(new TimeCycleEvent(cycle));
// 提示
MsgUtils.send(sender, "检查器 &f" + args[2] + " &7已更新");
}
}.runTaskAsynchronously(Main.getInst());
}
@Override
public boolean command() {
return true;
}
}

View File

@ -185,6 +185,20 @@ public class Language2Value {
}
}
/**
* 向指令发送者发送信息
*
* @param sender
*/
public void send(CommandSender sender) {
if (sender instanceof Player) {
send((Player) sender);
}
else {
send(Bukkit.getPlayerExact(""));
}
}
/**
* 获取文本
*

View File

@ -5,6 +5,9 @@ import org.bukkit.plugin.Plugin;
import me.clip.placeholderapi.external.EZPlaceholderHook;
import me.skymc.taboolib.database.GlobalDataManager;
import me.skymc.tlm.TLM;
import me.skymc.tlm.module.TabooLibraryModule;
import me.skymc.tlm.module.sub.ModuleKits;
public class SupportPlaceholder extends EZPlaceholderHook {
@ -22,6 +25,42 @@ public class SupportPlaceholder extends EZPlaceholderHook {
}
return GlobalDataManager.getVariableAsynchronous(sb.substring(0, sb.length() - 1), "<none>");
}
if (args.startsWith("tlm_kit_")) {
// 是否启用
if (TabooLibraryModule.getInst().valueOf("Kits") == null) {
return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.0").asString();
}
// 获取模块
ModuleKits moduleKits = (ModuleKits) TabooLibraryModule.getInst().valueOf("Kits");
String kit = args.split("_")[2];
// 礼包不存在
if (!moduleKits.contains(kit)) {
return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.1").asString();
}
// 是否领取
if (moduleKits.isPlayerRewared(player, kit)) {
// 是否只能领取一次
if (moduleKits.isDisposable(kit)) {
return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.2").asString();
}
// 是否冷却中
if (moduleKits.isPlayerCooldown(player, kit)) {
return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.4").asString();
}
}
// 是否有权限领取
String permission = moduleKits.getPermission(kit);
if (permission != null && !player.hasPermission(permission)) {
return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.5").asString();
}
// 可领取
return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.3").asString();
}
return null;
}

View File

@ -135,6 +135,8 @@ public class TimeCycleManager {
return 0L;
}
public static void load() {
// 注册调度器
new BukkitRunnable() {

View File

@ -7,7 +7,9 @@ import lombok.Getter;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.fileutils.ConfigUtils;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.string.language2.Language2;
import me.skymc.tlm.module.TabooLibraryModule;
import me.skymc.tlm.module.sub.ModuleKits;
import me.skymc.tlm.module.sub.ModuleTimeCycle;
/**
@ -21,18 +23,27 @@ public class TLM {
@Getter
private FileConfiguration config;
@Getter
private Language2 language;
/**
* 构造方法
*/
private TLM() {
// 重载配置文件
reloadConfig();
// 载入模块
if (isEnableModule("TimeCycle")) {
TabooLibraryModule.getInst().register(new ModuleTimeCycle());
}
if (isEnableModule("Kits")) {
TabooLibraryModule.getInst().register(new ModuleKits());
}
// 载入模块
TabooLibraryModule.getInst().loadModules();
// 提示
MsgUtils.send("载入 &f" + TabooLibraryModule.getInst().getSize() + " &7个 &fTLM &7模块");
}
@ -58,6 +69,13 @@ public class TLM {
*/
public void reloadConfig() {
config = ConfigUtils.saveDefaultConfig(Main.getInst(), "module.yml");
// 载入语言文件
try {
language = new Language2(config.getString("Language"), Main.getInst());
} catch (Exception e) {
MsgUtils.warn("语言文件不存在: &4" + config.getString("Language"));
return;
}
}
/**
@ -66,7 +84,7 @@ public class TLM {
* @param name 名称
* @return boolean
*/
private boolean isEnableModule(String name) {
public boolean isEnableModule(String name) {
return config.getStringList("EnableModule").contains(name);
}
}

View File

@ -4,11 +4,10 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.tlm.TLM;
import me.skymc.tlm.module.ITabooLibraryModule;
import me.skymc.tlm.module.TabooLibraryModule;
import me.skymc.tlm.command.sub.TLMKitCommand;
import me.skymc.tlm.command.sub.TLMListCommand;
import me.skymc.tlm.command.sub.TLMReloadCommand;
/**
* @author sky
@ -18,48 +17,32 @@ public class TLMCommands implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] args) {
if (args.length == 0) {
sender.sendMessage("§f");
sender.sendMessage("§b§l----- §3§lTaooLibraryModule Commands §b§l-----");
sender.sendMessage("§f");
sender.sendMessage("§7 /tlm list §f- §8列出所有模块");
sender.sendMessage("§7 /tlm reload [模块名/TLM/ALL] §f- §8重载配置文件");
sender.sendMessage("§f");
if (args.length == 0 || args[0].equalsIgnoreCase("help")) {
if (sender.hasPermission("taboolib.admin")) {
TLM.getInst().getLanguage().get("COMMAND-HELP").send(sender);
} else {
TLM.getInst().getLanguage().get("NOPERMISSION-HELP").send(sender);
}
}
else if (args[0].equalsIgnoreCase("reload")) {
if (args.length != 2) {
MsgUtils.send(sender, "&4参数错误。");
}
else if (args[1].equalsIgnoreCase("tlm")) {
TLM.getInst().reloadConfig();
MsgUtils.send(sender, "&fTLM &7配置文件已重载。");
}
else if (args[1].equalsIgnoreCase("all")) {
TabooLibraryModule.getInst().reloadConfig();
MsgUtils.send(sender, "所有模块配置文件已重载。");
}
else {
ITabooLibraryModule module = TabooLibraryModule.getInst().valueOf(args[1]);
if (module == null) {
MsgUtils.send(sender, "&4模块 &c" + args[1] + " &4不存在。");
}
else {
TabooLibraryModule.getInst().reloadConfig(module, true);
MsgUtils.send(sender, "模块 &f" + args[1] + " &7的配置文件已重载。");
}
if (sender.hasPermission("taboolib.admin")) {
new TLMReloadCommand(sender, args);
} else {
TLM.getInst().getLanguage().get("NOPERMISSION-RELOAD").send(sender);
}
}
else if (args[0].equalsIgnoreCase("list")) {
sender.sendMessage("§f");
sender.sendMessage("§b§l----- §3§lTaooLibraryModule Modules §b§l-----");
sender.sendMessage("§f");
for (ITabooLibraryModule module : TabooLibraryModule.getInst().keySet()) {
sender.sendMessage("§f - §8" + module.getName());
if (sender.hasPermission("taboolib.admin")) {
new TLMListCommand(sender, args);
} else {
TLM.getInst().getLanguage().get("NOPERMISSION-LIST").send(sender);
}
sender.sendMessage("§f");
}
else if (args[0].equalsIgnoreCase("kit")) {
new TLMKitCommand(sender, args);
}
else {
TLM.getInst().getLanguage().get("COMMAND-ERROR").send(sender);
}
return true;
}

View File

@ -0,0 +1,159 @@
package me.skymc.tlm.command.sub;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.tlm.TLM;
import me.skymc.tlm.module.TabooLibraryModule;
import me.skymc.tlm.module.sub.ModuleKits;
/**
* @author sky
* @since 2018年2月18日 下午2:53:58
*/
public class TLMKitCommand extends SubCommand {
/**
* @param sender
* @param args
*/
public TLMKitCommand(CommandSender sender, String[] args) {
super(sender, args);
if (TabooLibraryModule.getInst().valueOf("Kits") == null) {
TLM.getInst().getLanguage().get("KIT-DISABLE").send(sender);
return;
}
// 获取模块
ModuleKits moduleKits = (ModuleKits) TabooLibraryModule.getInst().valueOf("Kits");
// 判断命令
if (args.length == 1) {
TLM.getInst().getLanguage().get("KIT-EMPTY").send(sender);
return;
}
else if (args[1].equalsIgnoreCase("reward")) {
// 判断权限
if (!sender.hasPermission("taboolib.kit.reward")) {
TLM.getInst().getLanguage().get("NOPERMISSION-KIT-REWARD").send(sender);
return;
}
// 检查礼包
if (args.length < 3) {
TLM.getInst().getLanguage().get("KIT-NAME").send(sender);
return;
}
// 礼包不存在
if (!moduleKits.contains(args[2])) {
TLM.getInst().getLanguage().get("KIT-NOTFOUND").addPlaceholder("$kit", args[2]).send(sender);
return;
}
// 获取玩家
Player player;
if (args.length > 3) {
player = Bukkit.getPlayerExact(args[3]);
// 玩家不存在
if (player == null) {
TLM.getInst().getLanguage().get("KIT-OFFLINE").addPlaceholder("$name", args[3]).send(sender);
return;
}
} else if (sender instanceof Player) {
player = (Player) sender;
} else {
TLM.getInst().getLanguage().get("KIT-CONSOLE").send(sender);
return;
}
// 是否领取
if (moduleKits.isPlayerRewared(player, args[2])) {
// 是否只能领取一次
if (moduleKits.isDisposable(args[2])) {
TLM.getInst().getLanguage().get("KIT-DISPOSABLE").addPlaceholder("$kit", args[2]).send(sender);
return;
}
// 是否冷却中
if (moduleKits.isPlayerCooldown(player, args[2])) {
TLM.getInst().getLanguage().get("KIT-COOLDOWN").addPlaceholder("$kit", args[2]).send(sender);
return;
}
}
// 是否有权限领取
String permission = moduleKits.getPermission(args[2]);
if (permission != null && !player.hasPermission(permission)) {
// 提示信息
player.sendMessage(moduleKits.getPermissionMessage(args[2]));
return;
}
// 发送礼包
List<ItemStack> items = moduleKits.getItems(args[2]);
for (ItemStack item : items) {
// 给予物品
HashMap<Integer, ItemStack> result = player.getInventory().addItem(item);
// 如果背包空间不足
if (result.size() > 0 && moduleKits.isFullDrop(args[2])) {
// 掉落物品
player.getWorld().dropItem(player.getLocation(), item);
}
}
// 已领取
moduleKits.setPlayerReward(player, args[2], true);
// 提示信息
TLM.getInst().getLanguage().get("KIT-SUCCESS").addPlaceholder("$kit", args[2]).send(sender);
}
else if (args[1].equalsIgnoreCase("reset")) {
// 判断权限
if (!sender.hasPermission("taboolib.kit.reset")) {
TLM.getInst().getLanguage().get("NOPERMISSION-KIT-RESET").send(sender);
return;
}
// 检查礼包
if (args.length < 3) {
TLM.getInst().getLanguage().get("KIT-NAME").send(sender);
return;
}
// 礼包不存在
if (!moduleKits.contains(args[2])) {
TLM.getInst().getLanguage().get("KIT-NOTFOUND").addPlaceholder("$kit", args[2]).send(sender);
return;
}
// 获取玩家
Player player;
if (args.length > 3) {
player = Bukkit.getPlayerExact(args[3]);
// 玩家不存在
if (player == null) {
TLM.getInst().getLanguage().get("KIT-OFFLINE").addPlaceholder("$name", args[3]).send(sender);
return;
}
else {
moduleKits.setPlayerReward(player, args[2], false);
TLM.getInst().getLanguage().get("KIT-RESET-PLAYER").addPlaceholder("$kit", args[2]).addPlaceholder("$player", player.getName()).send(sender);
}
} else {
moduleKits.resetKit(args[2]);
TLM.getInst().getLanguage().get("KIT-RESET-ALL").addPlaceholder("$kit", args[2]).send(sender);
}
}
else {
TLM.getInst().getLanguage().get("COMMAND-ERROR").send(sender);
}
}
}

View File

@ -0,0 +1,32 @@
package me.skymc.tlm.command.sub;
import org.bukkit.command.CommandSender;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.tlm.module.ITabooLibraryModule;
import me.skymc.tlm.module.TabooLibraryModule;
/**
* @author sky
* @since 2018年2月18日 下午2:10:12
*/
public class TLMListCommand extends SubCommand {
/**
* @param sender
* @param args
*/
public TLMListCommand(CommandSender sender, String[] args) {
super(sender, args);
sender.sendMessage("§f");
sender.sendMessage("§b§l----- §3§lTaooLibraryModule Modules §b§l-----");
sender.sendMessage("§f");
for (ITabooLibraryModule module : TabooLibraryModule.getInst().keySet()) {
sender.sendMessage("§f - §8" + module.getName());
}
sender.sendMessage("§f");
}
}

View File

@ -0,0 +1,49 @@
package me.skymc.tlm.command.sub;
import org.bukkit.command.CommandSender;
import me.skymc.taboolib.commands.SubCommand;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.tlm.TLM;
import me.skymc.tlm.module.ITabooLibraryModule;
import me.skymc.tlm.module.TabooLibraryModule;
/**
* @author sky
* @since 2018年2月18日 下午2:09:34
*/
public class TLMReloadCommand extends SubCommand {
/**
* @param sender
* @param args
*/
public TLMReloadCommand(CommandSender sender, String[] args) {
super(sender, args);
if (args.length != 2) {
MsgUtils.send(sender, "&4参数错误。");
}
else if (args[1].equalsIgnoreCase("tlm")) {
TLM.getInst().reloadConfig();
MsgUtils.send(sender, "&fTLM &7配置文件已重载。");
}
else if (args[1].equalsIgnoreCase("all")) {
TabooLibraryModule.getInst().reloadConfig();
MsgUtils.send(sender, "所有模块配置文件已重载。");
}
else {
ITabooLibraryModule module = TabooLibraryModule.getInst().valueOf(args[1]);
if (module == null) {
MsgUtils.send(sender, "&4模块 &c" + args[1] + " &4不存在。");
}
else {
TabooLibraryModule.getInst().reloadConfig(module, true);
MsgUtils.send(sender, "模块 &f" + args[1] + " &7的配置文件已重载。");
}
}
}
}

View File

@ -0,0 +1,160 @@
package me.skymc.tlm.module.sub;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import me.skymc.taboolib.database.PlayerDataManager;
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.other.DateUtils;
import me.skymc.taboolib.other.NumberUtils;
import me.skymc.taboolib.playerdata.DataUtils;
import me.skymc.tlm.module.ITabooLibraryModule;
/**
* @author sky
* @since 2018쾨2墩18휑 苟敎12:13:55
*/
public class ModuleKits implements ITabooLibraryModule {
private FileConfiguration data;
@Override
public String getName() {
return "Kits";
}
@Override
public void onEnable() {
data = DataUtils.addPluginData("ModuleKits", null);
}
/**
* <EFBFBD>零鯤소角뤠쥴혤쟉관
*
* @param player 鯤소
*/
public void setPlayerReward(Player player, String kit, boolean reward) {
data.set(kit + "." + player.getName(), reward ? System.currentTimeMillis() : null);
}
/**
* 헌왕쟉관鑒앴
*
* @param kit 쟉관
*/
public void resetKit(String kit) {
data.set(kit, null);
}
/**
* 鯤소角뤠쥴혤쟉관
*
* @param player 鯤소
* @param kit 쟉관
* @return boolean
*/
public boolean isPlayerRewared(Player player, String kit) {
return data.contains(kit + "." + player.getName());
}
/**
* 쟉관角뤠瞳잤홱櫓
*
* @param player
* @param kit
* @return
*/
public boolean isPlayerCooldown(Player player, String kit) {
return System.currentTimeMillis() - data.getLong(kit + "." + player.getName()) < getCooldown(kit);
}
/**
* 쟉관角뤠닸瞳
*
* @param kit 쟉관츰
* @return boolean
*/
public boolean contains(String kit) {
return getConfig().contains("Kits." + kit);
}
/**
* 삿혤쟉관잤홱珂쇌
*
* @param kit 쟉관츰
* @return long
*/
public long getCooldown(String kit) {
return DateUtils.formatDate(getConfig().getString("Kits." + kit + ".Cooldown"));
}
/**
* 삿혤쟉관왕쇌꼇璃珂돨뇹잿렘駕
*
* @param kit 쟉관츰
* @return boolean
*/
public Boolean isFullDrop(String kit) {
return getConfig().getBoolean("Kits." + kit + ".FullDrop");
}
/**
* 쟉관角뤠怜콘쥴혤寧늴
*
* @param kit 쟉관츰
* @return boolean
*/
public boolean isDisposable(String kit) {
return getConfig().getBoolean("Kits." + kit + ".Disposable");
}
/**
* 삿혤쟉관홈掘
*
* @param kit 쟉관츰
* @return String
*/
public String getPermission(String kit) {
return getConfig().getString("Kits." + kit + ".Permission");
}
/**
* 삿혤쟉관홈掘瓊刻
*
* @param kit 쟉관츰
* @return String
*/
public String getPermissionMessage(String kit) {
return getConfig().getString("Kits." + kit + ".Permission-message").replace("&", "");
}
/**
* 삿혤쟉관膠틔
*
* @param kit 쟉관츰
* @return {@link List}
*/
public List<ItemStack> getItems(String kit) {
List<ItemStack> items = new ArrayList<>();
for (String itemStr : getConfig().getStringList("Kits." + kit + ".Items")) {
ItemStack item = ItemUtils.getCacheItem(itemStr.split(" ")[0]);
if (item != null) {
item = item.clone();
try {
item.setAmount(NumberUtils.getInteger(itemStr.split(" ")[1]));
items.add(item);
} catch (Exception e) {
MsgUtils.warn("친욥토零潼흙嫩끽: &4膠틔鑒좆댄轎");
MsgUtils.warn("친욥: &4Kits");
MsgUtils.warn("貫黨: &4" + itemStr);
}
}
}
return items;
}
}

View File

@ -64,7 +64,7 @@ public class ModuleTimeCycle implements ITabooLibraryModule, Listener {
int type = (int) Calendar.class.getField(typeStr.split("=")[0]).get(Calendar.class);
date.set(type, NumberUtils.getInteger(typeStr.split("=")[1]));
} catch (Exception err) {
MsgUtils.warn("<EFBFBD>£<EFBFBD>י<EFBFBD>ה<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>כ<EFBFBD>ל³£");
MsgUtils.warn("模块配置载入异常: &4日期类型错误");
MsgUtils.warn("Ä£¿é: &4TimeCycle");
MsgUtils.warn("λÓÚ: &4" + typeStr);
}

View File

@ -0,0 +1,37 @@
COMMAND-ERROR: '&8[&2&lTLM&8] &4指令错误'
COMMAND-HELP:
- ''
- '&b&l----- &3&lTaooLibraryModule Commands &b&l-----'
- ''
- '&f /tlm kit reward &8[&7名称] &8<&7名称&8> &6- &e领取礼包'
- '&f /tlm kit reset &8[&7名称] &8<&7玩家&8> &6- &e刷新礼包'
- ''
- '&f /tlm list &6- &e列出所有模块'
- ''
- '&f /tlm reload &8[&7模块名|TLM|ALL&8] &6- &e列出所有模块'
- ''
NOPERMISSION-HELP: '&8[&2&lTLM&8] &4你没有权限列出帮助命令'
NOPERMISSION-LIST: '&8[&2&lTLM&8] &4你没有权限这么做'
NOPERMISSION-RELOAD: '&8[&2&lTLM&8] &4你没有权限这么做'
NOPERMISSION-KIT-REWARD: '&8[&2&lTLM&8] &4你没有权限这么做'
NOPERMISSION-KIT-RESET: '&8[&2&lTLM&8] &4你没有权限这么做'
KIT-EMPTY: '&8[&2&lTLM&8] &4参数错误'
KIT-NAME: '&8[&2&lTLM&8] &4请输入正确的礼包名称'
KIT-DISABLE: '&8[&2&lTLM&8] &4该模块尚未在配置文件中启用'
KIT-NOTFOUND: '&8[&2&lTLM&8] &4礼包 &c$kit &4不存在'
KIT-OFFLINE: '&8[&2&lTLM&8] &4玩家 &c$name &4不在线'
KIT-CONSOLE: '&8[&2&lTLM&8] &4后台不允许输入这个指令'
KIT-COOLDOWN: '&8[&2&lTLM&8] &4礼包 &c$kit &4正在冷却中'
KIT-DISPOSABLE: '&8[&2&lTLM&8] &4礼包 &c$kit &4只能领取一次'
KIT-RESET-ALL: '&8[&2&lTLM&8] &7礼包 &f$kit &7已刷新'
KIT-RESET-PLAYER: '&8[&2&lTLM&8] &7玩家 &f$player &7的礼包 &f$kit &7已刷新'
KIT-SUCCESS: '&8[&2&lTLM&8] &7礼包 &f$kit &7已领取'
KIT-PLACEHOLDER:
0: '&4模块未启用'
1: '&4礼包不存在'
2: '&8已领取'
3: '&a可领取'
4: '&4冷却中'
5: '&4无权限'

View File

@ -0,0 +1,30 @@
# 礼包配置
Kits:
# 礼包名
kit_name:
# 礼包刷新时间
# ---------- #
# 1d = 1天
# 1h = 1小时
# 1m = 1分钟
# 1s = 1秒钟
# 时间之间用 ";" 分隔, 例如 1小时30分钟 = "1h;30m"
# ---------- #
Cooldown: '1d'
# 背包空间不足时物品是否掉落
FullDrop: true
# 是否只能领取一次
Disposable: false
# 礼包领取权限
Permission: 'taboolib.kit.kit_name'
# 礼包领取权限提示
Permission-message: '&4你没有权限领取这个礼包'
# 礼包内容
# 空格左侧为物品名,右侧为物品数量
Items:
- 'UnlimitSword 1'

View File

@ -1,4 +1,8 @@
# 语言文件
Language: 'zh_CN'
# 启用模块
# 该配置需要重启服务器才会生效
EnableModule:
#- 'TimeCycle'
#- 'Kits'