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

The following examples show how to use org.bukkit.entity.Player#hidePlayer() . 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: MatchPlayerImpl.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void resetVisibility() {
  final Player bukkit = getBukkit();

  bukkit.showInvisibles(isObserving());

  for (MatchPlayer other : getMatch().getPlayers()) {
    if (canSee(other)) {
      bukkit.showPlayer(other.getBukkit());
    } else {
      bukkit.hidePlayer(other.getBukkit());
    }

    if (other.canSee(this)) {
      other.getBukkit().showPlayer(getBukkit());
    } else {
      other.getBukkit().hidePlayer(getBukkit());
    }
  }
}
 
Example 2
Source File: ShadowDive.java    From MineTinker with GNU General Public License v3.0 6 votes vote down vote up
private void hidePlayer(Player p) {
	activePlayers.add(p);

	//Clear all mob targets
	Collection<Entity> nearbyEntities = p.getWorld().getNearbyEntities(p.getLocation(), 64, 64, 64);
	for (Entity ent : nearbyEntities) {
		if (ent instanceof Creature) {
			if (p.equals(((Creature) ent).getTarget())) {
				((Creature) ent).setTarget(null);
			}
		}
	}

	//Hide from all players
	for (Player player : Bukkit.getServer().getOnlinePlayers()) {
		if (!p.equals(player)) {
			if (!player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) player.hidePlayer(MineTinker.getPlugin(), p);
		}
	}
}
 
Example 3
Source File: MatchPlayer.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
public void refreshVisibility() {
    final Player bukkit = getBukkit();
    bukkit.showInvisibles(isObserving());

    for(MatchPlayer other : match.getPlayers()) {
        if(canSee(other)) {
            bukkit.showPlayer(other.getBukkit());
        } else {
            bukkit.hidePlayer(other.getBukkit());
        }

        if(other.canSee(this)) {
            other.getBukkit().showPlayer(bukkit);
        } else {
            other.getBukkit().hidePlayer(bukkit);
        }
    }
}
 
Example 4
Source File: FlagInvisibleSpectate.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe(priority = Subscribe.Priority.MONITOR)
public void onPlayerJoinGame(PlayerPreJoinGameEvent event) {
	Game game = event.getGame();
	
	if (event.getJoinResult() != JoinResult.ALLOW || game.getGameState() == GameState.INGAME) {
		return;
	}
	
	SpleefPlayer player = event.getPlayer();
	Player bukkitPlayer = player.getBukkitPlayer();
	
	FlagSpectate flag = (FlagSpectate) getParent();
	
	for (SpleefPlayer spectating : flag.getSpectators()) {
		if (!bukkitPlayer.canSee(spectating.getBukkitPlayer())) {
			continue;
		}
		
		bukkitPlayer.hidePlayer(spectating.getBukkitPlayer());
	}
}
 
Example 5
Source File: EffPlayerVisibility.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void execute(Event e) {
    Player[] targets = targetPlayers == null ? Bukkit.getOnlinePlayers().toArray(new Player[0]) : targetPlayers.getArray(e);
    for (Player targetPlayer : targets) {
        for (Player player : players.getArray(e)) {
            if (reveal) {
                if (USE_DEPRECATED_METHOD)
                    targetPlayer.showPlayer(player);
                else
                    targetPlayer.showPlayer(Skript.getInstance(), player);
            } else {
                if (USE_DEPRECATED_METHOD)
                    targetPlayer.hidePlayer(player);
                else
                    targetPlayer.hidePlayer(Skript.getInstance(), player);
            }
        }
    }
}
 
Example 6
Source File: Game.java    From Survival-Games with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public void addSpectator(Player p) {
	if (mode != GameMode.INGAME) {
		msgmgr.sendMessage(PrefixType.WARNING, "You can only spectate running games!", p);
		return;
	}

	saveInv(p);
	clearInv(p);
	p.teleport(SettingsManager.getInstance().getSpawnPoint(gameID, 1).add(0, 10, 0));

	HookManager.getInstance().runHook("PLAYER_SPECTATE", "player-"+p.getName());

	for (Player pl: Bukkit.getOnlinePlayers()) {
		pl.hidePlayer(p);
	}

	p.setAllowFlight(true);
	p.setFlying(true);
	spectators.add(p.getName());
	msgmgr.sendMessage(PrefixType.INFO, "You are now spectating! Use /sg spectate again to return to the lobby.", p);
	msgmgr.sendMessage(PrefixType.INFO, "Right click while holding shift to teleport to the next ingame player, left click to go back.", p);
	nextspec.put(p, 0);
}
 
