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

Conflicts:
	Plugins/Mineplex.Core/src/mineplex/core/inventory/data/InventoryRepository.java
This commit is contained in:
Chiss 2014-11-26 12:34:47 +11:00
commit 95e428eb4f
52 changed files with 612 additions and 974 deletions

View File

@ -7,25 +7,20 @@ import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.account.event.ClientUnloadEvent;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.util.NautHashMap;
public abstract class MiniClientPlugin<DataType extends Object> extends MiniPlugin
{
private static Object _clientDataLock = new Object();
private NautHashMap<String, DataType> _clientData = new NautHashMap<String, DataType>();
public MiniClientPlugin(String moduleName, JavaPlugin plugin)
{
super(moduleName, plugin);
}
@EventHandler
public void loadPlayer(RetrieveClientInformationEvent event)
{
loadClientInformation(event);
}
@EventHandler
public void UnloadPlayer(ClientUnloadEvent event)
{
@ -70,6 +65,4 @@ public abstract class MiniClientPlugin<DataType extends Object> extends MiniPlug
}
protected abstract DataType AddPlayer(String player);
protected abstract void loadClientInformation(RetrieveClientInformationEvent event);
}

View File

@ -0,0 +1,25 @@
package mineplex.core;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.ILoginProcessor;
public abstract class MiniDbClientPlugin<DataType extends Object> extends MiniClientPlugin<DataType> implements ILoginProcessor
{
protected CoreClientManager ClientManager = null;
public MiniDbClientPlugin(String moduleName, JavaPlugin plugin, CoreClientManager clientManager)
{
super(moduleName, plugin);
ClientManager = clientManager;
clientManager.addStoredProcedureLoginProcessor(this);
}
public abstract void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException;
}

View File

@ -10,10 +10,8 @@ import java.util.UUID;
import mineplex.core.MiniPlugin;
import mineplex.core.account.command.UpdateRank;
import mineplex.core.account.event.AsyncClientLoadEvent;
import mineplex.core.account.event.ClientUnloadEvent;
import mineplex.core.account.event.ClientWebResponseEvent;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.account.repository.AccountRepository;
import mineplex.core.account.repository.token.ClientToken;
import mineplex.core.common.Rank;
@ -41,11 +39,15 @@ import org.bukkit.plugin.java.JavaPlugin;
public class CoreClientManager extends MiniPlugin
{
private static NautHashMap<String, Object> _clientLoginLock = new NautHashMap<String, Object>();
private JavaPlugin _plugin;
private AccountRepository _repository;
private NautHashMap<String, CoreClient> _clientList;
private HashSet<String> _duplicateLoginGlitchPreventionList;
private NautHashMap<String, ILoginProcessor> _loginProcessors = new NautHashMap<String, ILoginProcessor>();
private Object _clientLock = new Object();
private static int _connectingClients = 0;
@ -187,38 +189,11 @@ public class CoreClientManager extends MiniPlugin
client.SetAccountId(token.AccountId);
client.SetRank(Rank.valueOf(token.Rank));
final RetrieveClientInformationEvent clientInformationEvent = new RetrieveClientInformationEvent(client.GetPlayerName(), uuid);
clientInformationEvent.incrementProcessingCount();
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
_repository.login(uuid.toString(), client.GetPlayerName());
Bukkit.getServer().getPluginManager().callEvent(clientInformationEvent);
clientInformationEvent.decreaseProcessingCount();
}
});
_repository.login(_loginProcessors, uuid.toString(), client.GetPlayerName());
// JSON sql response
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid));
// Load client in miniplugins
Bukkit.getServer().getPluginManager().callEvent(new AsyncClientLoadEvent(token, client));
while (clientInformationEvent.processing())
{
try
{
Thread.sleep(1);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
Bukkit.getServer().getScheduler().runTask(GetPlugin(), new Runnable()
{
public void run()
@ -235,42 +210,38 @@ public class CoreClientManager extends MiniPlugin
{
TimingManager.start(client.GetPlayerName() + " LoadClient Total.");
_clientLoginLock.put(client.GetPlayerName(), new Object());
ClientToken token = null;
Gson gson = new Gson();
final RetrieveClientInformationEvent clientInformationEvent = new RetrieveClientInformationEvent(client.GetPlayerName(), uuid);
clientInformationEvent.incrementProcessingCount();
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
runAsync(new Runnable()
{
public void run()
{
_repository.login(uuid.toString(), client.GetPlayerName());
Bukkit.getServer().getPluginManager().callEvent(clientInformationEvent);
clientInformationEvent.decreaseProcessingCount();
_repository.login(_loginProcessors, uuid.toString(), client.GetPlayerName());
_clientLoginLock.remove(client.GetPlayerName());
}
});
TimingManager.start(client.GetPlayerName() + " GetClient.");
String response = _repository.GetClient(client.GetPlayerName(), uuid, ipAddress);
TimingManager.stop(client.GetPlayerName() + " GetClient.");
token = gson.fromJson(response, ClientToken.class);
client.SetAccountId(token.AccountId);
client.SetRank(Rank.valueOf(token.Rank));
_repository.updateMysqlRank(uuid.toString(), token.Rank, token.RankPerm, new Timestamp(Date.parse(token.RankExpire)).toString());
// _repository.updateMysqlRank(uuid.toString(), token.Rank, token.RankPerm, new Timestamp(Date.parse(token.RankExpire)).toString());
// JSON sql response
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid));
// Load client in miniplugins
Bukkit.getServer().getPluginManager().callEvent(new AsyncClientLoadEvent(token, client));
while (clientInformationEvent.processing())
while (_clientLoginLock.containsKey(client.GetPlayerName()))
{
try
{
Thread.sleep(1);
Thread.sleep(2);
}
catch (InterruptedException e)
{
@ -431,4 +402,9 @@ public class CoreClientManager extends MiniPlugin
}
}
}
public void addStoredProcedureLoginProcessor(ILoginProcessor processor)
{
_loginProcessors.put(processor.getName(), processor);
}
}

View File

@ -0,0 +1,13 @@
package mineplex.core.account;
import java.sql.ResultSet;
import java.sql.SQLException;
public interface ILoginProcessor
{
String getName();
void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException;
String getQuery(String uuid, String name);
}

View File

@ -1,41 +0,0 @@
package mineplex.core.account.event;
import mineplex.core.account.CoreClient;
import mineplex.core.account.repository.token.ClientToken;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class AsyncClientLoadEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private ClientToken _token;
private CoreClient _client;
public AsyncClientLoadEvent(ClientToken token, CoreClient client)
{
_token = token;
_client = client;
}
public CoreClient GetClient()
{
return _client;
}
public ClientToken GetClientToken()
{
return _token;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
}

View File

@ -1,56 +0,0 @@
package mineplex.core.account.event;
import java.util.UUID;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class RetrieveClientInformationEvent extends Event
{
private static final HandlerList handlers = new HandlerList();
private String _playerName;
private UUID _uuid;
private int _processingCount;
public RetrieveClientInformationEvent(String playerName, UUID uuid)
{
_playerName = playerName;
_uuid = uuid;
}
public HandlerList getHandlers()
{
return handlers;
}
public static HandlerList getHandlerList()
{
return handlers;
}
public String getPlayerName()
{
return _playerName;
}
public UUID getUniqueId()
{
return _uuid;
}
public void incrementProcessingCount()
{
_processingCount++;
}
public boolean processing()
{
return _processingCount > 0;
}
public void decreaseProcessingCount()
{
_processingCount--;
}
}

View File

@ -2,6 +2,7 @@ package mineplex.core.account.repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
@ -11,10 +12,12 @@ import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.account.ILoginProcessor;
import mineplex.core.account.repository.token.LoginToken;
import mineplex.core.account.repository.token.RankUpdateToken;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.database.DatabaseRunnable;
import mineplex.core.database.RepositoryBase;
@ -26,9 +29,10 @@ import mineplex.core.server.remotecall.JsonWebCall;
public class AccountRepository extends RepositoryBase
{
private static String _loginString = null;
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_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 = ?;";
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 UPDATE_ACCOUNT_RANK = "UPDATE accounts SET rank=?, rankPerm=false, rankExpire=now() + INTERVAL 1 MONTH WHERE uuid = ?;";
private static String UPDATE_ACCOUNT_RANK_DONOR = "UPDATE accounts SET rank=?, donorRank=?, rankPerm=false, rankExpire=now() + INTERVAL 1 MONTH WHERE uuid = ?;";
private static String UPDATE_ACCOUNT_RANK_PERM = "UPDATE accounts SET rank=?, rankPerm=true WHERE uuid = ?;";
@ -41,9 +45,34 @@ public class AccountRepository extends RepositoryBase
public AccountRepository(JavaPlugin plugin, String webAddress)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true", "root", "tAbechAk3wR7tuTh");
_webAddress = webAddress;
Statement statement = null;
try
{
statement = getConnection().createStatement();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (statement != null)
{
try
{
statement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
@Override
@ -52,12 +81,110 @@ public class AccountRepository extends RepositoryBase
executeUpdate(CREATE_ACCOUNT_TABLE);
}
public void login(String uuid, String name)
public void login(NautHashMap<String, ILoginProcessor> loginProcessors, String uuid, String name)
{
int affectedRows = executeUpdate(ACCOUNT_LOGIN_UPDATE, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 40, name), new ColumnVarChar("uuid", 100, uuid));
Statement statement = null;
ResultSet resultSet = null;
if (affectedRows == 0)
executeUpdate(ACCOUNT_LOGIN_NEW, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 40, name));
try
{
statement = getConnection().createStatement();
/*
boolean statementStatus = statement.execute(
"UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE accounts.uuid = '" + uuid + "';"
+ "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests FROM accountPreferences WHERE accountPreferences.uuid = '" + uuid + "' LIMIT 1;"
+ "SELECT items.name, ic.name as category, count FROM accountInventory AS ai INNER JOIN items ON items.id = ai.itemId INNER JOIN itemCategories AS ic ON ic.id = items.categoryId INNER JOIN accounts ON accounts.id = ai.accountId WHERE accounts.uuid = '" + uuid + "';"
+ "SELECT benefit FROM rankBenefits WHERE rankBenefits.uuid = '" + uuid + "';"
+ "SELECT stats.name, value FROM accountStats INNER JOIN stats ON stats.id = accountStats.statId INNER JOIN accounts ON accountStats.accountId = accounts.id WHERE accounts.uuid = '" + uuid + "';"
+ "SELECT tA.Name, status, serverName, tA.lastLogin, now() 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 = '" + uuid + "';"
+ "SELECT gameType, elo FROM eloRating WHERE uuid = '" + uuid + "';"
);
*/
if (_loginString == null)
{
_loginString = "UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE accounts.uuid = '" + uuid + "';";
for (ILoginProcessor loginProcessor : loginProcessors.values())
{
_loginString += loginProcessor.getQuery(uuid, name);
System.out.println(loginProcessor.getClass().toString());
}
}
statement.execute(_loginString);
/*
while (true)
{
if (statementStatus)
{
System.out.println("ResultSet : " + statement.getResultSet().getMetaData().getColumnCount() + " columns:");
for (int i = 0; i < statement.getResultSet().getMetaData().getColumnCount(); i++)
{
System.out.println(statement.getResultSet().getMetaData().getColumnName(i + 1));
}
}
else
{
if (statement.getUpdateCount() == -1)
break;
System.out.println("Update statement : " + statement.getUpdateCount() + " rows affected.");
}
statementStatus = statement.getMoreResults();
}
System.out.println("Done");
*/
boolean accountExists = statement.getUpdateCount() != 0;
statement.getMoreResults();
for (ILoginProcessor loginProcessor : loginProcessors.values())
{
loginProcessor.processLoginResultSet(name, statement.getResultSet());
System.out.println(loginProcessor.getClass().toString());
}
statement.getMoreResults();
if (!accountExists)
{
executeUpdate(ACCOUNT_LOGIN_NEW, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 100, name));
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (statement != null)
{
try
{
statement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
if (resultSet != null)
{
try
{
resultSet.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
public String GetClient(String name, UUID uuid, String ipAddress)

View File

@ -1,138 +0,0 @@
package mineplex.core.antistack;
import java.util.HashSet;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.UtilMath;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class AntiStack extends MiniPlugin
{
private boolean _enabled = true;
private HashSet<Location> _ignoreAround = new HashSet<Location>();
public AntiStack(JavaPlugin plugin)
{
super("AntiStack", plugin);
}
@EventHandler(priority = EventPriority.MONITOR)
public void BlockBreak(BlockBreakEvent event)
{
if (!_enabled)
return;
if (event.isCancelled())
return;
_ignoreAround.add(event.getBlock().getLocation().add(0.5, 0.5, 0.5));
}
@EventHandler
public void ClearIgnoreAround(UpdateEvent event)
{
if (!_enabled)
return;
if (event.getType() != UpdateType.TICK)
return;
_ignoreAround.clear();
}
@EventHandler (priority=EventPriority.HIGHEST)
public void ItemSpawn(ItemSpawnEvent event)
{
if (!_enabled)
return;
if (event.isCancelled())
return;
Item item = event.getEntity();
for (Location loc : _ignoreAround)
if (UtilMath.offset(loc, event.getLocation()) < 2)
return;
//ItemName()
if (item.getLocation().getY() < -10)
return;
//Get Name
String name = ((CraftItemStack)item.getItemStack()).getHandle().getName();
//Append UID
name += ":" + item.getUniqueId();
//Set Name
((CraftItemStack)item.getItemStack()).getHandle().c(name);
}
@EventHandler (priority=EventPriority.HIGHEST)
public void PlayerPickup(PlayerPickupItemEvent event)
{
if (!_enabled)
return;
if (event.isCancelled())
return;
Item item = event.getItem();
removeUID(item);
}
@EventHandler
public void HopperPickup(InventoryPickupItemEvent event)
{
if (!_enabled)
return;
if (event.isCancelled())
return;
Item item = event.getItem();
//Get Name
String name = ((CraftItemStack)item.getItemStack()).getHandle().getName();
//Remove UID
if (name.contains(":"))
name = name.substring(0, name.indexOf(":" + item.getUniqueId()));
//Set Name
((CraftItemStack)item.getItemStack()).getHandle().c(name);
}
public void SetEnabled(boolean var)
{
_enabled = var;
}
public static void removeUID(Item item)
{
//Get Name
String name = ((CraftItemStack)item.getItemStack()).getHandle().getName();
//Remove UID
if (name.contains(":"))
name = name.substring(0, name.indexOf(":" + item.getUniqueId()));
//Set Name
((CraftItemStack)item.getItemStack()).getHandle().c(name);
}
}

View File

@ -0,0 +1,84 @@
package mineplex.core.benefit;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.benefit.benefits.BenefitBase;
import mineplex.core.common.util.Callback;
import mineplex.core.inventory.InventoryManager;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class BenefitManager extends MiniDbClientPlugin<PlayerBenefit>
{
private BenefitManagerRepository _repository;
private List<BenefitBase> _benefits = new ArrayList<BenefitBase>();
public BenefitManager(JavaPlugin plugin, CoreClientManager clientManager, InventoryManager inventoryManager)
{
super("Benefit Manager", plugin, clientManager);
_repository = new BenefitManagerRepository(plugin);
//_benefits.add(new Thanksgiving2014(plugin, _repository, inventoryManager));
}
@EventHandler(priority = EventPriority.LOWEST)
public void giveBenefit(final PlayerJoinEvent event)
{
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable()
{
public void run()
{
if (Get(event.getPlayer()).Loaded)
{
for (final BenefitBase benefit : _benefits)
{
if (!Get(event.getPlayer()).Benefits.contains(benefit.getName()))
{
benefit.recordBenefit(event.getPlayer(), new Callback<Boolean>()
{
public void run(Boolean success)
{
if (success)
{
benefit.rewardPlayer(event.getPlayer());
}
else
System.out.println("Benefit reward failed for " + event.getPlayer().getName());
}
});
}
}
}
}
}, 100L);
}
@Override
protected PlayerBenefit AddPlayer(String player)
{
return new PlayerBenefit();
}
@Override
public void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException
{
Set(playerName, _repository.retrievePlayerBenefitData(resultSet));
}
@Override
public String getQuery(String uuid, String name)
{
return "SELECT benefit FROM rankBenefits WHERE rankBenefits.uuid = '" + uuid + "';";
}
}

View File

@ -2,23 +2,19 @@ package mineplex.core.benefit;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
import org.bukkit.plugin.java.JavaPlugin;
public class RankBenefitsGiver9000Repository extends RepositoryBase
public class BenefitManagerRepository extends RepositoryBase
{
// private static String CREATE_BENEFIT_TABLE = "CREATE TABLE IF NOT EXISTS rankBenefits (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), benefit VARCHAR(100), PRIMARY KEY (id), INDEX rankUuid (uuid));";
private static String INSERT_BENEFIT = "INSERT INTO rankBenefits (uuid, benefit) VALUES (?, ?);";
private static String RETRIEVE_BENEFITS = "SELECT benefit FROM rankBenefits WHERE uuid = ?;";
public RankBenefitsGiver9000Repository(JavaPlugin plugin)
public BenefitManagerRepository(JavaPlugin plugin)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
}
@ -33,27 +29,21 @@ public class RankBenefitsGiver9000Repository extends RepositoryBase
protected void update()
{
}
public List<String> retrievePlayerBenefits(String uuid)
{
final List<String> benefits = new ArrayList<String>();
executeQuery(RETRIEVE_BENEFITS, new ResultSetCallable()
{
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
benefits.add(resultSet.getString(1));
}
}
}, new ColumnVarChar("uuid", 100, uuid));
return benefits;
}
public boolean addBenefit(String uuid, String benefit)
{
return executeUpdate(INSERT_BENEFIT, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("benefit", 100, benefit)) > 0;
}
public PlayerBenefit retrievePlayerBenefitData(ResultSet resultSet) throws SQLException
{
PlayerBenefit playerBenefit = new PlayerBenefit();
while (resultSet.next())
{
playerBenefit.Benefits.add(resultSet.getString(1));
}
return playerBenefit;
}
}

View File

@ -1,82 +0,0 @@
package mineplex.core.benefit;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.benefit.benefits.BenefitBase;
import mineplex.core.benefit.benefits.Thanksgiving2014;
import mineplex.core.common.util.Callback;
import mineplex.core.inventory.InventoryManager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class RankBenefitsGiver9000 extends MiniClientPlugin<PlayerBenefit>
{
private RankBenefitsGiver9000Repository _repository;
private List<BenefitBase> _benefits = new ArrayList<BenefitBase>();
public RankBenefitsGiver9000(JavaPlugin plugin, CoreClientManager clientManager, InventoryManager inventoryManager)
{
super("RankBenefitsGiver9000", plugin);
_repository = new RankBenefitsGiver9000Repository(plugin);
_benefits.add(new Thanksgiving2014(plugin, _repository, inventoryManager));
}
@EventHandler(priority = EventPriority.LOWEST)
public void giveBenefit(final PlayerJoinEvent event)
{
for (final BenefitBase benefit : _benefits)
{
if (!Get(event.getPlayer()).Benefits.contains(benefit.getName()))
{
benefit.recordBenefit(event.getPlayer(), new Callback<Boolean>()
{
public void run(Boolean success)
{
if (success)
{
benefit.rewardPlayer(event.getPlayer());
}
else
System.out.println("Benefit reward failed for " + event.getPlayer().getName());
}
});
}
}
}
@Override
protected PlayerBenefit AddPlayer(String player)
{
return new PlayerBenefit();
}
@Override
protected void loadClientInformation(final RetrieveClientInformationEvent event)
{
event.incrementProcessingCount();
runAsync(new Runnable()
{
public void run()
{
for (String benefit : _repository.retrievePlayerBenefits(event.getUniqueId().toString()))
{
Get(event.getPlayerName()).Benefits.add(benefit);
}
event.decreaseProcessingCount();
}
});
}
}

View File

@ -1,6 +1,6 @@
package mineplex.core.benefit.benefits;
import mineplex.core.benefit.RankBenefitsGiver9000Repository;
import mineplex.core.benefit.BenefitManagerRepository;
import mineplex.core.common.util.Callback;
import org.bukkit.Bukkit;
@ -11,9 +11,9 @@ public abstract class BenefitBase
{
private JavaPlugin _plugin;
private String _name;
private RankBenefitsGiver9000Repository _repository;
private BenefitManagerRepository _repository;
protected BenefitBase(JavaPlugin plugin, String name, RankBenefitsGiver9000Repository repository)
protected BenefitBase(JavaPlugin plugin, String name, BenefitManagerRepository repository)
{
_plugin = plugin;
_name = name;
@ -25,7 +25,7 @@ public abstract class BenefitBase
return _plugin;
}
public RankBenefitsGiver9000Repository getRepository()
public BenefitManagerRepository getRepository()
{
return _repository;
}

View File

@ -1,6 +1,6 @@
package mineplex.core.benefit.benefits;
import mineplex.core.benefit.RankBenefitsGiver9000Repository;
import mineplex.core.benefit.BenefitManagerRepository;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilPlayer;
@ -14,7 +14,7 @@ public class Thanksgiving2014 extends BenefitBase
{
private InventoryManager _inventoryManager;
public Thanksgiving2014(JavaPlugin plugin, RankBenefitsGiver9000Repository repository, InventoryManager inventoryManager)
public Thanksgiving2014(JavaPlugin plugin, BenefitManagerRepository repository, InventoryManager inventoryManager)
{
super(plugin, "Thanksgiving2014", repository);

View File

@ -10,6 +10,7 @@ import java.util.Iterator;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.column.Column;
import mineplex.core.logger.Logger;
import mineplex.core.timing.TimingManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -83,6 +84,7 @@ public abstract class RepositoryBase implements Listener
protected int executeUpdate(String query, ResultSetCallable callable, Column<?>...columns)
{
TimingManager.start(getClass().getName());
PreparedStatement preparedStatement = null;
int affectedRows = 0;
@ -101,6 +103,8 @@ public abstract class RepositoryBase implements Listener
affectedRows = preparedStatement.executeUpdate();
TimingManager.stop(getClass().getName());
if (callable != null)
callable.processResultSet(preparedStatement.getGeneratedKeys());
}
@ -128,6 +132,8 @@ public abstract class RepositoryBase implements Listener
protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>...columns)
{
TimingManager.start(getClass().getName());
ResultSet resultSet = null;
try
@ -138,7 +144,7 @@ public abstract class RepositoryBase implements Listener
}
resultSet = statement.executeQuery();
TimingManager.stop(getClass().getName());
callable.processResultSet(resultSet);
}
catch (Exception exception)

View File

@ -68,7 +68,7 @@ public class DonationManager extends MiniPlugin
synchronized (_donorLock)
{
_donors.put(token.Name, new Donor(token.DonorToken));
_repository.updateGemsAndCoins(uuid, Get(token.Name).GetGems(), Get(token.Name).getCoins());
//_repository.updateGemsAndCoins(uuid, Get(token.Name).GetGems(), Get(token.Name).getCoins());
}
}

View File

@ -0,0 +1,8 @@
package mineplex.core.elo;
import mineplex.core.common.util.NautHashMap;
public class EloClientData
{
public NautHashMap<String, Integer> Elos = new NautHashMap<String, Integer>();
}

View File

@ -1,16 +1,17 @@
package mineplex.core.elo;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import mineplex.core.MiniPlugin;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.NautHashMap;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
public class EloManager extends MiniPlugin
public class EloManager extends MiniDbClientPlugin<EloClientData>
{
private static Object _playerEloLock = new Object();
@ -18,51 +19,15 @@ public class EloManager extends MiniPlugin
private EloRatingSystem _ratingSystem;
private NautHashMap<String, NautHashMap<String, Integer>> _playerElos;
public EloManager(JavaPlugin plugin)
public EloManager(JavaPlugin plugin, CoreClientManager clientManager)
{
super("Elo Rating", plugin);
setupConfigValues(plugin);
_repository = new EloRepository(plugin.getConfig().getString("elo.connectionurl"));
super("Elo Rating", plugin, clientManager);
_repository = new EloRepository(plugin);
_ratingSystem = new EloRatingSystem(new KFactor(0, 1200, 25), new KFactor(1201, 1600, 20), new KFactor(1601, 2000, 15), new KFactor(2001, 2500, 10));
_playerElos = new NautHashMap<String, NautHashMap<String, Integer>>();
}
private void setupConfigValues(JavaPlugin plugin)
{
try
{
plugin.getConfig().addDefault("elo.connectionurl", "jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex?autoReconnect=true&failOverReadOnly=false&maxReconnects=10");
plugin.getConfig().set("elo.connectionurl", plugin.getConfig().getString("elo.connectionurl"));
plugin.saveConfig();
}
catch (Exception e)
{
e.printStackTrace();
}
}
@EventHandler
public void retrievePlayersElos(final RetrieveClientInformationEvent event)
{
event.incrementProcessingCount();
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
NautHashMap<String, Integer> eloMap = _repository.loadClientInformation(event.getUniqueId());
synchronized (_playerEloLock)
{
_playerElos.put(event.getUniqueId().toString(), eloMap);
}
event.decreaseProcessingCount();
}
});
}
public int getElo(UUID uuid, String gameType)
{
int elo = 1000;
@ -135,4 +100,22 @@ public class EloManager extends MiniPlugin
}
});
}
@Override
protected EloClientData AddPlayer(String player)
{
return new EloClientData();
}
@Override
public void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException
{
Set(playerName, _repository.loadClientInformation(resultSet));
}
@Override
public String getQuery(String uuid, String name)
{
return "SELECT gameType, elo FROM eloRating WHERE uuid = '" + uuid + "';";
}
}

