Java Code Examples for org.bukkit.OfflinePlayer

The following examples show how to use org.bukkit.OfflinePlayer. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: DungeonsXL   Source File: InviteCommand.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onExecute(String[] args, CommandSender sender) {
    ResourceWorld resource = plugin.getMapRegistry().get(args[2]);
    OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);

    if (resource != null) {
        if (player != null) {
            resource.addInvitedPlayer(player);
            MessageUtil.sendMessage(sender, DMessage.CMD_INVITE_SUCCESS.getMessage(args[1], args[2]));

        } else {
            MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_PLAYER.getMessage(args[2]));
        }

    } else {
        MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[2]));
    }
}
 
Example 2
Source Project: IridiumSkyblock   Source File: ValueCommand.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void execute(CommandSender sender, String[] args) {
    Player p = (Player) sender;
    User user = User.getUser(p);
    Island island;
    if (args.length == 2) {
        OfflinePlayer player = Bukkit.getOfflinePlayer(args[1]);
        island = User.getUser(player).getIsland();
    } else {
        island = user.getIsland();
    }
    if (island != null) {
        p.sendMessage(Utils.color(IridiumSkyblock.getMessages().islandValue.replace("%value%", island.getValue() + "").replace("%rank%", Utils.getIslandRank(island) + "").replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
    } else {
        p.sendMessage(Utils.color(IridiumSkyblock.getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
    }
}
 
Example 3
Source Project: Slimefun4   Source File: Script.java    License: GNU General Public License v3.0 6 votes vote down vote up
private Script(Config config) {
    Validate.notNull(config);

    this.config = config;
    this.name = config.getString("name");
    this.code = config.getString("code");
    String uuid = config.getString("author");

    Validate.notNull(name);
    Validate.notNull(code);
    Validate.notNull(uuid);
    Validate.notNull(config.getStringList("rating.positive"));
    Validate.notNull(config.getStringList("rating.negative"));

    OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(uuid));
    this.author = player.getName() != null ? player.getName() : config.getString("author_name");
}
 
Example 4
Source Project: AreaShop   Source File: RentRegion.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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 Project: Skript   Source File: ExprUUID.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
@Nullable
public String convert(final Object o) {
	if (o instanceof OfflinePlayer) {
		if (offlineUUIDSupported) {
			try {
				return ((OfflinePlayer) o).getUniqueId().toString();
			} catch (UnsupportedOperationException e) {
				// Some plugins (ProtocolLib) try to emulate offline players, but fail miserably
				// They will throw this exception... and somehow server may freeze when this happens
				Skript.warning("A script tried to get uuid of an offline player, which was faked by another plugin (probably ProtocolLib).");
				e.printStackTrace();
				return null;
			}
		} else
			return ((Player) o).getUniqueId().toString();
	} else if (o instanceof Entity) {
		return ((Entity)o).getUniqueId().toString();
	} else if (o instanceof World) {
		return ((World) o).getUID().toString();
	}
	return null;
}
 
Example 6
Source Project: AreaShop   Source File: BuyRegion.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean checkInactive() {
	if(isDeleted() || !isSold()) {
		return false;
	}
	long inactiveSetting = getInactiveTimeUntilSell();
	OfflinePlayer player = Bukkit.getOfflinePlayer(getBuyer());
	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.sell(true, null);
	}
	return false;
}
 
Example 7
Source Project: NametagEdit   Source File: NametagManager.java    License: GNU General Public License v3.0 6 votes vote down vote up
private FakeTeam reset(String player, FakeTeam fakeTeam) {
    if (fakeTeam != null && fakeTeam.getMembers().remove(player)) {
        boolean delete;
        Player removing = Bukkit.getPlayerExact(player);
        if (removing != null) {
            delete = removePlayerFromTeamPackets(fakeTeam, removing.getName());
        } else {
            OfflinePlayer toRemoveOffline = Bukkit.getOfflinePlayer(player);
            delete = removePlayerFromTeamPackets(fakeTeam, toRemoveOffline.getName());
        }

        plugin.debug(player + " was removed from " + fakeTeam.getName());
        if (delete) {
            removeTeamPackets(fakeTeam);
            TEAMS.remove(fakeTeam.getName());
            plugin.debug("FakeTeam " + fakeTeam.getName() + " has been deleted. Size: " + TEAMS.size());
        }
    }

    return fakeTeam;
}
 
Example 8
@SuppressWarnings({"deprecation", "ConstantConditions"}) // 2013 Bukkit
private void checkCommand(String message) {
    if (!DiscordSRV.getPlugin().isGroupRoleSynchronizationEnabled()) return;

    OfflinePlayer target = patterns.stream()
            .map(pattern -> pattern.matcher(message))
            .filter(Matcher::find)
            .map(matcher -> matcher.group(1))
            .filter(Objects::nonNull)
            .map(input -> {
                OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(input);
                if (offlinePlayer != null) return offlinePlayer;

                try {
                    return Bukkit.getOfflinePlayer(UUID.fromString(input));
                } catch (IllegalArgumentException ignored) {}
                return null;
            })
            .findAny().orElse(null);

    // run task later so that this command has time to execute & change the group state
    Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordSRV.getPlugin(),
            () -> resync(target, SyncDirection.TO_DISCORD),
            5
    );
}
 
Example 9
/**
 * Changes the owner of this shop to the given player.
 *
 * @param owner the new owner
 */
@Override
public void setOwner(@NotNull UUID owner) {
    OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(owner);
    //Get the sign at first
    List<Sign> signs = this.getSigns();
    //then setOwner
    this.moderator.setOwner(owner);
    //then change the sign
    for (Sign shopSign : signs) {
        shopSign.setLine(0, MsgUtil.getMessageOfflinePlayer("signs.header", offlinePlayer, ownerName(false)));
        //Don't forgot update it
        shopSign.update(true);
    }
    //Event
    Bukkit.getPluginManager().callEvent(new ShopModeratorChangedEvent(this, this.moderator));
    update();
}
 
Example 10
Source Project: QuickShop-Reremake   Source File: MsgUtil.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * getMessage in messages.yml
 *
 * @param loc    location
 * @param player The sender will send the message to
 * @param args   args
 * @return message
 */
public static String getMessageOfflinePlayer(
        @NotNull String loc, @Nullable OfflinePlayer player, @NotNull String... args) {
    try {
        Optional<String> raw = messagei18n.getString(loc);
        if (!raw.isPresent()) {
            return invaildMsg + ": " + loc;
        }
        String filled = fillArgs(raw.get(), args);
        if (player != null) {
            if (plugin.getPlaceHolderAPI() != null && plugin.getPlaceHolderAPI().isEnabled() && plugin.getConfig().getBoolean("plugin.PlaceHolderAPI")) {
                filled = PlaceholderAPI.setPlaceholders(player, filled);
                Util.debugLog("Processed message " + filled + " by PlaceHolderAPI.");
            }
        }
        return filled;
    } catch (Throwable th) {
        plugin.getSentryErrorReporter().ignoreThrow();
        th.printStackTrace();
        return "Cannot load language key: " + loc + " because something not right, check the console for details.";
    }
}
 
Example 11
Source Project: AreaShop   Source File: GeneralRegion.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get the landlord of this region (the player that receives any revenue from this region).
 * @return The UUID of the landlord of this region
 */
public UUID getLandlord() {
	String landlord = getStringSetting("general.landlord");
	if(landlord != null && !landlord.isEmpty()) {
		try {
			return UUID.fromString(landlord);
		} catch(IllegalArgumentException e) {
			// Incorrect UUID
		}
	}
	String landlordName = getStringSetting("general.landlordName");
	if(landlordName != null && !landlordName.isEmpty()) {
		@SuppressWarnings("deprecation")
		OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(landlordName);
		if(offlinePlayer != null) {
			return offlinePlayer.getUniqueId();
		}
	}
	return null;
}
 
Example 12
Source Project: MapManager   Source File: DefaultMapManager.java    License: MIT License 5 votes vote down vote up
@Override
public MapWrapper getWrapperForId(OfflinePlayer player, short id) {
	for (MapWrapper wrapper : getMapsVisibleTo(player)) {
		if (wrapper.getController().getMapId(player) == id) { return wrapper; }
	}
	return null;
}
 
Example 13
Source Project: CardinalPGM   Source File: Players.java    License: MIT License 5 votes vote down vote up
public static String getName(ServerOperator who, boolean flairs) {
    if (who instanceof OfflinePlayer) {
        OfflinePlayer player = (OfflinePlayer) who;
        return player.isOnline() ? (flairs ? player.getPlayer().getDisplayName() : Teams.getTeamColorByPlayer(player) + player.getPlayer().getName()) : Rank.getPrefix(player.getUniqueId()) + ChatColor.DARK_AQUA + player.getName();
    } else {
        return ChatColor.GOLD + "\u2756" + ChatColor.DARK_AQUA + "Console";
    }
}
 
Example 14
private static OfflinePlayer[] offlinePlayersWithNames(String... names) {
    OfflinePlayer[] players = new OfflinePlayer[names.length];
    for (int i = 0; i < names.length; ++i) {
        OfflinePlayer player = mock(OfflinePlayer.class);
        given(player.getName()).willReturn(names[i]);
        players[i] = player;
    }
    return players;
}
 
Example 15
Source Project: IridiumSkyblock   Source File: CoopCommand.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void admin(CommandSender sender, String[] args, Island island) {
    Player p = (Player) sender;
    if (island != null) {
        if (args.length != 4) {
            p.openInventory(island.getCoopGUI().getInventory());
            return;
        }
        OfflinePlayer player = Bukkit.getOfflinePlayer(args[3]);
        if (player != null) {
            User u = User.getUser(player);
            if (!island.equals(u.getIsland()) && u.getIsland() != null) {
                if (island.coopInvites.contains(u.islandID)) {
                    island.coopInvites.remove(u.islandID);
                    island.addCoop(u.getIsland());
                } else {
                    u.getIsland().inviteCoop(island);
                    sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().coopInviteSent.replace("%player%", User.getUser(u.getIsland().getOwner()).name).replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
                }
            } 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)));
        }
    } else {
        sender.sendMessage(Utils.color(IridiumSkyblock.getMessages().noIsland.replace("%prefix%", IridiumSkyblock.getConfiguration().prefix)));
    }
}
 
