commit 713d898251a7f16086685cfcbaf61ee75ee499e8 Author: poopki Date: Sun Jul 10 22:27:50 2022 +0900 User management base code diff --git a/DB/DBConnect.java b/DB/DBConnect.java new file mode 100644 index 0000000..41d68fd --- /dev/null +++ b/DB/DBConnect.java @@ -0,0 +1,40 @@ +package org.poopki.duckdns.user_db.DB; + +import java.sql.*; + + +public class DBConnect { + private static final String DB_DRIVER_CLASS = "org.mariadb.jdbc.Driver"; + private static final String DB_URL = "jdbc:mariadb://poopki.duckdns.org:3307/"; + private static final String DB_USERNAME = "mc_dev"; + private static final String DB_PASSWORD = "!Rkdalsrn1027"; + + public static Connection connectDB(){ + Connection conn = null; + Statement stmt = null; + try { + Class.forName("org.mariadb.jdbc.Driver"); + + conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); + System.out.println("Connection success"); + stmt = conn.createStatement(); + StringBuilder sb = new StringBuilder(); + String sql = sb.append("create table if not exists student(") + .append("id int,") + .append("name varchar(20),") + .append("grade int") + .append(");").toString(); + stmt.execute(sql); + } + catch (ClassNotFoundException e) { + e.printStackTrace(); + } + catch (SQLException e) { + // TODO Auto-generated catch block + System.err.println("에러 내용 :" + e.getMessage()); + System.out.println("DB Connection fail"); + } + return conn; + } + +} diff --git a/UserInfo.java b/UserInfo.java new file mode 100644 index 0000000..5f4d3b3 --- /dev/null +++ b/UserInfo.java @@ -0,0 +1,23 @@ +package org.poopki.duckdns.user_db; + +import org.bukkit.entity.Player; + +import java.util.UUID; + +public class UserInfo { + private UUID m_UUID; + private String m_Name; + + UserInfo(Player p){ + m_UUID = p.getUniqueId(); + m_Name = p.getName(); + } + + public String getUserName(){ + return m_Name; + } + + public UUID getUserUUID(){ + return m_UUID; + } +} diff --git a/UserInfoArray.java b/UserInfoArray.java new file mode 100644 index 0000000..b60e700 --- /dev/null +++ b/UserInfoArray.java @@ -0,0 +1,22 @@ +package org.poopki.duckdns.user_db; + +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class UserInfoArray { + static Map m_UserInfoArray = new HashMap(); + + public void getUserInfo(Player p) { + UserInfo m_UserInfo = m_UserInfoArray.get(p.getUniqueId()); + p.sendMessage(m_UserInfo.getUserName() + m_UserInfo.getUserUUID() + ("중복 입장")); + } + + public void putUserInfo(Player p) { + m_UserInfoArray.put(p.getUniqueId(), new UserInfo(p)); + UserInfo m_UserInfo = m_UserInfoArray.get(p.getUniqueId()); + p.sendMessage(m_UserInfo.getUserName() + m_UserInfo.getUserUUID() + ("초기 입장")); + } +} \ No newline at end of file diff --git a/UserJoin.java b/UserJoin.java new file mode 100644 index 0000000..b8611d5 --- /dev/null +++ b/UserJoin.java @@ -0,0 +1,22 @@ +package org.poopki.duckdns.user_db; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class UserJoin implements Listener { + private UserInfoArray m_InfoArray; + UserJoin(UserInfoArray m_UIA){ + m_InfoArray = m_UIA; + } + @EventHandler + public void PlayerLogin(PlayerJoinEvent e) { + Player p = e.getPlayer(); + if(m_InfoArray.m_UserInfoArray.containsKey(p.getUniqueId())){ + m_InfoArray.getUserInfo(p); + } + else{ + m_InfoArray.putUserInfo(p); + } + } +} \ No newline at end of file diff --git a/User_DB.java b/User_DB.java new file mode 100644 index 0000000..d910b0f --- /dev/null +++ b/User_DB.java @@ -0,0 +1,24 @@ +package org.poopki.duckdns.user_db; + +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; +import org.poopki.duckdns.user_db.DB.*; +import java.sql.Connection; +import java.sql.Statement; + + +public final class User_DB extends JavaPlugin implements Listener { + UserInfoArray m_UIA = new UserInfoArray(); + + @Override + public void onEnable() { + // Plugin startup logic + Connection conn = new DBConnect().connectDB(); + getServer().getPluginManager().registerEvents(new UserJoin(m_UIA),this); + } + + @Override + public void onDisable() { + // Plugin shutdown logic + } +} \ No newline at end of file