use of org.spongepowered.asm.mixin.injection.callback.CallbackInfo in project SpongeCommon by SpongePowered.
the class ServerLoginPacketListenerImplMixin_Vanilla method impl$onTick.
@Inject(method = "tick", at = @At("HEAD"))
private void impl$onTick(final CallbackInfo ci) {
if (this.state == ServerLoginPacketListenerImpl.State.NEGOTIATING) {
final ServerSideConnection connection = (ServerSideConnection) this;
if (this.impl$handshakeState == ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_NOT_STARTED) {
this.impl$handshakeState = ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_CLIENT_TYPE;
((SpongeChannelManager) Sponge.channelManager()).requestClientType(connection).thenAccept(result -> {
this.impl$handshakeState = ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_SYNC_CHANNEL_REGISTRATIONS;
});
} else if (this.impl$handshakeState == ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_SYNC_CHANNEL_REGISTRATIONS) {
((SpongeChannelManager) Sponge.channelManager()).sendLoginChannelRegistry(connection).thenAccept(result -> {
final Cause cause = Cause.of(EventContext.empty(), this);
final ServerSideConnectionEvent.Handshake event = SpongeEventFactory.createServerSideConnectionEventHandshake(cause, connection);
SpongeCommon.post(event);
this.impl$handshakeState = ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_SYNC_PLUGIN_DATA;
});
} else if (this.impl$handshakeState == ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_SYNC_PLUGIN_DATA) {
final TransactionStore store = ConnectionUtil.getTransactionStore(connection);
if (store.isEmpty()) {
this.state = ServerLoginPacketListenerImpl.State.READY_TO_ACCEPT;
}
}
}
}
use of org.spongepowered.asm.mixin.injection.callback.CallbackInfo in project SpongeCommon by SpongePowered.
the class AdvancementMixin method impl$setUpSpongeFields.
@SuppressWarnings({ "ConstantConditions" })
@Inject(method = "<init>", at = @At("RETURN"))
private void impl$setUpSpongeFields(ResourceLocation location, @Nullable Advancement parent, @Nullable DisplayInfo displayInfo, AdvancementRewards rewards, Map<String, Criterion> criteria, String[][] requirements, CallbackInfo ci) {
// Don't do anything on the client, unless we're performing registry initialization
if (!PlatformHooks.INSTANCE.getGeneralHooks().onServerThread()) {
return;
}
if (displayInfo != null) {
((DisplayInfoBridge) displayInfo).bridge$setAdvancement((org.spongepowered.api.advancement.Advancement) this);
}
this.impl$toastText = this.impl$generateToastText();
final Map<String, DefaultedAdvancementCriterion> criteriaMap = new LinkedHashMap<>();
final Map<String, List<DefaultedAdvancementCriterion>> scoreCriteria = new HashMap<>();
for (Map.Entry<String, Criterion> entry : criteria.entrySet()) {
final CriterionBridge mixinCriterion = (CriterionBridge) entry.getValue();
final String groupName = mixinCriterion.bridge$getScoreCriterionName();
if (groupName != null) {
scoreCriteria.computeIfAbsent(groupName, k -> new ArrayList<>()).add((DefaultedAdvancementCriterion) entry.getValue());
}
criteriaMap.put(entry.getKey(), (DefaultedAdvancementCriterion) mixinCriterion);
mixinCriterion.bridge$setName(entry.getKey());
}
for (Map.Entry<String, List<DefaultedAdvancementCriterion>> groupEntry : scoreCriteria.entrySet()) {
criteriaMap.put(groupEntry.getKey(), new SpongeScoreCriterion(groupEntry.getKey(), groupEntry.getValue()));
groupEntry.getValue().forEach(c -> criteriaMap.remove(c.name()));
}
final Set<AdvancementCriterion> andCriteria = new HashSet<>();
for (final String[] array : requirements) {
final Set<AdvancementCriterion> orCriteria = new HashSet<>();
for (final String name : array) {
DefaultedAdvancementCriterion criterion = criteriaMap.get(name);
if (criterion == null && criteria.get(name) != null) {
// internal removed by scoreCriterion
criterion = criteriaMap.get(((CriterionBridge) criteria.get(name)).bridge$getScoreCriterionName());
}
orCriteria.add(criterion);
}
andCriteria.add(OrCriterion.of(orCriteria));
}
this.impl$criterion = AndCriterion.of(andCriteria);
}
Aggregations