Skip to content

Commit

Permalink
Merge from upstream
Browse files Browse the repository at this point in the history
Merge branch 'feature/plugins' into bleeding

# Conflicts:
#	connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java
#	connector/src/main/java/org/geysermc/connector/network/translators/bedrock/entity/player/BedrockActionTranslator.java
#	connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUnloadChunkTranslator.java
#	connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java
#	connector/src/main/resources/mappings
  • Loading branch information
bundabrg committed Oct 15, 2020
2 parents 74c6be6 + a63a418 commit 2a99f5e
Show file tree
Hide file tree
Showing 26 changed files with 609 additions and 451 deletions.
2 changes: 1 addition & 1 deletion connector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<dependency>
<groupId>com.github.CloudburstMC.Protocol</groupId>
<artifactId>bedrock-v408</artifactId>
<version>250beb2a94</version>
<version>02f46a8700</version>
<scope>compile</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
import java.net.UnknownHostException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -214,8 +216,39 @@ private GeyserConnector(PlatformType platformType, GeyserBootstrap bootstrap) {
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("players", players::size));
metrics.addCustomChart(new Metrics.SimplePie("authMode", authType.name()::toLowerCase));
// Prevent unwanted words best we can
metrics.addCustomChart(new Metrics.SimplePie("authMode", () -> AuthType.getByName(config.getRemote().getAuthType()).toString().toLowerCase()));
metrics.addCustomChart(new Metrics.SimplePie("platform", platformType::getPlatformName));
metrics.addCustomChart(new Metrics.SimplePie("defaultLocale", LanguageUtils::getDefaultLocale));
metrics.addCustomChart(new Metrics.SimplePie("version", () -> GeyserConnector.VERSION));
metrics.addCustomChart(new Metrics.AdvancedPie("playerPlatform", () -> {
Map<String, Integer> valueMap = new HashMap<>();
for (GeyserSession session : players) {
if (session == null) continue;
if (session.getClientData() == null) continue;
String os = session.getClientData().getDeviceOS().toString();
if (!valueMap.containsKey(os)) {
valueMap.put(os, 1);
} else {
valueMap.put(os, valueMap.get(os) + 1);
}
}
return valueMap;
}));
metrics.addCustomChart(new Metrics.AdvancedPie("playerVersion", () -> {
Map<String, Integer> valueMap = new HashMap<>();
for (GeyserSession session : players) {
if (session == null) continue;
if (session.getClientData() == null) continue;
String version = session.getClientData().getGameVersion();
if (!valueMap.containsKey(version)) {
valueMap.put(version, 1);
} else {
valueMap.put(version, valueMap.get(version) + 1);
}
}
return valueMap;
}));
}

boolean isGui = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import java.nio.file.Path;
import java.util.Map;
import java.util.UUID;

@Getter
@JsonIgnoreProperties(ignoreUnknown = true)
Expand All @@ -45,8 +46,8 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
@Setter
private boolean autoconfiguredRemote = false;

private BedrockConfiguration bedrock;
private RemoteConfiguration remote;
private BedrockConfiguration bedrock = new BedrockConfiguration();
private RemoteConfiguration remote = new RemoteConfiguration();

@JsonProperty("floodgate-key-file")
private String floodgateKeyFile = "public-key.pem";
Expand Down Expand Up @@ -109,7 +110,7 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
@JsonProperty("force-resource-packs")
private boolean forceResourcePacks = true;

private MetricsInfo metrics;
private MetricsInfo metrics = new MetricsInfo();

