Merge pull request #194 from GeyserMC/plugin

Merge branch 'plugin' into master (Closes #54)
This commit is contained in:
Redned 2020-03-04 21:00:29 -06:00 committed by GitHub
commit f9e1964b6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
126 changed files with 2770 additions and 2139 deletions

View file

@ -28,4 +28,4 @@ jobs:
if: success() if: success()
with: with:
name: Geyser name: Geyser
path: target/Geyser.jar path: bootstrap/standalone/target/Geyser.jar

1
.gitignore vendored
View file

@ -224,3 +224,4 @@ nbdist/
### Geyser ### ### Geyser ###
config.yml config.yml
logs/ logs/
public-key.pem

2
Jenkinsfile vendored
View file

@ -15,7 +15,7 @@ pipeline {
} }
post { post {
success { success {
archiveArtifacts artifacts: 'target/Geyser.jar', fingerprint: true archiveArtifacts artifacts: 'bootstrap/**/target/*.jar', excludes: 'bootstrap/**/target/original-*.jar', fingerprint: true
} }
} }
} }

View file

@ -16,7 +16,7 @@ The ultimate goal of this project is to allow Minecraft: Bedrock Edition users t
### Currently supporting Minecraft Bedrock v1.14.X and Minecraft Java v1.15.2. ### Currently supporting Minecraft Bedrock v1.14.X and Minecraft Java v1.15.2.
## Setting Up ## Setting Up
Please note, Geyser is **not** (currently) a plugin. Watch the video below or take a look [here](https://github.com/GeyserMC/Geyser/wiki#Setup) for how to set it up. Take a look [here](https://github.com/GeyserMC/Geyser/wiki#Setup) for how to set up Geyser.
[![YouTube Video](https://img.youtube.com/vi/U7dZZ8w7Gi4/0.jpg)](https://www.youtube.com/watch?v=U7dZZ8w7Gi4) [![YouTube Video](https://img.youtube.com/vi/U7dZZ8w7Gi4/0.jpg)](https://www.youtube.com/watch?v=U7dZZ8w7Gi4)
@ -35,7 +35,6 @@ Please note, Geyser is **not** (currently) a plugin. Watch the video below or ta
- Block Particles - Block Particles
- Block Entities ([`block-entities`](https://github.com/GeyserMC/Geyser/tree/block-entities)) - Block Entities ([`block-entities`](https://github.com/GeyserMC/Geyser/tree/block-entities))
- Some Entity Flags - Some Entity Flags
- Support to be Ran as a Plugin ([`plugin`](https://github.com/GeyserMC/Geyser/tree/plugin))
## Compiling ## Compiling
1. Clone the repo to your computer 1. Clone the repo to your computer

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.geysermc</groupId>
<artifactId>geyser-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>api</artifactId>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View file

@ -1,76 +0,0 @@
/*
* Copyright (c) 2019 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.api;
import org.geysermc.api.command.CommandMap;
import org.geysermc.api.logger.Logger;
import org.geysermc.api.plugin.PluginManager;
import java.util.Collection;
import java.util.concurrent.ScheduledExecutorService;
public interface Connector {
/**
* Returns the logger
*
* @return the logger
*/
Logger getLogger();
/**
* Returns the command map
*
* @return the command map
*/
CommandMap getCommandMap();
/**
* Returns the plugin manager
*
* @return the plugin manager
*/
PluginManager getPluginManager();
/**
* Returns the general thread pool
*
* @return the general thread pool
*/
ScheduledExecutorService getGeneralThreadPool();
/**
* Returns a collection of the connected players
*
* @return a collection of the connected players
*/
Collection<? extends Player> getConnectedPlayers();
/**
* Shuts down the connector
*/
void shutdown();
}

View file

@ -1,69 +0,0 @@
/*
* Copyright (c) 2019 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.api;
public class ConsoleColors {
public static final String RESET = "\u001b[0m";
public static final String BOLD = "\u001b[1m";
public static final String BLINK = "\u001b[5m";
public static final String WHITE = "\u001b[30m";
public static final String RED = "\u001b[31m";
public static final String GREEN = "\u001b[32m";
public static final String YELLOW = "\u001b[33m";
public static final String BLUE = "\u001b[34m";
public static final String MAGENTA = "\u001b[35m";
public static final String CYAN = "\u001b[36m";
public static final String LIGHT_GRAY = "\u001b[37m";
public static final String DARK_GRAY = "\u001b[90m";
public static final String BRIGHT_RED = "\u001b[91m";
public static final String BRIGHT_GREEN = "\u001b[92m";
public static final String BRIGHT_YELLOW = "\u001b[93m";
public static final String BRIGHT_BLUE = "\u001b[94m";
public static final String BRIGHT_MAGENTA = "\u001b[95m";
public static final String BRIGHT_CYAN = "\u001b[96m";
public static final String BLACK = "\u001b[97m";
public static final String BLACK_BACKGROUND = "\u001b[30m";
public static final String RED_BACKGROUND = "\u001b[31m";
public static final String GREEN_BACKGROUND = "\u001b[32m";
public static final String YELLOW_BACKGROUND = "\u001b[33m";
public static final String BLUE_BACKGROUND = "\u001b[34m";
public static final String MAGENTA_BACKGROUND = "\u001b[35m";
public static final String CYAN_BACKGROUND = "\u001b[36m";
public static final String WHITE_BACKGROUND = "\u001b[37m";
/*public static final String BLACK_BACKGROUND = "\u001b[30m";
public static final String RED_BACKGROUND = "\u001b[31m";
public static final String GREEN_BACKGROUND = "\u001b[32m";
public static final String YELLOW_BACKGROUND = "\u001b[33m";
public static final String BLUE_BACKGROUND = "\u001b[34m";
public static final String MAGENTA_BACKGROUND = "\u001b[35m";
public static final String CYAN_BACKGROUND = "\u001b[36m";
public static final String WHITE_BACKGROUND = "\u001b[37m";*/
}

View file

@ -1,103 +0,0 @@
/*
* Copyright (c) 2019 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.api;
import org.geysermc.api.command.CommandMap;
import org.geysermc.api.logger.Logger;
import org.geysermc.api.plugin.PluginManager;
import java.util.Collection;
import java.util.concurrent.ScheduledExecutorService;
public class Geyser {
private static Connector connector;
/**
* Returns the connector instance for Geyser
*
* @return the connector instance for Geyser
*/
public static Connector getConnector() {
return connector;
}
/**
* Sets the connector instance for Geyser
*
* @param connector the connector instance
*/
public static void setConnector(Connector connector) {
Geyser.connector = connector;
}
/**
* Returns the logger
*
* @return the logger
*/
public static Logger getLogger() {
return connector.getLogger();
}
/**
* Returns the plugin manager
*
* @return the plugin manager
*/
public static PluginManager getPluginManager() {
return connector.getPluginManager();
}
/**
* Returns the command map
*
* @return the command map
*/
public static CommandMap getCommandMap() {
return connector.getCommandMap();
}
public static ScheduledExecutorService getGeneralThreadPool() {
return connector.getGeneralThreadPool();
}
/**
* @return the amount of online players
*/
public static int getPlayerCount() {
return connector.getConnectedPlayers().size();
}
/**
* Returns a collection of the connected players
*
* @return a collection of the connected players
*/
public static Collection<? extends Player> getConnectedPlayers() {
return connector.getConnectedPlayers();
}
}

View file

@ -1,80 +0,0 @@
/*
* Copyright (c) 2019 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.api;
import org.geysermc.api.command.CommandSender;
import org.geysermc.api.session.AuthData;
import org.geysermc.api.window.FormWindow;
import java.net.InetSocketAddress;
public interface Player extends CommandSender {
/**
* Connects the player to the remote server
*
* @param remoteServer the remote server to connect to
*/
void connect(RemoteServer remoteServer);
/**
* Disconnect the player for the specified reason
*
* @param reason the reason to disconnect the player for
*/
void disconnect(String reason);
/**
* Returns the authentication data of the player. This is not the
* player's Minecraft credentials; it's simply what is given to the server
* (Name, UUID, Xbox UUID) to verify the player can/actually exists.
*
* @return the authentication data of the player
*/
AuthData getAuthenticationData();
/**
* Sends a form window
*
* @param window the window form to send
*/
void sendForm(FormWindow window);
/**
* Sends a form window with the given ID
*
* @param window the window to send
* @param id the id of the window
*/
void sendForm(FormWindow window, int id);
/**
* Returns the current hostname and port the player is connected with.
*
* @return player's socket address.
*/
InetSocketAddress getSocketAddress();
}

View file

@ -1,43 +0,0 @@
/*
* Copyright (c) 2019 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.api;
public interface RemoteServer {
/**
* Returns the IP address of the remote server
*
* @return the IP address of the remote server
*/
String getAddress();
/**
* Returns the port of the remote server
*
* @return the port of the remote server
*/
int getPort();
}

View file

@ -1,67 +0,0 @@
/*
* Copyright (c) 2019 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.api.command;
import java.util.List;
public interface Command {
/**
* Returns the name of this command
*
* @return the name of this command
*/
String getName();
/**
* Returns the description of this command
*
* @return the description of this command
*/
String getDescription();
/**
* Returns the aliases of this command
*
* @return the aliases of this command
*/
List<String> getAliases();
/**
* Sets the aliases of this command
*
* @param aliases the a liases of the command
*/
void setAliases(List<String> aliases);
/**
* Executes the command
*
* @param sender the sender of the command
* @param args the arguments of the command
*/
void execute(CommandSender sender, String[] args);
}

View file

@ -1,53 +0,0 @@
/*
* Copyright (c) 2019 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.api.command;
import java.util.Map;
public interface CommandMap {
/**
* Registers a new command
*
* @param command the command to register
*/
void registerCommand(Command command);
/**
* Runs a command for the given command sender
*
* @param sender the sender to run the command for
* @param command the command to run
*/
void runCommand(CommandSender sender, String command);
/**
* Returns a map of the commands
*
* @return a map of the commands
*/
Map<String, Command> getCommands();
}

View file

@ -1,50 +0,0 @@
/*
* Copyright (c) 2019 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.api.command;
public interface CommandSender {
/**
* Returns the name of the sender
*
* @return the name of the sender
*/
String getName();
/**
* Sends a message to the command sender
*
* @param message the message to be sent
*/
void sendMessage(String message);
/**
* Sends multiple messages to the command sender
*
* @param messages the messages to be sent
*/
void sendMessage(String[] messages);
}

View file

@ -1,30 +0,0 @@
/*
* Copyright (c) 2019 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.api.command;
public interface ConsoleCommandSender extends CommandSender {
}

View file

@ -1,56 +0,0 @@
/*
* Copyright (c) 2019 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.api.events;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* The annotation to put on all methods that are events.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface EventHandler {
/**
* @return the order to execute events.
* @see EventPriority
*/
EventPriority value() default EventPriority.NORMAL;
/**
* When an eventHandler should be run.
* The names mostly explain.
*/
enum EventPriority {
FIRST,
NORMAL,
LAST,
READ_ONLY;
}
}

View file

@ -1,33 +0,0 @@
/*
* Copyright (c) 2019 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.api.events;
/**
* A marker class which says that a specific class uses events.
* @see EventHandler
*/
public interface Listener {
}

View file

@ -1,39 +0,0 @@
/*
* Copyright (c) 2019 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.api.events.player;
import lombok.Getter;
import org.geysermc.api.Player;
public class PlayerEvent {
@Getter
private Player player;
public PlayerEvent(Player player) {
this.player = player;
}
}

View file

@ -1,87 +0,0 @@
/*
* Copyright (c) 2019 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.api.plugin;
import org.geysermc.api.events.Listener;
import java.util.Set;
public interface PluginManager {
/**
* Loads a plugin and all its class files
*
* @param plugin the plugin to load
*/
void loadPlugin(Plugin plugin);
/**
* Enables a plugin
*
* @param plugin the plugin to enable
*/
void enablePlugin(Plugin plugin);
/**
* Disables a plugin
*
* @param plugin the plugin to disable
*/
void disablePlugin(Plugin plugin);
/**
* Unloads a plugin
*
* @param plugin the plugin to unload
*/
void unloadPlugin(Plugin plugin);
/**
* Returns a set of the loaded plugins
*
* @return a set of the loaded plugins
*/
Set<Plugin> getPlugins();
/**
* @param name The name of the plugin you want to get.
* @return The plugin with the String name in the parameters.
*/
Plugin getPluginByName(String name);
/**
* Registers a listener to be run when an event is executed
* @param plugin the plugin registering the listener
* @param listener the listener which will contain the event methods
*/
void registerEventListener(Plugin plugin, Listener listener);
/**
* Run an event
* @param o the event object.
*/
void runEvent(Object o);
}

