-
-
Notifications
You must be signed in to change notification settings - Fork 3
Prefix Manager
Another easy to understand option of Velen is the Prefix Manager, this is where you set the default prefix that will be used on all servers (unless you configure the Prefix Manager to use a per-server prefix which we will get into later), yes you heard me right... per-server prefixes is supported easily through this!
But first, before we move to the per-server prefixes, let us change the default prefix that Velen will use on all servers which is v.
. Changing this prefix is as simple as adding one single line on the builder:
Velen velen = Velen.builder().setDefaultPrefix("a.").build();
The line above will make Velen use the prefix: a.
on all servers from now on.
BUUUT! You can use per-server prefixes, this requires you to have a database of some sort, for example: MongoDB
or Redis
. To setup Velen to use a per-server (persistent) prefix, all you need is to create a new VelenPrefixManager
and add it to the builder, an example:
Velen velen = Velen.builder().setPrefixManager(new VelenPrefixManager("v.",
key -> MongoDB.collection("servers", "prefixes").find(Filters.eq("server", key)).first()
.getString("prefix"))).build();
What the line above does is tell Velen to fetch the prefix on the MongoDB
database and cache it to use for the exact server. The key
value is the server's id. You can also use a non-persistent version or a hard-coded through the default Velen Prefix Manager, an example would be:
Velen velen = ...;
velen.getPrefixManager().setPrefix(123123123L, "prefixHere");
The loader is also not just limited to external databases, in fact, you can even use a HashMap<Long, String>
and
store stuff there but database is recommended for persistence.
With v2.0
, you can now set the prefix of the server through VelenPrefixManager
by first creating a special type of VelenPrefixManager
which is:
new VelenPrefixManager(Default Prefix, Loader for Server Prefixes, Modifier for Server Prefixes)
An explanation of all the parameters are:
-
Default Prefix: This is the default prefix that all servers will use if the
Loader
returns nothing. - Loader for Server Prefixes: This is the loader which Velen will use to get the prefix of the user from the database.
-
Modifier for Server Prefixes: This is ran whenever the method
setPrefix(Server ID, Prefix)
is used, it should be used to change the database value, for example:(pair -> database.set(pair.getLeft(), pair.getRight())
. In the example,pair.getLeft()
is theServer ID
andpair.getRight()
is theNew Prefix
.
An example implementation of such would be:
new VelenPrefixManager("v.", key -> Database.find("server", key).getString("prefix"),
pair -> Database.find("server", pair.getLeft()).set("prefix", pair.getRight));