Fix AdventCalender only in December, Reduce code duplication #39
@ -21,6 +21,7 @@ package de.steamwar.lobby.listener;
|
||||
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import de.steamwar.lobby.command.ModifyCommand;
|
||||
import de.steamwar.lobby.special.advent.AdventsCalendar;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -33,9 +34,6 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
|
||||
public class InventoryInteraction extends BasicListener {
|
||||
|
||||
@EventHandler
|
||||
@ -46,9 +44,7 @@ public class InventoryInteraction extends BasicListener {
|
||||
|
||||
if(item.getType() == Material.FIREWORK_ROCKET && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
|
||||
int offset;
|
||||
LocalDate localDate = LocalDate.now();
|
||||
Month month = localDate.getMonth();
|
||||
if (month == Month.NOVEMBER || month == Month.DECEMBER || month == Month.JANUARY) {
|
||||
if (AdventsCalendar.active()) {
|
||||
offset = -1;
|
||||
} else {
|
||||
offset = 0;
|
||||
|
@ -21,6 +21,7 @@ package de.steamwar.lobby.listener;
|
||||
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import de.steamwar.lobby.boatrace.BoatRace;
|
||||
import de.steamwar.lobby.special.advent.AdventsCalendar;
|
||||
import de.steamwar.lobby.util.ItemBuilder;
|
||||
import de.steamwar.network.NetworkSender;
|
||||
import de.steamwar.network.packets.client.ImALobbyPacket;
|
||||
@ -36,9 +37,6 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
|
||||
public class PlayerSpawn extends BasicListener {
|
||||
|
||||
public static final int FIREWORK_SLOT = 2;
|
||||
@ -75,9 +73,7 @@ public class PlayerSpawn extends BasicListener {
|
||||
inventory.setItem(EquipmentSlot.CHEST, ELYTRA);
|
||||
|
||||
int offset = 0;
|
||||
LocalDate localDate = LocalDate.now();
|
||||
Month month = localDate.getMonth();
|
||||
if (month == Month.NOVEMBER || month == Month.DECEMBER || month == Month.JANUARY) {
|
||||
if (AdventsCalendar.active()) {
|
||||
offset = -1;
|
||||
}
|
||||
|
||||
|
@ -29,8 +29,6 @@ import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
@ -59,13 +57,11 @@ public class AdventCommand extends SWCommand {
|
||||
|
||||
@Register
|
||||
public void genericCommand(Player player, String... args) {
|
||||
LocalDate localDate = LocalDate.now();
|
||||
Month month = localDate.getMonth();
|
||||
if (month != Month.NOVEMBER && month != Month.DECEMBER && month != Month.JANUARY) {
|
||||
if (!AdventsCalendar.active()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Random random = new Random(localDate.getYear());
|
||||
Random random = new Random();
|
||||
|
||||
List<SWListInv.SWListEntry<Present>> itemList = new ArrayList<>();
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId());
|
||||
|
@ -28,9 +28,6 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
|
||||
public class AdventListener extends BasicListener {
|
||||
|
||||
public static final int ADVENT_SLOT = 7;
|
||||
@ -52,9 +49,7 @@ public class AdventListener extends BasicListener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
LocalDate localDate = LocalDate.now();
|
||||
Month month = localDate.getMonth();
|
||||
if (month != Month.NOVEMBER && month != Month.DECEMBER && month != Month.JANUARY) {
|
||||
if (!AdventsCalendar.active()) {
|
||||
return;
|
||||
}
|
||||
e.getPlayer().getInventory().setItem(ADVENT_SLOT, ADVENT.getItemStack());
|
||||
|
@ -26,6 +26,8 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -70,4 +72,10 @@ public class AdventsCalendar {
|
||||
}
|
||||
System.out.println("Save time: " + (System.currentTimeMillis() - time) + "ms");
|
||||
}
|
||||
|
||||
public static boolean active() {
|
||||
LocalDate localDate = LocalDate.now();
|
||||
Month month = localDate.getMonth();
|
||||
return month == Month.DECEMBER;
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
|
||||
public class PresentClickListener extends BasicListener {
|
||||
|
||||
@ -37,9 +36,8 @@ public class PresentClickListener extends BasicListener {
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
LocalDate localDate = LocalDate.now();
|
||||
int day = localDate.getDayOfMonth();
|
||||
Month month = localDate.getMonth();
|
||||
|
||||
if (month != Month.DECEMBER) {
|
||||
if (!AdventsCalendar.active()) {
|
||||
return;
|
||||
}
|
||||
AdventsCalendar.getPresentList().forEach(present -> {
|
||||
@ -56,9 +54,8 @@ public class PresentClickListener extends BasicListener {
|
||||
|
||||
LocalDate localDate = LocalDate.now();
|
||||
int day = localDate.getDayOfMonth();
|
||||
Month month = localDate.getMonth();
|
||||
|
||||
if (month != Month.DECEMBER) {
|
||||
if (!AdventsCalendar.active()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren