Java Code Examples for org.bukkit.entity.Player#isInsideVehicle()

The following examples show how to use org.bukkit.entity.Player#isInsideVehicle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Inertia.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void check(MoveEvent e) {
    Player p = e.getPlayer();
    HawkPlayer pp = e.getHawkPlayer();
    Vector moveVector = new Vector(e.getTo().getX() - e.getFrom().getX(), 0, e.getTo().getZ() - e.getFrom().getZ());
    Vector prevVector = pp.getVelocity().clone().setY(0);
    double horizSpeedSquared = Math.pow(e.getTo().getX() - e.getFrom().getX(), 2) + Math.pow(e.getTo().getZ() - e.getFrom().getZ(), 2);
    double deltaAngle = MathPlus.angle(moveVector, prevVector);
    boolean onGround = e.isOnGround(); //um... is this safe?
    boolean wasOnGround = pp.isOnGround(); //um... is this safe?

    if (!AdjacentBlocks.blockNearbyIsSolid(e.getTo(), true) && !wasOnGround && !onGround && !e.hasAcceptedKnockback() && !e.isTouchingBlocks() &&
            !AdjacentBlocks.blockNearbyIsSolid(e.getTo().clone().add(0, 1, 0), true) && !pp.isFlying() && !p.isInsideVehicle()) {

        //setting up expected values
        double magnitudeThres;
        double prevSpeed = e.hasHitSlowdown() ? prevVector.length() * 0.6 : prevVector.length();
        if(AdjacentBlocks.blockAdjacentIsLiquid(e.getFrom()) || AdjacentBlocks.blockAdjacentIsLiquid(e.getFrom().clone().add(0, 1, 0))) {
            magnitudeThres = 0; //screw it
        }
        else {
            magnitudeThres = e.getFriction() * prevSpeed - 0.026001;
        }

        //angle check
        if (horizSpeedSquared > 0.05 && deltaAngle > 0.2) {
            punishAndTryRubberband(pp, e);

        //magnitude check
        } else if(prevVector.lengthSquared() > 0.01 && moveVector.length() < magnitudeThres) {
            punishAndTryRubberband(pp, e);
        }

        else {
            reward(pp);
        }
    }
}
 
Example 2
Source File: QuadCrate.java    From Crazy-Crates with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
    Player player = e.getPlayer();
    if (QuadCrateSession.inSession(player)) {//Player tries to walk away from the crate area
        Location from = e.getFrom();
        Location to = e.getTo();
        if (from.getBlockX() != to.getBlockX() || from.getBlockZ() != to.getBlockZ()) {
            e.setCancelled(true);
            player.teleport(from);
            return;
        }
    }
    for (Entity en : player.getNearbyEntities(2, 2, 2)) {//Someone tries to enter the crate area
        if (en instanceof Player) {
            Player p = (Player) en;
            if (QuadCrateSession.inSession(p)) {
                Vector v = player.getLocation().toVector().subtract(p.getLocation().toVector()).normalize().setY(1);
                if (player.isInsideVehicle()) {
                    player.getVehicle().setVelocity(v);
                } else {
                    player.setVelocity(v);
                }
                break;
            }
        }
    }
}
 
Example 3
Source File: CrateControl.java    From Crazy-Crates with MIT License 5 votes vote down vote up
public static void knockBack(Player player, Location location) {
    Vector vector = player.getLocation().toVector().subtract(location.toVector()).normalize().multiply(1).setY(.1);
    if (player.isInsideVehicle()) {
        player.getVehicle().setVelocity(vector);
        return;
    }
    player.setVelocity(vector);
}
 
Example 4
Source File: SitListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler
public void onQuit(PlayerQuitEvent event) {
    Player player = event.getPlayer();
    Entity vehicle = player.getVehicle();
    if (safeLocations.containsKey(player.getUniqueId()) && player.isInsideVehicle() && vehicle instanceof ArmorStand) {
        safeLocations.remove(player.getUniqueId());
        player.leaveVehicle();
        vehicle.remove();
    }
}
 
