Eternal giveaway refactoring

This commit is contained in:
Shaun Bennett 2016-11-17 19:59:49 -05:00 committed by Shaun Bennett
parent cdfd030999
commit 562d7de1a9
7 changed files with 58 additions and 65 deletions

View File

@ -1,4 +1,4 @@
package mineplex.core.rankGiveaway.fatedgiveaway;
package mineplex.core.rankGiveaway.eternal;
import org.bukkit.Bukkit;
import org.bukkit.Color;
@ -17,12 +17,12 @@ import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class FatedGiveawayAnimation implements Listener
public class EternalGiveawayAnimation implements Listener
{
private Location _location;
private Long _duration, _startTime, _worldTime;
public FatedGiveawayAnimation(FatedGiveawayManager manager, Location start, Long duration)
public EternalGiveawayAnimation(EternalGiveawayManager manager, Location start, Long duration)
{
_location = start.clone();
_duration = duration;
@ -30,7 +30,7 @@ public class FatedGiveawayAnimation implements Listener
Bukkit.getPluginManager().registerEvents(this, manager.getPlugin());
}
public FatedGiveawayAnimation(FatedGiveawayManager manager, Location start)
public EternalGiveawayAnimation(EternalGiveawayManager manager, Location start)
{
this(manager, start, 11111L);
}

View File

@ -1,4 +1,4 @@
package mineplex.core.rankGiveaway.fatedgiveaway;
package mineplex.core.rankGiveaway.eternal;
import java.util.Random;
@ -9,38 +9,38 @@ import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.rankGiveaway.redis.FatedGiveawayMessage;
import mineplex.core.rankGiveaway.redis.EternalGiveawayMessage;
import mineplex.core.rankGiveaway.redis.GiveawayMessageHandler;
import mineplex.core.status.ServerStatusManager;
import mineplex.serverdata.Region;
import mineplex.serverdata.commands.ServerCommandManager;
public class FatedGiveawayManager extends MiniPlugin
public class EternalGiveawayManager extends MiniPlugin
{
private static final double RANK_FIND_CHANCE = 0.001;
private FatedGiveawayRepository _repository;
private EternalGiveawayRepository _repository;
private CoreClientManager _clientManager;
private ServerStatusManager _statusManager;
private Random _random;
public FatedGiveawayManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager)
public EternalGiveawayManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager)
{
super("Fated Giveaway", plugin);
super("Eternal Giveaway", plugin);
_repository = new FatedGiveawayRepository(plugin);
_repository = new EternalGiveawayRepository(plugin);
_clientManager = clientManager;
_statusManager = statusManager;
_random = new Random();
ServerCommandManager.getInstance().registerCommandType("FatedGiveawayMessage", FatedGiveawayMessage.class, new GiveawayMessageHandler(plugin));
ServerCommandManager.getInstance().registerCommandType("EternalGiveawayMessage", EternalGiveawayMessage.class, new GiveawayMessageHandler(plugin));
}
public void openPumpkin(final Player player, final Runnable onSuccess)
{
double rand = _random.nextDouble();
if (!hasFated(player) && rand < RANK_FIND_CHANCE)
if (!hasEternal(player) && rand < RANK_FIND_CHANCE)
{
final int accountId = _clientManager.getAccountId(player);
final Region region = getRegion();
@ -54,28 +54,22 @@ public class FatedGiveawayManager extends MiniPlugin
{
final boolean pass = _repository.canGiveaway(region);
if (pass && _repository.addFated(accountId, region, serverName))
if (pass && _repository.addEternal(accountId, region, serverName))
{
runSync(new Runnable()
{
@Override
public void run()
{
giveRank(new Callback<Rank>()
giveRank(rank ->
{
@Override
public void run(Rank rank)
if (rank == Rank.TITAN)
{
// TODO CHANGE RANK
if (rank == Rank.TITAN)
{
FatedGiveawayMessage message = new FatedGiveawayMessage(player.getName(), _repository.getFatedCount() + 1);
message.publish();
if (onSuccess != null) onSuccess.run();
}
EternalGiveawayMessage message = new EternalGiveawayMessage(player.getName(), _repository.getEternalCount() + 1);
message.publish();
if (onSuccess != null) onSuccess.run();
}
// TODO CHANGE RANK
}, Rank.TITAN, player);
}, Rank.ETERNAL, player);
}
});
}
@ -85,12 +79,11 @@ public class FatedGiveawayManager extends MiniPlugin
}
/**
* Confirm that the player doesn't already have FATED rank
* Confirm that the player doesn't already have ETERNAL rank
*/
private boolean hasFated(Player player)
private boolean hasEternal(Player player)
{
// TODO CHANGE RANK
return _clientManager.hasRank(player, Rank.TITAN);
return _clientManager.hasRank(player, Rank.ETERNAL);
}
public Region getRegion()

View File

@ -1,4 +1,4 @@
package mineplex.core.rankGiveaway.fatedgiveaway;
package mineplex.core.rankGiveaway.eternal;
import java.sql.CallableStatement;
import java.sql.Connection;
@ -12,16 +12,16 @@ import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
public class FatedGiveawayRepository extends MinecraftRepository
public class EternalGiveawayRepository extends MinecraftRepository
{
private static final String ADD_FATED = "INSERT INTO fatedGiveaway (accountId, region, serverName) VALUES (?, ?, ?)";
private static final String ADD_ETERNAL = "INSERT INTO eternalGiveaway (accountId, region, serverName) VALUES (?, ?, ?)";
private int _fatedCount;
private int _eternalCount;
public FatedGiveawayRepository(JavaPlugin plugin)
public EternalGiveawayRepository(JavaPlugin plugin)
{
super(plugin, DBPool.getAccount());
_fatedCount = 0;
_eternalCount = 0;
}
@Override
@ -36,15 +36,15 @@ public class FatedGiveawayRepository extends MinecraftRepository
}
public boolean addFated(int accountId, Region region, String serverName)
public boolean addEternal(int accountId, Region region, String serverName)
{
return 1 == executeUpdate(ADD_FATED, new ColumnInt("accountId", accountId), new ColumnVarChar("region", 10, region.name()), new ColumnVarChar("serverName", 64, serverName));
return 1 == executeUpdate(ADD_ETERNAL, new ColumnInt("accountId", accountId), new ColumnVarChar("region", 10, region.name()), new ColumnVarChar("serverName", 64, serverName));
}
public boolean canGiveaway(Region region)
{
try (Connection connection = getConnection();
CallableStatement callableStatement = connection.prepareCall("{call check_fatedGiveaway(?, ?, ?)}"))
CallableStatement callableStatement = connection.prepareCall("{call check_eternalGiveaway(?, ?, ?)}"))
{
callableStatement.setString(1, region.name());
callableStatement.registerOutParameter(2, Types.BOOLEAN);
@ -52,9 +52,9 @@ public class FatedGiveawayRepository extends MinecraftRepository
callableStatement.executeUpdate();
boolean pass = callableStatement.getBoolean(2);
int fatedCount = callableStatement.getInt(3);
int eternalCount = callableStatement.getInt(3);
_fatedCount = fatedCount;
_eternalCount = eternalCount;
return pass;
}
catch (Exception e)
@ -64,8 +64,8 @@ public class FatedGiveawayRepository extends MinecraftRepository
return false;
}
public int getFatedCount()
public int getEternalCount()
{
return _fatedCount;
return _eternalCount;
}
}

View File

@ -2,15 +2,15 @@ package mineplex.core.rankGiveaway.redis;
import mineplex.serverdata.commands.ServerCommand;
public class FatedGiveawayMessage extends ServerCommand
public class EternalGiveawayMessage extends ServerCommand
{
private String _playerName;
private int _fatedCount;
private int _eternalCount;
public FatedGiveawayMessage(String playerName, int fatedCount)
public EternalGiveawayMessage(String playerName, int eternalCount)
{
_playerName = playerName;
_fatedCount = fatedCount;
_eternalCount = eternalCount;
}
public String getPlayerName()
@ -18,9 +18,9 @@ public class FatedGiveawayMessage extends ServerCommand
return _playerName;
}
public int getFatedCount()
public int getEternalCount()
{
return _fatedCount;
return _eternalCount;
}
@Override

View File

@ -44,14 +44,14 @@ public class GiveawayMessageHandler implements CommandCallback
player.playSound(player.getEyeLocation(), Sound.AMBIENCE_CAVE, 1, 1);
}
}
else if (command instanceof FatedGiveawayMessage)
else if (command instanceof EternalGiveawayMessage)
{
FatedGiveawayMessage message = ((FatedGiveawayMessage) command);
EternalGiveawayMessage message = ((EternalGiveawayMessage) command);
String playerName = message.getPlayerName();
int count = message.getFatedCount();
int count = message.getEternalCount();
String countString = count + UtilTime.getDayOfMonthSuffix(count);
String chatMessage = C.cPurple + playerName + C.cWhite + " found Fated in a " + C.cPurple + "Thanksgiving Chicken";
UtilTextMiddle.display(C.cDPurple + C.Bold + "FATED", chatMessage, 20, 80, 20, UtilServer.getPlayers());
String chatMessage = C.cPurple + playerName + C.cWhite + " found Eternal Rank in a " + C.cPurple + "Thanksgiving Chicken";
UtilTextMiddle.display(C.cDPurple + C.Bold + "ETERNAL", chatMessage, 20, 80, 20, UtilServer.getPlayers());
World world = UtilServer.getPlayers().length > 0 ? UtilServer.getPlayers()[0].getWorld() : Bukkit.getWorlds().get(0);
LightFlicker lightFlicker = new LightFlicker(world);
lightFlicker.runTaskTimer(_plugin, 1, 1);

View File

@ -89,7 +89,7 @@ import mineplex.core.preferences.PreferencesManager;
import mineplex.core.progression.KitProgressionManager;
import mineplex.core.projectile.ProjectileManager;
import mineplex.core.punish.Punish;
import mineplex.core.rankGiveaway.fatedgiveaway.FatedGiveawayManager;
import mineplex.core.rankGiveaway.eternal.EternalGiveawayManager;
import mineplex.core.resourcepack.ResourcePackManager;
import mineplex.core.scoreboard.MineplexScoreboard;
import mineplex.core.scoreboard.ScoreboardManager;
@ -344,9 +344,9 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_hologramManager = hologramManager;
_idleManager = new IdleManager(this);
TitanGiveawayManager titanGiveaway = new TitanGiveawayManager(getPlugin(), clientManager, serverStatusManager);
FatedGiveawayManager fatedGiveaway = new FatedGiveawayManager(getPlugin(), clientManager, serverStatusManager);
EternalGiveawayManager eternalGiveawayManager = new EternalGiveawayManager(getPlugin(), clientManager, serverStatusManager);
new HolidayManager(this, titanGiveaway, fatedGiveaway);
new HolidayManager(this, titanGiveaway, eternalGiveawayManager);
IsHolidayEnabled = true;
new ValentinesGiftManager(plugin, clientManager, _bonusManager.getRewardManager(), inventoryManager, _cosmeticManager.getGadgetManager(), statsManager);

View File

@ -45,8 +45,8 @@ import mineplex.core.common.util.UtilWorld;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.particleeffects.HalloweenSmashedEffect;
import mineplex.core.rankGiveaway.fatedgiveaway.FatedGiveawayAnimation;
import mineplex.core.rankGiveaway.fatedgiveaway.FatedGiveawayManager;
import mineplex.core.rankGiveaway.eternal.EternalGiveawayAnimation;
import mineplex.core.rankGiveaway.eternal.EternalGiveawayManager;
import mineplex.core.rankGiveaway.titangiveaway.TitanGiveawayManager;
import mineplex.core.reward.RewardPool;
import mineplex.core.reward.RewardRarity;
@ -102,7 +102,7 @@ public class HolidayManager implements Listener
private ArcadeManager _arcadeManager;
private TitanGiveawayManager _titanManager;
private FatedGiveawayManager _fatedManager;
private EternalGiveawayManager _eternalGiveawayManager;
public HashSet<Block> _active = new HashSet<>();
public HashSet<org.bukkit.entity.Entity> _activeEntities = new HashSet<>();
@ -120,11 +120,11 @@ public class HolidayManager implements Listener
private EnumMap<RewardPool.Type, RewardPool> _rewardPools;
public HolidayManager(ArcadeManager arcadeManager, TitanGiveawayManager titanManager, FatedGiveawayManager fatedManager)
public HolidayManager(ArcadeManager arcadeManager, TitanGiveawayManager titanManager, EternalGiveawayManager eternalGiveawayManager)
{
_arcadeManager = arcadeManager;
_titanManager = titanManager;
_fatedManager = fatedManager;
_eternalGiveawayManager = eternalGiveawayManager;
_rewardPools = new EnumMap<>(RewardPool.Type.class);
for (RewardPool.Type type : RewardPool.Type.values())
@ -617,16 +617,16 @@ public class HolidayManager implements Listener
_gems.add(gem);
}
// Fated Giveaway
// Eternal Giveaway
if (player != null)
{
_fatedManager.openPumpkin(player, new Runnable()
_eternalGiveawayManager.openPumpkin(player, new Runnable()
{
@Override
public void run()
{
Location location = entity.getLocation().add(0.5, 0.5, 0.5);
new FatedGiveawayAnimation(_fatedManager, location, 3000L);
new EternalGiveawayAnimation(_eternalGiveawayManager, location, 3000L);
}
});
}