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