Skip to content

Commit

Permalink
Update color utils and dependency management
Browse files Browse the repository at this point in the history
  • Loading branch information
UltraFaceguy committed Feb 5, 2022
1 parent cf665e1 commit 8d21066
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 126 deletions.
27 changes: 25 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</parent>

<artifactId>facecore</artifactId>
<version>1.18.1.0</version>
<version>1.18.1.1</version>
<packaging>jar</packaging>

<name>facecore</name>
Expand Down Expand Up @@ -128,7 +128,7 @@
<dependency>
<groupId>com.loohp</groupId>
<artifactId>InteractiveChat</artifactId>
<version>4.1.0.18</version>
<version>4.1.1.14</version>
<scope>provided</scope>
</dependency>

Expand Down Expand Up @@ -216,6 +216,29 @@
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.8.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.loohp</groupId>
<artifactId>InteractiveChat</artifactId>
<version>4.1.1.14</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>

<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class EveryTickTask extends BukkitRunnable {
public void run() {
for (Player player : Bukkit.getOnlinePlayers()) {
MoveUtil.setSneak(player);
MoveUtil.setVelocity(player);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,11 +43,26 @@ public static Map<Integer, ItemStack> 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<String> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,31 @@
*/
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;

public class TextUtils {

public static List<String> color(List<String> text) {
List<String> 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<String> getLore(ItemStack stack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,138 +22,25 @@
*/
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<String, Object> advCriteria = new HashMap();
String[][] advRequirements;
advCriteria.put("for_free", nmsCriterionConstructor.newInstance(nmsCriterionTriggerImpossibleAConstructor.newInstance()));
List<String[]> 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<Object, Object> 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<Object> 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 {
INFO,
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();
}

}
}

0 comments on commit 8d21066

Please sign in to comment.