Offline mode server storing data

Discussion in 'Spigot Plugin Development' started by MrAxeTv, Apr 9, 2019.

  1. Hello there I have problem with storing data with offline mode servers (Cracked)
    So my plugin works perfect with online mode storing to UUID
    but offline server have problem is example some body miss types name of player in lower case
    Original name of player : BananaMan
    but some body type is in lower case /token balance bananaman
    server will get wrong player uuid and it will respond with result 0
    plus problem is values are stored in mysql data base
    so should I recode my whole plugin make and check if server is running in offline mode
    and store tokens balance without uuids and replace them with user name of players
    or is there any other way to check if player exists and correct the name bananaman to BananaMan

    Sorry for my bad eng I hope u will be able to understand my problem Thanks
  2. Bukkit.getOfflinePlayer("bananaman") is deprecated and is reccomended to fetch directly with UUIDs. I can image it will work if bananaman is online.

    Due to the lack of information, I dont know if BananaMan is online or not.

    if BananaMan is online, and it still cant find bananaman, try the following code to explicitly match

    Code (Java):
        public void onEntityDamageByEntity(ProjectileLaunchEvent event) {
            String input = "bAnaNaMaN";
            String inputLower = input.toLowerCase();
            Bukkit.getOnlinePlayers().forEach(player -> {
                String name = player.getName();
                String nameLower = name.toLowerCase();
                if (inputLower.equals(nameLower)) {
                    Player found = Bukkit.getPlayer(inputLower);
                    if (found != null) {
    #2 NaJated, Apr 9, 2019
    Last edited: Apr 9, 2019
  3. How are you storing data?
  4. This code snippet is garbage.
    • Agree Agree x 3
    • Funny Funny x 1
  5. It was psuedo at best, If you took this as a direct solution I feel bad for you - perhaps I should've clarified, for people like you, that it was to showcase the deprecation of Bukkit.getPlayer(String) and it's flaws, including this potential flaw of only matching if the characters explicitly match + not ignoring case.
  6. Bukkit#getPlayer is in fact doing an ignore case search (doesn't really care about capital cases or not). In other words, if I were only and I were to use Bukkit.getPlayer("shin"); it'd return a valid Player object. In other words the code provided is pointless and could be changed to a simple:
    Code (Java):
        public void onEntityDamageByEntity(ProjectileLaunchEvent event) {
            String input = "bAnaNaMaN";
            Player found = Bukkit.getPlayer(input);
            if (found != null){
             // Player's online!
    I am not certain but I think this is the case with Bukkit#getOfflinePlayer as well. In other words, Bukkit#getOfflinePlayer("bananaman"); Should return the correct name case for the OfflinePlayer#getName()

    Just to correct you, Bukkit#getPlayer is not deprecated.
    • Agree Agree x 1
  7. I am storing data in mysql with player uuid
    but problem is if player miss type player name on offline mode server they will get wrong data out because BananaMan and bananaman have a different UUID
  8. If you are storing data in your mysql, you should save the player name along with the uuid not only the uuid. This way, you'd be able to do a quick ignore case search into your database and find the proper user that way.

    Looking into the source code, if the server is in offline mode then things change a bit:
    Code (Java):
        public OfflinePlayer getOfflinePlayer(final String name) {
            OfflinePlayer result = this.getPlayerExact(name); // Is the target player online perhaps?
            if (result == null) { // They're not, trying different ways of getting the profile.
                GameProfile profile = null;
                if (MinecraftServer.getServer().getOnlineMode() || SpigotConfig.bungee) { // Is the server online mode or bungeecord?
                    profile = this.console.getUserCache().getProfile(name); // get the cached profile, if name is bananaman, this should return BananaMan as long as that user has joined once.
                if (profile == null) { // Not online mode or bungee, create a new profile with the name given and return that.
                    result = this.getOfflinePlayer(new GameProfile(UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), name));
                else { // found profile for online mode, return that.
                    result = this.getOfflinePlayer(profile);
            else {
            return result;