Example 7
Source File: TutorialListener.java    From ServerTutorial with MIT License 5 votes vote down vote up
@EventHandler
public void onJoin(PlayerJoinEvent event) {
    final Player player = event.getPlayer();
    final String playerName = player.getName();
    if (TutorialManager.getManager().getConfigs().getCheckGameMode()) {
        event.getPlayer().setGameMode(GameMode.SURVIVAL);
    }
    if (plugin.getTempPlayers().containsKey(player.getUniqueId())) {
        plugin.getTempPlayers().get(player.getUniqueId()).restorePlayer();
        plugin.getTempPlayers().remove(player.getUniqueId());
        DataLoading.getDataLoading().getTempData().set("players." + player.getUniqueId(), null);
        DataLoading.getDataLoading().saveTempData();
    }
    if (!plugin.getServer().getOnlineMode()) {
        plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
            @Override
            public void run() {
                try {
                    Caching.getCaching().getResponse().put(playerName, UUIDFetcher.getUUIDOf(playerName));
                } catch (Exception ignored) {

                }
            }
        });
    }
    for (String name : TutorialManager.getManager().getAllInTutorial()) {
        Player tut = plugin.getServer().getPlayerExact(name);
        if (tut != null) {
            player.hidePlayer(tut);
        }
    }
    if (!player.hasPlayedBefore()) {
        if (TutorialManager.getManager().getConfigs().firstJoin()) {
            plugin.startTutorial(TutorialManager.getManager().getConfigs().firstJoinTutorial(), player);
        }
    }
}
 
Example 8
Source File: TutorialPlayer.java    From ServerTutorial with MIT License 5 votes vote down vote up
public void clearPlayer(Player player) {
    player.getInventory().clear();
    player.setAllowFlight(true);
    player.setFlying(true);

    player.setExp(1.0f);
    player.setLevel(0);
    player.setFoodLevel(20);
    player.setHealth(player.getMaxHealth());

    for (Player online : Bukkit.getServer().getOnlinePlayers()) {
        online.hidePlayer(player);
        player.hidePlayer(online);
    }
}
 
Example 9
Source File: Visibility.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
    for (Player player : Bukkit.getOnlinePlayers()) {
        player.hidePlayer(event.getPlayer());
        event.getPlayer().hidePlayer(player);
    }
    showOrHide(event.getPlayer());
    showOrHideOthers(event.getPlayer());
}
 
Example 10
Source File: Visibility.java    From CardinalPGM with MIT License 5 votes vote down vote up
private void setVisibility(final Player viewer, final Player toSee, boolean shouldSee) {
    if (shouldSee) {
        viewer.showPlayer(toSee);
    } else {
        viewer.hidePlayer(toSee);
    }
}
 
Example 11
Source File: SkinApplier.java    From ChangeSkin with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void hideAndShow(Player other) {
    //removes the entity and display the new skin
    if (NEW_HIDE_METHOD_AVAILABLE) {
        other.hidePlayer(plugin, receiver);
        other.showPlayer(plugin, receiver);
    } else {
        other.hidePlayer(receiver);
        other.showPlayer(receiver);
    }
}
 
Example 12
Source File: BukkitPlayerHidingUtil.java    From SuperVanish with Mozilla Public License 2.0 5 votes vote down vote up
public static void hidePlayer(Player player, Player viewer, SuperVanish plugin) {
    if (isNewPlayerHidingAPISupported(viewer))
        viewer.hidePlayer(plugin, player);
    else
        //noinspection deprecation
        viewer.hidePlayer(player);
}
 
