Fixed server pages to show 5 servers.

Added in creeper explode block list for UHC.java
Added task assignment/reward message only on return confirm call.
Hide players in hub when they have an inventory open.
Added gem command into donation manager.

Revamped bungee player count method.
Revamped server status method.
This commit is contained in:
Jonathan Williams 2013-09-17 15:50:23 -07:00
parent cc39abfd7f
commit f31a734a0d
27 changed files with 794 additions and 398 deletions

View File

@ -11,7 +11,6 @@ public class Mineplexer extends Plugin
{ {
private DynamicServer _dynamicServers; private DynamicServer _dynamicServers;
private LobbyBalancer _lobbyBalancer; private LobbyBalancer _lobbyBalancer;
private PlayerCount _playerCount;
@Override @Override
public void onEnable() public void onEnable()
@ -21,13 +20,12 @@ public class Mineplexer extends Plugin
_dynamicServers = new DynamicServer(this); _dynamicServers = new DynamicServer(this);
_lobbyBalancer = new LobbyBalancer(this); _lobbyBalancer = new LobbyBalancer(this);
_playerCount = new PlayerCount(this); new PlayerCount(this);
} }
public void ReloadServerLists() public void ReloadServerLists()
{ {
_dynamicServers.LoadServers(); _dynamicServers.LoadServers();
_lobbyBalancer.loadLobbyServers(); _lobbyBalancer.loadLobbyServers();
_playerCount.LoadBungeeServers();
} }
} }

View File

