Merge pull request #154 in MIN/mineplex from develop to master

* commit '86917fb1463f018a1f00f80ffd919d1a4afadbb1':
  Fix treasure stair orientation
  add a shard queue to DonationManager, use that for TreasureShardReward
  Fixed various ways of players going invisible through Spec mode.
  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:
Shaun Bennett 2016-02-02 05:29:42 -06:00
commit 70d41b074f
13 changed files with 203 additions and 89 deletions

View File

@ -7,8 +7,6 @@ import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Queue; import java.util.Queue;
import java.util.TimeZone; import java.util.TimeZone;
@ -17,7 +15,6 @@ import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.ILoginProcessor; import mineplex.core.account.ILoginProcessor;
import mineplex.core.account.IQuerylessLoginProcessor;
import mineplex.core.account.event.ClientUnloadEvent; import mineplex.core.account.event.ClientUnloadEvent;
import mineplex.core.bonuses.redis.VoteHandler; import mineplex.core.bonuses.redis.VoteHandler;
import mineplex.core.bonuses.redis.VotifierCommand; 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.common.util.UtilParticle.ViewDist;
import mineplex.core.database.DBPool; import mineplex.core.database.DBPool;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.donation.GiveDonorData;
import mineplex.core.facebook.FacebookManager; import mineplex.core.facebook.FacebookManager;
import mineplex.core.giveaway.GiveawayManager; import mineplex.core.giveaway.GiveawayManager;
import mineplex.core.hologram.Hologram; import mineplex.core.hologram.Hologram;
@ -59,7 +57,6 @@ import mineplex.core.bonuses.gui.SpinGui;
import mineplex.core.poll.PollManager; import mineplex.core.poll.PollManager;
import mineplex.serverdata.commands.ServerCommandManager; import mineplex.serverdata.commands.ServerCommandManager;
import org.jooq.DSLContext;
import org.jooq.SQLDialect; import org.jooq.SQLDialect;
import org.jooq.impl.DSL; import org.jooq.impl.DSL;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -755,7 +752,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
if (gems > 0) if (gems > 0)
{ {
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(gems + " Gems"))); 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) if (gold > 0)
@ -780,7 +777,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
if (coins > 0) if (coins > 0)
{ {
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(coins + " Treasure Shards"))); 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) if (tickets > 0)

View File

@ -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++;
}
}

View File

@ -2,6 +2,8 @@ package mineplex.core.donation;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -30,17 +32,23 @@ import mineplex.core.updater.event.UpdateEvent;
public class DonationManager extends MiniDbClientPlugin<Donor> public class DonationManager extends MiniDbClientPlugin<Donor>
{ {
private final int MAX_GIVE_ATTEMPTS = 10;
private DonationRepository _repository; private DonationRepository _repository;
private NautHashMap<Player, NautHashMap<String, Integer>> _gemQueue = new NautHashMap<Player, NautHashMap<String, Integer>>(); 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>> _coinQueue = new NautHashMap<Player, NautHashMap<String, Integer>>();
private NautHashMap<Player, NautHashMap<String, Integer>> _goldQueue = 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) public DonationManager(JavaPlugin plugin, CoreClientManager clientManager, String webAddress)
{ {
super("Donation", plugin, clientManager); super("Donation", plugin, clientManager);
_repository = new DonationRepository(plugin, webAddress); _repository = new DonationRepository(plugin, webAddress);
_coinAttemptQueue = new LinkedList<>();
} }
@Override @Override
@ -204,6 +212,11 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
_gemQueue.clear(); _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) public void RewardCoins(Callback<Boolean> callback, String caller, String name, int accountId, int amount)
{ {
RewardCoins(callback, caller, name, accountId, amount, true); RewardCoins(callback, caller, name, accountId, amount, true);
@ -298,6 +311,57 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
//Clean //Clean
_coinQueue.clear(); _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) public void rewardGold(Callback<Boolean> callback, String caller, Player player, int amount)
{ {

View File

@ -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++;
}
}

View File

@ -12,7 +12,7 @@ public class RewardData
private final ItemStack _displayItem; private final ItemStack _displayItem;
private final RewardRarity _rarity; private final RewardRarity _rarity;
private final boolean _rewardedShards; private final boolean _rewardedShards;
private final int _shards; private int _shards;
public RewardData(String header, String friendlyName, ItemStack displayItem, RewardRarity rarity, int shards) public RewardData(String header, String friendlyName, ItemStack displayItem, RewardRarity rarity, int shards)
{ {
@ -63,4 +63,9 @@ public class RewardData
{ {
return _shards; return _shards;
} }
public void setShards(int value)
{
_shards = value;
}
} }

View File

@ -513,7 +513,7 @@ public class RewardManager
if (reward.canGiveReward(player)) if (reward.canGiveReward(player))
return reward; return reward;
else else
return new TreasureShardReward(_donationManager, reward, 1, reward.getRarity()); return new TreasureShardReward(_clientManager, _donationManager, reward, 1, reward.getRarity());
} }
} }
} }

View File

@ -1,5 +1,7 @@
package mineplex.core.reward.rewards; package mineplex.core.reward.rewards;
import mineplex.core.account.CoreClientManager;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -13,18 +15,20 @@ import mineplex.core.reward.RewardType;
public class TreasureShardReward extends Reward public class TreasureShardReward extends Reward
{ {
private CoreClientManager _clientManager;
private DonationManager _donationManager; private DonationManager _donationManager;
private Reward _otherReward; 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); super(rarity, weight, 0);
_clientManager = clientManager;
_donationManager = donationManager; _donationManager = donationManager;
_otherReward = otherReward; _otherReward = otherReward;
_shards = (int) (otherReward.getShardValue() + (Math.random() * otherReward.getShardValue() / 2.0)); _shards += (int) (otherReward.getShardValue() + (Math.random() * otherReward.getShardValue() / 2.0));
} }
@Override @Override
@ -33,14 +37,17 @@ public class TreasureShardReward extends Reward
RewardData fakeData = _otherReward.getFakeRewardData(player); RewardData fakeData = _otherReward.getFakeRewardData(player);
RewardData rewardData = new RewardData(fakeData.getHeader(), fakeData.getFriendlyName(), fakeData.getDisplayItem(), fakeData.getRarity(), _shards); 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 @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; return rewardData;
} }
@ -66,3 +73,4 @@ public class TreasureShardReward extends Reward
return false; return false;
} }
} }

View File

@ -117,7 +117,8 @@ public class Treasure
reward.giveReward(_rewardType, player, new Callback<RewardData>() reward.giveReward(_rewardType, player, new Callback<RewardData>()
{ {
@Override @Override
public void run(RewardData data) { public void run(RewardData data)
{
_rewardData.put(count, data); _rewardData.put(count, data);
} }
}); });
@ -350,6 +351,7 @@ public class Treasure
public void run(RewardData data) public void run(RewardData data)
{ {
// Do nothing // Do nothing
System.out.println("Shards: " + data.getShards());
} }
}); });
} }

View File

@ -77,7 +77,9 @@ public class BlockChangeAnimation extends Animation
continue; continue;
_blockInfoList.add(new BlockInfo(b)); _blockInfoList.add(new BlockInfo(b));
byte data = b.getData();
b.setType(mat); b.setType(mat);
b.setData(data);
} }
} }
} }

View File

@ -861,6 +861,9 @@ public class ArcadeManager extends MiniPlugin implements IRelation
public void Clear(Player player) public void Clear(Player player)
{ {
if (player.getGameMode() == GameMode.SPECTATOR)
player.setSpectatorTarget(null);
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
player.setAllowFlight(false); player.setAllowFlight(false);
player.setFlySpeed(0.1F); player.setFlySpeed(0.1F);

View File

@ -8,6 +8,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -481,6 +482,10 @@ public class Paintball extends TeamGame
} }
//Settings //Settings
if (player.getGameMode() == GameMode.SPECTATOR)
player.setSpectatorTarget(null);
player.setGameMode(GameMode.SURVIVAL);
player.setAllowFlight(false); player.setAllowFlight(false);
player.setFlying(false); player.setFlying(false);
((CraftPlayer)player).getHandle().spectating = false; ((CraftPlayer)player).getHandle().spectating = false;

View File

@ -9,6 +9,7 @@ import java.util.Set;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.EntityEffect; import org.bukkit.EntityEffect;
import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -820,6 +821,10 @@ public class WitherGame extends TeamGame implements IBlockRestorer
} }
// Settings // Settings
if (player.getGameMode() == GameMode.SPECTATOR)
player.setSpectatorTarget(null);
player.setGameMode(GameMode.SURVIVAL);
player.setAllowFlight(false); player.setAllowFlight(false);
player.setFlying(false); player.setFlying(false);
((CraftPlayer) player).getHandle().spectating = false; ((CraftPlayer) player).getHandle().spectating = false;

View File

@ -2,6 +2,19 @@ package nautilus.game.arcade.managers;
import java.util.List; import java.util.List;
import org.bukkit.GameMode;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
@ -13,23 +26,6 @@ import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.Game.GameState;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.inventory.ItemStack;
public class GameSpectatorManager implements Listener public class GameSpectatorManager implements Listener
{ {
ArcadeManager Manager; ArcadeManager Manager;
@ -228,19 +224,25 @@ public class GameSpectatorManager implements Listener
@Override @Override
public void run() public void run()
{ {
if(target instanceof Player) Player ptarget = null;
if (target instanceof Player)
ptarget = (Player) target;
if (ptarget != null)
{ {
if(!Manager.GetGame().IsAlive(target)) if (!Manager.GetGame().IsAlive(ptarget))
return; return;
} }
player.setGameMode(GameMode.SPECTATOR); player.setGameMode(GameMode.SPECTATOR);
player.setSpectatorTarget(target); player.setSpectatorTarget(target);
if(target instanceof Player)
UtilTextBottom.display(C.cYellow + "You are spectating " + F.game(((Player) target).getName()), player);
UtilPlayer.message(player, F.main("Game", "Sneak to stop spectating")); if (ptarget != null)
UtilTextBottom.display(C.cGray + "You are spectating " + F.elem(Manager.GetGame().GetTeam(ptarget).GetColor() + ptarget.getName()) + ".", player);
UtilPlayer.message(player, F.main("Game", "Sneak to stop spectating."));
} }
}, 3); }, 1);
} }
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)