Cuberite Forum
What's wrong with getting the UUID in this function? - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: What's wrong with getting the UUID in this function? (/thread-2211.html)

Pages: 1 2


What's wrong with getting the UUID in this function? - Gamerboy59 - 11-18-2015

Hi,
I'm about getting the UUID of a user to add them to a text file. It somehow doesn't work. :/

	local addusertofile = function(OtherPlayer)
		if OtherPlayer:GetName() == Split[3] then
			if OtherPlayer:GetUUID() == nil or OtherPlayer:GetUUID() == "" then
				friendusername = cMojangAPI:GetUUIDFromPlayerName(Split[3], true)
			else
				friendusername = OtherPlayer:GetUUID()
			end
			local file = io.open(friendDir.."\\friends.txt", "a")
			file:write(friendusername.."\n")
			file:close()
			Player:SendMessageSuccess("Friend added. You can check with /friend [playername]")
		else
			Player:SendMessageFailure("Fail")
		end
	end
	if not cRoot:Get():FindAndDoWithPlayer(Split[3], addusertofile) then
		Player:SendMessageFailure("Invalid Playername")
	end
	end

=> Always says "Invalid Playername" ingame so FindAndDoWith... was not successfull?!


RE: What's wrong with getting the UUID in this function? - NiLSPACE - 11-18-2015

Try this instead:
local UUID = cMojangAPI:GetUUIDFromPlayerName(Split[3], true)
if (UUID == "") then
   Player:SendMessageFailure("Invalid Playername")
   return true
end

local file = io.open(friendDir .. "/friends.txt", "a")
file:write(UUID, "\n")
file:close()
Player:SendMessageSuccess("Friend added. You can check with /friend [playername]")

You're using FindAndDoWithPlayer, but that means he already came online at least once. This means his UUID is already known in the database.


RE: What's wrong with getting the UUID in this function? - Gamerboy59 - 11-19-2015

I've got now:

	local addusertofile = function(OtherPlayer)
		if OtherPlayer:GetName() == Split[3] then
			friendusername = OtherPlayer:GetUUID()
			local file = io.open(friendDir.."\\friends.txt", "a")
			file:write(friendusername.."\n")
			file:close()
			Player:SendMessageSuccess("Friend added. You can check with /friend [playername]")
		else
			Player:SendMessageFailure("Fail")
		end
	end
	if not cRoot:Get():FindAndDoWithPlayer(Split[3], addusertofile) then
		local UUID = cMojangAPI:GetUUIDFromPlayerName(Split[3], true)
		if (UUID == "" or UUID == nil) then
			Player:SendMessageFailure("Invalid Playername")
		return true
		end
		local file = io.open(friendDir .. "/friends.txt", "a")
		file:write(UUID, "\n")
		file:close()
		Player:SendMessageSuccess("Friend added. You can check with /friend [playername]")
	end

Still invalid player.


RE: What's wrong with getting the UUID in this function? - NiLSPACE - 11-19-2015

You don't need FindAndDoWithPlayer. Try my code instead of all your code..


RE: What's wrong with getting the UUID in this function? - Gamerboy59 - 11-19-2015

(11-19-2015, 05:31 AM)NiLSPACE Wrote: You don't need FindAndDoWithPlayer. Try my code instead of all your code..

What's the difference between cClientHandle UUID and MojangAPI UUID call? I though the latter one uses more bandwidth (performance?).


RE: What's wrong with getting the UUID in this function? - NiLSPACE - 11-19-2015

cClientHandle:GetUUID is a member variable. You can only get it when a player is online. cMojangAPI, when using cached only, will get the info from a sql database next to the executable. It won't affect the bandwidth at all.


RE: What's wrong with getting the UUID in this function? - Gamerboy59 - 11-19-2015

I see, thanks for explaining.

I've got now the following code:
	local friendusername = cMojangAPI:GetUUIDFromPlayerName(Split[3], true)
	if (friendusername == "" or friendusername == nil) then
		Player:SendMessageFailure("Invalid Playername")
		return true
	end
	local file = io.open(friendDir.."\\friends.txt", "a")
	file:write(friendusername.."\n")
	file:close()
	Player:SendMessageSuccess("Friend added. You can check with /friend [playername]")

Still invalid playername. Is the MojangAPI broken?
I tried another function (/useruid <friendusername>):
local friendusername = cMojangAPI:GetUUIDFromPlayerName(Split[2], true)
Player:SendMessageInfo("Found player:"..friendusername)
Returns nil while the player definitely exists.


RE: What's wrong with getting the UUID in this function? - NiLSPACE - 11-19-2015

The username you're trying to get did already come online right? Also, I believe the function is case sensitive. If I search for gamerboy59 while you logged in as Gamerboy59 you wouldn't show up.


RE: What's wrong with getting the UUID in this function? - Gamerboy59 - 11-20-2015

(11-19-2015, 10:48 PM)NiLSPACE Wrote: The username you're trying to get did already come online right?
No.

(11-19-2015, 10:48 PM)NiLSPACE Wrote: Also, I believe the function is case sensitive. If I search for gamerboy59 while you logged in as Gamerboy59 you wouldn't show up.
Yes, tried case sensitive doesn't matter.


RE: What's wrong with getting the UUID in this function? - Seadragon91 - 11-20-2015

You are using true in the function cMojangAPI:GetUUIDFromPlayerName(Split[2], true).
True means that only the local cache will be used to lookup the uuid of the player. Set it to false, then it will connect to mojang to get the uuid.
cMojangAPI:GetUUIDFromPlayerName(Split[2], false)