Java Code Examples for org.bukkit.OfflinePlayer#isOnline()
The following examples show how to use
org.bukkit.OfflinePlayer#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: NicknameUpdater.java From DiscordSRV with GNU General Public License v3.0 | 6 votes |
public void setNickname(Member member, OfflinePlayer offlinePlayer) { String nickname; if (offlinePlayer.isOnline()) { Player player = offlinePlayer.getPlayer(); nickname = DiscordSRV.config().getString("NicknameSynchronizationFormat") .replace("%displayname%", player.getDisplayName() != null ? player.getDisplayName() : player.getName()) .replace("%username%", player.getName()); nickname = PlaceholderUtil.replacePlaceholders(nickname, player); } else { nickname = offlinePlayer.getName(); } nickname = DiscordUtil.strip(nickname); DiscordUtil.setNickname(member, nickname); }
Example 2
Source File: PlaceholderAPISupport.java From Crazy-Crates with MIT License | 6 votes |
@Override public String onRequest(OfflinePlayer player, String identifier) { if (player.isOnline()) { Player playerOnline = (Player) player; for (Crate crate : cc.getCrates()) { if (crate.getCrateType() != CrateType.MENU) { if (identifier.equalsIgnoreCase(crate.getName())) { return NumberFormat.getNumberInstance().format(cc.getVirtualKeys(playerOnline, crate)); } else if (identifier.equalsIgnoreCase(crate.getName() + "_physical")) { return NumberFormat.getNumberInstance().format(cc.getPhysicalKeys(playerOnline, crate)); } else if (identifier.equalsIgnoreCase(crate.getName() + "_total")) { return NumberFormat.getNumberInstance().format(cc.getTotalKeys(playerOnline, crate)); } } } } return ""; }
Example 3
Source File: EntityDamageListener.java From SaneEconomy with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onEntityDeath(EntityDeathEvent evt) { LivingEntity entity = evt.getEntity(); if (!this.damageDealt.containsKey(entity.getEntityId())) { return; } Map<UUID, Double> damageDoneToThisEntity = this.damageDealt.get(entity.getEntityId()); double totalDmg = entity.getMaxHealth();//sumValues(damageDoneToThisEntity); for (Map.Entry<UUID, Double> entry : damageDoneToThisEntity.entrySet()) { double thisDmg = entry.getValue(); double thisPercent = (thisDmg / totalDmg) * 100.0D; double thisAmount = this.plugin.getKillAmounts().get(this.getEntityType(entity)) * (thisPercent / 100); OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(entry.getKey()); if (offlinePlayer.isOnline()) { Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId()); this.plugin.getMessenger().sendMessage(player, "You have been awarded {1} for doing {2:.2f}% of the damage required to kill that {3}!", this.plugin.getSaneEconomy().getEconomyManager().getCurrency().formatAmount(BigDecimal.valueOf(thisAmount)), thisPercent, entity.getName()); } this.plugin.getSaneEconomy().getEconomyManager().transact(new Transaction( this.plugin.getSaneEconomy().getEconomyManager().getCurrency(), Economable.PLUGIN, Economable.wrap(offlinePlayer), BigDecimal.valueOf(thisAmount), TransactionReason.PLUGIN_GIVE )); } this.damageDealt.remove(evt.getEntity().getEntityId()); }
Example 4
Source File: UtilityBukkit.java From LunaChat with GNU Lesser General Public License v3.0 | 5 votes |
/** * 指定された名前のオフラインプレイヤーを取得する * @param name プレイヤー名 * @return オフラインプレイヤー */ @SuppressWarnings("deprecation") public static OfflinePlayer getOfflinePlayer(String name) { if (name == null) return null; OfflinePlayer player = Bukkit.getOfflinePlayer(name); if (player == null || (!player.hasPlayedBefore() && !player.isOnline())) return null; return player; }
Example 5
Source File: ListenerCombatChecks.java From CombatLogX with GNU General Public License v3.0 | 5 votes |
private void checkEnemyDeathUntag(LivingEntity enemy) { if(enemy == null) return; FileConfiguration config = this.plugin.getConfig("config.yml"); if(!config.getBoolean("untag.on-enemy-death")) return; ICombatManager combatManager = this.plugin.getCombatManager(); OfflinePlayer offline = combatManager.getByEnemy(enemy); if(offline == null || !offline.isOnline()) return; Player player = offline.getPlayer(); if(player == null || !combatManager.isInCombat(player)) return; combatManager.untag(player, PlayerUntagEvent.UntagReason.EXPIRE_ENEMY_DEATH); }
Example 6
Source File: MemoryPlayerDB.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@Override public String getDisplayName(String playerName) { OfflinePlayer offlinePlayer = getOfflinePlayer(playerName, true); return offlinePlayer != null && offlinePlayer.isOnline() && offlinePlayer.getPlayer() != null ? offlinePlayer.getPlayer().getDisplayName() : null; }
Example 7
Source File: VaultOperations.java From PlayerVaults with GNU General Public License v3.0 | 5 votes |
/** * Get the max size vault a player is allowed to have. * * @param player that is having his permissions checked. * @return max size as integer. If no max size is set then it will default to the configured default. */ public static int getMaxVaultSize(OfflinePlayer player) { if (player == null || !player.isOnline()) { return PlayerVaults.getInstance().getDefaultVaultSize(); } for (int i = 6; i != 0; i--) { if (player.getPlayer().hasPermission("playervaults.size." + i)) { return i * 9; } } return PlayerVaults.getInstance().getDefaultVaultSize(); }
Example 8
Source File: Teams.java From CardinalPGM with MIT License | 5 votes |
public static ChatColor getTeamColorByPlayer(OfflinePlayer player) { if (player.isOnline()) { Optional<TeamModule> team = getTeamByPlayer(player.getPlayer()); if (team.isPresent()) return team.get().getColor(); else return ChatColor.YELLOW; } else return ChatColor.DARK_AQUA; }
Example 9
Source File: TrustCommand.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@Override protected boolean doExecute(final String alias, final Player player, final PlayerInfo pi, final IslandInfo island, Map<String, Object> data, String... args) { if (args.length == 0) { player.sendMessage(tr("\u00a7eThe following players are trusted on your island:")); player.sendMessage(tr("\u00a74{0}", island.getTrustees())); player.sendMessage(tr("\u00a7eThe following leaders trusts you:")); player.sendMessage(tr("\u00a74{0}", getLeaderNames(pi))); player.sendMessage(tr("\u00a7eTo trust/untrust from your island, use /island trust <player>")); return true; } else if (args.length == 1) { final String name = args[0]; if (island.getMembers().contains(name)) { player.sendMessage(tr("\u00a74Members are already trusted!")); return true; } //noinspection deprecation OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name); if (!offlinePlayer.hasPlayedBefore() && !offlinePlayer.isOnline()) { player.sendMessage(tr("\u00a74Unknown player {0}", name)); return true; } if (alias.equals("trust")) { island.trustPlayer(offlinePlayer, player); if (offlinePlayer.isOnline()) { offlinePlayer.getPlayer().sendMessage(tr("\u00a7eYou are now trusted on \u00a74{0}''s \u00a7eisland.", pi.getDisplayName())); } island.sendMessageToIslandGroup(true, marktr("\u00a7a{0} trusted {1} on the island"), player.getName(), name); } else { island.untrustPlayer(offlinePlayer, player); if (offlinePlayer.isOnline()) { offlinePlayer.getPlayer().sendMessage(tr("\u00a7eYou are no longer trusted on \u00a74{0}''s \u00a7eisland.", pi.getDisplayName())); } island.sendMessageToIslandGroup(true, marktr("\u00a7c{0} revoked trust in {1} on the island"), player.getName(), name); } WorldGuardHandler.updateRegion(island); return true; } return false; }
Example 10
Source File: MailboxCommands.java From NyaaUtils with MIT License | 5 votes |
public void removeMailbox(Player admin, OfflinePlayer player) { if (plugin.cfg.mailbox.getMailboxLocation(player.getUniqueId()) == null) { msg(admin, "user.mailbox.admin.no_mailbox"); } else { UUID id = player.getUniqueId(); plugin.cfg.mailbox.updateLocationMapping(id, null); msg(admin, "user.mailbox.admin.success_remove"); if (player.isOnline()) { msg((Player) player, "user.mailbox.admin.player_hint_removed"); } } }
Example 11
Source File: MemoryPlayerDB.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@Override public String getDisplayName(UUID uuid) { OfflinePlayer offlinePlayer = getOfflinePlayer(uuid); return offlinePlayer != null && offlinePlayer.isOnline() && offlinePlayer.getPlayer() != null ? offlinePlayer.getPlayer().getDisplayName() : null; }
Example 12
Source File: Main.java From PlayTimeTracker with MIT License | 5 votes |
private void printStatistic(CommandSender s, OfflinePlayer p) { s.sendMessage(Locale.get("statistic-for", p.getName())); SessionedRecord rec = updater.getFullRecord(p.getUniqueId()); if (rec.dbRec == null) { s.sendMessage(Locale.get("statistic-no-record")); } else { s.sendMessage(Locale.get("statistic-day", Locale.formatTime(rec.dbRec.dailyTime))); s.sendMessage(Locale.get("statistic-week", Locale.formatTime(rec.dbRec.weeklyTime))); s.sendMessage(Locale.get("statistic-month", Locale.formatTime(rec.dbRec.monthlyTime))); s.sendMessage(Locale.get("statistic-total", Locale.formatTime(rec.dbRec.totalTime))); if (p.isOnline() && rec.getSessionTime() > 0) { s.sendMessage(Locale.get("statistic-session", Locale.formatTime(rec.getSessionTime()))); } } }
Example 13
Source File: FunctionalUtil.java From UHC with MIT License | 4 votes |
@Override public boolean apply(OfflinePlayer input) { return input != null && input.isOnline(); }
Example 14
Source File: DGroup.java From DungeonsXL with GNU General Public License v3.0 | 4 votes |
public boolean teleport() { if (dungeon == null || dungeon.getMap() == null) { sendMessage(DMessage.ERROR_NO_SUCH_DUNGEON.getMessage()); return false; } GameWorld target = dungeon.getMap().instantiateGameWorld(false); Game game = getGame(); if (target == null && game != null) { target = game.getWorld(); } if (target == null) { if (game != null) { for (PlayerGroup otherTeam : game.getGroups()) { if (otherTeam.getGameWorld() != null) { target = otherTeam.getGameWorld(); break; } } } } if (target == null && dungeon != null) { ResourceWorld resource = dungeon.getMap(); if (resource != null) { target = resource.instantiateGameWorld(false); if (target == null) { sendMessage(DMessage.ERROR_TOO_MANY_INSTANCES.getMessage()); return false; } gameWorld = target; } } if (target == null) { sendMessage(DMessage.ERROR_NO_SUCH_DUNGEON.getMessage()); return false; } if (game == null) { game = new DGame(plugin, this, target); } else { game.setWorld(target); gameWorld = target; } for (OfflinePlayer offline : players.getOfflinePlayers()) { if (!offline.isOnline()) { players.remove(offline); } Player player = offline.getPlayer(); new DGamePlayer(plugin, player, target); } return true; }
Example 15
Source File: JdbcAccountLinkManager.java From DiscordSRV with GNU General Public License v3.0 | 4 votes |
@Override public String process(String code, String discordId) { UUID existingUuid = getUuid(discordId); boolean alreadyLinked = existingUuid != null; if (alreadyLinked) { if (DiscordSRV.config().getBoolean("MinecraftDiscordAccountLinkedAllowRelinkBySendingANewCode")) { unlink(discordId); } else { OfflinePlayer offlinePlayer = DiscordSRV.getPlugin().getServer().getOfflinePlayer(existingUuid); return LangUtil.InternalMessage.ALREADY_LINKED.toString() .replace("{username}", String.valueOf(offlinePlayer.getName())) .replace("{uuid}", offlinePlayer.getUniqueId().toString()); } } // strip the code to get rid of non-numeric characters code = code.replaceAll("[^0-9]", ""); UUID uuid = getLinkingCodes().get(code); if (uuid != null) { link(discordId, uuid); try (final PreparedStatement statement = connection.prepareStatement("delete from " + codesTable + " where `code` = ?")) { statement.setString(1, code); statement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); if (player.isOnline()) { player.getPlayer().sendMessage(LangUtil.Message.MINECRAFT_ACCOUNT_LINKED.toString() .replace("%username%", DiscordUtil.getUserById(discordId).getName()) .replace("%id%", DiscordUtil.getUserById(discordId).getId()) ); } return LangUtil.Message.DISCORD_ACCOUNT_LINKED.toString() .replace("%name%", player.getName() != null ? player.getName() : "<Unknown>") .replace("%uuid%", uuid.toString()); } return code.length() == 4 ? LangUtil.InternalMessage.UNKNOWN_CODE.toString() : LangUtil.InternalMessage.INVALID_CODE.toString(); }
Example 16
Source File: PayCommand.java From SaneEconomy with GNU General Public License v3.0 | 4 votes |
@Override protected void onCommand(CommandSender sender, String[] args) throws CommandException { if (args.length != 2) { throw CommandException.makeArgumentException(2, args.length); } /* Doesn't make sense for console to pay a player, and admins paying a player is best done with /ecoadmin give */ if (!(sender instanceof Player)) { throw new NeedPlayerException(); } EconomyManager ecoMan = this.saneEconomy.getEconomyManager(); Player fromPlayer = (Player) sender; String sToPlayer = args[0]; OfflinePlayer toPlayer = PlayerUtils.getOfflinePlayer(sToPlayer); if (toPlayer == null) { this.saneEconomy.getMessenger().sendMessage(sender, "That player does not exist or has never played before."); return; } if (toPlayer.getUniqueId().equals(fromPlayer.getUniqueId())) { this.saneEconomy.getMessenger().sendMessage(sender, "You cannot pay yourself."); return; } if (!this.saneEconomy.getConfig().getConfigurationSection("economy").getBoolean("pay-offline-players", true) && !toPlayer.isOnline()) { this.saneEconomy.getMessenger().sendMessage(sender, "You cannot pay an offline player."); return; } String sAmount = args[1]; BigDecimal amount = NumberUtils.parseAndFilter(ecoMan.getCurrency(), sAmount); if (amount.compareTo(BigDecimal.ZERO) <= 0) { this.saneEconomy.getMessenger().sendMessage(sender, "{1} is not a positive number.", ((amount.equals(BigDecimal.ONE.negate())) ? sAmount : String.valueOf(amount))); return; } /* Perform the actual transfer. False == They didn't have enough money */ Transaction transaction = new Transaction(ecoMan.getCurrency(), Economable.wrap(fromPlayer), Economable.wrap(toPlayer), amount, TransactionReason.PLAYER_PAY); TransactionResult result = ecoMan.transact(transaction); if (result.getStatus() != TransactionResult.Status.SUCCESS) { this.saneEconomy.getMessenger().sendMessage(sender, "You do not have enough money to transfer {1} to {2}.", ecoMan.getCurrency().formatAmount(amount), sToPlayer ); return; } /* Inform the relevant parties. */ this.saneEconomy.getMessenger().sendMessage(sender, "You have transferred {1} to {2}.", ecoMan.getCurrency().formatAmount(amount), sToPlayer ); if (toPlayer.isOnline()) { this.saneEconomy.getMessenger().sendMessage(((CommandSender) toPlayer), "You have received {1} from {2}.", ecoMan.getCurrency().formatAmount(amount), fromPlayer.getDisplayName() ); } }
Example 17
Source File: TeamupCommand.java From UHC with MIT License | 4 votes |
@Override protected boolean runCommand(CommandSender sender, OptionSet options) { final List<OfflinePlayer> players = playersSpec.values(options); if (players.size() == 0) { sender.sendMessage(messages.getRaw("supply one player")); return true; } final Team team; // if they're specifying a team name to use if (options.has(teamNameSpec)) { final String teamName = teamNameSpec.value(options); team = teamModule.getScoreboard().getTeam(teamName); if (team == null) { sender.sendMessage(messages.evalTemplate("doesnt exist", ImmutableMap.of("name", teamName))); return true; } if (team.getPlayers().size() > 0) { sender.sendMessage(messages.getRaw("not empty")); return true; } } else { // grab the first UHC team available final Optional<Team> teamOptional = teamModule.findFirstEmptyTeam(); if (!teamOptional.isPresent()) { sender.sendMessage(messages.getRaw("no uhc teams")); return true; } team = teamOptional.get(); } final String members = Joiner.on(", ").join(Iterables.transform(players, FunctionalUtil.PLAYER_NAME_FETCHER)); final Map<String, String> context = ImmutableMap.<String, String>builder() .put("prefix", team.getPrefix()) .put("name", team.getName()) .put("display name", team.getDisplayName()) .put("players", members) .put("count", String.valueOf(players.size())) .build(); final String teamNotification = messages.evalTemplate("teamup notification", context); for (final OfflinePlayer player : players) { team.addPlayer(player); if (player.isOnline()) { player.getPlayer().sendMessage(teamNotification); } } sender.sendMessage(messages.evalTemplate("completed", context)); return true; }
Example 18
Source File: TutorialManager.java From Civs with GNU General Public License v3.0 | 4 votes |
public void completeStep(Civilian civilian, TutorialType type, String param) { if (!ConfigManager.getInstance().isUseTutorial()) { return; } if (civilian.getTutorialIndex() == -1) { return; } TutorialPath path = tutorials.get(civilian.getTutorialPath()); if (path == null) { return; } if (path.getSteps().size() <= civilian.getTutorialIndex()) { return; } TutorialStep step = path.getSteps().get(civilian.getTutorialIndex()); if (step == null) { return; } if (!step.getType().equalsIgnoreCase(type.toString())) { return; } if ((type.equals(TutorialType.BUILD) || type.equals(TutorialType.UPKEEP) || type.equals(TutorialType.BUY)) && !param.equalsIgnoreCase(step.getRegion())) { return; } if (type.equals(TutorialType.KILL) && !param.equals(step.getKillType())) { return; } int progress = civilian.getTutorialProgress(); int maxProgress = step.getTimes(); if (progress + 1 < maxProgress) { civilian.setTutorialProgress(progress + 1); CivilianManager.getInstance().saveCivilian(civilian); // TODO send message of progress made? return; } OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(civilian.getUuid()); Player player = null; if (offlinePlayer.isOnline()) { player = offlinePlayer.getPlayer(); } ArrayList<CVItem> itemList = step.getRewardItems(); if (itemList != null && !itemList.isEmpty() && player != null && player.isOnline()) { giveItemsToPlayer(player, itemList); } double money = step.getRewardMoney(); if (money > 0 && Civs.econ != null) { Civs.econ.depositPlayer(offlinePlayer, money); } List<String> permissions = step.getPermissions(); if (Civs.perm != null && !permissions.isEmpty()) { for (String permission : permissions) { PermissionUtil.applyPermission(offlinePlayer, permission); } } List<String> commands = step.getCommands(); if (!commands.isEmpty()) { for (String command : commands) { CommandUtil.performCommand(offlinePlayer, command); } } civilian.setTutorialProgress(0); civilian.setTutorialIndex(civilian.getTutorialIndex() + 1); CivilianManager.getInstance().saveCivilian(civilian); Util.spawnRandomFirework(player); sendMessageForCurrentTutorialStep(civilian, true); }
Example 19
Source File: Permission.java From VaultAPI with GNU Lesser General Public License v3.0 | 3 votes |
/** * Add transient permission to a player. * This implementation can be used by any subclass which implements a "pure" superperms plugin, i.e. * one that only needs the built-in Bukkit API to add transient permissions to a player. * * @param player to add to * @param permission Permission node * @return Success or Failure */ public boolean playerAddTransient(OfflinePlayer player, String permission) throws UnsupportedOperationException { if (player.isOnline()) { return playerAddTransient((Player) player, permission); } throw new UnsupportedOperationException(getName() + " does not support offline player transient permissions!"); }
Example 20
Source File: PlaceholderHook.java From PlaceholderAPI with GNU General Public License v3.0 | 3 votes |
/** * called when a placeholder value is requested from this hook * * @param p {@link OfflinePlayer} to request the placeholder value for, null if not needed for a * player * @param params String passed to the hook to determine what value to return * @return value for the requested player and params */ public String onRequest(OfflinePlayer p, String params) { if (p != null && p.isOnline()) { return onPlaceholderRequest((Player) p, params); } return onPlaceholderRequest(null, params); }