Skip to content

Commit

Permalink
版本更新至 3.65
Browse files Browse the repository at this point in the history
新增:版本更新检测
新增:Language2Value 对象新增 broadcast() 方法来发送给所有玩家
新增:/language2 send 命令现在可以使用 ALL 代替所有玩家
删除:FileUtils 工具的三个文本读取方法的异常打印
  • Loading branch information
Bkm016 committed Feb 23, 2018
1 parent e89e8b8 commit e67f889
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 28 deletions.
10 changes: 10 additions & 0 deletions src/main/src/me/skymc/taboolib/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import me.skymc.taboolib.inventory.ItemUtils;
import me.skymc.taboolib.inventory.speciaitem.SpecialItem;
import me.skymc.taboolib.javashell.JavaShell;
import me.skymc.taboolib.listener.ListenerNetWork;
import me.skymc.taboolib.listener.ListenerPlayerCommand;
import me.skymc.taboolib.listener.ListenerPlayerQuit;
import me.skymc.taboolib.listener.ListenerPlayerJump;
Expand All @@ -51,6 +52,7 @@
import me.skymc.taboolib.support.SupportPlaceholder;
import me.skymc.taboolib.team.TagUtils;
import me.skymc.taboolib.timecycle.TimeCycleManager;
import me.skymc.taboolib.update.UpdateTask;
import me.skymc.tlm.TLM;
import me.skymc.tlm.command.TLMCommands;
import me.skymc.tlm.module.TabooLibraryModule;
Expand Down Expand Up @@ -223,6 +225,9 @@ public void run() {
}
}.runTask(this);

// 更新检测
new UpdateTask();

// 启动
started = true;
}
Expand Down Expand Up @@ -316,6 +321,11 @@ private void registerListener() {
getServer().getPluginManager().registerEvents(new EntityUtils(), this);
getServer().getPluginManager().registerEvents(new SignUtils(), this);
}

// 如果 YUM 插件存在
if (Bukkit.getPluginManager().getPlugin("YUM") != null) {
getServer().getPluginManager().registerEvents(new ListenerNetWork(), this);
}
}

