Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex
This commit is contained in:
commit
91a70d6a04
@ -1,6 +1,5 @@
|
||||
package mineplex.bungee;
|
||||
|
||||
import mineplex.bungee.account.AccountManager;
|
||||
import mineplex.bungee.lobbyBalancer.LobbyBalancer;
|
||||
import mineplex.bungee.motd.MotdManager;
|
||||
import mineplex.bungee.playerCount.PlayerCount;
|
||||
@ -21,6 +20,5 @@ public class Mineplexer extends Plugin
|
||||
new PlayerStats(this);
|
||||
//new InternetStatus(this);
|
||||
new PlayerTracker(this);
|
||||
new AccountManager(this, playerCount);
|
||||
}
|
||||
}
|
||||
|
@ -1,71 +0,0 @@
|
||||
package mineplex.bungee.account;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import mineplex.bungee.playerCount.PlayerCount;
|
||||
import net.md_5.bungee.api.event.LoginEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
public class AccountManager implements Listener, Runnable
|
||||
{
|
||||
private Plugin _plugin;
|
||||
private PlayerCount _playerCount;
|
||||
private int _playerCap = -1;
|
||||
private AccountManagerRepository _repository;
|
||||
|
||||
private Gson _gson = new Gson();
|
||||
|
||||
public AccountManager(Plugin plugin, PlayerCount playerCount)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_playerCount = playerCount;
|
||||
|
||||
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||
_plugin.getProxy().getScheduler().schedule(_plugin, this, 10L, 10L, TimeUnit.SECONDS);
|
||||
|
||||
_repository = new AccountManagerRepository();
|
||||
_repository.initialize();
|
||||
_playerCap = _repository.retrievePlayerCap();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void login(LoginEvent event)
|
||||
{
|
||||
if (_playerCap == -1 || _playerCount.getTotalPlayers() <= _playerCap)
|
||||
return;
|
||||
|
||||
String response = getClient(event.getConnection().getName(), event.getConnection().getUniqueId(), event.getConnection().getAddress().toString());
|
||||
|
||||
ClientToken token = _gson.fromJson(response, ClientToken.class);
|
||||
|
||||
if (token.Rank.equalsIgnoreCase("ALL"))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
event.setCancelReason("§fDue to server issues, we have added a §cplayer limit§f.\n"
|
||||
+ "§fWe hope to have this resolved soon, §nplease be ptient§r.\n"
|
||||
+ "§fPlayers with Ranks can still join the server!\n\n"
|
||||
+ "§fPurchase Ranks at §awww.mineplex.com/shop");
|
||||
}
|
||||
}
|
||||
|
||||
public String getClient(String name, UUID uuid, String ipAddress)
|
||||
{
|
||||
LoginToken token = new LoginToken();
|
||||
token.Name = name;
|
||||
token.Uuid = uuid.toString();
|
||||
token.IpAddress = ipAddress;
|
||||
|
||||
return new JsonWebCall("http://accounts.mineplex.com/PlayerAccount/Login").ExecuteReturnStream(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
_playerCap = _repository.retrievePlayerCap();
|
||||
}
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
package mineplex.bungee.account;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class AccountManagerRepository
|
||||
{
|
||||
private Connection _connection = null;
|
||||
private String _connectionString = "jdbc:mysql://db.mineplex.com:3306/BungeeServers?autoReconnect=true&failOverReadOnly=false&maxReconnects=10";
|
||||
private String _userName = "root";
|
||||
private String _password = "tAbechAk3wR7tuTh";
|
||||
|
||||
private static String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS playerCap (id INT NOT NULL AUTO_INCREMENT, playerCap INT, PRIMARY KEY (id));";
|
||||
private static String RETRIEVE_PLAYERCAP = "SELECT playerCap FROM playerCap;";
|
||||
|
||||
public void initialize()
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (_connection == null || _connection.isClosed())
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
// Create table
|
||||
preparedStatement = _connection.prepareStatement(CREATE_TABLE);
|
||||
preparedStatement.execute();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (preparedStatement != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
preparedStatement.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Initialized AccountManager.");
|
||||
}
|
||||
|
||||
public int retrievePlayerCap()
|
||||
{
|
||||
ResultSet resultSet = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (_connection == null || _connection.isClosed())
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
preparedStatement = _connection.prepareStatement(RETRIEVE_PLAYERCAP);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
|
||||
while (resultSet.next())
|
||||
{
|
||||
return resultSet.getInt(1);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (preparedStatement != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
preparedStatement.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (resultSet != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
resultSet.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package mineplex.bungee.account;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class AccountToken
|
||||
{
|
||||
public int AccountId;
|
||||
public String Name;
|
||||
public RankToken Rank;
|
||||
|
||||
public int LoginCount;
|
||||
public long LastLogin;
|
||||
public long TotalPlayingTime;
|
||||
public HashSet<String> IpAdddresses = new HashSet<String>();
|
||||
|
||||
public boolean Banned;
|
||||
public String Reason;
|
||||
|
||||
public int BlueGems;
|
||||
public int GreenGems;
|
||||
public List<Integer> SalesPackageIds;
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package mineplex.bungee.account;
|
||||
|
||||
public interface Callback<T>
|
||||
{
|
||||
public void run(T data);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package mineplex.bungee.account;
|
||||
|
||||
public class ClientToken
|
||||
{
|
||||
public int AccountId;
|
||||
public String Name;
|
||||
public String Rank;
|
||||
public boolean RankPerm;
|
||||
public String RankExpire;
|
||||
public int EconomyBalance;
|
||||
|
||||
public AccountToken AccountToken;
|
||||
public long LastLogin;
|
||||
}
|
@ -1,355 +0,0 @@
|
||||
package mineplex.bungee.account;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.conn.scheme.PlainSocketFactory;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.conn.PoolingClientConnectionManager;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class JsonWebCall
|
||||
{
|
||||
private String _url;
|
||||
private PoolingClientConnectionManager _connectionManager;
|
||||
|
||||
public JsonWebCall(String url)
|
||||
{
|
||||
_url = url;
|
||||
|
||||
SchemeRegistry schemeRegistry = new SchemeRegistry();
|
||||
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
|
||||
|
||||
_connectionManager = new PoolingClientConnectionManager(schemeRegistry);
|
||||
_connectionManager.setMaxTotal(200);
|
||||
_connectionManager.setDefaultMaxPerRoute(20);
|
||||
}
|
||||
|
||||
public String ExecuteReturnStream(Object argument)
|
||||
{
|
||||
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||
InputStream in = null;
|
||||
String result = null;
|
||||
|
||||
try
|
||||
{
|
||||
HttpResponse response;
|
||||
|
||||
Gson gson = new Gson();
|
||||
HttpPost request = new HttpPost(_url);
|
||||
|
||||
if (argument != null)
|
||||
{
|
||||
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||
request.setEntity(params);
|
||||
}
|
||||
|
||||
response = httpClient.execute(request);
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
in = response.getEntity().getContent();
|
||||
result = convertStreamToString(in);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("Error executing JsonWebCall: \n" + ex.getMessage());
|
||||
System.out.println("Result: \n" + result);
|
||||
|
||||
for (StackTraceElement trace : ex.getStackTrace())
|
||||
{
|
||||
System.out.println(trace);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
|
||||
if (in != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
Execute((Object)null);
|
||||
}
|
||||
|
||||
public void Execute(Object argument)
|
||||
{
|
||||
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||
InputStream in = null;
|
||||
|
||||
try
|
||||
{
|
||||
Gson gson = new Gson();
|
||||
HttpPost request = new HttpPost(_url);
|
||||
|
||||
if (argument != null)
|
||||
{
|
||||
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||
request.setEntity(params);
|
||||
}
|
||||
|
||||
httpClient.execute(request);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("JsonWebCall.Execute() Error:\n" + ex.getMessage());
|
||||
|
||||
for (StackTraceElement trace : ex.getStackTrace())
|
||||
{
|
||||
System.out.println(trace);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
|
||||
if (in != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T Execute(Class<T> returnClass)
|
||||
{
|
||||
return Execute(returnClass, (Object)null);
|
||||
}
|
||||
|
||||
public <T> T Execute(Type returnType, Object argument)
|
||||
{
|
||||
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||
InputStream in = null;
|
||||
T returnData = null;
|
||||
String result = null;
|
||||
|
||||
try
|
||||
{
|
||||
HttpResponse response;
|
||||
|
||||
Gson gson = new Gson();
|
||||
HttpPost request = new HttpPost(_url);
|
||||
|
||||
if (argument != null)
|
||||
{
|
||||
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||
request.setEntity(params);
|
||||
}
|
||||
|
||||
response = httpClient.execute(request);
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
in = response.getEntity().getContent();
|
||||
|
||||
result = convertStreamToString(in);
|
||||
returnData = new Gson().fromJson(result, returnType);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("Error executing JsonWebCall: \n" + ex.getMessage());
|
||||
System.out.println("Result: \n" + result);
|
||||
|
||||
for (StackTraceElement trace : ex.getStackTrace())
|
||||
{
|
||||
System.out.println(trace);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
|
||||
if (in != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
public <T> T Execute(Class<T> returnClass, Object argument)
|
||||
{
|
||||
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||
InputStream in = null;
|
||||
T returnData = null;
|
||||
String result = null;
|
||||
|
||||
try
|
||||
{
|
||||
HttpResponse response;
|
||||
|
||||
Gson gson = new Gson();
|
||||
HttpPost request = new HttpPost(_url);
|
||||
|
||||
if (argument != null)
|
||||
{
|
||||
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||
request.setEntity(params);
|
||||
}
|
||||
|
||||
response = httpClient.execute(request);
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
in = response.getEntity().getContent();
|
||||
|
||||
result = convertStreamToString(in);
|
||||
returnData = new Gson().fromJson(result, returnClass);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("Error executing JsonWebCall: \n" + ex.getMessage());
|
||||
System.out.println("Result: \n" + result);
|
||||
|
||||
for (StackTraceElement trace : ex.getStackTrace())
|
||||
{
|
||||
System.out.println(trace);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
|
||||
if (in != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
public <T> void Execute(Class<T> callbackClass, Callback<T> callback)
|
||||
{
|
||||
Execute(callbackClass, callback, (Object)null);
|
||||
}
|
||||
|
||||
public <T> void Execute(Class<T> callbackClass, Callback<T> callback, Object argument)
|
||||
{
|
||||
HttpClient httpClient = new DefaultHttpClient(_connectionManager);
|
||||
InputStream in = null;
|
||||
String result = null;
|
||||
|
||||
try
|
||||
{
|
||||
HttpResponse response;
|
||||
|
||||
Gson gson = new Gson();
|
||||
HttpPost request = new HttpPost(_url);
|
||||
|
||||
if (argument != null)
|
||||
{
|
||||
StringEntity params = new StringEntity(gson.toJson(argument));
|
||||
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
||||
request.setEntity(params);
|
||||
}
|
||||
|
||||
response = httpClient.execute(request);
|
||||
|
||||
if (response != null && callback != null)
|
||||
{
|
||||
in = response.getEntity().getContent();
|
||||
|
||||
result = convertStreamToString(in);
|
||||
callback.run(new Gson().fromJson(result, callbackClass));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("Error executing JsonWebCall: \n" + ex.getMessage());
|
||||
System.out.println("Result: \n" + result);
|
||||
}
|
||||
finally
|
||||
{
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
|
||||
if (in != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String convertStreamToString(InputStream is)
|
||||
{
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String line = null;
|
||||
try {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package mineplex.bungee.account;
|
||||
|
||||
public class LoginToken
|
||||
{
|
||||
public String Name;
|
||||
public String IpAddress = "0.0.0.0";
|
||||
public String MacAddress = "00-00-00-00-00-00-00-00";
|
||||
public String Uuid;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package mineplex.bungee.account;
|
||||
|
||||
public class RankToken
|
||||
{
|
||||
public int RankId;
|
||||
|
||||
public String Name;
|
||||
}
|
@ -185,10 +185,10 @@ public class AccountRepository extends RepositoryBase
|
||||
}
|
||||
}, new ColumnVarChar("name", 100, name));
|
||||
|
||||
if (uuids.size() > 1)
|
||||
return null;
|
||||
if (uuids.size() > 0)
|
||||
return uuids.get(uuids.size() - 1);
|
||||
else
|
||||
return uuids.size() == 1 ? uuids.get(0) : null;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void saveRank(final Callback<Rank> callback, final String name, final UUID uuid, final Rank rank, final boolean perm)
|
||||
|
@ -7,9 +7,9 @@ import org.apache.commons.dbcp2.BasicDataSource;
|
||||
|
||||
public final class DBPool
|
||||
{
|
||||
public static final DataSource ACCOUNT = openDataSource("jdbc:mysql://db.mineplex.com/Account", "root", "tAbechAk3wR7tuTh");
|
||||
public static final DataSource QUEUE = openDataSource("jdbc:mysql://db.mineplex.com/Queue", "root", "tAbechAk3wR7tuTh");
|
||||
public static final DataSource MINEPLEX = openDataSource("jdbc:mysql://db.mineplex.com:3306/Mineplex", "root", "tAbechAk3wR7tuTh");
|
||||
public static final DataSource ACCOUNT = openDataSource("jdbc:mysql://db.mineplex.com/Account", "MilitaryPolice", "CUPr6Wuw2Rus$qap");
|
||||
public static final DataSource QUEUE = openDataSource("jdbc:mysql://db.mineplex.com/Queue", "MilitaryPolice", "CUPr6Wuw2Rus$qap");
|
||||
public static final DataSource MINEPLEX = openDataSource("jdbc:mysql://db.mineplex.com:3306/Mineplex", "MilitaryPolice", "CUPr6Wuw2Rus$qap");
|
||||
public static final DataSource STATS_MINEPLEX = openDataSource("jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex", "root", "tAbechAk3wR7tuTh");
|
||||
|
||||
private static DataSource openDataSource(String url, String username, String password)
|
||||
|
@ -81,7 +81,6 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
|
||||
if (event.getType() != UpdateType.SLOW || Bukkit.getOnlinePlayers().size() == 0)
|
||||
return;
|
||||
|
||||
/*
|
||||
final Player[] onlinePlayers = UtilServer.getPlayers();
|
||||
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
|
||||
@ -109,13 +108,10 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
|
||||
});
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
public void addFriend(final Player caller, final String name)
|
||||
{
|
||||
caller.sendMessage(F.main(getName(), ChatColor.RED + "Friend is currently disabled."));
|
||||
/*
|
||||
if (caller.getName().equalsIgnoreCase(name))
|
||||
{
|
||||
caller.sendMessage(F.main(getName(), ChatColor.GRAY + "You cannot add yourself as a friend"));
|
||||
@ -218,13 +214,10 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
|
||||
});
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
public void removeFriend(final Player caller, final String name)
|
||||
{
|
||||
caller.sendMessage(F.main(getName(), ChatColor.RED + "Friend is currently disabled."));
|
||||
/*
|
||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
@ -254,13 +247,10 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
|
||||
});
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
public void showFriends(Player caller)
|
||||
{
|
||||
caller.sendMessage(F.main(getName(), ChatColor.RED + "Friend is currently disabled."));
|
||||
/*
|
||||
boolean isStaff = ClientManager.Get(caller).GetRank().Has(Rank.HELPER);
|
||||
boolean gotAFriend = false;
|
||||
List<FriendStatus> friendStatuses = Get(caller).getFriends();
|
||||
@ -393,7 +383,6 @@ public class FriendManager extends MiniDbClientPlugin<FriendData>
|
||||
message.add(C.cAqua + C.Strike + "======================");
|
||||
|
||||
message.sendToPlayer(caller);
|
||||
*/
|
||||
}
|
||||
|
||||
public boolean isFriends(Player player, String friend)
|
||||
|
@ -16,7 +16,6 @@ import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.database.DBPool;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.ResultSetCallable;
|
||||
import mineplex.core.database.column.ColumnInt;
|
||||
import mineplex.core.database.column.ColumnVarChar;
|
||||
import mineplex.core.friend.FriendStatusType;
|
||||
import mineplex.serverdata.Region;
|
||||
@ -27,8 +26,11 @@ import mineplex.serverdata.servers.ServerManager;
|
||||
|
||||
public class FriendRepository extends RepositoryBase
|
||||
{
|
||||
private static String ADD_FRIEND_RECORD = "INSERT INTO accountFriend (sourceId, targetId) VALUES(?, ?);";
|
||||
private static String DELETE_FRIEND_RECORD = "DELETE FROM accountFriend WHERE id = ?;";
|
||||
private static String CREATE_FRIEND_TABLE = "CREATE TABLE IF NOT EXISTS accountFriend (id INT NOT NULL AUTO_INCREMENT, uuidSource VARCHAR(100), uuidTarget VARCHAR(100), status VARCHAR(100), PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuidSource, uuidTarget));";
|
||||
private static String RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, tA.Name, status, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget WHERE uuidSource IN ";
|
||||
private static String ADD_FRIEND_RECORD = "INSERT INTO accountFriend (uuidSource, uuidTarget, status, created) SELECT fA.uuid AS uuidSource, tA.uuid AS uuidTarget, ?, now() FROM accounts as fA LEFT JOIN accounts AS tA ON tA.name = ? WHERE fA.name = ?;";
|
||||
private static String UPDATE_MUTUAL_RECORD = "UPDATE accountFriend AS aF INNER JOIN accounts as fA ON aF.uuidSource = fA.uuid INNER JOIN accounts AS tA ON aF.uuidTarget = tA.uuid SET aF.status = ? WHERE tA.name = ? AND fA.name = ?;";
|
||||
private static String DELETE_FRIEND_RECORD = "DELETE aF FROM accountFriend AS aF INNER JOIN accounts as fA ON aF.uuidSource = fA.uuid INNER JOIN accounts AS tA ON aF.uuidTarget = tA.uuid WHERE fA.name = ? AND tA.name = ?;";
|
||||
|
||||
// Repository holding active PlayerStatus data.
|
||||
private DataRepository<PlayerStatus> _repository;
|
||||
@ -52,14 +54,29 @@ public class FriendRepository extends RepositoryBase
|
||||
{
|
||||
}
|
||||
|
||||
public boolean addFriend(int sourceAccountId, int targetAccountId)
|
||||
public boolean addFriend(final Player caller, String name)
|
||||
{
|
||||
return executeUpdate(ADD_FRIEND_RECORD, new ColumnInt("sourceId", sourceAccountId), new ColumnInt("targetId", targetAccountId)) > 0;
|
||||
int rowsAffected = executeUpdate(ADD_FRIEND_RECORD, new ColumnVarChar("status", 100, "Sent"), new ColumnVarChar("name", 100, name), new ColumnVarChar("name", 100, caller.getName()));
|
||||
|
||||
if (rowsAffected > 0)
|
||||
return executeUpdate(ADD_FRIEND_RECORD, new ColumnVarChar("status", 100, "Pending"), new ColumnVarChar("name", 100, caller.getName()), new ColumnVarChar("uuid", 100, name)) > 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeFriendRecord(int recordId)
|
||||
public boolean updateFriend(String caller, String name, String status)
|
||||
{
|
||||
return executeUpdate(UPDATE_MUTUAL_RECORD, new ColumnVarChar("status", 100, status), new ColumnVarChar("uuid", 100, name), new ColumnVarChar("name", 100, caller)) > 0;
|
||||
}
|
||||
|
||||
public boolean removeFriend(String caller, String name)
|
||||
{
|
||||
return executeUpdate(DELETE_FRIEND_RECORD, new ColumnInt("id", recordId)) > 0;
|
||||
int rowsAffected = executeUpdate(DELETE_FRIEND_RECORD, new ColumnVarChar("name", 100, name), new ColumnVarChar("name", 100, caller));
|
||||
|
||||
if (rowsAffected > 0)
|
||||
return executeUpdate(DELETE_FRIEND_RECORD, new ColumnVarChar("name", 100, caller), new ColumnVarChar("uuid", 100, name)) > 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public NautHashMap<String, FriendData> getFriendsForAll(Player...players)
|
||||
@ -67,7 +84,7 @@ public class FriendRepository extends RepositoryBase
|
||||
final NautHashMap<String, FriendData> friends = new NautHashMap<String, FriendData>();
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
//stringBuilder.append(RETRIEVE_MULTIPLE_FRIEND_RECORDS + "(");
|
||||
stringBuilder.append(RETRIEVE_MULTIPLE_FRIEND_RECORDS + "(");
|
||||
|
||||
for (Player player : players)
|
||||
{
|
||||
|
@ -70,10 +70,10 @@ public class ServerStatusManager extends MiniPlugin
|
||||
getPlugin().getConfig().addDefault("serverstatus.connectionurl", "db.mineplex.com:3306");
|
||||
getPlugin().getConfig().set("serverstatus.connectionurl", getPlugin().getConfig().getString("serverstatus.connectionurl"));
|
||||
|
||||
getPlugin().getConfig().addDefault("serverstatus.username", "root");
|
||||
getPlugin().getConfig().addDefault("serverstatus.username", "MilitaryPolice");
|
||||
getPlugin().getConfig().set("serverstatus.username", getPlugin().getConfig().getString("serverstatus.username"));
|
||||
|
||||
getPlugin().getConfig().addDefault("serverstatus.password", "tAbechAk3wR7tuTh");
|
||||
getPlugin().getConfig().addDefault("serverstatus.password", "CUPr6Wuw2Rus$qap");
|
||||
getPlugin().getConfig().set("serverstatus.password", getPlugin().getConfig().getString("serverstatus.password"));
|
||||
|
||||
getPlugin().getConfig().addDefault("serverstatus.us", true);
|
||||
|
@ -4,8 +4,8 @@
|
||||
<jdbc>
|
||||
<driver>com.mysql.jdbc.Driver</driver>
|
||||
<url>jdbc:mysql://db.mineplex.com:3306</url>
|
||||
<user>root</user>
|
||||
<password>tAbechAk3wR7tuTh</password>
|
||||
<user>MilitaryPolice</user>
|
||||
<password>CUPr6Wuw2Rus$qap</password>
|
||||
</jdbc>
|
||||
|
||||
<generator>
|
||||
|
@ -17,7 +17,6 @@ import mineplex.servermonitor.data.BungeeStatusData;
|
||||
public class StatusHistoryRepository
|
||||
{
|
||||
private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/ServerStats";
|
||||
private String _bungeeConnectionString = "jdbc:mysql://db.mineplex.com:3306/BungeeServers";
|
||||
private String _userName = "root";
|
||||
private String _password = "tAbechAk3wR7tuTh";
|
||||
|
||||
@ -47,9 +46,6 @@ public class StatusHistoryRepository
|
||||
if (_connection == null || _connection.isClosed())
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
if (_bungeeconnection == null || _bungeeconnection.isClosed())
|
||||
_bungeeconnection = DriverManager.getConnection(_bungeeConnectionString, _userName, _password);
|
||||
|
||||
// Create table
|
||||
preparedStatement = _connection.prepareStatement(CREATE_GROUP_TABLE);
|
||||
preparedStatement.execute();
|
||||
@ -189,6 +185,7 @@ public class StatusHistoryRepository
|
||||
|
||||
public void saveNetworkStats(double usedCpuPercent, double usedRamPercent, double availableCPU, double availableRAM, Region region)
|
||||
{
|
||||
/*
|
||||
int totalPlayers = 0;
|
||||
|
||||
List<BungeeStatusData> bungeeStatuses = new ArrayList<BungeeStatusData>();
|
||||
@ -318,5 +315,6 @@ public class StatusHistoryRepository
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user