Java Code Examples for org.bukkit.OfflinePlayer#getPlayer()
The following examples show how to use
org.bukkit.OfflinePlayer#getPlayer() .
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: AreaShop.java From AreaShop with GNU General Public License v3.0 | 6 votes |
/** * Check for a permission of a (possibly offline) player. * @param offlinePlayer OfflinePlayer to check * @param permission Permission to check * @return true if the player has the permission, false if the player does not have permission or, is offline and there is not Vault-compatible permission plugin */ public boolean hasPermission(OfflinePlayer offlinePlayer, String permission) { // Online, return through Bukkit if(offlinePlayer.getPlayer() != null) { return offlinePlayer.getPlayer().hasPermission(permission); } // Resolve while offline if possible net.milkbowl.vault.permission.Permission permissionProvider = getPermissionProvider(); if(permissionProvider != null) { // TODO: Should we provide a world here? return permissionProvider.playerHas(null, offlinePlayer, permission); } // Player offline and no offline permission provider available, safely say that there is no permission return false; }
Example 3
Source File: BanCommand.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@Override public void admin(CommandSender sender, String[] args, Island island) { if (args.length != 4) { sender.sendMessage(Utils.color(IridiumSkyblock.getConfiguration().prefix) + "/is admin <island> ban <player>"); sender.sendMessage("/is admin <island> ban <player>"); return; } if (island != null) { OfflinePlayer player = Bukkit.getOfflinePlayer(args[3]); if (player != null) { if (!island.equals(User.getUser(player).getIsland())) { island.addBan(User.getUser(player)); sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().playerBanned.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); if (player.getPlayer() != null) { if (island.isInIsland(player.getPlayer().getLocation())) { player.getPlayer().sendMessage(Utils.color(IridiumSkyblock.getMessages().bannedFromIsland.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); island.spawnPlayer(player.getPlayer()); } } } } else { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().playerOffline.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } } else { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } }
Example 4
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 5
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 6
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 7
Source File: PrettyUtil.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("ConstantConditions") // you should know bukkit public static String beautifyNickname(OfflinePlayer player, String noUsernameFormat, boolean includeUuid) { if (player == null || player.getName() == null) return noUsernameFormat; if (player.isOnline()) { if (player.getPlayer() == null) return beautifyUsername(player); String displayName = player.getPlayer().getDisplayName(); if (displayName == null || StringUtils.isBlank(displayName)) return beautifyUsername(player); return DiscordUtil.strip(displayName) + (includeUuid ? " (" + player.getUniqueId() + ")" : ""); } else { return beautifyUsername(player); } }
Example 8
Source File: CommandUtil.java From Civs with GNU General Public License v3.0 | 5 votes |
public static void performCommand(OfflinePlayer offlinePlayer, String command) { String finalCommand = command; boolean runAsOp = false; boolean runFromConsole = false; for (;;) { if (finalCommand.startsWith("^")) { runAsOp = true; finalCommand = finalCommand.substring(1); } else if (finalCommand.startsWith("!")) { runFromConsole = true; finalCommand = finalCommand.substring(1); } else { break; } } if (offlinePlayer.isOnline()) { finalCommand = finalCommand.replace("$name$", ((Player) offlinePlayer).getName()); } else { Player player1 = offlinePlayer.getPlayer(); if (player1 != null && player1.isValid()) { finalCommand = finalCommand.replace("$name$", player1.getName()); } } if (runFromConsole) { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), finalCommand); } else if (offlinePlayer.isOnline()) { Player player = (Player) offlinePlayer; boolean setOp = runAsOp && !player.isOp(); if (setOp) { player.setOp(true); } player.performCommand(finalCommand); if (setOp) { player.setOp(false); } } }
Example 9
Source File: MsgUtil.java From QuickShop-Reremake with GNU General Public License v3.0 | 5 votes |
/** * @param player The name of the player to message * @param message The message to send them Sends the given player a message if they're online. * Else, if they're not online, queues it for them in the database. * @param isUnlimited The shop is or unlimited */ public static void send(@NotNull UUID player, @NotNull String message, boolean isUnlimited) { if (plugin.getConfig().getBoolean("shop.ignore-unlimited-shop-messages") && isUnlimited) { return; // Ignore unlimited shops messages. } Util.debugLog(message); String[] msgData = message.split("##########"); OfflinePlayer p = Bukkit.getOfflinePlayer(player); if (!p.isOnline()) { LinkedList<String> msgs = player_messages.get(player); if (msgs == null) { msgs = new LinkedList<>(); } player_messages.put(player, msgs); msgs.add(message); plugin.getDatabaseHelper().sendMessage(player, message, System.currentTimeMillis()); } else { if (p.getPlayer() != null) { try { sendItemholochat(p.getPlayer(), msgData[0], Objects.requireNonNull(Util.deserialize(msgData[1])), msgData[2]); } catch (InvalidConfigurationException e) { Util.debugLog("Unknown error, send by plain text."); MsgUtil.sendMessage(p.getPlayer(),msgData[0] + msgData[1] + msgData[2]); } catch (ArrayIndexOutOfBoundsException e2) { try { sendItemholochat(p.getPlayer(), msgData[0], Objects.requireNonNull(Util.deserialize(msgData[1])), ""); } catch (Exception any) { // Normal msg MsgUtil.sendMessage(p.getPlayer(),message); } } } } }
Example 10
Source File: MsgUtil.java From QuickShop-Reremake with GNU General Public License v3.0 | 5 votes |
/** * Empties the queue of messages a player has and sends them to the player. * * @param p The player to message * @return True if success, False if the player is offline or null */ public static boolean flush(@NotNull OfflinePlayer p) { Player player = p.getPlayer(); if (player != null) { UUID pName = p.getUniqueId(); LinkedList<String> msgs = player_messages.get(pName); if (msgs != null) { for (String msg : msgs) { if (p.getPlayer() != null) { Util.debugLog("Accepted the msg for player " + p.getName() + " : " + msg); String[] msgData = msg.split("##########"); try { ItemStack data = Util.deserialize(msgData[1]); if (data == null) { throw new InvalidConfigurationException(); } sendItemholochat(player, msgData[0], data, msgData[2]); } catch (InvalidConfigurationException e) { MsgUtil.sendMessage(p.getPlayer(), msgData[0] + msgData[1] + msgData[2]); } catch (ArrayIndexOutOfBoundsException e2) { MsgUtil.sendMessage(p.getPlayer(), msg); } } } plugin.getDatabaseHelper().cleanMessageForPlayer(pName); msgs.clear(); return true; } } return false; }
Example 11
Source File: GiveCrystalsCommand.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@Override public void execute(CommandSender sender, String[] args) { if (args.length != 3) { sender.sendMessage(Utils.color(IridiumSkyblock.getConfiguration().prefix) + "/is givecrystals <player> <amount>"); return; } if (Bukkit.getPlayer(args[1]) != null) { OfflinePlayer player = Bukkit.getPlayer(args[1]); if (player != null) { Island island = User.getUser(player).getIsland(); if (island != null) { try { int amount = Integer.parseInt(args[2]); island.setCrystals(island.getCrystals() + amount); sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().giveCrystals.replace("%crystals%", args[2]).replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); if (player.getPlayer() != null) player.getPlayer().sendMessage(Utils.color(IridiumSkyblock.getMessages().givenCrystals.replace("%crystals%", args[2]).replace("%player%", sender.getName()).replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } catch (Exception e) { sender.sendMessage(args[2] + "is not a number"); } } else { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().playerNoIsland.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } } else { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().playerOffline.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } } }
Example 12
Source File: KickCommand.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@Override public void execute(CommandSender sender, String[] args) { if (args.length != 2) { sender.sendMessage(Utils.color(IridiumSkyblock.getConfiguration().prefix) + "/is kick <player>"); return; } Player p = (Player) sender; User user = User.getUser(p); // User kicking the player OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]); if (player != null) { User u = User.getUser(player); // Player we want to kick if (user.getIsland() != null) { if (user.getIsland().equals(u.getIsland())) { if (u.role.equals(Role.Owner)) { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().cantKickOwner.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } else { if (user.bypassing || user.getIsland().getPermissions(u.getRole()).kickMembers) { user.getIsland().removeUser(u); if (player.getPlayer() != null) player.getPlayer().sendMessage(Utils.color(IridiumSkyblock.getMessages().youHaveBeenKicked.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } else { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().noPermission.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } } } else { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().notInYourIsland.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } } else { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } } else { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().playerOffline.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } }
Example 13
Source File: InviteCommand.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@Override public void admin(CommandSender sender, String[] args, Island island) { if (args.length != 4) { sender.sendMessage(Utils.color(IridiumSkyblock.getConfiguration().prefix) + "/is admin <island> invite player"); return; } Player p = (Player) sender; OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]); if (player != null) { User u = User.getUser(player); if (island != null) { if (u.getIsland() == null) { u.invites.add(island.getId()); p.sendMessage(Utils.color(IridiumSkyblock.getMessages().playerInvited.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); if (player.getPlayer() != null) { BaseComponent[] components = TextComponent.fromLegacyText(Utils.color(IridiumSkyblock.getMessages().invitedByPlayer.replace("%player%", p.getName()).replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/is join " + p.getName()); HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Click to join players island!").create()); for (BaseComponent component : components) { component.setClickEvent(clickEvent); component.setHoverEvent(hoverEvent); } player.getPlayer().spigot().sendMessage(components); } } else { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().playerAlreadyHaveIsland.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } } else { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } } else { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().playerOffline.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } }
Example 14
Source File: BanCommand.java From IridiumSkyblock with GNU General Public License v2.0 | 5 votes |
@Override public void execute(CommandSender sender, String[] args) { if (args.length != 2) { sender.sendMessage(Utils.color(IridiumSkyblock.getConfiguration().prefix) + "/is ban <player>"); sender.sendMessage("/is ban <player>"); return; } Player p = (Player) sender; User user = User.getUser(p); if (user.getIsland() != null) { OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]); if (player != null) { if (!user.getIsland().equals(User.getUser(player).getIsland())) { user.getIsland().addBan(User.getUser(player)); sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().playerBanned.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); if (player.getPlayer() != null) { if (user.getIsland().isInIsland(player.getPlayer().getLocation())) { player.getPlayer().sendMessage(Utils.color(IridiumSkyblock.getMessages().bannedFromIsland.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); user.getIsland().spawnPlayer(player.getPlayer()); } } } } else { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().playerOffline.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } } else { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } }
Example 15
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 16
Source File: PermissionUtil.java From Civs with GNU General Public License v3.0 | 4 votes |
public static void applyPermission(OfflinePlayer offlinePlayer, String permission) { boolean remove = false; boolean transientPerm = false; String finalPermission = permission; for (;;) { if (finalPermission.startsWith("!")) { remove = true; finalPermission = finalPermission.substring(1); } else if (finalPermission.startsWith("^")) { transientPerm = true; finalPermission = finalPermission.substring(1); } else { break; } } if (offlinePlayer.isOnline()) { Player player = (Player) offlinePlayer; if (transientPerm) { if (remove) { Civs.perm.playerRemove(player, finalPermission); } else { Civs.perm.playerAddTransient(player, finalPermission); } } else { if (remove) { Civs.perm.playerRemove(player, finalPermission); } else { Civs.perm.playerAdd(player, finalPermission); } } } else { Player player1 = offlinePlayer.getPlayer(); if (player1 != null && player1.getLocation().getWorld() != null) { String worldName = player1.getLocation().getWorld().getName(); if (remove) { Civs.perm.playerRemove(worldName, offlinePlayer, finalPermission); } else { Civs.perm.playerAdd(worldName, offlinePlayer, finalPermission); } } } }
Example 17
Source File: MemoryPlayerDB.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
@Override public Player getPlayer(UUID uuid) { OfflinePlayer offlinePlayer = getOfflinePlayer(uuid); return offlinePlayer != null ? offlinePlayer.getPlayer() : null; }
Example 18
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 19
Source File: FunctionalUtil.java From UHC with MIT License | 4 votes |
@Override public Player apply(OfflinePlayer input) { return input == null ? null : input.getPlayer(); }
Example 20
Source File: MemoryPlayerDB.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
@Override public Player getPlayer(String name) { OfflinePlayer offlinePlayer = getOfflinePlayer(name, true); return offlinePlayer != null ? offlinePlayer.getPlayer() : null; }