2011-07-18 22:06:02 +02:00
|
|
|
package com.massivecraft.factions.listeners;
|
2011-02-06 13:36:11 +01:00
|
|
|
|
2011-07-20 19:22:03 +02:00
|
|
|
import org.bukkit.Location;
|
2011-06-10 21:16:14 +02:00
|
|
|
import org.bukkit.Material;
|
2011-02-06 13:36:11 +01:00
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Player;
|
2011-03-30 06:37:32 +02:00
|
|
|
import org.bukkit.event.block.BlockBreakEvent;
|
2011-02-06 13:36:11 +01:00
|
|
|
import org.bukkit.event.block.BlockDamageEvent;
|
|
|
|
import org.bukkit.event.block.BlockListener;
|
|
|
|
import org.bukkit.event.block.BlockPlaceEvent;
|
2011-07-20 19:22:03 +02:00
|
|
|
import org.bukkit.event.block.BlockPistonExtendEvent;
|
|
|
|
import org.bukkit.event.block.BlockPistonRetractEvent;
|
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;
|
2011-10-08 22:03:44 +02:00
|
|
|
import com.massivecraft.factions.P;
|
2011-10-08 23:22:02 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2011-08-24 00:12:17 +02:00
|
|
|
import com.massivecraft.factions.struct.Relation;
|
2011-02-06 13:36:11 +01:00
|
|
|
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public class FactionsBlockListener extends BlockListener
|
|
|
|
{
|
|
|
|
public P p;
|
|
|
|
public FactionsBlockListener(P p)
|
|
|
|
{
|
|
|
|
this.p = p;
|
|
|
|
}
|
2011-02-06 13:36:11 +01:00
|
|
|
|
|
|
|
@Override
|
2011-10-08 22:03:44 +02:00
|
|
|
public void onBlockPlace(BlockPlaceEvent event)
|
|
|
|
{
|
|
|
|
if (event.isCancelled()) return;
|
|
|
|
if ( ! event.canBuild()) return;
|
|
|
|
|
2011-06-10 21:16:14 +02:00
|
|
|
// special case for flint&steel, which should only be prevented by DenyUsage list
|
2011-10-08 22:03:44 +02:00
|
|
|
if (event.getBlockPlaced().getType() == Material.FIRE)
|
|
|
|
{
|
2011-03-30 06:37:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if ( ! playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "build", false))
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
event.setCancelled(true);
|
2012-01-15 18:41:13 +01:00
|
|
|
|
|
|
|
Material handItem = event.getPlayer().getItemInHand().getType();
|
|
|
|
if (handItem == Material.TNT || handItem == Material.REDSTONE_TORCH_ON)
|
|
|
|
{
|
|
|
|
Faction targetFaction = Board.getFactionAt(new FLocation(event.getBlock()));
|
|
|
|
FactionsEntityListener.trackPotentialExplosionExploit(event.getPlayer().getName(), targetFaction, handItem, event.getBlock().getLocation());
|
|
|
|
}
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
|
|
|
}
|
2011-03-08 13:42:48 +01:00
|
|
|
|
2011-03-30 06:37:32 +02:00
|
|
|
@Override
|
2011-10-08 22:03:44 +02:00
|
|
|
public void onBlockBreak(BlockBreakEvent event)
|
|
|
|
{
|
|
|
|
if (event.isCancelled()) return;
|
2011-03-30 06:37:32 +02:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if ( ! playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false))
|
|
|
|
{
|
2011-03-30 06:37:32 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
@Override
|
2011-10-08 22:03:44 +02:00
|
|
|
public void onBlockDamage(BlockDamageEvent event)
|
|
|
|
{
|
|
|
|
if (event.isCancelled()) return;
|
2011-03-18 00:04:45 +01:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if (event.getInstaBreak() && ! playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false))
|
|
|
|
{
|
2011-02-06 13:36:11 +01:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
2011-07-20 19:22:03 +02:00
|
|
|
|
|
|
|
@Override
|
2011-10-08 22:03:44 +02:00
|
|
|
public void onBlockPistonExtend(BlockPistonExtendEvent event)
|
|
|
|
{
|
|
|
|
if (event.isCancelled()) return;
|
|
|
|
if ( ! Conf.pistonProtectionThroughDenyBuild) return;
|
2011-07-20 19:22:03 +02:00
|
|
|
|
|
|
|
Faction pistonFaction = Board.getFactionAt(new FLocation(event.getBlock()));
|
|
|
|
|
|
|
|
// target end-of-the-line empty (air) block which is being pushed into, including if piston itself would extend into air
|
|
|
|
Block targetBlock = event.getBlock().getRelative(event.getDirection(), event.getLength() + 1);
|
|
|
|
|
|
|
|
// if potentially pushing into air in another territory, we need to check it out
|
2011-10-08 22:03:44 +02:00
|
|
|
if (targetBlock.isEmpty() && !canPistonMoveBlock(pistonFaction, targetBlock.getLocation()))
|
|
|
|
{
|
2011-07-20 19:22:03 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* note that I originally was testing the territory of each affected block, but since I found that pistons can only push
|
|
|
|
* up to 12 blocks and the width of any territory is 16 blocks, it should be safe (and much more lightweight) to test
|
|
|
|
* only the final target block as done above
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-10-08 22:03:44 +02:00
|
|
|
public void onBlockPistonRetract(BlockPistonRetractEvent event)
|
|
|
|
{
|
2011-07-20 19:22:03 +02:00
|
|
|
// if not a sticky piston, retraction should be fine
|
2011-10-08 22:03:44 +02:00
|
|
|
if (event.isCancelled() || !event.isSticky() || !Conf.pistonProtectionThroughDenyBuild)
|
|
|
|
{
|
2011-07-20 19:22:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Location targetLoc = event.getRetractLocation();
|
|
|
|
|
|
|
|
// if potentially retracted block is just air, no worries
|
2011-10-08 22:03:44 +02:00
|
|
|
if (targetLoc.getBlock().isEmpty())
|
|
|
|
{
|
2011-07-20 19:22:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Faction pistonFaction = Board.getFactionAt(new FLocation(event.getBlock()));
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if (!canPistonMoveBlock(pistonFaction, targetLoc))
|
|
|
|
{
|
2011-07-20 19:22:03 +02:00
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
private boolean canPistonMoveBlock(Faction pistonFaction, Location target)
|
|
|
|
{
|
2011-07-20 19:22:03 +02:00
|
|
|
|
|
|
|
Faction otherFaction = Board.getFactionAt(new FLocation(target));
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if (pistonFaction == otherFaction)
|
2011-07-20 19:22:03 +02:00
|
|
|
return true;
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if (otherFaction.isNone())
|
|
|
|
{
|
|
|
|
if (!Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(target.getWorld().getName()))
|
2011-07-20 19:22:03 +02:00
|
|
|
return true;
|
2011-10-13 05:31:18 +02:00
|
|
|
|
2011-07-20 19:22:03 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
else if (otherFaction.isSafeZone())
|
|
|
|
{
|
|
|
|
if ( ! Conf.safeZoneDenyBuild)
|
2011-07-20 19:22:03 +02:00
|
|
|
return true;
|
2011-10-13 05:31:18 +02:00
|
|
|
|
2011-07-20 19:22:03 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
else if (otherFaction.isWarZone())
|
|
|
|
{
|
|
|
|
if ( ! Conf.warZoneDenyBuild)
|
2011-07-20 19:22:03 +02:00
|
|
|
return true;
|
2011-10-13 05:31:18 +02:00
|
|
|
|
2011-07-20 19:22:03 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-10-12 17:25:01 +02:00
|
|
|
Relation rel = pistonFaction.getRelationTo(otherFaction);
|
2011-07-20 19:22:03 +02:00
|
|
|
|
2011-10-13 05:31:18 +02:00
|
|
|
if (rel.confDenyBuild(otherFaction.hasPlayersOnline()))
|
2011-07-20 19:22:03 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
public static boolean playerCanBuildDestroyBlock(Player player, Location location, String action, boolean justCheck)
|
|
|
|
{
|
2011-10-09 18:35:39 +02:00
|
|
|
FPlayer me = FPlayers.i.get(player);
|
2011-10-13 05:31:18 +02:00
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
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-10-08 22:03:44 +02:00
|
|
|
if (otherFaction.isNone())
|
|
|
|
{
|
2011-10-09 18:35:39 +02:00
|
|
|
if (!Conf.wildernessDenyBuild || 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-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 "+action+" in the wilderness.");
|
2011-10-13 05:31:18 +02:00
|
|
|
|
2011-06-02 01:32:09 +02:00
|
|
|
return false;
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
else if (otherFaction.isSafeZone())
|
|
|
|
{
|
2011-10-08 23:22:02 +02:00
|
|
|
if (!Conf.safeZoneDenyBuild || Permission.MANAGE_SAFE_ZONE.has(player))
|
2011-03-23 17:39:56 +01:00
|
|
|
return true;
|
2011-10-13 05:31:18 +02:00
|
|
|
|
|
|
|
if (!justCheck)
|
2011-10-21 18:14:04 +02:00
|
|
|
me.msg("<b>You can't "+action+" in a safe zone.");
|
2011-10-13 05:31:18 +02:00
|
|
|
|
2011-03-23 17:39:56 +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.warZoneDenyBuild || 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 "+action+" in a war zone.");
|
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-02-06 13:36:11 +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
|
|
|
boolean online = otherFaction.hasPlayersOnline();
|
|
|
|
boolean pain = !justCheck && rel.confPainBuild(online);
|
|
|
|
boolean deny = rel.confDenyBuild(online);
|
|
|
|
|
|
|
|
// hurt the player for building/destroying in other territory?
|
|
|
|
if (pain)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-13 05:31:18 +02:00
|
|
|
player.damage(Conf.actionDeniedPainAmount);
|
2011-09-06 23:35:43 +02:00
|
|
|
|
2011-10-13 05:31:18 +02:00
|
|
|
if (!deny)
|
2011-10-21 18:14:04 +02:00
|
|
|
me.msg("<b>It is painful to try to "+action+" in the territory of "+otherFaction.getTag(myFaction));
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
2011-10-13 05:31:18 +02:00
|
|
|
|
|
|
|
// cancel building/destroying in other territory?
|
|
|
|
if (deny)
|
|
|
|
{
|
|
|
|
if (!justCheck)
|
2011-10-21 18:14:04 +02:00
|
|
|
me.msg("<b>You can't "+action+" in the territory of "+otherFaction.getTag(myFaction));
|
2011-10-13 05:31:18 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-06 23:35:43 +02:00
|
|
|
// Also cancel and/or cause pain if player doesn't have ownership rights for this claim
|
2011-10-13 05:31:18 +02:00
|
|
|
if (Conf.ownedAreasEnabled && (Conf.ownedAreaDenyBuild || Conf.ownedAreaPainBuild) && !otherFaction.playerHasOwnershipRights(me, loc))
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-10-13 05:31:18 +02:00
|
|
|
if (!pain && Conf.ownedAreaPainBuild && !justCheck)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2011-08-04 04:47:49 +02:00
|
|
|
player.damage(Conf.actionDeniedPainAmount);
|
2011-10-13 05:31:18 +02:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
if (!Conf.ownedAreaDenyBuild)
|
2011-10-21 18:14:04 +02:00
|
|
|
me.msg("<b>It is painful to try to "+action+" in this territory, it is owned by: "+otherFaction.getOwnerListString(loc));
|
2011-08-04 04:47:49 +02:00
|
|
|
}
|
2011-10-08 22:03:44 +02:00
|
|
|
if (Conf.ownedAreaDenyBuild)
|
|
|
|
{
|
|
|
|
if (!justCheck)
|
2011-10-21 18:14:04 +02:00
|
|
|
me.msg("<b>You can't "+action+" in this territory, it is owned by: "+otherFaction.getOwnerListString(loc));
|
2011-10-13 05:31:18 +02:00
|
|
|
|
2011-08-03 08:29:51 +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
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|