diff --git a/src/main/java/de/fanta/challenges/guis/eventgui/EventSettingsGui.java b/src/main/java/de/fanta/challenges/guis/eventgui/EventSettingsGui.java new file mode 100644 index 0000000..405bdac --- /dev/null +++ b/src/main/java/de/fanta/challenges/guis/eventgui/EventSettingsGui.java @@ -0,0 +1,70 @@ +package de.fanta.challenges.guis.eventgui; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.utils.ChatUtil; +import de.fanta.challenges.utils.guiutils.AbstractWindow; +import de.fanta.challenges.utils.guiutils.GUIUtils; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemStack; + +public class EventSettingsGui extends AbstractWindow { + private static final Challenges plugin = Challenges.getPlugin(); + + public static final int INVENTORY_SIZE = 9; + + private static final int DIRECTION_INDEX = 11; + + public EventSettingsGui(Player player) { + super(player, Bukkit.createInventory(player, INVENTORY_SIZE, plugin.getGUIPREFIX() + " >> Event Settings")); + } + + @Override + public void onItemClicked(InventoryClickEvent event) { + Player player = getPlayer(); + if (!mayAffectThisInventory(event)) { + return; + } + + event.setCancelled(true); + if (!getInventory().equals(event.getClickedInventory())) { + return; + } + + int slot = event.getSlot(); + switch (slot) { + case DIRECTION_INDEX -> { + if (plugin.getConfig().getBoolean("event.minilwc")) { + GUIUtils.setConfig("event.minilwc", false); + ChatUtil.sendTitleToAll("Event", "Mini LWC aktiviert.", ChatUtil.GREEN, true); + } else { + GUIUtils.setConfig("event.minilwc", true); + ChatUtil.sendTitleToAll("Event", "Mini LWC deaktiviert.", ChatUtil.BLUE, true); + } + player.closeInventory(); + } + default -> { + } + } + } + + @Override + protected void rebuildInventory() { + for (int i = 0; i < INVENTORY_SIZE; i++) { + ItemStack item; + switch (i) { + case DIRECTION_INDEX -> { + if (plugin.getConfig().getBoolean("event.minilwc")) { + item = GUIUtils.createGuiItem(Material.BARREL, ChatUtil.BLUE + "Timer Richtung - rückwärts"); + } else { + item = GUIUtils.createGuiItem(Material.BARREL, ChatUtil.GREEN + "Timer Richtung - vorwärts"); + } + } + default -> item = GUIUtils.EMPTY_ICON; + } + this.getInventory().setItem(i, item); + } + } +} diff --git a/src/main/java/de/fanta/challenges/utils/ChatUtil.java b/src/main/java/de/fanta/challenges/utils/ChatUtil.java index c0f1e1a..c0bdf71 100644 --- a/src/main/java/de/fanta/challenges/utils/ChatUtil.java +++ b/src/main/java/de/fanta/challenges/utils/ChatUtil.java @@ -8,6 +8,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import javax.annotation.Nullable; + public class ChatUtil { public static final ChatColor GREEN = ChatColor.of("#52ff9d"); @@ -52,23 +54,8 @@ } public static void sendTitleToAll(String headline, String text, ChatColor textColor, int in, int time, int out, boolean pling) { - String tempheadline = headline; - String temptext = text; - - if (headline.equals("") || headline == null) { - tempheadline = " "; - } - - if (temptext.equals("") || temptext == null) { - temptext = " "; - } - - for (Player p : Bukkit.getOnlinePlayers()) { - p.sendTitle(ChatUtil.BLUE + tempheadline, textColor + temptext, in, time, out); - if (pling) { - p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1.0F, 2.0F); - } + sendTitleToPlayer(p, headline, text, textColor, in, time, out, pling); } } @@ -76,15 +63,15 @@ sendTitleToAll(headline, text, textColor, 10, 60 , 10, pling); } - public static void sendTitleToPlayer(Player player, String headline, String text, ChatColor textColor, int in, int time, int out, boolean pling) { + public static void sendTitleToPlayer(Player player, @Nullable String headline, @Nullable String text, ChatColor textColor, int in, int time, int out, boolean pling) { String tempheadline = headline; String temptext = text; - if (headline.equals("") || headline == null) { + if (headline == null || headline.equals("")) { tempheadline = " "; } - if (temptext.equals("") || temptext == null) { + if (temptext == null || temptext.equals("")) { temptext = " "; } @@ -92,6 +79,5 @@ if (pling) { player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1.0F, 2.0F); } - } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7cfc781..7a9b947 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -50,6 +50,7 @@ teams: false teamselect: false autoteams: false + minilwc: false sammelfieber: item: AIR money: 100