This commit is contained in:
NK 2022-11-15 19:38:19 +00:00
parent c3af2d9311
commit b761af24ce
4 changed files with 29 additions and 24 deletions

View file

@ -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);
}
}

View file

@ -22,6 +22,9 @@ public class WeaponCommand extends Command {
public void onCommand(CommandSender sender, String[] args) {
Player player = (Player) sender;
StringBuilder s = new StringBuilder();
if (args.length == 0) {
player.sendMessage(ChatColor.RED + "This item doesn't exist");
} else {
List<String> b = Arrays.asList(args);
for (String a : args) {
if (a.equals(b.get(b.size() - 1))) {
@ -31,9 +34,6 @@ public class WeaponCommand extends Command {
s.append(" ");
}
}
if (s.isEmpty()) {
player.sendMessage(ChatColor.RED + "This item doesn't exist");
} else {
ItemStack item = CustomItemManager.getItem(s.toString());
if (item.hasItemMeta()) {
player.getInventory().addItem(item);

View file

@ -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<Document> users;
@ -37,16 +39,19 @@ public class Client {
}
}
public static void getUser(String username) {
public static HashMap<String, Object> getUser(String username) {
try (MongoCursor<Document> 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));
Document doc = cursor.next();
for (String a : doc.keySet()) {
if (!a.equals("_id")) {
HashMap<String, Object> details = new HashMap<>();
details.put(a, doc.get(a));
return details;
}
}
}
}
return null;
}
}

View file

@ -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 + " )")));