use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.
the class RPBlockListener method onPistonExtend.
@EventHandler
public void onPistonExtend(BlockPistonExtendEvent e) {
RedProtect.get().logger.debug("RPBlockListener - Is BlockPistonExtendEvent event");
if (RPConfig.getBool("performance.disable-PistonEvent-handler")) {
return;
}
// delay piston
if (RPConfig.getBool("performance.piston.use-piston-restricter")) {
if (pistonExtendDelay.contains(e.getBlock().getLocation().toString())) {
e.setCancelled(true);
return;
} else {
delayExtendPiston(e.getBlock().getLocation().toString());
}
}
Block piston = e.getBlock();
List<Block> blocks = e.getBlocks();
Region pr = RedProtect.get().rm.getTopRegion(piston.getLocation());
Boolean antih = RPConfig.getBool("region-settings.anti-hopper");
World w = e.getBlock().getWorld();
for (Block b : blocks) {
RedProtect.get().logger.debug("BlockPistonExtendEvent event - Block: " + b.getType().name());
RedProtect.get().logger.debug("BlockPistonExtendEvent event - Relative: " + b.getRelative(e.getDirection()).getType().name());
Region br = RedProtect.get().rm.getTopRegion(b.getRelative(e.getDirection()).getLocation());
if (pr == null && br != null || (pr != null && br != null && pr != br && !pr.sameLeaders(br))) {
e.setCancelled(true);
return;
}
if (antih) {
int x = b.getX();
int y = b.getY();
int z = b.getZ();
Block ib = w.getBlockAt(x, y + 1, z);
if (!cont.canWorldBreak(ib) || !cont.canWorldBreak(b)) {
e.setCancelled(true);
return;
}
}
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.
the class RPBlockListener method onFrameBrake.
@EventHandler
public void onFrameBrake(HangingBreakEvent e) {
RedProtect.get().logger.debug("Is BlockListener - HangingBreakEvent event");
if (e.isCancelled()) {
return;
}
Entity ent = e.getEntity();
Location l = e.getEntity().getLocation();
if ((ent instanceof ItemFrame || ent instanceof Painting) && (e.getCause().toString().equals("EXPLOSION"))) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canFire()) {
e.setCancelled(true);
}
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.
the class RPBlockListener method onEntityExplode.
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityExplode(EntityExplodeEvent e) {
RedProtect.get().logger.debug("Is BlockListener - EntityExplodeEvent event");
List<Block> toRemove = new ArrayList<>();
if (e.getEntity() == null) {
return;
}
Region or = RedProtect.get().rm.getTopRegion(e.getEntity().getLocation());
for (Block b : e.blockList()) {
if (b == null) {
continue;
}
RedProtect.get().logger.debug("Blocks: " + b.getType().name());
Location l = b.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canFire() || !cont.canWorldBreak(b)) {
RedProtect.get().logger.debug("canWorldBreak Called!");
// e.setCancelled(true);
toRemove.add(b);
continue;
}
if (r == null) {
continue;
}
if (r != or) {
toRemove.add(b);
continue;
}
if (e.getEntity() instanceof LivingEntity && !r.canMobLoot()) {
toRemove.add(b);
}
}
if (!toRemove.isEmpty()) {
e.blockList().removeAll(toRemove);
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.
the class RPBlockListener method onBlockBreakGeneric.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBreakGeneric(ChangeBlockEvent.Break e) {
if (e.getCause().root().toString().contains("minecraft:fire")) {
BlockSnapshot b = e.getTransactions().get(0).getOriginal();
Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get());
if (r != null && !r.canFire() && !b.getState().getType().equals(BlockTypes.FIRE)) {
e.setCancelled(true);
RedProtect.get().logger.debug("blocks", "Tryed to break from FIRE!");
}
}
}
use of br.net.fabiozumbi12.RedProtect.Sponge.Region in project RedProtect by FabioZumbi12.
the class RPBlockListener method onBlockBreak.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBreak(ChangeBlockEvent.Break e, @First Player p) {
RedProtect.get().logger.debug("blocks", "BlockListener - Is ChangeBlockEvent.Break event!");
BlockSnapshot b = e.getTransactions().get(0).getOriginal();
Location<World> bloc = b.getLocation().get();
World w = bloc.getExtent();
Boolean antih = RedProtect.get().cfgs.getBool("region-settings.anti-hopper");
Region r = RedProtect.get().rm.getTopRegion(bloc);
if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) {
int x = bloc.getBlockX();
int y = bloc.getBlockY();
int z = bloc.getBlockZ();
BlockSnapshot ib = w.createSnapshot(x, y + 1, z);
if ((antih && !cont.canBreak(p, ib)) || !cont.canBreak(p, b)) {
RPLang.sendMessage(p, "blocklistener.container.breakinside");
e.setCancelled(true);
return;
}
}
if (r == null && RedProtect.get().cfgs.getGlobalFlagList(p.getWorld().getName(), "if-build-false", "break-blocks").contains(b.getState().getType().getName())) {
return;
}
if (r != null && b.getState().getType().equals(BlockTypes.MOB_SPAWNER) && r.allowSpawner(p)) {
return;
}
if (r != null && !r.canBuild(p) && !r.canTree(b) && !r.canMining(b) && !r.canCrops(b) && !r.canBreak(b)) {
RPLang.sendMessage(p, "blocklistener.region.cantbuild");
e.setCancelled(true);
}
}
Aggregations