@ -1,19 +1,5 @@
package mineplex.bungee.playerCount; package mineplex.bungee.playerCount;
import java.io.BufferedReader;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.HashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import net.md_5.bungee.api.config.ListenerInfo; import net.md_5.bungee.api.config.ListenerInfo;
@ -25,285 +11,38 @@ import net.md_5.bungee.event.EventHandler;
public class PlayerCount implements Listener, Runnable public class PlayerCount implements Listener, Runnable
{ {
private Plugin _plugin; private Plugin _plugin;
private PlayerCountRepository _repository;
private HashMap<String, InetSocketAddress> _otherBungeeInstances;
private int _totalPlayers = -1; private int _totalPlayers = -1;
private int _totalMaxPlayers; private int _totalMaxPlayers;
private int _tempPlayers;
private int _tempMaxPlayers;
private static Object _serverLock = new Object();
public PlayerCount(Plugin plugin) public PlayerCount(Plugin plugin)
{ {
_plugin = plugin; _plugin = plugin;
_otherBungeeInstances = new HashMap<String, InetSocketAddress>();
LoadBungeeServers(); _plugin.getProxy().getScheduler().schedule(_plugin, this, 3L, 3L, TimeUnit.SECONDS);
_plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.SECONDS);
_plugin.getProxy().getPluginManager().registerListener(_plugin, this); _plugin.getProxy().getPluginManager().registerListener(_plugin, this);
ListenerInfo listenerInfo = _plugin.getProxy().getConfigurationAdapter().getListeners().iterator().next();
_repository = new PlayerCountRepository(listenerInfo.getHost().getAddress().getHostAddress() + ":" + listenerInfo.getHost().getPort(), listenerInfo.getMaxPlayers());
_repository.initialize();
} }
public void run() public void run()
{ {
_tempPlayers = _plugin.getProxy().getOnlineCount(); _repository.updatePlayerCountInDatabase(_plugin.getProxy().getOnlineCount());
_tempMaxPlayers = 0;
for(ListenerInfo li : _plugin.getProxy().getConfigurationAdapter().getListeners()) PlayerTotalData playerTotalData = _repository.retrievePlayerCount();
{
_tempMaxPlayers += li.getMaxPlayers();
}
synchronized (_serverLock)
{
for (InetSocketAddress address : _otherBungeeInstances.values())
{
try
{
UpdateServerCount(address);
} catch (IOException e)
{
e.printStackTrace();
}
}
}
_totalPlayers = _tempPlayers; _totalPlayers = playerTotalData.CurrentPlayers;
_totalMaxPlayers = _tempMaxPlayers; _totalMaxPlayers = playerTotalData.MaxPlayers;
} }
@EventHandler @EventHandler
public void ServerPing(ProxyPingEvent event) public void ServerPing(ProxyPingEvent event)
{ {
if (!_otherBungeeInstances.containsKey(event.getConnection().getAddress().getAddress().getHostAddress())) net.md_5.bungee.api.ServerPing serverPing = event.getResponse();
{ event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getProtocolVersion(), serverPing.getGameVersion(), serverPing.getMotd(), _totalPlayers, _totalMaxPlayers));
net.md_5.bungee.api.ServerPing serverPing = event.getResponse();
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getProtocolVersion(), serverPing.getGameVersion(), serverPing.getMotd(), _totalPlayers, _totalMaxPlayers));
}
} }
protected void UpdateServerCount(InetSocketAddress address) throws IOException
{
Socket socket = null;
DataInputStream dataInputStream = null;
DataOutputStream dataOutputStream = null;
try
{
socket = new Socket();
socket.setSoTimeout(5000);
socket.setTcpNoDelay(true);
socket.setTrafficClass(18);
socket.connect(address, 3000);
dataInputStream = new DataInputStream(socket.getInputStream());
dataOutputStream = new DataOutputStream(socket.getOutputStream());
dataOutputStream.writeByte(254);
dataOutputStream.writeByte(74);
dataOutputStream.writeByte(1);
dataOutputStream.writeByte(254);
writeString("MC|PingHost", dataOutputStream);
dataOutputStream.writeShort(3 + 2 * address.getAddress().getHostName().length() + 4);
dataOutputStream.writeByte(74);
writeString(address.getAddress().getHostName(), dataOutputStream);
dataOutputStream.writeInt(address.getPort());
if (dataInputStream.read() != 255)
{
System.out.println("Bad message");
return;
}
String var6 = readString(dataInputStream, 256);
String[] var27;
if (var6.startsWith("\u00a7") && var6.length() > 1)
{
var27 = var6.substring(1).split("\u0000");
_tempPlayers += Integer.parseInt(var27[4]);
_tempMaxPlayers += Integer.parseInt(var27[5]);
}
}
catch (SocketTimeoutException e)
{
;
}
catch (ConnectException e)
{
;
}
catch (IOException e)
{
System.out.println("[PlayerCount] Error pinging " + address.getHostName() + ":" + address.getPort());
throw e;
}
finally
{
try
{
if (dataInputStream != null)
{
dataInputStream.close();
}
}
catch (Exception exception)
{
;
}
try
{
if (dataOutputStream != null)
{
dataOutputStream.close();
}
}
catch (Exception exception)
{
;
}
try
{
if (socket != null)
{
socket.close();
}
}
catch (Exception exception)
{
;
}
}
}
public static void writeString(String par0Str, DataOutput par1DataOutput) throws IOException
{
if (par0Str.length() > 32767)
{
throw new IOException("String too big");
}
else
{
par1DataOutput.writeShort(par0Str.length());
par1DataOutput.writeChars(par0Str);
}
}
public static String readString(DataInput par0DataInput, int par1) throws IOException
{
short var2 = par0DataInput.readShort();
if (var2 > par1)
{
throw new IOException("Received string length longer than maximum allowed (" + var2 + " > " + par1 + ")");
}
else if (var2 < 0)
{
throw new IOException("Received string length is less than zero! Weird string!");
}
else
{
StringBuilder var3 = new StringBuilder();
for (int var4 = 0; var4 < var2; ++var4)
{
var3.append(par0DataInput.readChar());
}
return var3.toString();
}
}
public void LoadBungeeServers()
{
synchronized (_serverLock)
{
_otherBungeeInstances.clear();
}
FileInputStream fstream = null;
BufferedReader br = null;
try
{
File npcFile = new File("bungeeServers.dat");
if (npcFile.exists())
{
fstream = new FileInputStream(npcFile);
br = new BufferedReader(new InputStreamReader(fstream));
String line = br.readLine();
while (line != null)
{
String address = line.split(":")[0];
Integer port = Integer.parseInt(line.split(":")[1]);
InetSocketAddress socketAddress = new InetSocketAddress(address, port);
boolean addAddress = true;
for (ListenerInfo listenerInfo : _plugin.getProxy().getConfigurationAdapter().getListeners())
{
if (address.equalsIgnoreCase(listenerInfo.getHost().getAddress().getHostAddress()))
{
addAddress = false;
break;
}
}
if (addAddress)
{
synchronized (_serverLock)
{
_otherBungeeInstances.put(socketAddress.getAddress().getHostAddress(), socketAddress);
}
}
line = br.readLine();
}
}
else
{
npcFile.createNewFile();
}
}
catch (Exception e)
{
System.out.println("Error parsing bungeeServers file.");
}
finally
{
if (br != null)
{
try
{
br.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
if (fstream != null)
{
try
{
fstream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
} }

View File

@ -0,0 +1,189 @@
package mineplex.bungee.playerCount;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class PlayerCountRepository
{
private String _connectionString = "jdbc:mysql://sql.mineplex.com:3306/BungeeServers";
private String _userName = "root";
private String _password = "tAbechAk3wR7tuTh";
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS BungeeServers (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(256), updated LONG, players INT, maxPlayers INT, ram INT, maxRam INT, PRIMARY KEY (id));";
private static String INSERT_PLAYER_COUNT = "INSERT INTO BungeeServers values(default, ?, now(), ?, ?, ?, ?);";
private static String UPDATE_PLAYER_COUNT = "UPDATE BungeeServers SET updated = now(), players = ?, maxPlayers = ?, ram = ?, maxRam = ? WHERE id = ?;";
private static String RETRIEVE_ID = "SELECT id FROM BungeeServers WHERE address = ?;";
private static String RETRIEVE_PLAYER_COUNT = "SELECT SUM(players) AS playerCount, SUM(maxPlayers) AS maxPlayerCount FROM BungeeServers WHERE TIME_TO_SEC(TIMEDIFF(now(), BungeeServers.updated)) < 10;";
private int _id = -1;
private String _address;
private int _maxPlayers = 0;
public PlayerCountRepository(String address, int maxPlayers)
{
_address = address;
_maxPlayers = maxPlayers;
}
public void initialize()
{
Connection connection = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
// Retrieve id
PreparedStatement preparedStatementRetrieve = connection.prepareStatement(RETRIEVE_ID);
preparedStatementRetrieve.setString(1, _address);
ResultSet resultSet = preparedStatementRetrieve.executeQuery();
while (resultSet.next())
{
_id = resultSet.getInt("id");
System.out.println("id = " + _id);
}
// Insert if not there
if (_id == -1)
{
PreparedStatement preparedStatementInsert = connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatementInsert.setString(1, _address);
preparedStatementInsert.setInt(2, 0);
preparedStatementInsert.setInt(3, _maxPlayers);
preparedStatementInsert.setInt(4, (int) ((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) / 1048576));
preparedStatementInsert.setInt(5, (int) (Runtime.getRuntime().maxMemory() / 1048576));
int affectedRows = preparedStatementInsert.executeUpdate();
if (affectedRows == 0)
{
throw new SQLException("Creating bungee server failed, no rows affected.");
}
resultSet = preparedStatementInsert.getGeneratedKeys();
if (resultSet.next())
{
_id = resultSet.getInt(1);
System.out.println("id = " + _id);
}
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public boolean updatePlayerCountInDatabase(int players)
{
Connection connection = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setInt(1, players);
preparedStatement.setInt(2, _maxPlayers);
preparedStatement.setInt(3, (int) ((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) / 1048576));
preparedStatement.setInt(4, (int) (Runtime.getRuntime().maxMemory() / 1048576));
preparedStatement.setInt(5, _id);
int affectedRows = preparedStatement.executeUpdate();
if (affectedRows == 0)
{
throw new SQLException("Updating bungee server player count failed, no rows affected.");
}
return true;
}
catch (Exception exception)
{
exception.printStackTrace();
return false;
}
finally
{
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public PlayerTotalData retrievePlayerCount()
{
Connection connection = null;
PlayerTotalData playerData = new PlayerTotalData();
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_PLAYER_COUNT);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
playerData.CurrentPlayers = resultSet.getInt(1);
playerData.MaxPlayers = resultSet.getInt(2);
return playerData;
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return playerData;
}
}

View File

@ -0,0 +1,7 @@
package mineplex.bungee.playerCount;
public class PlayerTotalData
{
public int CurrentPlayers;
public int MaxPlayers;
}

View File

@ -1,5 +1,6 @@
package mineplex.core.donation; package mineplex.core.donation;
import mineplex.core.MiniPlugin;
import mineplex.core.account.event.ClientUnloadEvent; import mineplex.core.account.event.ClientUnloadEvent;
import mineplex.core.account.event.ClientWebResponseEvent; import mineplex.core.account.event.ClientWebResponseEvent;
import mineplex.core.common.CurrencyType; import mineplex.core.common.CurrencyType;
@ -12,12 +13,10 @@ import mineplex.core.server.util.TransactionResponse;
import org.bukkit.craftbukkit.libs.com.google.gson.Gson; import org.bukkit.craftbukkit.libs.com.google.gson.Gson;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class DonationManager implements Listener public class DonationManager extends MiniPlugin
{ {
private JavaPlugin _plugin;
private DonationRepository _repository; private DonationRepository _repository;
private NautHashMap<String, Donor> _donors; private NautHashMap<String, Donor> _donors;
@ -26,12 +25,17 @@ public class DonationManager implements Listener
public DonationManager(JavaPlugin plugin, String webAddress) public DonationManager(JavaPlugin plugin, String webAddress)
{ {
_plugin = plugin; super("Donation", plugin);
_repository = new DonationRepository(webAddress); _repository = new DonationRepository(webAddress);
_donors = new NautHashMap<String, Donor>(); _donors = new NautHashMap<String, Donor>();
}
_plugin.getServer().getPluginManager().registerEvents(this, _plugin);
@Override
public void AddCommands()
{
AddCommand(new GemCommand(this));
} }
@EventHandler @EventHandler
@ -124,7 +128,7 @@ public class DonationManager implements Listener
}, name, salesPackageId); }, name, salesPackageId);
} }
public void RewardGems(final String name, final int greenGems) public void RewardGems(final Callback<Boolean> callback, final String caller, final String name, final int greenGems)
{ {
_repository.PlayerUpdate(new Callback<PlayerUpdateToken>() _repository.PlayerUpdate(new Callback<PlayerUpdateToken>()
{ {
@ -136,6 +140,28 @@ public class DonationManager implements Listener
{ {
donor.AddGems(greenGems); donor.AddGems(greenGems);
} }
if (callback != null)
callback.run(true);
}
}, caller, name, greenGems);
}
public void RewardGems(final Callback<Boolean> callback, final String name, final int greenGems)
{
_repository.PlayerUpdate(new Callback<PlayerUpdateToken>()
{
public void run(PlayerUpdateToken token)
{
Donor donor = Get(name);
if (donor != null)
{
donor.AddGems(greenGems);
}
if (callback != null)
callback.run(true);
} }
}, name, greenGems); }, name, greenGems);
} }

View File

@ -0,0 +1,47 @@
package mineplex.core.donation;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
public class GemCommand extends CommandBase<DonationManager>
{
public GemCommand(DonationManager plugin)
{
super(plugin, Rank.ADMIN, "gem");
}
@Override
public void Execute(final Player caller, String[] args)
{
if (args.length < 2)
{
UtilPlayer.message(caller, F.main("Gem", "Missing Args"));
return;
}
final Player target = UtilPlayer.searchOnline(caller, args[0], true);
if (target == null) return;
try
{
final int gems = Integer.parseInt(args[1]);
Plugin.RewardGems(new Callback<Boolean>()
{
public void run(Boolean completed)
{
UtilPlayer.message(caller, F.main("Gem", "You gave " + F.elem(gems + " Gems") + " to " + F.name(target.getName()) + "."));
UtilPlayer.message(target, F.main("Gem", F.name(caller.getName()) + " gave you " + F.elem(gems + " Gems") + "."));
}
}, caller.getName(), target.getName(), gems);
}
catch (Exception e)
{
UtilPlayer.message(caller, F.main("Gem", "Invalid Gem Amount"));
}
}
}

View File

@ -44,4 +44,13 @@ public class DonationRepository
token.Gems = greenGems; token.Gems = greenGems;
new AsyncJsonWebCall(_webAddress + "PlayerAccount/PlayerUpdate").Execute(PlayerUpdateToken.class, callback, token); new AsyncJsonWebCall(_webAddress + "PlayerAccount/PlayerUpdate").Execute(PlayerUpdateToken.class, callback, token);
} }
public void PlayerUpdate(Callback<PlayerUpdateToken> callback, String giver, String name, int greenGems)
{
PlayerUpdateToken token = new PlayerUpdateToken();
token.Source = giver;
token.Name = name;
token.Gems = greenGems;
new AsyncJsonWebCall(_webAddress + "PlayerAccount/PlayerUpdate").Execute(PlayerUpdateToken.class, callback, token);
}
} }

View File

