Search in sources :

Example 6 with EntitySnapshot

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");
}
Also used : Entity(org.spongepowered.api.entity.Entity) EntitySnapshot(org.spongepowered.api.entity.EntitySnapshot) Listener(org.spongepowered.api.event.Listener)

Example 7 with EntitySnapshot

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;
}
Also used : EntitySnapshot(org.spongepowered.api.entity.EntitySnapshot) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot)

Example 8 with EntitySnapshot

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());
    }
}
Also used : Action(org.cubeengine.module.vigil.report.Action) EntitySnapshot(org.spongepowered.api.entity.EntitySnapshot) Living(org.spongepowered.api.entity.living.Living) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) TextActions.showText(org.spongepowered.api.text.action.TextActions.showText) Text(org.spongepowered.api.text.Text) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Aggregations

EntitySnapshot (org.spongepowered.api.entity.EntitySnapshot)8 Entity (org.spongepowered.api.entity.Entity)5 Listener (org.spongepowered.api.event.Listener)2 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)2 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)1 EnterExitRegionEvent (br.net.fabiozumbi12.RedProtect.Sponge.events.EnterExitRegionEvent)1 ImmutableList (com.google.common.collect.ImmutableList)1 Optional (java.util.Optional)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 Action (org.cubeengine.module.vigil.report.Action)1 PotionEffect (org.spongepowered.api.effect.potion.PotionEffect)1 Living (org.spongepowered.api.entity.living.Living)1 Player (org.spongepowered.api.entity.living.player.Player)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 Text (org.spongepowered.api.text.Text)1 TextActions.showText (org.spongepowered.api.text.action.TextActions.showText)1 World (org.spongepowered.api.world.World)1 IMixinEntityLivingBase (org.spongepowered.common.interfaces.entity.IMixinEntityLivingBase)1