forked from SteamWar/SteamWar
Add BauSystem module
Fix ci java version Fix LinkageProcessor
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.lobby.special.advent;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import de.steamwar.sql.NodeMember;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class AdventCommand extends SWCommand {
|
||||
|
||||
public AdventCommand() {
|
||||
super("advent", "calendar", "adventcalendar");
|
||||
}
|
||||
|
||||
// @Register
|
||||
/*
|
||||
public void show(Player player, @Min(intValue = 1) @Max(intValue = 31) int day) {
|
||||
if (SteamwarUser.get(player.getUniqueId()).getUserGroup() == UserGroup.Member) {
|
||||
return;
|
||||
}
|
||||
|
||||
AdventsCalendar.getPresentList().forEach(present -> {
|
||||
present.removePlayer(player);
|
||||
if (day == present.getDay()) {
|
||||
present.addPlayer(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
@Register
|
||||
public void genericCommand(Player player, String... args) {
|
||||
if (!AdventsCalendar.active()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
List<SWListInv.SWListEntry<Present>> itemList = new ArrayList<>();
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId());
|
||||
AdventsCalendar.getPresentList().forEach(present -> {
|
||||
NodeMember nodeMember = NodeMember.getNodeMember(present.getSchematicId(), steamwarUser.getId());
|
||||
SWItem item;
|
||||
if (nodeMember == null) {
|
||||
item = SWItem.getPlayerSkull(random.nextBoolean() ? "MHF_Present1" : "MHF_Present2");
|
||||
} else {
|
||||
item = new SWItem(Material.CHEST, "");
|
||||
}
|
||||
item.setName(LobbySystem.getMessage().parse("ADVENT_CALENDAR_DAY", player, present.getDay()));
|
||||
itemList.add(new SWListInv.SWListEntry<>(item, present));
|
||||
});
|
||||
SWInventory swInventory = new SWInventory(player, 27, LobbySystem.getMessage().parse("ADVENT_CALENDAR_TITLE", player));
|
||||
for (int i = 0; i < itemList.size(); i++) {
|
||||
swInventory.setItem(i, itemList.get(i).getItem());
|
||||
}
|
||||
swInventory.open();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.lobby.special.advent;
|
||||
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.lobby.listener.BasicListener;
|
||||
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 AdventListener extends BasicListener {
|
||||
|
||||
public static final int ADVENT_SLOT = 7;
|
||||
public static final SWItem ADVENT = SWItem.getPlayerSkull("MHF_Present1");
|
||||
static {
|
||||
ADVENT.setName("§fAdvent");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void handlePlayerInteract(PlayerInteractEvent event) {
|
||||
ItemStack item = event.getItem();
|
||||
if(item == null)
|
||||
return;
|
||||
|
||||
if (item.getType() == Material.PLAYER_HEAD && item.getItemMeta() != null && item.getItemMeta().getDisplayName().equals("§fAdvent")) {
|
||||
event.getPlayer().performCommand("advent");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
if (!AdventsCalendar.active()) {
|
||||
return;
|
||||
}
|
||||
e.getPlayer().getInventory().setItem(ADVENT_SLOT, ADVENT.getItemStack());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.lobby.special.advent;
|
||||
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
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;
|
||||
|
||||
public class AdventsCalendar {
|
||||
|
||||
private static List<Present> presentList = new ArrayList<>();
|
||||
|
||||
private static File file = new File(LobbySystem.getPlugin().getDataFolder(), "presents.yml");
|
||||
private static FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
public static void init() {
|
||||
new AdventCommand();
|
||||
new AdventListener();
|
||||
new PresentClickListener();
|
||||
}
|
||||
|
||||
static {
|
||||
for (int i = 1; i <= 31; i++) {
|
||||
if (i > 24 && i < 31) continue;
|
||||
ConfigurationSection section = fileConfiguration.getConfigurationSection(i + "");
|
||||
if (section == null) {
|
||||
section = fileConfiguration.createSection(i + "");
|
||||
}
|
||||
presentList.add(new Present(i, section));
|
||||
if (i == 24) {
|
||||
presentList.add(new Present(25, section));
|
||||
presentList.add(new Present(26, section));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Present> getPresentList() {
|
||||
return presentList;
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
long time = System.currentTimeMillis();
|
||||
try {
|
||||
fileConfiguration.save(file);
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.lobby.special.advent;
|
||||
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import de.steamwar.sql.NodeMember;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Present {
|
||||
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
@Data
|
||||
private static class Point {
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
public static Point toPoint(Location location) {
|
||||
return new Point(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
}
|
||||
|
||||
private final List<Map<String, Integer>> blockList;
|
||||
private final Set<Point> locations = new HashSet<>();
|
||||
|
||||
@Getter
|
||||
private final int day;
|
||||
|
||||
@Getter
|
||||
private final int schematicId;
|
||||
|
||||
private Set<Player> players = new HashSet<>();
|
||||
|
||||
public Present(int day, ConfigurationSection configurationSection) {
|
||||
this.day = day;
|
||||
if (configurationSection.contains("schematicId")) {
|
||||
schematicId = configurationSection.getInt("schematicId");
|
||||
} else {
|
||||
configurationSection.set("schematicId", -1);
|
||||
schematicId = -1;
|
||||
}
|
||||
List<?> blockList = configurationSection.getList("blocks");
|
||||
if (blockList == null) {
|
||||
blockList = new ArrayList<>();
|
||||
configurationSection.set("blocks", blockList);
|
||||
}
|
||||
this.blockList = (List<Map<String, Integer>>) blockList;
|
||||
blockList.forEach(object -> {
|
||||
if (!(object instanceof Map)) return;
|
||||
Map<String, ?> map = (Map<String, ?>) object;
|
||||
locations.add(new Point((int) map.get("x"), (int) map.get("y"), (int) map.get("z")));
|
||||
});
|
||||
// generate();
|
||||
}
|
||||
|
||||
public void click(Player player, SteamwarUser user, int day, Location location) {
|
||||
if (day != this.day) return;
|
||||
if (!locations.contains(Point.toPoint(location))) return;
|
||||
if (NodeMember.getNodeMember(schematicId, user.getId()) != null) return;
|
||||
NodeMember.createNodeMember(schematicId, user.getId());
|
||||
LobbySystem.getMessage().send("ADVENT_CALENDAR_OPEN", player, SchematicNode.getSchematicNode(schematicId).getName());
|
||||
player.playSound(location, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
|
||||
}
|
||||
|
||||
public void removePlayer(Player player) {
|
||||
players.remove(player);
|
||||
locations.forEach(p -> {
|
||||
Location loc = new Location(WORLD, p.x, p.y, p.z);
|
||||
BlockData blockData = loc.getBlock().getBlockData();
|
||||
player.sendBlockChange(loc, blockData);
|
||||
});
|
||||
}
|
||||
|
||||
public void addPlayer(Player player) {
|
||||
players.add(player);
|
||||
locations.forEach(p -> {
|
||||
Location loc = new Location(WORLD, p.x, p.y, p.z);
|
||||
player.sendBlockChange(loc, BEDROCK);
|
||||
});
|
||||
}
|
||||
|
||||
public void edit(Player player, Location location) {
|
||||
if (!players.contains(player)) return;
|
||||
Point point = Point.toPoint(location);
|
||||
if (locations.contains(point)) {
|
||||
locations.remove(point);
|
||||
} else {
|
||||
locations.add(point);
|
||||
}
|
||||
generate();
|
||||
Bukkit.getScheduler().runTaskLater(LobbySystem.getPlugin(), () -> {
|
||||
BlockData blockData = location.getBlock().getBlockData();
|
||||
players.forEach(pl -> {
|
||||
if (pl == player) return;
|
||||
if (locations.contains(point)) {
|
||||
pl.sendBlockChange(location, blockData);
|
||||
} else {
|
||||
pl.sendBlockChange(location, BEDROCK);
|
||||
}
|
||||
});
|
||||
player.sendBlockChange(location, blockData);
|
||||
locations.forEach(p -> {
|
||||
Location loc = new Location(WORLD, p.x, p.y, p.z);
|
||||
player.sendBlockChange(loc, BEDROCK);
|
||||
});
|
||||
}, 4);
|
||||
}
|
||||
|
||||
private static final BlockData BEDROCK = Material.BEDROCK.createBlockData();
|
||||
|
||||
private void generate() {
|
||||
blockList.clear();
|
||||
locations.forEach(point -> {
|
||||
Map<String, Integer> pos = new HashMap<>();
|
||||
pos.put("x", point.x);
|
||||
pos.put("y", point.y);
|
||||
pos.put("z", point.z);
|
||||
blockList.add(pos);
|
||||
});
|
||||
AdventsCalendar.save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.lobby.special.advent;
|
||||
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import de.steamwar.lobby.listener.BasicListener;
|
||||
import de.steamwar.sql.NodeMember;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class PresentClickListener extends BasicListener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
LocalDate localDate = LocalDate.now();
|
||||
int day = localDate.getDayOfMonth();
|
||||
|
||||
if (!AdventsCalendar.active()) {
|
||||
return;
|
||||
}
|
||||
AdventsCalendar.getPresentList().forEach(present -> {
|
||||
if (present.getDay() != day) return;
|
||||
if (NodeMember.getNodeMember(present.getSchematicId(), SteamwarUser.get(event.getPlayer().getUniqueId()).getId()) != null) return;
|
||||
LobbySystem.getMessage().send("ADVENT_CALENDAR_MESSAGE", event.getPlayer());
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null) return;
|
||||
|
||||
LocalDate localDate = LocalDate.now();
|
||||
int day = localDate.getDayOfMonth();
|
||||
|
||||
if (!AdventsCalendar.active()) {
|
||||
return;
|
||||
}
|
||||
|
||||
AdventsCalendar.getPresentList().forEach(present -> {
|
||||
present.click(event.getPlayer(), SteamwarUser.get(event.getPlayer().getUniqueId()), day, block.getLocation());
|
||||
});
|
||||
}
|
||||
|
||||
// @EventHandler
|
||||
public void onPresentSetup(PlayerInteractEvent event) {
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null) return;
|
||||
AdventsCalendar.getPresentList().forEach(present -> {
|
||||
present.edit(event.getPlayer(), block.getLocation());
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package de.steamwar.lobby.special.easter;
|
||||
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Skull;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.profile.PlayerProfile;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Egg {
|
||||
|
||||
private static final World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
private final String message;
|
||||
private final EggDifficulty difficulty;
|
||||
|
||||
private Optional<PlayerProfile> playerProfile = null;
|
||||
|
||||
public Egg(Map<String, ?> config) {
|
||||
this.x = (int) config.get("x");
|
||||
this.y = (int) config.get("y");
|
||||
this.z = (int) config.get("z");
|
||||
this.message = (String) config.get("name");
|
||||
this.difficulty = EggDifficulty.valueOf(((String) config.get("difficulty")).toUpperCase());
|
||||
}
|
||||
|
||||
public Vector getVector() {
|
||||
return new Vector(x, y, z);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public EggDifficulty getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
if (block.getType() != Material.PLAYER_HEAD && block.getType() != Material.PLAYER_WALL_HEAD) {
|
||||
System.out.println("Block is not a skull: " + block.getType() + " " + x + "," + y + "," + z);
|
||||
return null;
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
public SWItem getItem(Player player, boolean found) {
|
||||
if (playerProfile == null) {
|
||||
Block block = getBlock();
|
||||
if (block == null) {
|
||||
playerProfile = Optional.empty();
|
||||
return null;
|
||||
}
|
||||
|
||||
Skull skull = (Skull) block.getState();
|
||||
PlayerProfile playerProfile = skull.getOwnerProfile();
|
||||
if (playerProfile == null) {
|
||||
this.playerProfile = Optional.empty();
|
||||
return null;
|
||||
}
|
||||
this.playerProfile = Optional.of(playerProfile);
|
||||
}
|
||||
|
||||
if (!playerProfile.isPresent()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SWItem swItem;
|
||||
if (found) {
|
||||
swItem = new SWItem();
|
||||
ItemStack itemStack = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();
|
||||
skullMeta.setOwnerProfile(playerProfile.get());
|
||||
itemStack.setItemMeta(skullMeta);
|
||||
swItem.setItemStack(itemStack);
|
||||
} else {
|
||||
swItem = SWItem.getPlayerSkull("MHF_Question");
|
||||
}
|
||||
|
||||
swItem.setLore(Arrays.asList(LobbySystem.getMessage().parse(difficulty.getMessage(), player)));
|
||||
try {
|
||||
swItem.setName("§f" + LobbySystem.getMessage().parse(message, player));
|
||||
} catch (Exception e) {
|
||||
swItem.setName("§f" + message);
|
||||
}
|
||||
return swItem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package de.steamwar.lobby.special.easter;
|
||||
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import de.steamwar.lobby.listener.BasicListener;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class EggClickListener extends BasicListener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
||||
return;
|
||||
}
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null) {
|
||||
return;
|
||||
}
|
||||
Vector vector = block.getLocation().toVector();
|
||||
Egg egg = null;
|
||||
int index = -1;
|
||||
for (Egg egg1 : EggHunt.getEggList()) {
|
||||
index++;
|
||||
if (egg1.getVector().equals(vector)) {
|
||||
egg = egg1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (egg == null) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
String found = UserConfig.getConfig(player.getUniqueId(), EggHunt.EGG_HUNT_CONFIG_KEY);
|
||||
if (found == null) {
|
||||
found = "";
|
||||
}
|
||||
StringBuilder builder = new StringBuilder(found);
|
||||
while (builder.length() <= index) {
|
||||
builder.append("0");
|
||||
}
|
||||
if (builder.charAt(index) == '1') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
player.sendTitle(LobbySystem.getMessage().parse(egg.getDifficulty().getMessage(), player), LobbySystem.getMessage().parse(egg.getMessage(), player), 0, 40, 5);
|
||||
} catch (Exception e) {
|
||||
player.sendTitle(LobbySystem.getMessage().parse(egg.getDifficulty().getMessage(), player), egg.getMessage(), 0, 40, 5);
|
||||
}
|
||||
|
||||
player.spawnParticle(Particle.END_ROD, block.getLocation().add(0.5, 0.5, 0.5), 10, 0.5, 0.5, 0.5, 0.1);
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.25f, 1.0f);
|
||||
|
||||
builder.setCharAt(index, '1');
|
||||
UserConfig.updatePlayerConfig(player.getUniqueId(), EggHunt.EGG_HUNT_CONFIG_KEY, builder.toString());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package de.steamwar.lobby.special.easter;
|
||||
|
||||
public enum EggDifficulty {
|
||||
EASY("DIFFICULTY_EASY"),
|
||||
MEDIUM("DIFFICULTY_MEDIUM"),
|
||||
HARD("DIFFICULTY_HARD"),
|
||||
EXTREME("DIFFICULTY_EXTREME"),
|
||||
ADVANCED("DIFFICULTY_ADVANCED");
|
||||
|
||||
private final String message;
|
||||
|
||||
EggDifficulty(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package de.steamwar.lobby.special.easter;
|
||||
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class EggHunt {
|
||||
|
||||
private static List<Egg> eggList = new ArrayList<>();
|
||||
|
||||
public static final String EGG_HUNT_CONFIG_KEY = "egghunt2023";
|
||||
|
||||
public static void init() {
|
||||
new EggHuntCommand();
|
||||
new EggClickListener();
|
||||
new EggHuntListener();
|
||||
}
|
||||
|
||||
static {
|
||||
File file = new File(LobbySystem.getPlugin().getDataFolder(), "eggs.yml");
|
||||
FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
fileConfiguration.getList("eggs")
|
||||
.forEach(o -> {
|
||||
if (!(o instanceof Map)) return;
|
||||
eggList.add(new Egg((Map) o));
|
||||
});
|
||||
}
|
||||
|
||||
public static List<Egg> getEggList() {
|
||||
return eggList;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 = 8;
|
||||
public static final ItemStack EASTER_HUNT = new ItemBuilder(Material.DRAGON_EGG, 1).setDisplayName("§fEaster 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("§fEaster Hunt")) {
|
||||
event.getPlayer().performCommand("egg");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
e.getPlayer().getInventory().setItem(EASTER_EGG_SLOT, EASTER_HUNT);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user