Skip to content

Commit

Permalink
Merge pull request #126 from Efnilite/dev
Browse files Browse the repository at this point in the history
Merge 5.2.5
  • Loading branch information
Efnilite authored May 24, 2024
2 parents b720392 + 6dca9c2 commit 795ec6f
Show file tree
Hide file tree
Showing 24 changed files with 182 additions and 302 deletions.
7 changes: 5 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
- 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
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.onarandombox.multiversecore</groupId>
<artifactId>Multiverse-Core</artifactId>
<version>4.3.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/dev/efnilite/ip/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" -> {
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/dev/efnilite/ip/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/dev/efnilite/ip/config/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public class Option {
public static Map<ParkourOption, Boolean> OPTIONS_ENABLED;
public static Map<ParkourOption, String> OPTIONS_DEFAULTS;

// Worlds
public static String WORLD_NAME;

public static Location GO_BACK_LOC;

public static void init(boolean firstLoad) {
Expand All @@ -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<ParkourOption> options = new ArrayList<>(Arrays.asList(ParkourOption.values()));
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/dev/efnilite/ip/generator/GeneratorOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public enum GeneratorOption {

DISABLE_SCHEMATICS,
DISABLE_SPECIAL,
REDUCE_RANDOM_BLOCK_SELECTION_ANGLE,
INCREASED_TICK_ACCURACY
REDUCE_RANDOM_BLOCK_SELECTION_ANGLE

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
48 changes: 39 additions & 9 deletions src/main/java/dev/efnilite/ip/leaderboard/Leaderboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<UUID, Score> 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;

Expand Down Expand Up @@ -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<UUID, Score> sort(Sort sort) {
LinkedHashMap<UUID, Score> 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);
}
Expand Down Expand Up @@ -171,4 +197,8 @@ public Score getScoreAtRank(int rank) {

return new ArrayList<>(scores.values()).get(rank - 1);
}

public enum Sort {
SCORE, TIME, DIFFICULTY
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,37 @@
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) {
return;
}

// 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<MenuItem> items = new ArrayList<>();
var items = new ArrayList<MenuItem>();

Item base = Locales.getItem(player, "%s.head".formatted(ParkourOption.LEADERBOARDS.path));
var base = Locales.getItem(player, "%s.head".formatted(ParkourOption.LEADERBOARDS.path));

Map<UUID, Score> sorted = sort.sort(leaderboard.scores);

for (UUID uuid : sorted.keySet()) {
for (Map.Entry<UUID, Score> 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;
Expand All @@ -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 .
Expand Down Expand Up @@ -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)
Expand All @@ -133,41 +135,4 @@ public void open(Player player, Mode mode, Sort sort) {
}))
.open(player);
}

public enum Sort {

SCORE {
@Override
Map<UUID, Score> sort(Map<UUID, Score> scores) {
return scores; // already sorted
}
}, TIME {
@Override
Map<UUID, Score> sort(Map<UUID, Score> 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<UUID, Score> sort(Map<UUID, Score> 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<UUID, Score> sort(Map<UUID, Score> scores);
}
}
3 changes: 1 addition & 2 deletions src/main/java/dev/efnilite/ip/mode/DefaultMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/dev/efnilite/ip/player/ParkourPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/dev/efnilite/ip/player/ParkourUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 795ec6f

Please sign in to comment.