mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-16 23:35:25 +01:00
Cleanup EngineMoveChunk and use cleaner method structure.
This commit is contained in:
parent
577c164e2a
commit
8f45585a8d
52
src/com/massivecraft/factions/AccessStatus.java
Normal file
52
src/com/massivecraft/factions/AccessStatus.java
Normal file
@ -0,0 +1,52 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
|
||||
import com.massivecraft.massivecore.Colorized;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public enum AccessStatus implements Colorized
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// ENUM
|
||||
// -------------------------------------------- //
|
||||
|
||||
STANDARD(ChatColor.WHITE, null),
|
||||
ELEVATED(ChatColor.GREEN, true),
|
||||
DECREASED(ChatColor.RED, false),
|
||||
|
||||
// END OF LIST
|
||||
;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final ChatColor color;
|
||||
@Override public ChatColor getColor() { return this.color; }
|
||||
|
||||
private final Boolean access;
|
||||
public Boolean hasAccess() { return access; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
AccessStatus(ChatColor color, Boolean access)
|
||||
{
|
||||
this.color = color;
|
||||
this.access = access;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MESSAGE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String getStatusMessage()
|
||||
{
|
||||
ChatColor color = this.getColor();
|
||||
String status = Txt.getNicedEnum(this).toLowerCase();
|
||||
return Txt.parse("%sYou have %s access to this area.", color.toString(), status);
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
|
||||
@ -198,22 +197,25 @@ public class TerritoryAccess
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// HAS CHECK
|
||||
// ACCESS STATUS
|
||||
// -------------------------------------------- //
|
||||
|
||||
// true means elevated access
|
||||
// false means decreased access
|
||||
// null means standard access
|
||||
public Boolean hasTerritoryAccess(MPlayer mplayer)
|
||||
public AccessStatus getTerritoryAccess(MPlayer mplayer)
|
||||
{
|
||||
if (this.isMPlayerGranted(mplayer)) return true;
|
||||
if (this.isMPlayerGranted(mplayer)) return AccessStatus.ELEVATED;
|
||||
|
||||
String factionId = mplayer.getFaction().getId();
|
||||
if (this.getFactionIds().contains(factionId)) return true;
|
||||
if (this.getFactionIds().contains(factionId)) return AccessStatus.ELEVATED;
|
||||
|
||||
if (this.getHostFactionId().equals(factionId) && !this.isHostFactionAllowed()) return false;
|
||||
if (this.getHostFactionId().equals(factionId) && !this.isHostFactionAllowed()) return AccessStatus.DECREASED;
|
||||
|
||||
return null;
|
||||
return AccessStatus.STANDARD;
|
||||
}
|
||||
|
||||
}
|
||||
@Deprecated
|
||||
public Boolean hasTerritoryAccess(MPlayer mplayer)
|
||||
{
|
||||
return this.getTerritoryAccess(mplayer).hasAccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.AccessStatus;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
@ -377,14 +378,15 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
|
||||
if (this.isTerritory())
|
||||
{
|
||||
Boolean hasTerritoryAccess = ta.hasTerritoryAccess(mplayer);
|
||||
if (hasTerritoryAccess != null)
|
||||
AccessStatus accessStatus = ta.getTerritoryAccess(mplayer);
|
||||
if (accessStatus != AccessStatus.STANDARD)
|
||||
{
|
||||
if (verboose && !hasTerritoryAccess)
|
||||
if (verboose && accessStatus == AccessStatus.DECREASED)
|
||||
{
|
||||
mplayer.message(this.createDeniedMessage(mplayer, hostFaction));
|
||||
}
|
||||
return hasTerritoryAccess;
|
||||
|
||||
return accessStatus.hasAccess();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user