Facebook Command

This commit is contained in:
Shaun Bennett 2016-01-28 22:15:35 -05:00
parent 877ec4710e
commit 051d70771b
11 changed files with 375 additions and 16 deletions

View File

@ -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<BonusClientData> 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<BonusClientData> 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<BonusClientData> implements I
_pollManager = pollManager;
_statsManager = statsManager;
_facebookManager = facebookManager;
_voteList = new ArrayList<String>();
_voteList.add("http://vote1.mineplex.com");
@ -828,7 +831,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> 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<BonusClientData> 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<BonusClientData> 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;
@ -1046,7 +1050,10 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
return _pollManager;
}
public FacebookManager getFacebookManager()
{
return _facebookManager;
}
@EventHandler
public void Join(final PlayerJoinEvent event)

View File

@ -17,7 +17,7 @@ public class GuiCommand extends CommandBase<BonusManager>{
@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();
}
}

View File

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

View File

@ -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<String> lore = new ArrayList<String>();
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);
}
}
}

View File

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

View File

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

View File

@ -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<FacebookClient>
{
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<FacebookCode>()
{
@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 + ";";
}
}

View File

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

View File

@ -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<FacebookManager>
{
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 <code>"));
UtilPlayer.message(caller, F.main("Facebook", "Get a redemption code at " + F.elem("facebook.com/MineplexGames")));
return;
}
Plugin.tryCode(caller, args[0]);
}
}

View File

@ -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<HubClient>
((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);

View File

@ -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;
@ -302,7 +303,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
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);