add support for using EntityType.valueOf instead of EntityType.fromName
This commit is contained in:
@@ -21,7 +21,16 @@ public class MobKillsRequirement extends ProgressiveRequirement {
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public double getProgress(Player player) {
|
public double getProgress(Player player) {
|
||||||
EntityType entity = Objects.requireNonNull(EntityType.fromName(getSub()), "Invalid entity type '" + getSub() + "' in mob-kills requirement.");
|
EntityType entity = EntityType.fromName(getSub());
|
||||||
|
if (entity == null) {
|
||||||
|
EntityType entityFromId;
|
||||||
|
try {
|
||||||
|
entityFromId = EntityType.valueOf(getSub().toUpperCase());
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
entityFromId = null;
|
||||||
|
}
|
||||||
|
entity = Objects.requireNonNull(entityFromId, "Invalid entity type '" + getSub() + "' in mob-kills requirement.");
|
||||||
|
}
|
||||||
return player.getStatistic(Statistic.KILL_ENTITY, entity);
|
return player.getStatistic(Statistic.KILL_ENTITY, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package sh.okx.rankup.requirements;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||||
|
import org.bukkit.Statistic;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import sh.okx.rankup.RankupTest;
|
||||||
|
import sh.okx.rankup.ranks.Rank;
|
||||||
|
|
||||||
|
public class MobKillsRequirementsTest extends RankupTest {
|
||||||
|
|
||||||
|
public MobKillsRequirementsTest() {
|
||||||
|
super("mobkillsrequirements");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPrestigeRequirements() {
|
||||||
|
PlayerMock player = server.addPlayer();
|
||||||
|
|
||||||
|
player.setStatistic(Statistic.KILL_ENTITY, EntityType.SNOWMAN, 2);
|
||||||
|
player.setStatistic(Statistic.KILL_ENTITY, EntityType.MUSHROOM_COW, 1);
|
||||||
|
|
||||||
|
Rank rank = plugin.getRankups().getFirst();
|
||||||
|
|
||||||
|
assertEquals(3 - 2, rank.getRequirement(player, "mob-kills#snow_golem").getRemaining(player));
|
||||||
|
assertEquals(3 - 1, rank.getRequirement(player, "mob-kills#mushroom_cow").getRemaining(player));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
a:
|
||||||
|
rank: 'A'
|
||||||
|
next: 'B'
|
||||||
|
requirements:
|
||||||
|
- 'mob-kills snow_golem 3' # entity name
|
||||||
|
- 'mob-kills mushroom_cow 3' # entity enum value
|
||||||
Reference in New Issue
Block a user