From 3893617d584516f284fca24bc9dbfb48c01786c7 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Fri, 6 Nov 2015 21:15:37 -0500 Subject: [PATCH] Logitech Giveaway (still needs testing) --- Plugins/.idea/dataSources.xml | 3 +- Plugins/.idea/encodings.xml | 4 +- .../mineplex/core/bonuses/BonusManager.java | 5 +- .../mineplex/core/bonuses/gui/SpinGui.java | 10 +- .../src/mineplex/core/giveaway/Giveaway.java | 51 ++++++++ .../core/giveaway/GiveawayCooldown.java | 30 +++++ .../core/giveaway/GiveawayManager.java | 104 ++++++++++++++++ .../core/giveaway/GiveawayRepository.java | 116 ++++++++++++++++++ .../core/giveaway/GiveawayResponse.java | 52 ++++++++ .../core/giveaway/redis/GiveawayMessage.java | 39 ++++++ .../redis/GiveawayMessageHandler.java | 45 +++++++ .../src/mineplex/core/reward/Reward.java | 30 ++++- .../mineplex/core/reward/RewardManager.java | 46 ++++++- .../core/reward/rewards/GiveawayReward.java | 95 ++++++++++++++ .../src/mineplex/core/treasure/Treasure.java | 99 ++++++++------- .../core/treasure/TreasureManager.java | 5 +- .../Mineplex.Hub/src/mineplex/hub/Hub.java | 4 +- .../src/mineplex/hub/HubManager.java | 7 +- .../src/nautilus/game/arcade/Arcade.java | 6 +- .../nautilus/game/arcade/ArcadeManager.java | 23 +++- .../game/arcade/managers/GameLootManager.java | 106 ++++++++-------- 21 files changed, 767 insertions(+), 113 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/giveaway/Giveaway.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayCooldown.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayManager.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayRepository.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayResponse.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/giveaway/redis/GiveawayMessage.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/giveaway/redis/GiveawayMessageHandler.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GiveawayReward.java diff --git a/Plugins/.idea/dataSources.xml b/Plugins/.idea/dataSources.xml index 16b134887..8c71c7a5f 100644 --- a/Plugins/.idea/dataSources.xml +++ b/Plugins/.idea/dataSources.xml @@ -1,6 +1,6 @@ - + mysql true @@ -13,7 +13,6 @@ - \ No newline at end of file diff --git a/Plugins/.idea/encodings.xml b/Plugins/.idea/encodings.xml index d82104827..f75895965 100644 --- a/Plugins/.idea/encodings.xml +++ b/Plugins/.idea/encodings.xml @@ -1,4 +1,6 @@ - + + + \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java index c6188442c..92a3f2d13 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java @@ -32,6 +32,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.giveaway.GiveawayManager; import mineplex.core.hologram.Hologram; import mineplex.core.hologram.HologramManager; import mineplex.core.inventory.InventoryManager; @@ -165,7 +166,7 @@ public class BonusManager extends MiniClientPlugin implements I updateOffSet(); } - public BonusManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager, DonationManager donationManager, PollManager pollManager, NpcManager npcManager, HologramManager hologramManager, StatsManager statsManager, InventoryManager inventoryManager, PetManager petManager) + public BonusManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager, DonationManager donationManager, PollManager pollManager, NpcManager npcManager, HologramManager hologramManager, StatsManager statsManager, InventoryManager inventoryManager, PetManager petManager, GiveawayManager giveawayManager) { super("Bonus", plugin); _repository = new BonusRepository(plugin, this, donationManager); @@ -174,7 +175,7 @@ public class BonusManager extends MiniClientPlugin implements I _npcManager = npcManager; _hologramManager = hologramManager; - _rewardManager = new RewardManager(clientManager, statusManager, donationManager, inventoryManager, petManager, statsManager, + _rewardManager = new RewardManager(clientManager, statusManager, donationManager, inventoryManager, petManager, statsManager, giveawayManager, 100, 250, 500, 1000, 4000, 6000, diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/SpinGui.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/SpinGui.java index c111054bf..3f7d56312 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/SpinGui.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/SpinGui.java @@ -3,6 +3,7 @@ package mineplex.core.bonuses.gui; import java.util.ArrayList; import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.gui.DisplayItem; @@ -109,7 +110,14 @@ public class SpinGui extends SimpleGui } } - _rewardData = _reward.giveReward(RewardType.SpinnerReal, getPlayer()); + _reward.giveReward(RewardType.SpinnerReal, getPlayer(), new Callback() + { + @Override + public void run(RewardData data) + { + _rewardData = data; + } + }); } private void tick() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/Giveaway.java b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/Giveaway.java new file mode 100644 index 000000000..eb8817526 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/Giveaway.java @@ -0,0 +1,51 @@ +package mineplex.core.giveaway; + +public class Giveaway +{ + private int _id; + private String _name; + private String _header; + private String _message; + private boolean _notifyNetwork; + private int _notifyCooldown; + + public Giveaway(int id, String name, String header, String message, boolean notifyNetwork, int notifyCooldown) + { + _id = id; + _name = name; + _header = header; + _message = message; + _notifyNetwork = notifyNetwork; + _notifyCooldown = notifyCooldown; + } + + public int getId() + { + return _id; + } + + public String getName() + { + return _name; + } + + public String getMessage() + { + return _message; + } + + public String getHeader() + { + return _header; + } + + public boolean isNotifyNetwork() + { + return _notifyNetwork; + } + + public int getNotifyCooldown() + { + return _notifyCooldown; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayCooldown.java b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayCooldown.java new file mode 100644 index 000000000..896a777e6 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayCooldown.java @@ -0,0 +1,30 @@ +package mineplex.core.giveaway; + +public class GiveawayCooldown +{ + private int _id; + private String _name; + private int _cooldown; + + public GiveawayCooldown(int id, String name, int cooldown) + { + _id = id; + _name = name; + _cooldown = cooldown; + } + + public int getId() + { + return _id; + } + + public String getName() + { + return _name; + } + + public int getCooldown() + { + return _cooldown; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayManager.java b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayManager.java new file mode 100644 index 000000000..03e912133 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayManager.java @@ -0,0 +1,104 @@ +package mineplex.core.giveaway; + +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.Callback; +import mineplex.core.giveaway.redis.GiveawayMessage; +import mineplex.core.giveaway.redis.GiveawayMessageHandler; +import mineplex.serverdata.Region; +import mineplex.serverdata.commands.ServerCommandManager; + +public class GiveawayManager extends MiniPlugin +{ + private CoreClientManager _clientManager; + private GiveawayRepository _repository; + private HashMap _giveawayMap; + private HashMap _cooldownMap; + + public GiveawayManager(JavaPlugin plugin, CoreClientManager clientManager) + { + super("Giveaway Manager", plugin); + _clientManager = clientManager; + _repository = new GiveawayRepository(plugin); + _giveawayMap = _repository.loadGiveaways(); + _cooldownMap = _repository.loadCooldowns(); + + ServerCommandManager.getInstance().registerCommandType("GiveawayMessage", GiveawayMessage.class, new GiveawayMessageHandler()); + } + + public void attemptToGiveaway(final String giveawayName, final String cooldownName, Player player, final Callback callback) + { + final int accountId = _clientManager.getAccountId(player); + + if (accountId == -1) + { + callback.run(new GiveawayResponse(GiveawayResponse.FailReason.INVALID_ACCOUNT_ID)); + return; + } + + if (!hasGiveaway(giveawayName)) + { + callback.run(new GiveawayResponse(GiveawayResponse.FailReason.INVALID_GIVEAWAY)); + return; + } + + if (!hasCooldown(cooldownName)) + { + callback.run(new GiveawayResponse(GiveawayResponse.FailReason.INVALID_COOLDOWN)); + return; + } + + final Giveaway giveaway = _giveawayMap.get(giveawayName); + final GiveawayCooldown cooldown = _cooldownMap.get(cooldownName); + runAsync(new Runnable() + { + @Override + public void run() + { + final GiveawayResponse response; + + if (_repository.canGiveaway(accountId, giveawayName)) + { + UUID uuid = UUID.randomUUID(); + if (_repository.addGiveaway(accountId, giveaway.getId(), cooldown.getId(), Region.US, "", uuid)) + { + response = new GiveawayResponse(uuid); + } + else + { + response = new GiveawayResponse(GiveawayResponse.FailReason.QUERY_FAILED); + } + } + else + { + response = new GiveawayResponse(GiveawayResponse.FailReason.CANNOT_GIVEAWAY); + } + + runSync(new Runnable() + { + @Override + public void run() + { + if (callback != null) callback.run(response); + } + }); + } + }); + } + + public boolean hasGiveaway(String name) + { + return _giveawayMap.containsKey(name); + } + + public boolean hasCooldown(String name) + { + return _cooldownMap.containsKey(name); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayRepository.java new file mode 100644 index 000000000..6564882ab --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayRepository.java @@ -0,0 +1,116 @@ +package mineplex.core.giveaway; + +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; +import java.util.HashMap; +import java.util.UUID; + +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.database.DBPool; +import mineplex.core.database.RepositoryBase; +import mineplex.core.database.ResultSetCallable; +import mineplex.core.database.column.ColumnInt; +import mineplex.core.database.column.ColumnVarChar; +import mineplex.serverdata.Region; + +public class GiveawayRepository extends RepositoryBase +{ + private static final String INSERT_GIVEAWAY = "INSERT INTO Account.accountGiveaway (giveawayId, accountId, cooldownId, region, serverName, time, uuid) VALUES (?, ?, ?, ?, ?, now(), ?)"; + private static final String LOAD_GIVEAWAY = "SELECT id, name, header, message, max, notifyNetwork, notifyCooldown, canWinTwice FROM Account.giveaway WHERE enabled = TRUE"; + private static final String LOAD_COOLDOWN = "SELECT id, name, cooldown FROM Account.giveawayCooldown"; + + public GiveawayRepository(JavaPlugin plugin) + { + super(plugin, DBPool.ACCOUNT); + } + + public boolean canGiveaway(int accountId, String giveawayName) + { + try (Connection connection = getConnection(); + CallableStatement callableStatement = connection.prepareCall("{call check_giveaway(?, ?, ?)}")) + { + callableStatement.setInt(1, accountId); + callableStatement.setString(2, giveawayName); + callableStatement.registerOutParameter(3, Types.BOOLEAN); + callableStatement.executeUpdate(); + + boolean pass = callableStatement.getBoolean(3); + return pass; + } + catch (Exception e) + { + } + return false; + } + + public boolean addGiveaway(int accountId, int giveawayId, int cooldownId, Region region, String serverName, UUID uuid) + { + return 1 == executeUpdate(INSERT_GIVEAWAY, new ColumnInt("giveawayId", giveawayId), new ColumnInt("accountId", accountId), + new ColumnInt("cooldownId", cooldownId), new ColumnVarChar("region", 10, region.name()), new ColumnVarChar("serverName", 64, serverName), + new ColumnVarChar("uuid", 32, uuid.toString().replaceAll("-", ""))); + } + + public HashMap loadGiveaways() + { + final HashMap map = new HashMap(); + executeQuery(LOAD_GIVEAWAY, new ResultSetCallable() + { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + while (resultSet.next()) + { + int id = resultSet.getInt(1); + String name = resultSet.getString(2); + String header = resultSet.getString(3); + String message = resultSet.getString(4); + int max = resultSet.getInt(5); + boolean notifyNetwork = resultSet.getBoolean(6); + int notifyCooldown = resultSet.getInt(7); + boolean canWinTwice = resultSet.getBoolean(8); + + Giveaway giveaway = new Giveaway(id, name, header, message, notifyNetwork, notifyCooldown); + map.put(name, giveaway); + } + } + }); + return map; + } + + public HashMap loadCooldowns() + { + final HashMap map = new HashMap(); + executeQuery(LOAD_COOLDOWN, new ResultSetCallable() + { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + while (resultSet.next()) + { + int id = resultSet.getInt(1); + String name = resultSet.getString(2); + int cooldown = resultSet.getInt(3); + GiveawayCooldown cd = new GiveawayCooldown(id, name, cooldown); + map.put(name, cd); + } + } + }); + return map; + } + + @Override + protected void initialize() + { + + } + + @Override + protected void update() + { + + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayResponse.java b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayResponse.java new file mode 100644 index 000000000..872cf87a2 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/GiveawayResponse.java @@ -0,0 +1,52 @@ +package mineplex.core.giveaway; + +import java.util.UUID; + +public class GiveawayResponse +{ + private boolean _success; + private FailReason _failReason; + private UUID _giveawayId; + + /** + * Success Constructor + * @param giveawayId + */ + protected GiveawayResponse(UUID giveawayId) + { + _success = true; + _failReason = null; + _giveawayId = giveawayId; + } + + /** + * Faulure constructor + * @param failReason + */ + protected GiveawayResponse(FailReason failReason) + { + _success = false; + _failReason = failReason; + _giveawayId = null; + } + + public boolean isSuccess() + { + return _success; + } + + public UUID getGiveawayId() + { + return _giveawayId; + } + + public FailReason getFailReason() + { + return _failReason; + } + + public static enum FailReason + { + INVALID_GIVEAWAY, INVALID_COOLDOWN, CANNOT_GIVEAWAY, INVALID_ACCOUNT_ID, QUERY_FAILED; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/redis/GiveawayMessage.java b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/redis/GiveawayMessage.java new file mode 100644 index 000000000..619cd7a33 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/redis/GiveawayMessage.java @@ -0,0 +1,39 @@ +package mineplex.core.giveaway.redis; + +import mineplex.serverdata.commands.ServerCommand; + +public class GiveawayMessage extends ServerCommand +{ + private String _giveawayName; + private String _playerName; + private String _giveawayHeader; + private String _giveawayMessage; + + public GiveawayMessage(String giveawayName, String playerName, String giveawayMessage, String giveawayHeader) + { + _giveawayName = giveawayName; + _playerName = playerName; + _giveawayMessage = giveawayMessage; + _giveawayHeader = giveawayHeader; + } + + public String getPlayerName() + { + return _playerName; + } + + public String getGiveawayMessage() + { + return _giveawayMessage; + } + + public String getGiveawayHeader() + { + return _giveawayHeader; + } + + public String getGiveawayName() + { + return _giveawayName; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/giveaway/redis/GiveawayMessageHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/redis/GiveawayMessageHandler.java new file mode 100644 index 000000000..d01e14858 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/giveaway/redis/GiveawayMessageHandler.java @@ -0,0 +1,45 @@ +package mineplex.core.giveaway.redis; + +import java.util.HashMap; + +import org.bukkit.ChatColor; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.serverdata.commands.CommandCallback; +import mineplex.serverdata.commands.ServerCommand; + +public class GiveawayMessageHandler implements CommandCallback +{ + private HashMap _cooldownMap; + + public GiveawayMessageHandler() + { + _cooldownMap = new HashMap(); + } + + @Override + public void run(ServerCommand command) + { + if (command instanceof GiveawayMessage) + { + GiveawayMessage message = ((GiveawayMessage) command); + + // %p - player name + String headerText = message.getGiveawayHeader(); + String chatMessage = message.getGiveawayMessage().replaceAll("%p", message.getPlayerName()); + + // Chat Colors + headerText = ChatColor.translateAlternateColorCodes('&', headerText); + chatMessage = ChatColor.translateAlternateColorCodes('&', chatMessage); + + UtilTextMiddle.display(headerText, chatMessage, 20, 80, 20); + for (Player player : UtilServer.getPlayers()) + { + player.playSound(player.getEyeLocation(), Sound.AMBIENCE_CAVE, 1, 1); + } + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/Reward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/Reward.java index d15bce608..8e5ab89e1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/Reward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/Reward.java @@ -4,6 +4,8 @@ import java.util.Random; import org.bukkit.entity.Player; +import mineplex.core.common.util.Callback; + /** * Created by Shaun on 9/2/2014. */ @@ -13,16 +15,31 @@ public abstract class Reward private RewardRarity _rarity; private int _weight; + private boolean _requiresCallback; public Reward(RewardRarity rarity, int weight) { - _rarity = rarity; - _weight = weight; + this(rarity, weight, false); } - public final RewardData giveReward(RewardType rewardType, Player player) + public Reward(RewardRarity rarity, int weight, boolean requiresCallback) { - return giveRewardCustom(player, rewardType); + _rarity = rarity; + _weight = weight; + _requiresCallback = requiresCallback; + } + + public final void giveReward(RewardType rewardType, Player player, Callback rewardDataCallback) + { + if (_requiresCallback) + giveRewardCallback(rewardType, player, rewardDataCallback); + else + rewardDataCallback.run(giveRewardCustom(player, rewardType)); + } + + protected void giveRewardCallback(RewardType rewardType, Player player, Callback rewardDataCallback) + { + // do nothing } protected abstract RewardData giveRewardCustom(Player player, RewardType rewardType); @@ -40,4 +57,9 @@ public abstract class Reward { return _weight; } + + public boolean isRequiresCallback() + { + return _requiresCallback; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java index 5b89aa562..591788557 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardManager.java @@ -14,12 +14,15 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.common.Rank; +import mineplex.core.common.util.C; import mineplex.core.donation.DonationManager; +import mineplex.core.giveaway.GiveawayManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.pet.PetManager; import mineplex.core.reward.rewards.CoinReward; import mineplex.core.reward.rewards.ExperienceReward; import mineplex.core.reward.rewards.GemReward; +import mineplex.core.reward.rewards.GiveawayReward; import mineplex.core.reward.rewards.InventoryReward; import mineplex.core.reward.rewards.PetReward; import mineplex.core.reward.rewards.RankReward; @@ -36,11 +39,13 @@ public class RewardManager private boolean _carlSpinner; private CoreClientManager _clientManager; + private DonationManager _donationManager; private ServerStatusManager _statusManager; + private GiveawayManager _giveawayManager; private boolean _doubleGadgetValue; - public RewardManager(CoreClientManager clientManager, ServerStatusManager statusManager, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, StatsManager statsManager, + public RewardManager(CoreClientManager clientManager, ServerStatusManager statusManager, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, StatsManager statsManager, GiveawayManager giveawayManager, int commonValueMin, int commonValueMax, int uncommonValueMin, int uncommonValueMax, int rareValueMin, int rareValueMax, @@ -58,6 +63,8 @@ public class RewardManager _clientManager = clientManager; _statusManager = statusManager; + _donationManager = donationManager; + _giveawayManager = giveawayManager; _doubleGadgetValue = doubleGadgetValue; _carlSpinner = carlSpinner; @@ -393,6 +400,10 @@ public class RewardManager //Dont give Rank Upgrade if already has Titan if (rarity == RewardRarity.MYTHICAL) { + if (canGiveMythical && type == RewardType.MythicalChest/* && Math.random() <= 0.1*/) + { + return getLogitechPrize(); + } if (canGiveMythical && type == RewardType.MythicalChest && !_clientManager.Get(player).GetRank().has(Rank.TITAN)) { return new RankReward(_clientManager, _statusManager, 0, rarity); @@ -462,4 +473,37 @@ public class RewardManager return null; } + + private Reward getLogitechPrize() + { + double rand = Math.random(); + + String name; + String cooldown = "logitech"; + Material mat = Material.DIAMOND; + String displayName; + + if (rand < 0.2) + { + name = "logitechKeyboard"; + displayName = C.cRed + "Logitech G910 RGB Keyboard"; + } + else if (rand < 0.4) + { + name = "logitechMouse"; + displayName = C.cRed + "Logitech G303 Gaming Mouse"; + } + else if (rand < 0.6) + { + name = "logitechHeadset"; + displayName = C.cRed + "Logitech G430 Gaming Headset"; + } + else + { + name = "logitechMousePad"; + displayName = C.cRed + "Logitech G240 Gaming Mousepad"; + } + + return new GiveawayReward(_giveawayManager, _clientManager, _donationManager, _statusManager, name, cooldown, displayName , mat, (byte) 0, RewardRarity.MYTHICAL, 0); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GiveawayReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GiveawayReward.java new file mode 100644 index 000000000..ef5b439fe --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/GiveawayReward.java @@ -0,0 +1,95 @@ +package mineplex.core.reward.rewards; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.Rank; +import mineplex.core.common.util.Callback; +import mineplex.core.donation.DonationManager; +import mineplex.core.giveaway.GiveawayManager; +import mineplex.core.giveaway.GiveawayResponse; +import mineplex.core.reward.Reward; +import mineplex.core.reward.RewardData; +import mineplex.core.reward.RewardRarity; +import mineplex.core.reward.RewardType; +import mineplex.core.status.ServerStatusManager; + +public class GiveawayReward extends Reward +{ + private GiveawayManager _giveawayManager; + private CoreClientManager _clientManager; + private DonationManager _donationManager; + private ServerStatusManager _serverStatusManager; + private String _giveawayName; + private String _cooldownName; + private String _displayName; + private Material _icon; + private byte _data; + + public GiveawayReward(GiveawayManager giveawayManager, CoreClientManager clientManager, DonationManager donationManager, ServerStatusManager serverStatusManager, String giveawayName, String cooldownName, String displayName, Material icon, byte data, RewardRarity rarity, int weight) + { + super(rarity, weight, true); + _giveawayManager = giveawayManager; + _clientManager = clientManager; + _donationManager = donationManager; + _serverStatusManager = serverStatusManager; + _giveawayName = giveawayName; + _cooldownName = cooldownName; + _displayName = displayName; + _icon = icon; + _data = data; + } + + @Override + protected void giveRewardCallback(final RewardType rewardType, final Player player, final Callback rewardDataCallback) + { + _giveawayManager.attemptToGiveaway(_giveawayName, _cooldownName, player, new Callback() + { + @Override + public void run(GiveawayResponse data) + { + if (data.isSuccess()) + { + RewardData rewardData = new RewardData(_displayName, new ItemStack(_icon, 1, (short) 0, _data), getRarity()); + if (rewardDataCallback != null) rewardDataCallback.run(rewardData); + } + else + { + // Dang, I guess we failed! + if (!_clientManager.hasRank(player, Rank.TITAN)) + { + Reward reward = new RankReward(_clientManager, _serverStatusManager, 0, getRarity()); + reward.giveReward(rewardType, player, rewardDataCallback); + } + else + { + Reward reward = new CoinReward(_donationManager, 20000, 30000, 0, getRarity()); + reward.giveReward(rewardType, player, rewardDataCallback); + } + } + } + }); + } + + @Override + protected RewardData giveRewardCustom(Player player, RewardType rewardType) + { + // This is a little hacky, this should never be called! + return null; + } + + @Override + public RewardData getFakeRewardData(Player player) + { + // Let's pretend we are coins! + return new RewardData(getRarity().getColor() + "Coins", new ItemStack(175), getRarity()); + } + + @Override + public boolean canGiveReward(Player player) + { + return true; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java index 86806edb7..1e7f103ed 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java @@ -17,6 +17,7 @@ import org.bukkit.entity.Player; import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilServer; @@ -193,53 +194,60 @@ public class Treasure openChest(block, true); } - public void openChest(Block block, boolean swapList) + public void openChest(final Block block, final boolean swapList) { - ChestData data = getChestData(block); + // This is very experimental! Pray to god that this works + final ChestData data = getChestData(block); if (data != null && !data.isOpened() && _currentReward < _rewards.length) { - Reward reward = _rewards[_currentReward]; - RewardData rewardData = reward.giveReward(_rewardType, _player); - _currentReward++; - - if (swapList) - { - BlockInfo info = getBlockInfo(block); - _chestBlockInfo.remove(info); - _openedChestBlockInfo.add(info); - } - + final Reward reward = _rewards[_currentReward]; data.setOpened(true); - ChestOpenAnimation chestOpenTask = new ChestOpenAnimation(this, data, rewardData, _hologramManager); - _animations.add(chestOpenTask); + reward.giveReward(_rewardType, _player, new Callback() + { + @Override + public void run(RewardData rewardData) + { + _currentReward++; - // Extra effects based off the rarity of the treasure - if (reward.getRarity() == RewardRarity.UNCOMMON) - { - _animations.add(new LootUncommonAnimation(this, data.getBlock())); - } - else if (reward.getRarity() == RewardRarity.RARE) - { - _animations.add(new LootRareAnimation(this, data.getBlock().getLocation().add(0.5, 1.5, 0.5))); - Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " found " + C.cPurple + "Rare " + rewardData.getFriendlyName())); - } - else if (reward.getRarity() == RewardRarity.LEGENDARY) - { - _animations.add(new LootLegendaryAnimation(this, data.getBlock())); - Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " found " + C.cGreen + "Legendary " + rewardData.getFriendlyName())); - } - else if (reward.getRarity() == RewardRarity.MYTHICAL) - { - _animations.add(new LootMythicalAnimation(this, data.getBlock())); - Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " found " + C.cRed + "Mythical " + rewardData.getFriendlyName())); - } + if (swapList) + { + BlockInfo info = getBlockInfo(block); + _chestBlockInfo.remove(info); + _openedChestBlockInfo.add(info); + } - if (isFinished()) - { - TreasureRemoveAnimation animation = new TreasureRemoveAnimation(this, _openedChestBlockInfo, _chestBlockInfo); - _animations.add(animation); - _finished = true; - } + ChestOpenAnimation chestOpenTask = new ChestOpenAnimation(Treasure.this, data, rewardData, _hologramManager); + _animations.add(chestOpenTask); + + // Extra effects based off the rarity of the treasure + if (reward.getRarity() == RewardRarity.UNCOMMON) + { + _animations.add(new LootUncommonAnimation(Treasure.this, data.getBlock())); + } + else if (reward.getRarity() == RewardRarity.RARE) + { + _animations.add(new LootRareAnimation(Treasure.this, data.getBlock().getLocation().add(0.5, 1.5, 0.5))); + Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " found " + C.cPurple + "Rare " + rewardData.getFriendlyName())); + } + else if (reward.getRarity() == RewardRarity.LEGENDARY) + { + _animations.add(new LootLegendaryAnimation(Treasure.this, data.getBlock())); + Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " found " + C.cGreen + "Legendary " + rewardData.getFriendlyName())); + } + else if (reward.getRarity() == RewardRarity.MYTHICAL) + { + _animations.add(new LootMythicalAnimation(Treasure.this, data.getBlock())); + Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " found " + C.cRed + "Mythical " + rewardData.getFriendlyName())); + } + + if (isFinished()) + { + TreasureRemoveAnimation animation = new TreasureRemoveAnimation(Treasure.this, _openedChestBlockInfo, _chestBlockInfo); + _animations.add(animation); + _finished = true; + } + } + }); } } @@ -299,7 +307,14 @@ public class Treasure for (int i = _currentReward; i < _rewards.length; i++) { - _rewards[_currentReward].giveReward(_rewardType, _player); + _rewards[_currentReward].giveReward(_rewardType, _player, new Callback() + { + @Override + public void run(RewardData data) + { + // Do nothing + } + }); } _currentReward = _rewards.length; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java index 92ced2a3d..c5e6aacac 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java @@ -14,6 +14,7 @@ import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.donation.DonationManager; +import mineplex.core.giveaway.GiveawayManager; import mineplex.core.hologram.HologramManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.pet.PetManager; @@ -35,7 +36,7 @@ public class TreasureManager extends MiniPlugin private StatsManager _statsManager; private List _treasureLocations; - public TreasureManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, BlockRestore blockRestore, HologramManager hologramManager, StatsManager statsManager) + public TreasureManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, BlockRestore blockRestore, HologramManager hologramManager, StatsManager statsManager, GiveawayManager giveawayManager) { super("Treasure", plugin); @@ -43,7 +44,7 @@ public class TreasureManager extends MiniPlugin _blockRestore = blockRestore; _hologramManager = hologramManager; _statsManager = statsManager; - _rewardManager = new RewardManager(clientManager, statusManager, donationManager, _inventoryManager, petManager, statsManager, + _rewardManager = new RewardManager(clientManager, statusManager, donationManager, _inventoryManager, petManager, statsManager, giveawayManager, 100, 250, 500, 1000, 4000, 6000, diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 979745883..9a2f3e30d 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -19,6 +19,7 @@ import mineplex.core.elo.EloManager; import mineplex.core.energy.Energy; import mineplex.core.friend.FriendManager; import mineplex.core.give.Give; +import mineplex.core.giveaway.GiveawayManager; import mineplex.core.globalpacket.GlobalPacketManager; import mineplex.core.hologram.HologramManager; import mineplex.core.ignore.IgnoreManager; @@ -111,6 +112,7 @@ public class Hub extends JavaPlugin implements IRelation //Main Modules ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager)); + GiveawayManager giveawayManager = new GiveawayManager(this, clientManager); new TitanGiveawayManager(this, clientManager, serverStatusManager); Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName()); @@ -127,7 +129,7 @@ public class Hub extends JavaPlugin implements IRelation PartyManager partyManager = new PartyManager(this, portal, clientManager, preferenceManager); PersonalServerManager personalServerManager = new PersonalServerManager(this, clientManager); - HubManager hubManager = new HubManager(this, blockRestore, clientManager, donationManager, inventoryManager, new ConditionManager(this), disguiseManager, new TaskManager(this, clientManager, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this), npcManager, personalServerManager, packetHandler, punish, serverStatusManager); + HubManager hubManager = new HubManager(this, blockRestore, clientManager, donationManager, inventoryManager, new ConditionManager(this), disguiseManager, new TaskManager(this, clientManager, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this), npcManager, personalServerManager, packetHandler, punish, serverStatusManager, giveawayManager); QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this, clientManager), partyManager); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 4f76875d2..a9fb8b9e2 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -30,6 +30,7 @@ import mineplex.core.donation.DonationManager; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.event.GadgetActivateEvent; import mineplex.core.gadget.event.GadgetCollideEntityEvent; +import mineplex.core.giveaway.GiveawayManager; import mineplex.core.hologram.HologramManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.message.PrivateMessageEvent; @@ -163,7 +164,7 @@ public class HubManager extends MiniClientPlugin //Admin private boolean _gadgetsEnabled = true; - public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, NpcManager npcManager, PersonalServerManager personalServerManager, PacketHandler packetHandler, Punish punish, ServerStatusManager serverStatusManager) + public HubManager(JavaPlugin plugin, BlockRestore blockRestore, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, ConditionManager conditionManager, DisguiseManager disguiseManager, TaskManager taskManager, Portal portal, PartyManager partyManager, PreferencesManager preferences, PetManager petManager, PollManager pollManager, StatsManager statsManager, AchievementManager achievementManager, HologramManager hologramManager, NpcManager npcManager, PersonalServerManager personalServerManager, PacketHandler packetHandler, Punish punish, ServerStatusManager serverStatusManager, GiveawayManager giveawayManager) { super("Hub Manager", plugin); @@ -196,7 +197,7 @@ public class HubManager extends MiniClientPlugin new BenefitManager(plugin, clientManager, _inventoryManager); _gadgetManager = new GadgetManager(_plugin, clientManager, donationManager, _inventoryManager, _mountManager, petManager, preferences, disguiseManager, blockRestore, new ProjectileManager(plugin), achievementManager); - _treasureManager = new TreasureManager(_plugin, clientManager, serverStatusManager, donationManager, _inventoryManager, petManager, _blockRestore, hologramManager, statsManager); + _treasureManager = new TreasureManager(_plugin, clientManager, serverStatusManager, donationManager, _inventoryManager, petManager, _blockRestore, hologramManager, statsManager, giveawayManager); new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, _mountManager, petManager, _treasureManager); new SoccerManager(this, _gadgetManager); @@ -224,7 +225,7 @@ public class HubManager extends MiniClientPlugin ((CraftWorld)Bukkit.getWorlds().get(0)).getHandle().pvpMode = true; - new BonusManager(plugin, clientManager, serverStatusManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager); + new BonusManager(plugin, clientManager, serverStatusManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager, giveawayManager); // _halloweenManager = new HalloweenSpookinessManager(this); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 08a7f2bec..875ee38e3 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -6,6 +6,8 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.FoodDupeFix; +import mineplex.core.account.CoreClient; +import mineplex.core.giveaway.GiveawayManager; import mineplex.core.globalpacket.GlobalPacketManager; import net.minecraft.server.v1_7_R4.BiomeBase; @@ -145,10 +147,12 @@ public class Arcade extends JavaPlugin cosmeticManager.disableTeamArmor(); new GlobalPacketManager(this, _clientManager, serverStatusManager); + + GiveawayManager giveawayManager = new GiveawayManager(this, _clientManager); //Arcade Manager PollManager pollManager = new PollManager(this, _clientManager, _donationManager); - _gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, statsManager, achievementManager, disguiseManager, creature, teleport, new Blood(this), chat, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, hologramManager, webServerAddress, pollManager, npcmanager); + _gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, statsManager, achievementManager, disguiseManager, creature, teleport, new Blood(this), chat, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, hologramManager, webServerAddress, pollManager, npcmanager, giveawayManager); new MemoryFix(this); new CustomTagFix(this, packetHandler); 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 61e1dca19..445b017d2 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -17,6 +17,7 @@ import mineplex.core.common.Rank; import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAction; @@ -33,6 +34,7 @@ import mineplex.core.elo.EloManager; import mineplex.core.energy.Energy; import mineplex.core.explosion.Explosion; import mineplex.core.explosion.ExplosionEvent; +import mineplex.core.giveaway.GiveawayManager; import mineplex.core.hologram.HologramManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.itemstack.ItemStackFactory; @@ -53,6 +55,7 @@ import mineplex.core.projectile.ProjectileManager; import mineplex.core.resourcepack.ResPackManager; import mineplex.core.resourcepack.ResUnloadCheck; import mineplex.core.resourcepack.redis.RedisUnloadResPack; +import mineplex.core.reward.RewardData; import mineplex.core.reward.RewardRarity; import mineplex.core.reward.rewards.PetReward; import mineplex.core.stats.StatsManager; @@ -189,6 +192,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation private StatsManager _statsManager; private PartyManager _partyManager; private PreferencesManager _preferencesManager; + private GiveawayManager _giveawayManager; private TaskManager _taskManager; private PacketHandler _packetHandler; @@ -219,7 +223,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager, StatsManager statsManager, AchievementManager achievementManager, DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood, Chat chat, Portal portal, PreferencesManager preferences, InventoryManager inventoryManager, PacketHandler packetHandler, - CosmeticManager cosmeticManager, ProjectileManager projectileManager, PetManager petManager, HologramManager hologramManager, String webAddress, PollManager pollManager, NpcManager npcManager) + CosmeticManager cosmeticManager, ProjectileManager projectileManager, PetManager petManager, HologramManager hologramManager, String webAddress, PollManager pollManager, NpcManager npcManager, GiveawayManager giveawayManager) { super("Game Manager", plugin); @@ -272,6 +276,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation _portal = portal; _petManager = petManager; _eventManager = new EventModule(this, getPlugin()); + _giveawayManager = giveawayManager; // Shop _arcadeShop = new ArcadeShop(this, clientManager, donationManager); @@ -304,7 +309,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation new NotificationManager(getPlugin(), clientManager); - new BonusManager(plugin, clientManager, serverStatusManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager); + new BonusManager(plugin, clientManager, serverStatusManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager, giveawayManager); //Champions Modules _energy = new Energy(plugin); @@ -518,6 +523,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation return _explosionManager; } + public GiveawayManager getGiveawayManager() + { + return _giveawayManager; + } + public Fire GetFire() { return _fire; @@ -1328,7 +1338,14 @@ public class ArcadeManager extends MiniPlugin implements IRelation PetReward reward = new PetReward(_petManager, _inventoryManager, _donationManager, pet, pet, type, RewardRarity.OTHER, 0); if (reward.canGiveReward(player)) - reward.giveReward(null, player); + reward.giveReward(null, player, new Callback() + { + @Override + public void run(RewardData data) + { + + } + }); } public void toggleChampionsModules(GameType gameType) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLootManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLootManager.java index b630bbe6a..ba57f7f18 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLootManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameLootManager.java @@ -18,11 +18,13 @@ import org.bukkit.inventory.ItemStack; import mineplex.core.common.Rank; import mineplex.core.common.util.C; +import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilFirework; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.giveaway.GiveawayManager; import mineplex.core.pet.PetManager; import mineplex.core.reward.Reward; import mineplex.core.reward.RewardData; @@ -50,7 +52,7 @@ public class GameLootManager implements Listener Manager.getPluginManager().registerEvents(this, Manager.getPlugin()); - _rewardManager = new RewardManager(Manager.GetClients(), Manager.GetServerStatusManager(), Manager.GetDonation(), Manager.getInventoryManager(), petManager, Manager.GetStatsManager(), + _rewardManager = new RewardManager(Manager.GetClients(), Manager.GetServerStatusManager(), Manager.GetDonation(), Manager.getInventoryManager(), petManager, Manager.GetStatsManager(), Manager.getGiveawayManager(), 100, 250, 500, 1000, 1500, 2500, @@ -133,7 +135,7 @@ public class GameLootManager implements Listener //Delay after Achievements } - public boolean giveReward(Player player, boolean force) + public boolean giveReward(final Player player, boolean force) { if (!force) { @@ -162,56 +164,60 @@ public class GameLootManager implements Listener return false; } - Reward reward = _rewardManager.nextReward(player, null, false, RewardType.GameLoot, true); - - RewardData rewardData = reward.giveReward(RewardType.GameLoot, player); - - String outputName = reward.getRarity().getColor() + rewardData.getFriendlyName(); - - String rarityName = ""; - if (reward.getRarity() != RewardRarity.COMMON) - rarityName = " " + reward.getRarity().getColor() + reward.getRarity().getName(); - - //Log - System.out.println(F.name(player.getName()) + " found" + rarityName + " " + outputName); - - //Self Display - UtilTextMiddle.display(C.cGreen + "Game Loot", "You found " + outputName, 20, 120, 20, player); - //if (reward.getRarity() == RewardRarity.COMMON) - // UtilPlayer.message(player, F.main("Loot", "You found " + rarityName + outputName)); - - Random _random = new Random(); - - //Announce - //if (reward.getRarity() != RewardRarity.COMMON) + final Reward reward = _rewardManager.nextReward(player, null, false, RewardType.GameLoot, true); + reward.giveReward(RewardType.GameLoot, player, new Callback() { - Bukkit.broadcastMessage(F.main("Loot", F.name(player.getName()) + " found" + rarityName + " " + outputName)); - } - - //Effect - if (reward.getRarity() == RewardRarity.UNCOMMON) - { - FireworkEffect effect = FireworkEffect.builder().withColor(Color.fromRGB(_random.nextInt(255), _random.nextInt(255), _random.nextInt(255))) - .withFade(Color.fromRGB(_random.nextInt(255), _random.nextInt(255), _random.nextInt(255))) - .with(FireworkEffect.Type.STAR) - .build(); + @Override + public void run(RewardData rewardData) + { + String outputName = reward.getRarity().getColor() + rewardData.getFriendlyName(); - UtilFirework.playFirework(player.getEyeLocation(), effect); - } - else if (reward.getRarity() == RewardRarity.RARE) - { - FireworkEffect effect = FireworkEffect.builder().with(FireworkEffect.Type.BALL).withColor(Color.YELLOW).withFade(Color.WHITE).build(); - UtilFirework.playFirework(player.getEyeLocation(), effect); - - player.getWorld().playSound(player.getEyeLocation().add(0.5, 0.5, 0.5), Sound.WITHER_SPAWN, 5F, 1.2F); - } - else if (reward.getRarity() == RewardRarity.LEGENDARY) - { - FireworkEffect effect = FireworkEffect.builder().with(FireworkEffect.Type.BALL_LARGE).withColor(Color.RED).withFade(Color.BLACK).build(); - UtilFirework.playFirework(player.getEyeLocation(), effect); - - player.getWorld().playSound(player.getEyeLocation().add(0.5, 0.5, 0.5), Sound.ENDERDRAGON_DEATH, 10F, 2.0F); - } + String rarityName = ""; + if (reward.getRarity() != RewardRarity.COMMON) + rarityName = " " + reward.getRarity().getColor() + reward.getRarity().getName(); + + //Log + System.out.println(F.name(player.getName()) + " found" + rarityName + " " + outputName); + + //Self Display + UtilTextMiddle.display(C.cGreen + "Game Loot", "You found " + outputName, 20, 120, 20, player); + //if (reward.getRarity() == RewardRarity.COMMON) + // UtilPlayer.message(player, F.main("Loot", "You found " + rarityName + outputName)); + + Random _random = new Random(); + + //Announce + //if (reward.getRarity() != RewardRarity.COMMON) + { + Bukkit.broadcastMessage(F.main("Loot", F.name(player.getName()) + " found" + rarityName + " " + outputName)); + } + + //Effect + if (reward.getRarity() == RewardRarity.UNCOMMON) + { + FireworkEffect effect = FireworkEffect.builder().withColor(Color.fromRGB(_random.nextInt(255), _random.nextInt(255), _random.nextInt(255))) + .withFade(Color.fromRGB(_random.nextInt(255), _random.nextInt(255), _random.nextInt(255))) + .with(FireworkEffect.Type.STAR) + .build(); + + UtilFirework.playFirework(player.getEyeLocation(), effect); + } + else if (reward.getRarity() == RewardRarity.RARE) + { + FireworkEffect effect = FireworkEffect.builder().with(FireworkEffect.Type.BALL).withColor(Color.YELLOW).withFade(Color.WHITE).build(); + UtilFirework.playFirework(player.getEyeLocation(), effect); + + player.getWorld().playSound(player.getEyeLocation().add(0.5, 0.5, 0.5), Sound.WITHER_SPAWN, 5F, 1.2F); + } + else if (reward.getRarity() == RewardRarity.LEGENDARY) + { + FireworkEffect effect = FireworkEffect.builder().with(FireworkEffect.Type.BALL_LARGE).withColor(Color.RED).withFade(Color.BLACK).build(); + UtilFirework.playFirework(player.getEyeLocation(), effect); + + player.getWorld().playSound(player.getEyeLocation().add(0.5, 0.5, 0.5), Sound.ENDERDRAGON_DEATH, 10F, 2.0F); + } + } + }); return true; }