@ -2,6 +2,7 @@ package mineplex.core.donation.repository.token;
public class PlayerUpdateToken public class PlayerUpdateToken
{ {
public String Source;
public String Name; public String Name;
public int Gems; public int Gems;
public boolean FilterChat; public boolean FilterChat;

View File

@ -67,28 +67,27 @@ public class LagMeter extends MiniPlugin
@EventHandler @EventHandler
public void update(UpdateEvent event) public void update(UpdateEvent event)
{ {
if (event.getType() != UpdateType.TICK) if (event.getType() != UpdateType.SEC)
return; return;
if (_count % 20 == 0) long now = System.currentTimeMillis();
_ticksPerSecond = 1000D / (now - _lastRun) * 20D;
sendUpdates();
if (_count % 30 == 0)
{ {
_ticksPerSecond = (1000D / (System.currentTimeMillis() - _lastRun)) * 20D; _ticksPerSecondAverage = 30000D / (now - _lastAverage) * 20D;
_ticksPerSecond = 0;
sendUpdates(); _lastAverage = now;
_lastRun = System.currentTimeMillis();
} }
if (_count % 600 == 0) _lastRun = now;
{
_ticksPerSecondAverage = 30000D / (System.currentTimeMillis() - _lastAverage);
_ticksPerSecond = 0;
_lastAverage = System.currentTimeMillis();
}
_count++; _count++;
} }
public double GetTicksPerSecond() public double getTicksPerSecond()
{ {
return _ticksPerSecond; return _ticksPerSecond;
} }

View File

@ -0,0 +1,9 @@
package mineplex.core.status;
public class ServerStatusData
{
public String Name;
public String Motd;
public int Players;
public int MaxPlayers;
}

View File

@ -0,0 +1,110 @@
package mineplex.core.status;
import java.io.File;
import java.net.InetAddress;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.server.ServerListPingEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.Callback;
import mineplex.core.monitor.LagMeter;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class ServerStatusManager extends MiniPlugin
{
private ServerStatusRepository _repository;
private LagMeter _lagMeter;
private boolean _alternateSeconds;
public ServerStatusManager(JavaPlugin plugin, LagMeter lagMeter)
{
super("Server Status Manager", plugin);
_lagMeter = lagMeter;
ServerListPingEvent event = new ServerListPingEvent(null, plugin.getServer().getMotd(), plugin.getServer().getOnlinePlayers().length, plugin.getServer().getMaxPlayers());
GetPluginManager().callEvent(event);
loadServerTrackerValues();
try
{
_repository = new ServerStatusRepository(plugin.getConfig().getString("serverstatus.name"), plugin.getConfig().getString("serverstatus.group"), InetAddress.getLocalHost().getHostAddress() + ":" + _plugin.getServer().getPort(), event.getMaxPlayers());
_repository.initialize();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
private void loadServerTrackerValues()
{
FileConfiguration yamlConfig = new YamlConfiguration();
File serverTrackerConfig = new File("plugins/ServerTracker/config.yml");
try
{
yamlConfig.load(serverTrackerConfig);
GetPlugin().getConfig().addDefault("serverstatus.name", yamlConfig.get("servertracker.informations.name"));
GetPlugin().getConfig().set("serverstatus.name", GetPlugin().getConfig().getString("serverstatus.name"));
GetPlugin().getConfig().addDefault("serverstatus.group", yamlConfig.get("servertracker.informations.group"));
GetPlugin().getConfig().set("serverstatus.group", GetPlugin().getConfig().getString("serverstatus.group"));
GetPlugin().saveConfig();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void retrieveServerStatuses(final Callback<List<ServerStatusData>> callback)
{
GetPlugin().getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
if (callback != null)
{
callback.run(_repository.retrieveServerStatuses());
}
}
});
}
@EventHandler
public void saveServerStatus(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
_alternateSeconds = !_alternateSeconds;
if (!_alternateSeconds)
return;
final ServerListPingEvent listPingEvent = new ServerListPingEvent(null, GetPlugin().getServer().getMotd(), GetPlugin().getServer().getOnlinePlayers().length, GetPlugin().getServer().getMaxPlayers());
GetPluginManager().callEvent(listPingEvent);
GetPlugin().getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
_repository.updatePlayerCountInDatabase(listPingEvent.getMotd(), Bukkit.getOnlinePlayers().length, (int)_lagMeter.getTicksPerSecond());
}
});
}
}

View File

