From e887a9f1a1eb2ff53a7bb1ec042d9ec1eafa1ab7 Mon Sep 17 00:00:00 2001 From: dfsek Date: Fri, 2 Sep 2022 22:51:57 -0700 Subject: [PATCH] remove additional events, make Event extend Monad --- .../biome/query/BiomeQueryAPIAddon.java | 4 +-- .../terra/addons/manifest/api/monad/Init.java | 9 ++---- .../api/event/events/AbstractCancellable.java | 28 ------------------ .../terra/api/event/events/Cancellable.java | 29 ------------------- .../dfsek/terra/api/event/events/Event.java | 5 +++- .../api/event/events/FailThroughEvent.java | 15 ---------- .../platform/CommandRegistrationEvent.java | 19 ------------ .../platform/PlatformInitializationEvent.java | 17 ----------- .../dfsek/terra/event/EventContextImpl.java | 1 - .../event/FunctionalEventHandlerImpl.java | 1 - 10 files changed, 9 insertions(+), 119 deletions(-) delete mode 100644 common/api/src/main/java/com/dfsek/terra/api/event/events/AbstractCancellable.java delete mode 100644 common/api/src/main/java/com/dfsek/terra/api/event/events/Cancellable.java delete mode 100644 common/api/src/main/java/com/dfsek/terra/api/event/events/FailThroughEvent.java delete mode 100644 common/api/src/main/java/com/dfsek/terra/api/event/events/platform/CommandRegistrationEvent.java delete mode 100644 common/api/src/main/java/com/dfsek/terra/api/event/events/platform/PlatformInitializationEvent.java diff --git a/common/addons/biome-query-api/src/main/java/com/dfsek/terra/addons/biome/query/BiomeQueryAPIAddon.java b/common/addons/biome-query-api/src/main/java/com/dfsek/terra/addons/biome/query/BiomeQueryAPIAddon.java index 155721f2f..b993b69a8 100644 --- a/common/addons/biome-query-api/src/main/java/com/dfsek/terra/addons/biome/query/BiomeQueryAPIAddon.java +++ b/common/addons/biome-query-api/src/main/java/com/dfsek/terra/addons/biome/query/BiomeQueryAPIAddon.java @@ -1,5 +1,7 @@ package com.dfsek.terra.addons.biome.query; +import org.jetbrains.annotations.NotNull; + import java.util.Collection; import com.dfsek.terra.addons.biome.query.impl.BiomeTagFlattener; @@ -15,8 +17,6 @@ import com.dfsek.terra.api.properties.PropertyKey; import com.dfsek.terra.api.util.function.monad.Monad; import com.dfsek.terra.api.world.biome.Biome; -import org.jetbrains.annotations.NotNull; - public class BiomeQueryAPIAddon implements MonadAddonInitializer { public static PropertyKey BIOME_TAG_KEY = Context.create(BiomeTagHolder.class); diff --git a/common/addons/manifest-addon-loader/src/main/java/com/dfsek/terra/addons/manifest/api/monad/Init.java b/common/addons/manifest-addon-loader/src/main/java/com/dfsek/terra/addons/manifest/api/monad/Init.java index a844c92ca..681ee6cdc 100644 --- a/common/addons/manifest-addon-loader/src/main/java/com/dfsek/terra/addons/manifest/api/monad/Init.java +++ b/common/addons/manifest-addon-loader/src/main/java/com/dfsek/terra/addons/manifest/api/monad/Init.java @@ -1,15 +1,12 @@ package com.dfsek.terra.addons.manifest.api.monad; +import java.util.function.Consumer; +import java.util.function.Function; + import com.dfsek.terra.addons.manifest.impl.InitInfo; import com.dfsek.terra.api.util.function.Functions; import com.dfsek.terra.api.util.function.monad.Monad; -import io.vavr.Function0; -import io.vavr.Function1; - -import java.util.function.Consumer; -import java.util.function.Function; - public class Init implements Monad> { private final Function get; diff --git a/common/api/src/main/java/com/dfsek/terra/api/event/events/AbstractCancellable.java b/common/api/src/main/java/com/dfsek/terra/api/event/events/AbstractCancellable.java deleted file mode 100644 index 188f078c9..000000000 --- a/common/api/src/main/java/com/dfsek/terra/api/event/events/AbstractCancellable.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2020-2021 Polyhedral Development - * - * The Terra API is licensed under the terms of the MIT License. For more details, - * reference the LICENSE file in the common/api directory. - */ - -package com.dfsek.terra.api.event.events; - -import com.dfsek.terra.api.util.mutable.MutableBoolean; - - -/** - * Abstract class containing basic {@link Cancellable} implementation. - */ -public abstract class AbstractCancellable implements Cancellable { - private final MutableBoolean cancelled = new MutableBoolean(false); - - @Override - public boolean isCancelled() { - return cancelled.get(); - } - - @Override - public void setCancelled(boolean cancelled) { - this.cancelled.set(cancelled); - } -} diff --git a/common/api/src/main/java/com/dfsek/terra/api/event/events/Cancellable.java b/common/api/src/main/java/com/dfsek/terra/api/event/events/Cancellable.java deleted file mode 100644 index 4a832b817..000000000 --- a/common/api/src/main/java/com/dfsek/terra/api/event/events/Cancellable.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2020-2021 Polyhedral Development - * - * The Terra API is licensed under the terms of the MIT License. For more details, - * reference the LICENSE file in the common/api directory. - */ - -package com.dfsek.terra.api.event.events; - -/** - * Events that implement this interface may be cancelled. - *

- * Cancelling an event is assumed to stop the execution of whatever action triggered the event. - */ -public interface Cancellable extends Event { - /** - * Get the cancellation status of the event. - * - * @return Whether event is cancelled. - */ - boolean isCancelled(); - - /** - * Set the cancellation status of the event. - * - * @param cancelled Whether event is cancelled. - */ - void setCancelled(boolean cancelled); -} diff --git a/common/api/src/main/java/com/dfsek/terra/api/event/events/Event.java b/common/api/src/main/java/com/dfsek/terra/api/event/events/Event.java index 3051c744f..e994898a4 100644 --- a/common/api/src/main/java/com/dfsek/terra/api/event/events/Event.java +++ b/common/api/src/main/java/com/dfsek/terra/api/event/events/Event.java @@ -7,8 +7,11 @@ package com.dfsek.terra.api.event.events; +import com.dfsek.terra.api.util.function.monad.Monad; + + /** * An event that addons may listen to. */ -public interface Event { +public interface Event extends Monad> { } diff --git a/common/api/src/main/java/com/dfsek/terra/api/event/events/FailThroughEvent.java b/common/api/src/main/java/com/dfsek/terra/api/event/events/FailThroughEvent.java deleted file mode 100644 index 0c1f35382..000000000 --- a/common/api/src/main/java/com/dfsek/terra/api/event/events/FailThroughEvent.java +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2020-2021 Polyhedral Development - * - * The Terra API is licensed under the terms of the MIT License. For more details, - * reference the LICENSE file in the common/api directory. - */ - -package com.dfsek.terra.api.event.events; - -/** - * An event which (optionally) passes exceptions thrown by listeners to - * the event caller. - */ -public interface FailThroughEvent extends Event { -} diff --git a/common/api/src/main/java/com/dfsek/terra/api/event/events/platform/CommandRegistrationEvent.java b/common/api/src/main/java/com/dfsek/terra/api/event/events/platform/CommandRegistrationEvent.java deleted file mode 100644 index 40d113079..000000000 --- a/common/api/src/main/java/com/dfsek/terra/api/event/events/platform/CommandRegistrationEvent.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.dfsek.terra.api.event.events.platform; - -import cloud.commandframework.CommandManager; - -import com.dfsek.terra.api.command.CommandSender; -import com.dfsek.terra.api.event.events.Event; - - -public class CommandRegistrationEvent implements Event { - private final CommandManager commandManager; - - public CommandRegistrationEvent(CommandManager commandManager) { - this.commandManager = commandManager; - } - - public CommandManager getCommandManager() { - return commandManager; - } -} diff --git a/common/api/src/main/java/com/dfsek/terra/api/event/events/platform/PlatformInitializationEvent.java b/common/api/src/main/java/com/dfsek/terra/api/event/events/platform/PlatformInitializationEvent.java deleted file mode 100644 index d94ee750c..000000000 --- a/common/api/src/main/java/com/dfsek/terra/api/event/events/platform/PlatformInitializationEvent.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright (c) 2020-2021 Polyhedral Development - * - * The Terra API is licensed under the terms of the MIT License. For more details, - * reference the LICENSE file in the common/api directory. - */ - -package com.dfsek.terra.api.event.events.platform; - -import com.dfsek.terra.api.event.events.Event; - - -/** - * Called when the platform is initialized. - */ -public class PlatformInitializationEvent implements Event { -} diff --git a/common/implementation/base/src/main/java/com/dfsek/terra/event/EventContextImpl.java b/common/implementation/base/src/main/java/com/dfsek/terra/event/EventContextImpl.java index 891102e2b..9ad51c4cb 100644 --- a/common/implementation/base/src/main/java/com/dfsek/terra/event/EventContextImpl.java +++ b/common/implementation/base/src/main/java/com/dfsek/terra/event/EventContextImpl.java @@ -26,7 +26,6 @@ import java.util.function.Consumer; import com.dfsek.terra.api.addon.BaseAddon; import com.dfsek.terra.api.event.events.Event; -import com.dfsek.terra.api.event.events.FailThroughEvent; import com.dfsek.terra.api.event.functional.EventContext; import com.dfsek.terra.api.util.reflection.ReflectionUtil; diff --git a/common/implementation/base/src/main/java/com/dfsek/terra/event/FunctionalEventHandlerImpl.java b/common/implementation/base/src/main/java/com/dfsek/terra/event/FunctionalEventHandlerImpl.java index 91941b9af..18d5bbe46 100644 --- a/common/implementation/base/src/main/java/com/dfsek/terra/event/FunctionalEventHandlerImpl.java +++ b/common/implementation/base/src/main/java/com/dfsek/terra/event/FunctionalEventHandlerImpl.java @@ -30,7 +30,6 @@ import java.util.Map; import com.dfsek.terra.api.addon.BaseAddon; import com.dfsek.terra.api.event.events.Event; -import com.dfsek.terra.api.event.events.FailThroughEvent; import com.dfsek.terra.api.event.functional.EventContext; import com.dfsek.terra.api.event.functional.FunctionalEventHandler; import com.dfsek.terra.api.util.reflection.TypeKey;