Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/GeyserMC/Geyser
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jul 21, 2024
2 parents 7d5c4a3 + 96f0098 commit ddce101
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 111 deletions.
45 changes: 32 additions & 13 deletions core/src/main/java/org/geysermc/geyser/GeyserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
import org.geysermc.geyser.api.command.CommandSource;
import org.geysermc.geyser.api.event.EventBus;
import org.geysermc.geyser.api.event.EventRegistrar;
import org.geysermc.geyser.api.event.lifecycle.*;
import org.geysermc.geyser.api.event.lifecycle.GeyserPostInitializeEvent;
import org.geysermc.geyser.api.event.lifecycle.GeyserPostReloadEvent;
import org.geysermc.geyser.api.event.lifecycle.GeyserPreInitializeEvent;
import org.geysermc.geyser.api.event.lifecycle.GeyserPreReloadEvent;
import org.geysermc.geyser.api.event.lifecycle.GeyserShutdownEvent;
import org.geysermc.geyser.api.network.AuthType;
import org.geysermc.geyser.api.network.BedrockListener;
import org.geysermc.geyser.api.network.RemoteServer;
Expand Down Expand Up @@ -85,7 +89,13 @@
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.text.MinecraftLocale;
import org.geysermc.geyser.translator.text.MessageTranslator;
import org.geysermc.geyser.util.*;
import org.geysermc.geyser.util.AssetUtils;
import org.geysermc.geyser.util.CooldownUtils;
import org.geysermc.geyser.util.DimensionUtils;
import org.geysermc.geyser.util.Metrics;
import org.geysermc.geyser.util.NewsHandler;
import org.geysermc.geyser.util.VersionCheckUtils;
import org.geysermc.geyser.util.WebUtils;
import org.geysermc.mcprotocollib.network.tcp.TcpSession;

import java.io.File;
Expand All @@ -97,11 +107,19 @@
import java.nio.file.Path;
import java.security.Key;
import java.text.DecimalFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -645,16 +663,11 @@ public void disable() {
bootstrap.getGeyserLogger().info(GeyserLocale.getLocaleStringLog("geyser.core.shutdown.kick.done"));
}

scheduledThread.shutdown();
geyserServer.shutdown();
if (skinUploader != null) {
skinUploader.close();
}
newsHandler.shutdown();

if (this.erosionUnixListener != null) {
this.erosionUnixListener.close();
}
runIfNonNull(scheduledThread, ScheduledExecutorService::shutdown);
runIfNonNull(geyserServer, GeyserServer::shutdown);
runIfNonNull(skinUploader, FloodgateSkinUploader::close);
runIfNonNull(newsHandler, NewsHandler::shutdown);
runIfNonNull(erosionUnixListener, UnixSocketClientListener::close);

Registries.RESOURCE_PACKS.get().clear();

Expand Down Expand Up @@ -833,6 +846,12 @@ public void saveRefreshToken(@NonNull String bedrockName, @NonNull String refres
}
}

private <T> void runIfNonNull(T nullable, Consumer<T> consumer) {
if (nullable != null) {
consumer.accept(nullable);
}
}

private void scheduleRefreshTokensWrite() {
scheduledThread.execute(() -> {
// Ensure all writes are handled on the same thread
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2024 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.item.type;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.item.BedrockItemBuilder;
import org.geysermc.mcprotocollib.protocol.data.game.item.component.DataComponents;

public interface BedrockRequiresTagItem {

void addRequiredNbt(GeyserSession session, @Nullable DataComponents components, BedrockItemBuilder builder);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import it.unimi.dsi.fastutil.ints.IntArrays;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.nbt.NbtList;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
import org.cloudburstmc.nbt.NbtType;
Expand All @@ -41,7 +43,7 @@
import java.util.ArrayList;
import java.util.List;

public class FireworkRocketItem extends Item {
public class FireworkRocketItem extends Item implements BedrockRequiresTagItem {
public FireworkRocketItem(String javaIdentifier, Builder builder) {
super(javaIdentifier, builder);
}
Expand All @@ -58,14 +60,16 @@ public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNul
fireworksNbt.putByte("Flight", (byte) fireworks.getFlightDuration());

List<Fireworks.FireworkExplosion> explosions = fireworks.getExplosions();
if (explosions.isEmpty()) {
return;
}
List<NbtMap> explosionNbt = new ArrayList<>();
for (Fireworks.FireworkExplosion explosion : explosions) {
explosionNbt.add(translateExplosionToBedrock(explosion));
if (!explosions.isEmpty()) {
List<NbtMap> explosionNbt = new ArrayList<>();
for (Fireworks.FireworkExplosion explosion : explosions) {
explosionNbt.add(translateExplosionToBedrock(explosion));
}
fireworksNbt.putList("Explosions", NbtType.COMPOUND, explosionNbt);
} else {
// This is the default firework
fireworksNbt.put("Explosions", NbtList.EMPTY);
}
fireworksNbt.putList("Explosions", NbtType.COMPOUND, explosionNbt);
builder.putCompound("Fireworks", fireworksNbt.build());
}

Expand Down Expand Up @@ -138,4 +142,20 @@ static Fireworks.FireworkExplosion translateExplosionToJava(NbtMap explosion) {
return null;
}
}

@Override
public void addRequiredNbt(GeyserSession session, @Nullable DataComponents components, BedrockItemBuilder builder) {
if (components != null) {
Fireworks fireworks = components.get(DataComponentType.FIREWORKS);
if (fireworks != null) {
// Already translated
return;
}
}

NbtMapBuilder fireworksNbt = NbtMap.builder();
fireworksNbt.putByte("Flight", (byte) 1);
fireworksNbt.put("Explosions", NbtList.EMPTY);
builder.putCompound("Fireworks", fireworksNbt.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.item.components.Rarity;
import org.geysermc.geyser.item.type.Item;
import org.geysermc.geyser.item.type.BedrockRequiresTagItem;
import org.geysermc.geyser.level.block.type.Block;
import org.geysermc.geyser.registry.BlockRegistries;
import org.geysermc.geyser.registry.Registries;
Expand Down Expand Up @@ -148,6 +149,12 @@ public static ItemData translateToBedrock(GeyserSession session, ItemStack stack
if (components.get(DataComponentType.HIDE_TOOLTIP) != null) hideTooltips = true;
}

// Fixes fireworks crafting recipe: they always contain a tag
// TODO remove once all items have their default components
if (javaItem instanceof BedrockRequiresTagItem requiresTagItem) {
requiresTagItem.addRequiredNbt(session, components, nbtBuilder);
}

Rarity rarity = javaItem.rarity();
boolean enchantmentGlint = javaItem.glint();
if (components != null) {
Expand Down
Loading

0 comments on commit ddce101

Please sign in to comment.