From a8dda4ef8b2a61cf66d8f8248d9a70dadbfd7e52 Mon Sep 17 00:00:00 2001 From: Chiss Date: Wed, 4 Jun 2014 13:02:16 +1000 Subject: [PATCH] Hub Gem Queueing --- .../core/donation/DonationManager.java | 76 +++++++++++++++++-- .../mineplex/core/message/MessageManager.java | 10 --- .../mineplex/hub/gadget/types/ItemGadget.java | 10 +-- .../mineplex/hub/modules/StackerManager.java | 10 --- 4 files changed, 75 insertions(+), 31 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java index 0baf4c546..3af28f13f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java @@ -9,6 +9,8 @@ import mineplex.core.common.util.NautHashMap; import mineplex.core.donation.repository.DonationRepository; import mineplex.core.donation.repository.token.DonorTokenWrapper; import mineplex.core.server.util.TransactionResponse; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import org.bukkit.craftbukkit.libs.com.google.gson.Gson; import org.bukkit.event.EventHandler; @@ -22,6 +24,8 @@ public class DonationManager extends MiniPlugin private Object _donorLock = new Object(); + private NautHashMap> _gemQueue = new NautHashMap>(); + public DonationManager(JavaPlugin plugin, String webAddress) { super("Donation", plugin); @@ -126,8 +130,13 @@ public class DonationManager extends MiniPlugin } }, name, salesPackageId); } + + public void RewardGems(final Callback callback, final String caller, final String name, final int amount) + { + RewardGems(callback, caller, name, amount, true); + } - public void RewardGems(final Callback callback, final String caller, final String name, final int greenGems) + public void RewardGems(final Callback callback, final String caller, final String name, final int amount, final boolean updateTotal) { _repository.PlayerUpdate(new Callback() { @@ -135,17 +144,72 @@ public class DonationManager extends MiniPlugin { if (success) { - Donor donor = Get(name); - - if (donor != null) + if (updateTotal) { - donor.AddGems(greenGems); + Donor donor = Get(name); + + if (donor != null) + { + donor.AddGems(amount); + } } if (callback != null) callback.run(true); } } - }, caller, name, greenGems); + }, caller, name, amount); + } + + public void RewardGemsLater(final String caller, final String name, final int amount) + { + if (!_gemQueue.containsKey(name)) + _gemQueue.put(name, new NautHashMap()); + + int totalAmount = amount; + + if (_gemQueue.get(name).containsKey(caller)) + totalAmount += _gemQueue.get(name).get(caller); + + _gemQueue.get(name).put(caller, totalAmount); + + //Do Temp Change + Donor donor = Get(name); + + if (donor != null) + donor.AddGems(amount); + } + + @EventHandler + public void UpdateGemQueue(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOWER) + return; + + for (String name : _gemQueue.keySet()) + { + String caller = null; + int total = 0; + + for (String curCaller : _gemQueue.get(name).keySet()) + { + caller = curCaller; + total += _gemQueue.get(name).get(curCaller); + } + + if (caller == null) + continue; + + //Actually Add Gems + RewardGems(null, caller, name, total, false); + + System.out.println("Queue Added [" + name + "] with Gems [" + total + "] for [" + caller + "]"); + + //Clean + _gemQueue.get(name).clear(); + } + + //Clean + _gemQueue.clear(); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java b/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java index ff53acf4e..269962a36 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java @@ -143,16 +143,6 @@ public class MessageManager extends MiniClientPlugin UtilPlayer.message(from, C.cPurple + "defek7 is often AFK or minimized, due to plugin development."); UtilPlayer.message(from, C.cPurple + "Please be patient if he does not reply instantly."); } - - //Youtuber - if (_clientManager.Get(to).GetRank() == Rank.YOUTUBE) - { - if (!_clientManager.Get(from).GetRank().Has(from, Rank.MODERATOR, true)) - { - UtilPlayer.message(from, C.cPurple + "YouTubers cannot be private messaged."); - return; - } - } //Log //Logger().logChat("Private Message", from, to.getName(), message); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/gadget/types/ItemGadget.java b/Plugins/Mineplex.Hub/src/mineplex/hub/gadget/types/ItemGadget.java index dfe7a9121..18b8625b2 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/gadget/types/ItemGadget.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/gadget/types/ItemGadget.java @@ -59,7 +59,7 @@ public abstract class ItemGadget extends Gadget @EventHandler public void orderThatChest(final PlayerDropItemEvent event) - { + { if (event.getItemDrop().getItemStack().getType() == GetDisplayMaterial()) { Bukkit.getScheduler().scheduleSyncDelayedTask(Manager.GetPlugin(), new Runnable() @@ -106,9 +106,9 @@ public abstract class ItemGadget extends Gadget Player player = event.getPlayer(); if (!IsActive(player)) - return; + return; - event.setCancelled(true); + event.setCancelled(true); //Parkour Deny if (!_nearParkour && Manager.Manager.GetParkour().InParkour(player)) @@ -116,7 +116,7 @@ public abstract class ItemGadget extends Gadget UtilPlayer.message(player, F.main("Parkour", "You cannot use " + this.GetName() + " near Parkour Challenges.")); return; } - + //Recharge if (!Recharge.Instance.use(player, GetName(), _recharge, true, false)) return; @@ -126,7 +126,7 @@ public abstract class ItemGadget extends Gadget { if (Manager.Manager.GetDonation().Get(player.getName()).GetGems() > _gemsPerUse) { - Manager.Manager.GetDonation().RewardGems(null, this.GetName(), player.getName(), -_gemsPerUse); + Manager.Manager.GetDonation().RewardGemsLater(GetName(), player.getName(), -_gemsPerUse); } else { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/StackerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/StackerManager.java index d1d9be26d..03b6263f1 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/StackerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/StackerManager.java @@ -112,16 +112,6 @@ public class StackerManager extends MiniPlugin implements IThrown return; } - //YouTuber - if (stackee instanceof Player && Manager.GetClients().Get((Player)stackee).GetRank() == Rank.YOUTUBE) - { - if (!Manager.GetClients().Get(stacker).GetRank().Has(Rank.YOUTUBE)) - { - UtilPlayer.message(stacker, F.main("Stacker", F.name(UtilEnt.getName(stackee)) + " cannot be stacked! Leave him/her alone!")); - return; - } - } - if (stackee instanceof LivingEntity) { if (((LivingEntity)stackee).isCustomNameVisible())