diff --git a/src/main/java/de/fanta/challenges/challenges/OreBattle.java b/src/main/java/de/fanta/challenges/challenges/OreBattle.java index e85aacd..ba179eb 100644 --- a/src/main/java/de/fanta/challenges/challenges/OreBattle.java +++ b/src/main/java/de/fanta/challenges/challenges/OreBattle.java @@ -3,6 +3,7 @@ import de.fanta.challenges.Challenges; import de.fanta.challenges.events.TimerChangedEvent; import de.fanta.challenges.scoreboard.ChallengePlayer; +import de.fanta.challenges.scoreboard.Scorable; import de.fanta.challenges.teams.ChallengeTeam; import de.fanta.challenges.teams.TeamUtils; import de.fanta.challenges.utils.ChatSkullAPI.ChatSkull; @@ -19,6 +20,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -69,12 +71,22 @@ pickaxe.setItemMeta(pickaxeMeta); if (!plugin.getConfig().getBoolean("event.teams")) { + for (Player player : Bukkit.getOnlinePlayers()) { + plugin.getScoreManager().join(new ChallengePlayer(player)); + } + if (TeamUtils.getPlayerTeam(pp) != null) { pp.getInventory().addItem(new ItemStack(Material.NETHERITE_SWORD)); pp.getInventory().addItem(pickaxe); pp.getInventory().addItem(new ItemStack(Material.COOKED_BEEF, 32)); } } else { + for (ChallengeTeam team : TeamUtils.getTeams()) { + if (team != null && !TeamUtils.getPlayersInTeam(team).isEmpty()) { + plugin.getScoreManager().join(team); + } + } + if (pp.getGameMode() == GameMode.SURVIVAL) { pp.getInventory().addItem(new ItemStack(Material.NETHERITE_SWORD)); pp.getInventory().addItem(pickaxe); @@ -88,27 +100,32 @@ } else { setRunning(false); if (!plugin.getConfig().getBoolean("event.teams")) { - Map.Entry maxEntry = null; //plugin.getScoreManager().getScores().entrySet().stream().max(Map.Entry.comparingByValue()).get(); //TODO GANZ MACHEN - OfflinePlayer p = (Bukkit.getServer().getOfflinePlayer(maxEntry.getKey())); - if (p.isOnline()) { - String[] lines = {"", "", "", " " + ChatUtil.BLUE + p.getName(), ChatUtil.GREEN + " hat " + maxEntry.getValue() + " Punkte und", ChatUtil.GREEN + " hat damit gewonnen!", "", ""}; - ChatSkull.sendAll((Player) p, lines); - } else { - ChatUtil.sendBrodcastMessage(ChatUtil.BLUE + maxEntry.getKey() + ChatUtil.GREEN + " hat " + maxEntry.getValue() + " Punkte und hat damit gewonnen!", ChatUtil.BLUE); + for (Scorable scorable : plugin.getScoreManager().getByPositon(1)) { + OfflinePlayer p = (Bukkit.getServer().getOfflinePlayer(scorable.getName())); + if (p.isOnline()) { + String[] lines = {"", "", "", " " + ChatUtil.BLUE + p.getName(), ChatUtil.GREEN + " hat " + plugin.getScoreManager().getScore(scorable) + " Punkte und", ChatUtil.GREEN + " hat damit gewonnen!", "", ""}; + ChatSkull.sendAll((Player) p, lines); + } else { + ChatUtil.sendBrodcastMessage(ChatUtil.BLUE + scorable.getName() + ChatUtil.GREEN + " hat " + plugin.getScoreManager().getScore(scorable) + " Punkte und hat damit gewonnen!", ChatUtil.BLUE); + } + GUIUtils.sendTitleToAll("Event", ChatUtil.BLUE + p.getName() + ChatUtil.GREEN + " gewinnt mit " + ChatUtil.BLUE + plugin.getScoreManager().getScore(scorable) + ChatUtil.GREEN + " Punkten", ChatUtil.GREEN); } - GUIUtils.sendTitleToAll("Event", ChatUtil.BLUE + p.getName() + ChatUtil.GREEN + " gewinnt mit " + ChatUtil.BLUE + maxEntry.getValue() + ChatUtil.GREEN + " Punkten", ChatUtil.GREEN); + + } else { - Map.Entry maxEntry = null; //plugin.getScoreManager().getScores().entrySet().stream().max(Map.Entry.comparingByValue()).get(); //TODO GANZ MACHEN - ChallengeTeam team = TeamUtils.getTeam(maxEntry.getKey()); - if (team != null) { - GUIUtils.sendTitleToAll("Event", "Team " + team.getChatColor() + team.getName() + ChatUtil.GREEN + " gewinnt mit " + ChatUtil.BLUE + maxEntry.getValue() + ChatUtil.GREEN + " Punkten", ChatUtil.GREEN); - String[] lines = {"", "", "", " " + ChatUtil.BLUE + "Team " + team.getChatColor() + team.getName(), ChatUtil.GREEN + " hat " + maxEntry.getValue() + " Punkte und", ChatUtil.GREEN + " hat damit gewonnen!", "", ""}; - for (OfflinePlayer pp : TeamUtils.getPlayersInTeam(team)) - if (pp.isOnline()) { - ChatSkull.sendAll((Player) pp, lines); - } + for (Scorable scorable : plugin.getScoreManager().getByPositon(1)) { + ChallengeTeam team = TeamUtils.getTeam(scorable.getName()); + if (team != null) { + GUIUtils.sendTitleToAll("Event", "Team " + team.getChatColor() + team.getName() + ChatUtil.GREEN + " gewinnt mit " + ChatUtil.BLUE + plugin.getScoreManager().getScore(scorable) + ChatUtil.GREEN + " Punkten", ChatUtil.GREEN); + String[] lines = {"", "", "", " " + ChatUtil.BLUE + "Team " + team.getChatColor() + team.getName(), ChatUtil.GREEN + " hat " + plugin.getScoreManager().getScore(scorable) + " Punkte und", ChatUtil.GREEN + " hat damit gewonnen!", "", ""}; + for (OfflinePlayer pp : TeamUtils.getPlayersInTeam(team)) + if (pp.isOnline()) { + ChatSkull.sendAll((Player) pp, lines); + } + } } + } } } @@ -129,7 +146,7 @@ } @EventHandler - public void onBreakPlace(BlockPlaceEvent e) { + public void onPlaceBlock(BlockPlaceEvent e) { if (isRunning()) { if (blocklist.containsKey(e.getBlock().getType())) { if (!plugin.getConfig().getBoolean("event.teams")) { @@ -141,4 +158,18 @@ } } } + + @EventHandler + public void onJoin(PlayerJoinEvent e) { + if (isRunning()) { + if (plugin.getConfig().getBoolean("event.teams")) { + ChallengeTeam team = TeamUtils.getPlayerTeam(e.getPlayer()); + if (team != null) { + plugin.getScoreManager().join(team); + } + } else { + plugin.getScoreManager().join(new ChallengePlayer(e.getPlayer())); + } + } + } } diff --git a/src/main/java/de/fanta/challenges/challenges/SammelFieberChallengeEvent.java b/src/main/java/de/fanta/challenges/challenges/SammelFieberChallengeEvent.java index a55539e..e07b373 100644 --- a/src/main/java/de/fanta/challenges/challenges/SammelFieberChallengeEvent.java +++ b/src/main/java/de/fanta/challenges/challenges/SammelFieberChallengeEvent.java @@ -75,6 +75,7 @@ bossBar = Bukkit.createBossBar(ChatUtil.GREEN + "Es wurden " + ChatUtil.BLUE + count + " " + new ItemStack(getMaterial()).getI18NDisplayName() + ChatUtil.GREEN + " abgegeben. Das sind " + ChatUtil.BLUE + count * SammelFieberSettingsGui.MONEY + " Cubes", BarColor.GREEN, BarStyle.SOLID); bossBar.setVisible(true); for (Player pl : Bukkit.getOnlinePlayers()) { + plugin.getScoreManager().join(new ChallengePlayer(pl)); bossBar.addPlayer(pl); } } else { @@ -202,6 +203,7 @@ if (!isRunning()) { return; } + plugin.getScoreManager().join(new ChallengePlayer(e.getPlayer())); bossBar.addPlayer(e.getPlayer()); }