✨Features

Custom Redis Messages

You can send messages via redis and receive them anywhere:

https://github.com/redisson/redisson/wiki/6.-Distributed-objects#67-topic

// Publish message
basementLib.redisManager().publishMessage(BasementMessage message);

// Register Topic Listener
basementLib.redisManager().registerTopicListener(String name,BasementMessageHandler<T extends BasementMessage> basementMessageHandler);

// Unregister Topic Listeners
basementLib.redisManager().unregisterTopicListener(String name,Integer...listenerId);

// Clear Topic Listeners
basementLib.redisManager().clearTopicListeners(String name);
// Custom Message class
public class ServerShutdownMessage extends BasementMessage {

    // Channel
    public static final String TOPIC = "server-shutdown";

    // Data
    private final String sender;
    private final String receiver;

    public ServerShutdownMessage() {
        super(TOPIC);
        this.sender = null;
        this.receiver = null;
    }

    public ServerShutdownMessage(String sender, String receiver) {
        super(TOPIC);
        this.sender = sender;
        this.receiver = receiver;
    }
}


// Handler
public class ServerShutdownHandler implements BasementMessageHandler<ServerShutdownMessage> {

    private final ProxyServer server;

    @Override
    public void execute(ServerShutdownMessage message) {
        // Do something
    }

    @Override
    public Class<ServerShutdownMessage> getCommandClass() {
        return ServerShutdownMessage.class;
    }
}

// Register
basementLib.redisManager().registerTopicListener(ServerShutdownMessage.TOPIC,new ServerShutdownHandler(this));

// Publish message
basementLib.redisManager().publishMessage(new ServerShutdownMessage("banana","moon"));

MySQL and H2 Query Builder

To query a database

AbstractMariaDatabase customDatabase = basementLib.database("name");
AbstractMariaDatabase defaultDatabase = basementLib.database();

defaultDatabase.insert()
defaultDatabase.select()
defaultDatabase.update()
defaultDatabase.replace()
defaultDatabase.delete()
defaultDatabase.useTable()
defaultDatabase.createTable()
defaultDatabase.dropTable()
something.where(WhereBuilder.builder().equalsNQ("uuid","?").close())
// Examples
private final QueryBuilderUpdate queryUpdateUserData;

public UserManager() {
    queryUpdateUserData = basement.database().update().table("players")
        .setNQ("xp", "?")
        .setNQ("level", "?").setNQ("coins", "?")
        .setNQ("language", "?")
        .where(WhereBuilder.builder().equalsNQ("uuid", "?").close());
}

// Sync
private void save(UserData data) {
    queryUpdateUserData.patternClone().clearSet()
      .setNQ("xp", data.getXp()).setNQ("level", data.getNetworkLevel())
      .setNQ("coins", data.getNetworkCoins())
      .where(WhereBuilder.builder().equals("uuid", data.getUuid()).close())
      .build().exec();
}

// Async
private CompletableFuture<QueryBuilderUpdate> saveAsync(UserData data) {
    return queryUpdateUserData.patternClone().clearSet()
        .setNQ("xp", data.getXp()).setNQ("level", data.getNetworkLevel())
        .setNQ("coins", data.getNetworkCoins())
        .where(WhereBuilder.builder().equals("uuid", data.getUuid()).close())
        .build().execAsync();
}

More Info: https://github.com/ServerBasement/BasementLib

Last updated