diff --git a/src/main/java/me/night/nullvalkyrie/commands/HologramCommand.java b/src/main/java/me/night/nullvalkyrie/commands/HologramCommand.java index 283942c..b8db7e0 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/HologramCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/HologramCommand.java @@ -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); } } diff --git a/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java b/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java index 21f1e8f..e38f9ae 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java @@ -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; diff --git a/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java b/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java index 5b91a51..d6d4439 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java @@ -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; diff --git a/src/main/java/me/night/nullvalkyrie/database/MinerDataManager.java b/src/main/java/me/night/nullvalkyrie/database/MinerDataManager.java index 1c30dc1..e8aa6a8 100644 --- a/src/main/java/me/night/nullvalkyrie/database/MinerDataManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/MinerDataManager.java @@ -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; diff --git a/src/main/java/me/night/nullvalkyrie/database/RankDataManager.java b/src/main/java/me/night/nullvalkyrie/database/RankDataManager.java index c081caa..323b085 100644 --- a/src/main/java/me/night/nullvalkyrie/database/RankDataManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/RankDataManager.java @@ -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; diff --git a/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java b/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java index a5712ea..830f54c 100644 --- a/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java +++ b/src/main/java/me/night/nullvalkyrie/entities/holograms/PerPlayerHologram.java @@ -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 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 getHolograms() { + return holograms; } } diff --git a/src/main/java/me/night/nullvalkyrie/entities/items/CustomItemManager.java b/src/main/java/me/night/nullvalkyrie/entities/items/CustomItemManager.java index a3cff44..a4fa214 100644 --- a/src/main/java/me/night/nullvalkyrie/entities/items/CustomItemManager.java +++ b/src/main/java/me/night/nullvalkyrie/entities/items/CustomItemManager.java @@ -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; diff --git a/src/main/java/me/night/nullvalkyrie/enums/Items.java b/src/main/java/me/night/nullvalkyrie/entities/items/Items.java similarity index 95% rename from src/main/java/me/night/nullvalkyrie/enums/Items.java rename to src/main/java/me/night/nullvalkyrie/entities/items/Items.java index 394604d..dcda099 100644 --- a/src/main/java/me/night/nullvalkyrie/enums/Items.java +++ b/src/main/java/me/night/nullvalkyrie/entities/items/Items.java @@ -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 { diff --git a/src/main/java/me/night/nullvalkyrie/entities/miners/CryptoMiner.java b/src/main/java/me/night/nullvalkyrie/entities/miners/CryptoMiner.java index 6283b8e..e8292b1 100644 --- a/src/main/java/me/night/nullvalkyrie/entities/miners/CryptoMiner.java +++ b/src/main/java/me/night/nullvalkyrie/entities/miners/CryptoMiner.java @@ -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); } } diff --git a/src/main/java/me/night/nullvalkyrie/entities/miners/MinerType.java b/src/main/java/me/night/nullvalkyrie/entities/miners/MinerType.java new file mode 100644 index 0000000..ed6acb7 --- /dev/null +++ b/src/main/java/me/night/nullvalkyrie/entities/miners/MinerType.java @@ -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; + } +} diff --git a/src/main/java/me/night/nullvalkyrie/enums/Rarity.java b/src/main/java/me/night/nullvalkyrie/entities/miners/Rarity.java similarity index 97% rename from src/main/java/me/night/nullvalkyrie/enums/Rarity.java rename to src/main/java/me/night/nullvalkyrie/entities/miners/Rarity.java index b6d1364..2139bf4 100644 --- a/src/main/java/me/night/nullvalkyrie/enums/Rarity.java +++ b/src/main/java/me/night/nullvalkyrie/entities/miners/Rarity.java @@ -1,4 +1,4 @@ -package me.night.nullvalkyrie.enums; +package me.night.nullvalkyrie.entities.miners; import org.bukkit.ChatColor; diff --git a/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java b/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java index d4bc684..4e42948 100644 --- a/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java +++ b/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java @@ -30,9 +30,9 @@ import java.util.List; import java.util.UUID; public class NPCManager { - private static final List NPCs = new ArrayList<>(); + private static final HashMap NPCs = new HashMap<>(); - public static List getNPCs() { + public static HashMap 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); } } diff --git a/src/main/java/me/night/nullvalkyrie/enums/MinerType.java b/src/main/java/me/night/nullvalkyrie/enums/MinerType.java deleted file mode 100644 index 4a4fe5c..0000000 --- a/src/main/java/me/night/nullvalkyrie/enums/MinerType.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java b/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java index ea5a3ae..39a2915 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/CustomItemEvents.java @@ -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; diff --git a/src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java b/src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java index db695b6..8336806 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/NPCEvents.java @@ -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(); diff --git a/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java b/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java index adad9cc..09a8f99 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java @@ -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()})); } } diff --git a/src/main/java/me/night/nullvalkyrie/packets/handle/PacketHandler.java b/src/main/java/me/night/nullvalkyrie/packets/handle/PacketHandler.java index 63c1e0c..bc136c5 100644 --- a/src/main/java/me/night/nullvalkyrie/packets/handle/PacketHandler.java +++ b/src/main/java/me/night/nullvalkyrie/packets/handle/PacketHandler.java @@ -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> list = pk.getUnpackedData(); SynchedEntityData.DataItem value = (SynchedEntityData.DataItem) 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); diff --git a/src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java b/src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java index 29b560f..27e826e 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java +++ b/src/main/java/me/night/nullvalkyrie/ui/inventory/InventoryListener.java @@ -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; diff --git a/src/main/java/me/night/nullvalkyrie/ui/inventory/LuckyDraw.java b/src/main/java/me/night/nullvalkyrie/ui/inventory/LuckyDraw.java index 6c69994..555386d 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/inventory/LuckyDraw.java +++ b/src/main/java/me/night/nullvalkyrie/ui/inventory/LuckyDraw.java @@ -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; diff --git a/src/main/java/me/night/nullvalkyrie/ui/player/NameTagManager.java b/src/main/java/me/night/nullvalkyrie/ui/player/NameTagManager.java index edb8cb5..410493c 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/player/NameTagManager.java +++ b/src/main/java/me/night/nullvalkyrie/ui/player/NameTagManager.java @@ -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.*; diff --git a/src/main/java/me/night/nullvalkyrie/ui/player/ScoreboardListener.java b/src/main/java/me/night/nullvalkyrie/ui/player/ScoreboardListener.java index 1c59ec1..1a9da4f 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/player/ScoreboardListener.java +++ b/src/main/java/me/night/nullvalkyrie/ui/player/ScoreboardListener.java @@ -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; diff --git a/src/main/java/me/night/nullvalkyrie/enums/Rank.java b/src/main/java/me/night/nullvalkyrie/util/Rank.java similarity index 91% rename from src/main/java/me/night/nullvalkyrie/enums/Rank.java rename to src/main/java/me/night/nullvalkyrie/util/Rank.java index 6c7c5ad..c2ba184 100644 --- a/src/main/java/me/night/nullvalkyrie/enums/Rank.java +++ b/src/main/java/me/night/nullvalkyrie/util/Rank.java @@ -1,4 +1,4 @@ -package me.night.nullvalkyrie.enums; +package me.night.nullvalkyrie.util; import org.bukkit.ChatColor; diff --git a/src/main/java/me/night/nullvalkyrie/util/enchantments/EnchantmentManager.java b/src/main/java/me/night/nullvalkyrie/util/enchantments/EnchantmentManager.java index 0187c24..1b730ec 100644 --- a/src/main/java/me/night/nullvalkyrie/util/enchantments/EnchantmentManager.java +++ b/src/main/java/me/night/nullvalkyrie/util/enchantments/EnchantmentManager.java @@ -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; diff --git a/src/main/java/me/night/nullvalkyrie/enums/Enchantments.java b/src/main/java/me/night/nullvalkyrie/util/enchantments/Enchantments.java similarity index 88% rename from src/main/java/me/night/nullvalkyrie/enums/Enchantments.java rename to src/main/java/me/night/nullvalkyrie/util/enchantments/Enchantments.java index 21b433c..175fe91 100644 --- a/src/main/java/me/night/nullvalkyrie/enums/Enchantments.java +++ b/src/main/java/me/night/nullvalkyrie/util/enchantments/Enchantments.java @@ -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 {