Skip to content

Commit

Permalink
fix papi placeholders when using world or placeholder requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
okx-code committed Jul 25, 2023
1 parent 8bf5029 commit abd4365
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pitest {
}

group 'sh.okx'
version '3.14.1'
version '3.14.2'

java {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/sh/okx/rankup/placeholders/RankupExpansion.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ private String getPlaceholderRequirement(Player player, Rank rank, String requir
case "left":
return placeholders.getSimpleFormat().format(orElse(requirement, r -> r.getRemaining(player), 0));
case "done":
return placeholders.getSimpleFormat().format(orElse(requirement, r -> r.getValueDouble() - r.getRemaining(player), 0));
return placeholders.getSimpleFormat().format(orElse(requirement, r -> r.getTotal(player) - r.getRemaining(player), 0));
case "percent_left":
return placeholders.getPercentFormat().format(orElse(requirement, r -> (r.getRemaining(player) / r.getValueDouble()) * 100, 0));
return placeholders.getPercentFormat().format(orElse(requirement, r -> (r.getRemaining(player) / r.getTotal(player)) * 100, 0));
case "percent_done":
return placeholders.getPercentFormat().format(orElse(requirement, r -> (1 - (r.getRemaining(player) / r.getValueDouble())) * 100, 100));
return placeholders.getPercentFormat().format(orElse(requirement, r -> (1 - (r.getRemaining(player) / r.getTotal(player))) * 100, 100));
default:
return null;
}
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/sh/okx/rankup/WorldRequirementTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package sh.okx.rankup;


import be.seeseemelk.mockbukkit.entity.PlayerMock;
import org.bukkit.Location;
import org.junit.jupiter.api.Test;
import sh.okx.rankup.placeholders.RankupExpansion;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class WorldRequirementTest extends RankupTest {

public WorldRequirementTest() {
super("world");
}

@Test
public void testStatusComplete() {
PlayerMock player = server.addPlayer();
groupProvider.addGroup(player.getUniqueId(), "a");

RankupExpansion expansion = plugin.getPlaceholders().getExpansion();
assertEquals("0", expansion.placeholder(player, "requirement_world_percent_done"));

player.teleport(new Location(server.getWorld("the_nether"), 0, 0, 0));

assertEquals("100", expansion.placeholder(player, "requirement_world_percent_done"));
}
}
5 changes: 5 additions & 0 deletions src/test/resources/world/rankups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a:
rank: 'a'
next: 'b'
requirements:
- 'world the_nether'

0 comments on commit abd4365

Please sign in to comment.