use of org.spongepowered.api.entity.living.Living in project Nucleus by NucleusPowered.
the class KillCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Collection<Entity> entities = args.getAll(key);
int entityKillCount = 0;
int playerKillCount = 0;
for (Entity x : entities) {
if (x instanceof Player) {
Player pl = (Player) x;
GameMode gm = pl.gameMode().getDirect().orElseGet(() -> pl.gameMode().getDefault());
if (gm != GameModes.SURVIVAL && gm != GameModes.NOT_SET) {
if (entities.size() == 1) {
throw ReturnMessageException.fromKey("command.kill.wronggm", pl.getName());
} else {
continue;
}
}
}
DataTransactionResult dtr = x.offer(Keys.HEALTH, 0d);
if (!dtr.isSuccessful() && !(x instanceof Living)) {
x.remove();
}
entityKillCount++;
if (x instanceof Player) {
playerKillCount++;
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kill.killed", Nucleus.getNucleus().getNameUtil().getSerialisedName((Player) x)));
((Player) x).sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kill.killedby", src.getName()));
}
}
if (entityKillCount > playerKillCount) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kill.overall", String.valueOf(entityKillCount), String.valueOf(playerKillCount)));
}
return CommandResult.success();
}
use of org.spongepowered.api.entity.living.Living in project Nucleus by NucleusPowered.
the class BackListeners method onDeathEvent.
@Listener
public void onDeathEvent(DestructEntityEvent.Death event) {
Living e = event.getTargetEntity();
if (!(e instanceof Player)) {
return;
}
Player pl = (Player) e;
if (backConfig.isOnDeath() && getLogBack(pl) && s.testSuffix(pl, ON_DEATH)) {
handler.setLastLocation(pl, event.getTargetEntity().getTransform());
}
}
Aggregations