Added 3 new hookable functions to main Factions class, for use by other plugins:

boolean isPlayerAllowedToBuildHere(Player player, Location location)
boolean isPlayerAllowedToInteractWith(Player player, Block block)
boolean isPlayerAllowedToUseThisHere(Player player, Location location, Material material)
Also update Bukkit lib for new RB.
This commit is contained in:
Brettflan 2011-10-04 22:46:11 -05:00
parent 58d97076b8
commit 7c249e1884
4 changed files with 70 additions and 29 deletions

Binary file not shown.

View File

@ -12,7 +12,9 @@ import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.block.Block;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -266,7 +268,7 @@ public class Factions extends JavaPlugin {
// This value will be updated whenever new hooks are added // This value will be updated whenever new hooks are added
public int hookSupportVersion() { public int hookSupportVersion() {
return 2; return 3;
} }
// If another plugin is handling insertion of chat tags, this should be used to notify Factions // If another plugin is handling insertion of chat tags, this should be used to notify Factions
@ -377,6 +379,21 @@ public class Factions extends JavaPlugin {
return players; return players;
} }
// check if player is allowed to build/destroy in a particular location
public boolean isPlayerAllowedToBuildHere(Player player, Location location) {
return FactionsBlockListener.playerCanBuildDestroyBlock(player, location, "", true);
}
// check if player is allowed to interact with the specified block (doors/chests/whatever)
public boolean isPlayerAllowedToInteractWith(Player player, Block block) {
return FactionsPlayerListener.canPlayerUseBlock(player, block, true);
}
// check if player is allowed to use a specified item (flint&steel, buckets, etc) in a particular location
public boolean isPlayerAllowedToUseThisHere(Player player, Location location, Material material) {
return FactionsPlayerListener.playerCanUseItemHere(player, location, material, true);
}
// -------------------------------------------- // // -------------------------------------------- //
// Test rights // Test rights
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -35,7 +35,7 @@ public class FactionsBlockListener extends BlockListener {
return; return;
} }
if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "build")) { if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "build", false)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -46,7 +46,7 @@ public class FactionsBlockListener extends BlockListener {
return; return;
} }
if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "destroy")) { if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -57,7 +57,7 @@ public class FactionsBlockListener extends BlockListener {
return; return;
} }
if (event.getInstaBreak() && ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "destroy")) { if (event.getInstaBreak() && ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -148,35 +148,41 @@ public class FactionsBlockListener extends BlockListener {
return true; return true;
} }
public boolean playerCanBuildDestroyBlock(Player player, Block block, String action) { public static boolean playerCanBuildDestroyBlock(Player player, Location location, String action, boolean justCheck) {
if (Conf.adminBypassPlayers.contains(player.getName())) { if (Conf.adminBypassPlayers.contains(player.getName())) {
return true; return true;
} }
FLocation loc = new FLocation(block); FLocation loc = new FLocation(location);
Faction otherFaction = Board.getFactionAt(loc); Faction otherFaction = Board.getFactionAt(loc);
FPlayer me = FPlayer.get(player); FPlayer me = FPlayer.get(player);
if (otherFaction.isNone()) { if (otherFaction.isNone()) {
if (!Conf.wildernessDenyBuild || Factions.hasPermAdminBypass(player) || Conf.worldsNoWildernessProtection.contains(block.getWorld().getName())) { if (!Conf.wildernessDenyBuild || Factions.hasPermAdminBypass(player) || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName())) {
return true; // This is not faction territory. Use whatever you like here. return true; // This is not faction territory. Use whatever you like here.
} }
me.sendMessage("You can't "+action+" in the wilderness."); if (!justCheck) {
me.sendMessage("You can't "+action+" in the wilderness.");
}
return false; return false;
} }
else if (otherFaction.isSafeZone()) { else if (otherFaction.isSafeZone()) {
if (!Conf.safeZoneDenyBuild || Factions.hasPermManageSafeZone(player)) { if (!Conf.safeZoneDenyBuild || Factions.hasPermManageSafeZone(player)) {
return true; return true;
} }
me.sendMessage("You can't "+action+" in a safe zone."); if (!justCheck) {
me.sendMessage("You can't "+action+" in a safe zone.");
}
return false; return false;
} }
else if (otherFaction.isWarZone()) { else if (otherFaction.isWarZone()) {
if (!Conf.warZoneDenyBuild || Factions.hasPermManageWarZone(player)) { if (!Conf.warZoneDenyBuild || Factions.hasPermManageWarZone(player)) {
return true; return true;
} }
me.sendMessage("You can't "+action+" in a war zone."); if (!justCheck) {
me.sendMessage("You can't "+action+" in a war zone.");
}
return false; return false;
} }
@ -187,7 +193,7 @@ public class FactionsBlockListener extends BlockListener {
// Cancel and/or cause pain (depending on configuration) if we are not in our own territory // Cancel and/or cause pain (depending on configuration) if we are not in our own territory
if (!rel.isMember()) { if (!rel.isMember()) {
boolean online = otherFaction.hasPlayersOnline(); boolean online = otherFaction.hasPlayersOnline();
boolean pain = rel.confPainBuild(online); boolean pain = (!justCheck) && rel.confPainBuild(online);
boolean deny = rel.confDenyBuild(online); boolean deny = rel.confDenyBuild(online);
//hurt the player for building/destroying? //hurt the player for building/destroying?
@ -201,20 +207,24 @@ public class FactionsBlockListener extends BlockListener {
} }
} }
if (deny) { if (deny) {
me.sendMessage("You can't "+action+" in the territory of "+otherFaction.getTag(myFaction)); if (!justCheck) {
me.sendMessage("You can't "+action+" in the territory of "+otherFaction.getTag(myFaction));
}
return false; return false;
} }
} }
// Also cancel and/or cause pain if player doesn't have ownership rights for this claim // Also cancel and/or cause pain if player doesn't have ownership rights for this claim
else if (rel.isMember() && ownershipFail && !Factions.hasPermOwnershipBypass(player)) { else if (rel.isMember() && ownershipFail && !Factions.hasPermOwnershipBypass(player)) {
if (Conf.ownedAreaPainBuild){ if (Conf.ownedAreaPainBuild && !justCheck){
player.damage(Conf.actionDeniedPainAmount); player.damage(Conf.actionDeniedPainAmount);
if (!Conf.ownedAreaDenyBuild) { if (!Conf.ownedAreaDenyBuild) {
me.sendMessage("You are hurt for "+action+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc)); me.sendMessage("You are hurt for "+action+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc));
} }
} }
if (Conf.ownedAreaDenyBuild){ if (Conf.ownedAreaDenyBuild){
me.sendMessage("You can't "+action+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc)); if (!justCheck) {
me.sendMessage("You can't "+action+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc));
}
return false; return false;
} }
} }

