Merge branch 'clans/world-events' of ssh://184.154.0.242:7999/min/mineplex into clans/world-events

This commit is contained in:
libraryaddict 2015-07-04 09:07:29 +12:00
commit 27c7e7be03
8 changed files with 181 additions and 46 deletions

View File

@ -30,11 +30,9 @@ public class PlayerScoreboard
public PlayerScoreboard(ScoreboardManager manager, Player player)
{
_manager = manager;
assignScoreboard(player, getData());
}
private void addTeams(Player player)
protected void addTeams(Player player)
{
for (Rank rank : Rank.values())
{
@ -93,10 +91,12 @@ public class PlayerScoreboard
if (data == null)
return;
for (int i=0 ; i<data.getLines(manager, player).size() ; i++)
ArrayList<String> lines = data.getLines(manager, player);
for (int i=0 ; i<lines.size() ; i++)
{
//Get New Line
String newLine = data.getLines(manager, player).get(i);
String newLine = lines.get(i);
//Check if Unchanged
if (_currentLines.size() > i)
@ -124,16 +124,16 @@ public class PlayerScoreboard
}
//Hide Old Unused
if (_currentLines.size() > data.getLines(manager, player).size())
if (_currentLines.size() > lines.size())
{
for (int i=data.getLines(manager, player).size() ; i<_currentLines.size() ; i++)
for (int i=lines.size() ; i<_currentLines.size() ; i++)
{
_scoreboard.resetScores(_teamNames[i]);
}
}
//Save New State
_currentLines = data.getLines(manager, player);
_currentLines = lines;
}
public void setTitle(String out)
@ -141,6 +141,11 @@ public class PlayerScoreboard
_sideObjective.setDisplayName(out);
}
public void assignScoreboard(Player player)
{
assignScoreboard(player, getData());
}
public void assignScoreboard(Player player, ScoreboardData data)
{
//Scoreboard
@ -195,4 +200,9 @@ public class PlayerScoreboard
//Set Scoreboard
player.setScoreboard(_scoreboard);
}
protected Scoreboard getScoreboard()
{
return _scoreboard;
}
}

View File