View File

@ -1,172 +1,50 @@
package mineplex.core.elo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import mineplex.core.common.util.NautHashMap;
import org.bukkit.plugin.java.JavaPlugin;
public class EloRepository
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
public class EloRepository extends RepositoryBase
{
private String _connectionString;
private String _userName = "root";
private String _password = "tAbechAk3wR7tuTh";
private static String CREATE_ELO_TABLE = "CREATE TABLE IF NOT EXISTS eloRating (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), gameType VARCHAR(256), elo INT, PRIMARY KEY (id), UNIQUE INDEX uuid_gameType_index (uuid, gameType));";
private static String INSERT_ELO = "INSERT INTO eloRating (uuid, gameType, elo) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE elo=VALUES(elo);";
private static String RETRIEVE_ELO = "SELECT gameType, elo FROM eloRating WHERE uuid = ?;";
private Connection _connection = null;
public EloRepository(String connectionUrl)
public EloRepository(JavaPlugin plugin)
{
_connectionString = connectionUrl;
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
initialize();
}
public void initialize()
{
PreparedStatement preparedStatement = null;
try
{
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
preparedStatement = _connection.prepareStatement(CREATE_ELO_TABLE);
preparedStatement.execute();
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
executeUpdate(CREATE_ELO_TABLE);
}
public void saveElo(String uuid, String gameType, int elo)
{
PreparedStatement preparedStatement = null;
int affectedRows = 0;
try
{
if (_connection.isClosed())
{
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
}
preparedStatement = _connection.prepareStatement(INSERT_ELO);
preparedStatement.setString(1, uuid);
preparedStatement.setString(2, gameType);
preparedStatement.setInt(3, elo);
affectedRows = preparedStatement.executeUpdate();
if (affectedRows == 0)
{
System.out.println("Error saving Elo.");
}
else
{
System.out.println("Saved '" + uuid + "' for '" + gameType + "' new elo " + elo);
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
executeUpdate(INSERT_ELO, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("gameType", 100, gameType), new ColumnInt("elo", elo));
}
public NautHashMap<String, Integer> loadClientInformation(UUID uuid)
public EloClientData loadClientInformation(ResultSet resultSet) throws SQLException
{
NautHashMap<String, Integer> elos = new NautHashMap<String, Integer>();
ResultSet resultSet = null;
PreparedStatement preparedStatement = null;
EloClientData clientData = new EloClientData();
try
while (resultSet.next())
{
if (_connection.isClosed())
{
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
}
preparedStatement = _connection.prepareStatement(RETRIEVE_ELO);
preparedStatement.setString(1, uuid.toString());
resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
elos.put(resultSet.getString(1), resultSet.getInt(2));
}
}
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();
}
}
clientData.Elos.put(resultSet.getString(1), resultSet.getInt(2));
}
return elos;
return clientData;
}
@Override
protected void update()
{
}
}

View File

@ -10,7 +10,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
@ -153,49 +152,8 @@ public class Energy extends MiniClientPlugin<ClientEnergy>
Get(player).MaxEnergyMods.remove(reason);
}
@Override
protected void loadClientInformation(RetrieveClientInformationEvent event)
{
}
public void setEnabled(boolean b)
{
_enabled = b;
}
/* ENERGY NO LONGER USED ON ATTACK
public void AddEnergySwingMod(Player player, String reason, int amount)
{
Get(player).SwingEnergyMods.put(reason, amount);
}
public void RemoveEnergySwingMod(Player player, String reason)
{
Get(player).SwingEnergyMods.remove(reason);
}
@EventHandler
public void WeaponSwing(PlayerInteractEvent event)
{
if (!UtilEvent.isAction(event, ActionType.L))
return;
Player player = event.getPlayer();
if (!UtilGear.isWeapon(player.getItemInHand()))
return;
if (player.hasPotionEffect(PotionEffectType.FAST_DIGGING))
return;
ModifyEnergy(player, -Get(player).SwingEnergy());
}
@EventHandler
public void ShootBow(EntityShootBowEvent event)
{
if (event.getEntity() instanceof Player)
ModifyEnergy((Player)event.getEntity(), -10);
}
*/
}

View File

@ -1,5 +1,7 @@
package mineplex.core.friend;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
@ -11,9 +13,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.Rank;
import mineplex.core.common.jsonchat.ChildJsonMessage;
import mineplex.core.common.jsonchat.JsonMessage;
@ -31,19 +32,17 @@ import mineplex.core.preferences.PreferencesManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class FriendManager extends MiniClientPlugin<FriendData>
public class FriendManager extends MiniDbClientPlugin<FriendData>
{
private static FriendSorter _friendSorter = new FriendSorter();
private CoreClientManager _clientManager;
private PreferencesManager _preferenceManager;
private FriendRepository _repository;
public FriendManager(JavaPlugin plugin, CoreClientManager clientManager, PreferencesManager preferences)
{
super("Friends", plugin);
super("Friends", plugin, clientManager);
_clientManager = clientManager;
_preferenceManager = preferences;
_repository = new FriendRepository(plugin);
}
@ -61,20 +60,6 @@ public class FriendManager extends MiniClientPlugin<FriendData>
return new FriendData();
}
@Override
protected void loadClientInformation(final RetrieveClientInformationEvent event)
{
event.incrementProcessingCount();
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
Set(event.getPlayerName(), _repository.loadClientInformation(event.getUniqueId()));
event.decreaseProcessingCount();
}
});
}
@EventHandler
public void updateFriends(UpdateEvent event)
{
@ -262,7 +247,7 @@ public class FriendManager extends MiniClientPlugin<FriendData>
public void showFriends(Player caller)
{
boolean isStaff = _clientManager.Get(caller).GetRank().Has(Rank.HELPER);
boolean isStaff = ClientManager.Get(caller).GetRank().Has(Rank.HELPER);
boolean gotAFriend = false;
List<FriendStatus> friendStatuses = Get(caller).Friends;
Collections.sort(friendStatuses, _friendSorter);
@ -379,4 +364,16 @@ public class FriendManager extends MiniClientPlugin<FriendData>
caller.sendMessage(C.cAqua + C.Strike + "=====================================================");
}
@Override
public void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException
{
Set(playerName, _repository.loadClientInformation(resultSet));
}
@Override
public String getQuery(String uuid, String name)
{
return "SELECT tA.Name, status, serverName, tA.lastLogin, now() 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 = '" + uuid + "';";
}
}

View File

@ -2,7 +2,6 @@ package mineplex.core.friend.data;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
@ -16,16 +15,11 @@ import mineplex.core.friend.FriendStatusType;
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), status VARCHAR(100), PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuidSource, uuidTarget));";
private static String RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, tA.Name, status, serverName, tA.lastLogin, now() 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, status, serverName, tA.lastLogin, now() 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 RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, tA.Name, status, serverName, tA.lastLogin, now() 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, status) SELECT fA.uuid AS uuidSource, tA.uuid AS uuidTarget, ? 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 = ?;";
// Not mutual, need to drop accountFriend to recreate with constraint.
// On add record need to check for a reverse uuidsource/uuidtarget and set mutual
public FriendRepository(JavaPlugin plugin)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
@ -109,27 +103,21 @@ public class FriendRepository extends RepositoryBase
return friends;
}
public FriendData loadClientInformation(final UUID uniqueId)
public FriendData loadClientInformation(ResultSet resultSet) throws SQLException
{
final FriendData friendData = new FriendData();
FriendData friendData = new FriendData();
executeQuery(RETRIEVE_FRIEND_RECORDS, new ResultSetCallable()
while (resultSet.next())
{
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
FriendStatus friend = new FriendStatus();
friend.Name = resultSet.getString(1);
friend.Status = Enum.valueOf(FriendStatusType.class, resultSet.getString(2));
friend.ServerName = resultSet.getString(3);
friend.LastSeenOnline = resultSet.getTimestamp(5).getTime() - resultSet.getTimestamp(4).getTime();
friendData.Friends.add(friend);
}
}
}, new ColumnVarChar("uuidSource", 100, uniqueId.toString()));
FriendStatus friend = new FriendStatus();
friend.Name = resultSet.getString(1);
friend.Status = Enum.valueOf(FriendStatusType.class, resultSet.getString(2));
friend.ServerName = resultSet.getString(3);
friend.LastSeenOnline = resultSet.getTimestamp(5).getTime() - resultSet.getTimestamp(4).getTime();
friendData.Friends.add(friend);
}
return friendData;
}

View File

@ -1,5 +1,7 @@
package mineplex.core.inventory;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
@ -7,8 +9,8 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.inventory.command.GiveItemCommand;
@ -16,7 +18,7 @@ import mineplex.core.inventory.data.Category;
import mineplex.core.inventory.data.InventoryRepository;
import mineplex.core.inventory.data.Item;
public class InventoryManager extends MiniClientPlugin<ClientInventory>
public class InventoryManager extends MiniDbClientPlugin<ClientInventory>
{
private static Object _inventoryLock = new Object();
@ -25,9 +27,9 @@ public class InventoryManager extends MiniClientPlugin<ClientInventory>
private NautHashMap<String, Item> _items = new NautHashMap<String, Item>();
private NautHashMap<String, Category> _categories = new NautHashMap<String, Category>();
public InventoryManager(JavaPlugin plugin)
public InventoryManager(JavaPlugin plugin, CoreClientManager clientManager)
{
super("Inventory Manager", plugin);
super("Inventory Manager", plugin, clientManager);
_repository = new InventoryRepository(plugin);
@ -69,6 +71,11 @@ public class InventoryManager extends MiniClientPlugin<ClientInventory>
public void addItemToInventory(final Player player, String category, final String item, final int count)
{
if (_items.containsKey(item))
{
Get(player).addItem(new ClientItem(_items.get(item), count));
}
addItemToInventory(null, player, category, item, count);
}
@ -78,16 +85,15 @@ public class InventoryManager extends MiniClientPlugin<ClientInventory>
{
public void run(Boolean success)
{
if (success)
if (!success)
{
System.out.println("Add item to Inventory FAILED for " + player.getName());
if (_items.containsKey(item))
{
Get(player).addItem(new ClientItem(_items.get(item), count));
Get(player).addItem(new ClientItem(_items.get(item), -count));
}
System.out.println("Add item to Inventory succeeded.");
}
else
System.out.println("Add item to Inventory FAILED for " + player.getName());
if (callback != null)
callback.run(success);
@ -165,23 +171,21 @@ public class InventoryManager extends MiniClientPlugin<ClientInventory>
return new ClientInventory();
}
@Override
protected void loadClientInformation(final RetrieveClientInformationEvent event)
{
event.incrementProcessingCount();
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
Set(event.getPlayerName(), _repository.loadClientInformation(event.getUniqueId().toString()));
event.decreaseProcessingCount();
}
});
}
@Override
public void AddCommands()
{
addCommand(new GiveItemCommand(this));
}
@Override
public void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException
{
Set(playerName, _repository.loadClientInformation(resultSet));
}
@Override
public String getQuery(String uuid, String name)
{
return "SELECT items.name, ic.name as category, count FROM accountInventory AS ai INNER JOIN items ON items.id = ai.itemId INNER JOIN itemCategories AS ic ON ic.id = items.categoryId INNER JOIN accounts ON accounts.id = ai.accountId WHERE accounts.uuid = '" + uuid + "';";
}
}

