Search in sources :

Example 46 with Item

use of net.minecraft.server.v1_15_R1.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 47 with Item

use of net.minecraft.server.v1_15_R1.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 48 with Item

use of net.minecraft.server.v1_15_R1.Item in project solinia3-core by mixxit.

the class ItemStackUtils method ConvertItemStackToJsonRegular.

public static String ConvertItemStackToJsonRegular(ItemStack itemStack) {
    // First we convert the item stack into an NMS itemstack
    net.minecraft.server.v1_15_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound compound = new NBTTagCompound();
    compound = nmsItemStack.save(compound);
    return compound.toString();
}
Also used : NBTTagCompound(net.minecraft.server.v1_15_R1.NBTTagCompound)

Example 49 with Item

use of net.minecraft.server.v1_15_R1.Item in project solinia3-core by mixxit.

the class ItemStackUtils method getWeaponDamageFromItemStack.

public static int getWeaponDamageFromItemStack(ItemStack itemStack, EnumItemSlot itemSlot) {
    double attackDamage = 1.0;
    UUID uuid = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF");
    net.minecraft.server.v1_15_R1.ItemStack craftItemStack = CraftItemStack.asNMSCopy(itemStack);
    net.minecraft.server.v1_15_R1.Item item = craftItemStack.getItem();
    if (item instanceof net.minecraft.server.v1_15_R1.ItemSword || item instanceof net.minecraft.server.v1_15_R1.ItemTool || item instanceof net.minecraft.server.v1_15_R1.ItemHoe) {
        Multimap<String, AttributeModifier> map = item.a(itemSlot);
        Collection<AttributeModifier> attributes = map.get(GenericAttributes.ATTACK_DAMAGE.getName());
        if (!attributes.isEmpty()) {
            for (AttributeModifier am : attributes) {
                if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.ADDITION)
                    attackDamage += am.getAmount();
            }
            double y = 1;
            for (AttributeModifier am : attributes) {
                if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.MULTIPLY_BASE)
                    y += am.getAmount();
            }
            attackDamage *= y;
            for (AttributeModifier am : attributes) {
                if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.MULTIPLY_TOTAL)
                    attackDamage *= (1 + am.getAmount());
            }
        }
    }
    Long rounded = Math.round(attackDamage);
    if (rounded > Integer.MAX_VALUE)
        rounded = (long) Integer.MAX_VALUE;
    int damage = Integer.valueOf(rounded.intValue());
    return damage;
}
Also used : AttributeModifier(net.minecraft.server.v1_15_R1.AttributeModifier) UUID(java.util.UUID)

Example 50 with Item

use of net.minecraft.server.v1_15_R1.Item in project solinia3-core by mixxit.

the class SoliniaLivingEntity method getItemBonusesTuple.

public Tuple<Integer, Integer> getItemBonusesTuple(SpellEffectType spellEffectType, SpellResistType filterResistType) {
    List<ISoliniaItem> equippedItems = this.getEquippedSoliniaItems();
    int highest = 0;
    int highest2 = 0;
    // Check if item focus effect exists for the client.
    if (equippedItems.size() > 0) {
        ISoliniaItem TempItem = null;
        // item focus
        for (ISoliniaItem item : equippedItems) {
            TempItem = item;
            if (TempItem == null)
                continue;
            if (TempItem.getFocusEffectId() < 1) {
                continue;
            }
            ISoliniaSpell spell = null;
            try {
                spell = StateManager.getInstance().getConfigurationManager().getSpell(item.getFocusEffectId());
                if (spell == null)
                    continue;
                if (!filterResistType.equals(SpellResistType.RESIST_NONE))
                    if (spell.isEffectInSpell(SpellEffectType.LimitResist)) {
                        try {
                            // For spells like Pet Focus where the spell type has type limits (ie fire resist = fire pet)
                            int resistTypeId = spell.getSpellEffectBase(SpellEffectType.LimitResist);
                            if (SpellUtils.getSpellResistType(resistTypeId) != filterResistType)
                                continue;
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                if (!spell.isEffectInSpell(spellEffectType))
                    continue;
                Tuple<Integer, Integer> spellBonuses = ApplySpellsBonuses(spell.getId(), getBukkitLivingEntity(), getBukkitLivingEntity(), spell.getSpellEffect(spellEffectType), getMentorLevel(), 0, 0);
                if (spellBonuses.a() > highest) {
                    highest = spellBonuses.a();
                    highest2 = spellBonuses.b();
                }
            } catch (CoreStateInitException e) {
            }
        }
    }
    return new Tuple<Integer, Integer>(highest, highest2);
}
Also used : ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Tuple(net.minecraft.server.v1_15_R1.Tuple)

Aggregations

Item (org.orcid.jaxb.model.notification.permission_v2.Item)19 CraftItemStack (org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack)12 ItemStack (org.bukkit.inventory.ItemStack)12 NBTTagCompound (net.minecraft.server.v1_15_R1.NBTTagCompound)8 Field (java.lang.reflect.Field)7 Test (org.junit.Test)7 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)7 ArrayList (java.util.ArrayList)5 Item (net.minecraft.server.v1_12_R1.Item)5 Items (org.orcid.jaxb.model.notification.permission_v2.Items)5 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)4 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)3 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)3 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)2 Font (java.awt.Font)2 Point (java.awt.Point)2 Timestamp (java.sql.Timestamp)2 UUID (java.util.UUID)2 Nullable (javax.annotation.Nullable)2 Block (net.minecraft.server.v1_12_R1.Block)2