Dear, How can I get a Player from their uuid? I stored a uuid in a database but Bukkit.getServer().getPlayer() only works for names. Code: Code:java /** * Get all warps from the database */ public static void getWarps() { final WarpPlugin wp = WarpPlugin.getInstance(); // Thread the database connection Bukkit.getScheduler().runTaskAsynchronously(wp, new Runnable() { public void run() { String query = getQuery("WARPS_SELECT"); query = query.replace("{PREFIX}", Configuration.prefix); ResultSet result = db.query(query); SendConsole.info("Loading warps from database ..."); // Log to // console // Get the result try { while (result.next()) { try { String name = result.getString("name"); String uuid = result.getString("owner"); Player owner = Bukkit.getServer().getPlayer(uuid); int id = result.getInt("id"); float x = result.getFloat("x"); float y = result.getFloat("y"); float z = result.getFloat("z"); float pitch = result.getFloat("pitch"); float yaw = result.getFloat("yaw"); World world = wp.getServer().getWorld( result.getString("world")); Location location = new Location(world, x, y, z, yaw, pitch); Warp warp = new Warp(name, owner, location, id); warp.saveWarpCache(); } catch (Exception ex) { ex.printStackTrace(); } } } catch (SQLException e) { e.printStackTrace(); } } }); } Best Regards, Maximvdw
Maximvdw Code: public Entity getEntityByUUID(UUID id) { for (World w : Bukkit.getServer().getWorlds()) { for (Entity e : w.getEntities()) { if (e.getUUID() == id) { return e; } } } return null; }
Thanks My code now: Code:java public static Player getPlayerByUUID(UUID id) { for (World w : Bukkit.getServer().getWorlds()) { for (Entity e : w.getEntities()) { if (e.getUniqueId() == id) { if (e instanceof Player){ return (Player)e; } } } } return null; }
metalhedd I might be mistaken, but isn't == used to compare object instances? Or is there something different in UUID?
== will ensure they are the exact same instance of the same UUID, which is not what you want, you only want to make sure the values are equivalent, not that they are the same object in memory