Skip to content

Gain access to unavailable members using dynamic proxy classes

License

Notifications You must be signed in to change notification settings

mcparkournet/impass

Repository files navigation

build Download

Impass

Impass allows you to access unavailable members using dynamic proxy classes. It is used mainly to access implementation members, which are not exposed in the API, such as some CraftBukkit or NMS methods.

Usage

Add dependency to project:

repositories {
	jcenter()
}

dependencies {
	implementation("net.mcparkour:impass-bukkit:1.0.8")
}

Create accessor interface:

import net.mcparkour.impass.annotation.method.Method;
import net.mcparkour.impass.annotation.type.CraftBukkitType;
import net.mcparkour.impass.instance.InstanceAccessor;

@CraftBukkitType("CraftPlayer") //Refers to org.bukkit.craftbukkit.<version>.CraftPlayer
public interface CraftPlayerAccessor extends InstanceAccessor {

	@Method("refreshPlayer")
	void refreshPlayer();
}

Create accessor factory:

org.bukkit.Server server = ...
AccessorFactory accessorFactory = new BukkitAccessorFactory(server);

Create instance of accessor and invoke defined there method:

AccessorFactory accessorFactory = ...

org.bukkit.entity.Player player = ...
CraftPlayerAccessor accessor = accessorFactory.createInstanceAccessor(CraftPlayerAccessor.class, player);

accessor.refreshPlayer(); //Invokes CraftPlayer#refreshPlayer()