76
bootstrap/bukkit/pom.xml Normal file
View file

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.geysermc</groupId>
<artifactId>bootstrap-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>bootstrap-bukkit</artifactId>
<dependencies>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>connector</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${outputName}-Bukkit</finalName>
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>io.netty</pattern>
<shadedPattern>org.geysermc.platform.bukkit.shaded.netty</shadedPattern>
</relocation>
</relocations>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*</exclude>
</excludes>
</filter>
</filters>
<artifactSet>
<excludes>
<exclude>com.google.code.gson:*</exclude>
<exclude>org.yaml:*</exclude>
</excludes>
</artifactSet>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,186 @@
/*
* Copyright (c) 2019 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.platform.bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.geysermc.common.IGeyserConfiguration;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
public class GeyserBukkitConfiguration implements IGeyserConfiguration {
private FileConfiguration config;
private File dataFolder;
private BukkitBedrockConfiguration bedrockConfig;
private BukkitRemoteConfiguration remoteConfig;
private BukkitMetricsInfo metricsInfo;
private Map<String, BukkitUserAuthenticationInfo> userAuthInfo = new HashMap<>();
public GeyserBukkitConfiguration(File dataFolder, FileConfiguration config) {
this.dataFolder = dataFolder;
this.config = config;
bedrockConfig = new BukkitBedrockConfiguration();
remoteConfig = new BukkitRemoteConfiguration();
metricsInfo = new BukkitMetricsInfo();
if (!config.contains("userAuths"))
return;
for (String key : config.getConfigurationSection("userAuths").getKeys(false)) {
userAuthInfo.put(key, new BukkitUserAuthenticationInfo(key));
}
}
@Override
public IBedrockConfiguration getBedrock() {
return bedrockConfig;
}
@Override
public IRemoteConfiguration getRemote() {
return remoteConfig;
}
@Override
public Map<String, BukkitUserAuthenticationInfo> getUserAuths() {
return userAuthInfo;
}
@Override
public boolean isPingPassthrough() {
return config.getBoolean("ping-passthrough", false);
}
@Override
public int getMaxPlayers() {
return config.getInt("max-players", 10);
}
@Override
public boolean isDebugMode() {
return config.getBoolean("debug-mode", false);
}
@Override
public int getGeneralThreadPool() {
return config.getInt("general-thread-pool", 32);
}
@Override
public boolean isAllowThirdPartyCapes() {
return config.getBoolean("allow-third-party-capes", true);
}
@Override
public Path getFloodgateKeyFile() {
return Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem"));
}
@Override
public IMetricsInfo getMetrics() {
return metricsInfo;
}
public class BukkitBedrockConfiguration implements IBedrockConfiguration {
@Override
public String getAddress() {
return config.getString("bedrock.address", "0.0.0.0");
}
@Override
public int getPort() {
return config.getInt("bedrock.port", 25565);
}
@Override
public String getMotd1() {
return config.getString("bedrock.motd1", "GeyserMC");
}
@Override
public String getMotd2() {
return config.getString("bedrock.motd2", "GeyserMC");
}
}
public class BukkitRemoteConfiguration implements IRemoteConfiguration {
@Override
public String getAddress() {
return config.getString("remote.address", "127.0.0.1");
}
@Override
public int getPort() {
return config.getInt("remote.port", 25565);
}
@Override
public String getAuthType() {
return config.getString("remote.auth-type", "online");
}
}
public class BukkitUserAuthenticationInfo implements IUserAuthenticationInfo {
private String key;
public BukkitUserAuthenticationInfo(String key) {
this.key = key;
}
@Override
public String getEmail() {
return config.getString("userAuths." + key + ".email");
}
@Override
public String getPassword() {
return config.getString("userAuths." + key + ".password");
}
}
public class BukkitMetricsInfo implements IMetricsInfo {
@Override
public boolean isEnabled() {
return config.getBoolean("metrics.enabled", true);
}
@Override
public String getUniqueId() {
return config.getString("metrics.uuid", "generateduuid");
}
}
}

View file

@ -0,0 +1,81 @@
/*
* Copyright (c) 2019 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.platform.bukkit;
import lombok.AllArgsConstructor;
import org.geysermc.common.logger.IGeyserLogger;
import java.util.logging.Level;
import java.util.logging.Logger;
@AllArgsConstructor
public class GeyserBukkitLogger implements IGeyserLogger {
private Logger logger;
private boolean debugMode;
@Override
public void severe(String message) {
logger.severe(message);
}
@Override
public void severe(String message, Throwable error) {
logger.log(Level.SEVERE, message, error);
}
@Override
public void error(String message) {
logger.warning(message);
}
@Override
public void error(String message, Throwable error) {
logger.log(Level.WARNING, message, error);
}
@Override
public void warning(String message) {
error(message);
}
@Override
public void info(String message) {
logger.info(message);
}
@Override
public void debug(String message) {
if (debugMode)
info(message);
}
@Override
public void setDebug(boolean debug) {
debugMode = debug;
}
}

View file

@ -23,54 +23,48 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.events.player; package org.geysermc.platform.bukkit;
import lombok.Getter; import org.bukkit.plugin.java.JavaPlugin;
import org.geysermc.api.Player; import org.geysermc.common.PlatformType;
import org.geysermc.api.window.FormWindow; import org.geysermc.connector.GeyserConnector;
import org.geysermc.api.window.response.FormResponse; import org.geysermc.common.bootstrap.IGeyserBootstrap;
/** import java.util.UUID;
* Called when a player interacts with a form
*/
public class PlayerFormResponseEvent extends PlayerEvent {
@Getter public class GeyserBukkitPlugin extends JavaPlugin implements IGeyserBootstrap {
private int formID;
@Getter private GeyserBukkitConfiguration geyserConfig;
private FormWindow window; private GeyserBukkitLogger geyserLogger;
/** @Override
* Constructs a new PlayerFormResponseEvent instance public void onEnable() {
* saveDefaultConfig();
* @param player the player interacting with the form
* @param formID the id of the form
* @param window the window
*/
public PlayerFormResponseEvent(Player player, int formID, FormWindow window) {
super(player);
this.formID = formID; geyserConfig = new GeyserBukkitConfiguration(getDataFolder(), getConfig());
this.window = window;
if (geyserConfig.getMetrics().getUniqueId().equals("generateduuid")) {
getConfig().set("metrics.uuid", UUID.randomUUID().toString());
saveConfig();
}
geyserLogger = new GeyserBukkitLogger(getLogger(), geyserConfig.isDebugMode());
GeyserConnector.start(PlatformType.BUKKIT, this);
} }
/** @Override
* Returns the response of the window, can be null public void onDisable() {
* if the player closed the window GeyserConnector.stop();
*
* @return the response of the window
*/
public FormResponse getResponse() {
return window.getResponse();
} }
/** @Override
* Returns if the window is closed public GeyserBukkitConfiguration getGeyserConfig() {
* return geyserConfig;
* @return if the window is closed }
*/
public boolean isClosed() { @Override
return window.isClosed(); public GeyserBukkitLogger getGeyserLogger() {
return geyserLogger;
} }
} }

View file

@ -0,0 +1,5 @@
main: org.geysermc.platform.bukkit.GeyserBukkitPlugin
name: ${outputName}-Bukkit
author: ${project.organization.name}
website: ${project.organization.url}
version: ${project.version}

