org.bukkit.Bukkit#getOfflinePlayer ( )源码实例Demo

下面列出了org.bukkit.Bukkit#getOfflinePlayer ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: UhcCore   文件: VaultManager.java
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));
}
 
源代码2 项目: AreaShop   文件: FriendsFeature.java
/**
 * 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;
}
 
源代码3 项目: AreaShop   文件: RentRegion.java
@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;
}
 
源代码4 项目: IridiumSkyblock   文件: UnBanCommand.java
@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)));
    }
}
 
源代码5 项目: Civs   文件: RegionManager.java
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);
    }
}
 
源代码6 项目: IridiumSkyblock   文件: JoinCommand.java
@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)));
    }
}
 
源代码7 项目: DiscordSRV   文件: LuckPermsHook.java
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
    );
}
 
源代码8 项目: NickNamer   文件: CommandUtil.java
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;
}
 
源代码9 项目: TelegramChat   文件: Main.java
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("&", "§"));

}
 
源代码10 项目: HeavySpleef   文件: UUIDManager.java
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;
}
 
源代码11 项目: QuickShop-Reremake   文件: MsgUtil.java
/**
 * @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);
                }
            }
        }
    }
}
 
源代码12 项目: IridiumSkyblock   文件: InviteCommand.java
@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)));
    }
}
 
源代码13 项目: Slimefun4   文件: TeleporterCommand.java
@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");
    }
}
 
源代码14 项目: PlayerVaults   文件: VaultOperations.java
/**
 * 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;
}
 
源代码15 项目: Civs   文件: TutorialManager.java
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);
}
 
源代码16 项目: GlobalWarming   文件: GPlayer.java
/**
 * @return never NULL, even when player-record does not exist
 */
public OfflinePlayer getOfflinePlayer() {
    return Bukkit.getOfflinePlayer(uuid);
}
 
源代码17 项目: DiscordSRV   文件: AccountLinkManager.java
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);
    }
}
 
源代码18 项目: UHC   文件: FunctionalUtil.java
@Override
public OfflinePlayer apply(String input) {
    return input == null ? null : Bukkit.getOfflinePlayer(input);
}
 
源代码19 项目: TabooLib   文件: LocalPlayer.java
public static OfflinePlayer toPlayer(String name) {
    return isUniqueIdMode() ? Bukkit.getOfflinePlayer(UUID.fromString(name)) : Bukkit.getOfflinePlayer(name);
}
 
源代码20 项目: DiscordSRV   文件: AccountLinkedEvent.java
public AccountLinkedEvent(User user, UUID playerUuid) {
    this.player = Bukkit.getOfflinePlayer(playerUuid);
    this.user = user;
}