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: