1
0
mirror of https://github.com/GeyserMC/Geyser.git synced 2026-01-04 15:31:36 +00:00

Moved the base api to a separate repo

This commit is contained in:
Tim203
2023-02-09 17:31:00 +01:00
parent 25c2d30881
commit 21885949c7
47 changed files with 19 additions and 565 deletions

View File

@@ -0,0 +1,119 @@
/*
* 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;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.api.Geyser;
import org.geysermc.api.GeyserApiBase;
import org.geysermc.geyser.api.connection.GeyserConnection;
import org.geysermc.geyser.api.event.EventBus;
import org.geysermc.geyser.api.event.EventRegistrar;
import org.geysermc.geyser.api.extension.ExtensionManager;
import org.geysermc.geyser.api.network.BedrockListener;
import org.geysermc.geyser.api.network.RemoteServer;
import java.util.List;
import java.util.UUID;
/**
* Represents the API used in Geyser.
*/
public interface GeyserApi extends GeyserApiBase {
/**
* {@inheritDoc}
*/
@Override
@Nullable GeyserConnection connectionByUuid(@NonNull UUID uuid);
/**
* {@inheritDoc}
*/
@Override
@Nullable GeyserConnection connectionByXuid(@NonNull String xuid);
/**
* {@inheritDoc}
*/
@NonNull
List<? extends GeyserConnection> onlineConnections();
/**
* Gets the {@link ExtensionManager}.
*
* @return the extension manager
*/
@NonNull
ExtensionManager extensionManager();
/**
* Provides an implementation for the specified API type.
*
* @param apiClass the builder class
* @param <R> the implementation type
* @param <T> the API type
* @return the builder instance
*/
@NonNull
<R extends T, T> R provider(@NonNull Class<T> apiClass, @Nullable Object... args);
/**
* Gets the {@link EventBus} for handling
* Geyser events.
*
* @return the event bus
*/
@NonNull
EventBus<EventRegistrar> eventBus();
/**
* Gets the default {@link RemoteServer} configured
* within the config file that is used by default.
*
* @return the default remote server used within Geyser
*/
@NonNull
RemoteServer defaultRemoteServer();
/**
* Gets the {@link BedrockListener} used for listening
* for Minecraft: Bedrock Edition client connections.
*
* @return the listener used for Bedrock client connectins
*/
@NonNull
BedrockListener bedrockListener();
/**
* Gets the current {@link GeyserApiBase} instance.
*
* @return the current geyser api instance
*/
@NonNull
static GeyserApi api() {
return Geyser.api(GeyserApi.class);
}
}

View File

