Search in sources :

Example 26 with Item

use of net.minecraft.server.v1_8_R3.Item in project ORCID-Source by ORCID.

the class MapperFacadeFactory method getObject.

@Override
public MapperFacade getObject() throws Exception {
    MapperFactory mapperFactory = getNewMapperFactory();
    // Register converters
    ConverterFactory converterFactory = mapperFactory.getConverterFactory();
    converterFactory.registerConverter("externalIdentifierIdConverter", new ExternalIdentifierTypeConverter());
    // Register factories
    mapperFactory.registerObjectFactory(new WorkEntityFactory(workDao), TypeFactory.<NotificationWorkEntity>valueOf(NotificationWorkEntity.class), TypeFactory.<Item>valueOf(Item.class));
    // Custom notification
    ClassMapBuilder<NotificationCustom, NotificationCustomEntity> notificationCustomClassMap = mapperFactory.classMap(NotificationCustom.class, NotificationCustomEntity.class);
    registerSourceConverters(mapperFactory, notificationCustomClassMap);
    mapCommonFields(notificationCustomClassMap).register();
    // Permission notification
    ClassMapBuilder<NotificationPermission, NotificationAddItemsEntity> notificationPermissionClassMap = mapperFactory.classMap(NotificationPermission.class, NotificationAddItemsEntity.class);
    registerSourceConverters(mapperFactory, notificationPermissionClassMap);
    mapCommonFields(notificationPermissionClassMap.field("authorizationUrl.uri", "authorizationUrl").field("items.items", "notificationItems").customize(new CustomMapper<NotificationPermission, NotificationAddItemsEntity>() {

        @Override
        public void mapAtoB(NotificationPermission notification, NotificationAddItemsEntity entity, MappingContext context) {
            if (StringUtils.isBlank(entity.getAuthorizationUrl())) {
                String authUrl = orcidUrlManager.getBaseUrl() + notification.getAuthorizationUrl().getPath();
                // validate
                validateAndConvertToURI(authUrl);
                entity.setAuthorizationUrl(authUrl);
            }
        }

        @Override
        public void mapBtoA(NotificationAddItemsEntity entity, NotificationPermission notification, MappingContext context) {
            AuthorizationUrl authUrl = notification.getAuthorizationUrl();
            if (authUrl != null) {
                authUrl.setPath(extractFullPath(authUrl.getUri()));
                authUrl.setHost(orcidUrlManager.getBaseHost());
            }
        }
    })).register();
    // Institutional sign in notification
    ClassMapBuilder<NotificationInstitutionalConnection, NotificationInstitutionalConnectionEntity> institutionalConnectionNotificationClassMap = mapperFactory.classMap(NotificationInstitutionalConnection.class, NotificationInstitutionalConnectionEntity.class);
    registerSourceConverters(mapperFactory, institutionalConnectionNotificationClassMap);
    mapCommonFields(institutionalConnectionNotificationClassMap.field("authorizationUrl.uri", "authorizationUrl").customize(new CustomMapper<NotificationInstitutionalConnection, NotificationInstitutionalConnectionEntity>() {

        @Override
        public void mapAtoB(NotificationInstitutionalConnection notification, NotificationInstitutionalConnectionEntity entity, MappingContext context) {
            if (StringUtils.isBlank(entity.getAuthorizationUrl())) {
                String authUrl = orcidUrlManager.getBaseUrl() + notification.getAuthorizationUrl().getPath();
                // validate
                validateAndConvertToURI(authUrl);
                entity.setAuthorizationUrl(authUrl);
            }
        }

        @Override
        public void mapBtoA(NotificationInstitutionalConnectionEntity entity, NotificationInstitutionalConnection notification, MappingContext context) {
            AuthorizationUrl authUrl = notification.getAuthorizationUrl();
            if (authUrl != null) {
                authUrl.setPath(extractFullPath(authUrl.getUri()));
                authUrl.setHost(orcidUrlManager.getBaseHost());
            }
            String providerId = entity.getAuthenticationProviderId();
            if (StringUtils.isNotBlank(providerId)) {
                String idpName = identityProviderManager.retrieveIdentitifyProviderName(providerId);
                notification.setIdpName(idpName);
            } else {
                notification.setIdpName(LAST_RESORT_IDENTITY_PROVIDER_NAME);
            }
        }
    })).register();
    // Amend notification
    ClassMapBuilder<NotificationAmended, NotificationAmendedEntity> amendNotificationClassMap = mapperFactory.classMap(NotificationAmended.class, NotificationAmendedEntity.class);
    registerSourceConverters(mapperFactory, amendNotificationClassMap);
    mapCommonFields(amendNotificationClassMap.exclude("amendedSection").customize(new CustomMapper<NotificationAmended, NotificationAmendedEntity>() {

        @Override
        public void mapAtoB(NotificationAmended a, NotificationAmendedEntity b, MappingContext context) {
            if (a.getAmendedSection() != null) {
                switch(a.getAmendedSection()) {
                    case AFFILIATION:
                        b.setAmendedSection(AmendedSection.AFFILIATION);
                        break;
                    case BIO:
                        b.setAmendedSection(AmendedSection.BIO);
                        break;
                    case EDUCATION:
                        b.setAmendedSection(AmendedSection.EDUCATION);
                        break;
                    case EMPLOYMENT:
                        b.setAmendedSection(AmendedSection.EMPLOYMENT);
                        break;
                    case EXTERNAL_IDENTIFIERS:
                        b.setAmendedSection(AmendedSection.EXTERNAL_IDENTIFIERS);
                        break;
                    case FUNDING:
                        b.setAmendedSection(AmendedSection.FUNDING);
                        break;
                    case PEER_REVIEW:
                        b.setAmendedSection(AmendedSection.PEER_REVIEW);
                        break;
                    case PREFERENCES:
                        b.setAmendedSection(AmendedSection.PREFERENCES);
                        break;
                    case UNKNOWN:
                        b.setAmendedSection(AmendedSection.UNKNOWN);
                        break;
                    case WORK:
                        b.setAmendedSection(AmendedSection.WORK);
                        break;
                    default:
                        b.setAmendedSection(AmendedSection.UNKNOWN);
                        break;
                }
            }
        }

        /**
         * From database to model object, map amended sections for new affiliation types as AFFILIATION
         */
        @Override
        public void mapBtoA(NotificationAmendedEntity b, NotificationAmended a, MappingContext context) {
            if (b.getAmendedSection() != null) {
                switch(b.getAmendedSection()) {
                    case AFFILIATION:
                    case DISTINCTION:
                    case INVITED_POSITION:
                    case MEMBERSHIP:
                    case QUALIFICATION:
                    case SERVICE:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.AFFILIATION);
                        break;
                    case BIO:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.BIO);
                        break;
                    case EDUCATION:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.EDUCATION);
                        break;
                    case EMPLOYMENT:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.EMPLOYMENT);
                        break;
                    case EXTERNAL_IDENTIFIERS:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.EXTERNAL_IDENTIFIERS);
                        break;
                    case FUNDING:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.FUNDING);
                        break;
                    case PEER_REVIEW:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.PEER_REVIEW);
                        break;
                    case PREFERENCES:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.PREFERENCES);
                        break;
                    case UNKNOWN:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.UNKNOWN);
                        break;
                    case WORK:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.WORK);
                        break;
                }
            }
        }
    })).register();
    mapperFactory.classMap(NotificationItemEntity.class, Item.class).fieldMap("externalIdType", "externalIdentifier.type").converter("externalIdentifierIdConverter").add().field("externalIdValue", "externalIdentifier.value").byDefault().register();
    return mapperFactory.getMapperFacade();
}
Also used : NotificationInstitutionalConnectionEntity(org.orcid.persistence.jpa.entities.NotificationInstitutionalConnectionEntity) ConverterFactory(ma.glasnost.orika.converter.ConverterFactory) NotificationCustom(org.orcid.jaxb.model.notification.custom_v2.NotificationCustom) NotificationAddItemsEntity(org.orcid.persistence.jpa.entities.NotificationAddItemsEntity) MappingContext(ma.glasnost.orika.MappingContext) AuthorizationUrl(org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl) Item(org.orcid.jaxb.model.notification.permission_v2.Item) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) NotificationAmendedEntity(org.orcid.persistence.jpa.entities.NotificationAmendedEntity) NotificationInstitutionalConnection(org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection) NotificationCustomEntity(org.orcid.persistence.jpa.entities.NotificationCustomEntity) NotificationWorkEntity(org.orcid.persistence.jpa.entities.NotificationWorkEntity) ExternalIdentifierTypeConverter(org.orcid.core.adapter.jsonidentifier.converter.ExternalIdentifierTypeConverter) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)

