Skip to content

Commit

Permalink
Merge pull request #120 from Efnilite/dev/5.2.1
Browse files Browse the repository at this point in the history
Merge 5.2.1
  • Loading branch information
Efnilite authored Apr 25, 2024
2 parents 934f95d + 9970074 commit 8e4db61
Show file tree
Hide file tree
Showing 25 changed files with 149 additions and 84 deletions.
20 changes: 11 additions & 9 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
**New Plugin [Infinite Elytra Parkour](https://www.spigotmc.org/resources/115322/) | [IP+](https://www.spigotmc.org/resources/105019/)**

- Fixed schematics being unusable when it contains unknown materials
- Fixed difficulty going above 1
- Fixed schematic points being based on all settings difficulty, not schematic difficulty
- Fixed inventories not being cleared
- Fixed inventories being cleared on leave with inventory handling off
- Fixed teleporting not being async when possible
- Fixed incorrect rewards documentation
- Added debugging messages
- Improved unsupported schematic message clarity
- Added item for IEP support
- Added option to disable players opening blocks with inventories
- Fixed players occasionally being reset to previous location while switching mode
- Fixed errors showing up in console on disable when nobody joined parkour
- Fixed world being deleted even if delete-on-reload is enabled
- Fixed not loading if delete-on-reload is enabled with Multiverse worlds
- Fixed bad parkour pathfinding near edges
- Fixed player mounting causing issues
- Fixed players being able to transfer inventory items with some plugins
- Fixed not being able to close leaderboard if not using IP+
- Fixed errors when joining as spectator
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.efnilite</groupId>
<artifactId>IP</artifactId>
<version>5.2.0</version>
<version>5.2.1</version>

<properties>
<maven.compiler.source>16</maven.compiler.source>
Expand Down Expand Up @@ -97,7 +97,7 @@
<dependency>
<groupId>com.github.Efnilite</groupId>
<artifactId>vilib</artifactId>
<version>ed66743ad8</version>
<version>66840fa513</version>
<scope>compile</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/efnilite/ip/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void sendHelpMessages(CommandSender sender) {
send(sender, "");
send(sender, "<gray>/parkour <dark_gray>- Main command");
if (sender.hasPermission(ParkourOption.JOIN.permission)) {
send(sender, "<gray>/parkour join [mode] <dark_gray>- Join the default mode or specify one.");
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)) {
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/dev/efnilite/ip/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityMountEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.*;
Expand Down Expand Up @@ -80,7 +81,7 @@ public void join(PlayerJoinEvent event) {

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 visit the wiki to fix this.");
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, "");
}

Expand Down Expand Up @@ -227,7 +228,9 @@ public void interact(PlayerInteractEvent event) {
} else if (held == quit) {
ParkourUser.leave(player);
} else {
event.setCancelled(false);
if (!Config.CONFIG.getBoolean("options.disable-inventory-blocks")) {
event.setCancelled(false);
}
}
}

Expand Down Expand Up @@ -278,7 +281,7 @@ public void damage(EntityDamageEvent event) {
handleRestriction(player, event);
}

