2011-07-18 22:06:02 +02:00
package com.massivecraft.factions.listeners ;
2011-02-06 13:36:11 +01:00
2014-04-04 20:55:21 +02:00
import com.massivecraft.factions.* ;
import com.massivecraft.factions.struct.Permission ;
import com.massivecraft.factions.struct.Relation ;
import com.massivecraft.factions.struct.Role ;
import com.massivecraft.factions.zcore.util.TextUtil ;
2011-03-23 17:39:56 +01:00
import org.bukkit.Location ;
2011-03-23 12:00:38 +01:00
import org.bukkit.Material ;
2011-03-08 13:06:52 +01:00
import org.bukkit.block.Block ;
2011-03-22 18:48:09 +01:00
import org.bukkit.entity.Player ;
2012-01-28 11:37:55 +01:00
import org.bukkit.event.EventHandler ;
import org.bukkit.event.EventPriority ;
import org.bukkit.event.Listener ;
2011-03-30 06:37:32 +02:00
import org.bukkit.event.block.Action ;
2014-04-04 20:55:21 +02:00
import org.bukkit.event.player.* ;
2012-03-19 13:59:44 +01:00
import org.bukkit.util.NumberConversions ;
2011-07-18 22:06:02 +02:00
2014-04-04 20:55:21 +02:00
import java.util.HashMap ;
import java.util.Iterator ;
import java.util.Map ;
2011-02-06 13:36:11 +01:00
2011-03-08 13:06:52 +01:00
2014-04-04 20:55:21 +02:00
public class FactionsPlayerListener implements Listener {
public P p ;
public FactionsPlayerListener ( P p ) {
this . p = p ;
}
@EventHandler ( priority = EventPriority . NORMAL )
public void onPlayerJoin ( PlayerJoinEvent event ) {
// Make sure that all online players do have a fplayer.
final FPlayer me = FPlayers . i . get ( event . getPlayer ( ) ) ;
// Update the lastLoginTime for this fplayer
me . setLastLoginTime ( System . currentTimeMillis ( ) ) ;
// Store player's current FLocation and notify them where they are
me . setLastStoodAt ( new FLocation ( event . getPlayer ( ) . getLocation ( ) ) ) ;
}
@EventHandler ( priority = EventPriority . NORMAL )
public void onPlayerQuit ( PlayerQuitEvent event ) {
FPlayer me = FPlayers . i . get ( event . getPlayer ( ) ) ;
// Make sure player's power is up to date when they log off.
me . getPower ( ) ;
// and update their last login time to point to when the logged off, for auto-remove routine
me . setLastLoginTime ( System . currentTimeMillis ( ) ) ;
2014-07-01 21:52:40 +02:00
Faction myFaction = me . getFaction ( ) ; if ( myFaction ! = null ) {
2014-04-04 20:55:21 +02:00
myFaction . memberLoggedOff ( ) ;
}
}
@EventHandler ( priority = EventPriority . MONITOR )
public void onPlayerMove ( PlayerMoveEvent event ) {
2014-07-01 21:49:42 +02:00
if ( event . isCancelled ( ) ) { return ; }
2014-04-04 20:55:21 +02:00
// quick check to make sure player is moving between chunks; good performance boost
2014-07-01 21:52:40 +02:00
if ( event . getFrom ( ) . getBlockX ( ) > > 4 = = event . getTo ( ) . getBlockX ( ) > > 4 & & event . getFrom ( ) . getBlockZ ( ) > > 4 = = event . getTo ( ) . getBlockZ ( ) > > 4 & & event . getFrom ( ) . getWorld ( ) = = event . getTo ( ) . getWorld ( ) ) {
return ;
}
2014-04-04 20:55:21 +02:00
2014-07-01 21:52:40 +02:00
Player player = event . getPlayer ( ) ; FPlayer me = FPlayers . i . get ( player ) ;
2014-04-04 20:55:21 +02:00
// Did we change coord?
2014-07-01 21:52:40 +02:00
FLocation from = me . getLastStoodAt ( ) ; FLocation to = new FLocation ( event . getTo ( ) ) ;
2014-04-04 20:55:21 +02:00
if ( from . equals ( to ) ) {
return ;
}
// Yes we did change coord (:
me . setLastStoodAt ( to ) ;
// Did we change "host"(faction)?
2014-07-01 21:52:40 +02:00
Faction factionFrom = Board . getFactionAt ( from ) ; Faction factionTo = Board . getFactionAt ( to ) ;
2014-04-04 20:55:21 +02:00
boolean changedFaction = ( factionFrom ! = factionTo ) ;
2014-05-19 18:14:55 +02:00
/ * Was used for displaying on Spout but we removed Spout compatibility .
2014-04-06 00:00:33 +02:00
if ( changedFaction )
2014-04-04 20:55:21 +02:00
changedFaction = false ;
2014-05-19 18:14:55 +02:00
* /
2014-04-04 20:55:21 +02:00
if ( me . isMapAutoUpdating ( ) ) {
me . sendMessage ( Board . getMap ( me . getFaction ( ) , to , player . getLocation ( ) . getYaw ( ) ) ) ;
2014-07-01 21:52:40 +02:00
} else {
Faction myFaction = me . getFaction ( ) ; String ownersTo = myFaction . getOwnerListString ( to ) ;
2014-04-04 20:55:21 +02:00
if ( changedFaction ) {
me . sendFactionHereMessage ( ) ;
2014-07-01 21:49:42 +02:00
if ( Conf . ownedAreasEnabled & & Conf . ownedMessageOnBorder & & myFaction = = factionTo & & ! ownersTo . isEmpty ( ) ) {
2014-04-04 20:55:21 +02:00
me . sendMessage ( Conf . ownedLandMessage + ownersTo ) ;
}
2014-07-01 21:52:40 +02:00
} else if ( Conf . ownedAreasEnabled & & Conf . ownedMessageInsideTerritory & & factionFrom = = factionTo & & myFaction = = factionTo ) {
2014-04-04 20:55:21 +02:00
String ownersFrom = myFaction . getOwnerListString ( from ) ;
if ( Conf . ownedMessageByChunk | | ! ownersFrom . equals ( ownersTo ) ) {
2014-07-01 21:52:40 +02:00
if ( ! ownersTo . isEmpty ( ) ) {
me . sendMessage ( Conf . ownedLandMessage + ownersTo ) ;
} else if ( ! Conf . publicLandMessage . isEmpty ( ) ) { me . sendMessage ( Conf . publicLandMessage ) ; }
2014-04-04 20:55:21 +02:00
}
}
}
if ( me . getAutoClaimFor ( ) ! = null ) {
me . attemptClaim ( me . getAutoClaimFor ( ) , event . getTo ( ) , true ) ;
2014-07-01 21:52:40 +02:00
} else if ( me . isAutoSafeClaimEnabled ( ) ) {
2014-04-04 20:55:21 +02:00
if ( ! Permission . MANAGE_SAFE_ZONE . has ( player ) ) {
me . setIsAutoSafeClaimEnabled ( false ) ;
2014-07-01 21:52:40 +02:00
} else {
2014-04-04 20:55:21 +02:00
if ( ! Board . getFactionAt ( to ) . isSafeZone ( ) ) {
2014-07-01 21:52:40 +02:00
Board . setFactionAt ( Factions . i . getSafeZone ( ) , to ) ; me . msg ( " <i>This land is now a safe zone. " ) ;
2014-04-04 20:55:21 +02:00
}
}
2014-07-01 21:52:40 +02:00
} else if ( me . isAutoWarClaimEnabled ( ) ) {
2014-04-04 20:55:21 +02:00
if ( ! Permission . MANAGE_WAR_ZONE . has ( player ) ) {
me . setIsAutoWarClaimEnabled ( false ) ;
2014-07-01 21:52:40 +02:00
} else {
2014-04-04 20:55:21 +02:00
if ( ! Board . getFactionAt ( to ) . isWarZone ( ) ) {
2014-07-01 21:52:40 +02:00
Board . setFactionAt ( Factions . i . getWarZone ( ) , to ) ; me . msg ( " <i>This land is now a war zone. " ) ;
2014-04-04 20:55:21 +02:00
}
}
}
}
@EventHandler ( priority = EventPriority . NORMAL )
public void onPlayerInteract ( PlayerInteractEvent event ) {
2014-07-01 21:49:42 +02:00
if ( event . isCancelled ( ) ) { return ; }
2014-04-04 20:55:21 +02:00
// only need to check right-clicks and physical as of MC 1.4+; good performance boost
2014-07-01 21:49:42 +02:00
if ( event . getAction ( ) ! = Action . RIGHT_CLICK_BLOCK & & event . getAction ( ) ! = Action . PHYSICAL ) { return ; }
2014-04-04 20:55:21 +02:00
2014-07-01 21:52:40 +02:00
Block block = event . getClickedBlock ( ) ; Player player = event . getPlayer ( ) ;
2014-04-04 20:55:21 +02:00
2014-07-01 21:49:42 +02:00
if ( block = = null ) {
return ; // clicked in air, apparently
}
2014-04-04 20:55:21 +02:00
if ( ! canPlayerUseBlock ( player , block , false ) ) {
2014-07-01 21:52:40 +02:00
event . setCancelled ( true ) ; if ( Conf . handleExploitInteractionSpam ) {
String name = player . getName ( ) ; InteractAttemptSpam attempt = interactSpammers . get ( name ) ;
2014-04-04 20:55:21 +02:00
if ( attempt = = null ) {
2014-07-01 21:52:40 +02:00
attempt = new InteractAttemptSpam ( ) ; interactSpammers . put ( name , attempt ) ;
} int count = attempt . increment ( ) ; if ( count > = 10 ) {
2014-04-04 20:55:21 +02:00
FPlayer me = FPlayers . i . get ( name ) ;
me . msg ( " <b>Ouch, that is starting to hurt. You should give it a rest. " ) ;
player . damage ( NumberConversions . floor ( ( double ) count / 10 ) ) ;
}
2014-07-01 21:52:40 +02:00
} return ;
2014-04-04 20:55:21 +02:00
}
2014-07-01 21:49:42 +02:00
if ( event . getAction ( ) ! = Action . RIGHT_CLICK_BLOCK ) {
return ; // only interested on right-clicks for below
}
2014-04-04 20:55:21 +02:00
if ( ! playerCanUseItemHere ( player , block . getLocation ( ) , event . getMaterial ( ) , false ) ) {
2014-07-01 21:52:40 +02:00
event . setCancelled ( true ) ; return ;
2014-04-04 20:55:21 +02:00
}
}
// for handling people who repeatedly spam attempts to open a door (or similar) in another faction's territory
private Map < String , InteractAttemptSpam > interactSpammers = new HashMap < String , InteractAttemptSpam > ( ) ;
private static class InteractAttemptSpam {
private int attempts = 0 ;
private long lastAttempt = System . currentTimeMillis ( ) ;
// returns the current attempt count
public int increment ( ) {
2014-07-01 21:52:40 +02:00
long Now = System . currentTimeMillis ( ) ; if ( Now > lastAttempt + 2000 ) { attempts = 1 ; } else { attempts + + ; }
lastAttempt = Now ; return attempts ;
2014-04-04 20:55:21 +02:00
}
}
public static boolean playerCanUseItemHere ( Player player , Location location , Material material , boolean justCheck ) {
2014-07-01 21:52:40 +02:00
String name = player . getName ( ) ; if ( Conf . playersWhoBypassAllProtection . contains ( name ) ) { return true ; }
2014-04-04 20:55:21 +02:00
2014-07-01 21:52:40 +02:00
FPlayer me = FPlayers . i . get ( player ) ; if ( me . isAdminBypassing ( ) ) { return true ; }
2014-04-04 20:55:21 +02:00
2014-07-01 21:52:40 +02:00
FLocation loc = new FLocation ( location ) ; Faction otherFaction = Board . getFactionAt ( loc ) ;
2014-04-04 20:55:21 +02:00
if ( otherFaction . hasPlayersOnline ( ) ) {
2014-07-01 21:49:42 +02:00
if ( ! Conf . territoryDenyUseageMaterials . contains ( material ) ) {
2014-04-04 20:55:21 +02:00
return true ; // Item isn't one we're preventing for online factions.
2014-07-01 21:49:42 +02:00
}
2014-07-01 21:52:40 +02:00
} else {
2014-07-01 21:49:42 +02:00
if ( ! Conf . territoryDenyUseageMaterialsWhenOffline . contains ( material ) ) {
2014-04-04 20:55:21 +02:00
return true ; // Item isn't one we're preventing for offline factions.
2014-07-01 21:49:42 +02:00
}
2014-04-04 20:55:21 +02:00
}
if ( otherFaction . isNone ( ) ) {
2014-07-01 21:49:42 +02:00
if ( ! Conf . wildernessDenyUseage | | Conf . worldsNoWildernessProtection . contains ( location . getWorld ( ) . getName ( ) ) ) {
2014-04-04 20:55:21 +02:00
return true ; // This is not faction territory. Use whatever you like here.
2014-07-01 21:49:42 +02:00
}
2014-04-04 20:55:21 +02:00
2014-07-01 21:49:42 +02:00
if ( ! justCheck ) {
2014-04-04 20:55:21 +02:00
me . msg ( " <b>You can't use <h>%s<b> in the wilderness. " , TextUtil . getMaterialName ( material ) ) ;
2014-07-01 21:49:42 +02:00
}
2014-04-04 20:55:21 +02:00
return false ;
2014-07-01 21:52:40 +02:00
} else if ( otherFaction . isSafeZone ( ) ) {
2014-07-01 21:49:42 +02:00
if ( ! Conf . safeZoneDenyUseage | | Permission . MANAGE_SAFE_ZONE . has ( player ) ) { return true ; }
2014-04-04 20:55:21 +02:00
2014-07-01 21:49:42 +02:00
if ( ! justCheck ) { me . msg ( " <b>You can't use <h>%s<b> in a safe zone. " , TextUtil . getMaterialName ( material ) ) ; }
2014-04-04 20:55:21 +02:00
return false ;
2014-07-01 21:52:40 +02:00
} else if ( otherFaction . isWarZone ( ) ) {
2014-07-01 21:49:42 +02:00
if ( ! Conf . warZoneDenyUseage | | Permission . MANAGE_WAR_ZONE . has ( player ) ) { return true ; }
2014-04-04 20:55:21 +02:00
2014-07-01 21:49:42 +02:00
if ( ! justCheck ) { me . msg ( " <b>You can't use <h>%s<b> in a war zone. " , TextUtil . getMaterialName ( material ) ) ; }
2014-04-04 20:55:21 +02:00
return false ;
}
2014-07-01 21:52:40 +02:00
Faction myFaction = me . getFaction ( ) ; Relation rel = myFaction . getRelationTo ( otherFaction ) ;
2014-04-04 20:55:21 +02:00
// Cancel if we are not in our own territory
if ( rel . confDenyUseage ( ) ) {
2014-07-01 21:49:42 +02:00
if ( ! justCheck ) {
2014-04-04 20:55:21 +02:00
me . msg ( " <b>You can't use <h>%s<b> in the territory of <h>%s<b>. " , TextUtil . getMaterialName ( material ) , otherFaction . getTag ( myFaction ) ) ;
2014-07-01 21:49:42 +02:00
}
2014-04-04 20:55:21 +02:00
return false ;
}
// Also cancel if player doesn't have ownership rights for this claim
if ( Conf . ownedAreasEnabled & & Conf . ownedAreaDenyUseage & & ! otherFaction . playerHasOwnershipRights ( me , loc ) ) {
2014-07-01 21:49:42 +02:00
if ( ! justCheck ) {
2014-04-04 20:55:21 +02:00
me . msg ( " <b>You can't use <h>%s<b> in this territory, it is owned by: %s<b>. " , TextUtil . getMaterialName ( material ) , otherFaction . getOwnerListString ( loc ) ) ;
2014-07-01 21:49:42 +02:00
}
2014-04-04 20:55:21 +02:00
return false ;
}
return true ;
}
public static boolean canPlayerUseBlock ( Player player , Block block , boolean justCheck ) {
2014-07-01 21:49:42 +02:00
if ( Conf . playersWhoBypassAllProtection . contains ( player . getName ( ) ) ) { return true ; }
2014-04-04 20:55:21 +02:00
2014-07-01 21:52:40 +02:00
FPlayer me = FPlayers . i . get ( player ) ; if ( me . isAdminBypassing ( ) ) { return true ; }
2014-04-04 20:55:21 +02:00
2014-07-01 21:52:40 +02:00
Material material = block . getType ( ) ; FLocation loc = new FLocation ( block ) ;
2014-04-04 20:55:21 +02:00
Faction otherFaction = Board . getFactionAt ( loc ) ;
// no door/chest/whatever protection in wilderness, war zones, or safe zones
2014-07-01 21:49:42 +02:00
if ( ! otherFaction . isNormal ( ) ) { return true ; }
2014-04-04 20:55:21 +02:00
// We only care about some material types.
if ( otherFaction . hasPlayersOnline ( ) ) {
2014-07-01 21:49:42 +02:00
if ( ! Conf . territoryProtectedMaterials . contains ( material ) ) { return true ; }
2014-07-01 21:52:40 +02:00
} else {
2014-07-01 21:49:42 +02:00
if ( ! Conf . territoryProtectedMaterialsWhenOffline . contains ( material ) ) { return true ; }
2014-04-04 20:55:21 +02:00
}
2014-07-01 21:52:40 +02:00
Faction myFaction = me . getFaction ( ) ; Relation rel = myFaction . getRelationTo ( otherFaction ) ;
2014-04-04 20:55:21 +02:00
// You may use any block unless it is another faction's territory...
if ( rel . isNeutral ( ) | | ( rel . isEnemy ( ) & & Conf . territoryEnemyProtectMaterials ) | | ( rel . isAlly ( ) & & Conf . territoryAllyProtectMaterials ) ) {
2014-07-01 21:49:42 +02:00
if ( ! justCheck ) {
2014-04-04 20:55:21 +02:00
me . msg ( " <b>You can't %s <h>%s<b> in the territory of <h>%s<b>. " , ( material = = Material . SOIL ? " trample " : " use " ) , TextUtil . getMaterialName ( material ) , otherFaction . getTag ( myFaction ) ) ;
2014-07-01 21:49:42 +02:00
}
2014-04-04 20:55:21 +02:00
return false ;
}
// Also cancel if player doesn't have ownership rights for this claim
if ( Conf . ownedAreasEnabled & & Conf . ownedAreaProtectMaterials & & ! otherFaction . playerHasOwnershipRights ( me , loc ) ) {
2014-07-01 21:49:42 +02:00
if ( ! justCheck ) {
2014-04-04 20:55:21 +02:00
me . msg ( " <b>You can't use <h>%s<b> in this territory, it is owned by: %s<b>. " , TextUtil . getMaterialName ( material ) , otherFaction . getOwnerListString ( loc ) ) ;
2014-07-01 21:49:42 +02:00
}
2014-04-04 20:55:21 +02:00
return false ;
}
return true ;
}
@EventHandler ( priority = EventPriority . HIGH )
public void onPlayerRespawn ( PlayerRespawnEvent event ) {
FPlayer me = FPlayers . i . get ( event . getPlayer ( ) ) ;
me . getPower ( ) ; // update power, so they won't have gained any while dead
2014-07-01 21:52:40 +02:00
Location home = me . getFaction ( ) . getHome ( ) ; if ( Conf . homesEnabled & &
Conf . homesTeleportToOnDeath & &
home ! = null & &
( Conf . homesRespawnFromNoPowerLossWorlds | | ! Conf . worldsNoPowerLoss . contains ( event . getPlayer ( ) . getWorld ( ) . getName ( ) ) ) ) {
2014-04-04 20:55:21 +02:00
event . setRespawnLocation ( home ) ;
}
}
// For some reason onPlayerInteract() sometimes misses bucket events depending on distance (something like 2-3 blocks away isn't detected),
// but these separate bucket events below always fire without fail
@EventHandler ( priority = EventPriority . NORMAL )
public void onPlayerBucketEmpty ( PlayerBucketEmptyEvent event ) {
2014-07-01 21:49:42 +02:00
if ( event . isCancelled ( ) ) { return ; }
2014-04-04 20:55:21 +02:00
2014-07-01 21:52:40 +02:00
Block block = event . getBlockClicked ( ) ; Player player = event . getPlayer ( ) ;
2014-04-04 20:55:21 +02:00
if ( ! playerCanUseItemHere ( player , block . getLocation ( ) , event . getBucket ( ) , false ) ) {
2014-07-01 21:52:40 +02:00
event . setCancelled ( true ) ; return ;
2014-04-04 20:55:21 +02:00
}
}
@EventHandler ( priority = EventPriority . NORMAL )
public void onPlayerBucketFill ( PlayerBucketFillEvent event ) {
2014-07-01 21:49:42 +02:00
if ( event . isCancelled ( ) ) { return ; }
2014-04-04 20:55:21 +02:00
2014-07-01 21:52:40 +02:00
Block block = event . getBlockClicked ( ) ; Player player = event . getPlayer ( ) ;
2014-04-04 20:55:21 +02:00
if ( ! playerCanUseItemHere ( player , block . getLocation ( ) , event . getBucket ( ) , false ) ) {
2014-07-01 21:52:40 +02:00
event . setCancelled ( true ) ; return ;
2014-04-04 20:55:21 +02:00
}
}
public static boolean preventCommand ( String fullCmd , Player player ) {
2014-07-01 21:49:42 +02:00
if ( ( Conf . territoryNeutralDenyCommands . isEmpty ( ) & & Conf . territoryEnemyDenyCommands . isEmpty ( ) & & Conf . permanentFactionMemberDenyCommands . isEmpty ( ) ) ) {
2014-04-04 20:55:21 +02:00
return false ;
2014-07-01 21:49:42 +02:00
}
2014-04-04 20:55:21 +02:00
fullCmd = fullCmd . toLowerCase ( ) ;
FPlayer me = FPlayers . i . get ( player ) ;
String shortCmd ; // command without the slash at the beginning
2014-07-01 21:52:40 +02:00
if ( fullCmd . startsWith ( " / " ) ) { shortCmd = fullCmd . substring ( 1 ) ; } else {
shortCmd = fullCmd ; fullCmd = " / " + fullCmd ;
2014-04-04 20:55:21 +02:00
}
2014-07-01 21:52:40 +02:00
if ( me . hasFaction ( ) & &
! me . isAdminBypassing ( ) & &
! Conf . permanentFactionMemberDenyCommands . isEmpty ( ) & &
me . getFaction ( ) . isPermanent ( ) & &
isCommandInList ( fullCmd , shortCmd , Conf . permanentFactionMemberDenyCommands . iterator ( ) ) ) {
2014-04-04 20:55:21 +02:00
me . msg ( " <b>You can't use the command \" " + fullCmd + " \" because you are in a permanent faction. " ) ;
return true ;
}
if ( ! me . isInOthersTerritory ( ) ) {
return false ;
}
2014-07-01 21:52:40 +02:00
Relation rel = me . getRelationToLocation ( ) ; if ( rel . isAtLeast ( Relation . ALLY ) ) {
2014-04-04 20:55:21 +02:00
return false ;
}
2014-07-01 20:46:30 +02:00
if ( rel . isNeutral ( ) & & ! Conf . territoryNeutralDenyCommands . isEmpty ( ) & & ! me . isAdminBypassing ( ) & & isCommandInList ( fullCmd , shortCmd , Conf . territoryNeutralDenyCommands . iterator ( ) ) ) {
2014-07-01 21:52:40 +02:00
me . msg ( " <b>You can't use the command \" " + fullCmd + " \" in neutral territory. " ) ; return true ;
2014-04-04 20:55:21 +02:00
}
2014-07-01 20:46:30 +02:00
if ( rel . isEnemy ( ) & & ! Conf . territoryEnemyDenyCommands . isEmpty ( ) & & ! me . isAdminBypassing ( ) & & isCommandInList ( fullCmd , shortCmd , Conf . territoryEnemyDenyCommands . iterator ( ) ) ) {
2014-07-01 21:52:40 +02:00
me . msg ( " <b>You can't use the command \" " + fullCmd + " \" in enemy territory. " ) ; return true ;
2014-04-04 20:55:21 +02:00
}
return false ;
}
private static boolean isCommandInList ( String fullCmd , String shortCmd , Iterator < String > iter ) {
2014-07-01 21:52:40 +02:00
String cmdCheck ; while ( iter . hasNext ( ) ) {
cmdCheck = iter . next ( ) ; if ( cmdCheck = = null ) {
iter . remove ( ) ; continue ;
2014-04-04 20:55:21 +02:00
}
cmdCheck = cmdCheck . toLowerCase ( ) ;
2014-07-01 21:49:42 +02:00
if ( fullCmd . startsWith ( cmdCheck ) | | shortCmd . startsWith ( cmdCheck ) ) { return true ; }
2014-07-01 21:52:40 +02:00
} return false ;
2014-04-04 20:55:21 +02:00
}
@EventHandler ( priority = EventPriority . NORMAL )
public void onPlayerKick ( PlayerKickEvent event ) {
2014-07-01 21:49:42 +02:00
if ( event . isCancelled ( ) ) { return ; }
2014-04-04 20:55:21 +02:00
2014-07-01 21:52:40 +02:00
FPlayer badGuy = FPlayers . i . get ( event . getPlayer ( ) ) ; if ( badGuy = = null ) {
2014-04-04 20:55:21 +02:00
return ;
}
// if player was banned (not just kicked), get rid of their stored info
if ( Conf . removePlayerDataWhenBanned & & event . getReason ( ) . equals ( " Banned by admin. " ) ) {
2014-07-01 21:49:42 +02:00
if ( badGuy . getRole ( ) = = Role . ADMIN ) { badGuy . getFaction ( ) . promoteNewLeader ( ) ; }
2014-04-04 20:55:21 +02:00
2014-07-01 21:52:40 +02:00
badGuy . leave ( false ) ; badGuy . detach ( ) ;
2014-04-04 20:55:21 +02:00
}
}
2011-02-06 13:36:11 +01:00
}