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

The following examples show how to use org.bukkit.entity.Player#getVehicle() . 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: LegacySkinRefresher.java    From SkinsRestorerX with GNU General Public License v3.0 6 votes vote down vote up
@Override
@SneakyThrows
public void accept(Player player) {
    val vehicle = player.getVehicle();
    val handle = MH_GET_HANDLE.invoke(player);
    val location = player.getLocation();
    val world = location.getWorld();
    val dimension = MH_WORLD_DIMENSION.invoke(MH_GET_WORLD_HANDLE.invoke(world));
    MH_REREGISTER.invoke(player, handle);
    MH_MOVE_TO_WORLD.invoke(PLAYER_LIST, handle, dimension, false, location, false);
    if (vehicle != null) {
        vehicle.addPassenger(player);
    }
}
 
Example 2
Source File: PushbackCharger.java    From QualityArmory with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public boolean shoot(Gun g, Player p, ItemStack i) {

	Location start = p.getEyeLocation().clone();
	Vector go = p.getLocation().getDirection().normalize();
	//go.add(new Vector((Math.random() * 2 * sway) - sway, (Math.random() * 2 * sway) - sway,
	//		(Math.random() * 2 * sway) - sway));
	GunUtil.playShoot(g,  p);

	boolean lookup = (go.getY() > go.getX() && go.getY() > go.getZ());
	boolean lookdown = (-go.getY() > go.getX() && -go.getY() > go.getZ());
	
	double degreeVector = Math.atan2(go.getX(), go.getZ());
	if (degreeVector > Math.PI)
		degreeVector = 2 * Math.PI - degreeVector;
	for (Entity e : p.getNearbyEntities(g.getMaxDistance(), g.getMaxDistance(), g.getMaxDistance())) {
		double dis = e.getLocation().distance(start);
		if (e instanceof Damageable)
			if (e != p && e != p.getVehicle() && e != p.getPassenger()) {
				double degreeEntity = Math.atan2(e.getLocation().getX() - start.getX(),
						e.getLocation().getZ() - start.getZ());
				if (degreeEntity > Math.PI)
					degreeEntity = 2 * Math.PI - degreeEntity;
				
				if ((lookup && e.getLocation().getY() > start.getY()) || (lookdown && e.getLocation().getY() < start.getY()) ||
						
						
						(!lookdown&&!lookup&&Math.max(degreeEntity, degreeVector)
						- Math.min(degreeEntity, degreeVector) < (dis > 10 ? Math.PI / 4 : Math.PI / 2))) {
					
					Vector pushback = new Vector(e.getLocation().getX() - start.getX(),e.getLocation().getY() - start.getY(),
							e.getLocation().getZ() - start.getZ());
					pushback.normalize().multiply(g.getMaxDistance()/(dis));
					e.setVelocity(pushback);
				}
			}
	}
	return false;
}
 
