Skip to content

Commit

Permalink
fix: get player by uuid no longer crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Jun 15, 2024
1 parent da1707f commit 38a7ec2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/endstone/detail/pybind_type_caster.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct type_caster<endstone::UUID> {
}

/* Now try to convert into C++ object */
PyObject *bytes = PyObject_CallMethod(source, "bytes", NULL);
PyObject *bytes = PyObject_GetAttrString(source, "bytes");
if (PyBytes_GET_SIZE(bytes) != 16) {
PyErr_SetString(PyExc_ValueError, "UUID bytes size must be 16");
Py_XDECREF(bytes);
Expand All @@ -57,7 +57,7 @@ struct type_caster<endstone::UUID> {
Py_XDECREF(bytes);
Py_XDECREF(uuid_module);
Py_XDECREF(uuid_class);
return PyErr_Occurred() != nullptr;
return PyErr_Occurred() == nullptr;
}

// C++ -> Python
Expand Down
2 changes: 1 addition & 1 deletion src/endstone_python/endstone_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void init_server(py::class_<Server> &server)
"Gets a list of all currently online players.")
.def_property("max_players", &Server::getMaxPlayers, &Server::setMaxPlayers,
"The maximum amount of players which can login to this server.")
.def("get_player", py::overload_cast<std::string>(&Server::getPlayer, py::const_), py::arg("name"),
.def("get_player", py::overload_cast<std::string>(&Server::getPlayer, py::const_), py::arg("name").noconvert(),
py::return_value_policy::reference, "Gets the player with the exact given name, case insensitive.")
.def("get_player", py::overload_cast<endstone::UUID>(&Server::getPlayer, py::const_),
py::arg("unique_id").noconvert(), py::return_value_policy::reference,
Expand Down

0 comments on commit 38a7ec2

Please sign in to comment.