Add BauSystem module

Fix ci java version
Fix LinkageProcessor
This commit is contained in:
2024-08-05 13:28:50 +02:00
parent 41d31e6c9c
commit 3366a30b0c
526 changed files with 43550 additions and 149479 deletions
@@ -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);
}
}