mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Merge branch 'master' of https://github.com/GeyserMC/Geyser into feature/extensions
This commit is contained in:
commit
9154a4571c
124 changed files with 2921 additions and 1121 deletions
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>bootstrap-parent</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>bootstrap-bungeecord</artifactId>
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
|||
<dependency>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Used for better working with internals without reflection -->
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>geyser-parent</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>bootstrap-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
@ -34,7 +34,7 @@
|
|||
<dependency>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>ap</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>bootstrap-parent</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>bootstrap-spigot</artifactId>
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
|||
<dependency>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -43,7 +43,7 @@
|
|||
<dependency>
|
||||
<groupId>org.geysermc.geyser.adapters</groupId>
|
||||
<artifactId>spigot-all</artifactId>
|
||||
<version>1.3-SNAPSHOT</version>
|
||||
<version>1.4-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
|
|
@ -32,27 +32,26 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.geysermc.common.PlatformType;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.Constants;
|
||||
import org.geysermc.geyser.GeyserBootstrap;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.adapters.spigot.SpigotAdapters;
|
||||
import org.geysermc.geyser.command.GeyserCommandManager;
|
||||
import org.geysermc.geyser.session.auth.AuthType;
|
||||
import org.geysermc.geyser.configuration.GeyserConfiguration;
|
||||
import org.geysermc.geyser.dump.BootstrapDumpInfo;
|
||||
import org.geysermc.geyser.network.MinecraftProtocol;
|
||||
import org.geysermc.geyser.level.WorldManager;
|
||||
import org.geysermc.geyser.network.MinecraftProtocol;
|
||||
import org.geysermc.geyser.ping.GeyserLegacyPingPassthrough;
|
||||
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
|
||||
import org.geysermc.geyser.Constants;
|
||||
import org.geysermc.geyser.util.FileUtils;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
import org.geysermc.geyser.adapters.spigot.SpigotAdapters;
|
||||
import org.geysermc.geyser.platform.spigot.command.GeyserSpigotCommandExecutor;
|
||||
import org.geysermc.geyser.platform.spigot.command.GeyserSpigotCommandManager;
|
||||
import org.geysermc.geyser.platform.spigot.command.SpigotCommandSource;
|
||||
import org.geysermc.geyser.platform.spigot.world.GeyserPistonListener;
|
||||
import org.geysermc.geyser.platform.spigot.world.GeyserSpigot1_11CraftingListener;
|
||||
import org.geysermc.geyser.platform.spigot.world.GeyserSpigotBlockPlaceListener;
|
||||
import org.geysermc.geyser.platform.spigot.world.manager.*;
|
||||
import org.geysermc.geyser.session.auth.AuthType;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
import org.geysermc.geyser.util.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -236,11 +235,6 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
|
|||
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new GeyserPistonListener(geyser, this.geyserWorldManager), this);
|
||||
|
||||
if (isPre1_12) {
|
||||
// Register events needed to send all recipes to the client
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new GeyserSpigot1_11CraftingListener(geyser), this);
|
||||
}
|
||||
|
||||
this.getCommand("geyser").setExecutor(new GeyserSpigotCommandExecutor(geyser));
|
||||
|
||||
// Check to ensure the current setup can support the protocol version Geyser uses
|
||||
|
|
|
@ -1,203 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
package org.geysermc.geyser.platform.spigot.world;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||
import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient;
|
||||
import com.github.steveice10.mc.protocol.data.game.recipe.RecipeType;
|
||||
import com.github.steveice10.mc.protocol.data.game.recipe.data.ShapedRecipeData;
|
||||
import com.github.steveice10.mc.protocol.data.game.recipe.data.ShapelessRecipeData;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.CraftingData;
|
||||
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
||||
import com.nukkitx.protocol.bedrock.packet.CraftingDataPacket;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolPathEntry;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.ShapelessRecipe;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.network.MinecraftProtocol;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.translator.inventory.item.ItemTranslator;
|
||||
import org.geysermc.geyser.util.InventoryUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Used to send all available recipes from the server to the client, as a valid recipe book packet won't be sent by the server.
|
||||
* Requires ViaVersion.
|
||||
*/
|
||||
public class GeyserSpigot1_11CraftingListener implements Listener {
|
||||
|
||||
private final GeyserImpl geyser;
|
||||
/**
|
||||
* Specific mapping data for 1.12 to 1.13. Used to convert the 1.12 item into 1.13.
|
||||
*/
|
||||
private final MappingData mappingData1_12to1_13;
|
||||
/**
|
||||
* The list of all protocols from the client's version to 1.13.
|
||||
*/
|
||||
private final List<ProtocolPathEntry> protocolList;
|
||||
|
||||
public GeyserSpigot1_11CraftingListener(GeyserImpl geyser) {
|
||||
this.geyser = geyser;
|
||||
this.mappingData1_12to1_13 = Via.getManager().getProtocolManager().getProtocol(Protocol1_13To1_12_2.class).getMappingData();
|
||||
this.protocolList = Via.getManager().getProtocolManager().getProtocolPath(MinecraftProtocol.getJavaProtocolVersion(),
|
||||
ProtocolVersion.v1_13.getVersion());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
GeyserSession session = null;
|
||||
for (GeyserSession otherSession : geyser.getSessionManager().getSessions().values()) {
|
||||
if (otherSession.name().equals(event.getPlayer().getName())) {
|
||||
session = otherSession;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (session == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendServerRecipes(session);
|
||||
}
|
||||
|
||||
public void sendServerRecipes(GeyserSession session) {
|
||||
int netId = InventoryUtils.LAST_RECIPE_NET_ID;
|
||||
|
||||
CraftingDataPacket craftingDataPacket = new CraftingDataPacket();
|
||||
craftingDataPacket.setCleanRecipes(true);
|
||||
|
||||
Iterator<Recipe> recipeIterator = Bukkit.getServer().recipeIterator();
|
||||
while (recipeIterator.hasNext()) {
|
||||
Recipe recipe = recipeIterator.next();
|
||||
|
||||
Pair<ItemStack, ItemData> outputs = translateToBedrock(session, recipe.getResult());
|
||||
ItemStack javaOutput = outputs.getKey();
|
||||
ItemData output = outputs.getValue();
|
||||
if (output == null || output.getId() == 0) continue; // If items make air we don't want that
|
||||
|
||||
boolean isNotAllAir = false; // Check for all-air recipes
|
||||
if (recipe instanceof ShapedRecipe shapedRecipe) {
|
||||
int size = shapedRecipe.getShape().length * shapedRecipe.getShape()[0].length();
|
||||
Ingredient[] ingredients = new Ingredient[size];
|
||||
ItemData[] input = new ItemData[size];
|
||||
for (int i = 0; i < input.length; i++) {
|
||||
// Index is converting char to integer, adding i then converting back to char based on ASCII code
|
||||
Pair<ItemStack, ItemData> result = translateToBedrock(session, shapedRecipe.getIngredientMap().get((char) ('a' + i)));
|
||||
ingredients[i] = new Ingredient(new ItemStack[]{result.getKey()});
|
||||
input[i] = result.getValue();
|
||||
isNotAllAir |= input[i].getId() != 0;
|
||||
}
|
||||
|
||||
if (!isNotAllAir) continue;
|
||||
UUID uuid = UUID.randomUUID();
|
||||
// Add recipe to our internal cache
|
||||
ShapedRecipeData data = new ShapedRecipeData(shapedRecipe.getShape()[0].length(), shapedRecipe.getShape().length,
|
||||
"", ingredients, javaOutput);
|
||||
session.getCraftingRecipes().put(netId,
|
||||
new com.github.steveice10.mc.protocol.data.game.recipe.Recipe(RecipeType.CRAFTING_SHAPED, uuid.toString(), data));
|
||||
|
||||
// Add recipe for Bedrock
|
||||
craftingDataPacket.getCraftingData().add(CraftingData.fromShaped(uuid.toString(),
|
||||
shapedRecipe.getShape()[0].length(), shapedRecipe.getShape().length, Arrays.asList(input),
|
||||
Collections.singletonList(output), uuid, "crafting_table", 0, netId++));
|
||||
} else if (recipe instanceof ShapelessRecipe shapelessRecipe) {
|
||||
Ingredient[] ingredients = new Ingredient[shapelessRecipe.getIngredientList().size()];
|
||||
ItemData[] input = new ItemData[shapelessRecipe.getIngredientList().size()];
|
||||
|
||||
for (int i = 0; i < input.length; i++) {
|
||||
Pair<ItemStack, ItemData> result = translateToBedrock(session, shapelessRecipe.getIngredientList().get(i));
|
||||
ingredients[i] = new Ingredient(new ItemStack[]{result.getKey()});
|
||||
input[i] = result.getValue();
|
||||
isNotAllAir |= input[i].getId() != 0;
|
||||
}
|
||||
|
||||
if (!isNotAllAir) continue;
|
||||
UUID uuid = UUID.randomUUID();
|
||||
// Add recipe to our internal cache
|
||||
ShapelessRecipeData data = new ShapelessRecipeData("", ingredients, javaOutput);
|
||||
session.getCraftingRecipes().put(netId,
|
||||
new com.github.steveice10.mc.protocol.data.game.recipe.Recipe(RecipeType.CRAFTING_SHAPELESS, uuid.toString(), data));
|
||||
|
||||
// Add recipe for Bedrock
|
||||
craftingDataPacket.getCraftingData().add(CraftingData.fromShapeless(uuid.toString(),
|
||||
Arrays.asList(input), Collections.singletonList(output), uuid, "crafting_table", 0, netId++));
|
||||
}
|
||||
}
|
||||
|
||||
session.sendUpstreamPacket(craftingDataPacket);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private Pair<ItemStack, ItemData> translateToBedrock(GeyserSession session, org.bukkit.inventory.ItemStack itemStack) {
|
||||
if (itemStack != null && itemStack.getData() != null) {
|
||||
if (itemStack.getType().getId() == 0) {
|
||||
return new Pair<>(null, ItemData.AIR);
|
||||
}
|
||||
|
||||
int legacyId = (itemStack.getType().getId() << 4) | (itemStack.getData().getData() & 0xFFFF);
|
||||
|
||||
if (itemStack.getType().getId() == 355 && itemStack.getData().getData() == (byte) 0) { // Handle bed color since the server will always be pre-1.12
|
||||
legacyId = (itemStack.getType().getId() << 4) | ((byte) 14 & 0xFFFF);
|
||||
}
|
||||
|
||||
// old version -> 1.13 -> 1.13.1 -> 1.14 -> 1.15 -> 1.16 and so on
|
||||
int itemId;
|
||||
if (mappingData1_12to1_13.getItemMappings().containsKey(legacyId)) {
|
||||
itemId = mappingData1_12to1_13.getNewItemId(legacyId);
|
||||
} else if (mappingData1_12to1_13.getItemMappings().containsKey((itemStack.getType().getId() << 4) | (0))) {
|
||||
itemId = mappingData1_12to1_13.getNewItemId((itemStack.getType().getId() << 4) | (0));
|
||||
} else {
|
||||
// No ID found, just send back air
|
||||
return new Pair<>(null, ItemData.AIR);
|
||||
}
|
||||
|
||||
for (int i = protocolList.size() - 1; i >= 0; i--) {
|
||||
MappingData mappingData = protocolList.get(i).getProtocol().getMappingData();
|
||||
if (mappingData != null) {
|
||||
itemId = mappingData.getNewItemId(itemId);
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack mcItemStack = new ItemStack(itemId, itemStack.getAmount());
|
||||
ItemData finalData = ItemTranslator.translateToBedrock(session, mcItemStack);
|
||||
return new Pair<>(mcItemStack, finalData);
|
||||
}
|
||||
|
||||
// Empty slot, most likely
|
||||
return new Pair<>(null, ItemData.AIR);
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>bootstrap-parent</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>bootstrap-sponge</artifactId>
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
|||
<dependency>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>bootstrap-parent</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>bootstrap-standalone</artifactId>
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
|||
<dependency>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -47,17 +47,17 @@
|
|||
<dependency>
|
||||
<groupId>org.jline</groupId>
|
||||
<artifactId>jline-terminal</artifactId>
|
||||
<version>3.20.0</version>
|
||||
<version>3.21.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jline</groupId>
|
||||
<artifactId>jline-terminal-jna</artifactId>
|
||||
<version>3.20.0</version>
|
||||
<version>3.21.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jline</groupId>
|
||||
<artifactId>jline-reader</artifactId>
|
||||
<version>3.20.0</version>
|
||||
<version>3.21.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
|
@ -132,7 +132,6 @@
|
|||
implementation="com.github.edwgiz.mavenShadePlugin.log4j2CacheTransformer.PluginsCacheFileTransformer">
|
||||
</transformer>
|
||||
</transformers>
|
||||
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
|
|
@ -276,6 +276,12 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap {
|
|||
return Paths.get(System.getProperty("user.dir"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getSavedUserLoginsFolder() {
|
||||
// Return the location of the config
|
||||
return new File(configFilename).getAbsoluteFile().getParentFile().toPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BootstrapDumpInfo getDumpInfo() {
|
||||
return new GeyserStandaloneDumpInfo(this);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>bootstrap-parent</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>bootstrap-velocity</artifactId>
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
|||
<dependency>
|
||||
<groupId>org.geysermc</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>2.0.1-SNAPSHOT</version>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue