More work on Clans.

This commit is contained in:
Jonathan Williams 2014-11-15 01:13:14 -08:00
parent 685a2899ca
commit df76f6be10
11 changed files with 1971 additions and 204 deletions

View File

@ -10,7 +10,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import me.chiss.Core.Clans.ClansClan;
import me.chiss.Core.Clans.ClanInfo;
import me.chiss.Core.Clans.ClansUtility.ClanRelation;
import me.chiss.Core.ClientData.ClientGame;
import me.chiss.Core.Module.AModule;
@ -263,7 +263,7 @@ public class PointManager extends AModule implements IScheduleListener
double petLevel = 0;
double clanAge = 0;
ClansClan clan = Clans().CUtil().getClanByPlayer(cur);
ClanInfo clan = Clans().CUtil().getClanByPlayer(cur);
if (clan != null) clanAge = (System.currentTimeMillis() - clan.GetDateCreated()) / 86400000d;
if (clanAge > 7)
clanAge = 7;
@ -341,7 +341,7 @@ public class PointManager extends AModule implements IScheduleListener
double petLevel = 0;
double clanAge = 0;
ClansClan clan = Clans().CUtil().getClanByPlayer(cur);
ClanInfo clan = Clans().CUtil().getClanByPlayer(cur);
if (clan != null) clanAge = (System.currentTimeMillis() - clan.GetDateCreated()) / 86400000d;
if (clanAge > 7)
clanAge = 7;

View File

@ -89,7 +89,7 @@ public abstract class MiniPlugin implements Listener
CommandCenter.Instance.RemoveCommand(command);
}
protected void log(String message)
public void log(String message)
{
System.out.println(F.main(_moduleName, message));
}

View File

@ -1,25 +1,20 @@
package mineplex.game.clans.clans;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import mineplex.core.account.CoreClient;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.game.clans.clans.repository.tokens.ClanAllianceToken;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
import mineplex.game.clans.clans.repository.tokens.ClanToken;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
@ -172,7 +167,7 @@ public class ClanInfo
{
LinkedList<String> stringList = new LinkedList<String>();
stringList.add(F.main("Clans", C.mRel(C.relPC(caller, this), getName() + " Information;", true)));
stringList.add(F.main("Clans", Clans.getClanUtility().mRel(Clans.getClanUtility().relPC(caller, this), getName() + " Information;", true)));
// stringList.add(F.value("Desc", _desc));
// Age
@ -180,7 +175,7 @@ public class ClanInfo
UtilTime.convertString(System.currentTimeMillis() - _dateCreated, 1, TimeUnit.FIT)));
// Home
if (C.relPC(caller, this) == ClanRelation.SELF)
if (Clans.getClanUtility().relPC(caller, this) == ClanRelation.SELF)
stringList.add(F.value("Home", UtilWorld.locToStrClean(getHome())));
// Land
@ -194,7 +189,7 @@ public class ClanInfo
allyUnsorted.add(allyName);
for (String cur : UtilAlg.sortKey(allyUnsorted))
allySorted += C.mRel(C.relPC(caller, Clans.getClanMap().get(cur)), cur, false)
allySorted += Clans.getClanUtility().mRel(Clans.getClanUtility().relPC(caller, Clans.getClanMap().get(cur)), cur, false)
+ ", ";
stringList.add(F.value("Allies", allySorted));
@ -224,12 +219,6 @@ public class ClanInfo
// Protected
stringList.add(F.value("TNT Protection", getProtected()));
// Dominance
ClanInfo callerClan = Clans.CUtil().getClanByPlayer(caller);
if (callerClan != null)
if (this.isEnemy(callerClan.getName()))
stringList.add(F.value("Dominance", callerClan.getDominanceString(this)));
return stringList;
}
@ -264,44 +253,6 @@ public class ClanInfo
}
}
public void chat(Player sender, String message, String filteredMessage)
{
for (String cur : getMembers().keySet())
{
Player player = UtilPlayer.searchOnline(null, cur, false);
if (player == null)
continue;
CoreClient client = Clans.Clients().Get(player);
if (client.Game().GetFilterChat())
UtilPlayer.message(player, C.cAqua + sender.getName() + C.cDAqua + " " + filteredMessage);
else
UtilPlayer.message(player, C.cAqua + sender.getName() + C.cDAqua + " " + message);
}
}
public void allyChat(ClanInfo senderClan, Player sender, String message, String filteredMessage)
{
for (String cur : getMembers().keySet())
{
Player player = UtilPlayer.searchOnline(null, cur, false);
if (player == null)
continue;
CoreClient client = Clans.Clients().Get(player);
// C.cDGreen + senderClan.GetName() + " " +
if (client.Game().GetFilterChat())
UtilPlayer.message(player, C.cDGreen + sender.getName() + C.cGreen + " " + filteredMessage);
else
UtilPlayer.message(player, C.cDGreen + sender.getName() + C.cGreen + " " + message);
}
}
public String getName()
{
return _name;
@ -382,73 +333,6 @@ public class ClanInfo
_lastOnline = lastOnline;
}
public void saveAlliances()
{
}
public void saveMembers()
{
}
public void saveTerritories()
{
}
public void saveBasicInfo()
{
}
public ClanToken GetToken()
{
// Update Members
_token.Members = new ArrayList<ClanMemberToken>();
for (String name : getMembers().keySet())
{
ClanMemberToken token = new ClanMemberToken();
token.Name = name;
token.ClanRole = getMembers().get(name).toString();
_token.Members.add(token);
}
// Update Territory
_token.Territories = new ArrayList<ClanTerritoryToken>();
for (String chunk : getClaimSet())
{
ClanTerritoryToken token = new ClanTerritoryToken();
token.ClanName = _token.Name;
token.ClanId = _token.ClanId;
token.ServerName = Clans.GetServerName();
token.Chunk = chunk;
if (Clans.GetClaimMap().get(chunk) != null)
token.Safe = Clans.GetClaimMap().get(chunk).safe;
_token.Territories.add(token);
}
// Update Relations
_token.Alliances = new ArrayList<AllianceToken>();
for (String clanName : getAllyMap().keySet())
{
ClanInfo clan = Clans.getClan(clanName);
ClanAllianceToken token = new ClanAllianceToken();
token.ClanId = clan.GetTokenUnupdated().ClanId;
token.ClanName = clan.GetTokenUnupdated().Name;
if (getAllyMap().get(clanName))
token.Trusted = true;
_token.Alliances.add(token);
}
return _token;
}
public boolean isOnlineNow()
{
for (String cur : getMembers().keySet())
@ -464,7 +348,7 @@ public class ClanInfo
if (UtilPlayer.isOnline(cur))
return true;
return System.currentTimeMillis() - _lastOnline < Clans.GetOnlineTime();
return System.currentTimeMillis() - _lastOnline < Clans.getOnlineTime();
}
public String getProtected()
@ -473,12 +357,12 @@ public class ClanInfo
if (UtilPlayer.isOnline(cur))
return C.cRed + "No - Clan Members are Online";
if (System.currentTimeMillis() - _lastOnline > Clans.GetOnlineTime())
if (System.currentTimeMillis() - _lastOnline > Clans.getOnlineTime())
return C.cGreen + "Yes - Clan Members are Offline";
return C.cGold
+ "No, "
+ UtilTime.convertString(Clans.GetOnlineTime() - (System.currentTimeMillis() - _lastOnline), 1,
+ UtilTime.convertString(Clans.getOnlineTime() - (System.currentTimeMillis() - _lastOnline), 1,
TimeUnit.FIT) + " to Protection";
}

View File

@ -0,0 +1,309 @@
package mineplex.game.clans.clans;
import java.util.ArrayList;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import mineplex.core.account.CoreClient;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClanInfo.Role;
import mineplex.game.clans.clans.repository.ClanRepository;
import mineplex.game.clans.clans.repository.ClanTerritory;
import mineplex.game.clans.clans.repository.tokens.ClanMemberToken;
import mineplex.game.clans.clans.repository.tokens.ClanToken;
public class ClansDataAccessLayer
{
private ClansManager _manager;
private ClanRepository _repository;
public ClansDataAccessLayer(ClansManager clans)
{
_manager = clans;
_repository = new ClanRepository(clans.GetPlugin(), clans.GetServerName());
}
public void delete(ClanInfo clan)
{
//Territory Unclaim
for (String cur : clan.getClaimSet())
_manager.getClaimMap().remove(cur);
_manager.getClanMap().remove(clan.getName());
for (String cur : clan.getMembers().keySet())
{
_manager.getClanMemberMap().remove(cur);
}
//Clean from Others
for (ClanInfo cur : _manager.getClanMap().values())
{
cur.getAllyMap().remove(clan.getName());
cur.getRequestMap().remove(clan.getName());
}
//Save
_repository.deleteClan(clan.getName());
//Log
_manager.log("Deleted [" + clan.getName() + "].");
}
public ClanInfo create(String creator, String name, boolean admin)
{
ClanToken token = new ClanToken();
token.Name = name;
token.Description = "No Description";
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);
//Log
_manager.log("[" + clan.getName() + "] with Admin [" + admin + "] created by [" + creator + "].");
return clan;
}
public void join(ClanInfo clan, String player, Role role)
{
if (_manager.getClanMemberMap().containsKey(player))
leave(_manager.getClanUtility().getClanByPlayer(player), player);
//Update Clan
clan.getMembers().put(player, role);
_manager.getClanMemberMap().put(player, clan);
clan.getInviteeMap().remove(player);
clan.getInviterMap().remove(player);
//Save
_repository.addMember(clan.getName(), player);
//Log
_manager.log("Added [" + player + "] to [" + clan.getName() + "].");
}
public void leave(ClanInfo clan, String player)
{
if (clan == null)
return;
//Update Clan
clan.getMembers().remove(player);
_manager.getClanMemberMap().remove(player);
//Save
_repository.removeMember(clan.getName(), player);
//Log
_manager.log("Removed [" + player + "] from [" + clan.getName() + "].");
}
public void role(ClanInfo clan, String player, Role role)
{
//Update Clan
clan.getMembers().put(player, role);
//Save
_repository.updateMember(clan.getName(), player, role);
//Log
_manager.log("Removed [" + player + "] from [" + clan.getName() + "].");
}
public void invite(ClanInfo clan, String player, String inviter)
{
clan.getInviteeMap().put(player, System.currentTimeMillis());
clan.getInviterMap().put(player, inviter);
//Log
_manager.log("Invited [" + player + "] to [" + clan.getName() + "] by [" + inviter + "].");
}
public void requestAlly(ClanInfo clan, ClanInfo target, String player)
{
clan.getRequestMap().put(target.getName(), System.currentTimeMillis());
//Log
_manager.log("Alliance Request to [" + target.getName() + "] from [" + clan.getName() + "] by [" + player + "].");
}
public void ally(ClanInfo cA, ClanInfo cB, String player)
{
//Remove Requests
cA.getRequestMap().remove(cB.getName());
cB.getRequestMap().remove(cA.getName());
//Update ClansManager
cA.getAllyMap().put(cB.getName(), false);
cB.getAllyMap().put(cA.getName(), false);
//Save
_manager.CRepo().EditClan(cA.GetToken());
_manager.CRepo().EditClan(cB.GetToken());
//Log
_manager.log("Added Ally for [" + cB.getName() + "] and [" + cA.getName() + "] by [" + player + "].");
}
public boolean trust(ClanInfo cA, ClanInfo cB, String player)
{
if (!cA.getAllyMap().containsKey(cB.getName()))
return false;
boolean trust = !cA.getAllyMap().get(cB.getName());
//Memory
cA.getAllyMap().put(cB.getName(), trust);
//Save
_manager.CRepo().EditClan(cA.GetToken());
_manager.CRepo().EditClan(cB.GetToken());
//Update Relations
for (String cur : cA.getMembers().keySet())
_manager.getClanUtility().updateRelations(cur);
//Update Relations
for (String cur : cB.getMembers().keySet())
_manager.getClanUtility().updateRelations(cur);
//Log
_manager.log("Gave Trust [" + trust + "] to [" + cB.getName() + "] for [" + cA.getName() + "] by [" + player + "].");
return trust;
}
public void neutral(ClanInfo cA, ClanInfo cB, String player, boolean bothClansManager)
{
//Update ClansManager
cA.getAllyMap().remove(cB.getName());
cB.getAllyMap().remove(cA.getName());
//Save
_manager.CRepo().EditClan(cA.GetToken());
_manager.CRepo().EditClan(cB.GetToken());
//Update Relations
for (String cur : cA.getMembers().keySet())
_manager.getClanUtility().updateRelations(cur);
//Update Relations
for (String cur : cB.getMembers().keySet())
_manager.getClanUtility().updateRelations(cur);
//Log
_manager.log("Added Neutral between [" + cA.getName() + "] and [" + cB.getName() + "] by [" + player + "].");
}
public boolean claim(String name, String chunk, String player, boolean safe)
{
if (!_manager.getClanMap().containsKey(name))
return false;
ClanInfo clan = _manager.getClanMap().get(name);
//Unclaim
if (_manager.getClaimMap().containsKey(chunk))
unclaim(chunk, player, false);
//Memory
ClanTerritory claim = new ClanTerritory(_manager, name, chunk, safe);
clan.getClaimSet().add(chunk);
_manager.getClaimMap().put(chunk, claim);
//Save
_manager.CRepo().EditClan(clan.GetToken());
//Visual
Chunk c = UtilWorld.strToChunk(chunk);
if (!clan.IsAdmin())
for (int i = 0 ; i < 3 ; i++)
for (int x=0 ; x < 16 ; x++)
for (int z=0 ; z < 16 ; z++)
if (z == 0 || z == 15 || x == 0 || x == 15)
{
Block down = UtilBlock.getHighest(c.getWorld(), c.getBlock(x, 0, z).getX(), c.getBlock(x, 0, z).getZ()).getRelative(BlockFace.DOWN);
if (down.getTypeId() == 1 || down.getTypeId() == 2 || down.getTypeId() == 3 || down.getTypeId() == 12 || down.getTypeId() == 8)
_manager.BlockRestore().Add(down, 89, (byte)0, 180000);
}
//Log
_manager.log("Added Claim for [" + name + "] at [" + chunk + "] by [" + player + "].");
return true;
}
public boolean unclaim(String chunk, String player, boolean sql)
{
ClanTerritory claim = _manager.getClaimMap().remove(chunk);
if (claim == null)
{
_manager.log("Unclaiming NULL Chunk Failed.");
return false;
}
ClanInfo clan = _manager.getClanMap().get(claim.Owner);
if (clan == null)
{
_manager.log("Unclaiming from NULL Clan Failed.");
return false;
}
//Memory
clan.getClaimSet().remove(chunk);
//Save
_manager.CRepo().EditClan(clan.GetToken());
//Register
_manager.getUnclaimMap().put(chunk, System.currentTimeMillis());
//Log
_manager.log("Removed Claim for [" + clan.getName() + "] at [" + chunk + "] by [" + player + "].");
return true;
}
public void home(ClanInfo clan, Location loc, String player)
{
//Memory
clan.SetHome(loc);
//Save
_manager.CRepo().EditClan(clan.GetToken());
//Log
_manager.log("Set Home for [" + clan.getName() + "] to " + UtilWorld.locToStrClean(loc) + " by [" + player + "].");
}
public void safe(ClanTerritory claim, String player)
{
//Memory
claim.Safe = !claim.Safe;
//Save
_manager.CRepo().EditClan(_manager.getClan(claim.Owner).GetToken());
//Log
_manager.log("Safe Zone at [" + claim.chunk + "] set to [" + claim.Safe + "] by [" + player + "].");
}
}

