use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.
the class RPBlockListener method onPistonEvent.
// TODO Test events
/*
@Listener
public void onListenEvent(TargetLivingEvent event) {
RedProtect.get().logger.severe("Event: "+ event.toString());
}
*/
/*
@Listener
public void onVehicleBreak(DamageEntityEvent e){
if (e.isCancelled()){
return;
}
if (!(e.getAttacker() instanceof Player)){
return;
}
Vehicle cart = e.getVehicle();
Player p = (Player) e.getAttacker();
Region r = RedProtect.get().rm.getTopRegion(cart.getLocation());
if (r == null){
return;
}
if (!r.canMinecart(p)){
RPLang.sendMessage(p, "blocklistener.region.cantbreak");
e.setCancelled(true);
return;
}
}
*/
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPistonEvent(ChangeBlockEvent.Pre e) {
Location<World> piston = null;
Location<World> block = null;
boolean antih = RedProtect.get().cfgs.getBool("region-settings.anti-hopper");
if (RedProtect.get().getPVHelper().checkCause(e.getCause(), "PISTON_EXTEND")) {
if (RedProtect.get().cfgs.getBool("performance.disable-PistonEvent-handler")) {
return;
}
List<Location<World>> locs = e.getLocations();
for (Location<World> loc : locs) {
if (piston == null) {
piston = loc;
continue;
}
block = loc;
}
}
if (RedProtect.get().getPVHelper().checkCause(e.getCause(), "PISTON_RETRACT")) {
if (RedProtect.get().cfgs.getBool("performance.disable-PistonEvent-handler")) {
return;
}
List<Location<World>> locs = e.getLocations();
for (Location<World> loc : locs) {
if (piston == null) {
piston = loc;
continue;
}
block = loc;
}
}
// process
if (piston != null && block != null) {
Region rPi = RedProtect.get().rm.getTopRegion(piston);
Region rB = RedProtect.get().rm.getTopRegion(block);
if (rPi == null && rB != null || (rPi != null && rB != null && rPi != rB && !rPi.sameLeaders(rB))) {
e.setCancelled(true);
return;
}
if (antih) {
BlockSnapshot ib = block.add(0, 1, 0).createSnapshot();
if (!cont.canWorldBreak(ib) || !cont.canWorldBreak(block.createSnapshot())) {
e.setCancelled(true);
}
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.
the class RPBlockListener method onFlow.
/*
@Listener
public void onBlockBurn(NotifyNeighborBlockEvent e, @First BlockSnapshot source){
RedProtect.get().logger.debug("Is ChangeBlockEvent.Modify event");
Map<Direction, BlockState> dirs = e.getNeighbors();
for (Direction dir:dirs.keySet()){
BlockSnapshot b = source.getLocation().get().getRelative(dir).createSnapshot();
BlockState bstate = source.getState();
Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get());
if ((bstate.getType().equals(BlockTypes.FIRE) || bstate.getType().getName().contains("LAVA")) && r != null && !r.canFire()){
e.setCancelled(true);
return;
}
if (!cont.canWorldBreak(b)){
e.setCancelled(true);
return;
}
}
return;
}
*/
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFlow(ChangeBlockEvent.Place e, @First BlockSnapshot source) {
BlockSnapshot bto = e.getTransactions().get(0).getOriginal();
RedProtect.get().logger.debug("blocks", "Is BlockFromToEvent.Place event is to " + source.getState().getType().getName() + " from " + bto.getState().getType().getName());
Region rto = RedProtect.get().rm.getTopRegion(bto.getLocation().get());
if (rto != null && (source.getState().getType().equals(BlockTypes.WATER) || source.getState().getType().equals(BlockTypes.LAVA) || source.getState().getType().equals(BlockTypes.FLOWING_LAVA) || source.getState().getType().equals(BlockTypes.FLOWING_WATER))) {
if (!rto.canFlow()) {
e.setCancelled(true);
return;
}
String bfType = bto.getState().getType().getName();
if (!rto.FlowDamage() && !bto.getState().getType().equals(BlockTypes.AIR) && !bfType.contains("water") && !bfType.contains("lava")) {
e.setCancelled(true);
return;
}
}
for (Direction dir : Arrays.asList(Direction.EAST, Direction.NORTH, Direction.SOUTH, Direction.WEST)) {
Location<World> locFrom = bto.getLocation().get().getBlockRelative(dir);
Region rfrom = RedProtect.get().rm.getTopRegion(locFrom);
if (rfrom != null && !rfrom.canFlow()) {
e.setCancelled(true);
return;
}
if (rfrom != null && rto != null && rfrom != rto && !rfrom.sameLeaders(rto)) {
e.setCancelled(true);
return;
}
if (rfrom == null && rto != null) {
e.setCancelled(true);
return;
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onBlockBreakGlobal.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBreakGlobal(ChangeBlockEvent.Break e, @Root Player p) {
RedProtect.get().logger.debug("default", "RPGlobalListener - Is BlockBreakEvent event! Cancelled? " + e.isCancelled());
BlockSnapshot bt = e.getTransactions().get(0).getOriginal();
BlockState b = bt.getState();
World w = bt.getLocation().get().getExtent();
Region r = RedProtect.get().rm.getTopRegion(bt.getLocation().get());
if (r != null) {
return;
}
if (!RPUtil.canBuildNear(p, bt.getLocation().get())) {
e.setCancelled(true);
return;
}
if (!bypassBuild(p, bt, 2)) {
e.setCancelled(true);
}
}
use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onDecay.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onDecay(ChangeBlockEvent.Decay e, @Root BlockSnapshot source) {
BlockSnapshot bfrom = e.getTransactions().get(0).getOriginal();
boolean allowDecay = RedProtect.get().cfgs.getGlobalFlag(bfrom.getLocation().get().getExtent().getName(), "allow-changes-of", "leaves-decay");
if (!allowDecay) {
e.setCancelled(true);
}
}
use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.
the class RPGlobalListener method onFlow.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFlow(ChangeBlockEvent.Place e, @Root BlockSnapshot source) {
BlockSnapshot bfrom = e.getTransactions().get(0).getOriginal();
boolean flow = RedProtect.get().cfgs.getGlobalFlag(bfrom.getLocation().get().getExtent().getName(), "liquid-flow");
boolean allowWater = RedProtect.get().cfgs.getGlobalFlag(bfrom.getLocation().get().getExtent().getName(), "allow-changes-of", "water-flow");
boolean allowLava = RedProtect.get().cfgs.getGlobalFlag(bfrom.getLocation().get().getExtent().getName(), "allow-changes-of", "lava-flow");
boolean allowdamage = RedProtect.get().cfgs.getGlobalFlag(bfrom.getLocation().get().getExtent().getName(), "allow-changes-of", "flow-damage");
Region r = RedProtect.get().rm.getTopRegion(bfrom.getLocation().get());
if (r != null) {
return;
}
RedProtect.get().logger.debug("blocks", "Is BlockFromToEvent.Place event is to " + source.getState().getType().getName() + " from " + bfrom.getState().getType().getName());
if (!flow && (source.getState().getType().equals(BlockTypes.WATER) || source.getState().getType().equals(BlockTypes.LAVA) || source.getState().getType().equals(BlockTypes.FLOWING_LAVA) || source.getState().getType().equals(BlockTypes.FLOWING_WATER))) {
e.setCancelled(true);
return;
}
if (!allowWater && (source.getState().getType().equals(BlockTypes.WATER) || source.getState().getType().equals(BlockTypes.FLOWING_WATER))) {
e.setCancelled(true);
return;
}
if (!allowLava && (source.getState().getType().equals(BlockTypes.LAVA) || source.getState().getType().equals(BlockTypes.FLOWING_LAVA))) {
e.setCancelled(true);
return;
}
if (!allowdamage && !source.getState().getType().equals(bfrom.getState().getType()) && !bfrom.getState().getType().equals(BlockTypes.AIR)) {
e.setCancelled(true);
}
}
Aggregations