use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class RegionMarker method onBlockBreak.
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
return;
}
RegionService service = optService.get();
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
if (!block.isValid()) {
continue;
}
if (block.getOriginal().getState().getType() != this) {
continue;
}
Optional<Location<World>> optLoc = block.getOriginal().getLocation();
if (optLoc.isPresent()) {
Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
if (optRef.isPresent()) {
Region ref = optRef.get();
if (ref.isMember(player)) {
ref.remPoint(new RegionPoint(optLoc.get().getPosition()));
player.sendMessage(Text.of(TextColors.YELLOW, "Region marker deleted!"));
}
}
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class RegionMaster method onBlockBreak.
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
return;
}
RegionService service = optService.get();
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
if (!block.isValid()) {
continue;
}
if (block.getOriginal().getState().getType() != this) {
continue;
}
Optional<Location<World>> optLoc = block.getOriginal().getLocation();
if (!optLoc.isPresent()) {
continue;
}
Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
if (!optRef.isPresent()) {
continue;
}
Region ref = optRef.get();
if (!ref.getFullPoints().isEmpty()) {
block.setValid(false);
player.sendMessage(Text.of(TextColors.RED, "You must first delete all markers!"));
} else {
service.rem(optLoc.get());
player.sendMessage(Text.of(TextColors.YELLOW, "Region deleted!"));
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class JungleRaidEffectListener method onBlockBurn.
@Listener
public void onBlockBurn(ChangeBlockEvent event) {
if (event.getCause().root() instanceof Player) {
return;
}
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
BlockType finalType = transaction.getFinal().getState().getType();
if (finalType != BlockTypes.FIRE) {
continue;
}
Optional<JungleRaidInstance> optInst = manager.getApplicableZone(transaction.getOriginal().getLocation().get());
if (optInst.isPresent()) {
JungleRaidInstance inst = optInst.get();
if (inst.isFlagEnabled(JungleRaidFlag.NO_FIRE_SPREAD)) {
event.setCancelled(true);
}
break;
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class CustomTerragu method process.
public void process(ChangeBlockEvent.Break event) {
if (event.getTransactions().size() > 1) {
return;
}
Optional<Player> optPlayer = event.getCause().first(Player.class);
if (optPlayer.isPresent()) {
Player player = optPlayer.get();
Optional<Direction> optClickedDir = Optional.ofNullable(clickMap.get(player));
Optional<org.spongepowered.api.item.inventory.ItemStack> optStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (optStack.isPresent() && optClickedDir.isPresent()) {
if (optStack.get().getItem() == this) {
ItemStack stack = tf(optStack.get());
for (Transaction<BlockSnapshot> snapshot : event.getTransactions()) {
if (!snapshot.getOriginal().getLocation().isPresent()) {
return;
}
int maxDist = getMaxEditDist(stack);
int dmg = destroyLine(player, optClickedDir.get(), maxDist - 1, snapshot.getOriginal());
stack.damageItem(dmg, tf(player));
player.setItemInHand(HandTypes.MAIN_HAND, tf(stack));
}
}
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class CursedMineListener method onPlayerInteract.
@Listener
public void onPlayerInteract(ChangeBlockEvent event) {
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
BlockSnapshot snapshot = block.getOriginal();
Optional<CursedMineInstance> optInst = manager.getApplicableZone(snapshot);
if (optInst.isPresent() && triggerBlocks.contains(snapshot.getState().getType())) {
optInst.get().activatePumps();
break;
}
}
}
Aggregations