v1.7: Bumped deps, dropped support for below 1.17, moved to Java 17

This commit is contained in:
Stijn Bannink 2025-01-27 20:15:10 +01:00
parent f921e44cdb
commit 489bf94712
Signed by: SBDeveloper
GPG key ID: B730712F2C3A9D7A
4 changed files with 340 additions and 15 deletions

16
pom.xml
View file

@ -6,14 +6,14 @@
<groupId>tech.sbdevelopment</groupId> <groupId>tech.sbdevelopment</groupId>
<artifactId>ShowControl</artifactId> <artifactId>ShowControl</artifactId>
<version>1.6.1</version> <version>1.7</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>ShowControl</name> <name>ShowControl</name>
<url>https://sbdevelopment.tech</url> <url>https://sbdevelopment.tech</url>
<description>Create shows easily using this plugin!</description> <description>Create shows easily using this plugin!</description>
<properties> <properties>
<release>11</release> <release>17</release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.lombok.delombok-target>${project.build.directory}/javadoc-delombok</maven.lombok.delombok-target> <maven.lombok.delombok-target>${project.build.directory}/javadoc-delombok</maven.lombok.delombok-target>
</properties> </properties>
@ -39,7 +39,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version> <version>3.13.0</version>
<configuration> <configuration>
<release>${release}</release> <release>${release}</release>
<annotationProcessorPaths> <annotationProcessorPaths>
@ -57,7 +57,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version> <version>3.6.0</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@ -115,7 +115,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.0</version> <version>3.11.2</version>
<configuration> <configuration>
<release>${release}</release> <release>${release}</release>
<sourcepath>${maven.lombok.delombok-target}</sourcepath> <sourcepath>${maven.lombok.delombok-target}</sourcepath>
@ -157,7 +157,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.20.2-R0.1-SNAPSHOT</version> <version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@ -168,7 +168,7 @@
<dependency> <dependency>
<groupId>com.github.cryptomorin</groupId> <groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId> <artifactId>XSeries</artifactId>
<version>9.10.0</version> <version>13.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>co.aikar</groupId> <groupId>co.aikar</groupId>
@ -179,7 +179,7 @@
<dependency> <dependency>
<groupId>com.github.SkytAsul</groupId> <groupId>com.github.SkytAsul</groupId>
<artifactId>GuardianBeam</artifactId> <artifactId>GuardianBeam</artifactId>
<version>97b0078aba</version> <version>2.4.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -50,7 +50,7 @@ public class Fireworks {
} }
private void spawn(Location loc) { private void spawn(Location loc) {
org.bukkit.entity.Firework fw = (org.bukkit.entity.Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK); org.bukkit.entity.Firework fw = (org.bukkit.entity.Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK_ROCKET);
FireworkMeta fwm = fw.getFireworkMeta(); FireworkMeta fwm = fw.getFireworkMeta();
fwm.addEffect(effectBuilder.build()); fwm.addEffect(effectBuilder.build());
fwm.setPower(power); fwm.setPower(power);

View file

@ -1,7 +1,9 @@
package tech.sbdevelopment.showcontrol.utils; package tech.sbdevelopment.showcontrol.utils;
import com.cryptomorin.xseries.SkullUtils;
import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.profiles.builder.XSkull;
import com.cryptomorin.xseries.profiles.objects.ProfileInputType;
import com.cryptomorin.xseries.profiles.objects.Profileable;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Material;
@ -10,15 +12,19 @@ import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.potion.PotionData; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionType; import org.bukkit.potion.PotionType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
import static tech.sbdevelopment.showcontrol.utils.ReflectionUtil.callDeclaredConstructor;
import static tech.sbdevelopment.showcontrol.utils.ReflectionUtil.callDeclaredMethod;
@Getter @Getter
public class ItemBuilder { public class ItemBuilder {
private final ItemStack itemStack; private final ItemStack itemStack;
@ -87,12 +93,14 @@ public class ItemBuilder {
return flag(ItemFlag.values()); return flag(ItemFlag.values());
} }
public ItemBuilder customModelData(int customModelData) { public ItemBuilder customModelData(int customModelData, Function<ItemBuilder, ItemBuilder> notSupportedFunction) {
if (XMaterial.supports(13)) { if (XMaterial.supports(14)) {
applyToMeta(meta -> { applyToMeta(meta -> {
meta.setCustomModelData(customModelData); meta.setCustomModelData(customModelData);
return meta; return meta;
}); });
} else {
return notSupportedFunction.apply(this);
} }
return this; return this;
} }
@ -140,7 +148,7 @@ public class ItemBuilder {
public ItemBuilder skullTexture(String identifier) { public ItemBuilder skullTexture(String identifier) {
applyToMeta(meta -> { applyToMeta(meta -> {
SkullUtils.applySkin(meta, identifier); meta = XSkull.of(meta).profile(Profileable.of(ProfileInputType.USERNAME, identifier)).apply();
return meta; return meta;
}); });
return this; return this;
@ -160,7 +168,15 @@ public class ItemBuilder {
throw new UnsupportedOperationException("ItemStack is not a potion! (Type: " + itemStack.getType().name() + ")"); throw new UnsupportedOperationException("ItemStack is not a potion! (Type: " + itemStack.getType().name() + ")");
applyToMeta(meta -> { applyToMeta(meta -> {
if (!(meta instanceof org.bukkit.inventory.meta.PotionMeta)) return meta; if (!(meta instanceof org.bukkit.inventory.meta.PotionMeta)) return meta;
((org.bukkit.inventory.meta.PotionMeta) meta).setBasePotionData(new PotionData(type)); PotionMeta pm = (PotionMeta) meta;
try {
pm.setBasePotionType(type);
} catch (NoSuchMethodError e) {
// Fallback for versions below 1.20.5 (using reflection)
Class<?> potionDataClass = ReflectionUtil.getClass("org.bukkit.potion.PotionData");
Object potionData = callDeclaredConstructor(potionDataClass, type);
callDeclaredMethod(pm, "setBasePotionData", potionDataClass, potionData);
}
return meta; return meta;
}); });
return this; return this;

View file

@ -0,0 +1,309 @@
package tech.sbdevelopment.showcontrol.utils;
import lombok.experimental.UtilityClass;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
@UtilityClass
public class ReflectionUtil {
private static final Map<String, Constructor<?>> constructorCache = new HashMap<>();
private static final Map<String, Method> methodCache = new HashMap<>();
private static final Map<String, Field> fieldCache = new HashMap<>();
/**
* Helper class converted to {@link List}
*
* @param <E> The storage type
*/
public static class ListParam<E> extends ArrayList<E> {
}
/**
* Helper class converted to {@link Collection}
*
* @param <E> The storage type
*/
public static class CollectionParam<E> extends ArrayList<E> {
}
private static Class<?> wrapperToPrimitive(Class<?> clazz) {
if (clazz == Boolean.class) return boolean.class;
if (clazz == Integer.class) return int.class;
if (clazz == Double.class) return double.class;
if (clazz == Float.class) return float.class;
if (clazz == Long.class) return long.class;
if (clazz == Short.class) return short.class;
if (clazz == Byte.class) return byte.class;
if (clazz == Void.class) return void.class;
if (clazz == Character.class) return char.class;
if (clazz == CollectionParam.class) return Collection.class;
if (clazz == ListParam.class) return List.class;
if (clazz == ArrayList.class) return Collection.class; //LEGACY!
if (clazz == HashMap.class) return Map.class;
return clazz;
}
private static Class<?>[] toParamTypes(Object... params) {
return Arrays.stream(params)
.map(obj -> obj != null ? wrapperToPrimitive(obj.getClass()) : null)
.toArray(Class<?>[]::new);
}
public static Class<?> getClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
return null;
}
}
public static Object callConstructorNull(Class<?> clazz, Class<?> paramClass) {
try {
String cacheKey = "ConstructorNull:" + clazz.getName() + ":" + paramClass.getName();
if (constructorCache.containsKey(cacheKey)) {
Constructor<?> cachedConstructor = constructorCache.get(cacheKey);
return cachedConstructor.newInstance(clazz.cast(null));
} else {
Constructor<?> con = clazz.getConstructor(paramClass);
con.setAccessible(true);
constructorCache.put(cacheKey, con);
return con.newInstance(clazz.cast(null));
}
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException |
InvocationTargetException ex) {
ex.printStackTrace();
return null;
}
}
public static Object callFirstConstructor(Class<?> clazz, Object... params) {
try {
String cacheKey = "FirstConstructor:" + clazz.getName();
if (constructorCache.containsKey(cacheKey)) {
Constructor<?> cachedConstructor = constructorCache.get(cacheKey);
return cachedConstructor.newInstance(params);
} else {
Constructor<?> con = clazz.getConstructors()[0];
con.setAccessible(true);
constructorCache.put(cacheKey, con);
return con.newInstance(params);
}
} catch (IllegalAccessException | InstantiationException |
InvocationTargetException ex) {
ex.printStackTrace();
return null;
}
}
public static Object callConstructor(Class<?> clazz, Object... params) {
try {
String cacheKey = "Constructor:" + clazz.getName() + ":" + Arrays.hashCode(params);
if (constructorCache.containsKey(cacheKey)) {
Constructor<?> cachedConstructor = constructorCache.get(cacheKey);
return cachedConstructor.newInstance(params);
} else {
Constructor<?> con = clazz.getConstructor(toParamTypes(params));
con.setAccessible(true);
constructorCache.put(cacheKey, con);
return con.newInstance(params);
}
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException |
InvocationTargetException ex) {
ex.printStackTrace();
return null;
}
}
public static Object callDeclaredConstructor(Class<?> clazz, Object... params) {
try {
String cacheKey = "DeclaredConstructor:" + clazz.getName() + ":" + Arrays.hashCode(params);
if (constructorCache.containsKey(cacheKey)) {
Constructor<?> cachedConstructor = constructorCache.get(cacheKey);
return cachedConstructor.newInstance(params);
} else {
Constructor<?> con = clazz.getDeclaredConstructor(toParamTypes(params));
con.setAccessible(true);
constructorCache.put(cacheKey, con);
return con.newInstance(params);
}
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException |
InvocationTargetException ex) {
ex.printStackTrace();
return null;
}
}
public static Object callMethod(Class<?> clazz, String method, Object... params) {
try {
String cacheKey = "Method:" + clazz.getName() + ":" + method + ":" + Arrays.hashCode(params);
if (methodCache.containsKey(cacheKey)) {
Method cachedMethod = methodCache.get(cacheKey);
return cachedMethod.invoke(null, params);
} else {
Method m = clazz.getMethod(method, toParamTypes(params));
m.setAccessible(true);
methodCache.put(cacheKey, m);
return m.invoke(null, params);
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
return null;
}
}
public static Object callMethod(Object obj, String method, Object... params) {
try {
String cacheKey = "Method:" + obj.getClass().getName() + ":" + method + ":" + Arrays.hashCode(params);
if (methodCache.containsKey(cacheKey)) {
Method cachedMethod = methodCache.get(cacheKey);
return cachedMethod.invoke(obj, params);
} else {
Method m = obj.getClass().getMethod(method, toParamTypes(params));
m.setAccessible(true);
methodCache.put(cacheKey, m);
return m.invoke(obj, params);
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
return null;
}
}
public static Object callDeclaredMethod(Object obj, String method, Object... params) {
try {
String cacheKey = "DeclaredMethod:" + obj.getClass().getName() + ":" + method + ":" + Arrays.hashCode(params);
if (methodCache.containsKey(cacheKey)) {
Method cachedMethod = methodCache.get(cacheKey);
return cachedMethod.invoke(obj, params);
} else {
Method m = obj.getClass().getDeclaredMethod(method, toParamTypes(params));
m.setAccessible(true);
methodCache.put(cacheKey, m);
return m.invoke(obj, params);
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
return null;
}
}
public static boolean hasField(Object packet, String field) {
try {
String cacheKey = "HasField:" + packet.getClass().getName() + ":" + field;
if (!fieldCache.containsKey(cacheKey)) {
packet.getClass().getDeclaredField(field);
fieldCache.put(cacheKey, null);
}
return true;
} catch (NoSuchFieldException ex) {
return false;
}
}
public static Object getField(Object object, String field) {
try {
String cacheKey = "Field:" + object.getClass().getName() + ":" + field;
if (fieldCache.containsKey(cacheKey)) {
Field cachedField = fieldCache.get(cacheKey);
return cachedField.get(object);
} else {
Field f = object.getClass().getField(field);
f.setAccessible(true);
fieldCache.put(cacheKey, f);
return f.get(object);
}
} catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace();
return null;
}
}
public static Object getDeclaredField(Class<?> clazz, String field) {
try {
String cacheKey = "DeclaredField:" + clazz.getName() + ":" + field;
if (fieldCache.containsKey(cacheKey)) {
Field cachedField = fieldCache.get(cacheKey);
return cachedField.get(null);
} else {
Field f = clazz.getDeclaredField(field);
f.setAccessible(true);
fieldCache.put(cacheKey, f);
return f.get(null);
}
} catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace();
return null;
}
}
public static Object getDeclaredField(Object object, String field) {
try {
String cacheKey = "DeclaredField:" + object.getClass().getName() + ":" + field;
if (fieldCache.containsKey(cacheKey)) {
Field cachedField = fieldCache.get(cacheKey);
return cachedField.get(object);
} else {
Field f = object.getClass().getDeclaredField(field);
f.setAccessible(true);
fieldCache.put(cacheKey, f);
return f.get(object);
}
} catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace();
return null;
}
}
public static Object getDeclaredField(Class<?> clazz, Object object, String field) {
try {
String cacheKey = "DeclaredField:" + clazz.getName() + ":" + field;
if (fieldCache.containsKey(cacheKey)) {
Field cachedField = fieldCache.get(cacheKey);
return cachedField.get(object);
} else {
Field f = clazz.getDeclaredField(field);
f.setAccessible(true);
fieldCache.put(cacheKey, f);
return f.get(object);
}
} catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace();
return null;
}
}
public static void setDeclaredField(Object object, String field, Object value) {
try {
String cacheKey = "DeclaredField:" + object.getClass().getName() + ":" + field;
if (fieldCache.containsKey(cacheKey)) {
Field cachedField = fieldCache.get(cacheKey);
cachedField.set(object, value);
} else {
Field f = object.getClass().getDeclaredField(field);
f.setAccessible(true);
fieldCache.put(cacheKey, f);
f.set(object, value);
}
} catch (NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace();
}
}
}