diff --git a/build.gradle b/build.gradle index 66ba5bb..95ecb71 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'com.github.johnrengelman.shadow' version '4.0.4' } group = 'me.skymc' -version = '4.76' +version = '4.77' sourceCompatibility = 1.8 targetCompatibility = 1.8 diff --git a/src/main/scala/com/ilummc/tlib/resources/TLocale.java b/src/main/scala/com/ilummc/tlib/resources/TLocale.java index 12175fe..1b41f23 100644 --- a/src/main/scala/com/ilummc/tlib/resources/TLocale.java +++ b/src/main/scala/com/ilummc/tlib/resources/TLocale.java @@ -52,6 +52,10 @@ public class TLocale { Ref.getCallerClass(3).ifPresent(clazz -> sendTo(path, sender, args, clazz)); } + public static void broadcast(String path, String... args) { + Ref.getCallerClass(3).ifPresent(clazz -> Bukkit.getOnlinePlayers().forEach(player -> sendTo(path, player, args, clazz))); + } + public static String asString(String path, String... args) { try { return asString(path, Ref.getCallerClass(3).orElse(Main.class), args); @@ -119,6 +123,14 @@ public class TLocale { return args.stream().map(var -> ChatColor.translateAlternateColorCodes('&', var)).collect(Collectors.toList()); } + public static String setUncolored(String args) { + return ChatColor.stripColor(args); + } + + public static List setUncolored(List args) { + return args.stream().map(ChatColor::stripColor).collect(Collectors.toList()); + } + public static String setPlaceholders(CommandSender sender, String args) { return isPlaceholderPluginEnabled() ? sender instanceof Player ? PlaceholderAPI.setPlaceholders((Player) sender, args) : args : args; } diff --git a/src/main/scala/me/skymc/taboolib/common/inject/TInjectLoader.java b/src/main/scala/me/skymc/taboolib/common/inject/TInjectLoader.java index c8907bd..d0423bb 100644 --- a/src/main/scala/me/skymc/taboolib/common/inject/TInjectLoader.java +++ b/src/main/scala/me/skymc/taboolib/common/inject/TInjectLoader.java @@ -8,6 +8,8 @@ import me.skymc.taboolib.commands.builder.SimpleCommandBuilder; import me.skymc.taboolib.common.configuration.TConfiguration; import me.skymc.taboolib.common.packet.TPacketHandler; import me.skymc.taboolib.common.packet.TPacketListener; +import me.skymc.taboolib.cooldown.seconds.CooldownPack2; +import me.skymc.taboolib.cooldown.seconds.CooldownUtils2; import org.bukkit.plugin.Plugin; import java.lang.reflect.Field; @@ -71,6 +73,14 @@ public class TInjectLoader implements TabooLibLoader.Loader { e.printStackTrace(); } }); + // CooldownPack Inject + injectTypes.put(CooldownPack2.class, (plugin, field, args, instance) -> { + try { + CooldownUtils2.register((CooldownPack2) field.get(instance), plugin); + } catch (Throwable t) { + t.printStackTrace(); + } + }); } @Override diff --git a/src/main/scala/me/skymc/taboolib/inventory/TEquipment.java b/src/main/scala/me/skymc/taboolib/inventory/TEquipment.java new file mode 100644 index 0000000..4e131ec --- /dev/null +++ b/src/main/scala/me/skymc/taboolib/inventory/TEquipment.java @@ -0,0 +1,78 @@ +package me.skymc.taboolib.inventory; + +import com.google.common.collect.Maps; +import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; + +import java.util.Arrays; +import java.util.Map; + +/** + * @Author 坏黑 + * @Since 2019-04-25 22:01 + */ +public enum TEquipment { + + HAND(EquipmentSlot.HAND, -1), + + OFF_HAND(EquipmentSlot.OFF_HAND, 40), + + FEET(EquipmentSlot.FEET, 36), + + LEGS(EquipmentSlot.LEGS, 37), + + CHEST(EquipmentSlot.CHEST, 38), + + HEAD(EquipmentSlot.HEAD, 39); + + private EquipmentSlot bukkit; + private int slot; + + TEquipment(EquipmentSlot bukkit, int slot) { + this.bukkit = bukkit; + this.slot = slot; + } + + public void setItem(Player player, ItemStack item) { + if (this != HAND) { + player.getInventory().setItem(slot, item); + } else { + player.setItemInHand(item); + } + } + + public ItemStack getItem(Player player) { + if (this != HAND) { + return player.getInventory().getItem(slot); + } else { + return player.getItemInHand(); + } + } + + public static TEquipment fromBukkit(EquipmentSlot bukkit) { + return Arrays.stream(values()).filter(tEquipment -> tEquipment.bukkit == bukkit).findFirst().orElse(null); + } + + public static Map getItems(Player player) { + Map map = Maps.newHashMap(); + for (TEquipment equipment : values()) { + map.put(equipment, equipment.getItem(player)); + } + return map; + } + + // ********************************* + // + // Getter and Setter + // + // ********************************* + + public EquipmentSlot getBukkit() { + return bukkit; + } + + public int getSlot() { + return slot; + } +} diff --git a/src/main/scala/me/skymc/taboolib/json/tellraw/TellrawJson.java b/src/main/scala/me/skymc/taboolib/json/tellraw/TellrawJson.java index f7f87c5..60df295 100644 --- a/src/main/scala/me/skymc/taboolib/json/tellraw/TellrawJson.java +++ b/src/main/scala/me/skymc/taboolib/json/tellraw/TellrawJson.java @@ -6,6 +6,7 @@ import com.ilummc.tlib.resources.TLocale; import com.ilummc.tlib.util.Strings; import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.string.ArrayUtils; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -55,6 +56,14 @@ public class TellrawJson { return new TellrawJson(); } + public void broadcast() { + Bukkit.getOnlinePlayers().forEach(player -> send(player, new String[0])); + } + + public void broadcast(String... args) { + Bukkit.getOnlinePlayers().forEach(player -> send(player, args)); + } + public void send(CommandSender sender) { send(sender, new String[0]); }