diff --git a/pom.xml b/pom.xml index fa2b463..85ba487 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ facecore - 1.18.1.0 + 1.18.1.1 jar facecore @@ -128,7 +128,7 @@ com.loohp InteractiveChat - 4.1.0.18 + 4.1.1.14 provided @@ -216,6 +216,29 @@ + + + + com.comphenix.protocol + ProtocolLib + 4.8.0-SNAPSHOT + provided + + + me.clip + placeholderapi + 2.11.1 + provided + + + com.loohp + InteractiveChat + 4.1.1.14 + provided + + + + apache.snapshots diff --git a/src/main/java/com/tealcube/minecraft/bukkit/facecore/profile/MoveListener.java b/src/main/java/com/tealcube/minecraft/bukkit/facecore/profile/MoveListener.java index 96baae2..64e5b97 100644 --- a/src/main/java/com/tealcube/minecraft/bukkit/facecore/profile/MoveListener.java +++ b/src/main/java/com/tealcube/minecraft/bukkit/facecore/profile/MoveListener.java @@ -45,7 +45,6 @@ public void onPlayerMove(PlayerMoveEvent event) { || event.getFrom().getY() != event.getTo().getY() || event.getFrom().getZ() != event.getTo().getZ()) { MoveUtil.setLastMoved(event.getPlayer()); - MoveUtil.setVelocity(event.getPlayer()); } boolean grounded = ((Entity) event.getPlayer()).isOnGround(); diff --git a/src/main/java/com/tealcube/minecraft/bukkit/facecore/task/EveryTickTask.java b/src/main/java/com/tealcube/minecraft/bukkit/facecore/task/EveryTickTask.java index 573cab0..d52ee61 100644 --- a/src/main/java/com/tealcube/minecraft/bukkit/facecore/task/EveryTickTask.java +++ b/src/main/java/com/tealcube/minecraft/bukkit/facecore/task/EveryTickTask.java @@ -33,6 +33,7 @@ public class EveryTickTask extends BukkitRunnable { public void run() { for (Player player : Bukkit.getOnlinePlayers()) { MoveUtil.setSneak(player); + MoveUtil.setVelocity(player); } } } diff --git a/src/main/java/com/tealcube/minecraft/bukkit/facecore/utilities/ItemUtils.java b/src/main/java/com/tealcube/minecraft/bukkit/facecore/utilities/ItemUtils.java index 4592aee..bf587fa 100644 --- a/src/main/java/com/tealcube/minecraft/bukkit/facecore/utilities/ItemUtils.java +++ b/src/main/java/com/tealcube/minecraft/bukkit/facecore/utilities/ItemUtils.java @@ -23,10 +23,13 @@ package com.tealcube.minecraft.bukkit.facecore.utilities; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -40,11 +43,26 @@ public static Map giveOrDrop(@Nonnull Player player, @Nullab World world = player.getWorld(); Location location = player.getLocation(); drop.values().forEach((item) -> { - world.dropItemNaturally(location, item); + if (item != null && item.getType() != Material.AIR) { + world.dropItemNaturally(location, item); + } }); return drop; } else { return new HashMap(); } } + + public static boolean containsLore(ItemStack itemStack, List lore) { + if (itemStack == null || !itemStack.hasItemMeta() || !itemStack.getItemMeta().hasLore()) { + return false; + } + for (String s : TextUtils.getLore(itemStack)) { + String stripped = ChatColor.stripColor(s); + if (lore.contains(stripped)) { + return true; + } + } + return false; + } } diff --git a/src/main/java/com/tealcube/minecraft/bukkit/facecore/utilities/TextUtils.java b/src/main/java/com/tealcube/minecraft/bukkit/facecore/utilities/TextUtils.java index 2f64c41..539517c 100644 --- a/src/main/java/com/tealcube/minecraft/bukkit/facecore/utilities/TextUtils.java +++ b/src/main/java/com/tealcube/minecraft/bukkit/facecore/utilities/TextUtils.java @@ -22,10 +22,9 @@ */ package com.tealcube.minecraft.bukkit.facecore.utilities; -import io.pixeloutlaw.minecraft.spigot.garbage.ListExtensionsKt; -import io.pixeloutlaw.minecraft.spigot.garbage.StringExtensionsKt; import java.util.ArrayList; import java.util.List; +import net.md_5.bungee.api.ChatColor; import org.apache.commons.lang3.StringUtils; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -33,17 +32,21 @@ public class TextUtils { public static List color(List text) { + List newList = new ArrayList<>(); if (text == null || text.size() == 0) { - return new ArrayList<>(); + return newList; + } + for (String s : text) { + newList.add(ChatColor.translateAlternateColorCodes('&', s)); } - return ListExtensionsKt.chatColorize(text); + return newList; } public static String color(String text) { if (StringUtils.isBlank(text)) { return text; } - return StringExtensionsKt.chatColorize(text); + return ChatColor.translateAlternateColorCodes('&', text); } public static List getLore(ItemStack stack) { diff --git a/src/main/java/com/tealcube/minecraft/bukkit/facecore/utilities/ToastUtils.java b/src/main/java/com/tealcube/minecraft/bukkit/facecore/utilities/ToastUtils.java index d6cc7b6..56e443d 100644 --- a/src/main/java/com/tealcube/minecraft/bukkit/facecore/utilities/ToastUtils.java +++ b/src/main/java/com/tealcube/minecraft/bukkit/facecore/utilities/ToastUtils.java @@ -22,100 +22,20 @@ */ package com.tealcube.minecraft.bukkit.facecore.utilities; -import com.comphenix.protocol.events.PacketContainer; -import com.loohp.interactivechat.InteractiveChat; -import com.loohp.interactivechat.libs.net.kyori.adventure.text.Component; -import com.loohp.interactivechat.libs.net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import com.loohp.interactivechat.utils.ChatComponentType; -import com.loohp.interactivechat.utils.ClassUtils; -import com.loohp.interactivechat.utils.ItemStackUtils; -import com.loohp.interactivechat.utils.NMSUtils; -import java.lang.reflect.Array; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.bukkit.ChatColor; +import com.loohp.interactivechat.api.InteractiveChatAPI; +import com.loohp.interactivechat.objectholders.ICPlayer; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import com.loohp.interactivechat.objectholders.ICPlayer; public class ToastUtils { - private static Class nmsMinecraftKeyClass; - private static Constructor nmsMinecraftKeyConstructor; - private static Class nmsAdvancementRewardsClass; - private static Class nmsCustomFunctionAClass; - private static Constructor nmsAdvancementRewardsConstructor; - private static Class nmsAdvancementDisplayClass; - private static Class nmsItemStackClass; - private static Class nmsIChatBaseComponentClass; - private static Class nmsAdvancementFrameTypeClass; - private static Constructor nmsAdvancementDisplayConstructor; - private static Object[] nmsAdvancementFrameTypeEnums; - private static Class nmsCriterionClass; - private static Class nmsCriterionTriggerImpossibleAClass; - private static Constructor nmsCriterionTriggerImpossibleAConstructor; - private static Class nmsCriterionInstanceClass; - private static Constructor nmsCriterionConstructor; - private static Class nmsAdvancementClass; - private static Constructor nmsAdvancementConstructor; - private static Class nmsAdvancementProgressClass; - private static Constructor nmsAdvancementProgressConstructor; - private static Method nmsAdvancementProgressAMethod; - private static Method nmsAdvancementProgressGetCriterionProgressMethod; - private static Method nmsAdvancementProgressGetCriterionProgressBMethod; - private static Class nmsPacketPlayOutAdvancementsClass; - private static Constructor nmsPacketPlayOutAdvancementsConstuctor; - public static void sendToast(Player player, String message, ItemStack stack) { sendToast(player, message, stack, ToastStyle.GOAL); } public static void sendToast(Player player, String message, ItemStack stack, ToastStyle style) { - ICPlayer toastPlayer = new ICPlayer(player); - sendPacketToast(toastPlayer, player, message, stack, style); - } - - private static void sendPacketToast(ICPlayer sender, Player pinged, String message, ItemStack icon, ToastStyle style) { - ChatColor.translateAlternateColorCodes('&', message); - try { - Object minecraftKey = nmsMinecraftKeyConstructor.newInstance("facecore", "toasty/" + sender.getUniqueId()); - Object advRewards = nmsAdvancementRewardsConstructor.newInstance(0, Array.newInstance(nmsMinecraftKeyClass, 0), Array.newInstance(nmsMinecraftKeyClass, 0), null); - Object componentTitle = ChatComponentType.IChatBaseComponent.convertTo( - LegacyComponentSerializer.legacySection().deserialize(message), InteractiveChat.version.isLegacy()); - Object componentSubtitle = ChatComponentType.IChatBaseComponent.convertTo(Component.empty(), InteractiveChat.version.isLegacy()); - Object advancementDisplay = nmsAdvancementDisplayConstructor.newInstance(ItemStackUtils.toNMSCopy(icon), componentTitle, componentSubtitle, null, nmsAdvancementFrameTypeEnums[style.ordinal()], true, false, true); - Map advCriteria = new HashMap(); - String[][] advRequirements; - advCriteria.put("for_free", nmsCriterionConstructor.newInstance(nmsCriterionTriggerImpossibleAConstructor.newInstance())); - List fixedRequirements = new ArrayList(); - fixedRequirements.add(new String[]{"for_free"}); - advRequirements = Arrays.stream(fixedRequirements.toArray()).toArray(String[][]::new); - Object saveAdv = nmsAdvancementConstructor.newInstance(minecraftKey, null, advancementDisplay, advRewards, advCriteria, advRequirements); - Map prg = new HashMap(); - Object advPrg = nmsAdvancementProgressConstructor.newInstance(); - nmsAdvancementProgressAMethod.invoke(advPrg, advCriteria, advRequirements); - nmsAdvancementProgressGetCriterionProgressBMethod.invoke(nmsAdvancementProgressGetCriterionProgressMethod.invoke(advPrg, "for_free")); - prg.put(minecraftKey, advPrg); - PacketContainer packet1 = PacketContainer.fromPacket(nmsPacketPlayOutAdvancementsConstuctor.newInstance(false, Arrays.asList(saveAdv), Collections.emptySet(), prg)); - InteractiveChat.protocolManager.sendServerPacket(pinged, packet1); - Set rm = new HashSet(); - rm.add(minecraftKey); - prg.clear(); - PacketContainer packet2 = PacketContainer.fromPacket(nmsPacketPlayOutAdvancementsConstuctor.newInstance(false, Collections.emptyList(), rm, prg)); - InteractiveChat.protocolManager.sendServerPacket(pinged, packet2); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException var18) { - var18.printStackTrace(); - } + ICPlayer toastPlayer = InteractiveChatAPI.getICPlayer(player); + com.loohp.interactivechat.utils.ToastUtils.mention(toastPlayer, player, TextUtils.color(message), stack); } public enum ToastStyle { @@ -123,37 +43,4 @@ public enum ToastStyle { CHALLENGE, GOAL } - - static { - try { - nmsMinecraftKeyClass = NMSUtils.getNMSClass("net.minecraft.server.%s.MinecraftKey", new String[]{"net.minecraft.resources.MinecraftKey"}); - nmsMinecraftKeyConstructor = nmsMinecraftKeyClass.getConstructor(String.class, String.class); - nmsAdvancementRewardsClass = NMSUtils.getNMSClass("net.minecraft.server.%s.AdvancementRewards", new String[]{"net.minecraft.advancements.AdvancementRewards"}); - nmsCustomFunctionAClass = NMSUtils.getNMSClass("net.minecraft.server.%s.CustomFunction$a", new String[]{"net.minecraft.commands.CustomFunction$a"}); - nmsAdvancementRewardsConstructor = nmsAdvancementRewardsClass.getConstructor(Integer.TYPE, ClassUtils.arrayType(nmsMinecraftKeyClass), ClassUtils.arrayType(nmsMinecraftKeyClass), nmsCustomFunctionAClass); - nmsAdvancementDisplayClass = NMSUtils.getNMSClass("net.minecraft.server.%s.AdvancementDisplay", new String[]{"net.minecraft.advancements.AdvancementDisplay"}); - nmsItemStackClass = NMSUtils.getNMSClass("net.minecraft.server.%s.ItemStack", new String[]{"net.minecraft.world.item.ItemStack"}); - nmsIChatBaseComponentClass = NMSUtils.getNMSClass("net.minecraft.server.%s.IChatBaseComponent", new String[]{"net.minecraft.network.chat.IChatBaseComponent"}); - nmsAdvancementFrameTypeClass = NMSUtils.getNMSClass("net.minecraft.server.%s.AdvancementFrameType", new String[]{"net.minecraft.advancements.AdvancementFrameType"}); - nmsAdvancementDisplayConstructor = nmsAdvancementDisplayClass.getConstructor(nmsItemStackClass, nmsIChatBaseComponentClass, nmsIChatBaseComponentClass, nmsMinecraftKeyClass, nmsAdvancementFrameTypeClass, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE); - nmsAdvancementFrameTypeEnums = nmsAdvancementFrameTypeClass.getEnumConstants(); - nmsCriterionClass = NMSUtils.getNMSClass("net.minecraft.server.%s.Criterion", new String[]{"net.minecraft.advancements.Criterion"}); - nmsCriterionTriggerImpossibleAClass = NMSUtils.getNMSClass("net.minecraft.server.%s.CriterionTriggerImpossible$a", new String[]{"net.minecraft.advancements.critereon.CriterionTriggerImpossible$a"}); - nmsCriterionTriggerImpossibleAConstructor = nmsCriterionTriggerImpossibleAClass.getConstructor(); - nmsCriterionInstanceClass = NMSUtils.getNMSClass("net.minecraft.server.%s.CriterionInstance", new String[]{"net.minecraft.advancements.CriterionInstance"}); - nmsCriterionConstructor = nmsCriterionClass.getConstructor(nmsCriterionInstanceClass); - nmsAdvancementClass = NMSUtils.getNMSClass("net.minecraft.server.%s.Advancement", new String[]{"net.minecraft.advancements.Advancement"}); - nmsAdvancementConstructor = nmsAdvancementClass.getConstructor(nmsMinecraftKeyClass, nmsAdvancementClass, nmsAdvancementDisplayClass, nmsAdvancementRewardsClass, Map.class, String[][].class); - nmsAdvancementProgressClass = NMSUtils.getNMSClass("net.minecraft.server.%s.AdvancementProgress", new String[]{"net.minecraft.advancements.AdvancementProgress"}); - nmsAdvancementProgressConstructor = nmsAdvancementProgressClass.getConstructor(); - nmsAdvancementProgressAMethod = nmsAdvancementProgressClass.getMethod("a", Map.class, String[][].class); - nmsAdvancementProgressGetCriterionProgressMethod = nmsAdvancementProgressClass.getMethod("getCriterionProgress", String.class); - nmsAdvancementProgressGetCriterionProgressBMethod = nmsAdvancementProgressGetCriterionProgressMethod.getReturnType().getMethod("b"); - nmsPacketPlayOutAdvancementsClass = NMSUtils.getNMSClass("net.minecraft.server.%s.PacketPlayOutAdvancements", new String[]{"net.minecraft.network.protocol.game.PacketPlayOutAdvancements"}); - nmsPacketPlayOutAdvancementsConstuctor = nmsPacketPlayOutAdvancementsClass.getConstructor(Boolean.TYPE, Collection.class, Set.class, Map.class); - } catch (Exception var1) { - var1.printStackTrace(); - } - - } }