Example 5
Source File: HorseArmourModule.java    From UHC with MIT License 5 votes vote down vote up
@Override
public void onDisable() {
    for (final Player player : Bukkit.getOnlinePlayers()) {
        if (player.isInsideVehicle()) {
            final Entity vehicle = player.getVehicle();

            if (vehicle.getType() == EntityType.HORSE && removeHorseArmour((Horse) vehicle)) {
                player.sendMessage(messages.getRaw("dropped armour"));
            }
        }
    }
}
 
Example 6
Source File: FeatureEmulation.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onShift(PlayerToggleSneakEvent event) {
	Player player = event.getPlayer();
	Connection connection = ProtocolSupportAPI.getConnection(player);
	if (
		player.isInsideVehicle() &&
		(connection != null) &&
		(connection.getVersion().getProtocolType() == ProtocolType.PC) &&
		connection.getVersion().isBeforeOrEq(ProtocolVersion.MINECRAFT_1_5_2)
	) {
		player.leaveVehicle();
	}
}
 
Example 7
Source File: ProcessSyncPasswordRegister.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Request that the player log in.
 *
 * @param player the player
 */
private void requestLogin(Player player) {
    limboService.replaceTasksAfterRegistration(player);

    if (player.isInsideVehicle() && player.getVehicle() != null) {
        player.getVehicle().eject();
    }
}
 
Example 8
Source File: FlyOld.java    From Hawk with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void check(MoveEvent event) {
    Player p = event.getPlayer();
    HawkPlayer pp = event.getHawkPlayer();
    double deltaY = event.getTo().getY() - event.getFrom().getY();
    if (pp.hasFlyPending() && p.getAllowFlight())
        return;
    if (!event.isOnGroundReally() && !pp.isFlying() && !p.isInsideVehicle() && !pp.isSwimming() && !p.isSleeping() &&
            !isInClimbable(event.getTo()) && !isOnBoat(p, event.getTo())) {

        if (!inAir.contains(p.getUniqueId()) && deltaY > 0)
            lastDeltaY.put(p.getUniqueId(), 0.42 + getJumpBoostLvl(p) * 0.1);

        //handle any pending knockbacks
        if(event.hasAcceptedKnockback())
            lastDeltaY.put(p.getUniqueId(), deltaY);

        if(event.isSlimeBlockBounce())
            lastDeltaY.put(p.getUniqueId(), deltaY);

        double expectedDeltaY = lastDeltaY.getOrDefault(p.getUniqueId(), 0D);
        double epsilon = 0.03;

        //lastDeltaY.put(p.getUniqueId(), (lastDeltaY.getOrDefault(p.getUniqueId(), 0D) - 0.025) * 0.8); //water function
        if (WrappedEntity.getWrappedEntity(p).getCollisionBox(event.getFrom().toVector()).getMaterials(p.getWorld()).contains(Material.WEB)) {
            lastDeltaY.put(p.getUniqueId(), -0.007);
            epsilon = 0.000001;
            if (AdjacentBlocks.onGroundReally(event.getTo().clone().add(0, -0.03, 0), -1, false, 0.02, pp))
                return;
        } else if(!pp.isInWater() && event.isInWater()) {
            //entering liquid
            lastDeltaY.put(p.getUniqueId(), (lastDeltaY.getOrDefault(p.getUniqueId(), 0D) * 0.98) - 0.038399);
        } else {
            //in air
            lastDeltaY.put(p.getUniqueId(), (lastDeltaY.getOrDefault(p.getUniqueId(), 0D) - 0.08) * 0.98);
        }


        //handle teleport
        if (event.hasTeleported()) {
            lastDeltaY.put(p.getUniqueId(), 0D);
            expectedDeltaY = 0;
            legitLoc.put(p.getUniqueId(), event.getTo());
        }

        if (deltaY - expectedDeltaY > epsilon && event.hasDeltaPos()) { //oopsie daisy. client made a goof up

            //wait one little second: minecraft is being a pain in the ass and it wants to play tricks when you parkour on the very edge of blocks
            //we need to check this first...
            if (deltaY < 0) {
                Location checkLoc = event.getFrom().clone();
                checkLoc.setY(event.getTo().getY());
                if (AdjacentBlocks.onGroundReally(checkLoc, deltaY, false, 0.02, pp)) {
                    onGroundStuff(p);
                    return;
                }
                //extrapolate move BEFORE getFrom, then check
                checkLoc.setY(event.getFrom().getY());
                checkLoc.setX(checkLoc.getX() - (event.getTo().getX() - event.getFrom().getX()));
                checkLoc.setZ(checkLoc.getZ() - (event.getTo().getZ() - event.getFrom().getZ()));
                if (AdjacentBlocks.onGroundReally(checkLoc, deltaY, false, 0.02, pp)) {
                    onGroundStuff(p);
                    return;
                }
            }

            if(event.isOnClientBlock() != null) {
                onGroundStuff(p);
                return;
            }

            //scold the child
            punish(pp, false, event);
            tryRubberband(event);
            lastDeltaY.put(p.getUniqueId(), canCancel() ? 0 : deltaY);
            failedSoDontUpdateRubberband.add(p.getUniqueId());
            return;
        }

        reward(pp);

        //the player is in air now, since they have a positive Y velocity and they're not on the ground
        if (inAir.contains(p.getUniqueId()))
            //upwards now
            stupidMoves.put(p.getUniqueId(), 0);

        //handle stupid moves, because the client tends to want to jump a little late if you jump off the edge of a block
        if (stupidMoves.getOrDefault(p.getUniqueId(), 0) >= STUPID_MOVES || (deltaY > 0 && AdjacentBlocks.onGroundReally(event.getFrom(), -1, true, 0.02, pp)))
            //falling now
            inAir.add(p.getUniqueId());
        stupidMoves.put(p.getUniqueId(), stupidMoves.getOrDefault(p.getUniqueId(), 0) + 1);
    } else {
        onGroundStuff(p);
    }

    if (!failedSoDontUpdateRubberband.contains(p.getUniqueId()) || event.isOnGroundReally()) {
        legitLoc.put(p.getUniqueId(), p.getLocation());
        failedSoDontUpdateRubberband.remove(p.getUniqueId());
    }

}
 
