首先的首先先导入前置
首先在plugin.yml写上
softdepend: [PlaceholderAPI]
想必都是废话吧
创建一个类,继承EZPlaceholderHook类
输入代码
public class Test extends EZPlaceholderHook {
public Test(Main main) { #假设Main是我们的主类,创建构造方法
super(main, "customplaceholder"); #引用父类方法
}
@Override
public String onPlaceholderRequest(Player p, String indentifier) { #重写父类方法,该方法被请求一个变量时调用
if (p == null) return new String();
if (indentifier.equals("test")) {#注意这里要使用变量时是 %customplaceholder_test%
return p.getMaxHealth();
}
}
#即在请求test变量时返回玩家p的最大血量.
}
如何hook这个变量?
在onEnable里面写入代码:
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) { #先判断有没有papi
new Test(this).hook();
} else {
getLogger().info("未找到PlaceholderAPI.");
}
到这里就已经hook上了
怎么使用一个变量呢:
Player player = Bukkit.getPlayer("LocyDragon"); #先要有一个玩家,LocyDragon是楼主的id
String msg = PlaceholderAPI.setPlaceholders(player, "血量: %customplaceholder_test%");
Bukkit.getLogger().info(msg); #就这样就ok了
maven:
- <repositories>
- <repository>
- <id>placeholderapi</id>
- <url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
- </repository>
- </repositories>
- <dependencies>
- <dependency>
- <groupId>me.clip</groupId>
- <artifactId>placeholderapi</artifactId>
- <version>2.9.2</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
复制代码
|
|
|
|