PluginPlayerListener.java 文件源码

java
阅读 20 收藏 0 点赞 0 评论 0

项目:AncientGates 作者:
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerPortal(final PlayerPortalEvent event) {
    if (event.isCancelled()) {
        return;
    }
    final Player player = event.getPlayer();

    // Ok so a player portal event begins
    // Find the nearest gate!
    final WorldCoord playerCoord = new WorldCoord(this.playerLocationAtEvent.get(player));
    final Gate nearestGate = Gates.gateFromPortal(playerCoord);

    if (nearestGate != null) {
        event.setCancelled(true);

        // Check teleportation method
        if (!Conf.useVanillaPortals) {
            return;
        }

        // Check player is not carrying a passenger
        if (player.getPassenger() != null) {
            return;
        }

        // Get current time
        final Long now = Calendar.getInstance().getTimeInMillis();

        // Check player has passed cooldown period
        if (Plugin.lastTeleportTime.containsKey(player.getName()) && Plugin.lastTeleportTime.get(player.getName()) > now - Conf.getGateCooldownMillis()) {
            return;
        }

        // Check player has permission to enter the gate.
        if (!Plugin.hasPermManage(player, "ancientgates.use." + nearestGate.getId()) && !Plugin.hasPermManage(player, "ancientgates.use.*") && Conf.enforceAccess) {
            player.sendMessage("You lack the permissions to enter this gate.");
            return;
        }

        // Handle economy (check player has funds to use gate)
        if (!Plugin.handleEconManage(player, nearestGate.getCost())) {
            player.sendMessage("This gate costs: " + nearestGate.getCost() + ". You have insufficient funds.");
            return;
        }

        // Handle BungeeCord gates (BungeeCord support disabled)
        if (nearestGate.getBungeeTo() != null && Conf.bungeeCordSupport == false) {
            player.sendMessage(String.format("BungeeCord support not enabled."));
            return;
        }

        // Teleport the player (Nether method)
        if (nearestGate.getTo() == null && nearestGate.getBungeeTo() == null && nearestGate.getCommand() == null) {
            player.sendMessage(String.format("This gate does not point anywhere :P"));
        } else if (nearestGate.getTo() != null) {
            TeleportUtil.teleportPlayer(player, nearestGate.getTo(), nearestGate.getTeleportEntities(), nearestGate.getTeleportInventory());

            if (nearestGate.getCommand() != null)
                ExecuteUtil.execCommand(player, nearestGate.getCommand(), nearestGate.getCommandType());
            if (nearestGate.getMessage() != null)
                player.sendMessage(nearestGate.getMessage());

            Plugin.lastTeleportTime.put(player.getName(), now);
        } else if (nearestGate.getBungeeTo() != null) {
            TeleportUtil.teleportPlayer(player, nearestGate.getBungeeTo(), nearestGate.getBungeeType(), nearestGate.getTeleportEntities(), nearestGate.getTeleportInventory(), false, nearestGate.getCommand(), nearestGate.getCommandType(),
                    nearestGate.getMessage());
        } else {
            ExecuteUtil.execCommand(player, nearestGate.getCommand(), nearestGate.getCommandType(), true);
            Plugin.lastTeleportTime.put(player.getName(), now);
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号