View File

@ -259,7 +259,7 @@ public class FactionsPlayerListener extends PlayerListener{
return; // clicked in air, apparently return; // clicked in air, apparently
} }
if ( ! canPlayerUseBlock(player, block)) { if ( ! canPlayerUseBlock(player, block, false)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -268,19 +268,19 @@ public class FactionsPlayerListener extends PlayerListener{
return; // only interested on right-clicks for below return; // only interested on right-clicks for below
} }
if ( ! this.playerCanUseItemHere(player, block, event.getMaterial())) { if ( ! this.playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
public boolean playerCanUseItemHere(Player player, Block block, Material material) { public static boolean playerCanUseItemHere(Player player, Location location, Material material, boolean justCheck) {
if (Conf.adminBypassPlayers.contains(player.getName())) { if (Conf.adminBypassPlayers.contains(player.getName())) {
return true; return true;
} }
FLocation loc = new FLocation(block); FLocation loc = new FLocation(location);
Faction otherFaction = Board.getFactionAt(loc); Faction otherFaction = Board.getFactionAt(loc);
if (otherFaction.hasPlayersOnline()){ if (otherFaction.hasPlayersOnline()){
@ -296,24 +296,30 @@ public class FactionsPlayerListener extends PlayerListener{
FPlayer me = FPlayer.get(player); FPlayer me = FPlayer.get(player);
if (otherFaction.isNone()) { if (otherFaction.isNone()) {
if (!Conf.wildernessDenyUseage || Factions.hasPermAdminBypass(player) || Conf.worldsNoWildernessProtection.contains(block.getWorld().getName())) { if (!Conf.wildernessDenyUseage || Factions.hasPermAdminBypass(player) || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName())) {
return true; // This is not faction territory. Use whatever you like here. return true; // This is not faction territory. Use whatever you like here.
} }
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the wilderness."); if (!justCheck) {
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the wilderness.");
}
return false; return false;
} }
else if (otherFaction.isSafeZone()) { else if (otherFaction.isSafeZone()) {
if (!Conf.safeZoneDenyUseage || Factions.hasPermManageSafeZone(player)) { if (!Conf.safeZoneDenyUseage || Factions.hasPermManageSafeZone(player)) {
return true; return true;
} }
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in a safe zone."); if (!justCheck) {
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in a safe zone.");
}
return false; return false;
} }
else if (otherFaction.isWarZone()) { else if (otherFaction.isWarZone()) {
if (!Conf.warZoneDenyUseage || Factions.hasPermManageWarZone(player)) { if (!Conf.warZoneDenyUseage || Factions.hasPermManageWarZone(player)) {
return true; return true;
} }
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in a war zone."); if (!justCheck) {
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in a war zone.");
}
return false; return false;
} }
@ -323,19 +329,23 @@ public class FactionsPlayerListener extends PlayerListener{
// Cancel if we are not in our own territory // Cancel if we are not in our own territory
if (!rel.isMember() && rel.confDenyUseage()) { if (!rel.isMember() && rel.confDenyUseage()) {
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction)); if (!justCheck) {
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction));
}
return false; return false;
} }
// Also cancel if player doesn't have ownership rights for this claim // Also cancel if player doesn't have ownership rights for this claim
else if (rel.isMember() && ownershipFail && !Factions.hasPermOwnershipBypass(player)) { else if (rel.isMember() && ownershipFail && !Factions.hasPermOwnershipBypass(player)) {
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc)); if (!justCheck) {
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc));
}
return false; return false;
} }
return true; return true;
} }
public boolean canPlayerUseBlock(Player player, Block block) { public static boolean canPlayerUseBlock(Player player, Block block, boolean justCheck) {
if (Conf.adminBypassPlayers.contains(player.getName())) { if (Conf.adminBypassPlayers.contains(player.getName())) {
return true; return true;
@ -368,12 +378,16 @@ public class FactionsPlayerListener extends PlayerListener{
// You may use any block unless it is another faction's territory... // You may use any block unless it is another faction's territory...
if (rel.isNeutral() || (rel.isEnemy() && Conf.territoryEnemyProtectMaterials) || (rel.isAlly() && Conf.territoryAllyProtectMaterials)) { if (rel.isNeutral() || (rel.isEnemy() && Conf.territoryEnemyProtectMaterials) || (rel.isAlly() && Conf.territoryAllyProtectMaterials)) {
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction)); if (!justCheck) {
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction));
}
return false; return false;
} }
// Also cancel if player doesn't have ownership rights for this claim // Also cancel if player doesn't have ownership rights for this claim
else if (rel.isMember() && ownershipFail && !Factions.hasPermOwnershipBypass(player)) { else if (rel.isMember() && ownershipFail && !Factions.hasPermOwnershipBypass(player)) {
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc)); if (!justCheck) {
me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc));
}
return false; return false;
} }
@ -402,7 +416,7 @@ public class FactionsPlayerListener extends PlayerListener{
Block block = event.getBlockClicked(); Block block = event.getBlockClicked();
Player player = event.getPlayer(); Player player = event.getPlayer();
if ( ! this.playerCanUseItemHere(player, block, event.getBucket())) { if ( ! this.playerCanUseItemHere(player, block.getLocation(), event.getBucket(), false)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -416,7 +430,7 @@ public class FactionsPlayerListener extends PlayerListener{
Block block = event.getBlockClicked(); Block block = event.getBlockClicked();
Player player = event.getPlayer(); Player player = event.getPlayer();
if ( ! this.playerCanUseItemHere(player, block, event.getBucket())) { if ( ! this.playerCanUseItemHere(player, block.getLocation(), event.getBucket(), false)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }