refactor: Restore API in favor of deprecation

This commit is contained in:
NotMyFault 2021-12-23 11:04:04 +01:00
parent 5325f90f7b
commit 6198d98488
No known key found for this signature in database
GPG Key ID: 158F5701A6AAD00C
11 changed files with 161 additions and 16 deletions

View File

@ -51,7 +51,7 @@ public class MVdWPlaceholders {
) {
this.plugin = plugin;
this.registry = registry;
for (final Placeholder placeholder : registry.allPlaceholders()) {
for (final Placeholder placeholder : registry.getPlaceholders()) {
this.addPlaceholder(placeholder);
}
PlotSquared.get().getEventDispatcher().registerListener(this);

View File

@ -149,7 +149,6 @@ public class PlotAPI {
*
* @param message the message
* @param replacements Variable replacements
* @since 6.3.0
*/
public void sendConsoleMessage(
final @NonNull String message,
@ -163,7 +162,6 @@ public class PlotAPI {
*
* @param caption the message
* @param replacements Variable replacements
* @since 6.3.0
*/
public void sendConsoleMessage(
final @NonNull Caption caption,

View File

@ -614,7 +614,6 @@ public abstract class Command {
* @param mustBeTrue The condition to check, that must be true
* @param message The message to send
* @param args The arguments to send with the message
* @since 6.3.0
*/
public void checkTrue(boolean mustBeTrue, Caption message, Placeholder<?>... args) {
if (!mustBeTrue) {
@ -630,7 +629,6 @@ public abstract class Command {
* @param args The arguments to send with the message
* @param <T> The type of the object
* @return The object
* @since 6.3.0
*/
public <T> T check(T object, Caption message, Placeholder<?>... args) {
if (object == null) {
@ -656,7 +654,6 @@ public abstract class Command {
*
* @param message The message to send
* @param placeholders The placeholders to send with the message
* @since 6.3.0
*/
public CommandException(final @Nullable Caption message, final Placeholder<?>... placeholders) {
this.message = message;

View File

@ -40,7 +40,6 @@ public interface CommandCaller {
*
* @param caption Caption to send
* @param replacements Variable replacements
* @since 6.3.0
*/
void sendMessage(@NonNull Caption caption, @NonNull Placeholder<?>... replacements);

View File

@ -36,6 +36,16 @@ public class CaptionHolder {
this.caption = caption;
}
/**
* @return a {@link Caption} from a {@link StaticCaption}
*
* @deprecated use {@link #caption()} instead
*/
@Deprecated(forRemoval = true, since = "6.3.0")
public Caption get() {
return this.caption;
}
/**
* @return a {@link Caption} from a {@link StaticCaption}
* @since 6.3.0
@ -44,6 +54,15 @@ public class CaptionHolder {
return this.caption;
}
/**
* @return an array of {@link net.kyori.adventure.text.minimessage.placeholder.Placeholder}s
* @deprecated use {@link #placeholders()} instead
*/
@Deprecated(forRemoval = true, since = "6.3.0")
public Placeholder<?>[] getTemplates() {
return this.placeholders;
}
/**
* @return an array of {@link net.kyori.adventure.text.minimessage.placeholder.Placeholder}s
* @since 6.3.0
@ -52,6 +71,16 @@ public class CaptionHolder {
return this.placeholders;
}
/**
* @param placeholders placeholders
*
* @deprecated use {@link #parsePlaceholders(Placeholder...)} instead
*/
@Deprecated(forRemoval = true, since = "6.3.0")
public void setTemplates(Placeholder<?>... placeholders) {
this.placeholders = placeholders;
}
/**
* @param placeholders placeholders
* @since 6.3.0

View File

@ -0,0 +1,129 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2021 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.configuration.caption;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.util.PlayerManager;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
import net.kyori.adventure.text.minimessage.placeholder.PlaceholderResolver;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.UUID;
/**
* Utility class that generates {@link net.kyori.adventure.text.minimessage.placeholder.Placeholder templates}
* @deprecated Use {@link Placeholders} instead
*/
@Deprecated(forRemoval = true, since = "6.3.0")
public final class Templates {
private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build();
private Templates() {
throw new UnsupportedOperationException(
"This is a utility class and cannot be instantiated");
}
/**
* Create a {@link net.kyori.adventure.text.minimessage.placeholder.Placeholder} from a PlotSquared {@link Caption}
*
* @param localeHolder Locale holder
* @param key Template key
* @param caption Caption object
* @param replacements Replacements
* @return Generated template
*
* @deprecated Use {@link Placeholders#miniMessage(LocaleHolder, String, Caption, Placeholder[])} instead
*/
@Deprecated(forRemoval = true, since = "6.3.0")
public static @NonNull Placeholder<?> of(
final @NonNull LocaleHolder localeHolder,
final @NonNull String key, final @NonNull Caption caption,
final @NonNull Placeholder<?>... replacements
) {
return net.kyori.adventure.text.minimessage.placeholder.Placeholder.component(key, MINI_MESSAGE.deserialize(caption.getComponent(localeHolder),
PlaceholderResolver.placeholders(replacements)));
}
/**
* Create a {@link net.kyori.adventure.text.minimessage.placeholder.Placeholder} from a username (using UUID mappings)
*
* @param key Template key
* @param uuid Player UUID
* @return Generated template
*
* @deprecated Use {@link Placeholders#miniMessage(String, UUID)} instead
*/
@Deprecated(forRemoval = true, since = "6.3.0")
public static @NonNull Placeholder<?> of(final @NonNull String key, final @NonNull UUID uuid) {
final String username = PlayerManager.getName(uuid);
return Placeholder.miniMessage(key, username);
}
/**
* Create a {@link Placeholder} from a string
*
* @param key Template key
* @param value Template value
* @return Generated template
*
* @deprecated Use {@link Placeholders#miniMessage(String, String)} instead
*/
@Deprecated(forRemoval = true, since = "6.3.0")
public static @NonNull Placeholder<?> of(final @NonNull String key, final @NonNull String value) {
return Placeholder.miniMessage(key, value);
}
/**
* Create a {@link Placeholder} from a plot area
*
* @param key Template Key
* @param area Plot area
* @return Generated template
*
* @deprecated Use {@link Placeholders#miniMessage(String, PlotArea)} instead
*/
@Deprecated(forRemoval = true, since = "6.3.0")
public static @NonNull Placeholder<?> of(final @NonNull String key, final @NonNull PlotArea area) {
return Placeholder.miniMessage(key, area.toString());
}
/**
* Create a {@link Placeholder} from a number
*
* @param key Template key
* @param number Number
* @return Generated template
*
* @deprecated Use {@link Placeholders#miniMessage(String, Number)} instead
*/
@Deprecated(forRemoval = true, since = "6.3.0")
public static @NonNull Placeholder<?> of(final @NonNull String key, final @NonNull Number number) {
return Placeholder.miniMessage(key, number.toString());
}
}

View File

@ -836,7 +836,6 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer,
* @param title Title text
* @param subtitle Subtitle text
* @param replacements Variable replacements
* @since 6.3.0
*/
public void sendTitle(
final @NonNull Caption title, final @NonNull Caption subtitle,
@ -861,7 +860,6 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer,
* @param stay The title stays for (in ticks)
* @param fadeOut Fade out time (in ticks)
* @param replacements Variable replacements
* @since 6.3.0
*/
public void sendTitle(
final @NonNull Caption title, final @NonNull Caption subtitle,
@ -887,7 +885,6 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer,
*
* @param caption Caption
* @param replacements Variable replacements
* @since 6.3.0
*/
public void sendActionBar(
final @NonNull Caption caption,

View File

@ -375,7 +375,6 @@ public final class PlotModificationManager {
* Sets the sign for a plot to a specific name
*
* @param name name
* @since 6.3.0
*/
public void setSign(final @NonNull String name) {
if (!this.plot.isLoaded()) {

View File

@ -43,7 +43,6 @@ public class FlagParseException extends Exception {
* @param value Value that failed ot parse
* @param errorMessage An error message explaining the failure
* @param args Arguments used to format the error message
* @since 6.3.0
*/
public FlagParseException(
final PlotFlag<?, ?> flag, final String value,

View File

@ -142,7 +142,6 @@ public abstract class WorldUtil {
* @param location Block location
* @param lines Sign text
* @param replacements Text replacements
* @since 6.3.0
*/
public abstract void setSign(
@NonNull Location location,

View File

@ -296,10 +296,9 @@ public final class PlaceholderRegistry {
/**
* Get all placeholders
*
* @return Unmodifiable collection of miniMessage
* @since 6.3.0
* @return Unmodifiable collection of placeholders
*/
public @NonNull Collection<Placeholder> allPlaceholders() {
public @NonNull Collection<Placeholder> getPlaceholders() {
return Collections.unmodifiableCollection(this.placeholders.values());
}