Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into floodgate-2.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java
  • Loading branch information
Tim203 committed Mar 23, 2021
2 parents 4229db0 + 86397ef commit 107cd5b
Show file tree
Hide file tree
Showing 45 changed files with 830 additions and 638 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void getBlocksInSection(GeyserSession session, int x, int y, int z, Chunk
}

@Override
public boolean hasMoreBlockDataThanChunkCache() {
public boolean hasOwnChunkCache() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void getBlocksInSection(GeyserSession session, int x, int y, int z, Chunk
}

@Override
public boolean hasMoreBlockDataThanChunkCache() {
public boolean hasOwnChunkCache() {
return true;
}

Expand Down Expand Up @@ -235,6 +235,7 @@ public NbtMap getLecternDataAt(GeyserSession session, int x, int y, int z, boole
NbtMap blockEntityTag = lecternTag.build();
BlockEntityUtils.updateBlockEntity(session, blockEntityTag, Vector3i.from(x, y, z));
};

if (isChunkLoad) {
// Delay to ensure the chunk is sent first, and then the lectern data
Bukkit.getScheduler().runTaskLater(this.plugin, lecternInfoGet, 5);
Expand Down
6 changes: 3 additions & 3 deletions connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<properties>
<netty.version>4.1.59.Final</netty.version>
<fastutil.version>8.5.2</fastutil.version>
<adventure.version>4.5.0</adventure.version>
<adventure.version>4.7.0</adventure.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -151,9 +151,9 @@
</exclusions>
</dependency>
<dependency>
<groupId>com.github.steveice10</groupId>
<groupId>com.github.GeyserMC</groupId>
<artifactId>PacketLib</artifactId>
<version>54f761c</version>
<version>b77a427</version>
<scope>compile</scope>
<exclusions>
<exclusion> <!-- Move this exclusion back to MCProtocolLib it gets the latest PacketLib -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.metrics.Metrics;
import org.geysermc.connector.network.ConnectorServerEventHandler;
import org.geysermc.connector.network.remote.RemoteServer;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.BiomeTranslator;
import org.geysermc.connector.network.translators.EntityIdentifierRegistry;
Expand Down Expand Up @@ -103,9 +102,8 @@ public class GeyserConnector {

private static GeyserConnector instance;

private RemoteServer remoteServer;
@Setter
private AuthType authType;
private AuthType defaultAuthType;

private FloodgateCipher cipher;
private FloodgateSkinUploader skinUploader;
Expand Down Expand Up @@ -175,7 +173,7 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {
String remoteAddress = config.getRemote().getAddress();
int remotePort = config.getRemote().getPort();
// Filters whether it is not an IP address or localhost, because otherwise it is not possible to find out an SRV entry.
if ((config.isLegacyPingPassthrough() || platformType == PlatformType.STANDALONE) && !remoteAddress.matches(IP_REGEX) && !remoteAddress.equalsIgnoreCase("localhost")) {
if (!remoteAddress.matches(IP_REGEX) && !remoteAddress.equalsIgnoreCase("localhost")) {
try {
// Searches for a server address and a port from a SRV record of the specified host name
InitialDirContext ctx = new InitialDirContext();
Expand All @@ -195,8 +193,7 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {
}
}

remoteServer = new RemoteServer(config.getRemote().getAddress(), remotePort);
authType = AuthType.getByName(config.getRemote().getAuthType());
defaultAuthType = AuthType.getByName(config.getRemote().getAuthType());

if (authType == AuthType.FLOODGATE) {
try {
Expand Down Expand Up @@ -355,8 +352,7 @@ public void run() {
generalThreadPool.shutdown();
bedrockServer.close();
players.clear();
remoteServer = null;
authType = null;
defaultAuthType = null;
this.getCommandManager().getCommands().clear();

bootstrap.getGeyserLogger().info(LanguageUtils.getLocaleStringLog("geyser.core.shutdown.done"));
Expand Down Expand Up @@ -392,6 +388,7 @@ public GeyserSession getPlayerByUuid(UUID uuid) {
* @param xuid the Xbox user identifier
* @return the player or <code>null</code> if there is no player online with this xuid
*/
@SuppressWarnings("unused") // API usage
public GeyserSession getPlayerByXuid(String xuid) {
for (GeyserSession session : players) {
if (session.getAuthData() != null && session.getAuthData().getXboxUUID().equals(xuid)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.MetadataType;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.AttributeData;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
Expand All @@ -50,11 +44,9 @@
import org.geysermc.connector.entity.living.ArmorStandEntity;
import org.geysermc.connector.entity.player.PlayerEntity;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.inventory.PlayerInventory;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.utils.AttributeUtils;
import org.geysermc.connector.network.translators.chat.MessageTranslator;
import org.geysermc.connector.utils.AttributeUtils;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -278,29 +270,6 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
if (!this.is(ArmorStandEntity.class)) {
metadata.getFlags().setFlag(EntityFlag.INVISIBLE, (xd & 0x20) == 0x20);
}

// Shield code
if (session.getPlayerEntity().getEntityId() == entityId && metadata.getFlags().getFlag(EntityFlag.SNEAKING)) {
PlayerInventory playerInv = session.getPlayerInventory();
if ((playerInv.getItemInHand().getJavaId() == ItemRegistry.SHIELD.getJavaId()) ||
(playerInv.getOffhand().getJavaId() == ItemRegistry.SHIELD.getJavaId())) {
ClientPlayerUseItemPacket useItemPacket;
metadata.getFlags().setFlag(EntityFlag.BLOCKING, true);
if (playerInv.getItemInHand().getJavaId() == ItemRegistry.SHIELD.getJavaId()) {
useItemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
}
// Else we just assume it's the offhand, to simplify logic and to assure the packet gets sent
else {
useItemPacket = new ClientPlayerUseItemPacket(Hand.OFF_HAND);
}
session.sendDownstreamPacket(useItemPacket);
}
} else if (session.getPlayerEntity().getEntityId() == entityId && !metadata.getFlags().getFlag(EntityFlag.SNEAKING) && metadata.getFlags().getFlag(EntityFlag.BLOCKING)) {
metadata.getFlags().setFlag(EntityFlag.BLOCKING, false);
metadata.getFlags().setFlag(EntityFlag.IS_AVOIDING_BLOCK, true);
ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, new Position(0, 0, 0), BlockFace.DOWN);
session.sendDownstreamPacket(releaseItemPacket);
}
}
break;
case 1: // Air/bubbles
Expand Down Expand Up @@ -331,15 +300,12 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
case 6: // Pose change
if (entityMetadata.getValue().equals(Pose.SLEEPING)) {
metadata.getFlags().setFlag(EntityFlag.SLEEPING, true);
// Has to be a byte or it does not work
metadata.put(EntityData.PLAYER_FLAGS, (byte) 2);
metadata.put(EntityData.BOUNDING_BOX_WIDTH, 0.2f);
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, 0.2f);
} else if (metadata.getFlags().getFlag(EntityFlag.SLEEPING)) {
metadata.getFlags().setFlag(EntityFlag.SLEEPING, false);
metadata.put(EntityData.BOUNDING_BOX_WIDTH, getEntityType().getWidth());
metadata.put(EntityData.BOUNDING_BOX_HEIGHT, getEntityType().getHeight());
metadata.put(EntityData.PLAYER_FLAGS, (byte) 0);
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,25 @@ protected void moveAbsoluteImmediate(GeyserSession session, Vector3f position, V
boolean touchingWater = false;
boolean collided = false;
for (Vector3i blockPos : collidableBlocks) {
if (0 <= blockPos.getY() && blockPos.getY() <= 255) {
int blockID = session.getConnector().getWorldManager().getBlockAt(session, blockPos);
BlockCollision blockCollision = CollisionTranslator.getCollision(blockID, blockPos.getX(), blockPos.getY(), blockPos.getZ());
if (blockCollision != null && blockCollision.checkIntersection(boundingBox)) {
// TODO Push bounding box out of collision to improve movement
collided = true;
}
int blockID = session.getConnector().getWorldManager().getBlockAt(session, blockPos);
BlockCollision blockCollision = CollisionTranslator.getCollision(blockID, blockPos.getX(), blockPos.getY(), blockPos.getZ());
if (blockCollision != null && blockCollision.checkIntersection(boundingBox)) {
// TODO Push bounding box out of collision to improve movement
collided = true;
}

int waterLevel = BlockStateValues.getWaterLevel(blockID);
if (BlockTranslator.isWaterlogged(blockID)) {
waterLevel = 0;
int waterLevel = BlockStateValues.getWaterLevel(blockID);
if (BlockTranslator.isWaterlogged(blockID)) {
waterLevel = 0;
}
if (waterLevel >= 0) {
double waterMaxY = blockPos.getY() + 1 - (waterLevel + 1) / 9.0;
// Falling water is a full block
if (waterLevel >= 8) {
waterMaxY = blockPos.getY() + 1;
}
if (waterLevel >= 0) {
double waterMaxY = blockPos.getY() + 1 - (waterLevel + 1) / 9.0;
// Falling water is a full block
if (waterLevel >= 8) {
waterMaxY = blockPos.getY() + 1;
}
if (position.getY() <= waterMaxY) {
touchingWater = true;
}
if (position.getY() <= waterMaxY) {
touchingWater = true;
}
}
}
Expand Down Expand Up @@ -177,10 +175,8 @@ protected float getGravity(GeyserSession session) {
*/
protected boolean isInAir(GeyserSession session) {
if (session.getConnector().getConfig().isCacheChunks()) {
if (0 <= position.getFloorY() && position.getFloorY() <= 255) {
int block = session.getConnector().getWorldManager().getBlockAt(session, position.toInt());
return block == BlockTranslator.JAVA_AIR_ID;
}
int block = session.getConnector().getWorldManager().getBlockAt(session, position.toInt());
return block == BlockTranslator.JAVA_AIR_ID;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
// Bed has to be updated, or else player is floating in the air
ChunkUtils.updateBlock(session, bed, bedPosition);
}
// Indicate that the player should enter the sleep cycle
// Has to be a byte or it does not work
// (Bed position is what actually triggers sleep - "pose" is only optional)
metadata.put(EntityData.PLAYER_FLAGS, (byte) 2);
} else {
// Player is no longer sleeping
metadata.put(EntityData.PLAYER_FLAGS, (byte) 0);
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package org.geysermc.connector.entity.living.merchant;

import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.VillagerData;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i;
Expand Down Expand Up @@ -101,11 +100,17 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s

@Override
public void moveRelative(GeyserSession session, double relX, double relY, double relZ, Vector3f rotation, boolean isOnGround) {
if (!metadata.getFlags().getFlag(EntityFlag.SLEEPING)) {
// No need to worry about extra processing to compensate for sleeping
super.moveRelative(session, relX, relY, relZ, rotation, isOnGround);
return;
}

int z = 0;
int bedId = 0;
float bedPositionSubtractorW = 0;
float bedPositionSubtractorN = 0;
Vector3i bedPosition = metadata.getPos(EntityData.BED_POSITION);
Vector3i bedPosition = metadata.getPos(EntityData.BED_POSITION, null);
if (session.getConnector().getConfig().isCacheChunks() && bedPosition != null) {
bedId = session.getConnector().getWorldManager().getBlockAt(session, bedPosition);
}
Expand All @@ -117,39 +122,33 @@ public void moveRelative(GeyserSession session, double relX, double relY, double
MoveEntityAbsolutePacket moveEntityPacket = new MoveEntityAbsolutePacket();
moveEntityPacket.setRuntimeEntityId(geyserId);
//Sets Villager position and rotation when sleeping
if (!metadata.getFlags().getFlag(EntityFlag.SLEEPING)) {
moveEntityPacket.setPosition(position);
moveEntityPacket.setRotation(getBedrockRotation());
} else {
//String Setup
Pattern r = Pattern.compile("facing=([a-z]+)");
Matcher m = r.matcher(bedRotationZ);
if (m.find()) {
switch (m.group(0)) {
case "facing=south":
//bed is facing south
z = 180;
bedPositionSubtractorW = -.5f;
break;
case "facing=east":
//bed is facing east
z = 90;
bedPositionSubtractorW = -.5f;
break;
case "facing=west":
//bed is facing west
z = 270;
bedPositionSubtractorW = .5f;
break;
case "facing=north":
//rotation does not change because north is 0
bedPositionSubtractorN = .5f;
break;
}
Pattern r = Pattern.compile("facing=([a-z]+)");
Matcher m = r.matcher(bedRotationZ);
if (m.find()) {
switch (m.group(0)) {
case "facing=south":
//bed is facing south
z = 180;
bedPositionSubtractorW = -.5f;
break;
case "facing=east":
//bed is facing east
z = 90;
bedPositionSubtractorW = -.5f;
break;
case "facing=west":
//bed is facing west
z = 270;
bedPositionSubtractorW = .5f;
break;
case "facing=north":
//rotation does not change because north is 0
bedPositionSubtractorN = .5f;
break;
}
moveEntityPacket.setRotation(Vector3f.from(0, 0, z));
moveEntityPacket.setPosition(Vector3f.from(position.getX() + bedPositionSubtractorW, position.getY(), position.getZ() + bedPositionSubtractorN));
}
moveEntityPacket.setRotation(Vector3f.from(0, 0, z));
moveEntityPacket.setPosition(Vector3f.from(position.getX() + bedPositionSubtractorW, position.getY(), position.getZ() + bedPositionSubtractorN));
moveEntityPacket.setOnGround(isOnGround);
moveEntityPacket.setTeleported(false);
session.sendUpstreamPacket(moveEntityPacket);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@

import com.github.steveice10.mc.protocol.data.game.window.WindowType;
import lombok.Getter;
import org.geysermc.connector.network.session.GeyserSession;

public class Generic3X3Container extends Container {
/**
* Whether we need to set the container type as {@link com.nukkitx.protocol.bedrock.data.inventory.ContainerType#DROPPER}
* Whether we need to set the container type as {@link com.nukkitx.protocol.bedrock.data.inventory.ContainerType#DROPPER}.
*
* Used at {@link org.geysermc.connector.network.translators.inventory.translators.Generic3X3InventoryTranslator#openInventory(GeyserSession, Inventory)}
*/
@Getter
private boolean isDropper = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public GeyserItemStack(int javaId, int amount, CompoundTag nbt, int netId) {
this.netId = netId;
}

public static GeyserItemStack from(ItemStack itemStack) {
return itemStack == null ? EMPTY : new GeyserItemStack(itemStack.getId(), itemStack.getAmount(), itemStack.getNbt());
}

public int getJavaId() {
return isEmpty() ? 0 : javaId;
}
Expand All @@ -74,10 +78,6 @@ public CompoundTag getNbt() {
return isEmpty() ? null : nbt;
}

public void setNetId(int netId) {
this.netId = netId;
}

public int getNetId() {
return isEmpty() ? 0 : netId;
}
Expand All @@ -90,10 +90,6 @@ public void sub(int sub) {
amount -= sub;
}

public static GeyserItemStack from(ItemStack itemStack) {
return itemStack == null ? EMPTY : new GeyserItemStack(itemStack.getId(), itemStack.getAmount(), itemStack.getNbt());
}

public ItemStack getItemStack() {
return getItemStack(amount);
}
Expand Down
Loading

0 comments on commit 107cd5b

Please sign in to comment.