diff --git a/src/main/java/me/night/nullvalkyrie/Main.java b/src/main/java/me/night/nullvalkyrie/Main.java index cac17f8..b24e1af 100644 --- a/src/main/java/me/night/nullvalkyrie/Main.java +++ b/src/main/java/me/night/nullvalkyrie/Main.java @@ -10,7 +10,7 @@ import me.night.nullvalkyrie.ui.inventory.InventoryListener; import me.night.nullvalkyrie.database.NPCDataManager; import me.night.nullvalkyrie.discord.DiscordClientManager; import me.night.nullvalkyrie.enchantments.EnchantmentManager; -import me.night.nullvalkyrie.ui.ScoreboardListener; +import me.night.nullvalkyrie.ui.player.ScoreboardListener; import me.night.nullvalkyrie.util.*; import me.night.nullvalkyrie.commands.*; import me.night.nullvalkyrie.database.DatabaseManager; diff --git a/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java b/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java index 453ec37..1d42ffd 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java @@ -1,5 +1,6 @@ package me.night.nullvalkyrie.commands; +import me.night.nullvalkyrie.entities.miners.CryptoMiner; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -14,6 +15,8 @@ public class BetaCommand extends Command { @Override public void onCommand(CommandSender sender, String[] args) { if (sender instanceof Player player) { + // TODO: how to make a armor stand turn + CryptoMiner.spawn(player, args[0], "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198"); } } diff --git a/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java b/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java index 36cfd58..678a0a2 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/MinerCommand.java @@ -9,7 +9,7 @@ import org.bukkit.entity.Player; import java.util.Date; import java.util.List; -import static me.night.nullvalkyrie.miners.CryptoMiner.generate; +import static me.night.nullvalkyrie.entities.miners.CryptoMiner.generate; public class MinerCommand extends Command { diff --git a/src/main/java/me/night/nullvalkyrie/database/MinerDataManager.java b/src/main/java/me/night/nullvalkyrie/database/MinerDataManager.java index 67a01f8..c18217b 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 com.mongodb.client.model.Filters; -import me.night.nullvalkyrie.miners.CryptoMiner; +import me.night.nullvalkyrie.entities.miners.CryptoMiner; import org.bson.Document; import org.bson.conversions.Bson; import org.bukkit.Material; diff --git a/src/main/java/me/night/nullvalkyrie/database/RankDataManager.java b/src/main/java/me/night/nullvalkyrie/database/RankDataManager.java index 75bf44c..ae5318d 100644 --- a/src/main/java/me/night/nullvalkyrie/database/RankDataManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/RankDataManager.java @@ -10,7 +10,7 @@ import org.bukkit.entity.Player; import java.util.UUID; -import static me.night.nullvalkyrie.ui.ScoreboardListener.nameTagManager; +import static me.night.nullvalkyrie.ui.player.ScoreboardListener.nameTagManager; public class RankDataManager { public static void setRank(UUID uuid, Rank rank) { diff --git a/src/main/java/me/night/nullvalkyrie/database/UserDataManager.java b/src/main/java/me/night/nullvalkyrie/database/UserDataManager.java index 161b1ca..4a9e7f8 100644 --- a/src/main/java/me/night/nullvalkyrie/database/UserDataManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/UserDataManager.java @@ -1,6 +1,6 @@ package me.night.nullvalkyrie.database; -import me.night.nullvalkyrie.ui.ScoreboardListener; +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/miners/CryptoMiner.java b/src/main/java/me/night/nullvalkyrie/entities/miners/CryptoMiner.java new file mode 100644 index 0000000..5dff65c --- /dev/null +++ b/src/main/java/me/night/nullvalkyrie/entities/miners/CryptoMiner.java @@ -0,0 +1,150 @@ +package me.night.nullvalkyrie.entities.miners; + +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.properties.Property; +import com.mojang.datafixers.util.Pair; +import me.night.nullvalkyrie.util.Util; +import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; +import net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.EntityPlayer; +import net.minecraft.server.level.WorldServer; +import net.minecraft.server.network.PlayerConnection; +import net.minecraft.world.entity.EnumItemSlot; +import org.apache.commons.codec.binary.Base64; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_19_R1.CraftServer; +import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.bukkit.inventory.meta.SkullMeta; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; + +public class CryptoMiner { + protected String name; + protected Material type; + protected int level; + protected double rate; + protected long lastclaim; + + public CryptoMiner(String name, Material type, int level, double rate, long lastclaim) { + this.name = name; // Name of the miner + this.type = type; // Material to mine + this.level = level; + this.rate = rate; // Percentage generate chance in each tick 20tick per sec + this.lastclaim = lastclaim; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getRate() { + return rate; + } + + public void setRate(double rate) { + this.rate = rate; + } + + public Material getType() { + return type; + } + + public void setType(Material type) { + this.type = type; + } + + public int getLevel() { + return level; + } + + public void setLevel(int level) { + this.level = level; + } + + public long getLastclaim() { + return lastclaim; + } + + public static void generate(int pp, int times) { + int generated = 0; + for (int counter = 0; counter < times; counter++) { + int count = ThreadLocalRandom.current().nextInt(100); + if (count > pp) generated++; + } + System.out.println(generated); + } + + public static void spawn(Player player, String name, String url) { + Location loc = player.getLocation(); + loc.setX(Math.round(loc.getX() * 2) / 2.0); + loc.setZ(Math.round(loc.getZ() * 2) / 2.0); + if (player.getLocation().getWorld() == null) return; + ArmorStand stand = player.getLocation().getWorld().spawn(loc, ArmorStand.class); + stand.setGravity(false); + stand.setBasePlate(false); + stand.setSmall(true); + stand.setArms(true); + stand.setVisible(true); + ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3); + SkullMeta meta = (SkullMeta) head.getItemMeta(); + GameProfile profile = new GameProfile(UUID.randomUUID(), null); + byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes()); + profile.getProperties().put("textures", new Property("textures", new String(encodedData))); + Field profileField; + try { + profileField = meta.getClass().getDeclaredField("profile"); + profileField.setAccessible(true); + profileField.set(meta, profile); + } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) { + e1.printStackTrace(); + } + head.setItemMeta(meta); + + ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE); + LeatherArmorMeta chestdata = (LeatherArmorMeta) chest.getItemMeta(); + chestdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58)); + chest.setItemMeta(chestdata); + ItemStack leg = new ItemStack(Material.LEATHER_LEGGINGS); + LeatherArmorMeta legdata = (LeatherArmorMeta) leg.getItemMeta(); + legdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58)); + leg.setItemMeta(legdata); + ItemStack boot = new ItemStack(Material.LEATHER_BOOTS); + LeatherArmorMeta bootdata = (LeatherArmorMeta) boot.getItemMeta(); + bootdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58)); + boot.setItemMeta(bootdata); + ItemStack pick = new ItemStack(Material.GOLDEN_PICKAXE); + List> list = new ArrayList<>(); + list.add(new Pair<>(EnumItemSlot.a, CraftItemStack.asNMSCopy(pick))); + list.add(new Pair<>(EnumItemSlot.c, CraftItemStack.asNMSCopy(boot))); + list.add(new Pair<>(EnumItemSlot.d, CraftItemStack.asNMSCopy(leg))); + list.add(new Pair<>(EnumItemSlot.e, CraftItemStack.asNMSCopy(chest))); + list.add(new Pair<>(EnumItemSlot.f, CraftItemStack.asNMSCopy(head))); + + GameProfile gameProfile = new GameProfile(UUID.randomUUID(), Util.color(name)); + MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); + WorldServer w = ((CraftWorld) player.getLocation().getWorld()).getHandle(); + EntityPlayer miner = new EntityPlayer(server, w, gameProfile, null); + // set the icon to the tab list + + + PlayerConnection pc = ((org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer) player).getHandle().b; + pc.a(new PacketPlayOutEntityEquipment(stand.getEntityId(), list)); + pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, miner)); + } +} 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 2b291ab..7c94bb1 100644 --- a/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java +++ b/src/main/java/me/night/nullvalkyrie/entities/npcs/NPCManager.java @@ -5,6 +5,7 @@ import com.mojang.authlib.properties.Property; import com.mojang.datafixers.util.Pair; import me.night.nullvalkyrie.Main; import me.night.nullvalkyrie.database.NPCDataManager; +import me.night.nullvalkyrie.util.Skin; import me.night.nullvalkyrie.util.Util; import net.minecraft.network.protocol.game.*; import net.minecraft.network.syncher.DataWatcher; 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 8cfd575..c0cb9d0 100644 --- a/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/listeners/ServerEvents.java @@ -41,6 +41,7 @@ public class ServerEvents implements Listener { } @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 } diff --git a/src/main/java/me/night/nullvalkyrie/miners/CryptoMiner.java b/src/main/java/me/night/nullvalkyrie/miners/CryptoMiner.java deleted file mode 100644 index f1a555b..0000000 --- a/src/main/java/me/night/nullvalkyrie/miners/CryptoMiner.java +++ /dev/null @@ -1,68 +0,0 @@ -package me.night.nullvalkyrie.miners; - -import org.bukkit.Material; - -import java.util.concurrent.ThreadLocalRandom; - -public class CryptoMiner { - protected String name; - protected Material type; - protected int level; - protected double rate; - protected long lastclaim; - - public CryptoMiner(String name, Material type, int level, double rate, long lastclaim) { - this.name = name; // Name of the miner - this.type = type; // Material to mine - this.level = level; - this.rate = rate; // Percentage generate chance in each tick 20tick per sec - this.lastclaim = lastclaim; - - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public double getRate() { - return rate; - } - - public void setRate(double rate) { - this.rate = rate; - } - - public Material getType() { - return type; - } - - public void setType(Material type) { - this.type = type; - } - - public int getLevel() { - return level; - } - - public void setLevel(int level) { - this.level = level; - } - - public long getLastclaim() { - return lastclaim; - } - - public static void generate(int pp, int times) { - int generated = 0; - for (int counter = 0; counter < times; counter++) { - int count = ThreadLocalRandom.current().nextInt(100); - if (count > pp) generated++; - } - System.out.println(generated); - } - -} diff --git a/src/main/java/me/night/nullvalkyrie/ui/inventory/Miner.java b/src/main/java/me/night/nullvalkyrie/ui/inventory/Miner.java index 0a270d8..fb688cb 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/inventory/Miner.java +++ b/src/main/java/me/night/nullvalkyrie/ui/inventory/Miner.java @@ -1,7 +1,7 @@ package me.night.nullvalkyrie.ui.inventory; import me.night.nullvalkyrie.database.MinerDataManager; -import me.night.nullvalkyrie.miners.CryptoMiner; +import me.night.nullvalkyrie.entities.miners.CryptoMiner; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; diff --git a/src/main/java/me/night/nullvalkyrie/ui/AnimatedSideBar.java b/src/main/java/me/night/nullvalkyrie/ui/player/AnimatedSideBar.java similarity index 92% rename from src/main/java/me/night/nullvalkyrie/ui/AnimatedSideBar.java rename to src/main/java/me/night/nullvalkyrie/ui/player/AnimatedSideBar.java index 6379036..06a3fd2 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/AnimatedSideBar.java +++ b/src/main/java/me/night/nullvalkyrie/ui/player/AnimatedSideBar.java @@ -1,4 +1,4 @@ -package me.night.nullvalkyrie.ui; +package me.night.nullvalkyrie.ui.player; import org.bukkit.Bukkit; diff --git a/src/main/java/me/night/nullvalkyrie/ui/BelowNameManager.java b/src/main/java/me/night/nullvalkyrie/ui/player/BelowNameManager.java similarity index 94% rename from src/main/java/me/night/nullvalkyrie/ui/BelowNameManager.java rename to src/main/java/me/night/nullvalkyrie/ui/player/BelowNameManager.java index 8154b04..83fd0e3 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/BelowNameManager.java +++ b/src/main/java/me/night/nullvalkyrie/ui/player/BelowNameManager.java @@ -1,4 +1,4 @@ -package me.night.nullvalkyrie.ui; +package me.night.nullvalkyrie.ui.player; import org.bukkit.ChatColor; import org.bukkit.entity.Player; diff --git a/src/main/java/me/night/nullvalkyrie/ui/NameTagManager.java b/src/main/java/me/night/nullvalkyrie/ui/player/NameTagManager.java similarity index 91% rename from src/main/java/me/night/nullvalkyrie/ui/NameTagManager.java rename to src/main/java/me/night/nullvalkyrie/ui/player/NameTagManager.java index 08cc825..2b5c187 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/NameTagManager.java +++ b/src/main/java/me/night/nullvalkyrie/ui/player/NameTagManager.java @@ -1,4 +1,4 @@ -package me.night.nullvalkyrie.ui; +package me.night.nullvalkyrie.ui.player; import me.night.nullvalkyrie.database.RankDataManager; import me.night.nullvalkyrie.enums.Rank; @@ -19,7 +19,7 @@ public class NameTagManager { for (Player target : Bukkit.getOnlinePlayers()) { if (player.getUniqueId() != target.getUniqueId()) { Rank rank = RankDataManager.getRank(target.getUniqueId()); - player.getScoreboard().getTeam(rank.name()).addEntry(target.getName()); + if (rank != null) player.getScoreboard().getTeam(rank.name()).addEntry(target.getName()); } } } diff --git a/src/main/java/me/night/nullvalkyrie/ui/ScoreboardListener.java b/src/main/java/me/night/nullvalkyrie/ui/player/ScoreboardListener.java similarity index 98% rename from src/main/java/me/night/nullvalkyrie/ui/ScoreboardListener.java rename to src/main/java/me/night/nullvalkyrie/ui/player/ScoreboardListener.java index 901735a..9d2dff9 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/ScoreboardListener.java +++ b/src/main/java/me/night/nullvalkyrie/ui/player/ScoreboardListener.java @@ -1,4 +1,4 @@ -package me.night.nullvalkyrie.ui; +package me.night.nullvalkyrie.ui.player; import me.night.nullvalkyrie.Main; import me.night.nullvalkyrie.database.RankDataManager; @@ -54,7 +54,6 @@ public class ScoreboardListener implements Listener { e.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard()); AnimatedSideBar board = sideBarManager.board; if (board.hasID()) board.stop(); - } @EventHandler diff --git a/src/main/java/me/night/nullvalkyrie/ui/SideBarManager.java b/src/main/java/me/night/nullvalkyrie/ui/player/SideBarManager.java similarity index 99% rename from src/main/java/me/night/nullvalkyrie/ui/SideBarManager.java rename to src/main/java/me/night/nullvalkyrie/ui/player/SideBarManager.java index 2321fd3..41c9365 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/SideBarManager.java +++ b/src/main/java/me/night/nullvalkyrie/ui/player/SideBarManager.java @@ -1,4 +1,4 @@ -package me.night.nullvalkyrie.ui; +package me.night.nullvalkyrie.ui.player; import me.night.nullvalkyrie.Main; import me.night.nullvalkyrie.database.UserDataManager; diff --git a/src/main/java/me/night/nullvalkyrie/entities/npcs/Skin.java b/src/main/java/me/night/nullvalkyrie/util/Skin.java similarity index 83% rename from src/main/java/me/night/nullvalkyrie/entities/npcs/Skin.java rename to src/main/java/me/night/nullvalkyrie/util/Skin.java index 0d9cf55..315bc60 100644 --- a/src/main/java/me/night/nullvalkyrie/entities/npcs/Skin.java +++ b/src/main/java/me/night/nullvalkyrie/util/Skin.java @@ -1,4 +1,4 @@ -package me.night.nullvalkyrie.entities.npcs; +package me.night.nullvalkyrie.util; import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -11,15 +11,6 @@ import java.io.InputStreamReader; import java.net.URL; public class Skin { - private final String texture; - private final String signature; - public Skin(String texture, String signature) { - this.texture = texture; - this.signature = signature; - } - public String getTexture() { return texture; } - public String getSignature() { return signature; } - public static String[] getSkin(String name) { try { URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + name);