Make reward items list thread safe; resolves #177

This commit is contained in:
Daniel Saukel 2016-11-27 00:03:40 +01:00
parent c1c04bc187
commit 4863dbca61
2 changed files with 6 additions and 4 deletions

View File

@ -30,6 +30,7 @@ import io.github.dre2n.dungeonsxl.world.DGameWorld;
import io.github.dre2n.dungeonsxl.world.DResourceWorld;
import java.io.File;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -55,7 +56,7 @@ public class DGlobalPlayer {
private ItemStack[] respawnInventory;
private ItemStack[] respawnArmor;
private List<ItemStack> rewardItems;
private CopyOnWriteArrayList<ItemStack> rewardItems;
public DGlobalPlayer(Player player) {
this(player, false);
@ -236,7 +237,7 @@ public class DGlobalPlayer {
/**
* @return the reward items
*/
public List<ItemStack> getRewardItems() {
public CopyOnWriteArrayList<ItemStack> getRewardItems() {
return rewardItems;
}
@ -251,7 +252,7 @@ public class DGlobalPlayer {
* @param rewardItems
* the reward items to set
*/
public void setRewardItems(List<ItemStack> rewardItems) {
public void setRewardItems(CopyOnWriteArrayList<ItemStack> rewardItems) {
this.rewardItems = rewardItems;
}

View File

@ -21,6 +21,7 @@ import io.github.dre2n.dungeonsxl.config.DMessages;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -78,7 +79,7 @@ public class ItemReward extends Reward {
} else {
new DLootInventory(player, items.subList(0, 54).toArray(new ItemStack[54]));
plugin.getDPlayers().getByPlayer(player).setRewardItems(items.subList(54, items.size()));
plugin.getDPlayers().getByPlayer(player).setRewardItems(new CopyOnWriteArrayList<>(items.subList(54, items.size())));
MessageUtil.sendMessage(player, DMessages.ERROR_TOO_MANY_REWARDS.getMessage());
}
}