本文整理汇总了Java中org.bukkit.entity.LivingEntity.setAI方法的典型用法代码示例。如果您正苦于以下问题:Java LivingEntity.setAI方法的具体用法?Java LivingEntity.setAI怎么用?Java LivingEntity.setAI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.LivingEntity
的用法示例。
在下文中一共展示了LivingEntity.setAI方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toggleAI
import org.bukkit.entity.LivingEntity; //导入方法依赖的package包/类
/**
* Toggle the entities AI until it should expire.
* Does not conflict with other AI toggles.
* @param done
*/
public void toggleAI(Function<LivingEntity, Boolean> done) {
LivingEntity le = getLivingEntity();
BukkitTask[] task = new BukkitTask[1];
le.setAI(true);
task[0] = Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
boolean isDone = done.apply(le);
le.setAI(!isDone);
if (isDone)
task[0].cancel();
}, 10L, 20L);
}
示例2: newPlayer
import org.bukkit.entity.LivingEntity; //导入方法依赖的package包/类
public boolean newPlayer(final Channel channel, String proposedUsername, String token) {
String theirName;
boolean authenticated = false;
if (validateClientAuthKey(proposedUsername, token)) {
theirName = proposedUsername;
authenticated = true;
// TODO: more features when logging in as an authenticated user: move to their last spawn?
} else {
if (!proposedUsername.equals("")) { // blank = anonymous
webSocketServerThread.sendLine(channel, "T,Failed to login as "+proposedUsername);
}
if (!allowAnonymous) {
webSocketServerThread.sendLine(channel,"T,This server requires authentication.");
return false;
}
int theirID = ++this.lastPlayerID;
theirName = "webguest" + theirID;
}
String ip = webSocketServerThread.getRemoteIPandPort(channel);
webSocketServerThread.log(Level.INFO, "New web client joined: " + theirName +
(authenticated ? " (authenticated)" : " (anonymous)") + " from " + ip);
this.channelId2name.put(channel.id(), theirName);
this.name2channel.put(theirName, channel);
webSocketServerThread.sendLine(channel, "T,Welcome to WebSandboxMC, "+theirName+"!");
if (this.entityClass != null) {
// Spawn an entity in the web user's place
Location location = webSocketServerThread.blockBridge.spawnLocation;
Entity entity = webSocketServerThread.blockBridge.world.spawn(location, (Class) this.entityClass);
if (setCustomNames) {
entity.setCustomName(theirName); // name tag
entity.setCustomNameVisible(true);
}
if (disableGravity) {
entity.setGravity(false); // allow flying
}
if (disableAI) {
if (entity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) entity;
livingEntity.setAI(false);
}
}
channelId2Entity.put(channel.id(), entity);
entityId2Username.put(entity.getEntityId(), theirName);
// Notify other web clients (except this one) of this new user
webSocketServerThread.broadcastLineExcept(channel.id(), "P," + entity.getEntityId() + "," + webSocketServerThread.playersBridge.encodeLocation(location));
webSocketServerThread.broadcastLineExcept(channel.id(), "N," + entity.getEntityId() + "," + theirName);
}
// TODO: should this go to Bukkit chat, too/instead? make configurable?
webSocketServerThread.broadcastLine("T," + theirName + " has joined.");
return true;
}