TabooLib v4.26
+ 调整 TConfiguration 类,增加 runListener 方法运行重载任务 + 调整 ItemBuilder 类,增加玩家皮肤头构造方法 + 调整 TagDataHandler 类,兼容了弱智 BedwarsRel 的计分板冲突 + 调整 SupportWorldGuard 类,新增了获取所有区域的方法。 + 重构 ItemUtils 类,现在更加整洁了。。 + SkullUtils 被赋予尊贵的 @Deprecated + 优化本地通讯网,修复了心跳包的语法错误问题,并新增了 /tclient 命令用于简单的操作通讯网络。
This commit is contained in:
parent
40aa95e17b
commit
5b5a96464f
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>me.skymc</groupId>
|
||||
<artifactId>TabooLib</artifactId>
|
||||
<version>4.25</version>
|
||||
<version>4.26</version>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -112,7 +112,7 @@ public class Main extends JavaPlugin {
|
||||
// 载入权限
|
||||
PermissionUtils.loadRegisteredServiceProvider();
|
||||
// 物品名称
|
||||
ItemUtils.LoadLib();
|
||||
ItemUtils.init();
|
||||
// 低层工具
|
||||
DabItemUtils.getInstance();
|
||||
// 载入周期管理器
|
||||
|
@ -25,25 +25,27 @@ public class TConfiguration extends YamlConfiguration {
|
||||
TLib.getTLib().getConfigWatcher().addSimpleListener(this.file, this::reload);
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放文件监听
|
||||
*/
|
||||
public void release() {
|
||||
TLib.getTLib().getConfigWatcher().removeListener(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新载入配置
|
||||
*/
|
||||
public void reload() {
|
||||
try {
|
||||
load(file);
|
||||
Optional.ofNullable(runnable).ifPresent(Runnable::run);
|
||||
runListener();
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
TLogger.getGlobalLogger().warn("Cannot load configuration from stream: " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void runListener() {
|
||||
try {
|
||||
Optional.ofNullable(runnable).ifPresent(Runnable::run);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建配置文件
|
||||
*
|
||||
|
@ -4,13 +4,13 @@ import com.ilummc.tlib.resources.TLocale;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.skymc.taboolib.Main;
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.common.configuration.TConfiguration;
|
||||
import me.skymc.taboolib.fileutils.ConfigUtils;
|
||||
import me.skymc.taboolib.itemnbtapi.NBTItem;
|
||||
import me.skymc.taboolib.itemnbtapi.NBTList;
|
||||
import me.skymc.taboolib.itemnbtapi.NBTListCompound;
|
||||
import me.skymc.taboolib.itemnbtapi.NBTType;
|
||||
import me.skymc.taboolib.other.NumberUtils;
|
||||
import me.skymc.taboolib.string.Language;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -39,74 +39,59 @@ import java.util.stream.IntStream;
|
||||
*/
|
||||
public class ItemUtils {
|
||||
|
||||
private static FileConfiguration itemdir = null;
|
||||
|
||||
private static FileConfiguration itemCache = null;
|
||||
|
||||
private static File finalItemsFolder;
|
||||
|
||||
private static LinkedHashMap<String, String> itemlib = new LinkedHashMap<>();
|
||||
|
||||
private static FileConfiguration itemDir;
|
||||
private static FileConfiguration itemCache;
|
||||
private static TConfiguration itemName;
|
||||
private static LinkedHashMap<String, String> itemLib = new LinkedHashMap<>();
|
||||
private static LinkedHashMap<String, ItemStack> itemCaches = new LinkedHashMap<>();
|
||||
|
||||
private static LinkedHashMap<String, ItemStack> itemCachesFinal = new LinkedHashMap<>();
|
||||
|
||||
public static FileConfiguration getItemdir() {
|
||||
return itemdir;
|
||||
}
|
||||
|
||||
public static FileConfiguration getItemCache() {
|
||||
return itemCache;
|
||||
}
|
||||
|
||||
public static File getFinalItemsFolder() {
|
||||
return finalItemsFolder;
|
||||
}
|
||||
|
||||
public static LinkedHashMap<String, String> getItemlib() {
|
||||
return itemlib;
|
||||
}
|
||||
|
||||
public static LinkedHashMap<String, ItemStack> getItemCaches() {
|
||||
return itemCaches;
|
||||
}
|
||||
|
||||
public static LinkedHashMap<String, ItemStack> getItemCachesFinal() {
|
||||
return itemCachesFinal;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物品缓存
|
||||
* 检测顺序:
|
||||
* 1. 固定物品库
|
||||
* 2. 动态物品库
|
||||
*
|
||||
* @param name 物品名称
|
||||
* @return
|
||||
*/
|
||||
public static ItemStack getCacheItem(String name) {
|
||||
// 检测固定物品库是否存在该物品
|
||||
if (itemCachesFinal.containsKey(name)) {
|
||||
return itemCachesFinal.get(name);
|
||||
}
|
||||
// 返回动态物品库
|
||||
return itemCaches.get(name);
|
||||
}
|
||||
|
||||
public static boolean isExists(String name) {
|
||||
return itemCachesFinal.containsKey(name) || itemCaches.containsKey(name);
|
||||
}
|
||||
|
||||
public static void LoadLib() {
|
||||
public static void init() {
|
||||
try {
|
||||
reloadItemDir();
|
||||
reloadItemName();
|
||||
reloadItemCache();
|
||||
itemdir = YamlConfiguration.loadConfiguration(new File(Main.getInst().getConfig().getString("DATAURL.ITEMDIR")));
|
||||
} catch (Exception e) {
|
||||
TLocale.Logger.error("ITEM-UTILS.FAIL-LOAD-ITEMS", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static void reloadItemDir() {
|
||||
File file = new File(Main.getInst().getConfig().getString("DATAURL.ITEMDIR"));
|
||||
if (file.exists()) {
|
||||
itemDir = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
}
|
||||
|
||||
public static void reloadItemName() {
|
||||
itemName = TConfiguration.createInResource(Main.getInst(), "Language/ITEM_NAME.yml");
|
||||
itemName.listener(() -> {
|
||||
itemName.getConfigurationSection("").getKeys(false).forEach(a -> itemLib.put(a, itemName.getString(a)));
|
||||
TLocale.Logger.info("ITEM-UTILS.SUCCESS-LOAD-NAMES", String.valueOf(itemLib.size()));
|
||||
}).runListener();
|
||||
}
|
||||
|
||||
public static void reloadItemCache() {
|
||||
itemCaches.clear();
|
||||
itemCachesFinal.clear();
|
||||
loadItemsFile(getItemCacheFile(), false);
|
||||
finalItemsFolder = new File(Main.getInst().getDataFolder(), "FinalItems");
|
||||
if (!finalItemsFolder.exists()) {
|
||||
finalItemsFolder.mkdir();
|
||||
}
|
||||
Arrays.stream(finalItemsFolder.listFiles()).forEach(file -> loadItemsFile(file, true));
|
||||
TLocale.Logger.info("ITEM-UTILS.SUCCESS-LOAD-CACHES", String.valueOf(itemCaches.size() + itemCachesFinal.size()));
|
||||
}
|
||||
|
||||
public static File getItemCacheFile() {
|
||||
File itemCacheFile = new File(Main.getInst().getDataFolder(), "items.yml");
|
||||
if (!itemCacheFile.exists()) {
|
||||
Main.getInst().saveResource("items.yml", true);
|
||||
}
|
||||
return itemCacheFile;
|
||||
}
|
||||
|
||||
public static void loadItemsFile(File file, boolean finalFile) {
|
||||
FileConfiguration conf = ConfigUtils.load(Main.getInst(), file);
|
||||
for (String name : conf.getConfigurationSection("").getKeys(false)) {
|
||||
@ -120,33 +105,22 @@ public class ItemUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void reloadItemCache() {
|
||||
itemCaches.clear();
|
||||
itemCachesFinal.clear();
|
||||
loadItemsFile(getItemCacheFile(), false);
|
||||
// 创建固定物品库
|
||||
finalItemsFolder = new File(Main.getInst().getDataFolder(), "FinalItems");
|
||||
if (!finalItemsFolder.exists()) {
|
||||
finalItemsFolder.mkdir();
|
||||
}
|
||||
// 检查固定物品库中的物品
|
||||
Arrays.stream(finalItemsFolder.listFiles()).forEach(file -> loadItemsFile(file, true));
|
||||
TLocale.Logger.info("ITEM-UTILS.SUCCESS-LOAD-CACHES", String.valueOf(itemCaches.size() + itemCachesFinal.size()));
|
||||
// *********************************
|
||||
//
|
||||
// API
|
||||
//
|
||||
// *********************************
|
||||
|
||||
public static boolean isExists(String name) {
|
||||
return itemCachesFinal.containsKey(name) || itemCaches.containsKey(name);
|
||||
}
|
||||
|
||||
public static void reloadItemName() {
|
||||
FileConfiguration conf = new Language("ITEM_NAME", Main.getInst(), true).getConfiguration();
|
||||
itemlib.clear();
|
||||
conf.getConfigurationSection("").getKeys(false).forEach(a -> itemlib.put(a, conf.getString(a)));
|
||||
TLocale.Logger.info("ITEM-UTILS.SUCCESS-LOAD-NAMES", String.valueOf(itemlib.size()));
|
||||
public static ItemStack getCacheItem(String name) {
|
||||
return itemCachesFinal.containsKey(name) ? itemCachesFinal.get(name) : itemCaches.get(name);
|
||||
}
|
||||
|
||||
public static File getItemCacheFile() {
|
||||
File itemCacheFile = new File(Main.getInst().getDataFolder(), "items.yml");
|
||||
if (!itemCacheFile.exists()) {
|
||||
Main.getInst().saveResource("items.yml", true);
|
||||
}
|
||||
return itemCacheFile;
|
||||
public static ItemStack getItemFromDir(String name) {
|
||||
return itemDir != null ? itemDir.getItemStack("item." + name) : null;
|
||||
}
|
||||
|
||||
public static String getCustomName(ItemStack item) {
|
||||
@ -154,19 +128,7 @@ public class ItemUtils {
|
||||
return TLocale.asString("ITEM-UTILS.EMPTY-ITEM");
|
||||
}
|
||||
int data = item.getType().getMaxDurability() == 0 ? item.getDurability() : 0;
|
||||
return item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : itemlib.get(item.getType() + ":" + data) == null ? item.getType().toString() : itemlib.get(item.getType() + ":" + data);
|
||||
}
|
||||
|
||||
public static ItemStack getItemFromDir(String name) {
|
||||
if (itemdir != null) {
|
||||
return itemdir.getItemStack("item." + name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ItemStack item(int n, int a, int d) {
|
||||
return new ItemStack(n, a, (short) d);
|
||||
return item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : itemLib.get(item.getType() + ":" + data) == null ? item.getType().toString() : itemLib.get(item.getType() + ":" + data);
|
||||
}
|
||||
|
||||
public static ItemStack setName(ItemStack i, String n) {
|
||||
@ -176,7 +138,7 @@ public class ItemUtils {
|
||||
return i;
|
||||
}
|
||||
|
||||
public static ItemStack Enchant(ItemStack i, Enchantment e, int l) {
|
||||
public static ItemStack enchant(ItemStack i, Enchantment e, int l) {
|
||||
ItemMeta meta = i.getItemMeta();
|
||||
meta.addEnchant(e, l, false);
|
||||
i.setItemMeta(meta);
|
||||
@ -203,10 +165,7 @@ public class ItemUtils {
|
||||
}
|
||||
|
||||
public static String asString(String args, Player placeholderPlayer) {
|
||||
if (placeholderPlayer == null) {
|
||||
return args.replace("&", "§");
|
||||
}
|
||||
return PlaceholderAPI.setPlaceholders(placeholderPlayer, args.replace("&", "§"));
|
||||
return placeholderPlayer == null ? args.replace("&", "§") : PlaceholderAPI.setPlaceholders(placeholderPlayer, args.replace("&", "§"));
|
||||
}
|
||||
|
||||
public static List<String> asString(List<String> args, Player placeholderPlayer) {
|
||||
@ -281,58 +240,30 @@ public class ItemUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 包含介绍
|
||||
*
|
||||
* @param i 物品
|
||||
* @param a 关键字
|
||||
*/
|
||||
public static int getLore(ItemStack i, String a) {
|
||||
return isLored(i) ? IntStream.range(0, i.getItemMeta().getLore().size()).filter(j -> i.getItemMeta().getLore().get(j).contains(a)).findFirst().orElse(0) : 0;
|
||||
}
|
||||
|
||||
public static boolean hasLore(ItemStack i, String a) {
|
||||
return isLored(i) && i.getItemMeta().getLore().toString().contains(a);
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果已描述
|
||||
*
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public static boolean isLored(ItemStack i) {
|
||||
return i != null && i.getItemMeta() != null && i.getItemMeta().getLore() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果已命名
|
||||
*
|
||||
* @param i
|
||||
* @return
|
||||
*/
|
||||
public static boolean isNamed(ItemStack i) {
|
||||
return i != null && i.getItemMeta() != null && i.getItemMeta().getDisplayName() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加描述
|
||||
*
|
||||
* @param is 物品
|
||||
* @param lore 描述
|
||||
*/
|
||||
public static ItemStack addLore(ItemStack is, String lore) {
|
||||
public static ItemStack addLore(ItemStack is, String line) {
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
|
||||
List<String> _lore = meta.hasLore() ? meta.getLore() : Collections.emptyList();
|
||||
_lore.add(lore.replaceAll("&", "§"));
|
||||
|
||||
List<String> lore = meta.hasLore() ? meta.getLore() : Collections.emptyList();
|
||||
lore.add(TLocale.Translate.setColored(line));
|
||||
is.setItemMeta(meta);
|
||||
return is;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除描述
|
||||
*
|
||||
* @param is 物品
|
||||
* @param line 行数
|
||||
*/
|
||||
public static ItemStack delLore(ItemStack is, int line) {
|
||||
ItemMeta meta = is.getItemMeta();
|
||||
if (meta.hasLore()) {
|
||||
@ -346,40 +277,7 @@ public class ItemUtils {
|
||||
return is;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取介绍所在行数
|
||||
*
|
||||
* @param i 物品
|
||||
* @param a 关键字
|
||||
*/
|
||||
public static int getLore(ItemStack i, String a) {
|
||||
return isLored(i) ? IntStream.range(0, i.getItemMeta().getLore().size()).filter(j -> i.getItemMeta().getLore().get(j).contains(a)).findFirst().orElse(0) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加耐久
|
||||
*
|
||||
* @param i 物品
|
||||
* @param d 耐久
|
||||
*/
|
||||
public static ItemStack addDurability(ItemStack i, int d) {
|
||||
i.setDurability((short) (i.getDurability() + d));
|
||||
int min = i.getDurability();
|
||||
int max = i.getType().getMaxDurability();
|
||||
if (min >= max) {
|
||||
i.setType(Material.AIR);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换描述
|
||||
*
|
||||
* @param i 物品
|
||||
* @param l1 关键字1
|
||||
* @param l2 关键字2
|
||||
*/
|
||||
public static ItemStack repalceLore(ItemStack i, String l1, String l2) {
|
||||
public static ItemStack replaceLore(ItemStack i, String l1, String l2) {
|
||||
if (!isLored(i)) {
|
||||
return i;
|
||||
} else {
|
||||
@ -392,6 +290,16 @@ public class ItemUtils {
|
||||
return i;
|
||||
}
|
||||
|
||||
public static ItemStack addDurability(ItemStack i, int d) {
|
||||
i.setDurability((short) (i.getDurability() + d));
|
||||
int min = i.getDurability();
|
||||
int max = i.getType().getMaxDurability();
|
||||
if (min >= max) {
|
||||
i.setType(Material.AIR);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public static ItemStack loadItem(FileConfiguration f, String s) {
|
||||
return loadItem(f, s, null);
|
||||
}
|
||||
@ -552,6 +460,62 @@ public class ItemUtils {
|
||||
return nbt;
|
||||
}
|
||||
|
||||
// *********************************
|
||||
//
|
||||
// Getter and Setter
|
||||
//
|
||||
// *********************************
|
||||
|
||||
public static FileConfiguration getItemDir() {
|
||||
return itemDir;
|
||||
}
|
||||
|
||||
public static LinkedHashMap<String, String> getItemLib() {
|
||||
return itemLib;
|
||||
}
|
||||
|
||||
public static FileConfiguration getItemCache() {
|
||||
return itemCache;
|
||||
}
|
||||
|
||||
public static File getFinalItemsFolder() {
|
||||
return finalItemsFolder;
|
||||
}
|
||||
|
||||
public static LinkedHashMap<String, ItemStack> getItemCaches() {
|
||||
return itemCaches;
|
||||
}
|
||||
|
||||
public static LinkedHashMap<String, ItemStack> getItemCachesFinal() {
|
||||
return itemCachesFinal;
|
||||
}
|
||||
|
||||
// *********************************
|
||||
//
|
||||
// Deprecated
|
||||
//
|
||||
// *********************************
|
||||
|
||||
@Deprecated
|
||||
public static FileConfiguration getItemdir() {
|
||||
return itemDir;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static LinkedHashMap<String, String> getItemlib() {
|
||||
return itemLib;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ItemStack item(int n, int a, int d) {
|
||||
return new ItemStack(n, a, (short) d);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ItemStack repalceLore(ItemStack i, String l1, String l2) {
|
||||
return replaceLore(i, l1, l2);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void putO(ItemStack item, Inventory inv, int i) {
|
||||
inv.setItem(i, item);
|
||||
|
@ -3,8 +3,10 @@ package me.skymc.taboolib.inventory.builder;
|
||||
import com.ilummc.tlib.resources.TLocale;
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.string.ArrayUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@ -20,7 +22,7 @@ import java.util.List;
|
||||
/**
|
||||
* @Author sky
|
||||
* @Since 2018-08-22 11:37
|
||||
* @BuilderVersion 1.0
|
||||
* @BuilderVersion 1.1
|
||||
*/
|
||||
public class ItemBuilder {
|
||||
|
||||
@ -40,6 +42,11 @@ public class ItemBuilder {
|
||||
itemMeta = itemStack.getItemMeta();
|
||||
}
|
||||
|
||||
public ItemBuilder(OfflinePlayer player) {
|
||||
this(Material.SKULL_ITEM, 1, 3);
|
||||
this.skullOwner(player.getName());
|
||||
}
|
||||
|
||||
public ItemBuilder material(int id) {
|
||||
itemStack.setType(Material.getMaterial(id));
|
||||
return this;
|
||||
@ -147,6 +154,13 @@ public class ItemBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder skullOwner(String name) {
|
||||
if (itemMeta instanceof SkullMeta) {
|
||||
((SkullMeta) itemMeta).setOwner(name);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder unbreakable(boolean value) {
|
||||
if (TabooLib.getVersionNumber() >= 12000) {
|
||||
itemMeta.setUnbreakable(value);
|
||||
|
@ -2,6 +2,7 @@ package me.skymc.taboolib.itagapi;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import me.skymc.taboolib.Main;
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.packet.PacketUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -132,7 +133,10 @@ public class TagDataHandler implements Listener {
|
||||
entryTeam.addEntry(playerData.getNameDisplay());
|
||||
entryTeam.setPrefix(playerData.getPrefix());
|
||||
entryTeam.setSuffix(playerData.getSuffix());
|
||||
TagUtils.cleanEmptyTeamInScoreboard(scoreboard);
|
||||
// 傻逼 BedWarsRel 我草你妈的
|
||||
if (TabooLib.instance().getConfig().getBoolean("TABLIST-AUTO-CLEAN-TEAM", true)) {
|
||||
TagUtils.cleanEmptyTeamInScoreboard(scoreboard);
|
||||
}
|
||||
}
|
||||
|
||||
private void cancelPlayerVariable(Player player, TagPlayerData playerData) {
|
||||
@ -142,7 +146,10 @@ public class TagDataHandler implements Listener {
|
||||
for (Player online : Bukkit.getOnlinePlayers()) {
|
||||
Scoreboard scoreboard = TagUtils.getScoreboardComputeIfAbsent(player);
|
||||
TagUtils.cleanEntryInScoreboard(scoreboard, playerData.getNameDisplay());
|
||||
TagUtils.cleanEmptyTeamInScoreboard(scoreboard);
|
||||
// 傻逼 BedWarsRel 我草你妈的
|
||||
if (TabooLib.instance().getConfig().getBoolean("TABLIST-AUTO-CLEAN-TEAM", true)) {
|
||||
TagUtils.cleanEmptyTeamInScoreboard(scoreboard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,7 +164,7 @@ public class TagDataHandler implements Listener {
|
||||
downloadPlayerVariable(e.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler (priority = EventPriority.MONITOR)
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onQuit(PlayerQuitEvent e) {
|
||||
cancelPlayerVariable(e.getPlayer(), unregisterPlayerData(e.getPlayer()));
|
||||
}
|
||||
|
@ -1,36 +1,19 @@
|
||||
package me.skymc.taboolib.skull;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import me.skymc.taboolib.inventory.builder.ItemBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
@Deprecated
|
||||
public class SkullUtils {
|
||||
|
||||
public static ItemStack getItme(OfflinePlayer p ) {
|
||||
SkullMeta s = (SkullMeta) Bukkit.getItemFactory().getItemMeta(Material.SKULL_ITEM);
|
||||
s.setOwner(p.getName());
|
||||
|
||||
ItemStack i = new ItemStack(Material.SKULL_ITEM);
|
||||
i.setDurability((short) 3);
|
||||
i.setItemMeta(s);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public static ItemStack getOnlineItem(OfflinePlayer p ) {
|
||||
if (p.isOnline())
|
||||
{
|
||||
SkullMeta s = (SkullMeta) Bukkit.getItemFactory().getItemMeta(Material.SKULL_ITEM);
|
||||
s.setOwner(p.getName());
|
||||
|
||||
ItemStack i = new ItemStack(Material.SKULL_ITEM);
|
||||
i.setDurability((short) 3);
|
||||
i.setItemMeta(s);
|
||||
return i;
|
||||
}
|
||||
return new ItemStack(Material.SKULL_ITEM);
|
||||
}
|
||||
|
||||
public static ItemStack getItme(OfflinePlayer p) {
|
||||
return new ItemBuilder(p).build();
|
||||
}
|
||||
|
||||
public static ItemStack getOnlineItem(OfflinePlayer p) {
|
||||
return p.isOnline() ? new ItemBuilder(p).build() : new ItemStack(Material.SKULL_ITEM);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,9 +2,13 @@ package me.skymc.taboolib.socket;
|
||||
|
||||
import com.ilummc.tlib.resources.TLocale;
|
||||
import me.skymc.taboolib.TabooLib;
|
||||
import me.skymc.taboolib.commands.builder.SimpleCommandBuilder;
|
||||
import me.skymc.taboolib.other.NumberUtils;
|
||||
import me.skymc.taboolib.socket.packet.Packet;
|
||||
import me.skymc.taboolib.socket.packet.PacketSerializer;
|
||||
import me.skymc.taboolib.socket.packet.impl.PacketCommand;
|
||||
import me.skymc.taboolib.socket.packet.impl.PacketMessage;
|
||||
import me.skymc.taboolib.string.ArrayUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.*;
|
||||
@ -83,6 +87,23 @@ public class TabooLibClient {
|
||||
TLocale.sendToConsole("COMMUNICATION.FAILED-READING-PACKET", e.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
SimpleCommandBuilder.create("TabooLibClient", TabooLib.instance())
|
||||
.aliases("tclient")
|
||||
.permission("*")
|
||||
.execute((sender, args) -> {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage("§c[TabooLibClient] §f/tclient message §7[TEXT] §8- §7发送测试信息");
|
||||
sender.sendMessage("§c[TabooLibClient] §f/tclient command §7[TEXT] §8- §7发送测试命令");
|
||||
} else if (args[0].equalsIgnoreCase("message") && args.length > 1) {
|
||||
sendPacket(new PacketMessage(ArrayUtils.arrayJoin(args, 1)));
|
||||
} else if (args[0].equalsIgnoreCase("command") && args.length > 1) {
|
||||
sendPacket(new PacketCommand(ArrayUtils.arrayJoin(args, 1)));
|
||||
} else {
|
||||
sender.sendMessage("§c[TabooLibClient] §7指令错误.");
|
||||
}
|
||||
return true;
|
||||
}).build();
|
||||
}
|
||||
|
||||
// *********************************
|
||||
|
@ -55,7 +55,7 @@ public class TabooLibServer {
|
||||
/*
|
||||
检测无效的客户端连接,如果超过 5000 毫秒没有收到客户端的回应(上一次心跳包的回应)则注销链接
|
||||
*/
|
||||
client.entrySet().stream().filter(connection -> connection.getValue().isAlive()).map(connection -> new PacketQuit(connection.getKey(), "Lost connection")).forEach(TabooLibServer::sendPacket);
|
||||
client.entrySet().stream().filter(connection -> !connection.getValue().isAlive()).map(connection -> new PacketQuit(connection.getKey(), "Lost connection")).forEach(TabooLibServer::sendPacket);
|
||||
}, 0, 1, TimeUnit.SECONDS);
|
||||
|
||||
while (true) {
|
||||
@ -76,7 +76,6 @@ public class TabooLibServer {
|
||||
}
|
||||
|
||||
public static void sendPacket(String origin) {
|
||||
println("Packet sending: " + origin + ", online: " + client.size());
|
||||
// 在服务端尝试解析动作并运行
|
||||
Optional.ofNullable(PacketSerializer.unSerialize(origin)).ifPresent(Packet::readOnServer);
|
||||
// 将动作发送至所有客户端
|
||||
|
@ -0,0 +1,51 @@
|
||||
package me.skymc.taboolib.socket.packet.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ilummc.tlib.resources.TLocale;
|
||||
import me.skymc.taboolib.socket.TabooLibServer;
|
||||
import me.skymc.taboolib.socket.packet.Packet;
|
||||
import me.skymc.taboolib.socket.packet.PacketType;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* @Author sky
|
||||
* @Since 2018-08-22 23:01
|
||||
*/
|
||||
@PacketType(name = "command")
|
||||
public class PacketCommand extends Packet {
|
||||
|
||||
private String command;
|
||||
|
||||
public PacketCommand(int port) {
|
||||
super(port);
|
||||
}
|
||||
|
||||
public PacketCommand(String command) {
|
||||
super(Bukkit.getPort());
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readOnServer() {
|
||||
String[] args = command.split(" ");
|
||||
if (args[0].equalsIgnoreCase("online")) {
|
||||
TabooLibServer.sendPacket(new PacketMessage(0, "Online: " + TabooLibServer.getClient().size()));
|
||||
} else {
|
||||
TabooLibServer.sendPacket(new PacketMessage(0, "Invalid arguments."));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readOnClient() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(JsonObject json) {
|
||||
json.addProperty("command", this.command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unSerialize(JsonObject json) {
|
||||
this.command = json.get("command").getAsString();
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package me.skymc.taboolib.socket.packet.impl;
|
||||
import me.skymc.taboolib.socket.TabooLibClient;
|
||||
import me.skymc.taboolib.socket.packet.Packet;
|
||||
import me.skymc.taboolib.socket.packet.PacketType;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* @Author sky
|
||||
|
@ -5,6 +5,7 @@ import com.ilummc.tlib.resources.TLocale;
|
||||
import me.skymc.taboolib.socket.TabooLibServer;
|
||||
import me.skymc.taboolib.socket.packet.Packet;
|
||||
import me.skymc.taboolib.socket.packet.PacketType;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* @Author sky
|
||||
@ -24,9 +25,14 @@ public class PacketMessage extends Packet {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public PacketMessage(String message) {
|
||||
super(Bukkit.getPort());
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readOnServer() {
|
||||
TabooLibServer.println(message);
|
||||
TabooLibServer.println(getPort() + ": " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -46,7 +46,7 @@ public class ClientConnection implements Runnable {
|
||||
/*
|
||||
连接丢失,客户端退出
|
||||
*/
|
||||
TabooLibServer.sendPacket(new PacketQuit(socket.getPort(), e.getMessage()));
|
||||
TabooLibServer.sendPacket(new PacketQuit(socket.getPort(), "SocketException: " + e.getMessage()));
|
||||
} catch (Exception e) {
|
||||
TabooLibServer.println("Client running failed: " + e.toString());
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.skymc.taboolib.support;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
||||
@ -9,60 +10,59 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author AgarthaLib
|
||||
*/
|
||||
public class SupportWorldGuard {
|
||||
|
||||
String Source_code_from_AgarthaLib;
|
||||
private WorldGuardPlugin worldGuard;
|
||||
|
||||
public SupportWorldGuard() {
|
||||
final Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
|
||||
if (plugin != null) {
|
||||
this.worldGuard = (WorldGuardPlugin) plugin;
|
||||
}
|
||||
Preconditions.checkNotNull(Bukkit.getServer().getPluginManager().getPlugin("WorldGuard"), "WorldGuard was not found.");
|
||||
worldGuard = WorldGuardPlugin.inst();
|
||||
}
|
||||
|
||||
public final WorldGuardPlugin getWorldGuard() {
|
||||
public WorldGuardPlugin getWorldGuard() {
|
||||
return this.worldGuard;
|
||||
}
|
||||
|
||||
public final RegionManager getRegionManager(final World world) {
|
||||
public RegionManager getRegionManager(World world) {
|
||||
return this.worldGuard.getRegionManager(world);
|
||||
}
|
||||
|
||||
public final boolean isRegionManagerExists(final World world) {
|
||||
public boolean isRegionManagerExists(World world) {
|
||||
return this.getRegionManager(world) != null;
|
||||
}
|
||||
|
||||
public final Collection<String> getRegionIDs(final World world) {
|
||||
final RegionManager regionManager = this.getRegionManager(world);
|
||||
return regionManager.getRegions().keySet();
|
||||
public Collection<String> getRegionIDs(World world) {
|
||||
return getRegionManager(world).getRegions().keySet();
|
||||
}
|
||||
|
||||
public final Collection<ProtectedRegion> getRegions(final World world) {
|
||||
final RegionManager regionManager = this.getRegionManager(world);
|
||||
return regionManager.getRegions().values();
|
||||
public Collection<ProtectedRegion> getRegions(World world) {
|
||||
return getRegionManager(world).getRegions().values();
|
||||
}
|
||||
|
||||
public final ProtectedRegion getRegion(final World world, final String id) {
|
||||
final RegionManager regionManager = this.getRegionManager(world);
|
||||
if (regionManager != null) {
|
||||
for (final String key : regionManager.getRegions().keySet()) {
|
||||
if (key.equalsIgnoreCase(id)) {
|
||||
return regionManager.getRegion(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
public List<String> getRegionsAtLocation(World world, Location location) {
|
||||
return getRegions(world).stream().filter(protectedRegion -> protectedRegion.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())).map(ProtectedRegion::getId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public final boolean isRegionExists(final World world, final String id) {
|
||||
public ProtectedRegion getRegion(World world, String id) {
|
||||
RegionManager regionManager = this.getRegionManager(world);
|
||||
return regionManager != null ? regionManager.getRegions().keySet().stream().filter(key -> key.equalsIgnoreCase(id)).findFirst().map(regionManager::getRegion).orElse(null) : null;
|
||||
}
|
||||
|
||||
public boolean isRegionExists(World world, String id) {
|
||||
return this.getRegion(world, id) != null;
|
||||
}
|
||||
|
||||
public final boolean isPlayerInsideRegion(final ProtectedRegion region, final Player player) {
|
||||
final Location location = player.getLocation();
|
||||
public boolean isPlayerInsideRegion(ProtectedRegion region, Player player) {
|
||||
Location location = player.getLocation();
|
||||
return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
}
|
||||
|
@ -33,10 +33,12 @@ LOCALE:
|
||||
# 关闭可提升性能
|
||||
# 如果需要开启仍然可以在语言文件中加入 papi: true
|
||||
USE_PAPI: false
|
||||
|
||||
# 玩家列表(TAB)是否根据前缀排序
|
||||
# 启用后将会导致部分通过计分板获取玩家数据的插件出错(BedwarsRel、SkyWars)
|
||||
TABLIST-SORT: false
|
||||
|
||||
# 玩家列表(TAB-API)是否根据前缀排序
|
||||
TABLIST-SORT: true
|
||||
|
||||
# 玩家列表(TAB-API)是否自动清理没有成员的队伍
|
||||
TABLIST-AUTO-CLEAN-TEAM: true
|
||||
|
||||
# 是否启用更新检测
|
||||
UPDATE-CHECK: true
|
||||
|
@ -569,6 +569,7 @@ COMMUNICATION:
|
||||
FAILED-CONNECT-CLIENT: '§8[§3§lTabooLibClient§8] &4本地通讯网络连接出错: {0}'
|
||||
FAILED-READING-PACKET: '§8[§3§lTabooLibClient§8] &4本地通讯网络数据包读取失败: {0}'
|
||||
SUCCESS-CONNECTED: '§8[§3§lTabooLibClient§8] &7本地通讯网络连接成功.'
|
||||
CLIENT-JOINED: '§8[§3§lTabooLibClient§8] &7服务器 &flocalhost:{0} &7加入本地通讯网络.'
|
||||
CLIENT-QUITED: '§8[§3§lTabooLibClient§8] &7服务器 &flocalhost:{0} &7退出本地通讯网络.'
|
||||
PACKET-MESSAGE: '§8[§3§lTabooLibClient§8] &7服务器 &flocalhost:{0} &7发送信息: &f{1}'
|
||||
CLIENT-JOINED: '§8[§3§lTabooLibClient§8] &7服务器 &f{0} &7加入本地通讯网络.'
|
||||
CLIENT-QUITED: '§8[§3§lTabooLibClient§8] &7服务器 &f{0} &7退出本地通讯网络.'
|
||||
PACKET-MESSAGE: '§8[§3§lTabooLibClient§8] &7服务器 &f{0} &7发送信息: &f{1}'
|
||||
PACKET-COMMAND: '§8[§3§lTabooLibClient§8] &7服务器 &f{0} &7运行命令: &f{1}'
|
Loading…
Reference in New Issue
Block a user