diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java index a8dcbfa34..0aa8652cf 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.facebook.FacebookManager; import mineplex.core.giveaway.GiveawayManager; import mineplex.core.hologram.Hologram; import mineplex.core.hologram.HologramManager; @@ -130,6 +131,7 @@ public class BonusManager extends MiniClientPlugin implements I private HologramManager _hologramManager; private RewardManager _rewardManager; private StatsManager _statsManager; + private FacebookManager _facebookManager; public boolean _enabled; private Npc _carlNpc; private AnimationCarl _animation; @@ -168,7 +170,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, GiveawayManager giveawayManager) + public BonusManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager, DonationManager donationManager, PollManager pollManager, NpcManager npcManager, HologramManager hologramManager, StatsManager statsManager, InventoryManager inventoryManager, PetManager petManager, GiveawayManager giveawayManager, FacebookManager facebookManager) { super("Bonus", plugin); _repository = new BonusRepository(plugin, this, donationManager); @@ -187,6 +189,7 @@ public class BonusManager extends MiniClientPlugin implements I _pollManager = pollManager; _statsManager = statsManager; + _facebookManager = facebookManager; _voteList = new ArrayList(); _voteList.add("http://vote1.mineplex.com"); @@ -828,7 +831,7 @@ public class BonusManager extends MiniClientPlugin implements I if (entity.equals(_carlNpc.getEntity())) { updateDailyStreak(event.getPlayer()); - new BonusGui(_plugin, event.getPlayer(), this, _rewardManager).openInventory(); + new BonusGui(_plugin, event.getPlayer(), this, _rewardManager, _facebookManager).openInventory(); } } @@ -844,7 +847,7 @@ public class BonusManager extends MiniClientPlugin implements I if (event.getEntity().equals(_carlNpc.getEntity())) { updateDailyStreak(player); - new BonusGui(_plugin, player, this, _rewardManager).openInventory(); + new BonusGui(_plugin, player, this, _rewardManager, _facebookManager).openInventory(); } } } @@ -909,6 +912,7 @@ public class BonusManager extends MiniClientPlugin implements I if (canRank(player) && _clientManager.hasRank(player, Rank.ULTRA) && isPastAugust()) availableRewards++; if (canDaily(player)) availableRewards++; if (getPollManager().getNextPoll(_pollManager.Get(player), _clientManager.Get(player).GetRank()) != null) availableRewards++; + if (!_facebookManager.hasRedeemed(player)) availableRewards++; Hologram hologram; @@ -1045,9 +1049,12 @@ public class BonusManager extends MiniClientPlugin implements I { return _pollManager; } - - - + + public FacebookManager getFacebookManager() + { + return _facebookManager; + } + @EventHandler public void Join(final PlayerJoinEvent event) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/GuiCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/GuiCommand.java index ccc55a251..d68a85d73 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/GuiCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/GuiCommand.java @@ -17,7 +17,7 @@ public class GuiCommand extends CommandBase{ @Override public void Execute(Player caller, String[] args) { - new BonusGui(Plugin.getPlugin(), caller, Plugin, Plugin.getRewardManager()).openInventory(); + new BonusGui(Plugin.getPlugin(), caller, Plugin, Plugin.getRewardManager(), Plugin.getFacebookManager()).openInventory(); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/BonusGui.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/BonusGui.java index 8306c84d5..7c8f448dd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/BonusGui.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/BonusGui.java @@ -1,5 +1,7 @@ package mineplex.core.bonuses.gui; +import mineplex.core.bonuses.gui.buttons.FacebookButton; +import mineplex.core.facebook.FacebookManager; import mineplex.core.gui.SimpleGui; import mineplex.core.reward.RewardManager; import mineplex.core.bonuses.BonusManager; @@ -17,19 +19,21 @@ public class BonusGui extends SimpleGui private BonusManager manager; - public BonusGui(Plugin plugin, Player player, BonusManager manager, RewardManager rewardManager) + public BonusGui(Plugin plugin, Player player, BonusManager manager, RewardManager rewardManager, FacebookManager facebookManager) { super(plugin, player, player.getName() + "'s Bonuses", 5 * 9); this.manager = manager; - setItem(10, new VoteButton(plugin, player, this, manager)); + setItem(9, new VoteButton(plugin, player, this, manager)); - setItem(12, new RankBonusButton(getPlugin(), player, this, manager)); + setItem(11, new RankBonusButton(getPlugin(), player, this, manager)); - setItem(14, new DailyBonusButton(getPlugin(), player, this, manager)); + setItem(13, new DailyBonusButton(getPlugin(), player, this, manager)); - setItem(16, new PollButton(getPlugin(), player, manager.getPollManager(), manager.getClientManager(), this, manager)); + setItem(15, new PollButton(getPlugin(), player, manager.getPollManager(), manager.getClientManager(), this, manager)); + + setItem(17, new FacebookButton(player, facebookManager)); setItem(31, new CarlSpinButton(getPlugin(), player, manager, rewardManager)); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/FacebookButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/FacebookButton.java new file mode 100644 index 000000000..aae8f2d64 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/FacebookButton.java @@ -0,0 +1,77 @@ +package mineplex.core.bonuses.gui.buttons; + +import java.util.ArrayList; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.bonuses.BonusAmount; +import mineplex.core.common.jsonchat.ClickEvent; +import mineplex.core.common.jsonchat.JsonMessage; +import mineplex.core.common.util.C; +import mineplex.core.facebook.FacebookManager; +import mineplex.core.gui.GuiItem; +import mineplex.core.itemstack.ItemStackFactory; + +public class FacebookButton implements GuiItem +{ + private Player _player; + private FacebookManager _facebookManager; + + public FacebookButton(Player player, FacebookManager facebookManager) + { + _player = player; + _facebookManager = facebookManager; + } + + @Override + public void setup() + { + + } + + @Override + public void close() + { + + } + + @Override + public void click(ClickType clickType) + { + _player.closeInventory(); + + new JsonMessage(C.cAquaB + "Click here to claim Facebook Prize!").click(ClickEvent.OPEN_URL, "https://www.facebook.com/MineplexGames/").sendToPlayer(_player); + } + + private boolean isAvailable() + { + return !_facebookManager.hasRedeemed(_player); + } + + @Override + public ItemStack getObject() + { + ArrayList lore = new ArrayList(); + + if (isAvailable()) + { + lore.add(" "); + BonusAmount bonus = new BonusAmount(); + bonus.setAncientChests(10); + bonus.addLore(lore); + lore.add(" "); + lore.add(C.cGreen + "Click to like us on Facebook!"); + return ItemStackFactory.Instance.CreateStack(Material.WATER_BUCKET, (byte) 0, 1, C.cGreen + C.Bold + "Like on Facebook", lore); + } + else + { + lore.add(" "); + lore.add(C.cWhite + "You have already claimed the Facebook reward!"); + return ItemStackFactory.Instance.CreateStack(Material.REDSTONE_BLOCK, (byte) 0, 1, ChatColor.RED + C.Bold + "Like on Facebook", lore); + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookClient.java b/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookClient.java new file mode 100644 index 000000000..2fd480912 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookClient.java @@ -0,0 +1,26 @@ +package mineplex.core.facebook; + +/** + * Created by phict on 1/28/2016. + */ +public class FacebookClient +{ + // Has the player already redeemed a facebook code + // This is used so we have instant access for Carl the Creeper + private boolean _redeemed; + + public FacebookClient(boolean redeemed) + { + _redeemed = redeemed; + } + + public boolean hasRedeemed() + { + return _redeemed; + } + + public void setRedeemed(boolean redeemed) + { + _redeemed = redeemed; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookCode.java b/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookCode.java new file mode 100644 index 000000000..1a36ebce5 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookCode.java @@ -0,0 +1,23 @@ +package mineplex.core.facebook; + +public class FacebookCode +{ + private final String _code; + private final boolean _activated; + + public FacebookCode(String code, boolean activated) + { + _code = code; + _activated = activated; + } + + public String getCode() + { + return _code; + } + + public boolean isActivated() + { + return _activated; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookManager.java b/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookManager.java new file mode 100644 index 000000000..054ac2c79 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookManager.java @@ -0,0 +1,126 @@ +package mineplex.core.facebook; + +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniClientPlugin; +import mineplex.core.MiniDbClientPlugin; +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.donation.DonationManager; +import mineplex.core.facebook.command.FacebookCommand; +import mineplex.core.inventory.InventoryManager; +import mineplex.core.treasure.TreasureType; +import org.apache.commons.lang.StringUtils; + +public class FacebookManager extends MiniDbClientPlugin +{ + private CoreClientManager _clientManager; + private DonationManager _donationManager; + private InventoryManager _inventoryManager; + + private FacebookRepository _repository; + + public FacebookManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager) + { + super("Facebook", plugin, clientManager); + + _clientManager = clientManager; + _donationManager = donationManager; + _inventoryManager = inventoryManager; + + _repository = new FacebookRepository(plugin); + } + + @Override + public void addCommands() + { + addCommand(new FacebookCommand(this)); + } + + public void tryCode(Player player, String code) + { + if (!StringUtils.isAlphanumeric(code) || code.length() != 8) + { + message(player, "Invalid Code"); + return; + } + + final int accountId = _clientManager.getAccountId(player); + + runAsync(new Runnable() + { + @Override + public void run() + { + _repository.getCode(code, new Callback() + { + @Override + public void run(FacebookCode data) + { + if (data == null) + { + message(player, "Invalid Code"); + } + else if (data.isActivated()) + { + message(player, "Code has already been redeemed"); + } + else + { + boolean completed = _repository.activateCode(code, accountId); + if (completed) + { + _inventoryManager.addItemToInventory(player, TreasureType.ANCIENT.getItemName(), 10); + message(player, "Thanks! You earned " + F.elem("10 Ancient Chests")); + player.playSound(player.getLocation(), Sound.NOTE_PIANO, 1f, 1f); +// _donationManager.RewardCoinsLater(getName(), player, 20000); + } + else + { + message(player, "You have already redeemed a code!"); + } + } + } + }); + } + }); + + } + + public boolean hasRedeemed(Player player) + { + return Get(player).hasRedeemed(); + } + + private void message(Player player, String message) + { + UtilPlayer.message(player, F.main("Facebook", message)); + } + + @Override + protected FacebookClient AddPlayer(String player) + { + return new FacebookClient(false); + } + + @Override + public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException + { + boolean hasRow = resultSet.next(); + Set(playerName, new FacebookClient(hasRow)); + } + + @Override + public String getQuery(int accountId, String uuid, String name) + { + return "SELECT * FROM facebook WHERE accountId = " + accountId + ";"; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookRepository.java new file mode 100644 index 000000000..08b6edf93 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/facebook/FacebookRepository.java @@ -0,0 +1,62 @@ +package mineplex.core.facebook; + +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.common.util.Callback; +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; + +public class FacebookRepository extends RepositoryBase +{ + private static final String GET_CODE = "SELECT code, activated FROM facebook WHERE code = ?"; + private static final String ACTIVATE_CODE = "UPDATE facebook SET activated = 1, accountId = ?, activationTime = NOW() WHERE code = ?"; + + public FacebookRepository(JavaPlugin plugin) + { + super(plugin, DBPool.getAccount()); + } + + @Override + protected void initialize() + { + + } + + @Override + protected void update() + { + + } + + public void getCode(String codeName, Callback callback) + { + executeQuery(GET_CODE, new ResultSetCallable() + { + @Override + public void processResultSet(ResultSet resultSet) throws SQLException + { + FacebookCode facebookCode = null; + + while (resultSet.next()) + { + String code = resultSet.getString(1); + boolean activated = resultSet.getBoolean(2); + facebookCode = new FacebookCode(code, activated); + } + + callback.run(facebookCode); + } + }, new ColumnVarChar("code", 8, codeName)); + } + + public boolean activateCode(String codeName, int accountId) + { + return executeUpdate(ACTIVATE_CODE, new ColumnInt("accountId", accountId), new ColumnVarChar("code", 8, codeName)) == 1; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/facebook/command/FacebookCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/facebook/command/FacebookCommand.java new file mode 100644 index 000000000..961258995 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/facebook/command/FacebookCommand.java @@ -0,0 +1,30 @@ +package mineplex.core.facebook.command; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.facebook.FacebookManager; + +public class FacebookCommand extends CommandBase +{ + public FacebookCommand(FacebookManager plugin) + { + super(plugin, Rank.ALL, "facebook", "redeem"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args == null || args.length != 1) + { + UtilPlayer.message(caller, F.main("Facebook", "Usage: /facebook ")); + UtilPlayer.message(caller, F.main("Facebook", "Get a redemption code at " + F.elem("facebook.com/MineplexGames"))); + return; + } + + Plugin.tryCode(caller, args[0]); + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index 9c33ad164..5a94efeb2 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -33,6 +33,7 @@ import mineplex.core.disguise.DisguiseManager; import mineplex.core.disguise.PlayerDisguiseManager; import mineplex.core.disguise.disguises.DisguiseSlime; import mineplex.core.donation.DonationManager; +import mineplex.core.facebook.FacebookManager; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.event.GadgetCollideEntityEvent; import mineplex.core.gadget.event.GadgetEnableEvent; @@ -238,7 +239,8 @@ 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, giveawayManager); + FacebookManager facebookManager = new FacebookManager(plugin, clientManager, donationManager); + new BonusManager(plugin, clientManager, serverStatusManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager, giveawayManager, facebookManager); // _halloweenManager = new HalloweenSpookinessManager(this); 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 ab789b8c1..494f5dcd5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -30,6 +30,7 @@ import mineplex.core.elo.EloManager; import mineplex.core.energy.Energy; import mineplex.core.explosion.Explosion; import mineplex.core.explosion.ExplosionEvent; +import mineplex.core.facebook.FacebookManager; import mineplex.core.giveaway.GiveawayManager; import mineplex.core.hologram.HologramManager; import mineplex.core.inventory.InventoryManager; @@ -301,9 +302,10 @@ public class ArcadeManager extends MiniPlugin implements IRelation new CompassAddon(plugin, this); new SoupAddon(plugin, this); new TeamArmorAddon(plugin, this); - - new BonusManager(plugin, clientManager, serverStatusManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager, giveawayManager); - + + FacebookManager facebookManager = new FacebookManager(plugin, clientManager, donationManager); + new BonusManager(plugin, clientManager, serverStatusManager, donationManager, pollManager , npcManager, hologramManager, statsManager, _inventoryManager, petManager, giveawayManager, facebookManager); + //Champions Modules _energy = new Energy(plugin);