Example 9
Source File: SitListener.java    From NyaaUtils with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onClickBlock(PlayerInteractEvent event) {
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.hasBlock() && !event.hasItem()) {
        Block block = event.getClickedBlock();
        BlockFace face = event.getBlockFace();
        if (face == BlockFace.DOWN || block.isLiquid() || !plugin.cfg.sit_blocks.contains(block.getType())) {
            return;
        }
        Block relative = block.getRelative(0, 1, 0);
        Player player = event.getPlayer();
        if (messageCooldown.getIfPresent(player.getUniqueId()) != null) {
            return;
        }
        messageCooldown.put(player.getUniqueId(), true);
        if (!player.hasPermission("nu.sit") || !enabledPlayers.contains(player.getUniqueId()) || player.isInsideVehicle() || !player.getPassengers().isEmpty() || player.getGameMode() == GameMode.SPECTATOR || !player.isOnGround()) {
            return;
        }
        if (relative.isLiquid() || !(relative.isEmpty() || relative.isPassable())) {
            player.sendMessage(I18n.format("user.sit.invalid_location"));
            return;
        }
        Vector vector = block.getBoundingBox().getCenter().clone();
        Location loc = vector.setY(block.getBoundingBox().getMaxY()).toLocation(player.getWorld()).clone();
        for (SitLocation sl : plugin.cfg.sit_locations.values()) {
            if (sl.blocks != null && sl.x != null && sl.y != null && sl.z != null && sl.blocks.contains(block.getType().name())) {
                loc.add(sl.x, sl.y, sl.z);
            }
        }
        if (block.getBlockData() instanceof Directional) {
            face = ((Directional) block.getBlockData()).getFacing();
            if (face == BlockFace.EAST) {
                loc.setYaw(90);
            } else if (face == BlockFace.WEST) {
                loc.setYaw(-90);
            } else if (face == BlockFace.NORTH) {
                loc.setYaw(0);
            } else if (face == BlockFace.SOUTH) {
                loc.setYaw(-180);
            }
        } else {
            if (face == BlockFace.WEST) {
                loc.setYaw(90);
            } else if (face == BlockFace.EAST) {
                loc.setYaw(-90);
            } else if (face == BlockFace.SOUTH) {
                loc.setYaw(0);
            } else if (face == BlockFace.NORTH) {
                loc.setYaw(-180);
            } else {
                loc.setYaw(player.getEyeLocation().getYaw());
            }
        }
        for (Entity e : loc.getWorld().getNearbyEntities(loc, 0.5, 0.7, 0.5)) {
            if (e instanceof LivingEntity) {
                if (e.hasMetadata(metadata_key) || (e instanceof Player && e.isInsideVehicle() && e.getVehicle().hasMetadata(metadata_key))) {
                    player.sendMessage(I18n.format("user.sit.invalid_location"));
                    return;
                }
            }
        }
        Location safeLoc = player.getLocation().clone();
        ArmorStand armorStand = loc.getWorld().spawn(loc, ArmorStand.class, (e) -> {
            e.setVisible(false);
            e.setPersistent(false);
            e.setCanPickupItems(false);
            e.setBasePlate(false);
            e.setArms(false);
            e.setMarker(true);
            e.setInvulnerable(true);
            e.setGravity(false);
        });
        if (armorStand != null) {
            armorStand.setMetadata(metadata_key, new FixedMetadataValue(plugin, true));
            if (armorStand.addPassenger(player)) {
                safeLocations.put(player.getUniqueId(), safeLoc);
            } else {
                armorStand.remove();
            }
        }
    }
}
 
