use of org.spongepowered.api.entity.EntitySnapshot in project SpongeCommon by SpongePowered.
the class DamageableDataTest method onGamePreInitialization.
@Listener
public void onGamePreInitialization(GamePreInitializationEvent event) {
Sponge.getCommandManager().register(this, CommandSpec.builder().arguments(GenericArguments.onlyOne(GenericArguments.entityOrSource(Text.of("target")))).executor((src, args) -> {
final Entity entity = args.<Entity>getOne("target").get();
final Optional<EntitySnapshot> optionalAttacker = entity.get(Keys.LAST_ATTACKER).get();
final Optional<Double> lastDamage = entity.get(Keys.LAST_DAMAGE).get();
if (optionalAttacker.isPresent() && lastDamage.isPresent()) {
final EntitySnapshot attacker = optionalAttacker.get();
src.sendMessage(Text.of(attacker.get(Keys.DISPLAY_NAME).orElse(Text.of(attacker.getUniqueId())) + " dealt " + lastDamage.get() + " damage to " + entity.get(Keys.DISPLAY_NAME).orElse(Text.of(entity.getUniqueId()))));
} else {
src.sendMessage(Text.of(TextColors.RED, "This target does not have a last attacker."));
}
return CommandResult.success();
}).build(), "lastattackertest");
}
use of org.spongepowered.api.entity.EntitySnapshot in project modules-extra by CubeEngine.
the class DestructReport method group.
@Override
public boolean group(Object lookup, Action action, Action otherAction, Report otherReport) {
if (!this.equals(otherReport)) {
return false;
}
if (!action.getData(CAUSE).equals(otherAction.getData(CAUSE))) {
// TODO check same cause better
return false;
}
EntitySnapshot e1 = Recall.entity(action);
EntitySnapshot e2 = Recall.entity(otherAction);
if (e1.getType() != e2.getType()) {
return false;
}
if (e1.getType() == EntityTypes.ITEM) {
Optional<ItemStackSnapshot> i1 = Recall.entity(otherAction).get(Keys.REPRESENTED_ITEM);
Optional<ItemStackSnapshot> i2 = Recall.entity(action).get(Keys.REPRESENTED_ITEM);
if (!i1.isPresent() && i2.isPresent()) {
return false;
}
if (ItemStackComparators.DEFAULT.compare(i1.map(ItemStackSnapshot::createStack).orElse(null), i2.map(ItemStackSnapshot::createStack).orElse(null)) != 0) {
return false;
}
}
return true;
}
use of org.spongepowered.api.entity.EntitySnapshot in project modules-extra by CubeEngine.
the class DestructReport method showReport.
@Override
public void showReport(List<Action> actions, Receiver receiver) {
Action action = actions.get(0);
// Optional<BlockSnapshot> orig = action.getCached(BLOCKS_ORIG, Recall::origSnapshot).get(0);
Text cause = Recall.cause(action);
EntitySnapshot entity = Recall.entity(action);
if (entity.getType() == EntityTypes.ITEM) {
Text name = ReportUtil.name(entity);
ItemStack i = entity.get(Keys.REPRESENTED_ITEM).map(ItemStackSnapshot::createStack).orElse(null);
Text item = Text.of("?");
if (i != null) {
item = Text.of(i.getTranslation().get(receiver.getLocale())).toBuilder().onHover(showText(Text.of(i.getType().getId()))).build();
}
int count = 0;
for (Action a : actions) {
count += Recall.entity(a).get(Keys.REPRESENTED_ITEM).map(ItemStackSnapshot::getQuantity).orElse(0);
}
if (count == 0) {
count = actions.size();
}
receiver.sendReport(this, actions, count, "{txt} destroyed {txt}", "{txt} destroyed {txt} x{}", cause, Text.of(name, ": ", item), count);
} else if (Living.class.isAssignableFrom(entity.getType().getEntityClass())) {
receiver.sendReport(this, actions, actions.size(), "{txt} killed {txt}", "{txt} killed {txt} x{}", cause, ReportUtil.name(entity), actions.size());
} else if (ExperienceOrb.class.isAssignableFrom(entity.getType().getEntityClass())) {
Integer exp = 0;
for (Action a : actions) {
EntitySnapshot orb = Recall.entity(a);
exp += orb.get(Keys.CONTAINED_EXPERIENCE).orElse(0);
}
receiver.sendReport(this, actions, actions.size(), "{txt} picked up an ExpOrb worth {2:amount} points", "{txt} picked up {amount} ExpOrbs worth {amount} points", cause, actions.size(), exp);
} else {
receiver.sendReport(this, actions, actions.size(), "{txt} destroyed {txt}", "{txt} destroyed {txt} x{}", cause, ReportUtil.name(entity), actions.size());
}
}
Aggregations