Skip to content

Commit faa2e52

Browse files
committed
removed custom condition from IntervalReward because it makes no sense there
1 parent 7b4cdc1 commit faa2e52

File tree

4 files changed

+6
-28
lines changed

4 files changed

+6
-28
lines changed

PlayerLevels-API/src/main/java/net/jandie1505/playerlevels/core/rewards/IntervalRewardData.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* This data is normally created by the reward creator for the specific reward type, like {@link CommandReward#createInterval(String, boolean, CommandReward.SenderType, Component, int, int, int)}.<br/>
1111
* It can be used to create events using {@link net.jandie1505.playerlevels.api.core.reward.RewardsManager#addIntervalReward(RewardConfig, IntervalRewardData)}.
1212
* @param executor the code that will be executed when the reward is applied
13-
* @param customCondition a custom condition when the reward counts as applied (apart from the level condition)
1413
* @param descriptionProvider Provides a description for the reward.
1514
* @param requiresPlayerOnline if the player is required to be online that the reward is applied
1615
* @param start the level where from which the interval calculation starts
@@ -19,7 +18,6 @@
1918
*/
2019
public record IntervalRewardData(
2120
@NotNull RewardExecutor executor,
22-
@Nullable RewardCondition customCondition,
2321
@Nullable RewardDescriptionProvider descriptionProvider,
2422
boolean requiresPlayerOnline,
2523
int start,

PlayerLevels-API/src/main/java/net/jandie1505/playerlevels/core/rewards/types/CommandReward.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static IntervalRewardData createInterval(
155155
int limit
156156
) {
157157
CommandReward reward = new CommandReward(command, senderType, description);
158-
return new IntervalRewardData(reward, null, reward, requiresOnlinePlayer, start, interval, limit);
158+
return new IntervalRewardData(reward, reward, requiresOnlinePlayer, start, interval, limit);
159159
}
160160

161161
// ----- CREATOR -----

PlayerLevels-API/src/main/java/net/jandie1505/playerlevels/core/rewards/types/PlayerPointsReward.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public static IntervalRewardData createInterval(
137137
int limit
138138
) {
139139
PlayerPointsReward reward = new PlayerPointsReward(formula, description);
140-
return new IntervalRewardData(reward, null, reward, true, start, interval, limit);
140+
return new IntervalRewardData(reward, reward, true, start, interval, limit);
141141
}
142142

143143
// ----- OTHER STUFF -----

PlayerLevels-Core/src/main/java/net/jandie1505/playerlevels/core/rewards/IntervalReward.java

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ public class IntervalReward extends Reward implements net.jandie1505.playerlevel
1313
private final int start;
1414
private final int interval;
1515
private final int limit;
16-
@NotNull private final RewardCondition customCondition;
1716

18-
public IntervalReward(@NotNull RewardsManager manager, @NotNull String id, @Nullable String serverId, int start, int interval, int limit, @NotNull RewardExecutor executor, @Nullable RewardCondition customCondition, boolean requireOnlinePlayer, @NotNull String name, @Nullable RewardDescriptionProvider descriptionProvider) {
17+
public IntervalReward(@NotNull RewardsManager manager, @NotNull String id, @Nullable String serverId, int start, int interval, int limit, @NotNull RewardExecutor executor, boolean requireOnlinePlayer, @NotNull String name, @Nullable RewardDescriptionProvider descriptionProvider) {
1918
super(manager, id, serverId, executor, requireOnlinePlayer, limit, name, descriptionProvider);
2019
this.start = start > 0 ? start : 1;
2120
this.interval = interval > 0 ? interval : 1;
2221
this.limit = limit;
23-
this.customCondition = customCondition != null ? customCondition : net.jandie1505.playerlevels.api.core.reward.IntervalReward.DEFAULT_CONDITION;
2422
}
2523

2624
public IntervalReward(@NotNull RewardsManager manager, @NotNull RewardConfig config, @NotNull IntervalRewardData data) {
27-
this(manager, config.id(), config.serverId(), data.start(), data.interval(), data.limit(), data.executor(), data.customCondition(), data.requiresPlayerOnline(), config.name(), data.descriptionProvider());
25+
this(manager, config.id(), config.serverId(), data.start(), data.interval(), data.limit(), data.executor(), data.requiresPlayerOnline(), config.name(), data.descriptionProvider());
2826
}
2927

3028
// ----- CONDITIONS -----
@@ -37,26 +35,8 @@ public boolean checkApplyCondition(@NotNull Leveler leveler, int checkedLevel) {
3735
return false;
3836
}
3937

40-
// Condition is not met when the reward has already been applied for the level
41-
if (leveler.getData().getOrCreateReceivedReward(this.getId()).level() >= checkedLevel) {
42-
return false;
43-
}
44-
45-
// Check if the reward has already been applied with the custom condition
46-
try {
47-
return !this.customCondition.isApplied(this, leveler, checkedLevel);
48-
} catch (Exception e) {
49-
IntervalReward.this.getManager().getPlugin().getLogger().log(Level.WARNING, "Exception while applying reward " + IntervalReward.this.getId() + " to player " + leveler.getPlayerUUID(), e);
50-
return false;
51-
} catch (Throwable t) {
52-
IntervalReward.this.setEnabled(false);
53-
IntervalReward.this.getManager().getPlugin().getLogger().log(Level.SEVERE,
54-
"A throwable which is not an exception has been thrown in isApplied from reward " + IntervalReward.this.getId() + " to player " + leveler.getPlayerUUID() + " " +
55-
"The reward has been disabled for safety reasons. DO NOT IGNORE THIS!",
56-
t
57-
);
58-
return false;
59-
}
38+
// The Condition is not met when the reward has already been applied for the level
39+
return leveler.getData().getOrCreateReceivedReward(this.getId()).level() < checkedLevel;
6040
}
6141

6242
@Override

0 commit comments

Comments
 (0)