@ -0,0 +1,207 @@
package mineplex.core.status;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class ServerStatusRepository
{
private String _connectionString = "jdbc:mysql://sql.mineplex.com:3306/ServerStatus";
private String _userName = "root";
private String _password = "tAbechAk3wR7tuTh";
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS ServerStatus (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(256), serverGroup VARCHAR(256), address VARCHAR(256), updated LONG, motd VARCHAR(256), players INT, maxPlayers INT, tps INT, ram INT, maxRam INT, PRIMARY KEY (id));";
private static String INSERT_PLAYER_COUNT = "INSERT INTO ServerStatus values(default, ?, ?, ?, now(), 'Configuring server.', ?, ?, 0, ?, ?);";
private static String UPDATE_PLAYER_COUNT = "UPDATE ServerStatus SET updated = now(), serverName = ?, serverGroup = ?, motd = ?, players = ?, maxPlayers = ?, tps = ?, ram = ?, maxRam = ? WHERE id = ?;";
private static String RETRIEVE_ID = "SELECT id FROM ServerStatus WHERE address = ?;";
private static String RETRIEVE_SERVER_STATUSES = "SELECT serverName, motd, players, maxPlayers FROM ServerStatus WHERE TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) < 10;";
private int _id = -1;
private String _serverName;
private String _serverGroup;
private String _address;
private int _maxPlayers = 0;
public ServerStatusRepository(String serverName, String serverGroup, String address, int maxPlayers)
{
_serverName = serverName;
_serverGroup = serverGroup;
_address = address;
_maxPlayers = maxPlayers;
}
public void initialize()
{
Connection connection = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
PreparedStatement preparedStatement = connection.prepareStatement(CREATE_TABLE);
preparedStatement.execute();
// Retrieve id
PreparedStatement preparedStatementRetrieve = connection.prepareStatement(RETRIEVE_ID);
preparedStatementRetrieve.setString(1, _address);
ResultSet resultSet = preparedStatementRetrieve.executeQuery();
while (resultSet.next())
{
_id = resultSet.getInt("id");
}
// Insert if not there
if (_id == -1)
{
PreparedStatement preparedStatementInsert = connection.prepareStatement(INSERT_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatementInsert.setString(1, _serverName);
preparedStatementInsert.setString(2, _serverGroup);
preparedStatementInsert.setString(3, _address);
preparedStatementInsert.setInt(4, 0);
preparedStatementInsert.setInt(5, _maxPlayers);
preparedStatementInsert.setInt(6, (int) ((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) / 1048576));
preparedStatementInsert.setInt(7, (int) (Runtime.getRuntime().maxMemory() / 1048576));
int affectedRows = preparedStatementInsert.executeUpdate();
if (affectedRows == 0)
{
throw new SQLException("Creating server status failed, no rows affected.");
}
resultSet = preparedStatementInsert.getGeneratedKeys();
if (resultSet.next())
{
_id = resultSet.getInt(1);
}
}
// Update stoof
updatePlayerCountInDatabase("Configuring server.", 0, 20);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public boolean updatePlayerCountInDatabase(String motd, int players, int tps)
{
Connection connection = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_PLAYER_COUNT, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setString(1, _serverName);
preparedStatement.setString(2, _serverGroup);
preparedStatement.setString(3, motd);
preparedStatement.setInt(4, players);
preparedStatement.setInt(5, _maxPlayers);
preparedStatement.setInt(6, tps);
preparedStatement.setInt(7, (int) ((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) / 1048576));
preparedStatement.setInt(8, (int) (Runtime.getRuntime().maxMemory() / 1048576));
preparedStatement.setInt(9, _id);
int affectedRows = preparedStatement.executeUpdate();
if (affectedRows == 0)
{
throw new SQLException("Updating server status failed, no rows affected.");
}
return true;
}
catch (Exception exception)
{
exception.printStackTrace();
return false;
}
finally
{
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public List<ServerStatusData> retrieveServerStatuses()
{
Connection connection = null;
List<ServerStatusData> serverData = new ArrayList<ServerStatusData>();
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
PreparedStatement preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
ServerStatusData serverStatusData = new ServerStatusData();
serverStatusData.Name = resultSet.getString(1);
serverStatusData.Motd = resultSet.getString(2);
serverStatusData.Players = resultSet.getInt(3);
serverStatusData.MaxPlayers = resultSet.getInt(4);
serverData.add(serverStatusData);
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return serverData;
}
}

View File

@ -67,7 +67,7 @@ public class Enjin extends MiniPlugin implements CommandExecutor
String name = args[1]; String name = args[1];
int amount = Integer.parseInt(args[2]); int amount = Integer.parseInt(args[2]);
_donationManager.RewardGems(name, amount); _donationManager.RewardGems(null, name, amount);
System.out.println("enjin gem"); System.out.println("enjin gem");
} }
else if (args.length == 4 && args[0].equalsIgnoreCase("rank")) else if (args.length == 4 && args[0].equalsIgnoreCase("rank"))

View File

@ -11,6 +11,7 @@ import mineplex.core.donation.DonationManager;
import mineplex.core.energy.Energy; import mineplex.core.energy.Energy;
import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.message.MessageManager; import mineplex.core.message.MessageManager;
import mineplex.core.monitor.LagMeter;
import mineplex.core.movement.Movement; import mineplex.core.movement.Movement;
import mineplex.core.npc.NpcManager; import mineplex.core.npc.NpcManager;
import mineplex.core.packethandler.PacketHandler; import mineplex.core.packethandler.PacketHandler;
@ -20,6 +21,7 @@ import mineplex.core.projectile.ProjectileManager;
import mineplex.core.punish.Punish; import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.spawn.Spawn; import mineplex.core.spawn.Spawn;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.task.TaskManager; import mineplex.core.task.TaskManager;
import mineplex.core.teleport.Teleport; import mineplex.core.teleport.Teleport;
import mineplex.core.updater.FileUpdater; import mineplex.core.updater.FileUpdater;
@ -56,14 +58,15 @@ public class Hub extends JavaPlugin implements INautilusPlugin, IRelation
saveConfig(); saveConfig();
//Core Modules //Core Modules
CoreClientManager clientManager = CoreClientManager.Initialize(this, GetWebServerAddress()); CoreClientManager clientManager = CoreClientManager.Initialize(this, GetWebServerAddress());
DonationManager donationManager = new DonationManager(this, GetWebServerAddress());
//Static Modules //Static Modules
CommandCenter.Initialize(this, clientManager); CommandCenter.Initialize(this, clientManager);
ItemStackFactory.Initialize(this, false); ItemStackFactory.Initialize(this, false);
Recharge.Initialize(this); Recharge.Initialize(this);
DonationManager donationManager = new DonationManager(this, GetWebServerAddress());
//Other Modules //Other Modules
new Punish(this, GetWebServerAddress()); new Punish(this, GetWebServerAddress());
Creature creature = new Creature(this); Creature creature = new Creature(this);
@ -77,11 +80,10 @@ public class Hub extends JavaPlugin implements INautilusPlugin, IRelation
PartyManager partyManager = new PartyManager(this, clientManager); PartyManager partyManager = new PartyManager(this, clientManager);
new HubManager(this, clientManager, donationManager, new DisguiseManager(this, packetHandler), new TaskManager(this, GetWebServerAddress()), portal, partyManager); new HubManager(this, clientManager, donationManager, new DisguiseManager(this, packetHandler), new TaskManager(this, GetWebServerAddress()), portal, partyManager);
new Stacker(this); new Stacker(this);
new ServerManager(this, clientManager, donationManager, portal, partyManager); new ServerManager(this, clientManager, donationManager, portal, partyManager, new ServerStatusManager(this, new LagMeter(this, clientManager)));
new Chat(this, clientManager); new Chat(this, clientManager);
new MemoryFix(this); new MemoryFix(this);
new FileUpdater(this, portal); new FileUpdater(this, portal);
//new LagMeter(this, clientManager);
CombatManager combatManager = new CombatManager(this); CombatManager combatManager = new CombatManager(this);
BlockRestore blockRestore = new BlockRestore(this); BlockRestore blockRestore = new BlockRestore(this);

View File

@ -37,6 +37,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerDropItemEvent;
@ -673,7 +674,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
if (player.equals(other)) if (player.equals(other))
continue; continue;
if (UtilMath.offset(player.getLocation(), GetSpawn()) < 4 || _tutorialManager.InTutorial(other) || _tutorialManager.InTutorial(player)) if (UtilMath.offset(player.getLocation(), GetSpawn()) < 4 || _tutorialManager.InTutorial(other) || _tutorialManager.InTutorial(player) || player.getOpenInventory().getType() != InventoryType.CRAFTING)
{ {
((CraftPlayer)other).hidePlayer(player, true, false); ((CraftPlayer)other).hidePlayer(player, true, false);
} }

View File

@ -13,6 +13,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -30,6 +31,7 @@ import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -38,6 +40,8 @@ import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
import mineplex.core.status.ServerStatusData;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.party.Party; import mineplex.hub.party.Party;
@ -52,6 +56,7 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
private DonationManager _donationManager; private DonationManager _donationManager;
private Portal _portal; private Portal _portal;
private PartyManager _partyManager; private PartyManager _partyManager;
private ServerStatusManager _statusManager;
private NautHashMap<String, HashSet<ServerInfo>> _serverNpcMap = new NautHashMap<String, HashSet<ServerInfo>>(); private NautHashMap<String, HashSet<ServerInfo>> _serverNpcMap = new NautHashMap<String, HashSet<ServerInfo>>();
private NautHashMap<String, ServerNpcShop> _serverNpcShopMap = new NautHashMap<String, ServerNpcShop>(); private NautHashMap<String, ServerNpcShop> _serverNpcShopMap = new NautHashMap<String, ServerNpcShop>();
@ -61,8 +66,10 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
private ServerNpcShop _quickShop; private ServerNpcShop _quickShop;
private boolean _loading = false; private boolean _loading = false;
private boolean _alternateUpdateFire = false;
private boolean _retrieving = false;
public ServerManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, Portal portal, PartyManager partyManager) public ServerManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, Portal portal, PartyManager partyManager, ServerStatusManager statusManager)
{ {
super("Server Manager", plugin); super("Server Manager", plugin);
@ -70,6 +77,7 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
_donationManager = donationManager; _donationManager = donationManager;
_portal = portal; _portal = portal;
_partyManager = partyManager; _partyManager = partyManager;
_statusManager = statusManager;
plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord"); plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord");
plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeSigns"); plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeSigns");
@ -251,7 +259,7 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
if (event.getType() != UpdateType.FAST) if (event.getType() != UpdateType.FAST)
return; return;
_quickShop.UpdatePages(); //_quickShop.UpdatePages();
for (ServerNpcShop shop : _serverNpcShopMap.values()) for (ServerNpcShop shop : _serverNpcShopMap.values())
{ {
@ -262,38 +270,61 @@ public class ServerManager extends MiniPlugin implements PluginMessageListener
@EventHandler @EventHandler
public void updateServers(UpdateEvent event) public void updateServers(UpdateEvent event)
{ {
if (event.getType() != UpdateType.SEC) if (event.getType() != UpdateType.SEC || _retrieving)
return; return;
if (Bukkit.getServer().getOnlinePlayers().length > 0) _alternateUpdateFire = !_alternateUpdateFire;
if (!_alternateUpdateFire)
return;
_retrieving = true;
_statusManager.retrieveServerStatuses(new Callback<List<ServerStatusData>>()
{ {
for (String serverName : _serverInfoMap.keySet()) public void run(List<ServerStatusData> serverStatusList)
{ {
ByteArrayOutputStream b = new ByteArrayOutputStream(); for (ServerStatusData serverStatus : serverStatusList)
DataOutputStream out = new DataOutputStream(b);
try
{ {
out.writeUTF(serverName); if (_serverInfoMap.containsKey(serverStatus.Name))
} {
catch (IOException e) String[] args = serverStatus.Motd.split("\\|");
{
e.printStackTrace(); ServerInfo serverInfo = _serverInfoMap.get(serverStatus.Name);
} serverInfo.MOTD = args.length > 0 ? args[0] : serverStatus.Motd;
serverInfo.CurrentPlayers = serverStatus.Players;
Bukkit.getServer().getOnlinePlayers()[0].sendPluginMessage(GetPlugin(), "BungeeSigns", b.toByteArray()); serverInfo.MaxPlayers = serverStatus.MaxPlayers;
if (_serverUpdate.get(serverName) != -1L && System.currentTimeMillis() - _serverUpdate.get(serverName) > 5000) if (args.length > 1)
{ serverInfo.ServerType = args[1];
ServerInfo serverInfo = _serverInfoMap.get(serverName);
serverInfo.MOTD = ChatColor.DARK_RED + "OFFLINE"; if (args.length > 2)
serverInfo.CurrentPlayers = 0; serverInfo.Game = args[2];
serverInfo.MaxPlayers = 0;
if (args.length > 3)
serverInfo.Map = args[3];
_serverUpdate.put(serverStatus.Name, System.currentTimeMillis());
}
_serverUpdate.put(serverName, -1L); for (String name : _serverUpdate.keySet())
{
if (_serverUpdate.get(name) != -1L && System.currentTimeMillis() - _serverUpdate.get(name) > 5000)
{
ServerInfo serverInfo = _serverInfoMap.get(name);
serverInfo.MOTD = ChatColor.DARK_RED + "OFFLINE";
serverInfo.CurrentPlayers = 0;
serverInfo.MaxPlayers = 0;
_serverUpdate.put(name, -1L);
}
}
} }
// Reset
_retrieving = false;
} }
} });
} }
public void Help(Player caller, String message) public void Help(Player caller, String message)

View File

@ -59,7 +59,7 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop>
} }
} }
int slot = 9; int slot = 10;
int greenCount = 0; int greenCount = 0;
int yellowCount = 0; int yellowCount = 0;
String openFull = ChatColor.RESET + C.Line + "Get Ultra to join full servers!"; String openFull = ChatColor.RESET + C.Line + "Get Ultra to join full servers!";
@ -67,7 +67,9 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop>
for (ServerInfo serverInfo : serverList) for (ServerInfo serverInfo : serverList)
{ {
String inProgress = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? (ChatColor.RESET + C.Line + "Game in progress.") : (ChatColor.RESET + C.Line + "Click to spectate and wait for next game!"); String inProgress = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? (ChatColor.RESET + C.Line + "Game in progress.") : (ChatColor.RESET + C.Line + "Click to spectate");
String inProgressLine2 = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? null : (ChatColor.RESET + C.Line + "and wait for next game!");
Material status = Material.REDSTONE_BLOCK; Material status = Material.REDSTONE_BLOCK;
List<String> lore = new ArrayList<String>(); List<String> lore = new ArrayList<String>();
@ -79,7 +81,7 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop>
if (greenCount > 0 && serverInfo.MaxPlayers == serverInfo.CurrentPlayers) if (greenCount > 0 && serverInfo.MaxPlayers == serverInfo.CurrentPlayers)
continue; continue;
slot += 2; slot += 1;
status = Material.EMERALD_BLOCK; status = Material.EMERALD_BLOCK;
lore.add(ChatColor.RESET + ""); lore.add(ChatColor.RESET + "");
@ -135,10 +137,20 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop>
if (!Client.GetRank().Has(Rank.ULTRA)) if (!Client.GetRank().Has(Rank.ULTRA))
lore.add(openFull); lore.add(openFull);
else else
{
lore.add(inProgress); lore.add(inProgress);
if (inProgressLine2 != null)
lore.add(inProgressLine2);
}
} }
else else
{
lore.add(inProgress); lore.add(inProgress);
if (inProgressLine2 != null)
lore.add(inProgressLine2);
}
yellowCount++; yellowCount++;
} }
@ -165,7 +177,6 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop>
{ {
ButtonMap.clear(); ButtonMap.clear();
BuildPage(); BuildPage();
System.out.println("Updated " + Player.getName() + "'s page.");
} }
public void SelectServer(Player player, ServerInfo serverInfo) public void SelectServer(Player player, ServerInfo serverInfo)

