Cleanup EngineMoveChunk and use cleaner method structure.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.massivecraft.factions.engine;
|
||||
|
||||
import com.massivecraft.factions.AccessStatus;
|
||||
import com.massivecraft.factions.Const;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
@@ -46,84 +48,85 @@ public class EngineMoveChunk extends Engine
|
||||
PS chunkFrom = PS.valueOf(event.getFrom()).getChunk(true);
|
||||
PS chunkTo = PS.valueOf(event.getTo()).getChunk(true);
|
||||
|
||||
// ... send info onwards and try auto-claiming.
|
||||
sendChunkInfo(mplayer, player, chunkFrom, chunkTo);
|
||||
tryAutoClaim(mplayer, chunkTo);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MOVE CHUNK: SEND CHUNK INFO
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static void sendChunkInfo(MPlayer mplayer, Player player, PS chunkFrom, PS chunkTo)
|
||||
{
|
||||
sendAutoMapUpdate(mplayer, player);
|
||||
sendFactionTerritoryInfo(mplayer, player, chunkFrom, chunkTo);
|
||||
sendTerritoryAccessMessage(mplayer, chunkFrom, chunkTo);
|
||||
}
|
||||
|
||||
private static void sendAutoMapUpdate(MPlayer mplayer, Player player)
|
||||
{
|
||||
if (!mplayer.isMapAutoUpdating()) return;
|
||||
AsciiMap map = new AsciiMap(mplayer, player, false);
|
||||
mplayer.message(map.render());
|
||||
}
|
||||
|
||||
private static void sendFactionTerritoryInfo(MPlayer mplayer, Player player, PS chunkFrom, PS chunkTo)
|
||||
{
|
||||
Faction factionFrom = BoardColl.get().getFactionAt(chunkFrom);
|
||||
Faction factionTo = BoardColl.get().getFactionAt(chunkTo);
|
||||
|
||||
// ... and send info onwards.
|
||||
this.moveChunkTerritoryInfo(mplayer, player, chunkFrom, chunkTo, factionFrom, factionTo);
|
||||
this.moveChunkAutoClaim(mplayer, chunkTo);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MOVE CHUNK: TERRITORY INFO
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void moveChunkTerritoryInfo(MPlayer mplayer, Player player, PS chunkFrom, PS chunkTo, Faction factionFrom, Faction factionTo)
|
||||
{
|
||||
// send host faction info updates
|
||||
if (mplayer.isMapAutoUpdating())
|
||||
|
||||
if (factionFrom == factionTo) return;
|
||||
|
||||
if (mplayer.isTerritoryInfoTitles())
|
||||
{
|
||||
AsciiMap map = new AsciiMap(mplayer, player, false);
|
||||
mplayer.message(map.render());
|
||||
String titleMain = parseTerritoryInfo(MConf.get().territoryInfoTitlesMain, mplayer, factionTo);
|
||||
String titleSub = parseTerritoryInfo(MConf.get().territoryInfoTitlesSub, mplayer, factionTo);
|
||||
int ticksIn = MConf.get().territoryInfoTitlesTicksIn;
|
||||
int ticksStay = MConf.get().territoryInfoTitlesTicksStay;
|
||||
int ticksOut = MConf.get().territoryInfoTitleTicksOut;
|
||||
MixinTitle.get().sendTitleMessage(player, ticksIn, ticksStay, ticksOut, titleMain, titleSub);
|
||||
}
|
||||
else if (factionFrom != factionTo)
|
||||
else
|
||||
{
|
||||
if (mplayer.isTerritoryInfoTitles())
|
||||
{
|
||||
String maintitle = parseTerritoryInfo(MConf.get().territoryInfoTitlesMain, mplayer, factionTo);
|
||||
String subtitle = parseTerritoryInfo(MConf.get().territoryInfoTitlesSub, mplayer, factionTo);
|
||||
MixinTitle.get().sendTitleMessage(player, MConf.get().territoryInfoTitlesTicksIn, MConf.get().territoryInfoTitlesTicksStay, MConf.get().territoryInfoTitleTicksOut, maintitle, subtitle);
|
||||
}
|
||||
else
|
||||
{
|
||||
String message = parseTerritoryInfo(MConf.get().territoryInfoChat, mplayer, factionTo);
|
||||
MixinMessage.get().messageOne(player, message);
|
||||
}
|
||||
}
|
||||
|
||||
// Show access level message if it changed.
|
||||
TerritoryAccess accessFrom = BoardColl.get().getTerritoryAccessAt(chunkFrom);
|
||||
Boolean hasTerritoryAccessFrom = accessFrom.hasTerritoryAccess(mplayer);
|
||||
|
||||
TerritoryAccess accessTo = BoardColl.get().getTerritoryAccessAt(chunkTo);
|
||||
Boolean hasTerritoryAccessTo = accessTo.hasTerritoryAccess(mplayer);
|
||||
|
||||
if ( ! MUtil.equals(hasTerritoryAccessFrom, hasTerritoryAccessTo))
|
||||
{
|
||||
if (hasTerritoryAccessTo == null)
|
||||
{
|
||||
mplayer.msg("<i>You have standard access to this area.");
|
||||
}
|
||||
else if (hasTerritoryAccessTo)
|
||||
{
|
||||
mplayer.msg("<g>You have elevated access to this area.");
|
||||
}
|
||||
else
|
||||
{
|
||||
mplayer.msg("<b>You have decreased access to this area.");
|
||||
}
|
||||
String message = parseTerritoryInfo(MConf.get().territoryInfoChat, mplayer, factionTo);
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public String parseTerritoryInfo(String string, MPlayer mplayer, Faction faction)
|
||||
|
||||
private static String parseTerritoryInfo(String string, MPlayer mplayer, Faction faction)
|
||||
{
|
||||
if (string == null) throw new NullPointerException("string");
|
||||
if (faction == null) throw new NullPointerException("faction");
|
||||
|
||||
|
||||
string = Txt.parse(string);
|
||||
|
||||
string = string.replace("{name}", faction.getName());
|
||||
string = string.replace("{relcolor}", faction.getColorTo(mplayer).toString());
|
||||
string = string.replace("{desc}", faction.getDescriptionDesc());
|
||||
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
private static void sendTerritoryAccessMessage(MPlayer mplayer, PS chunkFrom, PS chunkTo)
|
||||
{
|
||||
// Get TerritoryAccess for from & to chunks
|
||||
TerritoryAccess accessFrom = BoardColl.get().getTerritoryAccessAt(chunkFrom);
|
||||
TerritoryAccess accessTo = BoardColl.get().getTerritoryAccessAt(chunkTo);
|
||||
|
||||
// See if the status has changed
|
||||
AccessStatus statusFrom = accessFrom.getTerritoryAccess(mplayer);
|
||||
AccessStatus statusTo = accessTo.getTerritoryAccess(mplayer);
|
||||
if (statusFrom == statusTo) return;
|
||||
|
||||
// Inform
|
||||
mplayer.message(statusTo.getStatusMessage());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MOVE CHUNK: AUTO CLAIM
|
||||
// MOVE CHUNK: TRY AUTO CLAIM
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void moveChunkAutoClaim(MPlayer mplayer, PS chunkTo)
|
||||
private static void tryAutoClaim(MPlayer mplayer, PS chunkTo)
|
||||
{
|
||||
// If the player is auto claiming ...
|
||||
Faction autoClaimFaction = mplayer.getAutoClaimFaction();
|
||||
|
Reference in New Issue
Block a user