changing money amount in ssscoreboard

This commit is contained in:
NK 2022-12-03 14:02:36 +00:00
parent 95db3dc0e3
commit d4d4ef75e0
5 changed files with 37 additions and 37 deletions

View file

@ -1,5 +1,6 @@
package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.database.UserDataManager;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -14,6 +15,7 @@ public class BetaCommand extends Command {
@Override
public void onCommand(CommandSender sender, String[] args) {
if (sender instanceof Player player) {
UserDataManager.updateUserBank(player.getUniqueId().toString(), 10);
}
}

View file

@ -1,38 +1,45 @@
package me.night.nullvalkyrie.database;
import com.mongodb.client.MongoCursor;
import com.mongodb.client.model.Filters;
import me.night.nullvalkyrie.ui.ScoreboardListener;
import org.bson.Document;
import org.bson.conversions.Bson;
import java.util.HashMap;
public class UserDataManager {
public static void createUserSchema(String uuid) {
public static void createUserBank(String uuid) {
Document document = new Document();
document.put("UUID", uuid);
document.put("Bank", 0);
DatabaseManager.getUsersDB().insertOne(document);
}
public void updateUserBank(String uuid, Number coins) {
public static void updateUserBank(String uuid, Integer coins) {
Document document = DatabaseManager.getUsersDB().find(new Document("UUID", uuid)).first();
if (document != null) {
Bson updated = new Document("Bank", coins);
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);
} else {
Document doc = new Document();
doc.put("UUID", uuid);
doc.put("Bank", coins);
DatabaseManager.getUsersDB().insertOne(doc);
ScoreboardListener.sideBarManager.addBank(uuid);
}
}
public static HashMap<String, Object> getUser(String uuid) {
try (MongoCursor<Document> cursor = DatabaseManager.getUsersDB().find(Filters.eq("UUID", uuid)).cursor()) {
while (cursor.hasNext()) {
Document doc = cursor.next();
HashMap<String, Object> map = new HashMap<>();
for (String key : doc.keySet()) map.put(key, doc.get(key));
map.remove("_id");
return map;
}
Document document = 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));
map.remove("_id");
return map;
}
return null;
}

View file

@ -15,7 +15,7 @@ public class NPCEvents implements Listener {
@EventHandler
public void onClick(RightClickNPC e) {
Player player = e.getPlayer();
if (e.getNPC().getBukkitEntity().getName().equalsIgnoreCase(Util.color("&a&lNK"))) {
if (e.getNPC().getBukkitEntity().getName().equalsIgnoreCase(Util.color("&1&lRB18"))) {
player.sendMessage(Util.color("Hi"));
}
}

View file

@ -8,17 +8,16 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
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.createUserSchema;
import static me.night.nullvalkyrie.database.UserDataManager.createUserBank;
public class ScoreboardListener implements Listener {
public static NameTagManager nameTagManager;
private final SideBarManager sideBarManager;
public static SideBarManager sideBarManager;
private final BelowNameManager belowNameManager;
public ScoreboardListener(Main main) {
@ -33,7 +32,7 @@ public class ScoreboardListener implements Listener {
if (!player.hasPlayedBefore()) {
e.getPlayer().sendTitle(ChatColor.RED + "Welcome to Vanadium!", ChatColor.GREEN + "LOL", 20, 100, 20);
RankDataManager.setRank(player.getUniqueId(), Rank.ROOKIE);
createUserSchema(e.getPlayer().getUniqueId().toString());
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);
@ -63,10 +62,4 @@ public class ScoreboardListener implements Listener {
Player player = e.getPlayer();
Bukkit.broadcastMessage(RankDataManager.getRank(player.getUniqueId()).getDisplay() + " " + player.getName() + ChatColor.WHITE + ": " + e.getMessage());
}
//Death changing in sidebar
@EventHandler
public void onDeath(PlayerDeathEvent e) {
if (e.getEntity().getPlayer() == null) sideBarManager.changeOnDeath(e.getEntity().getPlayer());
}
}

View file

@ -1,6 +1,7 @@
package me.night.nullvalkyrie.ui;
import me.night.nullvalkyrie.Main;
import me.night.nullvalkyrie.database.UserDataManager;
import me.night.nullvalkyrie.util.Util;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -8,11 +9,9 @@ import org.bukkit.entity.Player;
import org.bukkit.scoreboard.*;
import org.bukkit.scoreboard.Scoreboard;
import java.util.HashMap;
import java.util.UUID;
public class SideBarManager {
private final HashMap<UUID, Integer> deaths = new HashMap<>();
private int taskID;
private final Main main;
public AnimatedSideBar board = null;
@ -44,15 +43,14 @@ public class SideBarManager {
space2.setScore(2);
Score website = obj.getScore(ChatColor.YELLOW + "cath.js.org");
website.setScore(1);
Team playersOnline;
if (board.getTeam("deathsTotal") != null) playersOnline = board.getTeam("deathsTotal");
else playersOnline = board.registerNewTeam("deathsTotal");
playersOnline.addEntry(ChatColor.BOLD.toString());
playersOnline.setPrefix(ChatColor.BLUE + "Deaths: ");
playersOnline.setSuffix(ChatColor.YELLOW + "0");
Team bankTeam;
if (board.getTeam("Bank") != null) bankTeam = board.getTeam("Bank");
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());
obj.getScore(ChatColor.BOLD.toString()).setScore(3);
player.setScoreboard(board);
deaths.put(player.getUniqueId(), 0);
}
public void start(Player player) {
@ -97,9 +95,9 @@ public class SideBarManager {
}, 0, 10);
}
public void changeOnDeath(Player player) {
int amount = deaths.get(player.getUniqueId());
deaths.put(player.getUniqueId(), amount++);
player.getScoreboard().getTeam("deathsTotal").setSuffix(ChatColor.YELLOW.toString() + amount);
public void addBank(String uuid) {
UUID uid = UUID.fromString(uuid);
Bukkit.getPlayer(uid).getScoreboard().getTeam("Bank").setSuffix(ChatColor.YELLOW.toString() + UserDataManager.getUser(uuid).get("Bank"));
}
}