@ -61,10 +61,17 @@ public class ScoreboardManager extends MiniPlugin
_shineIndex = 0;
}
protected PlayerScoreboard createScoreboard(Player player)
{
return new PlayerScoreboard(this, player);
}
@EventHandler
public void playerJoin(PlayerJoinEvent event)
{
_playerScoreboards.put(event.getPlayer(), new PlayerScoreboard(this, event.getPlayer()));
PlayerScoreboard scoreboard = createScoreboard(event.getPlayer());
scoreboard.assignScoreboard(event.getPlayer());
_playerScoreboards.put(event.getPlayer(), scoreboard);
}
@EventHandler
@ -92,7 +99,10 @@ public class ScoreboardManager extends MiniPlugin
}
}
public PlayerScoreboard getCurrentScoreboard(Player player)
{
return _playerScoreboards.get(player);
}
public ScoreboardData getData(String scoreboardName, boolean create)
{

View File

@ -6,6 +6,7 @@ import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilWorld;
@ -13,15 +14,18 @@ import mineplex.game.clans.clans.repository.ClanRepository;
import mineplex.game.clans.clans.repository.ClanTerritory;
import mineplex.game.clans.clans.repository.tokens.ClanEnemyToken;
import mineplex.game.clans.clans.repository.tokens.ClanToken;
import mineplex.game.clans.clans.scoreboard.ClansScoreboardManager;
public class ClansDataAccessLayer
{
private ClansManager _manager;
private ClanRepository _repository;
private ClansScoreboardManager _scoreboard;
public ClansDataAccessLayer(ClansManager clans)
public ClansDataAccessLayer(ClansManager clans, ClansScoreboardManager scoreboard)
{
_manager = clans;
_scoreboard = scoreboard;
_repository = new ClanRepository(clans.getPlugin(), clans.getServerName());
}
@ -48,6 +52,9 @@ public class ClansDataAccessLayer
//Save
_repository.deleteClan(clan.getId());
//Scoreboard
_scoreboard.refresh(clan);
//Log
_manager.log("Deleted [" + clan.getName() + "].");
}
@ -73,25 +80,35 @@ public class ClansDataAccessLayer
return clan;
}
public void join(ClanInfo clan, String player, ClanRole role)
public void join(ClanInfo clan, Player player, ClanRole role)
{
if (_manager.getClanMemberMap().containsKey(player))
String playerName = player.getName();
if (_manager.getClanMemberMap().containsKey(playerName))
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);
clan.getMembers().put(playerName, role);
_manager.getClanMemberMap().put(playerName, clan);
clan.getInviteeMap().remove(playerName);
clan.getInviterMap().remove(playerName);
clan.playerOnline(player);
//Save
_repository.addMember(clan.getId(), player, role.toString());
_repository.addMember(clan.getId(), playerName, role.toString());
//Scoreboard
_scoreboard.refresh(player);
//Log
_manager.log("Added [" + player + "] to [" + clan.getName() + "].");
}
public void leave(ClanInfo clan, Player player)
{
leave(clan, player.getName());
_scoreboard.refresh(player);
}
public void leave(ClanInfo clan, String player)
{
if (clan == null)
@ -152,6 +169,9 @@ public class ClansDataAccessLayer
_repository.addClanRelationship(cA.getId(), cB.getId(), false);
_repository.addClanRelationship(cB.getId(), cA.getId(), false);
//Scoreboard
_scoreboard.refresh(cA);
//Log
_manager.log("Added Ally for [" + cB.getName() + "] and [" + cA.getName() + "] by [" + player + "].");
}
@ -173,6 +193,9 @@ public class ClansDataAccessLayer
otherClanEnemyToken.EnemyName = clan.getName();
otherClan.updateEnemy(otherClanEnemyToken);
//Scoreboard
_scoreboard.refresh(clan);
_manager.log("Added Enemy for [" + clan.getName() + "] and [" + otherClan.getName() + "] by [" + player + "].");
}
@ -189,6 +212,9 @@ public class ClansDataAccessLayer
//Save
_repository.updateClanRelationship(ownerClan.getId(), otherClan.getId(), trust);
//Scoreboard
_scoreboard.refresh(ownerClan);
//Log
_manager.log((trust ? "Gave" : "Revoked") + " Trust [" + trust + "] to [" + otherClan.getName() + "] for [" + ownerClan.getName() + "] by [" + player + "].");
@ -205,6 +231,9 @@ public class ClansDataAccessLayer
_repository.removeClanRelationship(cA.getId(), cB.getId());
_repository.removeClanRelationship(cB.getId(), cA.getId());
//Scoreboard
_scoreboard.refresh(cA);
//Log
_manager.log("Added Neutral between [" + cA.getName() + "] and [" + cB.getName() + "] by [" + player + "].");
}

View File

