Cleanup EngineMoveChunk and use cleaner method structure.
This commit is contained in:
		
							
								
								
									
										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;
 | 
					package com.massivecraft.factions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.massivecraft.factions.entity.Faction;
 | 
					import com.massivecraft.factions.entity.Faction;
 | 
				
			||||||
import com.massivecraft.factions.entity.FactionColl;
 | 
					 | 
				
			||||||
import com.massivecraft.factions.entity.MPlayer;
 | 
					import com.massivecraft.factions.entity.MPlayer;
 | 
				
			||||||
import com.massivecraft.massivecore.collections.MassiveSet;
 | 
					import com.massivecraft.massivecore.collections.MassiveSet;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -198,22 +197,25 @@ public class TerritoryAccess
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	// HAS CHECK
 | 
						// ACCESS STATUS
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	// true means elevated access
 | 
						public AccessStatus getTerritoryAccess(MPlayer mplayer)
 | 
				
			||||||
	// false means decreased access
 | 
					 | 
				
			||||||
	// null means standard access
 | 
					 | 
				
			||||||
	public Boolean hasTerritoryAccess(MPlayer mplayer)
 | 
					 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (this.isMPlayerGranted(mplayer)) return true;
 | 
							if (this.isMPlayerGranted(mplayer)) return AccessStatus.ELEVATED;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		String factionId = mplayer.getFaction().getId();
 | 
							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;
 | 
					package com.massivecraft.factions.engine;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.massivecraft.factions.AccessStatus;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.Const;
 | 
				
			||||||
import com.massivecraft.factions.TerritoryAccess;
 | 
					import com.massivecraft.factions.TerritoryAccess;
 | 
				
			||||||
import com.massivecraft.factions.entity.BoardColl;
 | 
					import com.massivecraft.factions.entity.BoardColl;
 | 
				
			||||||
import com.massivecraft.factions.entity.Faction;
 | 
					import com.massivecraft.factions.entity.Faction;
 | 
				
			||||||