View file

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.geysermc</groupId>
<artifactId>bootstrap-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>bootstrap-bungeecord</artifactId>
<dependencies>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>connector</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.14-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${outputName}-BungeeCord</finalName>
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>net.md_5.bungee.jni</pattern>
<shadedPattern>org.geysermc.platform.bungeecord.shaded.jni</shadedPattern>
</relocation>
<relocation>
<pattern>io.netty</pattern>
<shadedPattern>org.geysermc.platform.bungeecord.shaded.netty</shadedPattern>
</relocation>
</relocations>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*</exclude>
</excludes>
</filter>
</filters>
<artifactSet>
<excludes>
<exclude>com.google.code.gson:*</exclude>
<exclude>org.yaml:*</exclude>
</excludes>
</artifactSet>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,187 @@
/*
* Copyright (c) 2019 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.platform.bungeecord;
import net.md_5.bungee.config.Configuration;
import org.geysermc.common.IGeyserConfiguration;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
public class GeyserBungeeConfiguration implements IGeyserConfiguration {
private File dataFolder;
private Configuration config;
private BungeeBedrockConfiguration bedrockConfig;
private BungeeRemoteConfiguration remoteConfig;
private BungeeMetricsInfo metricsInfo;
private Map<String, BungeeUserAuthenticationInfo> userAuthInfo = new HashMap<>();
public GeyserBungeeConfiguration(File dataFolder, Configuration config) {
this.dataFolder = dataFolder;
this.config = config;
bedrockConfig = new BungeeBedrockConfiguration();
remoteConfig = new BungeeRemoteConfiguration();
metricsInfo = new BungeeMetricsInfo();
if (!config.contains("userAuths"))
return;
for (String key : config.getSection("userAuths").getKeys()) {
userAuthInfo.put(key, new BungeeUserAuthenticationInfo(key));
}
}
@Override
public BungeeBedrockConfiguration getBedrock() {
return bedrockConfig;
}
@Override
public BungeeRemoteConfiguration getRemote() {
return remoteConfig;
}
@Override
public Map<String, BungeeUserAuthenticationInfo> getUserAuths() {
return userAuthInfo;
}
@Override
public boolean isPingPassthrough() {
return config.getBoolean("ping-passthrough", false);
}
@Override
public int getMaxPlayers() {
return config.getInt("max-players", 10);
}
@Override
public boolean isDebugMode() {
return config.getBoolean("debug-mode", false);
}
@Override
public int getGeneralThreadPool() {
return config.getInt("general-thread-pool", 32);
}
@Override
public boolean isAllowThirdPartyCapes() {
return config.getBoolean("allow-third-party-capes", true);
}
@Override
public Path getFloodgateKeyFile() {
return Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem"));
}
@Override
public BungeeMetricsInfo getMetrics() {
return metricsInfo;
}
public class BungeeBedrockConfiguration implements IBedrockConfiguration {
@Override
public String getAddress() {
return config.getString("bedrock.address", "0.0.0.0");
}
@Override
public int getPort() {
return config.getInt("bedrock.port", 25565);
}
@Override
public String getMotd1() {
return config.getString("bedrock.motd1", "GeyserMC");
}
@Override
public String getMotd2() {
return config.getString("bedrock.motd2", "GeyserMC");
}
}
public class BungeeRemoteConfiguration implements IRemoteConfiguration {
@Override
public String getAddress() {
return config.getString("remote.address", "127.0.0.1");
}
@Override
public int getPort() {
return config.getInt("remote.port", 25565);
}
@Override
public String getAuthType() {
return config.getString("remote.auth-type", "online");
}
}
public class BungeeUserAuthenticationInfo implements IUserAuthenticationInfo {
private String key;
public BungeeUserAuthenticationInfo(String key) {
this.key = key;
}
@Override
public String getEmail() {
return config.getString("userAuths." + key + ".email");
}
@Override
public String getPassword() {
return config.getString("userAuths." + key + ".password");
}
}
public class BungeeMetricsInfo implements IMetricsInfo {
@Override
public boolean isEnabled() {
return config.getBoolean("metrics.enabled", true);
}
@Override
public String getUniqueId() {
return config.getString("metrics.uuid", "generateduuid");
}
}
}

View file

@ -0,0 +1,83 @@
/*
* Copyright (c) 2019 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.platform.bungeecord;
import org.geysermc.common.logger.IGeyserLogger;
import java.util.logging.Level;
import java.util.logging.Logger;
public class GeyserBungeeLogger implements IGeyserLogger {
private Logger logger;
private boolean debugMode;
public GeyserBungeeLogger(Logger logger, boolean debugMode) {
this.logger = logger;
this.debugMode = debugMode;
}
@Override
public void severe(String message) {
logger.severe(message);
}
@Override
public void severe(String message, Throwable error) {
logger.log(Level.SEVERE, message, error);
}
@Override
public void error(String message) {
logger.warning(message);
}
@Override
public void error(String message, Throwable error) {
logger.log(Level.WARNING, message, error);
}
@Override
public void warning(String message) {
error(message);
}
@Override
public void info(String message) {
logger.info(message);
}
@Override
public void debug(String message) {
if (debugMode)
info(message);
}
@Override
public void setDebug(boolean debug) {
debugMode = debug;
}
}

View file

@ -0,0 +1,107 @@
/*
* Copyright (c) 2019 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.platform.bungeecord;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import org.geysermc.common.PlatformType;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.common.bootstrap.IGeyserBootstrap;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.UUID;
import java.util.logging.Level;
public class GeyserBungeePlugin extends Plugin implements IGeyserBootstrap {
private GeyserBungeeConfiguration geyserConfig;
private GeyserBungeeLogger geyserLogger;
@Override
public void onEnable() {
if (!getDataFolder().exists())
getDataFolder().mkdir();
File file = new File(getDataFolder(), "config.yml");
Configuration configuration = null;
if (!file.exists()) {
try (InputStream in = getResourceAsStream("config.yml")) {
Files.copy(in, file.toPath());
} catch (IOException ex) {
getLogger().log(Level.SEVERE, "Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
return;
}
}
try {
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
} catch(IOException e) {
e.printStackTrace();
}
if (configuration == null) {
getLogger().severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!");
return;
}
geyserConfig = new GeyserBungeeConfiguration(getDataFolder(), configuration);
if (geyserConfig.getMetrics().getUniqueId().equals("generateduuid")) {
configuration.set("metrics.uuid", UUID.randomUUID().toString());
try {
ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, new File(getDataFolder(), "config.yml"));
} catch (IOException ex) {
getLogger().log(Level.SEVERE, "Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
return;
}
}
geyserLogger = new GeyserBungeeLogger(getLogger(), geyserConfig.isDebugMode());
GeyserConnector.start(PlatformType.BUNGEECORD, this);
}
@Override
public void onDisable() {
GeyserConnector.stop();
}
@Override
public GeyserBungeeConfiguration getGeyserConfig() {
return geyserConfig;
}
@Override
public GeyserBungeeLogger getGeyserLogger() {
return geyserLogger;
}
}

View file

@ -0,0 +1,5 @@
main: org.geysermc.platform.bungeecord.GeyserBungeePlugin
name: ${outputName}-BungeeCord
author: ${project.organization.name}
website: ${project.organization.url}
version: ${project.version}

44
bootstrap/pom.xml Normal file
View file

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.geysermc</groupId>
<artifactId>geyser-parent</artifactId>
<version>parent</version>
<relativePath>../</relativePath>
</parent>
<artifactId>bootstrap-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<repositories>
<repository>
<id>spigot-public</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/public/</url>
</repository>
<repository>
<id>bukkit-public</id>
<url>https://repo.md-5.net/content/repositories/public/</url>
</repository>
<repository>
<id>sponge-repo</id>
<url>https://repo.spongepowered.org/maven</url>
</repository>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository>
<id>velocity-repo</id>
<url>https://repo.velocitypowered.com/snapshots/</url>
</repository>
</repositories>
<modules>
<module>bukkit</module>
<module>bungeecord</module>
<module>sponge</module>
<module>standalone</module>
<module>velocity</module>
</modules>
</project>

83
bootstrap/sponge/pom.xml Normal file
View file

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.geysermc</groupId>
<artifactId>bootstrap-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>bootstrap-sponge</artifactId>
<dependencies>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>connector</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spongepowered</groupId>
<artifactId>spongeapi</artifactId>
<version>7.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${outputName}-Sponge</finalName>
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>com.fasterxml.jackson</pattern>
<shadedPattern>org.geysermc.platform.sponge.shaded.jackson</shadedPattern>
</relocation>
<relocation>
<pattern>io.netty</pattern>
<shadedPattern>org.geysermc.platform.sponge.shaded.netty</shadedPattern>
</relocation>
</relocations>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*</exclude>
</excludes>
</filter>
</filters>
<artifactSet>
<excludes>
<exclude>com.google.code.gson:*</exclude>
<exclude>org.yaml:*</exclude>
<exclude>com.nukkitx:fastutil-lite:*</exclude>
<exclude>org.slf4j:*</exclude>
<exclude>org.ow2.asm:*</exclude>
</excludes>
</artifactSet>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,196 @@
/*
* Copyright (c) 2019 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.platform.sponge;
import lombok.AllArgsConstructor;
import ninja.leaping.configurate.ConfigurationNode;
import org.geysermc.common.IGeyserConfiguration;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GeyserSpongeConfiguration implements IGeyserConfiguration {
private File dataFolder;
private ConfigurationNode node;
private SpongeBedrockConfiguration bedrockConfig;
private SpongeRemoteConfiguration remoteConfig;
private SpongeMetricsInfo metricsInfo;
private Map<String, SpongeUserAuthenticationInfo> userAuthInfo = new HashMap<>();
public GeyserSpongeConfiguration(File dataFolder, ConfigurationNode node) {
this.dataFolder = dataFolder;
this.node = node;
this.bedrockConfig = new SpongeBedrockConfiguration(node.getNode("bedrock"));
this.remoteConfig = new SpongeRemoteConfiguration(node.getNode("remote"));
this.metricsInfo = new SpongeMetricsInfo();
if (node.getNode("userAuths").getValue() == null)
return;
for (String key : (List<String>) node.getNode("userAuths").getValue()) {
userAuthInfo.put(key, new SpongeUserAuthenticationInfo(key));
}
}
@Override
public SpongeBedrockConfiguration getBedrock() {
return bedrockConfig;
}
@Override
public SpongeRemoteConfiguration getRemote() {
return remoteConfig;
}
@Override
public Map<String, SpongeUserAuthenticationInfo> getUserAuths() {
return userAuthInfo;
}
@Override
public boolean isPingPassthrough() {
return node.getNode("ping-passthrough").getBoolean(false);
}
@Override
public int getMaxPlayers() {
return node.getNode("max-players").getInt(100);
}
@Override
public boolean isDebugMode() {
return node.getNode("debug-mode").getBoolean(false);
}
@Override
public int getGeneralThreadPool() {
return node.getNode("genereal-thread-pool").getInt(32);
}
@Override
public boolean isAllowThirdPartyCapes() {
return node.getNode("allow-third-party-capes").getBoolean(true);
}
@Override
public Path getFloodgateKeyFile() {
return Paths.get(dataFolder.toString(), node.getNode("floodgate-key-file").getString("public-key.pem"));
}
@Override
public SpongeMetricsInfo getMetrics() {
return metricsInfo;
}
@AllArgsConstructor
public class SpongeBedrockConfiguration implements IBedrockConfiguration {
private ConfigurationNode node;
@Override
public String getAddress() {
return node.getNode("address").getString("0.0.0.0");
}
@Override
public int getPort() {
return node.getNode("port").getInt(19132);
}
@Override
public String getMotd1() {
return node.getNode("motd1").getString("GeyserMC");
}
@Override
public String getMotd2() {
return node.getNode("motd2").getString("GeyserMC");
}
}
@AllArgsConstructor
public class SpongeRemoteConfiguration implements IRemoteConfiguration {
private ConfigurationNode node;
@Override
public String getAddress() {
return node.getNode("address").getString("127.0.0.1");
}
@Override
public int getPort() {
return node.getNode("port").getInt(25565);
}
@Override
public String getAuthType() {
return node.getNode("auth-type").getString("online");
}
}
public class SpongeUserAuthenticationInfo implements IUserAuthenticationInfo {
private String key;
public SpongeUserAuthenticationInfo(String key) {
this.key = key;
}
@Override
public String getEmail() {
return node.getNode("userAuths").getNode(key).getNode("email").getString();
}
@Override
public String getPassword() {
return node.getNode("userAuths").getNode(key).getNode("password").getString();
}
}
public class SpongeMetricsInfo implements IMetricsInfo {
@Override
public boolean isEnabled() {
return node.getNode("metrics").getNode("enabled").getBoolean(true);
}
@Override
public String getUniqueId() {
return node.getNode("metrics").getNode("uuid").getString("generateduuid");
}
}
}

View file

@ -23,31 +23,57 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.events; package org.geysermc.platform.sponge;
import lombok.Getter; import lombok.AllArgsConstructor;
import lombok.Setter;
import java.net.InetSocketAddress; import org.geysermc.common.logger.IGeyserLogger;
import org.slf4j.Logger;
@Getter @AllArgsConstructor
@Setter public class GeyserSpongeLogger implements IGeyserLogger {
public class PingEvent {
public PingEvent(InetSocketAddress address) { private Logger logger;
this.address = address; private boolean debugMode;
@Override
public void severe(String message) {
logger.error(message);
} }
private InetSocketAddress address; @Override
public void severe(String message, Throwable error) {
logger.error(message, error);
}
private String edition; @Override
private String motd; public void error(String message) {
private int protocolVersion; logger.error(message);
private String version; }
private int playerCount;
private int maximumPlayerCount; @Override
private long serverId; public void error(String message, Throwable error) {
private String subMotd; logger.error(message, error);
private String gameType; }
private boolean nintendoLimited;
@Override
public void warning(String message) {
logger.warn(message);
}
@Override
public void info(String message) {
logger.info(message);
}
@Override
public void debug(String message) {
if (debugMode)
info(message);
}
@Override
public void setDebug(boolean debugMode) {
this.debugMode = debugMode;
}
} }

View file

@ -0,0 +1,112 @@
/*
* Copyright (c) 2019 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.platform.sponge;
import com.google.inject.Inject;
import ninja.leaping.configurate.loader.ConfigurationLoader;
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
import org.geysermc.common.PlatformType;
import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.utils.FileUtils;
import org.slf4j.Logger;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameStartedServerEvent;
import org.spongepowered.api.event.game.state.GameStoppedEvent;
import org.spongepowered.api.plugin.Plugin;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
@Plugin(id = "geyser", name = GeyserConnector.NAME + "-Sponge", version = GeyserConnector.VERSION, url = "https://geysermc.org", authors = "GeyserMC")
public class GeyserSpongePlugin implements IGeyserBootstrap {
@Inject
private Logger logger;
@Inject
@ConfigDir(sharedRoot = false)
private File configDir;
private GeyserSpongeConfiguration geyserConfig;
private GeyserSpongeLogger geyserLogger;
@Override
public void onEnable() {
if (!configDir.exists())
configDir.mkdirs();
File configFile = null;
try {
configFile = FileUtils.fileOrCopiedFromResource(new File(configDir, "config.yml"), "config.yml", (file) -> file.replaceAll("generateduuid", UUID.randomUUID().toString()));
} catch (IOException ex) {
logger.warn("Failed to copy config.yml from jar path!");
ex.printStackTrace();
}
ConfigurationLoader loader = YAMLConfigurationLoader.builder().setPath(configFile.toPath()).build();
try {
this.geyserConfig = new GeyserSpongeConfiguration(configDir, loader.load());
} catch (IOException ex) {
logger.warn("Failed to load config.yml!");
ex.printStackTrace();
return;
}
this.geyserLogger = new GeyserSpongeLogger(logger, geyserConfig.isDebugMode());
GeyserConnector.start(PlatformType.SPONGE, this);
}
@Override
public void onDisable() {
GeyserConnector.stop();
}
@Override
public GeyserSpongeConfiguration getGeyserConfig() {
return geyserConfig;
}
@Override
public GeyserSpongeLogger getGeyserLogger() {
return geyserLogger;
}
@Listener
public void onServerStart(GameStartedServerEvent event) {
onEnable();
}
@Listener
public void onServerStop(GameStoppedEvent event) {
onDisable();
}
}

View file

@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.geysermc</groupId>
<artifactId>bootstrap-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>bootstrap-standalone</artifactId>
<dependencies>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>connector</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.minecrell</groupId>
<artifactId>terminalconsoleappender</artifactId>
<version>1.1.1</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.jline</groupId>
<artifactId>jline-reader</artifactId>
</exclusion>
<exclusion>
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jna</artifactId>
</exclusion>
<exclusion>
<groupId>org.jline</groupId>
<artifactId>jline-terminal</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-terminal</artifactId>
<version>3.9.0</version>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-terminal-jna</artifactId>
<version>3.9.0</version>
</dependency>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline-reader</artifactId>
<version>3.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j18-impl</artifactId>
<version>2.13.1</version>
</dependency>
</dependencies>
<build>
<finalName>${outputName}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestEntries>
<Main-Class>org.geysermc.platform.standalone.GeyserBootstrap</Main-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<dependencies>
<dependency>
<groupId>com.github.edwgiz</groupId>
<artifactId>maven-shade-plugin.log4j2-cachefile-transformer</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>false</minimizeJar>
</configuration>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/versions/9/module-info.class</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.geysermc.platform.standalone.GeyserBootstrap</mainClass>
</transformer>
<transformer
implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer">
</transformer>
</transformers>
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,78 @@
/*
* Copyright (c) 2019 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.platform.standalone;
import org.geysermc.common.PlatformType;
import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.utils.FileUtils;
import org.geysermc.platform.standalone.console.GeyserLogger;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
public class GeyserBootstrap implements IGeyserBootstrap {
private GeyserConfiguration geyserConfig;
private GeyserLogger geyserLogger;
public static void main(String[] args) {
new GeyserBootstrap().onEnable();
}
@Override
public void onEnable() {
geyserLogger = new GeyserLogger();
try {
File configFile = FileUtils.fileOrCopiedFromResource("config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
geyserConfig = FileUtils.loadConfig(configFile, GeyserConfiguration.class);
} catch (IOException ex) {
geyserLogger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
System.exit(0);
}
GeyserConnector.start(PlatformType.STANDALONE, this);
geyserLogger.start();
}
@Override
public void onDisable() {
GeyserConnector.stop();
System.exit(0);
}
@Override
public GeyserConfiguration getGeyserConfig() {
return geyserConfig;
}
@Override
public GeyserLogger getGeyserLogger() {
return geyserLogger;
}
}

View file

@ -23,20 +23,29 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.connector.configuration; package org.geysermc.platform.standalone;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter; import lombok.Getter;
import org.geysermc.common.IGeyserConfiguration;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map; import java.util.Map;
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
@Getter @Getter
public class GeyserConfiguration { public class GeyserConfiguration implements IGeyserConfiguration {
private BedrockConfiguration bedrock; private BedrockConfiguration bedrock;
private RemoteConfiguration remote; private RemoteConfiguration remote;
@JsonProperty("floodgate-key-file")
private String floodgateKeyFile;
private Map<String, UserAuthenticationInfo> userAuths; private Map<String, UserAuthenticationInfo> userAuths;
@JsonProperty("ping-passthrough") @JsonProperty("ping-passthrough")
@ -54,5 +63,48 @@ public class GeyserConfiguration {
@JsonProperty("allow-third-party-capes") @JsonProperty("allow-third-party-capes")
private boolean allowThirdPartyCapes; private boolean allowThirdPartyCapes;
private MetricInfo metrics; private MetricsInfo metrics;
@Override
public Path getFloodgateKeyFile() {
return Paths.get(floodgateKeyFile);
}
@Getter
public static class BedrockConfiguration implements IBedrockConfiguration {
private String address;
private int port;
private String motd1;
private String motd2;
}
@Getter
public static class RemoteConfiguration implements IRemoteConfiguration {
private String address;
private int port;
private String motd1;
private String motd2;
@JsonProperty("auth-type")
private String authType;
}
@Getter
public static class UserAuthenticationInfo implements IUserAuthenticationInfo {
private String email;
private String password;
}
@Getter
public static class MetricsInfo implements IMetricsInfo {
private boolean enabled;
@JsonProperty("uuid")
private String uniqueId;
}
} }

View file

@ -0,0 +1,116 @@
/*
* Copyright (c) 2019-2020 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.platform.standalone.console;
import lombok.extern.log4j.Log4j2;
import net.minecrell.terminalconsole.SimpleTerminalConsole;
import org.apache.logging.log4j.core.config.Configurator;
import org.geysermc.common.ChatColor;
import org.geysermc.common.logger.IGeyserLogger;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandSender;
@Log4j2
public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger, CommandSender {
private boolean colored = true;
@Override
protected boolean isRunning() {
return !GeyserConnector.getInstance().isShuttingDown();
}
@Override
protected void runCommand(String line) {
GeyserConnector.getInstance().getCommandMap().runCommand(this, line);
}
@Override
protected void shutdown() {
GeyserConnector.getInstance().shutdown();
}
@Override
public void severe(String message) {
log.fatal(printConsole(ChatColor.DARK_RED + message, colored));
}
@Override
public void severe(String message, Throwable error) {
log.fatal(printConsole(ChatColor.DARK_RED + message, colored), error);
}
@Override
public void error(String message) {
log.error(printConsole(ChatColor.RED + message, colored));
}
@Override
public void error(String message, Throwable error) {
log.error(printConsole(ChatColor.RED + message, colored), error);
}
@Override
public void warning(String message) {
log.warn(printConsole(ChatColor.YELLOW + message, colored));
}
@Override
public void info(String message) {
log.info(printConsole(ChatColor.WHITE + message, colored));
}
@Override
public void debug(String message) {
log.debug(printConsole(ChatColor.GRAY + message, colored));
}
public static String printConsole(String message, boolean colors) {
return colors ? ChatColor.toANSI(message + ChatColor.RESET) : ChatColor.stripColors(message + ChatColor.RESET);
}
@Override
public void setDebug(boolean debug) {
Configurator.setLevel(log.getName(), debug ? org.apache.logging.log4j.Level.DEBUG : log.getLevel());
}
@Override
public String getName() {
return "CONSOLE";
}
@Override
public void sendMessage(String message) {
info(message);
}
@Override
public boolean isConsole() {
return true;
}
}

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<TerminalConsole name="Console">
<PatternLayout pattern="[%d{HH:mm:ss} %style{%highlight{%level}{FATAL=red dark, ERROR=red, WARN=yellow bright, INFO=cyan bright, DEBUG=green, TRACE=white}}] %minecraftFormatting{%msg}%n"/>
</TerminalConsole>
<RollingRandomAccessFile name="File" fileName="logs/latest.log" filePattern="logs/%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %level{length=1} - %msg%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<OnStartupTriggeringPolicy/>
</Policies>
</RollingRandomAccessFile>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console"/>
<AppenderRef ref="File"/>
</Root>
</Loggers>
</Configuration>

View file

@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.geysermc</groupId>
<artifactId>bootstrap-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<artifactId>bootstrap-velocity</artifactId>
<dependencies>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>connector</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${outputName}-Velocity</finalName>
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*</exclude>
</excludes>
</filter>
</filters>
<artifactSet>
<excludes>
<exclude>com.google.code.gson:*</exclude>
<exclude>io.netty:*</exclude>
<exclude>org.slf4j:*</exclude>
<exclude>org.ow2.asm:*</exclude>
</excludes>
</artifactSet>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,110 @@
/*
* Copyright (c) 2019-2020 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.platform.velocity;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import org.geysermc.common.IGeyserConfiguration;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
public class GeyserVelocityConfiguration implements IGeyserConfiguration {
private BedrockConfiguration bedrock;
private RemoteConfiguration remote;
@JsonProperty("floodgate-key-file")
private String floodgateKeyFile;
private Map<String, UserAuthenticationInfo> userAuths;
@JsonProperty("ping-passthrough")
private boolean pingPassthrough;
@JsonProperty("max-players")
private int maxPlayers;
@JsonProperty("debug-mode")
private boolean debugMode;
@JsonProperty("general-thread-pool")
private int generalThreadPool;
@JsonProperty("allow-third-party-capes")
private boolean allowThirdPartyCapes;
private MetricsInfo metrics;
@Override
public Path getFloodgateKeyFile() {
return Paths.get(floodgateKeyFile);
}
@Getter
public static class BedrockConfiguration implements IBedrockConfiguration {
private String address;
private int port;
private String motd1;
private String motd2;
}
@Getter
public static class RemoteConfiguration implements IRemoteConfiguration {
private String address;
private int port;
private String motd1;
private String motd2;
@JsonProperty("auth-type")
private String authType;
}
@Getter
public static class UserAuthenticationInfo implements IUserAuthenticationInfo {
private String email;
private String password;
}
@Getter
public static class MetricsInfo implements IMetricsInfo {
private boolean enabled;
@JsonProperty("uuid")
private String uniqueId;
}
}

View file

@ -23,27 +23,57 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.connector.command; package org.geysermc.platform.velocity;
import org.geysermc.api.command.ConsoleCommandSender; import lombok.AllArgsConstructor;
import org.geysermc.connector.console.GeyserLogger;
public class GeyserConsoleCommandSender implements ConsoleCommandSender { import org.geysermc.common.logger.IGeyserLogger;
import org.slf4j.Logger;
@AllArgsConstructor
public class GeyserVelocityLogger implements IGeyserLogger {
private Logger logger;
private boolean debugMode;
@Override @Override
public String getName() { public void severe(String message) {
return "CONSOLE"; logger.error(message);
} }
@Override @Override
public void sendMessage(String message) { public void severe(String message, Throwable error) {
System.out.println(GeyserLogger.printConsole(message, true)); logger.error(message, error);
} }
@Override @Override
public void sendMessage(String[] messages) { public void error(String message) {
for (String message : messages) { logger.error(message);
sendMessage(message);
}
} }
}
@Override
public void error(String message, Throwable error) {
logger.error(message, error);
}
@Override
public void warning(String message) {
logger.warn(message);
}
@Override
public void info(String message) {
logger.info(message);
}
@Override
public void debug(String message) {
if (debugMode)
info(message);
}
@Override
public void setDebug(boolean debugMode) {
this.debugMode = debugMode;
}
}

View file

@ -0,0 +1,96 @@
/*
* Copyright (c) 2019-2020 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.platform.velocity;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
import com.velocitypowered.api.plugin.Plugin;
import org.geysermc.common.PlatformType;
import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.utils.FileUtils;
import org.slf4j.Logger;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
@Plugin(id = "geyser", name = GeyserConnector.NAME + "-Velocity", version = GeyserConnector.VERSION, url = "https://geysermc.org", authors = "GeyserMC")
public class GeyserVelocityPlugin implements IGeyserBootstrap {
@Inject
private Logger logger;
private GeyserVelocityConfiguration geyserConfig;
private GeyserVelocityLogger geyserLogger;
@Override
public void onEnable() {
try {
File configDir = new File("plugins/" + GeyserConnector.NAME + "-Velocity/");
if (!configDir.exists())
configDir.mkdir();
File configFile = FileUtils.fileOrCopiedFromResource(new File(configDir, "config.yml"), "config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
geyserConfig = FileUtils.loadConfig(configFile, GeyserVelocityConfiguration.class);
} catch (IOException ex) {
logger.warn("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
ex.printStackTrace();
}
this.geyserLogger = new GeyserVelocityLogger(logger, geyserConfig.isDebugMode());
GeyserConnector.start(PlatformType.VELOCITY, this);
}
@Override
public void onDisable() {
GeyserConnector.stop();
}
@Override
public GeyserVelocityConfiguration getGeyserConfig() {
return geyserConfig;
}
@Override
public GeyserVelocityLogger getGeyserLogger() {
return geyserLogger;
}
@Subscribe
public void onInit(ProxyInitializeEvent event) {
onEnable();
}
@Subscribe
public void onShutdown(ProxyShutdownEvent event) {
onDisable();
}
}

View file

@ -6,7 +6,17 @@
<parent> <parent>
<groupId>org.geysermc</groupId> <groupId>org.geysermc</groupId>
<artifactId>geyser-parent</artifactId> <artifactId>geyser-parent</artifactId>
<version>1.0-SNAPSHOT</version> <version>parent</version>
<relativePath>../</relativePath>
</parent> </parent>
<artifactId>common</artifactId> <artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project> </project>

View file

@ -0,0 +1,26 @@
package org.geysermc.common;
import lombok.Getter;
@Getter
public enum AuthType {
OFFLINE,
ONLINE,
FLOODGATE;
public static final AuthType[] VALUES = values();
public static AuthType getById(int id) {
return id < VALUES.length ? VALUES[id] : OFFLINE;
}
public static AuthType getByName(String name) {
String upperCase = name.toUpperCase();
for (AuthType type : VALUES) {
if (type.name().equals(upperCase)) {
return type;
}
}
return OFFLINE;
}
}

View file

@ -23,7 +23,7 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api; package org.geysermc.common;
public class ChatColor { public class ChatColor {
@ -84,4 +84,4 @@ public class ChatColor {
public static String stripColors(String message) { public static String stripColors(String message) {
return message = message.replaceAll("(&([a-fk-or0-9]))","").replaceAll("(§([a-fk-or0-9]))","").replaceAll("s/\\x1b\\[[0-9;]*[a-zA-Z]//g",""); return message = message.replaceAll("(&([a-fk-or0-9]))","").replaceAll("(§([a-fk-or0-9]))","").replaceAll("s/\\x1b\\[[0-9;]*[a-zA-Z]//g","");
} }
} }

View file

@ -23,62 +23,63 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.plugin; package org.geysermc.common;
import lombok.Getter; import java.nio.file.Path;
import lombok.Setter; import java.util.Map;
/** public interface IGeyserConfiguration {
* The class that any main plugin class should extend.
* The first init point is the constructor, followed by onLoad, and finally onEnable.
*/
public class Plugin {
protected String name;
protected String version;
/** IBedrockConfiguration getBedrock();
* Returns if the plugin is enabled
*
* @return if the plugin is enabled
*/
@Getter
@Setter
private boolean enabled = true;
/** IRemoteConfiguration getRemote();
* Called when a plugin is enabled
*/
public void onEnable() {
Map<String, ? extends IUserAuthenticationInfo> getUserAuths();
boolean isPingPassthrough();
int getMaxPlayers();
boolean isDebugMode();
int getGeneralThreadPool();
boolean isAllowThirdPartyCapes();
Path getFloodgateKeyFile();
IMetricsInfo getMetrics();
interface IBedrockConfiguration {
String getAddress();
int getPort();
String getMotd1();
String getMotd2();
} }
/** interface IRemoteConfiguration {
* Called when a plugin is disabled
*/
public void onDisable() {
String getAddress();
int getPort();
String getAuthType();
} }
/** interface IUserAuthenticationInfo {
* Called when a plugin is loaded String getEmail();
*/
public void onLoad() {
String getPassword();
} }
/** interface IMetricsInfo {
* Called when the server is reloaded
*/
public void onReload() {
} boolean isEnabled();
public final String getName() { String getUniqueId();
return name;
}
@Override
public final String toString() {
return getName();
} }
} }

