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

This commit is contained in:
CoderTim 2014-07-25 18:33:34 -04:00
commit c747638303
24 changed files with 570 additions and 310 deletions

View File

@ -45,6 +45,8 @@ public class LobbyBalancer implements Listener, Runnable
if (!event.getTarget().getName().equalsIgnoreCase("Lobby"))
return;
boolean sort = false;
synchronized (_serverLock)
{
if (_playersSentToBestServer >= _maxPlayersToSendToBestServer)
@ -64,6 +66,11 @@ public class LobbyBalancer implements Listener, Runnable
{
_bestServerIndex = 0;
_maxPlayersToSendToBestServer = 1;
// Since we had to enter our dangerzone, update local data so if we have to enter it again we don't pick the same server over and over
_sortedLobbies.get(_bestServerIndex).Players += 5;
sort = true;
}
}
@ -71,6 +78,10 @@ public class LobbyBalancer implements Listener, Runnable
event.setTarget(_plugin.getProxy().getServerInfo(_sortedLobbies.get(_bestServerIndex).Name));
_playersSentToBestServer++;
// Only if we had to pick default regardless of the buffer safezone
if (sort)
Collections.sort(_sortedLobbies, new LobbySorter());
}
}
@ -81,8 +92,6 @@ public class LobbyBalancer implements Listener, Runnable
public void loadLobbyServers()
{
_playersSentToBestServer = 0;
List<ServerStatusData> serverStatusDataList = _repository.retrieveServerStatuses();
synchronized (_serverLock)
@ -108,6 +117,7 @@ public class LobbyBalancer implements Listener, Runnable
Collections.sort(_sortedLobbies, new LobbySorter());
_playersSentToBestServer = 0;
_bestServerIndex = 0;
if (_sortedLobbies.size() > 0)

View File

@ -13,12 +13,6 @@ public class LobbySorter implements Comparator<ServerStatusData>
if (first.Players == 999)
return 1;
if (first.MaxPlayers - first.Players > 15 && second.MaxPlayers - second.Players <= 15)
return -1;
if (second.MaxPlayers - second.Players > 15 && first.MaxPlayers - first.Players <= 15)
return 1;
if (first.Players < (first.MaxPlayers / 2) && second.Players >= (second.MaxPlayers / 2))
return -1;
@ -44,7 +38,9 @@ public class LobbySorter implements Comparator<ServerStatusData>
if (Integer.parseInt(first.Name.split("-")[1]) < Integer.parseInt(second.Name.split("-")[1]))
return -1;
else if (Integer.parseInt(second.Name.split("-")[1]) < Integer.parseInt(first.Name.split("-")[1]))
return 1;
return 0;
}
}

View File