@ -83,6 +83,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
private CoreClientManager _clientManager;
private CombatManager _combatManager;
private ClansUtility _clanUtility;
private ClansScoreboardManager _scoreboard;
private ClansDataAccessLayer _clanDataAccess;
private ClansDisplay _clanDisplay;
private ClansAdmin _clanAdmin;
@ -128,32 +129,37 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
_chat = chat;
_blockRestore = blockRestore;
_teleport = teleport;
_warManager = new WarManager(plugin, this);
GoldManager goldManager = new GoldManager(this, _clientManager, donationManager);
LootManager lootManager = new LootManager(gearManager, goldManager);
PacketHandler packetHandler = new PacketHandler(plugin);
DisguiseManager disguiseManager = new DisguiseManager(plugin, packetHandler);
Creature creature = new Creature(plugin);
DamageManager damageManager = new DamageManager(plugin, _combatManager, new NpcManager(plugin, creature), disguiseManager);
_worldEvent = new WorldEventManager(plugin, this, damageManager, lootManager, blockRestore);
_scoreboard = new ClansScoreboardManager(plugin, this, _warManager, _worldEvent, clientManager, donationManager);
_clanAdmin = new ClansAdmin(this);
_clanBlocks = new ClansBlocks();
_clanDataAccess = new ClansDataAccessLayer(this);
_clanDataAccess = new ClansDataAccessLayer(this, _scoreboard);
_clanDisplay = new ClansDisplay(plugin, this);
_clanGame = new ClansGame(plugin, this);
_clanUtility = new ClansUtility(this);
_itemMapManager = new ItemMapManager(this);
Energy energy = new Energy(plugin);
PacketHandler packetHandler = new PacketHandler(plugin);
// TODO: Re-enable customtagfix with NCP update?
//new CustomTagFix(plugin, packetHandler);
DisguiseManager disguiseManager = new DisguiseManager(plugin, packetHandler);
_condition = new SkillConditionManager(plugin);
Creature creature = new Creature(plugin);
new Field(plugin, creature, _condition, energy, serverName);
// Required managers to be initialized
new Spawn(plugin);
new NPCManager(this);
new LoggingManager(plugin);
GoldManager goldManager = new GoldManager(this, _clientManager, donationManager);
DamageManager damageManager = new DamageManager(plugin, _combatManager, new NpcManager(plugin, creature), disguiseManager);
new Weapon(plugin, energy);
new Gameplay(plugin, this, blockRestore, damageManager);
@ -174,12 +180,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
ClassShopManager shopManager = new ClassShopManager(plugin, _classManager, skillManager, itemFactory, achievementManager, _clientManager);
_classShop = new ClassCombatShop(shopManager, _clientManager, donationManager, true, "Class Shop");
_warManager = new WarManager(plugin, this);
ClanEnergyManager clanEnergyManager = new ClanEnergyManager(plugin, this, clientManager, donationManager);
LootManager lootManager = new LootManager(gearManager, goldManager);
_worldEvent = new WorldEventManager(plugin, this, damageManager, lootManager, blockRestore);
for (ClanToken token : _clanDataAccess.getRepository().retrieveClans())
{
@ -196,8 +197,6 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
// Initialize default region factions and territory (spawn/fields/borderlands)
_clanRegions = new ClansRegions(plugin, this);
_clanRegions.initializeRegions();
new ClansScoreboardManager(plugin, this, clientManager, donationManager);
}
@Override

View File

