Fixed up BenefitManager.
This commit is contained in:
parent
d426c24970
commit
bbb661d686
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user