I want to override one class in the Bukkit api with my plugin. I know it's NOT IMPOSSIBLE, because PEX developers does it.

Here is the link: https://github.com/PEXPlugins/PermissionsEx/blob/master/src/main/java/ru/tehkode/permissions/bukkit/regexperms/PermissiblePEX.java

I'd like to know, what is the simplest working way to do it.

有帮助吗?

解决方案

I found the way in the PEX and I simplified it:

First I need to declare a Field variable:

public static Field mezo;

After that, at OnEnable method I need to get CraftHumanEntitys perm field:

try{
mezo=Class.forName("org.bukkit.craftbukkit.v1_7_R1.entity.CraftHumanEntity").getDeclaredField("perm");
}
catch(Throwable h){
}

And at every player join I need to register the player:

Jogkezelheto uj=new Jogkezelheto(j);
try{
    mezo.setAccessible(true);
    mezo.set(j,uj);
}
catch (Throwable h){
}

Jogkezelheto is my class, which extends the PermissibleBase, such as the PermissiblePex is PEX. And it's working!

其他提示

I'm assuming that when you say "override" you mean "extend". If that's correct, Java has a nice fancy keyword for that:

public class MyBukkitClass extends BukkitClass {
...
}

This gives you access to all the methods/variables that were in that original BukkitClass that you are extending.

If you look in that class you posted in github, the extends keyword is used on line 52. An example of constructing a class that you are extending is shown on line 77.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top