public static enum StorageType {
Expand Down
14 changes: 14 additions & 0 deletions src/main/src/me/skymc/taboolib/TabooLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@

public class TabooLib {

/**
* 获取插件版本
*
* @return
*/
public static double getPluginVersion() {
try {
return Double.valueOf(Main.getInst().getDescription().getVersion());
}
catch (Exception e) {
return 0D;
}
}

/**
* 获取 NMS 版本
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
sender.sendMessage("§f");
sender.sendMessage("§b§l----- §3§lLanguage2 Commands §b§l-----");
sender.sendMessage("§f");
sender.sendMessage("§f /language2 send §8[§7玩家§8] §8[§7语言§8] §8<§7变量§8> §6- §e发送语言提示");
sender.sendMessage("§f /language2 send §8[§7玩家/ALL§8] §8[§7语言§8] §8<§7变量§8> §6- §e发送语言提示");
sender.sendMessage("§f /language2 reload §6- §e重载语言库");
sender.sendMessage("§f");
}
Expand All @@ -38,35 +38,41 @@ else if (args[0].equalsIgnoreCase("send")) {
MsgUtils.send(sender, "§4参数错误");
}
else {
// 获取玩家
Player player = Bukkit.getPlayerExact(args[1]);
if (player == null) {
MsgUtils.send(sender, "§4玩家不在线");
// 时间
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++;
}
}

// 如果是公告
if (args[1].equals("ALL")) {
// 发送信息
value.broadcast();
}
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++;
}
// 获取玩家
Player player = Bukkit.getPlayerExact(args[1]);
if (player == null) {
MsgUtils.send(sender, "§4玩家不在线");
}

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

// 如果发送者是玩家
if (sender instanceof Player && ((Player) sender).getItemInHand().getType().equals(Material.COMMAND)) {
MsgUtils.send(sender, "§7信息已发送, 本次计算耗时: &f" + (System.currentTimeMillis() - time) + "ms");
else {
// 发送信息
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;
Expand Down
7 changes: 4 additions & 3 deletions src/main/src/me/skymc/taboolib/fileutils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;

import me.skymc.taboolib.client.LogClient;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.methods.MethodsUtils;

public class FileUtils {
Expand Down Expand Up @@ -78,7 +79,7 @@ public static String getStringFromInputStream(InputStream in, int size, String e
bos.close();
return new String(bos.toByteArray(), encode);
} catch (IOException e) {
e.printStackTrace();
MsgUtils.warn("输入流读取出错: &4" + e.getMessage());
}
return null;
}
Expand All @@ -101,7 +102,7 @@ public static String getStringFromFile(File file, int size, String encode) {
fin.close();
return new String(bos.toByteArray(), encode);
} catch (IOException e) {
e.printStackTrace();
MsgUtils.warn("文件读取出错: &4" + e.getMessage());
}
return null;
}
Expand All @@ -123,7 +124,7 @@ public static String getStringFromURL(String url, int size) {
bin.close();
return new String(bos.toByteArray(), conn.getContentEncoding() == null ? "UTF-8" : conn.getContentEncoding());
} catch (IOException e) {
e.printStackTrace();
MsgUtils.warn("网络访问出错: &4" + e.getMessage());
}
return null;
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/src/me/skymc/taboolib/listener/ListenerNetWork.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package me.skymc.taboolib.listener;

import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;

import me.skymc.taboolib.Main;
import me.skymc.taboolib.message.MsgUtils;
import pw.yumc.Yum.events.PluginNetworkEvent;

/**
* @author sky
* @since 2018年2月23日 下午11:10:03
*/
public class ListenerNetWork implements Listener {

public static final String GG = "本监听只是为了防止本插件的更新检测被 YUM 插件阻止,别无它用。";

@EventHandler (priority = EventPriority.HIGHEST)
public void onNetWork(PluginNetworkEvent e) {
if (e.getPlugin() != null && e.getPlugin().equals(Main.getInst())) {
// 取消阻止
e.setCancelled(false);
// 后台提示
MsgUtils.warn("已取消 &4YUM &c对本插件网络访问的阻止!");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.skymc.taboolib.string.language2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -199,6 +200,17 @@ public void send(CommandSender sender) {
}
}

/**
* 全服公告
*/
public void broadcast() {
List<Player> players = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) {
players.add(player);
}
send(players);
}

/**
* 获取文本
*
Expand Down
56 changes: 56 additions & 0 deletions src/main/src/me/skymc/taboolib/update/UpdateTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package me.skymc.taboolib.update;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.bukkit.scheduler.BukkitRunnable;

import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.fileutils.FileUtils;
import me.skymc.taboolib.message.MsgUtils;

/**
* @author sky
* @since 2018年2月23日 下午10:39:14
*/
public class UpdateTask {

/**
* 检测更新
*/
public UpdateTask() {
new BukkitRunnable() {

@Override
public void run() {
// 是否禁用
if (!Main.getInst().getConfig().getBoolean("UPDATE-CHECK")) {
return;
}

String value = FileUtils.getStringFromURL("https://github.com/Bkm016/TabooLib/releases", 1024);
Pattern pattern = Pattern.compile("<a href=\"/Bkm016/TabooLib/releases/tag/(\\S+)\">");
Matcher matcher = pattern.matcher(value);
if (matcher.find()) {
// 最新版本
double newVersion = Double.valueOf(matcher.group(1));
// 如果是最新版
if (TabooLib.getPluginVersion() == newVersion) {
MsgUtils.send("插件已是最新版, 无需更新!");
}
else {
MsgUtils.send("&8####################################################");
MsgUtils.send("检测到有新的版本更新!");
MsgUtils.send("当前版本: &f" + TabooLib.getPluginVersion());
MsgUtils.send("最新版本: &f" + newVersion);
MsgUtils.send("下载地址: &fhttp://www.mcbbs.net/thread-773065-1-1.html");
MsgUtils.send("开源地址: &fhttps://github.com/Bkm016/TabooLib/");
MsgUtils.send("&8####################################################");
}
}
}
}.runTaskLaterAsynchronously(Main.getInst(), 100);
}
}
3 changes: 3 additions & 0 deletions src/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ DATAURL:
# 启用后将收到来自其他插件的调试信息
DEBUG: false

# 是否启用更新检测
UPDATE-CHECK: true

# 是否在关闭服务器时清理玩家数据
# 该配置将在启用数据库储存时失效
DELETE-DATA: false
Expand Down

0 comments on commit e67f889

Please sign in to comment.