Merge pull request #116 in MIN/mineplex from bugfix/duplicates to develop
* commit 'af27944a39129454b2963707c27799643d2440f1': add a shard queue to DonationManager, use that for TreasureShardReward Import clean up Changed TreasureShard rewarding, removed Queue Unused import removed Queue speed up Debugs removed Treasure not giving Shards when dupes occur, fixed. Queue implemented for duplicate shard reward
This commit is contained in:
commit
0d02f526b6
@ -7,8 +7,6 @@ import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import java.util.TimeZone;
|
||||
@ -17,7 +15,6 @@ import mineplex.core.MiniClientPlugin;
|
||||
import mineplex.core.account.CoreClient;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.account.ILoginProcessor;
|
||||
import mineplex.core.account.IQuerylessLoginProcessor;
|
||||
import mineplex.core.account.event.ClientUnloadEvent;
|
||||
import mineplex.core.bonuses.redis.VoteHandler;
|
||||
import mineplex.core.bonuses.redis.VotifierCommand;
|
||||
@ -32,6 +29,7 @@ import mineplex.core.common.util.UtilParticle.ParticleType;
|
||||
import mineplex.core.common.util.UtilParticle.ViewDist;
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.donation.DonationManager;
|
||||
import mineplex.core.donation.GiveDonorData;
|
||||
import mineplex.core.facebook.FacebookManager;
|
||||
import mineplex.core.giveaway.GiveawayManager;
|
||||
import mineplex.core.hologram.Hologram;
|
||||
@ -59,7 +57,6 @@ import mineplex.core.bonuses.gui.SpinGui;
|
||||
import mineplex.core.poll.PollManager;
|
||||
import mineplex.serverdata.commands.ServerCommandManager;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -755,7 +752,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
||||
if (gems > 0)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(gems + " Gems")));
|
||||
_gemQueue.add(new GiveDonorData(player.getName(), coreClient.getAccountId(), player.getUniqueId(), gems));
|
||||
_gemQueue.add(new GiveDonorData(null, player.getName(), "Treasure", player.getUniqueId(), coreClient.getAccountId(), gems));
|
||||
}
|
||||
|
||||
if (gold > 0)
|
||||
@ -780,7 +777,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
||||
if (coins > 0)
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(coins + " Treasure Shards")));
|
||||
_coinQueue.add(new GiveDonorData(player.getName(), coreClient.getAccountId(), player.getUniqueId(), coins));
|
||||
_coinQueue.add(new GiveDonorData(null, player.getName(), "Treasure", player.getUniqueId(), coreClient.getAccountId(), coins));
|
||||
}
|
||||
|
||||
if (tickets > 0)
|
||||
|
@ -1,50 +0,0 @@
|
||||
package mineplex.core.bonuses;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class GiveDonorData
|
||||
{
|
||||
private String _playerName;
|
||||
private int _accountId;
|
||||
private UUID _uuid;
|
||||
private int _giveAmount;
|
||||
private int _attempts;
|
||||
|
||||
public GiveDonorData(String playerName, int accountId, UUID uuid, int giveAmount)
|
||||
{
|
||||
_playerName = playerName;
|
||||
_accountId = accountId;
|
||||
_uuid = uuid;
|
||||
_giveAmount = giveAmount;
|
||||
}
|
||||
|
||||
public String getPlayerName()
|
||||
{
|
||||
return _playerName;
|
||||
}
|
||||
|
||||
public int getAccountId()
|
||||
{
|
||||
return _accountId;
|
||||
}
|
||||
|
||||
public UUID getUuid()
|
||||
{
|
||||
return _uuid;
|
||||
}
|
||||
|
||||
public int getGiveAmount()
|
||||
{
|
||||
return _giveAmount;
|
||||
}
|
||||
|
||||
public int getAttempts()
|
||||
{
|
||||
return _attempts;
|
||||
}
|
||||
|
||||
public void incrementAttempts()
|
||||
{
|
||||
_attempts++;
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@ package mineplex.core.donation;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -30,17 +32,23 @@ import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
public class DonationManager extends MiniDbClientPlugin<Donor>
|
||||
{
|
||||
private final int MAX_GIVE_ATTEMPTS = 10;
|
||||
|
||||
private DonationRepository _repository;
|
||||
|
||||
private NautHashMap<Player, NautHashMap<String, Integer>> _gemQueue = new NautHashMap<Player, NautHashMap<String, Integer>>();
|
||||
private NautHashMap<Player, NautHashMap<String, Integer>> _coinQueue = new NautHashMap<Player, NautHashMap<String, Integer>>();
|
||||
private NautHashMap<Player, NautHashMap<String, Integer>> _goldQueue = new NautHashMap<Player, NautHashMap<String, Integer>>();
|
||||
|
||||
private Queue<GiveDonorData> _coinAttemptQueue;
|
||||
|
||||
public DonationManager(JavaPlugin plugin, CoreClientManager clientManager, String webAddress)
|
||||
{
|
||||
super("Donation", plugin, clientManager);
|
||||
|
||||
_repository = new DonationRepository(plugin, webAddress);
|
||||
|
||||
_coinAttemptQueue = new LinkedList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -204,6 +212,11 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
|
||||
_gemQueue.clear();
|
||||
}
|
||||
|
||||
public void rewardCoinsUntilSuccess(Callback<Boolean> callback, String caller, String name, int accountId, int amount)
|
||||
{
|
||||
_coinAttemptQueue.add(new GiveDonorData(callback, name, caller, accountId, amount));
|
||||
}
|
||||
|
||||
public void RewardCoins(Callback<Boolean> callback, String caller, String name, int accountId, int amount)
|
||||
{
|
||||
RewardCoins(callback, caller, name, accountId, amount, true);
|
||||
@ -298,6 +311,57 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
|
||||
//Clean
|
||||
_coinQueue.clear();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void processCoinAttemptQueue(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FAST)
|
||||
return;
|
||||
|
||||
GiveDonorData data = _coinAttemptQueue.poll();
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
_repository.rewardCoins(new Callback<Boolean>()
|
||||
{
|
||||
@Override
|
||||
public void run(Boolean success)
|
||||
{
|
||||
if (success)
|
||||
{
|
||||
Donor donor = Get(data.getPlayerName());
|
||||
|
||||
if (donor != null)
|
||||
{
|
||||
donor.addCoins(data.getGiveAmount());
|
||||
}
|
||||
|
||||
if (data.getCallback() != null) data.getCallback().run(true);
|
||||
|
||||
System.out.println("Successfully rewarded shards to player " + data.getPlayerName());
|
||||
}
|
||||
else
|
||||
{
|
||||
data.incrementAttempts();
|
||||
|
||||
if (data.getAttempts() >= MAX_GIVE_ATTEMPTS)
|
||||
{
|
||||
// Admit Defeat!
|
||||
if (data.getCallback() != null) data.getCallback().run(false);
|
||||
System.out.println("Gave up giving shards to player " + data.getPlayerName());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add again to the back of queue
|
||||
_coinAttemptQueue.add(data);
|
||||
System.out.println("Failed to reward shards to player " + data.getPlayerName() + ". Attempts: " + data.getAttempts());
|
||||
}
|
||||
}
|
||||
}
|
||||
}, data.getCaller(), data.getPlayerName(), data.getAccountId(), data.getGiveAmount());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void rewardGold(Callback<Boolean> callback, String caller, Player player, int amount)
|
||||
{
|
||||
|
@ -0,0 +1,71 @@
|
||||
package mineplex.core.donation;
|
||||
|
||||
import mineplex.core.common.util.Callback;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class GiveDonorData
|
||||
{
|
||||
private final String _playerName;
|
||||
private final String _caller;
|
||||
private final UUID _uuid;
|
||||
private final int _accountId;
|
||||
private final int _giveAmount;
|
||||
private final Callback<Boolean> _callback;
|
||||
private int _attempts;
|
||||
|
||||
public GiveDonorData(Callback<Boolean> callback, String playerName, String caller, UUID uuid, int accountId, int giveAmount)
|
||||
{
|
||||
_callback = callback;
|
||||
_playerName = playerName;
|
||||
_caller = caller;
|
||||
_uuid = uuid;
|
||||
_accountId = accountId;
|
||||
_giveAmount = giveAmount;
|
||||
}
|
||||
|
||||
public GiveDonorData(Callback<Boolean> callback, String playerName, String caller, int accountId, int giveAmount)
|
||||
{
|
||||
this(callback, playerName, caller, null, accountId, giveAmount);
|
||||
}
|
||||
|
||||
public UUID getUuid()
|
||||
{
|
||||
return _uuid;
|
||||
}
|
||||
|
||||
public Callback<Boolean> getCallback()
|
||||
{
|
||||
return _callback;
|
||||
}
|
||||
|
||||
public String getPlayerName()
|
||||
{
|
||||
return _playerName;
|
||||
}
|
||||
|
||||
public String getCaller()
|
||||
{
|
||||
return _caller;
|
||||
}
|
||||
|
||||
public int getAccountId()
|
||||
{
|
||||
return _accountId;
|
||||
}
|
||||
|
||||
public int getGiveAmount()
|
||||
{
|
||||
return _giveAmount;
|
||||
}
|
||||
|
||||
public int getAttempts()
|
||||
{
|
||||
return _attempts;
|
||||
}
|
||||
|
||||
public void incrementAttempts()
|
||||
{
|
||||
_attempts++;
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ public class RewardData
|
||||
private final ItemStack _displayItem;
|
||||
private final RewardRarity _rarity;
|
||||
private final boolean _rewardedShards;
|
||||
private final int _shards;
|
||||
private int _shards;
|
||||
|
||||
public RewardData(String header, String friendlyName, ItemStack displayItem, RewardRarity rarity, int shards)
|
||||
{
|
||||
@ -63,4 +63,9 @@ public class RewardData
|
||||
{
|
||||
return _shards;
|
||||
}
|
||||
|
||||
public void setShards(int value)
|
||||
{
|
||||
_shards = value;
|
||||
}
|
||||
}
|
||||
|
@ -513,7 +513,7 @@ public class RewardManager
|
||||
if (reward.canGiveReward(player))
|
||||
return reward;
|
||||
else
|
||||
return new TreasureShardReward(_donationManager, reward, 1, reward.getRarity());
|
||||
return new TreasureShardReward(_clientManager, _donationManager, reward, 1, reward.getRarity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package mineplex.core.reward.rewards;
|
||||
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -13,18 +15,20 @@ import mineplex.core.reward.RewardType;
|
||||
|
||||
public class TreasureShardReward extends Reward
|
||||
{
|
||||
private CoreClientManager _clientManager;
|
||||
private DonationManager _donationManager;
|
||||
private Reward _otherReward;
|
||||
private int _shards;
|
||||
private int _shards = 0;
|
||||
|
||||
public TreasureShardReward(DonationManager donationManager, Reward otherReward, int weight, RewardRarity rarity)
|
||||
public TreasureShardReward(CoreClientManager clientManager, DonationManager donationManager, Reward otherReward, int weight, RewardRarity rarity)
|
||||
{
|
||||
super(rarity, weight, 0);
|
||||
|
||||
_clientManager = clientManager;
|
||||
_donationManager = donationManager;
|
||||
_otherReward = otherReward;
|
||||
|
||||
_shards = (int) (otherReward.getShardValue() + (Math.random() * otherReward.getShardValue() / 2.0));
|
||||
_shards += (int) (otherReward.getShardValue() + (Math.random() * otherReward.getShardValue() / 2.0));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -33,14 +37,17 @@ public class TreasureShardReward extends Reward
|
||||
RewardData fakeData = _otherReward.getFakeRewardData(player);
|
||||
RewardData rewardData = new RewardData(fakeData.getHeader(), fakeData.getFriendlyName(), fakeData.getDisplayItem(), fakeData.getRarity(), _shards);
|
||||
|
||||
_donationManager.RewardCoins(new Callback<Boolean>()
|
||||
int accountId = _clientManager.getAccountId(player);
|
||||
|
||||
// Give shards 5 seconds later for better effect
|
||||
Bukkit.getScheduler().runTaskLater(_donationManager.getPlugin(), new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run(Boolean data)
|
||||
public void run()
|
||||
{
|
||||
|
||||
_donationManager.rewardCoinsUntilSuccess(null, "Treasure", player.getName(), accountId, _shards);
|
||||
}
|
||||
}, "Treasure Chest", player.getName(), _donationManager.getClientManager().Get(player).getAccountId(), _shards);
|
||||
}, 100);
|
||||
|
||||
return rewardData;
|
||||
}
|
||||
@ -66,3 +73,4 @@ public class TreasureShardReward extends Reward
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,8 @@ public class Treasure
|
||||
reward.giveReward(_rewardType, player, new Callback<RewardData>()
|
||||
{
|
||||
@Override
|
||||
public void run(RewardData data) {
|
||||
public void run(RewardData data)
|
||||
{
|
||||
_rewardData.put(count, data);
|
||||
}
|
||||
});
|
||||
@ -350,6 +351,7 @@ public class Treasure
|
||||
public void run(RewardData data)
|
||||
{
|
||||
// Do nothing
|
||||
System.out.println("Shards: " + data.getShards());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user