use of org.spongepowered.api.entity.Entity in project TotalEconomy by Erigitic.
the class TEJobManager method onPlayerKillEntity.
/**
* Used for the break option in jobs. Will check if the job has the break node and if it does it will check if the
* block that was broken is present in the config of the player's job. If it is, it will grab the job exp reward as
* well as the pay.
*
* @param event DestructEntityEvent.Death
*/
@Listener
public void onPlayerKillEntity(DestructEntityEvent.Death event) {
Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
if (optDamageSource.isPresent()) {
EntityDamageSource damageSource = optDamageSource.get();
Entity killer = damageSource.getSource();
Entity victim = event.getTargetEntity();
if (!(killer instanceof Player)) {
// If a projectile was shot to kill an entity, this will grab the player who shot it
Optional<UUID> damageCreator = damageSource.getSource().getCreator();
if (damageCreator.isPresent())
killer = Sponge.getServer().getPlayer(damageCreator.get()).get();
}
if (killer instanceof Player) {
Player player = (Player) killer;
UUID playerUUID = player.getUniqueId();
String victimName = victim.getType().getName();
String playerJob = getPlayerJob(player);
Optional<TEJob> optPlayerJob = getJob(playerJob, true);
if (optPlayerJob.isPresent()) {
Optional<TEActionReward> reward = Optional.empty();
List<String> sets = optPlayerJob.get().getSets();
for (String s : sets) {
Optional<TEJobSet> optSet = getJobSet(s);
if (!optSet.isPresent()) {
logger.warn("[TE] Job " + getPlayerJob(player) + " has nonexistent set \"" + s + "\"");
continue;
}
reward = optSet.get().getRewardFor("kill", victimName);
}
if (reward.isPresent()) {
int expAmount = reward.get().getExpReward();
BigDecimal payAmount = reward.get().getMoneyReward();
boolean notify = accountConfig.getNode(playerUUID.toString(), "jobnotifications").getBoolean();
TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(player.getUniqueId()).get();
if (notify) {
notifyPlayer(player, payAmount);
}
addExp(player, expAmount);
playerAccount.deposit(totalEconomy.getDefaultCurrency(), payAmount, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer())));
checkForLevel(player);
}
}
}
}
}
use of org.spongepowered.api.entity.Entity in project Skree by Skelril.
the class CursedMineInstance method drain.
public void drain() {
for (Entity e : getContained(Carrier.class)) {
// TODO Inventory API not fully implemented
if (!(e instanceof Player)) {
continue;
}
Inventory eInventory = ((Carrier) e).getInventory();
if (e instanceof Player) {
Location<World> playerLoc = e.getLocation();
// Emerald
long diff = System.currentTimeMillis() - lastActivation;
if (playerLoc.getY() < 30 && (lastActivation == 0 || diff <= timeTilPumpShutoff * .35 || diff >= timeTilPumpShutoff * 5)) {
PositionRandomizer randomizer = new PositionRandomizer(5);
for (int i = 0; i < Probability.getRangedRandom(2, 5); i++) {
Vector3i targetPos;
do {
targetPos = randomizer.createPosition3i(playerLoc.getPosition());
} while (getRegion().getExtent().getBlockType(targetPos) != BlockTypes.AIR);
Entity entity = getRegion().getExtent().createEntity(EntityTypes.BLAZE, targetPos);
getRegion().getExtent().spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.MOB_SPAWNER).build()).build());
}
}
}
for (int i = 0; i < (eInventory.size() / 2) - 2 || i < 1; i++) {
if (e instanceof Player) {
if (Probability.getChance(15) && checkInventory((Player) e)) {
((Player) e).sendMessage(Text.of(TextColors.YELLOW, "Divine intervention protects some of your items."));
continue;
}
}
// Iron
eInventory.query(ItemTypes.IRON_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.IRON_ORE).poll(Probability.getRandom(4));
eInventory.query(ItemTypes.IRON_INGOT).poll(Probability.getRandom(8));
// Gold
eInventory.query(ItemTypes.GOLD_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.GOLD_ORE).poll(Probability.getRandom(4));
eInventory.query(ItemTypes.GOLD_INGOT).poll(Probability.getRandom(10));
eInventory.query(ItemTypes.GOLD_NUGGET).poll(Probability.getRandom(80));
// Redstone
eInventory.query(ItemTypes.REDSTONE_ORE).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.REDSTONE).poll(Probability.getRandom(34));
// Lap
eInventory.query(ItemTypes.LAPIS_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.LAPIS_ORE).poll(Probability.getRandom(4));
eInventory.query(LAPIS_DYE).poll(Probability.getRandom(34));
// Diamond
eInventory.query(ItemTypes.DIAMOND_BLOCK).poll(Probability.getRandom(2));
eInventory.query(ItemTypes.DIAMOND_ORE).poll(Probability.getRandom(4));
eInventory.query(ItemTypes.DIAMOND).poll(Probability.getRandom(16));
}
}
}
use of org.spongepowered.api.entity.Entity in project Skree by Skelril.
the class Fangz method setupFangz.
private void setupFangz() {
Sponge.getEventManager().registerListeners(SkreePlugin.inst(), new BossListener<>(bossManager, Spider.class));
List<Instruction<BindCondition, Boss<Spider, WildernessBossDetail>>> bindProcessor = bossManager.getBindProcessor();
bindProcessor.add((condition, boss) -> {
Optional<Spider> optBossEnt = boss.getTargetEntity();
if (optBossEnt.isPresent()) {
Spider bossEnt = optBossEnt.get();
bossEnt.offer(Keys.DISPLAY_NAME, Text.of("Fangz"));
double bossHealth = 20 * 50 * boss.getDetail().getLevel();
setMaxHealth(bossEnt, bossHealth, true);
}
return Optional.empty();
});
List<Instruction<UnbindCondition, Boss<Spider, WildernessBossDetail>>> unbindProcessor = bossManager.getUnbindProcessor();
unbindProcessor.add((condition, boss) -> {
Optional<Spider> optBossEnt = boss.getTargetEntity();
if (optBossEnt.isPresent()) {
Spider bossEnt = optBossEnt.get();
CuboidContainmentPredicate predicate = new CuboidContainmentPredicate(bossEnt.getLocation().getPosition(), 3, 2, 3);
for (Entity aEntity : bossEnt.getNearbyEntities((entity) -> predicate.test(entity.getLocation().getPosition()))) {
Optional<PotionEffectData> optPotionEffects = aEntity.getOrCreate(PotionEffectData.class);
if (!optPotionEffects.isPresent()) {
continue;
}
PotionEffectData potionEffects = optPotionEffects.get();
potionEffects.addElement(PotionEffect.of(PotionEffectTypes.SLOWNESS, 2, 20 * 30));
potionEffects.addElement(PotionEffect.of(PotionEffectTypes.POISON, 2, 20 * 30));
aEntity.offer(potionEffects);
}
}
return Optional.empty();
});
List<Instruction<DamageCondition, Boss<Spider, WildernessBossDetail>>> damageProcessor = bossManager.getDamageProcessor();
damageProcessor.add((condition, boss) -> {
Optional<Spider> optBossEnt = boss.getTargetEntity();
if (optBossEnt.isPresent()) {
Spider bossEnt = optBossEnt.get();
Entity eToHit = condition.getAttacked();
if (!(eToHit instanceof Living))
return Optional.empty();
Living toHit = (Living) eToHit;
DamageEntityEvent event = condition.getEvent();
event.setBaseDamage(event.getBaseDamage() * 2);
EntityHealthUtil.heal(bossEnt, event.getBaseDamage());
Optional<PotionEffectData> optPotionEffects = toHit.getOrCreate(PotionEffectData.class);
if (!optPotionEffects.isPresent()) {
return Optional.empty();
}
PotionEffectData potionEffects = optPotionEffects.get();
potionEffects.addElement(PotionEffect.of(PotionEffectTypes.SLOWNESS, 1, 20 * 15));
potionEffects.addElement(PotionEffect.of(PotionEffectTypes.POISON, 1, 20 * 15));
toHit.offer(potionEffects);
}
return Optional.empty();
});
}
use of org.spongepowered.api.entity.Entity in project Skree by Skelril.
the class GraveDigger method setupGraveDigger.
private void setupGraveDigger() {
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("Grave Digger"));
double bossHealth = 20 * 43 * 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();
makeExplosiveTomb(targetLocation, boss);
return Optional.empty();
});
List<Instruction<DamagedCondition, Boss<Skeleton, WildernessBossDetail>>> damagedProcessor = bossManager.getDamagedProcessor();
damagedProcessor.add((condition, boss) -> {
Optional<DamageSource> optDamageSource = condition.getDamageSource();
if (optDamageSource.isPresent()) {
DamageSource damageSource = optDamageSource.get();
if (damageSource.getType() == DamageTypes.EXPLOSIVE) {
condition.getEvent().setCancelled(true);
}
if (!(damageSource instanceof IndirectEntityDamageSource)) {
return Optional.empty();
}
Entity source = ((IndirectEntityDamageSource) damageSource).getIndirectSource();
Location<World> targetLocation = source.getLocation();
makeExplosiveTomb(targetLocation, boss);
}
return Optional.empty();
});
}
use of org.spongepowered.api.entity.Entity in project Skree by Skelril.
the class GraveDigger method makeExplosiveTomb.
private void makeExplosiveTomb(Location<World> targetLocation, Boss<Skeleton, WildernessBossDetail> boss) {
makeSphere(targetLocation, 3, 3, 3);
for (int i = 0; i < boss.getDetail().getLevel(); ++i) {
Entity explosive = targetLocation.getExtent().createEntity(EntityTypes.PRIMED_TNT, targetLocation.getPosition());
explosive.offer(Keys.FUSE_DURATION, 20 * 4);
targetLocation.getExtent().spawnEntity(explosive, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
}
}
Aggregations