@@ -46,72 +48,58 @@ public class EngineMoveChunk extends Engine
 | 
				
			|||||||
		PS chunkFrom = PS.valueOf(event.getFrom()).getChunk(true);
 | 
							PS chunkFrom = PS.valueOf(event.getFrom()).getChunk(true);
 | 
				
			||||||
		PS chunkTo = PS.valueOf(event.getTo()).getChunk(true);
 | 
							PS chunkTo = PS.valueOf(event.getTo()).getChunk(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Faction factionFrom = BoardColl.get().getFactionAt(chunkFrom);
 | 
							// ... send info onwards and try auto-claiming.
 | 
				
			||||||
		Faction factionTo = BoardColl.get().getFactionAt(chunkTo);
 | 
							sendChunkInfo(mplayer, player, chunkFrom, chunkTo);
 | 
				
			||||||
 | 
							tryAutoClaim(mplayer, chunkTo);
 | 
				
			||||||
		// ... and send info onwards.
 | 
					 | 
				
			||||||
		this.moveChunkTerritoryInfo(mplayer, player, chunkFrom, chunkTo, factionFrom, factionTo);
 | 
					 | 
				
			||||||
		this.moveChunkAutoClaim(mplayer, chunkTo);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	// MOVE CHUNK: TERRITORY INFO
 | 
						// MOVE CHUNK: SEND CHUNK INFO
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public void moveChunkTerritoryInfo(MPlayer mplayer, Player player, PS chunkFrom, PS chunkTo, Faction factionFrom, Faction factionTo)
 | 
						private static void sendChunkInfo(MPlayer mplayer, Player player, PS chunkFrom, PS chunkTo)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// send host faction info updates
 | 
							sendAutoMapUpdate(mplayer, player);
 | 
				
			||||||
		if (mplayer.isMapAutoUpdating())
 | 
							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);
 | 
							AsciiMap map = new AsciiMap(mplayer, player, false);
 | 
				
			||||||
		mplayer.message(map.render());
 | 
							mplayer.message(map.render());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
		else if (factionFrom != factionTo)
 | 
						
 | 
				
			||||||
 | 
						private static void sendFactionTerritoryInfo(MPlayer mplayer, Player player, PS chunkFrom, PS chunkTo)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
							Faction factionFrom = BoardColl.get().getFactionAt(chunkFrom);
 | 
				
			||||||
 | 
							Faction factionTo = BoardColl.get().getFactionAt(chunkTo);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if (factionFrom == factionTo) return;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
		if (mplayer.isTerritoryInfoTitles())
 | 
							if (mplayer.isTerritoryInfoTitles())
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
				String maintitle = parseTerritoryInfo(MConf.get().territoryInfoTitlesMain, mplayer, factionTo);
 | 
								String titleMain = parseTerritoryInfo(MConf.get().territoryInfoTitlesMain, mplayer, factionTo);
 | 
				
			||||||
				String subtitle = parseTerritoryInfo(MConf.get().territoryInfoTitlesSub, mplayer, factionTo);
 | 
								String titleSub = parseTerritoryInfo(MConf.get().territoryInfoTitlesSub, mplayer, factionTo);
 | 
				
			||||||
				MixinTitle.get().sendTitleMessage(player, MConf.get().territoryInfoTitlesTicksIn, MConf.get().territoryInfoTitlesTicksStay, MConf.get().territoryInfoTitleTicksOut, maintitle, subtitle);
 | 
								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
 | 
							else
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			String message = parseTerritoryInfo(MConf.get().territoryInfoChat, mplayer, factionTo);
 | 
								String message = parseTerritoryInfo(MConf.get().territoryInfoChat, mplayer, factionTo);
 | 
				
			||||||
				MixinMessage.get().messageOne(player, message);
 | 
								player.sendMessage(message);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
		// Show access level message if it changed.
 | 
						private static String parseTerritoryInfo(String string, MPlayer mplayer, Faction faction)
 | 
				
			||||||
		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.");
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	public String parseTerritoryInfo(String string, MPlayer mplayer, Faction faction)
 | 
					 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (string == null) throw new NullPointerException("string");
 | 
							if (string == null) throw new NullPointerException("string");
 | 
				
			||||||
		if (faction == null) throw new NullPointerException("faction");
 | 
							if (faction == null) throw new NullPointerException("faction");
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		string = Txt.parse(string);
 | 
							string = Txt.parse(string);
 | 
				
			||||||
 | 
					 | 
				
			||||||
		string = string.replace("{name}", faction.getName());
 | 
							string = string.replace("{name}", faction.getName());
 | 
				
			||||||
		string = string.replace("{relcolor}", faction.getColorTo(mplayer).toString());
 | 
							string = string.replace("{relcolor}", faction.getColorTo(mplayer).toString());
 | 
				
			||||||
		string = string.replace("{desc}", faction.getDescriptionDesc());
 | 
							string = string.replace("{desc}", faction.getDescriptionDesc());
 | 
				
			||||||
@@ -119,11 +107,26 @@ public class EngineMoveChunk extends Engine
 | 
				
			|||||||
		return string;
 | 
							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 ...
 | 
							// If the player is auto claiming ...
 | 
				
			||||||
		Faction autoClaimFaction = mplayer.getAutoClaimFaction();
 | 
							Faction autoClaimFaction = mplayer.getAutoClaimFaction();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
package com.massivecraft.factions.entity;
 | 
					package com.massivecraft.factions.entity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.massivecraft.factions.AccessStatus;
 | 
				
			||||||
import com.massivecraft.factions.Perm;
 | 
					import com.massivecraft.factions.Perm;
 | 
				
			||||||
import com.massivecraft.factions.Rel;
 | 
					import com.massivecraft.factions.Rel;
 | 
				
			||||||
import com.massivecraft.factions.TerritoryAccess;
 | 
					import com.massivecraft.factions.TerritoryAccess;
 | 
				
			||||||
@@ -377,14 +378,15 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		if (this.isTerritory())
 | 
							if (this.isTerritory())
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Boolean hasTerritoryAccess = ta.hasTerritoryAccess(mplayer);
 | 
								AccessStatus accessStatus = ta.getTerritoryAccess(mplayer);
 | 
				
			||||||
			if (hasTerritoryAccess != null)
 | 
								if (accessStatus != AccessStatus.STANDARD)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				if (verboose && !hasTerritoryAccess)
 | 
									if (verboose && accessStatus == AccessStatus.DECREASED)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					mplayer.message(this.createDeniedMessage(mplayer, hostFaction));
 | 
										mplayer.message(this.createDeniedMessage(mplayer, hostFaction));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				return hasTerritoryAccess;
 | 
									
 | 
				
			||||||
 | 
									return accessStatus.hasAccess();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user