mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Merge remote-tracking branch 'origin/master' into feature/floodgate-merge
This commit is contained in:
commit
ca7d57e541
158 changed files with 3719 additions and 14571 deletions
|
@ -17,7 +17,7 @@ The ultimate goal of this project is to allow Minecraft: Bedrock Edition users t
|
|||
|
||||
Special thanks to the DragonProxy project for being a trailblazer in protocol translation and for all the team members who have joined us here!
|
||||
|
||||
### Currently supporting Minecraft Bedrock 1.19.0 - 1.19.40 and Minecraft Java 1.19.1/1.19.2.
|
||||
### Currently supporting Minecraft Bedrock 1.19.20 - 1.19.51 and Minecraft Java 1.19.3.
|
||||
|
||||
## Setting Up
|
||||
Take a look [here](https://wiki.geysermc.org/geyser/setup/) for how to set up Geyser.
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
plugins {
|
||||
id("geyser.api-conventions")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(libs.baseApi)
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications.named<MavenPublication>("mavenJava") {
|
||||
groupId = rootProject.group as String + ".geyser"
|
||||
artifactId = "api"
|
||||
}
|
||||
}
|
|
@ -1,119 +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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -1,215 +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.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();
|
||||
}
|
||||
}
|
|
@ -1,45 +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.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);
|
||||
}
|
|
@ -1,81 +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.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);
|
||||
}
|
|
@ -1,35 +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.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 {
|
||||
}
|
|
@ -1,43 +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.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);
|
||||
}
|
|
@ -1,47 +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.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);
|
||||
}
|
||||
}
|
|
@ -1,40 +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.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> {
|
||||
}
|
|
@ -1,32 +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.geysermc.event.Event;
|
||||
import org.geysermc.event.subscribe.Subscriber;
|
||||
|
||||
public interface ExtensionEventSubscriber<T extends Event> extends Subscriber<T> {
|
||||
}
|
|
@ -1,51 +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.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;
|
||||
}
|
||||
}
|
|
@ -1,85 +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.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();
|
||||
}
|
||||
}
|
|
@ -1,57 +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.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();
|
||||
}
|
|
@ -1,76 +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.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);
|
||||
}
|
|
@ -1,40 +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.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 {
|
||||
}
|
|
@ -1,41 +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.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 {
|
||||
}
|
|
@ -1,41 +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.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 {
|
||||
}
|
|
@ -1,38 +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.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 {
|
||||
}
|
|
@ -1,139 +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.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();
|
||||
}
|
||||
}
|
|
@ -1,106 +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.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();
|
||||
}
|
|
@ -1,105 +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.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);
|
||||
}
|
||||
}
|
|
@ -1,94 +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.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();
|
||||
}
|
|
@ -1,90 +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.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);
|
||||
}
|
||||
}
|
|
@ -1,43 +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.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);
|
||||
}
|
||||
}
|
|
@ -1,43 +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.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);
|
||||
}
|
||||
}
|
|
@ -1,109 +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.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();
|
||||
}
|
||||
}
|
|
@ -1,83 +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.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();
|
||||
}
|
||||
}
|
|
@ -1,51 +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.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) {
|
||||
}
|
||||
}
|
|
@ -1,188 +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.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();
|
||||
}
|
||||
}
|
|
@ -1,77 +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.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();
|
||||
}
|
|
@ -1,70 +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.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();
|
||||
}
|
|
@ -1,83 +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.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;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
* Copyright (c) 2019-2021 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
|
||||
|
@ -23,39 +23,30 @@
|
|||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
package org.geysermc.geyser.api.network;
|
||||
package org.geysermc.geyser.platform.bungeecord;
|
||||
|
||||
import java.util.Locale;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOutboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import net.md_5.bungee.protocol.packet.LoginSuccess;
|
||||
import net.md_5.bungee.protocol.packet.SetCompression;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
public class GeyserBungeeCompressionDisabler extends ChannelOutboundHandlerAdapter {
|
||||
|
||||
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;
|
||||
@Override
|
||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
||||
if (!(msg instanceof SetCompression)) {
|
||||
if (msg instanceof LoginSuccess) {
|
||||
// We're past the point that compression can be enabled
|
||||
if (ctx.pipeline().get("compress") != null) {
|
||||
ctx.pipeline().remove("compress");
|
||||
}
|
||||
if (ctx.pipeline().get("decompress") != null) {
|
||||
ctx.pipeline().remove("decompress");
|
||||
}
|
||||
ctx.pipeline().remove(this);
|
||||
}
|
||||
super.write(ctx, msg, promise);
|
||||
}
|
||||
return ONLINE;
|
||||
}
|
||||
}
|
|
@ -140,6 +140,11 @@ public class GeyserBungeeInjector extends GeyserInjector implements Listener {
|
|||
channelInitializer = PipelineUtils.SERVER_CHILD;
|
||||
}
|
||||
initChannel.invoke(channelInitializer, ch);
|
||||
|
||||
if (bootstrap.getGeyserConfig().isDisableCompression()) {
|
||||
ch.pipeline().addAfter(PipelineUtils.PACKET_ENCODER, "geyser-compression-disabler",
|
||||
new GeyserBungeeCompressionDisabler());
|
||||
}
|
||||
}
|
||||
})
|
||||
.childAttr(listener, listenerInfo)
|
||||
|
@ -163,7 +168,7 @@ public class GeyserBungeeInjector extends GeyserInjector implements Listener {
|
|||
// If native compression is enabled, then this line is tripped up if a heap buffer is sent over in such a situation
|
||||
// as a new direct buffer is not created with that patch (HeapByteBufs throw an UnsupportedOperationException here):
|
||||
// https://github.com/SpigotMC/BungeeCord/blob/a283aaf724d4c9a815540cd32f3aafaa72df9e05/native/src/main/java/net/md_5/bungee/jni/zlib/NativeZlib.java#L43
|
||||
// This issue could be mitigated down the line by preventing Bungee from setting compression
|
||||
// If disable compression is enabled, this can probably be disabled now, but BungeeCord (not Waterfall) complains
|
||||
LocalSession.createDirectByteBufAllocator();
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap {
|
|||
// Copied from ViaVersion.
|
||||
// https://github.com/ViaVersion/ViaVersion/blob/b8072aad86695cc8ec6f5e4103e43baf3abf6cc5/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java#L43
|
||||
try {
|
||||
ProtocolConstants.class.getField("MINECRAFT_1_19_1");
|
||||
ProtocolConstants.class.getField("MINECRAFT_1_19_3");
|
||||
} catch (NoSuchFieldException e) {
|
||||
getLogger().warning(" / \\");
|
||||
getLogger().warning(" / \\");
|
||||
|
|
|
@ -31,12 +31,13 @@ import com.nukkitx.nbt.NbtMapBuilder;
|
|||
import com.nukkitx.nbt.NbtType;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.WritableBookItem;
|
||||
import net.minecraft.world.item.WrittenBookItem;
|
||||
import net.minecraft.world.level.block.entity.BannerBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.LecternBlockEntity;
|
||||
import org.geysermc.geyser.level.GeyserWorldManager;
|
||||
|
@ -44,8 +45,10 @@ import org.geysermc.geyser.session.GeyserSession;
|
|||
import org.geysermc.geyser.translator.inventory.LecternInventoryTranslator;
|
||||
import org.geysermc.geyser.util.BlockEntityUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class GeyserFabricWorldManager extends GeyserWorldManager {
|
||||
|
@ -127,7 +130,127 @@ public class GeyserFabricWorldManager extends GeyserWorldManager {
|
|||
return Permissions.check(player, permission);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<com.github.steveice10.opennbt.tag.builtin.CompoundTag> getPickItemNbt(GeyserSession session, int x, int y, int z, boolean addNbtData) {
|
||||
CompletableFuture<com.github.steveice10.opennbt.tag.builtin.CompoundTag> future = new CompletableFuture<>();
|
||||
server.execute(() -> {
|
||||
ServerPlayer player = getPlayer(session);
|
||||
if (player == null) {
|
||||
future.complete(null);
|
||||
return;
|
||||
}
|
||||
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
// Don't create a new block entity if invalid
|
||||
BlockEntity blockEntity = player.level.getChunkAt(pos).getBlockEntity(pos);
|
||||
if (blockEntity instanceof BannerBlockEntity banner) {
|
||||
// Potentially exposes other NBT data? But we need to get the NBT data for the banner patterns *and*
|
||||
// the banner might have a custom name, both of which a Java client knows and caches
|
||||
ItemStack itemStack = banner.getItem();
|
||||
var tag = OpenNbtTagVisitor.convert("", itemStack.getOrCreateTag());
|
||||
|
||||
future.complete(tag);
|
||||
return;
|
||||
}
|
||||
future.complete(null);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
private ServerPlayer getPlayer(GeyserSession session) {
|
||||
return server.getPlayerList().getPlayer(session.getPlayerEntity().getUuid());
|
||||
}
|
||||
|
||||
// Future considerations: option to clone; would affect arrays
|
||||
private static class OpenNbtTagVisitor implements TagVisitor {
|
||||
private String currentKey;
|
||||
private final com.github.steveice10.opennbt.tag.builtin.CompoundTag root;
|
||||
private com.github.steveice10.opennbt.tag.builtin.Tag currentTag;
|
||||
|
||||
OpenNbtTagVisitor(String key) {
|
||||
root = new com.github.steveice10.opennbt.tag.builtin.CompoundTag(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitString(StringTag stringTag) {
|
||||
currentTag = new com.github.steveice10.opennbt.tag.builtin.StringTag(currentKey, stringTag.getAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitByte(ByteTag byteTag) {
|
||||
currentTag = new com.github.steveice10.opennbt.tag.builtin.ByteTag(currentKey, byteTag.getAsByte());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitShort(ShortTag shortTag) {
|
||||
currentTag = new com.github.steveice10.opennbt.tag.builtin.ShortTag(currentKey, shortTag.getAsShort());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInt(IntTag intTag) {
|
||||
currentTag = new com.github.steveice10.opennbt.tag.builtin.IntTag(currentKey, intTag.getAsInt());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLong(LongTag longTag) {
|
||||
currentTag = new com.github.steveice10.opennbt.tag.builtin.LongTag(currentKey, longTag.getAsLong());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitFloat(FloatTag floatTag) {
|
||||
currentTag = new com.github.steveice10.opennbt.tag.builtin.FloatTag(currentKey, floatTag.getAsFloat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitDouble(DoubleTag doubleTag) {
|
||||
currentTag = new com.github.steveice10.opennbt.tag.builtin.DoubleTag(currentKey, doubleTag.getAsDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitByteArray(ByteArrayTag byteArrayTag) {
|
||||
currentTag = new com.github.steveice10.opennbt.tag.builtin.ByteArrayTag(currentKey, byteArrayTag.getAsByteArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitIntArray(IntArrayTag intArrayTag) {
|
||||
currentTag = new com.github.steveice10.opennbt.tag.builtin.IntArrayTag(currentKey, intArrayTag.getAsIntArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLongArray(LongArrayTag longArrayTag) {
|
||||
currentTag = new com.github.steveice10.opennbt.tag.builtin.LongArrayTag(currentKey, longArrayTag.getAsLongArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitList(ListTag listTag) {
|
||||
var newList = new com.github.steveice10.opennbt.tag.builtin.ListTag(currentKey);
|
||||
for (Tag tag : listTag) {
|
||||
currentKey = "";
|
||||
tag.accept(this);
|
||||
newList.add(currentTag);
|
||||
}
|
||||
currentTag = newList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitCompound(CompoundTag compoundTag) {
|
||||
currentTag = convert(currentKey, compoundTag);
|
||||
}
|
||||
|
||||
private static com.github.steveice10.opennbt.tag.builtin.CompoundTag convert(String name, CompoundTag compoundTag) {
|
||||
OpenNbtTagVisitor visitor = new OpenNbtTagVisitor(name);
|
||||
for (String key : compoundTag.getAllKeys()) {
|
||||
visitor.currentKey = key;
|
||||
Tag tag = compoundTag.get(key);
|
||||
tag.accept(visitor);
|
||||
visitor.root.put(visitor.currentTag);
|
||||
}
|
||||
return visitor.root;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd(EndTag endTag) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2021 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.platform.spigot;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOutboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
|
||||
/**
|
||||
* Disables the compression packet (and the compression handlers from being added to the pipeline) for Geyser clients
|
||||
* that won't be receiving the data over the network.
|
||||
*
|
||||
* As of 1.8 - 1.17.1, compression is enabled in the Netty pipeline by adding a listener after a packet is written.
|
||||
* If we simply "cancel" or don't forward the packet, then the listener is never called.
|
||||
*/
|
||||
public class GeyserSpigotCompressionDisabler extends ChannelOutboundHandlerAdapter {
|
||||
static final boolean ENABLED;
|
||||
|
||||
private static final Class<?> COMPRESSION_PACKET_CLASS;
|
||||
private static final Class<?> LOGIN_SUCCESS_PACKET_CLASS;
|
||||
private static final boolean PROTOCOL_SUPPORT_INSTALLED;
|
||||
|
||||
static {
|
||||
PROTOCOL_SUPPORT_INSTALLED = Bukkit.getPluginManager().getPlugin("ProtocolSupport") != null;
|
||||
|
||||
Class<?> compressionPacketClass = null;
|
||||
Class<?> loginSuccessPacketClass = null;
|
||||
boolean enabled = false;
|
||||
try {
|
||||
compressionPacketClass = findCompressionPacket();
|
||||
loginSuccessPacketClass = findLoginSuccessPacket();
|
||||
enabled = true;
|
||||
} catch (Exception e) {
|
||||
GeyserImpl.getInstance().getLogger().error("Could not initialize compression disabler!", e);
|
||||
}
|
||||
COMPRESSION_PACKET_CLASS = compressionPacketClass;
|
||||
LOGIN_SUCCESS_PACKET_CLASS = loginSuccessPacketClass;
|
||||
ENABLED = enabled;
|
||||
}
|
||||
|
||||
public GeyserSpigotCompressionDisabler() {
|
||||
if (!ENABLED) {
|
||||
throw new RuntimeException("Geyser compression disabler cannot be initialized in its current state!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
||||
Class<?> msgClass = msg.getClass();
|
||||
// Don't let any compression packet get through
|
||||
if (!COMPRESSION_PACKET_CLASS.isAssignableFrom(msgClass)) {
|
||||
if (LOGIN_SUCCESS_PACKET_CLASS.isAssignableFrom(msgClass)) {
|
||||
if (PROTOCOL_SUPPORT_INSTALLED) {
|
||||
// ProtocolSupport must send the compression packet, so let's remove what it did before it does damage
|
||||
if (ctx.pipeline().get("compress") != null) {
|
||||
ctx.pipeline().remove("compress");
|
||||
}
|
||||
if (ctx.pipeline().get("decompress") != null) {
|
||||
ctx.pipeline().remove("decompress");
|
||||
}
|
||||
}
|
||||
// We're past the point that a compression packet can be sent, so we can safely yeet ourselves away
|
||||
ctx.channel().pipeline().remove(this);
|
||||
}
|
||||
super.write(ctx, msg, promise);
|
||||
} else if (PROTOCOL_SUPPORT_INSTALLED) {
|
||||
// We must indicate it "succeeded" or ProtocolSupport will time us out
|
||||
promise.setSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
private static Class<?> findCompressionPacket() throws ClassNotFoundException {
|
||||
try {
|
||||
return Class.forName("net.minecraft.network.protocol.login.PacketLoginOutSetCompression");
|
||||
} catch (ClassNotFoundException e) {
|
||||
String prefix = Bukkit.getServer().getClass().getPackage().getName().replace("org.bukkit.craftbukkit", "net.minecraft.server");
|
||||
return Class.forName(prefix + ".PacketLoginOutSetCompression");
|
||||
}
|
||||
}
|
||||
|
||||
private static Class<?> findLoginSuccessPacket() throws ClassNotFoundException {
|
||||
try {
|
||||
return Class.forName("net.minecraft.network.protocol.login.PacketLoginOutSuccess");
|
||||
} catch (ClassNotFoundException e) {
|
||||
String prefix = Bukkit.getServer().getClass().getPackage().getName().replace("org.bukkit.craftbukkit", "net.minecraft.server");
|
||||
return Class.forName(prefix + ".PacketLoginOutSuccess");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -117,10 +117,14 @@ public class GeyserSpigotInjector extends GeyserInjector {
|
|||
|
||||
ChannelFuture channelFuture = (new ServerBootstrap()
|
||||
.channel(LocalServerChannelWrapper.class)
|
||||
.childHandler(new ChannelInitializer<Channel>() {
|
||||
.childHandler(new ChannelInitializer<>() {
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception {
|
||||
initChannel.invoke(childHandler, ch);
|
||||
if (bootstrap.getGeyserConfig().isDisableCompression() && GeyserSpigotCompressionDisabler.ENABLED) {
|
||||
ch.pipeline().addAfter("encoder", "geyser-compression-disabler", new GeyserSpigotCompressionDisabler());
|
||||
}
|
||||
|
||||
if (GeyserImpl.getInstance().getConfig().getRemote().authType() == AuthType.FLOODGATE) {
|
||||
// we have to add the packet blocker in the data handler, otherwise ProtocolSupport breaks
|
||||
ch.pipeline().addBefore(
|
||||
|
|
|
@ -187,6 +187,9 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
|
|||
geyserLogger.severe("WHY DO YOU HAVE FLOODGATE INSTALLED!!!!!!! REMOVE IT!!!!");
|
||||
}
|
||||
|
||||
this.geyserCommandManager = new GeyserSpigotCommandManager(geyser);
|
||||
this.geyserCommandManager.init();
|
||||
|
||||
if (!INITIALIZED) {
|
||||
// Needs to be an anonymous inner class otherwise Bukkit complains about missing classes
|
||||
Bukkit.getPluginManager().registerEvents(new Listener() {
|
||||
|
@ -198,9 +201,6 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
|
|||
}
|
||||
}, this);
|
||||
|
||||
this.geyserCommandManager = new GeyserSpigotCommandManager(geyser);
|
||||
this.geyserCommandManager.init();
|
||||
|
||||
// Because Bukkit locks its command map upon startup, we need to
|
||||
// add our plugin commands in onEnable, but populating the executor
|
||||
// can happen at any time
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.geysermc.geyser.adapters.spigot.SpigotAdapters;
|
|||
import org.geysermc.geyser.adapters.spigot.SpigotWorldAdapter;
|
||||
import org.geysermc.geyser.level.block.BlockStateValues;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class GeyserSpigotNativeWorldManager extends GeyserSpigotWorldManager {
|
||||
protected final SpigotWorldAdapter adapter;
|
||||
|
@ -49,4 +50,12 @@ public class GeyserSpigotNativeWorldManager extends GeyserSpigotWorldManager {
|
|||
}
|
||||
return adapter.getBlockAt(player.getWorld(), x, y, z);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String[] getBiomeIdentifiers(boolean withTags) {
|
||||
// Biome identifiers will basically always be the same for one server, since you have to re-send the
|
||||
// ClientboundLoginPacket to change the registry. Therefore, don't bother caching for each player.
|
||||
return adapter.getBiomeSuggestions(withTags);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,33 +25,40 @@
|
|||
|
||||
package org.geysermc.geyser.platform.spigot.world.manager;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.nbt.NbtMapBuilder;
|
||||
import com.nukkitx.nbt.NbtType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Lectern;
|
||||
import org.bukkit.block.*;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.geysermc.geyser.level.GameRule;
|
||||
import org.geysermc.geyser.level.GeyserWorldManager;
|
||||
import org.geysermc.geyser.level.WorldManager;
|
||||
import org.geysermc.geyser.level.block.BlockStateValues;
|
||||
import org.geysermc.geyser.registry.BlockRegistries;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.translator.inventory.LecternInventoryTranslator;
|
||||
import org.geysermc.geyser.translator.inventory.item.nbt.BannerTranslator;
|
||||
import org.geysermc.geyser.util.BlockEntityUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* The base world manager to use when there is no supported NMS revision
|
||||
*/
|
||||
public class GeyserSpigotWorldManager extends GeyserWorldManager {
|
||||
public class GeyserSpigotWorldManager extends WorldManager {
|
||||
private final Plugin plugin;
|
||||
|
||||
public GeyserSpigotWorldManager(Plugin plugin) {
|
||||
|
@ -151,12 +158,12 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager {
|
|||
return true;
|
||||
}
|
||||
|
||||
public Boolean getGameRuleBool(GeyserSession session, GameRule gameRule) {
|
||||
public boolean getGameRuleBool(GeyserSession session, GameRule gameRule) {
|
||||
String value = Bukkit.getPlayer(session.getPlayerEntity().getUsername()).getWorld().getGameRuleValue(gameRule.getJavaID());
|
||||
if (!value.isEmpty()) {
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
return (Boolean) gameRule.getDefaultValue();
|
||||
return gameRule.getDefaultBooleanValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -165,7 +172,7 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager {
|
|||
if (!value.isEmpty()) {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
return (int) gameRule.getDefaultValue();
|
||||
return gameRule.getDefaultIntValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -173,6 +180,46 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager {
|
|||
return Bukkit.getPlayer(session.getPlayerEntity().getUsername()).hasPermission(permission);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public CompletableFuture<@Nullable CompoundTag> getPickItemNbt(GeyserSession session, int x, int y, int z, boolean addNbtData) {
|
||||
CompletableFuture<@Nullable CompoundTag> future = new CompletableFuture<>();
|
||||
// Paper 1.19.3 complains about async access otherwise.
|
||||
// java.lang.IllegalStateException: Tile is null, asynchronous access?
|
||||
Bukkit.getScheduler().runTask(this.plugin, () -> {
|
||||
Player bukkitPlayer;
|
||||
if ((bukkitPlayer = Bukkit.getPlayer(session.getPlayerEntity().getUuid())) == null) {
|
||||
future.complete(null);
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = bukkitPlayer.getWorld().getBlockAt(x, y, z);
|
||||
BlockState state = block.getState();
|
||||
if (state instanceof Banner banner) {
|
||||
ListTag list = new ListTag("Patterns");
|
||||
for (int i = 0; i < banner.numberOfPatterns(); i++) {
|
||||
Pattern pattern = banner.getPattern(i);
|
||||
list.add(BannerTranslator.getJavaPatternTag(pattern.getPattern().getIdentifier(), pattern.getColor().ordinal()));
|
||||
}
|
||||
|
||||
CompoundTag root = addToBlockEntityTag(list);
|
||||
|
||||
future.complete(root);
|
||||
return;
|
||||
}
|
||||
future.complete(null);
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
private CompoundTag addToBlockEntityTag(Tag tag) {
|
||||
CompoundTag compoundTag = new CompoundTag("");
|
||||
CompoundTag blockEntityTag = new CompoundTag("BlockEntityTag");
|
||||
blockEntityTag.put(tag);
|
||||
compoundTag.put(blockEntityTag);
|
||||
return compoundTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* This should be set to true if we are post-1.13 but before the latest version, and we should convert the old block state id
|
||||
* to the current one.
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2021 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.platform.velocity;
|
||||
|
||||
import io.netty.channel.ChannelDuplexHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class GeyserVelocityCompressionDisabler extends ChannelDuplexHandler {
|
||||
static final boolean ENABLED;
|
||||
private static final Class<?> COMPRESSION_PACKET_CLASS;
|
||||
private static final Class<?> LOGIN_SUCCESS_PACKET_CLASS;
|
||||
private static final Object COMPRESSION_ENABLED_EVENT;
|
||||
private static final Method SET_COMPRESSION_METHOD;
|
||||
|
||||
static {
|
||||
boolean enabled = false;
|
||||
Class<?> compressionPacketClass = null;
|
||||
Class<?> loginSuccessPacketClass = null;
|
||||
Object compressionEnabledEvent = null;
|
||||
Method setCompressionMethod = null;
|
||||
|
||||
try {
|
||||
compressionPacketClass = Class.forName("com.velocitypowered.proxy.protocol.packet.SetCompression");
|
||||
loginSuccessPacketClass = Class.forName("com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess");
|
||||
compressionEnabledEvent = Class.forName("com.velocitypowered.proxy.protocol.VelocityConnectionEvent")
|
||||
.getDeclaredField("COMPRESSION_ENABLED").get(null);
|
||||
setCompressionMethod = Class.forName("com.velocitypowered.proxy.connection.MinecraftConnection")
|
||||
.getMethod("setCompressionThreshold", int.class);
|
||||
enabled = true;
|
||||
} catch (Exception e) {
|
||||
GeyserImpl.getInstance().getLogger().error("Could not initialize compression disabler!", e);
|
||||
}
|
||||
|
||||
ENABLED = enabled;
|
||||
COMPRESSION_PACKET_CLASS = compressionPacketClass;
|
||||
LOGIN_SUCCESS_PACKET_CLASS = loginSuccessPacketClass;
|
||||
COMPRESSION_ENABLED_EVENT = compressionEnabledEvent;
|
||||
SET_COMPRESSION_METHOD = setCompressionMethod;
|
||||
}
|
||||
|
||||
public GeyserVelocityCompressionDisabler() {
|
||||
if (!ENABLED) {
|
||||
throw new RuntimeException("Geyser compression disabler cannot be initialized in its current state!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
||||
Class<?> msgClass = msg.getClass();
|
||||
if (!COMPRESSION_PACKET_CLASS.isAssignableFrom(msgClass)) {
|
||||
if (LOGIN_SUCCESS_PACKET_CLASS.isAssignableFrom(msgClass)) {
|
||||
// We're past the point that compression can be enabled
|
||||
|
||||
ctx.pipeline().remove(this);
|
||||
}
|
||||
super.write(ctx, msg, promise);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||
if (evt != COMPRESSION_ENABLED_EVENT) {
|
||||
super.userEventTriggered(ctx, evt);
|
||||
return;
|
||||
}
|
||||
|
||||
// Invoke the method as it calls a Netty event and handles removing cleaner than we could
|
||||
Object minecraftConnection = ctx.pipeline().get("handler");
|
||||
SET_COMPRESSION_METHOD.invoke(minecraftConnection, -1);
|
||||
// Do not call super and let the new compression enabled event continue firing
|
||||
}
|
||||
}
|
|
@ -34,6 +34,7 @@ import org.geysermc.geyser.network.netty.GeyserInjector;
|
|||
import org.geysermc.geyser.network.netty.LocalServerChannelWrapper;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class GeyserVelocityInjector extends GeyserInjector {
|
||||
|
@ -67,9 +68,23 @@ public class GeyserVelocityInjector extends GeyserInjector {
|
|||
workerGroupField.setAccessible(true);
|
||||
EventLoopGroup workerGroup = (EventLoopGroup) workerGroupField.get(connectionManager);
|
||||
|
||||
// This method is what initializes the connection in Java Edition, after Netty is all set.
|
||||
Method initChannel = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class);
|
||||
initChannel.setAccessible(true);
|
||||
|
||||
ChannelFuture channelFuture = (new ServerBootstrap()
|
||||
.channel(LocalServerChannelWrapper.class)
|
||||
.childHandler(channelInitializer)
|
||||
.childHandler(new ChannelInitializer<>() {
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception {
|
||||
initChannel.invoke(channelInitializer, ch);
|
||||
|
||||
if (bootstrap.getGeyserConfig().isDisableCompression() && GeyserVelocityCompressionDisabler.ENABLED) {
|
||||
ch.pipeline().addAfter("minecraft-encoder", "geyser-compression-disabler",
|
||||
new GeyserVelocityCompressionDisabler());
|
||||
}
|
||||
}
|
||||
})
|
||||
.group(bossGroup, workerGroup) // Cannot be DefaultEventLoopGroup
|
||||
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, serverWriteMark) // Required or else rare network freezes can occur
|
||||
.localAddress(LocalAddress.ANY))
|
||||
|
|
|
@ -16,7 +16,7 @@ dependencies {
|
|||
|
||||
// Within the gradle plugin classpath, there is a version conflict between loom and some other
|
||||
// plugin for databind. This fixes it: minimum 2.13.2 is required by loom.
|
||||
implementation("com.fasterxml.jackson.core:jackson-databind:2.13.3")
|
||||
implementation("com.fasterxml.jackson.core:jackson-databind:2.14.0")
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile> {
|
||||
|
|
|
@ -5,7 +5,7 @@ plugins {
|
|||
}
|
||||
|
||||
allprojects {
|
||||
group = "org.geysermc"
|
||||
group = "org.geysermc.geyser"
|
||||
version = "3.0.0-SNAPSHOT"
|
||||
description = "Allows for players from Minecraft: Bedrock Edition to join Minecraft: Java Edition servers."
|
||||
|
||||
|
@ -30,16 +30,8 @@ subprojects {
|
|||
plugin("geyser.build-logic")
|
||||
}
|
||||
|
||||
val relativePath = projectDir.relativeTo(rootProject.projectDir).path
|
||||
|
||||
if (relativePath.contains("api")) {
|
||||
plugins.apply("geyser.api-conventions")
|
||||
} else {
|
||||
group = rootProject.group as String + ".geyser"
|
||||
when (this) {
|
||||
in platforms -> plugins.apply("geyser.platform-conventions")
|
||||
//api -> plugins.apply("geyser.publish-conventions") FIXME
|
||||
else -> plugins.apply("geyser.base-conventions")
|
||||
}
|
||||
when (this) {
|
||||
in platforms -> plugins.apply("geyser.platform-conventions")
|
||||
else -> plugins.apply("geyser.base-conventions")
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ plugins {
|
|||
|
||||
dependencies {
|
||||
api("org.geysermc.floodgate", "core", "2.2.0-SNAPSHOT")
|
||||
api(projects.geyserApi)
|
||||
api(libs.geyser.api)
|
||||
|
||||
// Jackson JSON and YAML serialization
|
||||
api(libs.bundles.jackson)
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.net.URISyntaxException;
|
|||
|
||||
public final class Constants {
|
||||
public static final URI GLOBAL_API_WS_URI;
|
||||
public static final String NTP_SERVER = "time.cloudflare.com";
|
||||
|
||||
public static final String NEWS_OVERVIEW_URL = "https://api.geysermc.org/v2/news/";
|
||||
public static final String NEWS_PROJECT_NAME = "geyser";
|
||||
|
|
|
@ -76,6 +76,7 @@ import org.geysermc.geyser.session.GeyserSession;
|
|||
import org.geysermc.geyser.session.PendingMicrosoftAuthentication;
|
||||
import org.geysermc.geyser.session.SessionManager;
|
||||
import org.geysermc.geyser.skin.BedrockSkinUploader;
|
||||
import org.geysermc.geyser.skin.ProvidedSkins;
|
||||
import org.geysermc.geyser.skin.SkinProvider;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
import org.geysermc.geyser.text.MinecraftLocale;
|
||||
|
@ -91,6 +92,7 @@ import java.net.InetSocketAddress;
|
|||
import java.net.UnknownHostException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
@ -199,7 +201,23 @@ public class GeyserImpl implements GeyserApi {
|
|||
EntityDefinitions.init();
|
||||
ItemTranslator.init();
|
||||
MessageTranslator.init();
|
||||
MinecraftLocale.init();
|
||||
|
||||
// Download the latest asset list and cache it
|
||||
AssetUtils.generateAssetCache().whenComplete((aVoid, ex) -> {
|
||||
if (ex != null) {
|
||||
return;
|
||||
}
|
||||
MinecraftLocale.ensureEN_US();
|
||||
String locale = GeyserLocale.getDefaultLocale();
|
||||
if (!"en_us".equals(locale)) {
|
||||
// English will be loaded after assets are downloaded, if necessary
|
||||
MinecraftLocale.downloadAndLoadLocale(locale);
|
||||
}
|
||||
|
||||
ProvidedSkins.init();
|
||||
|
||||
CompletableFuture.runAsync(AssetUtils::downloadAndRunClientJarTasks);
|
||||
});
|
||||
|
||||
startInstance();
|
||||
|
||||
|
@ -227,7 +245,10 @@ public class GeyserImpl implements GeyserApi {
|
|||
logger.info(message);
|
||||
|
||||
if (platformType == PlatformType.STANDALONE) {
|
||||
logger.warning(GeyserLocale.getLocaleStringLog("geyser.core.movement_warn"));
|
||||
if (config.getRemote().authType() != AuthType.FLOODGATE) {
|
||||
// If the auth-type is Floodgate, then this Geyser instance is probably owned by the Java server
|
||||
logger.warning(GeyserLocale.getLocaleStringLog("geyser.core.movement_warn"));
|
||||
}
|
||||
} else if (config.getRemote().authType() == AuthType.FLOODGATE) {
|
||||
VersionCheckUtils.checkForOutdatedFloodgate(logger);
|
||||
}
|
||||
|
|
|
@ -113,6 +113,8 @@ public interface GeyserConfiguration {
|
|||
|
||||
boolean isNotifyOnNewBedrockUpdate();
|
||||
|
||||
String getUnusableSpaceBlock();
|
||||
|
||||
IMetricsInfo getMetrics();
|
||||
|
||||
int getPendingAuthenticationTimeout();
|
||||
|
@ -189,6 +191,8 @@ public interface GeyserConfiguration {
|
|||
|
||||
boolean isUseDirectConnection();
|
||||
|
||||
boolean isDisableCompression();
|
||||
|
||||
int getConfigVersion();
|
||||
|
||||
static void checkGeyserConfiguration(GeyserConfiguration geyserConfig, GeyserLogger geyserLogger) {
|
||||
|
|
|
@ -166,6 +166,9 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
|
|||
@JsonProperty("notify-on-new-bedrock-update")
|
||||
private boolean notifyOnNewBedrockUpdate = true;
|
||||
|
||||
@JsonProperty("unusable-space-block")
|
||||
private String unusableSpaceBlock = "minecraft:barrier";
|
||||
|
||||
private MetricsInfo metrics = new MetricsInfo();
|
||||
|
||||
@JsonProperty("pending-authentication-timeout")
|
||||
|
@ -344,6 +347,9 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
|
|||
@JsonProperty("use-direct-connection")
|
||||
private boolean useDirectConnection = true;
|
||||
|
||||
@JsonProperty("disable-compression")
|
||||
private boolean isDisableCompression = true;
|
||||
|
||||
@JsonProperty("config-version")
|
||||
private int configVersion = 0;
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ public final class EntityDefinitions {
|
|||
public static final EntityDefinition<BeeEntity> BEE;
|
||||
public static final EntityDefinition<BlazeEntity> BLAZE;
|
||||
public static final EntityDefinition<BoatEntity> BOAT;
|
||||
public static final EntityDefinition<CamelEntity> CAMEL;
|
||||
public static final EntityDefinition<CatEntity> CAT;
|
||||
public static final EntityDefinition<SpiderEntity> CAVE_SPIDER;
|
||||
public static final EntityDefinition<MinecartEntity> CHEST_MINECART;
|
||||
|
@ -859,6 +860,13 @@ public final class EntityDefinitions {
|
|||
.addTranslator(MetadataType.BYTE, AbstractHorseEntity::setHorseFlags)
|
||||
.addTranslator(null) // UUID of owner
|
||||
.build();
|
||||
CAMEL = EntityDefinition.inherited(CamelEntity::new, abstractHorseEntityBase)
|
||||
.type(EntityType.CAMEL)
|
||||
.identifier("minecraft:llama") // todo 1.20
|
||||
.height(2.375f).width(1.7f)
|
||||
.addTranslator(MetadataType.BOOLEAN, CamelEntity::setDashing)
|
||||
.addTranslator(null) // Last pose change tick
|
||||
.build();
|
||||
HORSE = EntityDefinition.inherited(HorseEntity::new, abstractHorseEntityBase)
|
||||
.type(EntityType.HORSE)
|
||||
.height(1.6f).width(1.3965f)
|
||||
|
|
|
@ -46,6 +46,7 @@ public class CommandBlockMinecartEntity extends DefaultBlockMinecartEntity {
|
|||
|
||||
@Override
|
||||
protected void initializeMetadata() {
|
||||
super.initializeMetadata();
|
||||
// Required, or else the GUI will not open
|
||||
dirtyMetadata.put(EntityData.CONTAINER_TYPE, (byte) 16);
|
||||
dirtyMetadata.put(EntityData.CONTAINER_BASE_SIZE, 1);
|
||||
|
|
|
@ -355,6 +355,7 @@ public class Entity {
|
|||
setFlag(EntityFlag.ON_FIRE, ((xd & 0x01) == 0x01) && !getFlag(EntityFlag.FIRE_IMMUNE)); // Otherwise immune entities sometimes flicker onfire
|
||||
setFlag(EntityFlag.SNEAKING, (xd & 0x02) == 0x02);
|
||||
setFlag(EntityFlag.SPRINTING, (xd & 0x08) == 0x08);
|
||||
|
||||
// Swimming is ignored here and instead we rely on the pose
|
||||
setFlag(EntityFlag.GLIDING, (xd & 0x80) == 0x80);
|
||||
|
||||
|
|
|
@ -40,6 +40,13 @@ public class AgeableEntity extends CreatureEntity {
|
|||
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeMetadata() {
|
||||
super.initializeMetadata();
|
||||
// Required as of 1.19.3 Java
|
||||
dirtyMetadata.put(EntityData.SCALE, getAdultSize());
|
||||
}
|
||||
|
||||
public void setBaby(BooleanEntityMetadata entityMetadata) {
|
||||
boolean isBaby = entityMetadata.getPrimitiveValue();
|
||||
dirtyMetadata.put(EntityData.SCALE, isBaby ? getBabySize() : getAdultSize());
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
package org.geysermc.geyser.entity.type.living.animal;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
|
||||
import com.nukkitx.math.vector.Vector3f;
|
||||
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
||||
|
@ -42,11 +41,6 @@ public class RabbitEntity extends AnimalEntity {
|
|||
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBaby(BooleanEntityMetadata entityMetadata) {
|
||||
super.setBaby(entityMetadata);
|
||||
}
|
||||
|
||||
public void setRabbitVariant(IntEntityMetadata entityMetadata) {
|
||||
int variant = entityMetadata.getPrimitiveValue();
|
||||
|
||||
|
|
|
@ -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.entity.type.living.animal.horse;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
||||
import com.nukkitx.math.vector.Vector3f;
|
||||
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
||||
import org.geysermc.geyser.entity.EntityDefinition;
|
||||
import org.geysermc.geyser.registry.type.ItemMapping;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class CamelEntity extends AbstractHorseEntity {
|
||||
|
||||
private static final float SITTING_HEIGHT_DIFFERENCE = 1.43F;
|
||||
|
||||
public CamelEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
|
||||
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeMetadata() {
|
||||
super.initializeMetadata();
|
||||
this.dirtyMetadata.put(EntityData.VARIANT, 2); // Closest llama colour to camel
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEat(String javaIdentifierStripped, ItemMapping mapping) {
|
||||
return "cactus".equals(javaIdentifierStripped);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setDimensions(Pose pose) {
|
||||
if (pose == Pose.SITTING) {
|
||||
setBoundingBoxWidth(definition.height() - SITTING_HEIGHT_DIFFERENCE);
|
||||
setBoundingBoxWidth(definition.width());
|
||||
} else {
|
||||
super.setDimensions(pose);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDashing(BooleanEntityMetadata entityMetadata) {
|
||||
|
||||
}
|
||||
}
|
|
@ -50,6 +50,13 @@ public class CatEntity extends TameableEntity {
|
|||
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeMetadata() {
|
||||
super.initializeMetadata();
|
||||
// Default value (minecraft:black).
|
||||
dirtyMetadata.put(EntityData.VARIANT, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRotation(float yaw, float pitch, boolean isOnGround) {
|
||||
moveRelative(0, 0, 0, yaw, pitch, yaw, isOnGround);
|
||||
|
|
|
@ -25,8 +25,9 @@
|
|||
|
||||
package org.geysermc.geyser.entity.type.living.monster;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.OptionalIntMetadataType;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
|
||||
import com.nukkitx.math.vector.Vector3f;
|
||||
import com.nukkitx.protocol.bedrock.data.SoundEvent;
|
||||
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
||||
|
@ -35,6 +36,7 @@ import com.nukkitx.protocol.bedrock.packet.LevelSoundEvent2Packet;
|
|||
import org.geysermc.geyser.entity.EntityDefinition;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
import java.util.UUID;
|
||||
|
||||
public class EndermanEntity extends MonsterEntity {
|
||||
|
@ -43,8 +45,15 @@ public class EndermanEntity extends MonsterEntity {
|
|||
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
|
||||
}
|
||||
|
||||
public void setCarriedBlock(IntEntityMetadata entityMetadata) {
|
||||
dirtyMetadata.put(EntityData.CARRIED_BLOCK, session.getBlockMappings().getBedrockBlockId(entityMetadata.getPrimitiveValue()));
|
||||
public void setCarriedBlock(EntityMetadata<OptionalInt, OptionalIntMetadataType> entityMetadata) {
|
||||
int bedrockBlockId;
|
||||
if (entityMetadata.getValue().isPresent()) {
|
||||
bedrockBlockId = session.getBlockMappings().getBedrockBlockId(entityMetadata.getValue().getAsInt());
|
||||
} else {
|
||||
bedrockBlockId = session.getBlockMappings().getBedrockAirId();
|
||||
}
|
||||
|
||||
dirtyMetadata.put(EntityData.CARRIED_BLOCK, bedrockBlockId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -77,7 +77,6 @@ public class PlayerEntity extends LivingEntity {
|
|||
}
|
||||
|
||||
private String username;
|
||||
private boolean playerList = true; // Player is in the player list
|
||||
|
||||
/**
|
||||
* The textures property from the GameProfile.
|
||||
|
@ -101,6 +100,7 @@ public class PlayerEntity extends LivingEntity {
|
|||
super(session, entityId, geyserId, uuid, EntityDefinitions.PLAYER, position, motion, yaw, pitch, headYaw);
|
||||
|
||||
this.username = username;
|
||||
this.nametag = username;
|
||||
this.texturesProperty = texturesProperty;
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ public class PlayerEntity extends LivingEntity {
|
|||
}
|
||||
|
||||
// The name can't be updated later (the entity metadata for it is ignored), so we need to check for this now
|
||||
updateDisplayName(null, false);
|
||||
updateDisplayName(session.getWorldCache().getScoreboard().getTeamFor(username));
|
||||
|
||||
AddPlayerPacket addPlayerPacket = new AddPlayerPacket();
|
||||
addPlayerPacket.setUuid(uuid);
|
||||
|
@ -316,19 +316,10 @@ public class PlayerEntity extends LivingEntity {
|
|||
}
|
||||
|
||||
//todo this will become common entity logic once UUID support is implemented for them
|
||||
/**
|
||||
* @param useGivenTeam even if there is no team, update the username in the entity metadata anyway, and don't look for a team
|
||||
*/
|
||||
public void updateDisplayName(@Nullable Team team, boolean useGivenTeam) {
|
||||
if (team == null && !useGivenTeam) {
|
||||
// Only search for the team if we are not supposed to use the given team
|
||||
// If the given team is null, this is intentional that we are being removed from the team
|
||||
team = session.getWorldCache().getScoreboard().getTeamFor(username);
|
||||
}
|
||||
|
||||
public void updateDisplayName(@Nullable Team team) {
|
||||
boolean needsUpdate;
|
||||
String newDisplayName = this.username;
|
||||
if (team != null) {
|
||||
String newDisplayName;
|
||||
if (team.isVisibleFor(session.getPlayerEntity().getUsername())) {
|
||||
TeamColor color = team.getColor();
|
||||
String chatColor = MessageTranslator.toChatColor(color);
|
||||
|
@ -340,23 +331,16 @@ public class PlayerEntity extends LivingEntity {
|
|||
// The name is not visible to the session player; clear name
|
||||
newDisplayName = "";
|
||||
}
|
||||
needsUpdate = useGivenTeam && !newDisplayName.equals(nametag);
|
||||
nametag = newDisplayName;
|
||||
dirtyMetadata.put(EntityData.NAMETAG, newDisplayName);
|
||||
} else if (useGivenTeam) {
|
||||
// The name has reset, if it was previously something else
|
||||
needsUpdate = !newDisplayName.equals(nametag);
|
||||
dirtyMetadata.put(EntityData.NAMETAG, this.username);
|
||||
needsUpdate = !newDisplayName.equals(this.nametag);
|
||||
this.nametag = newDisplayName;
|
||||
} else {
|
||||
needsUpdate = false;
|
||||
// The name has reset, if it was previously something else
|
||||
needsUpdate = !this.nametag.equals(this.username);
|
||||
this.nametag = this.username;
|
||||
}
|
||||
|
||||
if (needsUpdate) {
|
||||
// Update the metadata as it won't be updated later
|
||||
SetEntityDataPacket packet = new SetEntityDataPacket();
|
||||
packet.getMetadata().put(EntityData.NAMETAG, newDisplayName);
|
||||
packet.setRuntimeEntityId(geyserId);
|
||||
session.sendUpstreamPacket(packet);
|
||||
dirtyMetadata.put(EntityData.NAMETAG, this.nametag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -417,4 +401,11 @@ public class PlayerEntity extends LivingEntity {
|
|||
session.sendUpstreamPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the UUID that should be used when dealing with Bedrock's tab list.
|
||||
*/
|
||||
public UUID getTabListUuid() {
|
||||
return getUuid();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -250,4 +250,9 @@ public class SessionPlayerEntity extends PlayerEntity {
|
|||
dirtyMetadata.put(EntityData.PLAYER_HAS_DIED, (byte) 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getTabListUuid() {
|
||||
return session.getAuthData().uuid();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,17 +26,20 @@
|
|||
package org.geysermc.geyser.entity.type.player;
|
||||
|
||||
import com.nukkitx.math.vector.Vector3f;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.protocol.bedrock.data.GameType;
|
||||
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
||||
import com.nukkitx.protocol.bedrock.data.command.CommandPermission;
|
||||
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
||||
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
||||
import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket;
|
||||
import lombok.Getter;
|
||||
import org.geysermc.geyser.level.block.BlockStateValues;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.session.cache.SkullCache;
|
||||
import org.geysermc.geyser.skin.SkullSkinManager;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -46,9 +49,14 @@ import java.util.concurrent.TimeUnit;
|
|||
*/
|
||||
public class SkullPlayerEntity extends PlayerEntity {
|
||||
|
||||
@Getter
|
||||
private UUID skullUUID;
|
||||
|
||||
@Getter
|
||||
private Vector3i skullPosition;
|
||||
|
||||
public SkullPlayerEntity(GeyserSession session, long geyserId) {
|
||||
super(session, 0, geyserId, UUID.randomUUID(), Vector3f.ZERO, Vector3f.ZERO, 0, 0, 0, "", null);
|
||||
setPlayerList(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -103,11 +111,14 @@ public class SkullPlayerEntity extends PlayerEntity {
|
|||
}
|
||||
|
||||
public void updateSkull(SkullCache.Skull skull) {
|
||||
if (!skull.getTexturesProperty().equals(getTexturesProperty())) {
|
||||
skullPosition = skull.getPosition();
|
||||
|
||||
if (!Objects.equals(skull.getTexturesProperty(), getTexturesProperty()) || !Objects.equals(skullUUID, skull.getUuid())) {
|
||||
// Make skull invisible as we change skins
|
||||
setFlag(EntityFlag.INVISIBLE, true);
|
||||
updateBedrockMetadata();
|
||||
|
||||
skullUUID = skull.getUuid();
|
||||
setTexturesProperty(skull.getTexturesProperty());
|
||||
|
||||
SkullSkinManager.requestAndHandleSkin(this, session, (skin -> session.scheduleInEventLoop(() -> {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
* Copyright (c) 2019-2021 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
|
||||
|
|
|
@ -76,7 +76,7 @@ public class AnvilContainer extends Container {
|
|||
String originalName = ItemUtils.getCustomName(getInput().getNbt());
|
||||
|
||||
String plainOriginalName = MessageTranslator.convertToPlainText(originalName, session.locale());
|
||||
String plainNewName = MessageTranslator.convertToPlainText(rename, session.locale());
|
||||
String plainNewName = MessageTranslator.convertToPlainText(rename);
|
||||
if (!plainOriginalName.equals(plainNewName)) {
|
||||
// Strip out formatting since Java Edition does not allow it
|
||||
correctRename = plainNewName;
|
||||
|
|
|
@ -30,10 +30,7 @@ import com.github.steveice10.mc.protocol.data.game.inventory.ContainerActionType
|
|||
import com.github.steveice10.mc.protocol.data.game.inventory.ContainerType;
|
||||
import com.github.steveice10.mc.protocol.data.game.inventory.MoveToHotbarAction;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClickPacket;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import it.unimi.dsi.fastutil.ints.*;
|
||||
import org.geysermc.geyser.inventory.GeyserItemStack;
|
||||
import org.geysermc.geyser.inventory.Inventory;
|
||||
import org.geysermc.geyser.inventory.SlotType;
|
||||
|
@ -124,12 +121,14 @@ public final class ClickPlan {
|
|||
}
|
||||
|
||||
ItemStack clickedItemStack;
|
||||
if (!planIter.hasNext() && refresh) {
|
||||
clickedItemStack = InventoryUtils.REFRESH_ITEM;
|
||||
if (emulatePost1_16Logic) {
|
||||
// The action must be simulated first as Java expects the new contents of the cursor (as of 1.18.1)
|
||||
clickedItemStack = simulatedCursor.getItemStack();
|
||||
} else {
|
||||
if (emulatePost1_16Logic) {
|
||||
// The action must be simulated first as Java expects the new contents of the cursor (as of 1.18.1)
|
||||
clickedItemStack = simulatedCursor.getItemStack();
|
||||
if (!planIter.hasNext() && refresh) {
|
||||
// Doesn't have the intended effect with state IDs since this won't cause a complete window refresh
|
||||
// (It will eventually once state IDs desync, but this causes more problems than not)
|
||||
clickedItemStack = InventoryUtils.REFRESH_ITEM;
|
||||
} else {
|
||||
if (action.click.actionType == ContainerActionType.DROP_ITEM || action.slot == Click.OUTSIDE_SLOT) {
|
||||
clickedItemStack = null;
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
package org.geysermc.geyser.inventory.holder;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
|
||||
|
@ -39,6 +38,7 @@ import org.geysermc.geyser.registry.BlockRegistries;
|
|||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.translator.inventory.InventoryTranslator;
|
||||
import org.geysermc.geyser.util.BlockUtils;
|
||||
import org.geysermc.geyser.util.InventoryUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
@ -63,14 +63,14 @@ public class BlockInventoryHolder extends InventoryHolder {
|
|||
Set<String> validBlocksTemp = new HashSet<>(validBlocks.length + 1);
|
||||
Collections.addAll(validBlocksTemp, validBlocks);
|
||||
validBlocksTemp.add(BlockUtils.getCleanIdentifier(javaBlockIdentifier));
|
||||
this.validBlocks = ImmutableSet.copyOf(validBlocksTemp);
|
||||
this.validBlocks = Set.copyOf(validBlocksTemp);
|
||||
} else {
|
||||
this.validBlocks = Collections.singleton(BlockUtils.getCleanIdentifier(javaBlockIdentifier));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
|
||||
public boolean prepareInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
|
||||
// Check to see if there is an existing block we can use that the player just selected.
|
||||
// First, verify that the player's position has not changed, so we don't try to select a block wildly out of range.
|
||||
// (This could be a virtual inventory that the player is opening)
|
||||
|
@ -83,13 +83,16 @@ public class BlockInventoryHolder extends InventoryHolder {
|
|||
inventory.setHolderPosition(session.getLastInteractionBlockPosition());
|
||||
((Container) inventory).setUsingRealBlock(true, javaBlockString[0]);
|
||||
setCustomName(session, session.getLastInteractionBlockPosition(), inventory, javaBlockId);
|
||||
return;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, time to conjure up a fake block!
|
||||
Vector3i position = session.getPlayerEntity().getPosition().toInt();
|
||||
position = position.add(Vector3i.UP);
|
||||
Vector3i position = InventoryUtils.findAvailableWorldSpace(session);
|
||||
if (position == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
|
||||
blockPacket.setDataLayer(0);
|
||||
blockPacket.setBlockPosition(position);
|
||||
|
@ -99,6 +102,8 @@ public class BlockInventoryHolder extends InventoryHolder {
|
|||
inventory.setHolderPosition(position);
|
||||
|
||||
setCustomName(session, position, inventory, defaultJavaBlockState);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.geysermc.geyser.session.GeyserSession;
|
|||
import org.geysermc.geyser.translator.inventory.InventoryTranslator;
|
||||
|
||||
public abstract class InventoryHolder {
|
||||
public abstract void prepareInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory);
|
||||
public abstract boolean prepareInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory);
|
||||
public abstract void openInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory);
|
||||
public abstract void closeInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory);
|
||||
}
|
||||
|
|
|
@ -32,43 +32,41 @@ import lombok.Getter;
|
|||
* It is used to construct the list for the settings menu
|
||||
*/
|
||||
public enum GameRule {
|
||||
ANNOUNCEADVANCEMENTS("announceAdvancements", Boolean.class, true), // JE only
|
||||
COMMANDBLOCKOUTPUT("commandBlockOutput", Boolean.class, true),
|
||||
DISABLEELYTRAMOVEMENTCHECK("disableElytraMovementCheck", Boolean.class, false), // JE only
|
||||
DISABLERAIDS("disableRaids", Boolean.class, false), // JE only
|
||||
DODAYLIGHTCYCLE("doDaylightCycle", Boolean.class, true),
|
||||
DOENTITYDROPS("doEntityDrops", Boolean.class, true),
|
||||
DOFIRETICK("doFireTick", Boolean.class, true),
|
||||
DOIMMEDIATERESPAWN("doImmediateRespawn", Boolean.class, false),
|
||||
DOINSOMNIA("doInsomnia", Boolean.class, true),
|
||||
DOLIMITEDCRAFTING("doLimitedCrafting", Boolean.class, false), // JE only
|
||||
DOMOBLOOT("doMobLoot", Boolean.class, true),
|
||||
DOMOBSPAWNING("doMobSpawning", Boolean.class, true),
|
||||
DOPATROLSPAWNING("doPatrolSpawning", Boolean.class, true), // JE only
|
||||
DOTILEDROPS("doTileDrops", Boolean.class, true),
|
||||
DOTRADERSPAWNING("doTraderSpawning", Boolean.class, true), // JE only
|
||||
DOWEATHERCYCLE("doWeatherCycle", Boolean.class, true),
|
||||
DROWNINGDAMAGE("drowningDamage", Boolean.class, true),
|
||||
FALLDAMAGE("fallDamage", Boolean.class, true),
|
||||
FIREDAMAGE("fireDamage", Boolean.class, true),
|
||||
FREEZEDAMAGE("freezeDamage", Boolean.class, true),
|
||||
FORGIVEDEADPLAYERS("forgiveDeadPlayers", Boolean.class, true), // JE only
|
||||
KEEPINVENTORY("keepInventory", Boolean.class, false),
|
||||
LOGADMINCOMMANDS("logAdminCommands", Boolean.class, true), // JE only
|
||||
MAXCOMMANDCHAINLENGTH("maxCommandChainLength", Integer.class, 65536),
|
||||
MAXENTITYCRAMMING("maxEntityCramming", Integer.class, 24), // JE only
|
||||
MOBGRIEFING("mobGriefing", Boolean.class, true),
|
||||
NATURALREGENERATION("naturalRegeneration", Boolean.class, true),
|
||||
PLAYERSSLEEPINGPERCENTAGE("playersSleepingPercentage", Integer.class, 100), // JE only
|
||||
RANDOMTICKSPEED("randomTickSpeed", Integer.class, 3),
|
||||
REDUCEDDEBUGINFO("reducedDebugInfo", Boolean.class, false), // JE only
|
||||
SENDCOMMANDFEEDBACK("sendCommandFeedback", Boolean.class, true),
|
||||
SHOWDEATHMESSAGES("showDeathMessages", Boolean.class, true),
|
||||
SPAWNRADIUS("spawnRadius", Integer.class, 10),
|
||||
SPECTATORSGENERATECHUNKS("spectatorsGenerateChunks", Boolean.class, true), // JE only
|
||||
UNIVERSALANGER("universalAnger", Boolean.class, false), // JE only
|
||||
|
||||
UNKNOWN("unknown", Object.class);
|
||||
ANNOUNCEADVANCEMENTS("announceAdvancements", true), // JE only
|
||||
COMMANDBLOCKOUTPUT("commandBlockOutput", true),
|
||||
DISABLEELYTRAMOVEMENTCHECK("disableElytraMovementCheck", false), // JE only
|
||||
DISABLERAIDS("disableRaids", false), // JE only
|
||||
DODAYLIGHTCYCLE("doDaylightCycle", true),
|
||||
DOENTITYDROPS("doEntityDrops", true),
|
||||
DOFIRETICK("doFireTick", true),
|
||||
DOIMMEDIATERESPAWN("doImmediateRespawn", false),
|
||||
DOINSOMNIA("doInsomnia", true),
|
||||
DOLIMITEDCRAFTING("doLimitedCrafting", false), // JE only
|
||||
DOMOBLOOT("doMobLoot", true),
|
||||
DOMOBSPAWNING("doMobSpawning", true),
|
||||
DOPATROLSPAWNING("doPatrolSpawning", true), // JE only
|
||||
DOTILEDROPS("doTileDrops", true),
|
||||
DOTRADERSPAWNING("doTraderSpawning", true), // JE only
|
||||
DOWEATHERCYCLE("doWeatherCycle", true),
|
||||
DROWNINGDAMAGE("drowningDamage", true),
|
||||
FALLDAMAGE("fallDamage", true),
|
||||
FIREDAMAGE("fireDamage", true),
|
||||
FREEZEDAMAGE("freezeDamage", true),
|
||||
FORGIVEDEADPLAYERS("forgiveDeadPlayers", true), // JE only
|
||||
KEEPINVENTORY("keepInventory", false),
|
||||
LOGADMINCOMMANDS("logAdminCommands", true), // JE only
|
||||
MAXCOMMANDCHAINLENGTH("maxCommandChainLength", 65536),
|
||||
MAXENTITYCRAMMING("maxEntityCramming", 24), // JE only
|
||||
MOBGRIEFING("mobGriefing", true),
|
||||
NATURALREGENERATION("naturalRegeneration", true),
|
||||
PLAYERSSLEEPINGPERCENTAGE("playersSleepingPercentage", 100), // JE only
|
||||
RANDOMTICKSPEED("randomTickSpeed", 3),
|
||||
REDUCEDDEBUGINFO("reducedDebugInfo", false), // JE only
|
||||
SENDCOMMANDFEEDBACK("sendCommandFeedback", true),
|
||||
SHOWDEATHMESSAGES("showDeathMessages", true),
|
||||
SPAWNRADIUS("spawnRadius", 10),
|
||||
SPECTATORSGENERATECHUNKS("spectatorsGenerateChunks", true), // JE only
|
||||
UNIVERSALANGER("universalAnger", false); // JE only
|
||||
|
||||
public static final GameRule[] VALUES = values();
|
||||
|
||||
|
@ -78,48 +76,25 @@ public enum GameRule {
|
|||
@Getter
|
||||
private final Class<?> type;
|
||||
|
||||
@Getter
|
||||
private final Object defaultValue;
|
||||
private final int defaultValue;
|
||||
|
||||
GameRule(String javaID, Class<?> type) {
|
||||
this(javaID, type, null);
|
||||
GameRule(String javaID, boolean defaultValue) {
|
||||
this.javaID = javaID;
|
||||
this.type = Boolean.class;
|
||||
this.defaultValue = defaultValue ? 1 : 0;
|
||||
}
|
||||
|
||||
GameRule(String javaID, Class<?> type, Object defaultValue) {
|
||||
GameRule(String javaID, int defaultValue) {
|
||||
this.javaID = javaID;
|
||||
this.type = type;
|
||||
this.type = Integer.class;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string to an object of the correct type for the current gamerule
|
||||
*
|
||||
* @param value The string value to convert
|
||||
* @return The converted and formatted value
|
||||
*/
|
||||
public Object convertValue(String value) {
|
||||
if (type.equals(Boolean.class)) {
|
||||
return Boolean.parseBoolean(value);
|
||||
} else if (type.equals(Integer.class)) {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
|
||||
return null;
|
||||
public boolean getDefaultBooleanValue() {
|
||||
return defaultValue != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a game rule by the given Java ID
|
||||
*
|
||||
* @param id The ID of the gamerule
|
||||
* @return A {@link GameRule} object representing the requested ID or {@link GameRule#UNKNOWN}
|
||||
*/
|
||||
public static GameRule fromJavaID(String id) {
|
||||
for (GameRule gamerule : VALUES) {
|
||||
if (gamerule.javaID.equals(id)) {
|
||||
return gamerule;
|
||||
}
|
||||
}
|
||||
|
||||
return UNKNOWN;
|
||||
public int getDefaultIntValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
|
||||
package org.geysermc.geyser.level;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.nbt.NbtMapBuilder;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
|
@ -36,11 +34,8 @@ import org.geysermc.geyser.session.GeyserSession;
|
|||
import org.geysermc.geyser.session.cache.ChunkCache;
|
||||
import org.geysermc.geyser.translator.inventory.LecternInventoryTranslator;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class GeyserWorldManager extends WorldManager {
|
||||
|
||||
private static final Object2ObjectMap<String, String> gameruleCache = new Object2ObjectOpenHashMap<>();
|
||||
private final Object2ObjectMap<String, String> gameruleCache = new Object2ObjectOpenHashMap<>();
|
||||
|
||||
@Override
|
||||
public int getBlockAt(GeyserSession session, int x, int y, int z) {
|
||||
|
@ -82,18 +77,18 @@ public class GeyserWorldManager extends WorldManager {
|
|||
|
||||
@Override
|
||||
public void setGameRule(GeyserSession session, String name, Object value) {
|
||||
session.sendCommand("gamerule " + name + " " + value);
|
||||
super.setGameRule(session, name, value);
|
||||
gameruleCache.put(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getGameRuleBool(GeyserSession session, GameRule gameRule) {
|
||||
public boolean getGameRuleBool(GeyserSession session, GameRule gameRule) {
|
||||
String value = gameruleCache.get(gameRule.getJavaID());
|
||||
if (value != null) {
|
||||
return Boolean.parseBoolean(value);
|
||||
}
|
||||
|
||||
return gameRule.getDefaultValue() != null ? (Boolean) gameRule.getDefaultValue() : false;
|
||||
return gameRule.getDefaultBooleanValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -103,17 +98,7 @@ public class GeyserWorldManager extends WorldManager {
|
|||
return Integer.parseInt(value);
|
||||
}
|
||||
|
||||
return gameRule.getDefaultValue() != null ? (int) gameRule.getDefaultValue() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerGameMode(GeyserSession session, GameMode gameMode) {
|
||||
session.sendCommand("gamemode " + gameMode.name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDifficulty(GeyserSession session, Difficulty difficulty) {
|
||||
session.sendCommand("difficulty " + difficulty.name().toLowerCase(Locale.ROOT));
|
||||
return gameRule.getDefaultIntValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,9 +27,15 @@ package org.geysermc.geyser.level;
|
|||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.setting.Difficulty;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Class that manages or retrieves various information
|
||||
|
@ -105,7 +111,9 @@ public abstract class WorldManager {
|
|||
* @param name The gamerule to change
|
||||
* @param value The new value for the gamerule
|
||||
*/
|
||||
public abstract void setGameRule(GeyserSession session, String name, Object value);
|
||||
public void setGameRule(GeyserSession session, String name, Object value) {
|
||||
session.sendCommand("gamerule " + name + " " + value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a gamerule value as a boolean
|
||||
|
@ -114,7 +122,7 @@ public abstract class WorldManager {
|
|||
* @param gameRule The gamerule to fetch the value of
|
||||
* @return The boolean representation of the value
|
||||
*/
|
||||
public abstract Boolean getGameRuleBool(GeyserSession session, GameRule gameRule);
|
||||
public abstract boolean getGameRuleBool(GeyserSession session, GameRule gameRule);
|
||||
|
||||
/**
|
||||
* Get a gamerule value as an integer
|
||||
|
@ -131,7 +139,9 @@ public abstract class WorldManager {
|
|||
* @param session The session of the player to change the game mode of
|
||||
* @param gameMode The game mode to change the player to
|
||||
*/
|
||||
public abstract void setPlayerGameMode(GeyserSession session, GameMode gameMode);
|
||||
public void setPlayerGameMode(GeyserSession session, GameMode gameMode) {
|
||||
session.sendCommand("gamemode " + gameMode.name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the difficulty of the Java server
|
||||
|
@ -139,7 +149,9 @@ public abstract class WorldManager {
|
|||
* @param session The session of the user that requested the change
|
||||
* @param difficulty The difficulty to change to
|
||||
*/
|
||||
public abstract void setDifficulty(GeyserSession session, Difficulty difficulty);
|
||||
public void setDifficulty(GeyserSession session, Difficulty difficulty) {
|
||||
session.sendCommand("difficulty " + difficulty.name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given session's player has a permission
|
||||
|
@ -149,4 +161,22 @@ public abstract class WorldManager {
|
|||
* @return True if the player has the requested permission, false if not
|
||||
*/
|
||||
public abstract boolean hasPermission(GeyserSession session, String permission);
|
||||
|
||||
/**
|
||||
* Returns a list of biome identifiers available on the server.
|
||||
*/
|
||||
@Nullable
|
||||
public String[] getBiomeIdentifiers(boolean withTags) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for pick block, so we don't need to cache more data than necessary.
|
||||
*
|
||||
* @return expected NBT for this item.
|
||||
*/
|
||||
@Nonnull
|
||||
public CompletableFuture<@Nullable CompoundTag> getPickItemNbt(GeyserSession session, int x, int y, int z, boolean addNbtData) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,13 +125,9 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
|
|||
pong.setSubMotd(config.getBedrock().secondaryMotd());
|
||||
}
|
||||
|
||||
if (config.isPassthroughPlayerCounts() && pingInfo != null) {
|
||||
pong.setPlayerCount(pingInfo.getPlayers().getOnline());
|
||||
pong.setMaximumPlayerCount(pingInfo.getPlayers().getMax());
|
||||
} else {
|
||||
pong.setPlayerCount(geyser.getSessionManager().getSessions().size());
|
||||
pong.setMaximumPlayerCount(config.getMaxPlayers());
|
||||
}
|
||||
// https://github.com/GeyserMC/Geyser/issues/3388
|
||||
pong.setMotd(pong.getMotd().replace(';', ':'));
|
||||
pong.setSubMotd(pong.getSubMotd().replace(';', ':'));
|
||||
|
||||
// Fallbacks to prevent errors and allow Bedrock to see the server
|
||||
if (pong.getMotd() == null || pong.getMotd().isBlank()) {
|
||||
|
@ -160,6 +156,14 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
if (config.isPassthroughPlayerCounts() && pingInfo != null) {
|
||||
pong.setPlayerCount(pingInfo.getPlayers().getOnline());
|
||||
pong.setMaximumPlayerCount(pingInfo.getPlayers().getMax());
|
||||
} else {
|
||||
pong.setPlayerCount(geyser.getSessionManager().getSessions().size());
|
||||
pong.setMaximumPlayerCount(config.getMaxPlayers());
|
||||
}
|
||||
|
||||
//Bedrock will not even attempt a connection if the client thinks the server is full
|
||||
//so we have to fake it not being full
|
||||
if (pong.getPlayerCount() >= pong.getMaximumPlayerCount()) {
|
||||
|
|
|
@ -28,12 +28,11 @@ package org.geysermc.geyser.network;
|
|||
import com.github.steveice10.mc.protocol.codec.MinecraftCodec;
|
||||
import com.github.steveice10.mc.protocol.codec.PacketCodec;
|
||||
import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
|
||||
import com.nukkitx.protocol.bedrock.v527.Bedrock_v527;
|
||||
import com.nukkitx.protocol.bedrock.v534.Bedrock_v534;
|
||||
import com.nukkitx.protocol.bedrock.v544.Bedrock_v544;
|
||||
import com.nukkitx.protocol.bedrock.v545.Bedrock_v545;
|
||||
import com.nukkitx.protocol.bedrock.v554.Bedrock_v554;
|
||||
import com.nukkitx.protocol.bedrock.v557.Bedrock_v557;
|
||||
import com.nukkitx.protocol.bedrock.v560.Bedrock_v560;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -48,7 +47,7 @@ public final class GameProtocol {
|
|||
* Default Bedrock codec that should act as a fallback. Should represent the latest available
|
||||
* release of the game that Geyser supports.
|
||||
*/
|
||||
public static final BedrockPacketCodec DEFAULT_BEDROCK_CODEC = Bedrock_v557.V557_CODEC;
|
||||
public static final BedrockPacketCodec DEFAULT_BEDROCK_CODEC = Bedrock_v560.V560_CODEC;
|
||||
/**
|
||||
* A list of all supported Bedrock versions that can join Geyser
|
||||
*/
|
||||
|
@ -61,12 +60,6 @@ public final class GameProtocol {
|
|||
private static final PacketCodec DEFAULT_JAVA_CODEC = MinecraftCodec.CODEC;
|
||||
|
||||
static {
|
||||
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v527.V527_CODEC.toBuilder()
|
||||
.minecraftVersion("1.19.0/1.19.2")
|
||||
.build());
|
||||
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v534.V534_CODEC.toBuilder()
|
||||
.minecraftVersion("1.19.10/1.19.11")
|
||||
.build());
|
||||
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v544.V544_CODEC);
|
||||
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v545.V545_CODEC.toBuilder()
|
||||
.minecraftVersion("1.19.21/1.19.22")
|
||||
|
@ -74,7 +67,12 @@ public final class GameProtocol {
|
|||
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v554.V554_CODEC.toBuilder()
|
||||
.minecraftVersion("1.19.30/1.19.31")
|
||||
.build());
|
||||
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC);
|
||||
SUPPORTED_BEDROCK_CODECS.add(Bedrock_v557.V557_CODEC.toBuilder()
|
||||
.minecraftVersion("1.19.40/1.19.41")
|
||||
.build());
|
||||
SUPPORTED_BEDROCK_CODECS.add(DEFAULT_BEDROCK_CODEC.toBuilder()
|
||||
.minecraftVersion("1.19.50/1.19.51")
|
||||
.build());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,14 +91,14 @@ public final class GameProtocol {
|
|||
|
||||
/* Bedrock convenience methods to gatekeep features and easily remove the check on version removal */
|
||||
|
||||
public static boolean supports1_19_10(GeyserSession session) {
|
||||
return session.getUpstream().getProtocolVersion() >= Bedrock_v534.V534_CODEC.getProtocolVersion();
|
||||
}
|
||||
|
||||
public static boolean supports1_19_30(GeyserSession session) {
|
||||
return session.getUpstream().getProtocolVersion() >= Bedrock_v554.V554_CODEC.getProtocolVersion();
|
||||
}
|
||||
|
||||
public static boolean supports1_19_50(GeyserSession session) {
|
||||
return session.getUpstream().getProtocolVersion() >= Bedrock_v560.V560_CODEC.getProtocolVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link PacketCodec} for Minecraft: Java Edition.
|
||||
*
|
||||
|
@ -116,7 +114,7 @@ public final class GameProtocol {
|
|||
* @return the supported Minecraft: Java Edition version names
|
||||
*/
|
||||
public static List<String> getJavaVersions() {
|
||||
return List.of(DEFAULT_JAVA_CODEC.getMinecraftVersion(), "1.19.2");
|
||||
return List.of(DEFAULT_JAVA_CODEC.getMinecraftVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,9 +46,13 @@ import org.geysermc.geyser.util.MathUtils;
|
|||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
|
||||
public class UpstreamPacketHandler extends LoggingPacketHandler {
|
||||
|
||||
private Deque<String> packsToSent = new ArrayDeque<>();
|
||||
|
||||
public UpstreamPacketHandler(GeyserImpl geyser, GeyserSession session) {
|
||||
super(geyser, session);
|
||||
}
|
||||
|
@ -161,24 +165,8 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
|
|||
break;
|
||||
|
||||
case SEND_PACKS:
|
||||
for(String id : packet.getPackIds()) {
|
||||
ResourcePackDataInfoPacket data = new ResourcePackDataInfoPacket();
|
||||
String[] packID = id.split("_");
|
||||
ResourcePack pack = ResourcePack.PACKS.get(packID[0]);
|
||||
ResourcePackManifest.Header header = pack.getManifest().getHeader();
|
||||
|
||||
data.setPackId(header.getUuid());
|
||||
int chunkCount = (int) Math.ceil((int) pack.getFile().length() / (double) ResourcePack.CHUNK_SIZE);
|
||||
data.setChunkCount(chunkCount);
|
||||
data.setCompressedPackSize(pack.getFile().length());
|
||||
data.setMaxChunkSize(ResourcePack.CHUNK_SIZE);
|
||||
data.setHash(pack.getSha256());
|
||||
data.setPackVersion(packID[1]);
|
||||
data.setPremium(false);
|
||||
data.setType(ResourcePackType.RESOURCE);
|
||||
|
||||
session.sendUpstreamPacket(data);
|
||||
}
|
||||
packsToSent.addAll(packet.getPackIds());
|
||||
sendPackDataInfo(packsToSent.pop());
|
||||
break;
|
||||
|
||||
case HAVE_ALL_PACKS:
|
||||
|
@ -271,7 +259,8 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
|
|||
data.setPackId(packet.getPackId());
|
||||
|
||||
int offset = packet.getChunkIndex() * ResourcePack.CHUNK_SIZE;
|
||||
byte[] packData = new byte[(int) MathUtils.constrain(pack.getFile().length() - offset, 0, ResourcePack.CHUNK_SIZE)];
|
||||
long remainingSize = pack.getFile().length() - offset;
|
||||
byte[] packData = new byte[(int) MathUtils.constrain(remainingSize, 0, ResourcePack.CHUNK_SIZE)];
|
||||
|
||||
try (InputStream inputStream = new FileInputStream(pack.getFile())) {
|
||||
inputStream.skip(offset);
|
||||
|
@ -283,6 +272,31 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
|
|||
data.setData(packData);
|
||||
|
||||
session.sendUpstreamPacket(data);
|
||||
|
||||
// Check if it is the last chunk and send next pack in queue when available.
|
||||
if (remainingSize <= ResourcePack.CHUNK_SIZE && !packsToSent.isEmpty()) {
|
||||
sendPackDataInfo(packsToSent.pop());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendPackDataInfo(String id) {
|
||||
ResourcePackDataInfoPacket data = new ResourcePackDataInfoPacket();
|
||||
String[] packID = id.split("_");
|
||||
ResourcePack pack = ResourcePack.PACKS.get(packID[0]);
|
||||
ResourcePackManifest.Header header = pack.getManifest().getHeader();
|
||||
|
||||
data.setPackId(header.getUuid());
|
||||
int chunkCount = (int) Math.ceil((int) pack.getFile().length() / (double) ResourcePack.CHUNK_SIZE);
|
||||
data.setChunkCount(chunkCount);
|
||||
data.setCompressedPackSize(pack.getFile().length());
|
||||
data.setMaxChunkSize(ResourcePack.CHUNK_SIZE);
|
||||
data.setHash(pack.getSha256());
|
||||
data.setPackVersion(packID[1]);
|
||||
data.setPremium(false);
|
||||
data.setType(ResourcePackType.RESOURCE);
|
||||
|
||||
session.sendUpstreamPacket(data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -181,12 +181,15 @@ public final class Registries {
|
|||
POTION_MIXES = SimpleRegistry.create(PotionMixRegistryLoader::new);
|
||||
ENCHANTMENTS = SimpleMappedRegistry.create("mappings/enchantments.json", EnchantmentRegistryLoader::new);
|
||||
|
||||
// TEMPORARY FIX TO MAKE OLD BIOMES NBT WORK WITH 1.19.30
|
||||
// Remove unneeded client generation data from NbtMapBuilder
|
||||
NbtMapBuilder biomesNbt = NbtMap.builder();
|
||||
for (Map.Entry<String, Object> entry : BIOMES_NBT.get().entrySet()) {
|
||||
String key = entry.getKey();
|
||||
NbtMapBuilder value = ((NbtMap) entry.getValue()).toBuilder();
|
||||
value.put("name_hash", key);
|
||||
value.remove("minecraft:consolidated_features");
|
||||
value.remove("minecraft:multinoise_generation_rules");
|
||||
value.remove("minecraft:surface_material_adjustments");
|
||||
value.remove( "minecraft:surface_parameters");
|
||||
biomesNbt.put(key, value.build());
|
||||
}
|
||||
BIOMES_NBT.set(biomesNbt.build());
|
||||
|
|
|
@ -31,6 +31,7 @@ import com.google.common.collect.ImmutableMap;
|
|||
import com.nukkitx.nbt.*;
|
||||
import com.nukkitx.protocol.bedrock.v527.Bedrock_v527;
|
||||
import com.nukkitx.protocol.bedrock.v544.Bedrock_v544;
|
||||
import com.nukkitx.protocol.bedrock.v560.Bedrock_v560;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
|
@ -73,13 +74,9 @@ public final class BlockRegistryPopulator {
|
|||
private static void registerBedrockBlocks() {
|
||||
BiFunction<String, NbtMapBuilder, String> emptyMapper = (bedrockIdentifier, statesBuilder) -> null;
|
||||
ImmutableMap<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>> blockMappers = ImmutableMap.<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>>builder()
|
||||
.put(ObjectIntPair.of("1_19_0", Bedrock_v527.V527_CODEC.getProtocolVersion()), (bedrockIdentifier, statesBuilder) -> {
|
||||
if (bedrockIdentifier.equals("minecraft:muddy_mangrove_roots")) {
|
||||
statesBuilder.remove("pillar_axis");
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.put(ObjectIntPair.of("1_19_20", Bedrock_v544.V544_CODEC.getProtocolVersion()), emptyMapper).build();
|
||||
.put(ObjectIntPair.of("1_19_20", Bedrock_v544.V544_CODEC.getProtocolVersion()), emptyMapper)
|
||||
.put(ObjectIntPair.of("1_19_50", Bedrock_v560.V560_CODEC.getProtocolVersion()), emptyMapper)
|
||||
.build();
|
||||
|
||||
for (Map.Entry<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>> palette : blockMappers.entrySet()) {
|
||||
NbtList<NbtMap> blocksTag;
|
||||
|
|
|
@ -124,6 +124,33 @@ public class CustomItemRegistryPopulator {
|
|||
computeArmorProperties(mapping.getArmorType(), mapping.getProtectionValue(), componentBuilder);
|
||||
}
|
||||
|
||||
if (mapping.getFirstBlockRuntimeId() != null) {
|
||||
computeBlockItemProperties(mapping.getBedrockIdentifier(), componentBuilder);
|
||||
}
|
||||
|
||||
if (mapping.isEdible()) {
|
||||
computeConsumableProperties(itemProperties, componentBuilder, 1, false);
|
||||
}
|
||||
|
||||
if (mapping.isEntityPlacer()) {
|
||||
computeEntityPlacerProperties(componentBuilder);
|
||||
}
|
||||
|
||||
switch (mapping.getBedrockIdentifier()) {
|
||||
case "minecraft:fire_charge", "minecraft:flint_and_steel" -> {
|
||||
computeBlockItemProperties("minecraft:fire", componentBuilder);
|
||||
}
|
||||
case "minecraft:bow", "minecraft:crossbow", "minecraft:trident" -> {
|
||||
computeChargeableProperties(itemProperties, componentBuilder);
|
||||
}
|
||||
case "minecraft:honey_bottle", "minecraft:milk_bucket", "minecraft:potion" -> {
|
||||
computeConsumableProperties(itemProperties, componentBuilder, 2, true);
|
||||
}
|
||||
case "minecraft:experience_bottle", "minecraft:egg", "minecraft:ender_pearl", "minecraft:ender_eye", "minecraft:lingering_potion", "minecraft:snowball", "minecraft:splash_potion" -> {
|
||||
computeThrowableProperties(componentBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
computeRenderOffsets(false, customItemData, componentBuilder);
|
||||
|
||||
componentBuilder.putCompound("item_properties", itemProperties.build());
|
||||
|
@ -260,6 +287,48 @@ public class CustomItemRegistryPopulator {
|
|||
}
|
||||
}
|
||||
|
||||
private static void computeBlockItemProperties(String blockItem, NbtMapBuilder componentBuilder) {
|
||||
// carved pumpkin should be able to be worn and for that we would need to add wearable and armor with protection 0 here
|
||||
// however this would have the side effect of preventing carved pumpkins from working as an attachable on the RP side outside the head slot
|
||||
// it also causes the item to glitch when right clicked to "equip" so this should only be added here later if these issues can be overcome
|
||||
|
||||
// all block items registered should be given this component to prevent double placement
|
||||
componentBuilder.putCompound("minecraft:block_placer", NbtMap.builder().putString("block", blockItem).build());
|
||||
}
|
||||
|
||||
private static void computeChargeableProperties(NbtMapBuilder itemProperties, NbtMapBuilder componentBuilder) {
|
||||
// setting high use_duration prevents the consume animation from playing
|
||||
itemProperties.putInt("use_duration", Integer.MAX_VALUE);
|
||||
// display item as tool (mainly for crossbow and bow)
|
||||
itemProperties.putBoolean("hand_equipped", true);
|
||||
// ensure client moves at slow speed while charging (note: this was calculated by hand as the movement modifer value does not seem to scale linearly)
|
||||
componentBuilder.putCompound("minecraft:chargeable", NbtMap.builder().putFloat("movement_modifier", 0.35F).build());
|
||||
}
|
||||
|
||||
private static void computeConsumableProperties(NbtMapBuilder itemProperties, NbtMapBuilder componentBuilder, int useAnimation, boolean canAlwaysEat) {
|
||||
// this is the duration of the use animation in ticks; note that in behavior packs this is set as a float in seconds, but over the network it is an int in ticks
|
||||
itemProperties.putInt("use_duration", 32);
|
||||
// this dictates that the item will use the eat or drink animation (in the first person) and play eat or drink sounds
|
||||
// note that in behavior packs this is set as the string "eat" or "drink", but over the network it as an int, with these values being 1 and 2 respectively
|
||||
itemProperties.putInt("use_animation", useAnimation);
|
||||
// this component is required to allow the eat animation to play
|
||||
componentBuilder.putCompound("minecraft:food", NbtMap.builder().putBoolean("can_always_eat", canAlwaysEat).build());
|
||||
}
|
||||
|
||||
private static void computeEntityPlacerProperties(NbtMapBuilder componentBuilder) {
|
||||
// all items registered that place entities should be given this component to prevent double placement
|
||||
// it is okay that the entity here does not match the actual one since we control what entity actually spawns
|
||||
componentBuilder.putCompound("minecraft:entity_placer", NbtMap.builder().putString("entity", "minecraft:minecart").build());
|
||||
}
|
||||
|
||||
private static void computeThrowableProperties(NbtMapBuilder componentBuilder) {
|
||||
// allows item to be thrown when holding down right click (individual presses are required w/o this component)
|
||||
componentBuilder.putCompound("minecraft:throwable", NbtMap.builder().putBoolean("do_swing_animation", true).build());
|
||||
// this must be set to something for the swing animation to play
|
||||
// it is okay that the projectile here does not match the actual one since we control what entity actually spawns
|
||||
componentBuilder.putCompound("minecraft:projectile", NbtMap.builder().putString("projectile_entity", "minecraft:snowball").build());
|
||||
}
|
||||
|
||||
private static void computeRenderOffsets(boolean isHat, CustomItemData customItemData, NbtMapBuilder componentBuilder) {
|
||||
if (isHat) {
|
||||
componentBuilder.remove("minecraft:render_offsets");
|
||||
|
|
|
@ -37,6 +37,7 @@ import com.nukkitx.protocol.bedrock.data.SoundEvent;
|
|||
import com.nukkitx.protocol.bedrock.data.inventory.ComponentItemData;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
||||
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
||||
import com.nukkitx.protocol.bedrock.v560.Bedrock_v560;
|
||||
import it.unimi.dsi.fastutil.ints.*;
|
||||
import com.nukkitx.protocol.bedrock.v527.Bedrock_v527;
|
||||
import com.nukkitx.protocol.bedrock.v534.Bedrock_v534;
|
||||
|
@ -76,10 +77,8 @@ public class ItemRegistryPopulator {
|
|||
|
||||
public static void populate() {
|
||||
Map<String, PaletteVersion> paletteVersions = new Object2ObjectOpenHashMap<>();
|
||||
paletteVersions.put("1_19_0", new PaletteVersion(Bedrock_v527.V527_CODEC.getProtocolVersion(),
|
||||
Collections.singletonMap("minecraft:trader_llama_spawn_egg", "minecraft:llama_spawn_egg")));
|
||||
paletteVersions.put("1_19_10", new PaletteVersion(Bedrock_v534.V534_CODEC.getProtocolVersion(), Collections.emptyMap()));
|
||||
paletteVersions.put("1_19_20", new PaletteVersion(Bedrock_v544.V544_CODEC.getProtocolVersion(), Collections.emptyMap()));
|
||||
paletteVersions.put("1_19_50", new PaletteVersion(Bedrock_v560.V560_CODEC.getProtocolVersion(), Collections.emptyMap()));
|
||||
|
||||
GeyserBootstrap bootstrap = GeyserImpl.getInstance().getBootstrap();
|
||||
|
||||
|
|
|
@ -82,8 +82,6 @@ public class RecipeRegistryPopulator {
|
|||
Collections.singletonList(CraftingData.fromMulti(UUID.fromString("d392b075-4ba1-40ae-8789-af868d56f6ce"), ++LAST_RECIPE_NET_ID)));
|
||||
craftingData.put(RecipeType.CRAFTING_SPECIAL_MAPCLONING,
|
||||
Collections.singletonList(CraftingData.fromMulti(UUID.fromString("85939755-ba10-4d9d-a4cc-efb7a8e943c4"), ++LAST_RECIPE_NET_ID)));
|
||||
craftingData.put(RecipeType.CRAFTING_SPECIAL_BANNERADDPATTERN,
|
||||
Collections.singletonList(CraftingData.fromMulti(UUID.fromString("b5c5d105-75a2-4076-af2b-923ea2bf4bf0"), ++LAST_RECIPE_NET_ID)));
|
||||
|
||||
// https://github.com/pmmp/PocketMine-MP/blob/stable/src/pocketmine/inventory/MultiRecipe.php
|
||||
|
||||
|
|
|
@ -48,4 +48,6 @@ public class GeyserMappingItem {
|
|||
@JsonProperty("repair_materials") List<String> repairMaterials;
|
||||
@JsonProperty("has_suspicious_stew_effect") boolean hasSuspiciousStewEffect = false;
|
||||
@JsonProperty("dye_color") int dyeColor = -1;
|
||||
@JsonProperty("is_edible") boolean edible = false;
|
||||
@JsonProperty("is_entity_placer") boolean entityPlacer = false;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.nukkitx.protocol.bedrock.data.ScoreInfo;
|
|||
import com.nukkitx.protocol.bedrock.packet.RemoveObjectivePacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.SetDisplayObjectivePacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.SetScorePacket;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import lombok.Getter;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.GeyserLogger;
|
||||
|
@ -37,6 +38,7 @@ import org.geysermc.geyser.entity.type.Entity;
|
|||
import org.geysermc.geyser.entity.type.player.PlayerEntity;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
@ -55,6 +57,13 @@ public final class Scoreboard {
|
|||
@Getter
|
||||
private final Map<ScoreboardPosition, Objective> objectiveSlots = new EnumMap<>(ScoreboardPosition.class);
|
||||
private final Map<String, Team> teams = new ConcurrentHashMap<>(); // updated on multiple threads
|
||||
/**
|
||||
* Required to preserve vanilla behavior, which also uses a map.
|
||||
* Otherwise, for example, if TAB has a team for a player and vanilla has a team, "race conditions" that do not
|
||||
* match vanilla could occur.
|
||||
*/
|
||||
@Getter
|
||||
private final Map<String, Team> playerToTeam = new Object2ObjectOpenHashMap<>();
|
||||
|
||||
private int lastAddScoreCount = 0;
|
||||
private int lastRemoveScoreCount = 0;
|
||||
|
@ -132,6 +141,10 @@ public final class Scoreboard {
|
|||
team = new Team(this, teamName);
|
||||
team.addEntities(players);
|
||||
teams.put(teamName, team);
|
||||
|
||||
// Update command parameters - is safe to send even if the command enum doesn't exist on the client (as of 1.19.51)
|
||||
session.addCommandEnum("Geyser_Teams", team.getId());
|
||||
|
||||
return team;
|
||||
}
|
||||
|
||||
|
@ -328,12 +341,7 @@ public final class Scoreboard {
|
|||
}
|
||||
|
||||
public Team getTeamFor(String entity) {
|
||||
for (Team team : teams.values()) {
|
||||
if (team.hasEntity(entity)) {
|
||||
return team;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return playerToTeam.get(entity);
|
||||
}
|
||||
|
||||
public void removeTeam(String teamName) {
|
||||
|
@ -343,9 +351,19 @@ public final class Scoreboard {
|
|||
// We need to use the direct entities list here, so #refreshSessionPlayerDisplays also updates accordingly
|
||||
// With the player's lack of a team in visibility checks
|
||||
updateEntityNames(remove, remove.getEntities(), true);
|
||||
for (String name : remove.getEntities()) {
|
||||
playerToTeam.remove(name, remove);
|
||||
}
|
||||
|
||||
session.removeCommandEnum("Geyser_Teams", remove.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Contract("-> new")
|
||||
public String[] getTeamNames() {
|
||||
return teams.keySet().toArray(new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the display names of all entities in a given team.
|
||||
* @param teamChange the players have either joined or left the team. Used for optimizations when just the display name updated.
|
||||
|
@ -368,7 +386,8 @@ public final class Scoreboard {
|
|||
for (Entity entity : session.getEntityCache().getEntities().values()) {
|
||||
// This more complex logic is for the future to iterate over all entities, not just players
|
||||
if (entity instanceof PlayerEntity player && names.remove(player.getUsername())) {
|
||||
player.updateDisplayName(team, true);
|
||||
player.updateDisplayName(team);
|
||||
player.updateBedrockMetadata();
|
||||
if (names.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
@ -384,7 +403,8 @@ public final class Scoreboard {
|
|||
for (Entity entity : session.getEntityCache().getEntities().values()) {
|
||||
if (entity instanceof PlayerEntity player) {
|
||||
Team playerTeam = session.getWorldCache().getScoreboard().getTeamFor(player.getUsername());
|
||||
player.updateDisplayName(playerTeam, true);
|
||||
player.updateDisplayName(playerTeam);
|
||||
player.updateBedrockMetadata();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ public final class Team {
|
|||
if (entities.add(name)) {
|
||||
added.add(name);
|
||||
}
|
||||
scoreboard.getPlayerToTeam().put(name, this);
|
||||
}
|
||||
|
||||
if (added.isEmpty()) {
|
||||
|
@ -93,6 +94,7 @@ public final class Team {
|
|||
if (entities.remove(name)) {
|
||||
removed.add(name);
|
||||
}
|
||||
scoreboard.getPlayerToTeam().remove(name, this);
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
|
|
@ -62,18 +62,18 @@ import com.github.steveice10.packetlib.event.session.*;
|
|||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
||||
import com.github.steveice10.packetlib.tcp.TcpSession;
|
||||
import com.nukkitx.math.GenericMath;
|
||||
import com.nukkitx.math.vector.*;
|
||||
import com.nukkitx.nbt.NbtMap;
|
||||
import com.nukkitx.protocol.bedrock.BedrockPacket;
|
||||
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
||||
import com.nukkitx.protocol.bedrock.data.*;
|
||||
import com.nukkitx.protocol.bedrock.data.command.CommandEnumData;
|
||||
import com.nukkitx.protocol.bedrock.data.command.CommandPermission;
|
||||
import com.nukkitx.protocol.bedrock.data.command.SoftEnumUpdateType;
|
||||
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
||||
import com.nukkitx.protocol.bedrock.packet.*;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.EventLoop;
|
||||
import it.unimi.dsi.fastutil.bytes.ByteArrays;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
|
@ -120,7 +120,6 @@ import org.geysermc.geyser.inventory.recipe.GeyserStonecutterData;
|
|||
import org.geysermc.geyser.level.JavaDimension;
|
||||
import org.geysermc.geyser.level.WorldManager;
|
||||
import org.geysermc.geyser.level.physics.CollisionManager;
|
||||
import org.geysermc.geyser.network.GameProtocol;
|
||||
import org.geysermc.geyser.network.netty.LocalSession;
|
||||
import org.geysermc.geyser.registry.Registries;
|
||||
import org.geysermc.geyser.registry.type.BlockMappings;
|
||||
|
@ -296,6 +295,11 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
*/
|
||||
@Setter
|
||||
private String worldName = null;
|
||||
/**
|
||||
* As of Java 1.19.3, the client only uses these for commands.
|
||||
*/
|
||||
@Setter
|
||||
private String[] levels;
|
||||
|
||||
private boolean sneaking;
|
||||
|
||||
|
@ -452,9 +456,8 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
|
||||
/**
|
||||
* Counts how many ticks have occurred since an arm animation started.
|
||||
* -1 means there is no active arm swing.
|
||||
* -1 means there is no active arm swing; -2 means an arm swing will start in a tick.
|
||||
*/
|
||||
@Getter(AccessLevel.NONE)
|
||||
private int armAnimationTicks = -1;
|
||||
|
||||
/**
|
||||
|
@ -534,6 +537,12 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
@Setter
|
||||
private ScheduledFuture<?> lookBackScheduledFuture = null;
|
||||
|
||||
/**
|
||||
* Used to return players back to their vehicles if the server doesn't want them unmounting.
|
||||
*/
|
||||
@Setter
|
||||
private ScheduledFuture<?> mountVehicleScheduledFuture = null;
|
||||
|
||||
private MinecraftProtocol protocol;
|
||||
|
||||
public GeyserSession(GeyserImpl geyser, BedrockServerSession bedrockServerSession, EventLoop eventLoop) {
|
||||
|
@ -627,6 +636,12 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
creativePacket.setContents(this.itemMappings.getCreativeItems());
|
||||
upstream.sendPacket(creativePacket);
|
||||
|
||||
// Potion mixes are registered by default, as they are needed to be able to put ingredients into the brewing stand.
|
||||
CraftingDataPacket craftingDataPacket = new CraftingDataPacket();
|
||||
craftingDataPacket.setCleanRecipes(true);
|
||||
craftingDataPacket.getPotionMixData().addAll(Registries.POTION_MIXES.get());
|
||||
upstream.sendPacket(craftingDataPacket);
|
||||
|
||||
PlayStatusPacket playStatusPacket = new PlayStatusPacket();
|
||||
playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
||||
upstream.sendPacket(playStatusPacket);
|
||||
|
@ -1063,6 +1078,17 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
closed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves task to the session event loop if already not in it. Otherwise, the task is automatically ran.
|
||||
*/
|
||||
public void ensureInEventLoop(Runnable runnable) {
|
||||
if (eventLoop.inEventLoop()) {
|
||||
runnable.run();
|
||||
return;
|
||||
}
|
||||
executeInEventLoop(runnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a task and prints a stack trace if an error occurs.
|
||||
*/
|
||||
|
@ -1133,7 +1159,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
entity.tick();
|
||||
}
|
||||
|
||||
if (armAnimationTicks != -1) {
|
||||
if (armAnimationTicks >= 0) {
|
||||
// As of 1.18.2 Java Edition, it appears that the swing time is dynamically updated depending on the
|
||||
// player's effect status, but the animation can cut short if the duration suddenly decreases
|
||||
// (from suddenly no longer having mining fatigue, for example)
|
||||
|
@ -1172,7 +1198,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
public void startSneaking() {
|
||||
// Toggle the shield, if there is no ongoing arm animation
|
||||
// This matches Bedrock Edition behavior as of 1.18.12
|
||||
if (armAnimationTicks == -1) {
|
||||
if (armAnimationTicks < 0) {
|
||||
attemptToBlock();
|
||||
}
|
||||
|
||||
|
@ -1304,6 +1330,16 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For https://github.com/GeyserMC/Geyser/issues/2113 and combating arm ticking activating being delayed in
|
||||
* BedrockAnimateTranslator.
|
||||
*/
|
||||
public void armSwingPending() {
|
||||
if (armAnimationTicks == -1) {
|
||||
armAnimationTicks = -2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates to the client to stop blocking and tells the Java server the same.
|
||||
*/
|
||||
|
@ -1357,18 +1393,21 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
* Sends a chat message to the Java server.
|
||||
*/
|
||||
public void sendChat(String message) {
|
||||
sendDownstreamPacket(new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0L, ByteArrays.EMPTY_ARRAY, false, Collections.emptyList(), null));
|
||||
sendDownstreamPacket(new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0L, null, 0, new BitSet()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a command to the Java server.
|
||||
*/
|
||||
public void sendCommand(String command) {
|
||||
sendDownstreamPacket(new ServerboundChatCommandPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), false, Collections.emptyList(), null));
|
||||
sendDownstreamPacket(new ServerboundChatCommandPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet()));
|
||||
}
|
||||
|
||||
public void setServerRenderDistance(int renderDistance) {
|
||||
renderDistance = GenericMath.ceil(++renderDistance * MathUtils.SQRT_OF_TWO); //square to circle
|
||||
// +1 is for Fabric and Spigot
|
||||
// Without the client misses loading some chunks per https://github.com/GeyserMC/Geyser/issues/3490
|
||||
// Fog still appears essentially normally
|
||||
renderDistance = renderDistance + 1;
|
||||
this.serverRenderDistance = renderDistance;
|
||||
|
||||
ChunkRadiusUpdatedPacket chunkRadiusUpdatedPacket = new ChunkRadiusUpdatedPacket();
|
||||
|
@ -1420,7 +1459,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
startGamePacket.setRotation(Vector2f.from(1, 1));
|
||||
|
||||
startGamePacket.setSeed(-1L);
|
||||
startGamePacket.setDimensionId(DimensionUtils.javaToBedrock(dimension));
|
||||
startGamePacket.setDimensionId(DimensionUtils.javaToBedrock(chunkCache.getBedrockDimension()));
|
||||
startGamePacket.setGeneratorId(1);
|
||||
startGamePacket.setLevelGameType(GameType.SURVIVAL);
|
||||
startGamePacket.setDifficulty(1);
|
||||
|
@ -1622,76 +1661,40 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
boolean spectator = gameMode == GameMode.SPECTATOR;
|
||||
boolean worldImmutable = gameMode == GameMode.ADVENTURE || spectator;
|
||||
|
||||
if (GameProtocol.supports1_19_10(this)) {
|
||||
UpdateAdventureSettingsPacket adventureSettingsPacket = new UpdateAdventureSettingsPacket();
|
||||
adventureSettingsPacket.setNoMvP(false);
|
||||
adventureSettingsPacket.setNoPvM(false);
|
||||
adventureSettingsPacket.setImmutableWorld(worldImmutable);
|
||||
adventureSettingsPacket.setShowNameTags(false);
|
||||
adventureSettingsPacket.setAutoJump(true);
|
||||
sendUpstreamPacket(adventureSettingsPacket);
|
||||
UpdateAdventureSettingsPacket adventureSettingsPacket = new UpdateAdventureSettingsPacket();
|
||||
adventureSettingsPacket.setNoMvP(false);
|
||||
adventureSettingsPacket.setNoPvM(false);
|
||||
adventureSettingsPacket.setImmutableWorld(worldImmutable);
|
||||
adventureSettingsPacket.setShowNameTags(false);
|
||||
adventureSettingsPacket.setAutoJump(true);
|
||||
sendUpstreamPacket(adventureSettingsPacket);
|
||||
|
||||
UpdateAbilitiesPacket updateAbilitiesPacket = new UpdateAbilitiesPacket();
|
||||
updateAbilitiesPacket.setUniqueEntityId(bedrockId);
|
||||
updateAbilitiesPacket.setCommandPermission(commandPermission);
|
||||
updateAbilitiesPacket.setPlayerPermission(playerPermission);
|
||||
UpdateAbilitiesPacket updateAbilitiesPacket = new UpdateAbilitiesPacket();
|
||||
updateAbilitiesPacket.setUniqueEntityId(bedrockId);
|
||||
updateAbilitiesPacket.setCommandPermission(commandPermission);
|
||||
updateAbilitiesPacket.setPlayerPermission(playerPermission);
|
||||
|
||||
AbilityLayer abilityLayer = new AbilityLayer();
|
||||
Set<Ability> abilities = abilityLayer.getAbilityValues();
|
||||
if (canFly || spectator) {
|
||||
abilities.add(Ability.MAY_FLY);
|
||||
}
|
||||
|
||||
// Default stuff we have to fill in
|
||||
abilities.add(Ability.BUILD);
|
||||
abilities.add(Ability.MINE);
|
||||
// Needed so you can drop items
|
||||
abilities.add(Ability.DOORS_AND_SWITCHES);
|
||||
if (gameMode == GameMode.CREATIVE) {
|
||||
// Needed so the client doesn't attempt to take away items
|
||||
abilities.add(Ability.INSTABUILD);
|
||||
}
|
||||
|
||||
if (commandPermission == CommandPermission.OPERATOR) {
|
||||
// Fixes a bug? since 1.19.11 where the player can change their gamemode in Bedrock settings and
|
||||
// a packet is not sent to the server.
|
||||
// https://github.com/GeyserMC/Geyser/issues/3191
|
||||
abilities.add(Ability.OPERATOR_COMMANDS);
|
||||
}
|
||||
|
||||
if (flying || spectator) {
|
||||
if (spectator && !flying) {
|
||||
// We're "flying locked" in this gamemode
|
||||
flying = true;
|
||||
ServerboundPlayerAbilitiesPacket abilitiesPacket = new ServerboundPlayerAbilitiesPacket(true);
|
||||
sendDownstreamPacket(abilitiesPacket);
|
||||
}
|
||||
abilities.add(Ability.FLYING);
|
||||
}
|
||||
|
||||
if (spectator) {
|
||||
abilities.add(Ability.NO_CLIP);
|
||||
}
|
||||
|
||||
abilityLayer.setLayerType(AbilityLayer.Type.BASE);
|
||||
abilityLayer.setFlySpeed(flySpeed);
|
||||
// https://github.com/GeyserMC/Geyser/issues/3139 as of 1.19.10
|
||||
abilityLayer.setWalkSpeed(walkSpeed == 0f ? 0.01f : walkSpeed);
|
||||
Collections.addAll(abilityLayer.getAbilitiesSet(), USED_ABILITIES);
|
||||
|
||||
updateAbilitiesPacket.getAbilityLayers().add(abilityLayer);
|
||||
sendUpstreamPacket(updateAbilitiesPacket);
|
||||
return;
|
||||
AbilityLayer abilityLayer = new AbilityLayer();
|
||||
Set<Ability> abilities = abilityLayer.getAbilityValues();
|
||||
if (canFly || spectator) {
|
||||
abilities.add(Ability.MAY_FLY);
|
||||
}
|
||||
|
||||
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
||||
adventureSettingsPacket.setUniqueEntityId(bedrockId);
|
||||
adventureSettingsPacket.setCommandPermission(commandPermission);
|
||||
adventureSettingsPacket.setPlayerPermission(playerPermission);
|
||||
// Default stuff we have to fill in
|
||||
abilities.add(Ability.BUILD);
|
||||
abilities.add(Ability.MINE);
|
||||
// Needed so you can drop items
|
||||
abilities.add(Ability.DOORS_AND_SWITCHES);
|
||||
if (gameMode == GameMode.CREATIVE) {
|
||||
// Needed so the client doesn't attempt to take away items
|
||||
abilities.add(Ability.INSTABUILD);
|
||||
}
|
||||
|
||||
Set<AdventureSetting> flags = adventureSettingsPacket.getSettings();
|
||||
if (canFly || spectator) {
|
||||
flags.add(AdventureSetting.MAY_FLY);
|
||||
if (commandPermission == CommandPermission.OPERATOR) {
|
||||
// Fixes a bug? since 1.19.11 where the player can change their gamemode in Bedrock settings and
|
||||
// a packet is not sent to the server.
|
||||
// https://github.com/GeyserMC/Geyser/issues/3191
|
||||
abilities.add(Ability.OPERATOR_COMMANDS);
|
||||
}
|
||||
|
||||
if (flying || spectator) {
|
||||
|
@ -1701,20 +1704,21 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
ServerboundPlayerAbilitiesPacket abilitiesPacket = new ServerboundPlayerAbilitiesPacket(true);
|
||||
sendDownstreamPacket(abilitiesPacket);
|
||||
}
|
||||
flags.add(AdventureSetting.FLYING);
|
||||
}
|
||||
|
||||
if (worldImmutable) {
|
||||
flags.add(AdventureSetting.WORLD_IMMUTABLE);
|
||||
abilities.add(Ability.FLYING);
|
||||
}
|
||||
|
||||
if (spectator) {
|
||||
flags.add(AdventureSetting.NO_CLIP);
|
||||
abilities.add(Ability.NO_CLIP);
|
||||
}
|
||||
|
||||
flags.add(AdventureSetting.AUTO_JUMP);
|
||||
abilityLayer.setLayerType(AbilityLayer.Type.BASE);
|
||||
abilityLayer.setFlySpeed(flySpeed);
|
||||
// https://github.com/GeyserMC/Geyser/issues/3139 as of 1.19.10
|
||||
abilityLayer.setWalkSpeed(walkSpeed == 0f ? 0.01f : walkSpeed);
|
||||
Collections.addAll(abilityLayer.getAbilitiesSet(), USED_ABILITIES);
|
||||
|
||||
sendUpstreamPacket(adventureSettingsPacket);
|
||||
updateAbilitiesPacket.getAbilityLayers().add(abilityLayer);
|
||||
sendUpstreamPacket(updateAbilitiesPacket);
|
||||
}
|
||||
|
||||
private int getRenderDistance() {
|
||||
|
@ -1894,4 +1898,19 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
|
|||
sendUpstreamPacket(transferPacket);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addCommandEnum(String name, String... enums) {
|
||||
softEnumPacket(name, SoftEnumUpdateType.ADD, enums);
|
||||
}
|
||||
|
||||
public void removeCommandEnum(String name, String... enums) {
|
||||
softEnumPacket(name, SoftEnumUpdateType.REMOVE, enums);
|
||||
}
|
||||
|
||||
private void softEnumPacket(String name, SoftEnumUpdateType type, String... enums) {
|
||||
UpdateSoftEnumPacket packet = new UpdateSoftEnumPacket();
|
||||
packet.setType(type);
|
||||
packet.setSoftEnum(new CommandEnumData(name, enums, true));
|
||||
sendUpstreamPacket(packet);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,7 +123,8 @@ public class EntityCache {
|
|||
}
|
||||
|
||||
public void addPlayerEntity(PlayerEntity entity) {
|
||||
playerEntities.put(entity.getUuid(), entity);
|
||||
// putIfAbsent matches the behavior of playerInfoMap in Java as of 1.19.3
|
||||
playerEntities.putIfAbsent(entity.getUuid(), entity);
|
||||
}
|
||||
|
||||
public PlayerEntity getPlayerEntity(UUID uuid) {
|
||||
|
|
|
@ -71,8 +71,9 @@ public class SkullCache {
|
|||
this.skullRenderDistanceSquared = distance * distance;
|
||||
}
|
||||
|
||||
public void putSkull(Vector3i position, String texturesProperty, int blockState) {
|
||||
public void putSkull(Vector3i position, UUID uuid, String texturesProperty, int blockState) {
|
||||
Skull skull = skulls.computeIfAbsent(position, Skull::new);
|
||||
skull.uuid = uuid;
|
||||
skull.texturesProperty = texturesProperty;
|
||||
skull.blockState = blockState;
|
||||
|
||||
|
@ -201,6 +202,7 @@ public class SkullCache {
|
|||
@RequiredArgsConstructor
|
||||
@Data
|
||||
public static class Skull {
|
||||
private UUID uuid;
|
||||
private String texturesProperty;
|
||||
private int blockState;
|
||||
private SkullPlayerEntity entity;
|
||||
|
|
|
@ -33,6 +33,8 @@ import it.unimi.dsi.fastutil.objects.Object2IntMaps;
|
|||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.geysermc.geyser.api.util.TriState;
|
||||
import org.geysermc.geyser.scoreboard.Scoreboard;
|
||||
import org.geysermc.geyser.scoreboard.ScoreboardUpdater.ScoreboardSession;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
|
@ -61,6 +63,17 @@ public final class WorldCache {
|
|||
private int currentSequence;
|
||||
private final Object2IntMap<Vector3i> unverifiedPredictions = new Object2IntOpenHashMap<>(1);
|
||||
|
||||
/**
|
||||
* <ul>
|
||||
* <li>NOT_SET = not yet triggered</li>
|
||||
* <li>FALSE = enforce-secure-profile is true but player hasn't chatted yet</li>
|
||||
* <li>TRUE = enforce-secure-profile is enabled, and player has chatted and they have seen our message.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
private @NonNull TriState chatWarningSent = TriState.NOT_SET;
|
||||
|
||||
public WorldCache(GeyserSession session) {
|
||||
this.session = session;
|
||||
this.scoreboard = new Scoreboard(session);
|
||||
|
|
|
@ -29,10 +29,6 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
|||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.nukkitx.protocol.bedrock.data.skin.ImageData;
|
||||
import com.nukkitx.protocol.bedrock.data.skin.SerializedSkin;
|
||||
import com.nukkitx.protocol.bedrock.packet.PlayerListPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.PlayerSkinPacket;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
@ -45,7 +41,6 @@ import org.geysermc.geyser.text.GeyserLocale;
|
|||
import javax.annotation.Nonnull;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -68,7 +63,7 @@ public class FakeHeadProvider {
|
|||
|
||||
SkinProvider.Skin skin = skinData.skin();
|
||||
SkinProvider.Cape cape = skinData.cape();
|
||||
SkinProvider.SkinGeometry geometry = skinData.geometry().getGeometryName().equals("{\"geometry\" :{\"default\" :\"geometry.humanoid.customSlim\"}}")
|
||||
SkinProvider.SkinGeometry geometry = skinData.geometry().geometryName().equals("{\"geometry\" :{\"default\" :\"geometry.humanoid.customSlim\"}}")
|
||||
? SkinProvider.WEARING_CUSTOM_SKULL_SLIM : SkinProvider.WEARING_CUSTOM_SKULL;
|
||||
|
||||
SkinProvider.Skin headSkin = SkinProvider.getOrDefault(
|
||||
|
@ -111,7 +106,7 @@ public class FakeHeadProvider {
|
|||
try {
|
||||
SkinProvider.SkinData mergedSkinData = MERGED_SKINS_LOADING_CACHE.get(new FakeHeadEntry(texturesProperty, fakeHeadSkinUrl, entity));
|
||||
|
||||
sendSkinPacket(session, entity, mergedSkinData);
|
||||
SkinManager.sendSkinPacket(session, entity, mergedSkinData);
|
||||
} catch (ExecutionException e) {
|
||||
GeyserImpl.getInstance().getLogger().error("Couldn't merge skin of " + entity.getUsername() + " with head skin url " + fakeHeadSkinUrl, e);
|
||||
}
|
||||
|
@ -133,50 +128,10 @@ public class FakeHeadProvider {
|
|||
return;
|
||||
}
|
||||
|
||||
sendSkinPacket(session, entity, skinData);
|
||||
SkinManager.sendSkinPacket(session, entity, skinData);
|
||||
});
|
||||
}
|
||||
|
||||
private static void sendSkinPacket(GeyserSession session, PlayerEntity entity, SkinProvider.SkinData skinData) {
|
||||
SkinProvider.Skin skin = skinData.skin();
|
||||
SkinProvider.Cape cape = skinData.cape();
|
||||
SkinProvider.SkinGeometry geometry = skinData.geometry();
|
||||
|
||||
if (entity.getUuid().equals(session.getPlayerEntity().getUuid())) {
|
||||
PlayerListPacket.Entry updatedEntry = SkinManager.buildEntryManually(
|
||||
session,
|
||||
entity.getUuid(),
|
||||
entity.getUsername(),
|
||||
entity.getGeyserId(),
|
||||
skin.getTextureUrl(),
|
||||
skin.getSkinData(),
|
||||
cape.getCapeId(),
|
||||
cape.getCapeData(),
|
||||
geometry
|
||||
);
|
||||
|
||||
PlayerListPacket playerAddPacket = new PlayerListPacket();
|
||||
playerAddPacket.setAction(PlayerListPacket.Action.ADD);
|
||||
playerAddPacket.getEntries().add(updatedEntry);
|
||||
session.sendUpstreamPacket(playerAddPacket);
|
||||
} else {
|
||||
PlayerSkinPacket packet = new PlayerSkinPacket();
|
||||
packet.setUuid(entity.getUuid());
|
||||
packet.setOldSkinName("");
|
||||
packet.setNewSkinName(skin.getTextureUrl());
|
||||
packet.setSkin(getSkin(skin.getTextureUrl(), skin, cape, geometry));
|
||||
packet.setTrustedSkin(true);
|
||||
session.sendUpstreamPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static SerializedSkin getSkin(String skinId, SkinProvider.Skin skin, SkinProvider.Cape cape, SkinProvider.SkinGeometry geometry) {
|
||||
return SerializedSkin.of(skinId, "", geometry.getGeometryName(),
|
||||
ImageData.of(skin.getSkinData()), Collections.emptyList(),
|
||||
ImageData.of(cape.getCapeData()), geometry.getGeometryData(),
|
||||
"", true, false, false, cape.getCapeId(), skinId);
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
|
|
|
@ -1,63 +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.skin;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class ProvidedSkin {
|
||||
@Getter private byte[] skin;
|
||||
|
||||
public ProvidedSkin(String internalUrl) {
|
||||
try {
|
||||
BufferedImage image;
|
||||
try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource(internalUrl)) {
|
||||
image = ImageIO.read(stream);
|
||||
}
|
||||
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(image.getWidth() * 4 + image.getHeight() * 4);
|
||||
for (int y = 0; y < image.getHeight(); y++) {
|
||||
for (int x = 0; x < image.getWidth(); x++) {
|
||||
int rgba = image.getRGB(x, y);
|
||||
outputStream.write((rgba >> 16) & 0xFF); // Red
|
||||
outputStream.write((rgba >> 8) & 0xFF); // Green
|
||||
outputStream.write(rgba & 0xFF); // Blue
|
||||
outputStream.write((rgba >> 24) & 0xFF); // Alpha
|
||||
}
|
||||
}
|
||||
image.flush();
|
||||
skin = outputStream.toByteArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
128
core/src/main/java/org/geysermc/geyser/skin/ProvidedSkins.java
Normal file
128
core/src/main/java/org/geysermc/geyser/skin/ProvidedSkins.java
Normal file
|
@ -0,0 +1,128 @@
|
|||
/*
|
||||
* 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.skin;
|
||||
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.util.AssetUtils;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ProvidedSkins {
|
||||
private static final ProvidedSkin[] PROVIDED_SKINS = {
|
||||
new ProvidedSkin("textures/entity/player/slim/alex.png", true),
|
||||
new ProvidedSkin("textures/entity/player/slim/ari.png", true),
|
||||
new ProvidedSkin("textures/entity/player/slim/efe.png", true),
|
||||
new ProvidedSkin("textures/entity/player/slim/kai.png", true),
|
||||
new ProvidedSkin("textures/entity/player/slim/makena.png", true),
|
||||
new ProvidedSkin("textures/entity/player/slim/noor.png", true),
|
||||
new ProvidedSkin("textures/entity/player/slim/steve.png", true),
|
||||
new ProvidedSkin("textures/entity/player/slim/sunny.png", true),
|
||||
new ProvidedSkin("textures/entity/player/slim/zuri.png", true),
|
||||
new ProvidedSkin("textures/entity/player/wide/alex.png", false),
|
||||
new ProvidedSkin("textures/entity/player/wide/ari.png", false),
|
||||
new ProvidedSkin("textures/entity/player/wide/efe.png", false),
|
||||
new ProvidedSkin("textures/entity/player/wide/kai.png", false),
|
||||
new ProvidedSkin("textures/entity/player/wide/makena.png", false),
|
||||
new ProvidedSkin("textures/entity/player/wide/noor.png", false),
|
||||
new ProvidedSkin("textures/entity/player/wide/steve.png", false),
|
||||
new ProvidedSkin("textures/entity/player/wide/sunny.png", false),
|
||||
new ProvidedSkin("textures/entity/player/wide/zuri.png", false)
|
||||
};
|
||||
|
||||
public static ProvidedSkin getDefaultPlayerSkin(UUID uuid) {
|
||||
return PROVIDED_SKINS[Math.floorMod(uuid.hashCode(), PROVIDED_SKINS.length)];
|
||||
}
|
||||
|
||||
private ProvidedSkins() {
|
||||
}
|
||||
|
||||
public static final class ProvidedSkin {
|
||||
private SkinProvider.Skin data;
|
||||
private final boolean slim;
|
||||
|
||||
ProvidedSkin(String asset, boolean slim) {
|
||||
this.slim = slim;
|
||||
|
||||
Path folder = GeyserImpl.getInstance().getBootstrap().getConfigFolder()
|
||||
.resolve("cache")
|
||||
.resolve("default_player_skins")
|
||||
.resolve(slim ? "slim" : "wide");
|
||||
String assetName = asset.substring(asset.lastIndexOf('/') + 1);
|
||||
|
||||
File location = folder.resolve(assetName).toFile();
|
||||
AssetUtils.addTask(!location.exists(), new AssetUtils.ClientJarTask("assets/minecraft/" + asset,
|
||||
(stream) -> AssetUtils.saveFile(location, stream),
|
||||
() -> {
|
||||
try {
|
||||
// TODO lazy initialize?
|
||||
BufferedImage image;
|
||||
try (InputStream stream = new FileInputStream(location)) {
|
||||
image = ImageIO.read(stream);
|
||||
}
|
||||
|
||||
byte[] byteData = SkinProvider.bufferedImageToImageData(image);
|
||||
image.flush();
|
||||
|
||||
String identifier = "geysermc:" + assetName + "_" + (slim ? "slim" : "wide");
|
||||
this.data = new SkinProvider.Skin(-1, identifier, byteData);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public SkinProvider.Skin getData() {
|
||||
// Fall back to the default skin if we can't load our skins, or it's not loaded yet.
|
||||
return Objects.requireNonNullElse(data, SkinProvider.EMPTY_SKIN);
|
||||
}
|
||||
|
||||
public boolean isSlim() {
|
||||
return slim;
|
||||
}
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
// no-op
|
||||
}
|
||||
|
||||
static {
|
||||
Path folder = GeyserImpl.getInstance().getBootstrap().getConfigFolder()
|
||||
.resolve("cache")
|
||||
.resolve("default_player_skins");
|
||||
folder.toFile().mkdirs();
|
||||
// Two directories since there are two skins for each model: one slim, one wide
|
||||
folder.resolve("slim").toFile().mkdir();
|
||||
folder.resolve("wide").toFile().mkdir();
|
||||
}
|
||||
}
|
|
@ -32,9 +32,10 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
|||
import com.nukkitx.protocol.bedrock.data.skin.ImageData;
|
||||
import com.nukkitx.protocol.bedrock.data.skin.SerializedSkin;
|
||||
import com.nukkitx.protocol.bedrock.packet.PlayerListPacket;
|
||||
import com.nukkitx.protocol.bedrock.packet.PlayerSkinPacket;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.api.network.AuthType;
|
||||
import org.geysermc.geyser.entity.type.player.PlayerEntity;
|
||||
import org.geysermc.geyser.entity.type.player.SkullPlayerEntity;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.session.auth.BedrockClientData;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
|
@ -53,13 +54,30 @@ public class SkinManager {
|
|||
* Builds a Bedrock player list entry from our existing, cached Bedrock skin information
|
||||
*/
|
||||
public static PlayerListPacket.Entry buildCachedEntry(GeyserSession session, PlayerEntity playerEntity) {
|
||||
// First: see if we have the cached skin texture ID.
|
||||
GameProfileData data = GameProfileData.from(playerEntity);
|
||||
SkinProvider.Cape cape = SkinProvider.getCachedCape(data.capeUrl());
|
||||
SkinProvider.SkinGeometry geometry = SkinProvider.SkinGeometry.getLegacy(data.isAlex());
|
||||
SkinProvider.Skin skin = null;
|
||||
SkinProvider.Cape cape = null;
|
||||
SkinProvider.SkinGeometry geometry = SkinProvider.SkinGeometry.WIDE;
|
||||
if (data != null) {
|
||||
// GameProfileData is not null = server provided us with textures data to work with.
|
||||
skin = SkinProvider.getCachedSkin(data.skinUrl());
|
||||
cape = SkinProvider.getCachedCape(data.capeUrl());
|
||||
geometry = data.isAlex() ? SkinProvider.SkinGeometry.SLIM : SkinProvider.SkinGeometry.WIDE;
|
||||
}
|
||||
|
||||
SkinProvider.Skin skin = SkinProvider.getCachedSkin(data.skinUrl());
|
||||
if (skin == null) {
|
||||
skin = SkinProvider.EMPTY_SKIN;
|
||||
if (skin == null || cape == null) {
|
||||
// The server either didn't have a texture to send, or we didn't have the texture ID cached.
|
||||
// Let's see if this player is a Bedrock player, and if so, let's pull their skin.
|
||||
// Otherwise, grab the default player skin
|
||||
SkinProvider.SkinData fallbackSkinData = SkinProvider.determineFallbackSkinData(playerEntity.getUuid());
|
||||
if (skin == null) {
|
||||
skin = fallbackSkinData.skin();
|
||||
geometry = fallbackSkinData.geometry();
|
||||
}
|
||||
if (cape == null) {
|
||||
cape = fallbackSkinData.cape();
|
||||
}
|
||||
}
|
||||
|
||||
return buildEntryManually(
|
||||
|
@ -67,10 +85,8 @@ public class SkinManager {
|
|||
playerEntity.getUuid(),
|
||||
playerEntity.getUsername(),
|
||||
playerEntity.getGeyserId(),
|
||||
skin.getTextureUrl(),
|
||||
skin.getSkinData(),
|
||||
cape.getCapeId(),
|
||||
cape.getCapeData(),
|
||||
skin,
|
||||
cape,
|
||||
geometry
|
||||
);
|
||||
}
|
||||
|
@ -79,14 +95,10 @@ public class SkinManager {
|
|||
* With all the information needed, build a Bedrock player entry with translated skin information.
|
||||
*/
|
||||
public static PlayerListPacket.Entry buildEntryManually(GeyserSession session, UUID uuid, String username, long geyserId,
|
||||
String skinId, byte[] skinData,
|
||||
String capeId, byte[] capeData,
|
||||
SkinProvider.Skin skin,
|
||||
SkinProvider.Cape cape,
|
||||
SkinProvider.SkinGeometry geometry) {
|
||||
SerializedSkin serializedSkin = SerializedSkin.of(
|
||||
skinId, "", geometry.getGeometryName(), ImageData.of(skinData), Collections.emptyList(),
|
||||
ImageData.of(capeData), geometry.getGeometryData(), "", true, false,
|
||||
!capeId.equals(SkinProvider.EMPTY_CAPE.getCapeId()), capeId, skinId
|
||||
);
|
||||
SerializedSkin serializedSkin = getSkin(skin.getTextureUrl(), skin, cape, geometry);
|
||||
|
||||
// This attempts to find the XUID of the player so profile images show up for Xbox accounts
|
||||
String xuid = "";
|
||||
|
@ -116,6 +128,45 @@ public class SkinManager {
|
|||
return entry;
|
||||
}
|
||||
|
||||
public static void sendSkinPacket(GeyserSession session, PlayerEntity entity, SkinProvider.SkinData skinData) {
|
||||
SkinProvider.Skin skin = skinData.skin();
|
||||
SkinProvider.Cape cape = skinData.cape();
|
||||
SkinProvider.SkinGeometry geometry = skinData.geometry();
|
||||
|
||||
if (entity.getUuid().equals(session.getPlayerEntity().getUuid())) {
|
||||
// TODO is this special behavior needed?
|
||||
PlayerListPacket.Entry updatedEntry = buildEntryManually(
|
||||
session,
|
||||
entity.getUuid(),
|
||||
entity.getUsername(),
|
||||
entity.getGeyserId(),
|
||||
skin,
|
||||
cape,
|
||||
geometry
|
||||
);
|
||||
|
||||
PlayerListPacket playerAddPacket = new PlayerListPacket();
|
||||
playerAddPacket.setAction(PlayerListPacket.Action.ADD);
|
||||
playerAddPacket.getEntries().add(updatedEntry);
|
||||
session.sendUpstreamPacket(playerAddPacket);
|
||||
} else {
|
||||
PlayerSkinPacket packet = new PlayerSkinPacket();
|
||||
packet.setUuid(entity.getUuid());
|
||||
packet.setOldSkinName("");
|
||||
packet.setNewSkinName(skin.getTextureUrl());
|
||||
packet.setSkin(getSkin(skin.getTextureUrl(), skin, cape, geometry));
|
||||
packet.setTrustedSkin(true);
|
||||
session.sendUpstreamPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
private static SerializedSkin getSkin(String skinId, SkinProvider.Skin skin, SkinProvider.Cape cape, SkinProvider.SkinGeometry geometry) {
|
||||
return SerializedSkin.of(skinId, "", geometry.geometryName(),
|
||||
ImageData.of(skin.getSkinData()), Collections.emptyList(),
|
||||
ImageData.of(cape.capeData()), geometry.geometryData(),
|
||||
"", true, false, false, cape.capeId(), skinId);
|
||||
}
|
||||
|
||||
public static void requestAndHandleSkinAndCape(PlayerEntity entity, GeyserSession session,
|
||||
Consumer<SkinProvider.SkinAndCape> skinAndCapeConsumer) {
|
||||
SkinProvider.requestSkinData(entity).whenCompleteAsync((skinData, throwable) -> {
|
||||
|
@ -128,34 +179,7 @@ public class SkinManager {
|
|||
}
|
||||
|
||||
if (skinData.geometry() != null) {
|
||||
SkinProvider.Skin skin = skinData.skin();
|
||||
SkinProvider.Cape cape = skinData.cape();
|
||||
SkinProvider.SkinGeometry geometry = skinData.geometry();
|
||||
|
||||
PlayerListPacket.Entry updatedEntry = buildEntryManually(
|
||||
session,
|
||||
entity.getUuid(),
|
||||
entity.getUsername(),
|
||||
entity.getGeyserId(),
|
||||
skin.getTextureUrl(),
|
||||
skin.getSkinData(),
|
||||
cape.getCapeId(),
|
||||
cape.getCapeData(),
|
||||
geometry
|
||||
);
|
||||
|
||||
|
||||
PlayerListPacket playerAddPacket = new PlayerListPacket();
|
||||
playerAddPacket.setAction(PlayerListPacket.Action.ADD);
|
||||
playerAddPacket.getEntries().add(updatedEntry);
|
||||
session.sendUpstreamPacket(playerAddPacket);
|
||||
|
||||
if (!entity.isPlayerList()) {
|
||||
PlayerListPacket playerRemovePacket = new PlayerListPacket();
|
||||
playerRemovePacket.setAction(PlayerListPacket.Action.REMOVE);
|
||||
playerRemovePacket.getEntries().add(updatedEntry);
|
||||
session.sendUpstreamPacket(playerRemovePacket);
|
||||
}
|
||||
sendSkinPacket(session, entity, skinData);
|
||||
}
|
||||
|
||||
if (skinAndCapeConsumer != null) {
|
||||
|
@ -186,7 +210,7 @@ public class SkinManager {
|
|||
}
|
||||
|
||||
if (!clientData.getCapeId().equals("")) {
|
||||
SkinProvider.storeBedrockCape(playerEntity.getUuid(), capeBytes);
|
||||
SkinProvider.storeBedrockCape(clientData.getCapeId(), capeBytes);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError("Failed to cache skin for bedrock user (" + playerEntity.getUsername() + "): ", e);
|
||||
|
@ -231,30 +255,29 @@ public class SkinManager {
|
|||
* @param entity entity to build the GameProfileData from
|
||||
* @return The built GameProfileData
|
||||
*/
|
||||
public static GameProfileData from(PlayerEntity entity) {
|
||||
try {
|
||||
String texturesProperty = entity.getTexturesProperty();
|
||||
public static @Nullable GameProfileData from(PlayerEntity entity) {
|
||||
String texturesProperty = entity.getTexturesProperty();
|
||||
if (texturesProperty == null) {
|
||||
// Likely offline mode
|
||||
return null;
|
||||
}
|
||||
|
||||
if (texturesProperty == null) {
|
||||
// Likely offline mode
|
||||
return loadBedrockOrOfflineSkin(entity);
|
||||
}
|
||||
GameProfileData data = loadFromJson(texturesProperty);
|
||||
if (data != null) {
|
||||
return data;
|
||||
try {
|
||||
return loadFromJson(texturesProperty);
|
||||
} catch (Exception exception) {
|
||||
if (entity instanceof SkullPlayerEntity skullEntity) {
|
||||
GeyserImpl.getInstance().getLogger().debug("Something went wrong while processing skin for skull at " + skullEntity.getSkullPosition() + " with Value: " + texturesProperty);
|
||||
} else {
|
||||
return loadBedrockOrOfflineSkin(entity);
|
||||
GeyserImpl.getInstance().getLogger().debug("Something went wrong while processing skin for " + entity.getUsername() + " with Value: " + texturesProperty);
|
||||
}
|
||||
} catch (IOException exception) {
|
||||
GeyserImpl.getInstance().getLogger().debug("Something went wrong while processing skin for " + entity.getUsername());
|
||||
if (GeyserImpl.getInstance().getConfig().isDebugMode()) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
return loadBedrockOrOfflineSkin(entity);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static GameProfileData loadFromJson(String encodedJson) throws IOException {
|
||||
private static GameProfileData loadFromJson(String encodedJson) throws IOException, IllegalArgumentException {
|
||||
JsonNode skinObject = GeyserImpl.JSON_MAPPER.readTree(new String(Base64.getDecoder().decode(encodedJson), StandardCharsets.UTF_8));
|
||||
JsonNode textures = skinObject.get("textures");
|
||||
|
||||
|
@ -267,38 +290,25 @@ public class SkinManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
String skinUrl = skinTexture.get("url").asText().replace("http://", "https://");
|
||||
String skinUrl;
|
||||
JsonNode skinUrlNode = skinTexture.get("url");
|
||||
if (skinUrlNode != null && skinUrlNode.isTextual()) {
|
||||
skinUrl = skinUrlNode.asText().replace("http://", "https://");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean isAlex = skinTexture.has("metadata");
|
||||
|
||||
String capeUrl = null;
|
||||
JsonNode capeTexture = textures.get("CAPE");
|
||||
if (capeTexture != null) {
|
||||
capeUrl = capeTexture.get("url").asText().replace("http://", "https://");
|
||||
}
|
||||
|
||||
return new GameProfileData(skinUrl, capeUrl, isAlex);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return default skin with default cape when texture data is invalid, or the Bedrock player's skin if this
|
||||
* is a Bedrock player.
|
||||
*/
|
||||
private static GameProfileData loadBedrockOrOfflineSkin(PlayerEntity entity) {
|
||||
// Fallback to the offline mode of working it out
|
||||
UUID uuid = entity.getUuid();
|
||||
boolean isAlex = (Math.abs(uuid.hashCode() % 2) == 1);
|
||||
|
||||
String skinUrl = isAlex ? SkinProvider.EMPTY_SKIN_ALEX.getTextureUrl() : SkinProvider.EMPTY_SKIN.getTextureUrl();
|
||||
String capeUrl = SkinProvider.EMPTY_CAPE.getTextureUrl();
|
||||
if (("steve".equals(skinUrl) || "alex".equals(skinUrl)) && GeyserImpl.getInstance().getConfig().getRemote().authType() != AuthType.ONLINE) {
|
||||
GeyserSession session = GeyserImpl.getInstance().connectionByUuid(uuid);
|
||||
|
||||
if (session != null) {
|
||||
skinUrl = session.getClientData().getSkinId();
|
||||
capeUrl = session.getClientData().getCapeId();
|
||||
JsonNode capeUrlNode = capeTexture.get("url");
|
||||
if (capeUrlNode != null && capeUrlNode.isTextual()) {
|
||||
capeUrl = capeUrlNode.asText().replace("http://", "https://");
|
||||
}
|
||||
}
|
||||
|
||||
return new GameProfileData(skinUrl, capeUrl, isAlex);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,22 +26,22 @@
|
|||
package org.geysermc.geyser.skin;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import it.unimi.dsi.fastutil.bytes.ByteArrays;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.api.network.AuthType;
|
||||
import org.geysermc.geyser.entity.type.player.PlayerEntity;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
import org.geysermc.geyser.util.FileUtils;
|
||||
import org.geysermc.geyser.util.WebUtils;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
@ -57,28 +57,28 @@ import java.util.concurrent.*;
|
|||
import java.util.function.Predicate;
|
||||
|
||||
public class SkinProvider {
|
||||
public static final boolean ALLOW_THIRD_PARTY_CAPES = GeyserImpl.getInstance().getConfig().isAllowThirdPartyCapes();
|
||||
private static final boolean ALLOW_THIRD_PARTY_CAPES = GeyserImpl.getInstance().getConfig().isAllowThirdPartyCapes();
|
||||
static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(ALLOW_THIRD_PARTY_CAPES ? 21 : 14);
|
||||
|
||||
public static final byte[] STEVE_SKIN = new ProvidedSkin("bedrock/skin/skin_steve.png").getSkin();
|
||||
public static final Skin EMPTY_SKIN = new Skin(-1, "steve", STEVE_SKIN);
|
||||
public static final byte[] ALEX_SKIN = new ProvidedSkin("bedrock/skin/skin_alex.png").getSkin();
|
||||
public static final Skin EMPTY_SKIN_ALEX = new Skin(-1, "alex", ALEX_SKIN);
|
||||
private static final Map<String, Skin> permanentSkins = new HashMap<>() {{
|
||||
put("steve", EMPTY_SKIN);
|
||||
put("alex", EMPTY_SKIN_ALEX);
|
||||
}};
|
||||
private static final Cache<String, Skin> cachedSkins = CacheBuilder.newBuilder()
|
||||
static final Skin EMPTY_SKIN;
|
||||
static final Cape EMPTY_CAPE = new Cape("", "no-cape", ByteArrays.EMPTY_ARRAY, -1, true);
|
||||
|
||||
private static final Cache<String, Cape> CACHED_JAVA_CAPES = CacheBuilder.newBuilder()
|
||||
.expireAfterAccess(1, TimeUnit.HOURS)
|
||||
.build();
|
||||
private static final Cache<String, Skin> CACHED_JAVA_SKINS = CacheBuilder.newBuilder()
|
||||
.expireAfterAccess(1, TimeUnit.HOURS)
|
||||
.build();
|
||||
|
||||
private static final Map<String, CompletableFuture<Skin>> requestedSkins = new ConcurrentHashMap<>();
|
||||
|
||||
public static final Cape EMPTY_CAPE = new Cape("", "no-cape", new byte[0], -1, true);
|
||||
private static final Cache<String, Cape> cachedCapes = CacheBuilder.newBuilder()
|
||||
private static final Cache<String, Cape> CACHED_BEDROCK_CAPES = CacheBuilder.newBuilder()
|
||||
.expireAfterAccess(1, TimeUnit.HOURS)
|
||||
.build();
|
||||
private static final Cache<String, Skin> CACHED_BEDROCK_SKINS = CacheBuilder.newBuilder()
|
||||
.expireAfterAccess(1, TimeUnit.HOURS)
|
||||
.build();
|
||||
|
||||
private static final Map<String, CompletableFuture<Cape>> requestedCapes = new ConcurrentHashMap<>();
|
||||
private static final Map<String, CompletableFuture<Skin>> requestedSkins = new ConcurrentHashMap<>();
|
||||
|
||||
private static final Map<UUID, SkinGeometry> cachedGeometry = new ConcurrentHashMap<>();
|
||||
|
||||
|
@ -86,18 +86,36 @@ public class SkinProvider {
|
|||
* Citizens NPCs use UUID version 2, while legitimate Minecraft players use version 4, and
|
||||
* offline mode players use version 3.
|
||||
*/
|
||||
public static final Predicate<UUID> IS_NPC = uuid -> uuid.version() == 2;
|
||||
private static final Predicate<UUID> IS_NPC = uuid -> uuid.version() == 2;
|
||||
|
||||
public static final boolean ALLOW_THIRD_PARTY_EARS = GeyserImpl.getInstance().getConfig().isAllowThirdPartyEars();
|
||||
public static final String EARS_GEOMETRY;
|
||||
public static final String EARS_GEOMETRY_SLIM;
|
||||
public static final SkinGeometry SKULL_GEOMETRY;
|
||||
public static final SkinGeometry WEARING_CUSTOM_SKULL;
|
||||
public static final SkinGeometry WEARING_CUSTOM_SKULL_SLIM;
|
||||
|
||||
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
private static final boolean ALLOW_THIRD_PARTY_EARS = GeyserImpl.getInstance().getConfig().isAllowThirdPartyEars();
|
||||
private static final String EARS_GEOMETRY;
|
||||
private static final String EARS_GEOMETRY_SLIM;
|
||||
static final SkinGeometry SKULL_GEOMETRY;
|
||||
static final SkinGeometry WEARING_CUSTOM_SKULL;
|
||||
static final SkinGeometry WEARING_CUSTOM_SKULL_SLIM;
|
||||
|
||||
static {
|
||||
// Generate the empty texture to use as an emergency fallback
|
||||
final int pink = -524040;
|
||||
final int black = -16777216;
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(64 * 4 + 64 * 4);
|
||||
for (int y = 0; y < 64; y++) {
|
||||
for (int x = 0; x < 64; x++) {
|
||||
int rgba;
|
||||
if (y > 32) {
|
||||
rgba = x >= 32 ? pink : black;
|
||||
} else {
|
||||
rgba = x >= 32 ? black : pink;
|
||||
}
|
||||
outputStream.write((rgba >> 16) & 0xFF); // Red
|
||||
outputStream.write((rgba >> 8) & 0xFF); // Green
|
||||
outputStream.write(rgba & 0xFF); // Blue
|
||||
outputStream.write((rgba >> 24) & 0xFF); // Alpha
|
||||
}
|
||||
}
|
||||
EMPTY_SKIN = new Skin(-1, "geysermc:empty", outputStream.toByteArray());
|
||||
|
||||
/* Load in the normal ears geometry */
|
||||
EARS_GEOMETRY = new String(FileUtils.readAllBytes("bedrock/skin/geometry.humanoid.ears.json"), StandardCharsets.UTF_8);
|
||||
|
||||
|
@ -141,48 +159,103 @@ public class SkinProvider {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean hasCapeCached(String capeUrl) {
|
||||
return cachedCapes.getIfPresent(capeUrl) != null;
|
||||
/**
|
||||
* Search our cached database for an already existing, translated skin of this Java URL.
|
||||
*/
|
||||
static Skin getCachedSkin(String skinUrl) {
|
||||
return CACHED_JAVA_SKINS.getIfPresent(skinUrl);
|
||||
}
|
||||
|
||||
public static Skin getCachedSkin(String skinUrl) {
|
||||
return permanentSkins.getOrDefault(skinUrl, cachedSkins.getIfPresent(skinUrl));
|
||||
/**
|
||||
* If skin data fails to apply, or there is no skin data to apply, determine what skin we should give as a fallback.
|
||||
*/
|
||||
static SkinData determineFallbackSkinData(UUID uuid) {
|
||||
Skin skin = null;
|
||||
Cape cape = null;
|
||||
SkinGeometry geometry = SkinGeometry.WIDE;
|
||||
|
||||
if (GeyserImpl.getInstance().getConfig().getRemote().authType() != AuthType.ONLINE) {
|
||||
// Let's see if this player is a Bedrock player, and if so, let's pull their skin.
|
||||
GeyserSession session = GeyserImpl.getInstance().connectionByUuid(uuid);
|
||||
if (session != null) {
|
||||
String skinId = session.getClientData().getSkinId();
|
||||
skin = CACHED_BEDROCK_SKINS.getIfPresent(skinId);
|
||||
String capeId = session.getClientData().getCapeId();
|
||||
cape = CACHED_BEDROCK_CAPES.getIfPresent(capeId);
|
||||
geometry = cachedGeometry.getOrDefault(uuid, geometry);
|
||||
}
|
||||
}
|
||||
|
||||
if (skin == null) {
|
||||
// We don't have a skin for the player right now. Fall back to a default.
|
||||
ProvidedSkins.ProvidedSkin providedSkin = ProvidedSkins.getDefaultPlayerSkin(uuid);
|
||||
skin = providedSkin.getData();
|
||||
geometry = providedSkin.isSlim() ? SkinProvider.SkinGeometry.SLIM : SkinProvider.SkinGeometry.WIDE;
|
||||
}
|
||||
|
||||
if (cape == null) {
|
||||
cape = EMPTY_CAPE;
|
||||
}
|
||||
|
||||
return new SkinData(skin, cape, geometry);
|
||||
}
|
||||
|
||||
public static Cape getCachedCape(String capeUrl) {
|
||||
Cape cape = capeUrl != null ? cachedCapes.getIfPresent(capeUrl) : EMPTY_CAPE;
|
||||
return cape != null ? cape : EMPTY_CAPE;
|
||||
/**
|
||||
* Used as a fallback if an official Java cape doesn't exist for this user.
|
||||
*/
|
||||
@Nonnull
|
||||
private static Cape getCachedBedrockCape(UUID uuid) {
|
||||
GeyserSession session = GeyserImpl.getInstance().connectionByUuid(uuid);
|
||||
if (session != null) {
|
||||
String capeId = session.getClientData().getCapeId();
|
||||
Cape bedrockCape = CACHED_BEDROCK_CAPES.getIfPresent(capeId);
|
||||
if (bedrockCape != null) {
|
||||
return bedrockCape;
|
||||
}
|
||||
}
|
||||
return EMPTY_CAPE;
|
||||
}
|
||||
|
||||
public static CompletableFuture<SkinProvider.SkinData> requestSkinData(PlayerEntity entity) {
|
||||
@Nullable
|
||||
static Cape getCachedCape(String capeUrl) {
|
||||
if (capeUrl == null) {
|
||||
return null;
|
||||
}
|
||||
return CACHED_JAVA_CAPES.getIfPresent(capeUrl);
|
||||
}
|
||||
|
||||
static CompletableFuture<SkinProvider.SkinData> requestSkinData(PlayerEntity entity) {
|
||||
SkinManager.GameProfileData data = SkinManager.GameProfileData.from(entity);
|
||||
if (data == null) {
|
||||
// This player likely does not have a textures property
|
||||
return CompletableFuture.completedFuture(determineFallbackSkinData(entity.getUuid()));
|
||||
}
|
||||
|
||||
return requestSkinAndCape(entity.getUuid(), data.skinUrl(), data.capeUrl())
|
||||
.thenApplyAsync(skinAndCape -> {
|
||||
try {
|
||||
Skin skin = skinAndCape.getSkin();
|
||||
Cape cape = skinAndCape.getCape();
|
||||
SkinGeometry geometry = SkinGeometry.getLegacy(data.isAlex());
|
||||
Skin skin = skinAndCape.skin();
|
||||
Cape cape = skinAndCape.cape();
|
||||
SkinGeometry geometry = data.isAlex() ? SkinGeometry.SLIM : SkinGeometry.WIDE;
|
||||
|
||||
if (cape.isFailed()) {
|
||||
cape = getOrDefault(requestBedrockCape(entity.getUuid()),
|
||||
EMPTY_CAPE, 3);
|
||||
// Whether we should see if this player has a Bedrock skin we should check for on failure of
|
||||
// any skin property
|
||||
boolean checkForBedrock = entity.getUuid().version() != 4;
|
||||
|
||||
if (cape.failed() && checkForBedrock) {
|
||||
cape = getCachedBedrockCape(entity.getUuid());
|
||||
}
|
||||
|
||||
if (cape.isFailed() && ALLOW_THIRD_PARTY_CAPES) {
|
||||
if (cape.failed() && ALLOW_THIRD_PARTY_CAPES) {
|
||||
cape = getOrDefault(requestUnofficialCape(
|
||||
cape, entity.getUuid(),
|
||||
entity.getUsername(), false
|
||||
), EMPTY_CAPE, CapeProvider.VALUES.length * 3);
|
||||
}
|
||||
|
||||
geometry = getOrDefault(requestBedrockGeometry(
|
||||
geometry, entity.getUuid()
|
||||
), geometry, 3);
|
||||
|
||||
boolean isDeadmau5 = "deadmau5".equals(entity.getUsername());
|
||||
// Not a bedrock player check for ears
|
||||
if (geometry.isFailed() && (ALLOW_THIRD_PARTY_EARS || isDeadmau5)) {
|
||||
if (geometry.failed() && (ALLOW_THIRD_PARTY_EARS || isDeadmau5)) {
|
||||
boolean isEars;
|
||||
|
||||
// Its deadmau5, gotta support his skin :)
|
||||
|
@ -213,26 +286,17 @@ public class SkinProvider {
|
|||
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.skin.fail", entity.getUuid()), e);
|
||||
}
|
||||
|
||||
return new SkinData(skinAndCape.getSkin(), skinAndCape.getCape(), null);
|
||||
return new SkinData(skinAndCape.skin(), skinAndCape.cape(), null);
|
||||
});
|
||||
}
|
||||
|
||||
public static CompletableFuture<SkinAndCape> requestSkinAndCape(UUID playerId, String skinUrl, String capeUrl) {
|
||||
private static CompletableFuture<SkinAndCape> requestSkinAndCape(UUID playerId, String skinUrl, String capeUrl) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
long time = System.currentTimeMillis();
|
||||
String newSkinUrl = skinUrl;
|
||||
|
||||
if ("steve".equals(skinUrl) || "alex".equals(skinUrl)) {
|
||||
GeyserSession session = GeyserImpl.getInstance().connectionByUuid(playerId);
|
||||
|
||||
if (session != null) {
|
||||
newSkinUrl = session.getClientData().getSkinId();
|
||||
}
|
||||
}
|
||||
|
||||
CapeProvider provider = capeUrl != null ? CapeProvider.MINECRAFT : null;
|
||||
SkinAndCape skinAndCape = new SkinAndCape(
|
||||
getOrDefault(requestSkin(playerId, newSkinUrl, false), EMPTY_SKIN, 5),
|
||||
getOrDefault(requestSkin(playerId, skinUrl, false), EMPTY_SKIN, 5),
|
||||
getOrDefault(requestCape(capeUrl, provider, false), EMPTY_CAPE, 5)
|
||||
);
|
||||
|
||||
|
@ -241,7 +305,7 @@ public class SkinProvider {
|
|||
}, EXECUTOR_SERVICE);
|
||||
}
|
||||
|
||||
public static CompletableFuture<Skin> requestSkin(UUID playerId, String textureUrl, boolean newThread) {
|
||||
static CompletableFuture<Skin> requestSkin(UUID playerId, String textureUrl, boolean newThread) {
|
||||
if (textureUrl == null || textureUrl.isEmpty()) return CompletableFuture.completedFuture(EMPTY_SKIN);
|
||||
CompletableFuture<Skin> requestedSkin = requestedSkins.get(textureUrl);
|
||||
if (requestedSkin != null) {
|
||||
|
@ -249,7 +313,7 @@ public class SkinProvider {
|
|||
return requestedSkin;
|
||||
}
|
||||
|
||||
Skin cachedSkin = getCachedSkin(textureUrl);
|
||||
Skin cachedSkin = CACHED_JAVA_SKINS.getIfPresent(textureUrl);
|
||||
if (cachedSkin != null) {
|
||||
return CompletableFuture.completedFuture(cachedSkin);
|
||||
}
|
||||
|
@ -259,23 +323,26 @@ public class SkinProvider {
|
|||
future = CompletableFuture.supplyAsync(() -> supplySkin(playerId, textureUrl), EXECUTOR_SERVICE)
|
||||
.whenCompleteAsync((skin, throwable) -> {
|
||||
skin.updated = true;
|
||||
cachedSkins.put(textureUrl, skin);
|
||||
CACHED_JAVA_SKINS.put(textureUrl, skin);
|
||||
requestedSkins.remove(textureUrl);
|
||||
});
|
||||
requestedSkins.put(textureUrl, future);
|
||||
} else {
|
||||
Skin skin = supplySkin(playerId, textureUrl);
|
||||
future = CompletableFuture.completedFuture(skin);
|
||||
cachedSkins.put(textureUrl, skin);
|
||||
CACHED_JAVA_SKINS.put(textureUrl, skin);
|
||||
}
|
||||
return future;
|
||||
}
|
||||
|
||||
public static CompletableFuture<Cape> requestCape(String capeUrl, CapeProvider provider, boolean newThread) {
|
||||
private static CompletableFuture<Cape> requestCape(String capeUrl, CapeProvider provider, boolean newThread) {
|
||||
if (capeUrl == null || capeUrl.isEmpty()) return CompletableFuture.completedFuture(EMPTY_CAPE);
|
||||
if (requestedCapes.containsKey(capeUrl)) return requestedCapes.get(capeUrl); // already requested
|
||||
CompletableFuture<Cape> requestedCape = requestedCapes.get(capeUrl);
|
||||
if (requestedCape != null) {
|
||||
return requestedCape;
|
||||
}
|
||||
|
||||
Cape cachedCape = cachedCapes.getIfPresent(capeUrl);
|
||||
Cape cachedCape = CACHED_JAVA_CAPES.getIfPresent(capeUrl);
|
||||
if (cachedCape != null) {
|
||||
return CompletableFuture.completedFuture(cachedCape);
|
||||
}
|
||||
|
@ -284,21 +351,21 @@ public class SkinProvider {
|
|||
if (newThread) {
|
||||
future = CompletableFuture.supplyAsync(() -> supplyCape(capeUrl, provider), EXECUTOR_SERVICE)
|
||||
.whenCompleteAsync((cape, throwable) -> {
|
||||
cachedCapes.put(capeUrl, cape);
|
||||
CACHED_JAVA_CAPES.put(capeUrl, cape);
|
||||
requestedCapes.remove(capeUrl);
|
||||
});
|
||||
requestedCapes.put(capeUrl, future);
|
||||
} else {
|
||||
Cape cape = supplyCape(capeUrl, provider); // blocking
|
||||
future = CompletableFuture.completedFuture(cape);
|
||||
cachedCapes.put(capeUrl, cape);
|
||||
CACHED_JAVA_CAPES.put(capeUrl, cape);
|
||||
}
|
||||
return future;
|
||||
}
|
||||
|
||||
public static CompletableFuture<Cape> requestUnofficialCape(Cape officialCape, UUID playerId,
|
||||
private static CompletableFuture<Cape> requestUnofficialCape(Cape officialCape, UUID playerId,
|
||||
String username, boolean newThread) {
|
||||
if (officialCape.isFailed() && ALLOW_THIRD_PARTY_CAPES) {
|
||||
if (officialCape.failed() && ALLOW_THIRD_PARTY_CAPES) {
|
||||
for (CapeProvider provider : CapeProvider.VALUES) {
|
||||
if (provider.type != CapeUrlType.USERNAME && IS_NPC.test(playerId)) {
|
||||
continue;
|
||||
|
@ -308,7 +375,7 @@ public class SkinProvider {
|
|||
requestCape(provider.getUrlFor(playerId, username), provider, newThread),
|
||||
EMPTY_CAPE, 4
|
||||
);
|
||||
if (!cape1.isFailed()) {
|
||||
if (!cape1.failed()) {
|
||||
return CompletableFuture.completedFuture(cape1);
|
||||
}
|
||||
}
|
||||
|
@ -316,7 +383,7 @@ public class SkinProvider {
|
|||
return CompletableFuture.completedFuture(officialCape);
|
||||
}
|
||||
|
||||
public static CompletableFuture<Skin> requestEars(String earsUrl, boolean newThread, Skin skin) {
|
||||
private static CompletableFuture<Skin> requestEars(String earsUrl, boolean newThread, Skin skin) {
|
||||
if (earsUrl == null || earsUrl.isEmpty()) return CompletableFuture.completedFuture(skin);
|
||||
|
||||
CompletableFuture<Skin> future;
|
||||
|
@ -339,7 +406,7 @@ public class SkinProvider {
|
|||
* @param newThread Should we start in a new thread
|
||||
* @return The updated skin with ears
|
||||
*/
|
||||
public static CompletableFuture<Skin> requestUnofficialEars(Skin officialSkin, UUID playerId, String username, boolean newThread) {
|
||||
private static CompletableFuture<Skin> requestUnofficialEars(Skin officialSkin, UUID playerId, String username, boolean newThread) {
|
||||
for (EarsProvider provider : EarsProvider.VALUES) {
|
||||
if (provider.type != CapeUrlType.USERNAME && IS_NPC.test(playerId)) {
|
||||
continue;
|
||||
|
@ -357,30 +424,17 @@ public class SkinProvider {
|
|||
return CompletableFuture.completedFuture(officialSkin);
|
||||
}
|
||||
|
||||
public static CompletableFuture<Cape> requestBedrockCape(UUID playerID) {
|
||||
Cape bedrockCape = cachedCapes.getIfPresent(playerID.toString() + ".Bedrock");
|
||||
if (bedrockCape == null) {
|
||||
bedrockCape = EMPTY_CAPE;
|
||||
}
|
||||
return CompletableFuture.completedFuture(bedrockCape);
|
||||
static void storeBedrockSkin(UUID playerID, String skinId, byte[] skinData) {
|
||||
Skin skin = new Skin(playerID, skinId, skinData, System.currentTimeMillis(), true, false);
|
||||
CACHED_BEDROCK_SKINS.put(skin.getTextureUrl(), skin);
|
||||
}
|
||||
|
||||
public static CompletableFuture<SkinGeometry> requestBedrockGeometry(SkinGeometry currentGeometry, UUID playerID) {
|
||||
SkinGeometry bedrockGeometry = cachedGeometry.getOrDefault(playerID, currentGeometry);
|
||||
return CompletableFuture.completedFuture(bedrockGeometry);
|
||||
static void storeBedrockCape(String capeId, byte[] capeData) {
|
||||
Cape cape = new Cape(capeId, capeId, capeData, System.currentTimeMillis(), false);
|
||||
CACHED_BEDROCK_CAPES.put(capeId, cape);
|
||||
}
|
||||
|
||||
public static void storeBedrockSkin(UUID playerID, String skinID, byte[] skinData) {
|
||||
Skin skin = new Skin(playerID, skinID, skinData, System.currentTimeMillis(), true, false);
|
||||
cachedSkins.put(skin.getTextureUrl(), skin);
|
||||
}
|
||||
|
||||
public static void storeBedrockCape(UUID playerID, byte[] capeData) {
|
||||
Cape cape = new Cape(playerID.toString() + ".Bedrock", playerID.toString(), capeData, System.currentTimeMillis(), false);
|
||||
cachedCapes.put(playerID.toString() + ".Bedrock", cape);
|
||||
}
|
||||
|
||||
public static void storeBedrockGeometry(UUID playerID, byte[] geometryName, byte[] geometryData) {
|
||||
static void storeBedrockGeometry(UUID playerID, byte[] geometryName, byte[] geometryData) {
|
||||
SkinGeometry geometry = new SkinGeometry(new String(geometryName), new String(geometryData), false);
|
||||
cachedGeometry.put(playerID, geometry);
|
||||
}
|
||||
|
@ -391,7 +445,7 @@ public class SkinProvider {
|
|||
* @param skin The skin to cache
|
||||
*/
|
||||
public static void storeEarSkin(Skin skin) {
|
||||
cachedSkins.put(skin.getTextureUrl(), skin);
|
||||
CACHED_JAVA_SKINS.put(skin.getTextureUrl(), skin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -400,7 +454,7 @@ public class SkinProvider {
|
|||
* @param playerID The UUID to cache it against
|
||||
* @param isSlim If the player is using an slim base
|
||||
*/
|
||||
public static void storeEarGeometry(UUID playerID, boolean isSlim) {
|
||||
private static void storeEarGeometry(UUID playerID, boolean isSlim) {
|
||||
cachedGeometry.put(playerID, SkinGeometry.getEars(isSlim));
|
||||
}
|
||||
|
||||
|
@ -414,7 +468,7 @@ public class SkinProvider {
|
|||
}
|
||||
|
||||
private static Cape supplyCape(String capeUrl, CapeProvider provider) {
|
||||
byte[] cape = EMPTY_CAPE.getCapeData();
|
||||
byte[] cape = EMPTY_CAPE.capeData();
|
||||
try {
|
||||
cape = requestImage(capeUrl, provider);
|
||||
} catch (Exception ignored) {
|
||||
|
@ -539,48 +593,23 @@ public class SkinProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
* If a skull has a username but no textures, request them.
|
||||
* Request textures from a player's UUID
|
||||
*
|
||||
* @param skullOwner the CompoundTag of the skull with no textures
|
||||
* @param uuid the player's UUID without any hyphens
|
||||
* @return a completable GameProfile with textures included
|
||||
*/
|
||||
public static CompletableFuture<String> requestTexturesFromUsername(CompoundTag skullOwner) {
|
||||
public static CompletableFuture<String> requestTexturesFromUUID(String uuid) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
Tag uuidTag = skullOwner.get("Id");
|
||||
String uuidToString = "";
|
||||
JsonNode node;
|
||||
boolean retrieveUuidFromInternet = !(uuidTag instanceof IntArrayTag); // also covers null check
|
||||
|
||||
if (!retrieveUuidFromInternet) {
|
||||
int[] uuidAsArray = ((IntArrayTag) uuidTag).getValue();
|
||||
// thank u viaversion
|
||||
UUID uuid = new UUID((long) uuidAsArray[0] << 32 | ((long) uuidAsArray[1] & 0xFFFFFFFFL),
|
||||
(long) uuidAsArray[2] << 32 | ((long) uuidAsArray[3] & 0xFFFFFFFFL));
|
||||
retrieveUuidFromInternet = uuid.version() != 4;
|
||||
uuidToString = uuid.toString().replace("-", "");
|
||||
}
|
||||
|
||||
try {
|
||||
if (retrieveUuidFromInternet) {
|
||||
// Offline skin, or no present UUID
|
||||
node = WebUtils.getJson("https://api.mojang.com/users/profiles/minecraft/" + skullOwner.get("Name").getValue());
|
||||
JsonNode id = node.get("id");
|
||||
if (id == null) {
|
||||
GeyserImpl.getInstance().getLogger().debug("No UUID found in Mojang response for " + skullOwner.get("Name").getValue());
|
||||
return null;
|
||||
}
|
||||
uuidToString = id.asText();
|
||||
}
|
||||
|
||||
// Get textures from UUID
|
||||
node = WebUtils.getJson("https://sessionserver.mojang.com/session/minecraft/profile/" + uuidToString);
|
||||
JsonNode node = WebUtils.getJson("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid);
|
||||
JsonNode properties = node.get("properties");
|
||||
if (properties == null) {
|
||||
GeyserImpl.getInstance().getLogger().debug("No properties found in Mojang response for " + uuidToString);
|
||||
GeyserImpl.getInstance().getLogger().debug("No properties found in Mojang response for " + uuid);
|
||||
return null;
|
||||
}
|
||||
return node.get("properties").get(0).get("value").asText();
|
||||
} catch (Exception e) {
|
||||
GeyserImpl.getInstance().getLogger().debug("Unable to request textures for " + uuid);
|
||||
if (GeyserImpl.getInstance().getConfig().isDebugMode()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -589,6 +618,37 @@ public class SkinProvider {
|
|||
}, EXECUTOR_SERVICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request textures from a player's username
|
||||
*
|
||||
* @param username the player's username
|
||||
* @return a completable GameProfile with textures included
|
||||
*/
|
||||
public static CompletableFuture<String> requestTexturesFromUsername(String username) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
// Offline skin, or no present UUID
|
||||
JsonNode node = WebUtils.getJson("https://api.mojang.com/users/profiles/minecraft/" + username);
|
||||
JsonNode id = node.get("id");
|
||||
if (id == null) {
|
||||
GeyserImpl.getInstance().getLogger().debug("No UUID found in Mojang response for " + username);
|
||||
return null;
|
||||
}
|
||||
return id.asText();
|
||||
} catch (Exception e) {
|
||||
if (GeyserImpl.getInstance().getConfig().isDebugMode()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}, EXECUTOR_SERVICE).thenCompose(uuid -> {
|
||||
if (uuid == null) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
return requestTexturesFromUUID(uuid);
|
||||
});
|
||||
}
|
||||
|
||||
private static BufferedImage downloadImage(String imageUrl, CapeProvider provider) throws IOException {
|
||||
if (provider == CapeProvider.FIVEZIG)
|
||||
return readFiveZigCape(imageUrl);
|
||||
|
@ -604,7 +664,7 @@ public class SkinProvider {
|
|||
}
|
||||
|
||||
private static BufferedImage readFiveZigCape(String url) throws IOException {
|
||||
JsonNode element = OBJECT_MAPPER.readTree(WebUtils.getBody(url));
|
||||
JsonNode element = GeyserImpl.JSON_MAPPER.readTree(WebUtils.getBody(url));
|
||||
if (element != null && element.isObject()) {
|
||||
JsonNode capeElement = element.get("d");
|
||||
if (capeElement == null || capeElement.isNull()) return null;
|
||||
|
@ -683,13 +743,12 @@ public class SkinProvider {
|
|||
return defaultValue;
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public static class SkinAndCape {
|
||||
private final Skin skin;
|
||||
private final Cape cape;
|
||||
public record SkinAndCape(Skin skin, Cape cape) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a full package of skin, cape, and geometry.
|
||||
*/
|
||||
public record SkinData(Skin skin, Cape cape, SkinGeometry geometry) {
|
||||
}
|
||||
|
||||
|
@ -703,29 +762,19 @@ public class SkinProvider {
|
|||
private boolean updated;
|
||||
private boolean ears;
|
||||
|
||||
private Skin(long requestedOn, String textureUrl, byte[] skinData) {
|
||||
Skin(long requestedOn, String textureUrl, byte[] skinData) {
|
||||
this.requestedOn = requestedOn;
|
||||
this.textureUrl = textureUrl;
|
||||
this.skinData = skinData;
|
||||
}
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public static class Cape {
|
||||
private final String textureUrl;
|
||||
private final String capeId;
|
||||
private final byte[] capeData;
|
||||
private final long requestedOn;
|
||||
private final boolean failed;
|
||||
public record Cape(String textureUrl, String capeId, byte[] capeData, long requestedOn, boolean failed) {
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public static class SkinGeometry {
|
||||
private final String geometryName;
|
||||
private final String geometryData;
|
||||
private final boolean failed;
|
||||
public record SkinGeometry(String geometryName, String geometryData, boolean failed) {
|
||||
public static SkinGeometry WIDE = getLegacy(false);
|
||||
public static SkinGeometry SLIM = getLegacy(true);
|
||||
|
||||
/**
|
||||
* Generate generic geometry
|
||||
|
@ -733,7 +782,7 @@ public class SkinProvider {
|
|||
* @param isSlim Should it be the alex model
|
||||
* @return The generic geometry object
|
||||
*/
|
||||
public static SkinGeometry getLegacy(boolean isSlim) {
|
||||
private static SkinGeometry getLegacy(boolean isSlim) {
|
||||
return new SkinProvider.SkinGeometry("{\"geometry\" :{\"default\" :\"geometry.humanoid.custom" + (isSlim ? "Slim" : "") + "\"}}", "", true);
|
||||
}
|
||||
|
||||
|
@ -743,7 +792,7 @@ public class SkinProvider {
|
|||
* @param isSlim Should it be the alex model
|
||||
* @return The generated geometry for the ears model
|
||||
*/
|
||||
public static SkinGeometry getEars(boolean isSlim) {
|
||||
private static SkinGeometry getEars(boolean isSlim) {
|
||||
return new SkinProvider.SkinGeometry("{\"geometry\" :{\"default\" :\"geometry.humanoid.ears" + (isSlim ? "Slim" : "") + "\"}}", (isSlim ? EARS_GEOMETRY_SLIM : EARS_GEOMETRY), false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,11 +29,12 @@ import com.nukkitx.protocol.bedrock.data.skin.ImageData;
|
|||
import com.nukkitx.protocol.bedrock.data.skin.SerializedSkin;
|
||||
import com.nukkitx.protocol.bedrock.packet.PlayerSkinPacket;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.entity.type.player.PlayerEntity;
|
||||
import org.geysermc.geyser.entity.type.player.SkullPlayerEntity;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class SkullSkinManager extends SkinManager {
|
||||
|
@ -42,34 +43,43 @@ public class SkullSkinManager extends SkinManager {
|
|||
// Prevents https://cdn.discordapp.com/attachments/613194828359925800/779458146191147008/unknown.png
|
||||
skinId = skinId + "_skull";
|
||||
return SerializedSkin.of(
|
||||
skinId, "", SkinProvider.SKULL_GEOMETRY.getGeometryName(), ImageData.of(skinData), Collections.emptyList(),
|
||||
ImageData.of(SkinProvider.EMPTY_CAPE.getCapeData()), SkinProvider.SKULL_GEOMETRY.getGeometryData(),
|
||||
"", true, false, false, SkinProvider.EMPTY_CAPE.getCapeId(), skinId
|
||||
skinId, "", SkinProvider.SKULL_GEOMETRY.geometryName(), ImageData.of(skinData), Collections.emptyList(),
|
||||
ImageData.of(SkinProvider.EMPTY_CAPE.capeData()), SkinProvider.SKULL_GEOMETRY.geometryData(),
|
||||
"", true, false, false, SkinProvider.EMPTY_CAPE.capeId(), skinId
|
||||
);
|
||||
}
|
||||
|
||||
public static void requestAndHandleSkin(PlayerEntity entity, GeyserSession session,
|
||||
public static void requestAndHandleSkin(SkullPlayerEntity entity, GeyserSession session,
|
||||
Consumer<SkinProvider.Skin> skinConsumer) {
|
||||
BiConsumer<SkinProvider.Skin, Throwable> applySkin = (skin, throwable) -> {
|
||||
try {
|
||||
PlayerSkinPacket packet = new PlayerSkinPacket();
|
||||
packet.setUuid(entity.getUuid());
|
||||
packet.setOldSkinName("");
|
||||
packet.setNewSkinName(skin.getTextureUrl());
|
||||
packet.setSkin(buildSkullEntryManually(skin.getTextureUrl(), skin.getSkinData()));
|
||||
packet.setTrustedSkin(true);
|
||||
session.sendUpstreamPacket(packet);
|
||||
} catch (Exception e) {
|
||||
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.skin.fail", entity.getUuid()), e);
|
||||
}
|
||||
|
||||
if (skinConsumer != null) {
|
||||
skinConsumer.accept(skin);
|
||||
}
|
||||
};
|
||||
|
||||
GameProfileData data = GameProfileData.from(entity);
|
||||
|
||||
SkinProvider.requestSkin(entity.getUuid(), data.skinUrl(), true)
|
||||
.whenCompleteAsync((skin, throwable) -> {
|
||||
try {
|
||||
PlayerSkinPacket packet = new PlayerSkinPacket();
|
||||
packet.setUuid(entity.getUuid());
|
||||
packet.setOldSkinName("");
|
||||
packet.setNewSkinName(skin.getTextureUrl());
|
||||
packet.setSkin(buildSkullEntryManually(skin.getTextureUrl(), skin.getSkinData()));
|
||||
packet.setTrustedSkin(true);
|
||||
session.sendUpstreamPacket(packet);
|
||||
} catch (Exception e) {
|
||||
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.skin.fail", entity.getUuid()), e);
|
||||
}
|
||||
|
||||
if (skinConsumer != null) {
|
||||
skinConsumer.accept(skin);
|
||||
}
|
||||
});
|
||||
if (data == null) {
|
||||
GeyserImpl.getInstance().getLogger().debug("Using fallback skin for skull at " + entity.getSkullPosition() +
|
||||
" with texture value: " + entity.getTexturesProperty() + " and UUID: " + entity.getSkullUUID());
|
||||
// No texture available, fallback using the UUID
|
||||
SkinProvider.SkinData fallback = SkinProvider.determineFallbackSkinData(entity.getSkullUUID());
|
||||
applySkin.accept(fallback.skin(), null);
|
||||
} else {
|
||||
SkinProvider.requestSkin(entity.getUuid(), data.skinUrl(), true)
|
||||
.whenCompleteAsync(applySkin);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
package org.geysermc.geyser.text;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.BuiltinChatType;
|
||||
import com.github.steveice10.mc.protocol.data.game.chat.BuiltinChatType;
|
||||
import com.nukkitx.protocol.bedrock.packet.TextPacket;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
|
||||
|
|
|
@ -25,91 +25,45 @@
|
|||
|
||||
package org.geysermc.geyser.text;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import lombok.Getter;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.network.GameProtocol;
|
||||
import org.geysermc.geyser.util.AssetUtils;
|
||||
import org.geysermc.geyser.util.FileUtils;
|
||||
import org.geysermc.geyser.util.WebUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class MinecraftLocale {
|
||||
|
||||
public static final Map<String, Map<String, String>> LOCALE_MAPPINGS = new HashMap<>();
|
||||
|
||||
private static final Map<String, Asset> ASSET_MAP = new HashMap<>();
|
||||
|
||||
private static VersionDownload clientJarInfo;
|
||||
|
||||
static {
|
||||
// Create the locales folder
|
||||
File localesFolder = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("locales").toFile();
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
localesFolder.mkdir();
|
||||
|
||||
// Download the latest asset list and cache it
|
||||
generateAssetCache().whenComplete((aVoid, ex) -> downloadAndLoadLocale(GeyserLocale.getDefaultLocale()));
|
||||
// FIXME TEMPORARY
|
||||
try {
|
||||
Files.delete(localesFolder.toPath().resolve("en_us.hash"));
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the latest versions asset cache from Mojang so we can grab the locale files later
|
||||
*/
|
||||
private static CompletableFuture<Void> generateAssetCache() {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
// Get the version manifest from Mojang
|
||||
VersionManifest versionManifest = GeyserImpl.JSON_MAPPER.readValue(WebUtils.getBody("https://launchermeta.mojang.com/mc/game/version_manifest.json"), VersionManifest.class);
|
||||
|
||||
// Get the url for the latest version of the games manifest
|
||||
String latestInfoURL = "";
|
||||
for (Version version : versionManifest.getVersions()) {
|
||||
if (version.getId().equals(GameProtocol.getJavaCodec().getMinecraftVersion())) {
|
||||
latestInfoURL = version.getUrl();
|
||||
break;
|
||||
public static void ensureEN_US() {
|
||||
File localeFile = getFile("en_us");
|
||||
AssetUtils.addTask(!localeFile.exists(), new AssetUtils.ClientJarTask("assets/minecraft/lang/en_us.json",
|
||||
(stream) -> AssetUtils.saveFile(localeFile, stream),
|
||||
() -> {
|
||||
if ("en_us".equals(GeyserLocale.getDefaultLocale())) {
|
||||
loadLocale("en_us");
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure we definitely got a version
|
||||
if (latestInfoURL.isEmpty()) {
|
||||
throw new Exception(GeyserLocale.getLocaleStringLog("geyser.locale.fail.latest_version"));
|
||||
}
|
||||
|
||||
// Get the individual version manifest
|
||||
VersionInfo versionInfo = GeyserImpl.JSON_MAPPER.readValue(WebUtils.getBody(latestInfoURL), VersionInfo.class);
|
||||
|
||||
// Get the client jar for use when downloading the en_us locale
|
||||
GeyserImpl.getInstance().getLogger().debug(GeyserImpl.JSON_MAPPER.writeValueAsString(versionInfo.getDownloads()));
|
||||
clientJarInfo = versionInfo.getDownloads().get("client");
|
||||
GeyserImpl.getInstance().getLogger().debug(GeyserImpl.JSON_MAPPER.writeValueAsString(clientJarInfo));
|
||||
|
||||
// Get the assets list
|
||||
JsonNode assets = GeyserImpl.JSON_MAPPER.readTree(WebUtils.getBody(versionInfo.getAssetIndex().getUrl())).get("objects");
|
||||
|
||||
// Put each asset into an array for use later
|
||||
Iterator<Map.Entry<String, JsonNode>> assetIterator = assets.fields();
|
||||
while (assetIterator.hasNext()) {
|
||||
Map.Entry<String, JsonNode> entry = assetIterator.next();
|
||||
if (!entry.getKey().startsWith("minecraft/lang/")) {
|
||||
// No need to cache non-language assets as we don't use them
|
||||
continue;
|
||||
}
|
||||
|
||||
Asset asset = GeyserImpl.JSON_MAPPER.treeToValue(entry.getValue(), Asset.class);
|
||||
ASSET_MAP.put(entry.getKey(), asset);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.locale.fail.asset_cache", (!e.getMessage().isEmpty() ? e.getMessage() : e.getStackTrace())));
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,7 +79,7 @@ public class MinecraftLocale {
|
|||
}
|
||||
|
||||
// Check the locale isn't already loaded
|
||||
if (!ASSET_MAP.containsKey("minecraft/lang/" + locale + ".json") && !locale.equals("en_us")) {
|
||||
if (!AssetUtils.isAssetKnown("minecraft/lang/" + locale + ".json") && !locale.equals("en_us")) {
|
||||
if (loadLocale(locale)) {
|
||||
GeyserImpl.getInstance().getLogger().debug("Loaded locale locally while not being in asset map: " + locale);
|
||||
} else {
|
||||
|
@ -148,33 +102,15 @@ public class MinecraftLocale {
|
|||
* @param locale Locale to download
|
||||
*/
|
||||
private static void downloadLocale(String locale) {
|
||||
File localeFile = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("locales/" + locale + ".json").toFile();
|
||||
if (locale.equals("en_us")) {
|
||||
return;
|
||||
}
|
||||
File localeFile = getFile(locale);
|
||||
|
||||
// Check if we have already downloaded the locale file
|
||||
if (localeFile.exists()) {
|
||||
String curHash = "";
|
||||
String targetHash;
|
||||
|
||||
if (locale.equals("en_us")) {
|
||||
try {
|
||||
File hashFile = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("locales/en_us.hash").toFile();
|
||||
if (hashFile.exists()) {
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(hashFile))) {
|
||||
curHash = br.readLine().trim();
|
||||
}
|
||||
}
|
||||
} catch (IOException ignored) { }
|
||||
|
||||
if (clientJarInfo == null) {
|
||||
// Likely failed to download
|
||||
GeyserImpl.getInstance().getLogger().debug("Skipping en_US hash check as client jar is null.");
|
||||
return;
|
||||
}
|
||||
targetHash = clientJarInfo.getSha1();
|
||||
} else {
|
||||
curHash = byteArrayToHexString(FileUtils.calculateSHA1(localeFile));
|
||||
targetHash = ASSET_MAP.get("minecraft/lang/" + locale + ".json").getHash();
|
||||
}
|
||||
String curHash = byteArrayToHexString(FileUtils.calculateSHA1(localeFile));
|
||||
String targetHash = AssetUtils.getAsset("minecraft/lang/" + locale + ".json").getHash();
|
||||
|
||||
if (!curHash.equals(targetHash)) {
|
||||
GeyserImpl.getInstance().getLogger().debug("Locale out of date; re-downloading: " + locale);
|
||||
|
@ -184,22 +120,19 @@ public class MinecraftLocale {
|
|||
}
|
||||
}
|
||||
|
||||
// Create the en_us locale
|
||||
if (locale.equals("en_us")) {
|
||||
downloadEN_US(localeFile);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Get the hash and download the locale
|
||||
String hash = ASSET_MAP.get("minecraft/lang/" + locale + ".json").getHash();
|
||||
String hash = AssetUtils.getAsset("minecraft/lang/" + locale + ".json").getHash();
|
||||
WebUtils.downloadFile("https://resources.download.minecraft.net/" + hash.substring(0, 2) + "/" + hash, localeFile.toString());
|
||||
} catch (Exception e) {
|
||||
GeyserImpl.getInstance().getLogger().error("Unable to download locale file hash", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static File getFile(String locale) {
|
||||
return GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("locales/" + locale + ".json").toFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a locale already downloaded, if the file doesn't exist it just logs a warning
|
||||
*
|
||||
|
@ -254,51 +187,6 @@ public class MinecraftLocale {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download then en_us locale by downloading the server jar and extracting it from there.
|
||||
*
|
||||
* @param localeFile File to save the locale to
|
||||
*/
|
||||
private static void downloadEN_US(File localeFile) {
|
||||
try {
|
||||
// Let the user know we are downloading the JAR
|
||||
GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.locale.download.en_us"));
|
||||
GeyserImpl.getInstance().getLogger().debug("Download URL: " + clientJarInfo.getUrl());
|
||||
|
||||
// Download the smallest JAR (client or server)
|
||||
Path tmpFilePath = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("tmp_locale.jar");
|
||||
WebUtils.downloadFile(clientJarInfo.getUrl(), tmpFilePath.toString());
|
||||
|
||||
// Load in the JAR as a zip and extract the file
|
||||
try (ZipFile localeJar = new ZipFile(tmpFilePath.toString())) {
|
||||
try (InputStream fileStream = localeJar.getInputStream(localeJar.getEntry("assets/minecraft/lang/en_us.json"))) {
|
||||
try (FileOutputStream outStream = new FileOutputStream(localeFile)) {
|
||||
|
||||
// Write the file to the locale dir
|
||||
byte[] buf = new byte[fileStream.available()];
|
||||
int length;
|
||||
while ((length = fileStream.read(buf)) != -1) {
|
||||
outStream.write(buf, 0, length);
|
||||
}
|
||||
|
||||
// Flush all changes to disk and cleanup
|
||||
outStream.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store the latest jar hash
|
||||
FileUtils.writeFile(GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("locales/en_us.hash").toString(), clientJarInfo.getSha1().toCharArray());
|
||||
|
||||
// Delete the nolonger needed client/server jar
|
||||
Files.delete(tmpFilePath);
|
||||
|
||||
GeyserImpl.getInstance().getLogger().info(GeyserLocale.getLocaleStringLog("geyser.locale.download.en_us.done"));
|
||||
} catch (Exception e) {
|
||||
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.locale.fail.en_us"), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the given language string into the given locale, or falls back to the default locale
|
||||
*
|
||||
|
@ -333,111 +221,4 @@ public class MinecraftLocale {
|
|||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Getter
|
||||
static class VersionManifest {
|
||||
@JsonProperty("latest")
|
||||
private LatestVersion latestVersion;
|
||||
|
||||
@JsonProperty("versions")
|
||||
private List<Version> versions;
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Getter
|
||||
static class LatestVersion {
|
||||
@JsonProperty("release")
|
||||
private String release;
|
||||
|
||||
@JsonProperty("snapshot")
|
||||
private String snapshot;
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Getter
|
||||
static class Version {
|
||||
@JsonProperty("id")
|
||||
private String id;
|
||||
|
||||
@JsonProperty("type")
|
||||
private String type;
|
||||
|
||||
@JsonProperty("url")
|
||||
private String url;
|
||||
|
||||
@JsonProperty("time")
|
||||
private String time;
|
||||
|
||||
@JsonProperty("releaseTime")
|
||||
private String releaseTime;
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Getter
|
||||
static class VersionInfo {
|
||||
@JsonProperty("id")
|
||||
private String id;
|
||||
|
||||
@JsonProperty("type")
|
||||
private String type;
|
||||
|
||||
@JsonProperty("time")
|
||||
private String time;
|
||||
|
||||
@JsonProperty("releaseTime")
|
||||
private String releaseTime;
|
||||
|
||||
@JsonProperty("assetIndex")
|
||||
private AssetIndex assetIndex;
|
||||
|
||||
@JsonProperty("downloads")
|
||||
private Map<String, VersionDownload> downloads;
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Getter
|
||||
static class VersionDownload {
|
||||
@JsonProperty("sha1")
|
||||
private String sha1;
|
||||
|
||||
@JsonProperty("size")
|
||||
private int size;
|
||||
|
||||
@JsonProperty("url")
|
||||
private String url;
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Getter
|
||||
static class AssetIndex {
|
||||
@JsonProperty("id")
|
||||
private String id;
|
||||
|
||||
@JsonProperty("sha1")
|
||||
private String sha1;
|
||||
|
||||
@JsonProperty("size")
|
||||
private int size;
|
||||
|
||||
@JsonProperty("totalSize")
|
||||
private int totalSize;
|
||||
|
||||
@JsonProperty("url")
|
||||
private String url;
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Getter
|
||||
static class Asset {
|
||||
@JsonProperty("hash")
|
||||
private String hash;
|
||||
|
||||
@JsonProperty("size")
|
||||
private int size;
|
||||
}
|
||||
}
|
|
@ -65,8 +65,8 @@ public abstract class AbstractBlockInventoryTranslator extends BaseInventoryTran
|
|||
}
|
||||
|
||||
@Override
|
||||
public void prepareInventory(GeyserSession session, Inventory inventory) {
|
||||
holder.prepareInventory(this, session, inventory);
|
||||
public boolean prepareInventory(GeyserSession session, Inventory inventory) {
|
||||
return holder.prepareInventory(this, session, inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -59,10 +59,12 @@ public class AnvilInventoryTranslator extends AbstractBlockInventoryTranslator {
|
|||
CraftRecipeOptionalStackRequestActionData data = (CraftRecipeOptionalStackRequestActionData) request.getActions()[0];
|
||||
AnvilContainer container = (AnvilContainer) inventory;
|
||||
|
||||
// Required as of 1.18.30 - FilterTextPackets no longer appear to be sent
|
||||
String name = request.getFilterStrings()[data.getFilteredStringIndex()];
|
||||
if (!Objects.equals(name, container.getNewName())) {
|
||||
container.checkForRename(session, name);
|
||||
if (request.getFilterStrings().length != 0) {
|
||||
// Required as of 1.18.30 - FilterTextPackets no longer appear to be sent
|
||||
String name = request.getFilterStrings()[data.getFilteredStringIndex()];
|
||||
if (!Objects.equals(name, container.getNewName())) { // TODO is this still necessary after pre-1.19.50 support is dropped?
|
||||
container.checkForRename(session, name);
|
||||
}
|
||||
}
|
||||
|
||||
return super.translateRequest(session, inventory, request);
|
||||
|
|
|
@ -101,7 +101,7 @@ public abstract class InventoryTranslator {
|
|||
|
||||
public final int size;
|
||||
|
||||
public abstract void prepareInventory(GeyserSession session, Inventory inventory);
|
||||
public abstract boolean prepareInventory(GeyserSession session, Inventory inventory);
|
||||
public abstract void openInventory(GeyserSession session, Inventory inventory);
|
||||
public abstract void closeInventory(GeyserSession session, Inventory inventory);
|
||||
public abstract void updateProperty(GeyserSession session, Inventory inventory, int key, int value);
|
||||
|
|
|
@ -55,7 +55,8 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void prepareInventory(GeyserSession session, Inventory inventory) {
|
||||
public boolean prepareInventory(GeyserSession session, Inventory inventory) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -94,7 +94,7 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void prepareInventory(GeyserSession session, Inventory inventory) {
|
||||
public boolean prepareInventory(GeyserSession session, Inventory inventory) {
|
||||
MerchantContainer merchantInventory = (MerchantContainer) inventory;
|
||||
if (merchantInventory.getVillager() == null) {
|
||||
long geyserId = session.getEntityCache().getNextEntityId().incrementAndGet();
|
||||
|
@ -117,6 +117,8 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator {
|
|||
|
||||
merchantInventory.setVillager(villager);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -514,7 +514,8 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void prepareInventory(GeyserSession session, Inventory inventory) {
|
||||
public boolean prepareInventory(GeyserSession session, Inventory inventory) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.geysermc.geyser.level.block.DoubleChestValue;
|
|||
import org.geysermc.geyser.registry.BlockRegistries;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.translator.level.block.entity.DoubleChestBlockEntityTranslator;
|
||||
import org.geysermc.geyser.util.InventoryUtils;
|
||||
|
||||
public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
|
||||
private final int defaultJavaBlockState;
|
||||
|
@ -50,7 +51,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void prepareInventory(GeyserSession session, Inventory inventory) {
|
||||
public boolean prepareInventory(GeyserSession session, Inventory inventory) {
|
||||
// See BlockInventoryHolder - same concept there except we're also dealing with a specific block state
|
||||
if (session.getLastInteractionPlayerPosition().equals(session.getPlayerEntity().getPosition())) {
|
||||
int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
|
||||
|
@ -76,11 +77,16 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
|
|||
dataPacket.setData(tag.build());
|
||||
dataPacket.setBlockPosition(session.getLastInteractionBlockPosition());
|
||||
session.sendUpstreamPacket(dataPacket);
|
||||
return;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Vector3i position = session.getPlayerEntity().getPosition().toInt().add(Vector3i.UP);
|
||||
Vector3i position = InventoryUtils.findAvailableWorldSpace(session);
|
||||
if (position == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Vector3i pairPosition = position.add(Vector3i.UNIT_X);
|
||||
int bedrockBlockId = session.getBlockMappings().getBedrockBlockId(defaultJavaBlockState);
|
||||
|
||||
|
@ -125,6 +131,8 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
|
|||
session.sendUpstreamPacket(dataPacket);
|
||||
|
||||
inventory.setHolderPosition(position);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue