Fixed up BenefitManager.

This commit is contained in:
Jonathan Williams 2015-06-29 18:07:06 -04:00
parent d426c24970
commit bbb661d686
6 changed files with 22 additions and 15 deletions

View File

@ -31,7 +31,7 @@ public class BenefitManager extends MiniDbClientPlugin<BenefitData>
//_benefits.add(new Christmas2014(plugin, _repository, inventoryManager));
//_benefits.add(new Thanksgiving2014(plugin, _repository, inventoryManager));
_benefits.add(new Players40k(plugin, _repository, inventoryManager));
_benefits.add(new Players40k(this, _repository, inventoryManager));
}
@EventHandler(priority = EventPriority.LOWEST)

View File

@ -5,15 +5,16 @@ import java.sql.SQLException;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import org.bukkit.plugin.java.JavaPlugin;
public class BenefitManagerRepository extends RepositoryBase
{
private static String CREATE_BENEFIT_TABLE = "CREATE TABLE IF NOT EXISTS rankBenefits (id INT NOT NULL AUTO_INCREMENT, accountId INT, benefit VARCHAR(100), PRIMARY KEY (id), INDEX rankUuid (uuid));";
private static String CREATE_BENEFIT_TABLE = "CREATE TABLE IF NOT EXISTS rankBenefits (id INT NOT NULL AUTO_INCREMENT, accountId INT, benefit VARCHAR(100), PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id));";
private static String INSERT_BENEFIT = "INSERT INTO rankBenefits (uuid, benefit) VALUES (?, ?);";
private static String INSERT_BENEFIT = "INSERT INTO rankBenefits (accountId, benefit) VALUES (?, ?);";
public BenefitManagerRepository(JavaPlugin plugin)
{
@ -23,7 +24,7 @@ public class BenefitManagerRepository extends RepositoryBase
@Override
protected void initialize()
{
// executeUpdate(CREATE_BENEFIT_TABLE);
executeUpdate(CREATE_BENEFIT_TABLE);
}
@Override
@ -31,9 +32,9 @@ public class BenefitManagerRepository extends RepositoryBase
{
}
public boolean addBenefit(String uuid, String benefit)
public boolean addBenefit(int accountId, String benefit)
{
return executeUpdate(INSERT_BENEFIT, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("benefit", 100, benefit)) > 0;
return executeUpdate(INSERT_BENEFIT, new ColumnInt("accountId", accountId), new ColumnVarChar("benefit", 100, benefit)) > 0;
}
public BenefitData retrievePlayerBenefitData(ResultSet resultSet) throws SQLException
@ -42,9 +43,11 @@ public class BenefitManagerRepository extends RepositoryBase
while (resultSet.next())
{
playerBenefit.Benefits.add(resultSet.getString(1));
playerBenefit.Benefits.add(resultSet.getString(1));
}
playerBenefit.Loaded = true;
return playerBenefit;
}
}

View File

@ -1,5 +1,6 @@
package mineplex.core.benefit.benefits;
import mineplex.core.benefit.BenefitManager;
import mineplex.core.benefit.BenefitManagerRepository;
import mineplex.core.common.util.Callback;
@ -9,11 +10,11 @@ import org.bukkit.plugin.java.JavaPlugin;
public abstract class BenefitBase
{
private JavaPlugin _plugin;
private BenefitManager _plugin;
private String _name;
private BenefitManagerRepository _repository;
protected BenefitBase(JavaPlugin plugin, String name, BenefitManagerRepository repository)
protected BenefitBase(BenefitManager plugin, String name, BenefitManagerRepository repository)
{
_plugin = plugin;
_name = name;
@ -22,7 +23,7 @@ public abstract class BenefitBase
public JavaPlugin getPlugin()
{
return _plugin;
return _plugin.getPlugin();
}
public BenefitManagerRepository getRepository()
@ -34,11 +35,11 @@ public abstract class BenefitBase
public void recordBenefit(final Player player, final Callback<Boolean> callback)
{
Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable()
Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin.getPlugin(), new Runnable()
{
public void run()
{
boolean success = _repository.addBenefit(player.getUniqueId().toString(), _name);
boolean success = _repository.addBenefit(_plugin.getClientManager().Get(player).getAccountId(), _name);
callback.run(success);
}

View File

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

View File

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

View File

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