Skip to content

Commit

Permalink
Fix for Potion ParkourMode
Browse files Browse the repository at this point in the history
Reset FallTicks when teleporting player
Add %DEATHS% as a placeholder in TopTen Placeholder
  • Loading branch information
A5H73Y committed Jan 12, 2021
1 parent 5075933 commit 3dc389b
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 27 deletions.
8 changes: 2 additions & 6 deletions docs/tutorials/parkour-modes.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ TODO images

Simply sets the players movement speed to what is set in the config.yml. Allows you to run faster and jump further. Movement speed is reset to default once the player leaves.

## Moon

Straight forward, this applies Jump Boost to the player throughout the Course. If the player leaves the effect is removed. This will allow the player to reach new heights and simulate low gravity.

## Dropper

This allows you to integrate the plugin into the 'dropper' gamemode, allowing you to fall infinitely without dying or taking any fall damage. You can use DeathBlocks to allow the player to die if they hit a block.
Expand All @@ -47,6 +43,6 @@ Inspired by CodJumping, when you use an RPG's explosion to propel yourself into

You will be given a 'Rocket Launcher', which is a Rocket by default. Simply right click with the item in your hand and you will have a knockback applied to your player, which you can use to reach new heights and distances. The time between reuse can be configured, to reduce risk of it being abused.

## Free Checkpoint