Example 3
Source File: GadgetHandler.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
public void onFollow(Player player, Player targetPlayer)
{
	if(targetPlayer == null || player.getName().equals(targetPlayer.getName()))
	{
		return;
	}
	
	if(player.getVehicle() != null)
	{
		player.getVehicle().eject();
		return;
	}
	
	targetPlayer.setPassenger(player);
}
 
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: HorsesModule.java    From UHC with MIT License 5 votes vote down vote up
protected void kickOffHorse(Player player) {
    final Entity vehicle = player.getVehicle();
    if (vehicle == null) return;

    vehicle.eject();
    player.sendMessage(messages.getRaw("disabled message"));
}
 
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: ClaimBlockTask.java    From GriefDefender with MIT License 4 votes vote down vote up
@Override
public void run() {
    for (World world : Bukkit.getServer().getWorlds()) {
        for (Player player : world.getPlayers()) {
            final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
            final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation());
            final GDPermissionUser holder = PermissionHolderCache.getInstance().getOrCreateUser(player);
            final int accrualPerHour = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Integer.class), holder, Options.BLOCKS_ACCRUED_PER_HOUR, claim).intValue();
            if (accrualPerHour > 0) {
                Location lastLocation = playerData.lastAfkCheckLocation;
                // if he's not in a vehicle and has moved at least three blocks since the last check and he's not being pushed around by fluids
                if (player.getVehicle() == null &&
                        (lastLocation == null || lastLocation.getWorld() != player.getWorld() || lastLocation.distanceSquared(player.getLocation()) >= 0) &&
                        !NMSUtil.getInstance().isBlockWater(player.getLocation().getBlock())) {
                    int accruedBlocks = playerData.getBlocksAccruedPerHour() / 12;
                    if (accruedBlocks < 0) {
                        accruedBlocks = 1;
                    }

                    if (GriefDefenderPlugin.getInstance().isEconomyModeEnabled()) {
                        final VaultProvider vaultProvider = GriefDefenderPlugin.getInstance().getVaultProvider();
                        if (!vaultProvider.hasAccount(player)) {
                            continue;
                        }
                        vaultProvider.depositPlayer(player, accruedBlocks);
                    } else {
                        int currentTotal = playerData.getAccruedClaimBlocks();
                        if ((currentTotal + accruedBlocks) > playerData.getMaxAccruedClaimBlocks()) {
                            playerData.setAccruedClaimBlocks(playerData.getMaxAccruedClaimBlocks());
                            playerData.lastAfkCheckLocation = player.getLocation();
                            return;
                        }

                        playerData.setAccruedClaimBlocks(playerData.getAccruedClaimBlocks() + accruedBlocks);
                    }
                }

                playerData.lastAfkCheckLocation = player.getLocation();
            }
        }
    }
}
 
Example 9
Source File: RegionManager.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets executed when a player enters a region
 *
 * @param player the player
 * @param region region he entered
 */
public void playerEnteredRegion(Player player, NovaRegion region) {
	PlayerEnterRegionEvent regionEvent = new PlayerEnterRegionEvent(player, region);
	ListenerManager.getLoggedPluginManager().callEvent(regionEvent);

	if(regionEvent.isCancelled()) {
		return;
	}

	if(region == null) {
		return;
	}

	NovaPlayer nPlayer = PlayerManager.getPlayer(player);

	if(plugin.getPlayerManager().isVanished(player)) {
		return;
	}

	//border particles
	if(Config.REGION_BORDERPARTICLES.getBoolean()) {
		List<Block> blocks = RegionUtils.getBorderBlocks(region);
		for(Block block : blocks) {
			block.getLocation().setY(block.getLocation().getY() + 1);
			block.getWorld().playEffect(block.getLocation(), Effect.SMOKE, 100);
		}
	}

	//Chat message
	boolean sameGuildRegion = nPlayer.isAtRegion() && region.getGuild().ownsRegion(region);
	Map<VarKey, String> vars = new HashMap<>();
	if(!sameGuildRegion) {
		vars.put(VarKey.GUILD_NAME, region.getGuild().getName());
		vars.put(VarKey.PLAYER_NAME, player.getName());
		Message.CHAT_REGION_ENTERED.clone().vars(vars).send(player);
	}

	//Player is at region
	nPlayer.setAtRegion(region);

	if(!region.getGuild().isMember(nPlayer)) {
		checkRaidInit(nPlayer);

		if(!sameGuildRegion) {
			Message.CHAT_REGION_NOTIFYGUILD_ENTERED.clone().vars(vars).broadcast(region.getGuild());
		}
	}

	//Vehicle protection system
	Entity vehicle = player.getVehicle();
	if(vehicle != null && vehicle instanceof Vehicle) {
		nPlayer.addVehicle((Vehicle) vehicle);
	}
}
 