View file

@ -0,0 +1,17 @@
package org.geysermc.common;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum PlatformType {
BUKKIT("Bukkit"),
BUNGEECORD("BungeeCord"),
SPONGE("Sponge"),
STANDALONE("Standalone"),
VELOCITY("Velocity");
private String platformName;
}

View file

@ -23,15 +23,18 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.session; package org.geysermc.common.bootstrap;
import java.util.UUID; import org.geysermc.common.IGeyserConfiguration;
import org.geysermc.common.logger.IGeyserLogger;
public interface AuthData { public interface IGeyserBootstrap {
String getName(); void onEnable();
UUID getUUID(); void onDisable();
String getXboxUUID(); IGeyserConfiguration getGeyserConfig();
IGeyserLogger getGeyserLogger();
} }

View file

@ -23,9 +23,9 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.logger; package org.geysermc.common.logger;
public interface Logger { public interface IGeyserLogger {
/** /**
* Logs a severe message to console * Logs a severe message to console

View file

@ -23,12 +23,13 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window; package org.geysermc.common.window;
import lombok.Getter; import lombok.Getter;
import org.geysermc.api.window.button.FormImage; import org.geysermc.common.window.CustomFormWindow;
import org.geysermc.api.window.component.FormComponent; import org.geysermc.common.window.button.FormImage;
import org.geysermc.api.window.response.CustomFormResponse; import org.geysermc.common.window.component.FormComponent;
import org.geysermc.common.window.response.CustomFormResponse;
public class CustomFormBuilder { public class CustomFormBuilder {

View file

@ -23,22 +23,16 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window; package org.geysermc.common.window;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.geysermc.api.window.button.FormImage; import org.geysermc.common.window.button.FormImage;
import org.geysermc.api.window.component.DropdownComponent; import org.geysermc.common.window.component.*;
import org.geysermc.api.window.component.FormComponent; import org.geysermc.common.window.response.CustomFormResponse;
import org.geysermc.api.window.component.InputComponent; import org.geysermc.common.window.response.FormResponseData;
import org.geysermc.api.window.component.LabelComponent;
import org.geysermc.api.window.component.SliderComponent;
import org.geysermc.api.window.component.StepSliderComponent;
import org.geysermc.api.window.component.ToggleComponent;
import org.geysermc.api.window.response.CustomFormResponse;
import org.geysermc.api.window.response.FormResponseData;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;

View file

@ -23,11 +23,11 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window; package org.geysermc.common.window;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.geysermc.api.window.response.FormResponse; import org.geysermc.common.window.response.FormResponse;
public abstract class FormWindow { public abstract class FormWindow {

View file

@ -23,12 +23,12 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window; package org.geysermc.common.window;
import com.google.gson.Gson; import com.google.gson.Gson;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.geysermc.api.window.response.ModalFormResponse; import org.geysermc.common.window.response.ModalFormResponse;
public class ModalFormWindow extends FormWindow { public class ModalFormWindow extends FormWindow {

View file

@ -23,13 +23,13 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window; package org.geysermc.common.window;
import com.google.gson.Gson; import com.google.gson.Gson;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.geysermc.api.window.button.FormButton; import org.geysermc.common.window.button.FormButton;
import org.geysermc.api.window.response.SimpleFormResponse; import org.geysermc.common.window.response.SimpleFormResponse;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View file

@ -23,7 +23,7 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window.button; package org.geysermc.common.window.button;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;

View file

@ -23,7 +23,7 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window.button; package org.geysermc.common.window.button;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;

View file

@ -23,7 +23,7 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window.component; package org.geysermc.common.window.component;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;

View file

@ -23,7 +23,7 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window.component; package org.geysermc.common.window.component;
import lombok.Getter; import lombok.Getter;

View file

@ -23,7 +23,7 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window.component; package org.geysermc.common.window.component;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;

View file

@ -23,7 +23,7 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window.component; package org.geysermc.common.window.component;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;

View file

@ -23,7 +23,7 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window.component; package org.geysermc.common.window.component;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -54,7 +54,7 @@ public class SliderComponent extends FormComponent {
super("slider"); super("slider");
this.text = text; this.text = text;
this.min = min < 0f ? 0f : min; this.min = Math.max(min, 0f);
this.max = max > this.min ? max : this.min; this.max = max > this.min ? max : this.min;
if (step != -1f && step > 0) if (step != -1f && step > 0)
this.step = step; this.step = step;

View file

@ -23,7 +23,7 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window.component; package org.geysermc.common.window.component;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;

View file

@ -23,7 +23,7 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window.component; package org.geysermc.common.window.component;
public class ToggleComponent extends FormComponent { public class ToggleComponent extends FormComponent {

View file

@ -23,10 +23,12 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window.response; package org.geysermc.common.window.response;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import org.geysermc.common.window.response.FormResponse;
import org.geysermc.common.window.response.FormResponseData;
import java.util.Map; import java.util.Map;

View file

@ -23,7 +23,7 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window.response; package org.geysermc.common.window.response;
public interface FormResponse { public interface FormResponse {
} }

View file

@ -23,7 +23,7 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window.response; package org.geysermc.common.window.response;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;

View file

@ -23,10 +23,11 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window.response; package org.geysermc.common.window.response;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import org.geysermc.common.window.response.FormResponse;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor

View file

@ -23,11 +23,12 @@
* @link https://github.com/GeyserMC/Geyser * @link https://github.com/GeyserMC/Geyser
*/ */
package org.geysermc.api.window.response; package org.geysermc.common.window.response;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import org.geysermc.api.window.button.FormButton; import org.geysermc.common.window.button.FormButton;
import org.geysermc.common.window.response.FormResponse;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor

View file

@ -0,0 +1,44 @@
package org.geysermc.floodgate.util;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public class BedrockData {
public static final int EXPECTED_LENGTH = 7;
public static final String FLOODGATE_IDENTIFIER = "Geyser-Floodgate";
private String version;
private String username;
private String xuid;
private int deviceId;
private String languageCode;
private int inputMode;
private String ip;
private int dataLength;
public BedrockData(String version, String username, String xuid, int deviceId, String languageCode, int inputMode, String ip) {
this(version, username, xuid, deviceId, languageCode, inputMode, ip, EXPECTED_LENGTH);
}
public static BedrockData fromString(String data) {
String[] split = data.split("\0");
if (split.length != EXPECTED_LENGTH) return null;
return new BedrockData(
split[0], split[1], split[2], Integer.parseInt(split[3]),
split[4], Integer.parseInt(split[5]), split[6], split.length
);
}
public static BedrockData fromRawData(byte[] data) {
return fromString(new String(data));
}
@Override
public String toString() {
return version +'\0'+ username +'\0'+ xuid +'\0'+ deviceId +'\0'+ languageCode +'\0'+
inputMode +'\0'+ ip;
}
}

View file

@ -0,0 +1,76 @@
package org.geysermc.floodgate.util;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.*;
import java.security.spec.EncodedKeySpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
public class EncryptionUtil {
public static String encrypt(Key key, String data) throws IllegalBlockSizeException,
InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
KeyGenerator generator = KeyGenerator.getInstance("AES");
generator.init(128);
SecretKey secretKey = generator.generateKey();
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] encryptedText = cipher.doFinal(data.getBytes());
cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(key instanceof PublicKey ? Cipher.PUBLIC_KEY : Cipher.PRIVATE_KEY, key);
return Base64.getEncoder().encodeToString(cipher.doFinal(secretKey.getEncoded())) + '\0' +
Base64.getEncoder().encodeToString(encryptedText);
}
public static String encryptBedrockData(Key key, BedrockData data) throws IllegalBlockSizeException,
InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
return encrypt(key, data.toString());
}
public static byte[] decrypt(Key key, String encryptedData) throws IllegalBlockSizeException,
InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
String[] split = encryptedData.split("\0");
if (split.length != 2) {
throw new IllegalArgumentException("Expected two arguments, got " + split.length);
}
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(key instanceof PublicKey ? Cipher.PUBLIC_KEY : Cipher.PRIVATE_KEY, key);
byte[] decryptedKey = cipher.doFinal(Base64.getDecoder().decode(split[0]));
SecretKey secretKey = new SecretKeySpec(decryptedKey, 0, decryptedKey.length, "AES");
cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
return cipher.doFinal(Base64.getDecoder().decode(split[1]));
}
public static BedrockData decryptBedrockData(Key key, String encryptedData) throws IllegalBlockSizeException,
InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
return BedrockData.fromRawData(decrypt(key, encryptedData));
}
@SuppressWarnings("unchecked")
public static <T extends Key> T getKeyFromFile(Path fileLocation, Class<T> keyType) throws
IOException, InvalidKeySpecException, NoSuchAlgorithmException {
boolean isPublicKey = keyType == PublicKey.class;
if (!isPublicKey && keyType != PrivateKey.class) {
throw new RuntimeException("I can only read public and private keys!");
}
byte[] key = Files.readAllBytes(fileLocation);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
EncodedKeySpec keySpec = isPublicKey ? new X509EncodedKeySpec(key) : new PKCS8EncodedKeySpec(key);
return (T) (isPublicKey ?
keyFactory.generatePublic(keySpec) :
keyFactory.generatePrivate(keySpec)
);
}
}