@@ -0,0 +1,215 @@
/*
* 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.command;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.connection.GeyserConnection;
import org.geysermc.geyser.api.extension.Extension;
import java.util.Collections;
import java.util.List;
/**
* Represents a command.
*/
public interface Command {
/**
* Gets the command name.
*
* @return the command name
*/
@NonNull
String name();
/**
* Gets the command description.
*
* @return the command description
*/
@NonNull
String description();
/**
* Gets the permission node associated with
* this command.
*
* @return the permission node for this command
*/
@NonNull
String permission();
/**
* Gets the aliases for this command.
*
* @return the aliases for this command
*/
@NonNull
List<String> aliases();
/**
* Gets if this command is designed to be used only by server operators.
*
* @return if this command is designated to be used only by server operators.
*/
boolean isSuggestedOpOnly();
/**
* Gets if this command is executable on console.
*
* @return if this command is executable on console
*/
boolean isExecutableOnConsole();
/**
* Gets the subcommands associated with this
* command. Mainly used within the Geyser Standalone
* GUI to know what subcommands are supported.
*
* @return the subcommands associated with this command
*/
@NonNull
default List<String> subCommands() {
return Collections.emptyList();
}
/**
* Used to send a deny message to Java players if this command can only be used by Bedrock players.
*
* @return true if this command can only be used by Bedrock players.
*/
default boolean isBedrockOnly() {
return false;
}
/**
* Creates a new {@link Command.Builder} used to construct commands.
*
* @param extension the extension
* @param <T> the source type
* @return a new command builder used to construct commands
*/
static <T extends CommandSource> Command.Builder<T> builder(@NonNull Extension extension) {
return GeyserApi.api().provider(Builder.class, extension);
}
interface Builder<T extends CommandSource> {
/**
* Defines the source type to use for this command.
* <p>
* Command source types can be anything that extend
* {@link CommandSource}, such as {@link GeyserConnection}.
* This will guarantee that the source used in the executor
* is an instance of this source.
*
* @param sourceType the source type
* @return the builder
*/
Builder<T> source(@NonNull Class<? extends T> sourceType);
/**
* Sets the command name.
*
* @param name the command name
* @return the builder
*/
Builder<T> name(@NonNull String name);
/**
* Sets the command description.
*
* @param description the command description
* @return the builder
*/
Builder<T> description(@NonNull String description);
/**
* Sets the permission node.
*
* @param permission the permission node
* @return the builder
*/
Builder<T> permission(@NonNull String permission);
/**
* Sets the aliases.
*
* @param aliases the aliases
* @return the builder
*/
Builder<T> aliases(@NonNull List<String> aliases);
/**
* Sets if this command is designed to be used only by server operators.
*
* @param suggestedOpOnly if this command is designed to be used only by server operators
* @return the builder
*/
Builder<T> suggestedOpOnly(boolean suggestedOpOnly);
/**
* Sets if this command is executable on console.
*
* @param executableOnConsole if this command is executable on console
* @return the builder
*/
Builder<T> executableOnConsole(boolean executableOnConsole);
/**
* Sets the subcommands.
*
* @param subCommands the subcommands
* @return the builder
*/
Builder<T> subCommands(@NonNull List<String> subCommands);
/**
* Sets if this command is bedrock only.
*
* @param bedrockOnly if this command is bedrock only
* @return the builder
*/
Builder<T> bedrockOnly(boolean bedrockOnly);
/**
* Sets the {@link CommandExecutor} for this command.
*
* @param executor the command executor
* @return the builder
*/
Builder<T> executor(@NonNull CommandExecutor<T> executor);
/**
* Builds the command.
*
* @return the command
*/
@NonNull
Command build();
}
}

View File

@@ -0,0 +1,45 @@
/*
* 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.command;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Handles executing a command.
*
* @param <T> the command source
*/
public interface CommandExecutor<T extends CommandSource> {
/**
* Executes the given {@link Command} with the given
* {@link CommandSource}.
*
* @param source the command source
* @param command the command
* @param args the arguments
*/
void execute(@NonNull T source, @NonNull Command command, @NonNull String[] args);
}

View File

@@ -0,0 +1,81 @@
/*
* 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.command;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Represents an instance capable of sending commands.
*/
public interface CommandSource {
/**
* The name of the command source.
*
* @return the name of the command source
*/
String name();
/**
* Sends the given message to the command source
*
* @param message the message to send
*/
void sendMessage(@NonNull String message);
/**
* Sends the given messages to the command source
*
* @param messages the messages to send
*/
default void sendMessage(String[] messages) {
for (String message : messages) {
sendMessage(message);
}
}
/**
* If this source is the console.
*
* @return true if this source is the console
*/
boolean isConsole();
/**
* Returns the locale of the command source.
*
* @return the locale of the command source.
*/
String locale();
/**
* Checks if this command source has the given permission
*
* @param permission The permission node to check
* @return true if this command source has a permission
*/
boolean hasPermission(String permission);
}

View File

@@ -0,0 +1,35 @@
/*
* 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.connection;
import org.geysermc.api.connection.Connection;
import org.geysermc.geyser.api.command.CommandSource;
/**
* Represents a player connection used in Geyser.
*/
public interface GeyserConnection extends Connection, CommandSource {
}

View File

@@ -0,0 +1,43 @@
/*
* 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.event.Event;
import org.geysermc.event.bus.OwnedEventBus;
import org.geysermc.geyser.api.extension.Extension;
import java.util.Set;
/**
* Represents a bus capable of subscribing
* or "listening" to events and firing them.
*/
public interface EventBus<R extends EventRegistrar> extends OwnedEventBus<R, Event, EventSubscriber<R, ? extends Event>> {
@Override
@NonNull
<T extends Event> Set<? extends EventSubscriber<R, T>> subscribers(@NonNull Class<T> eventClass);
}

View File

