Reworked spawn to save to database.

Work on Clans:
Fixed clan loading/updating/adding.
Refactored some code for Clans.
This commit is contained in:
Jonathan Williams 2014-11-29 03:16:37 -08:00
parent 4b2998793c
commit f507db7664
16 changed files with 182 additions and 309 deletions

View File

@ -80,10 +80,10 @@ public abstract class RepositoryBase implements Listener
protected int executeUpdate(String query, Column<?>...columns)
{
return executeUpdate(query, null, columns);
return executeInsert(query, null, columns);
}
protected int executeUpdate(String query, ResultSetCallable callable, Column<?>...columns)
protected int executeInsert(String query, ResultSetCallable callable, Column<?>...columns)
{
PreparedStatement preparedStatement = null;

View File

@ -1,14 +1,7 @@
package mineplex.core.spawn;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.F;
@ -26,13 +19,20 @@ import org.bukkit.plugin.java.JavaPlugin;
public class Spawn extends MiniPlugin
{
public ArrayList<Location> spawnList;
private SpawnRepository _repository;
private List<Location> _spawns = new ArrayList<Location>();
public Spawn(JavaPlugin plugin)
public Spawn(JavaPlugin plugin, String serverName)
{
super("Spawn", plugin);
_repository = new SpawnRepository(plugin, serverName);
ReadSpawns();
for (String spawn : _repository.retrieveSpawns())
{
_spawns.add(UtilWorld.strToLoc(spawn));
}
}
@Override
@ -43,26 +43,32 @@ public class Spawn extends MiniPlugin
public Location getSpawn()
{
if (spawnList.isEmpty())
if (_spawns.isEmpty())
return UtilServer.getServer().getWorld("world").getSpawnLocation();
return spawnList.get(UtilMath.r(spawnList.size()));
return _spawns.get(UtilMath.r(_spawns.size()));
}
public void AddSpawn(Player player)
{
//Set Spawn Point
Location loc = player.getLocation();
final Location loc = player.getLocation();
//Set World Spawn
player.getWorld().setSpawnLocation((int)loc.getX(), (int)loc.getY(), (int)loc.getZ());
//Add Spawn
spawnList.add(loc);
_spawns.add(loc);
//Save
WriteSpawns();
runAsync(new Runnable()
{
public void run()
{
_repository.addSpawn(UtilWorld.locToStr(loc));
}
});
//Inform
UtilPlayer.message(player, F.main(_moduleName, "You added a Spawn Node."));
@ -73,10 +79,16 @@ public class Spawn extends MiniPlugin
public void ClearSpawn(Player player)
{
//Add Spawn
spawnList.clear();
_spawns.clear();
//Save
WriteSpawns();
runAsync(new Runnable()
{
public void run()
{
_repository.clearSpawns();
}
});
//Inform
UtilPlayer.message(player, F.main(_moduleName, "You cleared all Spawn Nodes."));
@ -90,132 +102,4 @@ public class Spawn extends MiniPlugin
{
event.setRespawnLocation(getSpawn());
}
private void ReadSpawns()
{
spawnList = new ArrayList<Location>();
FileInputStream fstream = null;
DataInputStream in = null;
BufferedReader br = null;
if (!new File("data/spawns.dat").exists())
return;
try
{
fstream = new FileInputStream("data/spawns.dat");
in = new DataInputStream(fstream);
br = new BufferedReader(new InputStreamReader(in));
String strLine = br.readLine();
while (strLine != null)
{
System.out.println(strLine);
try
{
Location spawn = UtilWorld.strToLoc(strLine);
spawnList.add(spawn);
}
catch (Exception e)
{
}
strLine = br.readLine();
}
}
catch (Exception e)
{
System.err.println("Spawn Read Error: " + e.getMessage());
e.printStackTrace();
}
finally
{
if (br != null)
{
try
{
br.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
if (in != null)
{
try
{
in.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
if (fstream != null)
{
try
{
fstream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
private void WriteSpawns()
{
FileWriter fstream = null;
BufferedWriter out = null;
try
{
fstream = new FileWriter("data/spawns.dat");
out = new BufferedWriter(fstream);
for (Location loc : spawnList)
{
out.write(UtilWorld.locToStr(loc) + "\n");
}
out.close();
}
catch (Exception e)
{
System.err.println("Spawn Write Error: " + e.getMessage());
}
finally
{
if (out != null)
{
try
{
out.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
if (fstream != null)
{
try
{
fstream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
}

View File

@ -3,20 +3,24 @@ package mineplex.core.spawn.command;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.command.MultiCommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.spawn.Spawn;
public class SpawnCommand extends CommandBase<Spawn>
public class SpawnCommand extends MultiCommandBase<Spawn>
{
public SpawnCommand(Spawn plugin)
{
super(plugin, Rank.ADMIN, "spawn");
AddCommand(new AddCommand(plugin));
AddCommand(new ClearCommand(plugin));
}
@Override
public void Execute(Player caller, String[] args)
public void Help(Player caller, String[] args)
{
UtilPlayer.message(caller, F.main("Spawn", "Commands List:"));
UtilPlayer.message(caller, F.help("/spawn add", "Add Location as Spawn", Rank.ADMIN));

View File

@ -3,12 +3,10 @@ package mineplex.core.teleport;
import java.util.LinkedList;
import mineplex.core.MiniPlugin;
import mineplex.core.spawn.Spawn;
import mineplex.core.teleport.command.TeleportCommand;
import mineplex.core.teleport.event.MineplexTeleportEvent;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.account.CoreClientManager;
import mineplex.core.account.event.ClientUnloadEvent;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
@ -24,17 +22,12 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
public class Teleport extends MiniPlugin
{
private Spawn _spawn;
private LinkedList<Teleporter> teleportList = new LinkedList<Teleporter>();
private NautHashMap<String, LinkedList<Location>> _tpHistory = new NautHashMap<String, LinkedList<Location>>();
public Teleport(JavaPlugin plugin, CoreClientManager clientManager, Spawn spawn)
public Teleport(JavaPlugin plugin)
{
super("Teleport", plugin);
_spawn = spawn;
}
@Override
@ -175,18 +168,6 @@ public class Teleport extends MiniPlugin
return;
}
}
public void playerToSpawn(Player caller, String target)
{
Player player = UtilPlayer.searchOnline(caller, target, true);
if (player == null)
return;
String mA = F.main("Teleport", F.elem(caller.getName()) + " teleported you to " + F.elem("Spawn") + ".");
String mB = F.main("Teleport", "You teleported " + F.count(player.getName()) + " to " + F.elem("Spawn") + ".");
Add(player, _spawn.getSpawn(), mA, true, caller, mB, player.getName() + " teleported to Spawn via " + caller.getName() + ".");
}
public void Add(Player pA, Location loc, String mA, boolean record, Player pB, String mB, String log)
{

View File

@ -1,24 +0,0 @@
package mineplex.core.teleport.command;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.teleport.Teleport;
public class SpawnCommand extends CommandBase<Teleport>
{
public SpawnCommand(Teleport plugin)
{
super(plugin, Rank.ADMIN, "spawn", "s");
}
@Override
public void Execute(Player caller, String[] args)
{
if (args.length == 0)
Plugin.playerToSpawn(caller, caller.getName());
else
Plugin.playerToSpawn(caller, args[0]);
}
}

View File

@ -17,7 +17,6 @@ public class TeleportCommand extends MultiCommandBase<Teleport>
AddCommand(new AllCommand(plugin));
AddCommand(new BackCommand(plugin));
AddCommand(new HereCommand(plugin));
AddCommand(new SpawnCommand(plugin));
}
@Override
@ -50,7 +49,6 @@ public class TeleportCommand extends MultiCommandBase<Teleport>
UtilPlayer.message(caller, F.help("/tp here <player>", "Teleport Player to Self", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/tp <player> <target>", "Teleport Player to Player", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/tp <X> <Y> <Z>", "Teleport to Location", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/tp spawn", "Teleport to Spawn", Rank.ADMIN));
UtilPlayer.message(caller, F.help("/tp all", "Teleport All to Self", Rank.OWNER));
}
}

View File

@ -78,10 +78,10 @@ public class Clans extends JavaPlugin
PreferencesManager preferenceManager = new PreferencesManager(this, _clientManager, _donationManager);
new MessageManager(this, _clientManager, preferenceManager);
Creature creature = new Creature(this);
Spawn spawn = new Spawn(this);
Teleport teleport = new Teleport(this, _clientManager, spawn);
Creature creature = new Creature(this);
ServerStatusManager serverStatusManager = new ServerStatusManager(this, new LagMeter(this, _clientManager));
new Spawn(this, serverStatusManager.getCurrentServerName());
Teleport teleport = new Teleport(this);
Portal portal = new Portal(this, serverStatusManager.getCurrentServerName());
new FileUpdater(this, portal);
PacketHandler packetHandler = new PacketHandler(this);
@ -112,7 +112,7 @@ public class Clans extends JavaPlugin
new FriendManager(this, _clientManager, preferenceManager);
new ClansManager(this, "CLANS-1", _clientManager, combatManager, blockRestore, teleport, new ConditionManager(this));
new ClansManager(this, serverStatusManager.getCurrentServerName(), _clientManager, combatManager, blockRestore, teleport, new ConditionManager(this));
//Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);

View File

@ -12,6 +12,9 @@ import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.repository.tokens.ClanAllianceToken;
import mineplex.game.clans.clans.repository.tokens.ClanMemberToken;
import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken;
import mineplex.game.clans.clans.repository.tokens.ClanToken;
import org.bukkit.Location;
@ -81,6 +84,21 @@ public class ClanInfo
_dateCreated = token.DateCreated;
_lastOnline = token.LastOnline;
for (ClanMemberToken memberToken : token.Members)
{
_memberMap.put(memberToken.Name, Role.valueOf(memberToken.ClanRole));
}
for (ClanTerritoryToken territoryToken : token.Territories)
{
_claimSet.add(territoryToken.Chunk);
}
for (ClanAllianceToken allianceToken : token.Alliances)
{
_allyMap.put(allianceToken.ClanName, allianceToken.Trusted);
}
}
public int getClaims()
@ -403,4 +421,9 @@ public class ClanInfo
{
return _id;
}
public void setId(int id)
{
_id = id;
}
}

View File

@ -61,17 +61,12 @@ public class ClansDataAccessLayer
token.Home = "";
token.Admin = admin;
token.Members = new ArrayList<ClanMemberToken>();
ClanMemberToken memberToken = new ClanMemberToken();
memberToken.ClanRole = Role.ADMIN.toString();
memberToken.Name = creator;
//Create Clan
ClanInfo clan = new ClanInfo(_manager, token);
_manager.getClanMap().put(name, clan);
//Save
_repository.addClan(token);
_repository.addClan(clan, token);
//Log
_manager.log("[" + clan.getName() + "] with Admin [" + admin + "] created by [" + creator + "].");
@ -292,4 +287,9 @@ public class ClansDataAccessLayer
//Log
_manager.log("Safe Zone at [" + claim.Chunk + "] set to [" + claim.Safe + "] by [" + player + "].");
}
public ClanRepository getRepository()
{
return _repository;
}
}

View File

@ -2,12 +2,15 @@ package mineplex.game.clans.clans;
import java.util.LinkedList;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.repository.ClanTerritory;
@ -15,17 +18,31 @@ import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World.Environment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class ClansDisplay
public class ClansDisplay extends MiniPlugin
{
private ClansManager Clans;
public ClansDisplay(ClansManager clans)
public ClansDisplay(JavaPlugin plugin, ClansManager clans)
{
super("Clans Display", plugin);
Clans = clans;
}
@EventHandler
public void Update(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTER)
return;
for (Player cur : UtilServer.getPlayers())
Update(cur);
}
public void Update(Player player)
{
if (player.getWorld().getEnvironment() != Environment.NORMAL)

View File

@ -8,6 +8,8 @@ import org.bukkit.World.Environment;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
@ -17,13 +19,13 @@ import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import mineplex.core.MiniPlugin;
import mineplex.core.blockrestore.BlockRestoreData;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
@ -34,32 +36,31 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo.Role;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
public class ClansGame
public class ClansGame extends MiniPlugin
{
private ClansManager Clans;
public ClansGame(ClansManager clans)
public ClansGame(JavaPlugin plugin, ClansManager clans)
{
super("Clans Game", plugin);
Clans = clans;
}
}
//Player Chunk Display
public void UpdateDisplay()
{
for (Player cur : UtilServer.getPlayers())
Clans.getClanDisplay().Update(cur);
}
public void UpdateSafe()
@EventHandler
public void Update(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
for (Player cur : UtilServer.getPlayers())
if (Clans.getClanUtility().isSafe(cur.getLocation()))
{
ClanInfo clan = Clans.getClanUtility().getClanByPlayer(cur);
long lastDamager = Clans.getCombatManager().Get(cur).GetLastCombat();
if (!UtilTime.elapsed(lastDamager, 15000))
@ -72,7 +73,8 @@ public class ClansGame
}
}
public void SafeSkill(SkillTriggerEvent event)
@EventHandler(priority = EventPriority.LOW)
public void SkillTrigger(SkillTriggerEvent event)
{
if (!Clans.getClanUtility().isSafe(event.GetPlayer()))
return;
@ -82,12 +84,14 @@ public class ClansGame
event.SetCancelled(true);
}
@EventHandler(priority = EventPriority.LOW)
public void BlockBurn(BlockBurnEvent event)
{
if (Clans.getClanUtility().isBorderlands(event.getBlock().getLocation()))
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOW)
public void BlockSpread(BlockIgniteEvent event)
{
if (event.getCause() == IgniteCause.SPREAD)
@ -95,9 +99,12 @@ public class ClansGame
event.setCancelled(true);
}
//Block Place (After Interact)
@EventHandler(priority = EventPriority.LOW)
public void BlockPlace(BlockPlaceEvent event)
{
if (event.isCancelled())
return;
if (event.getBlock().getType() != Material.LADDER)
return;
@ -194,8 +201,12 @@ public class ClansGame
"."));
}
@EventHandler(priority = EventPriority.LOWEST)
public void Damage(CustomDamageEvent event)
{
if (event.IsCancelled())
return;
Player damagee = event.GetDamageePlayer();
if (damagee == null) return;
@ -400,6 +411,7 @@ public class ClansGame
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void Piston(BlockPistonExtendEvent event)
{
ClanInfo pistonClan = Clans.getClanUtility().getOwner(event.getBlock().getLocation());
@ -438,6 +450,7 @@ public class ClansGame
}
}
@EventHandler
public void Quit(PlayerQuitEvent event)
{
ClanInfo clan = Clans.getClanUtility().getClanByPlayer(event.getPlayer());
@ -446,7 +459,8 @@ public class ClansGame
clan.setLastOnline(System.currentTimeMillis());
}
public void Explode(EntityExplodeEvent event)
@EventHandler(priority = EventPriority.LOWEST)
public void Explosion(EntityExplodeEvent event)
{
try
{

View File

@ -27,6 +27,9 @@ import mineplex.game.clans.clans.commands.ClansAllyChatCommand;
import mineplex.game.clans.clans.commands.ClansChatCommand;
import mineplex.game.clans.clans.commands.ClansCommand;
import mineplex.game.clans.clans.repository.ClanTerritory;
import mineplex.game.clans.clans.repository.tokens.ClanMemberToken;
import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken;
import mineplex.game.clans.clans.repository.tokens.ClanToken;
import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent;
import mineplex.minecraft.game.core.combat.CombatManager;
import mineplex.minecraft.game.core.condition.ConditionManager;
@ -78,9 +81,28 @@ public class ClansManager extends MiniClientPlugin<ClientClan>
_clanAdmin = new ClansAdmin(this);
_clanBlocks = new ClansBlocks();
_clanDataAccess = new ClansDataAccessLayer(this);
_clanDisplay = new ClansDisplay(this);
_clanGame = new ClansGame(this);
_clanDisplay = new ClansDisplay(plugin, this);
_clanGame = new ClansGame(plugin, this);
_clanUtility = new ClansUtility(this);
for (ClanToken token : _clanDataAccess.getRepository().retrieveClans())
{
ClanInfo clan = new ClanInfo(this, token);
System.out.println("Found clan : " + token.Name);
_clanMap.put(token.Name, clan);
for (ClanMemberToken memberToken : token.Members)
{
System.out.println("Found member : " + memberToken.Name);
_clanMemberMap.put(memberToken.Name, clan);
}
for (ClanTerritoryToken territoryToken : token.Territories)
{
System.out.println("Found territory : " + territoryToken.Chunk + " owned by " + territoryToken.ClanName);
_claimMap.put(territoryToken.Chunk, new ClanTerritory(territoryToken));
}
}
}
@Override
@ -116,39 +138,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan>
return _claimMap;
}
@EventHandler
public void Update(UpdateEvent event)
{
if (event.getType() == UpdateType.FAST)
getClanGame().UpdateSafe();
if (event.getType() == UpdateType.FASTER)
getClanGame().UpdateDisplay();
}
public long lastPower = System.currentTimeMillis();
@EventHandler(priority = EventPriority.LOW)
public void BlockBurn(BlockBurnEvent event)
{
getClanGame().BlockBurn(event);
}
@EventHandler(priority = EventPriority.LOW)
public void BlockIgnite(BlockIgniteEvent event)
{
getClanGame().BlockSpread(event);
}
@EventHandler(priority = EventPriority.LOW)
public void BlockPlace(BlockPlaceEvent event)
{
if (event.isCancelled())
return;
getClanGame().BlockPlace(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void BlockCreatureSpawn(CreatureSpawnCustomEvent event)
{
@ -158,15 +149,6 @@ public class ClansManager extends MiniClientPlugin<ClientClan>
if (!clan.isAdmin() && !clan.getName().equals("Spawn"))
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOWEST)
public void Damage(CustomDamageEvent event)
{
if (event.IsCancelled())
return;
getClanGame().Damage(event);
}
@EventHandler(priority = EventPriority.LOWEST)
public void Interact(PlayerInteractEvent event)
@ -174,31 +156,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>
getClanGame().Interact(event);
getClanDisplay().handleInteract(event);
}
@EventHandler(priority = EventPriority.LOWEST)
public void Piston(BlockPistonExtendEvent event)
{
getClanGame().Piston(event);
}
@EventHandler(priority = EventPriority.LOW)
public void SkillTrigger(SkillTriggerEvent event)
{
getClanGame().SafeSkill(event);
}
@EventHandler
public void Quit(PlayerQuitEvent event)
{
getClanGame().Quit(event);
}
@EventHandler(priority = EventPriority.LOWEST)
public void Explosion(EntityExplodeEvent event)
{
getClanGame().Explode(event);
}
@EventHandler
public void HandleClanChat(AsyncPlayerChatEvent event)
{

View File

@ -13,6 +13,7 @@ import mineplex.core.database.column.ColumnBoolean;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnLong;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.repository.tokens.ClanAllianceToken;
import mineplex.game.clans.clans.repository.tokens.ClanMemberToken;
import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken;
@ -20,14 +21,14 @@ import mineplex.game.clans.clans.repository.tokens.ClanToken;
public class ClanRepository extends RepositoryBase
{
private static String CREATE_CLAN_TABLE = "CREATE TABLE IF NOT EXISTS clans (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100), description VARCHAR(140), home VARCHAR(140), admin BOOL, dateCreated LONG, lastOnline LONG, 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 BOOL, dateCreated LONG, lastOnline LONG, 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_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_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 RETRIEVE_START_CLAN_INFO = "SELECT id, name, description, home, admin, dateCreated, lastOnline, ct.chunk, ct.safe FROM clans AS c INNER JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE serverName = ?;";
private static String RETRIEVE_CLAN_MEMBER_INFO = "SELECT c.name, a.name, role FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId INNER JOIN clans AS c on c.id = ac.clanId;";
private static String RETRIEVE_CLAN_ALLIANCE_INFO = "SELECT c.name, cOther.name, ca.trusted FROM clanAlliances AS ca INNER JOIN clans AS c ON c.id = ca.clanId INNER JOIN clans as cOther ON cOther.id = ca.otherClanId;";
private static String RETRIEVE_START_CLAN_INFO = "SELECT c.id, c.name, c.description, c.home, c.admin, 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, 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;";
private static String RETRIEVE_CLAN_ALLIANCE_INFO = "SELECT c.name, cOther.name, ca.trusted FROM clanAlliances AS ca INNER JOIN clans AS c ON c.id = ca.clanId INNER JOIN clans as cOther ON cOther.id = ca.otherClanId WHERE c.serverName = ?;";
private static String DELETE_CLAN_MEMBER = "DELETE FROM accountClan INNER JOIN accounts ON accounts.id = accountClan.accountId WHERE clans.id = ? AND accounts.name = ?;";
private static String DELETE_CLAN_MEMBERS = "DELETE FROM accountClan INNER JOIN clans ON clans.id = accountClan.clanId WHERE clans.name = ?;";
@ -37,12 +38,12 @@ public class ClanRepository extends RepositoryBase
private static String DELETE_CLAN_ALLIANCES = "DELETE FROM clanAlliances INNER JOIN clans ON clans.id = clanAlliances.clanId WHERE clans.name = ?;";
private static String DELETE_CLAN = "DELETE FROM clans WHERE name = ?;";
private static String ADD_CLAN = "INSERT INTO clans (name, description, home, admin, dateCreated, lastOnline) VALUES (?, ?, ?, ?, now(), now());";
private static String ADD_CLAN = "INSERT INTO clans (serverName, name, description, home, admin, dateCreated, lastOnline) VALUES (?, ?, ?, ?, ?, now(), now());";
private static String ADD_CLAN_MEMBER = "INSERT INTO accountClan (accountId, clanId, clanRole) SELECT accounts.id, ?, ? FROM accounts WHERE accounts.name = ?;";
private static String ADD_CLAN_ALLIANCE = "INSERT INTO clanAlliances (clandId, otherClanId, trusted) VALUES (?, ?, ?);";
private static String ADD_CLAN_TERRITORY = "INSERT INTO clanTerritory (clanId, serverName, chunk, safe) VALUES (?, ?, ?, ?);";
private static String UPDATE_CLAN = "UPDATE clans SET name = ?, desc = ?, home = ?, admin = ?, lastOnline = ? WHERE id = ?;";
private static String UPDATE_CLAN = "UPDATE clans SET name = ?, description = ?, home = ?, admin = ?, lastOnline = ? WHERE id = ?;";
private static String UPDATE_CLAN_MEMBER = "UPDATE AC SET clanRole = ? FROM accountClan AS AC INNER JOIN accounts ON accounts.id = accountClan.accountId WHERE clans.id = ? 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 serverName = ? AND chunk = ?;";
@ -69,6 +70,8 @@ public class ClanRepository extends RepositoryBase
{
final NautHashMap<String, ClanToken> clans = new NautHashMap<String, ClanToken>();
System.out.println("Running retrieveClans");
executeQuery(RETRIEVE_START_CLAN_INFO, new ResultSetCallable()
{
@Override
@ -86,6 +89,7 @@ public class ClanRepository extends RepositoryBase
token.LastOnline = resultSet.getLong(7);
ClanTerritoryToken territoryToken = new ClanTerritoryToken();
territoryToken.ClanName = token.Name;
territoryToken.Chunk = resultSet.getString(8);
territoryToken.Safe = resultSet.getBoolean(9);
@ -94,7 +98,10 @@ public class ClanRepository extends RepositoryBase
clans.put(token.Name, token);
}
clans.get(token.Name).Territories.add(territoryToken);
if (territoryToken.Chunk != null)
clans.get(token.Name).Territories.add(territoryToken);
System.out.println("DB clan : "+ token.Name);
}
}
@ -160,20 +167,20 @@ public class ClanRepository extends RepositoryBase
executeUpdate(DELETE_CLAN, new ColumnVarChar("name", 100, name));
}
public void addClan(final ClanToken token)
public void addClan(final ClanInfo clan, final ClanToken token)
{
executeUpdate(ADD_CLAN, new ResultSetCallable()
executeInsert(ADD_CLAN, new ResultSetCallable()
{
@Override
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
executeUpdate(ADD_CLAN_MEMBER, new ColumnInt("clanid", resultSet.getInt(1)), new ColumnVarChar("clanRole", 100, token.Members.get(0).ClanRole), new ColumnVarChar("name", 100, token.Members.get(0).Name));
clan.setId(resultSet.getInt(1));
}
}
}, new ColumnVarChar("name", 100, token.Name), new ColumnVarChar("description", 100, token.Description), new ColumnVarChar("home", 100, token.Home), new ColumnBoolean("admin", token.Admin));
}, new ColumnVarChar("serverName", 100, _serverName), new ColumnVarChar("name", 100, token.Name), new ColumnVarChar("description", 100, token.Description), new ColumnVarChar("home", 100, token.Home), new ColumnBoolean("admin", token.Admin));
}

View File

@ -1,8 +1,19 @@
package mineplex.game.clans.clans.repository;
import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken;
public class ClanTerritory
{
public ClanTerritory() { }
public ClanTerritory(ClanTerritoryToken territoryToken)
{
Owner = territoryToken.ClanName;
Safe = territoryToken.Safe;
Chunk = territoryToken.Chunk;
}
public boolean Safe;
public String Owner;
public String Chunk;
public String Owner = "";
public String Chunk = "";
}

View File

@ -120,7 +120,7 @@ public class Hub extends JavaPlugin implements IRelation
DamageManager damage = new DamageManager(this, combatManager, npcManager, disguiseManager);
Fire fire = new Fire(this, conditionManager, damage);
Teleport teleport = new Teleport(this, clientManager, new Spawn(this));
Teleport teleport = new Teleport(this);
Energy energy = new Energy(this);
energy.setEnabled(false);

View File

@ -90,9 +90,9 @@ public class Arcade extends JavaPlugin
new MessageManager(this, _clientManager, preferenceManager);
Creature creature = new Creature(this);
Spawn spawn = new Spawn(this);
Teleport teleport = new Teleport(this, _clientManager, spawn);
ServerStatusManager serverStatusManager = new ServerStatusManager(this, new LagMeter(this, _clientManager));
new Spawn(this, serverStatusManager.getCurrentServerName());
Teleport teleport = new Teleport(this);
Portal portal = new Portal(this, serverStatusManager.getCurrentServerName());
new FileUpdater(this, portal);
PacketHandler packetHandler = new PacketHandler(this);