Revert "Move clans database calls to a seperate thread"

This reverts commit 61b1e3f48b.
This commit is contained in:
Shaun Bennett 2015-02-24 21:04:57 -05:00
parent ad5481ef9c
commit 85ee98782e

View File

@ -26,7 +26,7 @@ public class ClansDataAccessLayer
_repository = new ClanRepository(clans.GetPlugin(), clans.getServerName());
}
public void delete(final ClanInfo clan)
public void delete(ClanInfo clan)
{
//Territory Unclaim
for (String cur : clan.getClaimSet())
@ -47,16 +47,7 @@ public class ClansDataAccessLayer
}
//Save
runAsync(new Runnable()
{
@Override
public void run()
{
// Need better error checking in future incase database
// queries do not go through
_repository.deleteClan(clan.getId());
}
});
_repository.deleteClan(clan.getId());
//Log
_manager.log("Deleted [" + clan.getName() + "].");
@ -64,25 +55,18 @@ public class ClansDataAccessLayer
public ClanInfo create(String creator, String name, boolean admin)
{
final ClanToken token = new ClanToken();
ClanToken token = new ClanToken();
token.Name = name;
token.Description = "No Description";
token.Home = "";
token.Admin = admin;
//Create Clan
final ClanInfo clan = new ClanInfo(_manager, token);
ClanInfo clan = new ClanInfo(_manager, token);
_manager.getClanMap().put(name, clan);
//Save
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.addClan(clan, token);
}
});
_repository.addClan(clan, token);
//Log
_manager.log("[" + clan.getName() + "] with Admin [" + admin + "] created by [" + creator + "].");
@ -90,7 +74,7 @@ public class ClansDataAccessLayer
return clan;
}
public void join(final ClanInfo clan, final String player, final Role role)
public void join(ClanInfo clan, String player, Role role)
{
if (_manager.getClanMemberMap().containsKey(player))
leave(_manager.getClanUtility().getClanByPlayer(player), player);
@ -102,20 +86,13 @@ public class ClansDataAccessLayer
clan.getInviterMap().remove(player);
//Save
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.addMember(clan.getId(), player, role.toString());
}
});
_repository.addMember(clan.getId(), player, role.toString());
//Log
_manager.log("Added [" + player + "] to [" + clan.getName() + "].");
}
public void leave(final ClanInfo clan, final String player)
public void leave(ClanInfo clan, String player)
{
if (clan == null)
return;
@ -125,33 +102,19 @@ public class ClansDataAccessLayer
_manager.getClanMemberMap().remove(player);
//Save
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.removeMember(clan.getId(), player);
}
});
_repository.removeMember(clan.getId(), player);
//Log
_manager.log("Removed [" + player + "] from [" + clan.getName() + "].");
}
public void role(final ClanInfo clan, final String player, final Role role)
public void role(ClanInfo clan, String player, Role role)
{
//Update Clan
clan.getMembers().put(player, role);
//Save
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.updateMember(clan.getId(), player, role.toString());
}
});
_repository.updateMember(clan.getId(), player, role.toString());
//Log
_manager.log("Removed [" + player + "] from [" + clan.getName() + "].");
@ -174,7 +137,7 @@ public class ClansDataAccessLayer
_manager.log("Alliance Request to [" + target.getName() + "] from [" + clan.getName() + "] by [" + player + "].");
}
public void ally(final ClanInfo cA, final ClanInfo cB, String player)
public void ally(ClanInfo cA, ClanInfo cB, String player)
{
//Remove Requests
cA.getRequestMap().remove(cB.getName());
@ -185,23 +148,16 @@ public class ClansDataAccessLayer
cB.getAllyMap().put(cA.getName(), false);
//Save
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.addClanRelationship(cA.getId(), cB.getId(), false);
_repository.addClanRelationship(cB.getId(), cA.getId(), false);
}
});
_repository.addClanRelationship(cA.getId(), cB.getId(), false);
_repository.addClanRelationship(cB.getId(), cA.getId(), false);
//Log
_manager.log("Added Ally for [" + cB.getName() + "] and [" + cA.getName() + "] by [" + player + "].");
}
public void enemy(final ClanInfo clan, final ClanInfo otherClan, String player)
public void enemy(ClanInfo clan, ClanInfo otherClan, String player)
{
_repository.addEnemy(clan.getId(), otherClan.getId());
Date currDate = new Date();
ClanEnemyToken clanEnemyToken = new ClanEnemyToken();
@ -216,37 +172,21 @@ public class ClansDataAccessLayer
otherClanEnemyToken.EnemyName = clan.getName();
otherClan.updateEnemy(otherClanEnemyToken);
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.addEnemy(clan.getId(), otherClan.getId());
}
});
_manager.log("Added Enemy for [" + clan.getName() + "] and [" + otherClan.getName() + "] by [" + player + "].");
}
public boolean trust(final ClanInfo ownerClan, final ClanInfo otherClan, String player)
public boolean trust(ClanInfo ownerClan, ClanInfo otherClan, String player)
{
if (!ownerClan.getAllyMap().containsKey(otherClan.getName()))
return false;
final boolean trust = !ownerClan.getAllyMap().get(otherClan.getName());
boolean trust = !ownerClan.getAllyMap().get(otherClan.getName());
//Memory
ownerClan.getAllyMap().put(otherClan.getName(), trust);
//Save
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.updateClanRelationship(ownerClan.getId(), otherClan.getId(), trust);
}
});
_repository.updateClanRelationship(ownerClan.getId(), otherClan.getId(), trust);
//Log
_manager.log((trust ? "Gave" : "Revoked") + " Trust [" + trust + "] to [" + otherClan.getName() + "] for [" + ownerClan.getName() + "] by [" + player + "].");
@ -254,34 +194,27 @@ public class ClansDataAccessLayer
return trust;
}
public void neutral(final ClanInfo cA, final ClanInfo cB, String player, boolean bothClansManager)
public void neutral(ClanInfo cA, ClanInfo cB, String player, boolean bothClansManager)
{
//Update ClansManager
cA.getAllyMap().remove(cB.getName());
cB.getAllyMap().remove(cA.getName());
//Save
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.removeClanRelationship(cA.getId(), cB.getId());
_repository.removeClanRelationship(cB.getId(), cA.getId());
}
});
_repository.removeClanRelationship(cA.getId(), cB.getId());
_repository.removeClanRelationship(cB.getId(), cA.getId());
//Log
_manager.log("Added Neutral between [" + cA.getName() + "] and [" + cB.getName() + "] by [" + player + "].");
}
@SuppressWarnings("deprecation")
public boolean claim(String name, final String chunk, String player, final boolean safe)
public boolean claim(String name, String chunk, String player, boolean safe)
{
if (!_manager.getClanMap().containsKey(name))
return false;
final ClanInfo clan = _manager.getClanMap().get(name);
ClanInfo clan = _manager.getClanMap().get(name);
//Unclaim
if (_manager.getClaimMap().containsKey(chunk))
@ -295,14 +228,7 @@ public class ClansDataAccessLayer
_manager.getClaimMap().put(chunk, claim);
//Save
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.addTerritoryClaim(clan.getId(), chunk, safe);
}
});
_repository.addTerritoryClaim(clan.getId(), chunk, safe);
//Visual
Chunk c = UtilWorld.strToChunk(chunk);
@ -324,7 +250,7 @@ public class ClansDataAccessLayer
return true;
}
public boolean unclaim(final String chunk, String player, boolean sql)
public boolean unclaim(String chunk, String player, boolean sql)
{
ClanTerritory claim = _manager.getClaimMap().remove(chunk);
@ -334,7 +260,7 @@ public class ClansDataAccessLayer
return false;
}
final ClanInfo clan = _manager.getClanMap().get(claim.Owner);
ClanInfo clan = _manager.getClanMap().get(claim.Owner);
if (clan == null)
{
@ -346,14 +272,7 @@ public class ClansDataAccessLayer
clan.getClaimSet().remove(chunk);
//Save
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.removeTerritoryClaim(clan.getId(), chunk);
}
});
_repository.removeTerritoryClaim(clan.getId(), chunk);
//Register
// _manager.getUnclaimMap().put(chunk, System.currentTimeMillis());
@ -370,20 +289,13 @@ public class ClansDataAccessLayer
return unclaim(chunk, null, sql);
}
public void home(final ClanInfo clan, Location loc, String player)
public void home(ClanInfo clan, Location loc, String player)
{
//Memory
clan.setHome(loc);
//Save
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.updateClan(clan.getId(), clan.getName(), clan.getDesc(), UtilWorld.locToStr(clan.getHome()), clan.isAdmin(), clan.getEnergy(), clan.getLastOnline());
}
});
_repository.updateClan(clan.getId(), clan.getName(), clan.getDesc(), UtilWorld.locToStr(clan.getHome()), clan.isAdmin(), clan.getEnergy(), clan.getLastOnline());
//Log
_manager.log("Set Home for [" + clan.getName() + "] to " + UtilWorld.locToStrClean(loc) + " by [" + player + "].");
@ -394,54 +306,32 @@ public class ClansDataAccessLayer
assert clan.getEnemyData() != null && otherClan.getEnemyData() != null;
assert clan.getEnemyData().getEnemyName() == otherClan.getName() && otherClan.getEnemyData().getEnemyName() == clan.getName();
final ClanInfo initiator = clan.getEnemyData().isInitiator() ? clan : otherClan;
final EnemyData iData = initiator.getEnemyData();
final ClanInfo other = clan == initiator ? otherClan : clan;
final EnemyData oData = other.getEnemyData();
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.updateEnemy(initiator.getId(), other.getId(), iData.getScore(), oData.getScore(), iData.getKills(), oData.getKills());
}
});
ClanInfo initiator = clan.getEnemyData().isInitiator() ? clan : otherClan;
EnemyData iData = initiator.getEnemyData();
ClanInfo other = clan == initiator ? otherClan : clan;
EnemyData oData = other.getEnemyData();
_repository.updateEnemy(initiator.getId(), other.getId(), iData.getScore(), oData.getScore(), iData.getKills(), oData.getKills());
//Log
_manager.log("Updated Enemy Data for [" + clan.getName() + ", " + otherClan.getName() + "]");
}
public void updateEnergy(final ClanInfo clan)
public void updateEnergy(ClanInfo clan)
{
//Save
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.updateClan(clan.getId(), clan.getName(), clan.getDesc(), UtilWorld.locToStr(clan.getHome()), clan.isAdmin(), clan.getEnergy(), clan.getLastOnline());
}
});
_repository.updateClan(clan.getId(), clan.getName(), clan.getDesc(), UtilWorld.locToStr(clan.getHome()), clan.isAdmin(), clan.getEnergy(), clan.getLastOnline());
//Log
_manager.log("Updated Energy for [" + clan.getName() + "] to " + clan.getEnergy() + ".");
}
public void safe(final ClanTerritory claim, String player)
public void safe(ClanTerritory claim, String player)
{
//Memory
claim.Safe = !claim.Safe;
//Save
runAsync(new Runnable()
{
@Override
public void run()
{
_repository.updateTerritoryClaim(claim.Chunk, claim.Safe);
}
});
_repository.updateTerritoryClaim(claim.Chunk, claim.Safe);
//Log
_manager.log("Safe Zone at [" + claim.Chunk + "] set to [" + claim.Safe + "] by [" + player + "].");
@ -451,9 +341,4 @@ public class ClansDataAccessLayer
{
return _repository;
}
public void runAsync(Runnable r)
{
_manager.runAsync(r);
}
}