View File

@ -13,7 +13,6 @@ import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.core.inventory.ClientInventory;
import mineplex.core.inventory.ClientItem;
import mineplex.core.timing.TimingManager;
public class InventoryRepository extends RepositoryBase
{
@ -28,7 +27,6 @@ public class InventoryRepository extends RepositoryBase
private static String RETRIEVE_CATEGORIES = "SELECT id, name FROM itemCategories;";
private static String INSERT_CLIENT_INVENTORY = "INSERT INTO accountInventory (accountId, itemId, count) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.uuid = ? ON DUPLICATE KEY UPDATE count=count + VALUES(count);";
private static String RETRIEVE_CLIENT_INVENTORY = "SELECT items.name, ic.name as category, count FROM accountInventory AS ai INNER JOIN items ON items.id = ai.itemId INNER JOIN itemCategories AS ic ON ic.id = items.categoryId INNER JOIN accounts ON accounts.id = ai.accountId WHERE accounts.uuid = ?;";
public InventoryRepository(JavaPlugin plugin)
{
@ -99,20 +97,15 @@ public class InventoryRepository extends RepositoryBase
return executeUpdate(INSERT_CLIENT_INVENTORY, new ColumnInt("itemid", itemId), new ColumnInt("count", count), new ColumnVarChar("uuid", 100, uuid)) > 0;
}
public ClientInventory loadClientInformation(String uuid)
{
public ClientInventory loadClientInformation(ResultSet resultSet) throws SQLException
{
final ClientInventory clientInventory = new ClientInventory();
executeQuery(RETRIEVE_CLIENT_INVENTORY, new ResultSetCallable()
while (resultSet.next())
{
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
clientInventory.addItem(new ClientItem(new Item(resultSet.getString(1), resultSet.getString(2)), resultSet.getInt(3)));
}
}
}, new ColumnVarChar("uuid", 100, uuid));
clientInventory.addItem(new ClientItem(new Item(resultSet.getString(1), resultSet.getString(2)), resultSet.getInt(3)));
}
return clientInventory;
}
}

View File

@ -9,7 +9,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
@ -210,9 +209,4 @@ public class MessageManager extends MiniClientPlugin<ClientMessage>
{
return _clientManager;
}
@Override
protected void loadClientInformation(RetrieveClientInformationEvent event)
{
}
}

View File

@ -1,7 +1,6 @@
package mineplex.core.movement;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.util.UtilMath;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -45,9 +44,4 @@ public class Movement extends MiniClientPlugin<ClientMovement>
{
return new ClientMovement();
}
@Override
protected void loadClientInformation(RetrieveClientInformationEvent event)
{
}
}

View File

@ -3,7 +3,6 @@ package mineplex.core.pet;
import mineplex.core.common.CurrencyType;
import mineplex.core.pet.repository.token.PetSalesToken;
import mineplex.core.shop.item.SalesPackageBase;
import mineplex.core.shop.item.ShopItem;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;

View File

@ -1,11 +1,9 @@
package mineplex.core.pet;
import mineplex.core.common.CurrencyType;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.pet.repository.token.PetExtraToken;
import mineplex.core.shop.item.SalesPackageBase;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;

View File

@ -11,14 +11,10 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.ClientWebResponseEvent;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.util.C;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilServer;
import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemStackFactory;
import net.minecraft.server.v1_7_R4.EntityCreature;
import net.minecraft.server.v1_7_R4.EntityHuman;
import net.minecraft.server.v1_7_R4.EntityInsentient;
@ -27,15 +23,7 @@ import net.minecraft.server.v1_7_R4.PathfinderGoalLookAtPlayer;
import net.minecraft.server.v1_7_R4.PathfinderGoalRandomLookaround;
import net.minecraft.server.v1_7_R4.PathfinderGoalSelector;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@ -46,18 +34,13 @@ import org.bukkit.entity.Ageable;
import org.bukkit.entity.Creature;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Skeleton;
import org.bukkit.entity.Zombie;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
@ -394,11 +377,6 @@ public class PetManager extends MiniClientPlugin<PetClient>
{
return _activePetOwners.get(name);
}
@Override
protected void loadClientInformation(RetrieveClientInformationEvent event)
{
}
public void DisableAll()
{

View File

@ -1,8 +1,9 @@
package mineplex.core.preferences;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -12,9 +13,8 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemStackFactory;
@ -23,7 +23,7 @@ import mineplex.core.preferences.ui.PreferencesShop;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class PreferencesManager extends MiniClientPlugin<UserPreferences>
public class PreferencesManager extends MiniDbClientPlugin<UserPreferences>
{
private PreferencesRepository _repository;
private PreferencesShop _shop;
@ -34,7 +34,7 @@ public class PreferencesManager extends MiniClientPlugin<UserPreferences>
public PreferencesManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
{
super("Preferences", plugin);
super("Preferences", plugin, clientManager);
setupConfigValues();
@ -64,20 +64,6 @@ public class PreferencesManager extends MiniClientPlugin<UserPreferences>
return new UserPreferences();
}
@Override
protected void loadClientInformation(final RetrieveClientInformationEvent event)
{
event.incrementProcessingCount();
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
Set(event.getPlayerName(), _repository.loadClientInformation(event.getUniqueId()));
event.decreaseProcessingCount();
}
});
}
public void savePreferences(Player caller)
{
_saveBuffer.put(caller.getUniqueId().toString(), Get(caller));
@ -134,4 +120,16 @@ public class PreferencesManager extends MiniClientPlugin<UserPreferences>
{
_shop.attemptShopOpen(caller);
}
@Override
public void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException
{
Set(playerName, _repository.loadClientInformation(resultSet));
}
@Override
public String getQuery(String uuid, String name)
{
return "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests FROM accountPreferences WHERE accountPreferences.uuid = '" + uuid + "' LIMIT 1;";
}
}

View File

@ -4,20 +4,17 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map.Entry;
import java.util.UUID;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
public class PreferencesRepository extends RepositoryBase
{
private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accountPreferences (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), games BOOL NOT NULL DEFAULT 1, visibility BOOL NOT NULL DEFAULT 1, showChat BOOL NOT NULL DEFAULT 1, friendChat BOOL NOT NULL DEFAULT 1, privateMessaging BOOL NOT NULL DEFAULT 1, partyRequests BOOL NOT NULL DEFAULT 0, invisibility BOOL NOT NULL DEFAULT 0, forcefield BOOL NOT NULL DEFAULT 0, showMacReports BOOL NOT NULL DEFAULT 0, ignoreVelocity BOOL NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE INDEX uuid_index (uuid));";
private static String INSERT_ACCOUNT = "INSERT INTO accountPreferences (uuid) VALUES (?) ON DUPLICATE KEY UPDATE uuid=uuid;";
private static String RETRIEVE_ACCOUNT_PREFERENCES = "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests FROM accountPreferences WHERE uuid = ?;";
private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ? WHERE uuid=?;";
public PreferencesRepository(JavaPlugin plugin, String connectionString)
@ -61,8 +58,33 @@ public class PreferencesRepository extends RepositoryBase
preparedStatement.addBatch();
}
int[] rowsAffected = preparedStatement.executeBatch();
int i = 0;
preparedStatement.executeBatch();
for (Entry<String, UserPreferences> entry : preferences.entrySet())
{
if (rowsAffected[i] < 1)
{
executeUpdate(INSERT_ACCOUNT, new ColumnVarChar("uuid", 100, entry.getKey()));
preparedStatement.setBoolean(1, entry.getValue().HubGames);
preparedStatement.setBoolean(2, entry.getValue().ShowPlayers);
preparedStatement.setBoolean(3, entry.getValue().ShowChat);
preparedStatement.setBoolean(4, entry.getValue().FriendChat);
preparedStatement.setBoolean(5, entry.getValue().PrivateMessaging);
preparedStatement.setBoolean(6, entry.getValue().PartyRequests);
preparedStatement.setBoolean(7, entry.getValue().Invisibility);
preparedStatement.setBoolean(8, entry.getValue().HubForcefield);
preparedStatement.setBoolean(9, entry.getValue().ShowMacReports);
preparedStatement.setBoolean(10, entry.getValue().IgnoreVelocity);
preparedStatement.setBoolean(11, entry.getValue().PendingFriendRequests);
preparedStatement.setString(12, entry.getKey());
preparedStatement.execute();
}
i++;
}
}
catch (Exception exception)
{
@ -84,34 +106,24 @@ public class PreferencesRepository extends RepositoryBase
}
}
public UserPreferences loadClientInformation(final UUID uuid)
public UserPreferences loadClientInformation(final ResultSet resultSet) throws SQLException
{
final UserPreferences preferences = new UserPreferences();
executeQuery(RETRIEVE_ACCOUNT_PREFERENCES, new ResultSetCallable()
if (resultSet.next())
{
public void processResultSet(ResultSet resultSet) throws SQLException
{
if (!resultSet.next())
{
executeUpdate(INSERT_ACCOUNT, new ColumnVarChar("uuid", 100, uuid.toString()));
}
else
{
preferences.HubGames = resultSet.getBoolean(1);
preferences.ShowPlayers = resultSet.getBoolean(2);
preferences.ShowChat = resultSet.getBoolean(3);
preferences.FriendChat = resultSet.getBoolean(4);
preferences.PrivateMessaging = resultSet.getBoolean(5);
preferences.PartyRequests = resultSet.getBoolean(6);
preferences.Invisibility = resultSet.getBoolean(7);
preferences.HubForcefield = resultSet.getBoolean(8);
preferences.ShowMacReports = resultSet.getBoolean(9);
preferences.IgnoreVelocity = resultSet.getBoolean(10);
preferences.PendingFriendRequests = resultSet.getBoolean(11);
}
}
}, new ColumnVarChar("uuid", 100, uuid.toString()));
preferences.HubGames = resultSet.getBoolean(1);
preferences.ShowPlayers = resultSet.getBoolean(2);
preferences.ShowChat = resultSet.getBoolean(3);
preferences.FriendChat = resultSet.getBoolean(4);
preferences.PrivateMessaging = resultSet.getBoolean(5);
preferences.PartyRequests = resultSet.getBoolean(6);
preferences.Invisibility = resultSet.getBoolean(7);
preferences.HubForcefield = resultSet.getBoolean(8);
preferences.ShowMacReports = resultSet.getBoolean(9);
preferences.IgnoreVelocity = resultSet.getBoolean(10);
preferences.PendingFriendRequests = resultSet.getBoolean(11);
}
return preferences;
}

