diff --git a/src/main/java/de/fanta/challenges/challenges/OreBattle.java b/src/main/java/de/fanta/challenges/challenges/OreBattle.java new file mode 100644 index 0000000..5552b96 --- /dev/null +++ b/src/main/java/de/fanta/challenges/challenges/OreBattle.java @@ -0,0 +1,107 @@ +package de.fanta.challenges.challenges; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.events.TimerChangedEvent; +import de.fanta.challenges.teams.ChallengeTeam; +import de.fanta.challenges.teams.TeamUtils; +import de.fanta.challenges.utils.ChatSkullAPI.ChatSkull; +import de.fanta.challenges.utils.ChatUtil; +import de.fanta.challenges.utils.guiutils.GUIUtils; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +public class OreBattle implements Listener { + private static final HashMap blocklist = new HashMap<>(); + private static boolean running; + private final Challenges plugin = Challenges.getPlugin(); + + public static boolean isRunning() { + return running; + } + + public void setRunning(boolean run) { + running = run; + } + + @EventHandler + public void onActivation(TimerChangedEvent event) { + if (Objects.equals(plugin.getConfig().getString("event.type"), "orebattle")) { + if (event.isRunning()) { + blocklist.put(Material.EMERALD_ORE, 10); + blocklist.put(Material.DEEPSLATE_EMERALD_ORE, 10); + blocklist.put(Material.DIAMOND_ORE, 10); + blocklist.put(Material.DEEPSLATE_DIAMOND_ORE, 10); + blocklist.put(Material.GOLD_ORE, 2); + blocklist.put(Material.DEEPSLATE_GOLD_ORE, 1); + blocklist.put(Material.IRON_ORE, 1); + blocklist.put(Material.DEEPSLATE_IRON_ORE, 2); + blocklist.put(Material.COPPER_ORE, 1); + blocklist.put(Material.DEEPSLATE_COPPER_ORE, 1); + blocklist.put(Material.REDSTONE_ORE, 1); + blocklist.put(Material.DEEPSLATE_REDSTONE_ORE, 1); + blocklist.put(Material.COAL_ORE, 1); + blocklist.put(Material.DEEPSLATE_COAL_ORE, 1); + setRunning(true); + } else { + setRunning(false); + if (!plugin.getConfig().getBoolean("event.teams")) { + Map.Entry maxEntry = plugin.getScoreManager().getScores().entrySet().stream().max(Map.Entry.comparingByValue()).get(); + 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); + } + GUIUtils.sendTitleToAll("Event", ChatUtil.BLUE + p.getName() + ChatUtil.GREEN + " gewinnt mit " + ChatUtil.BLUE + maxEntry.getValue() + ChatUtil.GREEN + " Punkten", ChatUtil.GREEN); + } else { + Map.Entry maxEntry = plugin.getScoreManager().getScores().entrySet().stream().max(Map.Entry.comparingByValue()).get(); + 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)) + ChatSkull.sendAll((Player) pp, lines); + } + + } + } + } + } + + @EventHandler + public void onBreakBlock(BlockBreakEvent e) { + if (isRunning()) { + if (blocklist.containsKey(e.getBlock().getType())) { + if (!plugin.getConfig().getBoolean("event.teams")) { + plugin.getScoreManager().updateScore(e.getPlayer(), blocklist.get(e.getBlock().getType())); + } else { + plugin.getScoreManager().updateTeamScore(e.getPlayer(), blocklist.get(e.getBlock().getType())); + } + } + } + } + + @EventHandler + public void onBreakPlace(BlockPlaceEvent e) { + if (isRunning()) { + if (blocklist.containsKey(e.getBlock().getType())) { + if (!plugin.getConfig().getBoolean("event.teams")) { + plugin.getScoreManager().updateScore(e.getPlayer(), -blocklist.get(e.getBlock().getType())); + } else { + plugin.getScoreManager().updateTeamScore(e.getPlayer(), -blocklist.get(e.getBlock().getType())); + } + } + } + } +} diff --git a/src/main/java/de/fanta/challenges/guis/eventgui/EventGui.java b/src/main/java/de/fanta/challenges/guis/eventgui/EventGui.java index 34ea819..9aa2c75 100644 --- a/src/main/java/de/fanta/challenges/guis/eventgui/EventGui.java +++ b/src/main/java/de/fanta/challenges/guis/eventgui/EventGui.java @@ -29,6 +29,7 @@ private static final int DEATHRUN_EVENT_INDEX = 13; private static final int DEATH_COUNTER_INDEX = 14; private static final int SAMMEL_FIEBER_INDEX = 15; + private static final int ORE_BATTLE_INDEX = 16; private static final int BINGO_ITEMS_INDEX = 19; private static final int SAMMEL_FIEBER_SETTINGS_INDEX = 24; private static final int CLOSE_IDEX = 26; @@ -71,6 +72,11 @@ } else { EVENT_GUI.setItem(DEATH_COUNTER_INDEX, GUIUtils.createGuiItem(Material.ANVIL, ChatUtil.RED + "Death Counter Event", ChatUtil.GREEN + "Zeigt Tode bei einem Event.", ChatUtil.GREEN + "Kann nicht mit anderen Events verbunden Werden.")); } + if (Objects.equals(plugin.getConfig().getString("event.type"), "orebattle")) { + EVENT_GUI.setItem(ORE_BATTLE_INDEX, GUIUtils.createGuiItem(Material.DIAMOND_ORE, ChatUtil.GREEN + "Ore Battle Event", true, ChatUtil.GREEN + "Baue so viele erze ab wie möglich.")); + } else { + EVENT_GUI.setItem(ORE_BATTLE_INDEX, GUIUtils.createGuiItem(Material.DIAMOND_ORE, ChatUtil.RED + "Ore Battle Event", ChatUtil.GREEN + "Baue so viele erze ab wie möglich.")); + } if (Objects.equals(plugin.getConfig().getString("event.type"), "sammelfieber")) { EVENT_GUI.setItem(SAMMEL_FIEBER_INDEX, GUIUtils.createGuiItem(Material.HOPPER, ChatUtil.GREEN + "Sammel Fieber Event", true, ChatUtil.GREEN + "Sammle so viel Items wie möglich!")); EVENT_GUI.setItem(SAMMEL_FIEBER_SETTINGS_INDEX, GUIUtils.createGuiItem(Material.NETHER_STAR, ChatUtil.GREEN + "Sammel Fieber Event Settings")); @@ -150,6 +156,10 @@ GUIUtils.setConfig("event.type", "sammelfieber"); GUIUtils.sendTitleToAll("Event", "SammelFieber", ChatUtil.GREEN); } + case ORE_BATTLE_INDEX -> { + GUIUtils.setConfig("event.type", "orebattle"); + GUIUtils.sendTitleToAll("Event", "Ore Battle", ChatUtil.GREEN); + } } createEventGUI(p); diff --git a/src/main/java/de/fanta/challenges/listeners/EventRegistration.java b/src/main/java/de/fanta/challenges/listeners/EventRegistration.java index b43a6ca..fd48ddd 100644 --- a/src/main/java/de/fanta/challenges/listeners/EventRegistration.java +++ b/src/main/java/de/fanta/challenges/listeners/EventRegistration.java @@ -71,5 +71,6 @@ pM.registerEvents(new BedrockWallChallenge(), plugin); pM.registerEvents(new WorldBorderLevelChallenge(), plugin); pM.registerEvents(new SammelFieberChallengeEvent(), plugin); + pM.registerEvents(new OreBattle(), plugin); } }