View File

@ -14,6 +14,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
@ -100,13 +101,13 @@ public class TutorialManager extends MiniPlugin
if (event.getType() != UpdateType.TICK) if (event.getType() != UpdateType.TICK)
return; return;
for (Tutorial tut : _tutorials) for (final Tutorial tut : _tutorials)
{ {
Iterator<Player> tuteIterator = tut.GetTutorial().keySet().iterator(); Iterator<Player> tuteIterator = tut.GetTutorial().keySet().iterator();
while (tuteIterator.hasNext()) while (tuteIterator.hasNext())
{ {
Player player = tuteIterator.next(); final Player player = tuteIterator.next();
TutorialData data = tut.GetTutorial().get(player); TutorialData data = tut.GetTutorial().get(player);
//Check if Phase Completed //Check if Phase Completed
@ -125,18 +126,20 @@ public class TutorialManager extends MiniPlugin
//Inform //Inform
UtilPlayer.message(player, F.main("Tutorial", "You completed " + F.elem(tut.GetTutName()) + ".")); UtilPlayer.message(player, F.main("Tutorial", "You completed " + F.elem(tut.GetTutName()) + "."));
//Gems (Not Completed Yet) //Gems
if (!_taskManager.hasCompletedTask(player, tut.GetTask())) if (!_taskManager.hasCompletedTask(player, tut.GetTask()))
{ {
_donationManager.RewardGems(player.getName(), tut.GetGems()); _donationManager.RewardGems(new Callback<Boolean>()
UtilPlayer.message(player, F.main("Tutorial", "You received " + F.elem(C.cGreen + tut.GetGems() + " Gems") + ".")); {
public void run(Boolean completed)
{
UtilPlayer.message(player, F.main("Tutorial", "You received " + F.elem(C.cGreen + tut.GetGems() + " Gems") + "."));
_taskManager.completedTask(player, tut.GetTask());
//Sound
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
}
}, player.getName(), tut.GetGems());
} }
//Set Completed
_taskManager.completedTask(player, tut.GetTask());
//Sound
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
} }
} }
} }

View File

@ -35,6 +35,7 @@ import mineplex.core.projectile.ProjectileManager;
import mineplex.core.punish.Punish; import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.spawn.Spawn; import mineplex.core.spawn.Spawn;
import mineplex.core.status.ServerStatusManager;
import mineplex.core.teleport.Teleport; import mineplex.core.teleport.Teleport;
import mineplex.core.updater.FileUpdater; import mineplex.core.updater.FileUpdater;
import mineplex.core.updater.Updater; import mineplex.core.updater.Updater;
@ -95,11 +96,12 @@ public class Arcade extends JavaPlugin implements INautilusPlugin, IPlugin
GetModules(); GetModules();
_clientManager = CoreClientManager.Initialize(this, GetWebServerAddress()); _clientManager = CoreClientManager.Initialize(this, GetWebServerAddress());
_donationManager = new DonationManager(this, GetWebServerAddress());
CommandCenter.Initialize(this, _clientManager); CommandCenter.Initialize(this, _clientManager);
ItemStackFactory.Initialize(this, false); ItemStackFactory.Initialize(this, false);
Recharge.Initialize(this); Recharge.Initialize(this);
_donationManager = new DonationManager(this, GetWebServerAddress());
ConditionManager conditionManager = new ConditionManager(this); ConditionManager conditionManager = new ConditionManager(this);
new MessageManager(this, _clientManager); new MessageManager(this, _clientManager);
@ -110,7 +112,7 @@ public class Arcade extends JavaPlugin implements INautilusPlugin, IPlugin
GetSpawn(); GetSpawn();
GetTeleport(); GetTeleport();
new FileUpdater(this, new Portal(this)); new FileUpdater(this, new Portal(this));
new LagMeter(this, _clientManager); new ServerStatusManager(this, new LagMeter(this, _clientManager));
PacketHandler packetHandler = new PacketHandler(this); PacketHandler packetHandler = new PacketHandler(this);
DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler); DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler);

View File

@ -45,6 +45,7 @@ import mineplex.core.common.util.*;
import mineplex.core.creature.Creature; import mineplex.core.creature.Creature;
import mineplex.core.disguise.DisguiseManager; import mineplex.core.disguise.DisguiseManager;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.donation.GemCommand;
import mineplex.core.packethandler.PacketHandler; import mineplex.core.packethandler.PacketHandler;
import mineplex.core.explosion.Explosion; import mineplex.core.explosion.Explosion;
import mineplex.core.portal.Portal; import mineplex.core.portal.Portal;
@ -152,7 +153,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
{ {
AddCommand(new GameCommand(this)); AddCommand(new GameCommand(this));
AddCommand(new ParseCommand(this)); AddCommand(new ParseCommand(this));
AddCommand(new GemCommand(this));
AddCommand(new WriteCommand(this)); AddCommand(new WriteCommand(this));
} }

