mirror of
https://github.com/plexusorg/ItemizerX.git
synced 2025-07-02 08:06:42 +00:00
Commit changes for Telesphoreo to finish
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
|
||||
compileOnly("org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT")
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package dev.plex.itemizerx.nms;
|
||||
|
||||
import dev.plex.itemizerx.nms.attribute.NMSAttributeManager;
|
||||
import dev.plex.itemizerx.nms.factory.Factory;
|
||||
import dev.plex.itemizerx.nms.platform.NMSPlatform;
|
||||
import dev.plex.itemizerx.nms.player.NMSPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class AbstractNMSPlatform implements NMSPlatform {
|
||||
protected final Factory<NMSPlayer, Player> playerFactory;
|
||||
protected final NMSAttributeManager attributeManager;
|
||||
protected AbstractNMSPlatform(final Factory<NMSPlayer, Player> playerFactory, final NMSAttributeManager attributeManager) {
|
||||
this.playerFactory = playerFactory;
|
||||
this.attributeManager = attributeManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Factory<NMSPlayer, Player> getPlayerFactory() {
|
||||
return this.playerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NMSAttributeManager getAttributeManager() {
|
||||
return this.attributeManager;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package dev.plex.itemizerx.nms.attribute;
|
||||
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public interface NMSAttributeManager {
|
||||
NBTTagList getAttributeList(final ItemStack itemStack);
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package dev.plex.itemizerx.nms.factory;
|
||||
|
||||
public interface Factory<T, U> {
|
||||
T get(final U from);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package dev.plex.itemizerx.nms.factory;
|
||||
|
||||
import dev.plex.itemizerx.nms.player.NMSPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface NMSPlayerFactory extends Factory<NMSPlayer, Player> {
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package dev.plex.itemizerx.nms.platform;
|
||||
|
||||
import dev.plex.itemizerx.nms.attribute.NMSAttributeManager;
|
||||
import dev.plex.itemizerx.nms.player.NMSPlayer;
|
||||
import dev.plex.itemizerx.nms.factory.Factory;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface NMSPlatform {
|
||||
Material getLingeringPotionMaterial();
|
||||
Material getSplashPotionMaterial();
|
||||
// In-case md5 decides to change the position of air in the Material enum
|
||||
default Material getAirMaterial() {
|
||||
return Material.AIR;
|
||||
}
|
||||
void register();
|
||||
Factory<NMSPlayer, Player> getPlayerFactory();
|
||||
NMSAttributeManager getAttributeManager();
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package dev.plex.itemizerx.nms.player;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class AbstractNMSPlayer implements NMSPlayer {
|
||||
protected final Player player;
|
||||
|
||||
protected AbstractNMSPlayer(final Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package dev.plex.itemizerx.nms.player;
|
||||
|
||||
public interface NMSPlayer {
|
||||
void sendMessage(final String message);
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package dev.plex.itemizerx.nms.registry;
|
||||
|
||||
import com.google.common.reflect.ClassPath;
|
||||
import dev.plex.itemizerx.nms.platform.NMSPlatform;
|
||||
import dev.plex.itemizerx.nms.registry.exception.PlatformLoadException;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public final class PlatformRegistry {
|
||||
private static final Map<String, NMSPlatform> PLATFORM_MAP = new Object2ObjectArrayMap<>();
|
||||
|
||||
public static void init() throws PlatformLoadException {
|
||||
final ClassPath classPath;
|
||||
|
||||
try {
|
||||
classPath = ClassPath.from(PlatformRegistry.class.getClassLoader());
|
||||
} catch (IOException e) {
|
||||
throw new PlatformLoadException("Failed to get class path of platform registry", e);
|
||||
}
|
||||
|
||||
final Set<ClassPath.ClassInfo> classInfoSet = classPath.getTopLevelClasses("dev.plex.itemizerx.nms.factory.impl");
|
||||
final Class<NMSPlatform> nmsPlatformClass = NMSPlatform.class;
|
||||
|
||||
for (final ClassPath.ClassInfo classInfo : classInfoSet) {
|
||||
final Class<?> loadedClass = classInfo.load();
|
||||
|
||||
if (!nmsPlatformClass.isAssignableFrom(loadedClass)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final Class<? extends NMSPlatform> platformImplementation = loadedClass.asSubclass(nmsPlatformClass);
|
||||
|
||||
try {
|
||||
platformImplementation.getDeclaredConstructor().newInstance().register();
|
||||
} catch (InvocationTargetException | InstantiationException | IllegalAccessException |
|
||||
NoSuchMethodException e) {
|
||||
throw new PlatformLoadException("Failed to construct NMS platform", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerPlatform(final String minecraftVersion, final NMSPlatform nmsPlatform) {
|
||||
PLATFORM_MAP.put(minecraftVersion, nmsPlatform);
|
||||
}
|
||||
|
||||
public static Optional<NMSPlatform> getPlatform(final String minecraftVersion) {
|
||||
return Optional.ofNullable(PLATFORM_MAP.get(minecraftVersion));
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package dev.plex.itemizerx.nms.registry.exception;
|
||||
|
||||
public class PlatformLoadException extends Exception {
|
||||
public PlatformLoadException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public PlatformLoadException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public PlatformLoadException(final Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user