More war fixes - still needs tweaking
This commit is contained in:
parent
00a689ea03
commit
5944b734be
@ -73,7 +73,7 @@ public class ClanRepository extends RepositoryBase
|
||||
private static String UPDATE_CLAN_MEMBER = "UPDATE accountClan AS AC INNER JOIN accounts ON accounts.id = AC.accountId SET AC.clanRole = ? WHERE AC.clanId = ? AND accounts.name = ?;";
|
||||
private static String UPDATE_CLAN_ALLIANCE = "UPDATE clanAlliances SET trusted = ? WHERE clanId = ? AND otherClanId = ?;";
|
||||
private static String UPDATE_CLAN_TERRITORY = "UPDATE clanTerritory SET safe = ? WHERE chunk = ?;"; //
|
||||
private static String UPDATE_CLAN_WAR = "UPDATE clanWar SET score = ?, completed = ?, ended = ?, lastUpdated = NOW() WHERE initiatorId = ? AND clanId = ?";
|
||||
private static String UPDATE_CLAN_WAR = "UPDATE clanWar SET score = ?, completed = ?, ended = ?, lastUpdated = ? WHERE initiatorId = ? AND clanId = ?";
|
||||
private static String UPDATE_CLAN_SERVER_ID = "UPDATE clans SET serverId = ?, home = '', generator = '' WHERE id = ?;";
|
||||
private static String UPDATE_CLAN_GENERATOR = "UPDATE clans SET generator = ?, generatorStock = ? WHERE id = ?;";
|
||||
|
||||
@ -378,6 +378,7 @@ public class ClanRepository extends RepositoryBase
|
||||
|
||||
if (clans.containsKey(warToken.ClanA) && clans.containsKey(warToken.ClanB))
|
||||
{
|
||||
System.out.println("Loaded War Token: " + warToken.ClanA);
|
||||
clans.get(warToken.ClanA).WarsInitiated.add(warToken);
|
||||
clans.get(warToken.ClanB).WarsInitiatedOn.add(warToken);
|
||||
}
|
||||
@ -516,10 +517,10 @@ public class ClanRepository extends RepositoryBase
|
||||
executeUpdate(ADD_CLAN_WAR, new ColumnInt("initiatorId", initiatorId), new ColumnInt("clanId", clanId), new ColumnInt("score", score));
|
||||
}
|
||||
|
||||
public void updateWar(int initiatorId, int clanId, int score, boolean completed, Timestamp ended)
|
||||
public boolean updateWar(int initiatorId, int clanId, int score, boolean completed, Timestamp lastUpdated, Timestamp ended)
|
||||
{
|
||||
executeUpdate(UPDATE_CLAN_WAR, new ColumnInt("score", score), new ColumnBoolean("completed", completed), new ColumnTimestamp("ended", ended),
|
||||
new ColumnInt("initiatorId", initiatorId), new ColumnInt("clanId", clanId));
|
||||
return 1 == executeUpdate(UPDATE_CLAN_WAR, new ColumnInt("score", score), new ColumnBoolean("completed", completed), new ColumnTimestamp("ended", ended),
|
||||
new ColumnTimestamp("lastUpdated", lastUpdated), new ColumnInt("initiatorId", initiatorId), new ColumnInt("clanId", clanId));
|
||||
}
|
||||
|
||||
public void deleteAllWar(int clanId)
|
||||
|
@ -135,8 +135,14 @@ public class ClanInfo
|
||||
for (ClanWarToken warToken : token.WarsInitiated)
|
||||
{
|
||||
ClanWar war = new ClanWar(warToken);
|
||||
_initiatedWars.put(war.getClanB(), war);
|
||||
}
|
||||
|
||||
for (ClanWarToken warToken : token.WarsInitiatedOn)
|
||||
{
|
||||
ClanWar war = new ClanWar(warToken);
|
||||
_initiatedOnWars.put(war.getClanA(), war);
|
||||
}
|
||||
}
|
||||
|
||||
public int getClaims()
|
||||
@ -540,23 +546,29 @@ public class ClanInfo
|
||||
|
||||
public ClanWar getInitiatedWar(String againstClan)
|
||||
{
|
||||
if (_initiatedWars.containsKey(againstClan))
|
||||
System.out.println("Grabbed from Initiated War");
|
||||
|
||||
return _initiatedWars.get(againstClan);
|
||||
}
|
||||
|
||||
public ClanWar getInitiatedOnWar(String againstClan)
|
||||
{
|
||||
if (_initiatedWars.containsKey(againstClan))
|
||||
System.out.println("Grabbed from Initiated On War");
|
||||
|
||||
return _initiatedOnWars.get(againstClan);
|
||||
}
|
||||
|
||||
public void addWar(ClanWar clanWar)
|
||||
{
|
||||
if (equals(clanWar.getClanA()))
|
||||
if (getName().equals(clanWar.getClanA()))
|
||||
{
|
||||
_initiatedWars.put(clanWar.getClanB().getName(), clanWar);
|
||||
_initiatedWars.put(clanWar.getClanB(), clanWar);
|
||||
}
|
||||
else if (equals(clanWar.getClanB()))
|
||||
else if (getName().equals(clanWar.getClanB()))
|
||||
{
|
||||
_initiatedOnWars.put(clanWar.getClanA().getName(), clanWar);
|
||||
_initiatedOnWars.put(clanWar.getClanA(), clanWar);
|
||||
}
|
||||
}
|
||||
|
||||
@ -566,6 +578,12 @@ public class ClanInfo
|
||||
return initiated == null ? getInitiatedOnWar(againstClan) : initiated;
|
||||
}
|
||||
|
||||
public void clearWar(String againstClan)
|
||||
{
|
||||
_initiatedWars.remove(againstClan);
|
||||
_initiatedOnWars.remove(againstClan);
|
||||
}
|
||||
|
||||
public boolean isAtWar(ClanInfo clanInfo)
|
||||
{
|
||||
return isAtWar(clanInfo.getName());
|
||||
|
@ -80,6 +80,8 @@ public class ClansDataAccessLayer
|
||||
|
||||
_manager.getClanMap().remove(clan.getName());
|
||||
|
||||
_manager.getWarManager().clearInvasions(clan.getName());
|
||||
|
||||
for (ClansPlayer player : clan.getMembers().values())
|
||||
{
|
||||
_manager.getClanMemberUuidMap().remove(player.getUuid());
|
||||
@ -90,6 +92,7 @@ public class ClansDataAccessLayer
|
||||
{
|
||||
cur.getAllyMap().remove(clan.getName());
|
||||
cur.getRequestMap().remove(clan.getName());
|
||||
cur.clearWar(cur.getName());
|
||||
}
|
||||
|
||||
//Scoreboard
|
||||
@ -632,7 +635,7 @@ public class ClansDataAccessLayer
|
||||
|
||||
public void war(final ClanInfo clanA, final ClanInfo clanB, final Callback<ClanWar> warCallback)
|
||||
{
|
||||
final ClanWar war = new ClanWar(clanA, clanB, WarManager.WAR_START_SCORE, false, new Timestamp(System.currentTimeMillis()), null, new Timestamp(System.currentTimeMillis()));
|
||||
final ClanWar war = new ClanWar(clanA.getName(), clanB.getName(), WarManager.WAR_START_SCORE, false, new Timestamp(System.currentTimeMillis()), null, new Timestamp(System.currentTimeMillis()));
|
||||
|
||||
runAsync(new Runnable()
|
||||
{
|
||||
@ -660,6 +663,26 @@ public class ClansDataAccessLayer
|
||||
|
||||
}
|
||||
|
||||
public void updateWar(final ClanInfo clanA, final ClanInfo clanB, final ClanWar war, final Callback<Boolean> callback)
|
||||
{
|
||||
runAsync(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final boolean ran = _repository.updateWar(clanA.getId(), clanB.getId(), war.getScore(), war.isCompleted(), war.getLastUpdated(), war.getEnded());
|
||||
runSync(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if (callback != null) callback.run(ran);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
public void updateEnemy(ClanInfo clan, ClanInfo otherClan)
|
||||
{
|
||||
|
@ -7,8 +7,8 @@ import mineplex.game.clans.core.repository.tokens.ClanWarToken;
|
||||
|
||||
public class ClanWar
|
||||
{
|
||||
private ClanInfo _clanA;
|
||||
private ClanInfo _clanB;
|
||||
private String _clanA;
|
||||
private String _clanB;
|
||||
private int _score;
|
||||
private boolean _completed;
|
||||
private Timestamp _created;
|
||||
@ -17,9 +17,20 @@ public class ClanWar
|
||||
|
||||
public ClanWar(ClanWarToken warToken)
|
||||
{
|
||||
_clanA = warToken.ClanA;
|
||||
_clanB = warToken.ClanB;
|
||||
_score = warToken.Score;
|
||||
_completed = false;
|
||||
_created = warToken.Created;
|
||||
_ended = warToken.Ended;
|
||||
_lastUpdated = warToken.Updated;
|
||||
System.out.println("Loading Clan War");
|
||||
System.out.println("Initiator: " + _clanA);
|
||||
System.out.println("Other Clan: " + _clanB);
|
||||
System.out.println("Score: " + _score);
|
||||
}
|
||||
|
||||
public ClanWar(ClanInfo clanA, ClanInfo clanB, int score, boolean completed, Timestamp created, Timestamp ended, Timestamp lastUpdated)
|
||||
public ClanWar(String clanA, String clanB, int score, boolean completed, Timestamp created, Timestamp ended, Timestamp lastUpdated)
|
||||
{
|
||||
_clanA = clanA;
|
||||
_clanB = clanB;
|
||||
@ -33,7 +44,7 @@ public class ClanWar
|
||||
/**
|
||||
* Get the clan that was the initiator for this war
|
||||
*/
|
||||
public ClanInfo getClanA()
|
||||
public String getClanA()
|
||||
{
|
||||
return _clanA;
|
||||
}
|
||||
@ -41,7 +52,7 @@ public class ClanWar
|
||||
/**
|
||||
* Get the clan that was initiated on for this war
|
||||
*/
|
||||
public ClanInfo getClanB()
|
||||
public String getClanB()
|
||||
{
|
||||
return _clanB;
|
||||
}
|
||||
@ -103,14 +114,16 @@ public class ClanWar
|
||||
*/
|
||||
public void increaseScoreFor(ClanInfo clanInfo)
|
||||
{
|
||||
if (_clanA.equals(clanInfo))
|
||||
if (_clanA.equals(clanInfo.getName()))
|
||||
{
|
||||
_score++;
|
||||
}
|
||||
else if (_clanB.equals(clanInfo))
|
||||
else if (_clanB.equals(clanInfo.getName()))
|
||||
{
|
||||
_score--;
|
||||
}
|
||||
|
||||
_lastUpdated.setTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,8 +6,8 @@ public class WarInvasion
|
||||
{
|
||||
private static final long INVADE_LENGTH = 60000L * 30; // 30 Minutes
|
||||
|
||||
private ClanInfo _invadedClan;
|
||||
private ClanInfo _invaderClan;
|
||||
private String _invadedClan;
|
||||
private String _invaderClan;
|
||||
private long _startTime;
|
||||
private long _endTime;
|
||||
|
||||
@ -30,7 +30,7 @@ public class WarInvasion
|
||||
_endTime = _startTime + INVADE_LENGTH;
|
||||
}
|
||||
|
||||
public WarInvasion(ClanInfo invadedClan, ClanInfo invaderClan)
|
||||
public WarInvasion(String invadedClan, String invaderClan)
|
||||
{
|
||||
_invadedClan = invadedClan;
|
||||
_invaderClan = invaderClan;
|
||||
@ -38,12 +38,12 @@ public class WarInvasion
|
||||
_endTime = _startTime + INVADE_LENGTH;
|
||||
}
|
||||
|
||||
public ClanInfo getInvadedClan()
|
||||
public String getInvadedClan()
|
||||
{
|
||||
return _invadedClan;
|
||||
}
|
||||
|
||||
public ClanInfo getInvaderClan()
|
||||
public String getInvaderClan()
|
||||
{
|
||||
return _invaderClan;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
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;
|
||||
@ -95,20 +96,20 @@ public class WarManager extends MiniPlugin
|
||||
|
||||
private void addInvasion(WarInvasion invasion)
|
||||
{
|
||||
ClanInfo invaded = invasion.getInvadedClan();
|
||||
String invaded = invasion.getInvadedClan();
|
||||
if (_activeInvasions.containsKey(invaded))
|
||||
{
|
||||
_activeInvasions.get(invaded.getName()).add(invasion);
|
||||
_activeInvasions.get(invaded).add(invasion);
|
||||
}
|
||||
else
|
||||
{
|
||||
LinkedList<WarInvasion> invasions = new LinkedList<WarInvasion>();
|
||||
invasions.add(invasion);
|
||||
_activeInvasions.put(invaded.getName(), invasions);
|
||||
_activeInvasions.put(invaded, invasions);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkWarComplete(ClanWar clanWar)
|
||||
private void checkWarComplete(final ClanWar clanWar)
|
||||
{
|
||||
boolean completed = false;
|
||||
|
||||
@ -125,16 +126,38 @@ public class WarManager extends MiniPlugin
|
||||
|
||||
if (completed)
|
||||
{
|
||||
ClanInfo clanA = _clansManager.getClan(clanWar.getClanA());
|
||||
ClanInfo clanB = _clansManager.getClan(clanWar.getClanB());
|
||||
|
||||
if (clanA == null || clanB == null)
|
||||
{
|
||||
System.out.println("CLAN WAR COMPLETE ERROR");
|
||||
System.out.println("CLAN A OR B IS NULL! THIS SHOULDNT HAPPEN");
|
||||
System.out.println("ClanA: " + clanWar.getClanA() + " clanB: " + clanWar.getClanB());
|
||||
return;
|
||||
}
|
||||
|
||||
clanWar.setCompleted(true);
|
||||
clanWar.setEnded(new Timestamp(System.currentTimeMillis()));
|
||||
_clansManager.getClanDataAccess().updateWar(clanA, clanB, clanWar, new Callback<Boolean>()
|
||||
{
|
||||
@Override
|
||||
public void run(Boolean data)
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
WarInvasion invasion = new WarInvasion(clanWar);
|
||||
addInvasion(invasion);
|
||||
|
||||
WarInvasion invasion = new WarInvasion(clanWar);
|
||||
addInvasion(invasion);
|
||||
// Remove from memory
|
||||
|
||||
WarEndEvent warEndEvent = new WarEndEvent(clanWar);
|
||||
WarInvasionStartEvent invasionStartEvent = new WarInvasionStartEvent(invasion);
|
||||
Bukkit.getServer().getPluginManager().callEvent(warEndEvent);
|
||||
Bukkit.getServer().getPluginManager().callEvent(invasionStartEvent);
|
||||
WarEndEvent warEndEvent = new WarEndEvent(clanWar);
|
||||
WarInvasionStartEvent invasionStartEvent = new WarInvasionStartEvent(invasion);
|
||||
Bukkit.getServer().getPluginManager().callEvent(warEndEvent);
|
||||
Bukkit.getServer().getPluginManager().callEvent(invasionStartEvent);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,6 +187,14 @@ public class WarManager extends MiniPlugin
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all invasions against clan. This is typically used for when a clan is deleted
|
||||
*/
|
||||
public void clearInvasions(String clan)
|
||||
{
|
||||
_activeInvasions.remove(clan);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handleDeath(ClansPlayerDeathEvent event)
|
||||
{
|
||||
@ -177,6 +208,7 @@ public class WarManager extends MiniPlugin
|
||||
ClanWar war = clan.getWar(killerClan);
|
||||
if (war != null && !war.isCompleted())
|
||||
{
|
||||
_clansManager.messageClan(killerClan, C.cAqua + "Gained +1 Dominance against " + C.cRed + clan.getName());
|
||||
war.increaseScoreFor(killerClan);
|
||||
checkWarComplete(war);
|
||||
}
|
||||
@ -214,6 +246,19 @@ public class WarManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInvasionStart(WarInvasionStartEvent event)
|
||||
{
|
||||
Bukkit.broadcastMessage(F.main("War", F.elem(event.getWarInvasion().getInvaderClan()) + " can now invade " + F.elem(event.getWarInvasion().getInvaderClan())));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInvasionEnd(WarInvasionEndEvent event)
|
||||
{
|
||||
Bukkit.broadcastMessage(F.main("War", F.elem(event.getWarInvasion().getInvaderClan()) + "'s invasion against " + F.elem(event.getWarInvasion().getInvaderClan() + " has ended.")));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCommands()
|
||||
{
|
||||
|
@ -46,8 +46,11 @@ public class DominanceCommand extends CommandBase<WarManager>
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Initiator: " + war.getClanA());
|
||||
System.out.println("Other Clan: " + war.getClanB());
|
||||
System.out.println("Score: " + war.getScore());
|
||||
UtilPlayer.message(caller, F.main("War", "War Status with " + searchName));
|
||||
UtilPlayer.message(caller, F.main("War", "Initiated by: " + (war.getClanA() == clan ? selfName : searchName)));
|
||||
UtilPlayer.message(caller, F.main("War", "Initiated by: " + (war.getClanA().equals(clan.getName()) ? selfName : searchName)));
|
||||
UtilPlayer.message(caller, F.main("War", "Initiator Dominance: " + F.elem("" + war.getScore())));
|
||||
UtilPlayer.message(caller, F.main("War", "Age: " + F.elem(UtilTime.convertString(System.currentTimeMillis() - war.getCreated().getTime(), 1, UtilTime.TimeUnit.FIT))));
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
@ -49,8 +50,8 @@ public class WarCommand extends CommandBase<WarManager>
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
Plugin.getClansManager().messageClan(clan, "You are now at war with " + search.getName());
|
||||
Plugin.getClansManager().messageClan(search, "You are now at war with " + clan.getName());
|
||||
Plugin.getClansManager().messageClan(clan, C.cRed + "You are now at war with " + C.cDRed + search.getName());
|
||||
Plugin.getClansManager().messageClan(search, C.cRed + "You are now at war with " + C.cDRed + clan.getName());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user