This ParkourMode allows you to treat any Pressure Plate as a checkpoint. Upon walking on a Pressure Plate the player will be notified that a checkpoint has been set, if the player dies they will be taken back to the last checkpoint they set. This allows you to create alternate routes through a course.
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<!-- MySQL database Repo -->
<repository>
<id>husk</id>
<url>https://maven.husk.pro/repository/maven-public/</url>
<url>https://maven.husk.pro/snapshots/</url>
</repository>
<!-- InventoryGui -->
<repository>
Expand Down Expand Up @@ -130,8 +130,14 @@
<dependency>
<groupId>pro.husk</groupId>
<artifactId>mysql</artifactId>
<version>1.4.0</version>
<version>1.4.1-SNAPSHOT</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- InventoryGui -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ private String getTopTenPlaceholderValue(String... arguments) {
} else {
return TOP_TEN_RESULT.replace(Constants.PLAYER_PLACEHOLDER, result.getPlayerName())
.replace("%POSITION%", Integer.toString(position))
.replace("%TIME%", DateTimeUtils.displayCurrentTime(result.getTime()));
.replace(Constants.TIME_PLACEHOLDER, DateTimeUtils.displayCurrentTime(result.getTime()))
.replace(Constants.DEATHS_PLACEHOLDER, Integer.toString(result.getDeaths()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.github.a5h73y.parkour.type.checkpoint.Checkpoint;
import io.github.a5h73y.parkour.type.player.ParkourSession;
import io.github.a5h73y.parkour.utility.MaterialUtils;
import io.github.a5h73y.parkour.utility.PlayerUtils;
import io.github.a5h73y.parkour.utility.PluginUtils;
import io.github.a5h73y.parkour.utility.TranslationUtils;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -136,7 +137,8 @@ public void onInventoryInteractParkourMode(PlayerInteractEvent event) {
TranslationUtils.sendTranslation("Mode.Freedom.Save", player);

} else {
player.teleport(parkour.getPlayerManager().getParkourSession(player).getFreedomLocation());
PlayerUtils.teleportToLocation(player,
parkour.getPlayerManager().getParkourSession(player).getFreedomLocation());
TranslationUtils.sendTranslation("Mode.Freedom.Load", player);
}

Expand Down
13 changes: 9 additions & 4 deletions src/main/java/io/github/a5h73y/parkour/plugin/BountifulApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.a5h73y.parkour.type.player.PlayerInfo;
import io.github.a5h73y.parkour.utility.PluginUtils;
import io.github.a5h73y.parkour.utility.TranslationUtils;
import io.github.a5h73y.parkour.utility.ValidationUtils;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -80,16 +81,20 @@ public void sendFullTitle(Player player, String title, String subTitle, boolean
if (attemptTitle) {
if (useSpigotMethods) {
player.sendTitle(title, subTitle, inDuration, stayDuration, outDuration);
return;

} else if (isEnabled()) {
BountifulAPI.sendTitle(player, inDuration, stayDuration, outDuration, title, subTitle);

} else {
TranslationUtils.sendMessage(player, title);
return;
}
} else {
}

if (ValidationUtils.isStringValid(title)) {
TranslationUtils.sendMessage(player, title);
}
if (ValidationUtils.isStringValid(subTitle)) {
TranslationUtils.sendMessage(player, subTitle);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.github.a5h73y.parkour.type.course.CourseInfo;
import io.github.a5h73y.parkour.type.player.PlayerInfo;
import io.github.a5h73y.parkour.utility.MaterialUtils;
import io.github.a5h73y.parkour.utility.PlayerUtils;
import io.github.a5h73y.parkour.utility.PluginUtils;
import io.github.a5h73y.parkour.utility.TranslationUtils;
import java.util.ArrayList;
Expand Down Expand Up @@ -205,7 +206,7 @@ public void teleportCheckpoint(Player player, String courseName, @Nullable Integ
return;
}

player.teleport(new Location(world, x, y, z, yaw, pitch));
PlayerUtils.teleportToLocation(player, new Location(world, x, y, z, yaw, pitch));
String message = TranslationUtils.getValueTranslation("Parkour.Teleport", courseName);
TranslationUtils.sendMessage(player, checkpoint != null ? message + " &f(&3" + checkpoint + "&f)" : message, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.github.a5h73y.parkour.type.course.CourseInfo;
import io.github.a5h73y.parkour.type.player.ParkourSession;
import io.github.a5h73y.parkour.type.player.PlayerInfo;
import io.github.a5h73y.parkour.utility.PlayerUtils;
import io.github.a5h73y.parkour.utility.PluginUtils;
import io.github.a5h73y.parkour.utility.TranslationUtils;
import io.github.a5h73y.parkour.utility.ValidationUtils;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void joinLobby(Player player, @Nullable String lobbyName) {
}

Lobby lobby = lobbyCache.getOrDefault(lobbyName, populateLobby(lobbyName));
player.teleport(lobby.getLocation());
PlayerUtils.teleportToLocation(player, lobby.getLocation());

if (lobbyName.equals(Constants.DEFAULT)) {
TranslationUtils.sendTranslation("Parkour.Lobby", player);
Expand All @@ -97,7 +98,7 @@ public void justTeleportToDefaultLobby(Player player) {
return;
}
Lobby lobby = lobbyCache.getOrDefault(Constants.DEFAULT, populateLobby(Constants.DEFAULT));
player.teleport(lobby.getLocation());
PlayerUtils.teleportToLocation(player, lobby.getLocation());
TranslationUtils.sendTranslation("Parkour.Lobby", player);
}

Expand All @@ -108,8 +109,7 @@ public void justTeleportToDefaultLobby(Player player) {
public void teleportToNearestLobby(Player player) {
Lobby lobby = getNearestLobby(player);
if (lobby != null) {
player.setFallDistance(0);
player.teleport(lobby.getLocation());
PlayerUtils.teleportToLocation(player, lobby.getLocation());
TranslationUtils.sendValueTranslation("Parkour.LobbyOther", lobby.getName(), player);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.github.a5h73y.parkour.utility.DateTimeUtils;
import io.github.a5h73y.parkour.utility.MaterialUtils;
import io.github.a5h73y.parkour.utility.PermissionUtils;
import io.github.a5h73y.parkour.utility.PlayerUtils;
import io.github.a5h73y.parkour.utility.PluginUtils;
import io.github.a5h73y.parkour.utility.StringUtils;
import io.github.a5h73y.parkour.utility.TranslationUtils;
Expand Down Expand Up @@ -212,7 +213,7 @@ public void joinCourse(Player player, Course course, boolean silent) {
}

if (parkour.getConfig().getBoolean("OnJoin.TeleportPlayer")) {
player.teleport(course.getCheckpoints().get(0).getLocation());
PlayerUtils.teleportToLocation(player, course.getCheckpoints().get(0).getLocation());
}
preparePlayerForCourse(player, course.getName());
CourseInfo.incrementViews(course.getName());
Expand Down Expand Up @@ -255,7 +256,7 @@ public void joinCourse(Player player, Course course, boolean silent) {
ParkourSession session;
if (canLoadParkourSession(player, course)) {
session = loadParkourSession(player);
player.teleport(determineDestination(session));
PlayerUtils.teleportToLocation(player, determineDestination(session));
TranslationUtils.sendValueTranslation("Parkour.Continue", session.getCourseName(), player);
} else {
session = addPlayer(player, new ParkourSession(course));
Expand Down Expand Up @@ -338,7 +339,7 @@ public void leaveCourse(Player player, boolean silent) {
if (parkour.getConfig().getBoolean("OnLeave.TeleportAway")) {
if (parkour.getConfig().isTeleportToJoinLocation()
&& PlayerInfo.hasJoinLocation(player)) {
player.teleport(PlayerInfo.getJoinLocation(player));
PlayerUtils.teleportToLocation(player, PlayerInfo.getJoinLocation(player));
} else {
parkour.getLobbyManager().teleportToLeaveDestination(player, session);
}
Expand Down Expand Up @@ -433,7 +434,7 @@ public void playerDie(Player player) {
}
}

player.teleport(determineDestination(session));
PlayerUtils.teleportToLocation(player, determineDestination(session));

// if the Player is in Test Mode, we don't need to run the rest
if (isPlayerInTestMode(player)) {
Expand Down Expand Up @@ -609,7 +610,7 @@ public void restartCourse(Player player, boolean doNotTeleport) {
joinCourse(player, course, true);
// if they are restarting the Course, we need to teleport them back
if (!doNotTeleport && !parkour.getConfig().getBoolean("OnJoin.TeleportPlayer")) {
player.teleport(course.getCheckpoints().get(0).getLocation());
PlayerUtils.teleportToLocation(player, course.getCheckpoints().get(0).getLocation());
}
TranslationUtils.sendTranslation("Parkour.Restarting", player);
}
Expand Down Expand Up @@ -894,8 +895,12 @@ public boolean hasPrizeCooldownDurationPassed(Player player, String courseName,
* @param gameModeName GameMode name
*/
public void preparePlayer(Player player, String gameModeName) {
for (PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
PlayerUtils.removeAllPotionEffects(player);
ParkourSession session = getParkourSession(player);

if (session != null && session.getParkourMode() == ParkourMode.POTION) {
XPotion.addPotionEffectsFromString(player,
CourseInfo.getPotionParkourModeEffects(session.getCourseName()));
}

if (!isPlayerInTestMode(player)) {
Expand Down Expand Up @@ -1779,7 +1784,7 @@ private void teleportCourseCompletion(Player player, String courseName) {
}

} else if (parkour.getConfig().isTeleportToJoinLocation()) {
player.teleport(PlayerInfo.getJoinLocation(player));
PlayerUtils.teleportToLocation(player, PlayerInfo.getJoinLocation(player));
TranslationUtils.sendTranslation("Parkour.JoinLocation", player);
return;
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/io/github/a5h73y/parkour/utility/PlayerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cryptomorin.xseries.XPotion;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
Expand Down Expand Up @@ -103,4 +104,16 @@ public static void changeGameMode(Player player, GameMode gameMode) {
TranslationUtils.sendMessage(player, "GameMode set to &b" + StringUtils.standardizeText(gameMode.name()));
}
}

/**
* Teleport Player to Location.
* Reset their fall distance so they don't take damage upon teleportation.
*
* @param player player
* @param location location
*/
public static void teleportToLocation(Player player, Location location) {
player.setFallDistance(0);
player.teleport(location);
}
}

0 comments on commit 3dc389b

Please sign in to comment.