@@ -0,0 +1,47 @@
/*
* 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.GeyserApi;
/**
* Represents an owner for an event that allows it
* to be registered through an {@link EventBus}.
*/
public interface EventRegistrar {
/**
* Creates an {@link EventRegistrar} instance.
*
* @param object the object to wrap around
* @return an event registrar instance
*/
@NonNull
static EventRegistrar of(@NonNull Object object) {
return GeyserApi.api().provider(EventRegistrar.class, object);
}
}

View File

@@ -0,0 +1,40 @@
/*
* 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.geysermc.event.Event;
import org.geysermc.event.subscribe.OwnedSubscriber;
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 EventSubscriber<R extends EventRegistrar, T extends Event> extends OwnedSubscriber<R, T> {
}

View File

@@ -0,0 +1,41 @@
/*
* 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.event.Event;
import org.geysermc.geyser.api.extension.Extension;
import java.util.Set;
/**
* An {@link EventBus} with additional methods that implicitly
* set the extension instance.
*/
public interface ExtensionEventBus extends org.geysermc.event.bus.EventBus<Event, EventSubscriber<Extension, ? extends Event>> {
@Override
@NonNull <T extends Event> Set<? extends EventSubscriber<EventRegistrar, T>> subscribers(@NonNull Class<T> eventClass);
}

View File

@@ -0,0 +1,32 @@
/*
* 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.geysermc.event.Event;
import org.geysermc.event.subscribe.Subscriber;
public interface ExtensionEventSubscriber<T extends Event> extends Subscriber<T> {
}

View File

@@ -0,0 +1,51 @@
/*
* 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.connection;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.Event;
import org.geysermc.geyser.api.connection.GeyserConnection;
/**
* An event that contains a {@link GeyserConnection}.
*/
public abstract class ConnectionEvent implements Event {
private final GeyserConnection connection;
public ConnectionEvent(@NonNull GeyserConnection connection) {
this.connection = connection;
}
/**
* Gets the {@link GeyserConnection}.
*
* @return the connection
*/
@NonNull
public GeyserConnection connection() {
return this.connection;
}
}

View File

@@ -0,0 +1,85 @@
/*
* 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.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.connection.ConnectionEvent;
import java.util.Set;
/**
* Called when the Java server defines the commands available on the server.
* <br>
* This event is mapped to the existence of Brigadier on the server.
*/
public class ServerDefineCommandsEvent extends ConnectionEvent implements Cancellable {
private final Set<? extends CommandInfo> commands;
private boolean cancelled;
public ServerDefineCommandsEvent(@NonNull GeyserConnection connection, @NonNull Set<? extends CommandInfo> commands) {
super(connection);
this.commands = commands;
}
/**
* A collection of commands sent from the server. Any element in this collection can be removed, but no element can
* be added.
*
* @return a collection of the commands sent over
*/
@NonNull
public Set<? extends CommandInfo> commands() {
return this.commands;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
public interface CommandInfo {
/**
* Gets the name of the command.
*
* @return the name of the command
*/
String name();
/**
* Gets the description of the command.
*
* @return the description of the command
*/
String description();
}
}

View File

@@ -0,0 +1,57 @@
/*
* 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.lifecycle;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.Event;
import org.geysermc.geyser.api.command.Command;
import java.util.Map;
/**
* Called when commands are defined within Geyser.
*
* This event allows you to register new commands using the {@link #register(Command)}
* method and retrieve the default commands defined.
*/
public interface GeyserDefineCommandsEvent extends Event {
/**
* Registers the given {@link Command} into the Geyser
* command manager.
*
* @param command the command to register
*/
void register(@NonNull Command command);
/**
* Gets all the registered built-in {@link Command}s.
*
* @return all the registered built-in commands
*/
@NonNull
Map<String, Command> commands();
}

View File

@@ -0,0 +1,76 @@
/*
* 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.lifecycle;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.Event;
import org.geysermc.geyser.api.item.custom.CustomItemData;
import org.geysermc.geyser.api.item.custom.NonVanillaCustomItemData;
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 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
*/
@NonNull
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
*/
@NonNull
List<NonVanillaCustomItemData> getExistingNonVanillaCustomItems();
/**
* Registers a custom item with a base Java item. This is used to register items with custom textures and properties
* based on NBT data.
*
* @param identifier the base (java) item
* @param customItemData the custom item data to register
* @return if the item was registered
*/
boolean register(@NonNull String identifier, @NonNull CustomItemData customItemData);
/**
* Registers a custom item with no base item. This is used for mods.
*
* @param customItemData the custom item data to register
* @return if the item was registered
*/
boolean register(@NonNull NonVanillaCustomItemData customItemData);
}

View File

@@ -0,0 +1,40 @@
/*
* 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.lifecycle;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.Event;
import java.nio.file.Path;
import java.util.List;
/**
* Called when resource packs are loaded within Geyser.
*
* @param resourcePacks a mutable list of the currently listed resource packs
*/
public record GeyserLoadResourcePacksEvent(@NonNull List<Path> resourcePacks) implements Event {
}

View File

@@ -0,0 +1,41 @@
/*
* 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.lifecycle;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.Event;
import org.geysermc.geyser.api.event.EventBus;
import org.geysermc.geyser.api.event.EventRegistrar;
import org.geysermc.geyser.api.extension.ExtensionManager;
/**
* Called when Geyser has completed initializing.
*
* @param extensionManager the extension manager
* @param eventBus the event bus
*/
public record GeyserPostInitializeEvent(@NonNull ExtensionManager extensionManager, @NonNull EventBus<EventRegistrar> eventBus) implements Event {
}

View File

@@ -0,0 +1,41 @@
/*
* 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.lifecycle;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.Event;
import org.geysermc.geyser.api.event.EventBus;
import org.geysermc.geyser.api.event.EventRegistrar;
import org.geysermc.geyser.api.extension.ExtensionManager;
/**
* Called when Geyser is starting to initialize.
*
* @param extensionManager the extension manager
* @param eventBus the event bus
*/
public record GeyserPreInitializeEvent(@NonNull ExtensionManager extensionManager, @NonNull EventBus<EventRegistrar> eventBus) implements Event {
}

View File

@@ -0,0 +1,38 @@
/*
* 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.lifecycle;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.Event;
import org.geysermc.geyser.api.event.EventBus;
import org.geysermc.geyser.api.event.EventRegistrar;
import org.geysermc.geyser.api.extension.ExtensionManager;
/**
* Called when Geyser is shutting down.
*/
public record GeyserShutdownEvent(@NonNull ExtensionManager extensionManager, @NonNull EventBus<EventRegistrar> eventBus) implements Event {
}

View File

@@ -0,0 +1,139 @@
/*
* 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;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.api.GeyserApiBase;
import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.event.EventRegistrar;
import org.geysermc.geyser.api.event.ExtensionEventBus;
import java.nio.file.Path;
import java.util.Objects;
/**
* Represents an extension within Geyser.
*/
public interface Extension extends EventRegistrar {
/**
* 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
*/
@NonNull
default Path dataFolder() {
return this.extensionLoader().dataFolder(this);
}
/**
* Gets the {@link ExtensionEventBus}.
*
* @return the extension event bus
*/
@NonNull
default ExtensionEventBus eventBus() {
return this.extensionLoader().eventBus(this);
}
/**
* Gets the {@link ExtensionManager}.
*
* @return the extension manager
*/
@NonNull
default ExtensionManager extensionManager() {
return this.geyserApi().extensionManager();
}
/**
* Gets the extension's name
*
* @return the extension's name
*/
@NonNull
default String name() {
return this.description().name();
}
/**
* Gets this extension's {@link ExtensionDescription}.
*
* @return the extension's description
*/
@NonNull
default ExtensionDescription description() {
return this.extensionLoader().description(this);
}
/**
* Gets the extension's logger
*
* @return the extension's logger
*/
@NonNull
default ExtensionLogger logger() {
return this.extensionLoader().logger(this);
}
/**
* Gets the {@link ExtensionLoader}.
*
* @return the extension loader
*/
@NonNull
default ExtensionLoader extensionLoader() {
return Objects.requireNonNull(this.extensionManager().extensionLoader());
}
/**
* Gets the {@link GeyserApiBase} instance
*
* @return the geyser api instance
*/
@NonNull
default GeyserApi geyserApi() {
return GeyserApi.api();
}
}

View File

