Fix War Points bug

This commit is contained in:
Shaun Bennett 2015-11-16 17:27:56 -05:00
parent 0d372cefaa
commit 5b30cfb67e
11 changed files with 120 additions and 153 deletions

View File

@ -30,6 +30,7 @@ import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.game.clans.core.repository.tokens.ClanWarToken; import mineplex.game.clans.core.repository.tokens.ClanWarToken;
import mineplex.game.clans.core.war.ClanWarData;
import org.jooq.DSLContext; import org.jooq.DSLContext;
import static mineplex.database.Tables.*; import static mineplex.database.Tables.*;
@ -369,18 +370,20 @@ public class ClanRepository extends RepositoryBase
while (resultSet.next()) while (resultSet.next())
{ {
ClanWarToken warToken = new ClanWarToken(); ClanWarToken warToken = new ClanWarToken();
warToken.ClanA = resultSet.getString(1); String clanA = resultSet.getString(1);
warToken.ClanB = resultSet.getString(2); String clanB = resultSet.getString(2);
warToken.Score = resultSet.getInt(3); int score = resultSet.getInt(3);
warToken.Created = resultSet.getTimestamp(4); Timestamp created = resultSet.getTimestamp(4);
// warToken.Ended = resultSet.getTimestamp(5); // warToken.Ended = resultSet.getTimestamp(5);
warToken.Updated = resultSet.getTimestamp(6); Timestamp updated = resultSet.getTimestamp(6);
ClanWarData warData = new ClanWarData(clanA, clanB, score, created, updated, 0);
warToken.WarData = warData;
if (clans.containsKey(warToken.ClanA) && clans.containsKey(warToken.ClanB)) if (clans.containsKey(warToken.WarData.getClanA()) && clans.containsKey(warToken.WarData.getClanB()))
{ {
System.out.println("Loaded War Token: " + warToken.ClanA); System.out.println("Loaded War Token: " + warToken.WarData.getClanA());
clans.get(warToken.ClanA).WarsOut.add(warToken); clans.get(warToken.WarData.getClanA()).WarsOut.add(warToken);
clans.get(warToken.ClanB).WarsIn.add(warToken); clans.get(warToken.WarData.getClanB()).WarsIn.add(warToken);
} }
} }
} }

View File

@ -1,12 +1,8 @@
package mineplex.game.clans.core.repository.tokens; package mineplex.game.clans.core.repository.tokens;
import java.sql.Timestamp; import mineplex.game.clans.core.war.ClanWarData;
public class ClanWarToken public class ClanWarToken
{ {
public String ClanA; public ClanWarData WarData;
public String ClanB;
public int Score;
public Timestamp Created;
public Timestamp Updated;
} }

View File

@ -0,0 +1,89 @@
package mineplex.game.clans.core.war;
import java.sql.Timestamp;
public class ClanWarData
{
private String _clanA;
private String _clanB;
private volatile int _clanAPoints;
private Timestamp _timeFormed;
private Timestamp _lastUpdated;
private long _cooldown;
public ClanWarData(String clanA, String clanB, int clanAPoints, Timestamp timeFormed, Timestamp lastUpdated, long cooldown)
{
_clanA = clanA;
_clanB = clanB;
_clanAPoints = clanAPoints;
_timeFormed = timeFormed;
_lastUpdated = lastUpdated;
_cooldown = cooldown;
}
public String getClanA()
{
return _clanA;
}
public String getClanB()
{
return _clanB;
}
public int getPoints(String clan)
{
if (_clanA.equals(clan))
return getPoints();
else if (_clanB.equals(clan))
return -getPoints();
throw new RuntimeException("ClanWarData::getPoints Invalid Clan for War. ClanA: " + _clanA + ", ClanB: " + _clanB + ", Lookup Clan: " + clan);
}
public int getPoints()
{
System.out.println("ClanWarData::getPoints Value: " + _clanAPoints + " Hash: " + hashCode());
return _clanAPoints;
}
public Timestamp getTimeFormed()
{
return _timeFormed;
}
public Timestamp getLastUpdated()
{
return _lastUpdated;
}
public void setLastUpdated(Timestamp lastUpdated)
{
_lastUpdated = lastUpdated;
}
public long getCooldown()
{
return _cooldown;
}
public void setCooldown(long cooldown)
{
_cooldown = cooldown;
}
public boolean isOnCooldown()
{
return _cooldown >= System.currentTimeMillis();
}
public void increment(String clan)
{
if (_clanA.equals(clan))
_clanAPoints++;
else if (_clanB.equals(clan))
_clanAPoints--;
else throw new RuntimeException("ClanWarData::increment Invalid Clan for War. ClanA: " + _clanA + ", ClanB: " + _clanB + ", Lookup Clan: " + clan);
}
}

View File