View File

@ -1,13 +1,49 @@
package mineplex.game.clans.clans;
import java.util.HashMap;
import java.util.HashSet;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockIgniteEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
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.core.MiniClientPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClient;
import mineplex.core.account.event.RetrieveClientInformationEvent;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.creature.event.CreatureSpawnCustomEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.repository.ClanTerritory;
import mineplex.minecraft.game.core.combat.CombatManager;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class ClansManager extends MiniPlugin
public class ClansManager extends MiniClientPlugin<ClientClan>
{
private CombatManager _combatManager;
private ClansUtility _clanUtility;
private int _dominanceLimit = 16;
private int _inviteExpire = 2;
private int _nameMin = 3;
@ -21,9 +57,12 @@ public class ClansManager extends MiniPlugin
private NautHashMap<String, ClanTerritory> _claimMap = new NautHashMap<String, ClanTerritory>();
private NautHashMap<String, Long> _unclaimMap = new NautHashMap<String, Long>();
public ClansManager(String moduleName, JavaPlugin plugin)
public ClansManager(JavaPlugin plugin, CombatManager combatManager)
{
super(moduleName, plugin);
super("Clans Manager", plugin);
_combatManager = combatManager;
_clanUtility = new ClansUtility(this);
}
public int getInviteExpire()
@ -50,4 +89,317 @@ public class ClansManager extends MiniPlugin
{
return _claimMap;
}
@Override
public void commands()
{
AddCommand("cc");
AddCommand("fc");
AddCommand("ac");
}
@Override
public void command(Player caller, String cmd, String[] args)
{
if (cmd.equals("cc") || cmd.equals("fc"))
CCommand().commandChat(caller, args);
else if (cmd.equals("ac"))
CCommand().commandAllyChat(caller, args);
else
CCommand().command(caller, args);
}
public ClansClan getClan(String name)
{
return GetClanMap().get(name);
}
@EventHandler
public void Update(UpdateEvent event)
{
if (event.getType() == UpdateType.SEC)
Power();
if (event.getType() == UpdateType.FAST)
CGame().UpdateSafe();
if (event.getType() == UpdateType.FASTER)
CGame().UpdateDisplay();
if (event.getType() == UpdateType.SEC)
{
for (ClansClan clan : _clanMap.values())
{
if (clan.GeneratorUpdate())
_genUpdateList.add(clan);
clan.OutpostUpdate();
}
if (_genUpdateList.size() > 0)
{
CRepo().Repository.UpdateClanTNTGenerators(_genUpdateList);
_genUpdateList.clear();
}
}
if (event.getType() == UpdateType.FAST)
for (ClansClan clan : _clanMap.values())
if (clan.GetOutpost() != null)
clan.GetOutpost().BuildUpdate();
}
public long lastPower = System.currentTimeMillis();
@EventHandler(priority = EventPriority.LOW)
public void BlockBurn(BlockBurnEvent event)
{
CGame().BlockBurn(event);
}
@EventHandler(priority = EventPriority.LOW)
public void BlockIgnite(BlockIgniteEvent event)
{
CGame().BlockSpread(event);
}
@EventHandler(priority = EventPriority.LOW)
public void BlockPlace(BlockPlaceEvent event)
{
if (event.isCancelled())
return;
CGame().BlockPlace(event);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void BlockCreatureSpawn(CreatureSpawnCustomEvent event)
{
ClansClan clan = Clans().CUtil().getOwner(event.GetLocation());
if (clan != null)
if (!clan.IsAdmin() && !clan.GetName().equals("Spawn"))
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.LOWEST)
public void Damage(CustomDamageEvent event)
{
if (event.IsCancelled())
return;
CGame().Damage(event);
}
@EventHandler(priority = EventPriority.LOWEST)
public void Interact(PlayerInteractEvent event)
{
CGame().Interact(event);
CDisplay().handleInteract(event);
if (Util().Event().isAction(event, ActionType.R_BLOCK))
if (event.getClickedBlock().getType() == Material.BREWING_STAND && !event.isCancelled())
{
for (ClansClan clan : _clanMap.values())
clan.GeneratorUse(event.getPlayer(), event.getClickedBlock().getLocation());
event.setCancelled(true);
}
else if (event.getClickedBlock().getType() == Material.BEACON)
{
for (ClansClan clan : _clanMap.values())
clan.OutpostUse(event.getPlayer(), event.getClickedBlock().getLocation());
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void Piston(BlockPistonExtendEvent event)
{
CGame().Piston(event);
}
@EventHandler(priority = EventPriority.LOW)
public void SkillTrigger(SkillTriggerEvent event)
{
CGame().SafeSkill(event);
}
@EventHandler(priority = EventPriority.MONITOR)
public void Death(CombatDeathEvent event)
{
CGame().DeathDominance(event);
CGame().DeathColor(event);
}
@EventHandler
public void Join(PlayerJoinEvent event)
{
CGame().Join(event);
}
@EventHandler
public void Quit(PlayerQuitEvent event)
{
CGame().Quit(event);
}
@EventHandler(priority = EventPriority.LOWEST)
public void Explosion(EntityExplodeEvent event)
{
CGame().Explode(event);
}
public boolean HandleClanChat(AsyncPlayerChatEvent event, String filteredMessage)
{
CoreClient client = Clients().Get(event.getPlayer());
if (client == null)
return false;
if (!client.Clan().IsClanChat())
return false;
ClansClan clan = CUtil().getClanByPlayer(event.getPlayer());
if (clan == null)
{
Clients().Get(event.getPlayer()).Clan().SetClanChat(false);
return false;
}
ChatClan(clan, event.getPlayer(), event.getMessage(), filteredMessage);
return true;
}
public boolean HandleAllyChat(AsyncPlayerChatEvent event, String filteredMessage)
{
if (!Get(event.getPlayer()).isAllyChat())
return false;
ClansClan clan = CUtil().getClanByPlayer(event.getPlayer());
if (clan == null)
{
Clients().Get(event.getPlayer()).Clan().SetAllyChat(false);
return false;
}
ChatAlly(clan, event.getPlayer(), event.getMessage(), filteredMessage);
return true;
}
public void ChatClan(ClanInfo clan, Player sender, String message, String filteredMessage)
{
clan.chat(sender, message, filteredMessage);
}
public void ChatAlly(ClanInfo clan, Player sender, String message, String filteredMessage)
{
for (String cur : clan.getAllyMap().keySet())
{
ClanInfo ally = _clanUtility.getClanByClanName(cur);
if (ally == null) continue;
ally.allyChat(clan, sender, message, filteredMessage);
}
clan.allyChat(clan, sender, message, filteredMessage);
}
public int getNameMin()
{
return _nameMin;
}
public int getNameMax()
{
return _nameMax;
}
public long getReclaimTime()
{
return _reclaimTime;
}
@Override
public boolean CanHurt(Player a, Player b)
{
if (a.equals(b))
return false;
return CUtil().canHurt(a, b);
}
@Override
public boolean CanHurt(String a, String b)
{
if (a.equals(b))
return false;
return CUtil().canHurt(UtilPlayer.searchExact(a), UtilPlayer.searchExact(b));
}
@Override
public boolean IsSafe(Player a)
{
return CUtil().isSafe(a);
}
public IRepository GetRepository() {
return _repository;
}
public void SetRepository(IRepository _repository) {
this._repository = _repository;
}
public HashMap<String, ClansClan> GetClanMemberMap()
{
return _clanMemberMap;
}
public ClanRelation GetRelation(String playerA, String playerB)
{
return Clients().Get(playerA).Clan().GetRelation(playerB);
}
@Override
public ChatColor GetColorOfFor(String other, Player player)
{
return CUtil().relChatColor(Clients().Get(player).Clan().GetRelation(other), false);
}
public String GetServerName()
{
return _serverName;
}
public long getOnlineTime()
{
return _onlineTime;
}
public CombatManager getCombatManager()
{
return _combatManager;
}
public ClansUtility getClanUtility()
{
return _clanUtility;
}
@Override
protected ClientClan AddPlayer(String player)
{
return new ClientClan();
}
@Override
protected void loadClientInformation(RetrieveClientInformationEvent event)
{
}
}

View File

@ -8,15 +8,13 @@ import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClient;
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.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClanInfo.Role;
import mineplex.game.clans.clans.repository.ClanTerritory;
import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken;
public class ClansUtility
{
@ -33,8 +31,6 @@ public class ClansUtility
ALLY,
ALLY_TRUST,
NEUTRAL,
ENEMY,
PILLAGE,
ADMIN,
SAFE
}
@ -178,9 +174,7 @@ public class ClansUtility
public boolean isSafe(Player player)
{
ClanInfo clan = getClanByPlayer(player);
if (!UtilTime.elapsed(Clans.Clients().Get(player).Player().GetLastDamager(), 15000))
if (!UtilTime.elapsed(Clans.getCombatManager().Get(player).GetLastDamaged(), 15000))
return false;
return isSafe(player.getLocation());
@ -307,24 +301,12 @@ public class ClansUtility
public ClanRelation getAccess(Player player, Location loc)
{
//Observer Override
if (Clans.Observer().isObserver(player, false))
{
if (Clans.Observer().isObserver(player, true))
return ClanRelation.SELF;
else
return ClanRelation.NEUTRAL;
}
ClanInfo owner = this.getOwner(loc);
ClanInfo clan = getClanByPlayer(player);
if (owner == null)
return ClanRelation.SELF;
if (owner.equals(Clans.CAdmin().getMimic(player, false)))
return ClanRelation.SELF;
if (owner.equals(clan))
return ClanRelation.SELF;
@ -336,10 +318,6 @@ public class ClansUtility
if (owner.isAlly(clan.getName()))
return ClanRelation.ALLY;
if (clan != null)
if (owner.isEnemy(clan.getName()))
return ClanRelation.ENEMY;
return ClanRelation.NEUTRAL;
}
@ -428,16 +406,12 @@ public class ClansUtility
if (relation == ClanRelation.SELF) return C.xSelf;
if (relation == ClanRelation.ALLY_TRUST) return C.xdAlly;
if (relation == ClanRelation.ALLY) return C.xAlly;
if (relation == ClanRelation.ENEMY) return C.xWar;
if (relation == ClanRelation.PILLAGE) return C.xPillage;
return C.xEnemy;
}
if (relation == ClanRelation.SELF) return C.xdSelf;
if (relation == ClanRelation.ALLY_TRUST) return C.xAlly;
if (relation == ClanRelation.ALLY) return C.xdAlly;
if (relation == ClanRelation.ENEMY) return C.xdWar;
if (relation == ClanRelation.PILLAGE) return C.xdPillage;
return C.xdEnemy;
}
@ -500,49 +474,13 @@ public class ClansUtility
if (isSafe(damager))
return false;
ClanRelation rel = Clans.CUtil().relPP(damagee.getName(), damager.getName());
ClanRelation rel = relPP(damagee.getName(), damager.getName());
if (rel == ClanRelation.ALLY || rel == ClanRelation.ALLY_TRUST || rel == ClanRelation.SELF)
return false;
return true;
}
public void updateRelations(String name)
{
updateRelations(UtilPlayer.searchExact(name));
}
public void updateRelations(Player player)
{
if (player == null)
return;
CoreClient client = Clans.Clients().Get(player);
for (Player cur : UtilServer.getPlayers())
{
//For Player
client.Clan().SetRelationship(
cur.getName(), relPP(cur.getName(), player.getName()));
//For Other
Clans.Clients().Get(cur.getName()).Clan().SetRelationship(
player.getName(), relPP(player.getName(), cur.getName()));
if (player.canSee(cur))
{
player.hidePlayer(cur);
player.showPlayer(cur);
}
if (cur.canSee(player))
{
cur.hidePlayer(player);
cur.showPlayer(player);
}
}
}
public boolean isBorderlands(Location loc)
{

View File

@ -0,0 +1,51 @@
package mineplex.game.clans.clans;
public class ClientClan
{
private boolean _clanChat;
private boolean _allyChat;
private boolean _mapOn;
private boolean _canJoin;
private long _joinDelay;
public boolean isAllyChat()
{
return _allyChat;
}
public void setAllyChat(boolean allyChat)
{
_allyChat = allyChat;
}
public boolean isClanChat()
{
return _clanChat;
}
public void setClanChat(boolean clanChat)
{
_clanChat = clanChat;
}
public boolean isMapOn()
{
return _mapOn;
}
public void setMapOn(boolean mapOn)
{
_mapOn = mapOn;
}
public boolean canJoin()
{
return _canJoin;
}
public long getDelay()
{
return _joinDelay;
}
}

View File

@ -2,13 +2,17 @@ package mineplex.game.clans.clans.repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Collection;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
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;
public class ClanRepository extends RepositoryBase
@ -18,9 +22,9 @@ public class ClanRepository extends RepositoryBase
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 FROM clans AS c INNER JOIN clanTerritory AS ct ON ct.clanId = c.id WHERE serverName = ?;";
private static String RETRIEVE_CLAN_MEMBER_INFO = "SELECT a.name, role FROM accountClan AS ac INNER JOIN accounts AS a ON a.id = ac.accountId WHERE ac.clanId = ?;";
private static String RETRIEVE_CLAN_ALLIANCE_INFO = "SELECT cOther.id, cOther.name 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 ac.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 String _serverName;
@ -40,16 +44,86 @@ public class ClanRepository extends RepositoryBase
executeUpdate(CREATE_CLAN_ALLIANCE_TABLE);
}
public List<ClanToken> retrieveStartupClanInformation()
public Collection<ClanToken> retrieveClans()
{
final NautHashMap<String, ClanToken> clans = new NautHashMap<String, ClanToken>();
executeQuery(RETRIEVE_START_CLAN_INFO, new ResultSetCallable()
{
@Override
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
ClanToken token = new ClanToken();
token.Id = resultSet.getInt(1);
token.Name = resultSet.getString(2);
token.Description = resultSet.getString(3);
token.Home = resultSet.getString(4);
token.Admin = resultSet.getBoolean(5);
token.DateCreated = resultSet.getLong(6);
token.LastOnline = resultSet.getLong(7);
ClanTerritoryToken territoryToken = new ClanTerritoryToken();
territoryToken.Chunk = resultSet.getString(8);
territoryToken.Safe = resultSet.getBoolean(9);
if (!clans.containsKey(token.Name))
{
clans.put(token.Name, token);
}
clans.get(token.Name).Territories.add(territoryToken);
}
}
}, new ColumnVarChar("serverName", 100, _serverName));
executeQuery(RETRIEVE_CLAN_MEMBER_INFO, new ResultSetCallable()
{
@Override
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
String clanName = resultSet.getString(1);
if (clans.containsKey(clanName))
{
ClanMemberToken memberToken = new ClanMemberToken();
memberToken.Name = resultSet.getString(2);
memberToken.ClanRole = resultSet.getString(3);
clans.get(clanName).Members.add(memberToken);
}
}
}
});
executeQuery(RETRIEVE_CLAN_ALLIANCE_INFO, new ResultSetCallable()
{
@Override
public void processResultSet(ResultSet resultSet) throws SQLException
{
while (resultSet.next())
{
String clanName = resultSet.getString(1);
if (clans.containsKey(clanName))
{
ClanAllianceToken allianceToken = new ClanAllianceToken();
allianceToken.ClanName = resultSet.getString(2);
allianceToken.Trusted = resultSet.getBoolean(3);
clans.get(clanName).Alliances.add(allianceToken);
}
}
}
}, new ColumnVarChar("serverName", 100, _serverName));
return clans.values();
}
@Override

View File

@ -1,9 +1,11 @@
package mineplex.game.clans.clans.repository.tokens;
import java.util.ArrayList;
import java.util.List;
public class ClanToken
{
public int Id;
public String Name;
public String Description;
public String Home;
@ -11,7 +13,7 @@ public class ClanToken
public long DateCreated;
public long LastOnline;
List<ClanMemberToken> Members;
List<ClanTerritoryToken> Territories;
List<ClanAllianceToken> Alliances;
public List<ClanMemberToken> Members = new ArrayList<ClanMemberToken>();
public List<ClanTerritoryToken> Territories = new ArrayList<ClanTerritoryToken>();
public List<ClanAllianceToken> Alliances = new ArrayList<ClanAllianceToken>();
}

View File

@ -1,6 +1,5 @@
package mineplex.minecraft.game.core.combat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;