Compare commits

...

10 Commits

Author SHA1 Message Date
nearfe 86579763ae LB MT FODA 2024-06-19 22:07:33 -03:00
nearfe e69d767b40 sla 2024-06-19 16:28:28 -03:00
nearfe de85d51556 lb bonita 2024-06-19 15:37:22 -03:00
nearfe 9fd1d5c274 Revert "driver"
This reverts commit 8482451eef.
2024-06-19 14:55:13 -03:00
nearfe 8482451eef driver 2024-06-19 14:25:02 -03:00
nearfe 85bbd29a89 updated java driver 2024-06-18 17:54:00 -03:00
nearfe f532124b92 seu merda 2024-06-18 13:16:51 -03:00
nearfe 710dc7f1d0 BEDFIGHTTTTTTTT 2024-06-17 21:18:58 -03:00
nearfe a8fdd72217 BEDFIGHTTTTTTTT 2024-06-17 21:13:22 -03:00
nearfe 820d418eac q q e pa fala 2024-06-17 19:38:17 -03:00
14 changed files with 396 additions and 36 deletions

View File

@ -109,8 +109,9 @@
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.12.9</version>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.11</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.citizne</groupId>

View File

@ -29,7 +29,6 @@ public class Arena {
private AsyncLocation min;
private AsyncLocation max;
private boolean enabled = false;
private Flag flag = Flag.DEFAULT;

View File

@ -27,7 +27,7 @@ public class NoneDeathEffect implements DeathEffect {
@Override
public Material getIcon() {
return Material.REDSTONE;
return Material.SKULL_ITEM;
}
@Override

View File

@ -31,6 +31,8 @@ public class Kit {
private Flag flag = Flag.DEFAULT;
public void applyToPlayer(Player player) {
player.getInventory().setContents(this.contents);
player.getInventory().setArmorContents(this.armor);

View File

@ -1,9 +1,11 @@
package land.battle.practice.listeners;
import com.google.common.collect.Sets;
import com.solexgames.core.listener.custom.PlayerFreezeEvent;
import com.solexgames.core.menu.impl.player.PlayerInfoMenu;
import com.solexgames.core.util.Color;
import com.solexgames.core.util.clickable.Clickable;
import io.netty.util.internal.ConcurrentSet;
import land.battle.practice.Practice;
import land.battle.practice.arena.type.StandaloneArena;
import land.battle.practice.event.match.MatchEndEvent;
@ -24,7 +26,11 @@ import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.HoverEvent;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -43,6 +49,7 @@ public class MatchListener implements Listener {
private final Practice plugin = Practice.getInstance();
private int counter = 0;
@EventHandler
public void onFreeze(PlayerFreezeEvent event) {
final Player player = event.getPlayer();
@ -95,6 +102,22 @@ public class MatchListener implements Listener {
}
}
public boolean isBreakable(Player player, Block block) {
final Match match = this.plugin.getMatchManager().getMatch(player.getUniqueId());
final Set<Location> placedBlocksLocations = new ConcurrentSet<>();
if (placedBlocksLocations.contains(block.getLocation())) {
return true;
}
Material material = block.getType();
if (material == Material.ENDER_STONE) {
return match.getKit().getFlag().equals(Flag.BEDWARS);
}
return false;
}
@EventHandler
public void onEntitySpawn(EntitySpawnEvent event) {
if (event.getEntityType().equals(EntityType.ARMOR_STAND)) {
@ -128,6 +151,13 @@ public class MatchListener implements Listener {
@EventHandler
public void onEntityDamage(EntityDamageByEntityEvent event) {
Player killer = (Player) event.getDamager();
Match match = this.plugin.getMatchManager().getMatch(killer.getUniqueId());
if (match.getKit().getFlag().equals(Flag.BEDWARS)) {
if (killer == null) {
return;
}
if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
Player defender = (Player) event.getEntity();
@ -151,7 +181,7 @@ public class MatchListener implements Listener {
}
}
}
}
@EventHandler
public void onMatchStart(MatchStartEvent event) {

View File

@ -1,20 +1,26 @@
package land.battle.practice.listeners;
import land.battle.practice.Practice;
import land.battle.practice.event.match.MatchEndEvent;
import land.battle.practice.flags.Flag;
import land.battle.practice.match.Match;
import land.battle.practice.match.MatchState;
import land.battle.practice.match.custom.CustomMatchRespawnRunnable;
import land.battle.practice.match.team.impl.MatchTeam;
import land.battle.practice.player.PlayerData;
import land.battle.practice.player.PlayerState;
import land.battle.practice.util.BlockUtil;
import io.papermc.lib.PaperLib;
import land.battle.practice.util.cuboid.Cuboid;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.potion.PotionEffectType;
/**
* @author BattleLand Team
@ -55,6 +61,38 @@ public class MovementListener implements Listener {
this.plugin.getMatchManager().removeFighter(startingOpponent, playerData, false);
}
}
if (match.getKit().getFlag().equals(Flag.BEDWARS)) {
MatchTeam playerTeam = match.getTeams().get(playerData.getTeamID());
if (player.getLocation().getY() <= 50
&& !player.hasPotionEffect(PotionEffectType.WEAKNESS)
&& match.getMatchState() != MatchState.ENDING) {
if (playerTeam.isHasBed()) {
match.broadcast(
(playerTeam.getTeamID() == 1 ? "&9" : "&c") + player.getName() + " &7has died.", Sound.ORB_PICKUP);
new CustomMatchRespawnRunnable(player, playerData, match, playerTeam, 4,
4).runTaskTimer(plugin, 0L, 20L);
} else if (match.isPartyMatch()) {
if (!playerTeam.isHasBed()) {
this.plugin.getMatchManager().removeFighter(player, playerData, false);
}
} else if (match.getMatchState() == MatchState.ENDING) {
this.plugin.getPlayerManager().sendToSpawnAndReset(player);
} else {
match.setCanContinue(false);
if (!match.isCanContinue() && !match.getMatchState().equals(MatchState.ENDING)) {
MatchTeam opposingTeam = match.isFFA() ? match.getTeams().get(0)
: ((playerData.getTeamID() == 0) ? match.getTeams().get(1)
: match.getTeams().get(0));
Bukkit.getPluginManager()
.callEvent(new MatchEndEvent(match, opposingTeam, playerTeam));
player.teleport(playerTeam.getTeamID() == 1 ? match.getStandaloneArena().getPositionOne()
.toBukkitLocation() : match.getStandaloneArena().getPositionTwo().toBukkitLocation());
match.broadcast("", Sound.FIREWORK_LAUNCH);
match.broadcast("", Sound.FIREWORK_TWINKLE2);
}
}
}
}
if (match.getKit().getFlag().equals(Flag.SPLEEF) || match.getKit().getFlag().equals(Flag.SUMO)) {
final Location location = player.getLocation();

View File

@ -5,11 +5,13 @@ import land.battle.practice.arena.type.StandaloneArena;
import land.battle.practice.flags.Flag;
import land.battle.practice.match.Match;
import land.battle.practice.match.MatchState;
import land.battle.practice.match.team.impl.MatchTeam;
import land.battle.practice.player.PlayerData;
import land.battle.practice.player.PlayerState;
import land.battle.practice.runnable.BlockRemoveRunnable;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
@ -33,13 +35,40 @@ public class WorldListener implements Listener {
public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
PlayerData playerData = this.plugin.getPlayerManager().getPlayerData(player.getUniqueId());
MatchListener matchListener = new MatchListener(); // Example initialization
if (playerData == null) {
this.plugin.getLogger().warning(player.getName() + "'s player data is null");
event.setCancelled(true);
return;
}
if (event.getBlock().getType() == Material.BED_BLOCK) {
Match match = this.plugin.getMatchManager().getMatch(player.getUniqueId());
MatchTeam playerTeam = match.getTeams().get(playerData.getTeamID());
MatchTeam opposingTeam = match.isFFA() ? match.getTeams().get(0)
: ((playerData.getTeamID() == 0) ? match.getTeams().get(1)
: match.getTeams().get(0));
if ((playerTeam.getTeamID() == 1 ? match.getStandaloneArena().getPositionOne().toBukkitLocation()
: match.getStandaloneArena().getPositionTwo().toBukkitLocation()).distance(
event.getBlock().getLocation()) > 20.0) {
if (match.getKit().getFlag().equals(Flag.BEDWARS)) {
if (playerTeam.getPlayers().contains(player.getUniqueId()) && (!match.getMatchState().equals(MatchState.ENDING))
&& opposingTeam.isHasBed()) {
opposingTeam.destroyBed();
match.broadcast(playerTeam.getTeamID() == 1 ? "&9"
: "&c" + player.getName() + " &7destroyed the bed of " + (
playerTeam.getTeamID() == 1 ? "&cRed" : "&9Blue") + "&7!");
match.broadcast(
playerTeam.getTeamID() == 1 ? "&cRed's" : "&9Blue's" + " destroyed",
"&7By " + (playerTeam.getTeamID() == 1 ? "&9" : "&c") + player.getName());
match.broadcast("", Sound.ENDERDRAGON_GROWL);
return;
}
}
}
}
if (playerData.getPlayerState() == PlayerState.FIGHTING) {
Match match = this.plugin.getMatchManager().getMatch(player.getUniqueId());

View File

@ -6,6 +6,7 @@ import com.solexgames.core.util.clickable.Clickable;
import land.battle.practice.Practice;
import land.battle.practice.arena.Arena;
import land.battle.practice.arena.type.StandaloneArena;
import land.battle.practice.flags.Flag;
import land.battle.practice.kit.Kit;
import land.battle.practice.match.snapshot.InventorySnapshot;
import land.battle.practice.match.team.impl.MatchTeam;
@ -17,7 +18,9 @@ import net.md_5.bungee.api.chat.BaseComponent;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -37,6 +40,7 @@ public class Match {
private final UUID matchId = UUID.randomUUID();
private final String shortMatchId = SaltUtil.getRandomSaltedString(7);
private boolean canContinue = true;
private final Set<Entity> entitiesToRemove = new HashSet<>();
@ -50,6 +54,9 @@ public class Match {
private final List<MatchTeam> teams;
private final Set<Location> placedBlocksLocations = new ConcurrentSet<>();
private final QueueType type;
private final Arena arena;
private final Kit kit;

View File

@ -0,0 +1,106 @@
package land.battle.practice.match.custom;
import land.battle.practice.Practice;
import land.battle.practice.match.Match;
import land.battle.practice.match.team.impl.MatchTeam;
import land.battle.practice.player.PlayerData;
import land.battle.practice.player.PlayerState;
import land.battle.practice.util.CC;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import static com.cryptomorin.xseries.messages.Titles.sendTitle;
public class CustomMatchRespawnRunnable extends BukkitRunnable {
private final Practice plugin = Practice.getInstance();
private final Player player;
private final PlayerData practicePlayerData;
private final Match match;
private final MatchTeam playerTeam;
private final PotionEffect weakness = new PotionEffect(PotionEffectType.WEAKNESS,
Integer.MAX_VALUE, 0);
private final int startingTime;
private int respawnTime;
public CustomMatchRespawnRunnable(Player player, PlayerData practicePlayerData,
Match match, MatchTeam playerTeam, int startingTime, int respawnTime) {
this.player = player;
this.practicePlayerData = practicePlayerData;
this.match = match;
this.playerTeam = playerTeam;
this.startingTime = startingTime;
this.respawnTime = respawnTime;
}
@Override
public void run() {
final PlayerData playerData = this.plugin.getPlayerManager().getPlayerData(player.getUniqueId());
if (playerData.getPlayerState() == PlayerState.FIGHTING) {
cancel();
return;
}
if (respawnTime <= 1) {
player.removePotionEffect(PotionEffectType.WEAKNESS);
player.teleport(
playerTeam.getTeamID() == 1 ? match.getStandaloneArena().getPositionOne().toBukkitLocation()
: match.getStandaloneArena().getPositionTwo().toBukkitLocation());
player.setFallDistance(50);
player.setAllowFlight(false);
player.setFlying(false);
sendTitle(player, "&aRespawning...", "");
player.sendMessage(CC.translate("&aYou have respawned!"));
player.playSound(player.getLocation(), Sound.ORB_PICKUP, 10, 1);
player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 20, 0));
match.getTeams().forEach(
team -> team.getAlivePlayers().stream().filter(player1 -> !player.equals(player1)).forEach(
matchplayer -> player.sendMessage(CC.translate(playerTeam.getTeamID() == 1 ? "&9"
: "&c" + player.getName() + "&a has respawned!"))));
player.resetMaxHealth();
player.setHealth(player.getMaxHealth());
player.setFoodLevel(20);
match.getKit().applyToPlayer(player);
cancel();
return;
}
if (respawnTime == startingTime) {
player.addPotionEffect(weakness);
player.getInventory().clear();
player.updateInventory();
player.setHealth(player.getMaxHealth());
player.setFoodLevel(20);
player.setVelocity(player.getVelocity().add(new Vector(0, 0.25, 0)));
player.setAllowFlight(true);
player.setFlying(true);
player.setVelocity(player.getVelocity().add(new Vector(0, 0.15, 0)));
player.setAllowFlight(true);
player.setFlying(true);
}
respawnTime--;
sendTitle(player, "&a" + respawnTime, "");
player.playSound(player.getLocation(), Sound.NOTE_PLING, 0.7f, 1.0f);
}
}

View File

@ -2,6 +2,8 @@ package land.battle.practice.match.team.impl;
import land.battle.practice.match.team.KillableTeam;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import java.util.List;
import java.util.UUID;
@ -10,6 +12,14 @@ import java.util.UUID;
public class MatchTeam extends KillableTeam {
private final int teamID;
private boolean hasBed = true;
@Setter
private int lives;
public void destroyBed() {
this.hasBed = false;
}
public MatchTeam(UUID leader, List<UUID> players, int teamID) {
super(leader, players);

View File

@ -37,6 +37,7 @@ public class PlayerData {
private final Map<String, Integer> highestKillStreaks = new HashMap<>();
private final Map<String, Integer> kitKillStreaks = new HashMap<>();
private final Map<String, Boolean> rankedDivisionBooleanMap = new HashMap<>();
private final List<String> matchIds = new ArrayList<>();
@ -106,6 +107,7 @@ public class PlayerData {
}
}
public Player getBukkitPlayer() {
return Bukkit.getPlayer(this.uniqueId);
}

View File

@ -16,10 +16,10 @@ import land.battle.practice.util.CC;
import land.battle.practice.util.division.RankedDivision;
import org.bson.Document;
import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@ -27,11 +27,9 @@ import java.util.stream.IntStream;
* @author BattleLand Team
* @since 7/29/2021
*/
public class LeaderboardUpdateRunnable implements Runnable {
public static final List<String> GLOBAL_ELO_LEADERBOARD_LORE = new ArrayList<>();
public static final Map<Kit, List<String>> KIT_SPECIFIC_LEADERBOARD_LORE = new HashMap<>();
public static final Map<Kit, List<String>> KIT_SPECIFIC_LEADERBOARD_LORE_SHORT = new HashMap<>();
public static final Map<Kit, List<String>> KIT_SPECIFIC_WIN_STREAK_LORE = new HashMap<>();
@ -39,12 +37,15 @@ public class LeaderboardUpdateRunnable implements Runnable {
@Override
public void run() {
DecimalFormat decimalFormat = new DecimalFormat("#,###");
CompletableFuture.runAsync(() -> {
Practice.getInstance().getKitManager().getKits().stream().filter(Kit::isRanked).forEach(kit -> {
final Map<UUID, Integer> allEloMap = new HashMap<>();
final Map<UUID, Integer> allKillStreaksMap = new HashMap<>();
final List<String> lore = new ArrayList<>();
final List<String> loreShort = new ArrayList<>();
MongoManager.getInstance().getPlayers().find().forEach((Block<? super Document>) document -> {
final Map<String, Integer> eloMap = CorePlugin.GSON.fromJson(document.getString("elo"), PracticeConstants.STRING_INTEGER_MAP_TYPE);
@ -64,7 +65,6 @@ public class LeaderboardUpdateRunnable implements Runnable {
}
allKillStreaksMap.put(playerUuid, value);
}
});
final List<UUID> sortedUuids = new HashSet<>(allEloMap.keySet()).stream()
@ -73,24 +73,58 @@ public class LeaderboardUpdateRunnable implements Runnable {
final AtomicInteger integer = new AtomicInteger();
final List<String> loreEloShort = new ArrayList<>();
sortedUuids.forEach(uuid -> {
if (integer.get() != 10) {
if (integer.get() < 3) { // primeiro, segundo e terceiro lugar
final Document playerDocument = CorePlugin.getInstance().getCoreDatabase().getPlayerCollection().find(Filters.eq("uuid", uuid.toString())).first();
if (playerDocument != null) {
lore.add(CC.GOLD + "#" + integer.incrementAndGet() + " " + CC.WHITE + playerDocument.getString("name") + CC.GRAY + " - " + CC.YELLOW + allEloMap.getOrDefault(uuid, 1000));
int rank = integer.incrementAndGet();
String color = String.valueOf(CC.YELLOW);
switch (rank) {
case 1:
color = String.valueOf(CC.GOLD);
break;
case 2:
color = String.valueOf(CC.GRAY);
break;
case 3:
color = String.valueOf(CC.DARK_GRAY);
break;
}
lore.add(color + "" + rank + " " + CC.GREEN + playerDocument.getString("name") + CC.GRAY + " - " + CC.YELLOW + decimalFormat.format(allEloMap.getOrDefault(uuid, 1000)));
}
} else if (integer.get() >= 3 && integer.get() < 10) {
final Document playerDocument = CorePlugin.getInstance().getCoreDatabase().getPlayerCollection().find(Filters.eq("uuid", uuid.toString())).first();
if (playerDocument != null) {
int rank = integer.incrementAndGet();
String color = String.valueOf(CC.YELLOW);
switch (rank) {
case 1:
color = String.valueOf(CC.GOLD);
break;
case 2:
color = String.valueOf(CC.GRAY);
break;
case 3:
color = String.valueOf(CC.DARK_GRAY);
break;
}
lore.add(color + "#" + rank + " " + CC.GREEN + playerDocument.getString("name") + CC.GRAY + " - " + CC.YELLOW + decimalFormat.format(allEloMap.getOrDefault(uuid, 1000)));
}
}
});
if (lore.size() >= 3) {
IntStream.range(0, 3).forEach(i -> loreEloShort.add(" " + lore.get(i)));
IntStream.range(0, 3).forEach(i -> loreShort.add(" " + lore.get(i).replace("", "#")));
}
LeaderboardUpdateRunnable.KIT_SPECIFIC_LEADERBOARD_LORE_SHORT.put(kit, loreEloShort);
LeaderboardUpdateRunnable.KIT_SPECIFIC_LEADERBOARD_LORE_SHORT.put(kit, loreShort);
LeaderboardUpdateRunnable.KIT_SPECIFIC_LEADERBOARD_LORE.put(kit, lore);
final List<String> loreForKillStreaks = new ArrayList<>();
@ -103,19 +137,53 @@ public class LeaderboardUpdateRunnable implements Runnable {
final AtomicInteger integerForKillStreaks = new AtomicInteger();
sortedUuidsForKillStreaks.forEach(uuid -> {
if (integerForKillStreaks.get() != 10) {
if (integerForKillStreaks.get() < 3) { // primeiro, segundo e terceiro lugar
final Document playerDocument = CorePlugin.getInstance().getCoreDatabase().getPlayerCollection().find(Filters.eq("uuid", uuid.toString())).first();
if (playerDocument != null) {
loreForKillStreaks.add(CC.GOLD + "#" + integerForKillStreaks.incrementAndGet() + " " + CC.WHITE + playerDocument.getString("name") + CC.GRAY + " - " + CC.YELLOW + allKillStreaksMap.get(uuid));
int rank = integerForKillStreaks.incrementAndGet();
String color = String.valueOf(CC.YELLOW);
switch (rank) {
case 1:
color = String.valueOf(CC.GOLD);
break;
case 2:
color = String.valueOf(CC.GRAY);
break;
case 3:
color = String.valueOf(CC.DARK_GRAY);
break;
}
loreForKillStreaks.add(color + "" + rank + " " + CC.GREEN + playerDocument.getString("name") + CC.GRAY + " - " + CC.YELLOW + decimalFormat.format(allKillStreaksMap.get(uuid)));
}
} else if (integerForKillStreaks.get() >= 3 && integerForKillStreaks.get() < 10) { // quarto até o décimo lugar
final Document playerDocument = CorePlugin.getInstance().getCoreDatabase().getPlayerCollection().find(Filters.eq("uuid", uuid.toString())).first();
if (playerDocument != null) {
int rank = integerForKillStreaks.incrementAndGet();
String color = String.valueOf(CC.YELLOW);
switch (rank) {
case 1:
color = String.valueOf(CC.GOLD);
break;
case 2:
color = String.valueOf(CC.GRAY);
break;
case 3:
color = String.valueOf(CC.DARK_GRAY);
break;
}
loreForKillStreaks.add(color + "#" + rank + " " + CC.GREEN + playerDocument.getString("name") + CC.GRAY + " - " + CC.YELLOW + decimalFormat.format(allKillStreaksMap.get(uuid)));
}
}
});
if (loreForKillStreaks.size() >= 3) {
IntStream.range(0, 3).forEach(i -> {
loreForKillStreaksShort.add(" " + loreForKillStreaks.get(i));
});
IntStream.range(0, 3).forEach(i -> loreForKillStreaksShort.add(" " + loreForKillStreaks.get(i).replace("", "#")));
}
LeaderboardUpdateRunnable.KIT_SPECIFIC_WIN_STREAK_LORE.put(kit, loreForKillStreaks);
@ -129,7 +197,7 @@ public class LeaderboardUpdateRunnable implements Runnable {
final Map<String, Integer> eloMap = CorePlugin.GSON.fromJson(document.getString("elo"), PracticeConstants.STRING_INTEGER_MAP_TYPE);
if (eloMap != null) {
globalEloMap.put(UUID.fromString(document.getString("uuid")), document.getInteger("globalElo"));
globalEloMap.put(UUID.fromString(document.getString("uuid")), eloMap.values().stream().mapToInt(i -> i).sum() / eloMap.size());
}
});
@ -140,27 +208,32 @@ public class LeaderboardUpdateRunnable implements Runnable {
final AtomicInteger integer = new AtomicInteger();
sortedUuids.forEach(uuid -> {
if (integer.get() != 11) {
final Document playerDocument = CorePlugin.getInstance().getCoreDatabase().getPlayerCollection()
.find(Filters.eq("uuid", uuid.toString())).first();
if (integer.get() < 10) { // top 10 players
final Document playerDocument = CorePlugin.getInstance().getCoreDatabase().getPlayerCollection().find(Filters.eq("uuid", uuid.toString())).first();
if (playerDocument != null) {
final int globalElo = globalEloMap.get(uuid);
final RankedDivision rankedDivision = RankedDivision.getByGlobalElo(globalElo);
int rank = integer.incrementAndGet();
String color = String.valueOf(CC.YELLOW);
if (rankedDivision != null) {
lore.add(CC.GOLD + "#" + integer.incrementAndGet() + " " + CC.WHITE + playerDocument.getString("name") + CC.GRAY + " - " + CC.YELLOW + globalElo + CC.GRAY + " - " + rankedDivision.getFancyName());
switch (rank) {
case 1:
color = String.valueOf(CC.GOLD);
break;
case 2:
color = String.valueOf(CC.GRAY);
break;
case 3:
color = String.valueOf(CC.DARK_GRAY);
break;
}
lore.add(color + "#" + rank + " " + CC.GREEN + playerDocument.getString("name") + CC.GRAY + " - " + CC.YELLOW + decimalFormat.format(globalEloMap.getOrDefault(uuid, 1000)));
}
}
});
LeaderboardUpdateRunnable.GLOBAL_ELO_LEADERBOARD_LORE.clear();
LeaderboardUpdateRunnable.GLOBAL_ELO_LEADERBOARD_LORE.addAll(lore);
}).whenComplete((unused, throwable) -> {
if (throwable != null) {
throwable.printStackTrace();
}
});
}
}

View File

@ -0,0 +1,63 @@
package land.battle.practice.util;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
public class ClassUtil {
/**
* Obtém todas as classes dentro de um pacote especificado.
*
* @param classLoader O ClassLoader a ser usado para carregar as classes.
* @param packageName O nome do pacote a ser escaneado.
* @return Um conjunto de classes dentro do pacote especificado.
*/
public static Set<Class<?>> getClasses(ClassLoader classLoader, String packageName) {
Set<Class<?>> classes = new HashSet<>();
String path = packageName.replace('.', '/');
Enumeration<URL> resources;
try {
resources = classLoader.getResources(path);
} catch (IOException e) {
e.printStackTrace();
return classes;
}
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
File directory = new File(resource.getFile());
if (!directory.exists()) {
continue;
}
File[] files = directory.listFiles();
if (files == null) {
continue;
}
for (File file : files) {
if (file.isDirectory()) {
classes.addAll(getClasses(classLoader, packageName + "." + file.getName()));
} else if (file.getName().endsWith(".class")) {
String className = packageName + '.' + file.getName().substring(0, file.getName().length() - 6);
try {
Class<?> clazz = Class.forName(className);
classes.add(clazz);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
}
return classes;
}
}

View File

@ -31,8 +31,8 @@ public class VoteManager {
public void sendVoteMessage(Player player, Arena arena) {
ChatComponentBuilder builder = new ChatComponentBuilder("");
builder.append(CC.AQUA + "Give us some feedback on " + CC.YELLOW + arena.getName() + " by clicking" );
builder.append(CC.AQUA + "one of the stars: ");
builder.append(CC.AQUA + "Give us some feedback on " + CC.YELLOW + arena.getName() + CC.AQUA + " by clicking" );
builder.append(CC.AQUA + " one of the stars: ");
Arrays.stream(Vote.values()).forEach(rating -> builder.append(rating.getDisplayName() + " ")
.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/rate " + rating.name()))