Fixed reward duplication on join

This commit is contained in:
Elias Müller 2023-12-27 10:00:26 +01:00
parent de559df98c
commit 53b94c99a9

View File

@ -100,7 +100,7 @@ public class Event extends Appliance {
Response response = new Gson().fromJson(rawResponse.body(), Response.class);
if(rawResponse.statusCode() != 200 || response.error != null) {
p.sendMessage(Component.text("Fehler beim betreten: " + response.error, NamedTextColor.RED));
p.sendMessage(Component.text("Fehler beim Betreten: " + response.error, NamedTextColor.RED));
return;
}
@ -128,7 +128,7 @@ public class Event extends Appliance {
giveReward(reward);
});
for (UUID uuid : rewardConfiguration.memorials) {
rewardConfiguration.memorials.forEach(uuid -> {
ItemStack memorialItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(rewardConfiguration.memorialMaterial)));
ItemMeta meta = memorialItem.getItemMeta();
meta.displayName(Component.text(rewardConfiguration.memorialTitle, NamedTextColor.GOLD));
@ -138,10 +138,10 @@ public class Event extends Appliance {
if (Bukkit.getPlayer(uuid) == null) {
pendingRewards.add(memorial);
continue;
return;
}
giveReward(memorial);
}
});
}
private void giveReward(Reward reward) {
@ -157,9 +157,9 @@ public class Event extends Appliance {
public void applyPendingRewards(Player player) {
if(this.pendingRewards.isEmpty()) return;
this.pendingRewards.stream()
.filter(reward -> reward.playerUuid.equals(player.getUniqueId()))
.forEach(this::giveReward);
List<Reward> givenRewards = this.pendingRewards.stream().filter(reward -> reward.playerUuid.equals(player.getUniqueId())).toList();
this.pendingRewards.removeAll(givenRewards);
givenRewards.forEach(this::giveReward);
}
@Override