@ -23,7 +23,7 @@ import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.common.util.UtilWorld; import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClansUtility.ClanRelation; import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.war.ClanWarData; import mineplex.game.clans.core.war.ClanWarData;
import mineplex.game.clans.core.repository.tokens.ClanAllianceToken; import mineplex.game.clans.core.repository.tokens.ClanAllianceToken;
import mineplex.game.clans.core.repository.tokens.ClanMemberToken; import mineplex.game.clans.core.repository.tokens.ClanMemberToken;
import mineplex.game.clans.core.repository.tokens.ClanTerritoryToken; import mineplex.game.clans.core.repository.tokens.ClanTerritoryToken;
@ -131,16 +131,16 @@ public class ClanInfo
for (ClanWarToken warToken : token.WarsIn) for (ClanWarToken warToken : token.WarsIn)
{ {
ClanWarData war = new ClanWarData(warToken); ClanWarData warData = warToken.WarData;
System.out.println("Adding war in for " + getName() + " against " + war.getClanA()); System.out.println("Adding war in for " + getName() + " against " + warData.getClanA());
_warIn.put(war.getClanA(), war); _warIn.put(warData.getClanA(), warData);
} }
for (ClanWarToken warToken : token.WarsOut) for (ClanWarToken warToken : token.WarsOut)
{ {
ClanWarData war = new ClanWarData(warToken); ClanWarData warData = warToken.WarData;
System.out.println("Adding war out for " + getName() + " against " + war.getClanB()); System.out.println("Adding war out for " + getName() + " against " + warData.getClanB());
_warOut.put(war.getClanB(), war); _warOut.put(warData.getClanB(), warData);
} }
} }
@ -558,7 +558,7 @@ public class ClanInfo
ClanWarData data = getWarData(against); ClanWarData data = getWarData(against);
if (data != null) if (data != null)
{ {
warPoints = data.getPoints(this); warPoints = data.getPoints(getName());
} }
return warPoints; return warPoints;

View File

@ -19,7 +19,7 @@ import mineplex.game.clans.clans.event.ClanCreatedEvent;
import mineplex.game.clans.clans.event.ClanDeleteEvent; import mineplex.game.clans.clans.event.ClanDeleteEvent;
import mineplex.game.clans.clans.scoreboard.ClansScoreboardManager; import mineplex.game.clans.clans.scoreboard.ClansScoreboardManager;
import mineplex.game.clans.clans.tntGenerator.TntGenerator; import mineplex.game.clans.clans.tntGenerator.TntGenerator;
import mineplex.game.clans.clans.war.ClanWarData; import mineplex.game.clans.core.war.ClanWarData;
import mineplex.game.clans.core.repository.ClanRepository; import mineplex.game.clans.core.repository.ClanRepository;
import mineplex.game.clans.core.repository.ClanTerritory; import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.game.clans.core.repository.tokens.ClanToken; import mineplex.game.clans.core.repository.tokens.ClanToken;

View File

@ -1,123 +0,0 @@
package mineplex.game.clans.clans.war;
import java.sql.Timestamp;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.core.repository.tokens.ClanWarToken;
public class ClanWarData
{
private String _clanA;
private String _clanB;
private volatile int _clanAPoints;
private Timestamp _timeFormed;
private Timestamp _lastUpdated;
private long _cooldown;
public ClanWarData(String clanA, String clanB, int clanAPoints, Timestamp timeFormed, Timestamp lastUpdated, long cooldown)
{
_clanA = clanA;
_clanB = clanB;
_clanAPoints = clanAPoints;
_timeFormed = timeFormed;
_lastUpdated = lastUpdated;
_cooldown = cooldown;
}
public ClanWarData(ClanWarToken token)
{
this(token.ClanA, token.ClanB, token.Score, token.Created, token.Updated, 0L);
}
public String getClanA()
{
return _clanA;
}
public String getClanB()
{
return _clanB;
}
public int getPoints(ClanInfo clan)
{
if (_clanA.equals(clan.getName()))
return _clanAPoints;
else if (_clanB.equals(clan.getName()))
return -_clanAPoints;
throw new RuntimeException("ClanWarData::getPoints Invalid Clan for War. ClanA: " + _clanA + ", ClanB: " + _clanB + ", Lookup Clan: " + clan.getName());
}
public int getPoints()
{
return _clanAPoints;
}
public Timestamp getTimeFormed()
{
return _timeFormed;
}
public Timestamp getLastUpdated()
{
return _lastUpdated;
}
public void setLastUpdated(Timestamp lastUpdated)
{
_lastUpdated = lastUpdated;
}
public long getCooldown()
{
return _cooldown;
}
public void setCooldown(long cooldown)
{
_cooldown = cooldown;
}
public boolean isOnCooldown()
{
return _cooldown >= System.currentTimeMillis();
}
public void increment(ClanInfo clan)
{
if (_clanA.equals(clan.getName()))
_clanAPoints++;
else if (_clanB.equals(clan.getName()))
_clanAPoints--;
else throw new RuntimeException("ClanWarData::increment Invalid Clan for War. ClanA: " + _clanA + ", ClanB: " + _clanB + ", Lookup Clan: " + clan.getName());
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClanWarData that = (ClanWarData) o;
if (_clanAPoints != that._clanAPoints) return false;
if (_cooldown != that._cooldown) return false;
if (!_clanA.equals(that._clanA)) return false;
if (!_clanB.equals(that._clanB)) return false;
if (!_timeFormed.equals(that._timeFormed)) return false;
return _lastUpdated.equals(that._lastUpdated);
}
@Override
public int hashCode()
{
int result = _clanA.hashCode();
result = 31 * result + _clanB.hashCode();
result = 31 * result + _clanAPoints;
result = 31 * result + _timeFormed.hashCode();
result = 31 * result + _lastUpdated.hashCode();
result = 31 * result + (int) (_cooldown ^ (_cooldown >>> 32));
return result;
}
}

View File

@ -1,5 +1,7 @@
package mineplex.game.clans.clans.war; package mineplex.game.clans.clans.war;
import mineplex.game.clans.core.war.ClanWarData;
public class WarInvasion public class WarInvasion
{ {
private static final long INVADE_LENGTH = 60000L * 30; // 30 Minutes private static final long INVADE_LENGTH = 60000L * 30; // 30 Minutes

View File

@ -23,9 +23,9 @@ import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ClansUtility; import mineplex.game.clans.clans.ClansUtility;
import mineplex.game.clans.clans.event.ClansPlayerDeathEvent; import mineplex.game.clans.clans.event.ClansPlayerDeathEvent;
import mineplex.game.clans.clans.war.command.WarPointsCommand; import mineplex.game.clans.clans.war.command.WarPointsCommand;
import mineplex.game.clans.clans.war.event.WarEndEvent;
import mineplex.game.clans.clans.war.event.WarInvasionEndEvent; import mineplex.game.clans.clans.war.event.WarInvasionEndEvent;
import mineplex.game.clans.clans.war.event.WarInvasionStartEvent; import mineplex.game.clans.clans.war.event.WarInvasionStartEvent;
import mineplex.game.clans.core.war.ClanWarData;
public class WarManager extends MiniPlugin public class WarManager extends MiniPlugin
{ {
@ -124,7 +124,7 @@ public class WarManager extends MiniPlugin
ClansUtility.ClanRelation rel = _clansManager.getClanUtility().rel(clan, killerClan); ClansUtility.ClanRelation rel = _clansManager.getClanUtility().rel(clan, killerClan);
_clansManager.middleTextClan(killerClan, "", C.cGreen + "+1 WP against " + rel.getColor(false) + clan.getName()); _clansManager.middleTextClan(killerClan, "", C.cGreen + "+1 WP against " + rel.getColor(false) + clan.getName());
_clansManager.middleTextClan(clan, "", C.cGreen + "-1 WP against " + rel.getColor(false) + killerClan.getName()); _clansManager.middleTextClan(clan, "", C.cGreen + "-1 WP against " + rel.getColor(false) + killerClan.getName());
war.increment(killerClan); war.increment(killerClan.getName());
// todo: check war complete // todo: check war complete
} }
else else

View File

@ -9,7 +9,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime;
import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.war.ClanWarData; import mineplex.game.clans.core.war.ClanWarData;
import mineplex.game.clans.clans.war.WarManager; import mineplex.game.clans.clans.war.WarManager;
public class WarPointsCommand extends CommandBase<WarManager> public class WarPointsCommand extends CommandBase<WarManager>
@ -49,7 +49,7 @@ public class WarPointsCommand extends CommandBase<WarManager>
{ {
System.out.println("Initiator: " + war.getClanA()); System.out.println("Initiator: " + war.getClanA());
System.out.println("Other Clan: " + war.getClanB()); System.out.println("Other Clan: " + war.getClanB());
System.out.println("Score: " + war.getPoints(clan)); System.out.println("Score: " + war.getPoints(clan.getName()));
UtilPlayer.message(caller, F.main("War", "War Status with " + searchName)); UtilPlayer.message(caller, F.main("War", "War Status with " + searchName));
UtilPlayer.message(caller, F.main("War", "Initiated by: " + (war.getClanA().equals(clan.getName()) ? selfName : searchName))); UtilPlayer.message(caller, F.main("War", "Initiated by: " + (war.getClanA().equals(clan.getName()) ? selfName : searchName)));
UtilPlayer.message(caller, F.main("War", "War Points: " + clan.getFormattedWarPoints(search))); UtilPlayer.message(caller, F.main("War", "War Points: " + clan.getFormattedWarPoints(search)));

View File

@ -3,7 +3,7 @@ package mineplex.game.clans.clans.war.event;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import mineplex.game.clans.clans.war.ClanWarData; import mineplex.game.clans.core.war.ClanWarData;
public class WarEndEvent extends Event public class WarEndEvent extends Event
{ {

View File

@ -3,7 +3,7 @@ package mineplex.game.clans.clans.war.event;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import mineplex.game.clans.clans.war.ClanWarData; import mineplex.game.clans.core.war.ClanWarData;
public class WarStartEvent extends Event public class WarStartEvent extends Event
{ {