Skip to content

Commit

Permalink
Merge pull request BetonQuest#3020 from MrGuitz/pointfix
Browse files Browse the repository at this point in the history
fixed global-/point condition
  • Loading branch information
Wolf2323 authored Oct 20, 2024
2 parents 6db0ba0 + 95e4ba3 commit baf6f8d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- LuckPerms integration not pushing the permission update to the connected servers correctly.
- `crafting` objective where complex recipes are not recognized
- `hieght` condition where variable locations threw an exception
- `globalpoint` condition where not initialized global points where 0
- `point` condition where not initialized points where 0
### Security

## [2.1.3] - 2024-08-06
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package org.betonquest.betonquest.quest.condition.point;

import org.betonquest.betonquest.Point;
import org.betonquest.betonquest.api.profiles.Profile;
import org.betonquest.betonquest.api.quest.condition.nullable.NullableCondition;
import org.betonquest.betonquest.database.GlobalData;
import org.betonquest.betonquest.exceptions.QuestRuntimeException;
import org.betonquest.betonquest.instruction.variable.VariableNumber;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
* A condition that checks if global data has a certain amount of points.
*/
Expand Down Expand Up @@ -49,8 +52,17 @@ public GlobalPointCondition(final GlobalData globalData, final String category,

@Override
public boolean check(@Nullable final Profile profile) throws QuestRuntimeException {
final int points = globalData.hasPointsFromCategory(category);
final int pCount = count.getValue(profile).intValue();
final List<Point> points = globalData.getPoints();
for (final Point point : points) {
if (point.getCategory().equals(category)) {
return checkPoints(point.getCount(), profile);
}
}
return false;
}

private boolean checkPoints(final int points, @Nullable final Profile profile) throws QuestRuntimeException {
final int pCount = this.count.getValue(profile).intValue();
return equal ? points == pCount : points >= pCount;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.betonquest.betonquest.quest.condition.point;

import org.betonquest.betonquest.BetonQuest;
import org.betonquest.betonquest.Point;
import org.betonquest.betonquest.api.profiles.Profile;
import org.betonquest.betonquest.api.quest.condition.PlayerCondition;
import org.betonquest.betonquest.exceptions.QuestRuntimeException;
import org.betonquest.betonquest.instruction.variable.VariableNumber;

import java.util.List;

/**
* A condition that checks if a player has a certain amount of points.
*/
Expand Down Expand Up @@ -48,8 +51,17 @@ public PointCondition(final BetonQuest betonQuest, final String category, final

@Override
public boolean check(final Profile profile) throws QuestRuntimeException {
final int points = betonQuest.getPlayerData(profile).hasPointsFromCategory(category);
final int pCount = count.getValue(profile).intValue();
final List<Point> points = betonQuest.getPlayerData(profile).getPoints();
for (final Point point : points) {
if (point.getCategory().equals(category)) {
return checkPoints(point.getCount(), profile);
}
}
return false;
}

private boolean checkPoints(final int points, final Profile profile) throws QuestRuntimeException {
final int pCount = this.count.getValue(profile).intValue();
return equal ? points == pCount : points >= pCount;
}
}

0 comments on commit baf6f8d

Please sign in to comment.