Example 27 with Item

use of net.minecraft.server.v1_8_R3.Item in project powerbot by powerbot.

the class DrawItems method repaint.

public void repaint(final Graphics render) {
    if (!ctx.game.loggedIn()) {
        return;
    }
    render.setFont(new Font("Arial", 0, 10));
    render.setColor(Color.green);
    for (final Item item : ctx.inventory.select()) {
        final Point p = item.centerPoint();
        p.translate(-21, -18);
        render.drawString(item.id() + "", p.x, p.y + 36);
    }
}
Also used : Item(org.powerbot.script.rt4.Item) Point(java.awt.Point) Font(java.awt.Font)

Example 28 with Item

use of net.minecraft.server.v1_8_R3.Item in project acidisland by tastybento.

the class NMSHandler method setBook.

@Override
public ItemStack setBook(Tag item) {
    ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
    // Bukkit.getLogger().info(item.toString());
    if (((CompoundTag) item).getValue().containsKey("tag")) {
        Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
        // BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
        String author = "";
        if (contents.containsKey("author")) {
            author = ((StringTag) contents.get("author")).getValue();
        }
        // Bukkit.getLogger().info("Author: " + author);
        // bookMeta.setAuthor(author);
        String title = "";
        if (contents.containsKey("title")) {
            title = ((StringTag) contents.get("title")).getValue();
        }
        // Bukkit.getLogger().info("Title: " + title);
        // bookMeta.setTitle(title);
        List<String> lore = new ArrayList<String>();
        if (contents.containsKey("display")) {
            Map<String, Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
            List<Tag> loreTag = ((ListTag) display.get("Lore")).getValue();
            for (Tag s : loreTag) {
                lore.add(((StringTag) s).getValue());
            }
        }
        // Bukkit.getLogger().info("Lore: " + lore);
        net.minecraft.server.v1_8_R3.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
        // Pages
        // Create the NMS Stack's NBT (item data)
        NBTTagCompound tag = new NBTTagCompound();
        // Set the book's title
        tag.setString("title", title);
        tag.setString("author", author);
        if (contents.containsKey("pages")) {
            NBTTagList pages = new NBTTagList();
            List<Tag> pagesTag = ((ListTag) contents.get("pages")).getValue();
            for (Tag s : pagesTag) {
                pages.add(new NBTTagString(((StringTag) s).getValue()));
            }
            // Add the pages to the tag
            tag.set("pages", pages);
        }
        // Apply the tag to the item
        stack.setTag(tag);
        chestItem = CraftItemStack.asCraftMirror(stack);
        ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
        bookMeta.setLore(lore);
        chestItem.setItemMeta(bookMeta);
    }
    return chestItem;
}
Also used : StringTag(com.wasteofplastic.org.jnbt.StringTag) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) NBTTagString(net.minecraft.server.v1_8_R3.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) NBTTagList(net.minecraft.server.v1_8_R3.NBTTagList) NBTTagString(net.minecraft.server.v1_8_R3.NBTTagString) StringTag(com.wasteofplastic.org.jnbt.StringTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag) Tag(com.wasteofplastic.org.jnbt.Tag) ListTag(com.wasteofplastic.org.jnbt.ListTag) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 29 with Item

