Knowledge API allows you to hook into the Knowledge Book Plugin that allows you to easily convert java classes into mongo documents.
- Installing the Knowledge Book API
- What's in the Knowledge Book API
- Using the Knowledge Book API
- Contributing to the Knowledge Book API
- Knowledge Book's License
- Donating to help support the Knowledge Book API
Knowledge Book among other various plugins I have worked on are free to use! Please consider donating to my ko-fi! It helps fund other projects that I am passionate about.
Below shows you how to install Knowledge Book API into your project.
Add it in your root build.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add the dependency
dependencies {
implementation 'com.github.Lodestones:Knowledge-Book:VERSION'
}
Add the JitPack repository to your build file
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add the dependency
<dependency>
<groupId>com.github.Lodestones</groupId>
<artifactId>Knowledge-Book</artifactId>
<version>VERSION</version>
</dependency>
The Knowledge Book API gives you the MongoJack API as well as the @Collection annotation to use.
To hook into the Knowledge Book API, you can use the KnowledgeBookAPI class.
Hooking into the Knowledge Book API.
import to.lodestone.knowledgebook.IKnowledgeBookAPI;
import to.lodestone.knowledgebook.KBHook;
public class MainPlugin extends JavaPlugin {
private KBHook kbHook; // Declare Knowledge Book Hook Variable.
@Override
public void onEnable() {
kbHook = new KBHook(this); // Hook into the Knowledge Book API.
}
public IKnowledgeBookAPI db() { // use this method to access the Knowledge Book API.
return kbHook.api(); // Retrieve the Knowledge Book API from the Hook.
}
}
As an example, you can convert a Java Class into a MongoDB document.
package to.lodestone.example.data;
import com.fasterxml.jackson.annotation.JsonProperty;
import to.lodestone.knowledgebook.annotation.Collection;
@Collection(name = "person_collection")
public class Person {
@JsonProperty("fullName")
private String fullName;
@JsonProperty("socialSecurityNumber")
private String socialSecurityNumber;
// For Knowledge Book to initialize an empty object to use getters and setters.
public Person() {
}
public Person(String fullName, String socialSecurityNumber) {
this.fullName = fullName;
this.socialSecurityNumber = socialSecurityNumber;
}
@JsonProperty("fullName")
public void setFullName(String fullName) {
this.fullName = fullName;
}
@JsonProperty("fullName")
public String getFullName() {
return fullName;
}
@JsonProperty("socialSecurityNumber")
public void setSocialSecurityNumber(String socialSecurityNumber) {
this.socialSecurityNumber = socialSecurityNumber;
}
@JsonProperty("socialSecurityNumber")
public String getSocialSecurityNumber() {
return socialSecurityNumber;
}
}
How to use Knowledge Book in your plugin:
package to.lodestone.example;
import org.bukkit.plugin.java.JavaPlugin;
import org.mongojack.JacksonMongoCollection;
import to.lodestone.conquest.data.Person;
import to.lodestone.knowledgebook.IKnowledgeBookAPI;
import to.lodestone.knowledgebook.KBHook;
public class TestPlugin extends JavaPlugin {
private KBHook kbHook;
@Override
public void onEnable() {
this.kbHook = new KBHook(this);
JacksonMongoCollection<Person> personCollection = this.kbHook.api().getOrCreateCollection(Person.class);
personCollection.insertOne(new Person("John Doe", "4355678656"));
}
public IKnowledgeBookAPI db() {
return kbHook.api();
}
}
Once you've started up your server, it will create a collection called person_collection
with a new Person document with all of the data you've provided.
Remember to set your variables with the correct values in order for Knowledge Book to properly function within the "config.yml" file!
database: null
connectionString: null
See something Knowledge Book doesn't support, a bug or something that may be useful? We welcome contributions to improve the Knowledge Book API. Open an issue here.
Knowledge Book is ARR. Please view the license here.