use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.
the class RPEconomy method getRegionValue.
public static long getRegionValue(Region r) {
long regionCost = 0;
World w = RedProtect.get().serv.getWorld(r.getWorld()).get();
int maxX = r.getMaxMbrX();
int minX = r.getMinMbrX();
int maxZ = r.getMaxMbrZ();
int minZ = r.getMinMbrZ();
for (int x = minX; x < maxX; x++) {
for (int y = 0; y < 256; y++) {
for (int z = minZ; z < maxZ; z++) {
BlockSnapshot b = w.createSnapshot(x, y, z);
/*
Location<World> loc = new Location<World>(w, x, y, z);
Collection<Entity> ents = w.getEntities(ent-> ent.getLocation().getBlockPosition().equals(loc.getBlockPosition()));
for (Entity ent:ents){
if (ent instanceof Equipable){
Equipable equip = (Equipable) ent;
regionCost += getInvValue(equip.getInventory().slots());
}
}
*/
if (b.getState().getType().equals(BlockTypes.AIR)) {
continue;
}
if (b.getLocation().get().getTileEntity().isPresent()) {
TileEntity invTile = b.getLocation().get().getTileEntity().get();
if (invTile instanceof TileEntityInventory) {
TileEntityInventory<?> inv = (TileEntityInventory<?>) invTile;
regionCost += getInvValue(inv.slots());
}
} else {
regionCost += RedProtect.get().cfgs.getBlockCost(b.getState().getType().getName());
}
}
}
}
r.setValue(regionCost);
return regionCost;
}
use of org.spongepowered.api.block.BlockSnapshot 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.block.BlockSnapshot 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.block.BlockSnapshot 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);
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project RedProtect by FabioZumbi12.
the class RPBlockListener method onInteractPrimBlock.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractPrimBlock(InteractBlockEvent.Primary event, @First Player p) {
BlockSnapshot b = event.getTargetBlock();
RedProtect.get().logger.debug("player", "RPBlockListener - Is InteractBlockEvent.Primary event");
if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) {
if (b.getState().getType().getName().contains("sign") && !cont.canBreak(p, b)) {
RPLang.sendMessage(p, "blocklistener.container.breakinside");
event.setCancelled(true);
}
}
}
Aggregations