TNT generator storage in mysql (needs testing still)

This commit is contained in:
Shaun Bennett 2015-08-29 14:37:35 -07:00
parent 16d807db2e
commit 8f1da698d2
3 changed files with 73 additions and 6 deletions

View File

@ -21,6 +21,7 @@ import mineplex.game.clans.clans.repository.ClanTerritory;
import mineplex.game.clans.clans.repository.tokens.ClanEnemyToken;
import mineplex.game.clans.clans.repository.tokens.ClanToken;
import mineplex.game.clans.clans.scoreboard.ClansScoreboardManager;
import mineplex.game.clans.clans.tntGenerator.TntGenerator;
public class ClansDataAccessLayer
{
@ -612,6 +613,44 @@ public class ClansDataAccessLayer
_manager.log("Updated Enemy Data for [" + clan.getName() + ", " + otherClan.getName() + "]");
}
public void updateGenerator(final ClanInfo clanInfo, final Callback<Boolean> callback)
{
TntGenerator generator = clanInfo.getGenerator();
final String location;
final int generatorStock;
if (generator != null)
{
location = UtilWorld.blockToStr(generator.getBlock());
generatorStock = generator.getStock();
}
else
{
location = "";
generatorStock = 0;
}
runAsync(new Runnable()
{
@Override
public void run()
{
final boolean ran = _repository.updateClanGenerator(clanInfo.getId(), location, generatorStock);
runSync(new Runnable()
{
@Override
public void run()
{
if (callback != null)
{
callback.run(ran);
}
}
});
}
});
}
public void updateEnergy(ClanInfo clan)
{
//Save

View File

@ -22,6 +22,7 @@ import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnTimestamp;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.database.tables.records.ClansRecord;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.repository.tokens.ClanAllianceToken;
import mineplex.game.clans.clans.repository.tokens.ClanEnemyToken;
import mineplex.game.clans.clans.repository.tokens.ClanMemberToken;
@ -66,6 +67,7 @@ public class ClanRepository extends RepositoryBase
private static String UPDATE_CLAN_ALLIANCE = "UPDATE clanAlliances SET trusted = ? WHERE clanId = ? AND otherClanId = ?;";
private static String UPDATE_CLAN_ENEMY = "UPDATE clanEnemies SET clanScore = ?, otherClanScore = ?, clanKills = ?, otherClanKills = ? WHERE clanId = ? AND otherClanId = ?;";
private static String UPDATE_CLAN_TERRITORY = "UPDATE clanTerritory SET safe = ? WHERE serverId = ? AND chunk = ?;";
private static String UPDATE_CLAN_GENERATOR = "UPDATE clans SET generator = ?, generatorCount = ? WHERE id = ?;";
private static String GET_CLAN_SERVER = "SELECT id FROM clanServer WHERE clanServer.serverName = ?";
private static String ADD_CLAN_SERVER = "INSERT INTO clanServer (serverName) VALUES (?);";
@ -414,6 +416,12 @@ public class ClanRepository extends RepositoryBase
new ColumnInt("otherClanKills", otherClanKills), new ColumnInt("clanId", clanId), new ColumnInt("otherClanId", otherClanId));
}
public boolean updateClanGenerator(int clanId, String generator, int generatorStock)
{
return executeUpdate(UPDATE_CLAN_GENERATOR, new ColumnVarChar("generator", 140, generator), new ColumnInt("generatorStock", generatorStock), new ColumnInt("clanId", clanId))
> 0;
}
public void updateTerritoryClaim(String chunk, boolean safe)
{
executeUpdate(UPDATE_CLAN_TERRITORY, new ColumnBoolean("safe", safe), new ColumnInt("serverId", _serverId), new ColumnVarChar("chunk", 100, chunk));

View File

@ -17,6 +17,7 @@ import net.minecraft.server.v1_7_R4.TileEntityBrewingStand;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextMiddle;
@ -59,6 +60,7 @@ public class TntGeneratorManager extends MiniPlugin
if (generator.getBlock().getType() != GENERATOR_MATERIAL)
{
clanInfo.setGenerator(null);
_clansManager.getClanDataAccess().updateGenerator(clanInfo, null);
continue;
}
@ -69,6 +71,7 @@ public class TntGeneratorManager extends MiniPlugin
_clansManager.messageClan(clanInfo, F.main("Clans", "Your " + F.elem("TNT Generator") + " has been destroyed due to the land no longer being claimed"));
destroyGenerator(generator);
clanInfo.setGenerator(null);
_clansManager.getClanDataAccess().updateGenerator(clanInfo, null);
continue;
}
@ -85,6 +88,7 @@ public class TntGeneratorManager extends MiniPlugin
generator.setStock(generator.getStock() + 1);
generator.setTicks(0);
updateBrewingStand(generator);
_clansManager.getClanDataAccess().updateGenerator(clanInfo, null);
}
generator.incrementTicks();
@ -129,6 +133,7 @@ public class TntGeneratorManager extends MiniPlugin
TntGenerator generator = new TntGenerator(event.getBlock());
clan.setGenerator(generator);
_clansManager.getClanDataAccess().updateGenerator(clan, null);
_clansManager.messageClan(clan, F.main("Clans", F.name(event.getPlayer().getName()) + " placed a " + F.elem("TNT Generator") + " at " + F.elem(UtilWorld.blockToStrClean(event.getBlock()))));
}
@ -154,23 +159,38 @@ public class TntGeneratorManager extends MiniPlugin
}
@EventHandler
public void onInteract(PlayerInteractEvent event)
public void onInteract(final PlayerInteractEvent event)
{
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null && event.getClickedBlock().getType() == GENERATOR_MATERIAL)
{
ClanInfo clan = getGenerator(event.getClickedBlock());
if (clan != null)
{
TntGenerator generator = clan.getGenerator();
int stock = generator.getStock();
final TntGenerator generator = clan.getGenerator();
final int stock = generator.getStock();
if (stock > 0)
{
generator.setStock(stock - 1);
_clansManager.getClanDataAccess().updateGenerator(clan, new Callback<Boolean>()
{
@Override
public void run(Boolean data)
{
if (data)
{
updateBrewingStand(generator);
dropItem(event.getClickedBlock(), new ItemStack(Material.TNT));
}
else
{
// failed
generator.setStock(stock);
}
}
});
}
else
{
int secondLeft = TICKS_PER_TNT - generator.getTicks();
int msLeft = secondLeft * 1000;