2013-04-22 09:37:53 +02:00
package com.massivecraft.factions.entity ;
2011-02-06 13:36:11 +01:00
2011-10-22 16:00:24 +02:00
import java.util.HashSet ;
import java.util.Set ;
2011-10-13 19:47:37 +02:00
2011-02-06 13:36:11 +01:00
import org.bukkit.ChatColor ;
import org.bukkit.entity.Player ;
2011-07-18 22:06:02 +02:00
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.EconomyParticipator ;
import com.massivecraft.factions.FFlag ;
2013-05-13 07:21:11 +02:00
import com.massivecraft.factions.FPerm ;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.Factions ;
import com.massivecraft.factions.Lang ;
import com.massivecraft.factions.Rel ;
import com.massivecraft.factions.RelationParticipator ;
2013-04-24 11:16:37 +02:00
import com.massivecraft.factions.event.FactionsEventChunkChange ;
2013-04-19 14:08:45 +02:00
import com.massivecraft.factions.event.FactionsEventMembershipChange ;
import com.massivecraft.factions.event.FactionsEventMembershipChange.MembershipChangeReason ;
2011-10-12 17:25:01 +02:00
import com.massivecraft.factions.util.RelationUtil ;
2013-04-18 10:35:40 +02:00
import com.massivecraft.mcore.mixin.Mixin ;
2013-04-11 11:11:31 +02:00
import com.massivecraft.mcore.ps.PS ;
2013-04-26 20:22:12 +02:00
import com.massivecraft.mcore.ps.PSFormatHumanSpace ;
2013-04-12 08:56:26 +02:00
import com.massivecraft.mcore.store.SenderEntity ;
2013-04-25 08:34:10 +02:00
import com.massivecraft.mcore.util.MUtil ;
2013-04-24 13:26:59 +02:00
import com.massivecraft.mcore.util.SenderUtil ;
2013-04-25 12:04:01 +02:00
import com.massivecraft.mcore.util.Txt ;
2011-02-06 13:36:11 +01:00
2013-04-22 17:59:51 +02:00
public class UPlayer extends SenderEntity < UPlayer > implements EconomyParticipator
2013-04-12 07:21:38 +02:00
{
// -------------------------------------------- //
2013-04-12 08:56:26 +02:00
// META
2013-04-12 07:21:38 +02:00
// -------------------------------------------- //
2013-04-22 17:59:51 +02:00
public static UPlayer get ( Object oid )
2013-04-12 07:21:38 +02:00
{
2013-04-22 17:59:51 +02:00
return UPlayerColls . get ( ) . get2 ( oid ) ;
2013-04-12 07:21:38 +02:00
}
// -------------------------------------------- //
// OVERRIDE: ENTITY
// -------------------------------------------- //
2013-04-12 08:56:26 +02:00
@Override
2013-04-22 17:59:51 +02:00
public UPlayer load ( UPlayer that )
2013-04-12 07:21:38 +02:00
{
2013-04-17 14:44:08 +02:00
this . setFactionId ( that . factionId ) ;
2013-04-17 15:30:21 +02:00
this . setRole ( that . role ) ;
this . setTitle ( that . title ) ;
2013-04-25 08:01:26 +02:00
this . setPowerBoost ( that . powerBoost ) ;
2013-04-23 12:14:36 +02:00
this . setPower ( that . power ) ;
2013-04-12 07:21:38 +02:00
return this ;
2013-04-12 08:56:26 +02:00
}
@Override
public boolean isDefault ( )
{
2013-04-23 12:14:36 +02:00
if ( this . hasFaction ( ) ) return false ;
// Role means nothing without a faction.
// Title means nothing without a faction.
2013-04-23 14:00:18 +02:00
if ( this . getPowerRounded ( ) ! = ( int ) Math . round ( UConf . get ( this ) . defaultPlayerPower ) ) return false ;
2013-04-17 15:30:21 +02:00
2013-04-12 08:56:26 +02:00
return true ;
}
2013-04-12 07:21:38 +02:00
2013-06-18 09:07:05 +02:00
@Override
public void postAttach ( String id )
{
// If inited ...
if ( ! Factions . get ( ) . isDatabaseInitialized ( ) ) return ;
// ... update the index.
Faction faction = this . getFaction ( ) ;
faction . uplayers . add ( this ) ;
Factions . get ( ) . log ( Txt . parse ( " <g>postAttach added <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>. " , id , Mixin . getDisplayName ( id ) , faction . getId ( ) , faction . getName ( ) ) ) ;
}
@Override
public void preDetach ( String id )
{
// If inited ...
if ( ! Factions . get ( ) . isDatabaseInitialized ( ) ) return ;
// ... update the index.
Faction faction = this . getFaction ( ) ;
faction . uplayers . remove ( this ) ;
Factions . get ( ) . log ( Txt . parse ( " <b>preDetach removed <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>. " , id , Mixin . getDisplayName ( id ) , faction . getId ( ) , faction . getName ( ) ) ) ;
}
2013-04-12 07:21:38 +02:00
// -------------------------------------------- //
2013-04-17 15:30:21 +02:00
// FIELDS: RAW
2013-04-12 07:21:38 +02:00
// -------------------------------------------- //
2013-04-17 15:30:21 +02:00
// In this section of the source code we place the field declarations only.
// Each field has it's own section further down since just the getter and setter logic takes up quite some place.
2013-04-12 07:21:38 +02:00
2013-04-17 15:30:21 +02:00
// This is a foreign key.
2013-04-23 12:14:36 +02:00
// Each player belong to a faction.
2013-04-24 14:31:10 +02:00
// Null means default for the universe.
2013-04-17 14:44:08 +02:00
private String factionId = null ;
2013-04-17 15:30:21 +02:00
// What role does the player have in the faction?
2013-04-24 14:31:10 +02:00
// Null means default for the universe.
2013-04-17 15:30:21 +02:00
private Rel role = null ;
// What title does the player have in the faction?
2013-04-23 12:14:36 +02:00
// The title is just for fun. It's not connected to any game mechanic.
2013-04-17 15:30:21 +02:00
// The player title is similar to the faction description.
//
// Question: Can the title contain chat colors?
// Answer: Yes but in such case the policy is that they already must be parsed using Txt.parse.
2013-04-23 12:14:36 +02:00
// If the title contains raw markup, such as "<white>" instead of "§f" it will not be parsed and "<white>" will be displayed.
2013-04-24 14:31:10 +02:00
//
// Null means the player has no title.
2013-04-17 15:30:21 +02:00
private String title = null ;
2013-04-25 07:53:21 +02:00
// Player usually do not have a powerboost. It defaults to 0.
// The powerBoost is a custom increase/decrease to default and maximum power.
// Note that player powerBoost and faction powerBoost are very similar.
private Double powerBoost = null ;
2013-04-23 12:14:36 +02:00
// Each player has an individual power level.
// The power level for online players is occasionally updated by a recurring task and the power should stay the same for offline players.
// For that reason the value is to be considered correct when you pick it. Do not call the power update method.
2013-04-24 14:31:10 +02:00
// Null means default for the universe.
2013-04-22 16:58:22 +02:00
private Double power = null ;
2013-04-17 15:30:21 +02:00
2013-04-24 15:14:15 +02:00
// The id for the faction this uplayer is currently autoclaiming for.
// NOTE: This field will not be saved to the database ever.
// Null means the player isn't auto claiming.
private transient Faction autoClaimFaction = null ;
public Faction getAutoClaimFaction ( ) { return this . autoClaimFaction ; }
public void setAutoClaimFaction ( Faction autoClaimFaction ) { this . autoClaimFaction = autoClaimFaction ; }
2013-04-17 15:30:21 +02:00
// -------------------------------------------- //
2013-04-24 15:14:15 +02:00
// FIELDS: MULTIVERSE PROXY
2013-04-17 15:30:21 +02:00
// -------------------------------------------- //
2013-04-24 15:14:15 +02:00
public boolean isMapAutoUpdating ( ) { return MPlayer . get ( this ) . isMapAutoUpdating ( ) ; }
public void setMapAutoUpdating ( boolean mapAutoUpdating ) { MPlayer . get ( this ) . setMapAutoUpdating ( mapAutoUpdating ) ; }
2013-04-17 15:30:21 +02:00
2013-04-24 15:14:15 +02:00
public boolean isUsingAdminMode ( ) { return MPlayer . get ( this ) . isUsingAdminMode ( ) ; }
public void setUsingAdminMode ( boolean usingAdminMode ) { MPlayer . get ( this ) . setUsingAdminMode ( usingAdminMode ) ; }
2013-04-17 15:30:21 +02:00
// -------------------------------------------- //
2013-04-23 12:14:36 +02:00
// CORE UTILITIES
2013-04-17 15:30:21 +02:00
// -------------------------------------------- //
2013-04-22 21:00:00 +02:00
public void resetFactionData ( )
2013-04-17 15:30:21 +02:00
{
// The default neutral faction
this . setFactionId ( null ) ;
this . setRole ( null ) ;
this . setTitle ( null ) ;
2013-04-24 15:14:15 +02:00
this . setAutoClaimFaction ( null ) ;
2013-04-17 15:30:21 +02:00
}
2013-04-23 12:14:36 +02:00
/ *
public boolean isPresent ( boolean requireFetchable )
{
if ( ! this . isOnline ( ) ) return false ;
if ( requireFetchable )
{
}
else
{
}
PS ps = Mixin . getSenderPs ( this . getId ( ) ) ;
if ( ps = = null ) return false ;
String psUniverse = Factions . get ( ) . getMultiverse ( ) . getUniverseForWorldName ( ps . getWorld ( ) ) ;
if ( ! psUniverse . equals ( this . getUniverse ( ) ) ) return false ;
if ( ! requireFetchable ) return true ;
Player player = this . getPlayer ( ) ;
if ( player = = null ) return false ;
if ( player . isDead ( ) ) return false ;
return true ;
}
* /
2013-04-17 15:30:21 +02:00
// -------------------------------------------- //
// FIELD: factionId
// -------------------------------------------- //
2013-04-23 14:00:18 +02:00
public String getDefaultFactionId ( )
{
return UConf . get ( this ) . defaultPlayerFactionId ;
}
2013-04-17 15:30:21 +02:00
// This method never returns null
2013-04-17 14:44:08 +02:00
public String getFactionId ( )
2011-10-08 23:22:02 +02:00
{
2013-04-23 14:00:18 +02:00
if ( this . factionId = = null ) return this . getDefaultFactionId ( ) ;
2013-04-17 14:44:08 +02:00
return this . factionId ;
}
2013-04-17 15:30:21 +02:00
// This method never returns null
2013-04-17 14:44:08 +02:00
public Faction getFaction ( )
{
2013-04-22 12:26:13 +02:00
Faction ret = FactionColls . get ( ) . get ( this ) . get ( this . getFactionId ( ) ) ;
2013-04-23 14:00:18 +02:00
if ( ret = = null ) ret = FactionColls . get ( ) . get ( this ) . get ( UConf . get ( this ) . defaultPlayerFactionId ) ;
2013-04-17 14:44:08 +02:00
return ret ;
}
public boolean hasFaction ( )
{
2013-04-24 13:50:02 +02:00
return ! this . getFactionId ( ) . equals ( UConf . get ( this ) . factionIdNone ) ;
2013-04-17 14:44:08 +02:00
}
// This setter is so long because it search for default/null case and takes care of updating the faction member index
public void setFactionId ( String factionId )
{
2013-04-25 08:34:10 +02:00
// Clean input
String target = factionId ;
2013-04-25 08:01:26 +02:00
// Detect Nochange
2013-04-25 08:34:10 +02:00
if ( MUtil . equals ( this . factionId , target ) ) return ;
2013-04-25 08:01:26 +02:00
2013-04-24 18:22:52 +02:00
// Get the raw old value
String oldFactionId = this . factionId ;
2013-04-17 14:44:08 +02:00
2013-04-25 08:01:26 +02:00
// Apply
2013-04-25 08:34:10 +02:00
this . factionId = target ;
2013-04-17 14:44:08 +02:00
2013-04-25 08:01:26 +02:00
// Must be attached and initialized
2013-04-17 14:44:08 +02:00
if ( ! this . attached ( ) ) return ;
2013-04-22 15:05:00 +02:00
if ( ! Factions . get ( ) . isDatabaseInitialized ( ) ) return ;
2013-04-17 14:44:08 +02:00
2013-04-24 18:22:52 +02:00
if ( oldFactionId = = null ) oldFactionId = this . getDefaultFactionId ( ) ;
2013-04-17 14:44:08 +02:00
// Update index
2013-04-22 12:26:13 +02:00
Faction oldFaction = FactionColls . get ( ) . get ( this ) . get ( oldFactionId ) ;
2013-04-25 12:04:01 +02:00
Faction faction = this . getFaction ( ) ;
2013-04-17 14:44:08 +02:00
2013-04-25 12:04:01 +02:00
if ( oldFaction ! = null ) oldFaction . uplayers . remove ( this ) ;
if ( faction ! = null ) faction . uplayers . add ( this ) ;
2013-04-17 14:44:08 +02:00
2013-06-18 09:07:05 +02:00
String oldFactionIdDesc = " NULL " ;
String oldFactionNameDesc = " NULL " ;
if ( oldFaction ! = null )
{
oldFactionIdDesc = oldFaction . getId ( ) ;
oldFactionNameDesc = oldFaction . getName ( ) ;
}
String factionIdDesc = " NULL " ;
String factionNameDesc = " NULL " ;
if ( faction ! = null )
{
factionIdDesc = faction . getId ( ) ;
factionNameDesc = faction . getName ( ) ;
}
Factions . get ( ) . log ( Txt . parse ( " <i>setFactionId moved <h>%s <i>aka <h>%s <i>from <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>. " , this . getId ( ) , Mixin . getDisplayName ( this . getId ( ) ) , oldFactionIdDesc , oldFactionNameDesc , factionIdDesc , factionNameDesc ) ) ;
2013-04-17 14:44:08 +02:00
// Mark as changed
this . changed ( ) ;
}
public void setFaction ( Faction faction )
{
this . setFactionId ( faction . getId ( ) ) ;
2011-10-08 23:22:02 +02:00
}
2013-04-17 15:30:21 +02:00
// -------------------------------------------- //
2011-10-08 23:22:02 +02:00
// FIELD: role
2013-04-17 15:30:21 +02:00
// -------------------------------------------- //
2011-10-08 23:22:02 +02:00
2013-04-23 14:00:18 +02:00
public Rel getDefaultRole ( )
{
return UConf . get ( this ) . defaultPlayerRole ;
}
2013-04-17 15:30:21 +02:00
public Rel getRole ( )
{
2013-04-23 14:00:18 +02:00
if ( this . role = = null ) return this . getDefaultRole ( ) ;
2013-04-17 15:30:21 +02:00
return this . role ;
}
2011-10-08 23:22:02 +02:00
2013-04-17 15:30:21 +02:00
public void setRole ( Rel role )
{
2013-04-25 08:34:10 +02:00
// Clean input
Rel target = role ;
2013-04-25 08:01:26 +02:00
// Detect Nochange
2013-04-25 08:34:10 +02:00
if ( MUtil . equals ( this . role , target ) ) return ;
2013-04-25 08:01:26 +02:00
// Apply
2013-04-25 08:34:10 +02:00
this . role = target ;
2013-04-25 08:01:26 +02:00
// Mark as changed
2013-04-17 15:30:21 +02:00
this . changed ( ) ;
}
2011-10-08 23:22:02 +02:00
2013-04-12 08:11:11 +02:00
// -------------------------------------------- //
2013-04-17 15:30:21 +02:00
// FIELD: title
2013-04-12 08:11:11 +02:00
// -------------------------------------------- //
2013-04-17 15:30:21 +02:00
public boolean hasTitle ( )
{
return this . title ! = null ;
}
2011-10-09 18:35:39 +02:00
2013-04-17 15:30:21 +02:00
public String getTitle ( )
{
if ( this . hasTitle ( ) ) return this . title ;
return Lang . PLAYER_NOTITLE ;
}
2011-10-08 23:22:02 +02:00
2013-04-17 15:30:21 +02:00
public void setTitle ( String title )
{
2013-04-25 08:01:26 +02:00
// Clean input
2013-04-25 08:34:10 +02:00
String target = title ;
if ( target ! = null )
2013-04-17 15:30:21 +02:00
{
2013-04-25 08:34:10 +02:00
target = target . trim ( ) ;
if ( target . length ( ) = = 0 )
2013-04-17 15:30:21 +02:00
{
2013-04-25 08:34:10 +02:00
target = null ;
2013-04-17 15:30:21 +02:00
}
}
2013-04-25 08:01:26 +02:00
2013-04-25 16:54:55 +02:00
// NOTE: That we parse the title here is considered part of the 1.8 --> 2.0 migration.
// This should be removed once the migration phase is considered to be over.
if ( target ! = null )
{
target = Txt . parse ( target ) ;
}
2013-04-25 08:01:26 +02:00
// Detect Nochange
2013-04-25 08:34:10 +02:00
if ( MUtil . equals ( this . title , target ) ) return ;
2013-04-25 08:01:26 +02:00
// Apply
2013-04-25 08:34:10 +02:00
this . title = target ;
2013-04-25 08:01:26 +02:00
// Mark as changed
2013-04-17 15:30:21 +02:00
this . changed ( ) ;
}
2011-10-12 17:25:01 +02:00
2013-04-25 07:53:21 +02:00
// -------------------------------------------- //
// FIELD: powerBoost
// -------------------------------------------- //
public double getPowerBoost ( )
{
Double ret = this . powerBoost ;
if ( ret = = null ) ret = 0D ;
return ret ;
}
public void setPowerBoost ( Double powerBoost )
{
2013-04-25 08:01:26 +02:00
// Clean input
2013-04-25 08:34:10 +02:00
Double target = powerBoost ;
if ( target = = null | | target = = 0 ) target = null ;
2013-04-25 08:01:26 +02:00
// Detect Nochange
2013-04-25 08:34:10 +02:00
if ( MUtil . equals ( this . powerBoost , target ) ) return ;
2013-04-25 08:01:26 +02:00
// Apply
2013-04-25 08:34:10 +02:00
this . powerBoost = target ;
2013-04-25 08:01:26 +02:00
// Mark as changed
2013-04-25 07:53:21 +02:00
this . changed ( ) ;
}
public boolean hasPowerBoost ( )
{
return this . getPowerBoost ( ) ! = 0D ;
}
2013-04-18 10:35:40 +02:00
// -------------------------------------------- //
// FIELD: power
2011-03-22 17:20:21 +01:00
// -------------------------------------------- //
2013-04-23 17:01:43 +02:00
// MIXIN: RAW
public double getPowerMaxUniversal ( )
{
return Factions . get ( ) . getPowerMixin ( ) . getMaxUniversal ( this ) ;
}
public double getPowerMax ( )
{
return Factions . get ( ) . getPowerMixin ( ) . getMax ( this ) ;
}
public double getPowerMin ( )
{
return Factions . get ( ) . getPowerMixin ( ) . getMin ( this ) ;
}
public double getPowerPerHour ( )
{
return Factions . get ( ) . getPowerMixin ( ) . getPerHour ( this ) ;
}
public double getPowerPerDeath ( )
{
return Factions . get ( ) . getPowerMixin ( ) . getPerDeath ( this ) ;
}
// MIXIN: FINER
public double getLimitedPower ( double power )
{
2013-06-20 09:59:36 +02:00
power = Math . max ( power , this . getPowerMin ( ) ) ;
power = Math . min ( power , this . getPowerMax ( ) ) ;
2013-06-18 09:07:05 +02:00
2013-04-23 17:01:43 +02:00
return power ;
}
2013-04-25 17:17:23 +02:00
public int getPowerMaxRounded ( )
{
return ( int ) Math . round ( this . getPowerMax ( ) ) ;
}
public int getPowerMinRounded ( )
{
return ( int ) Math . round ( this . getPowerMin ( ) ) ;
}
public int getPowerMaxUniversalRounded ( )
{
return ( int ) Math . round ( this . getPowerMaxUniversal ( ) ) ;
}
2013-04-18 10:35:40 +02:00
// RAW
2013-04-23 14:00:18 +02:00
public double getDefaultPower ( )
{
return UConf . get ( this ) . defaultPlayerPower ;
}
2013-04-18 10:35:40 +02:00
public double getPower ( )
{
2013-04-22 17:20:34 +02:00
Double ret = this . power ;
2013-04-23 14:00:18 +02:00
if ( ret = = null ) ret = this . getDefaultPower ( ) ;
2013-04-23 17:01:43 +02:00
ret = this . getLimitedPower ( ret ) ;
2013-04-22 17:20:34 +02:00
return ret ;
2013-04-18 10:35:40 +02:00
}
2013-04-23 12:14:36 +02:00
public void setPower ( Double power )
2013-04-18 10:35:40 +02:00
{
2013-04-25 08:34:10 +02:00
// Clean input
Double target = power ;
2013-04-25 08:01:26 +02:00
// Detect Nochange
2013-04-25 08:34:10 +02:00
if ( MUtil . equals ( this . power , target ) ) return ;
2013-04-25 08:01:26 +02:00
// Apply
2013-04-25 08:34:10 +02:00
this . power = target ;
2013-04-25 08:01:26 +02:00
// Mark as changed
2013-04-23 12:14:36 +02:00
this . changed ( ) ;
2013-04-18 10:35:40 +02:00
}
// FINER
public int getPowerRounded ( )
{
return ( int ) Math . round ( this . getPower ( ) ) ;
}
2013-04-12 07:21:38 +02:00
// -------------------------------------------- //
2013-04-24 19:01:17 +02:00
// TITLE, NAME, FACTION NAME AND CHAT
2013-04-12 07:21:38 +02:00
// -------------------------------------------- //
2011-10-08 22:03:44 +02:00
public String getName ( )
{
2013-04-17 15:49:29 +02:00
return this . getFixedId ( ) ;
2011-02-12 18:05:05 +01:00
}
2013-04-24 19:01:17 +02:00
public String getFactionName ( )
2011-10-08 22:03:44 +02:00
{
2013-04-23 14:00:18 +02:00
Faction faction = this . getFaction ( ) ;
if ( faction . isNone ( ) ) return " " ;
2013-04-24 19:01:17 +02:00
return faction . getName ( ) ;
2011-02-12 18:05:05 +01:00
}
// Base concatenations:
2013-04-25 16:54:55 +02:00
public String getNameAndSomething ( String color , String something )
2011-10-08 22:03:44 +02:00
{
2013-04-25 16:54:55 +02:00
String ret = " " ;
ret + = color ;
ret + = this . getRole ( ) . getPrefix ( ) ;
2013-04-25 16:02:37 +02:00
if ( something ! = null & & something . length ( ) > 0 )
2013-04-17 15:30:21 +02:00
{
2013-04-25 16:54:55 +02:00
ret + = something ;
ret + = " " ;
ret + = color ;
2011-02-12 18:05:05 +01:00
}
ret + = this . getName ( ) ;
return ret ;
}
2013-04-25 16:54:55 +02:00
public String getNameAndFactionName ( )
{
return this . getNameAndSomething ( " " , this . getFactionName ( ) ) ;
}
public String getNameAndTitle ( String color )
2011-10-08 22:03:44 +02:00
{
2013-04-17 15:30:21 +02:00
if ( this . hasTitle ( ) )
{
2013-04-25 16:54:55 +02:00
return this . getNameAndSomething ( color , this . getTitle ( ) ) ;
2013-04-17 15:30:21 +02:00
}
else
{
2013-04-25 16:54:55 +02:00
return this . getNameAndSomething ( color , null ) ;
2013-04-17 15:30:21 +02:00
}
2011-02-12 18:05:05 +01:00
}
// Colored concatenations:
// These are used in information messages
2011-10-08 22:03:44 +02:00
public String getNameAndTitle ( Faction faction )
{
2013-04-25 16:54:55 +02:00
return this . getNameAndTitle ( this . getColorTo ( faction ) . toString ( ) ) ;
2011-02-12 18:05:05 +01:00
}
2013-04-22 17:59:51 +02:00
public String getNameAndTitle ( UPlayer uplayer )
2011-10-08 22:03:44 +02:00
{
2013-04-25 16:54:55 +02:00
return this . getNameAndTitle ( this . getColorTo ( uplayer ) . toString ( ) ) ;
2011-02-12 18:05:05 +01:00
}
2013-04-12 07:21:38 +02:00
// -------------------------------------------- //
2013-04-11 11:11:31 +02:00
// RELATION AND RELATION COLORS
2013-04-12 07:21:38 +02:00
// -------------------------------------------- //
2011-02-12 18:05:05 +01:00
2011-10-12 17:25:01 +02:00
@Override
2011-10-24 11:07:06 +02:00
public String describeTo ( RelationParticipator observer , boolean ucfirst )
2011-10-08 22:03:44 +02:00
{
2011-10-24 11:07:06 +02:00
return RelationUtil . describeThatToMe ( this , observer , ucfirst ) ;
2011-02-12 18:05:05 +01:00
}
2011-10-12 17:25:01 +02:00
@Override
2011-10-24 11:07:06 +02:00
public String describeTo ( RelationParticipator observer )
2011-10-08 22:03:44 +02:00
{
2011-10-24 11:07:06 +02:00
return RelationUtil . describeThatToMe ( this , observer ) ;
2011-02-12 18:05:05 +01:00
}
2011-10-12 17:25:01 +02:00
@Override
2011-10-24 11:07:06 +02:00
public Rel getRelationTo ( RelationParticipator observer )
2011-10-08 22:03:44 +02:00
{
2011-10-24 11:07:06 +02:00
return RelationUtil . getRelationOfThatToMe ( this , observer ) ;
2011-08-04 07:07:38 +02:00
}
2011-10-12 17:25:01 +02:00
@Override
2011-10-24 11:07:06 +02:00
public Rel getRelationTo ( RelationParticipator observer , boolean ignorePeaceful )
2011-10-08 22:03:44 +02:00
{
2011-10-24 11:07:06 +02:00
return RelationUtil . getRelationOfThatToMe ( this , observer , ignorePeaceful ) ;
2011-02-12 18:05:05 +01:00
}
2011-10-12 17:25:01 +02:00
@Override
2011-10-24 11:07:06 +02:00
public ChatColor getColorTo ( RelationParticipator observer )
2011-10-12 17:25:01 +02:00
{
2011-10-24 11:07:06 +02:00
return RelationUtil . getColorOfThatToMe ( this , observer ) ;
2011-10-12 17:25:01 +02:00
}
2011-02-12 18:05:05 +01:00
2013-04-12 07:21:38 +02:00
// -------------------------------------------- //
2013-04-11 11:11:31 +02:00
// HEALTH
2013-04-12 07:21:38 +02:00
// -------------------------------------------- //
2011-10-08 22:03:44 +02:00
public void heal ( int amnt )
{
2011-02-06 13:36:11 +01:00
Player player = this . getPlayer ( ) ;
2011-10-08 22:03:44 +02:00
if ( player = = null )
{
2011-02-06 13:36:11 +01:00
return ;
}
player . setHealth ( player . getHealth ( ) + amnt ) ;
}
2013-04-12 07:21:38 +02:00
// -------------------------------------------- //
2013-04-11 11:11:31 +02:00
// TERRITORY
2013-04-12 07:21:38 +02:00
// -------------------------------------------- //
2011-10-08 22:03:44 +02:00
public boolean isInOwnTerritory ( )
{
2013-07-31 14:50:28 +02:00
PS ps = Mixin . getSenderPs ( this . getId ( ) ) ;
if ( ps = = null ) return false ;
return BoardColls . get ( ) . getFactionAt ( ps ) = = this . getFaction ( ) ;
2011-02-06 13:36:11 +01:00
}
2011-08-04 07:07:38 +02:00
2011-10-08 22:03:44 +02:00
public boolean isInEnemyTerritory ( )
{
2013-07-31 14:50:28 +02:00
PS ps = Mixin . getSenderPs ( this . getId ( ) ) ;
if ( ps = = null ) return false ;
return BoardColls . get ( ) . getFactionAt ( ps ) . getRelationTo ( this ) = = Rel . ENEMY ;
2011-02-06 13:36:11 +01:00
}
2013-04-12 07:21:38 +02:00
// -------------------------------------------- //
2013-04-11 11:11:31 +02:00
// ACTIONS
2013-04-12 07:21:38 +02:00
// -------------------------------------------- //
2011-03-22 20:36:33 +01:00
2013-04-24 08:39:26 +02:00
public void leave ( )
2011-10-08 22:03:44 +02:00
{
2011-03-22 20:36:33 +01:00
Faction myFaction = this . getFaction ( ) ;
2011-12-18 14:50:41 +01:00
2013-04-19 14:08:45 +02:00
boolean permanent = myFaction . getFlag ( FFlag . PERMANENT ) ;
2011-03-22 20:36:33 +01:00
2013-04-24 13:26:59 +02:00
if ( myFaction . getUPlayers ( ) . size ( ) > 1 )
2011-10-08 22:03:44 +02:00
{
2013-04-24 13:26:59 +02:00
if ( ! permanent & & this . getRole ( ) = = Rel . LEADER )
{
msg ( " <b>You must give the leader role to someone else first. " ) ;
return ;
}
if ( ! UConf . get ( myFaction ) . canLeaveWithNegativePower & & this . getPower ( ) < 0 )
{
msg ( " <b>You cannot leave until your power is positive. " ) ;
return ;
}
2011-05-29 23:41:50 +02:00
}
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
2013-04-19 14:08:45 +02:00
// Event
2013-04-25 16:02:37 +02:00
FactionsEventMembershipChange membershipChangeEvent = new FactionsEventMembershipChange ( this . getSender ( ) , this , myFaction , MembershipChangeReason . LEAVE ) ;
2013-04-19 14:08:45 +02:00
membershipChangeEvent . run ( ) ;
if ( membershipChangeEvent . isCancelled ( ) ) return ;
2011-10-13 19:47:37 +02:00
2011-10-08 22:03:44 +02:00
if ( myFaction . isNormal ( ) )
{
2013-04-22 17:59:51 +02:00
for ( UPlayer uplayer : myFaction . getUPlayersWhereOnline ( true ) )
2011-10-12 21:54:38 +02:00
{
2013-04-22 17:59:51 +02:00
uplayer . msg ( " %s<i> left %s<i>. " , this . describeTo ( uplayer , true ) , myFaction . describeTo ( uplayer ) ) ;
2011-10-12 21:54:38 +02:00
}
Additional logging, with new conf.json settings to enable/disable logging of specific events:
"logFactionCreate": true, - log faction creation
"logFactionDisband": true, - log factions being disbanded, by command or by circumstance
"logFactionJoin": true, - log player joining a faction
"logFactionKick": true, - log player being kicked from a faction
"logFactionLeave": true, - log player leaving a faction
"logLandClaims": true, - log land being claimed (including safe zone and war zone)
"logLandUnclaims": true, - log land being unclaimed (including safe zone and war zone)
"logMoneyTransactions": true, - log money being deposited, withdrawn, and otherwise transferred in relation to faction banks
Also a fix for a potential NPE from players logging out and Spout appearance handler referencing them afterwards
2011-10-23 19:50:02 +02:00
2013-04-22 10:05:03 +02:00
if ( MConf . get ( ) . logFactionLeave )
{
2013-04-24 19:01:17 +02:00
Factions . get ( ) . log ( this . getName ( ) + " left the faction: " + myFaction . getName ( ) ) ;
2013-04-22 10:05:03 +02:00
}
2011-04-28 22:45:43 +02:00
}
2011-10-13 19:47:37 +02:00
2011-10-13 06:44:59 +02:00
this . resetFactionData ( ) ;
2013-04-22 17:59:51 +02:00
if ( myFaction . isNormal ( ) & & ! permanent & & myFaction . getUPlayers ( ) . isEmpty ( ) )
2011-10-08 22:03:44 +02:00
{
2011-03-22 20:36:33 +01:00
// Remove this faction
2013-04-22 17:59:51 +02:00
for ( UPlayer uplayer : UPlayerColls . get ( ) . get ( this ) . getAllOnline ( ) )
2011-10-08 22:03:44 +02:00
{
2013-04-22 17:59:51 +02:00
uplayer . msg ( " <i>%s<i> was disbanded. " , myFaction . describeTo ( uplayer , true ) ) ;
2011-03-22 20:36:33 +01:00
}
2011-10-13 06:44:59 +02:00
2013-04-22 10:05:03 +02:00
if ( MConf . get ( ) . logFactionDisband )
{
2013-04-24 19:01:17 +02:00
Factions . get ( ) . log ( " The faction " + myFaction . getName ( ) + " ( " + myFaction . getId ( ) + " ) was disbanded due to the last player ( " + this . getName ( ) + " ) leaving. " ) ;
2013-04-22 10:05:03 +02:00
}
2013-06-18 09:07:05 +02:00
myFaction . detach ( ) ;
2011-03-22 20:36:33 +01:00
}
}
2013-04-24 13:26:59 +02:00
public boolean tryClaim ( Faction newFaction , PS ps , boolean verbooseChange , boolean verbooseSame )
2011-10-08 22:03:44 +02:00
{
2013-04-24 13:26:59 +02:00
PS chunk = ps . getChunk ( true ) ;
Faction oldFaction = BoardColls . get ( ) . getFactionAt ( chunk ) ;
2013-04-11 11:11:31 +02:00
2013-04-24 13:26:59 +02:00
UConf uconf = UConf . get ( newFaction ) ;
MConf mconf = MConf . get ( ) ;
2011-10-22 16:00:24 +02:00
2013-04-24 13:26:59 +02:00
// Validate
if ( newFaction = = oldFaction )
2011-10-08 22:03:44 +02:00
{
2013-04-24 13:26:59 +02:00
msg ( " %s<i> already owns this land. " , newFaction . describeTo ( this , true ) ) ;
2011-10-22 16:00:24 +02:00
return true ;
2011-06-10 21:26:12 +02:00
}
2013-04-24 13:26:59 +02:00
2013-05-13 07:21:11 +02:00
if ( ! this . isUsingAdminMode ( ) )
2011-10-08 22:03:44 +02:00
{
2013-05-13 07:21:11 +02:00
if ( newFaction . isNormal ( ) )
2013-04-24 13:26:59 +02:00
{
2013-05-13 07:21:11 +02:00
if ( mconf . worldsNoClaiming . contains ( ps . getWorld ( ) ) )
{
msg ( " <b>Sorry, this world has land claiming disabled. " ) ;
return false ;
}
if ( ! FPerm . TERRITORY . has ( this , newFaction , true ) )
{
return false ;
}
if ( newFaction . getUPlayers ( ) . size ( ) < uconf . claimsRequireMinFactionMembers )
{
msg ( " Factions must have at least <h>%s<b> members to claim land. " , uconf . claimsRequireMinFactionMembers ) ;
return false ;
}
int ownedLand = newFaction . getLandCount ( ) ;
if ( uconf . claimedLandsMax ! = 0 & & ownedLand > = uconf . claimedLandsMax & & ! newFaction . getFlag ( FFlag . INFPOWER ) )
{
msg ( " <b>Limit reached. You can't claim more land. " ) ;
return false ;
}
if ( ownedLand > = newFaction . getPowerRounded ( ) )
{
msg ( " <b>You can't claim more land. You need more power. " ) ;
return false ;
}
2013-04-25 12:04:01 +02:00
if
(
uconf . claimsMustBeConnected
2013-05-29 14:31:09 +02:00
& &
newFaction . getLandCountInWorld ( ps . getWorld ( ) ) > 0
& &
! BoardColls . get ( ) . isConnectedPs ( chunk , newFaction )
& &
( ! uconf . claimsCanBeUnconnectedIfOwnedByOtherFaction | | oldFaction . isNone ( ) )
2013-04-25 12:04:01 +02:00
)
{
if ( uconf . claimsCanBeUnconnectedIfOwnedByOtherFaction )
{
msg ( " <b>You can only claim additional land which is connected to your first claim or controlled by another faction! " ) ;
}
else
{
msg ( " <b>You can only claim additional land which is connected to your first claim! " ) ;
}
return false ;
}
2013-05-17 08:10:46 +02:00
}
if ( oldFaction . isNormal ( ) )
{
2013-05-13 07:21:11 +02:00
if ( ! FPerm . TERRITORY . has ( this , oldFaction , false ) )
2013-04-25 12:04:01 +02:00
{
2013-05-17 08:10:46 +02:00
if ( ! uconf . claimingFromOthersAllowed )
{
msg ( " <b>You may not claim land from others. " ) ;
return false ;
}
if ( oldFaction . getRelationTo ( newFaction ) . isAtLeast ( Rel . TRUCE ) )
{
msg ( " <b>You can't claim this land due to your relation with the current owner. " ) ;
return false ;
}
2013-05-13 07:21:11 +02:00
if ( ! oldFaction . hasLandInflation ( ) )
{
msg ( " %s<i> owns this land and is strong enough to keep it. " , oldFaction . getName ( this ) ) ;
return false ;
}
2013-05-17 08:37:32 +02:00
if ( ! BoardColls . get ( ) . isBorderPs ( chunk ) )
2013-05-13 07:21:11 +02:00
{
msg ( " <b>You must start claiming land at the border of the territory. " ) ;
return false ;
}
2013-04-24 13:26:59 +02:00
}
2011-06-10 21:26:12 +02:00
}
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
}
2011-10-22 16:00:24 +02:00
2013-04-19 12:44:28 +02:00
// Event
2013-04-24 13:26:59 +02:00
FactionsEventChunkChange event = new FactionsEventChunkChange ( sender , chunk , newFaction ) ;
2013-04-19 12:44:28 +02:00
event . run ( ) ;
if ( event . isCancelled ( ) ) return false ;
2012-03-13 15:48:34 +01:00
2013-04-24 13:26:59 +02:00
// Apply
BoardColls . get ( ) . setFactionAt ( chunk , newFaction ) ;
// Inform
Set < UPlayer > informees = new HashSet < UPlayer > ( ) ;
informees . add ( this ) ;
if ( newFaction . isNormal ( ) )
2011-10-08 22:03:44 +02:00
{
2013-04-24 13:26:59 +02:00
informees . addAll ( newFaction . getUPlayers ( ) ) ;
}
if ( oldFaction . isNormal ( ) )
{
informees . addAll ( oldFaction . getUPlayers ( ) ) ;
Added basic support for iConomy, where most Factions commands can be made to cost (or give) money. For claiming land, there are some extra features. Each additional land claimed by default costs more than the last, with the multiplier being configurable. For example, the first claim might cost $30, the 2nd $45, the third $60, and so forth. When land is claimed from a weakened faction, there is a configurable bonus amount of money deducted from the cost of claiming the land, as an incentive; this number can be changed to a negative value to instead make it cost more to claim such land. When land is unclaimed, a configurable percentage of the cost of claiming the land can be refunded (defaults to 70% of the cost). The total value of a faction's claimed land is now shown in the info given by /f who [faction tag], along with the depreciated (refund) value.
2011-08-02 01:05:01 +02:00
}
2013-04-22 10:05:03 +02:00
if ( MConf . get ( ) . logLandClaims )
{
2013-04-24 13:26:59 +02:00
informees . add ( UPlayer . get ( SenderUtil . getConsole ( ) ) ) ;
}
2013-04-26 20:22:12 +02:00
String chunkString = chunk . toString ( PSFormatHumanSpace . get ( ) ) ;
String typeString = event . getType ( ) . toString ( ) . toLowerCase ( ) ;
2013-04-24 13:26:59 +02:00
for ( UPlayer informee : informees )
{
2013-04-26 20:22:12 +02:00
informee . msg ( " <h>%s<i> did %s %s <i>for <h>%s<i> from <h>%s<i>. " , this . describeTo ( informee , true ) , typeString , chunkString , newFaction . describeTo ( informee ) , oldFaction . describeTo ( informee ) ) ;
2013-04-22 10:05:03 +02:00
}
Additional logging, with new conf.json settings to enable/disable logging of specific events:
"logFactionCreate": true, - log faction creation
"logFactionDisband": true, - log factions being disbanded, by command or by circumstance
"logFactionJoin": true, - log player joining a faction
"logFactionKick": true, - log player being kicked from a faction
"logFactionLeave": true, - log player leaving a faction
"logLandClaims": true, - log land being claimed (including safe zone and war zone)
"logLandUnclaims": true, - log land being unclaimed (including safe zone and war zone)
"logMoneyTransactions": true, - log money being deposited, withdrawn, and otherwise transferred in relation to faction banks
Also a fix for a potential NPE from players logging out and Spout appearance handler referencing them afterwards
2011-10-23 19:50:02 +02:00
2011-06-10 21:26:12 +02:00
return true ;
}
2011-03-19 13:00:03 +01:00
2013-01-06 21:44:29 +01:00
}