From 11a63101f1c16d634e6ff285610ce7f5bf53147c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 21 Nov 2022 18:02:50 +0100 Subject: [PATCH] Add CalendarCommand --- src/de/steamwar/bungeecore/BungeeCore.java | 1 + .../bungeecore/commands/CalendarCommand.java | 76 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/de/steamwar/bungeecore/commands/CalendarCommand.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 4013f34f..6051a853 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -156,6 +156,7 @@ public class BungeeCore extends Plugin { new LocalCommand(); new SetLocaleCommand(); new BuilderCloudCommand(); + new CalendarCommand(); // Punishment Commands: new PunishmentCommand("ban", Punishment.PunishmentType.Ban); diff --git a/src/de/steamwar/bungeecore/commands/CalendarCommand.java b/src/de/steamwar/bungeecore/commands/CalendarCommand.java new file mode 100644 index 00000000..2c5aa2bd --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/CalendarCommand.java @@ -0,0 +1,76 @@ +/* + * 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.commands; + +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; +import java.util.*; + +public class CalendarCommand extends SWCommand { + + private Map dayToSchematicId = new HashMap<>(); + + { + for (int i = 1; i < 31; i++) { + dayToSchematicId.put(i, 0); + } + } + + public CalendarCommand() { + super("calendar", null, "cal"); + } + + @Register + public void genericCommand(ProxiedPlayer player) { + LocalDate localDate = LocalDate.now(); + int day = localDate.getDayOfMonth(); + Month month = localDate.getMonth(); + Random random = new Random(localDate.getYear()); + + if (month != Month.NOVEMBER && month != Month.DECEMBER && month != Month.JANUARY) { + return; + } + + 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.setCallback(click -> { + if (month != Month.DECEMBER) return; + if (present.getKey() != day) return; + // TODO: Add to schematic + }); + items.add(swItem); + } + Collections.shuffle(items, random); + + SWInventory inventory = new SWInventory(player, 36, "§6§lAdventskalender"); + for (int i = 0; i < items.size(); i++) { + inventory.addItem(i, items.get(i)); + } + inventory.open(); + } +}