@Getter
public static class BedrockConfiguration implements IBedrockConfiguration {
Expand Down Expand Up @@ -157,7 +158,7 @@ public static class MetricsInfo implements IMetricsInfo {
private boolean enabled = true;

@JsonProperty("uuid")
private String uniqueId = "generateuuid";
private String uniqueId = UUID.randomUUID().toString();
}

@JsonProperty("scoreboard-packet-threshold")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,23 @@ public AreaEffectCloudEntity(long entityId, long geyserId, EntityType entityType

// This disabled client side shrink of the cloud
metadata.put(EntityData.AREA_EFFECT_CLOUD_RADIUS, 0.0f);
metadata.put(EntityData.AREA_EFFECT_CLOUD_CHANGE_RATE, -0.005f);
metadata.put(EntityData.AREA_EFFECT_CLOUD_CHANGE_ON_PICKUP, -0.5f);
}

@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 7) {
metadata.put(EntityData.AREA_EFFECT_CLOUD_RADIUS, entityMetadata.getValue());
metadata.put(EntityData.BOUNDING_BOX_WIDTH, 2.0f * (float) entityMetadata.getValue());
} else if (entityMetadata.getId() == 8) {
metadata.put(EntityData.EFFECT_COLOR, entityMetadata.getValue());
} else if (entityMetadata.getId() == 10) {
Particle particle = (Particle) entityMetadata.getValue();
metadata.put(EntityData.AREA_EFFECT_CLOUD_PARTICLE_ID, EffectRegistry.getParticleString(particle.getType()));
} else if (entityMetadata.getId() == 8) {
metadata.put(EntityData.POTION_AUX_VALUE, entityMetadata.getValue());
int particleId = EffectRegistry.getParticleId(particle.getType());
if (particleId != -1) {
metadata.put(EntityData.AREA_EFFECT_CLOUD_PARTICLE_ID, particleId);
}
}
super.updateBedrockMetadata(entityMetadata, session);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.entity.living.monster.raid;

import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;

public class PillagerEntity extends AbstractIllagerEntity {

public PillagerEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position, motion, rotation);
}

@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 16) {
// Java Edition always has the Pillager entity as positioning the crossbow
metadata.getFlags().setFlag(EntityFlag.USING_ITEM, true);
metadata.getFlags().setFlag(EntityFlag.CHARGED, true);
}
super.updateBedrockMetadata(entityMetadata, session);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.geysermc.connector.entity.living.merchant.*;
import org.geysermc.connector.entity.living.monster.*;
import org.geysermc.connector.entity.living.monster.raid.AbstractIllagerEntity;
import org.geysermc.connector.entity.living.monster.raid.PillagerEntity;
import org.geysermc.connector.entity.living.monster.raid.RaidParticipantEntity;
import org.geysermc.connector.entity.living.monster.raid.SpellcasterIllagerEntity;

