Giveaway extras

This commit is contained in:
Shaun Bennett 2015-11-09 03:27:42 -05:00
parent 2a7b272de3
commit 2c54e9e59a
7 changed files with 152 additions and 16 deletions

View File

@ -4,15 +4,17 @@ public class Giveaway
{
private int _id;
private String _name;
private String _prettyName;
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)
public Giveaway(int id, String name, String prettyName, String header, String message, boolean notifyNetwork, int notifyCooldown)
{
_id = id;
_name = name;
_prettyName = prettyName;
_header = header;
_message = message;
_notifyNetwork = notifyNetwork;
@ -29,6 +31,11 @@ public class Giveaway
return _name;
}
public String getPrettyName()
{
return _prettyName;
}
public String getMessage()
{
return _message;

View File

@ -1,30 +1,43 @@
package mineplex.core.giveaway;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
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.common.util.UtilServer;
import mineplex.core.giveaway.redis.GiveawayMessage;
import mineplex.core.giveaway.redis.GiveawayMessageHandler;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.Region;
import mineplex.serverdata.commands.ServerCommandManager;
public class GiveawayManager extends MiniPlugin
public class GiveawayManager extends MiniDbClientPlugin<PlayerGiveawayData>
{
private CoreClientManager _clientManager;
private ServerStatusManager _statusManager;
private GiveawayRepository _repository;
private HashMap<String, Giveaway> _giveawayMap;
private HashMap<String, GiveawayCooldown> _cooldownMap;
public GiveawayManager(JavaPlugin plugin, CoreClientManager clientManager)
public GiveawayManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager)
{
super("Giveaway Manager", plugin);
super("Giveaway Manager", plugin, clientManager);
_clientManager = clientManager;
_statusManager = statusManager;
_repository = new GiveawayRepository(plugin);
_giveawayMap = _repository.loadGiveaways();
_cooldownMap = _repository.loadCooldowns();
@ -66,7 +79,7 @@ public class GiveawayManager extends MiniPlugin
if (_repository.canGiveaway(accountId, giveawayName, cooldownName))
{
UUID uuid = UUID.randomUUID();
if (_repository.addGiveaway(accountId, giveaway.getId(), cooldown.getId(), Region.US, "", uuid))
if (_repository.addGiveaway(accountId, giveaway.getId(), cooldown.getId(), _statusManager.getRegion(), _statusManager.getName(), uuid))
{
response = new GiveawayResponse(uuid);
}
@ -89,6 +102,9 @@ public class GiveawayManager extends MiniPlugin
{
if (response.isSuccess())
{
Get(player).addGiveawayReward(new GiveawayReward(giveaway.getPrettyName(), response.getGiveawayId().toString().replace("-", "")));
notifyPlayer(player);
GiveawayMessage message = new GiveawayMessage(giveawayName, player.getName(), giveaway.getMessage(), giveaway.getHeader());
message.publish();
}
@ -114,4 +130,51 @@ public class GiveawayManager extends MiniPlugin
{
return _cooldownMap.containsKey(name);
}
@EventHandler
public void notifyGiveaway(UpdateEvent event)
{
if (event.getType() == UpdateType.MIN_01)
{
for (Player player : UtilServer.getPlayers())
notifyPlayer(player);
}
}
@EventHandler
public void join(PlayerJoinEvent event)
{
notifyPlayer(event.getPlayer());
}
public void notifyPlayer(Player player)
{
PlayerGiveawayData data = Get(player);
if (!data.getGiveawayRewards().isEmpty())
{
GiveawayReward reward = data.getGiveawayRewards().poll();
UtilPlayer.message(player, F.main("Giveaway", "You have a prize to claim!"));
UtilPlayer.message(player, F.main("Giveaway", "You have won " + F.elem(reward.getName())));
UtilPlayer.message(player, F.main("Giveaway", "To claim your reward please take a screenshot and contact support"));
UtilPlayer.message(player, F.main("Giveaway", "Reward Key: " + F.elem(reward.getUuid())));
}
}
@Override
public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException
{
Set(playerName, _repository.loadPlayerGiveaway(resultSet));
}
@Override
public String getQuery(int accountId, String uuid, String name)
{
return "SELECT g.prettyName, ag.uuid FROM accountGiveaway AS ag INNER JOIN giveaway AS g ON ag.giveawayId = g.id WHERE ag.claimed = 0 AND ag.accountId = " + accountId + ";";
}
@Override
protected PlayerGiveawayData AddPlayer(String player)
{
return new PlayerGiveawayData();
}
}

View File

@ -21,7 +21,7 @@ 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_GIVEAWAY = "SELECT id, name, prettyName, 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)
@ -68,14 +68,15 @@ public class GiveawayRepository extends RepositoryBase
{
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);
String prettyName = resultSet.getString(3);
String header = resultSet.getString(4);
String message = resultSet.getString(5);
int max = resultSet.getInt(6);
boolean notifyNetwork = resultSet.getBoolean(7);
int notifyCooldown = resultSet.getInt(8);
boolean canWinTwice = resultSet.getBoolean(9);
Giveaway giveaway = new Giveaway(id, name, header, message, notifyNetwork, notifyCooldown);
Giveaway giveaway = new Giveaway(id, name, prettyName, header, message, notifyNetwork, notifyCooldown);
map.put(name, giveaway);
}
}
@ -104,6 +105,21 @@ public class GiveawayRepository extends RepositoryBase
return map;
}
public PlayerGiveawayData loadPlayerGiveaway(ResultSet resultSet) throws SQLException
{
PlayerGiveawayData giveawayData = new PlayerGiveawayData();
while (resultSet.next())
{
String name = resultSet.getString(1);
String uuid = resultSet.getString(2);
GiveawayReward reward = new GiveawayReward(name, uuid);
giveawayData.addGiveawayReward(reward);
}
return giveawayData;
}
@Override
protected void initialize()
{

View File

@ -0,0 +1,23 @@
package mineplex.core.giveaway;
public class GiveawayReward
{
private String _name;
private String _uuid;
public GiveawayReward(String name, String uuid)
{
_name = name;
_uuid = uuid;
}
public String getName()
{
return _name;
}
public String getUuid()
{
return _uuid;
}
}

View File

@ -0,0 +1,26 @@
package mineplex.core.giveaway;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
public class PlayerGiveawayData
{
private Queue<GiveawayReward> _giveawayRewards;
public PlayerGiveawayData()
{
_giveawayRewards = new LinkedList<GiveawayReward>();
}
public void addGiveawayReward(GiveawayReward reward)
{
_giveawayRewards.add(reward);
}
public Queue<GiveawayReward> getGiveawayRewards()
{
return _giveawayRewards;
}
}

View File

@ -30,6 +30,7 @@ import mineplex.core.reward.rewards.UnknownPackageReward;
import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.timing.TimingManager;
import mineplex.serverdata.Region;
public class RewardManager
{
@ -398,9 +399,9 @@ public class RewardManager
RewardRarity rarity = type.generateRarity(requiresUncommon);
//Dont give Rank Upgrade if already has Titan
if (rarity == RewardRarity.MYTHICAL)
if (true || rarity == RewardRarity.MYTHICAL)
{
if (canGiveMythical && type == RewardType.MythicalChest && Math.random() <= 0.1)
if (true || _statusManager.getRegion() == Region.US && canGiveMythical && type == RewardType.MythicalChest && Math.random() <= 0.1)
{
return getLogitechPrize();
}

View File

@ -112,7 +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);
GiveawayManager giveawayManager = new GiveawayManager(this, clientManager, serverStatusManager);
new TitanGiveawayManager(this, clientManager, serverStatusManager);
Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName());