Java Code Examples for org.bukkit.entity.Player#isOnline()
The following examples show how to use
org.bukkit.entity.Player#isOnline() .
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: CommandRunAction.java From TrMenu with MIT License | 6 votes |
@Override public void onCommand(CommandSender sender, Command command, String label, String[] args) { Player player = Bukkit.getPlayerExact(args[0].startsWith("#") ? args[0].substring(1) : args[0]); if (player == null || !player.isOnline()) { TLocale.sendTo(sender, "COMMANDS.NO-PLAYER"); return; } String actionString = ArrayUtil.arrayJoin(args, 1); boolean print = args[0].startsWith("#"); TrAction.readActions(actionString).forEach(action -> { if (print) { player.sendMessage("§7Action Details: §3" + action.toString()); } action.run(player); }); }
Example 2
Source File: IslandInfo.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
public void setupPartyLeader(@NotNull final String leader) { Validate.notNull(leader, "Leader cannot be null"); Validate.notEmpty(leader, "Leader cannot be empty"); UUID uuid = plugin.getPlayerDB().getUUIDFromName(leader); String uuidString = UUIDUtil.asString(uuid); config.set("party.leader", leader); config.set("party.leader-uuid", uuidString); ConfigurationSection section = config.createSection("party.members." + uuidString); section.set("canChangeBiome", true); section.set("canToggleLock", true); section.set("canChangeWarp", true); section.set("canToggleWarp", true); section.set("canInviteOthers", true); section.set("canKickOthers", true); section.set("canBanOthers", true); config.set("party.currentSize", getMembers().size()); Player onlinePlayer = plugin.getPlayerDB().getPlayer(uuid); // The only time the onlinePlayer will be null is if it is being converted from another skyblock plugin. if (onlinePlayer != null && onlinePlayer.isOnline()) { updatePermissionPerks(onlinePlayer, plugin.getPerkLogic().getPerk(onlinePlayer)); } save(); }
Example 3
Source File: Game.java From Survival-Games with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") public void removeSpectator(Player p) { ArrayList < Player > players = new ArrayList < Player > (); players.addAll(activePlayers); players.addAll(inactivePlayers); if(p.isOnline()){ for (Player pl: Bukkit.getOnlinePlayers()) { pl.showPlayer(p); } } restoreInv(p); p.setAllowFlight(false); p.setFlying(false); p.setFallDistance(0); p.setHealth(p.getMaxHealth()); p.setFoodLevel(20); p.setSaturation(20); p.teleport(SettingsManager.getInstance().getLobbySpawn()); // Bukkit.getServer().broadcastPrefixType("Removing Spec "+p.getName()+" "+spectators.size()+" left"); spectators.remove(p.getName()); // Bukkit.getServer().broadcastPrefixType("Removed"); nextspec.remove(p); }
Example 4
Source File: LevelCommand.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public boolean getIslandLevel(final Player player, final String islandPlayer, final String cmd) { final PlayerInfo info = plugin.getPlayerInfo(islandPlayer); if (info == null || !info.getHasIsland()) { player.sendMessage(tr("\u00a74That player is invalid or does not have an island!")); return false; } final us.talabrek.ultimateskyblock.api.IslandInfo islandInfo = plugin.getIslandInfo(info); if (islandInfo == null || islandInfo.getIslandLocation() == null) { player.sendMessage(tr("\u00a74That player is invalid or does not have an island!")); return false; } final boolean shouldRecalculate = player.getName().equals(info.getPlayerName()) || player.hasPermission("usb.admin.island"); final Runnable showInfo = () -> { if (player != null && player.isOnline() && info != null) { player.sendMessage(tr("\u00a7eInformation about {0}''s Island:", islandPlayer)); if (cmd.equalsIgnoreCase("level")) { IslandRank rank = plugin.getIslandLogic().getRank(info.locationForParty()); if (rank != null) { player.sendMessage(new String[]{ tr("\u00a7aIsland level is {0,number,###.##}", rank.getScore()), tr("\u00a79Rank is {0}", rank.getRank()) }); } else { player.sendMessage(tr("\u00a74Could not locate rank of {0}", islandPlayer)); } } } }; if (shouldRecalculate) { plugin.getServer().getScheduler().runTaskLater(plugin, () -> plugin.calculateScoreAsync(player, info.locationForParty(), new Callback<us.talabrek.ultimateskyblock.api.model.IslandScore>() { @Override public void run() { plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, showInfo, 10L); } }), 1L); } else { showInfo.run(); } return true; }
Example 5
Source File: UhcTeam.java From UhcCore with GNU General Public License v3.0 | 5 votes |
public boolean isOnline(){ int membersOnline = 0; for(UhcPlayer uhcPlayer : getMembers()){ try{ Player player = uhcPlayer.getPlayer(); if(player.isOnline()) membersOnline++; }catch(UhcPlayerNotOnlineException e){ // not adding playing to count } } return (membersOnline > 0); }
Example 6
Source File: CommandOpenMenu.java From TrMenu with MIT License | 5 votes |
@Override public void onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length < 1) { TLocale.sendTo(sender, "COMMANDS.HELP-PAGE", TrMenu.getPlugin().getDescription().getVersion(), label.toUpperCase().charAt(0) + label.substring(1)); return; } Menu menu = TrMenuAPI.getMenu(args[0]); if (menu == null) { TLocale.sendTo(sender, "MENU.NOT-EXIST"); return; } if (args.length == 1) { if (sender instanceof Player) { menu.open((Player) sender, true); } else { TLocale.sendTo(sender, "COMMANDS.NOT-PLAYER"); } } if (args.length >= 2) { Player player = Bukkit.getPlayerExact(args[1]); if (player == null || !player.isOnline()) { TLocale.sendTo(sender, "COMMANDS.NO-PLAYER"); } else { menu.open(player, true); if (!(args.length >= 3 && "silent".equalsIgnoreCase(args[2]))) { TLocale.sendTo(sender, "COMMANDS.OPENED-FOR"); } } } }
Example 7
Source File: PlayerInfo.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public boolean addPermissions(@Nullable List<String> perms) { if (perms == null || perms.isEmpty()) { return true; } Player target = getPlayer(); Optional<PermissionsHook> hook = plugin.getHookManager().getPermissionsHook(); if (target != null && target.isOnline() && hook.isPresent()) { List<String> permList = playerData.getStringList("player.perms"); PermissionsHook pHook = hook.get(); for (String perm : perms) { if (pHook.hasPermission(target, perm)) { permList.add(perm); pHook.addPermission(target, perm); } } playerData.set("player.perms", permList); save(); return true; } else { List<String> pending = playerData.getStringList("pending-permissions"); pending.addAll(perms); playerData.set("pending-permissions", pending); save(); return false; } }
Example 8
Source File: PlayerGroup.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
/** * Sends a message to all players in the group. * <p> * Supports color codes. * * @param message the message to sent * @param except Players who shall not receive the message */ default void sendMessage(String message, Player... except) { members: for (Player player : getMembers().getOnlinePlayers()) { if (!player.isOnline()) { continue; } for (Player nope : except) { if (player == nope) { continue members; } } MessageUtil.sendMessage(player, message); } }
Example 9
Source File: NickNamerPlugin.java From NickNamer with MIT License | 5 votes |
@Override public void sendPluginMessage(Player player, String action, String... values) { if (!bungeecord) { return; } if (player == null || !player.isOnline()) { return; } ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF(action); out.writeUTF(player.getUniqueId().toString()); for (String s : values) { out.writeUTF(s); } player.sendPluginMessage(instance, channelIdentifier, out.toByteArray()); }
Example 10
Source File: IslandInfo.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public void sendMessageToIslandGroup(boolean broadcast, @NotNull String message, @Nullable Object... args) { Validate.notNull(message, "Message cannot be null"); Validate.notEmpty(message, "Message cannot be empty"); if (broadcast) { for (UUID uuid : getMemberUUIDs()) { Player player = plugin.getPlayerDB().getPlayer(uuid); if (player != null && player.isOnline()) { player.sendMessage(tr("\u00a7cSKY \u00a7f> \u00a77 {0}", tr(message, args))); } } } log(message, args); }
Example 11
Source File: RecalculateRunnable.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@Override public void run() { Set<String> recalcIslands = new HashSet<>(); for (Player player : plugin.getWorldManager().getWorld().getPlayers()) { if (player.isOnline() && plugin.playerIsOnIsland(player)) { recalcIslands.add(plugin.getPlayerInfo(player).locationForParty()); } } if (!recalcIslands.isEmpty()) { RecalculateTopTen runnable = new RecalculateTopTen(plugin, recalcIslands); runnable.runTaskAsynchronously(plugin); } }
Example 12
Source File: BanUtils.java From FunnyGuilds with Apache License 2.0 | 5 votes |
public static void ban(Guild guild, long time, String reason) { guild.setBan(time + System.currentTimeMillis()); for (User user : guild.getMembers()) { ban(user, time, reason); Player p = user.getPlayer(); if (p != null && p.isOnline()) { p.kickPlayer(getBanMessage(user)); } } }
Example 13
Source File: Messages.java From askyblock with GNU General Public License v2.0 | 5 votes |
/** * Sets a message for the player to receive next time they login * * @param playerUUID - the player's UUID - player's UUID * @param message - message to set * @return true if player is offline, false if online */ public boolean setMessage(UUID playerUUID, String message) { // getLogger().info("DEBUG: received message - " + message); Player player = plugin.getServer().getPlayer(playerUUID); // Check if player is online if (player != null) { if (player.isOnline()) { // Util.sendMessage(player, message); return false; } } storeMessage(playerUUID, message); return true; }
Example 14
Source File: BackpackCommand.java From MarriageMaster with GNU General Public License v3.0 | 5 votes |
private void openBackpack(MarriagePlayer opener, MarriagePlayer partner) { Player sender = opener.getPlayerOnline(); if(sender.getGameMode() == GameMode.SURVIVAL || sender.hasPermission(Permissions.BYPASS_BACKPACK_GAME_MODE)) //TODO use minepacks settings { Player partnerPlayer = partner.getPlayerOnline(); if(partnerPlayer == null || !partnerPlayer.isOnline()) { ((MarriageMaster) getMarriagePlugin()).messagePartnerOffline.send(sender); } else if(partner.isSharingBackpack()) { if(getMarriagePlugin().isInRangeSquared(sender, partnerPlayer, range)) { ((MarriageMaster) getMarriagePlugin()).getBackpacksIntegration().openBackpack(sender, partnerPlayer, true); messageOpened.send(partnerPlayer); } else { ((MarriageMaster) getMarriagePlugin()).messagePartnerNotInRange.send(sender); } } else { messageShareDenied.send(sender); } } else { messageOnlyInSurvival.send(sender); } }
Example 15
Source File: TownMenu.java From Civs with GNU General Public License v3.0 | 4 votes |
@Override public boolean doActionAndCancel(Civilian civilian, String actionString, ItemStack clickedItem) { Town town = (Town) MenuManager.getData(civilian.getUuid(), Constants.TOWN); Player player = Bukkit.getPlayer(civilian.getUuid()); if (player == null || town == null) { return true; } String townName = town.getName(); Object selectedTownObject = MenuManager.getData(civilian.getUuid(), Constants.SELECTED_TOWN); Town selectedTown; if (selectedTownObject == null) { selectedTown = TownManager.getInstance().isOwnerOfATown(civilian); } else if (selectedTownObject instanceof String) { selectedTown = TownManager.getInstance().getTown((String) selectedTownObject); } else { selectedTown = (Town) selectedTownObject; } if ("ally".equals(actionString)) { if (selectedTown == null || town.getAllyInvites().contains(selectedTown.getName())) { return true; } town.getAllyInvites().add(selectedTown.getName()); player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders(player, "town-ally-request-sent").replace("$1", townName)); for (UUID uuid : town.getRawPeople().keySet()) { if (town.getRawPeople().get(uuid).contains(Constants.OWNER)) { Player pSend = Bukkit.getPlayer(uuid); if (pSend != null && pSend.isOnline()) { pSend.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders(pSend, "town-ally-request-sent").replace("$1", townName)); } } } return true; } else if (actionString.equals("unally")) { if (selectedTown == null) { return true; } AllianceManager.getInstance().unAlly(selectedTown, town); for (Player cPlayer : Bukkit.getOnlinePlayers()) { cPlayer.sendMessage(Civs.getPrefix() + ChatColor.RED + LocaleManager.getInstance() .getTranslationWithPlaceholders(cPlayer, "town-ally-removed") .replace("$1", selectedTown.getName()) .replace("$2", townName)); } return true; } else if (actionString.equals("join-revolt")) { CVItem costItem = CVItem.createCVItemFromString(ConfigManager.getInstance().getRevoltCost()); if (!player.getInventory().contains(costItem.createItemStack())) { player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders( player, "item-cost").replace("$1", "" + costItem.getQty()) .replace("$2", costItem.getMat().name())); return true; } player.getInventory().removeItem(costItem.createItemStack()); town.getRevolt().add(civilian.getUuid()); TownManager.getInstance().saveTown(town); return true; } else if (actionString.equals("leave-revolt")) { town.getRevolt().remove(civilian.getUuid()); TownManager.getInstance().saveTown(town); return true; } return super.doActionAndCancel(civilian, actionString, clickedItem); }
Example 16
Source File: InviteCommand.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
@Override protected boolean doExecute(String alias, Player player, PlayerInfo pi, IslandInfo island, Map<String, Object> data, String... args) { if (args.length == 0) { player.sendMessage(I18nUtil.tr("\u00a7eUse\u00a7f /island invite <playername>\u00a7e to invite a player to your island.")); if (!island.isParty()) { return true; } if (!island.isLeader(player) || !island.hasPerm(player, "canInviteOthers")) { player.sendMessage(I18nUtil.tr("\u00a74Only the island''s owner can invite!")); return true; } int diff = island.getMaxPartySize() - island.getPartySize(); if (diff > 0) { player.sendMessage(I18nUtil.tr("\u00a7aYou can invite {0} more players.", diff)); } else { player.sendMessage(I18nUtil.tr("\u00a74You can't invite any more players.")); } } if (args.length == 1) { //noinspection deprecation Player otherPlayer = Bukkit.getPlayer(args[0]); if (!island.hasPerm(player, "canInviteOthers")) { player.sendMessage(I18nUtil.tr("\u00a74You do not have permission to invite others to this island!")); return true; } if (otherPlayer == null || !otherPlayer.isOnline()) { player.sendMessage(I18nUtil.tr("\u00a74That player is offline or doesn't exist.")); return true; } if (player.getName().equalsIgnoreCase(otherPlayer.getName())) { player.sendMessage(I18nUtil.tr("\u00a74You can't invite yourself!")); return true; } if (island.isLeader(otherPlayer)) { player.sendMessage(I18nUtil.tr("\u00a74That player is the leader of your island!")); return true; } plugin.getServer().getPluginManager().callEvent(new InviteEvent(player, island, otherPlayer)); } return true; }
Example 17
Source File: ChatPacketInterceptor.java From ChatMenuAPI with GNU Lesser General Public License v3.0 | 4 votes |
public PlayerChatIntercept getChat(Player player) { if(player == null || !player.isOnline()) return null; return chats.computeIfAbsent(player, this::intercept); }
Example 18
Source File: ChannelPlayerName.java From LunaChat with GNU Lesser General Public License v3.0 | 4 votes |
/** * オンラインかどうか * @return オンラインかどうか */ @Override public boolean isOnline() { Player player = getPlayer(); return (player != null && player.isOnline()); }
Example 19
Source File: LPBukkitBootstrap.java From LuckPerms with MIT License | 4 votes |
@Override public boolean isPlayerOnline(UUID uniqueId) { Player player = getServer().getPlayer(uniqueId); return player != null && player.isOnline(); }
Example 20
Source File: PlayerStateHolder.java From HeavySpleef with GNU General Public License v3.0 | 4 votes |
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); }