use of net.minecraft.server.v1_16_R2.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();
}
use of net.minecraft.server.v1_16_R2.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);
}
}
use of net.minecraft.server.v1_16_R2.Item in project CokesAddon by Cokes86.
the class v1_16_R2 method injectPlayer.
public void injectPlayer(Player player) {
CraftPlayer player1 = (CraftPlayer) player;
if (!player.isValid())
return;
if (channelHandlers.containsKey(player.getUniqueId())) {
final Pair<CraftPlayer, ChannelOutboundHandlerAdapter> pair = channelHandlers.get(player.getUniqueId());
if (!pair.getLeft().isValid()) {
try {
pair.getLeft().getHandle().playerConnection.networkManager.channel.pipeline().remove(pair.getRight());
} catch (NoSuchElementException ignored) {
}
} else
return;
}
final ChannelOutboundHandlerAdapter handler = new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
if (packet instanceof PacketPlayOutEntityEquipment) {
if ((int) ReflectionUtil.FieldUtil.getValue(packet, "a") == getPlayer().getEntityId()) {
ReflectionUtil.FieldUtil.setValue(packet, "c", ItemStack.a);
}
} else if (packet instanceof PacketPlayOutEntityMetadata) {
if ((int) ReflectionUtil.FieldUtil.getValue(packet, "a") == getPlayer().getEntityId()) {
List<Item<?>> items = ReflectionUtil.FieldUtil.getValue(packet, "b");
if (items.size() != 0) {
Item<?> item = items.get(0);
if (BYTE_DATA_WATCHER_OBJECT.equals(item.a())) {
Item<Byte> byteItem = (Item<Byte>) item;
byteItem.a((byte) (byteItem.b() | 1 << 5));
((CraftPlayer) getPlayer()).getHandle().setInvisible(true);
}
}
}
}
super.write(ctx, packet, promise);
}
};
channelHandlers.put(player.getUniqueId(), Pair.of(player1, handler));
player1.getHandle().playerConnection.networkManager.channel.pipeline().addBefore("packet_handler", hashCode() + ":" + player.getName(), handler);
}
use of net.minecraft.server.v1_16_R2.Item in project MechanicsMain by WeaponMechanics.
the class NonNullList_1_11_R1 method set.
@Override
public ItemStack set(int index, ItemStack newItem) {
ItemStack oldItem = get(index);
Item item = (Item) ReflectionUtil.invokeField(itemField, newItem);
if (newItem.getCount() == 0 && item != null) {
newItem.setCount(1);
consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index);
newItem.setCount(0);
} else if (!ItemStack.matches(oldItem, newItem)) {
consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index);
}
return super.set(index, newItem);
}
use of net.minecraft.server.v1_16_R2.Item in project MechanicsMain by WeaponMechanics.
the class NonNullList_1_14_R1 method set.
@Override
public ItemStack set(int index, ItemStack newItem) {
ItemStack oldItem = get(index);
Item item = (Item) ReflectionUtil.invokeField(itemField, newItem);
if (newItem.getCount() == 0 && item != null) {
newItem.setCount(1);
consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index);
newItem.setCount(0);
} else if (!ItemStack.matches(oldItem, newItem)) {
consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index);
}
return super.set(index, newItem);
}
Aggregations