Expand Down Expand Up @@ -90,7 +91,7 @@ public enum EntityType {
ENDERMITE(MonsterEntity.class, 55, 0.3f, 0.4f),
AGENT(Entity.class, 56, 0f),
VINDICATOR(AbstractIllagerEntity.class, 57, 1.8f, 0.6f, 0.6f, 1.62f),
PILLAGER(AbstractIllagerEntity.class, 114, 1.8f, 0.6f, 0.6f, 1.62f),
PILLAGER(PillagerEntity.class, 114, 1.8f, 0.6f, 0.6f, 1.62f),
WANDERING_TRADER(AbstractMerchantEntity.class, 118, 1.8f, 0.6f, 0.6f, 1.62f),
PHANTOM(FlyingEntity.class, 58, 0.5f, 0.9f, 0.9f, 0.6f),
RAVAGER(RaidParticipantEntity.class, 59, 1.9f, 1.2f),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public boolean handle(ResourcePackClientResponsePacket packet) {

case HAVE_ALL_PACKS:
ResourcePackStackPacket stackPacket = new ResourcePackStackPacket();
stackPacket.setExperimental(false);
stackPacket.setExperimentsPreviouslyToggled(false);
stackPacket.setForcedToAccept(false); // Leaving this as false allows the player to choose to download or not
stackPacket.setGameVersion(session.getClientData().getGameVersion());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
import java.util.Map;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -240,6 +241,13 @@ public void setSneaking(boolean sneaking) {
@Setter
private long lastInteractionTime;

/**
* Stores a future interaction to place a bucket. Will be cancelled if the client instead intended to
* interact with a block.
*/
@Setter
private ScheduledFuture<?> bucketScheduledFuture;

private boolean reducedDebugInfo = false;

@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,18 @@

import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
import com.github.steveice10.mc.protocol.data.game.chunk.Column;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import lombok.Getter;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import org.geysermc.connector.bootstrap.GeyserBootstrap;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.connector.network.translators.world.chunk.ChunkPosition;

import java.util.HashMap;
import java.util.Map;

public class ChunkCache {

private final boolean cache;

@Getter
private final Map<ChunkPosition, Column> chunks = new HashMap<>();
private final Long2ObjectMap<Column> chunks = new Long2ObjectOpenHashMap<>();

public ChunkCache(GeyserSession session) {
if (session.getConnector().getWorldManager().getClass() == GeyserBootstrap.DEFAULT_CHUNK_MANAGER.getClass()) {
Expand All @@ -56,57 +52,66 @@ public void addToCache(Column chunk) {
if (!cache) {
return;
}
ChunkPosition position = new ChunkPosition(chunk.getX(), chunk.getZ());
if (chunk.getBiomeData() == null && chunks.containsKey(position)) {
Column newColumn = chunk;
chunk = chunks.get(position);
for (int i = 0; i < newColumn.getChunks().length; i++) {
if (newColumn.getChunks()[i] != null) {
chunk.getChunks()[i] = newColumn.getChunks()[i];

long chunkPosition = ChunkPosition.toLong(chunk.getX(), chunk.getZ());
Column existingChunk;
if (chunk.getBiomeData() != null // Only consider merging columns if the new chunk isn't a full chunk
&& (existingChunk = chunks.getOrDefault(chunkPosition, null)) != null) { // Column is already present in cache, we can merge with existing
for (int i = 0; i < chunk.getChunks().length; i++) { // The chunks member is final, so chunk.getChunks() will probably be inlined and then completely optimized away
if (chunk.getChunks()[i] != null) {
existingChunk.getChunks()[i] = chunk.getChunks()[i];
}
}
} else {
chunks.put(chunkPosition, chunk);
}
chunks.put(position, chunk);
}

public void updateBlock(Position position, int block) {
public Column getChunk(int chunkX, int chunkZ) {
long chunkPosition = ChunkPosition.toLong(chunkX, chunkZ);
return chunks.getOrDefault(chunkPosition, null);
}

public void updateBlock(int x, int y, int z, int block) {
if (!cache) {
return;
}
ChunkPosition chunkPosition = new ChunkPosition(position.getX() >> 4, position.getZ() >> 4);
if (!chunks.containsKey(chunkPosition))

Column column = this.getChunk(x >> 4, z >> 4);
if (column == null) {
return;
}

Column column = chunks.get(chunkPosition);
Chunk chunk = column.getChunks()[position.getY() >> 4];
Position blockPosition = chunkPosition.getChunkBlock(position.getX(), position.getY(), position.getZ());
Chunk chunk = column.getChunks()[y >> 4];
if (chunk != null) {
chunk.set(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ(), block);
chunk.set(x & 0xF, y & 0xF, z & 0xF, block);
}
}

public int getBlockAt(Position position) {
public int getBlockAt(int x, int y, int z) {
if (!cache) {
return BlockTranslator.AIR;
}
ChunkPosition chunkPosition = new ChunkPosition(position.getX() >> 4, position.getZ() >> 4);
if (!chunks.containsKey(chunkPosition))

Column column = this.getChunk(x >> 4, z >> 4);
if (column == null) {
return BlockTranslator.AIR;
}

Column column = chunks.get(chunkPosition);
Chunk chunk = column.getChunks()[position.getY() >> 4];
Position blockPosition = chunkPosition.getChunkBlock(position.getX(), position.getY(), position.getZ());
Chunk chunk = column.getChunks()[y >> 4];
if (chunk != null) {
return chunk.get(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
return chunk.get(x & 0xF, y & 0xF, z & 0xF);
}

return BlockTranslator.AIR;
}

public void removeChunk(ChunkPosition position) {
public void removeChunk(int chunkX, int chunkZ) {
if (!cache) {
return;
}
chunks.remove(position);

long chunkPosition = ChunkPosition.toLong(chunkX, chunkZ);
chunks.remove(chunkPosition);
}
}
Loading

0 comments on commit 2a99f5e

Please sign in to comment.