Hilfe bei Minecraft Plugin

BlockCity

Neues Mitglied
Ich habe vor c.a. 3 Wochen mit Java angefangen. Für meinen Minecraft Server wollte ich ein Plugin schreiben. Ich wollte das man mit einer Config (YAML-Datei) das Plugin
configurieren kann. Ich kann mit
Code:
 this.getConfig().getString(MySQL.IP);
das was ich in die
YAML-Datei eingetragen habe, auslesen lassen. Aber wie grieg ich das in die MySQL.java hinein?

QuellCode von Test.java
Java:
package me.blockCity.test;

import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;

public class Test extends JavaPlugin {

	@Override
	public void onEnable() {
		loadConfiguration();
		
		PluginDescriptionFile pdf = this.getDescription();
		System.out.println(pdf.getName() + " version " + pdf.getVersion() + " is enabled");
	}

	@Override
	public void onDisable() {
		PluginDescriptionFile pdf = this.getDescription();
		System.out.println(pdf.getName() + " version " + pdf.getVersion() + " is disabled");
		
	}
	
		public void loadConfiguration() {
					
	    String IP = "MySQL.IP";
		this.getConfig().addDefault(IP, "localhost");
		
		String Port = "MySQL.Port";
		this.getConfig().addDefault(Port, "3306");
		
		String DB = "MySQL.DatenBank";
		this.getConfig().addDefault(DB, "");
		
		String Benutzer = "MySQL.Benutzer";
		this.getConfig().addDefault(Benutzer, "");
		
		String Pw = "MySQL.Passwort";
		this.getConfig().addDefault(Pw, "");
		
		this.getConfig().options().copyDefaults(true);
		this.saveConfig();
	}
}

QuellCode von MySQL.java:
Java:
package me.blockCity.test;

import java.sql.*;
 
public class MySQL {
 
    private static MySQL instance = null;
    private static Connection conn = null;
    
    //Hier sollen die Variablen hin
 
    
    
    private MySQL() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            // und hier sollen sie eingesetzt werden
            conn = DriverManager.getConnection("jdbc:mysql://" + "localhost" + ":" + "3306" + "/" + "DatenBank" + "?" + "user=" + "Benutzer" + "&" + "password=" + "Passwort"); 
        } catch (ClassNotFoundException e) {
            System.out.println("Treiber nicht gefunden");
        } catch (SQLException e) {
            System.out.println("Connect nicht moeglich");
        }
    }
 
    public static MySQL getInstance()
    {
        if(instance == null)
            instance = new MySQL();
        return instance;
    }
 
    public void getName()
    {
 
        if(conn != null)
        {	
            Statement abfrage;
            try {
                abfrage = conn.createStatement();
 
                String sql = "SELECT STONE, DIRT " + "FROM Block_Break ";

                ResultSet result = abfrage.executeQuery(sql);
 
                while (result.next()) {
                    String first_name = result.getString("first_name");
                    String last_name = result.getString("last_name");
                    String name = last_name + ", " + first_name;
                    System.out.println(name);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
 

Zurück
Oben