-
-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compatiblity patch for abandoned addons. (#7356)
* 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
Showing
3 changed files
with
272 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
121
src/main/java/ch/njol/skript/registrations/Converters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
Oops, something went wrong.