use of org.spongepowered.api.event.Listener 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 org.spongepowered.api.event.Listener 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);
}
}
use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.
the class RPBlockListener method onBlockStartBurn.
/*
@Listener
public void onFrameBrake(HangingBreakEvent e) {
if (e.isCancelled()){
return;
}
RedProtect.get().logger.debug("Is BlockListener - HangingBreakEvent event");
Entity ent = e.getEntity();
Location l = e.getEntity().getLocation();
if ((ent instanceof ItemFrame || ent instanceof Painting) && (e.getCause().toPlain().equals("EXPLOSION"))) {
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canFire()){
e.setCancelled(true);
return;
}
}
}
*/
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockStartBurn(IgniteEntityEvent e) {
Entity b = e.getTargetEntity();
Cause ignit = e.getCause();
if (b == null) {
return;
}
RedProtect.get().logger.debug("blocks", "Is BlockIgniteEvent event. Canceled? " + e.isCancelled());
Region r = RedProtect.get().rm.getTopRegion(b.getLocation());
if (r != null && !r.canFire()) {
if (ignit.first(Player.class).isPresent()) {
Player p = ignit.first(Player.class).get();
if (!r.canBuild(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantplace");
e.setCancelled(true);
return;
}
} else {
e.setCancelled(true);
return;
}
if (ignit.first(BlockSnapshot.class).isPresent() && (ignit.first(BlockSnapshot.class).get().getState().getType().equals(BlockTypes.FIRE) || ignit.first(BlockSnapshot.class).get().getState().getType().getName().contains("lava"))) {
e.setCancelled(true);
return;
}
if (ignit.first(Lightning.class).isPresent() || ignit.first(Explosion.class).isPresent() || ignit.first(Fireball.class).isPresent()) {
e.setCancelled(true);
}
}
}
use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.
the class RPBlockListener method onLightning.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onLightning(LightningEvent.Pre e, @First Lightning light) {
RedProtect.get().logger.debug("blocks", "Is LightningStrikeEvent event");
Location<World> l = light.getLocation();
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null && !r.canFire()) {
e.setCancelled(true);
}
}
use of org.spongepowered.api.event.Listener in project RedProtect by FabioZumbi12.
the class RPBlockListener method onInteractBlock.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractBlock(InteractBlockEvent event, @First Player p) {
BlockSnapshot b = event.getTargetBlock();
Location<World> l = null;
RedProtect.get().logger.debug("player", "RPBlockListener - Is InteractBlockEvent event");
if (!b.getState().getType().equals(BlockTypes.AIR)) {
l = b.getLocation().get();
RedProtect.get().logger.debug("player", "RPBlockListener - Is InteractBlockEvent event. The block is " + b.getState().getType().getName());
} else {
l = p.getLocation();
}
Region r = RedProtect.get().rm.getTopRegion(l);
if (r != null) {
ItemType itemInHand = ItemTypes.NONE;
if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
itemInHand = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
} else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
itemInHand = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
}
if (itemInHand.equals(ItemTypes.ARMOR_STAND) && !r.canBuild(p)) {
RPLang.sendMessage(p, "blocklistener.region.cantbuild");
event.setCancelled(true);
}
}
}
Aggregations