@ -122,7 +122,6 @@ public class CoreClientManager extends MiniPlugin
@EventHandler(priority = EventPriority.LOWEST)
public void AsyncLogin(AsyncPlayerPreLoginEvent event)
{
TimingManager.start(event.getName() + " logging in ASYNC.");
try
{
LoadClient(Add(event.getName()), event.getUniqueId(), event.getAddress().getHostAddress());
@ -132,6 +131,8 @@ public class CoreClientManager extends MiniPlugin
Logger.Instance.log(exception);
event.disallow(Result.KICK_OTHER, "Error retrieving information from web, please retry in a minute.");
System.out.println(exception.getMessage());
}
if (Bukkit.hasWhitelist() && !Get(event.getName()).GetRank().Has(Rank.MODERATOR))
@ -146,12 +147,12 @@ public class CoreClientManager extends MiniPlugin
event.disallow(Result.KICK_WHITELIST, "You are not whitelisted my friend.");
}
TimingManager.stop(event.getName() + " logging in ASYNC.");
}
private void LoadClient(CoreClient client, UUID uuid, String ipAddress)
{
TimingManager.start(client.GetPlayerName() + " LoadClient Total.");
// Prep for mysql
ClientToken token = null;
@ -171,29 +172,37 @@ public class CoreClientManager extends MiniPlugin
// Load client in miniplugins
Bukkit.getServer().getPluginManager().callEvent(new AsyncClientLoadEvent(token, client));
RetrieveClientInformationEvent clientInformationEvent = new RetrieveClientInformationEvent(client.GetPlayerName(), uuid);
try
{
// Mysql
Bukkit.getServer().getPluginManager().callEvent(new RetrieveClientInformationEvent(client.GetPlayerName(), uuid));
Bukkit.getServer().getPluginManager().callEvent(clientInformationEvent);
}
catch (Exception exception)
{
Logger.Instance.log(exception);
System.out.println("Error running RetrieveClientInformationEvent" + exception.getMessage());
}
while (clientInformationEvent.processing())
{
try
{
Thread.sleep(1);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void LoginTiming(PlayerLoginEvent event)
{
TimingManager.stop(event.getPlayer().getName() + " logging in SYNC.");
TimingManager.stop(client.GetPlayerName() + " LoadClient Total.");
}
@EventHandler(priority = EventPriority.LOWEST)
public void Login(PlayerLoginEvent event)
{
TimingManager.start(event.getPlayer().getName() + " logging in SYNC.");
synchronized(_clientLock)
{
if (!_clientList.containsKey(event.getPlayer().getName()))

View File

@ -11,6 +11,7 @@ public class RetrieveClientInformationEvent extends Event
private String _playerName;
private UUID _uuid;
private int _processingCount;
public RetrieveClientInformationEvent(String playerName, UUID uuid)
{
@ -37,4 +38,19 @@ public class RetrieveClientInformationEvent extends Event
{
return _uuid;
}
public void incrementProcessingCount()
{
_processingCount++;
}
public boolean processing()
{
return _processingCount > 0;
}
public void decreaseProcessingCount()
{
_processingCount--;
}
}

View File

@ -8,7 +8,8 @@ import mineplex.core.database.column.ColumnVarChar;
public class MysqlAccountRepository extends RepositoryBase
{
private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accounts (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), name VARCHAR(40), gems INT, rank VARCHAR(40), rankPerm BOOL, rankExpire LONG, lastLogin LONG, totalPlayTime LONG, PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuid), UNIQUE INDEX nameIndex (name), INDEX rankIndex (rank));";
private static String ACCOUNT_LOGIN = "INSERT INTO accounts (uuid, name, lastLogin) values(?, ?, now()) ON DUPLICATE KEY UPDATE name=VALUES(name), lastLogin=VALUES(lastLogin);";
private static String ACCOUNT_LOGIN_NEW = "INSERT INTO accounts (uuid, name, lastLogin) values(?, ?, now()) ON DUPLICATE KEY UPDATE name=VALUES(name), lastLogin=VALUES(lastLogin);";
private static String ACCOUNT_LOGIN_UPDATE = "UPDATE accounts SET uuid=?, name=?, lastLogin=now() WHERE uuid = ?;";
public MysqlAccountRepository(JavaPlugin plugin)
{
@ -26,6 +27,12 @@ public class MysqlAccountRepository extends RepositoryBase
public void login(String uuid, String name)
{
executeUpdate(ACCOUNT_LOGIN, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 40, name));
int affectedRows = executeUpdate(ACCOUNT_LOGIN_UPDATE, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 40, name), new ColumnVarChar("uuid", 100, uuid));
if (affectedRows == 0)
{
executeUpdate(ACCOUNT_LOGIN_NEW, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 40, name));
System.out.println("Executed LOGIN_NEW");
}
}
}

View File

@ -191,10 +191,11 @@ public class Chat extends MiniPlugin
{
final Player player = event.getPlayer();
final String plyrname = player.toString();
final String msg = event.getMessage();
final String msg = event.getMessage().replaceAll("[^\\x00-\\x7F]", "").trim();
final String filtertype = "chat";
final String dname = player.getPlayerListName();
JSONObject message = buildJsonChatObject(filtertype, dname, plyrname, msg, _serverName, 1);
String response = getResponseFromTwoHat(message, filtertype);
@ -208,7 +209,7 @@ public class Chat extends MiniPlugin
if (risk >= 5)
{
String filteredMessage = event.getMessage();
String filteredMessage = event.getMessage().replaceAll("[^\\x00-\\x7F]", "").trim();
if (parseHashes(response) == null)
event.setMessage(ChatColor.RED + msg);

View File

@ -61,15 +61,16 @@ public abstract class RepositoryBase
protected int executeUpdate(String query, Column<?>...columns)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
int affectedRows = 0;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = connection.prepareStatement(query);
if (_connection == null || !_connection.isValid(1))
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(query);
for (int i=0; i < columns.length; i++)
{
@ -95,18 +96,6 @@ public abstract class RepositoryBase
e.printStackTrace();
}
}
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return affectedRows;
@ -149,13 +138,14 @@ public abstract class RepositoryBase
protected void executeQuery(String query, ResultSetCallable callable, Column<?>...columns)
{
Connection connection = null;
PreparedStatement preparedStatement = null;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = connection.prepareStatement(query);
if (_connection == null || !_connection.isValid(1))
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(query);
executeQuery(preparedStatement, callable, columns);
}
@ -176,31 +166,15 @@ public abstract class RepositoryBase
e.printStackTrace();
}
}
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
protected int executeUpdate(PreparedStatement preparedStatement, Column<?>...columns)
{
Connection connection = null;
int affectedRows = 0;
try
{
connection = DriverManager.getConnection(_connectionString, _userName, _password);
for (int i=0; i < columns.length; i++)
{
columns[i].setValue(preparedStatement, i+1);
@ -212,20 +186,6 @@ public abstract class RepositoryBase
{
exception.printStackTrace();
}
finally
{
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return affectedRows;
}

View File

@ -5,12 +5,16 @@ import java.util.UUID;
import mineplex.core.MiniPlugin;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.timing.TimingManager;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
public class EloManager extends MiniPlugin
{
private static Object _playerEloLock = new Object();
private EloRepository _repository;
private EloRatingSystem _ratingSystem;
private NautHashMap<String, NautHashMap<String, Integer>> _playerElos;
@ -41,15 +45,33 @@ public class EloManager extends MiniPlugin
}
@EventHandler
public void retrievePlayersElos(RetrieveClientInformationEvent event)
public void retrievePlayersElos(final RetrieveClientInformationEvent event)
{
_playerElos.put(event.getUniqueId().toString(), _repository.loadClientInformation(event.getUniqueId()));
event.incrementProcessingCount();
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
TimingManager.start(event.getPlayerName() + " elo Account call.");
NautHashMap<String, Integer> eloMap = _repository.loadClientInformation(event.getUniqueId());
TimingManager.stop(event.getPlayerName() + " elo Account call.");
synchronized (_playerEloLock)
{
_playerElos.put(event.getUniqueId().toString(), eloMap);
}
event.decreaseProcessingCount();
}
});
}
public int getElo(UUID uuid, String gameType)
{
int elo = 1000;
synchronized (_playerEloLock)
{
if (_playerElos.containsKey(uuid.toString()))
{
if (_playerElos.get(uuid.toString()).containsKey(gameType))
@ -57,6 +79,7 @@ public class EloManager extends MiniPlugin
elo = _playerElos.get(uuid.toString()).get(gameType);
}
}
}
return elo;
}
@ -94,10 +117,16 @@ public class EloManager extends MiniPlugin
saveElo(uuid.toString(), gameType, elo);
}
public void saveElo(String uuid, String gameType, int elo)
public void saveElo(final String uuid, final String gameType, final int elo)
{
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
_repository.saveElo(uuid, gameType, elo);
synchronized (_playerEloLock)
{
if (_playerElos.containsKey(uuid))
{
if (_playerElos.get(uuid).containsKey(gameType))
@ -106,4 +135,7 @@ public class EloManager extends MiniPlugin
}
}
}
}
});
}
}

