跳到主要内容

开发者 API

依赖​

把云动作的 jar 加进编译依赖(只编译、不打包),在你的 plugin.yml 里声明依赖:

plugin.yml
softdepend: [CloudMotion]

一定要有云动作才能运行的插件写 depend: [CloudMotion]。用 softdepend 时,调用前先检查 Bukkit.getPluginManager().getPlugin("CloudMotion") != null,没装云动作就不要碰下面的类。

CloudMotionAPI​

类名 com.cloudplugins.cloudmotion.api.CloudMotionAPI,全部是静态方法,都要在主线程调用。

方法说明
isReady()云动作已经启用
play(Player, String)让玩家做一个动作,玩家自己按 F5 看得到人形
play(Player, String, boolean selfVisible)同上,selfVisible 为 false 时玩家自己看不到人形
stop(Player)停止动作,淡回原版姿势;本来没有在做动作时返回 false
isPlaying(Player)是否正在做动作,架势也算
hasAnimation(String)有没有这个动作,名称不分大小写
animations()所有动作名称
selfView(Player)玩家自己看不看得到自己的动作(/cmoself 的设置,1.5.2 起)
setSelfView(Player, boolean)改这个设置,和玩家打 /cmoself 一样,存在玩家数据里。可以在菜单插件里做一个「光影模式」开关

play 返回 CompletableFuture<Boolean>,在主线程完成。true 表示开始播放;动作不存在、尚未授权、MotionStartEvent 被取消、玩家下线时是 false。

import com.cloudplugins.cloudmotion.api.CloudMotionAPI;

if (CloudMotionAPI.isReady() && CloudMotionAPI.hasAnimation("剑4")) {
CloudMotionAPI.play(player, "剑4").thenAccept(ok -> {
if (!ok) player.sendMessage("动作没有播放");
});
}

MotionStartEvent​

com.cloudplugins.cloudmotion.api.MotionStartEvent,玩家开始做一个动作之前触发,可以取消,取消就不做。左键连招的每一刀、Shift + 右键、/cmo play、API 和 MythicMobs 都会触发;架势的循环动作不会。

方法说明
getPlayer()做动作的玩家
getAnimation()动作名称
getCause()来源:LEFT_CLICK、SNEAK_RIGHT_CLICK、COMMAND、API、MYTHICMOBS
getStage()左键连招的第几刀,从 0 开始;其他来源是 -1
setCancelled(boolean)取消这次动作
import com.cloudplugins.cloudmotion.api.MotionStartEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public final class MotionListener implements Listener {

@EventHandler
public void onMotion(MotionStartEvent e) {
// 安全区里不出招
if (inSafeZone(e.getPlayer())) {
e.setCancelled(true);
return;
}
// 连招第四刀(stage 从 0 开始)
if (e.getCause() == MotionStartEvent.Cause.LEFT_CLICK && e.getStage() == 3) {
e.getPlayer().sendMessage("终结一击");
}
}
}

左键连招的一刀被取消时,这一刀的音效、效果和向前推进也都不会执行,但连招计数照样往下走,下一次按左键会接下一刀。

0:000:00