Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex

Conflicts:
	Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/titangiveaway/TitanGiveawayRepository.java
This commit is contained in:
Cheese 2015-10-10 17:34:17 +11:00
commit 7bc3b4970b
15 changed files with 381 additions and 88 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

@ -24,7 +24,7 @@ public class BenefitManagerRepository extends RepositoryBase
@Override
protected void initialize()
{
executeUpdate(CREATE_BENEFIT_TABLE);
//executeUpdate(CREATE_BENEFIT_TABLE);
}
@Override

View File

@ -47,9 +47,11 @@ This will be used to determine if staff are handling
@Override
protected void initialize()
{
/*
executeUpdate(CREATE_TICKET_TABLE);
executeUpdate(CREATE_HANDLER_TABLE);
executeUpdate(CREATE_REPORTERS_TABLE);
*/
}
@Override

View File

@ -0,0 +1,47 @@
package mineplex.core.titangiveaway;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
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
{
private JavaPlugin _plugin;
public GiveawayMessageHandler(JavaPlugin plugin)
{
_plugin = plugin;
}
@Override
public void run(ServerCommand command)
{
if (command instanceof TitanGiveawayMessage)
{
TitanGiveawayMessage message = ((TitanGiveawayMessage) command);
String playerName = message.getPlayerName();
int count = message.getTitanCount();
String countString = count + UtilTime.getDayOfMonthSuffix(count);
String chatMessage = C.cRed + playerName + C.cWhite + " has become the " + C.cRed + countString + " Titan ";
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())
{
player.sendMessage(chatMessage);
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

@ -0,0 +1,118 @@
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(plugin));
}
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().contains("pumpkin"))
// {
// openPumpkin(event.getPlayer(), null);
// event.setCancelled(true);
// }
// }
}

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

@ -31,7 +31,7 @@ public class PasswordRepository extends RepositoryBase
@Override
protected void initialize()
{
executeUpdate(CREATE_SERVER_PASSWORD_TABLE);
//executeUpdate(CREATE_SERVER_PASSWORD_TABLE);
}
@Override

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