diff --git a/src/main/java/de/fanta/challenges/challenges/ChallengeEvents/SammelFieberChallengeEvent.java b/src/main/java/de/fanta/challenges/challenges/ChallengeEvents/SammelFieberChallengeEvent.java index 2c56d6b..5fe337a 100644 --- a/src/main/java/de/fanta/challenges/challenges/ChallengeEvents/SammelFieberChallengeEvent.java +++ b/src/main/java/de/fanta/challenges/challenges/ChallengeEvents/SammelFieberChallengeEvent.java @@ -4,11 +4,14 @@ import de.fanta.challenges.events.TimerChangedEvent; import de.fanta.challenges.guis.eventgui.SammelFieberSettingsGui; import de.fanta.challenges.scoreboard.ChallengePlayer; +import de.fanta.challenges.teams.ChallengeTeam; +import de.fanta.challenges.teams.TeamUtils; import de.fanta.challenges.utils.ChatUtil; import de.fanta.challenges.utils.Config; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.OfflinePlayer; import org.bukkit.Sound; import org.bukkit.boss.BarColor; import org.bukkit.boss.BarStyle; @@ -27,11 +30,14 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import java.util.HashMap; import java.util.Objects; public class SammelFieberChallengeEvent implements Listener { public static BossBar bossBar; + + public static HashMap bossBarList = new HashMap<>(); public static Location hopperloc; private static Material material; private static boolean running; @@ -73,12 +79,26 @@ ItemStack stack = SammelFieberSettingsGui.getEventItem(); if (stack != null && getHopperLocation() != null) { setMaterial(stack.getType()); - 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 pp : Bukkit.getOnlinePlayers()) { - plugin.getScoreManager().join(new ChallengePlayer(pp.getUniqueId())); - bossBar.addPlayer(pp); + if (!Config.getBoolean("event.teams")) { + 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 pp : Bukkit.getOnlinePlayers()) { + plugin.getScoreManager().join(new ChallengePlayer(pp.getUniqueId())); + bossBar.addPlayer(pp); + } + } else { + for (ChallengeTeam team : TeamUtils.getTeams()) { + plugin.getScoreManager().join(team); + BossBar teamBar = Bukkit.createBossBar(ChatUtil.GREEN + "Dein Team hat " + ChatUtil.BLUE + plugin.getScoreManager().getScore(team) + " " + new ItemStack(getMaterial()).getI18NDisplayName() + ChatUtil.GREEN + " abgegeben.", BarColor.GREEN, BarStyle.SOLID); + teamBar.setVisible(true); + bossBarList.put(team, teamBar); + for (OfflinePlayer offlinePlayer : TeamUtils.getPlayersInTeam(team)) + if (offlinePlayer instanceof Player player) { + teamBar.addPlayer(player); + } + } } + } else { ChatUtil.sendErrorMessage(plugin.getCurrentEditor(), "Du musst erst ein Item und Hopper festlegen."); plugin.getTimer().stopTimer(); @@ -113,11 +133,29 @@ ItemMeta meta = stack.getItemMeta(); if (meta != null && meta.hasDisplayName()) { - Player player = Bukkit.getPlayer(meta.getDisplayName()); - count = count + stack.getAmount(); - plugin.getScoreManager().updateScore(new ChallengePlayer(player.getUniqueId()), stack.getAmount()); - player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1.0F, 2.0F); - bossBar.setTitle(ChatUtil.GREEN + "Es wurden " + ChatUtil.BLUE + count + " " + new ItemStack(getMaterial()).getI18NDisplayName() + ChatUtil.GREEN + " abgegeben. Das sind " + ChatUtil.BLUE + count * SammelFieberSettingsGui.MONEY + " Cubes"); + if (!Config.getBoolean("event.teams")) { + Player player = Bukkit.getPlayer(meta.getDisplayName()); + count = count + stack.getAmount(); + plugin.getScoreManager().updateScore(new ChallengePlayer(player.getUniqueId()), stack.getAmount()); + player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1.0F, 2.0F); + bossBar.setTitle(ChatUtil.GREEN + "Es wurden " + ChatUtil.BLUE + count + " " + new ItemStack(getMaterial()).getI18NDisplayName() + ChatUtil.GREEN + " abgegeben. Das sind " + ChatUtil.BLUE + count * SammelFieberSettingsGui.MONEY + " Cubes"); + } else { + ChallengeTeam team = TeamUtils.getTeam(meta.getDisplayName()); + if (team != null) { + plugin.getScoreManager().updateScore(team, stack.getAmount()); + + for (OfflinePlayer offlinePlayer : TeamUtils.getPlayersInTeam(team)) { + if (offlinePlayer instanceof Player pp) { + pp.playSound(pp.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1.0F, 2.0F); + } + } + + for (ChallengeTeam tempTema : TeamUtils.getTeams()) { + BossBar teamBar = bossBarList.get(tempTema); + teamBar.setTitle(ChatUtil.GREEN + "Dein Team hat " + ChatUtil.BLUE + plugin.getScoreManager().getScore(tempTema) + " " + new ItemStack(getMaterial()).getI18NDisplayName() + ChatUtil.GREEN + " abgegeben." + ChatUtil.RED + " | " + ChatUtil.GREEN + "Platz: " + plugin.getScoreManager().getPosition(tempTema)); + } + } + } } Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> e.getInventory().clear(), 1); } @@ -176,7 +214,12 @@ } ItemMeta meta = stack.getItemMeta(); - meta.setDisplayName(e.getPlayer().getName()); + if (!Config.getBoolean("event.teams")) { + meta.setDisplayName(e.getPlayer().getName()); + } else { + meta.setDisplayName(TeamUtils.getPlayerTeam(e.getPlayer()).getName()); + } + stack.setItemMeta(meta); } @@ -204,8 +247,24 @@ if (!isRunning()) { return; } - plugin.getScoreManager().join(new ChallengePlayer(e.getPlayer().getUniqueId())); - bossBar.addPlayer(e.getPlayer()); + if (!Config.getBoolean("event.teams")) { + plugin.getScoreManager().join(new ChallengePlayer(e.getPlayer().getUniqueId())); + bossBar.addPlayer(e.getPlayer()); + } else { + ChallengeTeam team = TeamUtils.getPlayerTeam(e.getPlayer()); + if (team != null) { + plugin.getScoreManager().join(team); + if (bossBarList.containsKey(team)) { + bossBarList.get(team).addPlayer(e.getPlayer()); + } else { + BossBar teamBar = Bukkit.createBossBar(ChatUtil.GREEN + "Dein Team hat " + ChatUtil.BLUE + "0 " + new ItemStack(getMaterial()).getI18NDisplayName() + ChatUtil.GREEN + " abgegeben.", BarColor.GREEN, BarStyle.SOLID); + teamBar.setVisible(true); + bossBarList.put(team, teamBar); + + teamBar.addPlayer(e.getPlayer()); + } + } + } } } diff --git a/src/main/java/de/fanta/challenges/challenges/ChallengeGoals.java b/src/main/java/de/fanta/challenges/challenges/ChallengeGoals.java index 22b5c88..823c271 100644 --- a/src/main/java/de/fanta/challenges/challenges/ChallengeGoals.java +++ b/src/main/java/de/fanta/challenges/challenges/ChallengeGoals.java @@ -30,12 +30,14 @@ ChatUtil.sendBrodcastMessage(ChatUtil.ORANGE + " >> " + ChatUtil.GREEN + "Der " + ChatUtil.BLUE + ChatColor.BOLD + e.getEntity().getName().toLowerCase() + ChatUtil.GREEN + " wurde besiegt."); ChatUtil.sendBrodcastMessage(ChatUtil.ORANGE + " >> " + ChatUtil.GREEN + "Benötigte Zeit: " + plugin.getTimer().formatTime(ChatUtil.BLUE) + ChatUtil.GREEN + "!"); ChatUtil.sendBrodcastMessage(ChatUtil.ORANGE + " >> " + ChatUtil.GREEN + "Seed: " + ChatUtil.BLUE + ChatColor.BOLD + Bukkit.getWorlds().get(0).getSeed()); - if (!Config.getBoolean("editsettings")) { + if (e.getEntity().getType() == EntityType.ENDER_DRAGON) { if (!Config.getBoolean("editsettings")) { - plugin.getStatistics().saveSpeedRun(); - ChatUtil.sendBrodcastMessage(ChatUtil.ORANGE + " >> " + ChatUtil.GREEN + "SpeedRun wurde gespeichert. Deine Zeit: " + plugin.getTimer().formatTime(ChatUtil.BLUE)); - } + if (!Config.getBoolean("editsettings")) { + plugin.getStatistics().saveSpeedRun(); + ChatUtil.sendBrodcastMessage(ChatUtil.ORANGE + " >> " + ChatUtil.GREEN + "SpeedRun wurde gespeichert. Deine Zeit: " + plugin.getTimer().formatTime(ChatUtil.BLUE)); + } + } } ChatUtil.sendBrodcastMessage(""); ChatUtil.sendBrodcastMessage(""); diff --git a/src/main/java/de/fanta/challenges/commands/CommandRegistration.java b/src/main/java/de/fanta/challenges/commands/CommandRegistration.java index 1d6843e..13e3e6e 100644 --- a/src/main/java/de/fanta/challenges/commands/CommandRegistration.java +++ b/src/main/java/de/fanta/challenges/commands/CommandRegistration.java @@ -39,6 +39,7 @@ import de.fanta.challenges.commands.revive.ReviveCommand; import de.fanta.challenges.commands.settings.SettingsCommand; import de.fanta.challenges.commands.timer.TimerCommand; +import de.fanta.challenges.commands.timer.TimerGetCommand; import de.fanta.challenges.commands.timer.TimerPauseCommand; import de.fanta.challenges.commands.timer.TimerResetCommand; import de.fanta.challenges.commands.timer.TimerReverseCommand; @@ -96,6 +97,7 @@ timerRouter.addCommandMapping(new TimerReverseCommand(plugin), "reverse"); timerRouter.addCommandMapping(new TimerSetCommand(plugin), "set"); timerRouter.addCommandMapping(new TimerStartCommand(plugin), "start"); + timerRouter.addCommandMapping(new TimerGetCommand(plugin), "get"); CommandRouter forcemlgRouter = new CommandRouter(plugin.getCommand("forcemlg")); forcemlgRouter.addCommandMapping(new ForceMLGCommand(plugin)); diff --git a/src/main/java/de/fanta/challenges/commands/timer/TimerGetCommand.java b/src/main/java/de/fanta/challenges/commands/timer/TimerGetCommand.java new file mode 100644 index 0000000..4cbdeae --- /dev/null +++ b/src/main/java/de/fanta/challenges/commands/timer/TimerGetCommand.java @@ -0,0 +1,25 @@ +package de.fanta.challenges.commands.timer; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.utils.ChatUtil; +import de.fanta.challenges.utils.Config; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +public class TimerGetCommand extends SubCommand { + + private final Challenges plugin; + + public TimerGetCommand(Challenges plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + ChatUtil.sendNormalMessage(sender, "Timer: " + plugin.getTimer().formatTime() + Config.getBoolean("editsettings")); + return true; + } +} + 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 7e52988..5faefda 100644 --- a/src/main/java/de/fanta/challenges/guis/eventgui/EventGui.java +++ b/src/main/java/de/fanta/challenges/guis/eventgui/EventGui.java @@ -153,7 +153,8 @@ switch (slot) { case BINGO_ITEMS_INDEX -> EventItemsGui.openEventGUI(p); - case SAMMEL_FIEBER_SETTINGS_INDEX -> new SammelFieberSettingsGui(p).open(); + //case SAMMEL_FIEBER_SETTINGS_INDEX -> new SammelFieberSettingsGui(p).open(); + case SAMMEL_FIEBER_SETTINGS_INDEX -> SammelFieberSettingsGui.createSammelFieberSettingsGUI(p); case TEAM_INDEX -> TeamSettingsGUI.createTeamSettingsGUI(p); case EVENT_SETTINGS_INDEX -> new EventSettingsGui(p).open(); case CLOSE_IDEX -> p.closeInventory(); diff --git a/src/main/java/de/fanta/challenges/guis/eventgui/SammelFieberSettingsGui.java b/src/main/java/de/fanta/challenges/guis/eventgui/SammelFieberSettingsGui.java index 2a4aa85..b356a75 100644 --- a/src/main/java/de/fanta/challenges/guis/eventgui/SammelFieberSettingsGui.java +++ b/src/main/java/de/fanta/challenges/guis/eventgui/SammelFieberSettingsGui.java @@ -3,6 +3,124 @@ import de.fanta.challenges.Challenges; import de.fanta.challenges.challenges.ChallengeEvents.SammelFieberChallengeEvent; import de.fanta.challenges.utils.ChatUtil; +import de.fanta.challenges.utils.guiutils.GUIUtils; +import de.iani.cubesideutils.bukkit.items.CustomHeads; +import org.bukkit.Bukkit; +import org.bukkit.FluidCollisionMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +public class SammelFieberSettingsGui implements Listener { + + public static final int INVENTORY_SIZE = 9; + private static final Challenges plugin = Challenges.getPlugin(); + public static final Inventory SAMMEL_FIEBER_SETTINGS_GUI = Bukkit.createInventory(null, InventoryType.DISPENSER, plugin.getGUIPREFIX() + " >> Sammel Fieber Settings"); + private static final int MONEY_INDEX = 5; + private static final int ADD_MONEY_INDEX = 2; + private static final int REMOVE_MONEY_INDEX = 8; + private static final int BACK_INDEX = 6; + private static final int SET_HOPPER_INDEX = 0; + private static final int ITEM_INDEX = 4; + public static int MONEY = 100; + + public static void createSammelFieberSettingsGUI(Player p) { + SAMMEL_FIEBER_SETTINGS_GUI.setItem(SET_HOPPER_INDEX, GUIUtils.createGuiItem(Material.HOPPER, ChatUtil.GREEN + "Set Hopper", ChatUtil.GREEN + "Du musst auf einen Hopper schauen.")); + SAMMEL_FIEBER_SETTINGS_GUI.setItem(MONEY_INDEX, GUIUtils.createGuiItem(Material.GOLD_INGOT, ChatUtil.GREEN + "Money: " + MONEY)); + SAMMEL_FIEBER_SETTINGS_GUI.setItem(ADD_MONEY_INDEX, CustomHeads.QUARTZ_ARROW_UP.getHead()); + SAMMEL_FIEBER_SETTINGS_GUI.setItem(REMOVE_MONEY_INDEX, CustomHeads.QUARTZ_ARROW_DOWN.getHead()); + SAMMEL_FIEBER_SETTINGS_GUI.setItem(BACK_INDEX, CustomHeads.QUARTZ_ARROW_LEFT.getHead()); + for (int i = 0; i < INVENTORY_SIZE; i++) { + if (i != ITEM_INDEX) { + if (SAMMEL_FIEBER_SETTINGS_GUI.getItem(i) == null || SAMMEL_FIEBER_SETTINGS_GUI.getItem(i).getType() == Material.AIR) { + SAMMEL_FIEBER_SETTINGS_GUI.setItem(i, GUIUtils.EMPTY_ICON); + } + } + } + p.openInventory(SAMMEL_FIEBER_SETTINGS_GUI); + } + + public static ItemStack getEventItem() { + return SAMMEL_FIEBER_SETTINGS_GUI.getItem(ITEM_INDEX); + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent e) { + int slot = e.getRawSlot(); + Player p = (Player) e.getWhoClicked(); + if (SAMMEL_FIEBER_SETTINGS_GUI.equals(e.getClickedInventory()) && slot != ITEM_INDEX) { + if (plugin.getConfig().getBoolean("event.enabled")) { + switch (slot) { + case ADD_MONEY_INDEX -> { + if (!e.isShiftClick()) { + MONEY = MONEY + 10; + } else { + MONEY = MONEY + 1; + } + + } + case REMOVE_MONEY_INDEX -> { + if (MONEY > 10) { + if (!e.isShiftClick()) { + MONEY = MONEY - 10; + } else { + MONEY = MONEY - 1; + } + } + } + case SET_HOPPER_INDEX -> { + Block block = p.getTargetBlockExact(5, FluidCollisionMode.NEVER); + if (block != null && block.getType() == Material.HOPPER) { + Location loc = block.getLocation(); + SammelFieberChallengeEvent.setHopperLocation(new Location(loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); + ChatUtil.sendNormalMessage(p, "Hopper wurde gesetzt."); + } else { + ChatUtil.sendErrorMessage(p, "Du musst auf einen Hopper schauen!"); + } + } + } + createSammelFieberSettingsGUI(p); + if (slot == BACK_INDEX) { + EventGui.createEventGUI(p); + } + } + e.setCancelled(true); + } + } + + @EventHandler + public void onInventoryClose(InventoryCloseEvent e) { + Inventory inventory = e.getInventory(); + if (inventory.equals(SAMMEL_FIEBER_SETTINGS_GUI)) { + if (getEventItem() != null) { + plugin.getConfig().set("event.sammelfieber.item", getEventItem().getType().name()); + plugin.getConfig().set("event.sammelfieber.money", SammelFieberSettingsGui.MONEY); + plugin.saveConfig(); + } + } + } +} + + + + + + + + +/*package de.fanta.challenges.guis.eventgui; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.challenges.ChallengeEvents.SammelFieberChallengeEvent; +import de.fanta.challenges.utils.ChatUtil; import de.fanta.challenges.utils.Config; import de.fanta.challenges.utils.guiutils.AbstractWindow; import de.fanta.challenges.utils.guiutils.GUIUtils; @@ -134,6 +252,6 @@ public static ItemStack getEventItem() { return eventItem; } -} +}*/ diff --git a/src/main/java/de/fanta/challenges/listeners/EventRegistration.java b/src/main/java/de/fanta/challenges/listeners/EventRegistration.java index 6452cc7..4ce6697 100644 --- a/src/main/java/de/fanta/challenges/listeners/EventRegistration.java +++ b/src/main/java/de/fanta/challenges/listeners/EventRegistration.java @@ -34,6 +34,7 @@ import de.fanta.challenges.guis.coordsgui.CoordsGUI; import de.fanta.challenges.guis.eventgui.EventGui; import de.fanta.challenges.guis.eventgui.EventItemsGui; +import de.fanta.challenges.guis.eventgui.SammelFieberSettingsGui; import de.fanta.challenges.guis.eventgui.TeamSelectGUI; import de.fanta.challenges.guis.eventgui.TeamSettingsGUI; import de.fanta.challenges.teams.TeamListener; @@ -65,6 +66,7 @@ pM.registerEvents(new TeamSettingsGUI(), plugin); pM.registerEvents(new CoordsGUI(), plugin); pM.registerEvents(new CoordsDeleteGUI(), plugin); + pM.registerEvents(new SammelFieberSettingsGui(), plugin); pM.registerEvents(new GravestoneListener(), plugin); diff --git a/src/main/java/de/fanta/challenges/utils/Statistics.java b/src/main/java/de/fanta/challenges/utils/Statistics.java index 6e13bfd..2138be1 100644 --- a/src/main/java/de/fanta/challenges/utils/Statistics.java +++ b/src/main/java/de/fanta/challenges/utils/Statistics.java @@ -37,7 +37,7 @@ speedRunsWonSolo.setIsMonthlyStats(true); speedRunsTimeSolo = statistics.getStatisticKey("challenge.speedruns.solo.time"); - speedRunsTimeSolo.setDisplayName("Challenge - Beste zeit (Solo)"); + speedRunsTimeSolo.setDisplayName("Beste Zeit (Solo)"); speedRunsTimeSolo.setIsMonthlyStats(true); @@ -50,7 +50,7 @@ speedRunsWonDuo.setIsMonthlyStats(true); speedRunsTimeDuo = statistics.getStatisticKey("challenge.speedruns.duo.time"); - speedRunsTimeDuo.setDisplayName("Challenge - Beste zeit (Duo)"); + speedRunsTimeDuo.setDisplayName("Beste Zeit (Duo)"); speedRunsTimeDuo.setIsMonthlyStats(true); @@ -63,7 +63,7 @@ speedRunsWonTeam.setIsMonthlyStats(true); speedRunsTimeTeam = statistics.getStatisticKey("challenge.speedruns.team.time"); - speedRunsTimeTeam.setDisplayName("Challenge - Beste zeit (Team)"); + speedRunsTimeTeam.setDisplayName("Beste Zeit (Team)"); speedRunsTimeTeam.setIsMonthlyStats(true); }