View file

@ -6,16 +6,12 @@
<parent> <parent>
<groupId>org.geysermc</groupId> <groupId>org.geysermc</groupId>
<artifactId>geyser-parent</artifactId> <artifactId>geyser-parent</artifactId>
<version>1.0-SNAPSHOT</version> <version>parent</version>
<relativePath>../</relativePath>
</parent> </parent>
<artifactId>connector</artifactId> <artifactId>connector</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies> <dependencies>
<dependency>
<groupId>org.geysermc</groupId>
<artifactId>api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>org.geysermc</groupId> <groupId>org.geysermc</groupId>
<artifactId>common</artifactId> <artifactId>common</artifactId>
@ -40,30 +36,6 @@
<version>1.7.0</version> <version>1.7.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>net.minecrell</groupId>
<artifactId>terminalconsoleappender</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>1.18</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>com.nukkitx.protocol</groupId> <groupId>com.nukkitx.protocol</groupId>
<artifactId>bedrock-v389</artifactId> <artifactId>bedrock-v389</artifactId>
@ -121,45 +93,4 @@
</exclusions> </exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<finalName>${project.parent.name}-noshade</finalName>
<directory>../target</directory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Main-Class>org.geysermc.connector.GeyserConnector</Main-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<finalName>${project.parent.name}</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>${project.parent.name}</finalName>
<shadedArtifactAttached>true</shadedArtifactAttached>
<minimizeJar>true</minimizeJar>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>

View file

