2022-01-15 22:27:35 +00:00
|
|
|
/*
|
|
|
|
* 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.extension;
|
|
|
|
|
2022-09-04 21:11:08 +00:00
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
2022-01-15 22:27:35 +00:00
|
|
|
import org.geysermc.api.GeyserApiBase;
|
|
|
|
import org.geysermc.geyser.api.GeyserApi;
|
2022-09-04 21:11:08 +00:00
|
|
|
import org.geysermc.geyser.api.event.EventRegistrar;
|
2022-01-16 21:09:53 +00:00
|
|
|
import org.geysermc.geyser.api.event.ExtensionEventBus;
|
2022-01-15 22:27:35 +00:00
|
|
|
|
|
|
|
import java.nio.file.Path;
|
2022-09-04 21:11:08 +00:00
|
|
|
import java.util.Objects;
|
2022-01-15 22:27:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents an extension within Geyser.
|
|
|
|
*/
|
2022-09-04 21:11:08 +00:00
|
|
|
public interface Extension extends EventRegistrar {
|
2022-01-15 22:27:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets if the extension is enabled
|
|
|
|
*
|
|
|
|
* @return true if the extension is enabled
|
|
|
|
*/
|
|
|
|
default boolean isEnabled() {
|
|
|
|
return this.extensionLoader().isEnabled(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables or disables the extension
|
|
|
|
*
|
|
|
|
* @param enabled if the extension should be enabled
|
|
|
|
*/
|
|
|
|
default void setEnabled(boolean enabled) {
|
|
|
|
this.extensionLoader().setEnabled(this, enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the extension's data folder
|
|
|
|
*
|
|
|
|
* @return the extension's data folder
|
|
|
|
*/
|
2022-09-04 21:11:08 +00:00
|
|
|
@NonNull
|
2022-01-15 22:27:35 +00:00
|
|
|
default Path dataFolder() {
|
|
|
|
return this.extensionLoader().dataFolder(this);
|
|
|
|
}
|
|
|
|
|
2022-01-16 21:09:53 +00:00
|
|
|
/**
|
|
|
|
* Gets the {@link ExtensionEventBus}.
|
|
|
|
*
|
|
|
|
* @return the extension event bus
|
|
|
|
*/
|
2022-09-04 21:11:08 +00:00
|
|
|
@NonNull
|
2022-01-16 21:09:53 +00:00
|
|
|
default ExtensionEventBus eventBus() {
|
|
|
|
return this.extensionLoader().eventBus(this);
|
|
|
|
}
|
|
|
|
|
2022-01-15 22:27:35 +00:00
|
|
|
/**
|
|
|
|
* Gets the {@link ExtensionManager}.
|
|
|
|
*
|
|
|
|
* @return the extension manager
|
|
|
|
*/
|
2022-09-04 21:11:08 +00:00
|
|
|
@NonNull
|
2022-01-15 22:27:35 +00:00
|
|
|
default ExtensionManager extensionManager() {
|
|
|
|
return this.geyserApi().extensionManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the extension's name
|
|
|
|
*
|
|
|
|
* @return the extension's name
|
|
|
|
*/
|
2022-09-04 21:11:08 +00:00
|
|
|
@NonNull
|
2022-01-15 22:27:35 +00:00
|
|
|
default String name() {
|
|
|
|
return this.description().name();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets this extension's {@link ExtensionDescription}.
|
|
|
|
*
|
|
|
|
* @return the extension's description
|
|
|
|
*/
|
2022-09-04 21:11:08 +00:00
|
|
|
@NonNull
|
2022-01-15 22:27:35 +00:00
|
|
|
default ExtensionDescription description() {
|
|
|
|
return this.extensionLoader().description(this);
|
|
|
|
}
|
|
|
|
|
2024-07-12 04:56:42 +00:00
|
|
|
/**
|
|
|
|
* @return the root command that all of this extension's commands will stem from.
|
|
|
|
* By default, this is the extension's id.
|
|
|
|
*/
|
|
|
|
@NonNull
|
|
|
|
default String rootCommand() {
|
|
|
|
return this.description().id();
|
|
|
|
}
|
|
|
|
|
2022-01-15 22:27:35 +00:00
|
|
|
/**
|
|
|
|
* Gets the extension's logger
|
|
|
|
*
|
|
|
|
* @return the extension's logger
|
|
|
|
*/
|
2022-09-04 21:11:08 +00:00
|
|
|
@NonNull
|
2022-01-15 22:27:35 +00:00
|
|
|
default ExtensionLogger logger() {
|
|
|
|
return this.extensionLoader().logger(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the {@link ExtensionLoader}.
|
|
|
|
*
|
|
|
|
* @return the extension loader
|
|
|
|
*/
|
2022-09-04 21:11:08 +00:00
|
|
|
@NonNull
|
2022-01-15 22:27:35 +00:00
|
|
|
default ExtensionLoader extensionLoader() {
|
2022-09-14 18:19:56 +00:00
|
|
|
return Objects.requireNonNull(this.extensionManager().extensionLoader());
|
2022-01-15 22:27:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the {@link GeyserApiBase} instance
|
|
|
|
*
|
|
|
|
* @return the geyser api instance
|
|
|
|
*/
|
2022-09-04 21:11:08 +00:00
|
|
|
@NonNull
|
2022-01-15 22:27:35 +00:00
|
|
|
default GeyserApi geyserApi() {
|
|
|
|
return GeyserApi.api();
|
|
|
|
}
|
2023-05-25 16:03:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable the extension.
|
|
|
|
*/
|
|
|
|
default void disable() {
|
|
|
|
this.setEnabled(false);
|
|
|
|
this.eventBus().unregisterAll();
|
|
|
|
}
|
2022-01-15 22:27:35 +00:00
|
|
|
}
|