forked from SteamWar/SteamWar
Add BauSystem module
Fix ci java version Fix LinkageProcessor
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package de.steamwar.lobby.special.easter;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class EggHuntCommand extends SWCommand {
|
||||
|
||||
public EggHuntCommand() {
|
||||
super("egghunt", "easteregg", "easter", "egg", "eh");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(Player player, @OptionalValue("ALL") Selection selection) {
|
||||
AtomicInteger atomicInteger = new AtomicInteger();
|
||||
String found = UserConfig.getConfig(player.getUniqueId(), EggHunt.EGG_HUNT_CONFIG_KEY);
|
||||
AtomicInteger foundCount = new AtomicInteger();
|
||||
List<SWListInv.SWListEntry<Egg>> entries = EggHunt.getEggList().stream()
|
||||
.map(egg -> {
|
||||
int index = atomicInteger.getAndIncrement();
|
||||
boolean isFound = found != null && found.length() > index && found.charAt(index) == '1';
|
||||
if (isFound) foundCount.getAndIncrement();
|
||||
if (selection == Selection.FOUND && !isFound) return null;
|
||||
if (selection == Selection.NOT_FOUND && isFound) return null;
|
||||
SWItem swItem = egg.getItem(player, isFound);
|
||||
if (swItem == null) return null;
|
||||
return new SWListInv.SWListEntry<>(swItem, egg);
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.sorted(Comparator.comparing(eggSWListEntry -> eggSWListEntry.getObject().getDifficulty()))
|
||||
.collect(Collectors.toList());
|
||||
SWListInv<Egg> inv = new SWListInv<>(player, LobbySystem.getMessage().parse("EASTER_EGG_MENU", player, foundCount.get(), EggHunt.getEggList().size()), false, entries, (clickType, egg) -> {
|
||||
});
|
||||
inv.setItem(49, new SWItem(SWItem.getDye(15), (byte) 15, LobbySystem.getMessage().parse(Selection.ALL.key, player), Collections.emptyList(), selection == Selection.ALL, clickType -> {
|
||||
genericCommand(player, Selection.ALL);
|
||||
}));
|
||||
inv.setItem(48, new SWItem(SWItem.getDye(1), (byte) 1, LobbySystem.getMessage().parse(Selection.NOT_FOUND.key, player), Collections.emptyList(), selection == Selection.NOT_FOUND, clickType -> {
|
||||
genericCommand(player, Selection.NOT_FOUND);
|
||||
}));
|
||||
inv.setItem(50, new SWItem(SWItem.getDye(2), (byte) 2, LobbySystem.getMessage().parse(Selection.FOUND.key, player), Collections.emptyList(), selection == Selection.FOUND, clickType -> {
|
||||
genericCommand(player, Selection.FOUND);
|
||||
}));
|
||||
inv.open();
|
||||
}
|
||||
|
||||
public enum Selection {
|
||||
ALL("EASTER_EGG_SELECTION_ALL"),
|
||||
FOUND("EASTER_EGG_SELECTION_FOUND"),
|
||||
NOT_FOUND("EASTER_EGG_SELECTION_NOT_FOUND");
|
||||
|
||||
private final String key;
|
||||
|
||||
Selection(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user