From 6069ea9ad0cffad519a6e6751866ebea22129521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Wed, 4 Jul 2018 22:23:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8F=92=E4=BB=B6=E6=97=B6?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E5=9C=A8=E7=BA=BF=E7=8E=A9=E5=AE=B6=EF=BC=8C?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=9C=89=E7=8E=A9=E5=AE=B6=E5=88=99=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E6=9B=B4=E6=96=B0=E3=80=82=20=E4=BF=AE=E5=A4=8D=20/tl?= =?UTF-8?q?ib=20iteminfo=20=E5=91=BD=E4=BB=A4=E7=9A=84=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E8=AF=AD=E6=B3=95=E9=94=99=E8=AF=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/TabooLibMainCommand.java | 6 ++++ .../taboolib/itemnbtapi/NBTCompound.java | 2 +- .../me/skymc/taboolib/player/PlayerUtils.java | 28 +++++++++++++++++++ src/main/resources/lang/zh_CN.yml | 1 + 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/skymc/taboolib/commands/TabooLibMainCommand.java b/src/main/java/me/skymc/taboolib/commands/TabooLibMainCommand.java index 9b120a0..705133c 100644 --- a/src/main/java/me/skymc/taboolib/commands/TabooLibMainCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/TabooLibMainCommand.java @@ -12,6 +12,7 @@ import me.skymc.taboolib.commands.taboolib.*; import me.skymc.taboolib.fileutils.FileUtils; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.other.NumberUtils; +import me.skymc.taboolib.player.PlayerUtils; import me.skymc.taboolib.plugin.PluginUtils; import me.skymc.taboolib.update.UpdateTask; import org.bukkit.Bukkit; @@ -807,6 +808,11 @@ public class TabooLibMainCommand extends BaseMainCommand { @Override public void run() { + if (PlayerUtils.getOnlinePlayers().size() > 0) { + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.UPDATEPLUGIN.PLAYER-ONLINE"); + return; + } + String url = Strings.replaceWithOrder("https://github.com/Bkm016/TabooLib/releases/download/{0}/TabooLib-{0}.jar", UpdateTask.getNewVersion()); TLocale.sendTo(sender, "COMMANDS.TABOOLIB.UPDATEPLUGIN.UPDATE-START", url); diff --git a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTCompound.java b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTCompound.java index a5b9887..d02e435 100644 --- a/src/main/java/me/skymc/taboolib/itemnbtapi/NBTCompound.java +++ b/src/main/java/me/skymc/taboolib/itemnbtapi/NBTCompound.java @@ -190,7 +190,7 @@ public class NBTCompound { } public String asNBTString(){ - return getCompound().toString(); + return getCompound() == null ? "" : getCompound().toString(); } } diff --git a/src/main/java/me/skymc/taboolib/player/PlayerUtils.java b/src/main/java/me/skymc/taboolib/player/PlayerUtils.java index bc2a665..3fd1b95 100644 --- a/src/main/java/me/skymc/taboolib/player/PlayerUtils.java +++ b/src/main/java/me/skymc/taboolib/player/PlayerUtils.java @@ -1,11 +1,15 @@ package me.skymc.taboolib.player; +import com.google.common.collect.ImmutableList; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Collections; import java.util.HashSet; /** @@ -13,6 +17,30 @@ import java.util.HashSet; */ public class PlayerUtils { + private static boolean setup; + private static boolean useReflection; + private static Method oldGetOnlinePlayersMethod; + + public static Collection getOnlinePlayers() { + try { + if (!setup) { + oldGetOnlinePlayersMethod = Bukkit.class.getDeclaredMethod("getOnlinePlayers"); + if (oldGetOnlinePlayersMethod.getReturnType() == Player[].class) { + useReflection = true; + } + setup = true; + } + if (!useReflection) { + return Bukkit.getOnlinePlayers(); + } else { + Player[] playersArray = (Player[]) oldGetOnlinePlayersMethod.invoke(null); + return ImmutableList.copyOf(playersArray); + } + } catch (Exception e) { + return Collections.emptyList(); + } + } + /** * 获取目标方块 * diff --git a/src/main/resources/lang/zh_CN.yml b/src/main/resources/lang/zh_CN.yml index a727276..fbf0b08 100644 --- a/src/main/resources/lang/zh_CN.yml +++ b/src/main/resources/lang/zh_CN.yml @@ -239,6 +239,7 @@ COMMANDS: UPDATE-NOT-FOUND: '&8[&3&lTabooLib&8] &7插件已是最新版, 无需更新!' UPDATE-NOT-SUPPORT: '&8[&3&lTabooLib&8] &4您的服务器不支持在线更新!' FILE-NOT-FOUND: '&8[&3&lTabooLib&8] &4尚未寻找到插件文件' + PLAYER-ONLINE: '&8[&3&lTabooLib&8] &4服务器有玩家在线无法更新插件.' UPDATE-START: '&8[&3&lTabooLib&8] &7开始下载:&f {0}' UPDATE-SUCCESS: '&8[&3&lTabooLib&8] &7最新版下载完成, 服务器即将重启!' JAVASHELL: