Clans database refactoring
This commit is contained in:
parent
aebe390c3c
commit
6a368454ec
@ -13,5 +13,7 @@
|
|||||||
<orderEntry type="module" module-name="Mineplex.Minecraft.Game.Core" />
|
<orderEntry type="module" module-name="Mineplex.Minecraft.Game.Core" />
|
||||||
<orderEntry type="module" module-name="Mineplex.ServerData" />
|
<orderEntry type="module" module-name="Mineplex.ServerData" />
|
||||||
<orderEntry type="library" name="craftbukkit" level="project" />
|
<orderEntry type="library" name="craftbukkit" level="project" />
|
||||||
|
<orderEntry type="module" module-name="Mineplex.Database" />
|
||||||
|
<orderEntry type="library" name="jooq" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
@ -1,5 +1,6 @@
|
|||||||
package mineplex.game.clans.clans;
|
package mineplex.game.clans.clans;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -35,8 +36,8 @@ public class ClanInfo
|
|||||||
|
|
||||||
private boolean _admin = false;
|
private boolean _admin = false;
|
||||||
|
|
||||||
private long _dateCreated = 0;
|
private Timestamp _dateCreated = null;
|
||||||
private long _lastOnline = 0;
|
private Timestamp _lastOnline = null;
|
||||||
|
|
||||||
// Loaded from Client
|
// Loaded from Client
|
||||||
private NautHashMap<String, ClanRole> _memberMap = new NautHashMap<String, ClanRole>();
|
private NautHashMap<String, ClanRole> _memberMap = new NautHashMap<String, ClanRole>();
|
||||||
@ -193,7 +194,7 @@ public class ClanInfo
|
|||||||
|
|
||||||
// Age
|
// Age
|
||||||
stringList.add(F.value("Age",
|
stringList.add(F.value("Age",
|
||||||
UtilTime.convertString(System.currentTimeMillis() - _dateCreated, 1, TimeUnit.FIT)));
|
UtilTime.convertString(System.currentTimeMillis() - _dateCreated.getTime(), 1, TimeUnit.FIT)));
|
||||||
|
|
||||||
// Home
|
// Home
|
||||||
if (Clans.getClanUtility().relPC(caller, this) == ClanRelation.SELF)
|
if (Clans.getClanUtility().relPC(caller, this) == ClanRelation.SELF)
|
||||||
@ -371,17 +372,17 @@ public class ClanInfo
|
|||||||
return _requestMap;
|
return _requestMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getDateCreated()
|
public Timestamp getDateCreated()
|
||||||
{
|
{
|
||||||
return _dateCreated;
|
return _dateCreated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastOnline()
|
public Timestamp getLastOnline()
|
||||||
{
|
{
|
||||||
return _lastOnline;
|
return _lastOnline;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastOnline(long lastOnline)
|
public void setLastOnline(Timestamp lastOnline)
|
||||||
{
|
{
|
||||||
_lastOnline = lastOnline;
|
_lastOnline = lastOnline;
|
||||||
}
|
}
|
||||||
@ -401,7 +402,7 @@ public class ClanInfo
|
|||||||
if (UtilPlayer.isOnline(cur))
|
if (UtilPlayer.isOnline(cur))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return System.currentTimeMillis() - _lastOnline < Clans.getOnlineTime();
|
return System.currentTimeMillis() - _lastOnline.getTime() < Clans.getOnlineTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProtected()
|
public String getProtected()
|
||||||
@ -410,12 +411,12 @@ public class ClanInfo
|
|||||||
if (UtilPlayer.isOnline(cur))
|
if (UtilPlayer.isOnline(cur))
|
||||||
return C.cRed + "No - Clan Members are Online";
|
return C.cRed + "No - Clan Members are Online";
|
||||||
|
|
||||||
if (System.currentTimeMillis() - _lastOnline > Clans.getOnlineTime())
|
if (System.currentTimeMillis() - _lastOnline.getTime() > Clans.getOnlineTime())
|
||||||
return C.cGreen + "Yes - Clan Members are Offline";
|
return C.cGreen + "Yes - Clan Members are Offline";
|
||||||
|
|
||||||
return C.cGold
|
return C.cGold
|
||||||
+ "No, "
|
+ "No, "
|
||||||
+ UtilTime.convertString(Clans.getOnlineTime() - (System.currentTimeMillis() - _lastOnline), 1,
|
+ UtilTime.convertString(Clans.getOnlineTime() - (System.currentTimeMillis() - _lastOnline.getTime()), 1,
|
||||||
TimeUnit.FIT) + " to Protection";
|
TimeUnit.FIT) + " to Protection";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package mineplex.game.clans.clans;
|
package mineplex.game.clans.clans;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
@ -157,7 +158,7 @@ public class ClansDataAccessLayer
|
|||||||
public void enemy(ClanInfo clan, ClanInfo otherClan, String player)
|
public void enemy(ClanInfo clan, ClanInfo otherClan, String player)
|
||||||
{
|
{
|
||||||
_repository.addEnemy(clan.getId(), otherClan.getId());
|
_repository.addEnemy(clan.getId(), otherClan.getId());
|
||||||
Date currDate = new Date();
|
Timestamp currDate = new Timestamp(System.currentTimeMillis());
|
||||||
|
|
||||||
ClanEnemyToken clanEnemyToken = new ClanEnemyToken();
|
ClanEnemyToken clanEnemyToken = new ClanEnemyToken();
|
||||||
clanEnemyToken.Initiator = true;
|
clanEnemyToken.Initiator = true;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package mineplex.game.clans.clans;
|
package mineplex.game.clans.clans;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -516,7 +518,7 @@ public class ClansGame extends MiniPlugin
|
|||||||
ClanInfo clan = Clans.getClanUtility().getClanByPlayer(event.getPlayer());
|
ClanInfo clan = Clans.getClanUtility().getClanByPlayer(event.getPlayer());
|
||||||
if (clan == null) return;
|
if (clan == null) return;
|
||||||
|
|
||||||
clan.setLastOnline(System.currentTimeMillis());
|
clan.setLastOnline(new Timestamp(System.currentTimeMillis()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
@ -2,8 +2,8 @@ package mineplex.game.clans.clans.repository;
|
|||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -13,7 +13,7 @@ import mineplex.core.database.RepositoryBase;
|
|||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnBoolean;
|
import mineplex.core.database.column.ColumnBoolean;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
import mineplex.core.database.column.ColumnLong;
|
import mineplex.core.database.column.ColumnTimestamp;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
import mineplex.core.database.column.ColumnVarChar;
|
||||||
import mineplex.game.clans.clans.ClanInfo;
|
import mineplex.game.clans.clans.ClanInfo;
|
||||||
import mineplex.game.clans.clans.repository.tokens.ClanAllianceToken;
|
import mineplex.game.clans.clans.repository.tokens.ClanAllianceToken;
|
||||||
@ -24,10 +24,10 @@ import mineplex.game.clans.clans.repository.tokens.ClanToken;
|
|||||||
|
|
||||||
public class ClanRepository extends RepositoryBase
|
public class ClanRepository extends RepositoryBase
|
||||||
{
|
{
|
||||||
private static String CREATE_CLAN_TABLE = "CREATE TABLE IF NOT EXISTS clans (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(100), name VARCHAR(100), description VARCHAR(140), home VARCHAR(140), admin BOOL, dateCreated LONG, lastOnline LONG, energy INT, PRIMARY KEY (id), INDEX clanName (name));";
|
private static String CREATE_CLAN_TABLE = "CREATE TABLE IF NOT EXISTS clans (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(100), name VARCHAR(100), description VARCHAR(140), home VARCHAR(140), admin BIT(1), dateCreated DATETIME, lastOnline DATETIME, energy INT, PRIMARY KEY (id), INDEX clanName (name));";
|
||||||
private static String CREATE_ACCOUNT_CLAN_TABLE = "CREATE TABLE IF NOT EXISTS accountClan (id INT NOT NULL AUTO_INCREMENT, accountId INT, clanId INT, clanRole VARCHAR(140), PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId));";
|
private static String CREATE_ACCOUNT_CLAN_TABLE = "CREATE TABLE IF NOT EXISTS accountClan (id INT NOT NULL AUTO_INCREMENT, accountId INT, clanId INT, clanRole VARCHAR(140), PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId));";
|
||||||
private static String CREATE_CLAN_TERRITORY_TABLE = "CREATE TABLE IF NOT EXISTS clanTerritory (id INT NOT NULL AUTO_INCREMENT, clanId INT, serverName VARCHAR(100), chunk VARCHAR(100), safe BOOL, PRIMARY KEY (id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId, serverName));";
|
private static String CREATE_CLAN_TERRITORY_TABLE = "CREATE TABLE IF NOT EXISTS clanTerritory (id INT NOT NULL AUTO_INCREMENT, clanId INT, serverName VARCHAR(100), chunk VARCHAR(100), safe BIT(1), PRIMARY KEY (id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId, serverName));";
|
||||||
private static String CREATE_CLAN_ALLIANCE_TABLE = "CREATE TABLE IF NOT EXISTS clanAlliances (id INT NOT NULL AUTO_INCREMENT, clanId INT, otherClanId INT, trusted BOOL, PRIMARY KEY (id), FOREIGN KEY (otherClanId) REFERENCES clans(id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId));";
|
private static String CREATE_CLAN_ALLIANCE_TABLE = "CREATE TABLE IF NOT EXISTS clanAlliances (id INT NOT NULL AUTO_INCREMENT, clanId INT, otherClanId INT, trusted BIT(1), PRIMARY KEY (id), FOREIGN KEY (otherClanId) REFERENCES clans(id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId));";
|
||||||
|
|
||||||
private static String RETRIEVE_START_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.dateCreated, c.lastOnline, ct.chunk, ct.safe FROM clans AS c LEFT JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE c.serverName = ?;";
|
private static String RETRIEVE_START_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, c.energy, c.dateCreated, c.lastOnline, ct.chunk, ct.safe FROM clans AS c LEFT JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE c.serverName = ?;";
|
||||||
private static String RETRIEVE_CLAN_MEMBER_INFO = "SELECT c.name, a.name, a.uuid, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE c.serverName = ?;";
|
private static String RETRIEVE_CLAN_MEMBER_INFO = "SELECT c.name, a.name, a.uuid, clanRole FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId WHERE c.serverName = ?;";
|
||||||
@ -91,8 +91,8 @@ public class ClanRepository extends RepositoryBase
|
|||||||
token.Home = resultSet.getString(4);
|
token.Home = resultSet.getString(4);
|
||||||
token.Admin = resultSet.getBoolean(5);
|
token.Admin = resultSet.getBoolean(5);
|
||||||
token.Energy = resultSet.getInt(6);
|
token.Energy = resultSet.getInt(6);
|
||||||
token.DateCreated = resultSet.getLong(7);
|
token.DateCreated = resultSet.getTimestamp(7);
|
||||||
token.LastOnline = resultSet.getLong(8);
|
token.LastOnline = resultSet.getTimestamp(8);
|
||||||
|
|
||||||
ClanTerritoryToken territoryToken = new ClanTerritoryToken();
|
ClanTerritoryToken territoryToken = new ClanTerritoryToken();
|
||||||
territoryToken.ClanName = token.Name;
|
territoryToken.ClanName = token.Name;
|
||||||
@ -173,7 +173,7 @@ public class ClanRepository extends RepositoryBase
|
|||||||
int otherClanScore = resultSet.getInt(4);
|
int otherClanScore = resultSet.getInt(4);
|
||||||
int clanKills = resultSet.getInt(5);
|
int clanKills = resultSet.getInt(5);
|
||||||
int otherClanKills = resultSet.getInt(6);
|
int otherClanKills = resultSet.getInt(6);
|
||||||
Date timeFormed = resultSet.getTimestamp(7);
|
Timestamp timeFormed = resultSet.getTimestamp(7);
|
||||||
|
|
||||||
clanToken.EnemyName = otherClanName;
|
clanToken.EnemyName = otherClanName;
|
||||||
clanToken.Score = clanScore;
|
clanToken.Score = clanScore;
|
||||||
@ -204,10 +204,6 @@ public class ClanRepository extends RepositoryBase
|
|||||||
|
|
||||||
public void deleteClan(int clanId)
|
public void deleteClan(int clanId)
|
||||||
{
|
{
|
||||||
executeUpdate(DELETE_CLAN_MEMBERS, new ColumnInt("clanid", clanId));
|
|
||||||
executeUpdate(DELETE_CLAN_TERRITORIES, new ColumnInt("clanid", clanId));
|
|
||||||
executeUpdate(DELETE_CLAN_ALLIANCES, new ColumnInt("clanid", clanId), new ColumnInt("clanid", clanId));
|
|
||||||
executeUpdate(DELETE_CLAN_ENEMY, new ColumnInt("clanid", clanId));
|
|
||||||
executeUpdate(DELETE_CLAN, new ColumnInt("clanid", clanId));
|
executeUpdate(DELETE_CLAN, new ColumnInt("clanid", clanId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,9 +269,9 @@ public class ClanRepository extends RepositoryBase
|
|||||||
executeUpdate(DELETE_CLAN_TERRITORY, new ColumnInt("clanId", clanId), new ColumnVarChar("serverName", 100, _serverName), new ColumnVarChar("chunk", 100, chunk));
|
executeUpdate(DELETE_CLAN_TERRITORY, new ColumnInt("clanId", clanId), new ColumnVarChar("serverName", 100, _serverName), new ColumnVarChar("chunk", 100, chunk));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateClan(int clanId, String name, String desc, String home, boolean admin, int energy, long lastOnline)
|
public void updateClan(int clanId, String name, String desc, String home, boolean admin, int energy, Timestamp lastOnline)
|
||||||
{
|
{
|
||||||
executeUpdate(UPDATE_CLAN, new ColumnVarChar("name", 100, name), new ColumnVarChar("desc", 100, desc), new ColumnVarChar("home", 100, home), new ColumnBoolean("admin", admin), new ColumnInt("energy", energy), new ColumnLong("lastOnline", lastOnline), new ColumnInt("clanId", clanId));
|
executeUpdate(UPDATE_CLAN, new ColumnVarChar("name", 100, name), new ColumnVarChar("desc", 100, desc), new ColumnVarChar("home", 100, home), new ColumnBoolean("admin", admin), new ColumnInt("energy", energy), new ColumnTimestamp("lastOnline", lastOnline), new ColumnInt("clanId", clanId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateEnemy(int clanId, int otherClanId, int clanScore, int otherClanScore, int clanKills, int otherClanKills)
|
public void updateEnemy(int clanId, int otherClanId, int clanScore, int otherClanScore, int clanKills, int otherClanKills)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package mineplex.game.clans.clans.repository.tokens;
|
package mineplex.game.clans.clans.repository.tokens;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
public class ClanEnemyToken
|
public class ClanEnemyToken
|
||||||
{
|
{
|
||||||
@ -8,5 +8,5 @@ public class ClanEnemyToken
|
|||||||
public String EnemyName;
|
public String EnemyName;
|
||||||
public int Score;
|
public int Score;
|
||||||
public int Kills;
|
public int Kills;
|
||||||
public Date TimeFormed;
|
public Timestamp TimeFormed;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package mineplex.game.clans.clans.repository.tokens;
|
package mineplex.game.clans.clans.repository.tokens;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -11,8 +12,8 @@ public class ClanToken
|
|||||||
public String Home;
|
public String Home;
|
||||||
public boolean Admin;
|
public boolean Admin;
|
||||||
public int Energy;
|
public int Energy;
|
||||||
public long DateCreated;
|
public Timestamp DateCreated;
|
||||||
public long LastOnline;
|
public Timestamp LastOnline;
|
||||||
|
|
||||||
public ClanEnemyToken EnemyToken;
|
public ClanEnemyToken EnemyToken;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user