use of org.spongepowered.api.event.Listener in project Skree by Skelril.
the class CursedMineListener method onPlayerQuit.
@Listener
public void onPlayerQuit(ClientConnectionEvent.Disconnect event) {
Player player = event.getTargetEntity();
Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
if (optInst.isPresent() && optInst.get().hasRecordForPlayer(player)) {
manager.getHitList().addPlayer(player);
}
}
use of org.spongepowered.api.event.Listener 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.event.Listener in project Skree by Skelril.
the class WildernessWorldWrapper method onEntityDeath.
@Listener
public void onEntityDeath(DestructEntityEvent.Death event) {
Entity entity = event.getTargetEntity();
Location<World> loc = entity.getLocation();
Optional<Integer> optLevel = getLevel(loc);
if (!optLevel.isPresent()) {
return;
}
int level = optLevel.get();
if (entity instanceof Monster) {
DropTable dropTable;
if (entity.getLocation().getExtent().getDimension() == DimensionTypes.NETHER || entity instanceof Wither) {
dropTable = netherMobDropTable;
} else {
dropTable = commonDropTable;
}
Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
if (optDamageSource.isPresent()) {
Entity srcEntity;
if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
srcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getIndirectSource();
} else {
srcEntity = optDamageSource.get().getSource();
}
int dropTier = level;
if (srcEntity instanceof Player) {
Optional<ItemStack> optHeldItem = ((Player) srcEntity).getItemInHand(HandTypes.MAIN_HAND);
if (optHeldItem.isPresent()) {
Optional<ItemEnchantment> optLooting = EnchantmentUtil.getHighestEnchantment(optHeldItem.get(), Enchantments.LOOTING);
if (optLooting.isPresent()) {
dropTier += optLooting.get().getLevel();
}
}
dropTier = getDropTier(dropTier);
Collection<ItemStack> drops = dropTable.getDrops((entity instanceof Boss ? 5 : 1) * dropTier, getDropMod(dropTier, ((Monster) entity).getHealthData().maxHealth().get(), entity.getType()));
int times = 1;
Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
if (optService.isPresent()) {
ModifierService service = optService.get();
if (service.isActive(Modifiers.DOUBLE_WILD_DROPS)) {
times *= 2;
}
}
ItemDropper dropper = new ItemDropper(loc);
for (int i = 0; i < times; ++i) {
dropper.dropStacks(drops, SpawnTypes.DROPPED_ITEM);
}
}
}
if (entity.getType() == EntityTypes.ENDERMITE && Probability.getChance(20)) {
entity.getWorld().triggerExplosion(Explosion.builder().location(entity.getLocation()).shouldBreakBlocks(true).radius(4F).build(), Cause.source(SkreePlugin.container()).build());
}
}
GRAVE_STONE.createGraveFromDeath(event);
}
use of org.spongepowered.api.event.Listener 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.event.Listener in project Skree by Skelril.
the class InstanceWorldWrapper method onLogin.
@Listener
public void onLogin(ClientConnectionEvent.Join event, @Getter("getTargetEntity") Player player) {
if (!isApplicable(player)) {
return;
}
Optional<WorldService> optWorldService = Sponge.getServiceManager().provide(WorldService.class);
if (!optWorldService.isPresent()) {
return;
}
WorldService worldService = optWorldService.get();
Collection<World> worlds = worldService.getEffectWrapper(MainWorldWrapper.class).get().getWorlds();
player.setLocation(worlds.iterator().next().getSpawnLocation());
}
Aggregations