Add Selection modes
Dieser Commit ist enthalten in:
Ursprung
9b69b27310
Commit
6f308e3a56
@ -96,6 +96,12 @@ DIFFICULTY_HARD = §cHard
|
||||
DIFFICULTY_EXTREME = §5Extreme
|
||||
DIFFICULTY_ADVANCED = §5Advanced
|
||||
|
||||
EASTER_EGG_MENU = §0Easter Egg Hunt
|
||||
|
||||
EASTER_EGG_SELECTION_ALL = §eAll
|
||||
EASTER_EGG_SELECTION_FOUND = §aFound
|
||||
EASTER_EGG_SELECTION_NOT_FOUND = §cNot found
|
||||
|
||||
EASTER_EGG_0 = Where everything began
|
||||
EASTER_EGG_1 = Jump and Run
|
||||
EASTER_EGG_2 = Carry me please
|
||||
|
@ -93,6 +93,12 @@ DIFFICULTY_HARD = §cHart
|
||||
DIFFICULTY_EXTREME = §5Extrem
|
||||
DIFFICULTY_ADVANCED = §5Advanced
|
||||
|
||||
EASTER_EGG_MENU = §0Oster Eierer Suche
|
||||
|
||||
EASTER_EGG_SELECTION_ALL = §eAlle
|
||||
EASTER_EGG_SELECTION_FOUND = §aGefunden
|
||||
EASTER_EGG_SELECTION_NOT_FOUND = §cNicht gefunden
|
||||
|
||||
EASTER_EGG_0 = Wo alles begann
|
||||
EASTER_EGG_1 = Jump and Run
|
||||
EASTER_EGG_2 = Carry me please
|
||||
|
@ -19,6 +19,7 @@ public class EggHunt {
|
||||
static {
|
||||
new EggHuntCommand();
|
||||
new EggClickListener();
|
||||
new EggHuntListener();
|
||||
|
||||
File file = new File(LobbySystem.getPlugin().getDataFolder(), "eggs.yml");
|
||||
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
|
@ -3,9 +3,11 @@ 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;
|
||||
@ -19,20 +21,45 @@ public class EggHuntCommand extends SWCommand {
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(Player player) {
|
||||
public void genericCommand(Player player, @OptionalValue("ALL") Selection selection) {
|
||||
AtomicInteger atomicInteger = new AtomicInteger();
|
||||
String found = UserConfig.getConfig(player.getUniqueId(), "egghunt");
|
||||
List<SWListInv.SWListEntry<Egg>> entries = EggHunt.getEggList().stream()
|
||||
.map(egg -> {
|
||||
int index = atomicInteger.getAndIncrement();
|
||||
SWItem swItem = egg.getItem(player, found != null && found.length() > index && found.charAt(index) == '1');
|
||||
boolean isFound = found != null && found.length() > index && found.charAt(index) == '1';
|
||||
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()))
|
||||
.filter(Objects::nonNull).collect(Collectors.toList());
|
||||
SWListInv<Egg> inv = new SWListInv<>(player, "", entries, (clickType, egg) -> {
|
||||
.collect(Collectors.toList());
|
||||
SWListInv<Egg> inv = new SWListInv<>(player, LobbySystem.getMessage().parse("EASTER_EGG_MENU", player), 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
32
src/de/steamwar/lobby/special/easter/EggHuntListener.java
Normale Datei
32
src/de/steamwar/lobby/special/easter/EggHuntListener.java
Normale Datei
@ -0,0 +1,32 @@
|
||||
package de.steamwar.lobby.special.easter;
|
||||
|
||||
import de.steamwar.lobby.listener.BasicListener;
|
||||
import de.steamwar.lobby.util.ItemBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class EggHuntListener extends BasicListener {
|
||||
|
||||
public static final int EASTER_EGG_SLOT = 7;
|
||||
public static final ItemStack EASTER_HUNT = new ItemBuilder(Material.DRAGON_EGG, 1).setDisplayName("§5Easter Hunt").build();
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void handlePlayerInteract(PlayerInteractEvent event) {
|
||||
ItemStack item = event.getItem();
|
||||
if(item == null)
|
||||
return;
|
||||
|
||||
if (item.getType() == Material.DRAGON_EGG && item.getItemMeta() != null && item.getItemMeta().getDisplayName().equals("§5Easter Hunt")) {
|
||||
event.getPlayer().performCommand("egg");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
e.getPlayer().getInventory().setItem(EASTER_EGG_SLOT, EASTER_HUNT);
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren