Java Code Examples for org.bukkit.Bukkit#getOfflinePlayer()
The following examples show how to use
org.bukkit.Bukkit#getOfflinePlayer() .
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: VaultManager.java From UhcCore with GNU General Public License v3.0 | 6 votes |
public static void addMoney(final Player player, final double amount){ Validate.notNull(player); if(!GameManager.getGameManager().getConfiguration().getVaultLoaded()){ return; } if(economy == null){ Bukkit.getLogger().warning("[UhcCore] Vault is not loaded! Couldn't pay "+amount+" to "+player.getName()+"!"); return; } final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(player.getUniqueId()); Bukkit.getScheduler().runTaskAsynchronously(UhcCore.getPlugin(), () -> economy.depositPlayer(offlinePlayer, amount)); }
Example 2
Source File: RegionManager.java From Civs with GNU General Public License v3.0 | 6 votes |
private void runRegionCommands(Region region, List<String> commands) { Set<UUID> owners = region.getOwners(); OfflinePlayer owner = null; if (!owners.isEmpty()) { owner = Bukkit.getOfflinePlayer(owners.iterator().next()); } if (owner == null) { return; } double x = region.getLocation().getX(); double y = region.getLocation().getY(); double z = region.getLocation().getZ(); for (String command : commands) { String newCommand = command.replace("$x$", "" + x) .replace("$y$", "" + y).replace("$z$", "" + z); newCommand = newCommand.replace("$name$", owner.getName()); CommandUtil.performCommand(owner, newCommand); } }
Example 3
Source File: UnBanCommand.java From IridiumSkyblock with GNU General Public License v2.0 | 6 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> unban <player>"); return; } if (island != null) { OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]); if (player != null) { island.removeBan(User.getUser(player)); sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().playerUnBanned.replace("%player%", player.getName()).replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } 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: RentRegion.java From AreaShop with GNU General Public License v3.0 | 6 votes |
@Override public boolean checkInactive() { if(isDeleted() || !isRented()) { return false; } long inactiveSetting = getInactiveTimeUntilUnrent(); OfflinePlayer player = Bukkit.getOfflinePlayer(getRenter()); if(inactiveSetting <= 0 || player.isOp()) { return false; } long lastPlayed = getLastActiveTime(); //AreaShop.debug("currentTime=" + Calendar.getInstance().getTimeInMillis() + ", getLastPlayed()=" + lastPlayed + ", timeInactive=" + (Calendar.getInstance().getTimeInMillis()-player.getLastPlayed()) + ", inactiveSetting=" + inactiveSetting); if(Calendar.getInstance().getTimeInMillis() > (lastPlayed + inactiveSetting)) { AreaShop.info("Region " + getName() + " unrented because of inactivity for player " + getPlayerName()); AreaShop.debug("currentTime=" + Calendar.getInstance().getTimeInMillis() + ", getLastPlayed()=" + lastPlayed + ", timeInactive=" + (Calendar.getInstance().getTimeInMillis() - player.getLastPlayed()) + ", inactiveSetting=" + inactiveSetting); return this.unRent(true, null); } return false; }
Example 5
Source File: FriendsFeature.java From AreaShop with GNU General Public License v3.0 | 6 votes |
/** * Delete a friend from the region. * @param player The UUID of the player to delete * @param by The CommandSender that is adding the friend, or null * @return true if the friend has been added, false if adding a friend was cancelled by another plugin */ public boolean deleteFriend(UUID player, CommandSender by) { // Fire and check event DeletedFriendEvent event = new DeletedFriendEvent(getRegion(), Bukkit.getOfflinePlayer(player), by); Bukkit.getPluginManager().callEvent(event); if(event.isCancelled()) { plugin.message(by, "general-cancelled", event.getReason(), this); return false; } Set<String> friends = new HashSet<>(getRegion().getConfig().getStringList("general.friends")); friends.remove(player.toString()); List<String> list = new ArrayList<>(friends); if(list.isEmpty()) { getRegion().setSetting("general.friends", null); } else { getRegion().setSetting("general.friends", list); } return true; }
Example 6
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 7
Source File: TeleporterCommand.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Override public void onExecute(CommandSender sender, String[] args) { if (sender instanceof Player) { if (sender.hasPermission("slimefun.command.teleporter")) { if (args.length == 1) { Player p = (Player) sender; SlimefunPlugin.getGPSNetwork().getTeleportationManager().openTeleporterGUI(p, p.getUniqueId(), p.getLocation().getBlock().getRelative(BlockFace.DOWN), 999999999); } else if (args.length == 2) { @SuppressWarnings("deprecation") OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]); if (player.getName() != null) { SlimefunPlugin.getGPSNetwork().getTeleportationManager().openTeleporterGUI((Player) sender, player.getUniqueId(), ((Player) sender).getLocation().getBlock().getRelative(BlockFace.DOWN), 999999999); } else { SlimefunPlugin.getLocalization().sendMessage(sender, "messages.unknown-player", msg -> msg.replace("%player%", args[1])); } } else { SlimefunPlugin.getLocalization().sendMessage(sender, "messages.usage", msg -> msg.replace("%usage%", "/sf teleporter [Player]")); } } else { SlimefunPlugin.getLocalization().sendMessage(sender, "messages.no-permission"); } } else { SlimefunPlugin.getLocalization().sendMessage(sender, "messages.only-players"); } }
Example 8
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 9
Source File: JoinCommand.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 join <player>"); return; } Player p = (Player) sender; User user = User.getUser(p); OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]); if (player != null) { User u = User.getUser(player); if (u.getIsland() != null) { if (user.getIsland() == null) { Island island = u.getIsland(); if (user.invites.contains(island.getId())) { island.addUser(user); } else { sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().noActiveInvites.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix))); } } 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 10
Source File: UUIDManager.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
public GameProfile getProfile(UUID uuid) throws ExecutionException { GameProfile profile; if (onlineMode) { OfflinePlayer player = Bukkit.getOfflinePlayer(uuid); profile = new GameProfile(uuid, player.getName()); } else { profile = profileUUIDCache.get(uuid); } return profile; }
Example 11
Source File: Main.java From TelegramChat with GNU General Public License v3.0 | 5 votes |
private static void sendToMC(UUID uuid, String msg, int sender) { OfflinePlayer op = Bukkit.getOfflinePlayer(uuid); List<Integer> recievers = new ArrayList<Integer>(); recievers.addAll(Main.data.ids); recievers.remove((Object) sender); String msgF = Utils.formatMSG("general-message-to-mc", op.getName(), msg)[0]; for (int id : recievers) { telegramHook.sendMsg(id, msgF); } Bukkit.broadcastMessage(msgF.replace("&", "ยง")); }
Example 12
Source File: CommandUtil.java From NickNamer with MIT License | 5 votes |
static TargetInfo findOfflineTargetInfo(CommandSender sender, String targetName, boolean otherTarget) { TargetInfo targetInfo = null; if (otherTarget) { Player target = Bukkit.getPlayer(targetName); if (target != null) { targetInfo = new TargetInfo(target); } else { sender.sendMessage(MESSAGE_LOADER.getMessage("offlineInfo", "&eThe requested player is currently offline. Changes will be applied when they come online.")); try { // Paper targetInfo = new TargetInfo(Bukkit.getPlayerUniqueId(targetName), targetName); } catch (Exception ignored) { // Spigot OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(targetName); UUID offlineUuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + targetName).getBytes(Charsets.UTF_8)); if (!offlineUuid.equals(offlinePlayer.getUniqueId())) { // We want the real UUID, not the one generated from OfflinePlayer:name targetInfo = new TargetInfo(offlinePlayer); } } } } else { if (sender instanceof Player) { targetInfo = new TargetInfo((Player) sender); } else { throw new InvalidLengthException(2, 1); } } if (targetInfo == null) { sender.sendMessage(MESSAGE_LOADER.getMessage("error.target.notFound", "error.target.notFound")); return null; } return targetInfo; }
Example 13
Source File: LuckPermsHook.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
private void handle(UUID user) { if (!DiscordSRV.getPlugin().isGroupRoleSynchronizationEnabled()) return; OfflinePlayer player = Bukkit.getOfflinePlayer(user); Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordSRV.getPlugin(), () -> DiscordSRV.getPlugin().getGroupSynchronizationManager().resync(player, GroupSynchronizationManager.SyncDirection.TO_DISCORD), 5 ); }
Example 14
Source File: AccountLinkManager.java From DiscordSRV with GNU General Public License v3.0 | 4 votes |
public void afterLink(String discordId, UUID uuid) { // call link event DiscordSRV.api.callEvent(new AccountLinkedEvent(DiscordUtil.getUserById(discordId), uuid)); // trigger server commands OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); for (String command : DiscordSRV.config().getStringList("MinecraftDiscordAccountLinkedConsoleCommands")) { DiscordSRV.debug("Parsing command /" + command + " for linked commands..."); command = command .replace("%minecraftplayername%", PrettyUtil.beautifyUsername(offlinePlayer, "[Unknown Player]", false)) .replace("%minecraftdisplayname%", PrettyUtil.beautifyNickname(offlinePlayer, "[Unknown Player]", false)) .replace("%minecraftuuid%", uuid.toString()) .replace("%discordid%", discordId) .replace("%discordname%", DiscordUtil.getUserById(discordId) != null ? DiscordUtil.getUserById(discordId).getName() : "") .replace("%discorddisplayname%", DiscordSRV.getPlugin().getMainGuild().getMember(DiscordUtil.getUserById(discordId)).getEffectiveName()); if (StringUtils.isBlank(command)) { DiscordSRV.debug("Command was blank, skipping"); continue; } if (PluginUtil.pluginHookIsEnabled("placeholderapi")) command = me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(Bukkit.getPlayer(uuid), command); String finalCommand = command; DiscordSRV.debug("Final command to be run: /" + finalCommand); Bukkit.getScheduler().scheduleSyncDelayedTask(DiscordSRV.getPlugin(), () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), finalCommand)); } // group sync using the authoritative side if (DiscordSRV.config().getBoolean("GroupRoleSynchronizationOnLink")) { DiscordSRV.getPlugin().getGroupSynchronizationManager().resync(offlinePlayer, GroupSynchronizationManager.SyncDirection.AUTHORITATIVE, true); } else { try { Role roleToAdd = DiscordUtil.getJda().getRolesByName(DiscordSRV.config().getString("MinecraftDiscordAccountLinkedRoleNameToAddUserTo"), false).stream().findFirst().orElse(null); if (roleToAdd != null) { Member member = roleToAdd.getGuild().getMemberById(discordId); if (member != null) { DiscordUtil.addRoleToMember(member, roleToAdd); } else { DiscordSRV.debug("Couldn't find role: " + DiscordSRV.config().getString("MinecraftDiscordAccountLinkedRoleNameToAddUserTo")); } } else { DiscordSRV.debug("Couldn't add user to null (\"linked\") role"); } } catch (Throwable t) { DiscordSRV.debug("Couldn't add \"linked\" role due to exception: " + ExceptionUtils.getMessage(t)); } } // set user's discord nickname as their in-game name if (DiscordSRV.config().getBoolean("NicknameSynchronizationEnabled")) { DiscordSRV.getPlugin().getNicknameUpdater().setNickname(DiscordUtil.getMemberById(discordId), offlinePlayer); } }
Example 15
Source File: GPlayer.java From GlobalWarming with GNU Lesser General Public License v3.0 | 4 votes |
/** * @return never NULL, even when player-record does not exist */ public OfflinePlayer getOfflinePlayer() { return Bukkit.getOfflinePlayer(uuid); }
Example 16
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 17
Source File: FunctionalUtil.java From UHC with MIT License | 4 votes |
@Override public OfflinePlayer apply(String input) { return input == null ? null : Bukkit.getOfflinePlayer(input); }
Example 18
Source File: LocalPlayer.java From TabooLib with MIT License | 4 votes |
public static OfflinePlayer toPlayer(String name) { return isUniqueIdMode() ? Bukkit.getOfflinePlayer(UUID.fromString(name)) : Bukkit.getOfflinePlayer(name); }
Example 19
Source File: AccountLinkedEvent.java From DiscordSRV with GNU General Public License v3.0 | 4 votes |
public AccountLinkedEvent(User user, UUID playerUuid) { this.player = Bukkit.getOfflinePlayer(playerUuid); this.user = user; }
Example 20
Source File: VaultOperations.java From PlayerVaults with GNU General Public License v3.0 | 4 votes |
/** * Open another player's vault. * * @param player The player to open to. * @param vaultOwner The name of the vault owner. * @param arg The vault number to open. * @return Whether or not the player was allowed to open it. */ public static boolean openOtherVault(Player player, String vaultOwner, String arg) { if (isLocked()) { return false; } if (player.isSleeping() || player.isDead() || !player.isOnline()) { return false; } long time = System.currentTimeMillis(); int number = 0; try { number = Integer.parseInt(arg); if (number < 1) { player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER); return false; } } catch (NumberFormatException nfe) { player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER); } Inventory inv = VaultManager.getInstance().loadOtherVault(vaultOwner, number, getMaxVaultSize(vaultOwner)); String name = vaultOwner; try { OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(vaultOwner)); name = offlinePlayer.getName(); } catch (Exception e) { // not a player } if (inv == null) { player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString()); } else { player.openInventory(inv); // Check if the inventory was actually opened if (player.getOpenInventory().getTopInventory() instanceof CraftingInventory || player.getOpenInventory().getTopInventory() == null) { PlayerVaults.debug(String.format("Cancelled opening vault %s for %s from an outside source.", arg, player.getName())); return false; // inventory open event was cancelled. } player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_OTHER_VAULT.toString().replace("%v", arg).replace("%p", name)); PlayerVaults.debug("opening other vault", time); // Need to set ViewInfo for a third party vault for the opening player. VaultViewInfo info = new VaultViewInfo(vaultOwner, number); PlayerVaults.getInstance().getInVault().put(player.getUniqueId().toString(), info); PlayerVaults.getInstance().getOpenInventories().put(player.getUniqueId().toString(), inv); return true; } PlayerVaults.debug("opening other vault returning false", time); return false; }