Search in sources :

Example 11 with EntityType

use of org.spongepowered.api.entity.EntityType in project modules-extra by CubeEngine.

the class Recall method cause.

private static Text cause(Map<String, Object> source, Text text, CauseType type) {
    Object causeName = source.get(CAUSE_NAME);
    switch(type) {
        case CAUSE_PLAYER:
            text = Text.of(DARK_GREEN, causeName).toBuilder().onHover(TextActions.showText(Text.of(YELLOW, source.get(CAUSE_PLAYER_UUID)))).build();
            break;
        case CAUSE_BLOCK:
            Optional<BlockType> bType = Sponge.getRegistry().getType(BlockType.class, causeName.toString());
            if (!bType.isPresent()) {
                // TODO translate
                text = Text.of(TextColors.GOLD, "unknown Block");
            } else {
                if (bType.get() == BlockTypes.LAVA || bType.get() == BlockTypes.FLOWING_LAVA || bType.get() == BlockTypes.FIRE) {
                    text = Text.of(TextColors.RED, bType.get().getTranslation());
                } else {
                    text = Text.of(TextColors.GOLD, bType.get().getTranslation());
                }
            }
            break;
        case CAUSE_TNT:
            // TODO translatable
            text = Text.of(TextColors.RED, "TNT");
            if (source.get(CAUSE_PLAYER_UUID) == null) {
                text = text.toBuilder().append(Text.of(" (", Text.of(TextColors.GOLD, causeName), ")")).build();
            } else {
                text = text.toBuilder().append(Text.of(" (", Text.of(DARK_GREEN, causeName).toBuilder().onHover(TextActions.showText(Text.of(YELLOW, source.get(CAUSE_PLAYER_UUID)))).build(), ")")).build();
            }
            break;
        case CAUSE_DAMAGE:
            text = Text.of(TextColors.GOLD, causeName);
            break;
        case CAUSE_ENTITY:
            text = Text.of(TextColors.GOLD, Sponge.getRegistry().getType(EntityType.class, causeName.toString()).map(EntityType::getTranslation).map(Translation::get).orElse(causeName.toString()));
            // TODO translation
            if (source.containsKey(CAUSE_TARGET)) {
                Map<String, Object> sourceTarget = ((Map<String, Object>) source.get(CAUSE_TARGET));
                CauseType targetType = CauseType.valueOf(sourceTarget.get(CAUSE_TYPE).toString());
                text = text.toBuilder().append(Text.of("…").toBuilder().onHover(TextActions.showText(Text.of(text, "◎", cause(sourceTarget, Text.of("?"), targetType)))).build()).build();
            }
            break;
    }
    return text;
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) BlockType(org.spongepowered.api.block.BlockType) CauseType(org.cubeengine.module.vigil.report.block.BlockReport.CauseType)

Example 12 with EntityType

use of org.spongepowered.api.entity.EntityType in project modules-extra by CubeEngine.

the class Spawner method onInteract.

@Listener(order = POST)
public void onInteract(InteractBlockEvent.Secondary event, @First Player player) {
    if (!event.getTargetBlock().getLocation().isPresent()) {
        return;
    }
    Location<World> block = event.getTargetBlock().getLocation().get();
    if (block.getBlockType().equals(MOB_SPAWNER) && player.getItemInHand(MAIN_HAND).map(i -> i.getType().equals(ItemTypes.SPAWN_EGG)).orElse(false)) {
        event.setCancelled(true);
        if (block.get(SPAWNER_ENTITIES).map(RandomObjectTable::isEmpty).orElse(false)) {
            ItemStack itemInHand = player.getItemInHand(MAIN_HAND).get();
            EntityType type = itemInHand.get(Keys.SPAWNABLE_ENTITY_TYPE).get();
            Permission perm = this.perms.get(type);
            if (perm == null) {
                this.initPerm(type);
                perm = this.perms.get(type);
            }
            if (perm == null && !player.hasPermission(eggPerms.getId())) {
                i18n.send(ACTION_BAR, player, NEGATIVE, "Invalid SpawnEgg!");
                return;
            }
            if (perm != null && !player.hasPermission(perm.getId())) {
                i18n.send(ACTION_BAR, player, NEGATIVE, "You are not allowed to change Monster Spawner to this EntityType!");
                return;
            }
            WeightedTable<EntityArchetype> spawns = new WeightedTable<>();
            EntityArchetype nextSpawn = EntityArchetype.builder().type(type).build();
            spawns.add(nextSpawn, 1);
            block.offer(SPAWNER_ENTITIES, spawns);
            block.offer(SPAWNER_NEXT_ENTITY_TO_SPAWN, new WeightedSerializableObject<>(nextSpawn, 1));
            if (!player.gameMode().get().equals(CREATIVE)) {
                itemInHand.setQuantity(itemInHand.getQuantity() - 1);
                player.setItemInHand(MAIN_HAND, itemInHand);
            }
            i18n.send(ACTION_BAR, player, POSITIVE, "Monster Spawner activated!");
            return;
        }
        i18n.send(ACTION_BAR, player, NEGATIVE, "You can only change inactive Monster Spawner!");
    }
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) WeightedTable(org.spongepowered.api.util.weighted.WeightedTable) EntityArchetype(org.spongepowered.api.entity.EntityArchetype) Permission(org.cubeengine.libcube.service.permission.Permission) World(org.spongepowered.api.world.World) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 13 with EntityType

use of org.spongepowered.api.entity.EntityType in project Nucleus by NucleusPowered.

the class SpawnMobCommand method executeWithPlayer.

