Checking if player can build in location at interaction

This commit is contained in:
SvenjaReißaus 2019-03-18 22:09:03 -05:00
parent 62d37c061a
commit 4608f26975
No known key found for this signature in database
GPG Key ID: E5494A03FA36D54B
2 changed files with 3 additions and 19 deletions

View File

@ -179,7 +179,6 @@ public class FactionsPlayerListener implements Listener {
return false; return false;
} }
SavageFactions.plugin.log("Trying to match a material with access permission");
PermissableAction action = null; PermissableAction action = null;
if (SavageFactions.plugin.mc113) { if (SavageFactions.plugin.mc113) {
switch (block.getType()) { switch (block.getType()) {
@ -307,7 +306,6 @@ public class FactionsPlayerListener implements Listener {
} }
} }
SavageFactions.plugin.log("Material matched as " + action);
// We only care about some material types. // We only care about some material types.
/// Who was the idiot? /// Who was the idiot?
if (otherFaction.hasPlayersOnline()) { if (otherFaction.hasPlayersOnline()) {
@ -861,9 +859,7 @@ public class FactionsPlayerListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
// only need to check right-clicks and physical as of MC 1.4+; good performance boost // only need to check right-clicks and physical as of MC 1.4+; good performance boost
SavageFactions.plugin.log("Checking if the action aren't left clicks");
if (event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_AIR)) return; if (event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_AIR)) return;
SavageFactions.plugin.log("Attempting to allow food and potis");
if (event.getPlayer().getItemInHand() != null) { if (event.getPlayer().getItemInHand() != null) {
Material handItem = event.getPlayer().getItemInHand().getType(); Material handItem = event.getPlayer().getItemInHand().getType();
if (handItem.isEdible() if (handItem.isEdible()
@ -877,21 +873,14 @@ public class FactionsPlayerListener implements Listener {
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
Player player = event.getPlayer(); Player player = event.getPlayer();
SavageFactions.plugin.log("Checking for material bypass in config");
// Check if the material is bypassing protection // Check if the material is bypassing protection
if (Conf.territoryBypasssProtectedMaterials.contains(block.getType())) return; if (Conf.territoryBypasssProtectedMaterials.contains(block.getType())) return;
if (block == null) return; // clicked in air, apparently if (block == null) return; // clicked in air, apparently
SavageFactions.plugin.log("Checking if I can use the block"); if (!FactionsBlockListener.playerCanBuildDestroyBlock(player, block.getLocation(), "build", false)
if (!canPlayerUseBlock(player, block, false)) { || !canPlayerUseBlock(player, block, false)
event.setCancelled(true); || !playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false)) {
event.setUseInteractedBlock(Event.Result.DENY);
return;
}
SavageFactions.plugin.log("Checking if I can use the item");
if (!playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false)) {
event.setCancelled(true); event.setCancelled(true);
event.setUseInteractedBlock(Event.Result.DENY); event.setUseInteractedBlock(Event.Result.DENY);
return; return;
@ -1029,15 +1018,11 @@ public class FactionsPlayerListener implements Listener {
/// <param name="access">The current's faction access permission for the action</param> /// <param name="access">The current's faction access permission for the action</param>
private static boolean CheckPlayerAccess(Player player, FPlayer me, FLocation loc, Faction myFaction, Access access, PermissableAction action, boolean pain) { private static boolean CheckPlayerAccess(Player player, FPlayer me, FLocation loc, Faction myFaction, Access access, PermissableAction action, boolean pain) {
boolean doPain = pain && Conf.handleExploitInteractionSpam; boolean doPain = pain && Conf.handleExploitInteractionSpam;
SavageFactions.plugin.log("Checking player access, with pain: " + doPain);
if (access != null && access != Access.UNDEFINED) { if (access != null && access != Access.UNDEFINED) {
// TODO: Update this once new access values are added other than just allow / deny. // TODO: Update this once new access values are added other than just allow / deny.
boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty()); boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty());
SavageFactions.plugin.log("Land is owned: " + landOwned);
SavageFactions.plugin.log("Trying to check if the user is in the owner list or is leader of the faction");
if ((landOwned && myFaction.getOwnerListString(loc).contains(player.getName())) || (me.getRole() == Role.LEADER && me.getFactionId().equals(myFaction.getId()))) return true; if ((landOwned && myFaction.getOwnerListString(loc).contains(player.getName())) || (me.getRole() == Role.LEADER && me.getFactionId().equals(myFaction.getId()))) return true;
else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) { else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) {
SavageFactions.plugin.log("Land is owned and player is not on the owner list");
me.msg("<b>You can't do that in this territory, it is owned by: " + myFaction.getOwnerListString(loc)); me.msg("<b>You can't do that in this territory, it is owned by: " + myFaction.getOwnerListString(loc));
if (doPain) { if (doPain) {
player.damage(Conf.actionDeniedPainAmount); player.damage(Conf.actionDeniedPainAmount);
@ -1049,7 +1034,6 @@ public class FactionsPlayerListener implements Listener {
return false; return false;
} }
} }
SavageFactions.plugin.log("Access is " + access + " denying");
return false; return false;
} }
} }