View File

@ -4,6 +4,7 @@ import net.minecraft.server.v1_7_R3.Packet;
import net.minecraft.server.v1_7_R3.PacketPlayOutPlayerInfo;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
@ -12,6 +13,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.friend.command.AddFriend;
import mineplex.core.friend.command.DeleteFriend;
@ -21,6 +23,7 @@ import mineplex.core.friend.ui.FriendTabList;
import mineplex.core.packethandler.IPacketRunnable;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketVerifier;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -55,9 +58,19 @@ public class FriendManager extends MiniClientPlugin<FriendData> implements IPack
}
@Override
protected void loadClientInformation(RetrieveClientInformationEvent event)
protected void loadClientInformation(final RetrieveClientInformationEvent event)
{
event.incrementProcessingCount();
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
TimingManager.start(event.getPlayerName() + " friend Account call.");
Set(event.getPlayerName(), _repository.loadClientInformation(event.getUniqueId()));
TimingManager.stop(event.getPlayerName() + " friend Account call.");
event.decreaseProcessingCount();
}
});
}
@EventHandler
@ -77,9 +90,10 @@ public class FriendManager extends MiniClientPlugin<FriendData> implements IPack
_sendingPackets = false;
}
@EventHandler
public void updateFriends(UpdateEvent event)
{
if (event.getType() != UpdateType.SLOW)
if (event.getType() != UpdateType.SLOW || Bukkit.getOnlinePlayers().length == 0)
return;
Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
@ -94,11 +108,16 @@ public class FriendManager extends MiniClientPlugin<FriendData> implements IPack
{
for (Player player : _playerTabMap.keySet())
{
if (newData.containsKey(player.getName()))
if (newData.containsKey(player.getUniqueId().toString()))
{
_playerTabMap.get(player).updateFriends(newData.get(player.getName()).Friends);
Get(player).Friends = newData.get(player.getName()).Friends;
Get(player).Friends = newData.get(player.getUniqueId().toString()).Friends;
}
else
{
Get(player).Friends.clear();
}
_playerTabMap.get(player).updateFriends(Get(player).Friends);
}
}
});
@ -137,6 +156,14 @@ public class FriendManager extends MiniClientPlugin<FriendData> implements IPack
public void run()
{
_repository.addFriend(caller.getUniqueId().toString(), name);
Bukkit.getServer().getScheduler().runTask(_plugin, new Runnable()
{
public void run()
{
caller.sendMessage(F.main(GetName(), "Added " + ChatColor.GREEN + name + " to your friends list!"));
}
});
}
});
}
@ -148,6 +175,14 @@ public class FriendManager extends MiniClientPlugin<FriendData> implements IPack
public void run()
{
_repository.removeFriend(caller.getUniqueId().toString(), name);
Bukkit.getServer().getScheduler().runTask(_plugin, new Runnable()
{
public void run()
{
caller.sendMessage(F.main(GetName(), "Deleted " + ChatColor.GREEN + name + " from your friends list!"));
}
});
}
});
}

