Git Product home page Git Product logo

radon's Introduction

GitHub Downloads (all assets, all releases) GitHub Release Discord

Overview

Radon is a Mindustry HQL client that simplifies the usage of HQL/SQL.

Example

View the file

package example;

import arc.Events;
import arc.files.Fi;
import arc.util.CommandHandler;
import arc.util.Log;
import mindustry.Vars;
import mindustry.game.EventType;
import mindustry.game.EventType.PlayerJoin;
import mindustry.gen.Groups;
import mindustry.mod.Plugin;
import Radon.Radon;
import Radon.RegisterRadonEntities;

public class Example extends Plugin {
    public static void main(String[] args) {
        Vars.modDirectory = new Fi("");
        var r = new Radon();
        r.init();
        Events.on(RegisterRadonEntities.class, event -> event.configuration.addAnnotatedClass(UserData_DBO.class));
        Events.on(EventType.ServerLoadEvent.class, event -> {
            var ud = new UserData_DBO("123123123", "asdajhbdka");
            Radon.saveOrUpdate(ud);
            Log.info("saved!");
            var list = Radon.run("FROM UserData_DBO").getMultiple(UserData_DBO.class);
            for (var a : list)
                Log.info("@: @", a.getUuid(), a.getNickname());
        });
        Events.fire(new EventType.ServerLoadEvent());
    }

    @Override
    public void init() {
        Events.on(PlayerJoin.class, event -> {
            var p = event.player;
            var ud = Radon.run("FROM UserData_DBO WHERE uuid = :uuid").set("uuid", p.uuid()).getSingle(UserData_DBO.class);
            if (ud == null) {
                ud = new UserData_DBO(event.player.uuid(), event.player.plainName());
                Radon.save(ud);
                Log.info("saved!");
            }
            p.name(ud.getNickname());
        });

        Events.on(RegisterRadonEntities.class, event -> {
            //register entity classes used for SQL ORM
            event.configuration.addAnnotatedClass(UserData_DBO.class);
        });
    }

    @Override
    public void registerServerCommands(CommandHandler handler) {
        handler.register("allnicknames", "all nicknames in database", args -> {
            var list = Radon.run("FROM UserData_DBO").getMultiple(UserData_DBO.class);
            for (var a : list)
                Log.info("@: @", a.getUuid(), a.getNickname());
        });
        handler.register("resetonlineusernames", "reset usernames of players currently on the server", args -> {
            Integer r = Radon.run("UPDATE UserData_DBO SET nickname = :name WHERE uuid IN (:list)").set("name", "player").setList("list", Groups.player.copy().list()).update();
            Log.info("@ Entries updated.", r);
        });
    }
}

Setup

MySql Server

Google how to install a MySql server, or chatGPT it. The following is a basic, not all-encompassing guide for linux.

  1. Install MySql on your server.
    sudo apt install -y mysql-server
  2. Go through basic configuration of the MySql server
    sudo mysql_secure_installation
  3. Create a SQL User
    CREATE USER 'mindustry'@'%' IDENTIFIED BY 'password'
  4. Grant the user external access (so it can talk outside localhost)
    GRANT ALL PRIVILEGES ON *.* TO 'mindustry'@'%' WITH GRANT OPTION;
  5. Reload user privileges
    FLUSH PRIVILEGES;

Game Server

  1. Go to Relases, download Radon.jar, and place it inside your mindustry server's mods folder.
  2. Find ./config/mods/Radon/config.json and set the proper SQL url, port, username and password.

Warning

If you are not using MySql, remember to change the driver class and SQL dialect. You would also need a separate plugin to load your SQL Driver if you are not using one of the integrated drivers1.

Development

In order to use this plugin with your custom plugin, you will need to add Radon as dependency.

In gradle, add the following:

repositories {
   //other repositories like maven central
   maven{ url 'https://www.jitpack.io' }
}
dependencies {
   //other dependencies
   compileOnly "com.github.Atomic-Laboratory:Radon:1.0.0"
}

In your plugins.json, append the following:

"dependencies": [
"radon"
]

Building a Jar

gradlew jar / ./gradlew jar

Output jar should be in build/libs.

Footnotes

  1. Radon.jar comes packaged with MySQL, Microsoft SQL, Oracle DB, PostgreSQL, SQLite, and MariaDB. โ†ฉ

radon's People

Contributors

atomic-laboratory avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.