This commit is contained in:
NK 2022-11-25 23:29:56 +00:00
parent 4da943e385
commit a7b7db3db2
12 changed files with 36 additions and 38 deletions

View file

@ -14,18 +14,16 @@ 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;
@Override @Override
public void onEnable() { public void onEnable() {
getConfig().options().copyDefaults(); getConfig().options().copyDefaults();
saveDefaultConfig(); saveDefaultConfig();
// Dotenv env = Dotenv.configure().directory("C:\\Users\\NK\\OneDrive\\Desktop\\.nky\\Coding\\Java\\NullValkyrie\\src\\main\\resources").filename(".env").load();
// System.out.println(env.get("MONGO"));
EnchantmentManager.register(); EnchantmentManager.register();
new CustomItemManager(this); new CustomItemManager(this);
new FileManager(); new FileManager();
new CommandManager(this).register(); env = Dotenv.configure().directory("E:\\Files\\SB\\plugins\\NullValkyrie").filename(".env").load();
new CommandManager(this);
Bukkit.getPluginManager().registerEvents(new ServerEvents(), this); Bukkit.getPluginManager().registerEvents(new ServerEvents(), this);
Bukkit.getPluginManager().registerEvents(new MenuListener(), this); Bukkit.getPluginManager().registerEvents(new MenuListener(), this);
Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this); Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this);
@ -34,6 +32,6 @@ public final class Main extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new NPCEvents(), this); Bukkit.getPluginManager().registerEvents(new NPCEvents(), this);
new DiscordClientManager(); new DiscordClientManager();
new DatabaseManager(this); new DatabaseManager(this);
NPC.loadNPC(CustomItemManager.loadConfig("npcs.yml")); NPCManager.reloadNPC();
} }
} }

View file

@ -1,25 +1,23 @@
package me.night.nullvalkyrie.commands; package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.Main; import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.npc.NPC; import me.night.nullvalkyrie.npc.NPCManager;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List; import java.util.List;
public class BetaCommand extends Command { public class BetaCommand extends Command {
private Main main;
public BetaCommand(Main main) { public BetaCommand() {
super("beta", new String[]{"b", "npc"}, "Beta", ""); super("beta", new String[]{"b", "npc"}, "Beta", "");
this.main = main;
} }
@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; Player player = (Player) sender;
NPC.createNPC(player, "&a&lNK"); NPCManager.createNPC(player, "&a&lNK");
} }
} }
@Override @Override

View file

@ -3,11 +3,7 @@ package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.Main; import me.night.nullvalkyrie.Main;
public class CommandManager { public class CommandManager {
private final Main main;
public CommandManager(Main main) { public CommandManager(Main main) {
this.main = main;
}
public void register() {
new VanishCommand(); new VanishCommand();
new TestCommand(); new TestCommand();
new AnvilCommand(); new AnvilCommand();
@ -21,7 +17,7 @@ public class CommandManager {
new RankCommand(); new RankCommand();
new UtilCommand(); new UtilCommand();
new ShopCommand(); new ShopCommand();
new BetaCommand(main); new BetaCommand();
new MinerCommand(main); new MinerCommand(main);
} }
} }

View file

@ -17,12 +17,11 @@ public class DatabaseManager {
connect(); connect();
} }
public void connect() { public void connect() {
// System.out.println(System.getenv("MONGO")); try (MongoClient client = MongoClients.create(Main.env.get("MONGODB_URI"))) {
// try (MongoClient client = MongoClients.create(System.getenv("MONGO"))) {
// } catch (MongoException e) {
// } catch (MongoException e) { System.out.println("An error occurred when logging in to MongoDB" + e);
// System.out.println("An error occurred when logging in to MongoDB" + e); }
// }
MongoClient client = MongoClients.create("mongodb+srv://cath_exe:gaeismypassion@cath-exe.iolb7.mongodb.net/NullValkyrie"); MongoClient client = MongoClients.create("mongodb+srv://cath_exe:gaeismypassion@cath-exe.iolb7.mongodb.net/NullValkyrie");
MongoDatabase database = client.getDatabase("NullValkyrie"); MongoDatabase database = client.getDatabase("NullValkyrie");
users = database.getCollection("users"); users = database.getCollection("users");

View file

@ -1,4 +1,5 @@
package me.night.nullvalkyrie.discord; package me.night.nullvalkyrie.discord;
import me.night.nullvalkyrie.Main;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity; import net.dv8tion.jda.api.entities.Activity;
@ -12,7 +13,7 @@ public class DiscordClientManager {
register(); register();
} }
public void register() { public void register() {
JDABuilder builder = JDABuilder.createDefault("OTk3ODczMzgyNjM0ODM2MDQ5.Gd9Fdh.GEOleI-1znVeHwaAef54nXl2ovlSmC3hQX-qQI"); JDABuilder builder = JDABuilder.createDefault(Main.env.get("DISCORD_TOKEN"));
builder.setActivity(Activity.streaming("cath.exe", "https://www.youtube.com/watch?v=YSKDu1gKntY")); builder.setActivity(Activity.streaming("cath.exe", "https://www.youtube.com/watch?v=YSKDu1gKntY"));
try { try {
jda = builder.build(); jda = builder.build();

View file

@ -4,24 +4,25 @@ import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class CustomEnchantment extends Enchantment { public class CustomEnchantment extends Enchantment {
private final String name; private final String name;
private final int maxlvl; private final int max;
public CustomEnchantment(String namespace, String name, int lvl) { public CustomEnchantment(String namespace, String name, int lvl) {
super(NamespacedKey.minecraft(namespace)); super(NamespacedKey.minecraft(namespace));
this.name = name; this.name = name;
this.maxlvl = lvl; this.max = lvl;
} }
@Override @Override
public String getName() { public @NotNull String getName() {
return name; return name;
} }
@Override @Override
public int getMaxLevel() { public int getMaxLevel() {
return maxlvl; return max;
} }
@Override @Override
@ -30,7 +31,7 @@ public class CustomEnchantment extends Enchantment {
} }
@Override @Override
public EnchantmentTarget getItemTarget() { public @NotNull EnchantmentTarget getItemTarget() {
return null; return null;
} }
@ -45,12 +46,12 @@ public class CustomEnchantment extends Enchantment {
} }
@Override @Override
public boolean conflictsWith(Enchantment other) { public boolean conflictsWith(@NotNull Enchantment other) {
return false; return false;
} }
@Override @Override
public boolean canEnchantItem(ItemStack item) { public boolean canEnchantItem(@NotNull ItemStack item) {
return true; return true;
} }
} }

View file

@ -21,7 +21,7 @@ public class NPCEvents implements Listener {
} }
@EventHandler @EventHandler
public void onMove(PlayerMoveEvent e) { public void onMove(PlayerMoveEvent e) {
NPC.getNPCs().stream().forEach(npc -> { NPCManager.getNPCs().forEach(npc -> {
Location location = npc.getBukkitEntity().getLocation(); Location location = npc.getBukkitEntity().getLocation();
location.setDirection(e.getPlayer().getLocation().subtract(location).toVector()); location.setDirection(e.getPlayer().getLocation().subtract(location).toVector());
float yaw = location.getYaw(); float yaw = location.getYaw();

View file

@ -32,13 +32,15 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
public class NPC { public class NPCManager {
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 reloadNPC() {
loadNPC(CustomItemManager.loadConfig("npcs.yml"));
}
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 **
EntityPlayer sp = ((CraftPlayer) player).getHandle(); EntityPlayer sp = ((CraftPlayer) player).getHandle();
MinecraftServer server = sp.c; MinecraftServer server = sp.c;

View file

@ -36,7 +36,7 @@ public class PacketHandler extends ChannelDuplexHandler {
hand.setAccessible(true); hand.setAccessible(true);
if (!hand.get(data).toString().equals("MAIN_HAND")) { return; } if (!hand.get(data).toString().equals("MAIN_HAND")) { return; }
//Right Click //Right Click
for (EntityPlayer npcs : NPC.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), new Runnable() {
@Override @Override

View file

@ -1,7 +1,7 @@
package me.night.nullvalkyrie.ui; package me.night.nullvalkyrie.ui;
import me.night.nullvalkyrie.Main; import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.npc.NPC; import me.night.nullvalkyrie.npc.NPCManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -42,9 +42,9 @@ public class ScoreboardListener implements Listener {
sideBarManager.start(player); sideBarManager.start(player);
belowNameManager.setBelowName(player); belowNameManager.setBelowName(player);
e.setJoinMessage(rankManager.getRank(e.getPlayer().getUniqueId()).getDisplay() + " " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!"); e.setJoinMessage(rankManager.getRank(e.getPlayer().getUniqueId()).getDisplay() + " " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!");
if(NPC.getNPCs() == null) return; if(NPCManager.getNPCs() == null) return;
if(NPC.getNPCs().isEmpty()) return; if(NPCManager.getNPCs().isEmpty()) return;
NPC.addJoinPacket(e.getPlayer()); NPCManager.addJoinPacket(e.getPlayer());
} }
@EventHandler @EventHandler

View file

@ -4,6 +4,7 @@ import static me.night.nullvalkyrie.items.CustomItemManager.updateYamlFilesToPlu
public class FileManager { public class FileManager {
public FileManager() { public FileManager() {
updateYamlFilesToPlugin(".env");
updateYamlFilesToPlugin("shop.yml"); updateYamlFilesToPlugin("shop.yml");
} }
} }

View file

@ -9,3 +9,5 @@ depend: [ProtocolLib]
permissions: permissions:
nv.command.use: nv.command.use:
default: true default: true
libraries:
- "io.github.cdimascio:dotenv-java:2.3.1"