diff --git a/CHANGES.md b/CHANGES.md index d1271fc7..c6f620c6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,7 @@ **[Infinite Elytra Parkour](https://www.spigotmc.org/resources/115322/) | [Infinite Parkour+](https://www.spigotmc.org/resources/105019/)** -- Fixed first release of major versions not working -- Fixed spectator permission not working with /ip join \ No newline at end of file +- Running Multiverse with IP now does not require VoidGen +- Improved responsiveness of parkour and scoreboard +- Fixed leaderboards sorting being wrong +- Fixed placeholders returning wrong values +- Fixed vague sorting locale in leaderboard menu \ No newline at end of file diff --git a/pom.xml b/pom.xml index 94a30bfd..5a79f432 100644 --- a/pom.xml +++ b/pom.xml @@ -120,13 +120,6 @@ provided - - com.onarandombox.multiversecore - Multiverse-Core - 4.3.0 - provided - - com.github.MilkBowl VaultAPI diff --git a/src/main/java/dev/efnilite/ip/Command.java b/src/main/java/dev/efnilite/ip/Command.java index 3de12bf8..8a2ee7d6 100644 --- a/src/main/java/dev/efnilite/ip/Command.java +++ b/src/main/java/dev/efnilite/ip/Command.java @@ -6,7 +6,6 @@ import dev.efnilite.ip.leaderboard.Leaderboard; import dev.efnilite.ip.menu.Menus; import dev.efnilite.ip.menu.ParkourOption; -import dev.efnilite.ip.menu.community.SingleLeaderboardMenu; import dev.efnilite.ip.mode.Mode; import dev.efnilite.ip.mode.Modes; import dev.efnilite.ip.mode.MultiMode; @@ -451,7 +450,7 @@ private void handle2Args(@NotNull String arg1, @NotNull String arg2, @NotNull Co if (mode == null) { Menus.LEADERBOARDS.open(player); } else { - Menus.SINGLE_LEADERBOARD.open(player, mode, SingleLeaderboardMenu.Sort.SCORE); + Menus.SINGLE_LEADERBOARD.open(player, mode, Leaderboard.Sort.SCORE); } } case "schematic" -> { diff --git a/src/main/java/dev/efnilite/ip/Events.java b/src/main/java/dev/efnilite/ip/Events.java index 8f8706e8..4e9d078f 100644 --- a/src/main/java/dev/efnilite/ip/Events.java +++ b/src/main/java/dev/efnilite/ip/Events.java @@ -10,13 +10,11 @@ import dev.efnilite.ip.player.ParkourUser; import dev.efnilite.ip.session.Session; import dev.efnilite.ip.world.WorldManager; -import dev.efnilite.ip.world.WorldManagerMV; 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 dev.efnilite.vilib.util.VoidGenerator; import io.papermc.lib.PaperLib; import org.bukkit.*; import org.bukkit.command.CommandSender; @@ -78,12 +76,6 @@ public void chat(AsyncPlayerChatEvent event) { public void join(PlayerJoinEvent event) { Player player = event.getPlayer(); - if (player.isOp() && WorldManagerMV.MANAGER != null && VoidGenerator.getMultiverseGenerator() == null) { - send(player, ""); - send(player, IP.PREFIX + "You are running Multiverse without VoidGen. This causes extreme lag spikes and performance issues while playing. Please install the plugin 'VoidGen' to fix this."); - send(player, ""); - } - if (Config.CONFIG.getBoolean("bungeecord.enabled")) { Modes.DEFAULT.create(player); return; diff --git a/src/main/java/dev/efnilite/ip/config/Option.java b/src/main/java/dev/efnilite/ip/config/Option.java index b2985e8c..e3a644f6 100644 --- a/src/main/java/dev/efnilite/ip/config/Option.java +++ b/src/main/java/dev/efnilite/ip/config/Option.java @@ -27,9 +27,6 @@ public class Option { public static Map OPTIONS_ENABLED; public static Map OPTIONS_DEFAULTS; - // Worlds - public static String WORLD_NAME; - public static Location GO_BACK_LOC; public static void init(boolean firstLoad) { @@ -46,15 +43,6 @@ public static void init(boolean firstLoad) { // General settings - // Worlds - WORLD_NAME = Config.CONFIG.getString("world.name"); - - if (!WORLD_NAME.matches("[a-zA-Z0-9_-]+")) { - IP.logging().stack("Invalid world name: %s".formatted(WORLD_NAME), "world names need to contain only a-z, A-Z, 0-9, _ or -."); - - WORLD_NAME = "witp"; - } - // Options List options = new ArrayList<>(Arrays.asList(ParkourOption.values())); diff --git a/src/main/java/dev/efnilite/ip/generator/GeneratorOption.java b/src/main/java/dev/efnilite/ip/generator/GeneratorOption.java index b8e1e3e1..8318b792 100644 --- a/src/main/java/dev/efnilite/ip/generator/GeneratorOption.java +++ b/src/main/java/dev/efnilite/ip/generator/GeneratorOption.java @@ -7,7 +7,6 @@ public enum GeneratorOption { DISABLE_SCHEMATICS, DISABLE_SPECIAL, - REDUCE_RANDOM_BLOCK_SELECTION_ANGLE, - INCREASED_TICK_ACCURACY + REDUCE_RANDOM_BLOCK_SELECTION_ANGLE } diff --git a/src/main/java/dev/efnilite/ip/generator/ParkourGenerator.java b/src/main/java/dev/efnilite/ip/generator/ParkourGenerator.java index ef497546..115a1fd2 100644 --- a/src/main/java/dev/efnilite/ip/generator/ParkourGenerator.java +++ b/src/main/java/dev/efnilite/ip/generator/ParkourGenerator.java @@ -375,7 +375,7 @@ public void menu(ParkourPlayer player) { public void startTick() { task = Task.create(IP.getPlugin()) - .repeat(generatorOptions.contains(GeneratorOption.INCREASED_TICK_ACCURACY) ? 1 : Config.GENERATION.getInt("advanced.generator-check")) + .repeat(1) .execute(this::tick) .run(); } diff --git a/src/main/java/dev/efnilite/ip/leaderboard/Leaderboard.java b/src/main/java/dev/efnilite/ip/leaderboard/Leaderboard.java index 72bae190..4ce4e1c9 100644 --- a/src/main/java/dev/efnilite/ip/leaderboard/Leaderboard.java +++ b/src/main/java/dev/efnilite/ip/leaderboard/Leaderboard.java @@ -2,7 +2,6 @@ import dev.efnilite.ip.IP; import dev.efnilite.ip.config.Config; -import dev.efnilite.ip.menu.community.SingleLeaderboardMenu; import dev.efnilite.ip.storage.Storage; import dev.efnilite.vilib.util.Task; import org.jetbrains.annotations.NotNull; @@ -23,14 +22,14 @@ public class Leaderboard { /** * The way in which items will be sorted. */ - public final SingleLeaderboardMenu.Sort sort; + public final Sort sort; /** * A map of all scores for this mode */ public final Map scores = new LinkedHashMap<>(); - public Leaderboard(@NotNull String mode, SingleLeaderboardMenu.Sort sort) { + public Leaderboard(@NotNull String mode, Sort sort) { this.mode = mode.toLowerCase(); this.sort = sort; @@ -89,18 +88,45 @@ private void run(Runnable runnable, boolean async) { } } - // sorts all scores in the map - private void sort() { + /** + * Returns sorted copy of the score map. + * @param sort The sorting method. + * @return A sorted map of scores. + */ + public Map sort(Sort sort) { LinkedHashMap sorted = new LinkedHashMap<>(); scores.entrySet().stream() - .sorted((one, two) -> switch (sort) { - case SCORE -> two.getValue().score() - one.getValue().score(); - case TIME -> two.getValue().getTimeMillis() - one.getValue().getTimeMillis(); - case DIFFICULTY -> (int) Math.signum(Double.parseDouble(two.getValue().difficulty()) - Double.parseDouble(one.getValue().difficulty())); + .sorted((one, two) -> { + switch (sort) { + case SCORE -> { + int scoreComparison = two.getValue().score() - one.getValue().score(); + + if (scoreComparison != 0) { + return scoreComparison; + } else { + return one.getValue().getTimeMillis() - two.getValue().getTimeMillis(); + } + } + case TIME -> { + return one.getValue().getTimeMillis() - two.getValue().getTimeMillis(); + } + case DIFFICULTY -> { + return (int) Math.signum(Double.parseDouble(two.getValue().difficulty()) - + Double.parseDouble(one.getValue().difficulty())); + } + default -> throw new IllegalArgumentException("Invalid sort method"); + } }) .forEachOrdered(entry -> sorted.put(entry.getKey(), entry.getValue())); + return sorted; + } + + // sorts all scores in the map + private void sort() { + var sorted = sort(sort); + scores.clear(); scores.putAll(sorted); } @@ -171,4 +197,8 @@ public Score getScoreAtRank(int rank) { return new ArrayList<>(scores.values()).get(rank - 1); } + + public enum Sort { + SCORE, TIME, DIFFICULTY + } } \ No newline at end of file diff --git a/src/main/java/dev/efnilite/ip/menu/community/LeaderboardsMenu.java b/src/main/java/dev/efnilite/ip/menu/community/LeaderboardsMenu.java index 1af70b00..2658fad0 100644 --- a/src/main/java/dev/efnilite/ip/menu/community/LeaderboardsMenu.java +++ b/src/main/java/dev/efnilite/ip/menu/community/LeaderboardsMenu.java @@ -43,7 +43,7 @@ public void open(Player player) { } if (items.size() == 1) { - Menus.SINGLE_LEADERBOARD.open(player, latest, SingleLeaderboardMenu.Sort.SCORE); + Menus.SINGLE_LEADERBOARD.open(player, latest, Leaderboard.Sort.SCORE); return; } diff --git a/src/main/java/dev/efnilite/ip/menu/community/SingleLeaderboardMenu.java b/src/main/java/dev/efnilite/ip/menu/community/SingleLeaderboardMenu.java index ffd98086..764a4dc9 100644 --- a/src/main/java/dev/efnilite/ip/menu/community/SingleLeaderboardMenu.java +++ b/src/main/java/dev/efnilite/ip/menu/community/SingleLeaderboardMenu.java @@ -21,15 +21,17 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; -import java.util.*; -import java.util.stream.Collectors; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.UUID; /** * Menu for a single leaderboard */ public class SingleLeaderboardMenu { - public void open(Player player, Mode mode, Sort sort) { + public void open(Player player, Mode mode, Leaderboard.Sort sort) { Leaderboard leaderboard = mode.getLeaderboard(); if (leaderboard == null) { @@ -37,19 +39,19 @@ public void open(Player player, Mode mode, Sort sort) { } // init vars - ParkourUser user = ParkourUser.getUser(player); - String locale = user == null ? Option.OPTIONS_DEFAULTS.get(ParkourOption.LANG) : user.locale; - PagedMenu menu = new PagedMenu(3, Locales.getString(player, "%s.name".formatted(ParkourOption.LEADERBOARDS.path))); + 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))); - List items = new ArrayList<>(); + var items = new ArrayList(); - Item base = Locales.getItem(player, "%s.head".formatted(ParkourOption.LEADERBOARDS.path)); + var base = Locales.getItem(player, "%s.head".formatted(ParkourOption.LEADERBOARDS.path)); - Map sorted = sort.sort(leaderboard.scores); - - for (UUID uuid : sorted.keySet()) { + for (Map.Entry entry : leaderboard.sort(sort).entrySet()) { int rank = items.size() + 1; - Score score = sorted.get(uuid); + + var uuid = entry.getKey(); + var score = entry.getValue(); if (score == null) { continue; @@ -73,7 +75,7 @@ public void open(Player player, Mode mode, Sort sort) { // 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 <= 36 && !ParkourUser.isBedrockPlayer(player)) { + 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 . @@ -107,10 +109,10 @@ public void open(Player player, Mode mode, Sort sort) { }; // get next sorting type - Sort next = switch (sort) { - case SCORE -> Sort.TIME; - case TIME -> Sort.DIFFICULTY; - default -> Sort.SCORE; + var next = switch (sort) { + case SCORE -> Leaderboard.Sort.TIME; + case TIME -> Leaderboard.Sort.DIFFICULTY; + default -> Leaderboard.Sort.SCORE; }; menu.displayRows(0, 1) @@ -133,41 +135,4 @@ public void open(Player player, Mode mode, Sort sort) { })) .open(player); } - - public enum Sort { - - SCORE { - @Override - Map sort(Map scores) { - return scores; // already sorted - } - }, TIME { - @Override - Map sort(Map scores) { - return scores.entrySet().stream().sorted((o1, o2) -> { - long one = o1.getValue().getTimeMillis(); - long two = o2.getValue().getTimeMillis(); - - return Math.toIntExact(one - two); // natural order (lower == better) - }) // reverse natural order - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> b, LinkedHashMap::new)); - } - }, DIFFICULTY { - @Override - Map sort(Map scores) { - return scores.entrySet().stream().sorted((o1, o2) -> { - String first = o1.getValue().difficulty(); - String second = o2.getValue().difficulty(); - - double one = Double.parseDouble(first.equals("?") ? "1.0" : first); - double two = Double.parseDouble(second.equals("?") ? "1.0" : second); - - return (int) (100 * (two - one)); // reverse natural order (higher == better) - }) // reverse natural order - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> b, LinkedHashMap::new)); - } - }; - - abstract Map sort(Map scores); - } } \ No newline at end of file diff --git a/src/main/java/dev/efnilite/ip/mode/DefaultMode.java b/src/main/java/dev/efnilite/ip/mode/DefaultMode.java index 15c364ea..86b20847 100644 --- a/src/main/java/dev/efnilite/ip/mode/DefaultMode.java +++ b/src/main/java/dev/efnilite/ip/mode/DefaultMode.java @@ -4,7 +4,6 @@ import dev.efnilite.ip.config.Locales; import dev.efnilite.ip.generator.ParkourGenerator; import dev.efnilite.ip.leaderboard.Leaderboard; -import dev.efnilite.ip.menu.community.SingleLeaderboardMenu; import dev.efnilite.ip.player.ParkourPlayer; import dev.efnilite.ip.session.Session; import dev.efnilite.vilib.inventory.item.Item; @@ -17,7 +16,7 @@ */ public class DefaultMode implements Mode { - private final Leaderboard leaderboard = new Leaderboard(getName(), SingleLeaderboardMenu.Sort.SCORE); + private final Leaderboard leaderboard = new Leaderboard(getName(), Leaderboard.Sort.SCORE); @Override @NotNull diff --git a/src/main/java/dev/efnilite/ip/player/ParkourPlayer.java b/src/main/java/dev/efnilite/ip/player/ParkourPlayer.java index bf38b703..8e2ee126 100644 --- a/src/main/java/dev/efnilite/ip/player/ParkourPlayer.java +++ b/src/main/java/dev/efnilite/ip/player/ParkourPlayer.java @@ -19,6 +19,7 @@ import dev.efnilite.vilib.util.Task; import org.bukkit.GameMode; import org.bukkit.Location; +import org.bukkit.Registry; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -85,6 +86,8 @@ public ParkourPlayer(@NotNull Player player, @NotNull Session session, @Nullable player.setFlying(false); player.setAllowFlight(false); player.setInvisible(false); + + Registry.EFFECT.stream().forEach(player::removePotionEffect); } private static boolean parseBoolean(String string) { diff --git a/src/main/java/dev/efnilite/ip/player/ParkourUser.java b/src/main/java/dev/efnilite/ip/player/ParkourUser.java index 26db56f2..8f3d382a 100644 --- a/src/main/java/dev/efnilite/ip/player/ParkourUser.java +++ b/src/main/java/dev/efnilite/ip/player/ParkourUser.java @@ -130,9 +130,6 @@ public static void unregister(@NotNull ParkourUser user, boolean restorePrevious if (user instanceof ParkourPlayer player) { user.previousData.onLeave.forEach(r -> r.execute(player, mode)); } - - user.player.resetPlayerTime(); - user.player.resetPlayerWeather(); } // Sends a player to a BungeeCord server. server is the server name. diff --git a/src/main/java/dev/efnilite/ip/player/data/PreviousData.java b/src/main/java/dev/efnilite/ip/player/data/PreviousData.java index fd7651a3..1b7828fe 100644 --- a/src/main/java/dev/efnilite/ip/player/data/PreviousData.java +++ b/src/main/java/dev/efnilite/ip/player/data/PreviousData.java @@ -3,12 +3,13 @@ import dev.efnilite.ip.IP; import dev.efnilite.ip.config.Config; import dev.efnilite.ip.config.Option; -import dev.efnilite.ip.reward.RewardString; +import dev.efnilite.ip.reward.Reward; import io.papermc.lib.PaperLib; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; +import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -30,9 +31,9 @@ public class PreviousData { private final Collection effects; /** - * List of all {@link RewardString} to execute on leave. + * List of all {@link Reward} to execute on leave. */ - public List onLeave = new ArrayList<>(); + public List onLeave = new ArrayList<>(); public PreviousData(@NotNull Player player) { gamemode = player.getGameMode(); @@ -79,6 +80,11 @@ private void apply(Player player) { for (PotionEffect effect : effects) { player.addPotionEffect(effect); } + + player.resetPlayerTime(); + player.resetPlayerWeather(); + player.setVelocity(new Vector(0, 0, 0)); + player.setFallDistance(0f); } catch (Exception ex) { // not the best way to do this... too bad! IP.logging().stack("Error while recovering stats of %s".formatted(player.getName()), ex); } diff --git a/src/main/java/dev/efnilite/ip/reward/RewardString.java b/src/main/java/dev/efnilite/ip/reward/Reward.java similarity index 94% rename from src/main/java/dev/efnilite/ip/reward/RewardString.java rename to src/main/java/dev/efnilite/ip/reward/Reward.java index 8d52c6f5..473766d9 100644 --- a/src/main/java/dev/efnilite/ip/reward/RewardString.java +++ b/src/main/java/dev/efnilite/ip/reward/Reward.java @@ -14,7 +14,7 @@ */ // todo add cross-server support // todo mode-specific way of saving one-time-rewards -public record RewardString(@NotNull String string) { +public record Reward(@NotNull String string) { /** * Parses and executes this reward @@ -47,7 +47,7 @@ public void execute(@NotNull ParkourPlayer player, @NotNull Mode mode) { // check for extra data if (string.toLowerCase().contains("leave:")) { // leave: string = string.replaceFirst("leave:", ""); - player.previousData.onLeave.add(new RewardString(string)); + player.previousData.onLeave.add(new Reward(string)); return; } diff --git a/src/main/java/dev/efnilite/ip/reward/Rewards.java b/src/main/java/dev/efnilite/ip/reward/Rewards.java index 9ea0d742..93f10b9d 100644 --- a/src/main/java/dev/efnilite/ip/reward/Rewards.java +++ b/src/main/java/dev/efnilite/ip/reward/Rewards.java @@ -18,19 +18,19 @@ public class Rewards { * A map with all Score-type score rewards. * The key is the score, and the value are the commands that will be executed once this score is reached. */ - public static Map> SCORE_REWARDS = new HashMap<>(); + public static Map> SCORE_REWARDS = new HashMap<>(); /** * A map with all Interval-type score rewards. * The key is the score, and the value are the commands that will be executed once this score is reached. */ - public static Map> INTERVAL_REWARDS = new HashMap<>(); + public static Map> INTERVAL_REWARDS = new HashMap<>(); /** * A map with all One time-type score rewards. * The key is the score, and the value are the commands that will be executed once this score is reached. */ - public static Map> ONE_TIME_REWARDS = new HashMap<>(); + public static Map> ONE_TIME_REWARDS = new HashMap<>(); /** * Reads the rewards from the rewards-v2.yml file @@ -48,14 +48,14 @@ public static void init() { ONE_TIME_REWARDS = parseScores("one-time-rewards"); } - private static Map> parseScores(String path) { - Map> rewardMap = new HashMap<>(); + private static Map> parseScores(String path) { + Map> rewardMap = new HashMap<>(); for (String score : Config.REWARDS.getChildren(path)) { // read commands for this score - List rewardStrings = Config.REWARDS.getStringList("%s.%s".formatted(path, score)).stream() - .map(RewardString::new) + List rewardStrings = Config.REWARDS.getStringList("%s.%s".formatted(path, score)).stream() + .map(Reward::new) .toList(); try { diff --git a/src/main/java/dev/efnilite/ip/storage/StorageSQL.java b/src/main/java/dev/efnilite/ip/storage/StorageSQL.java index 300e98d7..61514771 100644 --- a/src/main/java/dev/efnilite/ip/storage/StorageSQL.java +++ b/src/main/java/dev/efnilite/ip/storage/StorageSQL.java @@ -9,7 +9,10 @@ import org.jetbrains.annotations.NotNull; import java.sql.*; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.UUID; @@ -133,32 +136,35 @@ public static void readPlayer(@NotNull ParkourPlayer player) { } public static void writePlayer(@NotNull ParkourPlayer player) { + DecimalFormat df = new DecimalFormat("#.######", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); + String schematicDifficulty = df.format(player.schematicDifficulty); + sendUpdate(""" - INSERT INTO `%s` - (uuid, style, blockLead, useParticles, useSpecial, showFallMsg, showScoreboard, - selectedTime, collectedRewards, locale, schematicDifficulty, sound) - VALUES ('%s', '%s', %d, %b, %b, %b, %b, %d, '%s', '%s', %f, %b) - ON DUPLICATE KEY UPDATE style = '%s', - blockLead = %d, - useParticles = %b, - useSpecial = %b, - showFallMsg = %b, - showScoreboard = %b, - selectedTime = %d, - collectedRewards = '%s', - locale = '%s', - schematicDifficulty = %f, - sound = %b; - """ + INSERT INTO `%s` + (uuid, style, blockLead, useParticles, useSpecial, showFallMsg, showScoreboard, + selectedTime, collectedRewards, locale, schematicDifficulty, sound) + VALUES ('%s', '%s', %d, %b, %b, %b, %b, %d, '%s', '%s', %s, %b) + ON DUPLICATE KEY UPDATE style = '%s', + blockLead = %d, + useParticles = %b, + useSpecial = %b, + showFallMsg = %b, + showScoreboard = %b, + selectedTime = %d, + collectedRewards = '%s', + locale = '%s', + schematicDifficulty = %s, + sound = %b; + """ .formatted("%soptions".formatted(Option.SQL_PREFIX), player.getUUID(), player.style, player.blockLead, player.particles, player.useSpecialBlocks, player.showFallMessage, player.showScoreboard, player.selectedTime, String.join(",", player.collectedRewards), player.locale, - player.schematicDifficulty, player.sound, + schematicDifficulty, player.sound, player.style, player.blockLead, player.particles, player.useSpecialBlocks, player.showFallMessage, player.showScoreboard, player.selectedTime, String.join(",", player.collectedRewards), player.locale, - player.schematicDifficulty, player.sound)); + schematicDifficulty, player.sound)); } public static void connect() { diff --git a/src/main/java/dev/efnilite/ip/world/WorldManager.java b/src/main/java/dev/efnilite/ip/world/WorldManager.java index 542691eb..726c8767 100644 --- a/src/main/java/dev/efnilite/ip/world/WorldManager.java +++ b/src/main/java/dev/efnilite/ip/world/WorldManager.java @@ -2,31 +2,27 @@ import dev.efnilite.ip.IP; import dev.efnilite.ip.config.Config; -import dev.efnilite.ip.config.Option; -import org.bukkit.Bukkit; -import org.bukkit.Difficulty; -import org.bukkit.GameRule; -import org.bukkit.World; +import dev.efnilite.vilib.util.VoidGenerator; +import org.bukkit.*; -public interface WorldManager { +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Comparator; +import java.util.stream.Stream; - /** - * Implementation for creating a world. - * - * @return The created world. - */ - World createWorld(); +public class WorldManager { - /** - * Implementation for deleting a world. - */ - void deleteWorld(); + private static String name; + private static World world; /** * Creates a new world and sets all according settings in it. */ - static void create() { - World world = getWorld(); + public static void create() { + name = Config.CONFIG.getString("world.name"); + + var world = Bukkit.getWorld(name); if (!Config.CONFIG.getBoolean("joining")) { return; @@ -36,15 +32,32 @@ static void create() { IP.logging().warn("Crash detected! The parkour world loading twice is not usual behaviour. This only happens after a server crash."); } - WorldManager manager = getInstance(); + if (Config.CONFIG.getBoolean("world.delete-on-reload")) { + deleteWorld(); + } - IP.log("Initializing world rules"); + createWorld(); + setup(); + } - if (Config.CONFIG.getBoolean("world.delete-on-reload")) { - manager.deleteWorld(); + private static void createWorld() { + IP.log("Creating Spigot world"); + + try { + WorldCreator creator = new WorldCreator(name) + .generateStructures(false) + .type(WorldType.NORMAL) + .generator(VoidGenerator.getGenerator()) // to fix No keys in MapLayer etc. + .environment(World.Environment.NORMAL); + + world = Bukkit.createWorld(creator); + } catch (Exception ex) { + IP.logging().stack("Error while trying to create the parkour world", "delete the parkour world folder and restart the server", ex); } + } - world = manager.createWorld(); + private static void setup() { + IP.log("Initializing world rules"); world.setGameRule(GameRule.DO_FIRE_TICK, false); world.setGameRule(GameRule.DO_MOB_SPAWNING, false); @@ -65,7 +78,7 @@ static void create() { /** * Deletes the world. */ - static void delete() { + public static void delete() { if (!Config.CONFIG.getBoolean("world.delete-on-reload") || !Config.CONFIG.getBoolean("joining")) { return; } @@ -73,24 +86,41 @@ static void delete() { getWorld().getPlayers().forEach(player -> player.kickPlayer("Server is restarting")); - getInstance().deleteWorld(); + deleteWorld(); + } + + private static void deleteWorld() { + IP.log("Deleting Spigot world"); + + File file = new File(name); + + // world has already been deleted + if (!file.exists()) { + return; + } + + Bukkit.unloadWorld(name, false); + + try (Stream files = Files.walk(file.toPath())) { + files.sorted(Comparator.reverseOrder()) + .map(Path::toFile) + .forEach(File::delete); + } catch (Exception ex) { + IP.logging().stack("Error while trying to delete the parkour world", ex); + } } /** - * Gets the parkour world. - * - * @return the Bukkit world wherein IP is currently active. + * @return the name of the parkour world. */ - static World getWorld() { - return Bukkit.getWorld(Option.WORLD_NAME); + public static String getName() { + return name; } /** - * Returns the appropriate instance. - * - * @return The appropriate instance. + * @return the Bukkit world wherein IP is currently active. */ - static WorldManager getInstance() { - return WorldManagerMV.MANAGER != null ? new WorldManagerMV() : new WorldManagerMC(); + public static World getWorld() { + return world; } } \ No newline at end of file diff --git a/src/main/java/dev/efnilite/ip/world/WorldManagerMC.java b/src/main/java/dev/efnilite/ip/world/WorldManagerMC.java deleted file mode 100644 index 6eaef07a..00000000 --- a/src/main/java/dev/efnilite/ip/world/WorldManagerMC.java +++ /dev/null @@ -1,63 +0,0 @@ -package dev.efnilite.ip.world; - -import dev.efnilite.ip.IP; -import dev.efnilite.ip.config.Option; -import dev.efnilite.vilib.util.VoidGenerator; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.WorldType; - -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Comparator; -import java.util.stream.Stream; - -/** - * Minecraft world manager. - */ -public class WorldManagerMC implements WorldManager { - - @Override - public World createWorld() { - IP.log("Creating Spigot world"); - - World world = null; - - try { - WorldCreator creator = new WorldCreator(Option.WORLD_NAME) - .generateStructures(false) - .type(WorldType.NORMAL) - .generator(VoidGenerator.getGenerator()) // to fix No keys in MapLayer etc. - .environment(World.Environment.NORMAL); - - world = Bukkit.createWorld(creator); - } catch (Exception ex) { - IP.logging().stack("Error while trying to create the parkour world", "delete the parkour world folder and restart the server", ex); - } - return world; - } - - @Override - public void deleteWorld() { - IP.log("Deleting Spigot world"); - - File file = new File(Option.WORLD_NAME); - - // world has already been deleted - if (!file.exists()) { - return; - } - - Bukkit.unloadWorld(Option.WORLD_NAME, false); - - try (Stream files = Files.walk(file.toPath())) { - files.sorted(Comparator.reverseOrder()) - .map(Path::toFile) - .forEach(File::delete); - } catch (Exception ex) { - IP.logging().stack("Error while trying to delete the parkour world", ex); - } - } -} \ No newline at end of file diff --git a/src/main/java/dev/efnilite/ip/world/WorldManagerMV.java b/src/main/java/dev/efnilite/ip/world/WorldManagerMV.java deleted file mode 100644 index ebdf755c..00000000 --- a/src/main/java/dev/efnilite/ip/world/WorldManagerMV.java +++ /dev/null @@ -1,62 +0,0 @@ -package dev.efnilite.ip.world; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import dev.efnilite.ip.IP; -import dev.efnilite.ip.config.Option; -import dev.efnilite.vilib.util.VoidGenerator; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.WorldType; - -/** - * Multiverse world manager. - */ -public class WorldManagerMV implements WorldManager { - - public static MVWorldManager MANAGER; - - static { - MultiverseCore core = (MultiverseCore) Bukkit.getServer().getPluginManager().getPlugin("Multiverse-Core"); - - if (core != null) { - MANAGER = core.getMVWorldManager(); - } - } - - @Override - public World createWorld() { - if (MANAGER == null) { - return null; - } - - // world has already been loaded - var existing = MANAGER.getMVWorld(Option.WORLD_NAME); - if (existing != null) { - return existing.getCBWorld(); - } - - IP.log("Creating MV world"); - - MANAGER.addWorld(Option.WORLD_NAME, World.Environment.NORMAL, null, WorldType.NORMAL, false, VoidGenerator.getMultiverseGenerator()); - MultiverseWorld world = MANAGER.getMVWorld(Option.WORLD_NAME); - - // optimizations to reduce memory usage - world.setAllowAnimalSpawn(false); - world.setAllowMonsterSpawn(false); - world.setKeepSpawnInMemory(false); - - return world.getCBWorld(); - } - - @Override - public void deleteWorld() { - if (MANAGER == null) { - return; - } - IP.log("Deleting MV world"); - - MANAGER.deleteWorld(Option.WORLD_NAME, false); // deleteFromConfig - } -} \ No newline at end of file diff --git a/src/main/resources/generation.yml b/src/main/resources/generation.yml index e41713dc..af73a05a 100644 --- a/src/main/resources/generation.yml +++ b/src/main/resources/generation.yml @@ -83,9 +83,4 @@ advanced: # -= Schematic cooldown =- # The amount of blocks that provide a cooldown for the schematics. - schematic-cooldown: 20 - - # -= Generator check interval =- - # The amount of ticks between checks of the player's location and score. - # Lowering this is not recommended. Raising this may cause additional lag. - generator-check: 2 \ No newline at end of file + schematic-cooldown: 20 \ No newline at end of file diff --git a/src/main/resources/locales/en.yml b/src/main/resources/locales/en.yml index ac63aa5c..a3689af5 100644 --- a/src/main/resources/locales/en.yml +++ b/src/main/resources/locales/en.yml @@ -67,7 +67,7 @@ community: sort: material: "bookshelf" - name: "<#DEA11F>Sort by %s" + name: "<#DEA11F>Sorted by %s" lore: "" values: ["score", "time", "difficulty"] diff --git a/src/main/resources/locales/fr.yml b/src/main/resources/locales/fr.yml index 0ec5614b..99219b1c 100644 --- a/src/main/resources/locales/fr.yml +++ b/src/main/resources/locales/fr.yml @@ -67,7 +67,7 @@ community: sort: material: "bookshelf" - name: "<#DEA11F>Sort par %s" + name: "<#DEA11F>Sorté par %s" lore: "" values: [ "score", "temps", "difficulté" ] diff --git a/src/main/resources/locales/nl.yml b/src/main/resources/locales/nl.yml index e796954e..9f97bdbb 100644 --- a/src/main/resources/locales/nl.yml +++ b/src/main/resources/locales/nl.yml @@ -67,7 +67,7 @@ community: sort: material: "bookshelf" - name: "<#DEA11F>Sorteren op %s" + name: "<#DEA11F>Gesorteerd op %s" lore: "" values: ["score", "tijd", "moeilijkheid"]