From e024282a20df86b2f52b000a5a0d0a422e36adb8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 22 Nov 2022 16:39:24 +0100 Subject: [PATCH] Add CalendarListener --- .../bungeecore/commands/CalendarCommand.java | 18 ++++--- .../listeners/CalendarListener.java | 49 +++++++++++++++++++ .../steamwar/messages/BungeeCore.properties | 7 ++- .../messages/BungeeCore_de.properties | 7 ++- 4 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 src/de/steamwar/bungeecore/listeners/CalendarListener.java diff --git a/src/de/steamwar/bungeecore/commands/CalendarCommand.java b/src/de/steamwar/bungeecore/commands/CalendarCommand.java index 2c5aa2bd..95bfd230 100644 --- a/src/de/steamwar/bungeecore/commands/CalendarCommand.java +++ b/src/de/steamwar/bungeecore/commands/CalendarCommand.java @@ -19,11 +19,11 @@ package de.steamwar.bungeecore.commands; +import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.command.SWCommand; import net.md_5.bungee.api.connection.ProxiedPlayer; -import sun.awt.OSInfo; import java.time.LocalDate; import java.time.Month; @@ -31,12 +31,13 @@ import java.util.*; public class CalendarCommand extends SWCommand { - private Map dayToSchematicId = new HashMap<>(); + private static Map dayToSchematicId = new HashMap<>(); - { - for (int i = 1; i < 31; i++) { + static { + for (int i = 1; i < 27; i++) { dayToSchematicId.put(i, 0); } + dayToSchematicId.put(31, 0); } public CalendarCommand() { @@ -57,7 +58,8 @@ public class CalendarCommand extends SWCommand { List items = new ArrayList<>(); for (Map.Entry present : dayToSchematicId.entrySet()) { boolean b = false; // TODO: Add check if player has schematic - SWItem swItem = new SWItem(b ? "iron_door" : "dark_oak_door", "§fTag " + present.getKey()); + SWItem swItem = b ? SWItem.getSkull("MHF_Chest") : SWItem.getSkull("MHF_Present1"); + swItem.setName(Message.parse("ADVENT_CALENDAR_DAY", player, present.getKey())); swItem.setCallback(click -> { if (month != Month.DECEMBER) return; if (present.getKey() != day) return; @@ -67,10 +69,14 @@ public class CalendarCommand extends SWCommand { } Collections.shuffle(items, random); - SWInventory inventory = new SWInventory(player, 36, "§6§lAdventskalender"); + SWInventory inventory = new SWInventory(player, 27, Message.parse("ADVENT_CALENDAR_TITLE", player)); for (int i = 0; i < items.size(); i++) { inventory.addItem(i, items.get(i)); } inventory.open(); } + + public static boolean hasDay(int day) { + return dayToSchematicId.containsKey(day); + } } diff --git a/src/de/steamwar/bungeecore/listeners/CalendarListener.java b/src/de/steamwar/bungeecore/listeners/CalendarListener.java new file mode 100644 index 00000000..935ac5c0 --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/CalendarListener.java @@ -0,0 +1,49 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2022 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bungeecore.listeners; + +import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.commands.CalendarCommand; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.event.PostLoginEvent; +import net.md_5.bungee.event.EventHandler; + +import java.time.LocalDate; +import java.time.Month; + +public class CalendarListener extends BasicListener { + + @EventHandler + public void onPostLogin(PostLoginEvent event) { + LocalDate localDate = LocalDate.now(); + int day = localDate.getDayOfMonth(); + Month month = localDate.getMonth(); + + if (month != Month.DECEMBER) { + return; + } + + if (!CalendarCommand.hasDay(day)) { + return; + } + + Message.send("ADVENT_CALENDAR_MESSAGE", event.getPlayer(), null, new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/calendar")); + } +} diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 878ede19..b8d510c2 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -648,4 +648,9 @@ LOCK_LOCALE_CHANGED=§aLanguage saved #Builder Cloud BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eversion§8] §8[§emap§8] §8<§7generator§8> -BUILDERCLOUD_VERSION=§cUnknown version. \ No newline at end of file +BUILDERCLOUD_VERSION=§cUnknown version. + +# Advent Calendar +ADVENT_CALENDAR_TITLE=§eAdvent Calendar +ADVENT_CALENDAR_DAY=§7Day§8: §e{0} +ADVENT_CALENDAR_MESSAGE=§7Did you already open your advent calendar? \ No newline at end of file diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 24f0a3d5..280b2f4d 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -626,4 +626,9 @@ LOCK_LOCALE_CHANGED=§aSprache gespeichert #Builder Cloud BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eVersion§8] §8[§eWelt§8] §8<§7Generator§8> -BUILDERCLOUD_VERSION=§cUnbekannte Version. \ No newline at end of file +BUILDERCLOUD_VERSION=§cUnbekannte Version. + +# Advent Calendar +ADVENT_CALENDAR_TITLE=§eAdventskalender +ADVENT_CALENDAR_DAY=§7Tag§8: §e{0} +ADVENT_CALENDAR_MESSAGE=§7Hast du heute schon dein Geschenk geholt? \ No newline at end of file