use of org.spongepowered.api.world.Location in project Skree by Skelril.
the class JungleRaidEffectListener method onPlayerInteract.
@Listener(order = Order.LATE)
public void onPlayerInteract(InteractBlockEvent.Primary.MainHand event, @First Player player) {
Optional<Location<World>> optBlockLoc = event.getTargetBlock().getLocation();
if (!optBlockLoc.isPresent()) {
return;
}
Location<World> blockLoc = optBlockLoc.get();
Optional<JungleRaidInstance> optInst = manager.getApplicableZone(blockLoc);
if (!optInst.isPresent()) {
return;
}
JungleRaidInstance inst = optInst.get();
if (inst.isFlagEnabled(JungleRaidFlag.TITAN_MODE) && player.getUniqueId().equals(inst.getFlagData().titan)) {
if (blockLoc.getBlockType() == BlockTypes.BEDROCK) {
return;
}
// TODO Convert to the Sponge API
((net.minecraft.world.World) blockLoc.getExtent()).destroyBlock(new BlockPos(blockLoc.getX(), blockLoc.getY(), blockLoc.getZ()), true);
}
}
use of org.spongepowered.api.world.Location 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.world.Location 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.world.Location in project Skree by Skelril.
the class ZoneRelativePositionListener method onBlockInteract.
@Listener
public void onBlockInteract(InteractBlockEvent.Secondary event, @First Player player) {
Optional<Location<World>> optLocation = event.getTargetBlock().getLocation();
if (!optLocation.isPresent()) {
return;
}
Location<World> location = optLocation.get();
Optional<T> optInst = getApplicable(location);
if (!optInst.isPresent()) {
return;
}
T inst = optInst.get();
Vector3i minPoint = inst.getRegion().getMinimumPoint();
Vector3i clickedPoint = location.getBlockPosition();
Vector3i offset = clickedPoint.sub(minPoint);
player.sendMessage(Text.of("Offset: ", offset));
}
use of org.spongepowered.api.world.Location 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());
}
}
}
Aggregations