View File

@ -14,8 +14,8 @@ import mineplex.core.database.column.ColumnVarChar;
public class FriendRepository extends RepositoryBase
{
private static String CREATE_FRIEND_TABLE = "CREATE TABLE IF NOT EXISTS accountFriend (id INT NOT NULL AUTO_INCREMENT, uuidSource VARCHAR(100), uuidTarget VARCHAR(100), mutual BOOL, PRIMARY KEY (id), INDEX uuidTargetIndex (uuidTarget));";
private static String RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, tA.Name, mutual FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource IN ";
private static String CREATE_FRIEND_TABLE = "CREATE TABLE IF NOT EXISTS accountFriend (id INT NOT NULL AUTO_INCREMENT, uuidSource VARCHAR(100), uuidTarget VARCHAR(100), mutual BOOL, PRIMARY KEY (id), INDEX uuidIndex (uuidSource, uuidTarget));";
private static String RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, tA.Name, mutual, serverName, tA.lastLogin FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource IN ";
private static String RETRIEVE_FRIEND_RECORDS = "SELECT tA.Name, mutual, serverName, tA.lastLogin FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource = ?;";
private static String ADD_FRIEND_RECORD = "INSERT INTO accountFriend (uuidSource, uuidTarget) SELECT fA.uuid AS uuidSource, tA.uuid AS uuidTarget FROM accounts as fA LEFT JOIN accounts AS tA ON tA.name = ? WHERE fA.uuid = ?;";
private static String DELETE_FRIEND_RECORD = "DELETE aF FROM accountFriend AS aF INNER JOIN accounts ON accounts.name = ? WHERE uuidSource = ? AND uuidTarget = accounts.uuid;";

View File

@ -18,13 +18,11 @@ public class FriendTabList extends TabList
{
super();
set(0, 0, ChatColor.GOLD + " Name");
set(1, 0, ChatColor.GOLD + " Location");
set(2, 0, ChatColor.GOLD + " Status");
set(0, 0, ChatColor.GOLD + "" + ChatColor.BOLD + " Name");
set(1, 0, ChatColor.GOLD + "" + ChatColor.BOLD + " Location");
set(2, 0, ChatColor.GOLD + "" + ChatColor.BOLD + " Status");
updateFriends(friends);
System.out.println("created friend tablist with " + friends.size() + " friends");
}
public void updateFriends(List<FriendStatus> friends)
@ -32,14 +30,24 @@ public class FriendTabList extends TabList
Collections.sort(friends, _friendSorter);
int row = 1;
for (int i = 0; i < 20 && i < friends.size(); i++)
for (int i = 0; i < 19; i++)
{
if (i < friends.size())
{
FriendStatus status = friends.get(i);
set(0, row, (status.Mutual ? ChatColor.GREEN : ChatColor.YELLOW) + status.Name);
set(1, row, status.Mutual ? ChatColor.GREEN + status.ServerName : ChatColor.YELLOW + "Unknown");
set(2, row, (status.Mutual ? ChatColor.GREEN : ChatColor.YELLOW) + (status.Online ? "Online" : UtilTime.convert(status.LastSeenOnline, 2, TimeUnit.MINUTES) + ""));
System.out.println("Added friend " + status.Name + " to tablist");
}
else
{
set(0, row, null);
set(1, row, null);
set(2, row, null);
}
row++;
}
}
}

View File

@ -2,6 +2,7 @@ package mineplex.core.preferences;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -19,6 +20,7 @@ import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.preferences.command.PreferencesCommand;
import mineplex.core.preferences.ui.PreferencesShop;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -64,9 +66,19 @@ public class PreferencesManager extends MiniClientPlugin<UserPreferences>
}
@Override
protected void loadClientInformation(RetrieveClientInformationEvent event)
protected void loadClientInformation(final RetrieveClientInformationEvent event)
{
event.incrementProcessingCount();
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
TimingManager.start(event.getPlayerName() + " pref Account call.");
Set(event.getPlayerName(), _repository.loadClientInformation(event.getUniqueId()));
TimingManager.stop(event.getPlayerName() + " pref Account call.");
event.decreaseProcessingCount();
}
});
}
public void savePreferences(Player caller)