@ -30,42 +30,31 @@ import com.nukkitx.protocol.bedrock.BedrockServer;
import com.nukkitx.protocol.bedrock.v389.Bedrock_v389; import com.nukkitx.protocol.bedrock.v389.Bedrock_v389;
import lombok.Getter; import lombok.Getter;
import org.fusesource.jansi.AnsiConsole;
import org.geysermc.api.Connector; import org.geysermc.common.AuthType;
import org.geysermc.api.Geyser; import org.geysermc.common.PlatformType;
import org.geysermc.api.Player; import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.api.command.CommandMap; import org.geysermc.common.logger.IGeyserLogger;
import org.geysermc.api.logger.Logger;
import org.geysermc.api.plugin.Plugin;
import org.geysermc.connector.command.GeyserCommandMap; import org.geysermc.connector.command.GeyserCommandMap;
import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.console.ConsoleCommandReader;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.metrics.Metrics; import org.geysermc.connector.metrics.Metrics;
import org.geysermc.connector.network.ConnectorServerEventHandler; import org.geysermc.connector.network.ConnectorServerEventHandler;
import org.geysermc.connector.network.remote.RemoteJavaServer; import org.geysermc.connector.network.remote.RemoteServer;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.TranslatorsInit; import org.geysermc.connector.network.translators.TranslatorsInit;
import org.geysermc.connector.plugin.GeyserPluginLoader;
import org.geysermc.connector.plugin.GeyserPluginManager;
import org.geysermc.connector.thread.PingPassthroughThread; import org.geysermc.connector.thread.PingPassthroughThread;
import org.geysermc.connector.utils.FileUtils;
import org.geysermc.connector.utils.Toolbox; import org.geysermc.connector.utils.Toolbox;
import org.geysermc.common.IGeyserConfiguration;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Getter @Getter
public class GeyserConnector implements Connector { public class GeyserConnector {
public static final BedrockPacketCodec BEDROCK_PACKET_CODEC = Bedrock_v389.V389_CODEC; public static final BedrockPacketCodec BEDROCK_PACKET_CODEC = Bedrock_v389.V389_CODEC;
@ -76,37 +65,31 @@ public class GeyserConnector implements Connector {
private static GeyserConnector instance; private static GeyserConnector instance;
private RemoteJavaServer remoteServer; private RemoteServer remoteServer;
private AuthType authType;
private Logger logger; private IGeyserLogger logger;
private IGeyserConfiguration config;
private CommandMap commandMap; private GeyserCommandMap commandMap;
private GeyserConfiguration config;
private GeyserPluginManager pluginManager;
private boolean shuttingDown = false; private boolean shuttingDown = false;
private final ScheduledExecutorService generalThreadPool; private final ScheduledExecutorService generalThreadPool;
private PingPassthroughThread passthroughThread; private PingPassthroughThread passthroughThread;
private BedrockServer bedrockServer;
private PlatformType platformType;
private Metrics metrics; private Metrics metrics;
public static void main(String[] args) { private GeyserConnector(PlatformType platformType, IGeyserConfiguration config, IGeyserLogger logger) {
instance = new GeyserConnector();
}
private GeyserConnector() {
long startupTime = System.currentTimeMillis(); long startupTime = System.currentTimeMillis();
// Metric
if (!(System.console() == null) && System.getProperty("os.name", "Windows 10").toLowerCase().contains("windows")) {
AnsiConsole.systemInstall();
}
instance = this; instance = this;
this.logger = GeyserLogger.DEFAULT; this.logger = logger;
this.platformType = platformType;
logger.info("******************************************"); logger.info("******************************************");
logger.info(""); logger.info("");
@ -114,17 +97,8 @@ public class GeyserConnector implements Connector {
logger.info(""); logger.info("");
logger.info("******************************************"); logger.info("******************************************");
try { this.config = config;
File configFile = FileUtils.fileOrCopiedFromResource("config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
config = FileUtils.loadConfig(configFile, GeyserConfiguration.class);
} catch (IOException ex) {
logger.severe("Failed to read/create config.yml! Make sure it's up to date and/or readable+writable!", ex);
shutdown();
}
this.generalThreadPool = Executors.newScheduledThreadPool(config.getGeneralThreadPool()); this.generalThreadPool = Executors.newScheduledThreadPool(config.getGeneralThreadPool());
ConsoleCommandReader consoleReader = new ConsoleCommandReader(this);
consoleReader.startConsole();
logger.setDebug(config.isDebugMode()); logger.setDebug(config.isDebugMode());
@ -132,18 +106,14 @@ public class GeyserConnector implements Connector {
TranslatorsInit.start(); TranslatorsInit.start();
commandMap = new GeyserCommandMap(this); commandMap = new GeyserCommandMap(this);
remoteServer = new RemoteJavaServer(config.getRemote().getAddress(), config.getRemote().getPort()); remoteServer = new RemoteServer(config.getRemote().getAddress(), config.getRemote().getPort());
authType = AuthType.getByName(config.getRemote().getAuthType());
Geyser.setConnector(this);
pluginManager = new GeyserPluginManager(new GeyserPluginLoader(this));
pluginManager.getLoader().loadPlugins();
passthroughThread = new PingPassthroughThread(this); passthroughThread = new PingPassthroughThread(this);
if (config.isPingPassthrough()) if (config.isPingPassthrough())
generalThreadPool.scheduleAtFixedRate(passthroughThread, 1, 1, TimeUnit.SECONDS); generalThreadPool.scheduleAtFixedRate(passthroughThread, 1, 1, TimeUnit.SECONDS);
BedrockServer bedrockServer = new BedrockServer(new InetSocketAddress(config.getBedrock().getAddress(), config.getBedrock().getPort())); bedrockServer = new BedrockServer(new InetSocketAddress(config.getBedrock().getAddress(), config.getBedrock().getPort()));
bedrockServer.setHandler(new ConnectorServerEventHandler(this)); bedrockServer.setHandler(new ConnectorServerEventHandler(this));
bedrockServer.bind().whenComplete((avoid, throwable) -> { bedrockServer.bind().whenComplete((avoid, throwable) -> {
if (throwable == null) { if (throwable == null) {
@ -155,43 +125,46 @@ public class GeyserConnector implements Connector {
}).join(); }).join();
if (config.getMetrics().isEnabled()) { if (config.getMetrics().isEnabled()) {
metrics = new Metrics("GeyserMC", config.getMetrics().getUUID(), false, java.util.logging.Logger.getLogger("")); metrics = new Metrics(this, "GeyserMC", config.getMetrics().getUniqueId(), false, java.util.logging.Logger.getLogger(""));
metrics.addCustomChart(new Metrics.SingleLineChart("servers", () -> 1)); metrics.addCustomChart(new Metrics.SingleLineChart("servers", () -> 1));
metrics.addCustomChart(new Metrics.SingleLineChart("players", Geyser::getPlayerCount)); metrics.addCustomChart(new Metrics.SingleLineChart("players", players::size));
metrics.addCustomChart(new Metrics.SimplePie("authMode", config.getRemote()::getAuthType)); metrics.addCustomChart(new Metrics.SimplePie("authMode", authType.name()::toLowerCase));
metrics.addCustomChart(new Metrics.SimplePie("platform", platformType::getPlatformName));
} }
double completeTime = (System.currentTimeMillis() - startupTime) / 1000D; double completeTime = (System.currentTimeMillis() - startupTime) / 1000D;
logger.info(String.format("Done (%ss)! Run /help for help!", new DecimalFormat("#.###").format(completeTime))); logger.info(String.format("Done (%ss)! Run /geyser help for help!", new DecimalFormat("#.###").format(completeTime)));
}
@Override
public Collection<? extends Player> getConnectedPlayers() {
return players.values();
} }
public void shutdown() { public void shutdown() {
logger.info("Shutting down connector."); logger.info("Shutting down Geyser.");
for (Plugin plugin : pluginManager.getPlugins()) {
pluginManager.disablePlugin(plugin);
pluginManager.unloadPlugin(plugin);
}
shuttingDown = true; shuttingDown = true;
generalThreadPool.shutdown(); generalThreadPool.shutdown();
System.exit(0); bedrockServer.close();
} }
public void addPlayer(GeyserSession player) { public void addPlayer(GeyserSession player) {
players.put(player.getAuthenticationData().getName(), player); players.put(player.getAuthData().getName(), player);
players.put(player.getAuthenticationData().getUUID(), player); players.put(player.getAuthData().getUUID(), player);
players.put(player.getSocketAddress(), player); players.put(player.getSocketAddress(), player);
} }
public void removePlayer(GeyserSession player) { public void removePlayer(GeyserSession player) {
players.remove(player.getAuthenticationData().getName()); players.remove(player.getAuthData().getName());
players.remove(player.getAuthenticationData().getUUID()); players.remove(player.getAuthData().getUUID());
players.remove(player.getSocketAddress()); players.remove(player.getSocketAddress());
} }
public static GeyserConnector start(PlatformType platformType, IGeyserBootstrap bootstrap) {
return new GeyserConnector(platformType, bootstrap.getGeyserConfig(), bootstrap.getGeyserLogger());
}
public static void stop() {
instance.shutdown();
}
public static GeyserConnector getInstance() {
return instance;
}
} }

View file

@ -0,0 +1,16 @@
package org.geysermc.connector.command;
public interface CommandSender {
String getName();
default void sendMessage(String[] messages) {
for (String message : messages) {
sendMessage(message);
}
}
void sendMessage(String message);
boolean isConsole();
}

View file

@ -25,18 +25,24 @@
package org.geysermc.connector.command; package org.geysermc.connector.command;
import org.geysermc.api.command.Command; import lombok.AccessLevel;
import org.geysermc.api.command.CommandSender; import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public abstract class GeyserCommand implements Command { @Getter
@Setter
public abstract class GeyserCommand {
private String name; private String name;
private String description; private String description;
@Setter(AccessLevel.NONE)
private GeyserCommandMap commandMap; private GeyserCommandMap commandMap;
private List<String> aliases; private List<String> aliases = new ArrayList<>();
public GeyserCommand(String name) { public GeyserCommand(String name) {
this(name, "A geyser command."); this(name, "A geyser command.");
@ -47,38 +53,5 @@ public abstract class GeyserCommand implements Command {
this.description = description; this.description = description;
} }
@Override
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public List<String> getAliases() {
return aliases;
}
@Override
public void setAliases(List<String> aliases) {
this.aliases = aliases;
}
@Override
public abstract void execute(CommandSender sender, String[] args); public abstract void execute(CommandSender sender, String[] args);
public GeyserCommandMap getCommandMap() {
return commandMap;
}
} }

View file

@ -25,9 +25,6 @@
package org.geysermc.connector.command; package org.geysermc.connector.command;
import org.geysermc.api.command.Command;
import org.geysermc.api.command.CommandMap;
import org.geysermc.api.command.CommandSender;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.defaults.HelpCommand; import org.geysermc.connector.command.defaults.HelpCommand;
import org.geysermc.connector.command.defaults.StopCommand; import org.geysermc.connector.command.defaults.StopCommand;
@ -36,9 +33,9 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class GeyserCommandMap implements CommandMap { public class GeyserCommandMap {
private final Map<String, Command> commandMap = Collections.synchronizedMap(new HashMap<String, Command>()); private final Map<String, GeyserCommand> commandMap = Collections.synchronizedMap(new HashMap<>());
private GeyserConnector connector; private GeyserConnector connector;
public GeyserCommandMap(GeyserConnector connector) { public GeyserCommandMap(GeyserConnector connector) {
@ -52,11 +49,11 @@ public class GeyserCommandMap implements CommandMap {
registerCommand(new StopCommand(connector, "stop", "Shut down Geyser.")); registerCommand(new StopCommand(connector, "stop", "Shut down Geyser."));
} }
public void registerCommand(Command command) { public void registerCommand(GeyserCommand command) {
commandMap.put(command.getName(), command); commandMap.put(command.getName(), command);
connector.getLogger().debug("Registered command " + command.getName()); connector.getLogger().debug("Registered command " + command.getName());
if (command.getAliases() == null || command.getAliases().isEmpty()) if (command.getAliases().isEmpty())
return; return;
for (String alias : command.getAliases()) for (String alias : command.getAliases())
@ -64,34 +61,33 @@ public class GeyserCommandMap implements CommandMap {
} }
public void runCommand(CommandSender sender, String command) { public void runCommand(CommandSender sender, String command) {
String trim = command.trim(); if (!command.startsWith("geyser "))
String label = null; return;
String[] args = null;
if (!trim.contains(" ")) { command = command.trim();
label = trim.toLowerCase(); command = command.replace("geyser ", "");
String label;
String[] args;
if (!command.contains(" ")) {
label = command.toLowerCase();
args = new String[0]; args = new String[0];
} else { } else {
label = trim.substring(0, trim.indexOf(" ")).toLowerCase(); label = command.substring(0, command.indexOf(" ")).toLowerCase();
String argLine = trim.substring(trim.indexOf(" " + 1)); String argLine = command.substring(command.indexOf(" " + 1));
args = argLine.contains(" ") ? argLine.split(" ") : new String[] { argLine }; args = argLine.contains(" ") ? argLine.split(" ") : new String[] { argLine };
} }
if (label == null) { GeyserCommand cmd = commandMap.get(label);
connector.getLogger().warning("Invalid Command! Try /help for a list of commands.");
return;
}
Command cmd = commandMap.get(label);
if (cmd == null) { if (cmd == null) {
connector.getLogger().warning("Invalid Command! Try /help for a list of commands."); connector.getLogger().error("Invalid Command! Try /geyser help for a list of commands.");
return; return;
} }
cmd.execute(sender, args); cmd.execute(sender, args);
} }
public Map<String, Command> getCommands() { public Map<String, GeyserCommand> getCommands() {
return commandMap; return commandMap;
} }
} }

View file

@ -25,17 +25,12 @@
package org.geysermc.connector.command.defaults; package org.geysermc.connector.command.defaults;
import org.geysermc.api.ChatColor; import org.geysermc.common.ChatColor;
import org.geysermc.api.command.Command;
import org.geysermc.api.command.CommandSender;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.command.GeyserCommand; import org.geysermc.connector.command.GeyserCommand;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class HelpCommand extends GeyserCommand { public class HelpCommand extends GeyserCommand {
@ -45,19 +40,19 @@ public class HelpCommand extends GeyserCommand {
super(name, description); super(name, description);
this.connector = connector; this.connector = connector;
this.setAliases(Arrays.asList("?")); this.setAliases(Collections.singletonList("?"));
} }
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
sender.sendMessage("---- Showing Help For: Geyser (Page 1/1) ----"); sender.sendMessage("---- Showing Help For: Geyser (Page 1/1) ----");
Map<String, Command> cmds = connector.getCommandMap().getCommands(); Map<String, GeyserCommand> cmds = connector.getCommandMap().getCommands();
List<String> commands = new ArrayList<String>(cmds.keySet()); List<String> commands = new ArrayList<>(cmds.keySet());
Collections.sort(commands); Collections.sort(commands);
for (String cmd : commands) { for (String cmd : commands) {
sender.sendMessage(ChatColor.YELLOW + "/" + cmd + ChatColor.WHITE + ": " + cmds.get(cmd).getDescription()); sender.sendMessage(ChatColor.YELLOW + "/geyser " + cmd + ChatColor.WHITE + ": " + cmds.get(cmd).getDescription());
} }
} }
} }

View file

@ -25,11 +25,11 @@
package org.geysermc.connector.command.defaults; package org.geysermc.connector.command.defaults;
import org.geysermc.api.command.CommandSender;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.command.GeyserCommand; import org.geysermc.connector.command.GeyserCommand;
import java.util.Arrays; import java.util.Collections;
public class StopCommand extends GeyserCommand { public class StopCommand extends GeyserCommand {
@ -39,11 +39,14 @@ public class StopCommand extends GeyserCommand {
super(name, description); super(name, description);
this.connector = connector; this.connector = connector;
this.setAliases(Arrays.asList("shutdown")); this.setAliases(Collections.singletonList("shutdown"));
} }
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if (!sender.isConsole())
return;
connector.shutdown(); connector.shutdown();
} }
} }

View file

@ -1,38 +0,0 @@
/*
* Copyright (c) 2019 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.connector.configuration;
import lombok.Getter;
@Getter
public class BedrockConfiguration {
private String address;
private int port;
private String motd1;
private String motd2;
}

View file

@ -1,38 +0,0 @@
/*
* Copyright (c) 2019 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.connector.configuration;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
@Getter
public class MetricInfo {
private boolean enabled;
@JsonProperty("uuid")
private String UUID;
}

View file

@ -1,42 +0,0 @@
/*
* Copyright (c) 2019 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.connector.configuration;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
@Getter
public class RemoteConfiguration {
private String address;
private int port;
private String motd1;
private String motd2;
@JsonProperty("auth-type")
private String authType;
}

View file

@ -1,31 +0,0 @@
/*
* Copyright (c) 2019 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.connector.configuration;
public class UserAuthenticationInfo {
public String email;
public String password;
}

View file

@ -1,98 +0,0 @@
/*
* Copyright (c) 2019-2020 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.connector.console;
import org.geysermc.api.command.ConsoleCommandSender;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.GeyserConsoleCommandSender;
import net.minecrell.terminalconsole.TerminalConsoleAppender;
import org.jline.reader.EndOfFileException;
import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
import org.jline.reader.UserInterruptException;
import org.jline.terminal.Terminal;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ConsoleCommandReader {
private GeyserConnector connector;
private Terminal terminal;
private Thread thread;
public ConsoleCommandReader(GeyserConnector connector) {
this.connector = connector;
this.terminal = TerminalConsoleAppender.getTerminal();
}
public void startConsole() {
thread = new Thread(() -> {
if (terminal != null) {
LineReader lineReader = LineReaderBuilder.builder()
.appName("Geyser")
.terminal(terminal)
.build();
TerminalConsoleAppender.setReader(lineReader);
try {
String line;
while (true) {
try {
line = lineReader.readLine("> ");
} catch (EndOfFileException ignored) {
continue;
}
if (line == null)
break;
}
} catch (UserInterruptException e /* do nothing */) {
//
} finally {
TerminalConsoleAppender.setReader(null);
}
} else {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
String line;
while ((line = reader.readLine()) != null) {
ConsoleCommandSender sender = new GeyserConsoleCommandSender();
connector.getCommandMap().runCommand(sender, line);
}
} catch (IOException ex) {
Logger.getLogger("Geyser").log(Level.SEVERE, null, ex);
}
}
});
thread.setName("ConsoleCommandThread");
connector.getGeneralThreadPool().execute(thread);
}
}

View file

