mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-27 10:59:14 +00:00
Added placeholder api
This commit is contained in:
1
.idea/modules/HMCCosmetics.main.iml
generated
1
.idea/modules/HMCCosmetics.main.iml
generated
@@ -4,7 +4,6 @@
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>PAPER</platformType>
|
||||
<platformType>MCP</platformType>
|
||||
<platformType>ADVENTURE</platformType>
|
||||
</autoDetectTypes>
|
||||
|
||||
@@ -14,6 +14,7 @@ repositories {
|
||||
maven { url = 'https://jitpack.io' }
|
||||
maven { url = 'https://repo.leonardobishop.com/releases/' }
|
||||
maven { url = 'https://repo.dmulloy2.net/repository/public/' }
|
||||
maven { url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -23,6 +24,7 @@ dependencies {
|
||||
compileOnly 'org.jetbrains:annotations:22.0.0'
|
||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.7.0'
|
||||
compileOnly 'net.kyori:adventure-api:4.9.3'
|
||||
compileOnly 'me.clip:placeholderapi:2.10.9'
|
||||
implementation 'net.kyori:adventure-text-minimessage:4.2.0-SNAPSHOT'
|
||||
implementation 'net.kyori:adventure-platform-bukkit:4.0.0'
|
||||
implementation 'dev.triumphteam:triumph-gui:3.0.3'
|
||||
|
||||
@@ -16,6 +16,7 @@ import io.github.fisher2911.hmccosmetics.message.Messages;
|
||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
import me.mattstudios.mf.base.CommandManager;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -29,6 +30,7 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
private MessageHandler messageHandler;
|
||||
private CosmeticsMenu cosmeticsMenu;
|
||||
private CommandManager commandManager;
|
||||
private boolean papiEnabled;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -45,6 +47,8 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
this.registerListeners();
|
||||
|
||||
this.userManager.startTeleportTask();
|
||||
|
||||
this.papiEnabled = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,5 +104,9 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
public ProtocolManager getProtocolManager() {
|
||||
return protocolManager;
|
||||
}
|
||||
|
||||
public boolean isPapiEnabled() {
|
||||
return papiEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.gui.ColorItem;
|
||||
import io.github.fisher2911.hmccosmetics.gui.DyeSelectorGui;
|
||||
import io.github.fisher2911.hmccosmetics.message.Adventure;
|
||||
import io.github.fisher2911.hmccosmetics.util.StringUtils;
|
||||
import org.bukkit.Color;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
@@ -81,10 +82,14 @@ public class DyeGuiSerializer implements TypeSerializer<DyeSelectorGui> {
|
||||
guiItemMap.put(slot, new ColorItem(guiItem.getItemStack(), Color.fromRGB(red, green, blue)));
|
||||
}
|
||||
|
||||
String title = titleNode.getString();
|
||||
|
||||
if (title == null) title = "";
|
||||
|
||||
return new DyeSelectorGui(
|
||||
plugin,
|
||||
Adventure.SERIALIZER.serialize(
|
||||
Adventure.MINI_MESSAGE.parse(titleNode.getString())),
|
||||
Adventure.MINI_MESSAGE.parse(StringUtils.applyPapiPlaceholders(null, title))),
|
||||
rowsNode.getInt(),
|
||||
guiItemMap);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import dev.triumphteam.gui.guis.GuiItem;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.gui.CosmeticGui;
|
||||
import io.github.fisher2911.hmccosmetics.message.Adventure;
|
||||
import io.github.fisher2911.hmccosmetics.papi.PAPIHook;
|
||||
import io.github.fisher2911.hmccosmetics.util.StringUtils;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
@@ -43,7 +45,7 @@ public class GuiSerializer implements TypeSerializer<CosmeticGui> {
|
||||
final ConfigurationNode rowsNode = this.nonVirtualNode(source, ROWS);
|
||||
final ConfigurationNode itemsNode = source.node(ITEMS);
|
||||
|
||||
final var childrenMap = source.node(ITEMS).childrenMap();
|
||||
final var childrenMap = itemsNode.childrenMap();
|
||||
|
||||
final Map<Integer, GuiItem> guiItemMap = new HashMap<>();
|
||||
|
||||
@@ -60,9 +62,13 @@ public class GuiSerializer implements TypeSerializer<CosmeticGui> {
|
||||
guiItemMap.put(slot, guiItem);
|
||||
}
|
||||
|
||||
String title = titleNode.getString();
|
||||
|
||||
if (title == null) title = "";
|
||||
|
||||
return new CosmeticGui(plugin,
|
||||
Adventure.SERIALIZER.serialize(
|
||||
Adventure.MINI_MESSAGE.parse(titleNode.getString())),
|
||||
Adventure.MINI_MESSAGE.parse(StringUtils.applyPapiPlaceholders(null, title))),
|
||||
rowsNode.getInt(),
|
||||
guiItemMap);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
@@ -27,6 +28,7 @@ public class CosmeticGui {
|
||||
protected final MessageHandler messageHandler;
|
||||
protected final String title;
|
||||
protected final int rows;
|
||||
protected final Map<Integer, ItemStack> itemStackMap;
|
||||
protected final Map<Integer, GuiItem> guiItemMap;
|
||||
protected Gui gui;
|
||||
|
||||
@@ -40,6 +42,8 @@ public class CosmeticGui {
|
||||
this.title = title;
|
||||
this.rows = rows;
|
||||
this.guiItemMap = guiItemMap;
|
||||
this.itemStackMap = new HashMap<>();
|
||||
this.guiItemMap.forEach((key, value) -> itemStackMap.put(key, value.getItemStack()));
|
||||
}
|
||||
|
||||
private void setItems(final User user) {
|
||||
@@ -55,6 +59,14 @@ public class CosmeticGui {
|
||||
|
||||
final GuiItem guiItem = entry.getValue();
|
||||
|
||||
final ItemStack itemStack = this.itemStackMap.get(slot);
|
||||
|
||||
if (itemStack == null) continue;
|
||||
|
||||
guiItem.setItemStack(
|
||||
ItemBuilder.from(itemStack.clone()).papiPlaceholders(player).build()
|
||||
);
|
||||
|
||||
if (guiItem instanceof final ArmorItem armorItem) {
|
||||
|
||||
final Map<String, String> placeholders = new HashMap<>();
|
||||
@@ -91,6 +103,7 @@ public class CosmeticGui {
|
||||
armorItem.getItemStack(hasPermission)
|
||||
).namePlaceholders(placeholders).
|
||||
lorePlaceholders(placeholders).
|
||||
papiPlaceholders(player).
|
||||
build(),
|
||||
event -> {
|
||||
if (!hasPermission) {
|
||||
|
||||
@@ -6,15 +6,19 @@ import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ColorBuilder;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class DyeSelectorGui extends CosmeticGui{
|
||||
public class DyeSelectorGui extends CosmeticGui {
|
||||
|
||||
public DyeSelectorGui(
|
||||
final HMCCosmetics plugin,
|
||||
@@ -30,8 +34,21 @@ public class DyeSelectorGui extends CosmeticGui{
|
||||
rows(rows).
|
||||
create();
|
||||
|
||||
final Player player = user.getPlayer();
|
||||
|
||||
for (final var entry : this.guiItemMap.entrySet()) {
|
||||
gui.setItem(entry.getKey(), entry.getValue());
|
||||
|
||||
final GuiItem guiItem = entry.getValue();
|
||||
|
||||
final ItemStack itemStack = this.itemStackMap.get(entry.getKey());
|
||||
|
||||
if (itemStack == null) continue;
|
||||
|
||||
guiItem.setItemStack(
|
||||
ItemBuilder.from(itemStack.clone()).papiPlaceholders(player).build()
|
||||
);
|
||||
|
||||
gui.setItem(entry.getKey(), guiItem);
|
||||
}
|
||||
|
||||
gui.setDefaultClickAction(event -> {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.fisher2911.hmccosmetics.message;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.papi.PAPIHook;
|
||||
import io.github.fisher2911.hmccosmetics.util.StringUtils;
|
||||
import io.github.fisher2911.hmccosmetics.util.Utils;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
@@ -40,22 +41,23 @@ public class MessageHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sender receiver of message
|
||||
* @param key message key
|
||||
* @param sender receiver of message
|
||||
* @param key message key
|
||||
* @param placeholders placeholders
|
||||
*/
|
||||
|
||||
public void sendMessage(final CommandSender sender, final Message key, final Map<String, String> placeholders) {
|
||||
final String message = StringUtils.applyPlaceholders(this.getMessage(key), placeholders);
|
||||
final Component component = Adventure.MINI_MESSAGE.parse(message);
|
||||
this.adventure.sender(sender).sendMessage(component);
|
||||
final String message = this.getPapiPlaceholders(
|
||||
sender,
|
||||
StringUtils.applyPlaceholders(this.getMessage(key), placeholders)
|
||||
);
|
||||
final Component component = Adventure.MINI_MESSAGE.parse(message);
|
||||
this.adventure.sender(sender).sendMessage(component);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sender receiver of message
|
||||
* @param key message key
|
||||
* @param key message key
|
||||
*/
|
||||
|
||||
public void sendMessage(final CommandSender sender, final Message key) {
|
||||
@@ -63,22 +65,23 @@ public class MessageHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player receiver of message
|
||||
* @param key message key
|
||||
* @param player receiver of message
|
||||
* @param key message key
|
||||
* @param placeholders placeholders
|
||||
*/
|
||||
|
||||
public void sendActionBar(final Player player, final Message key, final Map<String, String> placeholders) {
|
||||
final String message = StringUtils.applyPlaceholders(this.getMessage(key), placeholders);
|
||||
final String message = this.getPapiPlaceholders(
|
||||
player,
|
||||
StringUtils.applyPlaceholders(this.getMessage(key), placeholders)
|
||||
);
|
||||
Component component = Adventure.MINI_MESSAGE.parse(message);
|
||||
this.adventure.player(player).sendActionBar(component);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player receiver of message
|
||||
* @param key message key
|
||||
* @param key message key
|
||||
*/
|
||||
|
||||
public void sendActionBar(final Player player, final Message key) {
|
||||
@@ -86,22 +89,23 @@ public class MessageHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player receiver of message
|
||||
* @param key message key
|
||||
* @param player receiver of message
|
||||
* @param key message key
|
||||
* @param placeholders placeholders
|
||||
*/
|
||||
|
||||
public void sendTitle(final Player player, final Message key, final Map<String, String> placeholders) {
|
||||
final String message = StringUtils.applyPlaceholders(this.getMessage(key), placeholders);
|
||||
final String message = this.getPapiPlaceholders(
|
||||
player,
|
||||
StringUtils.applyPlaceholders(this.getMessage(key), placeholders)
|
||||
);
|
||||
Component component = Adventure.MINI_MESSAGE.parse(message);
|
||||
this.adventure.player(player).showTitle(Title.title(component, Component.empty()));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player receiver of message
|
||||
* @param key message key
|
||||
* @param key message key
|
||||
*/
|
||||
|
||||
public void sendTitle(final Player player, final Message key) {
|
||||
@@ -109,7 +113,6 @@ public class MessageHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param key message key
|
||||
* @return message, or empty string if message not found
|
||||
*/
|
||||
@@ -153,4 +156,12 @@ public class MessageHandler {
|
||||
this.messageMap.put(key, new Message(key, message, messageType));
|
||||
}
|
||||
}
|
||||
|
||||
private String getPapiPlaceholders(final CommandSender sender, final String message) {
|
||||
if (sender instanceof final Player player) {
|
||||
return StringUtils.applyPapiPlaceholders(player, message);
|
||||
}
|
||||
return StringUtils.applyPapiPlaceholders(null, message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,4 +9,5 @@ public class Placeholder {
|
||||
|
||||
public static final String ENABLED = "%enabled%";
|
||||
public static final String ALLOWED = "%allowed%";
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package io.github.fisher2911.hmccosmetics.papi;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PAPIHook {
|
||||
|
||||
public static String parse(final Player player, final String string) {
|
||||
return PlaceholderAPI.setPlaceholders(player, string);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,56 +6,36 @@ import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.Pair;
|
||||
import com.comphenix.protocol.wrappers.Vector3F;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.sun.jdi.InvocationException;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
|
||||
import io.github.fisher2911.hmccosmetics.message.MessageHandler;
|
||||
import io.github.fisher2911.hmccosmetics.message.Messages;
|
||||
import io.github.fisher2911.hmccosmetics.message.Placeholder;
|
||||
import io.github.fisher2911.hmccosmetics.util.Keys;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import net.minecraft.core.Vector3f;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
|
||||
import net.minecraft.network.syncher.DataWatcher;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftArmorStand;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.util.EulerAngle;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class User {
|
||||
|
||||
private final UUID uuid;
|
||||
private final PlayerArmor playerArmor;
|
||||
private ArmorStand attached;
|
||||
private ArmorItem lastSetItem;
|
||||
|
||||
private final int armorStandId;
|
||||
private boolean hasArmorStand;
|
||||
private final int armorStandId;
|
||||
|
||||
public User(final UUID uuid, final PlayerArmor playerArmor, final int armorStandId) {
|
||||
this.uuid = uuid;
|
||||
@@ -176,85 +156,10 @@ public class User {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void detach() {
|
||||
if (this.attached != null) {
|
||||
this.attached.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// teleports armor stand to the correct position
|
||||
public void updateArmorStand() {
|
||||
if (true) {
|
||||
this.updatePacketArmorStand();
|
||||
return;
|
||||
}
|
||||
|
||||
final ArmorItem backpackArmorItem = this.playerArmor.getBackpack();
|
||||
if (backpackArmorItem == null) {
|
||||
this.despawnAttached();
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack backpackItem = backpackArmorItem.getItemStack();
|
||||
|
||||
if (backpackItem == null || backpackItem.getType() == Material.AIR) {
|
||||
this.despawnAttached();
|
||||
return;
|
||||
}
|
||||
|
||||
public void spawnArmorStand(final Player other) {
|
||||
final Player player = this.getPlayer();
|
||||
|
||||
if (player == null) {
|
||||
this.despawnAttached();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.attached == null) {
|
||||
this.attached = player.getWorld().spawn(player.getLocation(),
|
||||
ArmorStand.class,
|
||||
armorStand -> {
|
||||
armorStand.setVisible(false);
|
||||
armorStand.setMarker(true);
|
||||
armorStand.getPersistentDataContainer().set(
|
||||
Keys.ARMOR_STAND_KEY,
|
||||
PersistentDataType.BYTE,
|
||||
(byte) 1
|
||||
);
|
||||
player.addPassenger(armorStand);
|
||||
});
|
||||
}
|
||||
|
||||
if (!player.getPassengers().contains(this.attached)) {
|
||||
player.addPassenger(this.attached);
|
||||
}
|
||||
|
||||
final EntityEquipment equipment = this.attached.getEquipment();
|
||||
|
||||
if (equipment == null) {
|
||||
this.despawnAttached();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!backpackItem.equals(equipment.getHelmet())) {
|
||||
equipment.setHelmet(backpackItem);
|
||||
}
|
||||
|
||||
this.attached.
|
||||
setRotation(
|
||||
player.getLocation().getYaw(),
|
||||
player.getLocation().getPitch());
|
||||
}
|
||||
|
||||
public void spawnPacketArmorStand() {
|
||||
|
||||
final Player player = this.getPlayer();
|
||||
|
||||
if (player == null) {
|
||||
this.updatePacketArmorStand();
|
||||
return;
|
||||
}
|
||||
|
||||
this.hasArmorStand = true;
|
||||
if (player == null) return;
|
||||
|
||||
final Location location = player.getLocation();
|
||||
|
||||
@@ -278,18 +183,36 @@ public class User {
|
||||
|
||||
packet.getEntityTypeModifier().write(0, EntityType.ARMOR_STAND);
|
||||
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
try {
|
||||
protocolManager.sendServerPacket(p, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
final PacketContainer ridingPacket = new PacketContainer(PacketType.Play.Server.MOUNT);
|
||||
ridingPacket.
|
||||
getIntegers().
|
||||
write(0, player.getEntityId());
|
||||
ridingPacket.getIntegerArrays().write(0, new int[]{this.armorStandId});
|
||||
|
||||
try {
|
||||
protocolManager.sendServerPacket(other, packet);
|
||||
protocolManager.sendServerPacket(other, ridingPacket);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePacketArmorStand() {
|
||||
public void spawnArmorStand() {
|
||||
if (this.hasArmorStand) {
|
||||
this.updateArmorStand();
|
||||
return;
|
||||
}
|
||||
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
this.spawnArmorStand(p);
|
||||
}
|
||||
|
||||
this.hasArmorStand = true;
|
||||
}
|
||||
|
||||
public void updateArmorStand() {
|
||||
if (!this.hasArmorStand) {
|
||||
this.spawnPacketArmorStand();
|
||||
this.spawnArmorStand();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -313,53 +236,13 @@ public class User {
|
||||
armorPacket.getIntegers().write(0, this.armorStandId);
|
||||
armorPacket.getSlotStackPairLists().write(0, equipmentList);
|
||||
|
||||
// final PacketContainer rotationContainer = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
|
||||
final Location location = player.getLocation();
|
||||
// rotationContainer.
|
||||
// getIntegers().
|
||||
// write(0, this.armorStandId);
|
||||
// rotationContainer.
|
||||
// getBytes().
|
||||
// write(0, (byte) (location.getYaw() * 256.0F / 360.0F));
|
||||
//
|
||||
// final PacketContainer rotationContainer2 = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
|
||||
// rotationContainer2.
|
||||
// getIntegers().
|
||||
// write(0, this.armorStandId);
|
||||
// rotationContainer2.
|
||||
// getBytes().
|
||||
// write(0, (byte) (location.getPitch() * 256.0F / 360.0F));
|
||||
|
||||
final PacketContainer metaContainer = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
// metaContainer.
|
||||
// getBytes().
|
||||
// write(15, (byte) 0x01);
|
||||
|
||||
|
||||
|
||||
WrappedDataWatcher metaData = new WrappedDataWatcher();
|
||||
metaData.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) (0x20)); //isSmall, noBasePlate, set Marker
|
||||
metaData.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, WrappedDataWatcher.Registry.get(Byte.class)), (byte) (0x01)); //isSmall, noBasePlate, set Marker
|
||||
|
||||
/* metadata.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(8, WrappedDataWatcher.Registry.get(Vector3F.getMinecraftClass())), new Vector3f(
|
||||
location.getPitch(),
|
||||
location.getYaw(),
|
||||
0
|
||||
));*/ //isSmall, noBasePlate, set Marker
|
||||
// metadata.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(16, WrappedDataWatcher.Registry.(), new Vector()));
|
||||
|
||||
// final PacketContainer rotationPacket = new PacketContainer(PacketType.Play.Server.REL_ENTITY_MOVE_LOOK);
|
||||
//
|
||||
// rotationPacket.getIntegers().write(0, this.armorStandId);
|
||||
// rotationPacket.
|
||||
// getShorts().
|
||||
// write(0, (short) 0).
|
||||
// write(1, (short) -5).
|
||||
// write(2, (short) 0);
|
||||
// rotationPacket.
|
||||
// getBytes().
|
||||
// write(0, (byte) (location.getYaw() * 256.0F / 360.0F)).
|
||||
// write(1, (byte) (location.getPitch() * 256.0F / 360.0F));
|
||||
metaData.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, WrappedDataWatcher.Registry.get(Byte.class)), (byte) (0x20));
|
||||
metaData.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, WrappedDataWatcher.Registry.get(Byte.class)), (byte) (0x10));
|
||||
|
||||
final PacketContainer rotationPacket = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
|
||||
|
||||
@@ -367,14 +250,7 @@ public class User {
|
||||
rotationPacket.getBytes().write(0, (byte) (location.getYaw() * 256 / 360));
|
||||
|
||||
metaContainer.getIntegers().write(0, this.armorStandId);
|
||||
// metaContainer.getWatchableCollectionModifier().write(0, metaData.getWatchableObjects());
|
||||
|
||||
// final WrappedDataWatcher dataWatcher = new WrappedDataWatcher();
|
||||
// dataWatcher.setObject(15, (byte) 0x01);
|
||||
//
|
||||
// metaContainer.getDataWatcherModifier().write(
|
||||
// 0, dataWatcher
|
||||
// );
|
||||
metaContainer.getWatchableCollectionModifier().write(0, metaData.getWatchableObjects());
|
||||
|
||||
final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
@@ -390,62 +266,30 @@ public class User {
|
||||
write(0, (byte) (location.getYaw() * 256.0F / 360.0F)).
|
||||
write(1, (byte) (location.getPitch() * 256.0F / 360.0F));
|
||||
|
||||
final PacketContainer destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||
// destroyPacket.getIntegerArrays().write(0, new int[]{this.armorStandId});
|
||||
destroyPacket.getModifier().write(0, new IntArrayList(new int[]{this.armorStandId}));
|
||||
|
||||
final PacketContainer ridingPacket = new PacketContainer(PacketType.Play.Server.MOUNT);
|
||||
ridingPacket.
|
||||
getIntegers().
|
||||
write(0, player.getEntityId());
|
||||
ridingPacket.getIntegerArrays().write(0, new int[]{this.armorStandId});
|
||||
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
try {
|
||||
// protocolManager.sendServerPacket(p, destroyPacket);
|
||||
if (i == 0) {
|
||||
i++;
|
||||
protocolManager.sendServerPacket(p, ridingPacket);
|
||||
}
|
||||
protocolManager.sendServerPacket(p, armorPacket);
|
||||
// protocolManager.sendServerPacket(p, metaContainer);
|
||||
protocolManager.sendServerPacket(p, metaContainer);
|
||||
protocolManager.sendServerPacket(p, rotationPacket);
|
||||
// protocolManager.sendServerPacket(p, teleportPacket);
|
||||
// protocolManager.sendServerPacket(p, rotationPacket2);
|
||||
// protocolManager.sendServerPacket(p, removeRiderPacket);
|
||||
// protocolManager.sendServerPacket(p, rotationPacket2);
|
||||
// i++;
|
||||
} catch (final InvocationTargetException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
|
||||
public void addArmorStandPassenger(final Entity entity) {
|
||||
final Player player = this.getPlayer();
|
||||
|
||||
if (player == null) return;
|
||||
|
||||
if (!player.getPassengers().contains(entity)) {
|
||||
player.addPassenger(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public void despawnAttached() {
|
||||
if (this.attached == null) {
|
||||
return;
|
||||
final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
final PacketContainer destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||
destroyPacket.getModifier().write(0, new IntArrayList(new int[]{this.armorStandId}));
|
||||
|
||||
for (final Player p : Bukkit.getOnlinePlayers()) {
|
||||
try {
|
||||
protocolManager.sendServerPacket(p, destroyPacket);
|
||||
} catch (final InvocationTargetException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
final Player player = this.getPlayer();
|
||||
|
||||
if (player != null) {
|
||||
player.removePassenger(this.attached);
|
||||
}
|
||||
|
||||
this.attached.remove();
|
||||
this.attached = null;
|
||||
}
|
||||
|
||||
public ArmorItem getLastSetItem() {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.github.fisher2911.hmccosmetics.user;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
@@ -9,18 +8,13 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.Pair;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
|
||||
import io.github.fisher2911.hmccosmetics.message.Placeholder;
|
||||
import io.github.fisher2911.hmccosmetics.util.Keys;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -90,6 +84,12 @@ public class UserManager {
|
||||
);
|
||||
}
|
||||
|
||||
public void resendCosmetics(final Player player) {
|
||||
for (final User user : this.userMap.values()) {
|
||||
user.spawnArmorStand(player);
|
||||
}
|
||||
}
|
||||
|
||||
private void registerPacketListener() {
|
||||
final ProtocolManager protocolManager = this.plugin.getProtocolManager();
|
||||
protocolManager.addPacketListener(new PacketAdapter(
|
||||
@@ -135,66 +135,6 @@ public class UserManager {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// protocolManager.addPacketListener(new PacketAdapter(
|
||||
// this.plugin,
|
||||
// ListenerPriority.NORMAL,
|
||||
// PacketType.Play.Server.SPAWN_ENTITY_LIVING
|
||||
// ) {
|
||||
// @Override
|
||||
// public void onPacketReceiving(PacketEvent event) {
|
||||
// if (event.getPacketType() != PacketType.Play.Server.SPAWN_ENTITY_LIVING) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// event.getPlayer().sendMessage("What the heck * 2");
|
||||
//
|
||||
// Bukkit.broadcast(Component.text("Received spawn"));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onPacketSending(PacketEvent event) {
|
||||
// if (event.getPacketType() != PacketType.Play.Server.SPAWN_ENTITY_LIVING) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// event.getPlayer().sendMessage("What the heck");
|
||||
//
|
||||
// PacketContainer packet = event.getPacket();
|
||||
//
|
||||
// Entity entity = packet.getEntityModifier(event).read(0);
|
||||
//
|
||||
// for (int i = 0; i < 100; i++) {
|
||||
// if (entity == null) {
|
||||
// Bukkit.broadcast(Component.text("Entity null" + packet));
|
||||
// } else {
|
||||
// Bukkit.broadcast(Component.text("Not null: " + entity.getEntityId()));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// final int id = entity.getEntityId();
|
||||
//
|
||||
// final User user = armorStandIdMap.get(id);
|
||||
//
|
||||
// if (user == null) return;
|
||||
//
|
||||
// user.addArmorStandPassenger(entity);
|
||||
//
|
||||
//// user.
|
||||
////
|
||||
//// WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(entity);
|
||||
////
|
||||
////
|
||||
//// WrappedDataWatcher.Serializer chatSerializer = WrappedDataWatcher.Registry.getChatComponentSerializer(true);
|
||||
////
|
||||
//// dataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(2, chatSerializer),
|
||||
//// Optional.of(WrappedChatComponent.fromChatMessage(leveledMob.getTag() /* or name, or what you need here */)[0].getHandle()));
|
||||
////
|
||||
//// packet.getWatchableCollectionModifier().write(0, dataWatcher.getWatchableObjects());
|
||||
////
|
||||
// event.setPacket(packet);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
public void setFakeHelmet(final User user) {
|
||||
@@ -241,7 +181,7 @@ public class UserManager {
|
||||
|
||||
public void removeAll() {
|
||||
for (final var user : this.userMap.values()) {
|
||||
user.detach();
|
||||
user.despawnAttached();
|
||||
}
|
||||
|
||||
this.userMap.clear();
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
package io.github.fisher2911.hmccosmetics.util;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.message.Adventure;
|
||||
import io.github.fisher2911.hmccosmetics.papi.PAPIHook;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
private static final HMCCosmetics plugin;
|
||||
|
||||
static {
|
||||
plugin = HMCCosmetics.getPlugin(HMCCosmetics.class);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message message being translated
|
||||
* @param message message being translated
|
||||
* @param placeholders placeholders applied
|
||||
* @return message with placeholders applied
|
||||
*/
|
||||
@@ -21,9 +31,15 @@ public class StringUtils {
|
||||
return message;
|
||||
}
|
||||
|
||||
public static String applyPapiPlaceholders(@Nullable final Player player, final String message) {
|
||||
if (plugin.isPapiEnabled()) {
|
||||
return PAPIHook.parse(player, message);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param parsed message to be parsed
|
||||
* @return MiniMessage parsed string
|
||||
*/
|
||||
|
||||
@@ -3,9 +3,11 @@ package io.github.fisher2911.hmccosmetics.util.builder;
|
||||
import io.github.fisher2911.hmccosmetics.message.Adventure;
|
||||
import io.github.fisher2911.hmccosmetics.util.StringUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.network.PacketListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@@ -147,6 +149,38 @@ public class ItemBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder papiPlaceholders(final Player player) {
|
||||
this.lorePapiPlaceholders(player);
|
||||
this.namePapiPlaceholders(player);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void lorePapiPlaceholders(final Player player) {
|
||||
if (this.itemMeta == null) return;
|
||||
final List<String> newLore = new ArrayList<>();
|
||||
|
||||
final List<String> lore = this.itemMeta.getLore();
|
||||
|
||||
if (lore == null) return;
|
||||
|
||||
for (final String line : this.itemMeta.getLore()) {
|
||||
newLore.add(StringUtils.applyPapiPlaceholders(player, line));
|
||||
}
|
||||
|
||||
this.itemMeta.setLore(newLore);
|
||||
}
|
||||
|
||||
private void namePapiPlaceholders(final Player player) {
|
||||
if (this.itemMeta == null) return;
|
||||
|
||||
this.itemMeta.setDisplayName(
|
||||
StringUtils.applyPapiPlaceholders(
|
||||
player,
|
||||
this.itemMeta.getDisplayName()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param unbreakable whether the ItemStack is unbreakable
|
||||
* @return this
|
||||
|
||||
@@ -4,6 +4,7 @@ version: 1.0.3
|
||||
api-version: 1.17
|
||||
softdepend:
|
||||
- Multiverse
|
||||
- PlaceholderAPI
|
||||
depend:
|
||||
- ProtocolLib
|
||||
permissions:
|
||||
|
||||
Reference in New Issue
Block a user