diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java index 0aa8652cf..8f5879b6f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java @@ -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 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 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) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/GiveDonorData.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/GiveDonorData.java deleted file mode 100644 index 1aa07d0d5..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/GiveDonorData.java +++ /dev/null @@ -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++; - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java index 91a071484..379d048bc 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java @@ -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 { + private final int MAX_GIVE_ATTEMPTS = 10; + private DonationRepository _repository; private NautHashMap> _gemQueue = new NautHashMap>(); private NautHashMap> _coinQueue = new NautHashMap>(); private NautHashMap> _goldQueue = new NautHashMap>(); + + private Queue _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 _gemQueue.clear(); } + public void rewardCoinsUntilSuccess(Callback callback, String caller, String name, int accountId, int amount) + { + _coinAttemptQueue.add(new GiveDonorData(callback, name, caller, accountId, amount)); + } + public void RewardCoins(Callback 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 //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() + { + @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 callback, String caller, Player player, int amount) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/GiveDonorData.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/GiveDonorData.java new file mode 100644 index 000000000..eb8f382b8 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/GiveDonorData.java @@ -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 _callback; + private int _attempts; + + public GiveDonorData(Callback 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 callback, String playerName, String caller, int accountId, int giveAmount) + { + this(callback, playerName, caller, null, accountId, giveAmount); + } + + public UUID getUuid() + { + return _uuid; + } + + public Callback 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++; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardData.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardData.java index b23f91c85..8179dbb98 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardData.java @@ -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; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java index b5a69e120..6a8507a5e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java @@ -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()); } } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/TreasureShardReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/TreasureShardReward.java index a931d2311..2fcb04e18 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/TreasureShardReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/TreasureShardReward.java @@ -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() + 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; } } + diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java index a9eecb3f7..d7c4b5303 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java @@ -117,7 +117,8 @@ public class Treasure reward.giveReward(_rewardType, player, new Callback() { @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()); } }); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/BlockChangeAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/BlockChangeAnimation.java index 2d6e42d38..f319264e9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/BlockChangeAnimation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/BlockChangeAnimation.java @@ -77,7 +77,9 @@ public class BlockChangeAnimation extends Animation continue; _blockInfoList.add(new BlockInfo(b)); + byte data = b.getData(); b.setType(mat); + b.setData(data); } } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 4e574f3cf..1c803d15a 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -861,6 +861,9 @@ public class ArcadeManager extends MiniPlugin implements IRelation public void Clear(Player player) { + if (player.getGameMode() == GameMode.SPECTATOR) + player.setSpectatorTarget(null); + player.setGameMode(GameMode.SURVIVAL); player.setAllowFlight(false); player.setFlySpeed(0.1F); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/paintball/Paintball.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/paintball/Paintball.java index 5f4d7b2b4..0d51c64a0 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/paintball/Paintball.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/paintball/Paintball.java @@ -8,6 +8,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Effect; +import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; @@ -481,6 +482,10 @@ public class Paintball extends TeamGame } //Settings + if (player.getGameMode() == GameMode.SPECTATOR) + player.setSpectatorTarget(null); + + player.setGameMode(GameMode.SURVIVAL); player.setAllowFlight(false); player.setFlying(false); ((CraftPlayer)player).getHandle().spectating = false; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java index efa9c8342..6a6749d96 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java @@ -9,6 +9,7 @@ import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.EntityEffect; +import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; @@ -820,6 +821,10 @@ public class WitherGame extends TeamGame implements IBlockRestorer } // Settings + if (player.getGameMode() == GameMode.SPECTATOR) + player.setSpectatorTarget(null); + + player.setGameMode(GameMode.SURVIVAL); player.setAllowFlight(false); player.setFlying(false); ((CraftPlayer) player).getHandle().spectating = false; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameSpectatorManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameSpectatorManager.java index 0082fc1ce..4515bcf47 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameSpectatorManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameSpectatorManager.java @@ -2,6 +2,19 @@ package nautilus.game.arcade.managers; 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.F; 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.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 { ArcadeManager Manager; @@ -228,19 +224,25 @@ public class GameSpectatorManager implements Listener @Override 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; } + player.setGameMode(GameMode.SPECTATOR); 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)