View File

@ -8,6 +8,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerQuitEvent;
@ -126,8 +127,16 @@ public class StatsManager extends MiniPlugin
}
@EventHandler
public void loadPlayerStats(RetrieveClientInformationEvent event)
public void loadPlayerStats(final RetrieveClientInformationEvent event)
{
event.incrementProcessingCount();
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
event.decreaseProcessingCount();
}
});
/* HA YOU THOUGHT I WAS GOING TO RUN DIDN'T YOU? */
if (true)

View File

@ -91,7 +91,7 @@ public class Hub extends JavaPlugin implements IRelation
//Main Modules
ServerStatusManager serverStatusManager = new ServerStatusManager(this, new LagMeter(this, clientManager));
PacketHandler packetHandler = new PacketHandler(this);
new FriendManager(this, packetHandler);
//new FriendManager(this, packetHandler);
PartyManager partyManager = new PartyManager(this, clientManager, preferenceManager);
Portal portal = new Portal(this, serverStatusManager.getCurrentServerName());
AntiHack.Initialize(this, punish, portal);

View File

@ -0,0 +1,71 @@
package mineplex.hub.commands;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.hub.HubManager;
import mineplex.hub.modules.NewsManager;
public class NewsAddCommand extends CommandBase<HubManager>
{
public NewsAddCommand(HubManager plugin)
{
super(plugin, Rank.ADMIN, "add");
}
@Override
public void Execute(final Player caller, final String[] args)
{
if (args == null || args.length == 0 || args.length > 128)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!"));
return;
}
else
{
NewsManager newsMang = Plugin.GetNewsManager();
String newsEntry = "";
for (int i = 0; i < args.length; i++)
{
newsEntry += args[i] + " ";
}
newsEntry = newsEntry.substring(0, newsEntry.length() - 1);
// Check for 256 character length for MySQL!
if (newsEntry.length() > 256)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news entry is too long [> 256 characters]!"));
return;
}
newsMang.AddNewsEntry(newsEntry, new Callback<Boolean>()
{
public void run(Boolean success)
{
if (success)
{
String newsEntry = "";
for (int i = 0; i < args.length; i++)
{
newsEntry += args[i] + " ";
}
newsEntry = newsEntry.substring(0, newsEntry.length() - 1);
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "The news entry: " + C.cGold + newsEntry + C.cGray + " has been added to the database!"));
}
else
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "There was an error adding the news entry to the database!"));
}
}
});
return;
}
}
}

View File

