From a7b7db3db2f9fc45903bdcdf16e7f173a14d2f39 Mon Sep 17 00:00:00 2001 From: NK Date: Fri, 25 Nov 2022 23:29:56 +0000 Subject: [PATCH] .env fix --- src/main/java/me/night/nullvalkyrie/Main.java | 10 ++++------ .../night/nullvalkyrie/commands/BetaCommand.java | 8 +++----- .../nullvalkyrie/commands/CommandManager.java | 6 +----- .../nullvalkyrie/database/DatabaseManager.java | 11 +++++------ .../discord/DiscordClientManager.java | 3 ++- .../enchantments/CustomEnchantment.java | 15 ++++++++------- .../java/me/night/nullvalkyrie/npc/NPCEvents.java | 2 +- .../npc/{NPC.java => NPCManager.java} | 6 ++++-- .../me/night/nullvalkyrie/npc/PacketHandler.java | 2 +- .../night/nullvalkyrie/ui/ScoreboardListener.java | 8 ++++---- .../me/night/nullvalkyrie/util/FileManager.java | 1 + src/main/resources/plugin.yml | 2 ++ 12 files changed, 36 insertions(+), 38 deletions(-) rename src/main/java/me/night/nullvalkyrie/npc/{NPC.java => NPCManager.java} (98%) diff --git a/src/main/java/me/night/nullvalkyrie/Main.java b/src/main/java/me/night/nullvalkyrie/Main.java index b64bcfa..8df2c9d 100644 --- a/src/main/java/me/night/nullvalkyrie/Main.java +++ b/src/main/java/me/night/nullvalkyrie/Main.java @@ -14,18 +14,16 @@ import me.night.nullvalkyrie.database.DatabaseManager; import org.bukkit.*; import org.bukkit.plugin.java.JavaPlugin; public final class Main extends JavaPlugin { - - + public static Dotenv env; @Override public void onEnable() { getConfig().options().copyDefaults(); 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(); new CustomItemManager(this); 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 MenuListener(), this); Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this); @@ -34,6 +32,6 @@ public final class Main extends JavaPlugin { Bukkit.getPluginManager().registerEvents(new NPCEvents(), this); new DiscordClientManager(); new DatabaseManager(this); - NPC.loadNPC(CustomItemManager.loadConfig("npcs.yml")); + NPCManager.reloadNPC(); } } diff --git a/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java b/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java index 05b9a3b..6fbba00 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/BetaCommand.java @@ -1,25 +1,23 @@ package me.night.nullvalkyrie.commands; 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.entity.Player; import java.util.List; public class BetaCommand extends Command { - private Main main; - public BetaCommand(Main main) { + public BetaCommand() { super("beta", new String[]{"b", "npc"}, "Beta", ""); - this.main = main; } @Override public void onCommand(CommandSender sender, String[] args) { if (sender instanceof Player) { Player player = (Player) sender; - NPC.createNPC(player, "&a&lNK"); + NPCManager.createNPC(player, "&a&lNK"); } } @Override diff --git a/src/main/java/me/night/nullvalkyrie/commands/CommandManager.java b/src/main/java/me/night/nullvalkyrie/commands/CommandManager.java index 7a18ed2..96e0fe3 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/CommandManager.java +++ b/src/main/java/me/night/nullvalkyrie/commands/CommandManager.java @@ -3,11 +3,7 @@ package me.night.nullvalkyrie.commands; import me.night.nullvalkyrie.Main; public class CommandManager { - private final Main main; public CommandManager(Main main) { - this.main = main; - } - public void register() { new VanishCommand(); new TestCommand(); new AnvilCommand(); @@ -21,7 +17,7 @@ public class CommandManager { new RankCommand(); new UtilCommand(); new ShopCommand(); - new BetaCommand(main); + new BetaCommand(); new MinerCommand(main); } } diff --git a/src/main/java/me/night/nullvalkyrie/database/DatabaseManager.java b/src/main/java/me/night/nullvalkyrie/database/DatabaseManager.java index b531786..6a08cbe 100644 --- a/src/main/java/me/night/nullvalkyrie/database/DatabaseManager.java +++ b/src/main/java/me/night/nullvalkyrie/database/DatabaseManager.java @@ -17,12 +17,11 @@ public class DatabaseManager { connect(); } public void connect() { -// System.out.println(System.getenv("MONGO")); -// try (MongoClient client = MongoClients.create(System.getenv("MONGO"))) { -// -// } catch (MongoException e) { -// System.out.println("An error occurred when logging in to MongoDB" + e); -// } + try (MongoClient client = MongoClients.create(Main.env.get("MONGODB_URI"))) { + + } catch (MongoException 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"); MongoDatabase database = client.getDatabase("NullValkyrie"); users = database.getCollection("users"); diff --git a/src/main/java/me/night/nullvalkyrie/discord/DiscordClientManager.java b/src/main/java/me/night/nullvalkyrie/discord/DiscordClientManager.java index d817bbd..41b2de6 100644 --- a/src/main/java/me/night/nullvalkyrie/discord/DiscordClientManager.java +++ b/src/main/java/me/night/nullvalkyrie/discord/DiscordClientManager.java @@ -1,4 +1,5 @@ package me.night.nullvalkyrie.discord; +import me.night.nullvalkyrie.Main; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.Activity; @@ -12,7 +13,7 @@ public class DiscordClientManager { 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")); try { jda = builder.build(); diff --git a/src/main/java/me/night/nullvalkyrie/enchantments/CustomEnchantment.java b/src/main/java/me/night/nullvalkyrie/enchantments/CustomEnchantment.java index 9c40c5f..ca60e8f 100644 --- a/src/main/java/me/night/nullvalkyrie/enchantments/CustomEnchantment.java +++ b/src/main/java/me/night/nullvalkyrie/enchantments/CustomEnchantment.java @@ -4,24 +4,25 @@ import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; public class CustomEnchantment extends Enchantment { private final String name; - private final int maxlvl; + private final int max; public CustomEnchantment(String namespace, String name, int lvl) { super(NamespacedKey.minecraft(namespace)); this.name = name; - this.maxlvl = lvl; + this.max = lvl; } @Override - public String getName() { + public @NotNull String getName() { return name; } @Override public int getMaxLevel() { - return maxlvl; + return max; } @Override @@ -30,7 +31,7 @@ public class CustomEnchantment extends Enchantment { } @Override - public EnchantmentTarget getItemTarget() { + public @NotNull EnchantmentTarget getItemTarget() { return null; } @@ -45,12 +46,12 @@ public class CustomEnchantment extends Enchantment { } @Override - public boolean conflictsWith(Enchantment other) { + public boolean conflictsWith(@NotNull Enchantment other) { return false; } @Override - public boolean canEnchantItem(ItemStack item) { + public boolean canEnchantItem(@NotNull ItemStack item) { return true; } } diff --git a/src/main/java/me/night/nullvalkyrie/npc/NPCEvents.java b/src/main/java/me/night/nullvalkyrie/npc/NPCEvents.java index d4c835f..1b2c2a7 100644 --- a/src/main/java/me/night/nullvalkyrie/npc/NPCEvents.java +++ b/src/main/java/me/night/nullvalkyrie/npc/NPCEvents.java @@ -21,7 +21,7 @@ public class NPCEvents implements Listener { } @EventHandler public void onMove(PlayerMoveEvent e) { - NPC.getNPCs().stream().forEach(npc -> { + NPCManager.getNPCs().forEach(npc -> { Location location = npc.getBukkitEntity().getLocation(); location.setDirection(e.getPlayer().getLocation().subtract(location).toVector()); float yaw = location.getYaw(); diff --git a/src/main/java/me/night/nullvalkyrie/npc/NPC.java b/src/main/java/me/night/nullvalkyrie/npc/NPCManager.java similarity index 98% rename from src/main/java/me/night/nullvalkyrie/npc/NPC.java rename to src/main/java/me/night/nullvalkyrie/npc/NPCManager.java index e296524..3bc164d 100644 --- a/src/main/java/me/night/nullvalkyrie/npc/NPC.java +++ b/src/main/java/me/night/nullvalkyrie/npc/NPCManager.java @@ -32,13 +32,15 @@ import java.util.List; import java.util.Objects; import java.util.UUID; -public class NPC { +public class NPCManager { private static final List NPCs = new ArrayList<>(); public static List getNPCs() { 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 ** EntityPlayer sp = ((CraftPlayer) player).getHandle(); MinecraftServer server = sp.c; diff --git a/src/main/java/me/night/nullvalkyrie/npc/PacketHandler.java b/src/main/java/me/night/nullvalkyrie/npc/PacketHandler.java index b904125..61e63fe 100644 --- a/src/main/java/me/night/nullvalkyrie/npc/PacketHandler.java +++ b/src/main/java/me/night/nullvalkyrie/npc/PacketHandler.java @@ -36,7 +36,7 @@ public class PacketHandler extends ChannelDuplexHandler { hand.setAccessible(true); if (!hand.get(data).toString().equals("MAIN_HAND")) { return; } //Right Click - for (EntityPlayer npcs : NPC.getNPCs()) { + for (EntityPlayer npcs : NPCManager.getNPCs()) { if (npcs.ae() == entityID && sneak) { Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getPlugin(Main.class), new Runnable() { @Override diff --git a/src/main/java/me/night/nullvalkyrie/ui/ScoreboardListener.java b/src/main/java/me/night/nullvalkyrie/ui/ScoreboardListener.java index 182f7e6..cce4a3f 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/ScoreboardListener.java +++ b/src/main/java/me/night/nullvalkyrie/ui/ScoreboardListener.java @@ -1,7 +1,7 @@ package me.night.nullvalkyrie.ui; import me.night.nullvalkyrie.Main; -import me.night.nullvalkyrie.npc.NPC; +import me.night.nullvalkyrie.npc.NPCManager; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -42,9 +42,9 @@ public class ScoreboardListener implements Listener { sideBarManager.start(player); belowNameManager.setBelowName(player); e.setJoinMessage(rankManager.getRank(e.getPlayer().getUniqueId()).getDisplay() + " " + e.getPlayer().getName() + ChatColor.WHITE + " joined the server!"); - if(NPC.getNPCs() == null) return; - if(NPC.getNPCs().isEmpty()) return; - NPC.addJoinPacket(e.getPlayer()); + if(NPCManager.getNPCs() == null) return; + if(NPCManager.getNPCs().isEmpty()) return; + NPCManager.addJoinPacket(e.getPlayer()); } @EventHandler diff --git a/src/main/java/me/night/nullvalkyrie/util/FileManager.java b/src/main/java/me/night/nullvalkyrie/util/FileManager.java index a2a770f..945e163 100644 --- a/src/main/java/me/night/nullvalkyrie/util/FileManager.java +++ b/src/main/java/me/night/nullvalkyrie/util/FileManager.java @@ -4,6 +4,7 @@ import static me.night.nullvalkyrie.items.CustomItemManager.updateYamlFilesToPlu public class FileManager { public FileManager() { + updateYamlFilesToPlugin(".env"); updateYamlFilesToPlugin("shop.yml"); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c47eccc..8f88048 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -9,3 +9,5 @@ depend: [ProtocolLib] permissions: nv.command.use: default: true +libraries: + - "io.github.cdimascio:dotenv-java:2.3.1"