@Override
public CommandResult executeWithPlayer(CommandSource src, Player pl, CommandContext args, boolean isSelf) throws Exception {
    // Get the amount
    int amount = args.<Integer>getOne(amountKey).get();
    EntityType et = args.<EntityType>getOne(mobTypeKey).get();
    if (!Living.class.isAssignableFrom(et.getEntityClass())) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.livingonly", et.getTranslation().get()));
    }
    String id = et.getId().toLowerCase();
    if (this.mobConfig.isPerMobPermission() && !permissions.testSuffix(src, "mob." + id.replace(":", "."))) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.mobnoperm", et.getTranslation().get()));
    }
    Optional<BlockSpawnsConfig> config = this.mobConfig.getBlockSpawnsConfigForWorld(pl.getWorld());
    if (config.isPresent() && (config.get().isBlockVanillaMobs() && id.startsWith("minecraft:") || config.get().getIdsToBlock().contains(id))) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.spawnmob.blockedinconfig", et.getTranslation().get()));
    }
    Location<World> loc = pl.getLocation();
    World w = loc.getExtent();
    MessageProvider mp = plugin.getMessageProvider();
    // Count the number of entities spawned.
    int i = 0;
    Entity entityone = null;
    do {
        Entity e = w.createEntity(et, loc.getPosition());
        if (!w.spawnEntity(e)) {
            throw ReturnMessageException.fromKeyText("command.spawnmob.fail", Text.of(e));
        }
        if (entityone == null) {
            entityone = e;
        }
        i++;
    } while (i < Math.min(amount, this.mobConfig.getMaxMobsToSpawn()));
    if (amount > this.mobConfig.getMaxMobsToSpawn()) {
        src.sendMessage(mp.getTextMessageWithFormat("command.spawnmob.limit", String.valueOf(this.mobConfig.getMaxMobsToSpawn())));
    }
    if (i == 0) {
        throw ReturnMessageException.fromKey("command.spawnmob.fail", et.getTranslation().get());
    }
    if (i == 1) {
        src.sendMessage(mp.getTextMessageWithTextFormat("command.spawnmob.success.singular", Text.of(i), Text.of(entityone)));
    } else {
        src.sendMessage(mp.getTextMessageWithTextFormat("command.spawnmob.success.plural", Text.of(i), Text.of(entityone)));
    }
    return CommandResult.success();
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) Entity(org.spongepowered.api.entity.Entity) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Living(org.spongepowered.api.entity.living.Living) BlockSpawnsConfig(io.github.nucleuspowered.nucleus.modules.mob.config.BlockSpawnsConfig) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) World(org.spongepowered.api.world.World)

Example 14 with EntityType

use of org.spongepowered.api.entity.EntityType in project Skree by Skelril.

the class CreatureImpact method run.

@Override
public void run(Living owner, Location<World> target) {
    EntityType targetType = getEntityType();
    mobBarrage(target, targetType, count);
    if (targetType == EntityTypes.BAT) {
        notify(owner, Text.of(TextColors.YELLOW, "Your bow releases a batty attack."));
    } else {
        notify(owner, Text.of(TextColors.YELLOW, "Your bow releases a " + targetType.getName().toLowerCase() + " attack."));
    }
}
Also used : EntityType(org.spongepowered.api.entity.EntityType)

Example 15 with EntityType

use of org.spongepowered.api.entity.EntityType in project SpongeCommon by SpongePowered.

the class MixinHoverEvent method getHandle.

@Override
public HoverAction<?> getHandle() {
    if (!this.initialized) {
        try {
            // This is inefficient, but at least we only need to do it once
            switch(this.action) {
                case SHOW_TEXT:
                    setHandle(TextActions.showText(((IMixinTextComponent) this.value).toText()));
                    break;
                case SHOW_ITEM:
                    setHandle(TextActions.showItem(ItemStackUtil.snapshotOf(new net.minecraft.item.ItemStack(loadNbt()))));
                    break;
                case SHOW_ENTITY:
                    NBTTagCompound nbt = loadNbt();
                    String name = nbt.getString("name");
                    EntityType type = null;
                    if (nbt.hasKey("type", NbtDataUtil.TAG_STRING)) {
                        type = SpongeImpl.getGame().getRegistry().getType(EntityType.class, name).orElse(null);
                    }
                    UUID uniqueId = UUID.fromString(nbt.getString("id"));
                    setHandle(TextActions.showEntity(uniqueId, name, type));
                    break;
                default:
            }
        } finally {
            this.initialized = true;
        }
    }
    return this.handle;
}
Also used : EntityType(org.spongepowered.api.entity.EntityType) IMixinTextComponent(org.spongepowered.common.interfaces.text.IMixinTextComponent) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) UUID(java.util.UUID)

Aggregations

EntityType (org.spongepowered.api.entity.EntityType)33 Vector3d (com.flowpowered.math.vector.Vector3d)7 World (net.minecraft.world.World)6 Entity (org.spongepowered.api.entity.Entity)6 Transform (org.spongepowered.api.entity.Transform)6 ConstructEntityEvent (org.spongepowered.api.event.entity.ConstructEntityEvent)6 SpongeEntityType (org.spongepowered.common.entity.SpongeEntityType)4 Entity (net.minecraft.entity.Entity)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 Player (org.spongepowered.api.entity.living.player.Player)3 CauseStackManager (org.spongepowered.api.event.CauseStackManager)3 World (org.spongepowered.api.world.World)3 Redirect (org.spongepowered.asm.mixin.injection.Redirect)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 NBTTagList (net.minecraft.nbt.NBTTagList)2