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

The following examples show how to use org.bukkit.entity.Player#setCompassTarget() . 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: CommandGuildCompass.java    From NovaGuilds with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void execute(CommandSender sender, String[] args) throws Exception {
	Player player = (Player) sender;
	NovaPlayer nPlayer = PlayerManager.getPlayer(sender);

	if(!nPlayer.hasGuild()) {
		Message.CHAT_GUILD_NOTINGUILD.send(sender);
		return;
	}

	if(nPlayer.getPreferences().isCompassPointingGuild()) { //disable
		nPlayer.getPreferences().setCompassPointingGuild(false);
		player.setCompassTarget(player.getWorld().getSpawnLocation());
		Message.CHAT_GUILD_COMPASSTARGET_OFF.send(sender);
	}
	else { //enable
		nPlayer.getPreferences().setCompassPointingGuild(true);
		player.setCompassTarget(nPlayer.getGuild().getHome());
		Message.CHAT_GUILD_COMPASSTARGET_ON.send(sender);
	}
}
 
Example 2
Source File: UhcPlayer.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
public void pointCompassToNextPlayer(int mode, int cooldown) {
	PlayersManager pm = GameManager.getGameManager().getPlayersManager();
	List<UhcPlayer> pointPlayers = new ArrayList<>();

	// Check cooldown
	if (cooldown != -1 && (cooldown*TimeUtils.SECOND) + compassPlayingLastUpdate > System.currentTimeMillis()){
		sendMessage(Lang.ITEMS_COMPASS_PLAYING_COOLDOWN);
		return;
	}

	switch (mode){
		case 1:
			pointPlayers.addAll(team.getOnlinePlayingMembers());
			break;
		case 2:
			pointPlayers.addAll(pm.getOnlinePlayingPlayers());
			for (UhcPlayer teamMember : team.getOnlinePlayingMembers()){
				pointPlayers.remove(teamMember);
			}
			break;
		case 3:
			pointPlayers.addAll(pm.getOnlinePlayingPlayers());
			break;
	}

	if((pointPlayers.size() == 1 && pointPlayers.get(0).equals(this)) || pointPlayers.size() == 0){
		sendMessage(Lang.ITEMS_COMPASS_PLAYING_ERROR);
	}else{
		int currentIndice = -1;
		for(int i = 0 ; i < pointPlayers.size() ; i++){
			if(pointPlayers.get(i).equals(compassPlayingCurrentPlayer))
				currentIndice = i;
		}

		// Switching to next player
		if(currentIndice == pointPlayers.size()-1)
			currentIndice = 0;
		else
			currentIndice++;


		// Skipping player if == this
		if(pointPlayers.get(currentIndice).equals(this))
			currentIndice++;

		// Correct indice if out of bounds
		if(currentIndice == pointPlayers.size())
			currentIndice = 0;


		// Pointing compass
		compassPlayingCurrentPlayer = pointPlayers.get(currentIndice);
		compassPlayingLastUpdate = System.currentTimeMillis();
		try {
			Player bukkitPlayer = getPlayer();
			Player bukkitPlayerPointing = compassPlayingCurrentPlayer.getPlayer();

			bukkitPlayer.setCompassTarget(bukkitPlayerPointing.getLocation());

			String message = Lang.ITEMS_COMPASS_PLAYING_POINTING.replace("%player%", compassPlayingCurrentPlayer.getName());

			if (message.contains("%distance%")){
				int distance = (int) bukkitPlayer.getLocation().distance(bukkitPlayerPointing.getLocation());
				message = message.replace("%distance%", String.valueOf(distance));
			}

			sendMessage(message);
		} catch (UhcPlayerNotOnlineException e) {
			sendMessage(Lang.TEAM_MESSAGE_PLAYER_NOT_ONLINE.replace("%player%", compassPlayingCurrentPlayer.getName()));
		}
	}

}
 
Example 3
Source File: ExprCompassTarget.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) throws UnsupportedOperationException {
	for (final Player p : getExpr().getArray(e))
		p.setCompassTarget(delta == null ? p.getWorld().getSpawnLocation() : (Location) delta[0]);
}
 
Example 4
Source File: KitLoading.java    From AnnihilationPro with MIT License 4 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST)
public void navCompassCheck(PlayerInteractEvent event)
{
	if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)
	{
		final Player player = event.getPlayer();
		ItemStack item = player.getItemInHand();
		String name = null;
		Loc target = null;
		if(KitUtils.itemHasName(item, CustomItem.NAVCOMPASS.getName()))
		{
			name = redcompass;
			target = AnniTeam.Red.getNexus().getLocation();
		}
		else if(KitUtils.itemHasName(item, redcompass))
		{
			name = bluecompass;
			target = AnniTeam.Blue.getNexus().getLocation();
		}
		else if(KitUtils.itemHasName(item, bluecompass))
		{
			name = greencompass;
			target = AnniTeam.Green.getNexus().getLocation();
		}
		else if(KitUtils.itemHasName(item, greencompass))
		{
			name = yellowcompass;
			target = AnniTeam.Yellow.getNexus().getLocation();
		}
		else if(KitUtils.itemHasName(item, yellowcompass))
		{
			name = redcompass;
			target = AnniTeam.Red.getNexus().getLocation();
		}
		
		if(name != null && target != null)
		{
			ItemMeta m = item.getItemMeta();
			m.setDisplayName(name);
			item.setItemMeta(m);
			player.setCompassTarget(target.toLocation());
		}
	}
}
 