Example 10
Source File: GridManager.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Teleport player to a home location. If one cannot be found a search is done to
 * find a safe place.
 * @param player player object
 * @param number - home location to do to
 * @return true if successful, false if not
 */
@SuppressWarnings("deprecation")
public void homeTeleport(final Player player, int number) {
    Location home = null;
    //plugin.getLogger().info("home teleport called for #" + number);
    home = getSafeHomeLocation(player.getUniqueId(), number);
    //plugin.getLogger().info("home get safe loc = " + home);
    // Check if the player is a passenger in a boat
    if (player.isInsideVehicle()) {
        Entity boat = player.getVehicle();
        if (boat instanceof Boat) {
            player.leaveVehicle();
            // Remove the boat so they don't lie around everywhere
            boat.remove();
            player.getInventory().addItem(new ItemStack(Material.BOAT, 1));
            player.updateInventory();
        }
    }
    if (home == null) {
        //plugin.getLogger().info("Fixing home location using safe spot teleport");
        // Try to fix this teleport location and teleport the player if possible
        new SafeTeleportBuilder(plugin)
        .entity(player)
        .location(plugin.getPlayers().getHomeLocation(player.getUniqueId(), number))
        .homeNumber(number)
        .build();
        return;
    }
    //plugin.getLogger().info("DEBUG: home loc = " + home + " teleporting");
    //home.getChunk().load();
    IslandPreTeleportEvent event = new IslandPreTeleportEvent(player, IslandPreTeleportEvent.Type.HOME, home);
    Bukkit.getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        player.teleport(event.getLocation());
        //player.sendBlockChange(home, Material.GLOWSTONE, (byte)0);
        if (number ==1 ) {
            Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).islandteleport);
        } else {
            Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).islandteleport + " #" + number);
        }
    }
    plugin.getPlayers().setInTeleport(player.getUniqueId(), false);
}