Example 13
Source File: VanishHandler.java    From StaffPlus with GNU General Public License v3.0 5 votes vote down vote up
private void applyVanish(Player player, VanishType vanishType, boolean shouldMessage)
{
	String message = "";
	
	switch(vanishType)
	{
		case TOTAL:
			for(Player p : Bukkit.getOnlinePlayers())
			{
				if(permission.has(p, options.permissionVanishTotal))
				{
					continue;
				}
				
				p.hidePlayer(player);
			}
			
			player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0));
			message = messages.totalVanish.replace("%status%", "enabled");
			break;
		case LIST:
			if(options.vanishTabList)
			{
				versionProtocol.listVanish(player, true);
			}
			
			message = messages.listVanish.replace("%status%", "enabled");
			break;
		default:
			break;
	}
	
	if(shouldMessage && !message.isEmpty())
	{
		this.message.send(player, message, messages.prefixGeneral);
	}
}
 
Example 14
Source File: ChickenGizmo.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
boolean add(Player viewer) {
    if(viewers.add(viewer)) {
        viewer.hidePlayer(player);
        entity.spawn(viewer, player.getLocation());
        viewer.playSound(viewer.getLocation(), Sound.ENTITY_CHICKEN_AMBIENT, 1f, 1f);
        viewer.playSound(viewer.getLocation(), Sound.ENTITY_CHICKEN_HURT, 1f, 1f);
        return true;
    }

    return false;
}
 
Example 15
Source File: PopperGizmo.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler
public void entityDamage(final EntityDamageEvent event) {
    if(!(event instanceof EntityDamageByEntityEvent)) return;
    EntityDamageByEntityEvent realEvent = (EntityDamageByEntityEvent) event;
    if(!(realEvent.getDamager() instanceof Player) || !(realEvent.getEntity() instanceof Player)) return;

    final Player damager = (Player) realEvent.getDamager();
    final Player victim = (Player) realEvent.getEntity();

    if(victim.hasPermission(GizmoConfig.EXEMPT_PERMISSION)) return;

    if(!(Gizmos.gizmoMap.get(damager) instanceof PopperGizmo)) return;
    if(damager.getItemInHand().getType() != this.getIcon()) return;

    if(!damager.canSee(victim)) return;

    damager.hidePlayer(victim);
    damager.playSound(damager.getLocation(), Sound.BLOCK_LAVA_POP, 1f, 2f);

    Integer count = poppedCount.get(damager);
    if(count == null) count = 0;

    count++;
    poppedCount.put(damager, count);

    if(count % 10 == 0) {
        RaindropUtil.giveRaindrops(
            Users.playerId(damager), 1, null,
            new TranslatableComponent("gizmo.popper.raindropsResult", new Component(String.valueOf(count), net.md_5.bungee.api.ChatColor.GOLD))
        );
    }

    event.setCancelled(true);
}
 
Example 16
Source File: ShadowDive.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
	Iterator<Player> iterator = activePlayers.iterator();
	//noinspection WhileLoopReplaceableByForEach
	while (iterator.hasNext()) {
		Player p = iterator.next();
		Location loc = p.getLocation();
		byte lightlevel = p.getWorld().getBlockAt(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()).getLightLevel();
		if (!p.isSneaking() || lightlevel > requiredLightLevel || p.hasPotionEffect(PotionEffectType.GLOWING)) {
			showPlayer(p);
			ChatWriter.sendActionBar(p, ChatColor.RED + ShadowDive.instance().getName() + ": "
					+ LanguageManager.getString("Modifier.Shadow-Dive.LightToHigh", p));
		} else if (PlayerInfo.isCombatTagged(p)) {
			showPlayer(p);
			ChatWriter.sendActionBar(p, ChatColor.RED + ShadowDive.instance().getName() + ": "
					+ LanguageManager.getString("Modifier.Shadow-Dive.InCombat", p));
		} else {
			for(Player pl : Bukkit.getOnlinePlayers()) {
				if (pl.equals(p)) continue;
				if (pl.hasPotionEffect(PotionEffectType.NIGHT_VISION)) {
					pl.showPlayer(MineTinker.getPlugin(), p);
				} else {
					pl.hidePlayer(MineTinker.getPlugin(), p);
				}
			}
		}
	}
}
 
Example 17
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);
}