basic stuff
This commit is contained in:
commit
2769fbac42
10 changed files with 532 additions and 0 deletions
39
app/build.gradle.kts
Normal file
39
app/build.gradle.kts
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* This generated file contains a sample Java application project to get you started.
|
||||
* For more details on building Java & JVM projects, please refer to https://docs.gradle.org/8.10.2/userguide/building_java_projects.html in the Gradle documentation.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
// Apply the application plugin to add support for building a CLI application in Java.
|
||||
application
|
||||
}
|
||||
|
||||
repositories {
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = "papermc"
|
||||
url = uri("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Use JUnit Jupiter for testing.
|
||||
testImplementation(libs.junit.jupiter)
|
||||
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
|
||||
// This dependency is used by the application.
|
||||
implementation(libs.guava)
|
||||
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
// Apply a specific Java toolchain to ease working on different environments.
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
}
|
43
app/src/main/java/net/xuyezo/main/Handler.java
Normal file
43
app/src/main/java/net/xuyezo/main/Handler.java
Normal file
|
@ -0,0 +1,43 @@
|
|||
package net.xuyezo.main;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
|
||||
public class Handler implements Listener {
|
||||
Connection cc;
|
||||
|
||||
public Handler(Connection c) {
|
||||
this.cc = c;
|
||||
PreparedStatement stmt;
|
||||
try {
|
||||
stmt = cc.prepareStatement("CREATE TABLE IF NOT EXISTS main.text (username TEXT, date REAL, content TEXT)");
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncChatEvent event) {
|
||||
PreparedStatement stmt;
|
||||
try {
|
||||
stmt = cc.prepareStatement("INSERT INTO main.text (username, date, content) values (?, ?, ?)");
|
||||
stmt.setString(1, event.getPlayer().getName());
|
||||
stmt.setLong(2, System.currentTimeMillis());
|
||||
stmt.setString(3, ((TextComponent) event.message()).content());
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
31
app/src/main/java/net/xuyezo/main/Main.java
Normal file
31
app/src/main/java/net/xuyezo/main/Main.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package net.xuyezo.main;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
String host = this.getConfig().getString("dbhost");
|
||||
String pass = this.getConfig().getString("dbpass");
|
||||
String user = this.getConfig().getString("dbuser");
|
||||
Connection c = null;
|
||||
try {
|
||||
c = DriverManager
|
||||
.getConnection(host,
|
||||
user,pass);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println(e.getClass().getName()+": "+e.getMessage());
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new Handler(c), this);
|
||||
|
||||
Server server = getServer();
|
||||
}
|
||||
}
|
8
app/src/main/resources/plugin.yml
Normal file
8
app/src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
name: DerverCore
|
||||
version: 2.0.0
|
||||
main: net.xuyezo.main.Main
|
||||
description: A test plugin
|
||||
author: BiglyDerv
|
||||
website: https://dervland.net/
|
||||
api-version: '1.21.4'
|
||||
load: STARTUP
|
Loading…
Add table
Add a link
Reference in a new issue