From 43d2754018b6d558770399ae47eac937f2c9b643 Mon Sep 17 00:00:00 2001 From: Draycia Date: Sat, 8 Jul 2023 15:16:50 -0700 Subject: [PATCH] Start hiding relocated api libs --- api/build.gradle.kts | 10 ++--- .../carbon/api/event/CarbonEventHandler.java | 19 ++++---- .../api/event/CarbonEventSubscriber.java | 38 ++++++++++++++++ .../api/event/CarbonEventSubscription.java | 44 +++++++++++++++++++ common/build.gradle.kts | 1 + .../common/event/CarbonEventHandlerImpl.java | 20 +++++---- .../event/CarbonEventSubscriptionImpl.java | 31 +++++++++++++ 7 files changed, 140 insertions(+), 23 deletions(-) create mode 100644 api/src/main/java/net/draycia/carbon/api/event/CarbonEventSubscriber.java create mode 100644 api/src/main/java/net/draycia/carbon/api/event/CarbonEventSubscription.java create mode 100644 common/src/main/java/net/draycia/carbon/common/event/CarbonEventSubscriptionImpl.java diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 76191003..b1596d19 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -20,13 +20,13 @@ dependencies { compileOnlyApi(libs.checkerQual) - api(libs.event) - api(libs.kyoriRegistry) { + compileOnlyApi(libs.event) + compileOnlyApi(libs.kyoriRegistry) { exclude("com.google.guava") } - api(libs.kyoriMoonshine) - api(libs.kyoriMoonshineCore) - api(libs.kyoriMoonshineStandard) + compileOnlyApi(libs.kyoriMoonshine) + compileOnlyApi(libs.kyoriMoonshineCore) + compileOnlyApi(libs.kyoriMoonshineStandard) // Provided by Minecraft compileOnlyApi(libs.gson) diff --git a/api/src/main/java/net/draycia/carbon/api/event/CarbonEventHandler.java b/api/src/main/java/net/draycia/carbon/api/event/CarbonEventHandler.java index e414adf7..47f41574 100644 --- a/api/src/main/java/net/draycia/carbon/api/event/CarbonEventHandler.java +++ b/api/src/main/java/net/draycia/carbon/api/event/CarbonEventHandler.java @@ -19,15 +19,15 @@ */ package net.draycia.carbon.api.event; -import com.seiama.event.EventSubscriber; -import com.seiama.event.EventSubscription; -import java.util.function.Consumer; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; /** * Carbon event dispatcher. * * @since 2.1.0 */ +@DefaultQualifier(NonNull.class) public interface CarbonEventHandler { /** @@ -39,9 +39,9 @@ public interface CarbonEventHandler { * @return the subscription, so that it may be unregistered * @since 2.0.0 */ - EventSubscription subscribe( + CarbonEventSubscription subscribe( final Class eventClass, - final EventSubscriber subscriber + final CarbonEventSubscriber subscriber ); /** @@ -51,16 +51,16 @@ public interface CarbonEventHandler { * @param eventClass the class to listen for * @param order the order of the consumer * @param acceptsCancelled if the consumer should be executed if the event is cancelled early - * @param consumer the consumer that's executed when the event is emitted + * @param subscriber the consumer that's executed when the event is emitted * @param the class to listen for * @return the subscription, so that it may be unregistered * @since 2.0.0 */ - EventSubscription subscribe( + CarbonEventSubscription subscribe( final Class eventClass, final int order, final boolean acceptsCancelled, - final Consumer consumer + final CarbonEventSubscriber subscriber ); /** @@ -69,8 +69,9 @@ public interface CarbonEventHandler { * the event while it's being emitted. * * @param event the event to be emitted + * @param the class to emit * @since 2.0.0 */ - void emit(final CarbonEvent event); + void emit(final T event); } diff --git a/api/src/main/java/net/draycia/carbon/api/event/CarbonEventSubscriber.java b/api/src/main/java/net/draycia/carbon/api/event/CarbonEventSubscriber.java new file mode 100644 index 00000000..540674fa --- /dev/null +++ b/api/src/main/java/net/draycia/carbon/api/event/CarbonEventSubscriber.java @@ -0,0 +1,38 @@ +/* + * CarbonChat + * + * Copyright (c) 2023 Josua Parks (Vicarious) + * Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.draycia.carbon.api.event; + +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; +import org.jetbrains.annotations.NotNull; + +@DefaultQualifier(NonNull.class) +public interface CarbonEventSubscriber { + + /** + * Invokes this event consumer. + * + * @param event the event + * @throws Throwable if an exception is thrown + * @since 1.0.0 + */ + void on(final @NotNull T event) throws Throwable; + +} diff --git a/api/src/main/java/net/draycia/carbon/api/event/CarbonEventSubscription.java b/api/src/main/java/net/draycia/carbon/api/event/CarbonEventSubscription.java new file mode 100644 index 00000000..e0e02290 --- /dev/null +++ b/api/src/main/java/net/draycia/carbon/api/event/CarbonEventSubscription.java @@ -0,0 +1,44 @@ +/* + * CarbonChat + * + * Copyright (c) 2023 Josua Parks (Vicarious) + * Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.draycia.carbon.api.event; + +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; + +@DefaultQualifier(NonNull.class) +public interface CarbonEventSubscription { + + /** + * Gets the event type. + * + * @return the event type + * @since 2.1.0 + */ + Class event(); + + /** + * Gets the subscriber. + * + * @return the subscriber + * @since 2.1.0 + */ + CarbonEventSubscriber subscriber(); + +} diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 6b313341..0c1a830d 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -27,6 +27,7 @@ dependencies { isTransitive = false } compileOnlyApi(libs.luckPermsApi) + compileOnlyApi(libs.event) // Storage compileOnlyApi(libs.jdbiCore) diff --git a/common/src/main/java/net/draycia/carbon/common/event/CarbonEventHandlerImpl.java b/common/src/main/java/net/draycia/carbon/common/event/CarbonEventHandlerImpl.java index 296a19ee..063615fa 100644 --- a/common/src/main/java/net/draycia/carbon/common/event/CarbonEventHandlerImpl.java +++ b/common/src/main/java/net/draycia/carbon/common/event/CarbonEventHandlerImpl.java @@ -22,15 +22,15 @@ package net.draycia.carbon.common.event; import com.google.inject.Inject; import com.google.inject.Singleton; import com.seiama.event.EventConfig; -import com.seiama.event.EventSubscriber; import com.seiama.event.EventSubscription; import com.seiama.event.bus.EventBus; import com.seiama.event.bus.SimpleEventBus; import com.seiama.event.registry.EventRegistry; import com.seiama.event.registry.SimpleEventRegistry; -import java.util.function.Consumer; import net.draycia.carbon.api.event.CarbonEvent; import net.draycia.carbon.api.event.CarbonEventHandler; +import net.draycia.carbon.api.event.CarbonEventSubscriber; +import net.draycia.carbon.api.event.CarbonEventSubscription; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.framework.qual.DefaultQualifier; @@ -56,27 +56,29 @@ public final class CarbonEventHandlerImpl implements CarbonEventHandler { } @Override - public EventSubscription subscribe( + public CarbonEventSubscription subscribe( final Class eventClass, - final EventSubscriber subscriber + final CarbonEventSubscriber subscriber ) { - return this.eventRegistry.subscribe(eventClass, subscriber); + this.eventRegistry.subscribe(eventClass, subscriber::on); + return new CarbonEventSubscriptionImpl<>(eventClass, subscriber); } // TODO: support EventConfig#exact() @Override - public EventSubscription subscribe( + public CarbonEventSubscription subscribe( final Class eventClass, final int order, final boolean acceptsCancelled, - final Consumer consumer + final CarbonEventSubscriber subscriber ) { final EventConfig eventConfig = EventConfig.defaults().order(order).acceptsCancelled(acceptsCancelled); - return this.eventRegistry.subscribe(eventClass, eventConfig, consumer::accept); + this.eventRegistry.subscribe(eventClass, eventConfig, subscriber::on); + return new CarbonEventSubscriptionImpl<>(eventClass, subscriber); } @Override - public void emit(final CarbonEvent event) { + public void emit(final T event) { this.eventBus.post(event); } diff --git a/common/src/main/java/net/draycia/carbon/common/event/CarbonEventSubscriptionImpl.java b/common/src/main/java/net/draycia/carbon/common/event/CarbonEventSubscriptionImpl.java new file mode 100644 index 00000000..47a0a513 --- /dev/null +++ b/common/src/main/java/net/draycia/carbon/common/event/CarbonEventSubscriptionImpl.java @@ -0,0 +1,31 @@ +/* + * CarbonChat + * + * Copyright (c) 2023 Josua Parks (Vicarious) + * Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.draycia.carbon.common.event; + +import net.draycia.carbon.api.event.CarbonEvent; +import net.draycia.carbon.api.event.CarbonEventSubscriber; +import net.draycia.carbon.api.event.CarbonEventSubscription; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.framework.qual.DefaultQualifier; + +@DefaultQualifier(NonNull.class) + record CarbonEventSubscriptionImpl(Class event, CarbonEventSubscriber subscriber) implements CarbonEventSubscription { + +}