@@ -0,0 +1,106 @@
/*
* 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;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.List;
/**
* Represents the description of an {@link Extension}.
*/
public interface ExtensionDescription {
/**
* Gets the extension's id.
*
* @return the extension's id
*/
@NonNull
String id();
/**
* Gets the extension's name.
*
* @return the extension's name
*/
@NonNull
String name();
/**
* Gets the extension's main class.
*
* @return the extension's main class
*/
@NonNull
String main();
/**
* Gets the extension's major api version
*
* @return the extension's major api version
*/
int majorApiVersion();
/**
* Gets the extension's minor api version
*
* @return the extension's minor api version
*/
int minorApiVersion();
/**
* Gets the extension's patch api version
*
* @return the extension's patch api version
*/
int patchApiVersion();
/**
* Gets the extension's api version.
*
* @return the extension's api version
*/
default String apiVersion() {
return majorApiVersion() + "." + minorApiVersion() + "." + patchApiVersion();
}
/**
* Gets the extension's description.
*
* @return the extension's description
*/
@NonNull
String version();
/**
* Gets the extension's authors.
*
* @return the extension's authors
*/
@NonNull
List<String> authors();
}

View File

@@ -0,0 +1,105 @@
/*
* 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;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.event.ExtensionEventBus;
import java.nio.file.Path;
/**
* The extension loader is responsible for loading, unloading, enabling and disabling extensions
*/
public abstract class ExtensionLoader {
/**
* Gets if the given {@link Extension} is enabled.
*
* @param extension the extension
* @return if the extension is enabled
*/
protected abstract boolean isEnabled(@NonNull Extension extension);
/**
* Sets if the given {@link Extension} is enabled.
*
* @param extension the extension to enable
* @param enabled if the extension should be enabled
*/
protected abstract void setEnabled(@NonNull Extension extension, boolean enabled);
/**
* Gets the given {@link Extension}'s data folder.
*
* @param extension the extension
* @return the data folder of the given extension
*/
@NonNull
protected abstract Path dataFolder(@NonNull Extension extension);
/**
* Gets the given {@link Extension}'s {@link ExtensionDescription}.
*
* @param extension the extension
* @return the description of the given extension
*/
@NonNull
protected abstract ExtensionDescription description(@NonNull Extension extension);
/**
* Gets the given {@link Extension}'s {@link ExtensionEventBus}.
*
* @param extension the extension
* @return the extension's event bus
*/
@NonNull
protected abstract ExtensionEventBus eventBus(@NonNull Extension extension);
/**
* Gets the {@link ExtensionLogger} for the given {@link Extension}.
*
* @param extension the extension
* @return the extension logger for the given extension
*/
@NonNull
protected abstract ExtensionLogger logger(@NonNull Extension extension);
/**
* Loads all extensions.
*
* @param extensionManager the extension manager
*/
protected abstract void loadAllExtensions(@NonNull ExtensionManager extensionManager);
/**
* Registers the given {@link Extension} with the given {@link ExtensionManager}.
*
* @param extension the extension
* @param extensionManager the extension manager
*/
protected void register(@NonNull Extension extension, @NonNull ExtensionManager extensionManager) {
extensionManager.register(extension);
}
}

View File

@@ -0,0 +1,94 @@
/*
* 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;
/**
* This is the Geyser extension logger
*/
public interface ExtensionLogger {
/**
* Get the logger prefix
*
* @return the logger prefix
*/
String prefix();
/**
* Logs a severe message to console
*
* @param message the message to log
*/
void severe(String message);
/**
* Logs a severe message and an exception to console
*
* @param message the message to log
* @param error the error to throw
*/
void severe(String message, Throwable error);
/**
* Logs an error message to console
*
* @param message the message to log
*/
void error(String message);
/**
* Logs an error message and an exception to console
*
* @param message the message to log
* @param error the error to throw
*/
void error(String message, Throwable error);
/**
* Logs a warning message to console
*
* @param message the message to log
*/
void warning(String message);
/**
* Logs an info message to console
*
* @param message the message to log
*/
void info(String message);
/**
* Logs a debug message to console
*
* @param message the message to log
*/
void debug(String message);
/**
* If debug is enabled for this logger
*/
boolean isDebug();
}

View File