Example 10
Source File: PlayerListener.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
private void setModifiedMovementSpeed(Player player) {
	/* Change move speed based on armor. */
	double speed = CivSettings.normal_speed;
	
	/* Set speed from armor. */
	if (Unit.isWearingFullComposite(player)) {
		speed *= CivSettings.T4_leather_speed;
	}
	
	if (Unit.isWearingFullHardened(player)) {
		speed *= CivSettings.T3_leather_speed;
	}
	
	if (Unit.isWearingFullRefined(player)) {
		speed *= CivSettings.T2_leather_speed;
	}
	
	if (Unit.isWearingFullBasicLeather(player)) {
		speed *= CivSettings.T1_leather_speed;
	}
	
	if (Unit.isWearingAnyIron(player)) {
		speed *= CivSettings.T1_metal_speed;
	}
	
	if (Unit.isWearingAnyChain(player)) {
		speed *= CivSettings.T2_metal_speed;
	}
	
	if (Unit.isWearingAnyGold(player)) {
		speed *= CivSettings.T3_metal_speed;
	}
	
	if (Unit.isWearingAnyDiamond(player)) {
		speed *= CivSettings.T4_metal_speed;
	}
	
	Resident resident = CivGlobal.getResident(player);
	if (resident != null && resident.isOnRoad()) {	
		if (player.getVehicle() != null && player.getVehicle().getType().equals(EntityType.HORSE)) {
			Vector vec = player.getVehicle().getVelocity();
			double yComp = vec.getY();
			
			vec.multiply(Road.ROAD_HORSE_SPEED);
			vec.setY(yComp); /* Do not multiply y velocity. */
			
			player.getVehicle().setVelocity(vec);
		} else {
			speed *= Road.ROAD_PLAYER_SPEED;
		}
	}
	
	player.setWalkSpeed((float) Math.min(1.0f, speed));
}
 
Example 11
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);
}
 
Example 12
Source File: AcidEffect.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Check if player can be burned by acid
 * @param player
 * @return true if player is not safe
 */
private boolean isSafeFromAcid(Player player) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: safe from acid");
    if (!player.getWorld().equals(ASkyBlock.getIslandWorld())) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: wrong world");
        return true;
    }
    // In liquid
    Material bodyMat = player.getLocation().getBlock().getType();
    Material headMat = player.getLocation().getBlock().getRelative(BlockFace.UP).getType();
    if (bodyMat.equals(Material.STATIONARY_WATER))
        bodyMat = Material.WATER;
    if (headMat.equals(Material.STATIONARY_WATER))
        headMat = Material.WATER;
    if (bodyMat != Material.WATER && headMat != Material.WATER) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: not in water " + player.getLocation().getBlock().isLiquid() + " " + player.getLocation().getBlock().getRelative(BlockFace.UP).isLiquid());
        return true;
    }
    // Check if player is in a boat
    Entity playersVehicle = player.getVehicle();
    if (playersVehicle != null) {
        // They are in a Vehicle
        if (playersVehicle.getType().equals(EntityType.BOAT)) {
            // I'M ON A BOAT! I'M ON A BOAT! A %^&&* BOAT!
            if (DEBUG)
                plugin.getLogger().info("DEBUG: boat");
            return true;
        }
    }
    // Check if full armor protects
    if (Settings.fullArmorProtection) {
        boolean fullArmor = true;
        for (ItemStack item : player.getInventory().getArmorContents()) {
            if (item == null || (item != null && item.getType().equals(Material.AIR))) {
                fullArmor = false;
                break;
            }
        }
        if (fullArmor) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: full armor");
            return true;
        }
    }
    // Check if player has an active water potion or not
    Collection<PotionEffect> activePotions = player.getActivePotionEffects();
    for (PotionEffect s : activePotions) {
        // plugin.getLogger().info("Potion is : " +
        // s.getType().toString());
        if (s.getType().equals(PotionEffectType.WATER_BREATHING)) {
            // Safe!
            if (DEBUG)
                plugin.getLogger().info("DEBUG: Water breathing potion protection!");
            return true;
        }
    }
    // Check if water above sea-level is not acid
    Island island = plugin.getGrid().getIslandAt(player.getLocation());
    if (island != null && !island.getIgsFlag(SettingsFlag.ACID_DAMAGE) && player.getLocation().getBlockY() > Settings.seaHeight) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG:no acid damage above sea level 1");
        return true;
    }
    if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.ACID_DAMAGE) && player.getLocation().getBlockY() > Settings.seaHeight) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: no acid damage above sea level");
        return true;
    }
    if (DEBUG)
        plugin.getLogger().info("DEBUG: burn in acid");
    return false;
}