Example 16
Source Project: Hawk   Source File: PunishmentScheduler.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void authorize(OfflinePlayer p) {
    UUID uuid = p.getUniqueId();
    if(convicts.containsKey(uuid)) {
        convicts.get(uuid).setValue(true);
        hawk.broadcastAlertToAdmins(USER_AUTHORIZED.replace("%player%", p.getName()));
    }
    else {
        hawk.broadcastAlertToAdmins(USER_NOT_FOUND.replace("%player%", p.getName()));
    }
}
 
Example 17
Source Project: PlayTimeTracker   Source File: Main.java    License: MIT License 5 votes vote down vote up
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 18
Source Project: MapManager   Source File: DefaultMapManager.java    License: MIT License 5 votes vote down vote up
@Override
public Set<Short> getOccupiedIdsFor(OfflinePlayer player) {
	Set<Short> ids = new HashSet<>();
	for (MapWrapper wrapper : MANAGED_MAPS) {
		short s;
		if ((s = wrapper.getController().getMapId(player)) >= 0) {
			ids.add(s);
		}
	}
	return ids;
}
 
Example 19
Source Project: Skript   Source File: WorldGuard6Hook.java    License: GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public boolean isOwner(final OfflinePlayer p) {
    if (supportsUUIDs)
        return region.isOwner(plugin.wrapOfflinePlayer(p));
    else
        return region.isOwner(p.getName());
}
 
Example 20
Source Project: civcraft   Source File: AdminCommand.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void playerreport_cmd() {

	LinkedList<OfflinePlayer> offplayers = new LinkedList<OfflinePlayer>();
	for (OfflinePlayer offplayer : Bukkit.getOfflinePlayers()) {
		offplayers.add(offplayer);
	}
	
	CivMessage.sendHeading(sender, "Players with Goodies");
	CivMessage.send(sender, "Processing (this may take a while)");
	TaskMaster.syncTask(new ReportPlayerInventoryTask(sender, offplayers), 0);
}
 
Example 21
Source Project: CardinalPGM   Source File: Database.java    License: MIT License 5 votes vote down vote up
private Element getPlayerElement(OfflinePlayer player) {
    for (Element element : document.getRootElement().getChildren()) {
        if (element.getAttributeValue("uuid") != null && player.getUniqueId().equals(UUID.fromString(element.getAttributeValue("uuid")))) return element;
    }
    Element newPlayer = new Element("player").setAttribute(new Attribute("uuid", player.getUniqueId().toString()));
    document.getRootElement().addContent(newPlayer);
    return newPlayer;
}
 
Example 22
Source Project: GriefDefender   Source File: CommandClaimOptionPlayer.java    License: MIT License 5 votes vote down vote up
@CommandCompletion("@gdplayers @gdoptions @gdcontexts @gddummy")
@CommandAlias("cop")
@Description("Gets/Sets option for a player in claim you are standing in.")
@Syntax("<player> <option> <value> [context[key=value]]")
@Subcommand("option player")
public void execute(Player src, OfflinePlayer player, @Optional String[] args) throws InvalidCommandArgument {
    this.subject = PermissionHolderCache.getInstance().getOrCreateUser(player);
    this.friendlySubjectName = player.getName();
    super.execute(src, args);
}
 
