SteamWar/BungeeCore
Archiviert
13
2

Add CalendarListener
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-11-22 16:39:24 +01:00
Ursprung 11a63101f1
Commit e024282a20
4 geänderte Dateien mit 73 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -19,11 +19,11 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.inventory.SWInventory; import de.steamwar.bungeecore.inventory.SWInventory;
import de.steamwar.bungeecore.inventory.SWItem; import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import sun.awt.OSInfo;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.Month; import java.time.Month;
@ -31,12 +31,13 @@ import java.util.*;
public class CalendarCommand extends SWCommand { public class CalendarCommand extends SWCommand {
private Map<Integer, Integer> dayToSchematicId = new HashMap<>(); private static Map<Integer, Integer> dayToSchematicId = new HashMap<>();
{ static {
for (int i = 1; i < 31; i++) { for (int i = 1; i < 27; i++) {
dayToSchematicId.put(i, 0); dayToSchematicId.put(i, 0);
} }
dayToSchematicId.put(31, 0);
} }
public CalendarCommand() { public CalendarCommand() {
@ -57,7 +58,8 @@ public class CalendarCommand extends SWCommand {
List<SWItem> items = new ArrayList<>(); List<SWItem> items = new ArrayList<>();
for (Map.Entry<Integer, Integer> present : dayToSchematicId.entrySet()) { for (Map.Entry<Integer, Integer> present : dayToSchematicId.entrySet()) {
boolean b = false; // TODO: Add check if player has schematic 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 -> { swItem.setCallback(click -> {
if (month != Month.DECEMBER) return; if (month != Month.DECEMBER) return;
if (present.getKey() != day) return; if (present.getKey() != day) return;
@ -67,10 +69,14 @@ public class CalendarCommand extends SWCommand {
} }
Collections.shuffle(items, random); 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++) { for (int i = 0; i < items.size(); i++) {
inventory.addItem(i, items.get(i)); inventory.addItem(i, items.get(i));
} }
inventory.open(); inventory.open();
} }
public static boolean hasDay(int day) {
return dayToSchematicId.containsKey(day);
}
} }

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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"));
}
}

Datei anzeigen

@ -649,3 +649,8 @@ LOCK_LOCALE_CHANGED=§aLanguage saved
#Builder Cloud #Builder Cloud
BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eversion§8] §8[§emap§8] §8<§7generator§8> BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eversion§8] §8[§emap§8] §8<§7generator§8>
BUILDERCLOUD_VERSION=§cUnknown version. 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?

Datei anzeigen

@ -627,3 +627,8 @@ LOCK_LOCALE_CHANGED=§aSprache gespeichert
#Builder Cloud #Builder Cloud
BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eVersion§8] §8[§eWelt§8] §8<§7Generator§8> BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eVersion§8] §8[§eWelt§8] §8<§7Generator§8>
BUILDERCLOUD_VERSION=§cUnbekannte Version. 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?