View File

@ -1,46 +0,0 @@
package nautilus.game.arcade.command;
import org.bukkit.entity.Player;
import nautilus.game.arcade.ArcadeManager;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
public class GemCommand extends CommandBase<ArcadeManager>
{
public GemCommand(ArcadeManager plugin)
{
super(plugin, Rank.OWNER, "gem");
}
@Override
public void Execute(Player caller, String[] args)
{
if (!caller.getName().equals("Chiss"))
return;
if (args.length < 2)
{
UtilPlayer.message(caller, F.main("Gem", "Missing Args"));
return;
}
Player target = UtilPlayer.searchOnline(caller, args[0], true);
if (target == null) return;
try
{
int gems = Integer.parseInt(args[1]);
Plugin.GetDonation().RewardGems(target.getName(), gems);
UtilPlayer.message(caller, F.main("Gem", "You gave " + F.elem(gems + " Blue/Green Gems") + " to " + F.name(target.getName()) + "."));
UtilPlayer.message(target, F.main("Gem", F.name(caller.getName()) + " gave you " + F.elem(gems + " Blue/Green Gems") + "."));
}
catch (Exception e)
{
UtilPlayer.message(caller, F.main("Gem", "Invalid Gem Amount"));
}
}
}

View File

@ -25,6 +25,7 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
@ -437,7 +438,7 @@ public class UHC extends TeamGame
if (event.getEntity() instanceof Ghast) if (event.getEntity() instanceof Ghast)
{ {
event.getDrops().clear(); event.getDrops().clear();
event.getDrops().add(ItemStackFactory.Instance.CreateStack(Material.GOLD_INGOT, 1 + UtilMath.r(6))); event.getDrops().add(ItemStackFactory.Instance.CreateStack(Material.GOLD_INGOT, 1));
} }
} }
@ -1024,7 +1025,19 @@ public class UHC extends TeamGame
} }
} }
} }
@EventHandler(priority = EventPriority.LOWEST)
public void clearCreeperExplode(EntityExplodeEvent event)
{
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void clearCreeperExplodeReenable(EntityExplodeEvent event)
{
event.setCancelled(false);
}
@EventHandler @EventHandler
public void SpecialCloak(UpdateEvent event) public void SpecialCloak(UpdateEvent event)
{ {

View File

@ -139,7 +139,7 @@ public class GameGemManager implements Listener
if (Manager.GetClients().Get(player).GetRank().Has(Rank.ULTRA) || Manager.GetDonation().Get(player.getName()).OwnsUnknownPackage(Manager.GetServerConfig().ServerType + " ULTRA")) if (Manager.GetClients().Get(player).GetRank().Has(Rank.ULTRA) || Manager.GetDonation().Get(player.getName()).OwnsUnknownPackage(Manager.GetServerConfig().ServerType + " ULTRA"))
total = total * 2; total = total * 2;
Manager.GetDonation().RewardGems(player.getName(), total); Manager.GetDonation().RewardGems(null, player.getName(), total);
} }
public void AnnounceGems(Game game, Player player, HashMap<String,GemData> gems, boolean give) public void AnnounceGems(Game game, Player player, HashMap<String,GemData> gems, boolean give)

View File

@ -69,6 +69,7 @@
<Compile Include="Model\Account\MacAddress.cs" /> <Compile Include="Model\Account\MacAddress.cs" />
<Compile Include="Model\Account\RemovedPunishment.cs" /> <Compile Include="Model\Account\RemovedPunishment.cs" />
<Compile Include="Model\Sales\AccountTransaction.cs" /> <Compile Include="Model\Sales\AccountTransaction.cs" />
<Compile Include="Model\Sales\AccountGemTransaction.cs" />
<Compile Include="Model\Server\GameServer\CaptureThePig\Stats\CaptureThePigGameStatsToken.cs" /> <Compile Include="Model\Server\GameServer\CaptureThePig\Stats\CaptureThePigGameStatsToken.cs" />
<Compile Include="Model\Server\GameServer\CaptureThePig\Stats\CaptureThePigPlayerStatsToken.cs" /> <Compile Include="Model\Server\GameServer\CaptureThePig\Stats\CaptureThePigPlayerStatsToken.cs" />
<Compile Include="Model\Server\GameServer\Dominate\Stats\DominatePlayerStatsToken.cs" /> <Compile Include="Model\Server\GameServer\Dominate\Stats\DominatePlayerStatsToken.cs" />

View File

@ -0,0 +1,15 @@
namespace LOC.Core.Model.Server
{
public class AccountGemTransaction
{
public int AccountGemTransactionId { get; set; }
public string Source { get; set; }
public string Reason { get; set; }
public bool Earned { get; set; }
public Account.Account Account { get; set; }
}
}

View File

@ -4,6 +4,7 @@
using System.Web.Mvc; using System.Web.Mvc;
using Common; using Common;
using Common.Models; using Common.Models;
using Core.Model.Server;
using Core.Tokens; using Core.Tokens;
using Core.Tokens.Client; using Core.Tokens.Client;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -146,6 +147,27 @@
return Content(json, "application/json"); return Content(json, "application/json");
} }
[HttpPost]
public ActionResult GemReward(GemRewardToken token)
{
var account = _accountAdministrator.GetAccountByName(token.Name);
account.Gems += token.Gems;
var accountGemTransaction = new AccountGemTransaction
{
Account = account,
Earned = token.Earned,
Reason = token.Reason,
Source = token.Source
};
_accountAdministrator.UpdateAccount(account);
var json = JsonConvert.SerializeObject(token);
return Content(json, "application/json");
}
[HttpPost] [HttpPost]
public ActionResult RankUpdate(RankUpdateToken token) public ActionResult RankUpdate(RankUpdateToken token)
{ {

Binary file not shown.