reformatting + suppress + all using oop now

This commit is contained in:
NK 2022-12-22 10:04:46 +00:00
parent 61066b2ad5
commit 64a5513ba8
17 changed files with 64 additions and 90 deletions

View file

@ -1,6 +1,5 @@
package me.night.nullvalkyrie;
import io.github.cdimascio.dotenv.Dotenv;
import me.night.nullvalkyrie.events.listeners.*;
import me.night.nullvalkyrie.tasks.AlwaysDayTask;
import me.night.nullvalkyrie.ui.inventory.InventoryListener;
@ -8,7 +7,6 @@ import me.night.nullvalkyrie.database.NPCDataManager;
import me.night.nullvalkyrie.discord.DiscordClientManager;
import me.night.nullvalkyrie.util.enchantments.EnchantmentManager;
import me.night.nullvalkyrie.ui.player.ScoreboardListener;
import me.night.nullvalkyrie.util.*;
import me.night.nullvalkyrie.commands.*;
import me.night.nullvalkyrie.database.DatabaseManager;
import org.bukkit.*;
@ -16,13 +14,10 @@ import org.bukkit.plugin.java.JavaPlugin;
public final class Main extends JavaPlugin {
public static Dotenv env;
@Override
public void onEnable() {
EnchantmentManager.register();
new FileManager();
env = Dotenv.configure().directory("E:\\Files\\SB\\plugins\\NullValkyrie").filename(".env").load();
new DatabaseManager();
new CommandManager();
Bukkit.getPluginManager().registerEvents(new ServerEvents(), this);

View file

@ -11,7 +11,6 @@ import org.bukkit.util.StringUtil;
import java.util.*;
import static me.night.nullvalkyrie.entities.miners.CryptoMiner.generate;
public class MinerCommand extends Command {
@ -28,8 +27,6 @@ public class MinerCommand extends Command {
}
if (args[0].equalsIgnoreCase("list")) {
new Miner().UI(player);
int seconds = (int) (new Date().getTime() - MinerDataManager.getLastClaim(1)) / 1000;
generate(50, seconds);
} else if (args[0].equalsIgnoreCase("new")) {
String name = args[2];
MinerType type = MinerType.getByName(args[1]);
@ -43,6 +40,8 @@ public class MinerCommand extends Command {
} else if (args[0].equalsIgnoreCase("claim")) {
MinerDataManager.setLastClaim(args[1]);
player.sendMessage(ChatColor.GREEN + "Claimed");
int seconds = (int) (new Date().getTime() - MinerDataManager.getLastClaim(1)) / 1000;
CryptoMiner.generate(50, seconds);
}
}
}

View file

@ -44,7 +44,7 @@ public class UtilCommand extends Command {
HashMap<String, Object> hh = CustomWeaponsDataManager.getWeapons();
ArrayList<String> cc = new ArrayList<>();
for (String s : hh.keySet()) {
HashMap<String, Object> item = (HashMap<String, Object>) hh.get(s);
@SuppressWarnings("unchecked") HashMap<String, Object> item = (HashMap<String, Object>) hh.get(s);
if (Objects.equals(item.get("Type"), "Util")) {
cc.add((String) item.get("Name"));
}

View file

@ -46,7 +46,7 @@ public class WeaponCommand extends Command {
HashMap<String, Object> hh = CustomWeaponsDataManager.getWeapons();
ArrayList<String> cc = new ArrayList<>();
for (String s : hh.keySet()) {
HashMap<String, Object> item = (HashMap<String, Object>) hh.get(s);
@SuppressWarnings("unchecked") HashMap<String, Object> item = (HashMap<String, Object>) hh.get(s);
if (Objects.equals(item.get("Type"), "Weapon")) {
cc.add((String) item.get("Name"));
}

View file

@ -9,12 +9,11 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@SuppressWarnings("unchecked")
public class CustomWeaponsDataManager {
public static HashMap<String, Object> getWeapon(String itemName) {
public HashMap<String, Object> getWeapon(String itemName) {
HashMap<String, Object> item = new HashMap<>();
try (MongoCursor<Document> cursor = DatabaseManager.getCustomWeaponsDB().find(Filters.eq("Name", itemName)).cursor()) {
try (MongoCursor<Document> cursor = new DatabaseManager().getCustomWeaponsDB().find(Filters.eq("Name", itemName)).cursor()) {
while (cursor.hasNext()) {
Document doc = cursor.next();
String name = doc.getString("Name");
@ -26,8 +25,7 @@ public class CustomWeaponsDataManager {
HashMap<String, Object> prop = new HashMap<>();
abi.put("Name", ability.getString("Name"));
List<String> details = new ArrayList<>();
if (ability.get("Details") != null)
details.addAll((List<String>) ability.get("Details"));
if (ability.get("Details") != null) details.addAll((List<String>) ability.get("Details"));
abi.put("Details", details);
for (String a : properties.keySet()) prop.put(a, properties.get(a));
lores.put("Ability", abi);
@ -40,8 +38,7 @@ public class CustomWeaponsDataManager {
for (String a : attributes.keySet()) attr.put(a, attributes.get(a));
Document pdc = (Document) doc.get("PDC");
HashMap<String, Object> pdcdata = new HashMap<>();
if (pdc != null)
for (String a : pdc.keySet()) pdcdata.put(a, pdc.get(a));
if (pdc != null) for (String a : pdc.keySet()) pdcdata.put(a, pdc.get(a));
Document recipe = (Document) doc.get("Recipes");
HashMap<String, Object> recipes = new HashMap<>();
if (recipe != null) {
@ -71,7 +68,7 @@ public class CustomWeaponsDataManager {
public static HashMap<String, Object> getWeapons() {
HashMap<String, Object> list = new HashMap<>();
try (MongoCursor<Document> cursor = DatabaseManager.getCustomWeaponsDB().find().cursor()) {
try (MongoCursor<Document> cursor = new DatabaseManager().getCustomWeaponsDB().find().cursor()) {
while (cursor.hasNext()) {
Document doc = cursor.next();
HashMap<String, Object> item = new HashMap<>();
@ -84,8 +81,7 @@ public class CustomWeaponsDataManager {
HashMap<String, Object> prop = new HashMap<>();
abi.put("Name", ability.getString("Name"));
List<String> details = new ArrayList<>();
if (ability.get("Details") != null)
details.addAll((List<String>) ability.get("Details"));
if (ability.get("Details") != null) details.addAll((List<String>) ability.get("Details"));
abi.put("Details", details);
for (String a : properties.keySet()) prop.put(a, properties.get(a));
lores.put("Ability", abi);

View file

@ -1,37 +1,36 @@
package me.night.nullvalkyrie.database;
import com.mongodb.client.*;
import me.night.nullvalkyrie.Main;
import org.bson.Document;
public class DatabaseManager {
public static MongoDatabase database;
public DatabaseManager() {
database = MongoClients.create(Main.env.get("MONGODB_URI")).getDatabase("NullValkyrie");
database = MongoClients.create(System.getenv("MONGODB_URI")).getDatabase("NullValkyrie");
}
public static MongoCollection<Document> getMinersDB() {
public MongoCollection<Document> getMinersDB() {
return database.getCollection("miners");
}
public static MongoCollection<Document> getShopsDB() {
public MongoCollection<Document> getShopsDB() {
return database.getCollection("shops");
}
public static MongoCollection<Document> getRanksDB() {
public MongoCollection<Document> getRanksDB() {
return database.getCollection("ranks");
}
public static MongoCollection<Document> getNPCsDB() {
public MongoCollection<Document> getNPCsDB() {
return database.getCollection("npcs");
}
public static MongoCollection<Document> getUsersDB() {
public MongoCollection<Document> getUsersDB() {
return database.getCollection("users");
}
public static MongoCollection<Document> getCustomWeaponsDB() {
public MongoCollection<Document> getCustomWeaponsDB() {
return database.getCollection("custom_weapons");
}

View file

@ -11,27 +11,27 @@ import java.util.HashMap;
public class MinerDataManager {
public static void setMiner(String name, MinerType type, int level, double rate, boolean enabled, long lastclaim) {
Document newDocument = new Document();
newDocument.put("ID", DatabaseManager.getMinersDB().countDocuments() + 1);
newDocument.put("ID", new DatabaseManager().getMinersDB().countDocuments() + 1);
newDocument.put("Name", name);
newDocument.put("Material", type.getName());
newDocument.put("Level", level);
newDocument.put("Rate", rate);
newDocument.put("Enabled", enabled);
newDocument.put("LastClaim", lastclaim);
DatabaseManager.getMinersDB().insertOne(newDocument);
new DatabaseManager().getMinersDB().insertOne(newDocument);
}
public static void setLastClaim(String name) {
Document document = DatabaseManager.getMinersDB().find(new Document("Name", name)).first();
Document document = new DatabaseManager().getMinersDB().find(new Document("Name", name)).first();
if (document != null) {
Bson updated = new Document("LastClaim", System.currentTimeMillis());
Bson update = new Document("$set", updated);
DatabaseManager.getMinersDB().updateOne(document, update);
new DatabaseManager().getMinersDB().updateOne(document, update);
}
}
public static long getLastClaim(long id) {
Document doc = DatabaseManager.getMinersDB().find(new Document("ID", id)).first();
Document doc = new DatabaseManager().getMinersDB().find(new Document("ID", id)).first();
if (doc != null) {
for (String key : doc.keySet()) {
if (key.equals("LastClaim")) return (long) doc.get(key);
@ -41,7 +41,7 @@ public class MinerDataManager {
}
public static CryptoMiner getMiner(long id) {
Document doc = DatabaseManager.getMinersDB().find(new Document("ID", id)).first();
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"));
}
@ -50,7 +50,7 @@ public class MinerDataManager {
public static HashMap<Long, CryptoMiner> getMiners() {
HashMap<Long, CryptoMiner> list = new HashMap<>();
try (MongoCursor<Document> cursor = DatabaseManager.getMinersDB().find().cursor()) {
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")));

View file

@ -11,7 +11,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) {
Document document = DatabaseManager.getNPCsDB().find(new Document("Name", name)).first();
Document document = new DatabaseManager().getNPCsDB().find(new Document("Name", name)).first();
if (document != null) {
System.out.println("A NPC with this name already exist");
} else {
@ -25,13 +25,13 @@ public class NPCDataManager {
newDocument.put("world", world);
newDocument.put("texture", texture);
newDocument.put("signature", signature);
DatabaseManager.getNPCsDB().insertOne(newDocument);
new DatabaseManager().getNPCsDB().insertOne(newDocument);
}
}
public static void reloadNPC() {
List<HashMap<String, Object>> npcList = new ArrayList<>();
try (MongoCursor<Document> cursor = DatabaseManager.getNPCsDB().find().cursor()) {
try (MongoCursor<Document> cursor = new DatabaseManager().getNPCsDB().find().cursor()) {
while (cursor.hasNext()) {
Document document = cursor.next();
HashMap<String, Object> npc = new HashMap<>();

View file

@ -2,6 +2,7 @@ package me.night.nullvalkyrie.database;
import com.mongodb.client.MongoCursor;
import me.night.nullvalkyrie.enums.Rank;
import me.night.nullvalkyrie.ui.player.ScoreboardListener;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bukkit.Bukkit;
@ -9,31 +10,29 @@ import org.bukkit.entity.Player;
import java.util.UUID;
import static me.night.nullvalkyrie.ui.player.ScoreboardListener.nameTagManager;
public class RankDataManager {
public static void setRank(UUID uuid, Rank rank) {
Document document = DatabaseManager.getRanksDB().find(new Document("UUID", uuid.toString())).first();
public static void setRank(UUID uuid, Rank rank, ScoreboardListener... listener) {
Document document = new DatabaseManager().getRanksDB().find(new Document("UUID", uuid.toString())).first();
if (document != null) {
Bson updated = new Document("Rank", rank.name());
Bson update = new Document("$set", updated);
DatabaseManager.getRanksDB().updateOne(document, update);
new DatabaseManager().getRanksDB().updateOne(document, update);
} else {
Document newDocument = new Document();
newDocument.put("UUID", uuid.toString());
newDocument.put("Rank", rank.name());
DatabaseManager.getRanksDB().insertOne(newDocument);
new DatabaseManager().getRanksDB().insertOne(newDocument);
}
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.hasPlayedBefore()) {
nameTagManager.removeTag(player);
nameTagManager.newTag(player);
listener[0].nameTagManager.removeTag(player);
listener[0].nameTagManager.newTag(player);
}
}
}
public static Rank getRank(UUID uuid) {
try (MongoCursor<Document> cursor = DatabaseManager.getRanksDB().find(new Document("UUID", uuid.toString())).cursor()) {
try (MongoCursor<Document> cursor = new DatabaseManager().getRanksDB().find(new Document("UUID", uuid.toString())).cursor()) {
while (cursor.hasNext()) {
Document doc = cursor.next();
for (String key : doc.keySet()) {

View file

@ -8,7 +8,7 @@ import java.util.HashMap;
public class ShopDataManager {
public static HashMap<String, Integer> getItems() {
HashMap<String, Integer> list = new HashMap<>();
try (MongoCursor<Document> cursor = DatabaseManager.getShopsDB().find().cursor()) {
try (MongoCursor<Document> cursor = new DatabaseManager().getShopsDB().find().cursor()) {
while (cursor.hasNext()) {
Document doc = cursor.next();
list.put(doc.getString("Name"), doc.getInteger("Price"));

View file

@ -7,34 +7,34 @@ import org.bson.conversions.Bson;
import java.util.HashMap;
public class UserDataManager {
public static void createUserBank(String uuid) {
public void createUserBank(String uuid) {
Document document = new Document();
document.put("UUID", uuid);
document.put("Bank", 0);
DatabaseManager.getUsersDB().insertOne(document);
new DatabaseManager().getUsersDB().insertOne(document);
}
public static void updateUserBank(String uuid, Integer coins) {
Document document = DatabaseManager.getUsersDB().find(new Document("UUID", uuid)).first();
public void updateUserBank(String uuid, Integer coins, ScoreboardListener... listener) {
Document document = new DatabaseManager().getUsersDB().find(new Document("UUID", uuid)).first();
if (document != null) {
Integer coinsBefore = document.getInteger("Bank");
Bson updated = new Document("Bank", coins + coinsBefore);
Bson update = new Document("$set", updated);
DatabaseManager.getUsersDB().updateOne(document, update);
ScoreboardListener.sideBarManager.addBank(uuid, coins);
new DatabaseManager().getUsersDB().updateOne(document, update);
listener[0].sideBarManager.addBank(uuid, coins);
} else {
Document doc = new Document();
doc.put("UUID", uuid);
doc.put("Bank", coins);
DatabaseManager.getUsersDB().insertOne(doc);
ScoreboardListener.sideBarManager.addBank(uuid, coins);
new DatabaseManager().getUsersDB().insertOne(doc);
listener[0].sideBarManager.addBank(uuid, coins);
}
}
public static HashMap<String, Object> getUser(String uuid) {
Document document = DatabaseManager.getUsersDB().find(new Document("UUID", uuid)).first();
public HashMap<String, Object> getUser(String uuid) {
Document document = new DatabaseManager().getUsersDB().find(new Document("UUID", uuid)).first();
if (document != null) {
HashMap<String, Object> map = new HashMap<>();
for (String key : document.keySet()) map.put(key, document.get(key));

View file

@ -1,6 +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;
@ -15,10 +14,11 @@ public class DiscordClientManager {
}
public void register() {
JDABuilder builder = JDABuilder.createDefault(Main.env.get("DISCORD_TOKEN"));
JDABuilder builder = JDABuilder.createDefault(System.getenv("DISCORD_TOKEN"));
builder.setActivity(Activity.streaming("cath.exe", "https://www.youtube.com/watch?v=YSKDu1gKntY"));
try {
JDA jda = builder.build();
System.out.println(jda.getSelfUser().getName());
} catch (LoginException e) {
e.printStackTrace();
}

View file

@ -1,6 +1,7 @@
package me.night.nullvalkyrie.entities.items;
import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.database.CustomWeaponsDataManager;
import me.night.nullvalkyrie.enums.Rarity;
import me.night.nullvalkyrie.util.Util;
import org.bukkit.Bukkit;
@ -15,23 +16,21 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import java.io.File;
import java.util.*;
import static me.night.nullvalkyrie.database.CustomWeaponsDataManager.getWeapon;
public class CustomItemManager {
public static final HashMap<String, NamespacedKey> keys = new HashMap<>();
@SuppressWarnings("unchecked")
public static ItemStack produceItem(String itemName) {
HashMap<String, Object> weapon = getWeapon(itemName);
HashMap<String, Object> weapon = new CustomWeaponsDataManager().getWeapon(itemName);
ItemStack item = new ItemStack((Material) weapon.get("Material"));
List<String> propertiesList = new ArrayList<>();
List<String> itemAbility = new ArrayList<>();
HashMap<String, Object> enchants = (HashMap<String, Object>) weapon.get("Enchants");
HashMap<String, Object> attributes = (HashMap<String, Object>) weapon.get("Attributes");
for (String enchant : enchants.keySet())
item.addUnsafeEnchantment(Enchantment.getByKey(NamespacedKey.minecraft(enchant)), (Integer) enchants.get(enchant));
item.addUnsafeEnchantment(Objects.requireNonNull(Enchantment.getByKey(NamespacedKey.minecraft(enchant))), (Integer) enchants.get(enchant));
HashMap<String, Object> lore = (HashMap<String, Object>) weapon.get("Lore");
HashMap<String, Object> ability = (HashMap<String, Object>) lore.get("Ability");
HashMap<String, Object> properties = (HashMap<String, Object>) lore.get("Properties");
@ -113,10 +112,4 @@ public class CustomItemManager {
if (Bukkit.getRecipe(nsk) != null) Bukkit.removeRecipe(nsk);
Bukkit.addRecipe(recipe);
}
public static void updateYamlFilesToPlugin(String path) {
File file = new File(Main.getPlugin(Main.class).getDataFolder(), path);
if (!file.exists()) Main.getPlugin(Main.class).saveResource(path, true);
else Main.getPlugin(Main.class).saveResource(path, true);
}
}

View file

@ -1,6 +1,7 @@
package me.night.nullvalkyrie.ui.player;
import me.night.nullvalkyrie.database.RankDataManager;
import me.night.nullvalkyrie.database.UserDataManager;
import me.night.nullvalkyrie.enums.Rank;
import me.night.nullvalkyrie.entities.npcs.NPCManager;
import org.bukkit.Bukkit;
@ -12,12 +13,11 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import static me.night.nullvalkyrie.database.UserDataManager.createUserBank;
@SuppressWarnings("ConstantConditions")
public class ScoreboardListener implements Listener {
public static NameTagManager nameTagManager;
public static SideBarManager sideBarManager;
public NameTagManager nameTagManager;
public SideBarManager sideBarManager;
private final BelowNameManager belowNameManager;
public ScoreboardListener() {
@ -31,8 +31,8 @@ public class ScoreboardListener implements Listener {
Player player = e.getPlayer();
if (!player.hasPlayedBefore()) {
e.getPlayer().sendTitle(ChatColor.RED + "Welcome to Vanadium!", ChatColor.GREEN + "LOL", 20, 100, 20);
RankDataManager.setRank(player.getUniqueId(), Rank.ROOKIE);
createUserBank(e.getPlayer().getUniqueId().toString());
RankDataManager.setRank(player.getUniqueId(), Rank.ROOKIE, this);
new UserDataManager().createUserBank(e.getPlayer().getUniqueId().toString());
}
e.getPlayer().setPlayerListHeaderFooter(ChatColor.AQUA + "You are playing on " + ChatColor.GREEN + "127.0.0.1", ChatColor.GOLD + "Ranks, boosters, & more!" + ChatColor.AQUA + "127.0.0.1");
nameTagManager.setNametags(player);

View file

@ -10,6 +10,7 @@ import org.bukkit.scoreboard.*;
import java.util.UUID;
@SuppressWarnings("ConstantConditions")
public class SideBarManager {
private int taskID;
public AnimatedSideBar board = null;
@ -42,7 +43,7 @@ public class SideBarManager {
else bankTeam = board.registerNewTeam("Bank");
bankTeam.addEntry(ChatColor.BOLD.toString());
bankTeam.setPrefix(ChatColor.BLUE + "Bank: ");
bankTeam.setSuffix(ChatColor.YELLOW + UserDataManager.getUser(player.getUniqueId().toString()).get("Bank").toString());
bankTeam.setSuffix(ChatColor.YELLOW + new UserDataManager().getUser(player.getUniqueId().toString()).get("Bank").toString());
obj.getScore(ChatColor.BOLD.toString()).setScore(3);
player.setScoreboard(board);
}
@ -91,6 +92,6 @@ public class SideBarManager {
public void addBank(String uuid, Integer amount) {
UUID uid = UUID.fromString(uuid);
Bukkit.getPlayer(uid).getScoreboard().getTeam("Bank").setSuffix(ChatColor.YELLOW.toString() + UserDataManager.getUser(uuid).get("Bank") + ChatColor.WHITE + "+(" + amount + ")");
Bukkit.getPlayer(uid).getScoreboard().getTeam("Bank").setSuffix(ChatColor.YELLOW.toString() + new UserDataManager().getUser(uuid).get("Bank") + ChatColor.WHITE + "+(" + amount + ")");
}
}

View file

@ -1,9 +0,0 @@
package me.night.nullvalkyrie.util;
import static me.night.nullvalkyrie.entities.items.CustomItemManager.updateYamlFilesToPlugin;
public class FileManager {
public FileManager() {
updateYamlFilesToPlugin(".env");
}
}

View file

@ -9,7 +9,8 @@ import java.util.Arrays;
import java.util.List;
public class EnchantmentManager {
public static List<Enchantment> enchants = new ArrayList<>();
public static final List<Enchantment> enchants = new ArrayList<>();
public static void register() {
List<Boolean> registeredList = new ArrayList<>();
for (Enchantments enchantment : Enchantments.values()) {