miners improvement
This commit is contained in:
parent
85ccd11904
commit
baf34db7ae
11 changed files with 119 additions and 131 deletions
|
@ -1,7 +1,8 @@
|
|||
package me.night.nullvalkyrie;
|
||||
|
||||
import me.night.nullvalkyrie.entities.miners.CryptoMiner;
|
||||
import me.night.nullvalkyrie.events.listeners.*;
|
||||
import me.night.nullvalkyrie.tasks.AlwaysDayTask;
|
||||
import me.night.nullvalkyrie.game.tasks.AlwaysDayTask;
|
||||
import me.night.nullvalkyrie.ui.inventory.InventoryListener;
|
||||
import me.night.nullvalkyrie.database.NPCDataManager;
|
||||
import me.night.nullvalkyrie.discord.DiscordClientManager;
|
||||
|
@ -12,7 +13,6 @@ import me.night.nullvalkyrie.database.DatabaseManager;
|
|||
import org.bukkit.*;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
||||
public final class NullValkyrie extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
@ -27,6 +27,7 @@ public final class NullValkyrie extends JavaPlugin {
|
|||
Bukkit.getPluginManager().registerEvents(new NPCEvents(), this);
|
||||
new DiscordClientManager();
|
||||
NPCDataManager.reloadNPC();
|
||||
CryptoMiner.reloadMiner();
|
||||
new AlwaysDayTask().runTaskTimer(this, 0, 100);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ public class MinerCommand extends Command {
|
|||
double rate = 0.4;
|
||||
long time = System.currentTimeMillis();
|
||||
assert type != null;
|
||||
MinerDataManager.setMiner(name, type, level, rate, true, time);
|
||||
CryptoMiner miner = new CryptoMiner(name, type, level, rate, time);
|
||||
MinerDataManager.setMiner(name, type, level, rate, true, time, player.getLocation());
|
||||
CryptoMiner miner = new CryptoMiner(name, type, level, rate, time, player.getLocation());
|
||||
miner.spawn(player);
|
||||
} else if (args[0].equalsIgnoreCase("claim")) {
|
||||
MinerDataManager.setLastClaim(args[1]);
|
||||
|
|
|
@ -5,11 +5,13 @@ import me.night.nullvalkyrie.entities.miners.CryptoMiner;
|
|||
import me.night.nullvalkyrie.enums.MinerType;
|
||||
import org.bson.Document;
|
||||
import org.bson.conversions.Bson;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MinerDataManager {
|
||||
public static void setMiner(String name, MinerType type, int level, double rate, boolean enabled, long lastclaim) {
|
||||
public static void setMiner(String name, MinerType type, int level, double rate, boolean enabled, long lastclaim, Location location) {
|
||||
Document newDocument = new Document();
|
||||
newDocument.put("ID", new DatabaseManager().getMinersDB().countDocuments() + 1);
|
||||
newDocument.put("Name", name);
|
||||
|
@ -18,6 +20,9 @@ public class MinerDataManager {
|
|||
newDocument.put("Rate", rate);
|
||||
newDocument.put("Enabled", enabled);
|
||||
newDocument.put("LastClaim", lastclaim);
|
||||
newDocument.put("x", location.getX());
|
||||
newDocument.put("y", location.getY());
|
||||
newDocument.put("z", location.getZ());
|
||||
new DatabaseManager().getMinersDB().insertOne(newDocument);
|
||||
}
|
||||
|
||||
|
@ -40,20 +45,12 @@ public class MinerDataManager {
|
|||
return 0;
|
||||
}
|
||||
|
||||
public static CryptoMiner getMiner(long id) {
|
||||
Document doc = new DatabaseManager().getMinersDB().find(new Document("ID", id)).first();
|
||||
if (doc != null) {
|
||||
return new CryptoMiner(doc.getString("Name"), MinerType.getByName(doc.getString("Material")), doc.getInteger("Level"), doc.getDouble("Rate"), doc.getLong("LastClaim"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static HashMap<Long, CryptoMiner> getMiners() {
|
||||
HashMap<Long, CryptoMiner> list = new HashMap<>();
|
||||
try (MongoCursor<Document> cursor = new DatabaseManager().getMinersDB().find().cursor()) {
|
||||
while (cursor.hasNext()) {
|
||||
Document doc = cursor.next();
|
||||
list.put(doc.getLong("ID"), new CryptoMiner(doc.getString("Name"), MinerType.getByName(doc.getString("Material")), doc.getInteger("Level"), doc.getDouble("Rate"), doc.getLong("LastClaim")));
|
||||
list.put(doc.getLong("ID"), new CryptoMiner(doc.getString("Name"), MinerType.getByName(doc.getString("Material")), doc.getInteger("Level"), doc.getDouble("Rate"), doc.getLong("LastClaim"), new Location(Bukkit.getWorld("world"), doc.getDouble("x"), doc.getDouble("y"), doc.getDouble("z"))));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.List;
|
|||
|
||||
|
||||
public class NPCDataManager {
|
||||
public static void setNPC(String name, int x, int y, int z, int pitch, int yaw, String world, String texture, String signature) {
|
||||
public static void setNPC(String name, double x, double y, double z, int pitch, int yaw, String world, String texture, String signature) {
|
||||
Document document = new DatabaseManager().getNPCsDB().find(new Document("Name", name)).first();
|
||||
if (document != null) {
|
||||
System.out.println("A NPC with this name already exist");
|
||||
|
@ -36,9 +36,9 @@ public class NPCDataManager {
|
|||
Document document = cursor.next();
|
||||
HashMap<String, Object> npc = new HashMap<>();
|
||||
String name = document.getString("Name");
|
||||
int x = document.getInteger("x");
|
||||
int y = document.getInteger("y");
|
||||
int z = document.getInteger("z");
|
||||
double x = document.getDouble("x");
|
||||
double y = document.getDouble("y");
|
||||
double z = document.getDouble("z");
|
||||
int pitch = document.getInteger("pitch");
|
||||
int yaw = document.getInteger("yaw");
|
||||
String world = document.getString("world");
|
||||
|
|
|
@ -2,48 +2,65 @@ 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.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;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
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;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
|
||||
public class CryptoMiner {
|
||||
protected String name;
|
||||
protected MinerType type;
|
||||
protected int level;
|
||||
protected double rate;
|
||||
protected final long lastclaim;
|
||||
protected final double x;
|
||||
protected final double y;
|
||||
protected final double z;
|
||||
protected final Location location;
|
||||
|
||||
public CryptoMiner(String name, MinerType type, int level, double rate, long lastclaim) {
|
||||
public CryptoMiner(String name, MinerType type, int level, double rate, long lastclaim, Location location) {
|
||||
this.name = name; // Name of the miner
|
||||
this.type = type; // Type of the miner
|
||||
this.level = level;
|
||||
this.rate = rate; // Percentage generate chance in each tick 20tick per sec
|
||||
this.lastclaim = lastclaim;
|
||||
this.x = location.getX();
|
||||
this.y = location.getY();
|
||||
this.z = location.getZ();
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
@ -58,16 +75,12 @@ public class CryptoMiner {
|
|||
return rate;
|
||||
}
|
||||
|
||||
public void setRate(double rate) {
|
||||
this.rate = rate;
|
||||
}
|
||||
|
||||
public Material getType() {
|
||||
return this.type.getMaterial();
|
||||
}
|
||||
|
||||
public void setType(MinerType type) {
|
||||
this.type = type;
|
||||
public MinerType getMinerType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
|
@ -82,6 +95,10 @@ public class CryptoMiner {
|
|||
return lastclaim;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public static void generate(int pp, int times) {
|
||||
int generated = 0;
|
||||
for (int counter = 0; counter < times; counter++) {
|
||||
|
@ -90,21 +107,15 @@ public class CryptoMiner {
|
|||
}
|
||||
System.out.println(generated);
|
||||
}
|
||||
|
||||
public void spawn(Player player) {
|
||||
Location loc = player.getLocation().getWorld().getBlockAt(player.getLocation()).getLocation().add(0.5, 0, 0.5);
|
||||
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);
|
||||
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.type.getHeadTexture()).getBytes());
|
||||
byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", this.getMinerType().getHeadTexture()).getBytes());
|
||||
profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
|
||||
try {
|
||||
Util.setFieldValue(meta, "profile", profile);
|
||||
|
@ -129,109 +140,76 @@ public class CryptoMiner {
|
|||
bootdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58));
|
||||
boot.setItemMeta(bootdata);
|
||||
ItemStack pick = new ItemStack(Material.GOLDEN_PICKAXE);
|
||||
stand.getEquipment().setItemInMainHand(pick);
|
||||
stand.getEquipment().setHelmet(head);
|
||||
stand.getEquipment().setChestplate(chest);
|
||||
stand.getEquipment().setLeggings(leg);
|
||||
stand.getEquipment().setBoots(boot);
|
||||
List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> list = new ArrayList<>();
|
||||
list.add(new Pair<>(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(head)));
|
||||
list.add(new Pair<>(EquipmentSlot.CHEST, CraftItemStack.asNMSCopy(chest)));
|
||||
list.add(new Pair<>(EquipmentSlot.LEGS, CraftItemStack.asNMSCopy(leg)));
|
||||
list.add(new Pair<>(EquipmentSlot.FEET, CraftItemStack.asNMSCopy(boot)));
|
||||
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]));
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
ServerLevel w = ((CraftWorld) player.getLocation().getWorld()).getHandle();
|
||||
ServerPlayer miner = new ServerPlayer(server, w, gameProfile, null);
|
||||
ServerPlayer m = new ServerPlayer(server, w, gameProfile, null);
|
||||
ServerGamePacketListenerImpl pc = ((CraftPlayer) player).getHandle().connection;
|
||||
pc.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, miner));
|
||||
World world = miner.getBukkitEntity().getWorld();
|
||||
pc.send(new ClientboundAddEntityPacket(stand));
|
||||
pc.send(new ClientboundSetEquipmentPacket(stand.getId(), list));
|
||||
pc.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, m));
|
||||
SynchedEntityData watcher = stand.getEntityData();
|
||||
watcher.set(new EntityDataAccessor<>(0, EntityDataSerializers.BYTE), (byte) 20);
|
||||
watcher.set(new EntityDataAccessor<>(5, EntityDataSerializers.BOOLEAN), true);
|
||||
watcher.set(new EntityDataAccessor<>(15, EntityDataSerializers.BYTE), (byte) 13);
|
||||
new PacketPlayOutEntityMetadata(player, stand, watcher);
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
generate();
|
||||
}
|
||||
}.runTaskTimer(NullValkyrie.getPlugin(NullValkyrie.class), 0, 40);
|
||||
}
|
||||
public void generate() {
|
||||
List<Location> locs = new ArrayList<>();
|
||||
for (int x = (int) stand.getLocation().getX() - 3; x <= stand.getLocation().getX() + 2; x++) {
|
||||
for (int z = (int) stand.getLocation().getZ() - 2; z <= stand.getLocation().getZ() + 2; z++) {
|
||||
for (int y = (int) stand.getLocation().getY() - 1; y <= stand.getLocation().getY() - 1; y++) {
|
||||
if (world.getBlockAt(x, y, z).getType() == this.getType())
|
||||
locs.add(world.getBlockAt(x, y, z).getLocation());
|
||||
for (int x = (int) this.getLocation().getX() - 2; x <= this.getLocation().getX() + 2; x++) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
locs.remove(world.getBlockAt(stand.getLocation().subtract(0, -1, 0)).getLocation());
|
||||
if (locs.size() != 0) {
|
||||
Location closest = locs.get(0);
|
||||
for (Location location : locs)
|
||||
if (location.distance(stand.getLocation()) < closest.distance(stand.getLocation())) closest = location;
|
||||
if (location.distance(this.getLocation()) < closest.distance(this.getLocation()))
|
||||
closest = location;
|
||||
ArrayList<ItemStack> items = new ArrayList<>();
|
||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
if (closest.getBlock().getType() == this.getType()) {
|
||||
closest.getBlock().getDrops().clear();
|
||||
int lower = 0;
|
||||
int upper = 0;
|
||||
if (this.level == 1) {
|
||||
lower = 1;
|
||||
upper = 3;
|
||||
} else if (this.level == 2) {
|
||||
lower = 2;
|
||||
upper = 5;
|
||||
} else if (this.level == 3) {
|
||||
lower = 3;
|
||||
upper = 7;
|
||||
} else if (this.level == 4) {
|
||||
lower = 4;
|
||||
upper = 9;
|
||||
} else if (this.level == 5) {
|
||||
lower = 5;
|
||||
upper = 11;
|
||||
} else if (this.level == 6) {
|
||||
lower = 6;
|
||||
upper = 13;
|
||||
} else if (this.level == 7) {
|
||||
lower = 7;
|
||||
upper = 15;
|
||||
} else if (this.level == 8) {
|
||||
lower = 8;
|
||||
upper = 17;
|
||||
} else if (this.level == 9) {
|
||||
lower = 9;
|
||||
upper = 19;
|
||||
} else if (this.level == 10) {
|
||||
lower = 10;
|
||||
upper = 21;
|
||||
} else if (this.level == 11) {
|
||||
lower = 11;
|
||||
upper = 23;
|
||||
} else if (this.level == 12) {
|
||||
lower = 12;
|
||||
upper = 25;
|
||||
} else if (this.level == 13) {
|
||||
lower = 13;
|
||||
upper = 27;
|
||||
} else if (this.level == 14) {
|
||||
lower = 14;
|
||||
upper = 29;
|
||||
} else if (this.level == 15) {
|
||||
lower = 15;
|
||||
upper = 31;
|
||||
} else if (this.level == 16) {
|
||||
lower = 16;
|
||||
upper = 33;
|
||||
} else if (this.level == 17) {
|
||||
lower = 17;
|
||||
upper = 35;
|
||||
} else if (this.level == 18) {
|
||||
lower = 18;
|
||||
upper = 37;
|
||||
} else if (this.level == 19) {
|
||||
lower = 19;
|
||||
upper = 39;
|
||||
} else if (this.level == 20) {
|
||||
lower = 20;
|
||||
upper = 41;
|
||||
}
|
||||
items.add(new ItemStack(this.getType(), random.nextInt(lower, upper)));
|
||||
closest.getBlock().setType(Material.AIR);
|
||||
}
|
||||
closest.getBlock().getDrops().clear();
|
||||
List<int[]> levels = List.of(new int[]{1, 3}, new int[]{2, 5}, new int[]{3, 7}, new int[]{4, 9}, new int[]{5, 11}, new int[]{6, 13}, new int[]{7, 15}, new int[]{8, 17}, new int[]{9, 19}, new int[]{10, 21}, new int[]{11, 23}, new int[]{12, 25}, new int[]{13, 27}, new int[]{14, 29}, new int[]{15, 31}, new int[]{16, 33}, new int[]{17, 35}, new int[]{18, 37}, new int[]{19, 39}, new int[]{20, 41}, new int[]{21, 43}, new int[]{22, 45}, new int[]{23, 47}, new int[]{24, 49}, new int[]{25, 51}, new int[]{26, 53}, new int[]{27, 55}, new int[]{28, 57}, new int[]{29, 59}, new int[]{30, 61}, new int[]{31, 63}, new int[]{32, 65}, new int[]{33, 67}, new int[]{34, 69}, new int[]{35, 71}, new int[]{36, 73}, new int[]{37, 75}, new int[]{38, 77}, new int[]{39, 79}, new int[]{40, 81}, new int[]{41, 83}, new int[]{42, 85}, new int[]{43, 87}, new int[]{44, 89}, new int[]{45, 91}, new int[]{46, 93}, new int[]{47, 95}, new int[]{48, 97}, new int[]{49, 99}, new int[]{50, 100});
|
||||
items.add(new ItemStack(this.getType(), random.nextInt(levels.get(this.getLevel())[0], levels.get(this.getLevel())[1])));
|
||||
closest.getBlock().setType(Material.AIR);
|
||||
// drop the items
|
||||
for (ItemStack item : items) {
|
||||
world.dropItemNaturally(closest, item);
|
||||
this.getLocation().add(0, 2, 0).getWorld().dropItemNaturally(closest, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void reloadMiner() {
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
for (CryptoMiner miner : MinerDataManager.getMiners().values()) {
|
||||
miner.spawn(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void onJoin(Player player) {
|
||||
for (CryptoMiner miner : MinerDataManager.getMiners().values()) {
|
||||
System.out.println(miner.getName());
|
||||
miner.spawn(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ public class NPCManager {
|
|||
public static List<ServerPlayer> getNPCs() {
|
||||
return NPCs;
|
||||
}
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public static void createNPC(Player player, String name) { // name must be less than 16 characters including color codes
|
||||
// TODO: npc not even spawning rn
|
||||
ServerPlayer sp = ((CraftPlayer) player).getHandle();
|
||||
MinecraftServer server = sp.server;
|
||||
ServerLevel level = ((CraftWorld) player.getLocation().getWorld()).getHandle();
|
||||
|
@ -48,8 +48,9 @@ public class NPCManager {
|
|||
npc.setPos(location.getX(), location.getY(), location.getZ());
|
||||
addNPCPacket(npc);
|
||||
NPCs.add(npc);
|
||||
NPCDataManager.setNPC(name, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), (int) player.getLocation().getPitch(), (int) player.getLocation().getYaw(), player.getLocation().getWorld().getName(), skin[0], skin[1]);
|
||||
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]);
|
||||
}
|
||||
|
||||
public static void addNPCPacket(ServerPlayer npc) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
ServerGamePacketListenerImpl pc = ((CraftPlayer) player).getHandle().connection;
|
||||
|
@ -87,9 +88,10 @@ public class NPCManager {
|
|||
pc.send(new ClientboundSetEquipmentPacket(npc.getBukkitEntity().getEntityId(), itemList));
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public static void reloadNPC(List<HashMap<String, Object>> npcs) {
|
||||
for (HashMap<String, Object> npc : npcs) {
|
||||
Location location = new Location(Bukkit.getWorld((String) npc.get("world")), (int) npc.get("x"), (int) npc.get("y"), (int) npc.get("z"), (int) npc.get("yaw"), (int) npc.get("pitch"));
|
||||
Location location = new Location(Bukkit.getWorld((String) npc.get("world")), (double) npc.get("x"), (double) npc.get("y"), (double) npc.get("z"), (int) npc.get("yaw"), (int) npc.get("pitch"));
|
||||
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), Util.color((String) npc.get("name")));
|
||||
gameProfile.getProperties().put("textures", new Property("textures", (String) npc.get("texture"), (String) npc.get("signature")));
|
||||
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
|
|
|
@ -3,7 +3,16 @@ package me.night.nullvalkyrie.enums;
|
|||
import org.bukkit.Material;
|
||||
|
||||
public enum MinerType {
|
||||
DIAMOND("Diamond", Material.DIAMOND_ORE, "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198"), 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");
|
||||
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;
|
||||
|
|
|
@ -29,7 +29,6 @@ public class ServerEvents implements Listener {
|
|||
public void onJoin(PlayerJoinEvent e) {
|
||||
bossbar.addPlayer(e.getPlayer());
|
||||
injector.addPlayer(e.getPlayer());
|
||||
e.getPlayer().setResourcePack("https://www.dropbox.com/s/7y7p93xzhar6vvw/%C2%A7b%C2%A7lNKRP%201.19.3.zip?dl=1");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package me.night.nullvalkyrie.tasks;
|
||||
package me.night.nullvalkyrie.game.tasks;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
|
@ -52,8 +52,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());
|
||||
ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
float health = random.nextFloat(5F,20F);
|
||||
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);
|
||||
|
|
|
@ -2,6 +2,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.entities.npcs.NPCManager;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -30,6 +31,7 @@ public class ScoreboardListener implements Listener {
|
|||
public void onJoin(PlayerJoinEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
if (!player.hasPlayedBefore()) {
|
||||
e.getPlayer().setResourcePack("https://www.dropbox.com/s/7y7p93xzhar6vvw/%C2%A7b%C2%A7lNKRP%201.19.3.zip?dl=1");
|
||||
e.getPlayer().sendTitle(ChatColor.RED + "Welcome to Vanadium!", ChatColor.GREEN + "LOL", 20, 100, 20);
|
||||
RankDataManager.setRank(player.getUniqueId(), Rank.ROOKIE, this);
|
||||
new UserDataManager().createUserBank(e.getPlayer().getUniqueId().toString());
|
||||
|
@ -44,6 +46,7 @@ public class ScoreboardListener implements Listener {
|
|||
if (NPCManager.getNPCs() == null) return;
|
||||
if (NPCManager.getNPCs().isEmpty()) return;
|
||||
NPCManager.addJoinPacket(e.getPlayer());
|
||||
CryptoMiner.onJoin(e.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
Loading…
Reference in a new issue