Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-20 15:00:11 +01:00
Add UrlFallbackOption
Dieser Commit ist enthalten in:
Ursprung
e1f86a8290
Commit
3160537573
@ -83,7 +83,7 @@ public interface ResourcePack {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link Builder} for a resource pack.
|
* Returns a {@link Builder} for a resource pack.
|
||||||
* It can be used to set a content key, or a default subpack.
|
* It can be used to set a content key.
|
||||||
*
|
*
|
||||||
* @param codec the {@link PackCodec} to base the builder on
|
* @param codec the {@link PackCodec} to base the builder on
|
||||||
* @return a {@link Builder} to build a resource pack.
|
* @return a {@link Builder} to build a resource pack.
|
||||||
@ -93,8 +93,7 @@ public interface ResourcePack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A builder for a resource pack. It allows providing a content key manually, or
|
* A builder for a resource pack. It allows providing a content key manually.
|
||||||
* setting a default subpack.
|
|
||||||
*/
|
*/
|
||||||
interface Builder {
|
interface Builder {
|
||||||
|
|
||||||
|
@ -54,7 +54,8 @@ public interface ResourcePackOption<T> {
|
|||||||
|
|
||||||
enum Type {
|
enum Type {
|
||||||
SUBPACK,
|
SUBPACK,
|
||||||
PRIORITY
|
PRIORITY,
|
||||||
|
FALLBACK
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* 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.api.pack.option;
|
||||||
|
|
||||||
|
import org.geysermc.geyser.api.GeyserApi;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be used for resource packs using the {@link org.geysermc.geyser.api.pack.UrlPackCodec}.
|
||||||
|
* When a Bedrock client is unable to download a resource pack from a URL, Geyser will, by default,
|
||||||
|
* serve the resource pack over raknet (as packs are served with the {@link org.geysermc.geyser.api.pack.PathPackCodec}).
|
||||||
|
* This option can be used to disable that behavior, and disconnect the player instead.
|
||||||
|
*/
|
||||||
|
public interface UrlFallbackOption extends ResourcePackOption<Boolean> {
|
||||||
|
|
||||||
|
UrlFallbackOption TRUE = fallback(true);
|
||||||
|
UrlFallbackOption FALSE = fallback(false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to fall back to serving packs over the raknet connection
|
||||||
|
* @param fallback whether to fall back
|
||||||
|
* @return a UrlFallbackOption with the specified behavior
|
||||||
|
*/
|
||||||
|
static UrlFallbackOption fallback(boolean fallback) {
|
||||||
|
return GeyserApi.api().provider(UrlFallbackOption.class, fallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -188,22 +188,20 @@ public class SessionLoadResourcePacksEventImpl extends SessionLoadResourcePacksE
|
|||||||
|
|
||||||
// Helper methods to get the options for a ResourcePack
|
// Helper methods to get the options for a ResourcePack
|
||||||
|
|
||||||
private double priority(GeyserResourcePack pack) {
|
public <T> T getValue(UUID uuid, ResourcePackOption.Type type, T defaultValue) {
|
||||||
OptionHolder holder = options.get(pack.uuid());
|
OptionHolder holder = options.get(uuid);
|
||||||
OptionHolder defaultHolder = packs.get(pack.uuid()).optionHolder();
|
OptionHolder defaultHolder = packs.get(uuid).optionHolder();
|
||||||
Objects.requireNonNull(defaultHolder); // should never be null
|
Objects.requireNonNull(defaultHolder); // should never be null
|
||||||
|
|
||||||
return OptionHolder.getWithFallbacks(ResourcePackOption.Type.PRIORITY,
|
return OptionHolder.getWithFallbacks(type, holder, defaultHolder, defaultValue);
|
||||||
holder, defaultHolder, 5);
|
}
|
||||||
|
|
||||||
|
private double priority(GeyserResourcePack pack) {
|
||||||
|
return getValue(pack.uuid(), ResourcePackOption.Type.PRIORITY, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String subpackName(GeyserResourcePack pack) {
|
private String subpackName(GeyserResourcePack pack) {
|
||||||
OptionHolder holder = options.get(pack.uuid());
|
return getValue(pack.uuid(), ResourcePackOption.Type.SUBPACK, "");
|
||||||
OptionHolder defaultHolder = packs.get(pack.uuid()).optionHolder();
|
|
||||||
Objects.requireNonNull(defaultHolder); // should never be null
|
|
||||||
|
|
||||||
return OptionHolder.getWithFallbacks(ResourcePackOption.Type.SUBPACK,
|
|
||||||
holder, defaultHolder, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper method to validate a pack
|
// Helper method to validate a pack
|
||||||
|
@ -60,6 +60,7 @@ import org.geysermc.geyser.api.pack.PackCodec;
|
|||||||
import org.geysermc.geyser.api.pack.ResourcePack;
|
import org.geysermc.geyser.api.pack.ResourcePack;
|
||||||
import org.geysermc.geyser.api.pack.ResourcePackManifest;
|
import org.geysermc.geyser.api.pack.ResourcePackManifest;
|
||||||
import org.geysermc.geyser.api.pack.UrlPackCodec;
|
import org.geysermc.geyser.api.pack.UrlPackCodec;
|
||||||
|
import org.geysermc.geyser.api.pack.option.ResourcePackOption;
|
||||||
import org.geysermc.geyser.event.type.SessionLoadResourcePacksEventImpl;
|
import org.geysermc.geyser.event.type.SessionLoadResourcePacksEventImpl;
|
||||||
import org.geysermc.geyser.pack.GeyserResourcePack;
|
import org.geysermc.geyser.pack.GeyserResourcePack;
|
||||||
import org.geysermc.geyser.pack.ResourcePackHolder;
|
import org.geysermc.geyser.pack.ResourcePackHolder;
|
||||||
@ -314,6 +315,11 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
|
|||||||
// If a remote pack ends up here, that usually implies that a client was not able to download the pack
|
// If a remote pack ends up here, that usually implies that a client was not able to download the pack
|
||||||
if (codec instanceof UrlPackCodec urlPackCodec) {
|
if (codec instanceof UrlPackCodec urlPackCodec) {
|
||||||
ResourcePackLoader.testRemotePack(session, urlPackCodec, packet.getPackId(), packet.getPackVersion());
|
ResourcePackLoader.testRemotePack(session, urlPackCodec, packet.getPackId(), packet.getPackVersion());
|
||||||
|
|
||||||
|
if (!resourcePackLoadEvent.getValue(pack.uuid(), ResourcePackOption.Type.FALLBACK, true)) {
|
||||||
|
session.disconnect("Unable to provide downloaded resource pack. Contact an administrator!");
|
||||||
|
return PacketSignal.HANDLED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setChunkIndex(packet.getChunkIndex());
|
data.setChunkIndex(packet.getChunkIndex());
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* 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.pack.option;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.geysermc.geyser.api.pack.ResourcePack;
|
||||||
|
import org.geysermc.geyser.api.pack.UrlPackCodec;
|
||||||
|
import org.geysermc.geyser.api.pack.option.UrlFallbackOption;
|
||||||
|
|
||||||
|
public record GeyserUrlFallbackOption(Boolean enabled) implements UrlFallbackOption {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Type type() {
|
||||||
|
return Type.FALLBACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Boolean value() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate(@NonNull ResourcePack pack) {
|
||||||
|
if (!(pack.codec() instanceof UrlPackCodec)) {
|
||||||
|
throw new IllegalArgumentException("UrlFallbackOption cannot be set on resource packs that do not use" +
|
||||||
|
"the url pack codec!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -116,10 +116,11 @@ public class ResourcePackLoader implements RegistryLoader<Path, Map<UUID, Resour
|
|||||||
resourcePacks.add(skullResourcePack);
|
resourcePacks.add(skullResourcePack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
//noinspection removal
|
||||||
GeyserLoadResourcePacksEvent event = new GeyserLoadResourcePacksEvent(resourcePacks);
|
GeyserLoadResourcePacksEvent event = new GeyserLoadResourcePacksEvent(resourcePacks);
|
||||||
GeyserImpl.getInstance().eventBus().fire(event);
|
GeyserImpl.getInstance().eventBus().fire(event);
|
||||||
|
|
||||||
|
//noinspection removal
|
||||||
for (Path path : event.resourcePacks()) {
|
for (Path path : event.resourcePacks()) {
|
||||||
try {
|
try {
|
||||||
GeyserResourcePack pack = readPack(path).build();
|
GeyserResourcePack pack = readPack(path).build();
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren