use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class MarketQuickAddCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command!"));
return CommandResult.empty();
}
Optional<MarketService> optService = Sponge.getServiceManager().provide(MarketService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The market service is not currently running."));
return CommandResult.empty();
}
MarketService service = optService.get();
Optional<ItemStack> held = ((Player) src).getItemInHand(HandTypes.MAIN_HAND);
if (!held.isPresent()) {
src.sendMessage(Text.of(TextColors.RED, "You are not holding an item."));
return CommandResult.empty();
}
ItemStack item = held.get();
String alias = args.<String>getOne("alias").get();
BigDecimal price;
try {
price = new BigDecimal(args.<String>getOne("price").get());
} catch (NumberFormatException ex) {
src.sendMessage(Text.of(TextColors.RED, "Invalid price specified"));
return CommandResult.empty();
}
if (service.addItem(item)) {
if (service.addAlias(alias, item)) {
if (service.setBasePrice(alias, price)) {
if (service.setPrimaryAlias(alias)) {
src.sendMessage(Text.of(TextColors.YELLOW, alias + " added to the market with a price of " + format(price)));
return CommandResult.success();
}
// Same error, fall through
}
src.sendMessage(Text.of(TextColors.RED, alias + " is not a valid alias"));
return CommandResult.empty();
}
src.sendMessage(Text.of(TextColors.RED, "Your held item is not currently tracked, or the alias is already in use."));
return CommandResult.empty();
}
src.sendMessage(Text.of(TextColors.RED, "Your held item is already tracked."));
return CommandResult.empty();
}
use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class PlayerCombatParser method parse.
default default void parse(DamageEntityEvent event) {
Entity entity = event.getTargetEntity();
if (!(entity instanceof Living)) {
return;
}
Optional<DamageSource> optDamageSource = event.getCause().first(DamageSource.class);
if (optDamageSource.isPresent()) {
Entity srcEntity = null;
Entity indirectSrcEntity = null;
if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
srcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getIndirectSource();
indirectSrcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getSource();
} else if (optDamageSource.get() instanceof EntityDamageSource) {
srcEntity = ((EntityDamageSource) optDamageSource.get()).getSource();
}
if (!(srcEntity instanceof Living)) {
if (entity instanceof Player) {
processNonLivingAttack(optDamageSource.get(), (Player) entity);
}
return;
}
Living living = (Living) srcEntity;
if (verify(living)) {
if (entity instanceof Player && living instanceof Player) {
processPvP((Player) living, (Player) entity);
processPvP((Player) living, (Player) entity, indirectSrcEntity);
} else if (entity instanceof Player) {
processMonsterAttack(living, (Player) entity);
} else if (living instanceof Player) {
processPlayerAttack((Player) living, (Living) entity);
}
}
}
}
use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class PlayerCombatParser method parse.
default default void parse(CollideEntityEvent.Impact event) {
Optional<Projectile> optProjectile = event.getCause().first(Projectile.class);
if (!optProjectile.isPresent()) {
return;
}
Projectile projectile = optProjectile.get();
ProjectileSource source = optProjectile.get().getShooter();
if (!(source instanceof Player)) {
return;
}
Player attacker = (Player) source;
for (Entity anEntity : event.getEntities()) {
if (anEntity instanceof Player) {
Player defender = (Player) anEntity;
processPvP(attacker, defender);
processPvP(attacker, defender, projectile);
}
}
}
use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class FreakyFourInstance method runFrimus.
private void runFrimus() {
createWall(getRegion(FreakyFourBoss.FRIMUS), type -> type == BlockTypes.AIR, type -> type == BlockTypes.LAVA || type == BlockTypes.FLOWING_LAVA, BlockTypes.AIR, BlockTypes.LAVA, config.frimusWallDensity, -1);
for (Player player : getPlayers(PlayerClassifier.PARTICIPANT)) {
List<PotionEffect> oldPotions = player.get(Keys.POTION_EFFECTS).orElse(new ArrayList<>());
List<PotionEffect> newPotions = oldPotions.stream().filter(effect -> effect.getType() != PotionEffectTypes.FIRE_RESISTANCE).collect(Collectors.toList());
if (oldPotions.size() != newPotions.size()) {
player.offer(Keys.POTION_EFFECTS, newPotions);
}
}
}
use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class FrimusBossManager method handleDamaged.
private void handleDamaged() {
List<Instruction<DamagedCondition, Boss<Living, ZoneBossDetail<FreakyFourInstance>>>> damagedProcessor = getDamagedProcessor();
damagedProcessor.add((condition, boss) -> {
DamageEntityEvent event = condition.getEvent();
new PlayerCombatParser() {
@Override
public void processPlayerAttack(Player attacker, Living defender) {
if (condition.getDamageSource().get() instanceof IndirectEntityDamageSource) {
attacker.sendMessage(Text.of(TextColors.RED, "Projectiles can't harm me... Mwahahaha!"));
event.setCancelled(true);
}
}
}.parse(event);
return Optional.empty();
});
}
Aggregations