@ -1,215 +1,27 @@
package mineplex.hub.commands;
import java.util.HashMap;
import java.util.Iterator;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.command.MultiCommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.hub.HubManager;
import mineplex.hub.modules.NewsManager;
public class NewsCommand extends CommandBase<HubManager>
public class NewsCommand extends MultiCommandBase<HubManager>
{
public NewsCommand(HubManager plugin)
{
super(plugin, Rank.ADMIN, "news");
AddCommand(new NewsAddCommand(plugin));
AddCommand(new NewsDeleteCommand(plugin));
AddCommand(new NewsConfirmCommand(plugin));
AddCommand(new NewsListCommand(plugin));
AddCommand(new NewsSetCommand(plugin));
}
@Override
public void Execute(final Player caller, final String[] args)
protected void Help(Player caller, String args[])
{
final NewsManager newsMang = Plugin.GetNewsManager();
if (args == null || args.length == 0)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!"));
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "Available news arguments for this command:"));
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news list" + C.cGray + " - Lists (numbered) stored news messages from database."));
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news add <newsEntry>" + C.cGray + " - Adds specified news entry string to database at end of table."));
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news delete #" + C.cGray + " - Removes specified (numbered) news entry string from database."));
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "news set # <newsEntry>" + C.cGray + " - Updates specified (numbered) news entry string in database."));
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cWhite + "*Please Note: " + C.cGray + "Updates to server news entries from the database are on a 4 minute refresh cycle!"));
return;
}
else if (args.length == 1 && args[0].equalsIgnoreCase("list"))
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "Current server news messages:"));
newsMang.RetriveNewsEntries(new Callback<HashMap<String, String>>()
{
public void run(final HashMap<String, String> newsEntries)
{
// Order newsEntries set or its output by newsPosition, not hash order...
newsMang.RetrieveMaxNewsPosition(new Callback<Integer>()
{
public void run(Integer maxPosition)
{
String[] newsStrings = new String[maxPosition];
for (Iterator<String> iterator = newsEntries.keySet().iterator(); iterator.hasNext();)
{
String newsPosition = iterator.next();
newsStrings[Integer.parseInt(newsPosition) - 1] = newsEntries.get(newsPosition);
}
for (int i = 0; i < newsStrings.length; i++)
{
UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + caller.getName() + " {\"text\":\"" + Plugin.GetName() + "> \", color:blue, \"extra\":[{\"text\":\"[DELETE] \", color:red, \"clickEvent\":{\"action\":\"run_command\",\"value\":\"/news ¢¤₦₣¡₨₥ " + (i + 1) + "\"}, \"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Deletes News Entry " + (i + 1) + " : " + newsStrings[i] + "\"}}, {\"text\":\"News " + (i + 1) + "\", color:gold}, {\"text\":\" : \", color:gray}, {\"text\":\"" + newsStrings[i] + "\", color:white}]}");
}
}
});
}
});
return;
}
else if (args.length >= 2 && args.length <= 128)
{
if (args[0].equals("¢¤₦₣¡₨₥") && args.length == 2)
{
int newsPosition;
try
{
newsPosition = Integer.parseInt(args[1]);
}
catch (Exception exception)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news position is invalid!"));
return;
}
UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + caller.getName() + " {\"text\":\"" + Plugin.GetName() + "> \", color:blue, \"extra\":[{\"text\":\"[CONFIRM] \", color:green, \"clickEvent\":{\"action\":\"run_command\",\"value\":\"/news delete " + newsPosition + "\"}, \"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Are you absolutely sure???\"}}, {\"text\":\"News Entry " + newsPosition + "\", color:gold}, {\"text\":\" deletion?\", color:gray}]}");
return;
}
else if (args[0].equalsIgnoreCase("delete") && args.length == 2)
{
final int newsPosition;
try
{
newsPosition = Integer.parseInt(args[1]);
}
catch (Exception exception)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news position is invalid!"));
return;
}
newsMang.DeleteNewsEntry(newsPosition, new Callback<Boolean>()
{
public void run(Boolean success)
{
if (success)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "The news entry at position " + C.cGold + newsPosition + C.cGray + " has been deleted!"));
}
else
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "There was an error deleting the news entry; likely the specified news position was invalid!"));
}
}
});
return;
}
else if (args[0].equalsIgnoreCase("add"))
{
String newsEntry = "";
for (int i = 1; i < args.length; i++)
{
newsEntry += args[i] + " ";
}
newsEntry = newsEntry.substring(0, newsEntry.length() - 1);
// Check for 256 character length for MySQL!
if (newsEntry.length() > 256)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news entry is too long [> 256 characters]!"));
return;
}
newsMang.AddNewsEntry(newsEntry, new Callback<Boolean>()
{
public void run(Boolean success)
{
if (success)
{
String newsEntry = "";
for (int i = 1; i < args.length; i++)
{
newsEntry += args[i] + " ";
}
newsEntry = newsEntry.substring(0, newsEntry.length() - 1);
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "The news entry: " + C.cGold + newsEntry + C.cGray + " has been added to the database!"));
}
else
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "There was an error adding the news entry to the database!"));
}
}
});
return;
}
else if (args[0].equalsIgnoreCase("set") && args.length >= 3)
{
final int newsPosition;
String newsEntry = "";
for (int i = 2; i < args.length; i++)
{
newsEntry += args[i] + " ";
}
newsEntry = newsEntry.substring(0, newsEntry.length() - 1);
// Check for 256 character length for MySQL!
if (newsEntry.length() > 256)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news entry is too long [> 256 characters]!"));
return;
}
try
{
newsPosition = Integer.parseInt(args[1]);
}
catch (Exception exception)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news position is invalid!"));
return;
}
newsMang.SetNewsEntry(newsEntry, newsPosition, new Callback<Boolean>()
{
public void run(Boolean success)
{
if (success)
{
String newsEntry = "";
for (int i = 2; i < args.length; i++)
{
newsEntry += args[i] + " ";
}
newsEntry = newsEntry.substring(0, newsEntry.length() - 1);
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "The news entry at position " + C.cGold + newsPosition + C.cGray + " has been updated to: " + C.cGold + newsEntry + C.cGray + "!"));
}
else
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "There was an error updating the news entry; likely the specified news position was invalid!"));
}
}
});
return;
}
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!"));
return;
}
else
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!"));
return;
}
Plugin.GetNewsManager().Help(caller);
}
}

View File