@@ -0,0 +1,90 @@
/*
* 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;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Collection;
/**
* Manages Geyser {@link Extension}s
*/
public abstract class ExtensionManager {
/**
* Gets an extension with the given name.
*
* @param name the name of the extension
* @return an extension with the given name
*/
@Nullable
public abstract Extension extension(@NonNull String name);
/**
* Enables the given {@link Extension}.
*
* @param extension the extension to enable
*/
public abstract void enable(@NonNull Extension extension);
/**
* Disables the given {@link Extension}.
*
* @param extension the extension to disable
*/
public abstract void disable(@NonNull Extension extension);
/**
* Gets all the {@link Extension}s currently loaded.
*
* @return all the extensions currently loaded
*/
@NonNull
public abstract Collection<Extension> extensions();
/**
* Gets the {@link ExtensionLoader}.
*
* @return the extension loader
*/
@Nullable
public abstract ExtensionLoader extensionLoader();
/**
* Registers an {@link Extension} with the given {@link ExtensionLoader}.
*
* @param extension the extension
*/
public abstract void register(@NonNull Extension extension);
/**
* Loads all extensions from the given {@link ExtensionLoader}.
*/
protected final void loadAllExtensions(@NonNull ExtensionLoader extensionLoader) {
extensionLoader.loadAllExtensions(this);
}
}

View File

