mini miner

This commit is contained in:
NK 2022-12-07 20:46:09 +00:00
parent d763a05158
commit 569f14bc39
17 changed files with 168 additions and 91 deletions

View file

@ -10,7 +10,7 @@ import me.night.nullvalkyrie.ui.inventory.InventoryListener;
import me.night.nullvalkyrie.database.NPCDataManager; import me.night.nullvalkyrie.database.NPCDataManager;
import me.night.nullvalkyrie.discord.DiscordClientManager; import me.night.nullvalkyrie.discord.DiscordClientManager;
import me.night.nullvalkyrie.enchantments.EnchantmentManager; 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.util.*;
import me.night.nullvalkyrie.commands.*; import me.night.nullvalkyrie.commands.*;
import me.night.nullvalkyrie.database.DatabaseManager; import me.night.nullvalkyrie.database.DatabaseManager;

View file

@ -1,5 +1,6 @@
package me.night.nullvalkyrie.commands; package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.entities.miners.CryptoMiner;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -14,6 +15,8 @@ public class BetaCommand extends Command {
@Override @Override
public void onCommand(CommandSender sender, String[] args) { public void onCommand(CommandSender sender, String[] args) {
if (sender instanceof Player player) { if (sender instanceof Player player) {
// TODO: how to make a armor stand turn
CryptoMiner.spawn(player, args[0], "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198");
} }
} }

View file

@ -9,7 +9,7 @@ import org.bukkit.entity.Player;
import java.util.Date; import java.util.Date;
import java.util.List; 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 { public class MinerCommand extends Command {

View file

@ -2,7 +2,7 @@ package me.night.nullvalkyrie.database;
import com.mongodb.client.MongoCursor; import com.mongodb.client.MongoCursor;
import com.mongodb.client.model.Filters; 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.Document;
import org.bson.conversions.Bson; import org.bson.conversions.Bson;
import org.bukkit.Material; import org.bukkit.Material;

View file

@ -10,7 +10,7 @@ import org.bukkit.entity.Player;
import java.util.UUID; 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 class RankDataManager {
public static void setRank(UUID uuid, Rank rank) { public static void setRank(UUID uuid, Rank rank) {

View file

@ -1,6 +1,6 @@
package me.night.nullvalkyrie.database; 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.Document;
import org.bson.conversions.Bson; import org.bson.conversions.Bson;

View file

@ -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<Pair<EnumItemSlot, net.minecraft.world.item.ItemStack>> 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));
}
}

View file

@ -5,6 +5,7 @@ import com.mojang.authlib.properties.Property;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import me.night.nullvalkyrie.Main; import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.database.NPCDataManager; import me.night.nullvalkyrie.database.NPCDataManager;
import me.night.nullvalkyrie.util.Skin;
import me.night.nullvalkyrie.util.Util; import me.night.nullvalkyrie.util.Util;
import net.minecraft.network.protocol.game.*; import net.minecraft.network.protocol.game.*;
import net.minecraft.network.syncher.DataWatcher; import net.minecraft.network.syncher.DataWatcher;

View file

@ -41,6 +41,7 @@ public class ServerEvents implements Listener {
} }
@EventHandler @EventHandler
public void onClickHologram(InteractHologramEvent e) { public void onClickHologram(InteractHologramEvent e) {
if (e.getHologram().getCustomName() == null) return;
if (e.getHologram().getCustomName().equals(ChatColor.GOLD + "Click me to change!!!")) { if (e.getHologram().getCustomName().equals(ChatColor.GOLD + "Click me to change!!!")) {
// TODO: change hologram things // TODO: change hologram things
} }

View file

@ -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);
}
}

View file

@ -1,7 +1,7 @@
package me.night.nullvalkyrie.ui.inventory; package me.night.nullvalkyrie.ui.inventory;
import me.night.nullvalkyrie.database.MinerDataManager; 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.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;

View file

@ -1,4 +1,4 @@
package me.night.nullvalkyrie.ui; package me.night.nullvalkyrie.ui.player;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;

View file

@ -1,4 +1,4 @@
package me.night.nullvalkyrie.ui; package me.night.nullvalkyrie.ui.player;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View file

@ -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.database.RankDataManager;
import me.night.nullvalkyrie.enums.Rank; import me.night.nullvalkyrie.enums.Rank;
@ -19,7 +19,7 @@ public class NameTagManager {
for (Player target : Bukkit.getOnlinePlayers()) { for (Player target : Bukkit.getOnlinePlayers()) {
if (player.getUniqueId() != target.getUniqueId()) { if (player.getUniqueId() != target.getUniqueId()) {
Rank rank = RankDataManager.getRank(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());
} }
} }
} }

View file

@ -1,4 +1,4 @@
package me.night.nullvalkyrie.ui; package me.night.nullvalkyrie.ui.player;
import me.night.nullvalkyrie.Main; import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.database.RankDataManager; import me.night.nullvalkyrie.database.RankDataManager;
@ -54,7 +54,6 @@ public class ScoreboardListener implements Listener {
e.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard()); e.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
AnimatedSideBar board = sideBarManager.board; AnimatedSideBar board = sideBarManager.board;
if (board.hasID()) board.stop(); if (board.hasID()) board.stop();
} }
@EventHandler @EventHandler

View file

@ -1,4 +1,4 @@
package me.night.nullvalkyrie.ui; package me.night.nullvalkyrie.ui.player;
import me.night.nullvalkyrie.Main; import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.database.UserDataManager; import me.night.nullvalkyrie.database.UserDataManager;

View file

@ -1,4 +1,4 @@
package me.night.nullvalkyrie.entities.npcs; package me.night.nullvalkyrie.util;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
@ -11,15 +11,6 @@ import java.io.InputStreamReader;
import java.net.URL; import java.net.URL;
public class Skin { 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) { public static String[] getSkin(String name) {
try { try {
URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + name); URL url = new URL("https://api.mojang.com/users/profiles/minecraft/" + name);