always day, formatting

This commit is contained in:
NK 2022-12-10 00:04:21 +00:00
parent 569f14bc39
commit 5bbf15458c
17 changed files with 108 additions and 102 deletions

View file

@ -2,10 +2,8 @@ package me.night.nullvalkyrie;
import com.mongodb.client.MongoDatabase; import com.mongodb.client.MongoDatabase;
import io.github.cdimascio.dotenv.Dotenv; import io.github.cdimascio.dotenv.Dotenv;
import me.night.nullvalkyrie.events.listeners.CustomItemEvents; import me.night.nullvalkyrie.events.listeners.*;
import me.night.nullvalkyrie.events.listeners.DamageEffectEvents; import me.night.nullvalkyrie.tasks.AlwaysDayTask;
import me.night.nullvalkyrie.events.listeners.NPCEvents;
import me.night.nullvalkyrie.events.listeners.ServerEvents;
import me.night.nullvalkyrie.ui.inventory.InventoryListener; 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;
@ -17,6 +15,7 @@ import me.night.nullvalkyrie.database.DatabaseManager;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public final class Main extends JavaPlugin { public final class Main extends JavaPlugin {
public static Dotenv env; public static Dotenv env;
public static MongoDatabase database; public static MongoDatabase database;
@ -30,11 +29,12 @@ public final class Main extends JavaPlugin {
new CommandManager(); new CommandManager();
Bukkit.getPluginManager().registerEvents(new ServerEvents(), this); Bukkit.getPluginManager().registerEvents(new ServerEvents(), this);
Bukkit.getPluginManager().registerEvents(new InventoryListener(), this); Bukkit.getPluginManager().registerEvents(new InventoryListener(), this);
Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this); Bukkit.getPluginManager().registerEvents(new ScoreboardListener(), this);
Bukkit.getPluginManager().registerEvents(new CustomItemEvents(this), this); Bukkit.getPluginManager().registerEvents(new CustomItemEvents(), this);
Bukkit.getPluginManager().registerEvents(new DamageEffectEvents(this), this); Bukkit.getPluginManager().registerEvents(new DamageEffectEvents(), this);
Bukkit.getPluginManager().registerEvents(new NPCEvents(), this); Bukkit.getPluginManager().registerEvents(new NPCEvents(), this);
new DiscordClientManager(); new DiscordClientManager();
NPCDataManager.reloadNPC(); NPCDataManager.reloadNPC();
new AlwaysDayTask().runTaskTimer(this, 0, 100);
} }
} }

View file

@ -15,7 +15,6 @@ 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"); CryptoMiner.spawn(player, args[0], "https://textures.minecraft.net/texture/c09cc3c75bd13c59602040b5970f30dbc76825c0e817da815a65d76ab0e82198");
} }
} }

View file

@ -6,25 +6,33 @@ import org.bson.Document;
public class DatabaseManager { public class DatabaseManager {
public static MongoDatabase database; public static MongoDatabase database;
public DatabaseManager() { public DatabaseManager() {
database = MongoClients.create(Main.env.get("MONGODB_URI")).getDatabase("NullValkyrie"); database = MongoClients.create(Main.env.get("MONGODB_URI")).getDatabase("NullValkyrie");
} }
public static MongoCollection<Document> getMinersDB() { public static MongoCollection<Document> getMinersDB() {
return database.getCollection("miners"); return database.getCollection("miners");
} }
public static MongoCollection<Document> getShopsDB() { public static MongoCollection<Document> getShopsDB() {
return database.getCollection("shops"); return database.getCollection("shops");
} }
public static MongoCollection<Document> getRanksDB() { public static MongoCollection<Document> getRanksDB() {
return database.getCollection("ranks"); return database.getCollection("ranks");
} }
public static MongoCollection<Document> getNPCsDB() { public static MongoCollection<Document> getNPCsDB() {
return database.getCollection("npcs"); return database.getCollection("npcs");
} }
public static MongoCollection<Document> getUsersDB() { public static MongoCollection<Document> getUsersDB() {
return database.getCollection("users"); return database.getCollection("users");
} }
public static MongoCollection<Document> getCustomWeaponsDB() { public static MongoCollection<Document> getCustomWeaponsDB() {
return database.getCollection("custom_weapons"); return database.getCollection("custom_weapons");
} }
} }

View file

@ -1,7 +1,6 @@
package me.night.nullvalkyrie.database; package me.night.nullvalkyrie.database;
import com.mongodb.client.MongoCursor; import com.mongodb.client.MongoCursor;
import com.mongodb.client.model.Filters;
import me.night.nullvalkyrie.enums.Rank; import me.night.nullvalkyrie.enums.Rank;
import org.bson.Document; import org.bson.Document;
import org.bson.conversions.Bson; import org.bson.conversions.Bson;
@ -15,7 +14,7 @@ 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) {
Document document = DatabaseManager.getRanksDB().find(new Document("UUID", uuid.toString())).first(); Document document = DatabaseManager.getRanksDB().find(new Document("UUID", uuid.toString())).first();
if(document != null) { if (document != null) {
Bson updated = new Document("Rank", rank.name()); Bson updated = new Document("Rank", rank.name());
Bson update = new Document("$set", updated); Bson update = new Document("$set", updated);
DatabaseManager.getRanksDB().updateOne(document, update); DatabaseManager.getRanksDB().updateOne(document, update);
@ -25,15 +24,16 @@ public class RankDataManager {
newDocument.put("Rank", rank.name()); newDocument.put("Rank", rank.name());
DatabaseManager.getRanksDB().insertOne(newDocument); DatabaseManager.getRanksDB().insertOne(newDocument);
} }
for(Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
if(player.hasPlayedBefore()) { if (player.hasPlayedBefore()) {
nameTagManager.removeTag(player); nameTagManager.removeTag(player);
nameTagManager.newTag(player); nameTagManager.newTag(player);
} }
} }
} }
public static Rank getRank(UUID uuid) { public static Rank getRank(UUID uuid) {
try (MongoCursor<Document> cursor = DatabaseManager.getRanksDB().find(Filters.eq("UUID", uuid.toString())).cursor()) { try (MongoCursor<Document> cursor = DatabaseManager.getRanksDB().find(new Document("UUID", uuid.toString())).cursor()) {
while (cursor.hasNext()) { while (cursor.hasNext()) {
Document doc = cursor.next(); Document doc = cursor.next();
for (String key : doc.keySet()) { for (String key : doc.keySet()) {

View file

@ -3,6 +3,7 @@ package me.night.nullvalkyrie.entities.miners;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.Property;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import me.night.nullvalkyrie.util.Skin;
import me.night.nullvalkyrie.util.Util; import me.night.nullvalkyrie.util.Util;
import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment; import net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment;
import net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo; import net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo;
@ -15,21 +16,24 @@ import org.apache.commons.codec.binary.Base64;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_19_R1.CraftServer; import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld; import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
public class CryptoMiner { public class CryptoMiner {
protected String name; protected String name;
protected Material type; protected Material type;
@ -103,29 +107,30 @@ public class CryptoMiner {
stand.setVisible(true); stand.setVisible(true);
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3); ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3);
SkullMeta meta = (SkullMeta) head.getItemMeta(); SkullMeta meta = (SkullMeta) head.getItemMeta();
if (meta == null) return;
GameProfile profile = new GameProfile(UUID.randomUUID(), null); GameProfile profile = new GameProfile(UUID.randomUUID(), null);
byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes()); byte[] encodedData = Base64.encodeBase64(String.format("{textures:{SKIN:{url:\"%s\"}}}", url).getBytes());
profile.getProperties().put("textures", new Property("textures", new String(encodedData))); profile.getProperties().put("textures", new Property("textures", new String(encodedData)));
Field profileField;
try { try {
profileField = meta.getClass().getDeclaredField("profile"); Util.setFieldValue(meta, "profile", profile);
profileField.setAccessible(true); } catch (Exception e) {
profileField.set(meta, profile); throw new RuntimeException(e);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e1) {
e1.printStackTrace();
} }
head.setItemMeta(meta); head.setItemMeta(meta);
ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE); ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE);
LeatherArmorMeta chestdata = (LeatherArmorMeta) chest.getItemMeta(); LeatherArmorMeta chestdata = (LeatherArmorMeta) chest.getItemMeta();
if (chestdata == null) return;
chestdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58)); chestdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58));
chest.setItemMeta(chestdata); chest.setItemMeta(chestdata);
ItemStack leg = new ItemStack(Material.LEATHER_LEGGINGS); ItemStack leg = new ItemStack(Material.LEATHER_LEGGINGS);
LeatherArmorMeta legdata = (LeatherArmorMeta) leg.getItemMeta(); LeatherArmorMeta legdata = (LeatherArmorMeta) leg.getItemMeta();
if (legdata == null) return;
legdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58)); legdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58));
leg.setItemMeta(legdata); leg.setItemMeta(legdata);
ItemStack boot = new ItemStack(Material.LEATHER_BOOTS); ItemStack boot = new ItemStack(Material.LEATHER_BOOTS);
LeatherArmorMeta bootdata = (LeatherArmorMeta) boot.getItemMeta(); LeatherArmorMeta bootdata = (LeatherArmorMeta) boot.getItemMeta();
if (bootdata == null) return;
bootdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58)); bootdata.setColor(org.bukkit.Color.fromRGB(2, 2, 58));
boot.setItemMeta(bootdata); boot.setItemMeta(bootdata);
ItemStack pick = new ItemStack(Material.GOLDEN_PICKAXE); ItemStack pick = new ItemStack(Material.GOLDEN_PICKAXE);
@ -137,14 +142,19 @@ public class CryptoMiner {
list.add(new Pair<>(EnumItemSlot.f, CraftItemStack.asNMSCopy(head))); list.add(new Pair<>(EnumItemSlot.f, CraftItemStack.asNMSCopy(head)));
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), Util.color(name)); GameProfile gameProfile = new GameProfile(UUID.randomUUID(), Util.color(name));
String[] skin = Skin.getSkin("Shiba_");
gameProfile.getProperties().put("textures", new Property("textures", skin[0], skin[1]));
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer(); MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
WorldServer w = ((CraftWorld) player.getLocation().getWorld()).getHandle(); WorldServer w = ((CraftWorld) player.getLocation().getWorld()).getHandle();
EntityPlayer miner = new EntityPlayer(server, w, gameProfile, null); EntityPlayer miner = new EntityPlayer(server, w, gameProfile, null);
// set the icon to the tab list // TODO: remove the icon from tablist
// TODO: how to make a armor stand turn
PlayerConnection pc = ((org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer) player).getHandle().b; PlayerConnection pc = ((org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer) player).getHandle().b;
pc.a(new PacketPlayOutEntityEquipment(stand.getEntityId(), list)); pc.a(new PacketPlayOutEntityEquipment(stand.getEntityId(), list));
pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, miner)); pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, miner));
double radius = 3;
World world = miner.getBukkitEntity().getWorld();
// write a loop to get nearby 24 blocks using radius 2
int x, y, z = 0;
} }
} }

View file

@ -1,27 +1,25 @@
package me.night.nullvalkyrie.enums; package me.night.nullvalkyrie.enums;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
public enum Rarity { public enum Rarity {
COMMON(ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON", ChatColor.WHITE.toString()), COMMON(ChatColor.WHITE.toString() + ChatColor.BOLD + "COMMON", ChatColor.WHITE.toString()), UNCOMMON(net.md_5.bungee.api.ChatColor.of("#31ff09").toString() + ChatColor.BOLD + "UNCOMMON", net.md_5.bungee.api.ChatColor.of("#31ff09").toString()), RARE(net.md_5.bungee.api.ChatColor.of("#2f57ae").toString() + ChatColor.BOLD + "RARE", net.md_5.bungee.api.ChatColor.of("#2f57ae").toString()), EPIC(net.md_5.bungee.api.ChatColor.of("#b201b2").toString() + ChatColor.BOLD + "EPIC", net.md_5.bungee.api.ChatColor.of("#b201b2").toString()), LEGENDARY(net.md_5.bungee.api.ChatColor.of("#ffa21b").toString() + ChatColor.BOLD + "LEGENDARY", net.md_5.bungee.api.ChatColor.of("#ffa21b").toString()), MYTHIC(net.md_5.bungee.api.ChatColor.of("#ff23ff").toString() + ChatColor.BOLD + "MYTHIC", net.md_5.bungee.api.ChatColor.of("#ff23ff").toString()), ULTRA(ChatColor.RED.toString() + ChatColor.BOLD + "ULTRA", ChatColor.RED.toString()), GRAND(net.md_5.bungee.api.ChatColor.of("#00fdff").toString() + ChatColor.BOLD + "GRAND", net.md_5.bungee.api.ChatColor.of("#00fdff").toString());
UNCOMMON(net.md_5.bungee.api.ChatColor.of("#31ff09").toString() + ChatColor.BOLD + "UNCOMMON", net.md_5.bungee.api.ChatColor.of("#31ff09").toString()),
RARE(net.md_5.bungee.api.ChatColor.of("#2f57ae").toString() + ChatColor.BOLD + "RARE", net.md_5.bungee.api.ChatColor.of("#2f57ae").toString()),
EPIC(net.md_5.bungee.api.ChatColor.of("#b201b2").toString() + ChatColor.BOLD + "EPIC", net.md_5.bungee.api.ChatColor.of("#b201b2").toString()),
LEGENDARY(net.md_5.bungee.api.ChatColor.of("#ffa21b").toString() + ChatColor.BOLD + "LEGENDARY", net.md_5.bungee.api.ChatColor.of("#ffa21b").toString()),
MYTHIC(net.md_5.bungee.api.ChatColor.of("#ff23ff").toString() + ChatColor.BOLD + "MYTHIC", net.md_5.bungee.api.ChatColor.of("#ff23ff").toString()),
ULTRA(ChatColor.RED.toString() + ChatColor.BOLD + "ULTRA", ChatColor.RED.toString()),
GRAND(net.md_5.bungee.api.ChatColor.of("#00fdff").toString() + ChatColor.BOLD + "GRAND", net.md_5.bungee.api.ChatColor.of("#00fdff").toString());
private final String display; private final String display;
private final String color; private final String color;
Rarity(String display, String color) { Rarity(String display, String color) {
this.display = display; this.display = display;
this.color = color; this.color = color;
} }
public String getDisplay() { public String getDisplay() {
return display; return display;
} }
public String getColor() { public String getColor() {
return color; return color;
} }
public static Rarity getRarity(String str) { public static Rarity getRarity(String str) {
return switch (str) { return switch (str) {
case "UNCOMMON" -> UNCOMMON; case "UNCOMMON" -> UNCOMMON;

View file

@ -30,12 +30,6 @@ import java.lang.reflect.InvocationTargetException;
import java.util.*; import java.util.*;
public class CustomItemEvents implements Listener { public class CustomItemEvents implements Listener {
private final Main main;
public CustomItemEvents(Main main) {
this.main = main;
}
@EventHandler @EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent e) { public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
if (e.getDamager().getType().equals(EntityType.SNOWBALL)) { if (e.getDamager().getType().equals(EntityType.SNOWBALL)) {
@ -257,7 +251,7 @@ public class CustomItemEvents implements Listener {
// player.setHealth(20); // player.setHealth(20);
// player.teleport(generateRandomCoord(9, Bukkit.getWorld("world"))); // player.teleport(generateRandomCoord(9, Bukkit.getWorld("world")));
// } // }
// }.runTaskLater(main, 100L); // }.runTaskLater(Main.getPlugin(Main.class), 100L);
// countDown(player, new int[]{5}); // countDown(player, new int[]{5});
// } // }
} }
@ -267,7 +261,7 @@ public class CustomItemEvents implements Listener {
private int taskID; private int taskID;
public void countDown(Player player, int[] a) { public void countDown(Player player, int[] a) {
taskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(main, () -> { taskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Main.getPlugin(Main.class), () -> {
player.sendTitle(ChatColor.RED + "YOU DIED!", ChatColor.GREEN + "You will revive in " + a[0] + " seconds", 0, 20, 0); player.sendTitle(ChatColor.RED + "YOU DIED!", ChatColor.GREEN + "You will revive in " + a[0] + " seconds", 0, 20, 0);
a[0]--; a[0]--;
if (a[0] == 0) { if (a[0] == 0) {
@ -309,8 +303,10 @@ public class CustomItemEvents implements Listener {
p.openMerchant(merchant, true); p.openMerchant(merchant, true);
} }
} }
private final HashMap<Location, Integer> blockStages = new HashMap<>(); private final HashMap<Location, Integer> blockStages = new HashMap<>();
private final HashMap<UUID, Long> miningCooldown = new HashMap<>(); private final HashMap<UUID, Long> miningCooldown = new HashMap<>();
@EventHandler @EventHandler
public void onAnimationEvent(PlayerAnimationEvent e) { //Material blockType, int mineInterval, Pickaxe x public void onAnimationEvent(PlayerAnimationEvent e) { //Material blockType, int mineInterval, Pickaxe x
Player player = e.getPlayer(); Player player = e.getPlayer();
@ -338,6 +334,7 @@ public class CustomItemEvents implements Listener {
block.breakNaturally(); block.breakNaturally();
} }
} }
ProtocolManager manager = ProtocolLibrary.getProtocolManager(); ProtocolManager manager = ProtocolLibrary.getProtocolManager();
public void sendBlockDamage(Player player, Block block) { public void sendBlockDamage(Player player, Block block) {

View file

@ -18,12 +18,6 @@ import java.text.DecimalFormat;
import java.util.*; import java.util.*;
public class DamageEffectEvents implements Listener { public class DamageEffectEvents implements Listener {
private final Main main;
public DamageEffectEvents(Main main) {
this.main = main;
}
public World world = Bukkit.getWorld("world"); public World world = Bukkit.getWorld("world");
public final Map<Entity, Integer> indicators = new HashMap<>(); public final Map<Entity, Integer> indicators = new HashMap<>();
private final DecimalFormat formatter = new DecimalFormat("#"); private final DecimalFormat formatter = new DecimalFormat("#");
@ -65,7 +59,7 @@ public class DamageEffectEvents implements Listener {
} }
removal.forEach(stands::remove); removal.forEach(stands::remove);
} }
}.runTaskTimer(main, 0L, 1L); }.runTaskTimer(Main.getPlugin(Main.class), 0L, 1L);
} }
public static boolean isSpawnable(Location loc) { public static boolean isSpawnable(Location loc) {

View file

@ -5,13 +5,12 @@ import me.night.nullvalkyrie.packets.PacketInjector;
import me.night.nullvalkyrie.util.Util; import me.night.nullvalkyrie.util.Util;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.boss.BarColor; import org.bukkit.boss.*;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import java.io.File; import java.io.File;
@ -46,4 +45,8 @@ public class ServerEvents implements Listener {
// TODO: change hologram things // TODO: change hologram things
} }
} }
@EventHandler
public void onWeatherChange(WeatherChangeEvent e) {
e.setCancelled(true);
}
} }

View file

@ -7,6 +7,7 @@ import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.entities.npcs.NPCManager; import me.night.nullvalkyrie.entities.npcs.NPCManager;
import me.night.nullvalkyrie.events.custom.InteractHologramEvent; import me.night.nullvalkyrie.events.custom.InteractHologramEvent;
import me.night.nullvalkyrie.events.custom.RightClickNPCEvent; import me.night.nullvalkyrie.events.custom.RightClickNPCEvent;
import me.night.nullvalkyrie.util.Util;
import net.minecraft.network.protocol.game.PacketPlayInUseEntity; import net.minecraft.network.protocol.game.PacketPlayInUseEntity;
import net.minecraft.server.level.EntityPlayer; import net.minecraft.server.level.EntityPlayer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -15,8 +16,6 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.lang.reflect.Field;
public class PacketHandler extends ChannelDuplexHandler { public class PacketHandler extends ChannelDuplexHandler {
private final Player player; private final Player player;
@ -33,40 +32,26 @@ public class PacketHandler extends ChannelDuplexHandler {
public void channelRead(ChannelHandlerContext c, Object packet) throws Exception { public void channelRead(ChannelHandlerContext c, Object packet) throws Exception {
if (packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) { if (packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) {
PacketPlayInUseEntity pk = (PacketPlayInUseEntity) packet; PacketPlayInUseEntity pk = (PacketPlayInUseEntity) packet;
int entityID = (int) PacketInjector.getFieldValue(packet, "a"); int entityID = (int) Util.getFieldValue(packet, "a");
boolean sneak = (boolean) PacketInjector.getFieldValue(packet, "c"); boolean sneak = (boolean) Util.getFieldValue(packet, "c");
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), () -> {
@Override for (Entity entity : Bukkit.getWorld("world").getEntities()) {
public void run() { if (entity.getEntityId() == entityID && entity.getType() == EntityType.ARMOR_STAND) {
for (Entity entity : Bukkit.getWorld("world").getEntities()) { Bukkit.getPluginManager().callEvent(new InteractHologramEvent(player, (ArmorStand) entity));
if (entity.getEntityId() == entityID && entity.getType() == EntityType.ARMOR_STAND){
Bukkit.getPluginManager().callEvent(new InteractHologramEvent(player, (ArmorStand) entity));
}
} }
} }
}, 0); }, 0);
Object data = Util.getFieldValue(pk, "b");
Field type = pk.getClass().getDeclaredField("b");
type.setAccessible(true);
Object data = type.get(pk);
if (data.toString().split("\\$")[1].charAt(0) == 'e') { if (data.toString().split("\\$")[1].charAt(0) == 'e') {
return; return;
} }
try { try {
Field hand = data.getClass().getDeclaredField("a"); Object hand = Util.getFieldValue(data, "a");
hand.setAccessible(true); if (!hand.toString().equals("MAIN_HAND")) return;
if (!hand.get(data).toString().equals("MAIN_HAND")) {
return;
}
//Right Click //Right Click
for (EntityPlayer npcs : NPCManager.getNPCs()) { for (EntityPlayer npcs : NPCManager.getNPCs()) {
if (npcs.ae() == entityID && sneak) { if (npcs.ae() == entityID && sneak) {
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), () -> Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, npcs)), 0);
@Override
public void run() {
Bukkit.getPluginManager().callEvent(new RightClickNPCEvent(player, npcs));
}
}, 0);
} }
} }

View file

@ -5,13 +5,11 @@ import net.minecraft.server.level.EntityPlayer;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.lang.reflect.Field;
public class PacketInjector { public class PacketInjector {
public void addPlayer(Player p) { public void addPlayer(Player p) {
try { try {
Channel ch = nms(p).b.b.m; Channel ch = nms(p).b.b.m;
if(ch.pipeline().get("PacketInjector") == null) { if (ch.pipeline().get("PacketInjector") == null) {
PacketHandler h = new PacketHandler(p); PacketHandler h = new PacketHandler(p);
ch.pipeline().addBefore("packet_handler", "PacketInjector", h); ch.pipeline().addBefore("packet_handler", "PacketInjector", h);
} }
@ -23,18 +21,14 @@ public class PacketInjector {
public void removePlayer(Player p) { public void removePlayer(Player p) {
try { try {
Channel ch = nms(p).b.b.m; Channel ch = nms(p).b.b.m;
if(ch.pipeline().get("PacketInjector") != null) { if (ch.pipeline().get("PacketInjector") != null) {
ch.pipeline().remove("PacketInjector"); ch.pipeline().remove("PacketInjector");
} }
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
} }
} }
public static Object getFieldValue(Object instance, String fieldName) throws Exception {
Field field = instance.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
return field.get(instance);
}
public static EntityPlayer nms(Player p) { public static EntityPlayer nms(Player p) {
return ((CraftPlayer) p).getHandle(); return ((CraftPlayer) p).getHandle();
} }

View file

@ -0,0 +1,13 @@
package me.night.nullvalkyrie.tasks;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.scheduler.BukkitRunnable;
public class AlwaysDayTask extends BukkitRunnable {
@Override
public void run() {
World world = Bukkit.getServer().getWorld("world");
if (world != null) world.setTime(0L);
}
}

View file

@ -2,17 +2,13 @@ package me.night.nullvalkyrie.ui.player;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Criteria; import org.bukkit.scoreboard.*;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
public class BelowNameManager { public class BelowNameManager {
public void setBelowName(Player player) { public void setBelowName(Player player) {
Scoreboard board = player.getScoreboard(); Scoreboard board = player.getScoreboard();
Objective obj = board.registerNewObjective("HealthBar", Criteria.DUMMY, ChatColor.RED.toString()); Objective obj = board.registerNewObjective("HealthBar", Criteria.create("CustomHealth"), ChatColor.RED.toString() + player.getHealth() + "");
obj.setDisplaySlot(DisplaySlot.BELOW_NAME); obj.setDisplaySlot(DisplaySlot.BELOW_NAME);
obj.setDisplayName(ChatColor.RED.toString() + player.getHealth() + "");
player.setScoreboard(board); player.setScoreboard(board);
} }
} }

View file

@ -1,6 +1,5 @@
package me.night.nullvalkyrie.ui.player; package me.night.nullvalkyrie.ui.player;
import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.database.RankDataManager; import me.night.nullvalkyrie.database.RankDataManager;
import me.night.nullvalkyrie.enums.Rank; import me.night.nullvalkyrie.enums.Rank;
import me.night.nullvalkyrie.entities.npcs.NPCManager; import me.night.nullvalkyrie.entities.npcs.NPCManager;
@ -21,9 +20,9 @@ public class ScoreboardListener implements Listener {
public static SideBarManager sideBarManager; public static SideBarManager sideBarManager;
private final BelowNameManager belowNameManager; private final BelowNameManager belowNameManager;
public ScoreboardListener(Main main) { public ScoreboardListener() {
nameTagManager = new NameTagManager(); nameTagManager = new NameTagManager();
sideBarManager = new SideBarManager(main); sideBarManager = new SideBarManager();
belowNameManager = new BelowNameManager(); belowNameManager = new BelowNameManager();
} }

View file

@ -13,13 +13,8 @@ import java.util.UUID;
public class SideBarManager { public class SideBarManager {
private int taskID; private int taskID;
private final Main main;
public AnimatedSideBar board = null; public AnimatedSideBar board = null;
public SideBarManager(Main main) {
this.main = main;
}
public void setSideBar(Player player) { public void setSideBar(Player player) {
Scoreboard board = player.getScoreboard(); Scoreboard board = player.getScoreboard();
Objective obj; Objective obj;
@ -55,7 +50,7 @@ public class SideBarManager {
public void start(Player player) { public void start(Player player) {
board = new AnimatedSideBar(player.getUniqueId()); board = new AnimatedSideBar(player.getUniqueId());
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(main, new Runnable() { taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getPlugin(Main.class), new Runnable() {
int count = 0; int count = 0;
public void animate(String str) { public void animate(String str) {

View file

@ -15,17 +15,18 @@ public class Skin {
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);
InputStreamReader reader = new InputStreamReader(url.openStream()); InputStreamReader reader = new InputStreamReader(url.openStream());
String uuid = new JsonParser().parse(reader).getAsJsonObject().get("id").getAsString(); String uuid = JsonParser.parseReader(reader).getAsJsonObject().get("id").getAsString();
URL url2 = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false"); URL url2 = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false");
InputStreamReader reader2 = new InputStreamReader(url2.openStream()); InputStreamReader reader2 = new InputStreamReader(url2.openStream());
JsonObject properties = new JsonParser().parse(reader2).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject(); JsonObject properties = JsonParser.parseReader(reader2).getAsJsonObject().get("properties").getAsJsonArray().get(0).getAsJsonObject();
String texture = properties.get("value").getAsString(); String texture = properties.get("value").getAsString();
String signature = properties.get("signature").getAsString(); String signature = properties.get("signature").getAsString();
return new String[] {texture, signature}; return new String[]{texture, signature};
} catch (Exception e) { } catch (Exception e) {
return new String[]{}; return new String[]{};
} }
} }
public static String[] getSkin(Player player) { public static String[] getSkin(Player player) {
try { try {
GameProfile profile = ((CraftPlayer) player).getProfile(); GameProfile profile = ((CraftPlayer) player).getProfile();

View file

@ -2,6 +2,8 @@ package me.night.nullvalkyrie.util;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import java.lang.reflect.Field;
public class Util { public class Util {
public static String centerText(String text, int lineLength) { public static String centerText(String text, int lineLength) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
@ -22,4 +24,16 @@ public class Util {
if (str == null || str.length() == 0) return str; if (str == null || str.length() == 0) return str;
return str.substring(0, 1).toUpperCase() + str.substring(1); return str.substring(0, 1).toUpperCase() + str.substring(1);
} }
public static Object getFieldValue(Object instance, String fieldName) throws Exception {
Field field = instance.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
return field.get(instance);
}
public static void setFieldValue(Object instance, String fieldName, Object value) throws Exception {
Field field = instance.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
field.set(instance, value);
}
} }