use of net.minecraft.server.v1_8_R3.Item in project MyPet by xXKeyleXx.

the class IconMenuInventory method createItemStack.

protected ItemStack createItemStack(IconMenuItem icon) {
    ItemStack is = CraftItemStack.asNMSCopy(CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(icon.getMaterial(), icon.getAmount(), (short) icon.getData())));
    if (is == null) {
        is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.SAPLING));
    }
    NBTTagList emptyList = new NBTTagList();
    if (is.getTag() == null) {
        is.setTag(new NBTTagCompound());
    }
    if (icon.getBukkitMeta() != null) {
        try {
            applyToItemMethhod.invoke(icon.getBukkitMeta(), is.getTag());
        } catch (InvocationTargetException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    // remove item attributes like attack damage
    is.getTag().set("AttributeModifiers", emptyList);
    // add enchantment glowing
    if (icon.isGlowing()) {
        is.getTag().set("ench", emptyList);
    } else {
        is.getTag().remove("ench");
    }
    // Prepare display tag
    NBTTagCompound display;
    if (is.getTag().hasKey("display")) {
        display = is.getTag().getCompound("display");
    } else {
        display = new NBTTagCompound();
        is.getTag().set("display", display);
    }
    // set Title
    if (!icon.getTitle().equals("")) {
        display.setString("Name", icon.getTitle());
    }
    if (icon.getLore().size() > 0) {
        // set Lore
        NBTTagList loreTag = new NBTTagList();
        display.set("Lore", loreTag);
        for (String loreLine : icon.getLore()) {
            loreTag.add(new NBTTagString(loreLine));
        }
    }
    if (icon.hasMeta()) {
        TagCompound tag = new TagCompound();
        icon.getMeta().applyTo(tag);
        NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag);
        for (String key : vanillaTag.c()) {
            is.getTag().set(key, vanillaTag.get(key));
        }
    }
    return is;
}
Also used : NBTTagList(net.minecraft.server.v1_8_R3.NBTTagList) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) NBTTagString(net.minecraft.server.v1_8_R3.NBTTagString) NBTTagString(net.minecraft.server.v1_8_R3.NBTTagString) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 30 with Item

