Skip to content

Commit

Permalink
版本更新至 3.54
Browse files Browse the repository at this point in the history
大更新!
新增:Language2 工具, wiki已添加该工具使用帮助
  • Loading branch information
Bkm016 committed Feb 13, 2018
1 parent 3c1aa99 commit 2794d88
Show file tree
Hide file tree
Showing 11 changed files with 890 additions and 16 deletions.
7 changes: 7 additions & 0 deletions src/main/src/me/skymc/taboolib/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import me.skymc.taboolib.bstats.Metrics;
import me.skymc.taboolib.client.LogClient;
import me.skymc.taboolib.commands.MainCommands;
import me.skymc.taboolib.commands.language.Language2Command;
import me.skymc.taboolib.commands.sub.itemlist.listener.ItemLibraryPatch;
import me.skymc.taboolib.database.PlayerDataManager;
import me.skymc.taboolib.database.GlobalDataManager;
Expand All @@ -45,6 +46,7 @@
import me.skymc.taboolib.mysql.protect.MySQLConnection;
import me.skymc.taboolib.sign.SignUtils;
import me.skymc.taboolib.string.StringUtils;
import me.skymc.taboolib.string.language2.Language2;
import me.skymc.taboolib.support.SupportPlaceholder;
import me.skymc.taboolib.team.TagUtils;
import me.skymc.taboolib.timecycle.TimeCycleManager;
Expand Down Expand Up @@ -80,6 +82,8 @@ public class Main extends JavaPlugin implements Listener {
private FileConfiguration config = null;
@Getter
private static LogClient client;
@Getter
private static Language2 exampleLangauge2;

public static Random getRandom() {
return NumberUtils.getRand();
Expand Down Expand Up @@ -163,6 +167,7 @@ public void onLoad() {
public void onEnable() {
// 注册指令
getCommand("taboolib").setExecutor(new MainCommands());
getCommand("language2").setExecutor(new Language2Command());

// 注册监听
registerListener();
Expand All @@ -178,6 +183,8 @@ public void onEnable() {
TimeCycleManager.load();
// 启动脚本
JavaShell.javaShellSetup();
// 载入语言文件
exampleLangauge2 = new Language2("Language2", this);

// 启动数据库储存方法
if (getStorageType() == StorageType.SQL) {
Expand Down
30 changes: 14 additions & 16 deletions src/main/src/me/skymc/taboolib/commands/MainCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,56 +56,54 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
sender.sendMessage("§f");
sender.sendMessage("§c /taboolib importdata §f- §4向数据库导入本地数据 §8(该操作将会清空数据库)");
sender.sendMessage("§f");
return false;
}
else if (args[0].equalsIgnoreCase("itemreload") || args[0].equalsIgnoreCase("ireload")) {
ItemUtils.reloadItemCache();
ItemUtils.reloadItemName();
MsgUtils.send(sender, "重载成功");
return true;
}
else if (args[0].equalsIgnoreCase("save")) {
return new SaveCommand(sender, args).command();
new SaveCommand(sender, args);
}
else if (args[0].equalsIgnoreCase("enchants")) {
return new EnchantCommand(sender, args).command();
new EnchantCommand(sender, args);
}
else if (args[0].equalsIgnoreCase("potions")) {
return new PotionCommand(sender, args).command();
new PotionCommand(sender, args);
}
else if (args[0].equalsIgnoreCase("flags")) {
return new FlagCommand(sender, args).command();
new FlagCommand(sender, args);
}
else if (args[0].equalsIgnoreCase("attributes")) {
return new AttributesCommand(sender, args).command();
new AttributesCommand(sender, args);
}
else if (args[0].equalsIgnoreCase("slots")) {
return new SlotCommand(sender, args).command();
new SlotCommand(sender, args);
}
else if (args[0].equalsIgnoreCase("importdata")) {
return new ImportCommand(sender, args).command();
new ImportCommand(sender, args);
}
else if (args[0].equalsIgnoreCase("iteminfo")) {
return new InfoCommand(sender, args).command();
new InfoCommand(sender, args);
}
else if (args[0].equalsIgnoreCase("itemlist")) {
return new ItemListCommand(sender, args).command();
new ItemListCommand(sender, args);
}
else if (args[0].equalsIgnoreCase("item") || args[0].equalsIgnoreCase("i")) {
return new ItemCommand(sender, args).command();
new ItemCommand(sender, args);
}
else if (args[0].equalsIgnoreCase("setvariable")) {
return new VariableSetCommand(sender, args).command();
new VariableSetCommand(sender, args);
}
else if (args[0].equalsIgnoreCase("getvariable")) {
return new VariableGetCommand(sender, args).command();
new VariableGetCommand(sender, args);
}
else if (args[0].equalsIgnoreCase("shell") || args[0].equalsIgnoreCase("s")) {
return new ShellCommand(sender, args).command();
new ShellCommand(sender, args);
}
else {
MsgUtils.send(sender, "&4指令错误");
}
return false;
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package me.skymc.taboolib.commands.language;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import me.skymc.taboolib.Main;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.string.language2.Language2Value;

/**
* @author sky
* @since 2018年2月13日 下午5:11:01
*/
public class Language2Command 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§lTabooLib Commands §b§l-----");
sender.sendMessage("§f");
sender.sendMessage("§7 /language2 reload §f- §8重载语言库");
sender.sendMessage("§7 /language2 send [玩家] [语言] <变量> §f- §8发送语言提示");
sender.sendMessage("§f");
}
else if (args[0].equalsIgnoreCase("reload")) {
MsgUtils.send(sender, "§7重载中..");
long time = System.currentTimeMillis();
Main.getExampleLangauge2().reload();
MsgUtils.send(sender, "§7重载完成! 耗时: &f" + (System.currentTimeMillis() - time) + "ms");
}
else if (args[0].equalsIgnoreCase("send")) {
if (args.length < 3) {
MsgUtils.send(sender, "§4参数错误");
}
else {
// 获取玩家
Player player = Bukkit.getPlayerExact(args[1]);
if (player == null) {
MsgUtils.send(sender, "§4玩家不在线");
}
else {
// 时间
long time = System.currentTimeMillis();

// 获取语言文件
Language2Value value = Main.getExampleLangauge2().get(args[2]);

// 如果有变量参数
if (args.length > 3) {
int i = 0;
for (String variable : args[3].split("\\|")) {
value.addPlaceholder("$" + i, variable);
i++;
}
}

// 发送信息
value.send(player);

// 如果发送者是玩家
if (sender instanceof Player && ((Player) sender).getItemInHand().getType().equals(Material.COMMAND)) {
MsgUtils.send(sender, "§7信息已发送, 本次计算耗时: &f" + (System.currentTimeMillis() - time) + "ms");
}
}
}
}
return true;
}
}
142 changes: 142 additions & 0 deletions src/main/src/me/skymc/taboolib/string/language2/Language2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package me.skymc.taboolib.string.language2;

import java.io.File;
import java.io.FileNotFoundException;

import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import lombok.Getter;
import me.clip.placeholderapi.PlaceholderAPI;
import me.skymc.taboolib.fileutils.ConfigUtils;

/**
* @author sky
* @since 2018年2月13日 下午2:37:07
*/
public class Language2 {

@Getter
private FileConfiguration configuration;

@Getter
private File languageFile;

@Getter
private File languageFolder;

@Getter
private Plugin plugin;

@Getter
private String languageName;

/**
* 构造方法
*
* @param plugin 插件
*/
public Language2(Plugin plugin) {
this("zh_CN", plugin);
}

/**
* 构造方法
*
* @param languageName 语言文件
* @param plugin 插件
*/
public Language2(String languageName, Plugin plugin) {
this.languageName = languageName;
this.plugin = plugin;
// 重载语言文件
reload(languageName);
}

/**
* 获取语言文件
*
* @param key 键
* @return {@link Language2Value}
*/
public Language2Value get(String key) {
return new Language2Value(this, key);
}

/**
* 重载语言文件
*/
public void reload() {
reload(this.languageName);
}

/**
* 重载语言文件
*
* @param languageName 新语言文件名称
*/
public void reload(String languageName) {
// 初始化文件夹
createFolder(plugin);
// 格式化配置名
languageName = formatName(languageName);
// 获取文件
languageFile = new File(languageFolder, languageName);
// 文件不存在
if (!languageFile.exists()) {
// 如果语言文件不存在
if (plugin.getResource("Language2/" + languageName) == null) {
try {
throw new FileNotFoundException("语言文件 " + languageName + " 不存在");
}
catch (Exception e) {
// TODO: handle exception
}
}
else {
// 释放资源
plugin.saveResource("Language2/" + languageName, true);
}
}
// 载入配置
configuration = ConfigUtils.load(plugin, languageFile);
}

/**
* PlaceholderAPI 变量识别
*
* @param player 玩家
* @param string 文本
* @return String
*/
public String setPlaceholderAPI(Player player, String string) {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null && player != null) {
return PlaceholderAPI.setPlaceholders(player, string);
}
return string;
}

/**
* 语言文件名称格式化
*
* @param name 语言文件名称
* @return String
*/
private String formatName(String name) {
return name.contains(".yml") ? name : name + ".yml";
}

/**
* 语言文件夹初始化
*
* @param plugin
*/
private void createFolder(Plugin plugin) {
languageFolder = new File(plugin.getDataFolder(), "Language2");
if (!languageFolder.exists()) {
languageFolder.mkdir();
}
}
}
29 changes: 29 additions & 0 deletions src/main/src/me/skymc/taboolib/string/language2/Language2Type.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package me.skymc.taboolib.string.language2;

/**
* @author sky
* @since 2018年2月13日 下午3:14:00
*/
public enum Language2Type {

/**
* 一般文本
*/
TEXT,

/**
* JSON 文本
*/
JSON,

/**
* 大标题
*/
TITLE,

/**
* 小标题
*/
ACTION,

}
Loading

0 comments on commit 2794d88

Please sign in to comment.