mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fixed building and switched event library
This commit is contained in:
parent
ab6e0d1e16
commit
13046a8602
25 changed files with 193 additions and 622 deletions
|
@ -1,5 +1,4 @@
|
|||
dependencies {
|
||||
api("org.geysermc.cumulus", "cumulus", Versions.cumulusVersion)
|
||||
api("org.geysermc.event", "events", Versions.eventsVersion)
|
||||
}
|
||||
|
||||
provided("net.kyori", "event-api", Versions.eventVersion)
|
||||
|
|
|
@ -55,12 +55,6 @@ public interface GeyserApi extends GeyserApiBase {
|
|||
@Override
|
||||
@Nullable GeyserConnection connectionByXuid(@NonNull String xuid);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@Nullable GeyserConnection connectionByUsername(@NonNull String username);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -26,71 +26,18 @@
|
|||
package org.geysermc.geyser.api.event;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.event.Event;
|
||||
import org.geysermc.event.bus.OwnedEventBus;
|
||||
import org.geysermc.geyser.api.extension.Extension;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Represents a bus capable of subscribing
|
||||
* or "listening" to events and firing them.
|
||||
*/
|
||||
public interface EventBus {
|
||||
|
||||
/**
|
||||
* Subscribes to the given event see {@link EventSubscription}.
|
||||
*
|
||||
* The difference between this method and {@link ExtensionEventBus#subscribe(Class, Consumer)}
|
||||
* is that this method takes in an extension parameter which allows for
|
||||
* the event to be unsubscribed upon extension disable and reloads.
|
||||
*
|
||||
* @param extension the extension to subscribe the event to
|
||||
* @param eventClass the class of the event
|
||||
* @param consumer the consumer for handling the event
|
||||
* @param <T> the event class
|
||||
* @return the event subscription
|
||||
*/
|
||||
public interface EventBus extends OwnedEventBus<Extension, Event, EventSubscriber<? extends Event>> {
|
||||
@Override
|
||||
@NonNull
|
||||
<T extends Event> EventSubscription<T> subscribe(@NonNull Extension extension, @NonNull Class<T> eventClass, @NonNull Consumer<? super T> consumer);
|
||||
|
||||
/**
|
||||
* Unsubscribes the given {@link EventSubscription}.
|
||||
*
|
||||
* @param subscription the event subscription
|
||||
*/
|
||||
<T extends Event> void unsubscribe(@NonNull EventSubscription<T> subscription);
|
||||
|
||||
/**
|
||||
* Registers events for the given listener.
|
||||
*
|
||||
* @param extension the extension registering the event
|
||||
* @param eventHolder the listener
|
||||
*/
|
||||
void register(@NonNull Extension extension, @NonNull Object eventHolder);
|
||||
|
||||
/**
|
||||
* Unregisters all events from a given {@link Extension}.
|
||||
*
|
||||
* @param extension the extension
|
||||
*/
|
||||
void unregisterAll(@NonNull Extension extension);
|
||||
|
||||
/**
|
||||
* Fires the given {@link Event} and returns the result.
|
||||
*
|
||||
* @param event the event to fire
|
||||
*
|
||||
* @return true if the event successfully fired
|
||||
*/
|
||||
boolean fire(@NonNull Event event);
|
||||
|
||||
/**
|
||||
* Gets the subscriptions for the given event class.
|
||||
*
|
||||
* @param eventClass the event class
|
||||
* @param <T> the value
|
||||
* @return the subscriptions for the event class
|
||||
*/
|
||||
@NonNull
|
||||
<T extends Event> Set<EventSubscription<T>> subscriptions(@NonNull Class<T> eventClass);
|
||||
<T extends Event> Set<? extends EventSubscriber<T>> subscribers(@NonNull Class<T> eventClass);
|
||||
}
|
||||
|
|
|
@ -25,22 +25,16 @@
|
|||
|
||||
package org.geysermc.geyser.api.event;
|
||||
|
||||
import org.geysermc.event.Event;
|
||||
import org.geysermc.event.subscribe.OwnedSubscriber;
|
||||
import org.geysermc.geyser.api.extension.Extension;
|
||||
|
||||
/**
|
||||
* Represents a cancellable event.
|
||||
* Represents a subscribed listener to a {@link Event}. Wraps around
|
||||
* the event and is capable of unsubscribing from the event or give
|
||||
* information about it.
|
||||
*
|
||||
* @param <T> the class of the event
|
||||
*/
|
||||
public interface Cancellable {
|
||||
|
||||
/**
|
||||
* Gets if the event is cancelled.
|
||||
*
|
||||
* @return if the event is cancelled
|
||||
*/
|
||||
boolean isCancelled();
|
||||
|
||||
/**
|
||||
* Cancels the event.
|
||||
*
|
||||
* @param cancelled if the event is cancelled
|
||||
*/
|
||||
void setCancelled(boolean cancelled);
|
||||
public interface EventSubscriber<T extends Event> extends OwnedSubscriber<Extension, T> {
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
package org.geysermc.geyser.api.event;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.geyser.api.extension.Extension;
|
||||
|
||||
/**
|
||||
* Represents a subscribed listener to a {@link Event}. Wraps around
|
||||
* the event and is capable of unsubscribing from the event or give
|
||||
* information about it.
|
||||
*
|
||||
* @param <T> the class of the event
|
||||
*/
|
||||
public interface EventSubscription<T extends Event> {
|
||||
|
||||
/**
|
||||
* Gets the event class.
|
||||
*
|
||||
* @return the event class
|
||||
*/
|
||||
@NonNull
|
||||
Class<T> eventClass();
|
||||
|
||||
/**
|
||||
* Gets the {@link Extension} that owns this
|
||||
* event subscription.
|
||||
*
|
||||
* @return the extension that owns this subscription
|
||||
*/
|
||||
@NonNull
|
||||
Extension owner();
|
||||
|
||||
/**
|
||||
* Gets the post order of this event subscription.
|
||||
*
|
||||
* @return the post order of this event subscription
|
||||
*/
|
||||
Subscribe.PostOrder order();
|
||||
|
||||
/**
|
||||
* Gets if this event subscription is active.
|
||||
*
|
||||
* @return if this event subscription is active
|
||||
*/
|
||||
boolean isActive();
|
||||
|
||||
/**
|
||||
* Unsubscribes from this event listener
|
||||
*/
|
||||
void unsubscribe();
|
||||
|
||||
/**
|
||||
* Invokes the given event
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
void invoke(@NonNull T event) throws Throwable;
|
||||
}
|
|
@ -26,36 +26,15 @@
|
|||
package org.geysermc.geyser.api.event;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.event.Event;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* An {@link EventBus} with additional methods that implicitly
|
||||
* set the extension instance.
|
||||
*
|
||||
*/
|
||||
public interface ExtensionEventBus extends EventBus {
|
||||
|
||||
/**
|
||||
* Subscribes to the given event see {@link EventSubscription}.
|
||||
*
|
||||
* @param eventClass the class of the event
|
||||
* @param consumer the consumer for handling the event
|
||||
* @param <T> the event class
|
||||
* @return the event subscription
|
||||
*/
|
||||
@NonNull
|
||||
<T extends Event> EventSubscription<T> subscribe(@NonNull Class<T> eventClass, @NonNull Consumer<? super T> consumer);
|
||||
|
||||
/**
|
||||
* Registers events for the given listener.
|
||||
*
|
||||
* @param eventHolder the listener
|
||||
*/
|
||||
void register(@NonNull Object eventHolder);
|
||||
|
||||
/**
|
||||
* Unregisters all events for this extension.
|
||||
*/
|
||||
void unregisterAll();
|
||||
public interface ExtensionEventBus extends org.geysermc.event.bus.EventBus<Event, EventSubscriber<? extends Event>> {
|
||||
@Override
|
||||
@NonNull <T extends Event> Set<? extends EventSubscriber<T>> subscribers(@NonNull Class<T> eventClass);
|
||||
}
|
||||
|
|
|
@ -25,17 +25,8 @@
|
|||
|
||||
package org.geysermc.geyser.api.event;
|
||||
|
||||
/**
|
||||
* Represents an event.
|
||||
*/
|
||||
public interface Event {
|
||||
import org.geysermc.event.Event;
|
||||
import org.geysermc.event.subscribe.Subscriber;
|
||||
|
||||
/**
|
||||
* Gets if the event is async.
|
||||
*
|
||||
* @return if the event is async
|
||||
*/
|
||||
default boolean isAsync() {
|
||||
return false;
|
||||
}
|
||||
public interface ExtensionEventSubscriber<T extends Event> extends Subscriber<T> {
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
package org.geysermc.geyser.api.event;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* An annotation used to signify the given method is
|
||||
* an {@link Event}. Only should be applied to methods
|
||||
* where the class containing them is designated for
|
||||
* events specifically.
|
||||
*
|
||||
* When using {@link EventBus#subscribe}, this annotation should
|
||||
* not be applied whatsoever as it will have no use and potentially
|
||||
* throw errors due to it being used wrongly.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface Subscribe {
|
||||
|
||||
/**
|
||||
* The {@link PostOrder} of the event
|
||||
*
|
||||
* @return the post order of the event
|
||||
*/
|
||||
Subscribe.PostOrder postOrder() default PostOrder.NORMAL;
|
||||
|
||||
/**
|
||||
* Represents the post order of an event.
|
||||
*/
|
||||
enum PostOrder {
|
||||
|
||||
/**
|
||||
* The lowest priority. Called first to
|
||||
* allow for other events to customize
|
||||
* the outcome
|
||||
*/
|
||||
FIRST(net.kyori.event.PostOrders.FIRST),
|
||||
|
||||
/**
|
||||
* The second lowest priority.
|
||||
*/
|
||||
EARLY(net.kyori.event.PostOrders.EARLY),
|
||||
|
||||
/**
|
||||
* Normal priority. Event is neither
|
||||
* important nor unimportant
|
||||
*/
|
||||
NORMAL(net.kyori.event.PostOrders.NORMAL),
|
||||
|
||||
/**
|
||||
* The second highest priority
|
||||
*/
|
||||
LATE(net.kyori.event.PostOrders.LATE),
|
||||
|
||||
/**
|
||||
* The highest of importance! Event is called
|
||||
* last and has the final say in the outcome
|
||||
*/
|
||||
LAST(net.kyori.event.PostOrders.LAST);
|
||||
|
||||
private final int postOrder;
|
||||
|
||||
PostOrder(int postOrder) {
|
||||
this.postOrder = postOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* The numerical post order value.
|
||||
*
|
||||
* @return numerical post order value
|
||||
*/
|
||||
public int postOrder() {
|
||||
return this.postOrder;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,8 +26,8 @@
|
|||
package org.geysermc.geyser.api.event.connection;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.event.Event;
|
||||
import org.geysermc.geyser.api.connection.GeyserConnection;
|
||||
import org.geysermc.geyser.api.event.Event;
|
||||
|
||||
/**
|
||||
* An event that contains a {@link GeyserConnection}.
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
package org.geysermc.geyser.api.event.downstream;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.event.Cancellable;
|
||||
import org.geysermc.geyser.api.connection.GeyserConnection;
|
||||
import org.geysermc.geyser.api.event.Cancellable;
|
||||
import org.geysermc.geyser.api.event.connection.ConnectionEvent;
|
||||
|
||||
import java.util.Set;
|
||||
|
|
|
@ -25,45 +25,34 @@
|
|||
|
||||
package org.geysermc.geyser.api.event.lifecycle;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.geyser.api.event.Event;
|
||||
import org.geysermc.event.Event;
|
||||
import org.geysermc.geyser.api.item.custom.CustomItemData;
|
||||
import org.geysermc.geyser.api.item.custom.NonVanillaCustomItemData;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Called on Geyser's startup when looking for custom items. Custom items must be registered through this event.
|
||||
*
|
||||
* This event will not be called if the "add non-Bedrock items" setting is disabled in the Geyser config.
|
||||
*/
|
||||
public abstract class GeyserDefineCustomItemsEvent implements Event {
|
||||
private final Multimap<String, CustomItemData> customItems;
|
||||
private final List<NonVanillaCustomItemData> nonVanillaCustomItems;
|
||||
|
||||
public GeyserDefineCustomItemsEvent(Multimap<String, CustomItemData> customItems, List<NonVanillaCustomItemData> nonVanillaCustomItems) {
|
||||
this.customItems = customItems;
|
||||
this.nonVanillaCustomItems = nonVanillaCustomItems;
|
||||
}
|
||||
|
||||
public interface GeyserDefineCustomItemsEvent extends Event {
|
||||
/**
|
||||
* Gets a multimap of all the already registered custom items indexed by the item's extended java item's identifier.
|
||||
*
|
||||
* @return a multimap of all the already registered custom items
|
||||
*/
|
||||
public Map<String, Collection<CustomItemData>> getExistingCustomItems() {
|
||||
return Collections.unmodifiableMap(this.customItems.asMap());
|
||||
}
|
||||
Map<String, Collection<CustomItemData>> getExistingCustomItems();
|
||||
|
||||
/**
|
||||
* Gets the list of the already registered non-vanilla custom items.
|
||||
*
|
||||
* @return the list of the already registered non-vanilla custom items
|
||||
*/
|
||||
public List<NonVanillaCustomItemData> getExistingNonVanillaCustomItems() {
|
||||
return Collections.unmodifiableList(this.nonVanillaCustomItems);
|
||||
}
|
||||
List<NonVanillaCustomItemData> getExistingNonVanillaCustomItems();
|
||||
|
||||
/**
|
||||
* Registers a custom item with a base Java item. This is used to register items with custom textures and properties
|
||||
|
@ -73,7 +62,7 @@ public abstract class GeyserDefineCustomItemsEvent implements Event {
|
|||
* @param customItemData the custom item data to register
|
||||
* @return if the item was registered
|
||||
*/
|
||||
public abstract boolean register(@NonNull String identifier, @NonNull CustomItemData customItemData);
|
||||
boolean register(@NonNull String identifier, @NonNull CustomItemData customItemData);
|
||||
|
||||
/**
|
||||
* Registers a custom item with no base item. This is used for mods.
|
||||
|
@ -81,5 +70,5 @@ public abstract class GeyserDefineCustomItemsEvent implements Event {
|
|||
* @param customItemData the custom item data to register
|
||||
* @return if the item was registered
|
||||
*/
|
||||
public abstract boolean register(@NonNull NonVanillaCustomItemData customItemData);
|
||||
boolean register(@NonNull NonVanillaCustomItemData customItemData);
|
||||
}
|
|
@ -26,7 +26,7 @@
|
|||
package org.geysermc.geyser.api.event.lifecycle;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.geyser.api.event.Event;
|
||||
import org.geysermc.event.Event;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
package org.geysermc.geyser.api.event.lifecycle;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.geyser.api.event.Event;
|
||||
import org.geysermc.event.Event;
|
||||
import org.geysermc.geyser.api.event.EventBus;
|
||||
import org.geysermc.geyser.api.extension.ExtensionManager;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
package org.geysermc.geyser.api.event.lifecycle;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.geyser.api.event.Event;
|
||||
import org.geysermc.event.Event;
|
||||
import org.geysermc.geyser.api.event.EventBus;
|
||||
import org.geysermc.geyser.api.extension.ExtensionManager;
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
package org.geysermc.geyser.api.event.lifecycle;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.event.Event;
|
||||
import org.geysermc.geyser.api.command.CommandManager;
|
||||
import org.geysermc.geyser.api.event.Event;
|
||||
import org.geysermc.geyser.api.event.EventBus;
|
||||
import org.geysermc.geyser.api.extension.ExtensionManager;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue