holograms

This commit is contained in:
NK 2022-12-27 18:48:37 +00:00
parent e5cfb54f7b
commit b4212a26c1
24 changed files with 120 additions and 112 deletions

View file

@ -1,9 +1,8 @@
package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.entities.holograms.PerPlayerHologram;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player;
import java.util.List;
@ -16,16 +15,8 @@ public class HologramCommand extends Command {
@Override
public void onCommand(CommandSender sender, String[] args) {
if (sender instanceof Player player) {
String[] ar = new String[]{ChatColor.AQUA + "Hi", ChatColor.DARK_PURPLE + "What", ChatColor.GOLD + "Hello World"};
Location location = player.getLocation();
for (String line : ar) {
ArmorStand stand = location.getWorld().spawn(location.subtract(0, 0.3, 0), ArmorStand.class);
stand.setVisible(false);
stand.setGravity(false);
stand.setInvulnerable(true);
stand.setCustomNameVisible(true);
stand.setCustomName(line);
}
String[] ar = new String[]{ChatColor.AQUA + "Hi", ChatColor.DARK_PURPLE + "What", ChatColor.GOLD + "Hello World", ChatColor.GOLD + ChatColor.BOLD.toString() + "CLICK"};
new PerPlayerHologram(player, ar);
}
}

View file

@ -2,7 +2,7 @@ package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.database.MinerDataManager;
import me.night.nullvalkyrie.entities.miners.CryptoMiner;
import me.night.nullvalkyrie.enums.MinerType;
import me.night.nullvalkyrie.entities.miners.MinerType;
import me.night.nullvalkyrie.ui.inventory.Miner;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

View file

@ -1,7 +1,7 @@
package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.database.RankDataManager;
import me.night.nullvalkyrie.enums.Rank;
import me.night.nullvalkyrie.util.Rank;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;

View file

@ -2,7 +2,7 @@ package me.night.nullvalkyrie.database;
import com.mongodb.client.MongoCursor;
import me.night.nullvalkyrie.entities.miners.CryptoMiner;
import me.night.nullvalkyrie.enums.MinerType;
import me.night.nullvalkyrie.entities.miners.MinerType;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bukkit.Bukkit;

View file

@ -1,7 +1,7 @@
package me.night.nullvalkyrie.database;
import com.mongodb.client.MongoCursor;
import me.night.nullvalkyrie.enums.Rank;
import me.night.nullvalkyrie.util.Rank;
import me.night.nullvalkyrie.ui.player.ScoreboardListener;
import org.bson.Document;
import org.bson.conversions.Bson;

View file

@ -11,24 +11,36 @@ import net.minecraft.world.entity.decoration.ArmorStand;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Optional;
public class PerPlayerHologram {
public static HashMap<Integer, ArmorStand[]> holograms = new HashMap<>();
public PerPlayerHologram(Player player, String[] lines) {
double c = (lines.length) * 0.3 - 0.15;
for (String line : lines) {
spawnLine(player.getLocation().getY() + c, player, line);
spawnLine(player, lines);
}
private void spawnLine(Player player, String[] lines) {
double c = (lines.length) * 0.3 - 0.8;
ArmorStand[] stands = new ArmorStand[lines.length];
for (int i = 0; i < lines.length; i++) {
ServerPlayer p = ((CraftPlayer) player).getHandle();
ArmorStand stand = new ArmorStand(p.getLevel(), player.getLocation().getX(), player.getLocation().getY() + c, player.getLocation().getZ());
stand.setInvisible(true);
new PacketPlayOutSpawnEntity(player, stand);
stands[i] = stand;
SynchedEntityData watcher = stand.getEntityData();
watcher.set(new EntityDataAccessor<>(2, EntityDataSerializers.OPTIONAL_COMPONENT), Optional.of(Component.nullToEmpty(lines[i])));
watcher.set(new EntityDataAccessor<>(3, EntityDataSerializers.BOOLEAN), true);
new PacketPlayOutEntityMetadata(player, stand, watcher);
c -= 0.3;
if (lines.length == i + 1)
holograms.put(stand.getBukkitEntity().getEntityId(), stands);
}
}
private void spawnLine(double y, Player player, String line) {
ServerPlayer p = ((CraftPlayer) player).getHandle();
ArmorStand stand = new ArmorStand(p.level, player.getLocation().getX(), y, player.getLocation().getZ());
stand.setInvisible(true);
new PacketPlayOutSpawnEntity(player, stand);
SynchedEntityData watcher = stand.getEntityData();
watcher.set(new EntityDataAccessor<>(2, EntityDataSerializers.OPTIONAL_COMPONENT), Optional.of(Component.nullToEmpty(line)));
watcher.set(new EntityDataAccessor<>(3, EntityDataSerializers.BOOLEAN), true);
new PacketPlayOutEntityMetadata(player, stand, watcher);
public static HashMap<Integer, ArmorStand[]> getHolograms() {
return holograms;
}
}

View file

@ -2,7 +2,7 @@ package me.night.nullvalkyrie.entities.items;
import me.night.nullvalkyrie.NullValkyrie;
import me.night.nullvalkyrie.database.CustomWeaponsDataManager;
import me.night.nullvalkyrie.enums.Rarity;
import me.night.nullvalkyrie.entities.miners.Rarity;
import me.night.nullvalkyrie.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

View file

@ -1,5 +1,6 @@
package me.night.nullvalkyrie.enums;
package me.night.nullvalkyrie.entities.items;
import me.night.nullvalkyrie.entities.miners.Rarity;
import org.bukkit.Material;
public enum Items {

View file

@ -5,9 +5,7 @@ import com.mojang.authlib.properties.Property;
import com.mojang.datafixers.util.Pair;
import me.night.nullvalkyrie.NullValkyrie;
import me.night.nullvalkyrie.database.MinerDataManager;
import me.night.nullvalkyrie.enums.MinerType;
import me.night.nullvalkyrie.packets.protocol.PacketPlayOutEntityMetadata;
import me.night.nullvalkyrie.util.Skin;
import me.night.nullvalkyrie.util.Util;
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
@ -21,7 +19,6 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.decoration.ArmorStand;
import org.apache.commons.codec.binary.Base64;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -110,20 +107,18 @@ public class CryptoMiner {
public void spawn(Player player) {
ArmorStand stand = new ArmorStand(((CraftWorld) this.getLocation().getWorld()).getHandle(), this.getLocation().getX() + 0.5, this.getLocation().getY(), this.getLocation().getZ() + 0.5);
stand.setInvulnerable(true);
stand.setPos(this.getLocation().getX() + 0.5, this.getLocation().getY(), this.getLocation().getZ() + 0.5);
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1);
SkullMeta meta = (SkullMeta) head.getItemMeta();
if (meta == null) return;
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", this.getMinerType().getHeadTexture()).getBytes());
profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
// url method: new String(Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", this.getMinerType().getHeadTexture()).getBytes()));
profile.getProperties().put("textures", new Property("textures", this.getMinerType().getHeadTexture()));
try {
Util.setFieldValue(meta, "profile", profile);
} catch (Exception e) {
throw new RuntimeException(e);
}
head.setItemMeta(meta);
ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE);
LeatherArmorMeta chestdata = (LeatherArmorMeta) chest.getItemMeta();
if (chestdata == null) return;
@ -148,8 +143,7 @@ public class CryptoMiner {
list.add(new Pair<>(EquipmentSlot.MAINHAND, CraftItemStack.asNMSCopy(pick)));
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), Util.color(this.name));
String[] skin = Skin.getSkin("Shiba_");
gameProfile.getProperties().put("textures", new Property("textures", skin[0], skin[1]));
gameProfile.getProperties().put("textures", new Property("textures", this.type.getHeadTexture()));
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
ServerLevel w = ((CraftWorld) player.getLocation().getWorld()).getHandle();
ServerPlayer m = new ServerPlayer(server, w, gameProfile, null);
@ -175,7 +169,6 @@ public class CryptoMiner {
for (int z = (int) this.getLocation().getZ() - 2; z <= this.getLocation().getZ() + 2; z++) {
for (int y = (int) this.getLocation().getY() - 1; y <= this.getLocation().getY() - 1; y++) {
this.getLocation().setY(17.0F);
System.out.println(x + " " + y + " " + z);
if (this.getLocation().getWorld().getBlockAt(x, y, z).getType() == this.getType()) {
locs.add(this.getLocation().getWorld().getBlockAt(x, y, z).getLocation());
}
@ -208,7 +201,6 @@ public class CryptoMiner {
public static void onJoin(Player player) {
for (CryptoMiner miner : MinerDataManager.getMiners().values()) {
System.out.println(miner.getName());
miner.spawn(player);
}
}

View file

@ -0,0 +1,46 @@
package me.night.nullvalkyrie.entities.miners;
import org.bukkit.Material;
public enum MinerType {
DIAMOND("Diamond", Material.DIAMOND_ORE, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOWM4Y2E2NjRmMDZkNDE0NjUwYWFjNWNkNDgyYzNiMGM3OWE2NjFiNWYxMWRjODUyMTQyNWJhNmU1NjllNSJ9fX0="),
EMERALD("Emerald", Material.EMERALD_ORE, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjRmNzNlMmVjZGMxYTM5MzlmYzEyZWY1N2Q3MTA0YTcwYzAyOGM1Y2ZiNzMyNGQ2OGVkM2IxZTIwYTkxMGEzIn19fQ=="),
GOLD("Gold", Material.GOLD_ORE, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDcxNDlmYjllNjM4NTI2OGY1MTk4N2IyZGU1MjVmNTkwNTFiNjE3Njc2Mjc2ZDI1YzZiMjQ1Y2E4ZDRkNCJ9fX0="),
IRON("Iron", Material.IRON_ORE, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGMzMTc1M2QzNDQwYjJhN2QxMTVmNmE3NTQyY2Q0YjI0ODdjYjdhZGEwYzk0NWJlNGQ0ZGY2MmJiMzlkNDA2NyJ9fX0="),
REDSTONE("Redstone", Material.REDSTONE_ORE, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzU1YjcwZWEyM2VmNjFkNjE4N2U1NTgzMTI4MTU2ZTE2MDg2YzIyODM4YjQ4YTc2YTk5NWZiZjk4ZjFlYjhhIn19fQ=="),
COAL("Coal", Material.COAL_ORE, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZmM2ZDBkYWQ4NmRjZDNkN2JjNDIxYTNjMjIyYWJhMzQxNDRjOTc5MWRkMmZjYTZiNzZlMzYwMmE2ZTM2In19fQ=="),
LAPIS("Lapis", Material.LAPIS_ORE, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNGI4M2QyMjkzYTVjYjVlOGE5YTY4M2JiOWYxYzI2NzAzZjdjMDNmMzE0Mzk2MTEzYjA3MzQ5Njk5YTNjOGIifX19"),
QUARTZ("Quartz", Material.NETHER_QUARTZ_ORE, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTQ1MjVhNTE2YTg3YTMxNTdlMTE2MzlhZWJiYzRjMmRmMmRiMTFkNTNjZWQ3NjgxMzQ0MzA0NmVkM2U1YiJ9fX0="),
OBSIDIAN("Obsidian", Material.OBSIDIAN, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDY1YmIxOTJhNjU2YmQ2ZGVjOGQ4YzhlNGRiM2I1NzNjZjcxNjliYjczOTM5MTZlZjlhYzE5ZGExNjNhZGE1In19fQ=="),
NETHERITE("Netherite", Material.ANCIENT_DEBRIS, "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDM1NzQ0NGFkZTY0ZWM2Y2VhNjQ1ZWM1N2U3NzU4NjRkNjdjNWZhNjIyOTk3ODZlMDM3OTkzMTdlZTRhZCJ9fX0=");
private final String name;
private final Material material;
private final String headTexture;
MinerType(String name, Material material, String headTexture) {
this.name = name;
this.material = material;
this.headTexture = headTexture;
}
public String getName() {
return name;
}
public Material getMaterial() {
return material;
}
public String getHeadTexture() {
return headTexture;
}
public static MinerType getByName(String name) {
for (MinerType type : MinerType.values()) {
if (type.getName().equalsIgnoreCase(name)) {
return type;
}
}
return null;
}
}

View file

@ -1,4 +1,4 @@
package me.night.nullvalkyrie.enums;
package me.night.nullvalkyrie.entities.miners;
import org.bukkit.ChatColor;

View file

@ -30,9 +30,9 @@ import java.util.List;
import java.util.UUID;
public class NPCManager {
private static final List<ServerPlayer> NPCs = new ArrayList<>();
private static final HashMap<Integer, ServerPlayer> NPCs = new HashMap<>();
public static List<ServerPlayer> getNPCs() {
public static HashMap<Integer, ServerPlayer> getNPCs() {
return NPCs;
}
@SuppressWarnings("ConstantConditions")
@ -47,7 +47,7 @@ public class NPCManager {
Location location = player.getLocation();
npc.setPos(location.getX(), location.getY(), location.getZ());
addNPCPacket(npc);
NPCs.add(npc);
NPCs.put(npc.getId(), npc);
NPCDataManager.setNPC(name, player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), (int) player.getLocation().getPitch(), (int) player.getLocation().getYaw(), player.getLocation().getWorld().getName(), skin[0], skin[1]);
}
@ -71,7 +71,7 @@ public class NPCManager {
}
public static void addJoinPacket(Player player) {
for (ServerPlayer npc : NPCs) {
for (ServerPlayer npc : NPCs.values()) {
ServerGamePacketListenerImpl pc = ((CraftPlayer) player).getHandle().connection;
pc.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, npc));
pc.send(new ClientboundAddPlayerPacket(npc));
@ -99,7 +99,7 @@ public class NPCManager {
ServerPlayer ep = new ServerPlayer(server, w, gameProfile, null);
ep.setPos(location.getX(), location.getY(), location.getZ()); // NMS: 1.19.2 https://nms.screamingsandals.org/1.19.2/net/minecraft/world/entity/Entity.html absMoveTo
addNPCPacket(ep);
NPCs.add(ep);
NPCs.put(ep.getId(), ep);
}
}

View file

@ -1,46 +0,0 @@
package me.night.nullvalkyrie.enums;
import org.bukkit.Material;
public enum MinerType {
DIAMOND("Diamond", Material.DIAMOND_ORE, "https://textures.minecraft.net/texture/d42a15a4be4196aba5b9ebc9545eb34186660970fac2b44e93723fff02fee7b2"),
EMERALD("Emerald", Material.EMERALD_ORE, "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198"),
GOLD("Gold", Material.GOLD_ORE, "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198"),
IRON("Iron", Material.IRON_ORE, "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198"),
REDSTONE("Redstone", Material.REDSTONE_ORE, "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198"),
COAL("Coal", Material.COAL_ORE, "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198"),
LAPIS("Lapis", Material.LAPIS_ORE, "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198"),
QUARTZ("Quartz", Material.NETHER_QUARTZ_ORE, "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198"),
OBSIDIAN("Obsidian", Material.OBSIDIAN, "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198"),
NETHERITE("Netherite", Material.ANCIENT_DEBRIS, "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198");
private final String name;
private final Material material;
private final String headTexture;
MinerType(String name, Material material, String headTexture) {
this.name = name;
this.material = material;
this.headTexture = headTexture;
}
public String getName() {
return name;
}
public Material getMaterial() {
return material;
}
public String getHeadTexture() {
return headTexture;
}
public static MinerType getByName(String name) {
for (MinerType type : MinerType.values()) {
if (type.getName().equalsIgnoreCase(name)) {
return type;
}
}
return null;
}
}

View file

@ -2,7 +2,7 @@ package me.night.nullvalkyrie.events.listeners;
import me.night.nullvalkyrie.entities.items.CustomItemManager;
import me.night.nullvalkyrie.entities.items.Pickaxe;
import me.night.nullvalkyrie.enums.Rarity;
import me.night.nullvalkyrie.entities.miners.Rarity;
import me.night.nullvalkyrie.NullValkyrie;
import me.night.nullvalkyrie.packets.protocol.PacketPlayOutBlockBreakAnimation;
import net.md_5.bungee.api.ChatMessageType;

View file

@ -24,7 +24,7 @@ public class NPCEvents implements Listener {
@EventHandler
public void onMove(PlayerMoveEvent e) {
NPCManager.getNPCs().forEach(npc -> {
NPCManager.getNPCs().values().forEach(npc -> {
Location location = npc.getBukkitEntity().getLocation();
location.setDirection(e.getPlayer().getLocation().subtract(location).toVector());
float yaw = location.getYaw();

View file

@ -1,5 +1,6 @@
package me.night.nullvalkyrie.events.listeners;
import me.night.nullvalkyrie.entities.holograms.PerPlayerHologram;
import me.night.nullvalkyrie.events.custom.InteractHologramEvent;
import me.night.nullvalkyrie.packets.handle.PacketInjector;
import me.night.nullvalkyrie.util.Util;
@ -48,12 +49,11 @@ public class ServerEvents implements Listener {
ee.printStackTrace();
}
}
@EventHandler
public void onClickHologram(InteractHologramEvent e) {
if (e.getHologram().getCustomName() == null) return;
if (e.getHologram().getCustomName().equals(ChatColor.GOLD + "Click me to change!!!")) {
// TODO: change hologram things
if (e.getHologram().getCustomName().equals(ChatColor.GOLD + ChatColor.BOLD.toString() + "CLICK")) {
e.getHologram().getNearbyEntities(0, 5, 0).forEach(entity -> new PerPlayerHologram(e.getPlayer(), new String[]{ChatColor.RED + "Player Info:", ChatColor.GOLD + "Name: " + ChatColor.AQUA + e.getPlayer().getName(), ChatColor.BLUE + "IP: " + e.getPlayer().getAddress()}));
}
}

View file

@ -4,10 +4,12 @@ import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import me.night.nullvalkyrie.NullValkyrie;
import me.night.nullvalkyrie.entities.holograms.PerPlayerHologram;
import me.night.nullvalkyrie.entities.npcs.NPCManager;
import me.night.nullvalkyrie.events.custom.InteractHologramEvent;
import me.night.nullvalkyrie.events.custom.RightClickNPCEvent;
import me.night.nullvalkyrie.util.Util;
import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket;
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
import net.minecraft.network.syncher.EntityDataAccessor;
@ -15,6 +17,7 @@ import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@ -52,7 +55,7 @@ public class PacketHandler extends ChannelDuplexHandler {
List<SynchedEntityData.DataItem<?>> list = pk.getUnpackedData();
SynchedEntityData.DataItem<Float> value = (SynchedEntityData.DataItem<Float>) list.get(9);
System.out.println(value.getAccessor());
float health = ThreadLocalRandom.current().nextInt(5,20);
float health = ThreadLocalRandom.current().nextInt(5, 20);
list.set(9, new SynchedEntityData.DataItem<>(new EntityDataAccessor<>(value.getAccessor().getId(), EntityDataSerializers.FLOAT), health));
}
super.write(ctx, packet, promise);
@ -63,12 +66,23 @@ public class PacketHandler extends ChannelDuplexHandler {
if (packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) {
ServerboundInteractPacket pk = (ServerboundInteractPacket) packet;
int entityID = (int) Util.getFieldValue(packet, "a");
// if (pk.getType() == ServerboundInteractPacket.Action.INTERACT) {
// Entity entity = ((CraftWorld) player.getWorld()).getHandle().getEntity(entityID);
// if (entity == null) return;
// if (entity instanceof ArmorStand) {
// Bukkit.getPluginManager().callEvent(new InteractHologramEvent(player, entity));
// }
// if (NPCManager.isNPC(entity)) {
// Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, entity));
// }
// }
boolean sneak = (boolean) Util.getFieldValue(packet, "c");
Bukkit.getScheduler().scheduleSyncDelayedTask(NullValkyrie.getPlugin(NullValkyrie.class), () -> {
for (Entity entity : Bukkit.getWorld("world").getEntities()) {
if (entity.getEntityId() == entityID && entity.getType() == EntityType.ARMOR_STAND) {
Bukkit.getPluginManager().callEvent(new InteractHologramEvent(player, (ArmorStand) entity));
}
net.minecraft.world.entity.decoration.ArmorStand[] stands = PerPlayerHologram.getHolograms().get(entityID);
if (stands == null) return;
Bukkit.getPluginManager().callEvent(new InteractHologramEvent(player, (ArmorStand) stands[stands.length - 1].getBukkitEntity()));
for (net.minecraft.world.entity.decoration.ArmorStand i : stands) {
((CraftPlayer) player).getHandle().connection.send(new ClientboundRemoveEntitiesPacket(i.getId()));
}
}, 0);
Object data = Util.getFieldValue(pk, "b");
@ -78,7 +92,7 @@ public class PacketHandler extends ChannelDuplexHandler {
Object hand = Util.getFieldValue(data, "a");
if (!hand.toString().equals("MAIN_HAND")) return;
//Right Click
for (ServerPlayer npcs : NPCManager.getNPCs()) {
for (ServerPlayer npcs : NPCManager.getNPCs().values()) {
if (npcs.getBukkitEntity().getEntityId() == entityID && sneak) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NullValkyrie.getPlugin(NullValkyrie.class), () -> Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, npcs)), 0);

View file

@ -2,7 +2,7 @@ package me.night.nullvalkyrie.ui.inventory;
import me.night.nullvalkyrie.NullValkyrie;
import me.night.nullvalkyrie.database.UserDataManager;
import me.night.nullvalkyrie.enums.Items;
import me.night.nullvalkyrie.entities.items.Items;
import me.night.nullvalkyrie.util.RandomCollection;
import me.night.nullvalkyrie.util.Util;
import org.bukkit.ChatColor;

View file

@ -1,6 +1,6 @@
package me.night.nullvalkyrie.ui.inventory;
import me.night.nullvalkyrie.enums.Items;
import me.night.nullvalkyrie.entities.items.Items;
import me.night.nullvalkyrie.util.Util;
import org.bukkit.ChatColor;
import org.bukkit.Material;

View file

@ -1,7 +1,7 @@
package me.night.nullvalkyrie.ui.player;
import me.night.nullvalkyrie.database.RankDataManager;
import me.night.nullvalkyrie.enums.Rank;
import me.night.nullvalkyrie.util.Rank;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.*;

View file

@ -3,7 +3,7 @@ package me.night.nullvalkyrie.ui.player;
import me.night.nullvalkyrie.database.RankDataManager;
import me.night.nullvalkyrie.database.UserDataManager;
import me.night.nullvalkyrie.entities.miners.CryptoMiner;
import me.night.nullvalkyrie.enums.Rank;
import me.night.nullvalkyrie.util.Rank;
import me.night.nullvalkyrie.entities.npcs.NPCManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

View file

@ -1,4 +1,4 @@
package me.night.nullvalkyrie.enums;
package me.night.nullvalkyrie.util;
import org.bukkit.ChatColor;

View file

@ -1,6 +1,5 @@
package me.night.nullvalkyrie.util.enchantments;
import me.night.nullvalkyrie.enums.Enchantments;
import org.bukkit.enchantments.Enchantment;
import java.lang.reflect.Field;

View file

@ -1,6 +1,5 @@
package me.night.nullvalkyrie.enums;
package me.night.nullvalkyrie.util.enchantments;
import me.night.nullvalkyrie.util.enchantments.EnchantmentManager;
import org.bukkit.enchantments.Enchantment;
public enum Enchantments {