Skip to content

Commit e161703

Browse files
Merge branch 'master' into hardcore-fix
2 parents 0fe4bbc + 006fe75 commit e161703

File tree

10 files changed

+401
-296
lines changed

10 files changed

+401
-296
lines changed

core/src/main/java/org/geysermc/geyser/entity/attribute/GeyserAttributeType.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@
3535
public enum GeyserAttributeType {
3636

3737
// Universal Attributes
38-
FOLLOW_RANGE("minecraft:generic.follow_range", "minecraft:follow_range", 0f, 2048f, 32f),
39-
KNOCKBACK_RESISTANCE("minecraft:generic.knockback_resistance", "minecraft:knockback_resistance", 0f, 1f, 0f),
40-
MOVEMENT_SPEED("minecraft:generic.movement_speed", "minecraft:movement", 0f, 1024f, 0.1f),
41-
FLYING_SPEED("minecraft:generic.flying_speed", "minecraft:movement", 0.0f, 1024.0f, 0.4000000059604645f),
42-
ATTACK_DAMAGE("minecraft:generic.attack_damage", "minecraft:attack_damage", 0f, 2048f, 1f),
43-
HORSE_JUMP_STRENGTH("minecraft:horse.jump_strength", "minecraft:horse.jump_strength", 0.0f, 2.0f, 0.7f),
44-
LUCK("minecraft:generic.luck", "minecraft:luck", -1024f, 1024f, 0f),
38+
FOLLOW_RANGE("minecraft:follow_range", "minecraft:follow_range", 0f, 2048f, 32f),
39+
KNOCKBACK_RESISTANCE("minecraft:knockback_resistance", "minecraft:knockback_resistance", 0f, 1f, 0f),
40+
MOVEMENT_SPEED("minecraft:movement_speed", "minecraft:movement", 0f, 1024f, 0.1f),
41+
FLYING_SPEED("minecraft:flying_speed", "minecraft:movement", 0.0f, 1024.0f, 0.4000000059604645f),
42+
ATTACK_DAMAGE("minecraft:attack_damage", "minecraft:attack_damage", 0f, 2048f, 1f),
43+
HORSE_JUMP_STRENGTH("minecraft:jump_strength", "minecraft:horse.jump_strength", 0.0f, 2.0f, 0.7f),
44+
LUCK("minecraft:luck", "minecraft:luck", -1024f, 1024f, 0f),
4545

4646
// Java Attributes
47-
ARMOR("minecraft:generic.armor", null, 0f, 30f, 0f),
48-
ARMOR_TOUGHNESS("minecraft:generic.armor_toughness", null, 0F, 20f, 0f),
49-
ATTACK_KNOCKBACK("minecraft:generic.attack_knockback", null, 1.5f, Float.MAX_VALUE, 0f),
50-
ATTACK_SPEED("minecraft:generic.attack_speed", null, 0f, 1024f, 4f),
51-
MAX_HEALTH("minecraft:generic.max_health", null, 0f, 1024f, 20f),
52-
SCALE("minecraft:generic.scale", null, 0.0625f, 16f, 1f),
53-
BLOCK_INTERACTION_RANGE("minecraft:player.block_interaction_range", null, 0.0f, 64f, 4.5f),
47+
ARMOR("minecraft:armor", null, 0f, 30f, 0f),
48+
ARMOR_TOUGHNESS("minecraft:armor_toughness", null, 0F, 20f, 0f),
49+
ATTACK_KNOCKBACK("minecraft:attack_knockback", null, 1.5f, Float.MAX_VALUE, 0f),
50+
ATTACK_SPEED("minecraft:attack_speed", null, 0f, 1024f, 4f),
51+
MAX_HEALTH("minecraft:max_health", null, 0f, 1024f, 20f),
52+
SCALE("minecraft:scale", null, 0.0625f, 16f, 1f),
53+
BLOCK_INTERACTION_RANGE("minecraft:block_interaction_range", null, 0.0f, 64f, 4.5f),
5454
MINING_EFFICIENCY("minecraft:mining_efficiency", null, 0f, 1024f, 0f),
5555
BLOCK_BREAK_SPEED("minecraft:block_break_speed", null, 0f, 1024f, 1f),
5656
SUBMERGED_MINING_SPEED("minecraft:submerged_mining_speed", null, 0f, 20f, 0.2f),

core/src/main/java/org/geysermc/geyser/entity/type/BoatEntity.java

+12-24
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import org.cloudburstmc.protocol.bedrock.packet.MoveEntityAbsolutePacket;
3333
import org.geysermc.geyser.entity.EntityDefinition;
3434
import org.geysermc.geyser.entity.EntityDefinitions;
35-
import org.geysermc.geyser.item.Items;
36-
import org.geysermc.geyser.item.type.Item;
3735
import org.geysermc.geyser.network.GameProtocol;
3836
import org.geysermc.geyser.session.GeyserSession;
3937
import org.geysermc.geyser.util.InteractionResult;
@@ -220,10 +218,6 @@ public long leashHolderBedrockId() {
220218
return leashHolderBedrockId;
221219
}
222220

223-
public Item getPickItem() {
224-
return variant.pickItem;
225-
}
226-
227221
private void sendAnimationPacket(GeyserSession session, Entity rower, AnimatePacket.Action action, float rowTime) {
228222
AnimatePacket packet = new AnimatePacket();
229223
packet.setRuntimeEntityId(rower.getGeyserId());
@@ -236,23 +230,17 @@ private void sendAnimationPacket(GeyserSession session, Entity rower, AnimatePac
236230
* Ordered by Bedrock ordinal
237231
*/
238232
public enum BoatVariant {
239-
OAK(Items.OAK_BOAT, Items.OAK_CHEST_BOAT),
240-
SPRUCE(Items.SPRUCE_BOAT, Items.SPRUCE_CHEST_BOAT),
241-
BIRCH(Items.BIRCH_BOAT, Items.BIRCH_CHEST_BOAT),
242-
JUNGLE(Items.JUNGLE_BOAT, Items.JUNGLE_CHEST_BOAT),
243-
ACACIA(Items.ACACIA_BOAT, Items.ACACIA_CHEST_BOAT),
244-
DARK_OAK(Items.DARK_OAK_BOAT, Items.DARK_OAK_CHEST_BOAT),
245-
MANGROVE(Items.MANGROVE_BOAT, Items.MANGROVE_CHEST_BOAT),
246-
BAMBOO(Items.BAMBOO_RAFT, Items.BAMBOO_CHEST_RAFT),
247-
CHERRY(Items.CHERRY_BOAT, Items.CHERRY_CHEST_BOAT),
248-
PALE_OAK(Items.PALE_OAK_BOAT, Items.PALE_OAK_CHEST_BOAT);
249-
250-
private final Item pickItem;
251-
final Item chestPickItem;
252-
253-
BoatVariant(Item pickItem, Item chestPickItem) {
254-
this.pickItem = pickItem;
255-
this.chestPickItem = chestPickItem;
256-
}
233+
OAK,
234+
SPRUCE,
235+
BIRCH,
236+
JUNGLE,
237+
ACACIA,
238+
DARK_OAK,
239+
MANGROVE,
240+
BAMBOO,
241+
CHERRY,
242+
PALE_OAK;
243+
244+
BoatVariant() {}
257245
}
258246
}

core/src/main/java/org/geysermc/geyser/entity/type/ChestBoatEntity.java

-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import org.cloudburstmc.math.vector.Vector3f;
2929
import org.geysermc.geyser.entity.EntityDefinition;
30-
import org.geysermc.geyser.item.type.Item;
3130
import org.geysermc.geyser.session.GeyserSession;
3231
import org.geysermc.geyser.util.InteractionResult;
3332
import org.geysermc.geyser.util.InteractiveTag;
@@ -49,9 +48,4 @@ protected InteractiveTag testInteraction(Hand hand) {
4948
public InteractionResult interact(Hand hand) {
5049
return passengers.isEmpty() && !session.isSneaking() ? super.interact(hand) : InteractionResult.SUCCESS;
5150
}
52-
53-
@Override
54-
public Item getPickItem() {
55-
return this.variant.chestPickItem;
56-
}
5751
}

core/src/main/java/org/geysermc/geyser/entity/type/TextDisplayEntity.java

+16
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,25 @@
2525

2626
package org.geysermc.geyser.entity.type;
2727

28+
import lombok.Getter;
2829
import net.kyori.adventure.text.Component;
30+
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
2931
import org.cloudburstmc.math.vector.Vector3f;
3032
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
3133
import org.geysermc.geyser.entity.EntityDefinition;
3234
import org.geysermc.geyser.session.GeyserSession;
3335
import org.geysermc.geyser.translator.text.MessageTranslator;
3436
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
37+
import org.jetbrains.annotations.Nullable;
3538

3639
import java.util.UUID;
3740

3841
// Note: 1.19.4 requires that the billboard is set to something in order to show, on Java Edition
42+
@Getter
3943
public class TextDisplayEntity extends DisplayBaseEntity {
44+
45+
private int lineCount;
46+
4047
public TextDisplayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
4148
super(session, entityId, geyserId, uuid, definition, position.add(0, definition.offset(), 0), motion, yaw, pitch, headYaw);
4249
}
@@ -61,5 +68,14 @@ protected void initializeMetadata() {
6168

6269
public void setText(EntityMetadata<Component, ?> entityMetadata) {
6370
this.dirtyMetadata.put(EntityDataTypes.NAME, MessageTranslator.convertMessage(entityMetadata.getValue()));
71+
calculateLineCount(entityMetadata.getValue());
72+
}
73+
74+
private void calculateLineCount(@Nullable Component text) {
75+
if (text == null) {
76+
lineCount = 0;
77+
return;
78+
}
79+
lineCount = PlainTextComponentSerializer.plainText().serialize(text).split("\n").length;
6480
}
6581
}

core/src/main/java/org/geysermc/geyser/extension/GeyserExtensionLoader.java

+92-40
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.checkerframework.checker.nullness.qual.NonNull;
3232
import org.geysermc.api.util.ApiVersion;
3333
import org.geysermc.geyser.GeyserImpl;
34+
import org.geysermc.geyser.GeyserLogger;
3435
import org.geysermc.geyser.api.GeyserApi;
3536
import org.geysermc.geyser.api.event.ExtensionEventBus;
3637
import org.geysermc.geyser.api.extension.Extension;
@@ -42,6 +43,7 @@
4243
import org.geysermc.geyser.api.extension.exception.InvalidExtensionException;
4344
import org.geysermc.geyser.extension.event.GeyserExtensionEventBus;
4445
import org.geysermc.geyser.text.GeyserLocale;
46+
import org.geysermc.geyser.util.ThrowingBiConsumer;
4547

4648
import java.io.IOException;
4749
import java.io.Reader;
@@ -51,10 +53,12 @@
5153
import java.nio.file.NoSuchFileException;
5254
import java.nio.file.Path;
5355
import java.nio.file.StandardCopyOption;
56+
import java.util.ArrayList;
5457
import java.util.HashMap;
5558
import java.util.LinkedHashMap;
5659
import java.util.List;
5760
import java.util.Map;
61+
import java.util.function.BiConsumer;
5862
import java.util.regex.Pattern;
5963

6064
@RequiredArgsConstructor
@@ -155,6 +159,7 @@ void setClass(String name, final Class<?> clazz) {
155159

156160
@Override
157161
protected void loadAllExtensions(@NonNull ExtensionManager extensionManager) {
162+
GeyserLogger logger = GeyserImpl.getInstance().getLogger();
158163
try {
159164
if (Files.notExists(extensionsDirectory)) {
160165
Files.createDirectory(extensionsDirectory);
@@ -163,55 +168,68 @@ protected void loadAllExtensions(@NonNull ExtensionManager extensionManager) {
163168
Map<String, Path> extensions = new LinkedHashMap<>();
164169
Map<String, GeyserExtensionContainer> loadedExtensions = new LinkedHashMap<>();
165170

166-
Pattern[] extensionFilters = this.extensionFilters();
167-
List<Path> extensionPaths = Files.walk(extensionsDirectory).toList();
168-
extensionPaths.forEach(path -> {
169-
if (Files.isDirectory(path)) {
171+
Path updateDirectory = extensionsDirectory.resolve("update");
172+
if (Files.isDirectory(updateDirectory)) {
173+
// Step 1: Collect the extension files that currently exist so they can be replaced
174+
Map<String, List<Path>> extensionFiles = new HashMap<>();
175+
this.processExtensionsFolder(extensionsDirectory, (path, description) -> {
176+
extensionFiles.computeIfAbsent(description.id(), k -> new ArrayList<>()).add(path);
177+
}, (path, e) -> {
178+
// this file will throw again when we actually try to load extensions, and it will be handled there
179+
});
180+
181+
// Step 2: Move the updated/new extensions
182+
this.processExtensionsFolder(updateDirectory, (path, description) -> {
183+
// Remove the old extension files with the same ID if it exists
184+
List<Path> oldExtensionFiles = extensionFiles.get(description.id());
185+
if (oldExtensionFiles != null) {
186+
for (Path oldExtensionFile : oldExtensionFiles) {
187+
Files.delete(oldExtensionFile);
188+
}
189+
}
190+
191+
// Overwrite the extension with the new jar
192+
Files.move(path, extensionsDirectory.resolve(path.getFileName()), StandardCopyOption.REPLACE_EXISTING);
193+
}, (path, e) -> {
194+
logger.error(GeyserLocale.getLocaleStringLog("geyser.extensions.update.failed", path.getFileName()), e);
195+
});
196+
}
197+
198+
// Step 3: Load the extensions
199+
this.processExtensionsFolder(extensionsDirectory, (path, description) -> {
200+
String name = description.name();
201+
String id = description.id();
202+
if (extensions.containsKey(id) || extensionManager.extension(id) != null) {
203+
logger.warning(GeyserLocale.getLocaleStringLog("geyser.extensions.load.duplicate", name, path.toString()));
170204
return;
171205
}
172206

173-
for (Pattern filter : extensionFilters) {
174-
if (!filter.matcher(path.getFileName().toString()).matches()) {
207+
// Check whether an extensions' requested api version is compatible
208+
ApiVersion.Compatibility compatibility = GeyserApi.api().geyserApiVersion().supportsRequestedVersion(
209+
description.humanApiVersion(),
210+
description.majorApiVersion(),
211+
description.minorApiVersion()
212+
);
213+
214+
if (compatibility != ApiVersion.Compatibility.COMPATIBLE) {
215+
// Workaround for the switch to the Geyser API version instead of the Base API version in extensions
216+
if (compatibility == ApiVersion.Compatibility.HUMAN_DIFFER && description.humanApiVersion() == 1) {
217+
logger.warning("The extension %s requested the Base API version %s, which is deprecated in favor of specifying the Geyser API version. Please update the extension, or contact its developer."
218+
.formatted(name, description.apiVersion()));
219+
} else {
220+
logger.error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, description.apiVersion()));
175221
return;
176222
}
177223
}
178224

179-
try {
180-
GeyserExtensionDescription description = this.extensionDescription(path);
181-
182-
String name = description.name();
183-
String id = description.id();
184-
if (extensions.containsKey(id) || extensionManager.extension(id) != null) {
185-
GeyserImpl.getInstance().getLogger().warning(GeyserLocale.getLocaleStringLog("geyser.extensions.load.duplicate", name, path.toString()));
186-
return;
187-
}
188-
189-
// Check whether an extensions' requested api version is compatible
190-
ApiVersion.Compatibility compatibility = GeyserApi.api().geyserApiVersion().supportsRequestedVersion(
191-
description.humanApiVersion(),
192-
description.majorApiVersion(),
193-
description.minorApiVersion()
194-
);
195-
196-
if (compatibility != ApiVersion.Compatibility.COMPATIBLE) {
197-
// Workaround for the switch to the Geyser API version instead of the Base API version in extensions
198-
if (compatibility == ApiVersion.Compatibility.HUMAN_DIFFER && description.humanApiVersion() == 1) {
199-
GeyserImpl.getInstance().getLogger().warning("The extension %s requested the Base API version %s, which is deprecated in favor of specifying the Geyser API version. Please update the extension, or contact its developer."
200-
.formatted(name, description.apiVersion()));
201-
} else {
202-
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_api_version", name, description.apiVersion()));
203-
return;
204-
}
205-
}
206-
207-
GeyserExtensionContainer container = this.loadExtension(path, description);
208-
extensions.put(id, path);
209-
loadedExtensions.put(id, container);
210-
} catch (Throwable e) {
211-
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_with_name", path.getFileName(), path.toAbsolutePath()), e);
212-
}
225+
GeyserExtensionContainer container = this.loadExtension(path, description);
226+
extensions.put(id, path);
227+
loadedExtensions.put(id, container);
228+
}, (path, e) -> {
229+
logger.error(GeyserLocale.getLocaleStringLog("geyser.extensions.load.failed_with_name", path.getFileName(), path.toAbsolutePath()), e);
213230
});
214231

232+
// Step 4: Register the extensions
215233
for (GeyserExtensionContainer container : loadedExtensions.values()) {
216234
this.extensionContainers.put(container.extension(), container);
217235
this.register(container.extension(), extensionManager);
@@ -221,6 +239,40 @@ protected void loadAllExtensions(@NonNull ExtensionManager extensionManager) {
221239
}
222240
}
223241

242+
/**
243+
* Process extension jars in a folder and call the accept or reject consumer based on the result
244+
*
245+
* @param directory the directory to process
246+
* @param accept the consumer to call when an extension is accepted
247+
* @param reject the consumer to call when an extension is rejected
248+
* @throws IOException if an I/O error occurs
249+
*/
250+
private void processExtensionsFolder(Path directory, ThrowingBiConsumer<Path, GeyserExtensionDescription> accept, BiConsumer<Path, Throwable> reject) throws IOException {
251+
List<Path> extensionPaths = Files.list(directory).toList();
252+
Pattern[] extensionFilters = this.extensionFilters();
253+
extensionPaths.forEach(path -> {
254+
if (Files.isDirectory(path)) {
255+
return;
256+
}
257+
258+
// Only look at files that meet the extension filter
259+
for (Pattern filter : extensionFilters) {
260+
if (!filter.matcher(path.getFileName().toString()).matches()) {
261+
return;
262+
}
263+
}
264+
265+
try {
266+
// Try load the description, so we know it's a valid extension
267+
GeyserExtensionDescription description = this.extensionDescription(path);
268+
269+
accept.acceptThrows(path, description);
270+
} catch (Throwable e) {
271+
reject.accept(path, e);
272+
}
273+
});
274+
}
275+
224276
@Override
225277
protected boolean isEnabled(@NonNull Extension extension) {
226278
return this.extensionContainers.get(extension).enabled;

0 commit comments

Comments
 (0)