Example 23
Source Project: MarriageMaster   Source File: Database.java    License: GNU General Public License v3.0 5 votes vote down vote up
public MarriagePlayerData getPlayer(OfflinePlayer bPlayer)
{
	MarriagePlayerData player = cache.getPlayer(bPlayer.getUniqueId());
	if(player == null)
	{
		player = new MarriagePlayerData(bPlayer);
		cache.cache(player); // Let's put the new player into the cache
		load(player);
	}
	return player;
}
 
Example 24
@Override
public boolean addToGroup(OfflinePlayer player, String group) {
    if (!PermissionsEx.getPermissionManager().getGroupNames().contains(group)) {
        return false;
    }

    PermissionUser user = PermissionsEx.getUser(player.getName());
    user.addGroup(group);
    return true;
}
 
Example 25
Source Project: Thermos   Source File: CraftScoreboard.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void resetScores(OfflinePlayer player) throws IllegalArgumentException {
    Validate.notNull(player, "OfflinePlayer cannot be null");

    board.func_96515_c(player.getName());
}
 
Example 26
public PlayerStatistic(OfflinePlayer player) {
    this.uuid = player.getUniqueId();
    this.name = player.getName();
}
 
Example 27
Source Project: CombatLogX   Source File: TraitCombatLogX.java    License: GNU General Public License v3.0 4 votes vote down vote up
public OfflinePlayer getOwner() {
    return Bukkit.getOfflinePlayer(this.ownerId);
}
 
Example 28
Source Project: uSkyBlock   Source File: PlayerInfo.java    License: GNU General Public License v3.0 4 votes vote down vote up
public OfflinePlayer getOfflinePlayer() {
    if (uuid != null) {
        return uSkyBlock.getInstance().getPlayerDB().getOfflinePlayer(uuid);
    }
    return null;
}
 
Example 29
Source Project: DiscordSRV   Source File: PrettyUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static String beautifyUsername(OfflinePlayer player, String noUsernameFormat, boolean includeUuid) {
    if (player == null) return noUsernameFormat;

    String name = player.getName();
    return (name != null ? player.getName() : noUsernameFormat) + (includeUuid ? " (" + player.getUniqueId() + ")" : "");
}
 
Example 30
Source Project: Kettle   Source File: MemorySection.java    License: GNU General Public License v3.0 4 votes vote down vote up
public boolean isOfflinePlayer(String path) {
    return getSerializable(path, OfflinePlayer.class) != null;
}