NPC clicking event and miner updates(working)

This commit is contained in:
NK 2022-11-23 22:25:08 +00:00
parent 05ca15ef0c
commit 9090b473cb
17 changed files with 297 additions and 268 deletions

View file

@ -8,12 +8,14 @@ import me.night.nullvalkyrie.events.CustomItemEvents;
import me.night.nullvalkyrie.events.DamageEffect; import me.night.nullvalkyrie.events.DamageEffect;
import me.night.nullvalkyrie.hardpoint.ConfigManager; import me.night.nullvalkyrie.hardpoint.ConfigManager;
import me.night.nullvalkyrie.items.CustomItemManager; import me.night.nullvalkyrie.items.CustomItemManager;
import me.night.nullvalkyrie.npc.ClickNPC;
import me.night.nullvalkyrie.npc.NPC; import me.night.nullvalkyrie.npc.NPC;
import me.night.nullvalkyrie.npc.PacketInjector;
import me.night.nullvalkyrie.rank.ScoreboardListener; import me.night.nullvalkyrie.rank.ScoreboardListener;
import me.night.nullvalkyrie.util.FileManager;
import me.night.nullvalkyrie.util.Util; import me.night.nullvalkyrie.util.Util;
import me.night.nullvalkyrie.commands.*; import me.night.nullvalkyrie.commands.*;
import me.night.nullvalkyrie.database.Client; import me.night.nullvalkyrie.database.DatabaseManager;
import me.night.nullvalkyrie.miners.CryptoMiner;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.boss.BarColor; import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle; import org.bukkit.boss.BarStyle;
@ -25,23 +27,19 @@ import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
import java.util.Date;
import static me.night.nullvalkyrie.items.CustomItemManager.updateYamlFilesToPlugin;
public final class Main extends JavaPlugin implements Listener { public final class Main extends JavaPlugin implements Listener {
private BossBar bossbar; private BossBar bossbar;
private PacketInjector injector;
@Override @Override
public void onEnable() { public void onEnable() {
getConfig().options().copyDefaults(); getConfig().options().copyDefaults();
saveDefaultConfig(); saveDefaultConfig();
new NPC(this);
EnchantmentManager.register(); EnchantmentManager.register();
new CustomItemManager(this); new CustomItemManager(this);
updateYamlFilesToPlugin("shop.yml"); new FileManager();
updateYamlFilesToPlugin("hardpoint.yml");
updateYamlFilesToPlugin("miners.yml");
new CommandManager(this).register(); new CommandManager(this).register();
bossbar = Bukkit.createBossBar(ChatColor.GOLD + "Kuudra", BarColor.RED, BarStyle.SEGMENTED_12); bossbar = Bukkit.createBossBar(ChatColor.GOLD + "Kuudra", BarColor.RED, BarStyle.SEGMENTED_12);
Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(this, this);
@ -49,16 +47,18 @@ public final class Main extends JavaPlugin implements Listener {
Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this); Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this);
Bukkit.getPluginManager().registerEvents(new CustomItemEvents(this), this); Bukkit.getPluginManager().registerEvents(new CustomItemEvents(this), this);
Bukkit.getPluginManager().registerEvents(new DamageEffect(this), this); Bukkit.getPluginManager().registerEvents(new DamageEffect(this), this);
Bukkit.getPluginManager().registerEvents(new ClickNPC(), this);
//Bukkit.getPluginManager().registerEvents(new GameEvent(this), this); //Bukkit.getPluginManager().registerEvents(new GameEvent(this), this);
new DiscordClientManager(); new DiscordClientManager();
new CryptoMiner(this, "Baka", Material.ENDER_CHEST, 10, 0.7, new Date().getTime()); new DatabaseManager();
new Client();
ConfigManager.setConfig(); ConfigManager.setConfig();
NPC.loadNPC(CustomItemManager.loadConfig("npcs.yml"));
this.injector = new PacketInjector();
} }
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent e) { public void onJoin(PlayerJoinEvent e) {
bossbar.addPlayer(e.getPlayer()); bossbar.addPlayer(e.getPlayer());
injector.addPlayer(e.getPlayer());
} }
@EventHandler @EventHandler

View file

