Titan giveaway

This commit is contained in:
Shaun Bennett 2015-10-10 02:19:05 -04:00
parent 36fabf93b6
commit f1e9acbb58
3 changed files with 81 additions and 21 deletions

View File

@ -1,7 +1,10 @@
package mineplex.core.titangiveaway; package mineplex.core.titangiveaway;
import org.bukkit.Bukkit;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
@ -12,6 +15,13 @@ import mineplex.serverdata.commands.ServerCommand;
public class GiveawayMessageHandler implements CommandCallback public class GiveawayMessageHandler implements CommandCallback
{ {
private JavaPlugin _plugin;
public GiveawayMessageHandler(JavaPlugin plugin)
{
_plugin = plugin;
}
@Override @Override
public void run(ServerCommand command) public void run(ServerCommand command)
{ {
@ -20,12 +30,16 @@ public class GiveawayMessageHandler implements CommandCallback
TitanGiveawayMessage message = ((TitanGiveawayMessage) command); TitanGiveawayMessage message = ((TitanGiveawayMessage) command);
String playerName = message.getPlayerName(); String playerName = message.getPlayerName();
int count = message.getTitanCount(); int count = message.getTitanCount();
String countString = UtilTime.getDayOfMonthSuffix(count); String countString = count + UtilTime.getDayOfMonthSuffix(count);
String chatMessage = C.cRed + playerName + C.cDRed + " has become the " + C.cRed + countString + " Titan"; String chatMessage = C.cRed + playerName + C.cWhite + " has become the " + C.cRed + countString + " Titan ";
UtilTextMiddle.display("", chatMessage, UtilServer.getPlayers()); UtilTextMiddle.display(C.cDRed + C.Bold + "TITAN", chatMessage, 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);
for (Player player : UtilServer.getPlayers()) for (Player player : UtilServer.getPlayers())
{ {
player.sendMessage(chatMessage);
player.playSound(player.getEyeLocation(), Sound.AMBIENCE_CAVE, 1, 1); player.playSound(player.getEyeLocation(), Sound.AMBIENCE_CAVE, 1, 1);
} }
} }

View File

@ -0,0 +1,52 @@
package mineplex.core.titangiveaway;
import java.util.Random;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class LightFlicker extends BukkitRunnable
{
private static int MAX_TICKS = 100;
private World _world;
private Random _random;
private int _ticks;
private long _previousTime;
public LightFlicker(World world)
{
_world = world;
_random = new Random();
_ticks = 0;
_previousTime = world.getTime();
}
@Override
public void run()
{
if (_ticks >= MAX_TICKS)
{
_world.setTime(_previousTime);
cancel();
}
if (_ticks % 5 == 0)
{
long time = (long) (24000 * _random.nextDouble());
_world.setTime(time);
}
if (_ticks % 10 == 0)
{
for (Player player : _world.getPlayers())
{
player.playSound(player.getEyeLocation(), Sound.AMBIENCE_THUNDER, 1, 1);
}
}
_ticks++;
}
}

View File

@ -17,8 +17,8 @@ import mineplex.serverdata.commands.ServerCommandManager;
public class TitanGiveawayManager extends MiniPlugin public class TitanGiveawayManager extends MiniPlugin
{ {
// private static final double RANK_FIND_CHANCE = 0.001; private static final double RANK_FIND_CHANCE = 0.001;
private static final double RANK_FIND_CHANCE = 1; // private static final double RANK_FIND_CHANCE = 1;
private TitanGiveawayRepository _repository; private TitanGiveawayRepository _repository;
private CoreClientManager _clientManager; private CoreClientManager _clientManager;
@ -34,19 +34,17 @@ public class TitanGiveawayManager extends MiniPlugin
_statusManager = statusManager; _statusManager = statusManager;
_random = new Random(); _random = new Random();
ServerCommandManager.getInstance().registerCommandType("TitanGiveawayMessage", TitanGiveawayMessage.class, new GiveawayMessageHandler()); ServerCommandManager.getInstance().registerCommandType("TitanGiveawayMessage", TitanGiveawayMessage.class, new GiveawayMessageHandler(plugin));
} }
public void openPumpkin(final Player player, final Runnable onSuccess) public void openPumpkin(final Player player, final Runnable onSuccess)
{ {
double rand = _random.nextDouble(); double rand = _random.nextDouble();
System.out.println("a");
if (!hasTitan(player) && rand < RANK_FIND_CHANCE) if (!hasTitan(player) && rand < RANK_FIND_CHANCE)
{ {
final int accountId = _clientManager.getAccountId(player); final int accountId = _clientManager.getAccountId(player);
final Region region = getRegion(); final Region region = getRegion();
final String serverName = getServerName(); final String serverName = getServerName();
System.out.println("b");
// Need to check database that we can give away a rank // Need to check database that we can give away a rank
runAsync(new Runnable() runAsync(new Runnable()
@ -55,11 +53,9 @@ public class TitanGiveawayManager extends MiniPlugin
public void run() public void run()
{ {
final boolean pass = _repository.canGiveaway(); final boolean pass = _repository.canGiveaway();
System.out.println("c");
if (pass && _repository.addTitan(accountId, region, serverName)) if (pass && _repository.addTitan(accountId, region, serverName))
{ {
System.out.println("C");
runSync(new Runnable() runSync(new Runnable()
{ {
@Override @Override
@ -70,10 +66,8 @@ public class TitanGiveawayManager extends MiniPlugin
@Override @Override
public void run(Rank rank) public void run(Rank rank)
{ {
System.out.println("d");
if (rank == Rank.TITAN) if (rank == Rank.TITAN)
{ {
System.out.println("e");
TitanGiveawayMessage message = new TitanGiveawayMessage(player.getName(), _repository.getTitanCount() + 1); TitanGiveawayMessage message = new TitanGiveawayMessage(player.getName(), _repository.getTitanCount() + 1);
message.publish(); message.publish();
if (onSuccess != null) onSuccess.run(); if (onSuccess != null) onSuccess.run();
@ -112,13 +106,13 @@ public class TitanGiveawayManager extends MiniPlugin
_clientManager.getRepository().saveRank(callback, player.getName(), player.getUniqueId(), rank, true); _clientManager.getRepository().saveRank(callback, player.getName(), player.getUniqueId(), rank, true);
} }
@EventHandler // @EventHandler
public void onCommand(PlayerCommandPreprocessEvent event) // public void onCommand(PlayerCommandPreprocessEvent event)
{ // {
if (event.getMessage().contains("pumpkin")) // if (event.getMessage().contains("pumpkin"))
{ // {
openPumpkin(event.getPlayer(), null); // openPumpkin(event.getPlayer(), null);
event.setCancelled(true); // event.setCancelled(true);
} // }
} // }
} }