Changed TreasureShard rewarding, removed Queue

This commit is contained in:
Teddy 2016-01-08 13:46:39 +00:00
parent 6bf0970dbe
commit 78405749a4

View File

@ -20,10 +20,8 @@ public class TreasureShardReward extends Reward
{
private DonationManager _donationManager;
private Reward _otherReward;
private int _shards = 0;
private int _task;
private Queue<GiveDonorData> _rewardQueue;
private int _shards = 0, _task;
private boolean _success = true;
public TreasureShardReward(DonationManager donationManager, Reward otherReward, int weight, RewardRarity rarity)
{
@ -32,8 +30,6 @@ public class TreasureShardReward extends Reward
_donationManager = donationManager;
_otherReward = otherReward;
_rewardQueue = new LinkedList<GiveDonorData>();
_shards += (int) (otherReward.getShardValue() + (Math.random() * otherReward.getShardValue() / 2.0));
}
@ -42,46 +38,34 @@ public class TreasureShardReward extends Reward
{
RewardData fakeData = _otherReward.getFakeRewardData(player);
RewardData rewardData = new RewardData(fakeData.getHeader(), fakeData.getFriendlyName(), fakeData.getDisplayItem(), fakeData.getRarity(), _shards);
_rewardQueue.add(new GiveDonorData(player.getName(), _donationManager.getClientManager().Get(player).getAccountId(), player.getUniqueId(), _shards));
final GiveDonorData coinData = _rewardQueue.poll();
_task = Bukkit.getScheduler().scheduleSyncRepeatingTask(_donationManager.getPlugin(), new Runnable()
{
@Override
public void run()
{
if (coinData != null && coinData.getAttempts() < 10)
{
_donationManager.RewardCoins(new Callback<Boolean>()
{
@Override
public void run(Boolean data)
{
if (!data)
{
coinData.incrementAttempts();
// System.out.println("Failed to process shards for " + coinData.getPlayerName() + " adding to back of queue. Attempts: " + coinData.getAttempts());
_rewardQueue.add(coinData);
}
else
{
// System.out.println("process of " + _shards + " shards successful");
Bukkit.getScheduler().cancelTask(_task);
}
}
}, "Treasure Chest", player.getName(), _donationManager.getClientManager().Get(player).getAccountId(), _shards);
}
else
{
System.out.println("Failed to process shards for " + coinData.getPlayerName() + ", Too many attempts taken place. (10)");
if(hasRewarded(fakeData, player))
Bukkit.getScheduler().cancelTask(_task);
}
}
}, 0, 5L);
}, 0, 3);
return rewardData;
}
public boolean hasRewarded(RewardData fakeData, Player player)
{
_donationManager.RewardCoins(new Callback<Boolean>()
{
@Override
public void run(Boolean data)
{
_success = data;
}
}, "Treasure Chest", player.getName(), _donationManager.getClientManager().Get(player).getAccountId(), _shards);
return _success;
}
@Override
public RewardData getFakeRewardData(Player player)
{