@EventHandler
@EventHandler(priority = EventPriority.HIGHEST)
public void inventory(InventoryClickEvent event) {
if (!(event.getWhoClicked() instanceof Player player) || event.getInventory().getType() == InventoryType.CRAFTING) {
return;
Expand All @@ -296,6 +299,15 @@ public void spectate(PlayerTeleportEvent event) {
handleRestriction(event.getPlayer(), event);
}

@EventHandler(priority = EventPriority.HIGHEST)
public void mount(EntityMountEvent event) {
if (!(event.getEntity() instanceof Player player)) {
return;
}

handleRestriction(player, event);
}

private void handleRestriction(Player player, Cancellable event) {
if (!ParkourUser.isUser(player)) {
return;
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/dev/efnilite/ip/IP.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import dev.efnilite.vilib.bstats.charts.SingleLineChart;
import dev.efnilite.vilib.inventory.Menu;
import dev.efnilite.vilib.util.Logging;
import dev.efnilite.vilib.util.elevator.GitElevator;
import org.jetbrains.annotations.Nullable;

import java.io.File;
Expand Down Expand Up @@ -107,20 +106,19 @@ public void enable() {

@Override
public void disable() {
for (ParkourUser user : ParkourUser.getUsers()) {
ParkourUser.leave(user);
}
try {
for (ParkourUser user : ParkourUser.getUsers()) {
ParkourUser.leave(user);
}

// write all IP gamemodes
Modes.DEFAULT.getLeaderboard().write(false);
// write all IP gamemodes
Modes.DEFAULT.getLeaderboard().write(false);

Storage.close();
WorldManager.delete();
}
Storage.close();
WorldManager.delete();
} catch (Throwable ignored) {

@Override
public GitElevator getElevator() {
return null;
}
}

public static void log(String message) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/dev/efnilite/ip/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public enum Config {

if (!path.exists()) {
IP.getPlugin().saveResource(fileName, false);
IP.log("Created config file %s".formatted(fileName));
}

update();
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/dev/efnilite/ip/generator/Island.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import dev.efnilite.ip.IP;
import dev.efnilite.ip.config.Config;
import dev.efnilite.ip.session.Session;
import dev.efnilite.ip.world.Divider;
import dev.efnilite.vilib.schematic.Schematic;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -44,22 +43,20 @@ public Island(@NotNull Session session, @Nullable Schematic schematic) {
/**
* Builds the island and teleports the player.
*/
public void build() {
public void build(Location location) {
if (schematic == null) {
return;
}
IP.log("Building island");

IP.log("Building island");

blocks = schematic.paste(Divider.toLocation(session).subtract(0, schematic.getDimensions().getY(), 0));
blocks = schematic.paste(location.subtract(0, schematic.getDimensions().getY(), 0));

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());

try {
Block player = blocks.stream().filter(block -> block.getType() == playerMaterial).findAny().get();
Block parkour = blocks.stream().filter(block -> block.getType() == parkourMaterial).findAny().get();
Block player = blocks.stream().filter(block -> block.getType() == playerMaterial).findAny().orElseThrow();
Block parkour = blocks.stream().filter(block -> block.getType() == parkourMaterial).findAny().orElseThrow();

player.setType(Material.AIR);
parkour.setType(Material.AIR);
Expand Down
22 changes: 13 additions & 9 deletions src/main/java/dev/efnilite/ip/generator/JumpDirector.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ private double[][] calculateParameterization(@NotNull Vector point) {
* the heading will automatically be turned around to ensure that the edge does not get
* destroyed.
*
* @return The recommended new heading. (0,0,0) if no modification is needed.
* @return The recommended new heading. Current heading if no modification is needed.
*/
@NotNull
public Vector getRecommendedHeading() {
public Vector getRecommendedHeading(Vector current) {
// get x values from progress array
double tx = progress[0][0];
double borderMarginX = progress[0][1];
Expand All @@ -84,21 +84,25 @@ public Vector getRecommendedHeading() {
// check border
if (tx < borderMarginX) {
// x should increase
recommendedHeading.add(new Vector(1, 0, 0));
recommendedHeading = new Vector(1, 0, 1);
} else if (tx > 1 - borderMarginX) {
// x should decrease
recommendedHeading.add(new Vector(-1, 0, 0));
recommendedHeading = new Vector(-1, 0, -1);
}

if (tz < borderMarginZ) {
// z should increase
recommendedHeading.add(new Vector(0, 0, 1));
recommendedHeading = new Vector(1, 0, 1);
} else if (tz > 1 - borderMarginZ) {
// z should decrease
recommendedHeading.add(new Vector(0, 0, -1));
recommendedHeading = new Vector(-1, 0, -1);
}

return recommendedHeading;
if (recommendedHeading.isZero()) {
return current;
} else {
return recommendedHeading;
}
}

/**
Expand All @@ -109,7 +113,7 @@ public Vector getRecommendedHeading() {
*
* @return The recommended new height. 0 if no modification is needed.
*/
public int getRecommendedHeight() {
public int getRecommendedHeight(int current) {
double ty = progress[1][0];
double borderMarginY = progress[1][1];

Expand All @@ -120,7 +124,7 @@ public int getRecommendedHeight() {
// y should decrease
return -1;
}
return 0;
return current;
}

/**
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/dev/efnilite/ip/generator/ParkourGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,8 @@ protected List<Block> selectBlocks() {
protected Block selectNext(Block current, int distance, int height) {
JumpDirector director = new JumpDirector(BoundingBox.of(zone[0], zone[1]), getLatest().getLocation().toVector());

Vector recommendedHeading = director.getRecommendedHeading();

if (!recommendedHeading.equals(new Vector(0, 0, 0))) {
heading = recommendedHeading;
}

int recommendedHeight = director.getRecommendedHeight();

if (recommendedHeight != 0) {
height = recommendedHeight;
}
heading = director.getRecommendedHeading(heading);
height = director.getRecommendedHeight(height);

// ensure special is possible
switch (getLatest().getType()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.efnilite.ip.menu.community;

import dev.efnilite.ip.IP;
import dev.efnilite.ip.api.Registry;
import dev.efnilite.ip.config.Locales;
import dev.efnilite.ip.config.Option;
import dev.efnilite.ip.leaderboard.Leaderboard;
Expand Down Expand Up @@ -118,7 +119,19 @@ public void open(Player player, Mode mode, Sort sort) {
.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 -> Menus.LEADERBOARDS.open(event.getPlayer())))
.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());
}))
.fillBackground(ParkourUser.isBedrockPlayer(player) ? Material.AIR : Material.GRAY_STAINED_GLASS_PANE)
.open(player);
}
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/dev/efnilite/ip/menu/play/PlayMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.efnilite.ip.player.ParkourUser;
import dev.efnilite.vilib.inventory.Menu;
import dev.efnilite.vilib.inventory.animation.RandomAnimation;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;

Expand All @@ -16,9 +17,21 @@
public class PlayMenu extends DynamicMenu {

public PlayMenu() {
registerMainItem(1, 0, (player, user) -> Locales.getItem(player, "play.single.item").click(event -> Menus.SINGLE.open(event.getPlayer())), ParkourOption.SINGLE::mayPerform);
registerMainItem(1, 2, (player, user) -> Locales.getItem(player, "play.spectator.item").click(event -> Menus.SPECTATOR.open(event.getPlayer())), ParkourOption.SPECTATOR::mayPerform);
registerMainItem(2, 0, (player, user) -> Locales.getItem(player, "other.close").click(event -> event.getPlayer().closeInventory()), player -> true);
registerMainItem(1, 0, (player, user) -> Locales.getItem(player, "play.single.item")
.click(event -> Menus.SINGLE.open(event.getPlayer())),
ParkourOption.SINGLE::mayPerform);

registerMainItem(1, 1, (player, user) -> Locales.getItem(player, "other.iep")
.click(event -> event.getPlayer().performCommand("iep play")),
player -> Bukkit.getPluginManager().isPluginEnabled("IEP"));

registerMainItem(1, 6, (player, user) -> Locales.getItem(player, "play.spectator.item")
.click(event -> Menus.SPECTATOR.open(event.getPlayer())),
ParkourOption.SPECTATOR::mayPerform);

registerMainItem(2, 0, (player, user) -> Locales.getItem(player, "other.close")
.click(event -> event.getPlayer().closeInventory()),
player -> true);
}

public void open(Player player) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dev/efnilite/ip/player/ParkourSpectator.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public void update() {
player.setGameMode(GameMode.SPECTATOR);
updateScoreboard(session.generator);

// spectator is still being teleported to world
if (closest.getLocation().getWorld() != player.getLocation().getWorld()) {
return;
}

if (closest.getLocation().distanceSquared(player.getLocation()) < 100 * 100) { // avoid sqrt
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/dev/efnilite/ip/player/ParkourUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public static void unregister(@NotNull ParkourUser user, boolean restorePrevious
return;
}

if (!restorePreviousData) return;

user.previousData.apply(user.player, urgent);

if (user instanceof ParkourPlayer player) {
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/dev/efnilite/ip/player/data/PreviousData.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ public PreviousData(@NotNull Player player) {
inventoryData = null;
}

// health handling after removing effects and inventory to avoid them affecting it
if (Config.CONFIG.getBoolean("options.health-handling")) {
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(20);
player.setHealth(maxHealth);
}
player.setHealth(maxHealth);
}

public void apply(Player player, boolean urgent) {
Expand All @@ -83,11 +79,7 @@ private void apply(Player player) {
player.setGameMode(gamemode);
player.setAllowFlight(allowFlight);
player.setFlying(flying);

if (Config.CONFIG.getBoolean("options.health-handling")) {
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth);
player.setHealth(health);
}
player.setHealth(health);

for (PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dev/efnilite/ip/session/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static Session create(Function<Session, ParkourGenerator> generatorFuncti

Session session = new Session();

Divider.add(session);
var location = Divider.add(session);

if (isAcceptingPlayers != null) session.isAcceptingPlayers = isAcceptingPlayers;
if (isAcceptingSpectators != null) session.isAcceptingSpectators = isAcceptingSpectators;
Expand All @@ -90,7 +90,7 @@ public static Session create(Function<Session, ParkourGenerator> generatorFuncti
pps.forEach(p -> p.updateGeneratorSettings(session.generator));
}

session.generator.island.build();
session.generator.island.build(location);

return session;
}
Expand Down
Loading

0 comments on commit 8e4db61

Please sign in to comment.