Titan giveaway work

This commit is contained in:
Shaun Bennett 2015-10-09 22:14:10 -04:00
parent 611fb88f15
commit aa9fd1abf3
12 changed files with 310 additions and 136 deletions

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" hash="1293212710">
<data-source source="LOCAL" name="Mineplex" uuid="14dfc55d-5343-47c4-ab24-76a055b8059e">
<driver-ref>mysql</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.mysql.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://db.mineplex.com:3306</jdbc-url>
<driver-properties>
<property name="zeroDateTimeBehavior" value="convertToNull" />
<property name="tinyInt1isBit" value="false" />
<property name="characterEncoding" value="utf8" />
<property name="characterSetResults" value="utf8" />
<property name="yearIsDateType" value="false" />
</driver-properties>
<libraries />
</data-source>
</component>
</project>

View File

@ -29,6 +29,19 @@ public class UtilTime
return sdf.format(cal.getTime());
}
public static String getDayOfMonthSuffix(final int n)
{
if (n >= 11 && n <= 13) {
return "th";
}
switch (n % 10) {
case 1: return "st";
case 2: return "nd";
case 3: return "rd";
default: return "th";
}
}
public enum TimeUnit
{
FIT,

View File

@ -0,0 +1,33 @@
package mineplex.core.titangiveaway;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilTime;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
public class GiveawayMessageHandler implements CommandCallback
{
@Override
public void run(ServerCommand command)
{
if (command instanceof TitanGiveawayMessage)
{
TitanGiveawayMessage message = ((TitanGiveawayMessage) command);
String playerName = message.getPlayerName();
int count = message.getTitanCount();
String countString = UtilTime.getDayOfMonthSuffix(count);
String chatMessage = C.cRed + playerName + C.cDRed + " has become the " + C.cRed + countString + " Titan";
UtilTextMiddle.display("", chatMessage, UtilServer.getPlayers());
for (Player player : UtilServer.getPlayers())
{
player.playSound(player.getEyeLocation(), Sound.AMBIENCE_CAVE, 1, 1);
}
}
}
}

View File

@ -0,0 +1,117 @@
package mineplex.core.titangiveaway;
import java.util.Random;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.status.ServerStatusManager;
import mineplex.serverdata.Region;
import mineplex.serverdata.commands.ServerCommandManager;
public class TitanGiveawayManager extends MiniPlugin
{
// private static final double RANK_FIND_CHANCE = 0.001;
private static final double RANK_FIND_CHANCE = 1;
private TitanGiveawayRepository _repository;
private CoreClientManager _clientManager;
private ServerStatusManager _statusManager;
private Random _random;
public TitanGiveawayManager(JavaPlugin plugin, CoreClientManager clientManager, ServerStatusManager statusManager)
{
super("Titan Giveaway", plugin);
_repository = new TitanGiveawayRepository(plugin);
_clientManager = clientManager;
_statusManager = statusManager;
_random = new Random();
ServerCommandManager.getInstance().registerCommandType("TitanGiveawayMessage", TitanGiveawayMessage.class, new GiveawayMessageHandler());
}
public void openPumpkin(final Player player, final Runnable onSuccess)
{
double rand = _random.nextDouble();
if (!hasTitan(player) && rand < RANK_FIND_CHANCE)
{
final int accountId = _clientManager.getAccountId(player);
final Region region = getRegion();
final String serverName = getServerName();
// Need to check database that we can give away a rank
runAsync(new Runnable()
{
@Override
public void run()
{
final boolean pass = _repository.canGiveaway();
if (pass && _repository.addTitan(accountId, region, serverName))
{
runSync(new Runnable()
{
@Override
public void run()
{
giveRank(new Callback<Rank>()
{
@Override
public void run(Rank rank)
{
if (rank == Rank.TITAN)
{
TitanGiveawayMessage message = new TitanGiveawayMessage(player.getName(), _repository.getTitanCount() + 1);
message.publish();
if (onSuccess != null) onSuccess.run();
}
}
}, Rank.TITAN, player);
}
});
}
}
});
}
}
/**
* Confirm that the player doesn't already have TITAN rank
*/
private boolean hasTitan(Player player)
{
return !_clientManager.hasRank(player, Rank.TITAN);
}
public Region getRegion()
{
return _statusManager.getRegion();
}
public String getServerName()
{
return _statusManager.getCurrentServerName();
}
private void giveRank(Callback<Rank> callback, Rank rank, Player player)
{
_clientManager.Get(player).SetRank(rank);
_clientManager.getRepository().saveRank(callback, player.getName(), player.getUniqueId(), rank, true);
}
@EventHandler
public void onCommand(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().startsWith("/pumpkin"))
{
openPumpkin(event.getPlayer(), null);
}
}
}