@ -1,135 +0,0 @@
/*
* Copyright (c) 2019-2020 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.connector.console;
import io.sentry.Sentry;
import org.geysermc.api.ChatColor;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.logging.*;
public class GeyserLogger implements org.geysermc.api.logger.Logger {
private boolean colored = true;
private boolean debug = false;
public static final GeyserLogger DEFAULT = new GeyserLogger();
private GeyserLogger() {
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.INFO);
consoleHandler.setFormatter(new SimpleFormatter() {
private static final String format = "[%1$tT][%2$-5s] %3$s %n";
@Override
public synchronized String format(LogRecord lr) {
return String.format(format,
new Date(lr.getMillis()),
lr.getLevel().getLocalizedName(),
lr.getMessage()
);
}
});
try {
File logDir = new File("logs");
logDir.mkdir();
File logFile = new File(logDir, "latest.log");
int maxLogFileSize = 20;//Mo
if (logFile.exists() && (logFile.length()) > maxLogFileSize * 1024L * 1024L)
this.warning("Your log file is larger than " + maxLogFileSize + "Mo, you should backup and clean it !");
FileHandler fileHandler = new FileHandler(logFile.getCanonicalPath(), true);
fileHandler.setLevel(Level.INFO);
fileHandler.setFormatter(new SimpleFormatter() {
private static final String format = "[%1$tF %1$tT][%2$-5s] %3$s %n";
@Override
public synchronized String format(LogRecord lr) {
return String.format(format,
new Date(lr.getMillis()),
lr.getLevel().getLocalizedName(),
lr.getMessage()
);
}
});
} catch (IOException | SecurityException ex) {
Logger.getLogger(GeyserLogger.class.getName()).log(Level.SEVERE, null, ex);
}
if (System.getenv().containsKey("DP_SENTRY_CLIENT_KEY")) {
Handler sentryHandler = new io.sentry.jul.SentryHandler();
sentryHandler.setLevel(Level.SEVERE);
Sentry.init(System.getenv().get("DP_SENTRY_CLIENT_KEY"));
}
}
@Override
public void severe(String message) {
System.out.println(printConsole(ChatColor.DARK_RED + message, colored));
}
@Override
public void severe(String message, Throwable error) {
System.out.println(printConsole(ChatColor.DARK_RED + message + "\n" + error.getMessage(), colored));
}
@Override
public void error(String message) {
System.out.println(printConsole(ChatColor.RED + message, colored));
}
@Override
public void error(String message, Throwable error) {
System.out.println(printConsole(ChatColor.RED + message + "\n" + error, colored));
}
@Override
public void warning(String message) {
System.out.println(printConsole(ChatColor.YELLOW + message, colored));
}
@Override
public void info(String message) {
System.out.println(printConsole(ChatColor.WHITE + message, colored));
}
@Override
public void debug(String message) {
if (debug)
System.out.println(printConsole(ChatColor.GRAY + message, colored));
}
public static String printConsole(String message, boolean colors) {
return colors ? ChatColor.toANSI(message + ChatColor.RESET) : ChatColor.stripColors(message + ChatColor.RESET);
}
@Override
public void setDebug(boolean debug) {
this.debug = debug;
}
}

View file

@ -34,11 +34,13 @@ import com.nukkitx.protocol.bedrock.data.EntityDataMap;
import com.nukkitx.protocol.bedrock.data.EntityFlag; import com.nukkitx.protocol.bedrock.data.EntityFlag;
import com.nukkitx.protocol.bedrock.data.EntityFlags; import com.nukkitx.protocol.bedrock.data.EntityFlags;
import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.packet.*;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import it.unimi.dsi.fastutil.longs.LongSet; import it.unimi.dsi.fastutil.longs.LongSet;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.entity.attribute.Attribute; import org.geysermc.connector.entity.attribute.Attribute;
import org.geysermc.connector.entity.attribute.AttributeType; import org.geysermc.connector.entity.attribute.AttributeType;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
@ -114,7 +116,7 @@ public class Entity {
valid = true; valid = true;
session.getUpstream().sendPacket(addEntityPacket); session.getUpstream().sendPacket(addEntityPacket);
GeyserLogger.DEFAULT.debug("Spawned entity " + entityType + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); session.getConnector().getLogger().debug("Spawned entity " + entityType + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")");
} }
/** /**

View file

@ -27,10 +27,11 @@ package org.geysermc.connector.entity;
import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.AddPaintingPacket; import com.nukkitx.protocol.bedrock.packet.AddPaintingPacket;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.PaintingType; import org.geysermc.connector.utils.PaintingType;
@ -58,7 +59,7 @@ public class PaintingEntity extends Entity {
valid = true; valid = true;
GeyserLogger.DEFAULT.debug("Spawned painting on " + position); session.getConnector().getLogger().debug("Spawned painting on " + position);
} }
public Vector3f fixOffset(boolean toBedrock) { public Vector3f fixOffset(boolean toBedrock) {

View file

@ -32,9 +32,11 @@ import com.nukkitx.protocol.bedrock.data.PlayerPermission;
import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket; import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket;
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
import com.nukkitx.protocol.bedrock.packet.PlayerListPacket; import com.nukkitx.protocol.bedrock.packet.PlayerListPacket;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.geysermc.api.Geyser;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.SkinUtils; import org.geysermc.connector.utils.SkinUtils;
@ -108,7 +110,7 @@ public class PlayerEntity extends LivingEntity {
if (!playerList) { if (!playerList) {
// remove from playerlist if player isn't on playerlist // remove from playerlist if player isn't on playerlist
Geyser.getGeneralThreadPool().execute(() -> { GeyserConnector.getInstance().getGeneralThreadPool().execute(() -> {
PlayerListPacket playerList = new PlayerListPacket(); PlayerListPacket playerList = new PlayerListPacket();
playerList.setAction(PlayerListPacket.Action.REMOVE); playerList.setAction(PlayerListPacket.Action.REMOVE);
playerList.getEntries().add(new PlayerListPacket.Entry(uuid)); playerList.getEntries().add(new PlayerListPacket.Entry(uuid));

View file

@ -27,7 +27,6 @@ package org.geysermc.connector.metrics;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import org.geysermc.api.Geyser;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
@ -72,15 +71,19 @@ public class Metrics {
// A list with all custom charts // A list with all custom charts
private final List<CustomChart> charts = new ArrayList<>(); private final List<CustomChart> charts = new ArrayList<>();
private GeyserConnector connector;
/** /**
* Class constructor. * Class constructor.
* *
* @param connector The GeyserConnector instance
* @param name The name of the server software. * @param name The name of the server software.
* @param serverUUID The uuid of the server. * @param serverUUID The uuid of the server.
* @param logFailedRequests Whether failed requests should be logged or not. * @param logFailedRequests Whether failed requests should be logged or not.
* @param logger The logger for the failed requests. * @param logger The logger for the failed requests.
*/ */
public Metrics(String name, String serverUUID, boolean logFailedRequests, Logger logger) { public Metrics(GeyserConnector connector, String name, String serverUUID, boolean logFailedRequests, Logger logger) {
this.connector = connector;
this.name = name; this.name = name;
this.serverUUID = serverUUID; this.serverUUID = serverUUID;
Metrics.logFailedRequests = logFailedRequests; Metrics.logFailedRequests = logFailedRequests;
@ -106,7 +109,7 @@ public class Metrics {
* Starts the Scheduler which submits our data every 30 minutes. * Starts the Scheduler which submits our data every 30 minutes.
*/ */
private void startSubmitting() { private void startSubmitting() {
Geyser.getGeneralThreadPool().scheduleAtFixedRate(this::submitData, 1, 30, TimeUnit.MINUTES); connector.getGeneralThreadPool().scheduleAtFixedRate(this::submitData, 1, 30, TimeUnit.MINUTES);
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
// WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted! // WARNING: Changing the frequency has no effect but your plugin WILL be blocked/deleted!
// WARNING: Just don't do it! // WARNING: Just don't do it!
@ -144,7 +147,7 @@ public class Metrics {
*/ */
private JsonObject getServerData() { private JsonObject getServerData() {
// OS specific data // OS specific data
int playerAmount = Geyser.getPlayerCount(); int playerAmount = connector.getPlayers().size();
String osName = System.getProperty("os.name"); String osName = System.getProperty("os.name");
String osArch = System.getProperty("os.arch"); String osArch = System.getProperty("os.arch");

View file

@ -29,11 +29,9 @@ import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
import com.nukkitx.protocol.bedrock.BedrockPong; import com.nukkitx.protocol.bedrock.BedrockPong;
import com.nukkitx.protocol.bedrock.BedrockServerEventHandler; import com.nukkitx.protocol.bedrock.BedrockServerEventHandler;
import com.nukkitx.protocol.bedrock.BedrockServerSession; import com.nukkitx.protocol.bedrock.BedrockServerSession;
import org.geysermc.api.Player;
import org.geysermc.api.events.PingEvent; import org.geysermc.common.IGeyserConfiguration;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.MessageUtils; import org.geysermc.connector.utils.MessageUtils;
@ -49,50 +47,35 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
@Override @Override
public boolean onConnectionRequest(InetSocketAddress inetSocketAddress) { public boolean onConnectionRequest(InetSocketAddress inetSocketAddress) {
GeyserLogger.DEFAULT.info(inetSocketAddress + " tried to connect!"); connector.getLogger().info(inetSocketAddress + " tried to connect!");
return true; return true;
} }
@Override @Override
public BedrockPong onQuery(InetSocketAddress inetSocketAddress) { public BedrockPong onQuery(InetSocketAddress inetSocketAddress) {
GeyserLogger.DEFAULT.debug(inetSocketAddress + " has pinged you!"); connector.getLogger().debug(inetSocketAddress + " has pinged you!");
GeyserConfiguration config = connector.getConfig();
PingEvent pongEvent = new PingEvent(inetSocketAddress);
pongEvent.setEdition("MCPE");
pongEvent.setGameType("Default");
pongEvent.setNintendoLimited(false);
pongEvent.setProtocolVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getProtocolVersion());
pongEvent.setVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion());
connector.getPluginManager().runEvent(pongEvent); IGeyserConfiguration config = connector.getConfig();
if (connector.getConfig().isPingPassthrough()) { ServerStatusInfo serverInfo = connector.getPassthroughThread().getInfo();
ServerStatusInfo serverInfo = connector.getPassthroughThread().getInfo();
if (serverInfo != null) {
pongEvent.setMotd(MessageUtils.getBedrockMessage(serverInfo.getDescription()));
pongEvent.setSubMotd(config.getBedrock().getMotd2());
pongEvent.setPlayerCount(serverInfo.getPlayerInfo().getOnlinePlayers());
pongEvent.setMaximumPlayerCount(serverInfo.getPlayerInfo().getMaxPlayers());
}
} else {
pongEvent.setPlayerCount(1);
pongEvent.setMaximumPlayerCount(config.getMaxPlayers());
pongEvent.setMotd(config.getBedrock().getMotd1());
pongEvent.setSubMotd(config.getBedrock().getMotd2());
}
BedrockPong pong = new BedrockPong(); BedrockPong pong = new BedrockPong();
pong.setEdition(pongEvent.getEdition()); pong.setEdition("MCPE");
pong.setGameType(pongEvent.getGameType()); pong.setGameType("Default");
pong.setNintendoLimited(pongEvent.isNintendoLimited()); pong.setNintendoLimited(false);
pong.setProtocolVersion(pongEvent.getProtocolVersion()); pong.setProtocolVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getProtocolVersion());
pong.setVersion(pongEvent.getVersion()); pong.setVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion());
pong.setMotd(pongEvent.getMotd());
pong.setSubMotd(pongEvent.getSubMotd());
pong.setPlayerCount(pongEvent.getPlayerCount());
pong.setMaximumPlayerCount(pongEvent.getMaximumPlayerCount());
pong.setIpv4Port(config.getBedrock().getPort()); pong.setIpv4Port(config.getBedrock().getPort());
if (connector.getConfig().isPingPassthrough() && serverInfo != null) {
pong.setMotd(MessageUtils.getBedrockMessage(serverInfo.getDescription()));
pong.setSubMotd(config.getBedrock().getMotd2());
pong.setPlayerCount(serverInfo.getPlayerInfo().getOnlinePlayers());
pong.setMaximumPlayerCount(serverInfo.getPlayerInfo().getMaxPlayers());
} else {
pong.setPlayerCount(connector.getPlayers().size());
pong.setMaximumPlayerCount(config.getMaxPlayers());
pong.setMotd(config.getBedrock().getMotd1());
pong.setMotd(config.getBedrock().getMotd2());
}
return pong; return pong;
} }
@ -101,7 +84,7 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
bedrockServerSession.setLogging(true); bedrockServerSession.setLogging(true);
bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(connector, new GeyserSession(connector, bedrockServerSession))); bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(connector, new GeyserSession(connector, bedrockServerSession)));
bedrockServerSession.addDisconnectHandler(disconnectReason -> { bedrockServerSession.addDisconnectHandler(disconnectReason -> {
GeyserLogger.DEFAULT.info("Bedrock user with ip: " + bedrockServerSession.getAddress().getAddress() + " has disconnected for reason " + disconnectReason); connector.getLogger().info("Bedrock user with ip: " + bedrockServerSession.getAddress().getAddress() + " has disconnected for reason " + disconnectReason);
GeyserSession player = connector.getPlayers().get(bedrockServerSession.getAddress()); GeyserSession player = connector.getPlayers().get(bedrockServerSession.getAddress());
if (player != null) { if (player != null) {

View file

@ -27,8 +27,8 @@ package org.geysermc.connector.network;
import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.BedrockPacket;
import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.packet.*;
import org.geysermc.common.IGeyserConfiguration;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.configuration.UserAuthenticationInfo;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.Registry; import org.geysermc.connector.network.translators.Registry;
import org.geysermc.connector.utils.LoginEncryptionUtils; import org.geysermc.connector.utils.LoginEncryptionUtils;
@ -66,7 +66,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
switch (packet.getStatus()) { switch (packet.getStatus()) {
case COMPLETED: case COMPLETED:
session.connect(connector.getRemoteServer()); session.connect(connector.getRemoteServer());
connector.getLogger().info("Player connected with username " + session.getAuthenticationData().getName()); connector.getLogger().info("Player connected with username " + session.getAuthData().getName());
break; break;
case HAVE_ALL_PACKS: case HAVE_ALL_PACKS:
ResourcePackStackPacket stack = new ResourcePackStackPacket(); ResourcePackStackPacket stack = new ResourcePackStackPacket();
@ -90,11 +90,11 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
private boolean couldLoginUserByName(String bedrockUsername) { private boolean couldLoginUserByName(String bedrockUsername) {
if (connector.getConfig().getUserAuths() != null) { if (connector.getConfig().getUserAuths() != null) {
UserAuthenticationInfo info = connector.getConfig().getUserAuths().get(bedrockUsername); IGeyserConfiguration.IUserAuthenticationInfo info = connector.getConfig().getUserAuths().get(bedrockUsername);
if (info != null) { if (info != null) {
connector.getLogger().info("using stored credentials for bedrock user " + session.getAuthenticationData().getName()); connector.getLogger().info("using stored credentials for bedrock user " + session.getAuthData().getName());
session.authenticate(info.email, info.password); session.authenticate(info.getEmail(), info.getPassword());
// TODO send a message to bedrock user telling them they are connected (if nothing like a motd // TODO send a message to bedrock user telling them they are connected (if nothing like a motd
// somes from the Java server w/in a few seconds) // somes from the Java server w/in a few seconds)
@ -109,7 +109,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
public boolean handle(MovePlayerPacket packet) { public boolean handle(MovePlayerPacket packet) {
if (!session.isLoggedIn() && !session.isLoggingIn()) { if (!session.isLoggedIn() && !session.isLoggingIn()) {
// TODO it is safer to key authentication on something that won't change (UUID, not username) // TODO it is safer to key authentication on something that won't change (UUID, not username)
if (!couldLoginUserByName(session.getAuthenticationData().getName())) { if (!couldLoginUserByName(session.getAuthData().getName())) {
LoginEncryptionUtils.showLoginWindow(session); LoginEncryptionUtils.showLoginWindow(session);
} }
// else we were able to log the user in // else we were able to log the user in
@ -126,9 +126,4 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
boolean defaultHandler(BedrockPacket packet) { boolean defaultHandler(BedrockPacket packet) {
return translateAndDefault(packet); return translateAndDefault(packet);
} }
@Override
public boolean handle(InventoryTransactionPacket packet) {
return translateAndDefault(packet);
}
} }

View file

@ -27,11 +27,10 @@ package org.geysermc.connector.network.remote;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import org.geysermc.api.RemoteServer;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class RemoteJavaServer implements RemoteServer { public class RemoteServer {
private String address; private String address;
private int port; private int port;

View file

@ -30,11 +30,9 @@ import com.github.steveice10.mc.auth.exception.request.RequestException;
import com.github.steveice10.mc.protocol.MinecraftProtocol; import com.github.steveice10.mc.protocol.MinecraftProtocol;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerRespawnPacket;
import com.github.steveice10.mc.protocol.packet.handshake.client.HandshakePacket;
import com.github.steveice10.packetlib.Client; import com.github.steveice10.packetlib.Client;
import com.github.steveice10.packetlib.event.session.ConnectedEvent; import com.github.steveice10.packetlib.event.session.*;
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.tcp.TcpSessionFactory; import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
import com.nukkitx.math.GenericMath; import com.nukkitx.math.GenericMath;
@ -48,33 +46,44 @@ import com.nukkitx.protocol.bedrock.data.GamePublishSetting;
import com.nukkitx.protocol.bedrock.data.GameRuleData; import com.nukkitx.protocol.bedrock.data.GameRuleData;
import com.nukkitx.protocol.bedrock.data.PlayerPermission; import com.nukkitx.protocol.bedrock.data.PlayerPermission;
import com.nukkitx.protocol.bedrock.packet.*; import com.nukkitx.protocol.bedrock.packet.*;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.geysermc.api.Player;
import org.geysermc.api.RemoteServer; import org.geysermc.common.AuthType;
import org.geysermc.api.session.AuthData; import org.geysermc.common.window.FormWindow;
import org.geysermc.api.window.FormWindow;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.inventory.PlayerInventory; import org.geysermc.connector.inventory.PlayerInventory;
import org.geysermc.connector.network.remote.RemoteServer;
import org.geysermc.connector.network.session.auth.AuthData;
import org.geysermc.connector.network.session.auth.BedrockClientData;
import org.geysermc.connector.network.session.cache.*; import org.geysermc.connector.network.session.cache.*;
import org.geysermc.connector.network.translators.Registry; import org.geysermc.connector.network.translators.Registry;
import org.geysermc.connector.network.translators.block.BlockTranslator; import org.geysermc.connector.network.translators.block.BlockTranslator;
import org.geysermc.connector.utils.ChunkUtils; import org.geysermc.connector.utils.ChunkUtils;
import org.geysermc.connector.utils.Toolbox; import org.geysermc.connector.utils.Toolbox;
import org.geysermc.floodgate.util.BedrockData;
import org.geysermc.floodgate.util.EncryptionUtil;
import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@Getter @Getter
public class GeyserSession implements Player { public class GeyserSession implements CommandSender {
private final GeyserConnector connector; private final GeyserConnector connector;
private final UpstreamSession upstream; private final UpstreamSession upstream;
private RemoteServer remoteServer; private RemoteServer remoteServer;
private Client downstream; private Client downstream;
private AuthData authenticationData; @Setter private AuthData authData;
@Setter private BedrockClientData clientData;
private PlayerEntity playerEntity; private PlayerEntity playerEntity;
private PlayerInventory inventory; private PlayerInventory inventory;
@ -135,9 +144,14 @@ public class GeyserSession implements Player {
public void connect(RemoteServer remoteServer) { public void connect(RemoteServer remoteServer) {
startGame(); startGame();
this.remoteServer = remoteServer; this.remoteServer = remoteServer;
if (!(connector.getConfig().getRemote().getAuthType().hashCode() == "online".hashCode())) { if (connector.getAuthType() != AuthType.ONLINE) {
connector.getLogger().info("Attempting to login using offline mode... authentication is disabled."); connector.getLogger().info(
authenticate(authenticationData.getName()); "Attempting to login using " + connector.getAuthType().name().toLowerCase() + " mode... " +
(connector.getAuthType() == AuthType.OFFLINE ?
"authentication is disabled." : "authentication will be encrypted"
)
);
authenticate(authData.getName());
} }
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false); ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
@ -176,14 +190,62 @@ public class GeyserSession implements Player {
protocol = new MinecraftProtocol(username); protocol = new MinecraftProtocol(username);
} }
boolean floodgate = connector.getAuthType() == AuthType.FLOODGATE;
final PublicKey publicKey;
if (floodgate) {
PublicKey key = null;
try {
key = EncryptionUtil.getKeyFromFile(
connector.getConfig().getFloodgateKeyFile(),
PublicKey.class
);
} catch (IOException | InvalidKeySpecException | NoSuchAlgorithmException e) {
connector.getLogger().error("Error while reading Floodgate key file", e);
}
publicKey = key;
} else publicKey = null;
if (publicKey != null) {
connector.getLogger().info("Loaded Floodgate key!");
}
downstream = new Client(remoteServer.getAddress(), remoteServer.getPort(), protocol, new TcpSessionFactory()); downstream = new Client(remoteServer.getAddress(), remoteServer.getPort(), protocol, new TcpSessionFactory());
downstream.getSession().addListener(new SessionAdapter() { downstream.getSession().addListener(new SessionAdapter() {
@Override
public void packetSending(PacketSendingEvent event) {
//todo move this somewhere else
if (event.getPacket() instanceof HandshakePacket && floodgate) {
String encrypted = "";
try {
encrypted = EncryptionUtil.encryptBedrockData(publicKey, new BedrockData(
clientData.getGameVersion(),
authData.getName(),
authData.getXboxUUID(),
clientData.getDeviceOS().ordinal(),
clientData.getLanguageCode(),
clientData.getCurrentInputMode().ordinal(),
upstream.getSession().getAddress().getAddress().getHostAddress()
));
} catch (Exception e) {
connector.getLogger().error("Failed to encrypt message", e);
}
HandshakePacket handshakePacket = event.getPacket();
event.setPacket(new HandshakePacket(
handshakePacket.getProtocolVersion(),
handshakePacket.getHostname() + '\0' + BedrockData.FLOODGATE_IDENTIFIER + '\0' + encrypted,
handshakePacket.getPort(),
handshakePacket.getIntent()
));
}
}
@Override @Override
public void connected(ConnectedEvent event) { public void connected(ConnectedEvent event) {
loggingIn = false; loggingIn = false;
loggedIn = true; loggedIn = true;
connector.getLogger().info(authenticationData.getName() + " (logged in as: " + protocol.getProfile().getName() + ")" + " has connected to remote java server on address " + remoteServer.getAddress()); connector.getLogger().info(authData.getName() + " (logged in as: " + protocol.getProfile().getName() + ")" + " has connected to remote java server on address " + remoteServer.getAddress());
playerEntity.setUuid(protocol.getProfile().getId()); playerEntity.setUuid(protocol.getProfile().getId());
playerEntity.setUsername(protocol.getProfile().getName()); playerEntity.setUsername(protocol.getProfile().getName());
} }
@ -192,7 +254,7 @@ public class GeyserSession implements Player {
public void disconnected(DisconnectedEvent event) { public void disconnected(DisconnectedEvent event) {
loggingIn = false; loggingIn = false;
loggedIn = false; loggedIn = false;
connector.getLogger().info(authenticationData.getName() + " has disconnected from remote java server on address " + remoteServer.getAddress() + " because of " + event.getReason()); connector.getLogger().info(authData.getName() + " has disconnected from remote java server on address " + remoteServer.getAddress() + " because of " + event.getReason());
upstream.disconnect(event.getReason()); upstream.disconnect(event.getReason());
} }
@ -236,21 +298,17 @@ public class GeyserSession implements Player {
closed = true; closed = true;
} }
public boolean isClosed() {
return closed;
}
public void close() { public void close() {
disconnect("Server closed."); disconnect("Server closed.");
} }
public void setAuthenticationData(AuthData authData) { public void setAuthenticationData(AuthData authData) {
authenticationData = authData; this.authData = authData;
} }
@Override @Override
public String getName() { public String getName() {
return authenticationData.getName(); return authData.getName();
} }
@Override @Override
@ -267,10 +325,8 @@ public class GeyserSession implements Player {
} }
@Override @Override
public void sendMessage(String[] messages) { public boolean isConsole() {
for (String message : messages) { return false;
sendMessage(message);
}
} }
public void sendForm(FormWindow window, int id) { public void sendForm(FormWindow window, int id) {
@ -287,7 +343,6 @@ public class GeyserSession implements Player {
upstream.sendPacket(chunkRadiusUpdatedPacket); upstream.sendPacket(chunkRadiusUpdatedPacket);
} }
@Override
public InetSocketAddress getSocketAddress() { public InetSocketAddress getSocketAddress() {
return this.upstream.getAddress(); return this.upstream.getAddress();
} }

View file

@ -2,13 +2,12 @@ package org.geysermc.connector.network.session.auth;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import org.geysermc.api.session.AuthData;
import java.util.UUID; import java.util.UUID;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class BedrockAuthData implements AuthData { public class AuthData {
private String name; private String name;
private UUID UUID; private UUID UUID;

View file

@ -0,0 +1,92 @@
package org.geysermc.connector.network.session.auth;
import com.fasterxml.jackson.annotation.JsonEnumDefaultValue;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import java.util.UUID;
@JsonIgnoreProperties(ignoreUnknown = true)
@Getter
public class BedrockClientData {
@JsonProperty(value = "GameVersion")
private String gameVersion;
@JsonProperty(value = "ServerAddress")
private String serverAddress;
@JsonProperty(value = "ThirdPartyName")
private String username;
@JsonProperty(value = "LanguageCode")
private String languageCode;
@JsonProperty(value = "SkinId")
private String skinId;
@JsonProperty(value = "SkinData")
private String skinData;
@JsonProperty(value = "CapeId")
private String capeId;
@JsonProperty(value = "CapeData")
private byte[] capeData;
@JsonProperty(value = "CapeOnClassicSkin")
private boolean capeOnClassicSkin;
@JsonProperty(value = "SkinResourcePatch")
private String geometryName;
@JsonProperty(value = "SkinGeometryData")
private String geometryData;
@JsonProperty(value = "PremiumSkin")
private boolean premiumSkin;
@JsonProperty(value = "DeviceId")
private String deviceId;
@JsonProperty(value = "DeviceModel")
private String deviceModel;
@JsonProperty(value = "DeviceOS")
private DeviceOS deviceOS;
@JsonProperty(value = "UIProfile")
private UIProfile uiProfile;
@JsonProperty(value = "GuiScale")
private int guiScale;
@JsonProperty(value = "CurrentInputMode")
private InputMode currentInputMode;
@JsonProperty(value = "DefaultInputMode")
private InputMode defaultInputMode;
@JsonProperty("PlatformOnlineId")
private String platformOnlineId;
@JsonProperty(value = "PlatformOfflineId")
private String platformOfflineId;
@JsonProperty(value = "SelfSignedId")
private UUID selfSignedId;
@JsonProperty(value = "ClientRandomId")
private long clientRandomId;
public enum UIProfile {
@JsonEnumDefaultValue
CLASSIC,
POCKET
}
public enum DeviceOS {
@JsonEnumDefaultValue
UNKOWN,
ANDROID,
IOS,
OSX,
FIREOS,
GEARVR,
HOLOLENS,
WIN10,
WIN32,
DEDICATED,
ORBIS,
NX,
SWITCH
}
public enum InputMode {
@JsonEnumDefaultValue
UNKNOWN,
KEYBOARD_MOUSE,
TOUCH, // I guess Touch?
CONTROLLER
}
}

View file

@ -26,14 +26,14 @@
package org.geysermc.connector.network.session.cache; package org.geysermc.connector.network.session.cache;
import com.nukkitx.protocol.bedrock.packet.ModalFormRequestPacket; import com.nukkitx.protocol.bedrock.packet.ModalFormRequestPacket;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.Getter;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.api.window.FormWindow;
import java.util.HashMap; import lombok.Getter;
import java.util.Map;
import org.geysermc.common.window.FormWindow;
import org.geysermc.connector.network.session.GeyserSession;
public class WindowCache { public class WindowCache {

View file

@ -27,7 +27,7 @@ package org.geysermc.connector.network.translators;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.BedrockPacket;
import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import java.util.HashMap; import java.util.HashMap;
@ -55,7 +55,7 @@ public class Registry<T> {
return true; return true;
} }
} catch (Throwable ex) { } catch (Throwable ex) {
GeyserLogger.DEFAULT.error("Could not translate packet " + packet.getClass().getSimpleName(), ex); GeyserConnector.getInstance().getLogger().error("Could not translate packet " + packet.getClass().getSimpleName(), ex);
ex.printStackTrace(); ex.printStackTrace();
} }
} }

View file

@ -37,6 +37,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenW
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.*; import com.github.steveice10.mc.protocol.packet.ingame.server.world.*;
import com.github.steveice10.mc.protocol.packet.login.server.LoginPluginRequestPacket;
import com.nukkitx.nbt.CompoundTagBuilder; import com.nukkitx.nbt.CompoundTagBuilder;
import com.nukkitx.nbt.NbtUtils; import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.nbt.stream.NBTOutputStream; import com.nukkitx.nbt.stream.NBTOutputStream;
@ -91,6 +92,8 @@ public class TranslatorsInit {
} }
public static void start() { public static void start() {
Registry.registerJava(LoginPluginRequestPacket.class, new JavaLoginPluginMessageTranslator());
Registry.registerJava(ServerJoinGamePacket.class, new JavaJoinGameTranslator()); Registry.registerJava(ServerJoinGamePacket.class, new JavaJoinGameTranslator());
Registry.registerJava(ServerPluginMessagePacket.class, new JavaPluginMessageTranslator()); Registry.registerJava(ServerPluginMessagePacket.class, new JavaPluginMessageTranslator());
Registry.registerJava(ServerChatPacket.class, new JavaChatTranslator()); Registry.registerJava(ServerChatPacket.class, new JavaChatTranslator());

View file

@ -27,7 +27,8 @@ package org.geysermc.connector.network.translators.bedrock;
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket; import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket;
import org.geysermc.api.Geyser;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
@ -36,8 +37,8 @@ public class BedrockCommandRequestTranslator extends PacketTranslator<CommandReq
@Override @Override
public void translate(CommandRequestPacket packet, GeyserSession session) { public void translate(CommandRequestPacket packet, GeyserSession session) {
String command = packet.getCommand().replace("/", ""); String command = packet.getCommand().replace("/", "");
if (Geyser.getConnector().getCommandMap().getCommands().containsKey(command)) { if (GeyserConnector.getInstance().getCommandMap().getCommands().containsKey(command)) {
Geyser.getConnector().getCommandMap().runCommand(session, command); GeyserConnector.getInstance().getCommandMap().runCommand(session, command);
} else { } else {
ClientChatPacket chatPacket = new ClientChatPacket(packet.getCommand()); ClientChatPacket chatPacket = new ClientChatPacket(packet.getCommand());
session.getDownstream().getSession().send(chatPacket); session.getDownstream().getSession().send(chatPacket);

View file

@ -31,7 +31,8 @@ import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket; import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
import org.geysermc.api.ChatColor;
import org.geysermc.common.ChatColor;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;

View file

@ -26,6 +26,8 @@
package org.geysermc.connector.network.translators.bedrock; package org.geysermc.connector.network.translators.bedrock;
import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket; import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket;
import org.geysermc.common.AuthType;
import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.entity.PlayerEntity;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;

View file

@ -35,7 +35,7 @@ import com.nukkitx.nbt.tag.ListTag;
import gnu.trove.map.TObjectIntMap; import gnu.trove.map.TObjectIntMap;
import gnu.trove.map.hash.TObjectIntHashMap; import gnu.trove.map.hash.TObjectIntHashMap;
import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.ints.*;
import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.utils.Toolbox; import org.geysermc.connector.utils.Toolbox;
import java.io.InputStream; import java.io.InputStream;
@ -110,7 +110,7 @@ public class BlockTranslator {
} else { } else {
int duplicateRuntimeId = addedStatesMap.get(blockTag); int duplicateRuntimeId = addedStatesMap.get(blockTag);
if (duplicateRuntimeId == -1) { if (duplicateRuntimeId == -1) {
GeyserLogger.DEFAULT.debug("Mapping " + javaId + " was not found for bedrock edition!"); GeyserConnector.getInstance().getLogger().debug("Mapping " + javaId + " was not found for bedrock edition!");
} else { } else {
JAVA_TO_BEDROCK_BLOCK_MAP.put(javaRuntimeId, duplicateRuntimeId); JAVA_TO_BEDROCK_BLOCK_MAP.put(javaRuntimeId, duplicateRuntimeId);
} }

Some files were not shown because too many files have changed in this diff Show more