Skip to content

Commit c697bb0

Browse files
authored
Merge branch 'master' into new-rankups.yml
2 parents 360e48d + 2a826db commit c697bb0

File tree

9 files changed

+700
-24
lines changed

9 files changed

+700
-24
lines changed

.github/workflows/ci_test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: CI Test
2+
on:
3+
push:
4+
paths:
5+
- 'src/**'
6+
7+
jobs:
8+
ci_test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Setup JDK
13+
uses: actions/setup-java@v2
14+
with:
15+
java-version: 11
16+
distribution: 'adopt'
17+
- name: Gradle Test
18+
run: ./gradlew test --no-daemon

LICENSE.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

LICENSE.txt

Lines changed: 619 additions & 0 deletions
Large diffs are not rendered by default.

src/main/java/sh/okx/rankup/RankupPlugin.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,21 @@ private List<RankSerialized> loadRankupConfig(String name) {
370370
return YamlDeserializer.deserialize(YamlConfiguration.loadConfiguration(ymlFile));
371371
}
372372

373+
private List<RankSerialized> loadRankupConfig(String name) {
374+
File ymlFile = new File(getDataFolder(), name + ".yml");
375+
File tomlFile = new File(getDataFolder(), name + ".toml");
376+
if (tomlFile.exists()) {
377+
try {
378+
return ShadowDeserializer.deserialize(TomlFormat.instance().createParser().parse(new FileReader(tomlFile)));
379+
} catch (FileNotFoundException ignored) {
380+
}
381+
}
382+
if (!ymlFile.exists()) {
383+
saveResource(ymlFile.getName(), false);
384+
}
385+
return YamlDeserializer.deserialize(YamlConfiguration.loadConfiguration(ymlFile));
386+
}
387+
373388
private FileConfiguration loadConfig(String name) {
374389
File file = new File(getDataFolder(), name);
375390
if (!file.exists()) {

src/main/java/sh/okx/rankup/requirements/requirement/MobKillsRequirement.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@ protected MobKillsRequirement(Requirement clone) {
2121
@SuppressWarnings("deprecation")
2222
@Override
2323
public double getProgress(Player player) {
24-
EntityType entity = Objects.requireNonNull(EntityType.fromName(getSub()), "Invalid entity type '" + getSub() + "' in mob-kills requirement.");
24+
EntityType entity = EntityType.fromName(getSub());
25+
if (entity == null) {
26+
EntityType entityFromId;
27+
try {
28+
entityFromId = EntityType.valueOf(getSub().toUpperCase());
29+
} catch (IllegalArgumentException e) {
30+
entityFromId = null;
31+
}
32+
entity = Objects.requireNonNull(entityFromId, "Invalid entity type '" + getSub() + "' in mob-kills requirement.");
33+
}
2534
return player.getStatistic(Statistic.KILL_ENTITY, entity);
2635
}
2736

src/main/resources/locale/es.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# the messages in this section can be customised for each rankup in rankups.yml.
1+
# the messages in this section can be customised for each rankup in rankups.yml.
22
rankup:
33
requirements-not-met: "&cNo satisfaces los requisitos para seguir al siguiente rango."
44
no-rankup: "&eEstás en el último rango."

src/main/resources/rankups.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ ExampleD:
8282
&cYou need:
8383
&c- {{ rank.req('money').total | simple }} money
8484
&c- {{ rank.req('xp-level').total | simple }} XP levels
85-
&cTo rank up to {{next.rank}}!
85+
&cTo rank up to {{next.rank}}!
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package sh.okx.rankup.requirements;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import be.seeseemelk.mockbukkit.entity.PlayerMock;
6+
import org.bukkit.Statistic;
7+
import org.bukkit.entity.EntityType;
8+
import org.junit.jupiter.api.Test;
9+
import sh.okx.rankup.RankupTest;
10+
import sh.okx.rankup.ranks.Rank;
11+
12+
public class MobKillsRequirementsTest extends RankupTest {
13+
14+
public MobKillsRequirementsTest() {
15+
super("mobkillsrequirements");
16+
}
17+
18+
@Test
19+
public void testPrestigeRequirements() {
20+
PlayerMock player = server.addPlayer();
21+
22+
player.setStatistic(Statistic.KILL_ENTITY, EntityType.SNOWMAN, 2);
23+
player.setStatistic(Statistic.KILL_ENTITY, EntityType.MUSHROOM_COW, 1);
24+
25+
Rank rank = plugin.getRankups().getFirst();
26+
27+
assertEquals(3 - 2, rank.getRequirement(player, "mob-kills#snow_golem").getRemaining(player));
28+
assertEquals(3 - 1, rank.getRequirement(player, "mob-kills#mushroom_cow").getRemaining(player));
29+
}
30+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
a:
2+
rank: 'A'
3+
next: 'B'
4+
requirements:
5+
- 'mob-kills snow_golem 3' # entity name
6+
- 'mob-kills mushroom_cow 3' # entity enum value

0 commit comments

Comments
 (0)