-
-
Notifications
You must be signed in to change notification settings - Fork 0
Usage
FigT edited this page Jun 27, 2021
·
2 revisions
Temporary JavaDoc online: https://figt.github.io/jd/mesh/1.2.0/
If you've made a project that uses Mesh and you want to add it here for other people to learn from, submit an issue with the link to your repository.
Here's a small code snippet from a personal project:
public Mesh<Boolean> hasVoted(UUID uuid) {
// create new mesh
Mesh<Boolean> mesh = Mesh.createMesh();
// supply it asynchronously
mesh.supplyAsync(() -> {
try {
ResultSet result = executeSQLQuery("SELECT * FROM data WHERE uuid=?", uuid.toString()); // execute MySQL query
if (result != null && result.next()) {
return true; // if the uuid does exist in the table, supply true
}
} catch (SQLException e) {
throw new CompletionException(e); // just throw a new CompletionException with the SQLException wrapped
}
return false; // else supply false
});
// if there is an exception,
mesh.exceptionallySync(throwable -> {
logException(throwable);
// returning false if error
return false;
});
return mesh;
}
// accept SYNC because Bukkit API isn't thread safe
hasVotedMesh.acceptSync(b -> {
player.sendMessage(ChatColor.GREEN + "hasVoted returned: " + b); // send msg
player.teleport(player.getLocation().add(0, 10, 0)); // teleport them because idk
});