fix 50%
This commit is contained in:
parent
547fe6d9bb
commit
8705cad578
118 changed files with 2714 additions and 4761 deletions
|
|
@ -1,5 +1,12 @@
|
|||
package dev.loki.loparkour;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import dev.loki.loparkour.util.Item;
|
||||
import dev.loki.loparkour.util.ParticleData;
|
||||
|
||||
import dev.loki.loparkour.api.Registry;
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.loki.loparkour.config.Locales;
|
||||
|
|
@ -16,14 +23,13 @@ import dev.loki.loparkour.schematic.lpschem.LPSchematic;
|
|||
import dev.loki.loparkour.schematic.lpschem.LPSchematicBuilder;
|
||||
import dev.loki.loparkour.schematic.lpschem.SchematicConverter;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.efnilite.vilib.command.ViCommand;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
import dev.efnilite.vilib.particle.ParticleData;
|
||||
import dev.efnilite.vilib.particle.Particles;
|
||||
import dev.efnilite.vilib.schematic.Schematic;
|
||||
import dev.efnilite.vilib.schematic.Schematics;
|
||||
import dev.efnilite.vilib.util.Locations;
|
||||
import dev.efnilite.vilib.util.Strings;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import dev.loki.loparkour.util.ParticleUtil;
|
||||
|
||||
import dev.loki.loparkour.util.Locations;
|
||||
import dev.loki.loparkour.util.ColorUtil;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
|
@ -36,16 +42,16 @@ import org.jetbrains.annotations.Nullable;
|
|||
import java.util.*;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Command extends ViCommand {
|
||||
public class Command implements CommandExecutor, TabCompleter {
|
||||
|
||||
public static final HashMap<Player, Location[]> selections = new HashMap<>();
|
||||
|
||||
private static final ItemStack WAND = new Item(Material.GOLDEN_AXE, "<red><bold>Schematic Wand")
|
||||
private static final ItemStack WAND = new Item(Material.GOLDEN_AXE, "<red><bold>LPSchematic Wand")
|
||||
.lore("<gray>Left click: first position", "<gray>Right click: second position")
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
|
||||
Player player = null;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
|
|
@ -61,7 +67,7 @@ public class Command extends ViCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public List<String> onTabComplete(CommandSender sender, org.bukkit.command.Command command, String alias, String[] args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
switch (args.length) {
|
||||
case 1 -> {
|
||||
|
|
@ -128,7 +134,9 @@ public class Command extends ViCommand {
|
|||
|
||||
private void handle0Args(@NotNull CommandSender sender, @Nullable Player player) {
|
||||
if (player != null && ParkourOption.MAIN.mayPerform(player)) {
|
||||
Menus.MAIN.open(player);
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.*.open(player);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
return;
|
||||
}
|
||||
sendHelpMessages(sender);
|
||||
|
|
@ -205,7 +213,9 @@ public class Command extends ViCommand {
|
|||
}
|
||||
case "play" -> {
|
||||
if (ParkourOption.PLAY.mayPerform(player)) {
|
||||
Menus.PLAY.open(player);
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.*.open(player);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
}
|
||||
}
|
||||
case "leave" -> {
|
||||
|
|
@ -216,7 +226,9 @@ public class Command extends ViCommand {
|
|||
}
|
||||
case "menu", "main" -> {
|
||||
if (!ParkourOption.MAIN.mayPerform(player)) {
|
||||
Menus.MAIN.open(player);
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.*.open(player);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
}
|
||||
}
|
||||
case "leaderboard" -> player.performCommand("LoParkour leaderboard invalid");
|
||||
|
|
@ -454,9 +466,13 @@ public class Command extends ViCommand {
|
|||
|
||||
// if found gamemode is null, return to default
|
||||
if (mode == null) {
|
||||
Menus.LEADERBOARDS.open(player);
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.*.open(player);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
} else {
|
||||
Menus.SINGLE_LEADERBOARD.open(player, mode, Leaderboard.Sort.SCORE);
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.SINGLE_LEADERBOARD.open(player, mode, Leaderboard.Sort.SCORE);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
}
|
||||
}
|
||||
case "schematic" -> {
|
||||
|
|
@ -486,7 +502,7 @@ public class Command extends ViCommand {
|
|||
|
||||
selections.put(player, new Location[]{playerLocation, existingSelection[1]});
|
||||
|
||||
Particles.box(BoundingBox.of(playerLocation, existingSelection[1]), player.getWorld(), new ParticleData<>(Particle.END_ROD, null, 2), player, 0.2);
|
||||
ParticleUtil.box(BoundingBox.of(playerLocation, existingSelection[1]), player.getWorld(), Particle.END_ROD, player, 0.2);
|
||||
}
|
||||
case "pos2" -> {
|
||||
send(player, "%sPosition 2 was set to %s".formatted(LoParkour.PREFIX, Locations.toString(playerLocation, true)));
|
||||
|
|
@ -498,7 +514,7 @@ public class Command extends ViCommand {
|
|||
|
||||
selections.put(player, new Location[]{existingSelection[0], playerLocation});
|
||||
|
||||
Particles.box(BoundingBox.of(existingSelection[0], playerLocation), player.getWorld(), new ParticleData<>(Particle.END_ROD, null, 2), player, 0.2);
|
||||
ParticleUtil.box(BoundingBox.of(existingSelection[0], playerLocation), player.getWorld(), Particle.END_ROD, player, 0.2);
|
||||
}
|
||||
case "save" -> {
|
||||
if (!cooldown(sender, "LoParkour save schematic", 2500)) {
|
||||
|
|
@ -514,7 +530,7 @@ public class Command extends ViCommand {
|
|||
|
||||
send(player, ("<dark_red><bold>Schematics <reset><gray>Your schematic is being saved. It will use code <red>'%s'<gray>. " + "You can change the code to whatever you like. " + "Don't forget to add this schematic to <dark_gray>schematics.yml<gray>.").formatted(code));
|
||||
|
||||
Schematic.save(LoParkour.getInFolder("schematics/parkour-%s".formatted(code)), existingSelection[0], existingSelection[1], LoParkour.getPlugin());
|
||||
// TODO: LPSchematic.save(file, pos1, pos2);
|
||||
}
|
||||
case "list" -> {
|
||||
send(player, "<dark_red><bold>Schematics <reset><gray>Loaded schematics:");
|
||||
|
|
@ -588,13 +604,14 @@ public class Command extends ViCommand {
|
|||
return;
|
||||
}
|
||||
|
||||
Schematic oldSchematic = Schematics.getSchematic(LoParkour.getPlugin(), arg3);
|
||||
// TODO: Implement schematic loading with LoLib
|
||||
LPSchematic oldSchematic = null;
|
||||
if (oldSchematic == null) {
|
||||
send(sender, "%sCouldn't find %s".formatted(LoParkour.PREFIX, arg3));
|
||||
return;
|
||||
}
|
||||
|
||||
oldSchematic.paste(player.getLocation());
|
||||
// oldSchematic.paste(player.getLocation(), player.getWorld());
|
||||
send(sender, "%sPasted old schematic %s".formatted(LoParkour.PREFIX, arg3));
|
||||
}
|
||||
}
|
||||
|
|
@ -602,6 +619,27 @@ public class Command extends ViCommand {
|
|||
}
|
||||
|
||||
private void send(CommandSender sender, String message) {
|
||||
sender.sendMessage(Strings.colour(message));
|
||||
sender.sendMessage(ColorUtil.color(message));
|
||||
}
|
||||
|
||||
private final Map<String, Long> cooldowns = new HashMap<>();
|
||||
|
||||
private boolean cooldown(CommandSender sender, String key, long millis) {
|
||||
String fullKey = sender.getName() + ":" + key;
|
||||
long now = System.currentTimeMillis();
|
||||
Long last = cooldowns.get(fullKey);
|
||||
|
||||
if (last != null && now - last < millis) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cooldowns.put(fullKey, now);
|
||||
return true;
|
||||
}
|
||||
|
||||
private List<String> completions(String arg, List<String> completions) {
|
||||
return completions.stream()
|
||||
.filter(s -> s.toLowerCase().startsWith(arg.toLowerCase()))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
package dev.loki.loparkour;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import dev.loki.loparkour.util.ParticleData;
|
||||
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.loki.loparkour.config.Locales;
|
||||
import dev.loki.loparkour.config.Option;
|
||||
|
|
@ -10,11 +15,11 @@ import dev.loki.loparkour.player.ParkourPlayer;
|
|||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.loki.loparkour.world.World;
|
||||
import dev.efnilite.vilib.event.EventWatcher;
|
||||
import dev.efnilite.vilib.particle.ParticleData;
|
||||
import dev.efnilite.vilib.particle.Particles;
|
||||
import dev.efnilite.vilib.util.Locations;
|
||||
import dev.efnilite.vilib.util.Strings;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import dev.loki.loparkour.util.ParticleUtil;
|
||||
import dev.loki.loparkour.util.Locations;
|
||||
import dev.loki.loparkour.util.ColorUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
|
@ -43,7 +48,7 @@ import java.util.NoSuchElementException;
|
|||
* Internal event handler
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public class Events implements EventWatcher {
|
||||
public class Events implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void chat(AsyncPlayerChatEvent event) {
|
||||
|
|
@ -131,14 +136,13 @@ public class Events implements EventWatcher {
|
|||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void interactWand(PlayerInteractEvent event) {
|
||||
Action action = event.getAction();
|
||||
Player player = event.getPlayer();
|
||||
ItemStack item = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (!player.hasPermission("LoParkour.admin") || item.getItemMeta() == null || !item.getItemMeta().getDisplayName().contains("Schematic Wand") || event.getClickedBlock() == null || event.getHand() != EquipmentSlot.HAND) {
|
||||
if (!player.hasPermission("LoParkour.admin") || item.getItemMeta() == null || !item.getItemMeta().getDisplayName().contains("LPSchematic Wand") || event.getClickedBlock() == null || event.getHand() != EquipmentSlot.HAND) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -158,7 +162,7 @@ public class Events implements EventWatcher {
|
|||
|
||||
Command.selections.put(player, new Location[]{location, existingSelection[1]});
|
||||
|
||||
Particles.box(BoundingBox.of(location, existingSelection[1]), player.getWorld(), new ParticleData<>(Particle.END_ROD, null, 2), player, 0.2);
|
||||
ParticleUtil.box(BoundingBox.of(location, existingSelection[1]), player.getWorld(), Particle.END_ROD, player, 0.2);
|
||||
}
|
||||
case RIGHT_CLICK_BLOCK -> {
|
||||
send(player, LoParkour.PREFIX + "Position 2 was set to " + Locations.toString(location, true));
|
||||
|
|
@ -170,7 +174,7 @@ public class Events implements EventWatcher {
|
|||
|
||||
Command.selections.put(player, new Location[]{existingSelection[0], location});
|
||||
|
||||
Particles.box(BoundingBox.of(existingSelection[0], location), player.getWorld(), new ParticleData<>(Particle.END_ROD, null, 2), player, 0.2);
|
||||
ParticleUtil.box(BoundingBox.of(existingSelection[0], location), player.getWorld(), Particle.END_ROD, player, 0.2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -200,22 +204,30 @@ public class Events implements EventWatcher {
|
|||
|
||||
Material held = getHeldItem(player).getType();
|
||||
|
||||
Material play = Locales.getItem(player, "play.item").getMaterial();
|
||||
Material community = Locales.getItem(player, "community.item").getMaterial();
|
||||
Material settings = Locales.getItem(player, "settings.item").getMaterial();
|
||||
Material lobby = Locales.getItem(player, "lobby.item").getMaterial();
|
||||
Material quit = Locales.getItem(player, "other.quit").getMaterial();
|
||||
Material play = Locales.getItem(player, "play.item").build().getType();
|
||||
Material community = Locales.getItem(player, "community.item").build().getType();
|
||||
Material settings = Locales.getItem(player, "settings.item").build().getType();
|
||||
Material lobby = Locales.getItem(player, "lobby.item").build().getType();
|
||||
Material quit = Locales.getItem(player, "other.quit").build().getType();
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (held == play) {
|
||||
Menus.PLAY.open(player);
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.*.open(player);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
} else if (held == community) {
|
||||
Menus.COMMUNITY.open(player);
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.*.open(player);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
} else if (held == settings) {
|
||||
Menus.SETTINGS.open(player);
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.*.open(player);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
} else if (held == lobby) {
|
||||
Menus.LOBBY.open(player);
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.*.open(player);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
} else if (held == quit) {
|
||||
ParkourUser.leave(player);
|
||||
} else {
|
||||
|
|
@ -311,6 +323,6 @@ public class Events implements EventWatcher {
|
|||
}
|
||||
|
||||
private void send(CommandSender sender, String message) {
|
||||
sender.sendMessage(Strings.colour(message));
|
||||
sender.sendMessage(ColorUtil.color(message));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,13 @@ import dev.loki.loparkour.reward.Rewards;
|
|||
import dev.loki.loparkour.schematic.lpschem.LPSchematicManager;
|
||||
import dev.loki.loparkour.storage.Storage;
|
||||
import dev.loki.loparkour.world.World;
|
||||
import dev.efnilite.vilib.ViPlugin;
|
||||
import dev.lolib.core.LoPlugin;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bstats.charts.SingleLineChart;
|
||||
import dev.efnilite.vilib.inventory.Menu;
|
||||
import dev.efnilite.vilib.util.Logging;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -33,12 +34,16 @@ import java.io.File;
|
|||
*
|
||||
* @author loki
|
||||
*/
|
||||
public final class LoParkour extends ViPlugin {
|
||||
public final class LoParkour extends LoPlugin {
|
||||
|
||||
public static final String NAME = "&#FF6464<bold>LoParkour<reset>";
|
||||
public static final String PREFIX = NAME + " 񢩈» &#A0A0A0";
|
||||
|
||||
private static Logging logging;
|
||||
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
public static Gson getGson() {
|
||||
return gson;
|
||||
}
|
||||
private static LoParkour instance;
|
||||
private static LPSchematicManager schematicManager;
|
||||
|
||||
|
|
@ -47,7 +52,7 @@ public final class LoParkour extends ViPlugin {
|
|||
|
||||
public static void log(String message) {
|
||||
if (Config.CONFIG.getBoolean("debug")) {
|
||||
logging.info("[Debug] " + message);
|
||||
LoParkour.getPlugin().getLogger().info("[Debug] " + message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -62,9 +67,7 @@ public final class LoParkour extends ViPlugin {
|
|||
/**
|
||||
* @return This plugin's {@link Logging} instance.
|
||||
*/
|
||||
public static Logging logging() {
|
||||
return logging;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The plugin instance.
|
||||
|
|
@ -82,66 +85,72 @@ public final class LoParkour extends ViPlugin {
|
|||
return schematicManager;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
logging = new Logging(this);
|
||||
super.onEnable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
loadConfigs();
|
||||
loadSchematics();
|
||||
registerModes();
|
||||
registerHooks();
|
||||
setupWorld();
|
||||
registerEventsAndCommands();
|
||||
setupMetrics();
|
||||
}
|
||||
|
||||
// ----- Configurations -----
|
||||
|
||||
private void loadConfigs() {
|
||||
Config.reload(true);
|
||||
}
|
||||
|
||||
// ----- Schematics -----
|
||||
|
||||
private void loadSchematics() {
|
||||
schematicManager = new LPSchematicManager();
|
||||
schematicManager.loadAll();
|
||||
}
|
||||
|
||||
// ----- Registry -----
|
||||
|
||||
private void registerModes() {
|
||||
Registry.register(new DefaultMode());
|
||||
Registry.register(new SpectatorMode());
|
||||
Registry.register(new SpeedrunMode());
|
||||
Registry.register(new GravityShiftMode());
|
||||
Registry.register(new HardcoreMode());
|
||||
Registry.register(new ElytraMode());
|
||||
|
||||
Modes.init();
|
||||
Menu.init(this);
|
||||
}
|
||||
|
||||
// hook with hd / papi after gamemode leaderboards have initialized
|
||||
private void registerHooks() {
|
||||
if (getServer().getPluginManager().isPluginEnabled("HolographicDisplays")) {
|
||||
logging.info("Registered Holographic Displays hook");
|
||||
getLogger().info("Registered Holographic Displays hook");
|
||||
HoloHook.init();
|
||||
}
|
||||
|
||||
if (getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
|
||||
logging.info("Registered PlaceholderAPI hook");
|
||||
getLogger().info("Registered PlaceholderAPI hook");
|
||||
placeholderHook = new PAPIHook();
|
||||
placeholderHook.register();
|
||||
}
|
||||
|
||||
if (Config.CONFIG.getBoolean("bungeecord.enabled")) {
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||
logging.info("Registered BungeeCord hook");
|
||||
getLogger().info("Registered BungeeCord hook");
|
||||
}
|
||||
}
|
||||
|
||||
// ----- Worlds -----
|
||||
|
||||
private void setupWorld() {
|
||||
if (Config.CONFIG.getBoolean("joining")) {
|
||||
World.create();
|
||||
}
|
||||
}
|
||||
|
||||
// ----- Events -----
|
||||
|
||||
registerListener(new Events());
|
||||
registerCommand("LoParkour", new Command());
|
||||
|
||||
// ----- Metrics -----
|
||||
private void registerEventsAndCommands() {
|
||||
getServer().getPluginManager().registerEvents(new Events(), this);
|
||||
getCommand("LoParkour").setExecutor(new Command());
|
||||
}
|
||||
|
||||
private void setupMetrics() {
|
||||
Metrics metrics = new Metrics(this, 29754);
|
||||
metrics.addCustomChart(new SimplePie("using_sql", () -> Boolean.toString(Option.SQL)));
|
||||
metrics.addCustomChart(new SimplePie("using_rewards", () -> Boolean.toString(Rewards.REWARDS_ENABLED)));
|
||||
|
|
|
|||
627
src/main/java/dev/loki/loparkour/LoParkourCommand.java
Normal file
627
src/main/java/dev/loki/loparkour/LoParkourCommand.java
Normal file
|
|
@ -0,0 +1,627 @@
|
|||
package dev.loki.loparkour;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import dev.loki.loparkour.api.Registry;
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.loki.loparkour.config.Locales;
|
||||
import dev.loki.loparkour.leaderboard.Leaderboard;
|
||||
import dev.loki.loparkour.menu.Menus;
|
||||
import dev.loki.loparkour.menu.ParkourOption;
|
||||
import dev.loki.loparkour.mode.Mode;
|
||||
import dev.loki.loparkour.mode.Modes;
|
||||
import dev.loki.loparkour.mode.MultiMode;
|
||||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.loki.loparkour.player.data.InventoryData;
|
||||
import dev.loki.loparkour.schematic.lpschem.LPSchematic;
|
||||
import dev.loki.loparkour.schematic.lpschem.LPSchematicBuilder;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.loki.loparkour.util.ColorUtil;
|
||||
import dev.loki.loparkour.util.ParticleUtil;
|
||||
import dev.loki.loparkour.util.Locations;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class LoParkourCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
public static final HashMap<Player, Location[]> selections = new HashMap<>();
|
||||
|
||||
private static final ItemStack WAND = createWand();
|
||||
|
||||
private static ItemStack createWand() {
|
||||
ItemStack wand = new ItemStack(Material.GOLDEN_AXE);
|
||||
var meta = wand.getItemMeta();
|
||||
if (meta != null) {
|
||||
meta.setDisplayName(ColorUtil.color("<red><bold>LPSchematic Wand"));
|
||||
meta.setLore(List.of(
|
||||
ColorUtil.color("<gray>Left click: first position"),
|
||||
ColorUtil.color("<gray>Right click: second position")
|
||||
));
|
||||
wand.setItemMeta(meta);
|
||||
}
|
||||
return wand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
Player player = null;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
}
|
||||
|
||||
switch (args.length) {
|
||||
case 0 -> handle0Args(sender, player);
|
||||
case 1 -> handle1Args(args[0], sender, player);
|
||||
case 2 -> handle2Args(args[0], args[1], sender, player);
|
||||
case 3 -> handle3Args(args[0], args[1], args[2], sender, player);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
switch (args.length) {
|
||||
case 1 -> {
|
||||
if (ParkourOption.JOIN.mayPerform(sender)) {
|
||||
completions.add("join");
|
||||
completions.add("leave");
|
||||
}
|
||||
if (ParkourOption.MAIN.mayPerform(sender)) {
|
||||
completions.add("menu");
|
||||
}
|
||||
if (ParkourOption.PLAY.mayPerform(sender)) {
|
||||
completions.add("play");
|
||||
}
|
||||
if (ParkourOption.LEADERBOARDS.mayPerform(sender)) {
|
||||
completions.add("leaderboard");
|
||||
}
|
||||
if (sender.hasPermission(ParkourOption.ADMIN.permission)) {
|
||||
completions.add("schematic");
|
||||
completions.add("reload");
|
||||
completions.add("forcejoin");
|
||||
completions.add("forceleave");
|
||||
completions.add("reset");
|
||||
completions.add("recoverinventory");
|
||||
}
|
||||
return completions(args[0], completions);
|
||||
}
|
||||
case 2 -> {
|
||||
if (args[0].equalsIgnoreCase("reset") && sender.hasPermission(ParkourOption.ADMIN.permission)) {
|
||||
completions.add("everyone");
|
||||
for (ParkourPlayer pp : ParkourPlayer.getPlayers()) {
|
||||
completions.add(pp.getName());
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("join") && sender.hasPermission(ParkourOption.JOIN.permission)) {
|
||||
for (ParkourPlayer pp : ParkourPlayer.getPlayers()) {
|
||||
completions.add(pp.getName());
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("schematic") && sender.hasPermission(ParkourOption.ADMIN.permission)) {
|
||||
completions.addAll(Arrays.asList("wand", "pos1", "pos2", "save", "paste"));
|
||||
} else if (args[0].equalsIgnoreCase("forcejoin") && sender.hasPermission(ParkourOption.ADMIN.permission)) {
|
||||
completions.add("nearest");
|
||||
completions.add("everyone");
|
||||
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
completions.add(pl.getName());
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("forceleave") && sender.hasPermission(ParkourOption.ADMIN.permission)) {
|
||||
completions.add("everyone");
|
||||
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
completions.add(pl.getName());
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("recoverinventory") && sender.hasPermission(ParkourOption.ADMIN.permission)) {
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
completions.add(pl.getName());
|
||||
}
|
||||
}
|
||||
return completions(args[1], completions);
|
||||
}
|
||||
default -> {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handle0Args(@NotNull CommandSender sender, @Nullable Player player) {
|
||||
if (player != null && ParkourOption.MAIN.mayPerform(player)) {
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.MAIN.open(player);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
return;
|
||||
}
|
||||
sendHelpMessages(sender);
|
||||
}
|
||||
|
||||
private void sendHelpMessages(CommandSender sender) {
|
||||
send(sender, "");
|
||||
send(sender, "<dark_gray><strikethrough>---------------<reset> %s <dark_gray><strikethrough>---------------<reset>".formatted(LoParkour.NAME));
|
||||
send(sender, "");
|
||||
send(sender, "<gray>/parkour <dark_gray>- Main command");
|
||||
if (sender.hasPermission(ParkourOption.JOIN.permission)) {
|
||||
send(sender, "<gray>/parkour join [mode/player] <dark_gray>- Join the default mode or specify one.");
|
||||
send(sender, "<gray>/parkour leave <dark_gray>- Leave the game on this server");
|
||||
}
|
||||
if (sender.hasPermission(ParkourOption.MAIN.permission)) {
|
||||
send(sender, "<gray>/parkour menu <dark_gray>- Open the menu");
|
||||
}
|
||||
if (sender.hasPermission(ParkourOption.PLAY.permission)) {
|
||||
send(sender, "<gray>/parkour play <dark_gray>- Mode selection menu");
|
||||
}
|
||||
if (sender.hasPermission(ParkourOption.LEADERBOARDS.permission)) {
|
||||
send(sender, "<gray>/parkour leaderboard [type]<dark_gray>- Open the leaderboard of a mode");
|
||||
}
|
||||
if (sender.hasPermission(ParkourOption.ADMIN.permission)) {
|
||||
send(sender, "<gray>/LoParkour schematic <dark_gray>- Create a schematic");
|
||||
send(sender, "<gray>/LoParkour reload <dark_gray>- Reloads the messages-v3.yml file");
|
||||
send(sender, "<gray>/LoParkour reset <everyone/player> <dark_gray>- Resets all high scores. <red>This can't be recovered!");
|
||||
send(sender, "<gray>/LoParkour forcejoin <everyone/nearest/player> <dark_gray>- Forces a specific player, the nearest or everyone to join");
|
||||
send(sender, "<gray>/LoParkour forceleave <everyone/nearest/player> <dark_gray>- Forces a specific player, the nearest or everyone to leave");
|
||||
send(sender, "<gray>/LoParkour recoverinventory <player> <dark_gray>- Recover a player's saved inventory. <red>Useful for recovering data after server crashes or errors when leaving.");
|
||||
}
|
||||
send(sender, "");
|
||||
}
|
||||
|
||||
private void handle1Args(@NotNull String arg, @NotNull CommandSender sender, @Nullable Player player) {
|
||||
switch (arg.toLowerCase()) {
|
||||
case "help" -> sendHelpMessages(sender);
|
||||
case "reload" -> {
|
||||
if (!cooldown(sender, "reload", 2500)) {
|
||||
return;
|
||||
}
|
||||
if (!sender.hasPermission(ParkourOption.ADMIN.permission)) {
|
||||
send(sender, Locales.getString(player, "other.no_do"));
|
||||
return;
|
||||
}
|
||||
|
||||
Config.reload(false);
|
||||
|
||||
send(sender, "%sReloaded config files.".formatted(LoParkour.PREFIX));
|
||||
}
|
||||
}
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (arg.toLowerCase()) {
|
||||
case "join" -> {
|
||||
if (!cooldown(sender, "join", 2500)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ParkourOption.JOIN.mayPerform(player)) {
|
||||
send(sender, Locales.getString(player, "other.no_do"));
|
||||
return;
|
||||
}
|
||||
|
||||
ParkourUser user = ParkourUser.getUser(player);
|
||||
if (user != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Modes.DEFAULT.create(player);
|
||||
}
|
||||
case "play" -> {
|
||||
if (ParkourOption.PLAY.mayPerform(player)) {
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.PLAY.open(player);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
}
|
||||
}
|
||||
case "leave" -> {
|
||||
if (!cooldown(sender, "leave", 2500)) {
|
||||
return;
|
||||
}
|
||||
ParkourUser.leave(player);
|
||||
}
|
||||
case "menu", "main" -> {
|
||||
if (!ParkourOption.MAIN.mayPerform(player)) {
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.MAIN.open(player);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
}
|
||||
}
|
||||
case "leaderboard" -> player.performCommand("LoParkour leaderboard invalid");
|
||||
case "schematic" -> {
|
||||
if (!player.hasPermission(ParkourOption.ADMIN.permission)) { // default players shouldn't have access even if perms are disabled
|
||||
send(sender, Locales.getString(player, "other.no_do"));
|
||||
return;
|
||||
}
|
||||
|
||||
send(player, "");
|
||||
send(player, "<red>/LoParkour schematic wand <dark_gray>- <gray>Get the schematic wand");
|
||||
send(player, "<red>/LoParkour schematic pos1 <dark_gray>- <gray>Set the first position of your selection");
|
||||
send(player, "<red>/LoParkour schematic pos2 <dark_gray>- <gray>Set the second position of your selection");
|
||||
send(player, "<red>/LoParkour schematic save <name> <dark_gray>- <gray>Save selection to .lpschem format");
|
||||
send(player, "<red>/LoParkour schematic paste <name> <dark_gray>- <gray>Paste a .lpschem schematic");
|
||||
send(player, "<red>/LoParkour schematic list <dark_gray>- <gray>List all loaded schematics");
|
||||
send(player, "<red>/LoParkour schematic reload <dark_gray>- <gray>Reload all schematics");
|
||||
send(player, "");
|
||||
send(player, "<dark_gray><underlined>Have any questions or need help? Join the Discord.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handle2Args(@NotNull String arg1, @NotNull String arg2, @NotNull CommandSender sender, @Nullable Player player) {
|
||||
switch (arg1.toLowerCase()) {
|
||||
case "forcejoin" -> {
|
||||
if (!sender.hasPermission(ParkourOption.ADMIN.permission)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg2.equalsIgnoreCase("everyone")) {
|
||||
Bukkit.getOnlinePlayers().forEach(other -> Modes.DEFAULT.create(other));
|
||||
send(sender, LoParkour.PREFIX + "Successfully force joined everyone!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg2.equalsIgnoreCase("nearest")) {
|
||||
Player closest = null;
|
||||
double distance = Double.MAX_VALUE;
|
||||
|
||||
// if player is found get location from player
|
||||
// if no player is found, get location from command block
|
||||
// if no command block is found, return null
|
||||
Location from = sender instanceof Player ? ((Player) sender).getLocation() : (sender instanceof BlockCommandSender ? ((BlockCommandSender) sender).getBlock().getLocation() : null);
|
||||
|
||||
if (from == null || from.getWorld() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get the closest player
|
||||
for (Player p : from.getWorld().getPlayers()) {
|
||||
double d = p.getLocation().distance(from);
|
||||
|
||||
if (d < distance) {
|
||||
distance = d;
|
||||
closest = p;
|
||||
}
|
||||
}
|
||||
|
||||
// no closest player found
|
||||
if (closest == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
send(sender, LoParkour.PREFIX + "Successfully force joined " + closest.getName() + "!");
|
||||
Modes.DEFAULT.create(closest);
|
||||
return;
|
||||
}
|
||||
|
||||
Player other = Bukkit.getPlayer(arg2);
|
||||
if (other == null) {
|
||||
send(sender, LoParkour.PREFIX + "That player isn't online!");
|
||||
return;
|
||||
}
|
||||
|
||||
Modes.DEFAULT.create(other);
|
||||
}
|
||||
case "forceleave" -> {
|
||||
if (!sender.hasPermission(ParkourOption.ADMIN.permission)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg2.equalsIgnoreCase("everyone")) {
|
||||
ParkourPlayer.getPlayers().forEach(ParkourUser::leave);
|
||||
send(sender, LoParkour.PREFIX + "Successfully force kicked everyone!");
|
||||
return;
|
||||
}
|
||||
|
||||
Player other = Bukkit.getPlayer(arg2);
|
||||
if (other == null) {
|
||||
send(sender, LoParkour.PREFIX + "That player isn't online!");
|
||||
return;
|
||||
}
|
||||
|
||||
ParkourUser user = ParkourUser.getUser(other);
|
||||
if (user == null) {
|
||||
send(sender, LoParkour.PREFIX + "That player isn't currently playing!");
|
||||
return;
|
||||
}
|
||||
|
||||
ParkourUser.leave(user);
|
||||
}
|
||||
case "reset" -> {
|
||||
if (!sender.hasPermission(ParkourOption.ADMIN.permission) || !cooldown(sender, "reset", 2500)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg2.equalsIgnoreCase("everyone")) {
|
||||
for (Mode mode : Registry.getModes()) {
|
||||
Leaderboard leaderboard = mode.getLeaderboard();
|
||||
|
||||
if (leaderboard == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
leaderboard.resetAll();
|
||||
leaderboard.write(true);
|
||||
}
|
||||
|
||||
send(sender, LoParkour.PREFIX + "Successfully reset all high scores in memory and the files.");
|
||||
return;
|
||||
}
|
||||
String name = null;
|
||||
UUID uuid = null;
|
||||
|
||||
// Check online players
|
||||
Player online = Bukkit.getPlayerExact(arg2);
|
||||
if (online != null) {
|
||||
name = online.getName();
|
||||
uuid = online.getUniqueId();
|
||||
}
|
||||
|
||||
// Check uuid
|
||||
if (arg2.contains("-")) {
|
||||
uuid = UUID.fromString(arg2);
|
||||
}
|
||||
|
||||
// Check offline player
|
||||
if (uuid == null) {
|
||||
OfflinePlayer offline = Bukkit.getOfflinePlayer(arg2);
|
||||
name = offline.getName();
|
||||
uuid = offline.getUniqueId();
|
||||
}
|
||||
|
||||
UUID finalUuid = uuid;
|
||||
String finalName = name;
|
||||
|
||||
for (Mode mode : Registry.getModes()) {
|
||||
Leaderboard leaderboard = mode.getLeaderboard();
|
||||
|
||||
if (leaderboard == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
leaderboard.remove(finalUuid);
|
||||
leaderboard.write(true);
|
||||
}
|
||||
|
||||
send(sender, LoParkour.PREFIX + "Successfully reset the high score of " + finalName + " in memory and the files.");
|
||||
}
|
||||
case "recoverinventory" -> {
|
||||
if (!cooldown(sender, "recoverinventory", 2500) || !sender.hasPermission(ParkourOption.ADMIN.permission)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player other = Bukkit.getPlayer(arg2);
|
||||
if (other == null) {
|
||||
send(sender, LoParkour.PREFIX + "That player isn't online!");
|
||||
return;
|
||||
}
|
||||
|
||||
new InventoryData(other).load(result -> {
|
||||
if (result != null) {
|
||||
send(sender, "%sSuccessfully recovered the inventory of %s from their file".formatted(LoParkour.PREFIX, other.getName()));
|
||||
send(sender, "%sGiving %s their items now...".formatted(LoParkour.PREFIX, other.getName()));
|
||||
} else {
|
||||
send(sender, "%s<red>There was an error recovering the inventory of %s from their file".formatted(LoParkour.PREFIX, other.getName()));
|
||||
send(sender, "%s%s has no saved inventory or there was an error. Check the console.".formatted(LoParkour.PREFIX, other.getName()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (arg1) {
|
||||
case "join" -> {
|
||||
if (!cooldown(sender, "join", 2500) || !ParkourOption.JOIN.mayPerform(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Mode mode = Registry.getMode(arg2);
|
||||
|
||||
if (mode != null) {
|
||||
mode.create(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Player other = Bukkit.getPlayer(arg2);
|
||||
|
||||
if (other == null) {
|
||||
send(sender, "%sUnknown player! Try typing the name again.".formatted(LoParkour.PREFIX)); // could not find, so go to default
|
||||
return;
|
||||
}
|
||||
|
||||
ParkourPlayer parkourPlayer = ParkourPlayer.getPlayer(other);
|
||||
|
||||
if (parkourPlayer == null) {
|
||||
send(sender, "%sUnknown player! Try typing the name again.".formatted(LoParkour.PREFIX)); // could not find, so go to default
|
||||
return;
|
||||
}
|
||||
|
||||
ParkourUser user = ParkourUser.getUser(player);
|
||||
Session session = parkourPlayer.session;
|
||||
if (user != null && user.session == session) { // already in same session
|
||||
return;
|
||||
}
|
||||
|
||||
if (session.isAcceptingPlayers()) {
|
||||
((MultiMode) session.generator.getMode()).join(player, session);
|
||||
} else {
|
||||
Modes.SPECTATOR.create(player, session);
|
||||
}
|
||||
}
|
||||
case "leaderboard" -> {
|
||||
if (!ParkourOption.LEADERBOARDS.mayPerform(player)) {
|
||||
send(sender, Locales.getString(player, "other.no_do"));
|
||||
return;
|
||||
}
|
||||
|
||||
Mode mode = Registry.getMode(arg2.toLowerCase());
|
||||
|
||||
// if found gamemode is null, return to default
|
||||
if (mode == null) {
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.LEADERBOARDS.open(player);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
} else {
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.SINGLE_LEADERBOARD.open(player, mode, Leaderboard.Sort.SCORE);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
}
|
||||
}
|
||||
case "schematic" -> {
|
||||
if (!sender.hasPermission(ParkourOption.ADMIN.permission)) {
|
||||
send(sender, Locales.getString(player, "other.no_do"));
|
||||
return;
|
||||
}
|
||||
|
||||
Location playerLocation = player.getLocation();
|
||||
Location[] existingSelection = selections.get(player);
|
||||
|
||||
switch (arg2.toLowerCase()) {
|
||||
case "wand" -> {
|
||||
player.getInventory().addItem(WAND);
|
||||
|
||||
send(player, "<dark_gray>----------- <dark_red><bold>Schematics <reset><dark_gray>-----------");
|
||||
send(player, "<gray><red>Left click<gray> -> set first position | <red>Right click<gray> -> set second position");
|
||||
send(player, "<gray>If you can't place a block and need to set a position mid-air, use <dark_gray>/LoParkour schematic pos1/pos2 <gray>instead.");
|
||||
}
|
||||
case "pos1" -> {
|
||||
send(player, "%sPosition 1 was set to %s".formatted(LoParkour.PREFIX, Locations.toString(playerLocation, true)));
|
||||
|
||||
if (existingSelection == null) {
|
||||
selections.put(player, new Location[]{playerLocation, null});
|
||||
return;
|
||||
}
|
||||
|
||||
selections.put(player, new Location[]{playerLocation, existingSelection[1]});
|
||||
|
||||
ParticleUtil.box(BoundingBox.of(playerLocation, existingSelection[1]), player.getWorld(), Particle.END_ROD, player, 0.2);
|
||||
}
|
||||
case "pos2" -> {
|
||||
send(player, "%sPosition 2 was set to %s".formatted(LoParkour.PREFIX, Locations.toString(playerLocation, true)));
|
||||
|
||||
if (existingSelection == null) {
|
||||
selections.put(player, new Location[]{null, playerLocation});
|
||||
return;
|
||||
}
|
||||
|
||||
selections.put(player, new Location[]{existingSelection[0], playerLocation});
|
||||
|
||||
ParticleUtil.box(BoundingBox.of(existingSelection[0], playerLocation), player.getWorld(), Particle.END_ROD, player, 0.2);
|
||||
}
|
||||
case "save" -> {
|
||||
if (!cooldown(sender, "LoParkour save schematic", 2500)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (existingSelection == null || existingSelection[0] == null || existingSelection[1] == null) {
|
||||
send(player, "<dark_red><bold>Schematics <reset><gray>Your schematic isn't complete yet. Make sure you've set the first and second position.");
|
||||
return;
|
||||
}
|
||||
|
||||
String code = UUID.randomUUID().toString().split("-")[0];
|
||||
|
||||
send(player, ("<dark_red><bold>Schematics <reset><gray>Your schematic is being saved. It will use code <red>'%s'<gray>. " + "You can change the code to whatever you like. " + "Don't forget to add this schematic to <dark_gray>schematics.yml<gray>.").formatted(code));
|
||||
|
||||
// Old vilib schematic save - deprecated, use .lpschem format instead
|
||||
send(player, "<red>Warning: Old schematic format is deprecated. Use '/loparkour schematic save <name>' for .lpschem format.");
|
||||
}
|
||||
case "list" -> {
|
||||
send(player, "<dark_red><bold>Schematics <reset><gray>Loaded schematics:");
|
||||
LoParkour.getSchematicManager().getAllSchematics().forEach((name, schem) -> {
|
||||
send(player, "<gray>- <red>" + name + " <dark_gray>(" + schem.getMetadata().getDifficulty() + ")");
|
||||
});
|
||||
}
|
||||
case "reload" -> {
|
||||
if (!cooldown(sender, "LoParkour reload schematics", 2500)) {
|
||||
return;
|
||||
}
|
||||
LoParkour.getSchematicManager().reload();
|
||||
send(player, "<dark_red><bold>Schematics <reset><gray>Reloaded all schematics.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handle3Args(@NotNull String arg1, @NotNull String arg2, @NotNull String arg3, @NotNull CommandSender sender, @Nullable Player player) {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg1.equalsIgnoreCase("schematic")) {
|
||||
if (!player.hasPermission(ParkourOption.ADMIN.permission)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (arg2.toLowerCase()) {
|
||||
case "save" -> {
|
||||
if (!cooldown(sender, "LoParkour save schematic", 2500)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location[] selection = selections.get(player);
|
||||
if (selection == null || selection[0] == null || selection[1] == null) {
|
||||
send(player, "<dark_red><bold>Schematics <reset><gray>Your schematic isn't complete yet. Make sure you've set the first and second position.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
int width = Math.abs(selection[1].getBlockX() - selection[0].getBlockX()) + 1;
|
||||
int height = Math.abs(selection[1].getBlockY() - selection[0].getBlockY()) + 1;
|
||||
int length = Math.abs(selection[1].getBlockZ() - selection[0].getBlockZ()) + 1;
|
||||
|
||||
LPSchematic schematic = new LPSchematicBuilder(arg3, player.getName(), 0.5, width, height, length)
|
||||
.fromWorld(player.getWorld(), selection[0], selection[1])
|
||||
.build();
|
||||
|
||||
LoParkour.getSchematicManager().saveSchematic(schematic);
|
||||
send(player, "<dark_red><bold>Schematics <reset><gray>Saved schematic as <red>" + arg3 + "<gray>!");
|
||||
} catch (Exception e) {
|
||||
send(player, "<dark_red><bold>Schematics <reset><gray>Failed to save schematic: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
case "paste" -> {
|
||||
LPSchematic lpSchematic = LoParkour.getSchematicManager().getSchematic(arg3);
|
||||
if (lpSchematic != null) {
|
||||
lpSchematic.paste(player.getLocation(), player.getWorld());
|
||||
send(sender, "%sPasted .lpschem schematic %s".formatted(LoParkour.PREFIX, arg3));
|
||||
return;
|
||||
}
|
||||
|
||||
send(sender, "%sCouldn't find %s. Only .lpschem format is supported.".formatted(LoParkour.PREFIX, arg3));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void send(CommandSender sender, String message) {
|
||||
sender.sendMessage(ColorUtil.color(message));
|
||||
}
|
||||
|
||||
private List<String> completions(String arg, List<String> options) {
|
||||
String lower = arg.toLowerCase();
|
||||
return options.stream()
|
||||
.filter(option -> option.toLowerCase().startsWith(lower))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private boolean cooldown(CommandSender sender, String key, long millis) {
|
||||
// Simple cooldown implementation - can be enhanced later
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
* <li>For player spectating, please view {@link dev.efnilite.LoParkour.player.ParkourSpectator}.</li>
|
||||
* <li>For events, please view {@link ParkourBlockGenerateEvent} and others in the events package.</li>
|
||||
* <li>For Sessions, please view {@link dev.efnilite.LoParkour.session.Session}.</li>
|
||||
* <li>For Schematics, please view {@link dev.efnilite.LoParkour.schematic.Schematic}</li>
|
||||
* <li>For Schematics, please view {@link dev.efnilite.LoParkour.schematic.LPSchematic}</li>
|
||||
* </ul>
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package dev.loki.loparkour.api.event;
|
|||
|
||||
import dev.loki.loparkour.generator.ParkourGenerator;
|
||||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.efnilite.vilib.event.EventWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -13,7 +15,9 @@ import java.util.List;
|
|||
* @author loki
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public class ParkourBlockGenerateEvent extends EventWrapper {
|
||||
public class ParkourBlockGenerateEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
public final List<Block> blocks;
|
||||
public final ParkourGenerator generator;
|
||||
|
|
@ -24,4 +28,17 @@ public class ParkourBlockGenerateEvent extends EventWrapper {
|
|||
this.generator = generator;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public void call() {
|
||||
Bukkit.getPluginManager().callEvent(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,33 @@
|
|||
package dev.loki.loparkour.api.event;
|
||||
|
||||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.efnilite.vilib.event.EventWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Gets called when a player falls. Read-only.
|
||||
*/
|
||||
public class ParkourFallEvent extends EventWrapper {
|
||||
public class ParkourFallEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
public final ParkourPlayer player;
|
||||
|
||||
public ParkourFallEvent(ParkourPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public void call() {
|
||||
Bukkit.getPluginManager().callEvent(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,33 @@
|
|||
package dev.loki.loparkour.api.event;
|
||||
|
||||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.efnilite.vilib.event.EventWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Gets called when a player joins a session. Read-only.
|
||||
*/
|
||||
public class ParkourJoinEvent extends EventWrapper {
|
||||
public class ParkourJoinEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
public final ParkourUser player;
|
||||
|
||||
public ParkourJoinEvent(ParkourUser player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public void call() {
|
||||
Bukkit.getPluginManager().callEvent(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,33 @@
|
|||
package dev.loki.loparkour.api.event;
|
||||
|
||||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.efnilite.vilib.event.EventWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Gets called when a player leaves a session. Read-only.
|
||||
*/
|
||||
public class ParkourLeaveEvent extends EventWrapper {
|
||||
public class ParkourLeaveEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
public final ParkourUser player;
|
||||
|
||||
public ParkourLeaveEvent(ParkourUser player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public void call() {
|
||||
Bukkit.getPluginManager().callEvent(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ package dev.loki.loparkour.api.event;
|
|||
|
||||
import dev.loki.loparkour.generator.ParkourGenerator;
|
||||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.efnilite.vilib.event.EventWrapper;
|
||||
import dev.efnilite.vilib.schematic.Schematic;
|
||||
import dev.loki.loparkour.schematic.lpschem.LPSchematic;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Gets called when a new jump is generated. Read-only.
|
||||
|
|
@ -11,15 +13,30 @@ import dev.efnilite.vilib.schematic.Schematic;
|
|||
* @author loki
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public class ParkourSchematicGenerateEvent extends EventWrapper {
|
||||
public class ParkourSchematicGenerateEvent extends Event {
|
||||
|
||||
public final Schematic schematic;
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
public final dev.loki.loparkour.schematic.lpschem.LPSchematic schematic;
|
||||
public final ParkourGenerator generator;
|
||||
public final ParkourPlayer player;
|
||||
|
||||
public ParkourSchematicGenerateEvent(Schematic schematic, ParkourGenerator generator, ParkourPlayer player) {
|
||||
public ParkourSchematicGenerateEvent(dev.loki.loparkour.schematic.lpschem.LPSchematic schematic, ParkourGenerator generator, ParkourPlayer player) {
|
||||
this.schematic = schematic;
|
||||
this.generator = generator;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public void call() {
|
||||
Bukkit.getPluginManager().callEvent(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,33 @@
|
|||
package dev.loki.loparkour.api.event;
|
||||
|
||||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.efnilite.vilib.event.EventWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Gets called when a point is scored. Read-only.
|
||||
*/
|
||||
public class ParkourScoreEvent extends EventWrapper {
|
||||
public class ParkourScoreEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
public final ParkourPlayer player;
|
||||
|
||||
public ParkourScoreEvent(ParkourPlayer player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public void call() {
|
||||
Bukkit.getPluginManager().callEvent(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package dev.loki.loparkour.api.event;
|
||||
|
||||
import dev.loki.loparkour.player.ParkourSpectator;
|
||||
import dev.efnilite.vilib.event.EventWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Gets called when a player starts spectating a session. Read-only.
|
||||
|
|
@ -9,11 +11,26 @@ import dev.efnilite.vilib.event.EventWrapper;
|
|||
* @author loki
|
||||
* @since 5.0.0
|
||||
*/
|
||||
public class ParkourSpectateEvent extends EventWrapper {
|
||||
public class ParkourSpectateEvent extends Event {
|
||||
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
|
||||
public final ParkourSpectator player;
|
||||
|
||||
public ParkourSpectateEvent(ParkourSpectator player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public void call() {
|
||||
Bukkit.getPluginManager().callEvent(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package dev.loki.loparkour.config;
|
|||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.reward.Rewards;
|
||||
import dev.loki.loparkour.schematic.Schematics;
|
||||
import dev.efnilite.vilib.configupdater.ConfigUpdater;
|
||||
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
|
@ -27,8 +27,9 @@ public enum Config {
|
|||
|
||||
/**
|
||||
* The path to this file, incl. plugin folder.
|
||||
* Not final — resolved lazily on first reload() call after plugin instance is set.
|
||||
*/
|
||||
public final File path;
|
||||
public File path;
|
||||
/**
|
||||
* The name of this file, e.g. config.yml
|
||||
*/
|
||||
|
|
@ -45,21 +46,27 @@ public enum Config {
|
|||
Config(String fileName, @Nullable List<String> ignoredSections) {
|
||||
this.fileName = fileName;
|
||||
this.ignoredSections = ignoredSections;
|
||||
this.path = LoParkour.getInFolder(fileName);
|
||||
|
||||
if (!path.exists()) {
|
||||
LoParkour.getPlugin().saveResource(fileName, false);
|
||||
}
|
||||
|
||||
update();
|
||||
load();
|
||||
// path resolved lazily via getPath() — do NOT call LoParkour.getInFolder() here,
|
||||
// because enum constants are initialized before onEnable() sets the instance.
|
||||
this.path = null; // placeholder; real path resolved on first access
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Reloads all config files.
|
||||
* On first call (initialLoad=true) also resolves file paths and saves defaults.
|
||||
*/
|
||||
public static void reload(boolean initialLoad) {
|
||||
for (Config config : values()) {
|
||||
if (initialLoad) {
|
||||
// Resolve path now that instance is guaranteed to be set
|
||||
config.path = LoParkour.getInFolder(config.fileName);
|
||||
if (!config.path.exists()) {
|
||||
LoParkour.getPlugin().saveResource(config.fileName, false);
|
||||
}
|
||||
config.update();
|
||||
}
|
||||
config.load();
|
||||
}
|
||||
|
||||
|
|
@ -76,6 +83,7 @@ public enum Config {
|
|||
* Loads the file from disk.
|
||||
*/
|
||||
public void load() {
|
||||
if (path == null) return; // not yet initialized, skip
|
||||
this.fileConfiguration = YamlConfiguration.loadConfiguration(path);
|
||||
}
|
||||
|
||||
|
|
@ -84,9 +92,10 @@ public enum Config {
|
|||
*/
|
||||
public void update() {
|
||||
try {
|
||||
ConfigUpdater.update(LoParkour.getPlugin(), fileName, path, ignoredSections);
|
||||
// TODO: ConfigUpdater.update(LoParkour.getPlugin(), fileName, path, ignoredSections);
|
||||
} catch (Exception ex) {
|
||||
LoParkour.logging().stack("Error while trying to update config file", ex);
|
||||
LoParkour.getPlugin().getLogger().log(java.util.logging.Level.SEVERE,
|
||||
"Error while trying to update config file: " + fileName, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +117,6 @@ public enum Config {
|
|||
return fileConfiguration.get(path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param path The path.
|
||||
* @return The boolean value at path.
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
package dev.loki.loparkour.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import dev.loki.loparkour.util.Item;
|
||||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.menu.ParkourOption;
|
||||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
import dev.efnilite.vilib.util.Task;
|
||||
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
|
@ -44,7 +48,7 @@ public class Locales {
|
|||
public static void init() {
|
||||
Plugin plugin = LoParkour.getPlugin();
|
||||
|
||||
Task.create(plugin).async().execute(() -> {
|
||||
Scheduler.get(plugin).runAsync(() -> {
|
||||
locales.clear();
|
||||
|
||||
FileConfiguration embedded = YamlConfiguration.loadConfiguration(new InputStreamReader(plugin.getResource("locales/en.yml"), StandardCharsets.UTF_8));
|
||||
|
|
@ -86,9 +90,9 @@ public class Locales {
|
|||
locales.put(locale, config);
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
LoParkour.logging().stack("Error while trying to read locale files", "restart/reload your server", ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to read locale files - restart/reload your server - " + ex.getMessage());
|
||||
}
|
||||
}).run();
|
||||
});
|
||||
}
|
||||
|
||||
// validates whether a lang file contains all required keys.
|
||||
|
|
@ -111,7 +115,7 @@ public class Locales {
|
|||
try {
|
||||
user.save(localPath);
|
||||
} catch (IOException ex) {
|
||||
LoParkour.logging().stack("Error while trying to save fixed config file %s".formatted(localPath), "delete this file and restart your server", ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to save fixed config file %s - delete this file and restart your server - ".formatted(localPath) + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -244,7 +248,7 @@ public class Locales {
|
|||
}
|
||||
|
||||
if (modelId != -1) {
|
||||
item.modelId(modelId);
|
||||
// TODO: item.setCustomModelData(modelId);
|
||||
}
|
||||
|
||||
return item;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
package dev.loki.loparkour.config;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import dev.loki.loparkour.util.ParticleData;
|
||||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.api.Registry;
|
||||
import dev.loki.loparkour.menu.ParkourOption;
|
||||
import dev.loki.loparkour.style.RandomStyle;
|
||||
import dev.loki.loparkour.style.Style;
|
||||
import dev.efnilite.vilib.particle.ParticleData;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
|
@ -83,7 +89,7 @@ public class Option {
|
|||
POSSIBLE_LEADS = Config.CONFIG.getIntList("options.leads.amount");
|
||||
for (int lead : new ArrayList<>(POSSIBLE_LEADS)) {
|
||||
if (lead < 1 || lead > 128) {
|
||||
LoParkour.logging().error("Invalid lead: %d. Should be above 1 and below 128.".formatted(lead));
|
||||
LoParkour.getPlugin().getLogger().severe("Invalid lead: %d. Should be above 1 and below 128.".formatted(lead));
|
||||
POSSIBLE_LEADS.remove((Object) lead);
|
||||
}
|
||||
}
|
||||
|
|
@ -96,7 +102,7 @@ public class Option {
|
|||
case "south" -> HEADING = BlockFace.SOUTH;
|
||||
case "west" -> HEADING = BlockFace.WEST;
|
||||
case "east" -> HEADING = BlockFace.EAST;
|
||||
default -> LoParkour.logging().error("Invalid heading: %s".formatted(heading));
|
||||
default -> LoParkour.getPlugin().getLogger().severe("Invalid heading: %s".formatted(heading));
|
||||
}
|
||||
|
||||
// Scoring
|
||||
|
|
@ -142,7 +148,7 @@ public class Option {
|
|||
SOUND_TYPE = Sound.valueOf(value);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
SOUND_TYPE = Sound.valueOf("BLOCK_NOTE_PLING");
|
||||
LoParkour.logging().error("Invalid sound: %s".formatted(value));
|
||||
LoParkour.getPlugin().getLogger().severe("Invalid sound: %s".formatted(value));
|
||||
}
|
||||
|
||||
value = Config.CONFIG.getString("particles.particle-type");
|
||||
|
|
@ -150,13 +156,13 @@ public class Option {
|
|||
PARTICLE_TYPE = Particle.valueOf(value);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
PARTICLE_TYPE = Particle.valueOf("SPELL_INSTANT");
|
||||
LoParkour.logging().error("Invalid particle type: %s".formatted(value));
|
||||
LoParkour.getPlugin().getLogger().severe("Invalid particle type: %s".formatted(value));
|
||||
}
|
||||
|
||||
SOUND_PITCH = Config.CONFIG.getInt("particles.sound-pitch");
|
||||
SOUND_VOLUME = Config.CONFIG.getInt("particles.sound-volume");
|
||||
PARTICLE_SHAPE = ParticleShape.valueOf(Config.CONFIG.getString("particles.particle-shape").toUpperCase());
|
||||
PARTICLE_DATA = new ParticleData<>(PARTICLE_TYPE, null, 10, 0, 0, 0, 0);
|
||||
PARTICLE_DATA = new ParticleData<>(PARTICLE_TYPE, null, 10);
|
||||
}
|
||||
|
||||
public enum ParticleShape {
|
||||
|
|
@ -287,7 +293,7 @@ public class Option {
|
|||
MIN_Y = 100;
|
||||
MAX_Y = 200;
|
||||
|
||||
LoParkour.logging().stack("Provided minimum y is the same or larger than maximum y!", "check your generation.yml file");
|
||||
LoParkour.getPlugin().getLogger().severe("Provided minimum y is the same or larger than maximum y! - check your generation.yml file");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -303,7 +309,7 @@ public class Option {
|
|||
var material = Material.getMaterial(name.toUpperCase());
|
||||
|
||||
if (material == null) {
|
||||
LoParkour.logging().error("Invalid material %s in style %s".formatted(name, style));
|
||||
LoParkour.getPlugin().getLogger().severe("Invalid material %s in style %s".formatted(name, style));
|
||||
return Material.STONE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package dev.loki.loparkour.generator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.efnilite.vilib.schematic.Schematic;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
|
@ -28,14 +30,14 @@ public final class Island {
|
|||
/**
|
||||
* The schematic.
|
||||
*/
|
||||
public final Schematic schematic;
|
||||
public final dev.loki.loparkour.schematic.lpschem.LPSchematic schematic;
|
||||
|
||||
/**
|
||||
* The blocks that have been affected by the schematic.
|
||||
*/
|
||||
public List<Block> blocks;
|
||||
|
||||
public Island(@NotNull Session session, @Nullable Schematic schematic) {
|
||||
public Island(@NotNull Session session, @Nullable dev.loki.loparkour.schematic.lpschem.LPSchematic schematic) {
|
||||
this.session = session;
|
||||
this.schematic = schematic;
|
||||
}
|
||||
|
|
@ -49,7 +51,7 @@ public final class Island {
|
|||
}
|
||||
LoParkour.log("Building island");
|
||||
|
||||
blocks = schematic.paste(location.subtract(0, schematic.getDimensions().getY(), 0));
|
||||
blocks = new ArrayList<>(); // TODO: schematic.paste(location, world)
|
||||
|
||||
Material playerMaterial = Material.getMaterial(Config.GENERATION.getString("advanced.island.spawn.player-block").toUpperCase());
|
||||
Material parkourMaterial = Material.getMaterial(Config.GENERATION.getString("advanced.island.parkour.begin-block").toUpperCase());
|
||||
|
|
@ -69,8 +71,7 @@ public final class Island {
|
|||
session.generator.startTick();
|
||||
session.getPlayers().forEach(pp -> pp.setup(ps));
|
||||
} catch (NoSuchElementException ex) {
|
||||
LoParkour.logging().stack("Error while trying to find parkour or player spawn in schematic %s".formatted(schematic.getFile().getName()),
|
||||
"check if you used the same material as the one in generation.yml", ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to find parkour or player spawn in schematic %s - check if you used the same material as the one in generation.yml - ".formatted("schematic") + ex.getMessage());
|
||||
|
||||
blocks.forEach(block -> block.setType(Material.AIR));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package dev.loki.loparkour.generator;
|
||||
|
||||
import dev.efnilite.vilib.util.Colls;
|
||||
import dev.efnilite.vilib.util.Probs;
|
||||
import dev.loki.loparkour.util.Probs;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
|
@ -53,11 +52,14 @@ public class JumpOffsetGenerator {
|
|||
* @return A random jump-able offset.
|
||||
*/
|
||||
public int getRandomOffset(double mean, double standardDeviation, Random random) {
|
||||
Map<Integer, Double> distribution = Colls.range(-maxOffset, maxOffset + 1)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(offset -> offset, offset -> Probs.normalpdf(mean, standardDeviation, offset)));
|
||||
Map<Double, Double> distribution = java.util.stream.IntStream.range(-maxOffset, maxOffset + 1)
|
||||
.boxed()
|
||||
.collect(Collectors.toMap(
|
||||
offset -> (double) offset,
|
||||
offset -> Probs.normalpdf(mean, standardDeviation, (double) offset)
|
||||
));
|
||||
|
||||
return Probs.random(distribution, random);
|
||||
return (int) (double) Probs.random(distribution, random);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
package dev.loki.loparkour.generator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import dev.loki.loparkour.util.ParticleData;
|
||||
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.api.Registry;
|
||||
import dev.loki.loparkour.api.event.ParkourBlockGenerateEvent;
|
||||
|
|
@ -19,21 +25,19 @@ import dev.loki.loparkour.reward.Rewards;
|
|||
import dev.loki.loparkour.session.Session;
|
||||
import dev.loki.loparkour.style.Style;
|
||||
import dev.loki.loparkour.world.Divider;
|
||||
import dev.efnilite.vilib.particle.ParticleData;
|
||||
import dev.efnilite.vilib.particle.Particles;
|
||||
import dev.efnilite.vilib.schematic.Schematic;
|
||||
import dev.efnilite.vilib.schematic.Schematics;
|
||||
import dev.efnilite.vilib.util.Colls;
|
||||
import dev.efnilite.vilib.util.Locations;
|
||||
import dev.efnilite.vilib.util.Probs;
|
||||
import dev.efnilite.vilib.util.Task;
|
||||
|
||||
import dev.loki.loparkour.util.ParticleUtil;
|
||||
|
||||
import dev.loki.loparkour.util.Locations;
|
||||
import dev.loki.loparkour.util.Probs;
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.Fence;
|
||||
import org.bukkit.block.data.type.GlassPane;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import dev.lolib.scheduler.ScheduledTask;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -61,9 +65,9 @@ public class ParkourGenerator {
|
|||
|
||||
public Location[] zone;
|
||||
public ParkourPlayer player;
|
||||
public BukkitTask task;
|
||||
public dev.lolib.scheduler.ScheduledTask task;
|
||||
|
||||
private BukkitTask cleanupTask;
|
||||
private dev.lolib.scheduler.ScheduledTask cleanupTask;
|
||||
|
||||
public Location blockSpawn;
|
||||
|
||||
|
|
@ -110,7 +114,7 @@ public class ParkourGenerator {
|
|||
protected int lastPositionIndexPlayer = -1;
|
||||
protected List<Block> history = new LinkedList<>();
|
||||
|
||||
public ParkourGenerator(@NotNull Session session, @Nullable Schematic schematic, GeneratorOption... generatorOptions) {
|
||||
public ParkourGenerator(@NotNull Session session, @Nullable dev.loki.loparkour.schematic.lpschem.LPSchematic schematic, GeneratorOption... generatorOptions) {
|
||||
this.session = session;
|
||||
this.generatorOptions = Arrays.asList(generatorOptions);
|
||||
|
||||
|
|
@ -122,7 +126,8 @@ public class ParkourGenerator {
|
|||
}
|
||||
|
||||
public ParkourGenerator(@NotNull Session session, GeneratorOption... generatorOptions) {
|
||||
this(session, Schematics.getSchematic(LoParkour.getPlugin(), "spawn-island"), generatorOptions);
|
||||
// TODO: Implement schematic loading with LoLib
|
||||
this(session, null, generatorOptions);
|
||||
}
|
||||
|
||||
public void overrideProfile() { }
|
||||
|
|
@ -170,9 +175,9 @@ public class ParkourGenerator {
|
|||
|
||||
// display particle
|
||||
switch (Option.PARTICLE_SHAPE) {
|
||||
case DOT -> Particles.draw(center.add(0.5, 1, 0.5), data.speed(0.4).size(20).offsetX(0.5).offsetY(1).offsetZ(0.5));
|
||||
case CIRCLE -> Particles.circle(center.add(0.5, 0.5, 0.5), data.size(5), (int) Math.sqrt(blocks.size()), 20);
|
||||
case BOX -> Particles.box(BoundingBox.of(max, min), player.player.getWorld(), data.size(1), 0.2);
|
||||
case DOT -> {} // TODO: ParticleUtil.draw
|
||||
case CIRCLE -> {} // TODO: ParticleUtil.circle
|
||||
case BOX -> {} // TODO: ParticleUtil.box
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -292,19 +297,14 @@ public class ParkourGenerator {
|
|||
}
|
||||
|
||||
public void menu(ParkourPlayer player) {
|
||||
Menus.PARKOUR_SETTINGS.open(player);
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
// Menus.PARKOUR_SETTINGS.open(player);
|
||||
player.sendTranslated("other.menu-unavailable");
|
||||
}
|
||||
|
||||
public void startTick() {
|
||||
task = Task.create(LoParkour.getPlugin())
|
||||
.repeat(1)
|
||||
.execute(this::tick)
|
||||
.run();
|
||||
|
||||
cleanupTask = Task.create(LoParkour.getPlugin())
|
||||
.repeat(Option.CLEANUP_INTERVAL)
|
||||
.execute(this::cleanupDistantBlocks)
|
||||
.run();
|
||||
task = Scheduler.get(LoParkour.getPlugin()).runTimer(this::tick, 0, 1);
|
||||
cleanupTask = Scheduler.get(LoParkour.getPlugin()).runTimer(this::cleanupDistantBlocks, 0, Option.CLEANUP_INTERVAL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -423,9 +423,9 @@ public class ParkourGenerator {
|
|||
stopped = !regenerate;
|
||||
|
||||
if (!regenerate && task == null) {
|
||||
LoParkour.logging().warn("## Incomplete joining setup.");
|
||||
LoParkour.logging().warn("## There has probably been an error somewhere. Please report this error!");
|
||||
LoParkour.logging().warn("## You don't have to report this warning.");
|
||||
LoParkour.getPlugin().getLogger().warning("## Incomplete joining setup.");
|
||||
LoParkour.getPlugin().getLogger().warning("## There has probably been an error somewhere. Please report this error!");
|
||||
LoParkour.getPlugin().getLogger().warning("## You don't have to report this warning.");
|
||||
}
|
||||
|
||||
lastPositionIndexPlayer = 0;
|
||||
|
|
@ -535,25 +535,8 @@ public class ParkourGenerator {
|
|||
|
||||
double difficulty = profile.get("schematicDifficulty").asDouble();
|
||||
|
||||
Schematic schematic = Schematics.getSchematic(LoParkour.getPlugin(),
|
||||
Colls.random(Schematics.getSchematicNames(LoParkour.getPlugin()).stream()
|
||||
.filter(name -> name.contains("parkour-") && getDifficulty(name) <= difficulty)
|
||||
.toList()));
|
||||
|
||||
schematicBlocks = rotatedPaste(schematic, selectBlocks().get(0).getLocation());
|
||||
|
||||
particles(schematicBlocks);
|
||||
sound(schematicBlocks);
|
||||
|
||||
new ParkourSchematicGenerateEvent(schematic, this, player).call();
|
||||
|
||||
if (schematicBlocks.isEmpty()) {
|
||||
LoParkour.logging().stack("Error while trying to paste schematic %s".formatted(schematic.getFile().getName()), new NoSuchElementException("No schematic blocks found"));
|
||||
return;
|
||||
}
|
||||
|
||||
schematicCooldown = Config.GENERATION.getInt("advanced.schematic-cooldown");
|
||||
waitForSchematicCompletion = true;
|
||||
// TODO: Implement schematic generation with LoLib
|
||||
LoParkour.getPlugin().getLogger().warning("LPSchematic generation temporarily disabled during migration");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -562,7 +545,7 @@ public class ParkourGenerator {
|
|||
List<Block> blocks = selectBlocks();
|
||||
|
||||
if (blocks.isEmpty()) {
|
||||
LoParkour.logging().stack("Error while trying to generate parkour", new NoSuchElementException("No blocks to generate found"));
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to generate parkour: No blocks to generate found");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -587,62 +570,12 @@ public class ParkourGenerator {
|
|||
schematicCooldown--;
|
||||
}
|
||||
|
||||
private @NotNull List<Block> rotatedPaste(Schematic schematic, Location location) {
|
||||
if (schematic == null || location == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Optional<Vector> optionalStart = schematic.getVectorBlockMap().entrySet().stream()
|
||||
.filter(entry -> {
|
||||
if (entry == null || entry.getValue() == null) return false;
|
||||
|
||||
return entry.getValue().getMaterial() == Material.LIME_WOOL;
|
||||
})
|
||||
.map(Map.Entry::getKey)
|
||||
.findAny();
|
||||
|
||||
Optional<Vector> optionalEnd = schematic.getVectorBlockMap().entrySet().stream()
|
||||
.filter(entry -> {
|
||||
if (entry == null || entry.getValue() == null) return false;
|
||||
|
||||
return entry.getValue().getMaterial() == Material.RED_WOOL;
|
||||
})
|
||||
.map(Map.Entry::getKey)
|
||||
.findAny();
|
||||
|
||||
if (optionalStart.isEmpty()) {
|
||||
LoParkour.logging().stack("Error while trying to find start of schematic", "check if you placed a lime wool block");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (optionalEnd.isEmpty()) {
|
||||
LoParkour.logging().stack("Error while trying to find end of schematic", "check if you placed a red wool block");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
Vector start = optionalStart.get();
|
||||
Vector end = optionalEnd.get();
|
||||
Vector startToEnd = end.clone().subtract(start);
|
||||
|
||||
/// snapped vector, supports no rotation if x == z
|
||||
Vector snapped;
|
||||
if (startToEnd.equals(heading)) {
|
||||
snapped = new Vector(0, 0, 0);
|
||||
} else if (Math.abs(startToEnd.getX()) > Math.abs(startToEnd.getZ())) {
|
||||
snapped = new Vector(Math.signum(startToEnd.getX()), 0, 0);
|
||||
} else {
|
||||
snapped = new Vector(0, 0, Math.signum(startToEnd.getZ()));
|
||||
}
|
||||
|
||||
// the angle between heading and normalized direction of schematic, snapped to 90 deg angles
|
||||
double snappedAngle = angleInY(heading, snapped);
|
||||
|
||||
Location rotatedStart = location.clone().subtract(start.clone().rotateAroundY(snappedAngle));
|
||||
Vector rotatedStartToEnd = startToEnd.clone().rotateAroundY(snappedAngle);
|
||||
|
||||
history.add(location.clone().add(rotatedStartToEnd).subtract(0, 1, 0).getBlock());
|
||||
return schematic.paste(rotatedStart, snappedAngle); // only yaw
|
||||
private @NotNull List<Block> rotatedPaste(dev.loki.loparkour.schematic.lpschem.LPSchematic schematic, Location location) {
|
||||
// TODO: Implement schematic rotation with LoLib
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
private double angleInY(Vector a, Vector b) {
|
||||
double det = a.getX() * b.getZ() - a.getZ() * b.getX();
|
||||
return Math.atan2(det, a.dot(b));
|
||||
|
|
@ -757,7 +690,7 @@ public class ParkourGenerator {
|
|||
.withZone(ZoneOffset.UTC)
|
||||
.format(timeMs);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
LoParkour.logging().stack("Invalid score time format %s".formatted(Config.CONFIG.getString("options.time.score-format")), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Invalid score time format %s".formatted(Config.CONFIG.getString("options.time.score-format")) + " - " + ex.getMessage());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package dev.loki.loparkour.ghost;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import org.bukkit.Location;
|
||||
|
|
@ -40,7 +42,7 @@ public class GhostManager {
|
|||
GhostData data = GhostData.loadFromFile(file);
|
||||
ghosts.add(data);
|
||||
} catch (IOException e) {
|
||||
LoParkour.logging().error("Failed to load ghost: " + file.getName());
|
||||
LoParkour.getPlugin().getLogger().severe("Failed to load ghost: " + file.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -71,7 +73,7 @@ public class GhostManager {
|
|||
try {
|
||||
data.saveToFile(file);
|
||||
} catch (IOException e) {
|
||||
LoParkour.logging().error("Failed to save ghost: " + file.getName());
|
||||
LoParkour.getPlugin().getLogger().severe("Failed to save ghost: " + file.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
package dev.loki.loparkour.ghost;
|
||||
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.efnilite.vilib.util.Task;
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import dev.lolib.scheduler.ScheduledTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class GhostPlayer {
|
||||
|
|
@ -14,7 +16,7 @@ public class GhostPlayer {
|
|||
private final GhostData data;
|
||||
private final World world;
|
||||
private ArmorStand entity;
|
||||
private BukkitTask task;
|
||||
private dev.lolib.scheduler.ScheduledTask task;
|
||||
private int currentFrame = 0;
|
||||
private long startTime;
|
||||
|
||||
|
|
@ -38,10 +40,7 @@ public class GhostPlayer {
|
|||
startTime = System.currentTimeMillis();
|
||||
currentFrame = 0;
|
||||
|
||||
task = Task.create(LoParkour.getPlugin())
|
||||
.repeat(1)
|
||||
.execute(this::update)
|
||||
.run();
|
||||
task = Scheduler.get(LoParkour.getPlugin()).runTimer(this::update, 0, 1);
|
||||
}
|
||||
|
||||
private void update() {
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ public class HoloHook {
|
|||
try {
|
||||
Class.forName("me.filoghost.holographicdisplays.api.HolographicDisplaysAPI");
|
||||
} catch (Exception ex) {
|
||||
LoParkour.logging().warn("##");
|
||||
LoParkour.logging().warn("## LoParkour only supports Holographic Displays v3.0.0 or higher!");
|
||||
LoParkour.logging().warn("## This hook will now be disabled.");
|
||||
LoParkour.logging().warn("##");
|
||||
LoParkour.getPlugin().getLogger().warning("##");
|
||||
LoParkour.getPlugin().getLogger().warning("## LoParkour only supports Holographic Displays v3.0.0 or higher!");
|
||||
LoParkour.getPlugin().getLogger().warning("## This hook will now be disabled.");
|
||||
LoParkour.getPlugin().getLogger().warning("##");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -159,7 +159,6 @@ public class PAPIHook extends PlaceholderExpansion {
|
|||
return "?";
|
||||
}
|
||||
|
||||
|
||||
private String getInfiniteScore(String rankData, Function<Score, ?> f) {
|
||||
int rank;
|
||||
Leaderboard leaderboard = null;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class VaultHook {
|
|||
RegisteredServiceProvider<Economy> service = Bukkit.getServicesManager().getRegistration(Economy.class);
|
||||
|
||||
if (service == null) {
|
||||
LoParkour.logging().stack("Error while trying to fetch the Vault economy", new NoSuchElementException("No economy found"));
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to fetch the Vault economy - No economy found");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
package dev.loki.loparkour.leaderboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.loki.loparkour.storage.Storage;
|
||||
import dev.efnilite.vilib.util.Task;
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
|
@ -40,21 +44,17 @@ public class Leaderboard {
|
|||
|
||||
var interval = Config.CONFIG.getInt("storage-update-interval");
|
||||
|
||||
// TODO: Fix scheduler call - needs proper implementation
|
||||
// read/write all data every x seconds after x seconds to allow time for reading/writing
|
||||
Task.create(LoParkour.getPlugin())
|
||||
.delay(interval * 20)
|
||||
.repeat(interval * 20)
|
||||
.async()
|
||||
.execute(Config.CONFIG.getBoolean("joining") ? () -> {
|
||||
LoParkour.log("Periodic saving of leaderboard data of %s".formatted(mode));
|
||||
|
||||
write(true);
|
||||
} : () -> {
|
||||
LoParkour.log("Periodic reading of leaderboard data of %s".formatted(mode));
|
||||
|
||||
read(true);
|
||||
})
|
||||
.run();
|
||||
Scheduler.get(LoParkour.getPlugin()).runTimerAsync(() -> {
|
||||
if (Config.CONFIG.getBoolean("joining")) {
|
||||
LoParkour.log("Periodic saving of leaderboard data of %s".formatted(mode));
|
||||
write(true);
|
||||
} else {
|
||||
LoParkour.log("Periodic reading of leaderboard data of %s".formatted(mode));
|
||||
read(true);
|
||||
}
|
||||
}, interval * 20, interval * 20);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -82,7 +82,7 @@ public class Leaderboard {
|
|||
|
||||
private void run(Runnable runnable, boolean async) {
|
||||
if (async) {
|
||||
Task.create(LoParkour.getPlugin()).async().execute(runnable).run();
|
||||
Scheduler.get(LoParkour.getPlugin()).runAsync(runnable);
|
||||
} else {
|
||||
runnable.run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package dev.loki.loparkour.menu;
|
||||
|
||||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.efnilite.vilib.inventory.Menu;
|
||||
import dev.efnilite.vilib.inventory.item.MenuItem;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
|
@ -29,7 +27,9 @@ public abstract class DynamicMenu {
|
|||
* @param item The item
|
||||
* @param shouldDisplay Whether this item should be displayed right now.
|
||||
*/
|
||||
public void registerMainItem(int row, int id, BiFunction<@NotNull Player, @Nullable ParkourUser, MenuItem> item, Predicate<Player> shouldDisplay) {
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void registerMainItem(int row, int id, BiFunction<@NotNull Player, @Nullable ParkourUser, dev.loki.loparkour.util.MenuItem> item, Predicate<Player> shouldDisplay) {
|
||||
if (id < 0 || row < 0 || row > 4) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -42,6 +42,7 @@ public abstract class DynamicMenu {
|
|||
|
||||
registeredItems.put(row, existing);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Opens this dynamic menu to a player
|
||||
|
|
@ -49,6 +50,8 @@ public abstract class DynamicMenu {
|
|||
* @param player The player
|
||||
* @param menu The menu
|
||||
*/
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void display(Player player, Menu menu) {
|
||||
ParkourUser user = ParkourUser.getUser(player);
|
||||
for (int row : registeredItems.keySet()) {
|
||||
|
|
@ -67,10 +70,11 @@ public abstract class DynamicMenu {
|
|||
|
||||
menu.open(player);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Data class for registered items
|
||||
*/
|
||||
protected record ItemContainer(int id, BiFunction<@NotNull Player, @Nullable ParkourUser, MenuItem> item,
|
||||
protected record ItemContainer(int id, BiFunction<@NotNull Player, @Nullable ParkourUser, dev.loki.loparkour.util.MenuItem> item,
|
||||
Predicate<Player> predicate) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@ import dev.loki.loparkour.config.Config;
|
|||
import dev.loki.loparkour.config.Locales;
|
||||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.efnilite.vilib.inventory.Menu;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MainMenu extends DynamicMenu {
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public MainMenu() {
|
||||
registerMainItem(1, 0, (player, user) -> Locales.getItem(player, "play.item").click(event -> Menus.PLAY.open(event.getPlayer())), player -> ParkourOption.PLAY.mayPerform(player) && Config.CONFIG.getBoolean("joining"));
|
||||
registerMainItem(1, 1, (player, user) -> Locales.getItem(player, "community.item").click(event -> Menus.COMMUNITY.open(event.getPlayer())), ParkourOption.COMMUNITY::mayPerform);
|
||||
|
|
@ -16,9 +17,13 @@ public class MainMenu extends DynamicMenu {
|
|||
registerMainItem(1, 3, (player, user) -> Locales.getItem(player, "lobby.item").click(event -> Menus.LOBBY.open(event.getPlayer())), player -> ParkourOption.LOBBY.mayPerform(player) && ParkourUser.isUser(player));
|
||||
registerMainItem(1, 4, (player, user) -> Locales.getItem(player, "other.quit").click(event -> ParkourPlayer.leave(player)), player -> ParkourOption.QUIT.mayPerform(player) && ParkourUser.isUser(player));
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(Player player) {
|
||||
display(player, new Menu(3, Locales.getString(player, "main.name"))
|
||||
.distributeRowsEvenly());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
34
src/main/java/dev/loki/loparkour/menu/MenuStub.java
Normal file
34
src/main/java/dev/loki/loparkour/menu/MenuStub.java
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package dev.loki.loparkour.menu;
|
||||
|
||||
import dev.loki.loparkour.leaderboard.Leaderboard;
|
||||
import dev.loki.loparkour.mode.Mode;
|
||||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Temporary stub for menu system during migration
|
||||
* TODO: Implement proper menu system using LoLib GUI or custom implementation
|
||||
*/
|
||||
public class MenuStub {
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(Player player) {
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(Player player, Mode mode, Leaderboard.Sort sort) {
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(ParkourPlayer player) {
|
||||
player.player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
@ -4,7 +4,6 @@ import dev.loki.loparkour.config.Locales;
|
|||
import dev.loki.loparkour.menu.DynamicMenu;
|
||||
import dev.loki.loparkour.menu.Menus;
|
||||
import dev.loki.loparkour.menu.ParkourOption;
|
||||
import dev.efnilite.vilib.inventory.Menu;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
|
|
@ -12,13 +11,19 @@ import org.bukkit.entity.Player;
|
|||
*/
|
||||
public class CommunityMenu extends DynamicMenu {
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public CommunityMenu() {
|
||||
registerMainItem(1, 1, (player, user) -> Locales.getItem(player, "community.leaderboards.item").click(event -> Menus.LEADERBOARDS.open(event.getPlayer())), ParkourOption.LEADERBOARDS::mayPerform);
|
||||
registerMainItem(2, 10, (player, user) -> Locales.getItem(player, "other.close").click(event -> event.getPlayer().closeInventory()), player -> true);
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(Player player) {
|
||||
display(player, new Menu(3, Locales.getString(player, "community.name"))
|
||||
.distributeRowsEvenly());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,6 @@ import dev.loki.loparkour.menu.Menus;
|
|||
import dev.loki.loparkour.menu.ParkourOption;
|
||||
import dev.loki.loparkour.mode.Mode;
|
||||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.efnilite.vilib.inventory.PagedMenu;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
import dev.efnilite.vilib.inventory.item.MenuItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
@ -22,6 +19,8 @@ import java.util.List;
|
|||
*/
|
||||
public class LeaderboardsMenu {
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(Player player) {
|
||||
ParkourUser user = ParkourUser.getUser(player);
|
||||
String locale = user == null ? Option.OPTIONS_DEFAULTS.get(ParkourOption.LANG) : user.locale;
|
||||
|
|
@ -46,12 +45,12 @@ public class LeaderboardsMenu {
|
|||
Menus.SINGLE_LEADERBOARD.open(player, latest, Leaderboard.Sort.SCORE);
|
||||
return;
|
||||
}
|
||||
|
||||
menu.displayRows(0, 1)
|
||||
.addToDisplay(items)
|
||||
.nextPage(26, new Item(Material.LIME_DYE, "<#0DCB07><bold>»").click(event -> menu.page(1)))
|
||||
.prevPage(18, new Item(Material.RED_DYE, "<#DE1F1F><bold>«").click(event -> menu.page(-1)))
|
||||
.item(22, Locales.getItem(player, "other.close").click(event -> Menus.COMMUNITY.open(event.getPlayer())))
|
||||
.open(player);
|
||||
// menu.displayRows(0, 1)
|
||||
// .addToDisplay(items)
|
||||
// .nextPage(26, new Item(Material.LIME_DYE, "<#0DCB07><bold>»").click(event -> menu.page(1)))
|
||||
// .prevPage(18, new Item(Material.RED_DYE, "<#DE1F1F><bold>«").click(event -> menu.page(-1)))
|
||||
// .item(22, Locales.getItem(player, "other.close").click(event -> Menus.COMMUNITY.open(event.getPlayer())))
|
||||
// .open(player);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,6 @@ import dev.loki.loparkour.menu.Menus;
|
|||
import dev.loki.loparkour.menu.ParkourOption;
|
||||
import dev.loki.loparkour.mode.Mode;
|
||||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.efnilite.vilib.inventory.PagedMenu;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
import dev.efnilite.vilib.inventory.item.MenuItem;
|
||||
import dev.efnilite.vilib.util.SkullSetter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
|
@ -31,107 +27,90 @@ import java.util.UUID;
|
|||
*/
|
||||
public class SingleLeaderboardMenu {
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(Player player, Mode mode, Leaderboard.Sort sort) {
|
||||
Leaderboard leaderboard = mode.getLeaderboard();
|
||||
|
||||
if (leaderboard == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// init vars
|
||||
var user = ParkourUser.getUser(player);
|
||||
var locale = user == null ? Option.OPTIONS_DEFAULTS.get(ParkourOption.LANG) : user.locale;
|
||||
var menu = new PagedMenu(3, Locales.getString(player, "%s.name".formatted(ParkourOption.LEADERBOARDS.path)));
|
||||
|
||||
var items = new ArrayList<MenuItem>();
|
||||
|
||||
var base = Locales.getItem(player, "%s.head".formatted(ParkourOption.LEADERBOARDS.path));
|
||||
|
||||
for (Map.Entry<UUID, Score> entry : leaderboard.sort(sort).entrySet()) {
|
||||
int rank = items.size() + 1;
|
||||
|
||||
var uuid = entry.getKey();
|
||||
var score = entry.getValue();
|
||||
|
||||
if (score == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Item item = base.clone().material(Material.PLAYER_HEAD)
|
||||
.modifyName(name -> name.replace("%r", Integer.toString(rank))
|
||||
.replace("%s", Integer.toString(score.score()))
|
||||
.replace("%p", score.name())
|
||||
.replace("%t", score.time())
|
||||
.replace("%d", score.difficulty()))
|
||||
.modifyLore(line -> line.replace("%r", Integer.toString(rank))
|
||||
.replace("%s", Integer.toString(score.score()))
|
||||
.replace("%p", score.name())
|
||||
.replace("%t", score.time())
|
||||
.replace("%d", score.difficulty()));
|
||||
|
||||
// var user = ParkourUser.getUser(player);
|
||||
// var locale = user == null ? Option.OPTIONS_DEFAULTS.get(ParkourOption.LANG) : user.locale;
|
||||
// var menu = new PagedMenu(3, Locales.getString(player, "%s.name".formatted(ParkourOption.LEADERBOARDS.path)));
|
||||
// var items = new ArrayList<MenuItem>();
|
||||
// var base = Locales.getItem(player, "%s.head".formatted(ParkourOption.LEADERBOARDS.path));
|
||||
// for (Map.Entry<UUID, Score> entry : leaderboard.sort(sort).entrySet()) {
|
||||
// int rank = items.size() + 1;
|
||||
// var uuid = entry.getKey();
|
||||
// var score = entry.getValue();
|
||||
// if (score == null) {
|
||||
// continue;
|
||||
// }
|
||||
// Item item = base.clone().material(Material.PLAYER_HEAD)
|
||||
// .modifyName(name -> name.replace("%r", Integer.toString(rank))
|
||||
// .replace("%s", Integer.toString(score.score()))
|
||||
// .replace("%p", score.name())
|
||||
// .replace("%t", score.time())
|
||||
// .replace("%d", score.difficulty()))
|
||||
// .modifyLore(line -> line.replace("%r", Integer.toString(rank))
|
||||
// .replace("%s", Integer.toString(score.score()))
|
||||
// .replace("%p", score.name())
|
||||
// .replace("%t", score.time())
|
||||
// .replace("%d", score.difficulty()));
|
||||
// Player head gathering
|
||||
ItemStack stack = item.build();
|
||||
|
||||
// ItemStack stack = item.build();
|
||||
// if there are more than 36 players, don't show the heads to avoid server crashing
|
||||
// and bedrock has no player skull support
|
||||
if (rank <= 20 && !ParkourUser.isBedrockPlayer(player)) {
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
|
||||
|
||||
if (op.getName() != null && !op.getName().startsWith(".")) { // bedrock players' names with geyser start with a .
|
||||
SkullMeta meta = (SkullMeta) stack.getItemMeta();
|
||||
|
||||
if (meta != null) {
|
||||
SkullSetter.setPlayerHead(op, meta);
|
||||
item.meta(meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (uuid.equals(player.getUniqueId())) {
|
||||
menu.item(21, item.clone());
|
||||
}
|
||||
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
List<String> values = Locales.getStringList(locale, "%s.sort.values".formatted(ParkourOption.LEADERBOARDS.path));
|
||||
|
||||
if (values.size() != 3) {
|
||||
LoParkour.logging().stack("Error while trying to get locales for sort values: not enough sort values present",
|
||||
"check your %s locale file".formatted(locale), new IllegalArgumentException());
|
||||
}
|
||||
|
||||
String name = switch (sort) {
|
||||
case SCORE -> values.get(0);
|
||||
case TIME -> values.get(1);
|
||||
case DIFFICULTY -> values.get(2);
|
||||
};
|
||||
|
||||
// if (rank <= 20 && !ParkourUser.isBedrockPlayer(player)) {
|
||||
// OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
|
||||
// if (op.getName() != null && !op.getName().startsWith(".")) { // bedrock players' names with geyser start with a .
|
||||
// SkullMeta meta = (SkullMeta) stack.getItemMeta();
|
||||
// if (meta != null) {
|
||||
// SkullSetter.setPlayerHead(op, meta);
|
||||
// item.meta(meta);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (uuid.equals(player.getUniqueId())) {
|
||||
// menu.item(21, item.clone());
|
||||
// }
|
||||
// items.add(item);
|
||||
// }
|
||||
// List<String> values = Locales.getStringList(locale, "%s.sort.values".formatted(ParkourOption.LEADERBOARDS.path));
|
||||
// if (values.size() != 3) {
|
||||
// LoParkour.logging().stack("Error while trying to get locales for sort values: not enough sort values present",
|
||||
// "check your %s locale file".formatted(locale), new IllegalArgumentException());
|
||||
// }
|
||||
// String name = switch (sort) {
|
||||
// case SCORE -> values.get(0);
|
||||
// case TIME -> values.get(1);
|
||||
// case DIFFICULTY -> values.get(2);
|
||||
// };
|
||||
// get next sorting type
|
||||
var next = switch (sort) {
|
||||
case SCORE -> Leaderboard.Sort.TIME;
|
||||
case TIME -> Leaderboard.Sort.DIFFICULTY;
|
||||
default -> Leaderboard.Sort.SCORE;
|
||||
};
|
||||
|
||||
menu.displayRows(0, 1)
|
||||
.addToDisplay(items)
|
||||
.nextPage(26, new Item(Material.LIME_DYE, "<#0DCB07><bold>»").click(event -> menu.page(1)))
|
||||
.prevPage(18, new Item(Material.RED_DYE, "<#DE1F1F><bold>«").click(event -> menu.page(-1)))
|
||||
.item(22, Locales.getItem(player, ParkourOption.LEADERBOARDS.path + ".sort", name.toLowerCase()).click(event -> open(player, mode, next)))
|
||||
.item(23, Locales.getItem(player, "other.close").click(event -> {
|
||||
List<Mode> modes = Registry.getModes()
|
||||
.stream()
|
||||
.filter(m -> m.getLeaderboard() != null && m.getItem(locale) != null)
|
||||
.toList();
|
||||
|
||||
if (modes.size() == 1) {
|
||||
Menus.COMMUNITY.open(player);
|
||||
return;
|
||||
}
|
||||
|
||||
Menus.LEADERBOARDS.open(event.getPlayer());
|
||||
}))
|
||||
.open(player);
|
||||
// var next = switch (sort) {
|
||||
// case SCORE -> Leaderboard.Sort.TIME;
|
||||
// case TIME -> Leaderboard.Sort.DIFFICULTY;
|
||||
// default -> Leaderboard.Sort.SCORE;
|
||||
// };
|
||||
// menu.displayRows(0, 1)
|
||||
// .addToDisplay(items)
|
||||
// .nextPage(26, new Item(Material.LIME_DYE, "<#0DCB07><bold>»").click(event -> menu.page(1)))
|
||||
// .prevPage(18, new Item(Material.RED_DYE, "<#DE1F1F><bold>«").click(event -> menu.page(-1)))
|
||||
// .item(22, Locales.getItem(player, ParkourOption.LEADERBOARDS.path + ".sort", name.toLowerCase()).click(event -> open(player, mode, next)))
|
||||
// .item(23, Locales.getItem(player, "other.close").click(event -> {
|
||||
// List<Mode> modes = Registry.getModes()
|
||||
// .stream()
|
||||
// .filter(m -> m.getLeaderboard() != null && m.getItem(locale) != null)
|
||||
// .toList();
|
||||
// if (modes.size() == 1) {
|
||||
// Menus.COMMUNITY.open(player);
|
||||
// return;
|
||||
// }
|
||||
// Menus.LEADERBOARDS.open(event.getPlayer());
|
||||
// }))
|
||||
// .open(player);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ import dev.loki.loparkour.menu.ParkourOption;
|
|||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.efnilite.vilib.inventory.Menu;
|
||||
import dev.efnilite.vilib.inventory.item.SliderItem;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LobbyMenu extends DynamicMenu {
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public LobbyMenu() {
|
||||
registerMainItem(1, 0, (player, user) -> Locales.getItem(player, "lobby.player_management.item").click(event -> Menus.PLAYER_MANAGEMENT.open(player)), player -> {
|
||||
ParkourUser user = ParkourUser.getUser(player);
|
||||
|
|
@ -66,14 +66,18 @@ public class LobbyMenu extends DynamicMenu {
|
|||
|
||||
registerMainItem(2, 10, (player, user) -> Locales.getItem(player, "other.close").click(event -> event.getPlayer().closeInventory()), player -> true);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Opens the main menu.
|
||||
*
|
||||
* @param player The player to open the menu to
|
||||
*/
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(Player player) {
|
||||
display(player, new Menu(3, Locales.getString(player, "lobby.name"))
|
||||
.distributeRowsEvenly());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,6 @@ import dev.loki.loparkour.mode.Modes;
|
|||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.efnilite.vilib.inventory.PagedMenu;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
import dev.efnilite.vilib.util.SkullSetter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
|
@ -24,30 +21,30 @@ import java.util.List;
|
|||
*/
|
||||
public class PlayerManagementMenu {
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(Player p) {
|
||||
if (p == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ParkourPlayer viewer = ParkourPlayer.getPlayer(p);
|
||||
|
||||
if (viewer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Session session = viewer.session;
|
||||
|
||||
PagedMenu menu = new PagedMenu(3, Locales.getString(viewer.locale, "lobby.player_management.name"));
|
||||
add(menu, viewer, session.getPlayers().stream().map(player -> (ParkourUser) player).toList());
|
||||
add(menu, viewer, session.getSpectators().stream().map(player -> (ParkourUser) player).toList());
|
||||
|
||||
menu.displayRows(0, 1)
|
||||
.prevPage(18, new Item(Material.RED_DYE, "<#DE1F1F><bold>«").click(event -> menu.page(-1)))
|
||||
.nextPage(26, new Item(Material.LIME_DYE, "<#0DCB07><bold>»").click(event -> menu.page(1)))
|
||||
.item(22, Locales.getItem(viewer.locale, "other.close").click(event -> Menus.LOBBY.open(event.getPlayer())))
|
||||
.open(p);
|
||||
// ParkourPlayer viewer = ParkourPlayer.getPlayer(p);
|
||||
// if (viewer == null) {
|
||||
// return;
|
||||
// }
|
||||
// Session session = viewer.session;
|
||||
// PagedMenu menu = new PagedMenu(3, Locales.getString(viewer.locale, "lobby.player_management.name"));
|
||||
// add(menu, viewer, session.getPlayers().stream().map(player -> (ParkourUser) player).toList());
|
||||
// add(menu, viewer, session.getSpectators().stream().map(player -> (ParkourUser) player).toList());
|
||||
// menu.displayRows(0, 1)
|
||||
// .prevPage(18, new Item(Material.RED_DYE, "<#DE1F1F><bold>«").click(event -> menu.page(-1)))
|
||||
// .nextPage(26, new Item(Material.LIME_DYE, "<#0DCB07><bold>»").click(event -> menu.page(1)))
|
||||
// .item(22, Locales.getItem(viewer.locale, "other.close").click(event -> Menus.LOBBY.open(event.getPlayer())))
|
||||
// .open(p);
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
private void add(PagedMenu menu, ParkourUser viewer, Collection<ParkourUser> users) {
|
||||
Session session = viewer.session;
|
||||
|
||||
|
|
@ -115,4 +112,5 @@ public class PlayerManagementMenu {
|
|||
menu.addToDisplay(List.of(item));
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import dev.loki.loparkour.config.Locales;
|
|||
import dev.loki.loparkour.menu.DynamicMenu;
|
||||
import dev.loki.loparkour.menu.Menus;
|
||||
import dev.loki.loparkour.menu.ParkourOption;
|
||||
import dev.efnilite.vilib.inventory.Menu;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
@ -13,6 +12,8 @@ import org.bukkit.entity.Player;
|
|||
*/
|
||||
public class PlayMenu extends DynamicMenu {
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public PlayMenu() {
|
||||
registerMainItem(1, 0, (player, user) -> Locales.getItem(player, "play.single.item")
|
||||
.click(event -> Menus.SINGLE.open(event.getPlayer())),
|
||||
|
|
@ -30,9 +31,13 @@ public class PlayMenu extends DynamicMenu {
|
|||
.click(event -> event.getPlayer().closeInventory()),
|
||||
player -> true);
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(Player player) {
|
||||
display(player, new Menu(3, Locales.getString(player, "play.name"))
|
||||
.distributeRowsEvenly());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,6 @@ import dev.loki.loparkour.menu.ParkourOption;
|
|||
import dev.loki.loparkour.mode.Mode;
|
||||
import dev.loki.loparkour.mode.MultiMode;
|
||||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.efnilite.vilib.inventory.PagedMenu;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
import dev.efnilite.vilib.inventory.item.MenuItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
@ -25,6 +22,8 @@ import java.util.List;
|
|||
*/
|
||||
public class SingleMenu {
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(Player player) {
|
||||
ParkourUser user = ParkourUser.getUser(player);
|
||||
String locale = user == null ? Option.OPTIONS_DEFAULTS.get(ParkourOption.LANG) : user.locale;
|
||||
|
|
@ -55,14 +54,14 @@ public class SingleMenu {
|
|||
modeSet.get(0).create(player);
|
||||
return;
|
||||
}
|
||||
|
||||
PagedMenu mode = new PagedMenu(3, Locales.getString(player, "play.single.name"));
|
||||
mode.displayRows(0, 1)
|
||||
.addToDisplay(items)
|
||||
.nextPage(26, new Item(Material.LIME_DYE, "<#0DCB07><bold>»").click(event -> mode.page(1)))
|
||||
.prevPage(18, new Item(Material.RED_DYE, "<#DE1F1F><bold>«").click(event -> mode.page(-1)))
|
||||
.item(22, Locales.getItem(player, "other.close").click(event -> Menus.PLAY.open(event.getPlayer())))
|
||||
.open(player);
|
||||
// PagedMenu mode = new PagedMenu(3, Locales.getString(player, "play.single.name"));
|
||||
// mode.displayRows(0, 1)
|
||||
// .addToDisplay(items)
|
||||
// .nextPage(26, new Item(Material.LIME_DYE, "<#0DCB07><bold>»").click(event -> mode.page(1)))
|
||||
// .prevPage(18, new Item(Material.RED_DYE, "<#DE1F1F><bold>«").click(event -> mode.page(-1)))
|
||||
// .item(22, Locales.getItem(player, "other.close").click(event -> Menus.PLAY.open(event.getPlayer())))
|
||||
// .open(player);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,6 @@ import dev.loki.loparkour.mode.Modes;
|
|||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.loki.loparkour.world.Divider;
|
||||
import dev.efnilite.vilib.inventory.PagedMenu;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
import dev.efnilite.vilib.inventory.item.MenuItem;
|
||||
import dev.efnilite.vilib.util.SkullSetter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
|
@ -25,6 +21,8 @@ import java.util.List;
|
|||
*/
|
||||
public class SpectatorMenu {
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(Player player) {
|
||||
ParkourUser user = ParkourUser.getUser(player);
|
||||
String locale = user == null ? Option.OPTIONS_DEFAULTS.get(ParkourOption.LANG) : user.locale;
|
||||
|
|
@ -80,5 +78,6 @@ public class SpectatorMenu {
|
|||
.open(player);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,6 @@ package dev.loki.loparkour.menu.settings;
|
|||
import dev.loki.loparkour.config.Locales;
|
||||
import dev.loki.loparkour.menu.Menus;
|
||||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.efnilite.vilib.inventory.PagedMenu;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
import dev.efnilite.vilib.inventory.item.MenuItem;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -18,29 +15,28 @@ public class LangMenu {
|
|||
*
|
||||
* @param user The ParkourPlayer instance
|
||||
*/
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(ParkourPlayer user) {
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PagedMenu style = new PagedMenu(3, Locales.getString(user.locale, "settings.lang.name"));
|
||||
|
||||
List<MenuItem> items = new ArrayList<>();
|
||||
for (String lang : Locales.locales.keySet()) {
|
||||
Item item = new Item(Material.PAPER, "<#238681><bold>" + Locales.getString(lang, "name"));
|
||||
|
||||
items.add(item.click(event -> {
|
||||
user.locale = lang;
|
||||
user._locale = lang;
|
||||
Menus.SETTINGS.open(event.getPlayer());
|
||||
}));
|
||||
}
|
||||
|
||||
style.displayRows(0, 1).addToDisplay(items)
|
||||
.nextPage(26, new Item(Material.LIME_DYE, "<#0DCB07><bold>»").click(event -> style.page(1)))
|
||||
.prevPage(18, new Item(Material.RED_DYE, "<#DE1F1F><bold>«").click(event -> style.page(-1)))
|
||||
.item(22, Locales.getItem(user.locale, "other.close").click(event -> Menus.SETTINGS.open(event.getPlayer())))
|
||||
.open(user.player);
|
||||
// PagedMenu style = new PagedMenu(3, Locales.getString(user.locale, "settings.lang.name"));
|
||||
// List<MenuItem> items = new ArrayList<>();
|
||||
// for (String lang : Locales.locales.keySet()) {
|
||||
// Item item = new Item(Material.PAPER, "<#238681><bold>" + Locales.getString(lang, "name"));
|
||||
// items.add(item.click(event -> {
|
||||
// user.locale = lang;
|
||||
// user._locale = lang;
|
||||
// Menus.SETTINGS.open(event.getPlayer());
|
||||
// }));
|
||||
// }
|
||||
// style.displayRows(0, 1).addToDisplay(items)
|
||||
// .nextPage(26, new Item(Material.LIME_DYE, "<#0DCB07><bold>»").click(event -> style.page(1)))
|
||||
// .prevPage(18, new Item(Material.RED_DYE, "<#DE1F1F><bold>«").click(event -> style.page(-1)))
|
||||
// .item(22, Locales.getItem(user.locale, "other.close").click(event -> Menus.SETTINGS.open(event.getPlayer())))
|
||||
// .open(user.player);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,14 +12,6 @@ import dev.loki.loparkour.player.ParkourPlayer;
|
|||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.loki.loparkour.style.RandomStyle;
|
||||
import dev.loki.loparkour.style.Style;
|
||||
import dev.efnilite.vilib.fastboard.FastBoard;
|
||||
import dev.efnilite.vilib.inventory.Menu;
|
||||
import dev.efnilite.vilib.inventory.MenuClickEvent;
|
||||
import dev.efnilite.vilib.inventory.PagedMenu;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
import dev.efnilite.vilib.inventory.item.MenuItem;
|
||||
import dev.efnilite.vilib.inventory.item.SliderItem;
|
||||
import dev.efnilite.vilib.inventory.item.TimedItem;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -36,6 +28,8 @@ import java.util.List;
|
|||
*/
|
||||
public class ParkourSettingsMenu extends DynamicMenu {
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public ParkourSettingsMenu(ParkourOption... disabled) {
|
||||
|
||||
// ---------- top row ----------
|
||||
|
|
@ -266,23 +260,29 @@ public class ParkourSettingsMenu extends DynamicMenu {
|
|||
.click(event -> Menus.SETTINGS.open(event.getPlayer())),
|
||||
player -> true);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Shows the main menu to a valid ParkourPlayer instance
|
||||
*
|
||||
* @param user The ParkourPlayer
|
||||
*/
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(ParkourPlayer user) {
|
||||
display(user.player, new Menu(4, Locales.getString(user.locale, "settings.name"))
|
||||
.distributeRowEvenly(0, 1, 2, 3)
|
||||
.item(27, Locales.getItem(user.locale, "other.close").click(event -> Menus.SETTINGS.open(event.getPlayer()))));
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Opens the style menu
|
||||
*
|
||||
* @param player The ParkourPlayer instance
|
||||
*/
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void openStyleMenu(ParkourPlayer player) {
|
||||
// init menu
|
||||
PagedMenu menu = new PagedMenu(3, Locales.getString(player.locale, ParkourOption.STYLES.path + ".name"));
|
||||
|
|
@ -314,13 +314,19 @@ public class ParkourSettingsMenu extends DynamicMenu {
|
|||
.item(22, Locales.getItem(player.locale, "other.close").click(event -> open(player)))
|
||||
.open(player.player);
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
private boolean handleSettingChange(ParkourPlayer player, Runnable onAllowed) {
|
||||
onAllowed.run();
|
||||
player.updateGeneratorSettings(player.session.generator);
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
private boolean handleScoreSettingChange(ParkourPlayer player, MenuClickEvent event, Runnable onAllowed) {
|
||||
if (player.session.generator.score == 0) {
|
||||
return handleSettingChange(player, onAllowed);
|
||||
|
|
@ -331,6 +337,7 @@ public class ParkourSettingsMenu extends DynamicMenu {
|
|||
return false;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
// replaces true/false with a checkmark and cross
|
||||
private String getBooleanSymbol(ParkourUser user, boolean value) {
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ import dev.loki.loparkour.menu.ParkourOption;
|
|||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.efnilite.vilib.inventory.Menu;
|
||||
import dev.efnilite.vilib.inventory.item.SliderItem;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -18,6 +16,8 @@ import java.util.List;
|
|||
*/
|
||||
public class SettingsMenu extends DynamicMenu {
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public SettingsMenu() {
|
||||
registerMainItem(1, 0, (player, user) -> Locales.getItem(player, "settings.parkour_settings.item").click(event -> {
|
||||
ParkourPlayer pp = ParkourPlayer.getPlayer(event.getPlayer());
|
||||
|
|
@ -68,8 +68,12 @@ public class SettingsMenu extends DynamicMenu {
|
|||
|
||||
registerMainItem(2, 0, (player, user) -> Locales.getItem(player, "other.close").click(event -> event.getPlayer().closeInventory()), player -> true);
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: Migrate to LoLib GUI system
|
||||
/*
|
||||
public void open(Player player) {
|
||||
display(player, new Menu(3, Locales.getString(player, "settings.name")).distributeRowsEvenly());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
package dev.loki.loparkour.mode;
|
||||
|
||||
import dev.loki.loparkour.util.Item;
|
||||
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.loki.loparkour.config.Locales;
|
||||
import dev.loki.loparkour.generator.ParkourGenerator;
|
||||
import dev.loki.loparkour.leaderboard.Leaderboard;
|
||||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
|
@ -26,7 +28,7 @@ public class DefaultMode implements Mode {
|
|||
|
||||
@Override
|
||||
@Nullable
|
||||
public Item getItem(String locale) {
|
||||
public dev.loki.loparkour.util.Item getItem(String locale) {
|
||||
return Locales.getItem(locale, "play.single.default");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
package dev.loki.loparkour.mode;
|
||||
|
||||
import dev.loki.loparkour.util.Item;
|
||||
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.loki.loparkour.config.Locales;
|
||||
import dev.loki.loparkour.generator.ParkourGenerator;
|
||||
import dev.loki.loparkour.leaderboard.Leaderboard;
|
||||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -29,7 +31,7 @@ public class ElytraMode implements Mode {
|
|||
|
||||
@Override
|
||||
@Nullable
|
||||
public Item getItem(String locale) {
|
||||
public dev.loki.loparkour.util.Item getItem(String locale) {
|
||||
return Locales.getItem(locale, "modes.elytra");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
package dev.loki.loparkour.mode;
|
||||
|
||||
import dev.loki.loparkour.util.Item;
|
||||
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.loki.loparkour.config.Locales;
|
||||
import dev.loki.loparkour.generator.ParkourGenerator;
|
||||
import dev.loki.loparkour.leaderboard.Leaderboard;
|
||||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
|
@ -30,7 +32,7 @@ public class GravityShiftMode implements Mode {
|
|||
|
||||
@Override
|
||||
@Nullable
|
||||
public Item getItem(String locale) {
|
||||
public dev.loki.loparkour.util.Item getItem(String locale) {
|
||||
return Locales.getItem(locale, "play.single.gravity-shift");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
package dev.loki.loparkour.mode;
|
||||
|
||||
import dev.loki.loparkour.util.Item;
|
||||
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.loki.loparkour.config.Locales;
|
||||
import dev.loki.loparkour.generator.ParkourGenerator;
|
||||
import dev.loki.loparkour.leaderboard.Leaderboard;
|
||||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
|
@ -23,7 +25,7 @@ public class HardcoreMode implements Mode {
|
|||
|
||||
@Override
|
||||
@Nullable
|
||||
public Item getItem(String locale) {
|
||||
public dev.loki.loparkour.util.Item getItem(String locale) {
|
||||
return Locales.getItem(locale, "play.single.hardcore");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package dev.loki.loparkour.mode;
|
||||
|
||||
import dev.loki.loparkour.leaderboard.Leaderboard;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
|
@ -23,7 +23,7 @@ public interface Mode {
|
|||
* @param locale The locale of the menu, used to adjust the name.
|
||||
* @return The item used in menus to show this mode. If this item is null, the mode won't be displayed.
|
||||
*/
|
||||
@Nullable Item getItem(String locale);
|
||||
@Nullable dev.loki.loparkour.util.Item getItem(String locale);
|
||||
|
||||
/**
|
||||
* @return The {@link Leaderboard} that belongs to this mode
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package dev.loki.loparkour.mode;
|
||||
|
||||
import dev.loki.loparkour.util.Item;
|
||||
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.loki.loparkour.config.Locales;
|
||||
import dev.loki.loparkour.leaderboard.Leaderboard;
|
||||
|
|
@ -8,8 +10,8 @@ import dev.loki.loparkour.menu.ParkourOption;
|
|||
import dev.loki.loparkour.player.ParkourSpectator;
|
||||
import dev.loki.loparkour.player.ParkourUser;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
import dev.efnilite.vilib.util.Strings;
|
||||
|
||||
import dev.loki.loparkour.util.ColorUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
|
@ -23,7 +25,7 @@ public class SpectatorMode implements Mode {
|
|||
|
||||
@Override
|
||||
@Nullable
|
||||
public Item getItem(String locale) {
|
||||
public dev.loki.loparkour.util.Item getItem(String locale) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -35,12 +37,14 @@ public class SpectatorMode implements Mode {
|
|||
|
||||
@Override
|
||||
public void create(Player player) {
|
||||
Menus.SPECTATOR.open(player);
|
||||
// TODO: Migrate to LoLib GUI
|
||||
// Menus.SPECTATOR.open(player);
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
}
|
||||
|
||||
public void create(Player player, Session session) {
|
||||
if (!Config.CONFIG.getBoolean("joining")) {
|
||||
player.sendMessage(Strings.colour("<red><bold>Joining is currently disabled."));
|
||||
player.sendMessage(ColorUtil.color("<red><bold>Joining is currently disabled."));
|
||||
return;
|
||||
}
|
||||
if (!ParkourOption.SPECTATOR.mayPerform(player)) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
package dev.loki.loparkour.mode;
|
||||
|
||||
import dev.loki.loparkour.util.Item;
|
||||
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.loki.loparkour.config.Locales;
|
||||
|
|
@ -7,8 +11,8 @@ import dev.loki.loparkour.generator.ParkourGenerator;
|
|||
import dev.loki.loparkour.leaderboard.Leaderboard;
|
||||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
import dev.efnilite.vilib.util.Task;
|
||||
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
|
|
@ -33,7 +37,7 @@ public class SpeedrunMode implements Mode {
|
|||
|
||||
@Override
|
||||
@Nullable
|
||||
public Item getItem(String locale) {
|
||||
public dev.loki.loparkour.util.Item getItem(String locale) {
|
||||
return Locales.getItem(locale, "play.single.speedrun");
|
||||
}
|
||||
|
||||
|
|
@ -74,25 +78,19 @@ public class SpeedrunMode implements Mode {
|
|||
long removalTime = (long) (blockLifetime * 1000);
|
||||
long warningTimeMs = (long) (warningTime * 1000);
|
||||
|
||||
Task.create(LoParkour.getPlugin())
|
||||
.delay((int) ((removalTime - warningTimeMs) / 50))
|
||||
.execute(() -> {
|
||||
Scheduler.get(LoParkour.getPlugin()).runLater(() -> {
|
||||
if (block.getType() != Material.AIR) {
|
||||
player.player.playSound(block.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 1.0f, 2.0f);
|
||||
player.player.spawnParticle(Particle.FLAME, block.getLocation().add(0.5, 1, 0.5), 10, 0.3, 0.3, 0.3, 0.01);
|
||||
}
|
||||
})
|
||||
.run();
|
||||
}, warningTimeMs / 50);
|
||||
|
||||
Task.create(LoParkour.getPlugin())
|
||||
.delay((int) (removalTime / 50))
|
||||
.execute(() -> {
|
||||
Scheduler.get(LoParkour.getPlugin()).runLater(() -> {
|
||||
if (block.getType() != Material.AIR) {
|
||||
block.setType(Material.AIR);
|
||||
blockTimestamps.remove(block);
|
||||
}
|
||||
})
|
||||
.run();
|
||||
}, removalTime / 50);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
package dev.loki.loparkour.player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.config.Config;
|
||||
|
|
@ -13,10 +17,8 @@ import dev.loki.loparkour.player.data.PreviousData;
|
|||
import dev.loki.loparkour.session.Session;
|
||||
import dev.loki.loparkour.storage.Storage;
|
||||
import dev.loki.loparkour.world.Divider;
|
||||
import dev.efnilite.vilib.inventory.Menu;
|
||||
import dev.efnilite.vilib.inventory.item.Item;
|
||||
import dev.efnilite.vilib.util.Colls;
|
||||
import dev.efnilite.vilib.util.Task;
|
||||
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -190,7 +192,7 @@ public class ParkourPlayer extends ParkourUser {
|
|||
Runnable write = () -> Storage.writePlayer(this);
|
||||
|
||||
if (async) {
|
||||
Task.create(LoParkour.getPlugin()).async().execute(write).run();
|
||||
Scheduler.get(LoParkour.getPlugin()).runAsync(write);
|
||||
} else {
|
||||
write.run();
|
||||
}
|
||||
|
|
@ -207,12 +209,12 @@ public class ParkourPlayer extends ParkourUser {
|
|||
|
||||
// -= Inventory =-
|
||||
if (Config.CONFIG.getBoolean("options.inventory-handling")) {
|
||||
Task.create(LoParkour.getPlugin()).delay(5).execute(() -> {
|
||||
Scheduler.get(LoParkour.getPlugin()).runLater(() -> {
|
||||
LoParkour.log("Setting up inventory for player %s".formatted(player.getName()));
|
||||
|
||||
player.getInventory().clear();
|
||||
|
||||
List<Item> items = new ArrayList<>();
|
||||
List<dev.loki.loparkour.util.Item> items = new ArrayList<>();
|
||||
|
||||
if (ParkourOption.PLAY.mayPerform(player)) items.add(Locales.getItem(locale, "play.item"));
|
||||
if (ParkourOption.COMMUNITY.mayPerform(player)) items.add(Locales.getItem(locale, "community.item"));
|
||||
|
|
@ -221,9 +223,11 @@ public class ParkourPlayer extends ParkourUser {
|
|||
|
||||
if (ParkourOption.QUIT.mayPerform(player)) items.add(Locales.getItem(locale, "other.quit"));
|
||||
|
||||
List<Integer> slots = Menu.getEvenlyDistributedSlots(items.size());
|
||||
Colls.range(0, items.size()).forEach(idx -> player.getInventory().setItem(slots.get(idx), items.get(idx).build()));
|
||||
}).run();
|
||||
List<Integer> slots = getEvenlyDistributedSlots(items.size());
|
||||
for (int idx = 0; idx < items.size(); idx++) {
|
||||
player.getInventory().setItem(slots.get(idx), items.get(idx).build());
|
||||
}
|
||||
}, 5);
|
||||
} else {
|
||||
sendTranslated("other.customize");
|
||||
}
|
||||
|
|
@ -232,4 +236,13 @@ public class ParkourPlayer extends ParkourUser {
|
|||
public record OptionContainer(ParkourOption option, BiConsumer<ParkourPlayer, String> consumer) {
|
||||
|
||||
}
|
||||
|
||||
private List<Integer> getEvenlyDistributedSlots(int count) {
|
||||
List<Integer> slots = new ArrayList<>();
|
||||
int[] positions = {10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25};
|
||||
for (int i = 0; i < Math.min(count, positions.length); i++) {
|
||||
slots.add(positions[i]);
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
package dev.loki.loparkour.player;
|
||||
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.api.event.ParkourSpectateEvent;
|
||||
import dev.loki.loparkour.config.Locales;
|
||||
import dev.loki.loparkour.player.data.PreviousData;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.efnilite.vilib.util.Strings;
|
||||
import dev.efnilite.vilib.util.Task;
|
||||
import dev.loki.loparkour.util.ColorUtil;
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import dev.lolib.scheduler.ScheduledTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
|
@ -24,7 +26,7 @@ import java.util.Comparator;
|
|||
*/
|
||||
public class ParkourSpectator extends ParkourUser {
|
||||
|
||||
private final BukkitTask closestChecker;
|
||||
private final dev.lolib.scheduler.ScheduledTask closestChecker;
|
||||
/**
|
||||
* The closest player.
|
||||
*/
|
||||
|
|
@ -38,9 +40,7 @@ public class ParkourSpectator extends ParkourUser {
|
|||
|
||||
new ParkourSpectateEvent(this).call();
|
||||
|
||||
Task.create(LoParkour.getPlugin())
|
||||
.delay(1)
|
||||
.execute(() -> {
|
||||
Scheduler.get(LoParkour.getPlugin()).runLater(() -> {
|
||||
teleport(closest.getLocation());
|
||||
|
||||
sendTranslated("play.spectator.join");
|
||||
|
|
@ -52,14 +52,9 @@ public class ParkourSpectator extends ParkourUser {
|
|||
player.setInvisible(true);
|
||||
player.setCollidable(false);
|
||||
}
|
||||
})
|
||||
.run();
|
||||
}, 1);
|
||||
|
||||
closestChecker = Task.create(LoParkour.getPlugin())
|
||||
.async()
|
||||
.delay(1)
|
||||
.repeat(10)
|
||||
.execute(() -> {
|
||||
closestChecker = Scheduler.get(LoParkour.getPlugin()).runTimerAsync(() -> {
|
||||
if (session.getPlayers().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -67,15 +62,14 @@ public class ParkourSpectator extends ParkourUser {
|
|||
closest = session.getPlayers().stream()
|
||||
.min(Comparator.comparing(other -> other.getLocation().distanceSquared(player.getLocation()))) // x or x^2 doesn't matter in getting smallest
|
||||
.orElse(closest);
|
||||
})
|
||||
.run();
|
||||
}, 1, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the spectator's action bar, scoreboard and checks distance.
|
||||
*/
|
||||
public void update() {
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(Strings.colour(Locales.getString(player, "play.spectator.action_bar"))));
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ColorUtil.color(Locales.getString(player, "play.spectator.action_bar"))));
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
updateScoreboard(session.generator);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,10 @@ import dev.loki.loparkour.player.data.PreviousData;
|
|||
import dev.loki.loparkour.session.Session;
|
||||
import dev.loki.loparkour.storage.Storage;
|
||||
import dev.loki.loparkour.world.Divider;
|
||||
import dev.efnilite.vilib.fastboard.FastBoard;
|
||||
import dev.efnilite.vilib.util.Strings;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import dev.loki.loparkour.util.ColorUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
@ -110,11 +112,13 @@ public abstract class ParkourUser {
|
|||
try {
|
||||
user.unregister();
|
||||
|
||||
if (user.board != null && !user.board.isDeleted()) {
|
||||
user.board.delete();
|
||||
}
|
||||
// TODO: Implement scoreboard deletion with LoLib
|
||||
// if (user.board != null) {
|
||||
// user.board.delete();
|
||||
// }
|
||||
} catch (Exception ex) { // safeguard to prevent people from losing data
|
||||
LoParkour.logging().stack("Error while trying to make player %s leave".formatted(user.getName()), ex);
|
||||
LoParkour.getPlugin().getLogger().log(java.util.logging.Level.SEVERE,
|
||||
"Error while trying to make player " + user.getName() + " leave", ex);
|
||||
user.send("<red><bold>There was an error while trying to handle leaving.");
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +133,7 @@ public abstract class ParkourUser {
|
|||
|
||||
Mode mode = user.session.generator.getMode();
|
||||
if (mode == null) {
|
||||
LoParkour.logging().error("Mode is null for %s".formatted(user.getName()));
|
||||
LoParkour.getPlugin().getLogger().severe("Mode is null for %s".formatted(user.getName()));
|
||||
mode = Modes.DEFAULT;
|
||||
}
|
||||
|
||||
|
|
@ -148,7 +152,7 @@ public abstract class ParkourUser {
|
|||
try {
|
||||
player.sendPluginMessage(LoParkour.getPlugin(), "BungeeCord", out.toByteArray());
|
||||
} catch (ChannelNotRegisteredException ex) {
|
||||
LoParkour.logging().stack("Error while trying to send %s to server %s. This server is not registered.".formatted(player.getName(), server), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to send %s to server %s. This server is not registered.".formatted(player.getName(), server) + " - " + ex.getMessage());
|
||||
player.kickPlayer("Couldn't move you to %s. Please rejoin.".formatted(server));
|
||||
}
|
||||
}
|
||||
|
|
@ -190,7 +194,7 @@ public abstract class ParkourUser {
|
|||
/**
|
||||
* This user's scoreboard
|
||||
*/
|
||||
public FastBoard board;
|
||||
public Scoreboard board;
|
||||
|
||||
/**
|
||||
* This user's PreviousData
|
||||
|
|
@ -230,7 +234,7 @@ public abstract class ParkourUser {
|
|||
this.previousData = previousData == null ? new PreviousData(player) : previousData;
|
||||
|
||||
if (Boolean.parseBoolean(Option.OPTIONS_DEFAULTS.get(ParkourOption.SCOREBOARD))) {
|
||||
this.board = new FastBoard(player);
|
||||
this.board = Bukkit.getScoreboardManager().getNewScoreboard();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -254,7 +258,7 @@ public abstract class ParkourUser {
|
|||
* @param message The message
|
||||
*/
|
||||
public void send(String message) {
|
||||
player.sendMessage(Strings.colour(message));
|
||||
player.sendMessage(ColorUtil.color(message));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -274,7 +278,7 @@ public abstract class ParkourUser {
|
|||
*/
|
||||
public void updateScoreboard(ParkourGenerator generator) {
|
||||
// board can be null a few ticks after on player leave
|
||||
if (board == null || board.isDeleted() || !generator.profile.get("showScoreboard").asBoolean()) {
|
||||
if (board == null || false || !generator.profile.get("showScoreboard").asBoolean()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -285,8 +289,8 @@ public abstract class ParkourUser {
|
|||
top = new Score("?", "?", "?", 0);
|
||||
}
|
||||
|
||||
board.updateTitle(replace(Locales.getString(locale, "scoreboard.title"), top, high, generator));
|
||||
board.updateLines(replace(Locales.getStringList(locale, "scoreboard.lines"), top, high, generator));
|
||||
// board.updateTitle(replace(Locales.getString(locale, "scoreboard.title"), top, high, generator));
|
||||
// board.updateLines(replace(Locales.getStringList(locale, "scoreboard.lines"), top, high, generator));
|
||||
}
|
||||
|
||||
private List<String> replace(List<String> s, Score top, Score high, ParkourGenerator generator) {
|
||||
|
|
@ -294,7 +298,7 @@ public abstract class ParkourUser {
|
|||
}
|
||||
|
||||
private String replace(String s, Score top, Score high, ParkourGenerator generator) {
|
||||
return Strings.colour(translate(player, s)
|
||||
return ColorUtil.color(translate(player, s)
|
||||
.replace("%score%", Integer.toString(generator.score))
|
||||
.replace("%time%", generator.getFormattedTime())
|
||||
.replace("%difficulty%", Double.toString(generator.getDifficultyScore()))
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package dev.loki.loparkour.player.data;
|
||||
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.efnilite.vilib.util.Task;
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
|
@ -46,7 +48,7 @@ public class InventoryData {
|
|||
return;
|
||||
}
|
||||
|
||||
Task.create(LoParkour.getPlugin()).async().execute(() -> loadFile(onFinish)).run();
|
||||
Scheduler.get(LoParkour.getPlugin()).runAsync(() -> loadFile(onFinish));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -56,7 +58,7 @@ public class InventoryData {
|
|||
|
||||
onFinish.accept(this);
|
||||
} catch (IOException | ClassNotFoundException ex) {
|
||||
LoParkour.logging().stack("Error while reading inventory of %s from file %s".formatted(player.getName(), file.getName()), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while reading inventory of %s from file %s".formatted(player.getName(), file.getName()) + " - " + ex.getMessage());
|
||||
onFinish.accept(null);
|
||||
}
|
||||
}
|
||||
|
|
@ -84,7 +86,7 @@ public class InventoryData {
|
|||
}
|
||||
|
||||
if (toFile) {
|
||||
Task.create(LoParkour.getPlugin()).async().execute(this::saveFile).run();
|
||||
Scheduler.get(LoParkour.getPlugin()).runAsync(this::saveFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,14 +95,14 @@ public class InventoryData {
|
|||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
} catch (IOException ex) {
|
||||
LoParkour.logging().stack("Error while creating file to save inventory of %s to file %s".formatted(player.getName(), file.getName()), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while creating file to save inventory of %s to file %s".formatted(player.getName(), file.getName()) + " - " + ex.getMessage());
|
||||
}
|
||||
|
||||
try (ObjectOutputStream stream = new BukkitObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) {
|
||||
stream.writeObject(items);
|
||||
stream.flush();
|
||||
} catch (IOException ex) {
|
||||
LoParkour.logging().stack("Error while saving inventory of %s to file %s".formatted(player.getName(), file.getName()), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while saving inventory of %s to file %s".formatted(player.getName(), file.getName()) + " - " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class PreviousData {
|
|||
player.setVelocity(new Vector(0, 0, 0));
|
||||
player.setFallDistance(0f);
|
||||
} catch (Exception ex) { // not the best way to do this... too bad!
|
||||
LoParkour.logging().stack("Error while recovering stats of %s".formatted(player.getName()), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while recovering stats of %s".formatted(player.getName()) + " - " + ex.getMessage());
|
||||
}
|
||||
|
||||
if (inventoryData != null) {
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public record Reward(@NotNull String string) {
|
|||
try {
|
||||
VaultHook.deposit(player.player, Double.parseDouble(string));
|
||||
} catch (NumberFormatException ex) {
|
||||
LoParkour.logging().stack("Error while trying to process Vault reward", "check your rewards file for incorrect numbers", ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to process Vault reward - check your rewards file for incorrect numbers - " + ex.getMessage());
|
||||
}
|
||||
} else {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), string);
|
||||
|
|
|
|||
|
|
@ -62,15 +62,13 @@ public class Rewards {
|
|||
int value = Integer.parseInt(score);
|
||||
|
||||
if (value < 1) {
|
||||
LoParkour.logging().stack("Error while trying to read rewards",
|
||||
"check the rewards file for incorrect numbers",
|
||||
new IllegalArgumentException("%s is not a valid score".formatted(value)));
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to read rewards - check the rewards file for incorrect numbers - " + value + " is not a valid score");
|
||||
continue;
|
||||
}
|
||||
|
||||
rewardMap.put(value, rewardStrings);
|
||||
} catch (NumberFormatException ex) {
|
||||
LoParkour.logging().stack("Error while trying to read rewards", "check the rewards file for incorrect numbers", ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to read rewards - check the rewards file for incorrect numbers - " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package dev.loki.loparkour.schematic;
|
||||
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.efnilite.vilib.util.Task;
|
||||
import dev.lolib.scheduler.Scheduler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
|
@ -24,7 +26,7 @@ public class Schematics {
|
|||
* Reads all files.
|
||||
*/
|
||||
public static void init() {
|
||||
Task.create(LoParkour.getPlugin()).async().execute(() -> {
|
||||
Scheduler.get(LoParkour.getPlugin()).runAsync(() -> {
|
||||
if (!FOLDER.exists()) {
|
||||
FOLDER.mkdirs();
|
||||
}
|
||||
|
|
@ -38,11 +40,13 @@ public class Schematics {
|
|||
}
|
||||
|
||||
try {
|
||||
dev.efnilite.vilib.schematic.Schematics.addFromFiles(LoParkour.getPlugin(), files);
|
||||
} catch (IOException | ClassNotFoundException ex) {
|
||||
LoParkour.logging().stack("Error while trying to load schematics", ex);
|
||||
// TODO: Migrate to LoLib schematics
|
||||
// dev.efnilite.vilib.schematic.Schematics.addFromFiles(LoParkour.getPlugin(), files);
|
||||
} catch (Exception ex) {
|
||||
LoParkour.getPlugin().getLogger().log(java.util.logging.Level.SEVERE,
|
||||
"Error while trying to load schematics", ex);
|
||||
}
|
||||
}).run();
|
||||
});
|
||||
}
|
||||
|
||||
private static void download() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package dev.loki.loparkour.schematic.lpschem;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import org.bukkit.Location;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package dev.loki.loparkour.schematic.lpschem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class LPSchematicManager {
|
|||
loadedSchematics.put(name, schematic);
|
||||
LoParkour.log("Loaded schematic: " + name);
|
||||
} catch (IOException e) {
|
||||
LoParkour.logging().error("Failed to load schematic: " + file.getName());
|
||||
LoParkour.getPlugin().getLogger().severe("Failed to load schematic: " + file.getName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,42 +1,44 @@
|
|||
package dev.loki.loparkour.schematic.lpschem;
|
||||
|
||||
import dev.efnilite.vilib.schematic.Schematic;
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class SchematicConverter {
|
||||
|
||||
public static LPSchematic fromVilib(@NotNull Schematic oldSchematic, @NotNull String name, @NotNull String author) {
|
||||
public static LPSchematic fromVilib(@NotNull LPSchematic oldSchematic, @NotNull String name, @NotNull String author) {
|
||||
var dimensions = oldSchematic.getDimensions();
|
||||
int width = (int) dimensions.getX();
|
||||
int height = (int) dimensions.getY();
|
||||
int length = (int) dimensions.getZ();
|
||||
// TODO: Fix LPSchematic API
|
||||
int width = 10; // dimensions.getWidth();
|
||||
int height = 10; // dimensions.getHeight();
|
||||
int length = 10; // dimensions.getLength();
|
||||
|
||||
LPSchematicBuilder builder = new LPSchematicBuilder(name, author, 0.5, width, height, length);
|
||||
|
||||
var blocks = oldSchematic.getVectorBlockMap();
|
||||
for (var entry : blocks.entrySet()) {
|
||||
var pos = entry.getKey();
|
||||
BlockData data = entry.getValue();
|
||||
|
||||
if (data != null && data.getMaterial() != Material.AIR) {
|
||||
int x = (int) pos.getX();
|
||||
int y = (int) pos.getY();
|
||||
int z = (int) pos.getZ();
|
||||
|
||||
builder.setBlock(x, y, z, data);
|
||||
|
||||
if (data.getMaterial() == Material.LIME_WOOL) {
|
||||
builder.setStart(x, y, z);
|
||||
} else if (data.getMaterial() == Material.RED_WOOL) {
|
||||
builder.setEnd(x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: Fix LPSchematic API - vilib code commented out
|
||||
// var blocks = oldSchematic.getBlocks();
|
||||
// for (Map.Entry<Location, BlockData> entry : blocks.entrySet()) {
|
||||
// var pos = entry.getKey();
|
||||
// BlockData data = entry.getValue();
|
||||
//
|
||||
// if (data != null && data.getMaterial() != Material.AIR) {
|
||||
// int x = (int) pos.getX();
|
||||
// int y = (int) pos.getY();
|
||||
// int z = (int) pos.getZ();
|
||||
//
|
||||
// builder.setBlock(x, y, z, data);
|
||||
//
|
||||
// if (data.getMaterial() == Material.LIME_WOOL) {
|
||||
// builder.setStart(x, y, z);
|
||||
// } else if (data.getMaterial() == Material.RED_WOOL) {
|
||||
// builder.setEnd(x, y, z);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if (!hasMarkers(builder)) {
|
||||
builder.setStart(0, 0, 0);
|
||||
|
|
@ -60,26 +62,27 @@ public class SchematicConverter {
|
|||
int converted = 0;
|
||||
int failed = 0;
|
||||
|
||||
try {
|
||||
for (String name : dev.efnilite.vilib.schematic.Schematics.getSchematicNames(LoParkour.getPlugin())) {
|
||||
try {
|
||||
Schematic oldSchematic = dev.efnilite.vilib.schematic.Schematics.getSchematic(LoParkour.getPlugin(), name);
|
||||
if (oldSchematic != null) {
|
||||
LPSchematic newSchematic = fromVilib(oldSchematic, name, "Converted");
|
||||
LoParkour.getSchematicManager().saveSchematic(newSchematic);
|
||||
converted++;
|
||||
LoParkour.log("Converted: " + name);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
failed++;
|
||||
LoParkour.logging().error("Failed to convert schematic: " + name);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LoParkour.logging().error("Error during schematic conversion");
|
||||
e.printStackTrace();
|
||||
}
|
||||
// TODO: Fix vilib schematic conversion - vilib code commented out
|
||||
// try {
|
||||
// for (String name : dev.efnilite.vilib.schematic.dev.loki.loparkour.schematic.Schematics.getSchematicNames(LoParkour.getPlugin())) {
|
||||
// try {
|
||||
// LPSchematic oldSchematic = dev.efnilite.vilib.schematic.dev.loki.loparkour.schematic.Schematics.getSchematic(LoParkour.getPlugin(), name);
|
||||
// if (oldSchematic != null) {
|
||||
// LPSchematic newSchematic = fromVilib(oldSchematic, name, "Converted");
|
||||
// LoParkour.getSchematicManager().saveSchematic(newSchematic);
|
||||
// converted++;
|
||||
// LoParkour.log("Converted: " + name);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// failed++;
|
||||
// LoParkour.getPlugin().getLogger().severe("Failed to convert schematic: " + name);
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// LoParkour.getPlugin().getLogger().severe("Error during schematic conversion");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
LoParkour.log("Conversion complete: " + converted + " converted, " + failed + " failed");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package dev.loki.loparkour.session;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.config.Locales;
|
||||
import dev.loki.loparkour.generator.ParkourGenerator;
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class StorageDisk {
|
|||
|
||||
return scores;
|
||||
} catch (IOException ex) {
|
||||
LoParkour.logging().stack("Error while trying to read leaderboard file %s".formatted(mode), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to read leaderboard file %s".formatted(mode) + " - " + ex.getMessage());
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ class StorageDisk {
|
|||
LoParkour.getGson().toJson(container, writer);
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
LoParkour.logging().stack("Error while trying to write to leaderboard file %s".formatted(mode), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to write to leaderboard file %s".formatted(mode) + " - " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ class StorageDisk {
|
|||
|
||||
player.setSettings(settings);
|
||||
} catch (IOException ex) {
|
||||
LoParkour.logging().stack("Error while trying to read disk data of %s".formatted(player.getName()), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to read disk data of %s".formatted(player.getName()) + " - " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +110,7 @@ class StorageDisk {
|
|||
LoParkour.getGson().toJson(player, writer);
|
||||
writer.flush();
|
||||
} catch (IOException ex) {
|
||||
LoParkour.logging().stack("Error while trying to write disk data of %s to file %s".formatted(player.getName(), file), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to write disk data of %s to file %s".formatted(player.getName(), file) + " - " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ class StorageDisk {
|
|||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
} catch (IOException ex) {
|
||||
LoParkour.logging().stack("Error while trying to create file %s".formatted(file), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to create file %s".formatted(file) + " - " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ import dev.loki.loparkour.LoParkour;
|
|||
import dev.loki.loparkour.config.Option;
|
||||
import dev.loki.loparkour.leaderboard.Score;
|
||||
import dev.loki.loparkour.player.ParkourPlayer;
|
||||
import dev.efnilite.vilib.util.Colls;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import dev.lolib.utils.Colls;
|
||||
import java.sql.*;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
|
|
@ -49,7 +50,7 @@ class StorageSQL {
|
|||
connection.close();
|
||||
LoParkour.log("Closed connection to MySQL");
|
||||
} catch (SQLException ex) {
|
||||
LoParkour.logging().stack("Error while trying to close connection to SQL database", ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to close connection to SQL database" + " - " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +77,7 @@ class StorageSQL {
|
|||
|
||||
return scores;
|
||||
} catch (SQLException ex) {
|
||||
LoParkour.logging().stack("Error while trying to read SQL data of %s".formatted(mode), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to read SQL data of %s".formatted(mode) + " - " + ex.getMessage());
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
|
@ -120,18 +121,18 @@ class StorageSQL {
|
|||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> settings = Colls.thread(ParkourPlayer.PLAYER_COLUMNS).mapv((key, value) -> {
|
||||
Map<String, Object> settings = new HashMap<>();
|
||||
for (String key : ParkourPlayer.PLAYER_COLUMNS.keySet()) {
|
||||
try {
|
||||
return results.getObject(key);
|
||||
settings.put(key, results.getObject(key));
|
||||
} catch (SQLException ex) {
|
||||
LoParkour.logging().stack("Error while trying to read SQL data of %s, option = %s".formatted(player.getName(), key), ex);
|
||||
return null;
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to read SQL data of %s, option = %s - %s".formatted(player.getName(), key, ex.getMessage()));
|
||||
}
|
||||
}).get();
|
||||
}
|
||||
|
||||
player.setSettings(settings);
|
||||
} catch (SQLException ex) {
|
||||
LoParkour.logging().stack("Error while trying to read SQL data of %s".formatted(player.getName()), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to read SQL data of %s".formatted(player.getName()) + " - " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -206,7 +207,7 @@ class StorageSQL {
|
|||
|
||||
LoParkour.log("Connected to MySQL");
|
||||
} catch (Exception ex) {
|
||||
LoParkour.logging().stack("Could not connect to MySQL", "check your SQL settings in the config", ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Could not connect to MySQL - check your SQL settings in the config - " + ex.getMessage());
|
||||
Bukkit.getPluginManager().disablePlugin(LoParkour.getPlugin()); // disable plugin since data handling without db will go horribly wrong
|
||||
}
|
||||
}
|
||||
|
|
@ -217,7 +218,7 @@ class StorageSQL {
|
|||
connect();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LoParkour.logging().stack("Error while trying to reconnect to MySQL", ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to reconnect to MySQL" + " - " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -228,7 +229,7 @@ class StorageSQL {
|
|||
try {
|
||||
return connection.prepareStatement(sql).executeQuery();
|
||||
} catch (SQLException ex) {
|
||||
LoParkour.logging().stack("Error while sending query %s".formatted(sql), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while sending query %s".formatted(sql) + " - " + ex.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -240,7 +241,7 @@ class StorageSQL {
|
|||
try (PreparedStatement statement = connection.prepareStatement(sql)) {
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
LoParkour.logging().stack("Error while sending query %s".formatted(sql), ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while sending query %s".formatted(sql) + " - " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
41
src/main/java/dev/loki/loparkour/util/ColorUtil.java
Normal file
41
src/main/java/dev/loki/loparkour/util/ColorUtil.java
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package dev.loki.loparkour.util;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Utility class for color formatting
|
||||
* Replaces vilib ColorUtil.color()
|
||||
*/
|
||||
public class ColorUtil {
|
||||
|
||||
private static final Pattern HEX_PATTERN = Pattern.compile("&#([A-Fa-f0-9]{6})");
|
||||
|
||||
/**
|
||||
* Converts color codes to Minecraft format
|
||||
* Supports both legacy (&) and hex (&#RRGGBB) colors
|
||||
*
|
||||
* @param text The text to color
|
||||
* @return Colored text
|
||||
*/
|
||||
public static String color(String text) {
|
||||
if (text == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
// Convert hex colors &#RRGGBB to <#RRGGBB>
|
||||
Matcher matcher = HEX_PATTERN.matcher(text);
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
while (matcher.find()) {
|
||||
String hexCode = matcher.group(1);
|
||||
matcher.appendReplacement(buffer, ChatColor.of("#" + hexCode).toString());
|
||||
}
|
||||
matcher.appendTail(buffer);
|
||||
|
||||
// Convert legacy color codes
|
||||
return ChatColor.translateAlternateColorCodes('&', buffer.toString());
|
||||
}
|
||||
}
|
||||
110
src/main/java/dev/loki/loparkour/util/Item.java
Normal file
110
src/main/java/dev/loki/loparkour/util/Item.java
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
package dev.loki.loparkour.util;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Simple ItemStack builder for migration from vilib
|
||||
*/
|
||||
public class Item {
|
||||
private final ItemStack item;
|
||||
private Consumer<org.bukkit.event.inventory.InventoryClickEvent> clickHandler;
|
||||
|
||||
public Item(@NotNull Material material, @NotNull String name) {
|
||||
this.item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null) {
|
||||
meta.setDisplayName(ColorUtil.color(name));
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
||||
public Item lore(@NotNull String... lore) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null) {
|
||||
List<String> loreList = new ArrayList<>();
|
||||
for (String line : lore) {
|
||||
loreList.add(ColorUtil.color(line));
|
||||
}
|
||||
meta.setLore(loreList);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Item lore(@NotNull List<String> lore) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null) {
|
||||
List<String> loreList = new ArrayList<>();
|
||||
for (String line : lore) {
|
||||
loreList.add(ColorUtil.color(line));
|
||||
}
|
||||
meta.setLore(loreList);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Item material(@NotNull Material material) {
|
||||
item.setType(material);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Item click(@NotNull Consumer<org.bukkit.event.inventory.InventoryClickEvent> handler) {
|
||||
this.clickHandler = handler;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Item modifyLore(@NotNull Function<String, String> modifier) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null && meta.hasLore()) {
|
||||
List<String> lore = meta.getLore();
|
||||
if (lore != null) {
|
||||
List<String> newLore = new ArrayList<>();
|
||||
for (String line : lore) {
|
||||
newLore.add(modifier.apply(line));
|
||||
}
|
||||
meta.setLore(newLore);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Item modifyName(@NotNull Function<String, String> modifier) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null && meta.hasDisplayName()) {
|
||||
meta.setDisplayName(modifier.apply(meta.getDisplayName()));
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Item meta(@NotNull ItemMeta meta) {
|
||||
item.setItemMeta(meta);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item clone() {
|
||||
Item cloned = new Item(item.getType(), "");
|
||||
cloned.item.setItemMeta(item.getItemMeta());
|
||||
cloned.clickHandler = this.clickHandler;
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public ItemStack build() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public Consumer<org.bukkit.event.inventory.InventoryClickEvent> getClickHandler() {
|
||||
return clickHandler;
|
||||
}
|
||||
}
|
||||
58
src/main/java/dev/loki/loparkour/util/Locations.java
Normal file
58
src/main/java/dev/loki/loparkour/util/Locations.java
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
package dev.loki.loparkour.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
/**
|
||||
* Location utilities (replacement for vilib Locations)
|
||||
*/
|
||||
public class Locations {
|
||||
|
||||
/**
|
||||
* Gets the maximum location from two locations (highest x, y, z)
|
||||
*
|
||||
* @param a First location
|
||||
* @param b Second location
|
||||
* @return Location with maximum coordinates
|
||||
*/
|
||||
public static Location max(Location a, Location b) {
|
||||
return new Location(
|
||||
a.getWorld(),
|
||||
Math.max(a.getX(), b.getX()),
|
||||
Math.max(a.getY(), b.getY()),
|
||||
Math.max(a.getZ(), b.getZ())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the minimum location from two locations (lowest x, y, z)
|
||||
*
|
||||
* @param a First location
|
||||
* @param b Second location
|
||||
* @return Location with minimum coordinates
|
||||
*/
|
||||
public static Location min(Location a, Location b) {
|
||||
return new Location(
|
||||
a.getWorld(),
|
||||
Math.min(a.getX(), b.getX()),
|
||||
Math.min(a.getY(), b.getY()),
|
||||
Math.min(a.getZ(), b.getZ())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts location to string
|
||||
*
|
||||
* @param location Location to convert
|
||||
* @param includeYawPitch Whether to include yaw and pitch
|
||||
* @return String representation
|
||||
*/
|
||||
public static String toString(Location location, boolean includeYawPitch) {
|
||||
if (includeYawPitch) {
|
||||
return String.format("%.2f, %.2f, %.2f (yaw: %.2f, pitch: %.2f)",
|
||||
location.getX(), location.getY(), location.getZ(),
|
||||
location.getYaw(), location.getPitch());
|
||||
}
|
||||
return String.format("%.2f, %.2f, %.2f",
|
||||
location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
}
|
||||
31
src/main/java/dev/loki/loparkour/util/Menu.java
Normal file
31
src/main/java/dev/loki/loparkour/util/Menu.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package dev.loki.loparkour.util;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Temporary stub for Menu during migration
|
||||
*/
|
||||
public class Menu {
|
||||
private final int rows;
|
||||
private final String title;
|
||||
|
||||
public Menu(int rows, String title) {
|
||||
this.rows = rows;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public Menu item(int slot, Item item) {
|
||||
// TODO: Implement with LoLib GUI
|
||||
return this;
|
||||
}
|
||||
|
||||
public Menu distributeRowsEvenly() {
|
||||
// TODO: Implement
|
||||
return this;
|
||||
}
|
||||
|
||||
public void open(Player player) {
|
||||
// TODO: Implement with LoLib GUI
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
}
|
||||
}
|
||||
19
src/main/java/dev/loki/loparkour/util/MenuItem.java
Normal file
19
src/main/java/dev/loki/loparkour/util/MenuItem.java
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package dev.loki.loparkour.util;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Menu item holder for migration from vilib
|
||||
*/
|
||||
public class MenuItem {
|
||||
private final ItemStack item;
|
||||
|
||||
public MenuItem(@NotNull ItemStack item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
53
src/main/java/dev/loki/loparkour/util/PagedMenu.java
Normal file
53
src/main/java/dev/loki/loparkour/util/PagedMenu.java
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package dev.loki.loparkour.util;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Temporary stub for PagedMenu during migration
|
||||
*/
|
||||
public class PagedMenu {
|
||||
private final int rows;
|
||||
private final String title;
|
||||
private final List<MenuItem> items = new ArrayList<>();
|
||||
|
||||
public PagedMenu(int rows, String title) {
|
||||
this.rows = rows;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public PagedMenu addToDisplay(List<Item> items) {
|
||||
// TODO: Implement with LoLib GUI
|
||||
return this;
|
||||
}
|
||||
|
||||
public PagedMenu item(int slot, Item item) {
|
||||
// TODO: Implement with LoLib GUI
|
||||
return this;
|
||||
}
|
||||
|
||||
public PagedMenu nextPage(int slot, Item item) {
|
||||
// TODO: Implement with LoLib GUI
|
||||
return this;
|
||||
}
|
||||
|
||||
public PagedMenu prevPage(int slot, Item item) {
|
||||
// TODO: Implement with LoLib GUI
|
||||
return this;
|
||||
}
|
||||
|
||||
public void page(int direction) {
|
||||
// TODO: Implement with LoLib GUI
|
||||
}
|
||||
|
||||
public List<Object> getTotalToDisplay() {
|
||||
// TODO: Implement with LoLib GUI
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public void open(Player player) {
|
||||
// TODO: Implement with LoLib GUI
|
||||
player.sendMessage("§cМеню временно недоступно во время миграции");
|
||||
}
|
||||
}
|
||||
79
src/main/java/dev/loki/loparkour/util/ParticleData.java
Normal file
79
src/main/java/dev/loki/loparkour/util/ParticleData.java
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
package dev.loki.loparkour.util;
|
||||
|
||||
import dev.loki.loparkour.util.ParticleData;
|
||||
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Particle data holder for migration from vilib
|
||||
*/
|
||||
public class ParticleData<T> {
|
||||
private final Particle particle;
|
||||
private final T data;
|
||||
private int size = 1;
|
||||
private double speed = 0.0;
|
||||
private double offsetX = 0.0;
|
||||
private double offsetY = 0.0;
|
||||
private double offsetZ = 0.0;
|
||||
|
||||
public ParticleData(@NotNull Particle particle, @Nullable T data, int size) {
|
||||
this.particle = particle;
|
||||
this.data = data;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public ParticleData<T> size(int size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ParticleData<T> speed(double speed) {
|
||||
this.speed = speed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ParticleData<T> offsetX(double offsetX) {
|
||||
this.offsetX = offsetX;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ParticleData<T> offsetY(double offsetY) {
|
||||
this.offsetY = offsetY;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ParticleData<T> offsetZ(double offsetZ) {
|
||||
this.offsetZ = offsetZ;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Particle getParticle() {
|
||||
return particle;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public double getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public double getOffsetX() {
|
||||
return offsetX;
|
||||
}
|
||||
|
||||
public double getOffsetY() {
|
||||
return offsetY;
|
||||
}
|
||||
|
||||
public double getOffsetZ() {
|
||||
return offsetZ;
|
||||
}
|
||||
}
|
||||
101
src/main/java/dev/loki/loparkour/util/ParticleUtil.java
Normal file
101
src/main/java/dev/loki/loparkour/util/ParticleUtil.java
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
package dev.loki.loparkour.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
/**
|
||||
* Utility class for particle effects
|
||||
* Replaces vilib Particles
|
||||
*/
|
||||
public class ParticleUtil {
|
||||
|
||||
/**
|
||||
* Shows a box outline with particles
|
||||
*
|
||||
* @param box The bounding box
|
||||
* @param world The world
|
||||
* @param particle The particle type
|
||||
* @param player The player to show particles to
|
||||
* @param spacing The spacing between particles
|
||||
*/
|
||||
public static void box(BoundingBox box, World world, Particle particle, Player player, double spacing) {
|
||||
double minX = box.getMinX();
|
||||
double minY = box.getMinY();
|
||||
double minZ = box.getMinZ();
|
||||
double maxX = box.getMaxX();
|
||||
double maxY = box.getMaxY();
|
||||
double maxZ = box.getMaxZ();
|
||||
|
||||
// Draw edges
|
||||
for (double x = minX; x <= maxX; x += spacing) {
|
||||
player.spawnParticle(particle, x, minY, minZ, 1, 0, 0, 0, 0);
|
||||
player.spawnParticle(particle, x, minY, maxZ, 1, 0, 0, 0, 0);
|
||||
player.spawnParticle(particle, x, maxY, minZ, 1, 0, 0, 0, 0);
|
||||
player.spawnParticle(particle, x, maxY, maxZ, 1, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
for (double y = minY; y <= maxY; y += spacing) {
|
||||
player.spawnParticle(particle, minX, y, minZ, 1, 0, 0, 0, 0);
|
||||
player.spawnParticle(particle, minX, y, maxZ, 1, 0, 0, 0, 0);
|
||||
player.spawnParticle(particle, maxX, y, minZ, 1, 0, 0, 0, 0);
|
||||
player.spawnParticle(particle, maxX, y, maxZ, 1, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
for (double z = minZ; z <= maxZ; z += spacing) {
|
||||
player.spawnParticle(particle, minX, minY, z, 1, 0, 0, 0, 0);
|
||||
player.spawnParticle(particle, minX, maxY, z, 1, 0, 0, 0, 0);
|
||||
player.spawnParticle(particle, maxX, minY, z, 1, 0, 0, 0, 0);
|
||||
player.spawnParticle(particle, maxX, maxY, z, 1, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows particles at a location
|
||||
*
|
||||
* @param location The location
|
||||
* @param particle The particle type
|
||||
* @param count The number of particles
|
||||
*/
|
||||
public static void show(Location location, Particle particle, int count) {
|
||||
location.getWorld().spawnParticle(particle, location, count, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws particles at a location with offset
|
||||
*
|
||||
* @param location Location
|
||||
* @param particle Particle type
|
||||
* @param count Number of particles
|
||||
* @param offsetX X offset
|
||||
* @param offsetY Y offset
|
||||
* @param offsetZ Z offset
|
||||
* @param speed Particle speed
|
||||
*/
|
||||
public static void draw(Location location, Particle particle, int count, double offsetX, double offsetY, double offsetZ, double speed) {
|
||||
if (location.getWorld() != null) {
|
||||
location.getWorld().spawnParticle(particle, location, count, offsetX, offsetY, offsetZ, speed);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws particles in a circle
|
||||
*
|
||||
* @param center Center location
|
||||
* @param particle Particle type
|
||||
* @param radius Circle radius
|
||||
* @param points Number of points
|
||||
*/
|
||||
public static void circle(Location center, Particle particle, int radius, int points) {
|
||||
if (center.getWorld() == null) return;
|
||||
|
||||
for (int i = 0; i < points; i++) {
|
||||
double angle = 2 * Math.PI * i / points;
|
||||
double x = center.getX() + radius * Math.cos(angle);
|
||||
double z = center.getZ() + radius * Math.sin(angle);
|
||||
center.getWorld().spawnParticle(particle, x, center.getY(), z, 1, 0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
59
src/main/java/dev/loki/loparkour/util/Probs.java
Normal file
59
src/main/java/dev/loki/loparkour/util/Probs.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package dev.loki.loparkour.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* Probability utilities (replacement for vilib Probs)
|
||||
*/
|
||||
public class Probs {
|
||||
|
||||
/**
|
||||
* Selects a random key from a map based on weighted probabilities
|
||||
*
|
||||
* @param chances Map of items to their probability weights
|
||||
* @param <T> The type of items
|
||||
* @return A randomly selected item based on weights
|
||||
*/
|
||||
public static <T> T random(Map<T, Double> chances) {
|
||||
return random(chances, ThreadLocalRandom.current());
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects a random key from a map based on weighted probabilities
|
||||
*
|
||||
* @param chances Map of items to their probability weights
|
||||
* @param random Random instance to use
|
||||
* @param <T> The type of items
|
||||
* @return A randomly selected item based on weights
|
||||
*/
|
||||
public static <T> T random(Map<T, Double> chances, Random random) {
|
||||
double totalWeight = chances.values().stream().mapToDouble(Double::doubleValue).sum();
|
||||
double randomValue = random.nextDouble() * totalWeight;
|
||||
|
||||
double currentWeight = 0;
|
||||
for (Map.Entry<T, Double> entry : chances.entrySet()) {
|
||||
currentWeight += entry.getValue();
|
||||
if (randomValue <= currentWeight) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to first entry
|
||||
return chances.keySet().iterator().next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Normal probability density function
|
||||
*
|
||||
* @param mean Mean value
|
||||
* @param stdDev Standard deviation
|
||||
* @param x Value to calculate probability for
|
||||
* @return Probability density at x
|
||||
*/
|
||||
public static double normalpdf(double mean, double stdDev, double x) {
|
||||
double exponent = -Math.pow(x - mean, 2) / (2 * Math.pow(stdDev, 2));
|
||||
return (1 / (stdDev * Math.sqrt(2 * Math.PI))) * Math.exp(exponent);
|
||||
}
|
||||
}
|
||||
16
src/main/java/dev/loki/loparkour/util/SkullSetter.java
Normal file
16
src/main/java/dev/loki/loparkour/util/SkullSetter.java
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package dev.loki.loparkour.util;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
/**
|
||||
* Utility for setting player heads
|
||||
*/
|
||||
public class SkullSetter {
|
||||
|
||||
public static void setPlayerHead(OfflinePlayer player, SkullMeta meta) {
|
||||
if (meta != null && player != null) {
|
||||
meta.setOwningPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
src/main/java/dev/loki/loparkour/util/SliderItem.java
Normal file
20
src/main/java/dev/loki/loparkour/util/SliderItem.java
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package dev.loki.loparkour.util;
|
||||
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Temporary stub for SliderItem during migration
|
||||
*/
|
||||
public class SliderItem {
|
||||
|
||||
public SliderItem initial(int value) {
|
||||
// TODO: Implement with LoLib GUI
|
||||
return this;
|
||||
}
|
||||
|
||||
public SliderItem add(int index, Item item, Consumer<InventoryClickEvent> handler) {
|
||||
// TODO: Implement with LoLib GUI
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ package dev.loki.loparkour.world;
|
|||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.config.Option;
|
||||
import dev.loki.loparkour.session.Session;
|
||||
import dev.efnilite.vilib.util.Locations;
|
||||
import dev.loki.loparkour.util.Locations;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
package dev.loki.loparkour.world;
|
||||
|
||||
import dev.lolib.worlds.VoidGenerator;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.config.Config;
|
||||
import dev.efnilite.vilib.util.VoidGenerator;
|
||||
|
||||
import dev.lolib.worlds.VoidGenerator;
|
||||
import org.bukkit.*;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -29,7 +33,7 @@ public class World {
|
|||
}
|
||||
|
||||
if (world != null) {
|
||||
LoParkour.logging().warn("Crash detected! The parkour world loading twice is not usual behaviour. This only happens after a server crash.");
|
||||
LoParkour.getPlugin().getLogger().warning("Crash detected! The parkour world loading twice is not usual behaviour. This only happens after a server crash.");
|
||||
}
|
||||
|
||||
if (Config.CONFIG.getBoolean("world.delete-on-reload")) {
|
||||
|
|
@ -52,7 +56,7 @@ public class World {
|
|||
|
||||
world = Bukkit.createWorld(creator);
|
||||
} catch (Exception ex) {
|
||||
LoParkour.logging().stack("Error while trying to create the parkour world", "delete the parkour world folder and restart the server", ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to create the parkour world - delete the parkour world folder and restart the server - " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -106,7 +110,7 @@ public class World {
|
|||
.map(Path::toFile)
|
||||
.forEach(File::delete);
|
||||
} catch (Exception ex) {
|
||||
LoParkour.logging().stack("Error while trying to delete the parkour world", ex);
|
||||
LoParkour.getPlugin().getLogger().severe("Error while trying to delete the parkour world" + " - " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue