Fixes a crash that prevented STATISTICS entity and material/item challenges to be completed.

This commit is contained in:
BONNe 2023-02-02 23:24:22 +02:00
parent 5ba7c681de
commit ee8eaf8e84
1 changed files with 65 additions and 44 deletions

View File

@ -495,16 +495,20 @@ public class TryToComplete
}
}
case ITEM, BLOCK -> {
int statistic = this.user.getPlayer().getStatistic(requirements.getStatistic());
if (requirements.getMaterial() == null)
{
// Just a sanity check. Material cannot be null at this point of code.
removeAmount = 0;
}
else if (removeAmount >= statistic)
else
{
this.user.getPlayer().setStatistic(requirements.getStatistic(), requirements.getMaterial(), 0);
int statistic = this.user.getPlayer().getStatistic(requirements.getStatistic(),
requirements.getMaterial());
if (removeAmount >= statistic)
{
this.user.getPlayer()
.setStatistic(requirements.getStatistic(), requirements.getMaterial(), 0);
removeAmount -= statistic;
}
else
@ -515,15 +519,19 @@ public class TryToComplete
removeAmount = 0;
}
}
}
case ENTITY -> {
int statistic = this.user.getPlayer().getStatistic(requirements.getStatistic());
if (requirements.getEntity() == null)
{
// Just a sanity check. Entity cannot be null at this point of code.
removeAmount = 0;
}
else if (removeAmount >= statistic)
else
{
int statistic = this.user.getPlayer().getStatistic(requirements.getStatistic(),
requirements.getEntity());
if (removeAmount >= statistic)
{
this.user.getPlayer().setStatistic(requirements.getStatistic(), requirements.getEntity(), 0);
removeAmount -= statistic;
@ -537,6 +545,7 @@ public class TryToComplete
}
}
}
}
// If challenges are in sync with all island members, then punish others too.
if (this.addon.getChallengesSettings().isStoreAsIslandData())
@ -577,17 +586,22 @@ public class TryToComplete
}
}
case ITEM, BLOCK -> {
int statistic = player.getStatistic(requirements.getStatistic());
if (requirements.getMaterial() == null)
{
// Just a sanity check. Entity cannot be null at this point of code.
removeAmount = 0;
}
else if (removeAmount >= statistic)
else
{
int statistic = player.getStatistic(requirements.getStatistic(),
requirements.getMaterial());
if (removeAmount >= statistic)
{
removeAmount -= statistic;
player.setStatistic(requirements.getStatistic(), requirements.getMaterial(), 0);
player.setStatistic(requirements.getStatistic(),
requirements.getMaterial(),
0);
}
else
{
@ -597,18 +611,24 @@ public class TryToComplete
removeAmount = 0;
}
}
}
case ENTITY -> {
int statistic = player.getStatistic(requirements.getStatistic());
if (requirements.getEntity() == null)
{
// Just a sanity check. Entity cannot be null at this point of code.
removeAmount = 0;
}
else if (removeAmount >= statistic)
else
{
int statistic = player.getStatistic(requirements.getStatistic(),
requirements.getEntity());
if (removeAmount >= statistic)
{
removeAmount -= statistic;
player.setStatistic(requirements.getStatistic(), requirements.getEntity(), 0);
player.setStatistic(requirements.getStatistic(),
requirements.getEntity(),
0);
}
else
{
@ -625,6 +645,7 @@ public class TryToComplete
}
}
}
}
/**