geforkt von SteamWar/BungeeCore
Merge pull request 'AdventCalendar' (#442) from AdventCalendar into master
Reviewed-on: SteamWar/BungeeCore#442 Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Commit
15fedebff1
@ -157,6 +157,9 @@ public class BungeeCore extends Plugin {
|
||||
new SetLocaleCommand();
|
||||
new BuilderCloudCommand();
|
||||
|
||||
new CalendarCommand();
|
||||
new CalendarListener();
|
||||
|
||||
// Punishment Commands:
|
||||
new PunishmentCommand("ban", Punishment.PunishmentType.Ban);
|
||||
new PunishmentCommand("mute", Punishment.PunishmentType.Mute);
|
||||
|
112
src/de/steamwar/bungeecore/commands/CalendarCommand.java
Normale Datei
112
src/de/steamwar/bungeecore/commands/CalendarCommand.java
Normale Datei
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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.commands;
|
||||
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.inventory.SWInventory;
|
||||
import de.steamwar.bungeecore.inventory.SWItem;
|
||||
import de.steamwar.bungeecore.sql.NodeMember;
|
||||
import de.steamwar.bungeecore.sql.SchematicNode;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.*;
|
||||
|
||||
public class CalendarCommand extends SWCommand {
|
||||
|
||||
private static Map<Integer, Integer> dayToSchematicId = new HashMap<>();
|
||||
|
||||
static {
|
||||
dayToSchematicId.put(1, 105386);
|
||||
dayToSchematicId.put(2, 105463);
|
||||
dayToSchematicId.put(3, 105438);
|
||||
dayToSchematicId.put(4, 105383);
|
||||
dayToSchematicId.put(5, 105381);
|
||||
dayToSchematicId.put(6, 105396);
|
||||
dayToSchematicId.put(7, 105462);
|
||||
dayToSchematicId.put(8, 105457);
|
||||
dayToSchematicId.put(9, 105388);
|
||||
dayToSchematicId.put(10, 105390);
|
||||
dayToSchematicId.put(11, 105385);
|
||||
dayToSchematicId.put(12, 105397);
|
||||
dayToSchematicId.put(13, 105455);
|
||||
dayToSchematicId.put(14, 105389);
|
||||
dayToSchematicId.put(15, 105454);
|
||||
dayToSchematicId.put(16, 105394);
|
||||
dayToSchematicId.put(17, 105459);
|
||||
dayToSchematicId.put(18, 105384);
|
||||
dayToSchematicId.put(19, 105392);
|
||||
dayToSchematicId.put(20, 105465);
|
||||
dayToSchematicId.put(21, 105393);
|
||||
dayToSchematicId.put(22, 105464);
|
||||
dayToSchematicId.put(23, 105380);
|
||||
dayToSchematicId.put(24, 105505);
|
||||
dayToSchematicId.put(25, 105517);
|
||||
dayToSchematicId.put(26, 105517);
|
||||
dayToSchematicId.put(31, 105507);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
List<SWItem> items = new ArrayList<>();
|
||||
for (Map.Entry<Integer, Integer> present : dayToSchematicId.entrySet()) {
|
||||
boolean b = NodeMember.getNodeMember(present.getValue(), user.getId()) != null;
|
||||
SWItem randomPresent = random.nextDouble() > 0.5 ? SWItem.getSkull("MHF_Present1") : SWItem.getSkull("MHF_Present2");
|
||||
SWItem swItem = b ? SWItem.getSkull("MHF_Chest") : randomPresent;
|
||||
swItem.setName(Message.parse("ADVENT_CALENDAR_DAY", player, present.getKey()));
|
||||
swItem.setCallback(click -> {
|
||||
if (b) return;
|
||||
if (month != Month.DECEMBER) return;
|
||||
if (present.getKey() != day) return;
|
||||
NodeMember.createNodeMember(present.getValue(), user.getId());
|
||||
Message.send("ADVENT_CALENDAR_OPEN", player, SchematicNode.getSchematicNode(present.getValue()).getName());
|
||||
});
|
||||
items.add(swItem);
|
||||
}
|
||||
Collections.shuffle(items, random);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
54
src/de/steamwar/bungeecore/listeners/CalendarListener.java
Normale Datei
54
src/de/steamwar/bungeecore/listeners/CalendarListener.java
Normale Datei
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.BungeeCore;
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.commands.CalendarCommand;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
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;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
BungeeCord.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
||||
Message.send("ADVENT_CALENDAR_MESSAGE", event.getPlayer(), Message.parse("ADVENT_CALENDAR_MESSAGE_HOVER", event.getPlayer()), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/calendar"));
|
||||
}, 2, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
@ -648,4 +648,11 @@ LOCK_LOCALE_CHANGED=§aLanguage saved
|
||||
|
||||
#Builder Cloud
|
||||
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=§eDid you already open your advent calendar?
|
||||
ADVENT_CALENDAR_MESSAGE_HOVER=§eClick to open!
|
||||
ADVENT_CALENDAR_OPEN=§7You got §e{0} §7from the advent calendar!
|
@ -626,4 +626,11 @@ LOCK_LOCALE_CHANGED=§aSprache gespeichert
|
||||
|
||||
#Builder Cloud
|
||||
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=§eHast du heute schon dein Geschenk geholt?
|
||||
ADVENT_CALENDAR_MESSAGE_HOVER=§eKlicken zum öffnen!
|
||||
ADVENT_CALENDAR_OPEN=§7Du hast §e{0}§7 aus dem Adventskalender erhalten!
|
In neuem Issue referenzieren
Einen Benutzer sperren