πŸ“ƒ
Wiki
  • πŸŒ‹Plugins
  • Overview
    • πŸ’‘High Quality Products
  • products
    • πŸ›οΈUltimateBedwars
      • ✨Features
      • πŸͺΆInstallation
      • πŸ“œConfiguration
      • πŸ›οΈArena
      • πŸ–±οΈCommand & Permissions
      • πŸŽ‰Party
      • πŸ–₯️For Developers
    • 🌡UltimateOneBlock
      • ✨Features
      • πŸͺΆInstallation
      • πŸ“œConfiguration
      • πŸ•‘Phase
      • πŸ§žβ€β™‚οΈGenerators
      • πŸ–±οΈCommand & Permissions
      • πŸ–₯️For Developers
    • ⛏️UltimateGuilds
      • ✨Features
      • πŸͺΆInstallation
      • πŸ“œConfiguration
      • πŸ–±οΈCommand & Permissions
      • πŸ–₯️For Developers
    • πŸ“œPlayerDataHistory
      • ✨Features
      • πŸͺΆInstallation
      • πŸ“œConfiguration
      • πŸ•ΈοΈWeb Panel
      • πŸ–±οΈCommand & Permissions
    • βš”οΈUltimateTournament
      • ✨Features
      • πŸͺΆInstallation
      • πŸ’‘Placeholders
      • πŸ“œConfiguration
      • 🀺Tournament
      • πŸ–±οΈCommand & Permissions
    • 🏒BasementLib
      • ✨Features
      • πŸ“œConfiguration
    • πŸ“‘Minedock
      • ✨Features
      • πŸͺΆInstallation
      • πŸ“œConfiguration
      • πŸ–₯️For Developers
    • πŸŽ’UltimateMatchmaking
      • ✨Features
Powered by GitBook
On this page
  • Custom Redis Messages
  • MySQL and H2 Query Builder

Was this helpful?

  1. products
  2. BasementLib

Features

PreviousBasementLibNextConfiguration

Last updated 11 months ago

Was this helpful?

Custom Redis Messages

You can send messages via redis and receive them anywhere:

// 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/redisson/redisson/wiki/6.-Distributed-objects#67-topic
https://github.com/ServerBasement/BasementLib