@@ -0,0 +1,43 @@
/*
* 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.exception;
/**
* Thrown when an extension's description is invalid.
*/
public class InvalidDescriptionException extends Exception {
public InvalidDescriptionException(Throwable cause) {
super(cause);
}
public InvalidDescriptionException(String message) {
super(message);
}
public InvalidDescriptionException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -0,0 +1,43 @@
/*
* 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.exception;
/**
* Thrown when an extension is invalid.
*/
public class InvalidExtensionException extends Exception {
public InvalidExtensionException(Throwable cause) {
super(cause);
}
public InvalidExtensionException(String message) {
super(message);
}
public InvalidExtensionException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@@ -0,0 +1,109 @@
/*
* 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.item.custom;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.GeyserApi;
/**
* This is used to store data for a custom item.
*/
public interface CustomItemData {
/**
* Gets the item's name.
*
* @return the item's name
*/
@NonNull String name();
/**
* Gets the custom item options of the item.
*
* @return the custom item options of the item.
*/
CustomItemOptions customItemOptions();
/**
* Gets the item's display name. By default, this is the item's name.
*
* @return the item's display name
*/
@NonNull String displayName();
/**
* Gets the item's icon. By default, this is the item's name.
*
* @return the item's icon
*/
@NonNull String icon();
/**
* Gets if the item is allowed to be put into the offhand.
*
* @return true if the item is allowed to be used in the offhand, false otherwise
*/
boolean allowOffhand();
/**
* Gets the item's texture size. This is to resize the item if the texture is not 16x16.
*
* @return the item's texture size
*/
int textureSize();
/**
* Gets the item's render offsets. If it is null, the item will be rendered normally, with no offsets.
*
* @return the item's render offsets
*/
@Nullable CustomRenderOffsets renderOffsets();
static CustomItemData.Builder builder() {
return GeyserApi.api().provider(CustomItemData.Builder.class);
}
interface Builder {
/**
* Will also set the display name and icon to the provided parameter, if it is currently not set.
*/
Builder name(@NonNull String name);
Builder customItemOptions(@NonNull CustomItemOptions customItemOptions);
Builder displayName(@NonNull String displayName);
Builder icon(@NonNull String icon);
Builder allowOffhand(boolean allowOffhand);
Builder textureSize(int textureSize);
Builder renderOffsets(@Nullable CustomRenderOffsets renderOffsets);
CustomItemData build();
}
}

View File

@@ -0,0 +1,83 @@
/*
* 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.item.custom;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.api.GeyserApi;
import org.geysermc.geyser.api.util.TriState;
import java.util.OptionalInt;
/**
* This class represents the different ways you can register custom items
*/
public interface CustomItemOptions {
/**
* Gets if the item should be unbreakable.
*
* @return if the item should be unbreakable
*/
@NonNull TriState unbreakable();
/**
* Gets the item's custom model data predicate.
*
* @return the item's custom model data
*/
@NonNull OptionalInt customModelData();
/**
* Gets the item's damage predicate.
*
* @return the item's damage predicate
*/
@NonNull OptionalInt damagePredicate();
/**
* Checks if the item has at least one option set
*
* @return true if the item at least one options set
*/
default boolean hasCustomItemOptions() {
return this.unbreakable() != TriState.NOT_SET ||
this.customModelData().isPresent() ||
this.damagePredicate().isPresent();
}
static CustomItemOptions.Builder builder() {
return GeyserApi.api().provider(CustomItemOptions.Builder.class);
}
interface Builder {
Builder unbreakable(boolean unbreakable);
Builder customModelData(int customModelData);
Builder damagePredicate(int damagePredicate);
CustomItemOptions build();
}
}

View File

@@ -0,0 +1,51 @@
/*
* 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.item.custom;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* This class is used to store the render offsets of custom items.
*/
public record CustomRenderOffsets(@Nullable Hand mainHand, @Nullable Hand offhand) {
/**
* The hand that is used for the offset.
*/
public record Hand(@Nullable Offset firstPerson, @Nullable Offset thirdPerson) {
}
/**
* The offset of the item.
*/
public record Offset(@Nullable OffsetXYZ position, @Nullable OffsetXYZ rotation, @Nullable OffsetXYZ scale) {
}
/**
* X, Y and Z positions for the offset.
*/
public record OffsetXYZ(float x, float y, float z) {
}
}

View File

@@ -0,0 +1,188 @@
/*
* 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.item.custom;
import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.GeyserApi;
import java.util.OptionalInt;
import java.util.Set;
/**
* Represents a completely custom item that is not based on an existing vanilla Minecraft item.
*/
public interface NonVanillaCustomItemData extends CustomItemData {
/**
* Gets the java identifier for this item.
*
* @return The java identifier for this item.
*/
@NonNull String identifier();
/**
* Gets the java item id of the item.
*
* @return the java item id of the item
*/
@NonNegative int javaId();
/**
* Gets the stack size of the item.
*
* @return the stack size of the item
*/
@NonNegative int stackSize();
/**
* Gets the max damage of the item.
*
* @return the max damage of the item
*/
int maxDamage();
/**
* Gets the tool type of the item.
*
* @return the tool type of the item
*/
@Nullable String toolType();
/**
* Gets the tool tier of the item.
*
* @return the tool tier of the item
*/
@Nullable String toolTier();
/**
* Gets the armor type of the item.
*
* @return the armor type of the item
*/
@Nullable String armorType();
/**
* Gets the armor protection value of the item.
*
* @return the armor protection value of the item
*/
int protectionValue();
/**
* Gets the item's translation string.
*
* @return the item's translation string
*/
@Nullable String translationString();
/**
* Gets the repair materials of the item.
*
* @return the repair materials of the item
*/
@Nullable Set<String> repairMaterials();
/**
* Gets the item's creative category, or tab id.
*
* @return the item's creative category
*/
@NonNull OptionalInt creativeCategory();
/**
* Gets the item's creative group.
*
* @return the item's creative group
*/
@Nullable String creativeGroup();
/**
* Gets if the item is a hat. This is used to determine if the item should be rendered on the player's head, and
* normally allow the player to equip it. This is not meant for armor.
*
* @return if the item is a hat
*/
boolean isHat();
/**
* Gets if the item is a tool. This is used to set the render type of the item, if the item is handheld.
*
* @return if the item is a tool
*/
boolean isTool();
static NonVanillaCustomItemData.Builder builder() {
return GeyserApi.api().provider(NonVanillaCustomItemData.Builder.class);
}
interface Builder extends CustomItemData.Builder {
Builder name(@NonNull String name);
Builder identifier(@NonNull String identifier);
Builder javaId(@NonNegative int javaId);
Builder stackSize(@NonNegative int stackSize);
Builder maxDamage(int maxDamage);
Builder toolType(@Nullable String toolType);
Builder toolTier(@Nullable String toolTier);
Builder armorType(@Nullable String armorType);
Builder protectionValue(int protectionValue);
Builder translationString(@Nullable String translationString);
Builder repairMaterials(@Nullable Set<String> repairMaterials);
Builder creativeCategory(int creativeCategory);
Builder creativeGroup(@Nullable String creativeGroup);
Builder hat(boolean isHat);
Builder tool(boolean isTool);
@Override
Builder displayName(@NonNull String displayName);
@Override
Builder allowOffhand(boolean allowOffhand);
@Override
Builder textureSize(int textureSize);
@Override
Builder renderOffsets(@Nullable CustomRenderOffsets renderOffsets);
NonVanillaCustomItemData build();
}
}

View File

@@ -0,0 +1,61 @@
/*
* 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.network;
import java.util.Locale;
/**
* The authentication types that a Java server can be on connection.
*/
public enum AuthType {
OFFLINE,
ONLINE,
/**
* The internal name for connecting to an online mode server without needing a Java account. The presence of this
* authentication type does not necessarily mean the Floodgate plugin is installed; it only means that this
* authentication type will be attempted.
*/
FLOODGATE;
private static final AuthType[] VALUES = values();
/**
* Convert the AuthType string (from config) to the enum, ONLINE on fail
*
* @param name AuthType string
*
* @return The converted AuthType
*/
public static AuthType getByName(String name) {
String upperCase = name.toUpperCase(Locale.ROOT);
for (AuthType type : VALUES) {
if (type.name().equals(upperCase)) {
return type;
}
}
return ONLINE;
}
}

View File

@@ -0,0 +1,77 @@
/*
* 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.network;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* The listener that handles connections from Minecraft:
* Bedrock Edition.
*/
public interface BedrockListener {
/**
* Gets the address used for listening for Bedrock
* connections from.
*
* @return the listening address
*/
@NonNull
String address();
/**
* Gets the port used for listening for Bedrock
* connections from.
*
* @return the listening port
*/
int port();
/**
* Gets the primary MOTD shown to Bedrock players if a ping passthrough setting is not enabled.
* <p>
* This is the first line that will be displayed.
*
* @return the primary MOTD shown to Bedrock players.
*/
String primaryMotd();
/**
* Gets the secondary MOTD shown to Bedrock players if a ping passthrough setting is not enabled.
* <p>
* This is the second line that will be displayed.
*
* @return the secondary MOTD shown to Bedrock players.
*/
String secondaryMotd();
/**
* Gets the server name that is sent to Bedrock clients.
*
* @return the server sent to Bedrock clients
*/
String serverName();
}

View File

@@ -0,0 +1,70 @@
/*
* 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.network;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Represents the Java server that Geyser is connecting to.
*/
public interface RemoteServer {
/**
* Gets the IP address of the remote server.
*
* @return the IP address of the remote server
*/
String address();
/**
* Gets the port of the remote server.
*
* @return the port of the remote server
*/
int port();
/**
* Gets the protocol version of the remote server.
*
* @return the protocol version of the remote server
*/
int protocolVersion();
/**
* Gets the Minecraft version of the remote server.
*
* @return the Minecraft version of the remote server
*/
String minecraftVersion();
/**
* Gets the {@link AuthType} required by the remote server.
*
* @return the auth type required by the remote server
*/
@NonNull
AuthType authType();
}

View File

@@ -0,0 +1,83 @@
/*
* 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.util;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* This is a way to represent a boolean, but with a non set value added.
* This class was inspired by adventure's version https://github.com/KyoriPowered/adventure/blob/main/4/api/src/main/java/net/kyori/adventure/util/TriState.java
*/
public enum TriState {
/**
* Describes a value that is not set, null, or not present.
*/
NOT_SET,
/**
* Describes a true value.
*/
TRUE,
/**
* Describes a false value.
*/
FALSE;
/**
* Converts the TriState to a boolean.
*
* @return the boolean value of the TriState
*/
public @Nullable Boolean toBoolean() {
return switch (this) {
case TRUE -> true;
case FALSE -> false;
default -> null;
};
}
/**
* Creates a TriState from a boolean.
*
* @param value the Boolean value
* @return the created TriState
*/
public static @NonNull TriState fromBoolean(@Nullable Boolean value) {
return value == null ? NOT_SET : fromBoolean(value.booleanValue());
}
/**
* Creates a TriState from a primitive boolean.
*
* @param value the boolean value
* @return the created TriState
*/
public @NonNull static TriState fromBoolean(boolean value) {
return value ? TRUE : FALSE;
}
}