@ -30,12 +30,24 @@ public class ClansUtility
public enum ClanRelation
{
SELF,
ALLY,
ALLY_TRUST,
NEUTRAL,
ADMIN,
SAFE
SELF(C.xSelf.toString()),
ALLY(C.xAlly.toString()),
ALLY_TRUST(C.xAlly.toString()),
NEUTRAL(C.xNone.toString()),
ADMIN(C.xAdmin.toString()),
SAFE(C.xSafe.toString());
private String _prefix;
ClanRelation(String prefix)
{
_prefix = prefix;
}
public String getPrefix()
{
return _prefix;
}
}
/**

View File

@ -293,7 +293,7 @@ public class ClansCommand extends CommandBase<ClansManager>
ClanInfo clan = Plugin.getClanDataAccess().create(caller.getName(), args[1], false);
Plugin.getClanDataAccess().join(clan, caller.getName(), ClanRole.LEADER);
Plugin.getClanDataAccess().join(clan, caller, ClanRole.LEADER);
}
public void delete(Player caller, String[] args)
@ -401,7 +401,7 @@ public class ClansCommand extends CommandBase<ClansManager>
}
//Task
Plugin.getClanDataAccess().join(clan, caller.getName(), ClanRole.RECRUIT);
Plugin.getClanDataAccess().join(clan, caller, ClanRole.RECRUIT);
//Inform
UtilPlayer.message(caller, F.main("Clans", "You joined " + F.elem("Clan " + clan.getName()) + "."));
@ -431,7 +431,7 @@ public class ClansCommand extends CommandBase<ClansManager>
UtilPlayer.message(caller, F.main("Clans", "You left " + F.elem("Clan " + clan.getName()) + "."));
//Task
Plugin.getClanDataAccess().leave(clan, caller.getName());
Plugin.getClanDataAccess().leave(clan, caller);
//Inform
clan.inform(F.name(caller.getName()) + " has left your Clan.", null);
@ -660,7 +660,7 @@ public class ClansCommand extends CommandBase<ClansManager>
//Inform
UtilPlayer.message(caller, F.main("Clans", "You accepted alliance with " + F.elem("Clan " + cB.getName()) + "."));
cA.inform(F.name(caller.getName()) + " accepted alliance with " + F.elem("Clan " + cB.getName()) + ".", caller.getName());
cB.inform(F.elem("Clan " + cA.getName()) + " has accepted alliance with you.", null);
cB.inform(F.elem("Clan " + cA.getName()) + " has accepted alliance with you.", null);
}
else
{

View File

@ -0,0 +1,47 @@
package mineplex.game.clans.clans.scoreboard;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.scoreboard.PlayerScoreboard;
import mineplex.core.scoreboard.ScoreboardManager;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.ClansUtility.ClanRelation;
public class ClansPlayerScoreboard extends PlayerScoreboard
{
private ClansManager _clansManager;
public ClansPlayerScoreboard(ScoreboardManager manager, ClansManager clansManager, Player player)
{
super(manager, player);
_clansManager = clansManager;
}
@Override
protected void addTeams(Player player)
{
for (ClanRelation relation : ClanRelation.values())
{
getScoreboard().registerNewTeam(relation.name()).setPrefix(relation.getPrefix());
}
refreshTeams(player);
}
public void refreshTeams(Player player)
{
for (Player otherPlayer : Bukkit.getOnlinePlayers())
{
if (otherPlayer.equals(player))
continue;
ClanRelation relation = _clansManager.getRelation(player.getName(), otherPlayer.getName());
// Add Other to Self
getScoreboard().getTeam(relation.name()).addPlayer(otherPlayer);
// Add Self to Other
otherPlayer.getScoreboard().getTeam(relation.name()).addPlayer(player);
}
}
}

View File

@ -1,29 +1,38 @@
package mineplex.game.clans.clans.scoreboard;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.scoreboard.PlayerScoreboard;
import mineplex.core.scoreboard.ScoreboardData;
import mineplex.core.scoreboard.ScoreboardManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.scoreboard.elements.ScoreboardElementClan;
import mineplex.game.clans.clans.scoreboard.elements.ScoreboardElementPlayer;
import mineplex.game.clans.clans.scoreboard.elements.ScoreboardElementWar;
import mineplex.game.clans.clans.war.WarManager;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
public class ClansScoreboardManager extends ScoreboardManager
{
private ClansManager _clansManager;
private WarManager _warManager;
private WorldEventManager _worldEvent;
public ClansScoreboardManager(JavaPlugin plugin, ClansManager clansManager, CoreClientManager clientManager, DonationManager donationManager)
public ClansScoreboardManager(JavaPlugin plugin, ClansManager clansManager, WarManager warManager, WorldEventManager worldEvent, CoreClientManager clientManager, DonationManager donationManager)
{
super(plugin, clientManager, donationManager);
_clansManager = clansManager;
_warManager = warManager;
_worldEvent = worldEvent;
init();
}
@ -37,12 +46,12 @@ public class ClansScoreboardManager extends ScoreboardManager
data.writeElement(new ScoreboardElementClan(_clansManager));
data.writeEmpty();
data.writeElement(new ScoreboardElementWar(_clansManager, _clansManager.getWarManager()));
data.writeElement(new ScoreboardElementWar(_clansManager, _warManager));
data.writeEmpty();
data.writeElement(new ScoreboardElementPlayer(_clansManager));
data.writeElement(_clansManager.getWorldEvent());
data.writeElement(_worldEvent);
}
@EventHandler
@ -51,4 +60,23 @@ public class ClansScoreboardManager extends ScoreboardManager
if (event.getType() == UpdateType.FAST)
draw();
}
@Override
protected PlayerScoreboard createScoreboard(Player player)
{
return new ClansPlayerScoreboard(this, _clansManager, player);
}
public void refresh(ClanInfo clanInfo)
{
for (Player player : clanInfo.getOnlinePlayers())
{
refresh(player);
}
}
public void refresh(Player player)
{
((ClansPlayerScoreboard) getCurrentScoreboard(player)).refreshTeams(player);
}
}