use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.
the class DeathMark method apply.
@Override
public Optional<Instruction<DamagedCondition, Boss<Zombie, CatacombsBossDetail>>> apply(DamagedCondition damagedCondition, Boss<Zombie, CatacombsBossDetail> zombieCatacombsBossDetailBoss) {
new PlayerCombatParser() {
@Override
public void processPlayerAttack(Player attacker, Living defender) {
CatacombsBossDetail detail = zombieCatacombsBossDetailBoss.getDetail();
CatacombsInstance inst = detail.getZone();
if (detail.getMarked().isPresent()) {
if (attacker.equals(detail.getMarked().get())) {
inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.YELLOW, attacker.getName() + " has been freed!"));
} else {
detail.getMarked().get().offer(Keys.HEALTH, 0D);
}
detail.setMarked(null);
} else if (activate(detail)) {
detail.setMarked(attacker);
inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.DARK_RED, attacker.getName() + " has been marked!"));
}
}
}.parse(damagedCondition.getEvent());
return Optional.empty();
}
use of org.spongepowered.api.entity.living.player.Player in project TotalEconomy by Erigitic.
the class TEJobManager method onSignInteract.
/**
* Called when a player clicks a sign. If the clicked sign is a "Job Changing" sign then the player's job will
* be changed on click.
*
* @param event InteractBlockEvent
*/
@Listener
public void onSignInteract(InteractBlockEvent event) {
if (event.getCause().first(Player.class).isPresent()) {
Player player = event.getCause().first(Player.class).get();
if (event.getTargetBlock().getLocation().isPresent()) {
Optional<TileEntity> tileEntityOpt = event.getTargetBlock().getLocation().get().getTileEntity();
if (tileEntityOpt.isPresent()) {
TileEntity tileEntity = tileEntityOpt.get();
if (tileEntity instanceof Sign) {
Sign sign = (Sign) tileEntity;
Optional<SignData> data = sign.getOrCreate(SignData.class);
if (data.isPresent()) {
SignData signData = data.get();
Text lineOneText = signData.lines().get(0);
Text lineTwoText = signData.lines().get(1);
String lineOne = lineOneText.toPlain();
String lineTwo = lineTwoText.toPlain().toLowerCase();
if (lineOne.equals("[TEJobs]")) {
if (jobExists(lineTwo)) {
if (setJob(player, lineTwo)) {
player.sendMessage(Text.of(TextColors.GRAY, "Job changed to: ", TextColors.GOLD, lineTwo));
} else {
player.sendMessage(Text.of(TextColors.RED, "[TE] Failed to set job. Contact your administrator."));
}
} else {
player.sendMessage(Text.of(TextColors.RED, "[TE] Sorry, this job does not exist"));
}
}
}
}
}
}
}
}
use of org.spongepowered.api.entity.living.player.Player in project TotalEconomy by Erigitic.
the class TEJobManager method onPlayerPlaceBlock.
/**
* Used for the place option in jobs. Will check if the job has the place node and if it does it will check if the
* block that was placed 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 ChangeBlockEvent.Place
*/
@Listener
public void onPlayerPlaceBlock(ChangeBlockEvent.Place event) {
if (event.getCause().first(Player.class).isPresent()) {
Player player = event.getCause().first(Player.class).get();
UUID playerUUID = player.getUniqueId();
String playerJob = getPlayerJob(player);
Optional<TEJob> optPlayerJob = getJob(playerJob, true);
String blockName = event.getTransactions().get(0).getFinal().getState().getType().getName();
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("place", blockName);
}
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.living.player.Player 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.living.player.Player in project TotalEconomy by Erigitic.
the class TotalEconomy method onPlayerJoin.
@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event) {
Player player = event.getTargetEntity();
accountManager.getOrCreateAccount(player.getUniqueId());
}
Aggregations