use of net.minecraft.server.v1_8_R3.Item in project MyPet by xXKeyleXx.

the class IconMenuInventory method update.

@Override
public void update(IconMenu menu) {
    if (minecraftInventory != null) {
        for (int slot = 0; slot < size; slot++) {
            IconMenuItem menuItem = menu.getOption(slot);
            if (menuItem != null) {
                ItemStack item = createItemStack(menuItem);
                minecraftInventory.setItem(slot, item);
            } else {
                minecraftInventory.setItem(slot, null);
            }
        }
    }
}
Also used : IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)

Aggregations

Item (org.orcid.jaxb.model.notification.permission_v2.Item)19 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)7 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)6 ItemStack (org.bukkit.inventory.ItemStack)5 Test (org.junit.Test)5 Items (org.orcid.jaxb.model.notification.permission_v2.Items)5 ArrayList (java.util.ArrayList)4 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)4 ItemStack (net.minecraft.server.v1_8_R3.ItemStack)3 NBTTagList (net.minecraft.server.v1_8_R3.NBTTagList)3 NBTTagString (net.minecraft.server.v1_8_R3.NBTTagString)3 Url (org.orcid.jaxb.model.common_v2.Url)3 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)2 ListTag (com.wasteofplastic.org.jnbt.ListTag)2 StringTag (com.wasteofplastic.org.jnbt.StringTag)2 Tag (com.wasteofplastic.org.jnbt.Tag)2 IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)2 Font (java.awt.Font)2 Point (java.awt.Point)2 Map (java.util.Map)2