Skip to content

Commit

Permalink
Added Challenge losing wager message
Browse files Browse the repository at this point in the history
Added option to disable "OnCourse.ParkourKit.FloatingClosestBlock"
Fixed various Challenge bugs
Fix attempt of NPE with placeholders
Update dependency versions
  • Loading branch information
A5H73Y committed Jul 3, 2023
1 parent f43ca88 commit 89915e7
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 48 deletions.
2 changes: 1 addition & 1 deletion docs/changelogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Please note that each version of Parkour is backwards compatible with the previo
## 7.2.0

* Added ability to set a one-time fee for a course
Added "ParkourTool.RemoveRightClickRestriction" to support geyser controls
* Added "ParkourTool.RemoveRightClickRestriction" to support geyser controls
* Added "Other.Display.CurrencyName" to show or hide currency name in messages
* Added Throwables to be ParkourTools
* Ability to disable nested parkour commands
Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.2</version>
<version>2.11.3</version>
<scope>provided</scope>
</dependency>
<!-- Bountiful API -->
Expand All @@ -111,7 +111,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
<!-- MySQL Database -->
Expand All @@ -138,7 +138,7 @@
<dependency>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>9.3.0</version>
<version>9.4.0</version>
<scope>compile</scope>
</dependency>
<!-- Version Compare -->
Expand All @@ -152,7 +152,7 @@
<dependency>
<groupId>com.github.simplix-softworks</groupId>
<artifactId>simplixstorage</artifactId>
<version>3.2.5</version>
<version>3.2.6</version>
</dependency>
<!-- Update to remove known vulnerabilities -->
<dependency>
Expand All @@ -168,7 +168,7 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20230227</version>
<version>20230618</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public DefaultConfig(File file) {
this.setDefault("OnCourse.TreatLastCheckpointAsFinish", false);
this.setDefault("OnCourse.ParkourKit.Enabled", true);
this.setDefault("OnCourse.ParkourKit.IncludeVehicles", false);
this.setDefault("OnCourse.ParkourKit.FloatingClosestBlock", true);
this.setDefault("OnCourse.EnforceParkourCommands.Enabled", true);
this.setDefault("OnCourse.EnforceParkourCommands.Whitelist", Collections.singletonList("login"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public StringsConfig(File file) {
this.setDefault("Parkour.Challenge.Winner", "Congratulations! You won the challenge on &b%VALUE%!");
this.setDefault("Parkour.Challenge.WinnerWager", "You have been rewarded &b%VALUE% &ffor winning the wager!");
this.setDefault("Parkour.Challenge.Loser", "&b%PLAYER% &fhas completed &b%COURSE% &fbefore you!");
this.setDefault("Parkour.Challenge.LoserWager", "You have had &b%VALUE% &fdeducted from your balance!");

this.setDefault("Event.Join", "This server uses &bParkour &3%VALUE%");
this.setDefault("Event.Checkpoint", "Checkpoint set to &b%CURRENT% &8/ &7%TOTAL%");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public class ParkourBlockListener extends AbstractPluginReceiver implements List
public static final List<BlockFace> BLOCK_FACES =
Arrays.asList(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST);

private final boolean floatingClosestBlock;

public ParkourBlockListener(final Parkour parkour) {
super(parkour);
this.floatingClosestBlock = parkour.getParkourConfig().getBoolean("OnCourse.ParkourKit.FloatingClosestBlock");
}

/**
Expand Down Expand Up @@ -64,7 +67,9 @@ public void onPlayerMove(PlayerMoveEvent event) {
}

// they are clearly hovering and another block is holding them up
if (player.isOnGround() && XBlock.isAir(belowMaterial)) {
if (player.isOnGround()
&& this.floatingClosestBlock
&& XBlock.isAir(belowMaterial)) {
belowMaterial = calculateClosestBlock(player);
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/github/a5h73y/parkour/plugin/EconomyApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,9 @@ private void processAmountCommand(CommandSender commandSender, String... args) {

TranslationUtils.sendMessage(commandSender, args[2] + "'s balance: &b" + getAmount(economy.getBalance(targetPlayer)));
}

@Override
public String getPluginDisplayName() {
return "Vault (Economy)";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ public String getPluginName() {
return "Vault";
}

@Override
public String getPluginDisplayName() {
return "Vault (Permissions)";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public abstract class PluginWrapper extends AbstractPluginReceiver {
*/
public abstract String getPluginName();

public String getPluginDisplayName() {
return this.getPluginName();
}

/**
* Initialise the startup of the plugin on Construction of object.
*/
Expand All @@ -46,11 +50,11 @@ protected void initialise() {
// otherwise display error
if (externalPlugin != null && externalPlugin.isEnabled()) {
enabled = true;
PluginUtils.log("[" + getPluginName() + "] Successfully linked. "
PluginUtils.log("[" + getPluginDisplayName() + "] Successfully linked. "
+ "Version: " + externalPlugin.getDescription().getVersion(), 0);

} else {
PluginUtils.log("[" + getPluginName() + "] Plugin is missing, link was unsuccessful.", 1);
PluginUtils.log("[" + getPluginDisplayName() + "] Plugin is missing, link was unsuccessful.", 1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
import static io.github.a5h73y.parkour.other.ParkourConstants.ERROR_NO_EXIST;
import static io.github.a5h73y.parkour.other.ParkourConstants.PLAYER_PLACEHOLDER;

import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.WeakHashMap;

import io.github.a5h73y.parkour.Parkour;
import io.github.a5h73y.parkour.other.AbstractPluginReceiver;
import io.github.a5h73y.parkour.plugin.EconomyApi;
Expand All @@ -15,12 +22,6 @@
import io.github.a5h73y.parkour.utility.ValidationUtils;
import io.github.a5h73y.parkour.utility.permission.Permission;
import io.github.a5h73y.parkour.utility.permission.PermissionUtils;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.WeakHashMap;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
Expand Down Expand Up @@ -178,7 +179,8 @@ public void removeInvitation(Player player) {
*/
public boolean hasPlayerBeenChallenged(Player player) {
return hasPlayerBeenInvited(player)
|| challenges.values().stream().filter(challenge -> challenge.hasStarted()).anyMatch(challenge -> challenge.isPlayerParticipating(player));
|| challenges.values().stream()
.anyMatch(challenge -> challenge.isPlayerParticipating(player));
}

/**
Expand Down Expand Up @@ -267,6 +269,8 @@ public void completeChallenge(Player winner) {

if (challenge.getWager() != null) {
parkour.getEconomyApi().chargePlayer(loser, challenge.getWager());
TranslationUtils.sendValueTranslation("Parkour.Challenge.LoserWager",
parkour.getEconomyApi().getAmount(challenge.getWager()), loser);
}
}
}
Expand Down Expand Up @@ -361,7 +365,7 @@ public void prepareParticipant(Challenge challenge, Player participant) {
}

if (parkour.getParkourSessionManager().isPlaying(participant)) {
parkour.getPlayerManager().leaveCourse(participant, false);
parkour.getPlayerManager().leaveCourse(participant, true);
}
parkour.getPlayerManager().joinCourse(participant, challenge.getCourseName());
participant.setWalkSpeed(0f);
Expand Down Expand Up @@ -516,15 +520,9 @@ private void processCreateCommand(Player player, String courseName, @Nullable St
}

private void processSendInviteCommand(Player player, String... args) {
Challenge challenge = getChallengeForHost(player);

if (challenge == null) {
TranslationUtils.sendMessage(player, "You have not created a Challenge.");
return;
}
Challenge challenge = getChallengeForPlayer(player);

if (challenge.hasStarted()) {
TranslationUtils.sendMessage(player, "Your Challenge has already started.");
if (!validateChallengeAuthorityValidity(player, challenge)) {
return;
}

Expand All @@ -537,15 +535,9 @@ private void processSendInviteCommand(Player player, String... args) {
}

private void processStartCommand(Player player) {
Challenge challenge = getChallengeForHost(player);

if (challenge == null) {
TranslationUtils.sendMessage(player, "You have not created a challenge.");
return;
}
Challenge challenge = getChallengeForPlayer(player);

if (challenge.hasStarted()) {
TranslationUtils.sendMessage(player, "The Challenge has already started!");
if (!validateChallengeAuthorityValidity(player, challenge)) {
return;
}

Expand All @@ -559,6 +551,20 @@ private void processStartCommand(Player player) {
challenge.markStarted();
}

private void processTerminateCommand(Player player) {
Challenge challenge = getChallengeForPlayer(player);

if (!validateChallengeAuthorityValidity(player, challenge)) {
return;
}

challenge.getParticipatingPlayers().forEach(participantId ->
TranslationUtils.sendMessage(Bukkit.getPlayer(participantId), "The host has terminated the Challenge."));

invites.entrySet().removeIf(entry -> entry.getValue().getChallenge().equals(challenge));
removeChallenge(player);
}

private void processInviteReceiveCommand(Player player, boolean accepted) {
ChallengeInvite invite = getInviteForPlayer(player);

Expand All @@ -574,24 +580,23 @@ private void processInviteReceiveCommand(Player player, boolean accepted) {
}
}

private void processTerminateCommand(Player hostPlayer) {
Challenge challenge = getChallengeForHost(hostPlayer);

private boolean validateChallengeAuthorityValidity(Player player, Challenge challenge) {
if (challenge == null) {
TranslationUtils.sendMessage(hostPlayer, "You have not created a Challenge.");
return;
TranslationUtils.sendMessage(player, "You are not on a Challenge.");
return false;
}

if (challenge.hasStarted()) {
TranslationUtils.sendMessage(hostPlayer, "You can not terminate a Challenge in progress.");
return;
if (!challenge.getChallengeHost().getName().equals(player.getName())) {
TranslationUtils.sendMessage(player, "You are not the host of this Challenge.");
return false;
}

challenge.getParticipatingPlayers().forEach(participantId ->
TranslationUtils.sendMessage(Bukkit.getPlayer(participantId), "The host has terminated the Challenge."));
if (challenge.hasStarted()) {
TranslationUtils.sendMessage(player, "The Challenge has already started!");
return false;
}

invites.entrySet().removeIf(entry -> entry.getValue().getChallenge().equals(challenge));
removeChallenge(hostPlayer);
return true;
}

/**
Expand Down Expand Up @@ -648,6 +653,11 @@ public boolean canCreateChallenge(Player player, String courseNameInput, String
return false;
}

if (getChallengeForPlayer(player) != null) {
TranslationUtils.sendTranslation("Error.OnChallenge", player);
return false;
}

if (!parkour.getPlayerManager().canJoinCourseSilent(player, courseName)) {
TranslationUtils.sendMessage(player, "You are not able to join this Course!");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,19 @@ public boolean containsKey(K key) {
}

protected Set<K> getExpiredKeys() {
return this.cacheMap.keySet().parallelStream()
return this.cacheMap.keySet()
.parallelStream()
.filter(this::isExpired)
.collect(Collectors.toSet());
}

protected boolean isExpired(K key) {
LocalDateTime expirationDateTime = this.cacheMap.get(key).getCreatedAt().plus(this.cacheTimeout, ChronoUnit.SECONDS);
return LocalDateTime.now().isAfter(expirationDateTime);
boolean result = true;
if (this.cacheMap.containsKey(key)) {
LocalDateTime expirationDateTime = this.cacheMap.get(key).getCreatedAt().plus(this.cacheTimeout, ChronoUnit.SECONDS);
result = LocalDateTime.now().isAfter(expirationDateTime);
}
return result;
}

@Override
Expand Down

0 comments on commit 89915e7

Please sign in to comment.