Make MinecraftComponent immutable

This commit is contained in:
Vankka 2024-07-26 23:39:55 +03:00
parent 6f8b5bd023
commit 8077555bd7
No known key found for this signature in database
GPG Key ID: 62E48025ED4E7EBB
2 changed files with 41 additions and 2 deletions

View File

@ -28,8 +28,9 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* A helper class to make {@link MinecraftComponent}s using Adventure.
* @param <Component> the Adventure Component type, relocated or unrelocated
* A persistent Adventure adapter for {@link MinecraftComponent}s, this is more efficient than using {@link MinecraftComponent#asAdventure(Class)}.
* @see MinecraftComponent#asAdventure(MinecraftComponentAdapter)
* @param <Component> the Adventure Component type, unrelocated or relocated
*/
public interface MinecraftComponentAdapter<Component> {

View File

@ -0,0 +1,38 @@
/*
* This file is part of the DiscordSRV API, licensed under the MIT License
* Copyright (c) 2016-2024 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* 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.
*/
package com.discordsrv.api.component;
class MinecraftComponentAdapterUnrelocated {
public static final MinecraftComponentAdapter<Object> INSTANCE = make();
private static MinecraftComponentAdapter<Object> make() {
try {
return MinecraftComponentAdapter.create(
Class.forName("net.ky".concat("ori.adventure.text.serializer.gson.GsonComponentSerializer"))
);
} catch (ClassNotFoundException ignored) {}
return null;
}
}