当前位置: 首页>>代码示例>>Java>>正文


Java LivingEntity.setAI方法代码示例

本文整理汇总了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);
}
 
开发者ID:Kneesnap,项目名称:Kineticraft,代码行数:17,代码来源:ActionEntity.java

示例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;
}
 
开发者ID:satoshinm,项目名称:WebSandboxMC,代码行数:59,代码来源:WebPlayerBridge.java


注:本文中的org.bukkit.entity.LivingEntity.setAI方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。