View File

@ -0,0 +1,32 @@
package mineplex.core.titangiveaway;
import mineplex.serverdata.commands.ServerCommand;
public class TitanGiveawayMessage extends ServerCommand
{
private String _playerName;
private int _titanCount;
public TitanGiveawayMessage(String playerName, int titanCount)
{
_playerName = playerName;
_titanCount = titanCount;
}
public String getPlayerName()
{
return _playerName;
}
public int getTitanCount()
{
return _titanCount;
}
@Override
public void run()
{
// Handled in Command Callback
}
}

View File

@ -0,0 +1,69 @@
package mineplex.core.titangiveaway;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Types;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.Region;
public class TitanGiveawayRepository extends RepositoryBase
{
private static final String ADD_TITAN = "INSERT INTO titanGiveaway (accountId, region, serverName) VALUES (?, ?, ?)";
private int _titanCount;
public TitanGiveawayRepository(JavaPlugin plugin)
{
super(plugin, DBPool.ACCOUNT);
_titanCount = 0;
}
@Override
protected void initialize()
{
}
@Override
protected void update()
{
}
public boolean addTitan(int accountId, Region region, String serverName)
{
return 1 == executeUpdate(ADD_TITAN, new ColumnInt("accountId", accountId), new ColumnVarChar("region", 10, region.name()), new ColumnVarChar("serverName", 64, serverName));
}
public boolean canGiveaway()
{
try (Connection connection = getConnection();
CallableStatement callableStatement = connection.prepareCall("{call check_titanGiveaway(?, ?)}"))
{
callableStatement.registerOutParameter(1, Types.BOOLEAN);
callableStatement.registerOutParameter(2, Types.INTEGER);
callableStatement.executeUpdate();
boolean pass = callableStatement.getBoolean(1);
int titanCount = callableStatement.getInt(2);
_titanCount = titanCount;
return pass;
}
catch (Exception e)
{
}
return false;
}
public int getTitanCount()
{
return _titanCount;
}
}

View File

@ -44,6 +44,7 @@ import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport;
import mineplex.core.titangiveaway.TitanGiveawayManager;
import mineplex.core.updater.FileUpdater;
import mineplex.core.updater.Updater;
import mineplex.core.velocity.VelocityFix;
@ -107,6 +108,7 @@ public class Hub extends JavaPlugin implements IRelation
//Main Modules
ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager));
new TitanGiveawayManager(this, clientManager, serverStatusManager);
Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName());

View File

@ -93,6 +93,7 @@ import mineplex.core.status.ServerStatusManager;
import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport;
import mineplex.core.timing.TimingManager;
import mineplex.core.titangiveaway.TitanGiveawayManager;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.classcombat.Class.ClassManager;
import mineplex.minecraft.game.classcombat.Condition.SkillConditionManager;
@ -135,6 +136,7 @@ import nautilus.game.arcade.managers.GameSpectatorManager;
import nautilus.game.arcade.managers.GameStatManager;
import nautilus.game.arcade.managers.GameTournamentManager;
import nautilus.game.arcade.managers.GameWorldManager;
import nautilus.game.arcade.managers.HolidayManager;
import nautilus.game.arcade.managers.IdleManager;
import nautilus.game.arcade.managers.MiscManager;
import nautilus.game.arcade.shop.ArcadeShop;
@ -294,7 +296,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
new MiscManager(this);
_hologramManager = hologramManager;
_idleManager = new IdleManager(this);
//new HolidayManager(this);
TitanGiveawayManager titanGiveaway = new TitanGiveawayManager(getPlugin(), clientManager, serverStatusManager);
new HolidayManager(this, titanGiveaway);
// Game Addons
new CompassAddon(plugin, this);

View File

@ -15,6 +15,7 @@ import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.titangiveaway.TitanGiveawayManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
@ -81,6 +82,7 @@ public class HolidayManager implements Listener
private HolidayType type = HolidayType.Halloween;
ArcadeManager Manager;
private TitanGiveawayManager _titanManager;
public HashSet<Block> _active = new HashSet<Block>();
@ -90,9 +92,10 @@ public class HolidayManager implements Listener
public long _lastSpawn = System.currentTimeMillis();
public HolidayManager(ArcadeManager manager)
public HolidayManager(ArcadeManager manager, TitanGiveawayManager titanManager)
{
Manager = manager;
_titanManager = titanManager;
Manager.getPluginManager().registerEvents(this, Manager.getPlugin());
}
@ -122,7 +125,7 @@ public class HolidayManager implements Listener
block.getType() != Material.JACK_O_LANTERN &&
block.getType() != Material.CHEST)
{
specialBlockBreak(block);
specialBlockBreak(null, block);
blockIterator.remove();
continue;
}
@ -295,7 +298,7 @@ public class HolidayManager implements Listener
event.setCancelled(true);
specialBlockBreak(event.getClickedBlock());
specialBlockBreak(event.getPlayer(), event.getClickedBlock());
}
@EventHandler
@ -310,10 +313,10 @@ public class HolidayManager implements Listener
if (!_active.contains(event.getBlock()))
return;
specialBlockBreak(event.getBlock());
specialBlockBreak(event.getPlayer(), event.getBlock());
}
private void specialBlockBreak(Block block)
private void specialBlockBreak(Player player, Block block)
{
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, type.getBlockType());
block.setType(Material.AIR);
@ -336,6 +339,19 @@ public class HolidayManager implements Listener
_coins.add(coin);
}
// Titan Giveaway
if (player != null)
{
_titanManager.openPumpkin(player, new Runnable()
{
@Override
public void run()
{
// TODO
}
});
}
//Effect
block.getWorld().playSound(block.getLocation(), type.getBlockSound(), 1f, 1f);
}

View File

@ -1,60 +0,0 @@
package nautilus.game.arcade.managers.titangiveaway;
import java.util.Random;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
public class TitanGiveawayManager extends MiniPlugin
{
// private static final double RANK_FIND_CHANCE = 0.001;
private static final double RANK_FIND_CHANCE = 1;
private TitanGiveawayRepository _repository;
private CoreClientManager _clientManager;
private Random _random;
public TitanGiveawayManager(JavaPlugin plugin, CoreClientManager clientManager)
{
super("Titan Giveaway", plugin);
_repository = new TitanGiveawayRepository(plugin);
_clientManager = clientManager;
_random = new Random();
}
public void openPumpkin(Player player)
{
double rand = _random.nextDouble();
if (rand < RANK_FIND_CHANCE)
{
// Need to check database that we can give away a rank
runAsync(new Runnable()
{
@Override
public void run()
{
}
});
}
}
/**
* Confirm that the player doesn't already have TITAN rank
*/
private boolean canGiveRank(Player player)
{
return !_clientManager.hasRank(player, Rank.TITAN);
}
private void giveRank(Rank rank, Player player)
{
_clientManager.Get(player).SetRank(rank);
_clientManager.getRepository().saveRank(null, player.getName(), player.getUniqueId(), rank, true);
}
}

View File

@ -1,20 +0,0 @@
package nautilus.game.arcade.managers.titangiveaway;
import mineplex.serverdata.commands.ServerCommand;
public class TitanGiveawayMessage extends ServerCommand
{
private String _playerName;
public TitanGiveawayMessage(String playerName)
{
_playerName = playerName;
}
@Override
public void run()
{
super.run();
}
}

View File

@ -1,50 +0,0 @@
package nautilus.game.arcade.managers.titangiveaway;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLType;
import java.sql.Types;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
public class TitanGiveawayRepository extends RepositoryBase
{
private int _titanGiveawayCount;
public TitanGiveawayRepository(JavaPlugin plugin)
{
super(plugin, DBPool.ACCOUNT);
_titanGiveawayCount = 0;
}
@Override
protected void initialize()
{
}
@Override
protected void update()
{
}
public boolean canGiveaway()
{
try (Connection connection = getConnection();
CallableStatement callableStatement = connection.prepareCall("{call check_titanGiveaway(?)}"))
{
callableStatement.registerOutParameter(1, Types.BOOLEAN);
}
catch (Exception e)
{
}
return false;
}
}