diff --git a/src/main/java/me/night/nullvalkyrie/commands/CommandManager.java b/src/main/java/me/night/nullvalkyrie/commands/CommandManager.java index 04e6415..b2d7200 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/CommandManager.java +++ b/src/main/java/me/night/nullvalkyrie/commands/CommandManager.java @@ -17,10 +17,10 @@ public class CommandManager { new HologramCommand(); new CraftCommand(); new EnchantingCommand(); + new WeaponCommand(); new BetaCommand(main); new RankCommand(main); new UtilCommand(main); - new WeaponCommand(main); new MinerCommand(main); } } diff --git a/src/main/java/me/night/nullvalkyrie/commands/WeaponCommand.java b/src/main/java/me/night/nullvalkyrie/commands/WeaponCommand.java index 15d7785..6fb64b6 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/WeaponCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/WeaponCommand.java @@ -22,18 +22,18 @@ public class WeaponCommand extends Command { public void onCommand(CommandSender sender, String[] args) { Player player = (Player) sender; StringBuilder s = new StringBuilder(); - List b = Arrays.asList(args); - for (String a : args) { - if (a.equals(b.get(b.size() - 1))) { - s.append(a); - } else { - s.append(a); - s.append(" "); - } - } - if (s.isEmpty()) { + if (args.length == 0) { player.sendMessage(ChatColor.RED + "This item doesn't exist"); } else { + List b = Arrays.asList(args); + for (String a : args) { + if (a.equals(b.get(b.size() - 1))) { + s.append(a); + } else { + s.append(a); + s.append(" "); + } + } ItemStack item = CustomItemManager.getItem(s.toString()); if (item.hasItemMeta()) { player.getInventory().addItem(item); diff --git a/src/main/java/me/night/nullvalkyrie/database/Client.java b/src/main/java/me/night/nullvalkyrie/database/Client.java index 389902a..e9f5165 100644 --- a/src/main/java/me/night/nullvalkyrie/database/Client.java +++ b/src/main/java/me/night/nullvalkyrie/database/Client.java @@ -6,6 +6,8 @@ import com.mongodb.client.model.Filters; import org.bson.Document; import org.bson.conversions.Bson; +import java.util.HashMap; + public class Client { private MongoClient client; private static MongoCollection users; @@ -37,16 +39,19 @@ public class Client { } } - public static void getUser(String username) { + public static HashMap getUser(String username) { try (MongoCursor cursor = users.find(Filters.eq("Username", username)).cursor()) { - while (cursor.hasNext()) { - Document doc = (Document) cursor.next(); - for(String a : doc.keySet()) { - if(!a.equals("_id")) { -// System.out.println(a + ": " + doc.get(a)); - } - } - } + while (cursor.hasNext()) { + Document doc = cursor.next(); + for (String a : doc.keySet()) { + if (!a.equals("_id")) { + HashMap details = new HashMap<>(); + details.put(a, doc.get(a)); + return details; + } + } + } } + return null; } } diff --git a/src/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java b/src/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java index 0550b52..2396470 100644 --- a/src/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java +++ b/src/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java @@ -108,11 +108,11 @@ public class CustomItemEvents implements Listener { ItemStack weapon = player.getInventory().getItemInMainHand(); ItemMeta weaponMeta = weapon.getItemMeta(); PersistentDataContainer container = weaponMeta.getPersistentDataContainer(); - System.out.println(name); if(container != null) { - int ammo = container.get(CustomItemManager.keys.get("Snow Gun" + "." + "ammo"), PersistentDataType.INTEGER); - container.set(CustomItemManager.keys.get("Snow Gun" + "." + "ammo"), PersistentDataType.INTEGER, ammo - 1); - int maxload = container.get(CustomItemManager.keys.get("Snow Gun" + "." + "maxload"), PersistentDataType.INTEGER); + NamespacedKey ammocount = CustomItemManager.keys.get("Snow Gun.ammo"); + int ammo = container.get(ammocount, PersistentDataType.INTEGER); + container.set(ammocount, PersistentDataType.INTEGER, ammo - 1); + int maxload = container.get(CustomItemManager.keys.get("Snow Gun.maxload"), PersistentDataType.INTEGER); weapon.setItemMeta(weaponMeta); e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', "&6AK-47 ( " + (ammo - 1) + "/ " + maxload + " )")));