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;
|
|
|
|
import com.massivecraft.factions.Faction;
|
|
|
|
import com.massivecraft.factions.Factions;
|
2011-08-24 00:12:17 +02:00
|
|
|
import com.massivecraft.factions.struct.Relation;
|
2011-02-06 13:36:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
public class FactionsBlockListener extends BlockListener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockPlace(BlockPlaceEvent event) {
|
|
|
|
if (event.isCancelled()) {
|
2011-03-22 17:20:21 +01:00
|
|
|
return;
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
2011-03-30 06:37:32 +02:00
|
|
|
if (!event.canBuild()) {
|
2011-06-10 21:16:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// special case for flint&steel, which should only be prevented by DenyUsage list
|
|
|
|
if (event.getBlockPlaced().getType() == Material.FIRE) {
|
2011-03-30 06:37:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "build")) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
2011-03-08 13:42:48 +01:00
|
|
|
|
2011-03-30 06:37:32 +02:00
|
|
|
@Override
|
|
|
|
public void onBlockBreak(BlockBreakEvent event) {
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "destroy")) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
@Override
|
|
|
|
public void onBlockDamage(BlockDamageEvent event) {
|
|
|
|
if (event.isCancelled()) {
|
2011-03-23 12:00:38 +01:00
|
|
|
return;
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
2011-03-18 00:04:45 +01:00
|
|
|
|
2011-03-30 06:37:32 +02:00
|
|
|
if (event.getInstaBreak() && ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "destroy")) {
|
2011-02-06 13:36:11 +01:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
2011-07-20 19:22:03 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockPistonExtend(BlockPistonExtendEvent event) {
|
|
|
|
if (event.isCancelled() || !Conf.pistonProtectionThroughDenyBuild) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
if (targetBlock.isEmpty() && !canPistonMoveBlock(pistonFaction, targetBlock.getLocation())) {
|
|
|
|
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
|
|
|
|
public void onBlockPistonRetract(BlockPistonRetractEvent event) {
|
|
|
|
// if not a sticky piston, retraction should be fine
|
|
|
|
if (event.isCancelled() || !event.isSticky() || !Conf.pistonProtectionThroughDenyBuild) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Location targetLoc = event.getRetractLocation();
|
|
|
|
|
|
|
|
// if potentially retracted block is just air, no worries
|
|
|
|
if (targetLoc.getBlock().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Faction pistonFaction = Board.getFactionAt(new FLocation(event.getBlock()));
|
|
|
|
|
|
|
|
if (!canPistonMoveBlock(pistonFaction, targetLoc)) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean canPistonMoveBlock(Faction pistonFaction, Location target) {
|
|
|
|
|
|
|
|
Faction otherFaction = Board.getFactionAt(new FLocation(target));
|
|
|
|
|
|
|
|
if (pistonFaction == otherFaction) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (otherFaction.isNone()) {
|
2011-08-23 07:37:31 +02:00
|
|
|
if (!Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(target.getWorld().getName())) {
|
2011-07-20 19:22:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (otherFaction.isSafeZone()) {
|
|
|
|
if (!Conf.safeZoneDenyBuild) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (otherFaction.isWarZone()) {
|
|
|
|
if (!Conf.warZoneDenyBuild) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-24 00:12:17 +02:00
|
|
|
Relation rel = pistonFaction.getRelation(otherFaction);
|
2011-07-20 19:22:03 +02:00
|
|
|
boolean online = otherFaction.hasPlayersOnline();
|
|
|
|
|
|
|
|
if (
|
2011-08-24 00:12:17 +02:00
|
|
|
(online && (rel.isEnemy() ? Conf.territoryEnemyDenyBuild : (rel.isAlly() ? Conf.territoryAllyDenyBuild : Conf.territoryDenyBuild)))
|
|
|
|
|| (!online && (rel.isEnemy() ? Conf.territoryEnemyDenyBuildWhenOffline : (rel.isAlly() ? Conf.territoryAllyDenyBuildWhenOffline : Conf.territoryDenyBuildWhenOffline)))
|
2011-07-20 19:22:03 +02:00
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
public boolean playerCanBuildDestroyBlock(Player player, Block block, String action) {
|
2011-04-04 14:16:53 +02:00
|
|
|
|
2011-04-06 12:04:57 +02:00
|
|
|
if (Conf.adminBypassPlayers.contains(player.getName())) {
|
2011-04-04 14:16:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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-06-02 01:32:09 +02:00
|
|
|
FPlayer me = FPlayer.get(player);
|
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-03-23 17:39:56 +01:00
|
|
|
if (otherFaction.isNone()) {
|
2011-08-23 07:37:31 +02:00
|
|
|
if (!Conf.wildernessDenyBuild || Factions.hasPermAdminBypass(player) || Conf.worldsNoWildernessProtection.contains(block.getWorld().getName())) {
|
2011-06-02 01:32:09 +02:00
|
|
|
return true; // This is not faction territory. Use whatever you like here.
|
|
|
|
}
|
|
|
|
me.sendMessage("You can't "+action+" in the wilderness.");
|
|
|
|
return false;
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
2011-06-16 09:37:05 +02:00
|
|
|
else if (otherFaction.isSafeZone()) {
|
|
|
|
if (!Conf.safeZoneDenyBuild || Factions.hasPermManageSafeZone(player)) {
|
2011-03-23 17:39:56 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
me.sendMessage("You can't "+action+" in a safe zone.");
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-29 23:28:29 +02:00
|
|
|
else if (otherFaction.isWarZone()) {
|
2011-06-16 09:37:05 +02:00
|
|
|
if (!Conf.warZoneDenyBuild || Factions.hasPermManageWarZone(player)) {
|
2011-05-29 23:28:29 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
me.sendMessage("You can't "+action+" in a war zone.");
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-06 23:35:43 +02:00
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
Faction myFaction = me.getFaction();
|
2011-08-24 00:12:17 +02:00
|
|
|
Relation rel = myFaction.getRelation(otherFaction);
|
2011-09-06 23:35:43 +02:00
|
|
|
boolean ownershipFail = Conf.ownedAreasEnabled && (Conf.ownedAreaDenyBuild || Conf.ownedAreaPainBuild) && !otherFaction.playerHasOwnershipRights(me, loc);
|
|
|
|
|
|
|
|
// Cancel and/or cause pain (depending on configuration) if we are not in our own territory
|
|
|
|
if (!rel.isMember()) {
|
2011-06-21 07:20:36 +02:00
|
|
|
boolean online = otherFaction.hasPlayersOnline();
|
2011-09-06 23:35:43 +02:00
|
|
|
boolean pain = rel.confPainBuild(online);
|
|
|
|
boolean deny = rel.confDenyBuild(online);
|
|
|
|
|
2011-08-04 04:47:49 +02:00
|
|
|
//hurt the player for building/destroying?
|
|
|
|
if (pain) {
|
|
|
|
player.damage(Conf.actionDeniedPainAmount);
|
|
|
|
if (!deny) {
|
2011-08-03 08:29:51 +02:00
|
|
|
me.sendMessage("You are hurt for "+action+" in the territory of "+otherFaction.getTag(myFaction));
|
2011-09-06 23:35:43 +02:00
|
|
|
if (!Conf.ownedAreaDenyBuild) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-03 08:29:51 +02:00
|
|
|
}
|
2011-08-04 04:47:49 +02:00
|
|
|
}
|
|
|
|
if (deny) {
|
|
|
|
me.sendMessage("You can't "+action+" in the territory of "+otherFaction.getTag(myFaction));
|
|
|
|
return false;
|
|
|
|
}
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
2011-09-06 23:35:43 +02:00
|
|
|
// Also cancel and/or cause pain if player doesn't have ownership rights for this claim
|
|
|
|
if (ownershipFail && !Factions.hasPermOwnershipBypass(player)
|
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-08-04 04:47:49 +02:00
|
|
|
if (Conf.ownedAreaPainBuild){
|
|
|
|
player.damage(Conf.actionDeniedPainAmount);
|
|
|
|
if (!Conf.ownedAreaDenyBuild) {
|
|
|
|
me.sendMessage("You are hurt for "+action+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc));
|
|
|
|
}
|
|
|
|
}
|
2011-08-03 08:29:51 +02:00
|
|
|
if (Conf.ownedAreaDenyBuild){
|
|
|
|
me.sendMessage("You can't "+action+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc));
|
|
|
|
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-02-06 13:36:11 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|