Fixed Spawner Breaking NPE

This commit is contained in:
Driftay 2019-12-22 01:03:47 -05:00
parent 91ca08e66b
commit 3a22bb348e
2 changed files with 21 additions and 36 deletions

View File

@ -38,10 +38,6 @@ import java.util.List;
public class FactionsBlockListener implements Listener { public class FactionsBlockListener implements Listener {
/**
* @author FactionsUUID Team
*/
public static HashMap<String, Location> bannerLocations = new HashMap<>(); public static HashMap<String, Location> bannerLocations = new HashMap<>();
private HashMap<String, Boolean> bannerCooldownMap = new HashMap<>(); private HashMap<String, Boolean> bannerCooldownMap = new HashMap<>();
@ -82,7 +78,6 @@ public class FactionsBlockListener implements Listener {
boolean pain = !justCheck && myFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW; boolean pain = !justCheck && myFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW;
return CheckActionState(myFaction, loc, me, PermissableAction.fromString(action), pain); return CheckActionState(myFaction, loc, me, PermissableAction.fromString(action), pain);
} }
// Something failed prevent build
return false; return false;
} }
@ -128,20 +123,15 @@ public class FactionsBlockListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
if (!event.canBuild()) return; if (!event.canBuild()) return;
// special case for flint&steel, which should only be prevented by DenyUsage list
if (event.getBlockPlaced().getType() == Material.FIRE) return; if (event.getBlockPlaced().getType() == Material.FIRE) return;
boolean isSpawner = event.getBlock().getType().equals(XMaterial.SPAWNER.parseMaterial());
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), !isSpawner ? "build" : "mine spawners", false)) { if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "build", false)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (isSpawner) { if (event.getBlock().getType().equals(XMaterial.SPAWNER.parseMaterial()) && Conf.spawnerLock) {
if (Conf.spawnerLock) { event.setCancelled(true);
event.setCancelled(true); event.getPlayer().sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_SPAWNER_LOCK_CANNOT_PLACE.toString()));
event.getPlayer().sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_SPAWNER_LOCK_CANNOT_PLACE.toString()));
}
} }
} }
@ -425,9 +415,9 @@ public class FactionsBlockListener implements Listener {
public void entityDamage(EntityDamageEvent e) { public void entityDamage(EntityDamageEvent e) {
if (!Conf.gracePeriod) return; if (!Conf.gracePeriod) return;
if (e.getEntity() instanceof Player) { if (e.getEntity() instanceof Player) {
if (e.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) { if (e.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) {
e.setCancelled(true); e.setCancelled(true);
} }
} }
} }
@ -462,9 +452,17 @@ public class FactionsBlockListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
boolean isSpawner = event.getBlock().getType() == XMaterial.SPAWNER.parseMaterial(); FPlayer fme = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), !isSpawner ? "destroy" : "mine spawners", false)) { if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
event.setCancelled(true); event.setCancelled(true);
return;
}
if (!fme.hasFaction()) return;
if (event.getBlock().getType() == XMaterial.SPAWNER.parseMaterial() && !fme.isAdminBypassing()) {
Access access = fme.getFaction().getAccess(fme, PermissableAction.SPAWNER);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "mine spawners");
}
} }
} }

View File

@ -23,7 +23,6 @@ public class FactionsExploitListener implements Listener {
return ((from.getX() > target.getX() && (from.getX() - target.getX() < thickness)) || (target.getX() > from.getX() && (target.getX() - from.getX() < thickness)) || (from.getZ() > target.getZ() && (from.getZ() - target.getZ() < thickness)) || (target.getZ() > from.getZ() && (target.getZ() - from.getZ() < thickness))); return ((from.getX() > target.getX() && (from.getX() - target.getX() < thickness)) || (target.getX() > from.getX() && (target.getX() - from.getX() < thickness)) || (from.getZ() > target.getZ() && (from.getZ() - target.getZ() < thickness)) || (target.getZ() > from.getZ() && (target.getZ() - from.getZ() < thickness)));
} }
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void obsidianGenerator(BlockFromToEvent event) { public void obsidianGenerator(BlockFromToEvent event) {
if (!Conf.handleExploitObsidianGenerators) { if (!Conf.handleExploitObsidianGenerators) {
@ -33,23 +32,11 @@ public class FactionsExploitListener implements Listener {
// thanks to ObGenBlocker and WorldGuard for this method // thanks to ObGenBlocker and WorldGuard for this method
Block block = event.getToBlock(); Block block = event.getToBlock();
// Added this so it wont die on 1.14 :) Material source = event.getBlock().getType();
if (FactionsPlugin.getInstance().mc114) { Material target = block.getType();
Material source = event.getBlock().getType(); if ((target == XMaterial.REDSTONE_WIRE.parseMaterial() || target == XMaterial.TRIPWIRE.parseMaterial()) && (source == XMaterial.AIR.parseMaterial() || source == XMaterial.LAVA.parseMaterial() || source.toString().equalsIgnoreCase("STATIONARY_LAVA"))) {
Material target = block.getType(); block.setType(XMaterial.AIR.parseMaterial());
if ((target == Material.REDSTONE_WIRE || target == Material.TRIPWIRE) && (source == Material.AIR || source == Material.LEGACY_STATIONARY_LAVA || source == Material.LEGACY_LAVA)) {
block.setType(Material.AIR);
}
return;
} }
// run this for all versions below 1.14
int source = event.getBlock().getType().getId();
int target = block.getType().getId();
if ((target == 55 || target == 132) && (source == 0 || source == 10 || source == 11)) {
block.setType(Material.AIR);
}
} }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)