use of org.spongepowered.api.entity.Entity in project Skree by Skelril.
the class GraveStone method createGraveFromDeath.
public void createGraveFromDeath(DestructEntityEvent.Death event) {
Entity target = event.getTargetEntity();
if (target instanceof Player) {
Player player = (Player) target;
List<ItemStack> items = new ArrayList<>();
Optional<ItemStack> optStack;
do {
optStack = player.getInventory().poll();
} while (optStack.isPresent() && items.add(optStack.get()));
Iterator<ItemStack> it = items.iterator();
Optional<RespawnQueueService> optService = Sponge.getServiceManager().provide(RespawnQueueService.class);
if (optService.isPresent()) {
RespawnQueueService service = optService.get();
while (it.hasNext()) {
if (it.next().getItem() == CustomItemTypes.NETHER_BOWL) {
it.remove();
ItemStack stack = tf(new net.minecraft.item.ItemStack(CustomItemTypes.NETHER_BOWL));
CustomItemTypes.NETHER_BOWL.setDestination(stack, player.getLocation());
service.enque(player, stack);
break;
}
}
}
Task.builder().execute(() -> {
createGraveDropExcess(items, target.getLocation());
}).delayTicks(1).submit(SkreePlugin.inst());
}
}
use of org.spongepowered.api.entity.Entity in project Skree by Skelril.
the class PactScroll method onEntityInteract.
@Listener
public void onEntityInteract(InteractEntityEvent.Primary event, @Root Player player) {
Entity targetEntity = event.getTargetEntity();
if (!(targetEntity instanceof Player)) {
return;
}
Player targetPlayer = (Player) targetEntity;
Optional<ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optItemStack.isPresent()) {
return;
}
ItemStack itemStack = optItemStack.get();
if (itemStack.getItem() != this) {
return;
}
pactMap.putIfAbsent(player.getUniqueId(), new ArrayList<>());
List<UUID> pacts = pactMap.get(player.getUniqueId());
if (pacts.contains(targetPlayer.getUniqueId())) {
pacts.remove(targetPlayer.getUniqueId());
player.sendMessage(Text.of(TextColors.YELLOW, "Your pact with ", targetPlayer.getName(), " has been broken!"));
} else {
pacts.add(targetPlayer.getUniqueId());
player.sendMessage(Text.of(TextColors.YELLOW, "You've formed a pact with ", targetPlayer.getName(), "."));
player.sendMessage(Text.of(TextColors.YELLOW, "You will no longer be able to damage ", targetPlayer.getName(), ", unless attacked first."));
player.sendMessage(Text.of(TextColors.YELLOW, "You must carry a pact scroll for the pact to remain in effect."));
player.sendMessage(Text.of(TextColors.YELLOW, "All pacts will automatically be reset upon disconnect."));
}
event.setCancelled(true);
}
use of org.spongepowered.api.entity.Entity in project Skree by Skelril.
the class MainWorldWrapper method createFor.
private PlayerCombatParser createFor(Cancellable event) {
return new PlayerCombatParser() {
@Override
public void processPvP(Player attacker, Player defender, @Nullable Entity indirectSource) {
Optional<PvPService> optService = Sponge.getServiceManager().provide(PvPService.class);
if (optService.isPresent()) {
PvPService service = optService.get();
if (service.getPvPState(attacker).allowByDefault() && service.getPvPState(defender).allowByDefault()) {
return;
}
}
if (!(indirectSource instanceof Snowball) || !lobby.contains(attacker)) {
attacker.sendMessage(Text.of(TextColors.RED, "PvP is opt-in only in the main world!"));
event.setCancelled(true);
}
}
@Override
public void processNonLivingAttack(DamageSource attacker, Player defender) {
if (attacker.getType() == DamageTypes.VOID) {
defender.setLocation(defender.getWorld().getSpawnLocation());
defender.offer(Keys.FALL_DISTANCE, 0F);
event.setCancelled(true);
}
}
};
}
use of org.spongepowered.api.entity.Entity in project Skree by Skelril.
the class StormBringer method setupStormBringer.
private void setupStormBringer() {
Sponge.getEventManager().registerListeners(SkreePlugin.inst(), new BossListener<>(bossManager, Skeleton.class));
List<Instruction<BindCondition, Boss<Skeleton, WildernessBossDetail>>> bindProcessor = bossManager.getBindProcessor();
bindProcessor.add((condition, boss) -> {
Optional<Skeleton> optBossEnt = boss.getTargetEntity();
if (optBossEnt.isPresent()) {
Skeleton bossEnt = optBossEnt.get();
bossEnt.offer(Keys.DISPLAY_NAME, Text.of("Storm Bringer"));
double bossHealth = 20 * 30 * boss.getDetail().getLevel();
setMaxHealth(bossEnt, bossHealth, true);
}
return Optional.empty();
});
List<Instruction<DamageCondition, Boss<Skeleton, WildernessBossDetail>>> damageProcessor = bossManager.getDamageProcessor();
damageProcessor.add((condition, boss) -> {
Entity eToHit = condition.getAttacked();
if (!(eToHit instanceof Living)) {
return Optional.empty();
}
Living toHit = (Living) eToHit;
Location<World> targetLocation = toHit.getLocation();
for (int i = boss.getDetail().getLevel() * Probability.getRangedRandom(1, 10); i >= 0; --i) {
Task.builder().execute(() -> {
Entity lightning = targetLocation.getExtent().createEntity(EntityTypes.LIGHTNING, targetLocation.getPosition());
targetLocation.getExtent().spawnEntity(lightning, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
}).delayTicks(5 * (6 + i)).submit(SkreePlugin.inst());
}
return Optional.empty();
});
}
use of org.spongepowered.api.entity.Entity in project Skree by Skelril.
the class BuildWorldWrapper method onEntitySpawn.
@Listener
public void onEntitySpawn(SpawnEntityEvent event) {
List<Entity> entities = event.getEntities();
Optional<BlockSpawnCause> optBlockCause = event.getCause().first(BlockSpawnCause.class);
for (Entity entity : entities) {
if (!isApplicable(entity))
continue;
if (entity instanceof Lightning) {
((Lightning) entity).setEffect(true);
continue;
}
if (entity instanceof Egg && optBlockCause.isPresent()) {
new ItemDropper(entity.getLocation()).dropStacks(Lists.newArrayList(newItemStack(ItemTypes.EGG)), SpawnTypes.DISPENSE);
event.setCancelled(true);
return;
}
if (entity instanceof Monster || (entity instanceof Horse && entity.get(Keys.HORSE_VARIANT).get().equals(HorseVariants.SKELETON_HORSE))) {
event.setCancelled(true);
return;
}
}
}
Aggregations