事件块
package minecord.plugingenerin.Event;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import javax.management.timer.Timer;
import java.util.concurrent.ExecutorService;
public class EventBlock implements Listener {
@EventHandler
public void onDestroy(BlockBreakEvent blockBreak) throws SQLException {
Player player = blockBreak.getPlayer(); //Получение игрока
Block block = blockBreak.getBlock();
Location loc = block.getLocation();
World world = block.getWorld();
Material material = block.getType();
player.sendMessage("Блок сломан");
SqliteDB db =new SqliteDB();
db.insert(loc,player);
}
}
SqliteDB
package minecord.plugingenerin.Event;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class SqliteDB {
SqliteDB program = new SqliteDB();
Connection c = DriverManager.getConnection("jdbc:sqlite:memory:F:/Location.db");
Statement stmt = c.createStatement();
void insert(Location location, Player user) throws SQLException {
stmt.executeUpdate("insert LocatioInfo values('"+location+"','"+user+"')");
stmt.executeUpdate("backup to C:Users/Татьяна/Desktop/Server 1.20.1 paper/plugins/DB/backup.db");
}
public SqliteDB() throws SQLException {
stmt.executeUpdate("create table Location(Location Location, User TEXT)");
}
}
错误
[16:56:39 错误]:无法将事件 BlockBreakEvent 传递给 PluginGenerin v1.0 java.lang.StackOverflowError: null 在minecord.plugingenerin.Event.SqliteDB.(SqliteDB.java:12)~[original-PluginGenerin-1.0.jar:?] 在minecord.plugingenerin.Event.SqliteDB.(SqliteDB.java:12)~[original-PluginGenerin-1.0.jar:?] 在minecord.plugingenerin.Event.SqliteDB.(SqliteDB.java:12)~[original-PluginGenerin-1.0.jar:?] 在minecord.plugingenerin.Event.SqliteDB.(SqliteDB.java:12)~[original-PluginGenerin-1.0.jar:?] 在minecord.plugingenerin.Event.SqliteDB.(SqliteDB.java:12)~[original-PluginGenerin-1.0.jar:?] 在minecord.plugingenerin.Event.SqliteDB.(SqliteDB.java:12)~[original-PluginGenerin-1.0.jar:?]
我尝试删除 SqliteDB db =new SqliteDB(); db.insert(loc,玩家);
您的问题是由以下语句引起的:
public class SqliteDB {
SqliteDB program = new SqliteDB();
...
}
当类 SqliteDB 被实例化时,字段
program
被创建并分配给一个新的 SqliteDB 类,该类有一个字段 program
被创建并分配给新的 SqliteDB 类,依此类推,直到发生堆栈溢出。