View File

@ -1,21 +1,21 @@
package mineplex.core.stats;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.MiniDbClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilServer;
import mineplex.core.stats.command.GiveStatCommand;
import mineplex.core.stats.command.TimeCommand;
import mineplex.core.stats.event.StatChangeEvent;
public class StatsManager extends MiniClientPlugin<PlayerStats>
public class StatsManager extends MiniDbClientPlugin<PlayerStats>
{
private static Object _statSync = new Object();
@ -25,9 +25,9 @@ public class StatsManager extends MiniClientPlugin<PlayerStats>
private NautHashMap<String, NautHashMap<String, Integer>> _statUploadQueue = new NautHashMap<String, NautHashMap<String, Integer>>();
private Runnable _saveRunnable;
public StatsManager(JavaPlugin plugin)
public StatsManager(JavaPlugin plugin, CoreClientManager clientManager)
{
super("StatsManager", plugin);
super("Stats Manager", plugin, clientManager);
_repository = new StatsRepository(plugin);
@ -117,20 +117,6 @@ public class StatsManager extends MiniClientPlugin<PlayerStats>
return new PlayerStats();
}
@Override
protected void loadClientInformation(final RetrieveClientInformationEvent event)
{
event.incrementProcessingCount();
Bukkit.getServer().getScheduler().runTaskAsynchronously(GetPlugin(), new Runnable()
{
public void run()
{
Set(event.getPlayerName(), _repository.loadClientInformation(event.getUniqueId().toString()));
event.decreaseProcessingCount();
}
});
}
public PlayerStats getOfflinePlayerStats(String playerName) throws SQLException
{
return _repository.loadOfflinePlayerStats(playerName);
@ -185,4 +171,16 @@ public class StatsManager extends MiniClientPlugin<PlayerStats>
addCommand(new TimeCommand(this));
addCommand(new GiveStatCommand(this));
}
@Override
public void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException
{
Set(playerName, _repository.loadClientInformation(resultSet));
}
@Override
public String getQuery(String uuid, String name)
{
return "SELECT stats.name, value FROM accountStats INNER JOIN stats ON stats.id = accountStats.statId INNER JOIN accounts ON accountStats.accountId = accounts.id WHERE accounts.uuid = '" + uuid + "';";
}
}

View File

@ -1,6 +1,5 @@
package mineplex.core.stats;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
@ -14,17 +13,12 @@ import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.database.Tables;
import mineplex.database.tables.records.AccountStatsRecord;
import mineplex.database.tables.records.StatsRecord;
import org.jooq.DSLContext;
import org.jooq.Insert;
import org.jooq.InsertQuery;
import org.jooq.Query;
import org.jooq.Record;
import org.jooq.Record2;
import org.jooq.Result;
import org.jooq.Update;
import org.jooq.UpdateQuery;
import org.jooq.impl.DSL;
public class StatsRepository extends RepositoryBase
@ -32,7 +26,6 @@ public class StatsRepository extends RepositoryBase
private static String CREATE_STAT_TABLE = "CREATE TABLE IF NOT EXISTS stats (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100), PRIMARY KEY (id), UNIQUE INDEX nameIndex (name));";
private static String CREATE_STAT_RELATION_TABLE = "CREATE TABLE IF NOT EXISTS accountStats (id INT NOT NULL AUTO_INCREMENT, accountId INT NOT NULL, statId INT NOT NULL, value INT NOT NULL, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id), UNIQUE INDEX accountStatIndex (accountId, statId));";
private static String RETRIEVE_PLAYER_STATS = "SELECT stats.name, value FROM accountStats INNER JOIN stats ON stats.id = accountStats.statId INNER JOIN accounts ON accountStats.accountId = accounts.id WHERE accounts.uuid = ?;";
private static String RETRIEVE_STATS = "SELECT id, name FROM stats;";
private static String INSERT_STAT = "INSERT INTO stats (name) VALUES (?);";
@ -81,10 +74,9 @@ public class StatsRepository extends RepositoryBase
executeUpdate(INSERT_STAT, new ColumnVarChar("name", 100, name));
}
@SuppressWarnings("rawtypes")
public void saveStats(NautHashMap<String, NautHashMap<Integer, Integer>> uploadQueue)
{
System.out.println("saving stats.");
try
{
DSLContext context = DSL.using(getConnection());
@ -96,8 +88,6 @@ public class StatsRepository extends RepositoryBase
{
for (Integer statId : uploadQueue.get(uuid).keySet())
{
System.out.println("saving stat : uuid=" + uuid + " " + statId + "=" + uploadQueue.get(uuid).get(statId));
Update update = context
.update(Tables.accountStats)
.set(Tables.accountStats.value, Tables.accountStats.value.plus(uploadQueue.get(uuid).get(statId)))
@ -166,20 +156,14 @@ public class StatsRepository extends RepositoryBase
return playerStats;
}
public PlayerStats loadClientInformation(String uuid)
public PlayerStats loadClientInformation(ResultSet resultSet) throws SQLException
{
final PlayerStats playerStats = new PlayerStats();
executeQuery(RETRIEVE_PLAYER_STATS, new ResultSetCallable()
while (resultSet.next())
{
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
playerStats.addStat(resultSet.getString(1), resultSet.getInt(2));
}
}
}, new ColumnVarChar("uuid", 100, uuid));
playerStats.addStat(resultSet.getString(1), resultSet.getInt(2));
}
return playerStats;
}

View File

@ -7,7 +7,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.event.ClientWebResponseEvent;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.task.repository.TaskRepository;
import mineplex.core.task.repository.TaskToken;
@ -52,9 +51,4 @@ public class TaskManager extends MiniClientPlugin<TaskClient>
_repository.AddTask(client.Name, taskName);
}
@Override
protected void loadClientInformation(RetrieveClientInformationEvent event)
{
}
}

View File

@ -37,6 +37,7 @@ import mineplex.core.creature.event.CreatureSpawnCustomEvent;
import mineplex.core.teleport.Teleport;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.repository.ClanTerritory;
import mineplex.minecraft.game.core.combat.CombatManager;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
@ -126,9 +127,6 @@ public class ClansManager extends MiniClientPlugin<ClientClan>
@EventHandler
public void Update(UpdateEvent event)
{
if (event.getType() == UpdateType.SEC)
Power();
if (event.getType() == UpdateType.FAST)
CGame().UpdateSafe();
@ -184,7 +182,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>
@EventHandler(priority = EventPriority.HIGHEST)
public void BlockCreatureSpawn(CreatureSpawnCustomEvent event)
{
ClansClan clan = Clans().CUtil().getOwner(event.GetLocation());
ClansClan clan = _clanUtility.getOwner(event.GetLocation());
if (clan != null)
if (!clan.IsAdmin() && !clan.GetName().equals("Spawn"))
@ -263,18 +261,18 @@ public class ClansManager extends MiniClientPlugin<ClientClan>
public boolean HandleClanChat(AsyncPlayerChatEvent event, String filteredMessage)
{
CoreClient client = Clients().Get(event.getPlayer());
ClientClan client = Get(event.getPlayer());
if (client == null)
return false;
if (!client.Clan().IsClanChat())
if (!client.isClanChat())
return false;
ClansClan clan = CUtil().getClanByPlayer(event.getPlayer());
ClanInfo clan = _clanUtility.getClanByPlayer(event.getPlayer());
if (clan == null)
{
Clients().Get(event.getPlayer()).Clan().SetClanChat(false);
Get(event.getPlayer()).setClanChat(false);
return false;
}
@ -287,10 +285,10 @@ public class ClansManager extends MiniClientPlugin<ClientClan>
if (!Get(event.getPlayer()).isAllyChat())
return false;
ClansClan clan = CUtil().getClanByPlayer(event.getPlayer());
ClanInfo clan = _clanUtility.getClanByPlayer(event.getPlayer());
if (clan == null)
{
Clients().Get(event.getPlayer()).Clan().SetAllyChat(false);
Get(event.getPlayer()).setAllyChat(false);
return false;
}
@ -331,59 +329,38 @@ public class ClansManager extends MiniClientPlugin<ClientClan>
return _reclaimTime;
}
@Override
public boolean CanHurt(Player a, Player b)
public boolean canHurt(Player a, Player b)
{
if (a.equals(b))
return false;
return CUtil().canHurt(a, b);
return _clanUtility.canHurt(a, b);
}
@Override
public boolean CanHurt(String a, String b)
public boolean canHurt(String a, String b)
{
if (a.equals(b))
return false;
return CUtil().canHurt(UtilPlayer.searchExact(a), UtilPlayer.searchExact(b));
return _clanUtility.canHurt(UtilPlayer.searchExact(a), UtilPlayer.searchExact(b));
}
@Override
public boolean IsSafe(Player a)
public boolean isSafe(Player a)
{
return CUtil().isSafe(a);
return _clanUtility.isSafe(a);
}
public IRepository GetRepository() {
return _repository;
}
public void SetRepository(IRepository _repository) {
this._repository = _repository;
}
public HashMap<String, ClansClan> GetClanMemberMap()
public ClanRelation getRelation(String playerA, String playerB)
{
return _clanMemberMap;
}
public ClanRelation GetRelation(String playerA, String playerB)
{
return Clients().Get(playerA).Clan().GetRelation(playerB);
return Get(playerA).getRelation(playerB);
}
@Override
public ChatColor GetColorOfFor(String other, Player player)
{
return CUtil().relChatColor(Clients().Get(player).Clan().GetRelation(other), false);
return _clanUtility.relChatColor(Get(player).getRelation(other), false);
}
public String GetServerName()
{
return _serverName;
}
public long getOnlineTime()
{
return _onlineTime;

View File

@ -7,7 +7,6 @@ import mineplex.core.CustomTagFix;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
import mineplex.core.antihack.AntiHack;
import mineplex.core.antistack.AntiStack;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.chat.Chat;
import mineplex.core.command.CommandCenter;
@ -91,7 +90,6 @@ public class Hub extends JavaPlugin implements IRelation
Creature creature = new Creature(this);
NpcManager npcManager = new NpcManager(this, creature);
PetManager petManager = new PetManager(this, clientManager, donationManager, creature, webServerAddress);
new AntiStack(this);
PollManager pollManager = new PollManager(this, donationManager);
//Main Modules
@ -101,11 +99,11 @@ public class Hub extends JavaPlugin implements IRelation
AntiHack.Initialize(this, punish, portal, preferenceManager, clientManager);
PacketHandler packetHandler = new PacketHandler(this);
DisguiseManager disguiseManager = new DisguiseManager(this, packetHandler);
StatsManager statsManager = new StatsManager(this);
StatsManager statsManager = new StatsManager(this, clientManager);
AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager);
HubManager hubManager = new HubManager(this, new BlockRestore(this), clientManager, donationManager, new ConditionManager(this), disguiseManager, new TaskManager(this, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager);
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this), partyManager);
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this, clientManager), partyManager);
new ServerManager(this, clientManager, donationManager, portal, partyManager, serverStatusManager, hubManager, new StackerManager(hubManager), queueManager);
new Chat(this, clientManager, preferenceManager, serverStatusManager.getCurrentServerName());

View File

@ -42,9 +42,8 @@ import org.bukkit.scoreboard.Scoreboard;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.achievement.AchievementManager;
import mineplex.core.benefit.RankBenefitsGiver9000;
import mineplex.core.benefit.BenefitManager;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
@ -157,6 +156,8 @@ public class HubManager extends MiniClientPlugin<HubClient>
_portal = portal;
_spawn = new Location(UtilWorld.getWorld("world"), 0.5, 74, 0.5);
// Disable item merging
((CraftWorld) _spawn.getWorld()).getHandle().spigotConfig.itemMerge = 0;
_textCreator = new TextManager(this);
_parkour = new ParkourManager(this, donationManager, taskManager);
@ -170,8 +171,8 @@ public class HubManager extends MiniClientPlugin<HubClient>
_news = new NewsManager(this);
_mountManager = new MountManager(_plugin, clientManager, donationManager, blockRestore, _disguiseManager);
_inventoryManager = new InventoryManager(plugin);
new RankBenefitsGiver9000(plugin, clientManager, _inventoryManager);
_inventoryManager = new InventoryManager(plugin, clientManager);
new BenefitManager(plugin, clientManager, _inventoryManager);
_gadgetManager = new GadgetManager(_plugin, clientManager, donationManager, _inventoryManager, _mountManager, petManager, preferences, disguiseManager, blockRestore, new ProjectileManager(plugin));
_treasureManager = new TreasureManager(_plugin, donationManager, _inventoryManager, petManager, _blockRestore);
new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, _mountManager, petManager, false, _treasureManager);
@ -960,12 +961,6 @@ public class HubManager extends MiniClientPlugin<HubClient>
return _news;
}
@Override
protected void loadClientInformation(RetrieveClientInformationEvent event)
{
}
@EventHandler
public void ignoreVelocity(PlayerVelocityEvent event)
{

View File

@ -13,6 +13,8 @@ public class PlayerPollData
private NautHashMap<Integer, Integer> _pollAnswers;
private long _nextPollTime;
public boolean Loaded;
public PlayerPollData()
{
_pollAnswers = new NautHashMap<Integer, Integer>();
@ -40,7 +42,7 @@ public class PlayerPollData
public boolean shouldPoll()
{
return System.currentTimeMillis() > _nextPollTime;
return Loaded && System.currentTimeMillis() > _nextPollTime;
}
}

View File

@ -14,7 +14,6 @@ import net.minecraft.server.v1_7_R4.PacketPlayOutChat;
import net.minecraft.util.com.google.gson.JsonObject;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
@ -24,9 +23,6 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.poll.command.PollCommand;
/**
* Created by Shaun on 8/16/2014.
*/
public class PollManager extends MiniClientPlugin<PlayerPollData>
{
private PollRepository _repository;
@ -57,17 +53,14 @@ public class PollManager extends MiniClientPlugin<PlayerPollData>
return new PlayerPollData();
}
@Override
protected void loadClientInformation(final RetrieveClientInformationEvent event)
public void loadClientInformation(final PlayerJoinEvent event)
{
event.incrementProcessingCount();
_plugin.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
{
@Override
public void run()
{
Set(event.getPlayerName(), _repository.loadPollData(event.getUniqueId()));
event.decreaseProcessingCount();
Set(event.getPlayer().getName(), _repository.loadPollData(event.getPlayer().getUniqueId()));
}
});
}

View File

@ -89,6 +89,8 @@ public class PollRepository extends RepositoryBase
}
}, new ColumnVarChar("uuid", 100, uuid.toString()));
pollData.Loaded = true;
return pollData;
}

View File

@ -9,12 +9,10 @@ import mineplex.minecraft.game.classcombat.Class.repository.token.ClientClassTok
import mineplex.minecraft.game.classcombat.Class.repository.token.CustomBuildToken;
import mineplex.minecraft.game.classcombat.Skill.ISkill;
import mineplex.minecraft.game.classcombat.Skill.SkillFactory;
import mineplex.minecraft.game.classcombat.Skill.ISkill.SkillType;
import mineplex.minecraft.game.classcombat.item.ItemFactory;
import mineplex.core.MiniClientPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.ClientWebResponseEvent;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.donation.DonationManager;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.updater.UpdateType;
@ -309,9 +307,4 @@ public class ClassManager extends MiniClientPlugin<ClientClass> implements IClas
event.setCancelled(true);
}
}
@Override
protected void loadClientInformation(RetrieveClientInformationEvent event)
{
}
}

View File

@ -19,7 +19,6 @@ import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.util.Vector;
import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType;
import mineplex.core.antistack.AntiStack;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilEnt;
@ -156,7 +155,6 @@ public class AxeThrow extends SkillActive implements IThrown
Player player = _thrown.remove(event.getItem());
AntiStack.removeUID(event.getItem());
player.getInventory().addItem(event.getItem().getItemStack());
UtilInv.Update(event.getPlayer());
@ -190,7 +188,6 @@ public class AxeThrow extends SkillActive implements IThrown
if (item.getTicksLived() > 400 - level * 40)
{
AntiStack.removeUID(item);
_thrown.get(item).getInventory().addItem(item.getItemStack());
item.remove();
itemIterator.remove();

View File

@ -44,6 +44,7 @@ public class ServerCommandManager
*/
private void initialize()
{
/* CAUSING STUTTER LAG IN HUBS
final Jedis jedis = _jedisPool.getResource();
// Spin up a new thread and subscribe to the Redis pubsub network
@ -67,30 +68,37 @@ public class ServerCommandManager
});
thread.start();
*/
}
/**
* Publish a {@link ServerCommand} across the network to all live servers.
* @param serverCommand - the {@link ServerCommand} to issue to all servers.
*/
public void publishCommand(ServerCommand serverCommand)
public void publishCommand(final ServerCommand serverCommand)
{
Jedis jedis = _jedisPool.getResource();
try
new Thread(new Runnable()
{
String commandType = serverCommand.getClass().getSimpleName();
String serializedCommand = Utility.serialize(serverCommand);
jedis.publish(SERVER_COMMANDS_CHANNEL + ":" + commandType, serializedCommand);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
_jedisPool.returnResource(jedis);
}
public void run()
{
Jedis jedis = _jedisPool.getResource();
try
{
String commandType = serverCommand.getClass().getSimpleName();
String serializedCommand = Utility.serialize(serverCommand);
jedis.publish(SERVER_COMMANDS_CHANNEL + ":" + commandType, serializedCommand);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
_jedisPool.returnResource(jedis);
}
}
}).start();
}
/**

View File

@ -57,7 +57,7 @@ public class StaffServer extends JavaPlugin
new MemoryFix(this);
new FileUpdater(this, portal);
new CustomerSupport(this, clientManager, donationManager, new SalesPackageManager(this, clientManager, donationManager, new InventoryManager(this), new StatsManager(this)));
new CustomerSupport(this, clientManager, donationManager, new SalesPackageManager(this, clientManager, donationManager, new InventoryManager(this, clientManager), new StatsManager(this, clientManager)));
new Password(this, serverStatusManager.getCurrentServerName());
//Updates

View File

@ -9,7 +9,6 @@ import net.minecraft.server.v1_7_R4.MinecraftServer;
import mineplex.core.CustomTagFix;
import mineplex.core.account.CoreClientManager;
import mineplex.core.antihack.AntiHack;
import mineplex.core.antistack.AntiStack;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.blood.Blood;
import mineplex.core.command.CommandCenter;
@ -89,7 +88,6 @@ public class Arcade extends JavaPlugin
PreferencesManager preferenceManager = new PreferencesManager(this, _clientManager, _donationManager);
new MessageManager(this, _clientManager, preferenceManager);
AntiStack antistack = new AntiStack(this);
Creature creature = new Creature(this);
Spawn spawn = new Spawn(this);
Teleport teleport = new Teleport(this, _clientManager, spawn);
@ -111,7 +109,7 @@ public class Arcade extends JavaPlugin
ProjectileManager projectileManager = new ProjectileManager(this);
//Inventory
InventoryManager inventoryManager = new InventoryManager(this);
InventoryManager inventoryManager = new InventoryManager(this, _clientManager);
PetManager petManager = new PetManager(this, _clientManager, _donationManager, creature, webServerAddress);
MountManager mountManager = new MountManager(this, _clientManager, _donationManager, blockRestore, disguiseManager);
GadgetManager gadgetManager = new GadgetManager(this, _clientManager, _donationManager, inventoryManager, mountManager, petManager, preferenceManager, disguiseManager, blockRestore, projectileManager);
@ -119,7 +117,7 @@ public class Arcade extends JavaPlugin
cosmeticManager.setInterfaceSlot(7);
//Arcade Manager
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), antistack, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, webServerAddress);
_gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, disguiseManager, creature, teleport, new Blood(this), portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, webServerAddress);
new MemoryFix(this);
new CustomTagFix(this, packetHandler);

View File

@ -36,7 +36,6 @@ import org.bukkit.event.server.ServerListPingEvent;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
import mineplex.core.antistack.AntiStack;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.blood.Blood;
import mineplex.core.chat.Chat;
@ -116,7 +115,6 @@ import nautilus.game.arcade.shop.ArcadeShop;
public class ArcadeManager extends MiniPlugin implements IRelation
{
// Modules
private AntiStack _antistack;
private BlockRestore _blockRestore;
private Blood _blood;
private Chat _chat;
@ -173,7 +171,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
public ArcadeManager(Arcade plugin, ServerStatusManager serverStatusManager, GameServerConfig serverConfig,
CoreClientManager clientManager, DonationManager donationManager, DamageManager damageManager,
DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood, AntiStack antistack,
DisguiseManager disguiseManager, Creature creature, Teleport teleport, Blood blood,
Portal portal, PreferencesManager preferences, InventoryManager inventoryManager, PacketHandler packetHandler,
CosmeticManager cosmeticManager, ProjectileManager projectileManager, PetManager petManager, String webAddress)
{
@ -182,8 +180,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_serverConfig = serverConfig;
// Modules
_antistack = antistack;
_blockRestore = new BlockRestore(plugin);
_blood = blood;
@ -219,7 +215,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_projectileManager = projectileManager;
_statsManager = new StatsManager(plugin);
_statsManager = new StatsManager(plugin, clientManager);
_taskManager = new TaskManager(plugin, webAddress);
_achievementManager = new AchievementManager(_statsManager, clientManager, donationManager);
_inventoryManager = inventoryManager;
@ -273,7 +269,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_classShopManager = new ClassShopManager(_plugin, _classManager, _skillFactory, itemFactory, _achievementManager, clientManager);
_classShop = new ClassCombatShop(_classShopManager, clientManager, donationManager, webAddress);
_eloManager = new EloManager(_plugin);
_eloManager = new EloManager(_plugin, clientManager);
}
}
@ -300,11 +296,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
return _achievementManager;
}
public AntiStack GetAntiStack()
{
return _antistack;
}
public Blood GetBlood()
{
return _blood;

View File

@ -14,6 +14,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Hanging;
@ -33,6 +34,7 @@ import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.scoreboard.Objective;
import org.bukkit.util.Vector;
@ -203,6 +205,7 @@ public abstract class Game implements Listener
public boolean RepairWeapons = true;
private double _itemMergeRadius = 0;
public boolean AnnounceStay = true;
public boolean AnnounceJoinQuit = true;
@ -1286,8 +1289,34 @@ public abstract class Game implements Listener
loc.getY() >= WorldData.MaxY ||
loc.getY() <= WorldData.MinY);
}
public void setItemMerge(boolean itemMerge)
{
setItemMergeRadius(itemMerge ? 3.5 : 0);
}
public void setItemMergeRadius(double mergeRadius)
{
_itemMergeRadius = mergeRadius;
if (WorldData.World != null)
{
((CraftWorld) WorldData.World).getHandle().spigotConfig.itemMerge = _itemMergeRadius;
}
}
public double getItemMergeRadius()
{
return _itemMergeRadius;
}
@EventHandler
public void applyItemMerge(WorldLoadEvent event)
{
if (event.getWorld().getName().equals(WorldData.GetFolder()))
{
System.out.println("Setting item merge radius for game to " + _itemMergeRadius);
((CraftWorld) event.getWorld()).getHandle().spigotConfig.itemMerge = _itemMergeRadius;
}
}
}

View File

@ -57,7 +57,6 @@ import org.bukkit.scoreboard.Team;
import org.bukkit.scoreboard.TeamNameTagVisibility;
import org.bukkit.util.Vector;
import mineplex.core.antistack.AntiStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
@ -898,8 +897,6 @@ public class MineStrike extends TeamGame
if (UtilInv.contains(event.getPlayer(), Material.SHEARS, (byte)0, 1))
return;
AntiStack.removeUID(event.getItem());
event.getPlayer().getInventory().setItem(8, event.getItem().getItemStack());
UtilPlayer.message(event.getPlayer(), F.main("Game", "You equipped Defusal Kit."));

View File

@ -149,7 +149,8 @@ public class SurvivalGamesTeams extends TeamGame
C.cAqua + "Compass finds Players during day time.",
};
Manager.GetAntiStack().SetEnabled(false);
setItemMerge(true);
// Manager.GetAntiStack().SetEnabled(false);
this.GameTimeout = 9600000;

View File

@ -174,7 +174,8 @@ public class UHC extends TeamGame
Manager.GetCreature().SetDisableCustomDrops(true);
//Disable Anti-Stack
Manager.GetAntiStack().SetEnabled(false);
setItemMerge(true);
// Manager.GetAntiStack().SetEnabled(false);
//Damage Settings
Manager.GetDamage().SetEnabled(false);

View File

@ -159,7 +159,7 @@ public class GameCreationManager implements Listener
Manager.GetDamage().SetEnabled(true);
Manager.GetExplosion().SetRegenerate(false);
Manager.GetExplosion().SetTNTSpread(true);
Manager.GetAntiStack().SetEnabled(true);
// Manager.GetAntiStack().SetEnabled(true);
Manager.getCosmeticManager().setHideParticles(false);
HashMap<String, ChatColor> pastTeams = null;

View File

@ -129,7 +129,7 @@ public class MiscManager implements Listener
@EventHandler
public void HubCommand(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().startsWith("/hub") || event.getMessage().startsWith("/leave"))
if (event.getMessage().startsWith("/lobby") || event.getMessage().startsWith("/hub") || event.getMessage().startsWith("/leave"))
{
Manager.GetPortal().SendPlayerToServer(event.getPlayer(), "Lobby");
event.setCancelled(true);

View File

@ -23,6 +23,7 @@ import org.bukkit.Difficulty;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.event.world.ChunkUnloadEvent;
public class WorldData
@ -84,7 +85,7 @@ public class WorldData
TimingManager.stop("WorldData loading world.");
World.setDifficulty(Difficulty.HARD);
TimingManager.start("WorldData loading WorldConfig.");
//Load World Data
worldData.LoadWorldConfig();
@ -116,7 +117,7 @@ public class WorldData
return File;
}
protected String GetFolder()
public String GetFolder()
{
if (Folder == null)
Folder = "Game" + Id + "_" + Host.GetName() + "_" + GetFile();