use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class CursedMineListener method onBlockPlace.
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Named(NamedCause.SOURCE) Player player) {
Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
BlockType originalType = transaction.getFinal().getState().getType();
BlockType finalType = transaction.getFinal().getState().getType();
if (isRedstoneTransition(originalType, finalType)) {
continue;
}
event.setCancelled(true);
break;
}
}
use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class CursedMineListener method onItemDrop.
@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause, @Named(NamedCause.NOTIFIER) Player player) {
if (!Probability.getChance(4)) {
return;
}
BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();
Optional<Location<World>> optLocation = blockSnapshot.getLocation();
if (!optLocation.isPresent()) {
return;
}
Location<World> loc = optLocation.get();
Optional<CursedMineInstance> optInst = manager.getApplicableZone(loc);
if (!optInst.isPresent()) {
return;
}
CursedMineInstance inst = optInst.get();
if (!inst.hasrecordForPlayerAt(player, loc)) {
return;
}
List<ItemStackSnapshot> itemStacks = new ArrayList<>();
Iterator<Entity> entityIterator = event.getEntities().iterator();
while (entityIterator.hasNext()) {
Entity entity = entityIterator.next();
if (entity instanceof Item) {
ItemStackSnapshot snapshot = ((Item) entity).item().get();
itemStacks.add(snapshot);
entityIterator.remove();
}
}
int times = 1;
Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
if (optService.isPresent()) {
ModifierService service = optService.get();
if (service.isActive(Modifiers.DOUBLE_CURSED_ORES)) {
times *= 2;
}
}
for (ItemStackSnapshot stackSnapshot : itemStacks) {
int quantity = Math.min(stackSnapshot.getCount() * Probability.getRangedRandom(4, 8), stackSnapshot.getType().getMaxStackQuantity());
for (int i = 0; i < times; ++i) {
ItemStack stack = stackSnapshot.createStack();
stack.setQuantity(quantity);
player.getInventory().offer(stack);
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class WildernessWorldWrapper method onBlockPlace.
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Named(NamedCause.SOURCE) Player player) {
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
Optional<Location<World>> optLoc = block.getFinal().getLocation();
if (!optLoc.isPresent() || !isApplicable(optLoc.get())) {
continue;
}
Location<World> loc = optLoc.get();
BlockState finalState = block.getFinal().getState();
if (config.getDropAmplificationConfig().amplifies(finalState)) {
// Allow creative mode players to still place blocks
if (player.getGameModeData().type().get().equals(GameModes.CREATIVE)) {
continue;
}
BlockType originalType = block.getOriginal().getState().getType();
if (ore().contains(originalType)) {
continue;
}
try {
Vector3d origin = loc.getPosition();
World world = loc.getExtent();
for (int i = 0; i < 40; ++i) {
ParticleEffect effect = ParticleEffect.builder().type(ParticleTypes.MAGIC_CRITICAL_HIT).velocity(new Vector3d(Probability.getRangedRandom(-1, 1), Probability.getRangedRandom(-.7, .7), Probability.getRangedRandom(-1, 1))).quantity(1).build();
world.spawnParticles(effect, origin.add(.5, .5, .5));
}
} catch (Exception ex) {
player.sendMessage(/* ChatTypes.SYSTEM, */
Text.of(TextColors.RED, "You find yourself unable to place that block."));
}
block.setValid(false);
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project Skree by Skelril.
the class AntiJumpListener method onBlockPlace.
@Listener(order = Order.POST)
@IsCancelled(value = Tristate.TRUE)
public void onBlockPlace(ChangeBlockEvent.Place event, @Root Player player) {
final Location<World> playerLoc = player.getLocation();
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
Optional<Location<World>> optLoc = transaction.getOriginal().getLocation();
if (!optLoc.isPresent()) {
continue;
}
Location<World> blockLoc = optLoc.get();
final int blockY = blockLoc.getBlockY();
if (Math.abs(player.getVelocity().getY()) > UPWARDS_VELOCITY && playerLoc.getY() > blockY) {
Task.builder().execute(() -> {
Vector3d position = player.getLocation().getPosition();
if (position.getY() >= (blockY + LEAP_DISTANCE)) {
if (playerLoc.getPosition().distanceSquared(blockLoc.getPosition()) > Math.pow(RADIUS, 2)) {
return;
}
player.sendMessage(Text.of(TextColors.RED, "Hack jumping detected."));
player.setLocation(playerLoc.setPosition(new Vector3d(position.getX(), blockY, position.getZ())));
}
}).delayTicks(4).submit(SkreePlugin.inst());
}
}
}
use of org.spongepowered.api.block.BlockSnapshot in project SpongeCommon by SpongePowered.
the class MixinMinecraftServer method onServerTickEnd.
@Inject(method = "tick", at = @At(value = "RETURN"))
public void onServerTickEnd(CallbackInfo ci) {
int lastAnimTick = SpongeCommonEventFactory.lastAnimationPacketTick;
int lastPrimaryTick = SpongeCommonEventFactory.lastPrimaryPacketTick;
int lastSecondaryTick = SpongeCommonEventFactory.lastSecondaryPacketTick;
if (SpongeCommonEventFactory.lastAnimationPlayer != null) {
EntityPlayerMP player = SpongeCommonEventFactory.lastAnimationPlayer.get();
if (player != null && lastAnimTick != lastPrimaryTick && lastAnimTick != lastSecondaryTick && lastAnimTick != 0 && lastAnimTick - lastPrimaryTick > 3 && lastAnimTick - lastSecondaryTick > 3) {
BlockSnapshot blockSnapshot = BlockSnapshot.NONE;
EnumFacing side = null;
final RayTraceResult result = SpongeImplHooks.rayTraceEyes(player, SpongeImplHooks.getBlockReachDistance(player) + 1);
// Hit non-air block
if (result != null && result.getBlockPos() != null) {
blockSnapshot = new Location<>((World) player.world, VecHelper.toVector3d(result.getBlockPos())).createSnapshot();
side = result.sideHit;
}
Sponge.getCauseStackManager().pushCause(player);
if (!player.getHeldItemMainhand().isEmpty()) {
if (SpongeCommonEventFactory.callInteractItemEventPrimary(player, player.getHeldItemMainhand(), EnumHand.MAIN_HAND, result == null ? null : VecHelper.toVector3d(result.hitVec), blockSnapshot).isCancelled()) {
SpongeCommonEventFactory.lastAnimationPacketTick = 0;
Sponge.getCauseStackManager().popCause();
return;
}
}
if (side != null) {
SpongeCommonEventFactory.callInteractBlockEventPrimary(player, blockSnapshot, EnumHand.MAIN_HAND, side, VecHelper.toVector3d(result.hitVec));
} else {
SpongeCommonEventFactory.callInteractBlockEventPrimary(player, EnumHand.MAIN_HAND, result == null ? null : VecHelper.toVector3d(result.hitVec));
}
Sponge.getCauseStackManager().popCause();
}
}
SpongeCommonEventFactory.lastAnimationPacketTick = 0;
TimingsManager.FULL_SERVER_TICK.stopTiming();
}
Aggregations