Skip to content

Commit

Permalink
Compatiblity patch for abandoned addons. (#7356)
Browse files Browse the repository at this point in the history
* Add back converter class stub.

* Add caller error.

* Alter message a bit.

* Update src/main/java/ch/njol/skript/util/Utils.java

* Remove method.

---------
  • Loading branch information
Moderocky authored Jan 14, 2025
1 parent 1fd0c93 commit 0a441ce
Show file tree
Hide file tree
Showing 3 changed files with 272 additions and 35 deletions.
53 changes: 53 additions & 0 deletions src/main/java/ch/njol/skript/classes/Converter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ch.njol.skript.classes;

import ch.njol.skript.command.Commands;
import ch.njol.skript.util.Utils;
import org.jetbrains.annotations.Nullable;

/**
* <h2>WARNING! This class has been removed in this update.</h2>
* This class stub has been left behind to prevent loading errors from outdated addons,
* but its functionality has been largely removed.
*
* @deprecated Use {@link org.skriptlang.skript.lang.converter.Converter}
*/
@Deprecated(forRemoval = true)
public interface Converter<F, T> extends org.skriptlang.skript.lang.converter.Converter<F, T> {

// Interfaces don't have a <clinit> so we trigger the warning notice with this
int $_WARNING = Utils.loadedRemovedClassWarning(Converter.class);

@Deprecated(forRemoval = true)
int NO_LEFT_CHAINING = org.skriptlang.skript.lang.converter.Converter.NO_LEFT_CHAINING;
@Deprecated(forRemoval = true)
int NO_RIGHT_CHAINING = org.skriptlang.skript.lang.converter.Converter.NO_RIGHT_CHAINING;
@Deprecated(forRemoval = true)
int NO_CHAINING = NO_LEFT_CHAINING | NO_RIGHT_CHAINING;
@Deprecated(forRemoval = true)
int NO_COMMAND_ARGUMENTS = Commands.CONVERTER_NO_COMMAND_ARGUMENTS;

@Deprecated(forRemoval = true)
@Nullable T convert(F f);

@Deprecated(forRemoval = true)
final class ConverterUtils {

@Deprecated(forRemoval = true)
public static <F, T> Converter<?, T> createInstanceofConverter(Class<F> from, Converter<F, T> conv) {
throw new UnsupportedOperationException();
}

@Deprecated(forRemoval = true)
public static <F, T> Converter<F, T> createInstanceofConverter(Converter<F, ?> conv, Class<T> to) {
throw new UnsupportedOperationException();
}

@Deprecated(forRemoval = true)
public static <F, T> Converter<?, T>
createDoubleInstanceofConverter(Class<F> from, Converter<F, ?> conv, Class<T> to) {
throw new UnsupportedOperationException();
}

}

}
121 changes: 121 additions & 0 deletions src/main/java/ch/njol/skript/registrations/Converters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package ch.njol.skript.registrations;

import ch.njol.skript.classes.Converter;
import ch.njol.skript.util.Utils;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.converter.ConverterInfo;

import java.util.List;
import java.util.stream.Collectors;

/**
* <h2>WARNING! This class has been removed in this update.</h2>
* This class stub has been left behind to prevent loading errors from outdated addons,
* but its functionality has been largely removed.
*
* @deprecated Use {@link org.skriptlang.skript.lang.converter.Converters}
*/
@Deprecated(forRemoval = true)
@SuppressWarnings("removal")
public abstract class Converters {

static {
Utils.loadedRemovedClassWarning(Converters.class);
}

@SuppressWarnings("unchecked")
@Deprecated(forRemoval = true)
public static <F, T> List<ConverterInfo<?, ?>> getConverters() {
return org.skriptlang.skript.lang.converter.Converters.getConverterInfos().stream()
.map(unknownInfo -> {
org.skriptlang.skript.lang.converter.ConverterInfo<F, T> info =
(org.skriptlang.skript.lang.converter.ConverterInfo<F, T>) unknownInfo;
return new ConverterInfo<>(info.getFrom(), info.getTo(), info.getConverter(), info.getFlags());
})
.collect(Collectors.toList());
}

@Deprecated(forRemoval = true)
public static <F, T> void registerConverter(Class<F> from, Class<T> to, Converter<F, T> converter) {
registerConverter(from, to, converter, 0);
}

@Deprecated(forRemoval = true)
public static <F, T> void registerConverter(Class<F> from, Class<T> to, Converter<F, T> converter, int options) {
org.skriptlang.skript.lang.converter.Converters.registerConverter(from, to, converter::convert, options);
}

@Deprecated(forRemoval = true)
public static <F, T> T convert(@Nullable F o, Class<T> to) {
return org.skriptlang.skript.lang.converter.Converters.convert(o, to);
}

@Deprecated(forRemoval = true)
public static <F, T> T convert(@Nullable F o, Class<? extends T>[] to) {
return org.skriptlang.skript.lang.converter.Converters.convert(o, to);
}

@Deprecated(forRemoval = true)
public static <T> T[] convertArray(@Nullable Object[] o, Class<T> to) {
T[] converted = org.skriptlang.skript.lang.converter.Converters.convert(o, to);
if (converted.length == 0) // no longer nullable with new converter classes
return null;
return converted;
}

@Deprecated(forRemoval = true)
public static <T> T[] convertArray(@Nullable Object[] o, Class<? extends T>[] to,
Class<T> superType) {
return org.skriptlang.skript.lang.converter.Converters.convert(o, to, superType);
}

@Deprecated(forRemoval = true)
public static <T> T[] convertStrictly(Object[] original, Class<T> to) throws ClassCastException {
return org.skriptlang.skript.lang.converter.Converters.convertStrictly(original, to);
}

@Deprecated(forRemoval = true)
public static <T> T convertStrictly(Object original, Class<T> to) throws ClassCastException {
return org.skriptlang.skript.lang.converter.Converters.convertStrictly(original, to);
}

@Deprecated(forRemoval = true)
public static boolean converterExists(Class<?> from, Class<?> to) {
return org.skriptlang.skript.lang.converter.Converters.converterExists(from, to);
}

@Deprecated(forRemoval = true)
public static boolean converterExists(Class<?> from, Class<?>... to) {
return org.skriptlang.skript.lang.converter.Converters.converterExists(from, to);
}

@Deprecated(forRemoval = true)
public static <F, T> Converter<? super F, ? extends T> getConverter(Class<F> from, Class<T> to) {
org.skriptlang.skript.lang.converter.Converter<F, T> converter =
org.skriptlang.skript.lang.converter.Converters.getConverter(from, to);
if (converter == null)
return null;
return (Converter<F, T>) converter::convert;
}

@Deprecated(forRemoval = true)
public static <F, T> ConverterInfo<? super F, ? extends T> getConverterInfo(Class<F> from, Class<T> to) {
org.skriptlang.skript.lang.converter.ConverterInfo<F, T> info =
org.skriptlang.skript.lang.converter.Converters.getConverterInfo(from, to);
if (info == null)
return null;
return new ConverterInfo<>(info.getFrom(), info.getTo(), info.getConverter()::convert, info.getFlags());
}

@Deprecated(forRemoval = true)
public static <F, T> T[] convertUnsafe(F[] from, Class<?> to,
Converter<? super F, ? extends T> conv) {
return org.skriptlang.skript.lang.converter.Converters.convertUnsafe(from, to, conv::convert);
}

@Deprecated(forRemoval = true)
public static <F, T> T[] convert(F[] from, Class<T> to, Converter<? super F, ? extends T> conv) {
return org.skriptlang.skript.lang.converter.Converters.convert(from, to, conv::convert);
}

}
Loading

0 comments on commit 0a441ce

Please sign in to comment.