@ -1,7 +1,9 @@
package me.night.nullvalkyrie.commands; package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.Main; import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.miners.CryptoMiner;
import me.night.nullvalkyrie.miners.MinerGUI; import me.night.nullvalkyrie.miners.MinerGUI;
import org.bukkit.Material;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -27,11 +29,27 @@ public class MinerCommand extends Command {
@Override @Override
public void onCommand(CommandSender sender, String[] args) { public void onCommand(CommandSender sender, String[] args) {
if (sender instanceof Player) { if (sender instanceof Player) {
Player player = (Player) sender; if(args.length == 0) {
new MinerGUI(main, player); Player player = (Player) sender;
int seconds = (int) (new Date().getTime() - (long) getMiner("1").get("lastclaim")) / 1000; new MinerGUI(main, player);
System.out.println("Seconds" + seconds); int seconds = (int) (new Date().getTime() - getMiner("0").getLastclaim()) / 1000;
generate(50, seconds); System.out.println("Seconds" + seconds);
generate(50, seconds);
} else if (args[0].equalsIgnoreCase("new")) {
String name = args[1];
Material pick = Material.STONE_PICKAXE;
int level = 20;
double rate = 0.4;
long time = System.currentTimeMillis();
CryptoMiner miner = new CryptoMiner(main, name, pick, level, rate, time);
miner.setMiner(name, pick.name(), level, rate, time);
} else if (args[0].equalsIgnoreCase("claim")) {
String minerIndex = args[1];
CryptoMiner miner = getMiner(minerIndex);
miner.setLastClaim(minerIndex, System.currentTimeMillis());
System.out.println("Done");
}
} }
} }

View file

@ -8,10 +8,9 @@ import org.bson.conversions.Bson;
import java.util.HashMap; import java.util.HashMap;
public class Client { public class DatabaseManager {
private MongoClient client;
private static MongoCollection<Document> users; private static MongoCollection<Document> users;
public Client() { public DatabaseManager() {
connect(); connect();
} }
public void connect() { public void connect() {
@ -31,7 +30,7 @@ public class Client {
users.insertOne(document); users.insertOne(document);
} }
public void updateUserBank(String username, Number coins) { public void updateUserBank(String username, Number coins) {
Document document = (Document) users.find(new Document("Username", username)).first(); Document document = users.find(new Document("Username", username)).first();
if(document != null) { if(document != null) {
Bson updated = new Document("Bank", coins); Bson updated = new Document("Bank", coins);
Bson update = new Document("$set", updated); Bson update = new Document("$set", updated);

View file

@ -3,17 +3,24 @@ package me.night.nullvalkyrie.enchantments;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class EnchantmentManager { public class EnchantmentManager {
public static final Enchantment ThunderBolt = new CustomEnchantment("thunderbolt", "ThunderBolt", 5); public static final Enchantment ThunderBolt = new CustomEnchantment("thunderbolt", "ThunderBolt", 5);
public static final Enchantment SmeltingTouch = new CustomEnchantment("smelting-touch", "Smelting Touch", 1); public static final Enchantment SmeltingTouch = new CustomEnchantment("smelting-touch", "Smelting Touch", 1);
public static void register() { public static void register() {
boolean registered = Arrays.stream(Enchantment.values()).collect(Collectors.toList()).contains(ThunderBolt); List<Enchantment> enchants = new ArrayList<>();
if(!registered) { enchants.add(ThunderBolt);
registerEnchantment(ThunderBolt); enchants.add(SmeltingTouch);
registerEnchantment(SmeltingTouch); List<Boolean> registeredList = new ArrayList<>();
for (Enchantment enchant : enchants) {
registeredList.add(Arrays.stream(Enchantment.values()).collect(Collectors.toList()).contains(enchant));
}
for (int counter = 0; counter < registeredList.size(); counter++) {
if (!registeredList.get(counter)) registerEnchantment(enchants.get(counter));
} }
} }

View file

@ -221,7 +221,7 @@ public class CustomItemManager {
} }
public static void updateYamlFilesToPlugin(String path) { public static void updateYamlFilesToPlugin(String path) {
File file = new File(main.getDataFolder(), path); //xxx.yml File file = new File(main.getDataFolder(), path);
if (!file.exists()) main.saveResource(path, true); if (!file.exists()) main.saveResource(path, true);
else main.saveResource(path, true); else main.saveResource(path, true);
} }

View file

@ -6,7 +6,6 @@ import org.bukkit.configuration.file.FileConfiguration;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -28,8 +27,7 @@ public class CryptoMiner {
this.level = level; this.level = level;
this.rate = rate; // Percentage generate chance in each tick 20tick per sec this.rate = rate; // Percentage generate chance in each tick 20tick per sec
this.lastclaim = lastclaim; this.lastclaim = lastclaim;
FileConfiguration file = loadConfig("miners.yml");
setMiner(Integer.toString(file.getKeys(false).size()), name, type.name(), level, rate, lastclaim);
} }
public String getName() { public String getName() {
@ -57,8 +55,15 @@ public class CryptoMiner {
public long getLastclaim() { public long getLastclaim() {
return lastclaim; return lastclaim;
} }
public void setLastClaim(long lastclaim) { public void setLastClaim(String index, long lastclaim) {
this.lastclaim = lastclaim; this.lastclaim = lastclaim;
FileConfiguration file = loadConfig("miners.yml");
file.set(index + ".last-claim", lastclaim);
try {
file.save(loadFile("miners.yml"));
} catch (IOException ignored) {
}
} }
public static void generate(int pp, int times) { public static void generate(int pp, int times) {
for (int counter = 0; counter < times; counter++) { for (int counter = 0; counter < times; counter++) {
@ -75,18 +80,18 @@ public class CryptoMiner {
} }
return arr; return arr;
} }
public static HashMap<String, Object> getMiner(String index) { public static CryptoMiner getMiner(String index) {
FileConfiguration file = loadConfig("miners.yml"); FileConfiguration file = loadConfig("miners.yml");
HashMap<String, Object> details = new HashMap<>(); String name = file.getString(index + ".name");
details.put("name", file.getString(index + ".name")); Material material = Material.matchMaterial(file.getString(index + ".material"));
details.put("material", Material.matchMaterial(file.getString(index + ".material"))); int level = file.getInt(index + ".level");
details.put("level", file.getInt(index + ".level")); double rate = file.getDouble(index + ".rate");
details.put("rate", file.getDouble(index + ".rate")); long lastclaim = file.getLong(index + ".last-claim");
details.put("lastclaim", file.getLong(index + ".last-claim")); return new CryptoMiner(main, name, material, level, rate, lastclaim);
return details;
} }
public void setMiner(String index, String name, String material, int level, double rate, long time) { public void setMiner(String name, String material, int level, double rate, long time) {
FileConfiguration file = loadConfig("miners.yml"); FileConfiguration file = loadConfig("miners.yml");
String index = Integer.toString(file.getKeys(false).size());
file.createSection(index); file.createSection(index);
file.set(index + ".name", name); file.set(index + ".name", name);
file.set(index + ".material", material); file.set(index + ".material", material);

View file

@ -11,7 +11,9 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
public class MinerGUI { public class MinerGUI {
@ -45,6 +47,7 @@ public class MinerGUI {
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
lore.add("Level: " + file.getString(c + ".level")); lore.add("Level: " + file.getString(c + ".level"));
lore.add("Rate: " + file.getString(c + ".rate")); lore.add("Rate: " + file.getString(c + ".rate"));
lore.add("Last Claim: " + new SimpleDateFormat("d MMM yyyy HH:mm:ss").format(new Date(file.getLong(c + ".last-claim"))));
boolean b = file.getBoolean(c + ".rate") ? lore.add(ChatColor.GRAY + "Click to enable miner!") : lore.add(ChatColor.RED + "Click to disable miner!"); boolean b = file.getBoolean(c + ".rate") ? lore.add(ChatColor.GRAY + "Click to enable miner!") : lore.add(ChatColor.RED + "Click to disable miner!");
itemMeta.setLore(lore); itemMeta.setLore(lore);
item.setItemMeta(itemMeta); item.setItemMeta(itemMeta);

View file

@ -0,0 +1,16 @@
package me.night.nullvalkyrie.npc;
import me.night.nullvalkyrie.util.Util;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class ClickNPC implements Listener {
@EventHandler
public void onClick(RightClickNPC e) {
Player player = e.getPlayer();
if (e.getNPC().getBukkitEntity().getName().equalsIgnoreCase(Util.color("&a&lNK"))) {
player.sendMessage(Util.color("Hi"));
}
}
}

View file

@ -4,6 +4,7 @@ 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.Main; import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.items.CustomItemManager;
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;
@ -17,51 +18,86 @@ import net.minecraft.world.entity.EnumItemSlot;
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.configuration.file.FileConfiguration;
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.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
public class NPC { public class NPC {
private static Main main;
public NPC(Main main) {
NPC.main = main;
}
private static final List<EntityPlayer> NPCs = new ArrayList<>(); private static final List<EntityPlayer> NPCs = new ArrayList<>();
public static List<EntityPlayer> getNPCs() { public static List<EntityPlayer> getNPCs() {
return NPCs; return NPCs;
} }
public static void createNPC(Player player, String name) { //name must be less than 16 characters including color codes ** public static void createNPC(Player player, String name) { //name must be less than 16 characters including color codes **
CraftPlayer creaftPlayer = (CraftPlayer) player; EntityPlayer sp = ((CraftPlayer) player).getHandle();
EntityPlayer sp = creaftPlayer.getHandle();
MinecraftServer server = sp.c; MinecraftServer server = sp.c;
WorldServer level = ((CraftWorld) Bukkit.getWorld(player.getWorld().getName())).getHandle(); WorldServer level = ((CraftWorld) player.getLocation().getWorld()).getHandle();
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), Util.color(name)); GameProfile gameProfile = new GameProfile(UUID.randomUUID(), Util.color(name));
String[] skin = Skin.getSkin("Lendortv"); String[] skin = Skin.getSkin(player);
gameProfile.getProperties().put("textures", new Property("textures", skin[0], skin[1])); gameProfile.getProperties().put("textures", new Property("textures", skin[0], skin[1]));
EntityPlayer npc = new EntityPlayer(server, level, gameProfile, null); EntityPlayer npc = new EntityPlayer(server, level, gameProfile, null);
Location location = player.getLocation(); Location location = player.getLocation();
npc.a(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); npc.a(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
addNPCPacket(npc); addNPCPacket(npc);
NPCs.add(npc); NPCs.add(npc);
int var = 1;
FileConfiguration npcFile = CustomItemManager.loadConfig("npcs.yml");
if (npcFile.contains("data")) var = npcFile.getConfigurationSection("data").getKeys(false).size() + 1;
npcFile.set("data." + var + ".x", (int) player.getLocation().getX());
npcFile.set("data." + var + ".y", (int) player.getLocation().getY());
npcFile.set("data." + var + ".z", (int) player.getLocation().getZ());
npcFile.set("data." + var + ".pitch", (int) player.getLocation().getPitch());
npcFile.set("data." + var + ".yaw", (int) player.getLocation().getYaw());
npcFile.set("data." + var + ".world", player.getLocation().getWorld().getName());
npcFile.set("data." + var + ".name", name);
npcFile.set("data." + var + ".texture", skin[0]);
npcFile.set("data." + var + ".signature", skin[1]);
try {
npcFile.save(CustomItemManager.loadFile("npcs.yml"));
} catch (IOException e) {
e.printStackTrace();
}
} }
public static void loadNPC(FileConfiguration npcFile) {
npcFile.getConfigurationSection("data").getKeys(false).forEach(npc -> {
Location location = new Location(Bukkit.getWorld(Objects.requireNonNull(npcFile.getString("data." + npc + ".world"))), npcFile.getInt("data." + npc + ".x"), npcFile.getInt("data." + npc + ".y"), npcFile.getInt("data." + npc + ".z"));
location.setPitch((float) npcFile.getDouble("data." + npc + ".pitch"));
location.setYaw((float) npcFile.getDouble("data." + npc + ".yaw"));
String name = npcFile.getString("data." + npc + ".name");
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), Util.color(name));
gameProfile.getProperties().put("textures", new Property("textures", npcFile.getString("data." + npc + ".texture"), npcFile.getString("data." + npc + ".signature")));
MinecraftServer server = ((CraftServer) Bukkit.getServer()).getServer();
WorldServer world = ((CraftWorld) location.getWorld()).getHandle();
EntityPlayer npcs = new EntityPlayer(server, world, gameProfile, null);
npcs.a(location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getPitch());
addNPCPacket(npcs);
NPCs.add(npcs);
});
}
public static void addNPCPacket(EntityPlayer npc) { public static void addNPCPacket(EntityPlayer npc) {
for(Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
CraftPlayer creaftPlayer = (CraftPlayer) player; PlayerConnection pc = ((CraftPlayer) player).getHandle().b;
EntityPlayer sp = creaftPlayer.getHandle();
PlayerConnection pc = sp.b;
pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, npc)); pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, npc));
pc.a(new PacketPlayOutNamedEntitySpawn(npc)); pc.a(new PacketPlayOutNamedEntitySpawn(npc));
pc.a(new PacketPlayOutEntityHeadRotation(npc, (byte) (npc.getBukkitYaw() * 256 / 360))); pc.a(new PacketPlayOutEntityHeadRotation(npc, (byte) (npc.getBukkitYaw() * 256 / 360)));
DataWatcher watcher = npc.ai(); DataWatcher watcher = npc.ai();
watcher.b(new DataWatcherObject<>(17, DataWatcherRegistry.a), (byte) 127); watcher.b(new DataWatcherObject<>(17, DataWatcherRegistry.a), (byte) 127);
pc.a(new PacketPlayOutEntityMetadata(npc.ae(), watcher, true)); pc.a(new PacketPlayOutEntityMetadata(npc.ae(), watcher, true));
Bukkit.getScheduler().runTaskLaterAsynchronously(main, () -> pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, npc)), 50); Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(Main.class), () -> pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, npc)), 50);
ItemStack netheriteAxe = new ItemStack(Material.NETHERITE_AXE); ItemStack netheriteAxe = new ItemStack(Material.NETHERITE_AXE);
ItemStack anotherAxe = new ItemStack(Material.NETHERITE_INGOT); ItemStack anotherAxe = new ItemStack(Material.NETHERITE_INGOT);
List<Pair<EnumItemSlot, net.minecraft.world.item.ItemStack>> list = new ArrayList<>(); List<Pair<EnumItemSlot, net.minecraft.world.item.ItemStack>> list = new ArrayList<>();
@ -70,18 +106,24 @@ public class NPC {
pc.a(new PacketPlayOutEntityEquipment(npc.ae(), list)); pc.a(new PacketPlayOutEntityEquipment(npc.ae(), list));
} }
} }
public static void addJoinPacket(Player player) { public static void addJoinPacket(Player player) {
for(EntityPlayer npc : NPCs) { for (EntityPlayer npc : NPCs) {
CraftPlayer creaftPlayer = (CraftPlayer) player; PlayerConnection pc = ((CraftPlayer) player).getHandle().b;
EntityPlayer sp = creaftPlayer.getHandle();
PlayerConnection pc = sp.b;
pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, npc)); pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.a, npc));
pc.a(new PacketPlayOutNamedEntitySpawn(npc)); pc.a(new PacketPlayOutNamedEntitySpawn(npc));
pc.a(new PacketPlayOutEntityHeadRotation(npc, (byte) (npc.getBukkitYaw() * 256 / 360))); pc.a(new PacketPlayOutEntityHeadRotation(npc, (byte) (npc.getBukkitYaw() * 256 / 360)));
DataWatcher watcher = npc.ai(); DataWatcher watcher = npc.ai();
watcher.b(new DataWatcherObject<>(17, DataWatcherRegistry.a), (byte) 127); watcher.b(new DataWatcherObject<>(17, DataWatcherRegistry.a), (byte) 127);
pc.a(new PacketPlayOutEntityMetadata(npc.ae(), watcher, true)); pc.a(new PacketPlayOutEntityMetadata(npc.ae(), watcher, true));
Bukkit.getScheduler().runTaskLaterAsynchronously(main, () -> pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, npc)), 50); Bukkit.getScheduler().runTaskLaterAsynchronously(Main.getPlugin(Main.class), () -> pc.a(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.e, npc)), 50);
ItemStack netheriteAxe = new ItemStack(Material.NETHERITE_AXE);
ItemStack anotherAxe = new ItemStack(Material.NETHERITE_INGOT);
List<Pair<EnumItemSlot, net.minecraft.world.item.ItemStack>> list = new ArrayList<>();
list.add(new Pair<>(EnumItemSlot.a, CraftItemStack.asNMSCopy(netheriteAxe)));
list.add(new Pair<>(EnumItemSlot.b, CraftItemStack.asNMSCopy(anotherAxe)));
pc.a(new PacketPlayOutEntityEquipment(npc.ae(), list));
} }
} }
} }

View file

@ -0,0 +1,57 @@
package me.night.nullvalkyrie.npc;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import me.night.nullvalkyrie.Main;
import net.minecraft.network.protocol.game.PacketPlayInUseEntity;
import net.minecraft.server.level.EntityPlayer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
public class PacketHandler extends ChannelDuplexHandler {
private final Player player;
public PacketHandler(Player player) {
this.player = player;
}
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
super.write(ctx, msg, promise);
}
@Override
public void channelRead(ChannelHandlerContext c, Object packet) throws Exception {
if (packet.getClass().getSimpleName().equalsIgnoreCase("PacketPlayInUseEntity")) {
PacketPlayInUseEntity pk = (PacketPlayInUseEntity) packet;
int entityID = (int) PacketInjector.getFieldValue(packet, "a");
boolean sneak = (boolean) PacketInjector.getFieldValue(packet, "c");
Field type = pk.getClass().getDeclaredField("b");
type.setAccessible(true);
Object data = type.get(pk);
if (data.toString().split("\\$")[1].charAt(0) == 'e') { return; }
try {
Field hand = data.getClass().getDeclaredField("a");
hand.setAccessible(true);
if (!hand.get(data).toString().equals("MAIN_HAND")) { return; }
//Right Click
for (EntityPlayer npcs : NPC.getNPCs()) {
if (npcs.ae() == entityID && sneak) {
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), new Runnable() {
@Override
public void run() {
Bukkit.getPluginManager().callEvent(new RightClickNPC(player, npcs));
}
}, 0);
}
}
} catch (NoSuchFieldException x) {
//Left Click
}
} else {
super.channelRead(c, packet);
}
}
}

View file

@ -0,0 +1,41 @@
package me.night.nullvalkyrie.npc;
import io.netty.channel.Channel;
import net.minecraft.server.level.EntityPlayer;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
public class PacketInjector {
public void addPlayer(Player p) {
try {
Channel ch = nms(p).b.b.m;
if(ch.pipeline().get("PacketInjector") == null) {
PacketHandler h = new PacketHandler(p);
ch.pipeline().addBefore("packet_handler", "PacketInjector", h);
}
} catch (Throwable t) {
t.printStackTrace();
}
}
public void removePlayer(Player p) {
try {
Channel ch = nms(p).b.b.m;
if(ch.pipeline().get("PacketInjector") != null) {
ch.pipeline().remove("PacketInjector");
}
} catch (Throwable t) {
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) {
return ((CraftPlayer) p).getHandle();
}
}

View file

@ -0,0 +1,40 @@
package me.night.nullvalkyrie.npc;
import net.minecraft.server.level.EntityPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class RightClickNPC extends Event implements Cancellable {
private final Player player;
private final EntityPlayer npc;
private boolean isCancelled;
private static final HandlerList HANDLERS = new HandlerList();
public RightClickNPC(Player player, EntityPlayer npc) {
this.player = player;
this.npc = npc;
}
public Player getPlayer() {
return player;
}
public EntityPlayer getNPC() {
return npc;
}
@Override
public boolean isCancelled() {
return isCancelled;
}
@Override
public void setCancelled(boolean cancel) {
isCancelled = cancel;
}
@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
}

View file

@ -12,7 +12,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import static me.night.nullvalkyrie.database.Client.createUserSchema; import static me.night.nullvalkyrie.database.DatabaseManager.createUserSchema;
public class ScoreboardListener implements Listener { public class ScoreboardListener implements Listener {

View file

@ -0,0 +1,10 @@
package me.night.nullvalkyrie.util;
import static me.night.nullvalkyrie.items.CustomItemManager.updateYamlFilesToPlugin;
public class FileManager {
public FileManager() {
updateYamlFilesToPlugin("shop.yml");
updateYamlFilesToPlugin("hardpoint.yml");
}
}

View file

View file

@ -12,213 +12,3 @@
rate: 0.7 rate: 0.7
enabled: true enabled: true
last-claim: 1668208245832 last-claim: 1668208245832
'2':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668208370651
'3':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668208676271
'4':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668210448531
'5':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668210799036
'6':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668254119769
'7':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668254787702
'8':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668256451864
'9':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668257458167
'10':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668257773080
'11':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668259524393
'12':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668260226503
'13':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668261403911
'14':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668261796376
'15':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668262686577
'16':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668262788190
'17':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668263553259
'18':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668263687264
'19':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668267428787
'20':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668267550253
'21':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668267769594
'22':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668268013534
'23':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668268096781
'24':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668268392432
'25':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668268601044
'26':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668300216256
'27':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668300740524
'28':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668301188489
'29':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668303289593
'30':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668303659410
'31':
name: Sussy
material: ENDER_CHEST
level: 10
rate: 0.7
enabled: true
last-claim: 1668304689097

View file

@ -0,0 +1 @@
data: