feat(bukkit): 添加新的工具方法
This commit is contained in:
@@ -9,18 +9,19 @@ import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@@ -51,19 +52,6 @@ public final class BukkitUtils {
|
||||
return Class.forName("net.minecraft.server." + nmsVersion + "." + className);
|
||||
}
|
||||
|
||||
/**
|
||||
* 让玩家以最高权限执行命令
|
||||
*
|
||||
* @param player 玩家
|
||||
* @param command 要执行的命令
|
||||
*/
|
||||
public static void opCommand(@NotNull Player player, @NotNull String command) {
|
||||
boolean isOp = player.isOp();
|
||||
player.setOp(true);
|
||||
Bukkit.dispatchCommand(player, command);
|
||||
player.setOp(isOp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取玩家的头颅
|
||||
* 在1.11以上的服务端中获取头颅材质是在服务器上运行的
|
||||
@@ -138,12 +126,40 @@ public final class BukkitUtils {
|
||||
* @param stack 物品
|
||||
* @return 是否为空
|
||||
*/
|
||||
public static boolean isEmptyItemStack(ItemStack stack) {
|
||||
public static boolean isEmptyItemStack(@Nullable ItemStack stack) {
|
||||
return stack == null || stack.getAmount() < 1 || stack.getType() == Material.AIR;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断物品是否包含某条 lore
|
||||
*
|
||||
* @param stack 要检测的物品
|
||||
* @param string 需要包含的 lore
|
||||
* @return 检测结果
|
||||
*/
|
||||
public static boolean containsLore(@Nullable ItemStack stack, @NotNull String string) {
|
||||
if (stack == null) {
|
||||
return false;
|
||||
}
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
if (meta == null) {
|
||||
return false;
|
||||
}
|
||||
List<String> lore = meta.getLore();
|
||||
if (lore == null) {
|
||||
return false;
|
||||
}
|
||||
for (String s : lore) {
|
||||
if (s.contains(string)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给予玩家一个物品, 当玩家背包满时
|
||||
* <p>
|
||||
* 将会在玩家附近生成这个物品的掉落物
|
||||
*
|
||||
* @param player 玩家
|
||||
@@ -159,29 +175,6 @@ public final class BukkitUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物品的名称
|
||||
* 当物品为null时返回"null"
|
||||
* 当物品拥有DisplayName时返回DisplayName
|
||||
* 否则返回物品的Material的name
|
||||
*
|
||||
* @param stack 物品
|
||||
* @return 物品的名称
|
||||
*/
|
||||
@NotNull
|
||||
public static String getItemName(ItemStack stack) {
|
||||
if (stack == null) {
|
||||
return "null";
|
||||
}
|
||||
if (stack.hasItemMeta()) {
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
if (meta != null && meta.hasDisplayName()) {
|
||||
return meta.getDisplayName();
|
||||
}
|
||||
}
|
||||
return stack.getType().name();
|
||||
}
|
||||
|
||||
public static DisplayMessage getDisplayMessage(ConfigurationSection config) {
|
||||
if (config == null) {
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user