mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-22 18:26:04 +01:00
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:
parent
58d97076b8
commit
7c249e1884
Binary file not shown.
@ -12,7 +12,9 @@ import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -266,7 +268,7 @@ public class Factions extends JavaPlugin {
|
||||
|
||||
// This value will be updated whenever new hooks are added
|
||||
public int hookSupportVersion() {
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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
|
||||
// -------------------------------------------- //
|
||||
|
@ -35,7 +35,7 @@ public class FactionsBlockListener extends BlockListener {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "build")) {
|
||||
if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "build", false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -46,7 +46,7 @@ public class FactionsBlockListener extends BlockListener {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "destroy")) {
|
||||
if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -57,7 +57,7 @@ public class FactionsBlockListener extends BlockListener {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -148,35 +148,41 @@ public class FactionsBlockListener extends BlockListener {
|
||||
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())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
FLocation loc = new FLocation(block);
|
||||
FLocation loc = new FLocation(location);
|
||||
Faction otherFaction = Board.getFactionAt(loc);
|
||||
FPlayer me = FPlayer.get(player);
|
||||
|
||||
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.
|
||||
}
|
||||
me.sendMessage("You can't "+action+" in the wilderness.");
|
||||
if (!justCheck) {
|
||||
me.sendMessage("You can't "+action+" in the wilderness.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (otherFaction.isSafeZone()) {
|
||||
if (!Conf.safeZoneDenyBuild || Factions.hasPermManageSafeZone(player)) {
|
||||
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;
|
||||
}
|
||||
else if (otherFaction.isWarZone()) {
|
||||
if (!Conf.warZoneDenyBuild || Factions.hasPermManageWarZone(player)) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
if (!rel.isMember()) {
|
||||
boolean online = otherFaction.hasPlayersOnline();
|
||||
boolean pain = rel.confPainBuild(online);
|
||||
boolean pain = (!justCheck) && rel.confPainBuild(online);
|
||||
boolean deny = rel.confDenyBuild(online);
|
||||
|
||||
//hurt the player for building/destroying?
|
||||
@ -201,20 +207,24 @@ public class FactionsBlockListener extends BlockListener {
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
// Also cancel and/or cause pain if player doesn't have ownership rights for this claim
|
||||
else if (rel.isMember() && ownershipFail && !Factions.hasPermOwnershipBypass(player)) {
|
||||
if (Conf.ownedAreaPainBuild){
|
||||
if (Conf.ownedAreaPainBuild && !justCheck){
|
||||
player.damage(Conf.actionDeniedPainAmount);
|
||||
if (!Conf.ownedAreaDenyBuild) {
|
||||
me.sendMessage("You are hurt for "+action+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc));
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ public class FactionsPlayerListener extends PlayerListener{
|
||||
return; // clicked in air, apparently
|
||||
}
|
||||
|
||||
if ( ! canPlayerUseBlock(player, block)) {
|
||||
if ( ! canPlayerUseBlock(player, block, false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -268,19 +268,19 @@ public class FactionsPlayerListener extends PlayerListener{
|
||||
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);
|
||||
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())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
FLocation loc = new FLocation(block);
|
||||
FLocation loc = new FLocation(location);
|
||||
Faction otherFaction = Board.getFactionAt(loc);
|
||||
|
||||
if (otherFaction.hasPlayersOnline()){
|
||||
@ -296,24 +296,30 @@ public class FactionsPlayerListener extends PlayerListener{
|
||||
FPlayer me = FPlayer.get(player);
|
||||
|
||||
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.
|
||||
}
|
||||
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;
|
||||
}
|
||||
else if (otherFaction.isSafeZone()) {
|
||||
if (!Conf.safeZoneDenyUseage || Factions.hasPermManageSafeZone(player)) {
|
||||
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;
|
||||
}
|
||||
else if (otherFaction.isWarZone()) {
|
||||
if (!Conf.warZoneDenyUseage || Factions.hasPermManageWarZone(player)) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -323,19 +329,23 @@ public class FactionsPlayerListener extends PlayerListener{
|
||||
|
||||
// Cancel if we are not in our own territory
|
||||
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;
|
||||
}
|
||||
// Also cancel if player doesn't have ownership rights for this claim
|
||||
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 true;
|
||||
}
|
||||
|
||||
public boolean canPlayerUseBlock(Player player, Block block) {
|
||||
public static boolean canPlayerUseBlock(Player player, Block block, boolean justCheck) {
|
||||
|
||||
if (Conf.adminBypassPlayers.contains(player.getName())) {
|
||||
return true;
|
||||
@ -368,12 +378,16 @@ public class FactionsPlayerListener extends PlayerListener{
|
||||
|
||||
// You may use any block unless it is another faction's territory...
|
||||
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;
|
||||
}
|
||||
// Also cancel if player doesn't have ownership rights for this claim
|
||||
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;
|
||||
}
|
||||
|
||||
@ -402,7 +416,7 @@ public class FactionsPlayerListener extends PlayerListener{
|
||||
Block block = event.getBlockClicked();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if ( ! this.playerCanUseItemHere(player, block, event.getBucket())) {
|
||||
if ( ! this.playerCanUseItemHere(player, block.getLocation(), event.getBucket(), false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -416,7 +430,7 @@ public class FactionsPlayerListener extends PlayerListener{
|
||||
Block block = event.getBlockClicked();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if ( ! this.playerCanUseItemHere(player, block, event.getBucket())) {
|
||||
if ( ! this.playerCanUseItemHere(player, block.getLocation(), event.getBucket(), false)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user