@ -0,0 +1,45 @@
package mineplex.hub.commands;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.hub.HubManager;
public class NewsConfirmCommand extends CommandBase<HubManager>
{
public NewsConfirmCommand(HubManager plugin)
{
super(plugin, Rank.ADMIN, "¢¤₦₣¡₨₥");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args == null || args.length == 0 || args.length > 1)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!"));
return;
}
else
{
int newsPosition;
try
{
newsPosition = Integer.parseInt(args[0]);
}
catch (Exception exception)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news position is invalid!"));
return;
}
UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + caller.getName() + " {\"text\":\"" + Plugin.GetName() + "> \", color:blue, \"extra\":[{\"text\":\"[CONFIRM] \", color:green, \"clickEvent\":{\"action\":\"run_command\",\"value\":\"/news delete " + newsPosition + "\"}, \"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Are you absolutely sure???\"}}, {\"text\":\"News Entry " + newsPosition + "\", color:gold}, {\"text\":\" deletion?\", color:gray}]}");
return;
}
}
}

View File

@ -0,0 +1,59 @@
package mineplex.hub.commands;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.hub.HubManager;
import mineplex.hub.modules.NewsManager;
public class NewsDeleteCommand extends CommandBase<HubManager>
{
public NewsDeleteCommand(HubManager plugin)
{
super(plugin, Rank.ADMIN, "delete");
}
@Override
public void Execute(final Player caller, String[] args)
{
if (args == null || args.length == 0 || args.length > 1)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!"));
return;
}
else
{
NewsManager newsMang = Plugin.GetNewsManager();
final int newsPosition;
try
{
newsPosition = Integer.parseInt(args[0]);
}
catch (Exception exception)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news position is invalid!"));
return;
}
newsMang.DeleteNewsEntry(newsPosition, new Callback<Boolean>()
{
public void run(Boolean success)
{
if (success)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "The news entry at position " + C.cGold + newsPosition + C.cGray + " has been deleted!"));
}
else
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "There was an error deleting the news entry; likely the specified news position was invalid!"));
}
}
});
return;
}
}
}

View File

@ -0,0 +1,66 @@
package mineplex.hub.commands;
import java.util.HashMap;
import java.util.Iterator;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.hub.HubManager;
import mineplex.hub.modules.NewsManager;
public class NewsListCommand extends CommandBase<HubManager>
{
public NewsListCommand(HubManager plugin)
{
super(plugin, Rank.ADMIN, "list");
}
@Override
public void Execute(final Player caller, String[] args)
{
if (args == null || args.length == 0)
{
final NewsManager newsMang = Plugin.GetNewsManager();
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "Current server news messages:"));
newsMang.RetriveNewsEntries(new Callback<HashMap<String, String>>()
{
public void run(final HashMap<String, String> newsEntries)
{
// Order newsEntries set or its output by newsPosition, not hash order...
newsMang.RetrieveMaxNewsPosition(new Callback<Integer>()
{
public void run(Integer maxPosition)
{
String[] newsStrings = new String[maxPosition];
for (Iterator<String> iterator = newsEntries.keySet().iterator(); iterator.hasNext();)
{
String newsPosition = iterator.next();
newsStrings[Integer.parseInt(newsPosition) - 1] = newsEntries.get(newsPosition);
}
for (int i = 0; i < newsStrings.length; i++)
{
UtilServer.getServer().dispatchCommand(UtilServer.getServer().getConsoleSender(), "tellraw " + caller.getName() + " {\"text\":\"" + Plugin.GetName() + "> \", color:blue, \"extra\":[{\"text\":\"[DELETE] \", color:red, \"clickEvent\":{\"action\":\"run_command\",\"value\":\"/news ¢¤₦₣¡₨₥ " + (i + 1) + "\"}, \"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Deletes News Entry " + (i + 1) + " : " + newsStrings[i] + "\"}}, {\"text\":\"News " + (i + 1) + "\", color:gold}, {\"text\":\" : \", color:gray}, {\"text\":\"" + newsStrings[i] + "\", color:white}]}");
}
}
});
}
});
return;
}
else
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!"));
return;
}
}
}

View File