Example 5
Source File: PlayerStateHolder.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
public void apply(Player player, boolean teleport) {
	PlayerInventory playerInv = player.getInventory();
	boolean is1_9 = MinecraftVersion.getImplementationVersion().compareTo(MinecraftVersion.V1_9) >= 0;
       boolean isSimpleSize = playerInv.getContents().length <= SIMPLE_INVENTORY_SIZE;

       ItemStack[] inventoryContents = new ItemStack[is1_9 && !isSimpleSize ? playerInv.getSize() : SIMPLE_INVENTORY_SIZE];
       System.arraycopy(inventory, 0, inventoryContents, 0, inventoryContents.length);

       if (!is1_9 || isSimpleSize) {
           ItemStack[] armorContents = new ItemStack[ARMOR_INVENTORY_SIZE];
           System.arraycopy(inventory, inventory.length - ARMOR_INVENTORY_SIZE, armorContents, 0, armorContents.length);
           playerInv.setArmorContents(armorContents);
       }
	
	playerInv.setContents(inventoryContents);

	player.setItemOnCursor(null);
	Map<Integer, ItemStack> exceeded = playerInv.addItem(onCursor);
	for (ItemStack stack : exceeded.values()) {
           if (stack.getType() == Material.AIR) {
               continue;
           }
           
		player.getWorld().dropItem(player.getLocation(), stack);
	}
	
	player.updateInventory();

       player.setMaxHealth(maxHealth);
	player.setHealth(health);
	player.setFoodLevel(foodLevel);
	player.setLevel(level);
	player.setExp(experience);
	player.setAllowFlight(allowFlight);
	player.setFlying(isFlying);
	
	/* Remove current potion effects */
	Collection<PotionEffect> effects = player.getActivePotionEffects();
	for (PotionEffect effect : effects) {
		player.removePotionEffect(effect.getType());
	}
	player.addPotionEffects(activeEffects);
	
	player.setExhaustion(exhaustion);
	player.setSaturation(saturation);
	player.setFallDistance(fallDistance);
	player.setFireTicks(fireTicks);
	
	if (scoreboard != player.getScoreboard()) {
		Scoreboard showBoard = scoreboard;
		if (scoreboard == null) {
			showBoard = Bukkit.getScoreboardManager().getMainScoreboard();
		}
		
		player.setScoreboard(showBoard);
	}
	
	if (teleport) {
		player.teleport(location);
	}
	
	Location compassTarget = this.compassTarget;
	
	if (compassTarget == null) {
		compassTarget = player.getWorld().getSpawnLocation();
	}
	
	player.setCompassTarget(compassTarget);
	
	for (WeakReference<Player> ref : cantSee) {
		Player cantSeePlayer = ref.get();
		
		if (cantSeePlayer == null) {
			// Player object has been garbage-collected
			continue;
		}
		
		if (!cantSeePlayer.isOnline()) {
			continue;
		}
		
		player.hidePlayer(cantSeePlayer);
	}
	
	player.setGameMode(gamemode);
}
 
Example 6
Source File: UHPluginListener.java    From KTP with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerInteract(PlayerInteractEvent ev) {
	if ((ev.getAction() == Action.RIGHT_CLICK_AIR || ev.getAction() == Action.RIGHT_CLICK_BLOCK) && ev.getPlayer().getItemInHand().getType() == Material.COMPASS && p.getConfig().getBoolean("compass")) {
		Player pl = ev.getPlayer();
		Boolean foundRottenFlesh = false;
		for (ItemStack is : pl.getInventory().getContents()) {
			if (is != null && is.getType() == Material.ROTTEN_FLESH) {
				p.getLogger().info(""+is.getAmount());
				if (is.getAmount() != 1) is.setAmount(is.getAmount()-1);
				else { p.getLogger().info("lol"); pl.getInventory().removeItem(is); }
				pl.updateInventory();
				foundRottenFlesh = true;
				break;
			}
		}
		if (!foundRottenFlesh) {
			pl.sendMessage(ChatColor.GRAY+""+ChatColor.ITALIC+"Vous n'avez pas de chair de zombie.");
			pl.playSound(pl.getLocation(), Sound.BLOCK_WOOD_STEP, 1F, 1F);
			return;
		}
		pl.playSound(pl.getLocation(), Sound.ENTITY_PLAYER_BURP, 1F, 1F);
		Player nearest = null;
		Double distance = 99999D;
		for (Player pl2 : p.getServer().getOnlinePlayers()) {
			try {	
				Double calc = pl.getLocation().distance(pl2.getLocation());
				if (calc > 1 && calc < distance) {
					distance = calc;
					if (pl2 != pl && !this.p.inSameTeam(pl, pl2)) nearest = pl2.getPlayer();
				}
			} catch (Exception e) {}
		}
		if (nearest == null) {
			pl.sendMessage(ChatColor.GRAY+""+ChatColor.ITALIC+"Seul le silence comble votre requĂȘte.");
			return;
		}
		pl.sendMessage(ChatColor.GRAY+"La boussole pointe sur le joueur le plus proche.");
		pl.setCompassTarget(nearest.getLocation());
	}
}