commit
713d898251
5 changed files with 131 additions and 0 deletions
@ -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; |
||||
} |
||||
|
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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<UUID, UserInfo> m_UserInfoArray = new HashMap<UUID, UserInfo>(); |
||||
|
||||
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() + ("초기 입장")); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
@ -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
|
||||
} |
||||
} |
Loading…
Reference in new issue