@ -0,0 +1,81 @@
package mineplex.hub.commands;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.hub.HubManager;
import mineplex.hub.modules.NewsManager;
public class NewsSetCommand extends CommandBase<HubManager>
{
public NewsSetCommand(HubManager plugin)
{
super(plugin, Rank.ADMIN, "set");
}
@Override
public void Execute(final Player caller, final String[] args)
{
if (args == null || args.length < 2 || args.length > 128)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "Your arguments are inappropriate for this command!"));
return;
}
else
{
NewsManager newsMang = Plugin.GetNewsManager();
final int newsPosition;
String newsEntry = "";
for (int i = 1; i < args.length; i++)
{
newsEntry += args[i] + " ";
}
newsEntry = newsEntry.substring(0, newsEntry.length() - 1);
// Check for 256 character length for MySQL!
if (newsEntry.length() > 256)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news entry is too long [> 256 characters]!"));
return;
}
try
{
newsPosition = Integer.parseInt(args[0]);
}
catch (Exception exception)
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "The specified news position is invalid!"));
return;
}
newsMang.SetNewsEntry(newsEntry, newsPosition, new Callback<Boolean>()
{
public void run(Boolean success)
{
if (success)
{
String newsEntry = "";
for (int i = 1; i < args.length; i++)
{
newsEntry += args[i] + " ";
}
newsEntry = newsEntry.substring(0, newsEntry.length() - 1);
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cGray + "The news entry at position " + C.cGold + newsPosition + C.cGray + " has been updated to: " + C.cGold + newsEntry + C.cGray + "!"));
}
else
{
UtilPlayer.message(caller, F.main(Plugin.GetName(), C.cRed + "There was an error updating the news entry; likely the specified news position was invalid!"));
}
}
});
return;
}
}
}

View File

@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.MiniPlugin;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
@ -187,6 +188,24 @@ public class NewsManager extends MiniPlugin
});
}
public void Help(Player caller, String message)
{
UtilPlayer.message(caller, F.main(_moduleName, "Available news arguments for this command:"));
UtilPlayer.message(caller, F.help(C.cGold + "/news list", "Lists (numbered) stored news messages from database.", Rank.ADMIN));
UtilPlayer.message(caller, F.help(C.cGold + "/news add <newsEntry>", "Adds specified news entry string to database at end of table.", Rank.ADMIN));
UtilPlayer.message(caller, F.help(C.cGold + "/news delete #", "Removes specified (numbered) news entry string from database.", Rank.ADMIN));
UtilPlayer.message(caller, F.help(C.cGold + "/news set # <newsEntry>", "Updates specified (numbered) news entry string in database.", Rank.ADMIN));
UtilPlayer.message(caller, F.help("*Please Note:", "Updates to server news entries from the database are on a 4 minute refresh cycle!", Rank.ADMIN));
if (message != null)
UtilPlayer.message(caller, F.main(_moduleName, ChatColor.RED + message));
}
public void Help(Player caller)
{
Help(caller, null);
}
@EventHandler
public void NewsUpdate(UpdateEvent event)
{
@ -217,6 +236,11 @@ public class NewsManager extends MiniPlugin
_newsIndex = (_newsIndex + 1)%_news.length;
_newsTime = System.currentTimeMillis();
}
if (_newsIndex >= _news.length)
{
// Resets newsIndex if outside of bounds of news array after RefreshNews but before UtilTime.elapsed above
_newsIndex = 0;
}
//Text
String text = col + C.Bold + "MINEPLEX" + ChatColor.RESET + " - " + _news[_newsIndex];

View File

@ -44,7 +44,7 @@ public class GroupStatusData
// Lobby joinable checking
if (existingServer.Motd.isEmpty() || existingServer.Motd.equals(""))
{
if (serverStatusData.MaxPlayers - serverStatusData.Players > 15)
if (serverStatusData.MaxPlayers - serverStatusData.Players > 20)
_joinableCount--;
}
else
@ -66,7 +66,7 @@ public class GroupStatusData
// Lobby joinable checking
if (serverStatusData.Motd.isEmpty() || serverStatusData.Motd.equals(""))
{
if (serverStatusData.MaxPlayers - serverStatusData.Players > 15)
if (serverStatusData.MaxPlayers - serverStatusData.Players > 20)
{
_joinableCount++;
}

View File

@ -141,6 +141,13 @@ public class ServerMonitor
int serversToAdd = Math.max(serverGroup.RequiredTotalServers - groupStatus.getTotalServers(), serverGroup.RequiredJoinableServers - groupStatus.getJoinableCount());
int serversToKill = (groupStatus.getTotalServers() > serverGroup.RequiredTotalServers && groupStatus.getJoinableCount() > serverGroup.RequiredJoinableServers) ? Math.min(groupStatus.getJoinableCount() - serverGroup.RequiredJoinableServers, groupStatus.EmptyServers.size()) : 0;
// Minimum 1500 slot bufferzone
if (serverGroup.Name.equalsIgnoreCase("Lobby"))
{
if (groupStatus.MaxPlayers - groupStatus.Players < 1500)
serversToAdd = serverGroup.RequiredJoinableServers;
}
while (serversToAdd > 0)
{
int serverNum = groupStatus.getNextServerNumber();

Binary file not shown.