2011-07-18 22:06:02 +02:00
package com.massivecraft.factions.listeners ;
2011-02-06 13:36:11 +01:00
2011-02-12 18:05:05 +01:00
import java.util.logging.Logger ;
2011-08-04 07:07:38 +02:00
import java.util.Iterator ;
2011-08-20 03:36:23 +02:00
import java.util.UnknownFormatConversionException ;
2011-02-06 13:36:11 +01:00
2011-03-30 12:11:06 +02:00
import org.bukkit.ChatColor ;
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 ;
2012-01-28 10:16:28 +01:00
import org.bukkit.block.BlockFace ;
2011-03-22 18:48:09 +01:00
import org.bukkit.entity.Player ;
2011-03-30 06:37:32 +02:00
import org.bukkit.event.block.Action ;
2011-03-30 11:23:20 +02:00
import org.bukkit.event.player.PlayerBucketEmptyEvent ;
import org.bukkit.event.player.PlayerBucketFillEvent ;
2011-02-06 13:36:11 +01:00
import org.bukkit.event.player.PlayerChatEvent ;
2011-03-30 06:37:32 +02:00
import org.bukkit.event.player.PlayerInteractEvent ;
import org.bukkit.event.player.PlayerJoinEvent ;
2011-10-05 07:33:15 +02:00
import org.bukkit.event.player.PlayerKickEvent ;
2011-02-06 13:36:11 +01:00
import org.bukkit.event.player.PlayerListener ;
import org.bukkit.event.player.PlayerMoveEvent ;
2011-05-29 23:28:29 +02:00
import org.bukkit.event.player.PlayerQuitEvent ;
2011-03-23 17:39:56 +01:00
import org.bukkit.event.player.PlayerRespawnEvent ;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.Board ;
import com.massivecraft.factions.Conf ;
import com.massivecraft.factions.FLocation ;
import com.massivecraft.factions.FPlayer ;
2011-10-08 22:03:44 +02:00
import com.massivecraft.factions.FPlayers ;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.Faction ;
import com.massivecraft.factions.Factions ;
2011-10-08 22:03:44 +02:00
import com.massivecraft.factions.P ;
2011-10-05 12:13:54 +02:00
import com.massivecraft.factions.integration.SpoutFeatures ;
2011-10-08 23:22:02 +02:00
import com.massivecraft.factions.struct.Permission ;
2011-08-04 07:07:38 +02:00
import com.massivecraft.factions.struct.Relation ;
2011-12-18 14:47:15 +01:00
import com.massivecraft.factions.struct.Role ;
2011-10-08 22:03:44 +02:00
import com.massivecraft.factions.zcore.util.TextUtil ;
2011-02-06 13:36:11 +01:00
2011-10-08 22:03:44 +02:00
import java.util.logging.Level ;
2011-02-13 17:02:51 +01:00
2011-02-06 13:36:11 +01:00
2011-03-08 13:06:52 +01:00
2011-10-08 22:03:44 +02:00
public class FactionsPlayerListener extends PlayerListener
{
public P p ;
public FactionsPlayerListener ( P p )
{
this . p = p ;
}
2011-02-06 13:36:11 +01:00
@Override
2011-10-08 22:03:44 +02:00
public void onPlayerChat ( PlayerChatEvent event )
{
if ( event . isCancelled ( ) ) return ;
2011-02-12 18:05:05 +01:00
Player talkingPlayer = event . getPlayer ( ) ;
2011-02-06 13:36:11 +01:00
String msg = event . getMessage ( ) ;
2011-02-12 18:05:05 +01:00
// ... it was not a command. This means that it is a chat message!
2011-10-08 22:03:44 +02:00
FPlayer me = FPlayers . i . get ( talkingPlayer ) ;
2011-02-13 09:08:20 +01:00
2011-02-12 18:05:05 +01:00
// Are we to insert the Faction tag into the format?
// If we are not to insert it - we are done.
2011-10-08 22:03:44 +02:00
if ( ! Conf . chatTagEnabled | | Conf . chatTagHandledByAnotherPlugin )
{
2011-02-12 18:05:05 +01:00
return ;
}
2011-04-26 03:29:47 +02:00
2011-06-03 20:06:41 +02:00
int InsertIndex = 0 ;
String eventFormat = event . getFormat ( ) ;
2011-10-08 22:03:44 +02:00
if ( ! Conf . chatTagReplaceString . isEmpty ( ) & & eventFormat . contains ( Conf . chatTagReplaceString ) )
{
2011-06-03 20:06:41 +02:00
// we're using the "replace" method of inserting the faction tags
2011-06-21 04:15:41 +02:00
// if they stuck "{FACTION_TITLE}" in there, go ahead and do it too
2011-10-08 22:03:44 +02:00
if ( eventFormat . contains ( " {FACTION_TITLE} " ) )
{
2011-06-21 04:15:41 +02:00
eventFormat = eventFormat . replace ( " {FACTION_TITLE} " , me . getTitle ( ) ) ;
}
2011-06-03 20:06:41 +02:00
InsertIndex = eventFormat . indexOf ( Conf . chatTagReplaceString ) ;
eventFormat = eventFormat . replace ( Conf . chatTagReplaceString , " " ) ;
Conf . chatTagPadAfter = false ;
Conf . chatTagPadBefore = false ;
}
2011-10-08 22:03:44 +02:00
else if ( ! Conf . chatTagInsertAfterString . isEmpty ( ) & & eventFormat . contains ( Conf . chatTagInsertAfterString ) )
{
2011-06-03 20:06:41 +02:00
// we're using the "insert after string" method
InsertIndex = eventFormat . indexOf ( Conf . chatTagInsertAfterString ) + Conf . chatTagInsertAfterString . length ( ) ;
}
2011-10-08 22:03:44 +02:00
else if ( ! Conf . chatTagInsertBeforeString . isEmpty ( ) & & eventFormat . contains ( Conf . chatTagInsertBeforeString ) )
{
2011-06-03 20:06:41 +02:00
// we're using the "insert before string" method
InsertIndex = eventFormat . indexOf ( Conf . chatTagInsertBeforeString ) ;
}
2011-10-08 22:03:44 +02:00
else
{
2011-06-03 20:06:41 +02:00
// we'll fall back to using the index place method
InsertIndex = Conf . chatTagInsertIndex ;
if ( InsertIndex > eventFormat . length ( ) )
return ;
}
2011-06-06 05:03:58 +02:00
String formatStart = eventFormat . substring ( 0 , InsertIndex ) + ( ( Conf . chatTagPadBefore & & ! me . getChatTag ( ) . isEmpty ( ) ) ? " " : " " ) ;
String formatEnd = ( ( Conf . chatTagPadAfter & & ! me . getChatTag ( ) . isEmpty ( ) ) ? " " : " " ) + eventFormat . substring ( InsertIndex ) ;
2011-02-12 18:05:05 +01:00
2011-06-03 20:06:41 +02:00
String nonColoredMsgFormat = formatStart + me . getChatTag ( ) . trim ( ) + formatEnd ;
2011-02-12 18:05:05 +01:00
// Relation Colored?
2011-10-08 22:03:44 +02:00
if ( Conf . chatTagRelationColored )
{
2011-02-12 18:05:05 +01:00
// We must choke the standard message and send out individual messages to all players
// Why? Because the relations will differ.
event . setCancelled ( true ) ;
2011-10-08 22:03:44 +02:00
for ( Player listeningPlayer : event . getRecipients ( ) )
{
FPlayer you = FPlayers . i . get ( listeningPlayer ) ;
2011-06-03 20:06:41 +02:00
String yourFormat = formatStart + me . getChatTag ( you ) . trim ( ) + formatEnd ;
2011-10-08 22:03:44 +02:00
try
{
2011-08-20 03:36:23 +02:00
listeningPlayer . sendMessage ( String . format ( yourFormat , talkingPlayer . getDisplayName ( ) , msg ) ) ;
}
2011-10-08 22:03:44 +02:00
catch ( UnknownFormatConversionException ex )
{
P . p . log ( Level . SEVERE , " Critical error in chat message formatting! Complete format string: " + yourFormat ) ;
P . p . log ( Level . SEVERE , " First half of event.getFormat() string: " + formatStart ) ;
P . p . log ( Level . SEVERE , " Second half of event.getFormat() string: " + formatEnd ) ;
P . p . log ( Level . SEVERE , " NOTE: To fix this quickly, running this command should work: f config chatTagInsertIndex 0 " ) ;
P . p . log ( Level . SEVERE , " For a more proper fix, please read the chat configuration notes on the configuration page of the Factions user guide. " ) ;
2011-08-20 03:36:23 +02:00
ex . printStackTrace ( ) ;
return ;
}
2011-02-06 13:36:11 +01:00
}
2011-02-12 18:05:05 +01:00
// Write to the log... We will write the non colored message.
2011-03-30 12:11:06 +02:00
String nonColoredMsg = ChatColor . stripColor ( String . format ( nonColoredMsgFormat , talkingPlayer . getDisplayName ( ) , msg ) ) ;
2011-02-12 18:05:05 +01:00
Logger . getLogger ( " Minecraft " ) . info ( nonColoredMsg ) ;
2011-10-08 22:03:44 +02:00
}
else
{
2011-02-12 18:05:05 +01:00
// No relation color.
event . setFormat ( nonColoredMsgFormat ) ;
2011-02-06 13:36:11 +01:00
}
}
@Override
2011-10-08 22:03:44 +02:00
public void onPlayerJoin ( PlayerJoinEvent event )
{
2011-03-22 18:48:09 +01:00
// Make sure that all online players do have a fplayer.
2011-10-08 22:03:44 +02:00
final FPlayer me = FPlayers . i . get ( event . getPlayer ( ) ) ;
2011-03-22 20:36:33 +01:00
// Update the lastLoginTime for this fplayer
me . setLastLoginTime ( System . currentTimeMillis ( ) ) ;
2011-03-23 12:00:38 +01:00
// Run the member auto kick routine. Twice to get to the admins...
2011-10-08 22:03:44 +02:00
FPlayers . i . autoLeaveOnInactivityRoutine ( ) ;
FPlayers . i . autoLeaveOnInactivityRoutine ( ) ;
2011-10-23 16:03:28 +02:00
SpoutFeatures . updateAppearancesShortly ( event . getPlayer ( ) ) ;
2011-02-06 13:36:11 +01:00
}
2011-05-29 23:28:29 +02:00
@Override
2011-10-08 22:03:44 +02:00
public void onPlayerQuit ( PlayerQuitEvent event )
{
2011-05-29 23:28:29 +02:00
// Make sure player's power is up to date when they log off.
2011-10-08 22:03:44 +02:00
FPlayer me = FPlayers . i . get ( event . getPlayer ( ) ) ;
2011-05-29 23:28:29 +02:00
me . getPower ( ) ;
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
Faction myFaction = me . getFaction ( ) ;
2011-10-08 22:03:44 +02:00
if ( myFaction ! = null )
{
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
myFaction . memberLoggedOff ( ) ;
}
2011-10-05 12:13:54 +02:00
SpoutFeatures . playerDisconnect ( me ) ;
2011-05-29 23:28:29 +02:00
}
2011-02-06 13:36:11 +01:00
@Override
2011-10-08 22:03:44 +02:00
public void onPlayerMove ( PlayerMoveEvent event )
{
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
Player player = event . getPlayer ( ) ;
2011-10-08 22:03:44 +02:00
FPlayer me = FPlayers . i . get ( player ) ;
2011-02-13 17:04:06 +01:00
2011-02-06 13:36:11 +01:00
// Did we change coord?
2011-03-22 18:48:09 +01:00
FLocation from = me . getLastStoodAt ( ) ;
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
FLocation to = new FLocation ( player . getLocation ( ) ) ;
2011-03-22 18:48:09 +01:00
2011-10-08 22:03:44 +02:00
if ( from . equals ( to ) )
{
2011-02-06 13:36:11 +01:00
return ;
}
// Yes we did change coord (:
2011-03-22 18:48:09 +01:00
me . setLastStoodAt ( to ) ;
2011-12-16 07:31:23 +01:00
// Did we change "host"(faction)?
boolean spoutClient = SpoutFeatures . availableFor ( player ) ;
Faction factionFrom = Board . getFactionAt ( from ) ;
Faction factionTo = Board . getFactionAt ( to ) ;
boolean changedFaction = ( factionFrom ! = factionTo ) ;
if ( changedFaction & & SpoutFeatures . updateTerritoryDisplay ( me ) )
changedFaction = false ;
2011-10-08 22:03:44 +02:00
if ( me . isMapAutoUpdating ( ) )
{
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
me . sendMessage ( Board . getMap ( me . getFaction ( ) , to , player . getLocation ( ) . getYaw ( ) ) ) ;
2011-12-16 07:31:23 +01:00
if ( spoutClient & & Conf . spoutTerritoryOwnersShow )
SpoutFeatures . updateOwnerList ( me ) ;
2011-10-08 22:03:44 +02:00
}
else
{
2011-08-23 06:31:37 +02:00
Faction myFaction = me . getFaction ( ) ;
String ownersTo = myFaction . getOwnerListString ( to ) ;
2011-10-13 21:30:47 +02:00
2011-12-16 07:31:23 +01:00
if ( changedFaction )
2011-10-08 22:03:44 +02:00
{
2011-02-06 13:36:11 +01:00
me . sendFactionHereMessage ( ) ;
2011-10-13 21:09:47 +02:00
if
(
Conf . ownedAreasEnabled
& &
Conf . ownedMessageOnBorder
& &
(
2011-10-13 21:30:47 +02:00
! spoutClient
2011-10-13 21:09:47 +02:00
| |
! Conf . spoutTerritoryOwnersShow
)
& &
myFaction = = factionTo
& &
! ownersTo . isEmpty ( )
)
2011-10-08 22:03:44 +02:00
{
2011-08-23 06:31:37 +02:00
me . sendMessage ( Conf . ownedLandMessage + ownersTo ) ;
}
}
2011-10-13 21:30:47 +02:00
else if ( spoutClient & & Conf . spoutTerritoryOwnersShow )
2011-10-13 21:09:47 +02:00
{
SpoutFeatures . updateOwnerList ( me ) ;
}
else if
(
Conf . ownedAreasEnabled
& &
Conf . ownedMessageInsideTerritory
& &
factionFrom = = factionTo
& &
myFaction = = factionTo
)
2011-10-08 22:03:44 +02:00
{
2011-08-23 06:31:37 +02:00
String ownersFrom = myFaction . getOwnerListString ( from ) ;
2011-10-08 22:03:44 +02:00
if ( Conf . ownedMessageByChunk | | ! ownersFrom . equals ( ownersTo ) )
{
if ( ! ownersTo . isEmpty ( ) )
2011-08-23 06:31:37 +02:00
me . sendMessage ( Conf . ownedLandMessage + ownersTo ) ;
2011-10-08 22:03:44 +02:00
else if ( ! Conf . publicLandMessage . isEmpty ( ) )
2011-08-23 06:31:37 +02:00
me . sendMessage ( Conf . publicLandMessage ) ;
}
2011-02-06 13:36:11 +01:00
}
}
2011-06-10 21:26:12 +02:00
2011-10-22 17:03:49 +02:00
if ( me . getAutoClaimFor ( ) ! = null )
2011-10-08 22:03:44 +02:00
{
2011-10-22 17:03:49 +02:00
me . attemptClaim ( me . getAutoClaimFor ( ) , player . getLocation ( ) , true ) ;
2011-06-10 21:26:12 +02:00
}
2011-10-09 14:53:38 +02:00
else if ( me . isAutoSafeClaimEnabled ( ) )
2011-10-08 22:03:44 +02:00
{
2011-10-08 23:22:02 +02:00
if ( ! Permission . MANAGE_SAFE_ZONE . has ( player ) )
2011-10-08 22:03:44 +02:00
{
2011-10-09 14:53:38 +02:00
me . setIsAutoSafeClaimEnabled ( false ) ;
2011-10-08 22:03:44 +02:00
}
else
{
2011-06-10 21:26:12 +02:00
FLocation playerFlocation = new FLocation ( me ) ;
2011-10-08 22:03:44 +02:00
if ( ! Board . getFactionAt ( playerFlocation ) . isSafeZone ( ) )
{
Board . setFactionAt ( Factions . i . getSafeZone ( ) , playerFlocation ) ;
2011-10-21 18:14:04 +02:00
me . msg ( " <i>This land is now a safe zone. " ) ;
2011-06-10 21:26:12 +02:00
}
}
}
2011-10-09 14:53:38 +02:00
else if ( me . isAutoWarClaimEnabled ( ) )
2011-10-08 22:03:44 +02:00
{
2011-10-08 23:22:02 +02:00
if ( ! Permission . MANAGE_WAR_ZONE . has ( player ) )
2011-10-08 22:03:44 +02:00
{
2011-10-09 14:53:38 +02:00
me . setIsAutoWarClaimEnabled ( false ) ;
2011-10-08 22:03:44 +02:00
}
else
{
2011-06-10 21:26:12 +02:00
FLocation playerFlocation = new FLocation ( me ) ;
2011-10-08 22:03:44 +02:00
if ( ! Board . getFactionAt ( playerFlocation ) . isWarZone ( ) )
{
Board . setFactionAt ( Factions . i . getWarZone ( ) , playerFlocation ) ;
2011-10-21 18:14:04 +02:00
me . msg ( " <i>This land is now a war zone. " ) ;
2011-06-10 21:26:12 +02:00
}
}
}
2011-02-06 13:36:11 +01:00
}
2011-03-08 13:06:52 +01:00
@Override
2011-10-08 22:03:44 +02:00
public void onPlayerInteract ( PlayerInteractEvent event )
{
if ( event . isCancelled ( ) ) return ;
2011-03-10 01:21:17 +01:00
2011-03-30 06:37:32 +02:00
Block block = event . getClickedBlock ( ) ;
Player player = event . getPlayer ( ) ;
2011-10-08 22:03:44 +02:00
if ( block = = null )
{
2011-04-04 15:34:32 +02:00
return ; // clicked in air, apparently
}
2011-10-08 22:03:44 +02:00
if ( ! canPlayerUseBlock ( player , block , false ) )
{
2011-03-30 06:37:32 +02:00
event . setCancelled ( true ) ;
return ;
}
2011-04-04 15:34:32 +02:00
2011-10-08 22:03:44 +02:00
if ( event . getAction ( ) ! = Action . RIGHT_CLICK_BLOCK )
{
2011-04-04 15:34:32 +02:00
return ; // only interested on right-clicks for below
}
2012-01-28 10:16:28 +01:00
// workaround fix for new CraftBukkit 1.1-R1 bug where half-step on half-step placement doesn't trigger BlockPlaceEvent
if (
event . hasItem ( )
& &
event . getItem ( ) . getType ( ) = = Material . STEP
& &
block . getType ( ) = = Material . STEP
& &
event . getBlockFace ( ) = = BlockFace . UP
& &
event . getItem ( ) . getData ( ) . getData ( ) = = block . getData ( )
& &
! FactionsBlockListener . playerCanBuildDestroyBlock ( player , block . getLocation ( ) , " build " , false )
)
{
event . setCancelled ( true ) ;
return ;
}
2011-10-08 22:03:44 +02:00
if ( ! playerCanUseItemHere ( player , block . getLocation ( ) , event . getMaterial ( ) , false ) )
{
2011-03-08 13:06:52 +01:00
event . setCancelled ( true ) ;
return ;
}
}
2011-03-30 06:37:32 +02:00
2011-10-08 22:03:44 +02:00
public static boolean playerCanUseItemHere ( Player player , Location location , Material material , boolean justCheck )
{
2011-10-09 18:35:39 +02:00
FPlayer me = FPlayers . i . get ( player ) ;
if ( me . isAdminBypassing ( ) )
2011-04-04 14:16:53 +02:00
return true ;
2011-10-05 05:46:11 +02:00
FLocation loc = new FLocation ( location ) ;
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
Faction otherFaction = Board . getFactionAt ( loc ) ;
2011-03-08 13:06:52 +01:00
2011-10-13 05:31:18 +02:00
if ( otherFaction . hasPlayersOnline ( ) )
{
2011-10-08 22:03:44 +02:00
if ( ! Conf . territoryDenyUseageMaterials . contains ( material ) )
2011-06-04 11:36:28 +02:00
return true ; // Item isn't one we're preventing for online factions.
2011-10-08 22:03:44 +02:00
}
else
{
if ( ! Conf . territoryDenyUseageMaterialsWhenOffline . contains ( material ) )
2011-06-04 11:36:28 +02:00
return true ; // Item isn't one we're preventing for offline factions.
}
2011-03-08 13:06:52 +01:00
2011-10-08 22:03:44 +02:00
if ( otherFaction . isNone ( ) )
{
2011-10-09 18:35:39 +02:00
if ( ! Conf . wildernessDenyUseage | | Conf . worldsNoWildernessProtection . contains ( location . getWorld ( ) . getName ( ) ) )
2011-06-02 01:32:09 +02:00
return true ; // This is not faction territory. Use whatever you like here.
2011-10-08 22:03:44 +02:00
if ( ! justCheck )
2011-10-21 18:14:04 +02:00
me . msg ( " <b>You can't use <h>%s<b> in the wilderness. " , TextUtil . getMaterialName ( material ) ) ;
2011-10-13 05:31:18 +02:00
2011-06-02 01:32:09 +02:00
return false ;
2011-03-08 13:06:52 +01:00
}
2011-10-08 22:03:44 +02:00
else if ( otherFaction . isSafeZone ( ) )
{
2011-10-08 23:22:02 +02:00
if ( ! Conf . safeZoneDenyUseage | | Permission . MANAGE_SAFE_ZONE . has ( player ) )
2011-03-24 15:49:33 +01:00
return true ;
2011-10-13 05:31:18 +02:00
2011-10-08 22:03:44 +02:00
if ( ! justCheck )
2011-10-21 18:14:04 +02:00
me . msg ( " <b>You can't use <h>%s<b> in a safe zone. " , TextUtil . getMaterialName ( material ) ) ;
2011-10-13 05:31:18 +02:00
2011-03-24 15:49:33 +01:00
return false ;
}
2011-10-08 22:03:44 +02:00
else if ( otherFaction . isWarZone ( ) )
{
2011-10-08 23:22:02 +02:00
if ( ! Conf . warZoneDenyUseage | | Permission . MANAGE_WAR_ZONE . has ( player ) )
2011-05-29 23:28:29 +02:00
return true ;
2011-10-13 05:31:18 +02:00
2011-10-08 22:03:44 +02:00
if ( ! justCheck )
2011-10-21 18:14:04 +02:00
me . msg ( " <b>You can't use <h>%s<b> in a war zone. " , TextUtil . getMaterialName ( material ) ) ;
2011-10-13 05:31:18 +02:00
2011-05-29 23:28:29 +02:00
return false ;
}
2011-10-13 05:31:18 +02:00
2011-03-08 13:06:52 +01:00
Faction myFaction = me . getFaction ( ) ;
2011-10-12 17:25:01 +02:00
Relation rel = myFaction . getRelationTo ( otherFaction ) ;
2011-10-13 05:31:18 +02:00
2011-03-08 13:06:52 +01:00
// Cancel if we are not in our own territory
2011-10-13 05:31:18 +02:00
if ( rel . confDenyUseage ( ) )
2011-10-08 22:03:44 +02:00
{
if ( ! justCheck )
2011-10-21 18:14:04 +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 ) ) ;
2011-10-13 05:31:18 +02:00
2011-09-06 23:35:43 +02:00
return false ;
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
}
2011-10-13 05:31:18 +02:00
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
// Also cancel if player doesn't have ownership rights for this claim
2011-10-13 05:31:18 +02:00
if ( Conf . ownedAreasEnabled & & Conf . ownedAreaDenyUseage & & ! otherFaction . playerHasOwnershipRights ( me , loc ) )
2011-10-08 22:03:44 +02:00
{
if ( ! justCheck )
2011-10-21 18:14:04 +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 ) ) ;
2011-10-13 05:31:18 +02:00
2011-03-08 13:06:52 +01:00
return false ;
}
2011-10-13 05:31:18 +02:00
2011-03-08 13:06:52 +01:00
return true ;
}
2011-03-30 06:37:32 +02:00
2011-10-08 22:03:44 +02:00
public static boolean canPlayerUseBlock ( Player player , Block block , boolean justCheck )
{
2011-10-09 18:35:39 +02:00
FPlayer me = FPlayers . i . get ( player ) ;
if ( me . isAdminBypassing ( ) )
2011-04-04 14:16:53 +02:00
return true ;
2011-03-30 06:37:32 +02:00
Material material = block . getType ( ) ;
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
FLocation loc = new FLocation ( block ) ;
Faction otherFaction = Board . getFactionAt ( loc ) ;
2011-09-15 16:12:24 +02:00
// no door/chest/whatever protection in wilderness, war zones, or safe zones
2011-10-08 22:03:44 +02:00
if ( ! otherFaction . isNormal ( ) )
2011-09-15 16:12:24 +02:00
return true ;
2011-03-30 06:37:32 +02:00
// We only care about some material types.
2011-10-08 22:03:44 +02:00
if ( otherFaction . hasPlayersOnline ( ) )
{
if ( ! Conf . territoryProtectedMaterials . contains ( material ) )
2011-06-04 11:59:35 +02:00
return true ;
2011-10-08 22:03:44 +02:00
}
else
{
if ( ! Conf . territoryProtectedMaterialsWhenOffline . contains ( material ) )
2011-06-04 11:59:35 +02:00
return true ;
2011-03-30 06:37:32 +02:00
}
2011-10-13 05:31:18 +02:00
2011-03-30 06:37:32 +02:00
Faction myFaction = me . getFaction ( ) ;
2011-10-12 17:25:01 +02:00
Relation rel = myFaction . getRelationTo ( otherFaction ) ;
2011-10-13 05:31:18 +02:00
2011-06-10 21:14:02 +02:00
// You may use any block unless it is another faction's territory...
2011-10-08 22:03:44 +02:00
if ( rel . isNeutral ( ) | | ( rel . isEnemy ( ) & & Conf . territoryEnemyProtectMaterials ) | | ( rel . isAlly ( ) & & Conf . territoryAllyProtectMaterials ) )
{
if ( ! justCheck )
2011-12-18 15:39:52 +01: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 ) ) ;
2011-10-13 05:31:18 +02:00
2011-03-30 06:37:32 +02:00
return false ;
}
2011-10-13 05:31:18 +02:00
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
// Also cancel if player doesn't have ownership rights for this claim
2011-10-13 05:31:18 +02:00
if ( Conf . ownedAreasEnabled & & Conf . ownedAreaProtectMaterials & & ! otherFaction . playerHasOwnershipRights ( me , loc ) )
2011-10-08 22:03:44 +02:00
{
if ( ! justCheck )
2011-10-21 18:14:04 +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 ) ) ;
Faction admins can now mark already claimed areas as owned by specific faction members. Ownership can include multiple members. New command /f owner *[player name], to set/remove ownership. This command is only available to the faction admin and optionally the faction moderators. If no player name is specified, it will either set ownership to the player running the command (if no owner is currently set) or completely clear ownership of the territory. New command /f ownerlist, to view a list of owners for the current area. Only works inside your own faction's territory. New conf.json options "ownedAreasEnabled", "ownedAreasModeratorsCanSet", "ownedAreaModeratorsBypass", "ownedAreaDenyBuild", "ownedAreaProtectMaterials", and "ownedAreaDenyUseage" (all defaulting to true) to determine whether faction moderators can set or bypass ownership (faction admin always can), and what sort of protection these owned areas have against normal members of the faction (members other than the owner(s), faction admin, and probably faction moderators). New conf.json option "ownedAreasLimitPerFaction" to limit how many owned areas can be set. New permission node "factions.ownershipBypass" which allows a player to bypass ownership protection, but only within the person's own faction.
various little tweaks and improvements to other code
moderate speed boost to FLocation code
made commandDisable permissions work for any command alias of a command, instead of just the first one
2011-07-31 03:17:00 +02:00
return false ;
}
2011-03-30 06:37:32 +02:00
return true ;
}
2011-03-23 17:39:56 +01:00
@Override
2011-10-08 22:03:44 +02:00
public void onPlayerRespawn ( PlayerRespawnEvent event )
{
FPlayer me = FPlayers . i . get ( event . getPlayer ( ) ) ;
2011-03-23 17:39:56 +01:00
Location home = me . getFaction ( ) . getHome ( ) ;
2011-10-08 22:03:44 +02:00
if
(
Conf . homesEnabled
& &
Conf . homesTeleportToOnDeath
& &
home ! = null
& &
(
Conf . homesRespawnFromNoPowerLossWorlds
| |
! Conf . worldsNoPowerLoss . contains ( event . getPlayer ( ) . getWorld ( ) . getName ( ) )
)
)
{
2011-03-23 17:39:56 +01:00
event . setRespawnLocation ( home ) ;
}
}
2011-03-30 11:23:20 +02:00
// 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
@Override
2011-10-08 22:03:44 +02:00
public void onPlayerBucketEmpty ( PlayerBucketEmptyEvent event )
{
if ( event . isCancelled ( ) ) return ;
2011-03-30 11:23:20 +02:00
Block block = event . getBlockClicked ( ) ;
Player player = event . getPlayer ( ) ;
2011-10-08 22:03:44 +02:00
if ( ! playerCanUseItemHere ( player , block . getLocation ( ) , event . getBucket ( ) , false ) )
{
2011-03-30 11:23:20 +02:00
event . setCancelled ( true ) ;
return ;
}
}
@Override
2011-10-08 22:03:44 +02:00
public void onPlayerBucketFill ( PlayerBucketFillEvent event )
{
if ( event . isCancelled ( ) ) return ;
2011-03-30 11:23:20 +02:00
Block block = event . getBlockClicked ( ) ;
Player player = event . getPlayer ( ) ;
2011-10-08 22:03:44 +02:00
if ( ! playerCanUseItemHere ( player , block . getLocation ( ) , event . getBucket ( ) , false ) )
{
2011-03-30 11:23:20 +02:00
event . setCancelled ( true ) ;
return ;
}
}
2011-08-04 07:07:38 +02:00
2011-10-08 22:03:44 +02:00
public static boolean preventCommand ( String fullCmd , Player player )
{
2012-01-19 06:31:37 +01:00
if ( ( Conf . territoryNeutralDenyCommands . isEmpty ( ) & & Conf . territoryEnemyDenyCommands . isEmpty ( ) & & Conf . permanentFactionMemberDenyCommands . isEmpty ( ) ) )
2011-08-04 07:34:52 +02:00
return false ;
2011-10-08 22:03:44 +02:00
FPlayer me = FPlayers . i . get ( player ) ;
2011-08-04 07:07:38 +02:00
2012-01-19 06:31:37 +01:00
String shortCmd ; // command without the slash at the beginning
if ( fullCmd . startsWith ( " / " ) )
shortCmd = fullCmd . substring ( 1 ) ;
else
{
shortCmd = fullCmd ;
fullCmd = " / " + fullCmd ;
}
if
(
me . hasFaction ( )
& &
! me . isAdminBypassing ( )
& &
! Conf . permanentFactionMemberDenyCommands . isEmpty ( )
& &
me . getFaction ( ) . isPermanent ( )
& &
isCommandInList ( fullCmd , shortCmd , Conf . permanentFactionMemberDenyCommands . iterator ( ) )
)
{
me . msg ( " <b>You can't use the command \" " + fullCmd + " \" because you are in a permanent faction. " ) ;
return true ;
}
2011-10-08 22:03:44 +02:00
if ( ! me . isInOthersTerritory ( ) )
{
2011-08-04 07:34:52 +02:00
return false ;
2011-08-04 07:07:38 +02:00
}
Relation rel = me . getRelationToLocation ( ) ;
2011-10-08 22:03:44 +02:00
if ( rel . isAtLeast ( Relation . ALLY ) )
{
2011-08-04 07:34:52 +02:00
return false ;
2011-08-04 07:07:38 +02:00
}
2011-10-08 22:03:44 +02:00
if
(
rel . isNeutral ( )
& &
! Conf . territoryNeutralDenyCommands . isEmpty ( )
& &
2011-10-09 18:35:39 +02:00
! me . isAdminBypassing ( )
2012-01-19 06:31:37 +01:00
& &
isCommandInList ( fullCmd , shortCmd , Conf . territoryNeutralDenyCommands . iterator ( ) )
2011-10-08 22:03:44 +02:00
)
{
2012-01-19 06:31:37 +01:00
me . msg ( " <b>You can't use the command \" " + fullCmd + " \" in neutral territory. " ) ;
return true ;
2011-08-04 07:07:38 +02:00
}
2012-01-19 06:31:37 +01:00
if
2011-10-08 22:03:44 +02:00
(
rel . isEnemy ( )
& &
! Conf . territoryEnemyDenyCommands . isEmpty ( )
& &
2011-10-09 18:35:39 +02:00
! me . isAdminBypassing ( )
2012-01-19 06:31:37 +01:00
& &
isCommandInList ( fullCmd , shortCmd , Conf . territoryEnemyDenyCommands . iterator ( ) )
2011-10-08 22:03:44 +02:00
)
{
2012-01-19 06:31:37 +01:00
me . msg ( " <b>You can't use the command \" " + fullCmd + " \" in enemy territory. " ) ;
return true ;
}
2011-08-05 21:06:35 +02:00
2012-01-19 06:31:37 +01:00
return false ;
}
private static boolean isCommandInList ( String fullCmd , String shortCmd , Iterator < String > iter )
{
String cmdCheck ;
while ( iter . hasNext ( ) )
{
cmdCheck = iter . next ( ) ;
if ( cmdCheck = = null )
{
iter . remove ( ) ;
continue ;
2011-08-04 07:07:38 +02:00
}
2012-01-19 06:31:37 +01:00
cmdCheck = cmdCheck . toLowerCase ( ) ;
if ( fullCmd . startsWith ( cmdCheck ) | | shortCmd . startsWith ( cmdCheck ) )
return true ;
2011-08-04 07:07:38 +02:00
}
2011-08-04 07:34:52 +02:00
return false ;
2011-08-04 07:07:38 +02:00
}
2011-08-04 07:34:52 +02:00
2011-10-05 07:33:15 +02:00
@Override
2011-10-08 22:03:44 +02:00
public void onPlayerKick ( PlayerKickEvent event )
{
if ( event . isCancelled ( ) ) return ;
2011-10-05 07:33:15 +02:00
2011-10-08 22:03:44 +02:00
FPlayer badGuy = FPlayers . i . get ( event . getPlayer ( ) ) ;
if ( badGuy = = null )
{
2011-10-05 12:13:54 +02:00
return ;
}
SpoutFeatures . playerDisconnect ( badGuy ) ;
2011-10-05 07:33:15 +02:00
// if player was banned (not just kicked), get rid of their stored info
2011-12-18 09:47:56 +01:00
if ( Conf . removePlayerDataWhenBanned & & event . getReason ( ) . equals ( " Banned by admin. " ) )
2011-10-08 22:03:44 +02:00
{
2011-12-18 14:47:15 +01:00
if ( badGuy . getRole ( ) = = Role . ADMIN )
badGuy . getFaction ( ) . promoteNewLeader ( ) ;
2011-10-05 07:33:15 +02:00
badGuy . leave ( false ) ;
2012-01-10 04:38:00 +01:00
badGuy . detach ( ) ;
2011-10-05 07:33:15 +02:00
}
}
2011-02-06 13:36:11 +01:00
}