Group Event Handler 분리

Group_System
poopki 2 years ago
parent 6037d17087
commit 8295f06691
  1. 1
      AccountArray.java
  2. 1
      AccountEventHandler.java
  3. 180
      DB/DBUpdate.java
  4. 47
      Farm.java
  5. 162
      FarmArray.java
  6. 188
      FarmEventHandler.java
  7. 17
      Group.java
  8. 51
      GroupArray.java
  9. 47
      Nation.java
  10. 162
      NationArray.java
  11. 232
      NationEventHandler.java
  12. 14
      User_DB.java

@ -26,6 +26,7 @@ public class AccountArray {
}
}
public int getAccountInfo(UUID uuid) { // DB backup시 account 정보 접근 method
Account m_Account = m_AccountArray.get(uuid);
return m_Account.getBalance();

@ -38,7 +38,6 @@ public class AccountEventHandler implements CommandExecutor {
} else{
p.sendMessage("최대 금액 이상으로 설정할 수 없습니다.");
}
} else {
p.sendMessage("설정 금액은 숫자만 가능합니다.");
}

@ -1,9 +1,11 @@
package org.poopki.duckdns.user_db.DB;
import org.poopki.duckdns.user_db.AccountArray;
import org.poopki.duckdns.user_db.UserInfoArray;
import org.poopki.duckdns.user_db.*;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public class DBUpdate {
@ -14,9 +16,15 @@ public class DBUpdate {
private static UserInfoArray m_InfoArrayInstance;
private static AccountArray m_AccountArray;
public DBUpdate(UserInfoArray UIA, AccountArray AA){
private static FarmArray m_FarmArray;
private static NationArray m_NationArray;
UUID ZERO_UUID = new UUID(0,0);
static int MAX_FARM_NUM = 13;
public DBUpdate(UserInfoArray UIA, AccountArray AA, FarmArray FA, NationArray NA){
m_InfoArrayInstance = UIA;
m_AccountArray = AA;
m_FarmArray = FA;
m_NationArray = NA;
}
public static void InitDB() throws SQLException { // 플러그인 초기 사용 시 테이블 생성
@ -33,9 +41,9 @@ public class DBUpdate {
String sql = sb.append("create table if not exists UserInfo(")
.append("UUID varchar(36) PRIMARY KEY,")
.append("Name varchar(15), ")
.append("Nation int(8),") //public
.append("Squad int(8),") //public
.append("Farm int(8),") //public
.append("Nation varchar(36),") //public
.append("Squad varchar(36),") //public
.append("Farm varchar(36),") //public
.append("Account int(10)") //public
/*
.append("Occupation int(8),") //private
@ -92,13 +100,83 @@ public class DBUpdate {
conn.close();
}
}
try {
Class.forName("org.mariadb.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
System.out.println("Connection success");
stmt = conn.createStatement();
String sql = "SELECT * FROM Farm";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
List<UUID> m_MemberList = new ArrayList<>();
for(int index = 4; index<MAX_FARM_NUM; index++){
m_MemberList.add(index-4,UUID.fromString(rs.getString(index)));
}
m_FarmArray.PutGroup(UUID.fromString(rs.getString(1)),
rs.getString(2),
m_MemberList);
m_AccountArray.putAccountInfo(UUID.fromString(rs.getString(1)),Integer.parseInt(rs.getString(3)));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (SQLException e) {
// TODO Auto-generated catch block
System.err.println("에러 내용 :" + e.getMessage());
System.out.println("DB Connection fail");
}finally{
if(conn != null && !conn.isClosed()){
conn.close();
}
}
try {
Class.forName("org.mariadb.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
System.out.println("Connection success");
stmt = conn.createStatement();
String sql = "SELECT * FROM Nation";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
List<UUID> m_MemberList = new ArrayList<>();
for(int index = 4; index<MAX_FARM_NUM; index++){
m_MemberList.add(index-4,UUID.fromString(rs.getString(index)));
}
m_NationArray.PutGroup(UUID.fromString(rs.getString(1)),
rs.getString(2),
m_MemberList);
m_AccountArray.putAccountInfo(UUID.fromString(rs.getString(1)),Integer.parseInt(rs.getString(3)));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (SQLException e) {
// TODO Auto-generated catch block
System.err.println("에러 내용 :" + e.getMessage());
System.out.println("DB Connection fail");
}finally{
if(conn != null && !conn.isClosed()){
conn.close();
}
}
}
public void UpdateDB() throws SQLException { // 서버 종료시 DB 업데이트
Connection conn = null;
PreparedStatement pstmt;
// Update UserINFO
try{
Class.forName("org.mariadb.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
@ -135,5 +213,93 @@ public class DBUpdate {
conn.close();
}
}
// Update Farm Info
try{
Class.forName("org.mariadb.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
for (UUID key : m_FarmArray.getKeySet()) {
String sql = "REPLACE INTO Farm VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, String.valueOf(key.toString()));
pstmt.setString(2, String.valueOf(m_FarmArray.GetGroupName(key)));
pstmt.setString(3, String.valueOf(m_AccountArray.getAccountInfo(key)));
int index = 4;
for (UUID MemUUID : m_FarmArray.GetGroupMembersUUID(key)){
pstmt.setString(index, String.valueOf(MemUUID.toString()));
index++;
}
for(; index<=MAX_FARM_NUM;index++){
pstmt.setString(index, String.valueOf(ZERO_UUID));
}
int cnt = pstmt.executeUpdate();
if( cnt == 0 ){
System.out.println("데이터 입력 실패");
}
else{
System.out.println("데이터 입력 성공");
}
}
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
catch(SQLException e){
System.err.println("에러 내용 :" + e.getMessage());
System.out.println("DB Connection fail");
}
finally {
if( conn != null && !conn.isClosed()){
conn.close();
}
}
// Update nation Info
try{
Class.forName("org.mariadb.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
for (UUID key : m_NationArray.getKeySet()) {
String sql = "REPLACE INTO Nation VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, String.valueOf(key.toString()));
pstmt.setString(2, String.valueOf(m_NationArray.GetGroupName(key)));
pstmt.setString(3, String.valueOf(m_AccountArray.getAccountInfo(key)));
int index = 4;
for (UUID MemUUID : m_NationArray.GetGroupMembersUUID(key)){
pstmt.setString(index, String.valueOf(MemUUID.toString()));
index++;
}
for(; index<=MAX_FARM_NUM;index++){
pstmt.setString(index, String.valueOf(ZERO_UUID));
}
int cnt = pstmt.executeUpdate();
if( cnt == 0 ){
System.out.println("데이터 입력 실패");
}
else{
System.out.println("데이터 입력 성공");
}
}
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
catch(SQLException e){
System.err.println("에러 내용 :" + e.getMessage());
System.out.println("DB Connection fail");
}
finally {
if( conn != null && !conn.isClosed()){
conn.close();
}
}
}
}

@ -0,0 +1,47 @@
package org.poopki.duckdns.user_db;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class Farm {
private String m_Name;
private List<UUID> m_MemberList = new ArrayList<>();
UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
int MAX_FARM_NUM = 13;
public Farm(String Name, List<UUID> uuid_list){
int index = 0;
for(UUID key: uuid_list){
m_MemberList.add(index,key);
index++;
}
m_Name = Name;
}
public void SignUp(UUID uuid){
m_MemberList.add((UUID)uuid);
}
public void Expulsion(UUID uuid){
m_MemberList.remove(uuid);
m_MemberList.add(ZERO_UUID);
}
public boolean isMember(UUID uuid){
return m_MemberList.contains(uuid);
}
public List<UUID> getGroupMembers(){ return m_MemberList;}
public String getGroupName(){ return m_Name; }
public int isEmpty(){return m_MemberList.size();}
public boolean isOwner(UUID uuid){
if(m_MemberList.get(0).equals(uuid)){
return true;
}else{
return false;
}
}
}

@ -0,0 +1,162 @@
package org.poopki.duckdns.user_db;
import org.bukkit.Bukkit;
import java.util.*;
public class FarmArray {
public static Map<UUID, Farm> m_GroupArray;
public static Map<String, UUID> m_GroupNameList;
UserInfoArray m_UserInfoArray;
UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
int MAX_GROUP_NUM = 13;
public FarmArray(UserInfoArray m_UIA){
m_UserInfoArray = m_UIA;
m_GroupArray = new HashMap<UUID, Farm>();
m_GroupNameList = new HashMap<String, UUID>();
}
public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){
if(m_GroupNameList.containsKey(Name)){
return false; // Conflict
} else{
List<UUID> m_MemberList = new ArrayList<>();
m_MemberList.add(PlayerUUID);
for(int index=1; index<MAX_GROUP_NUM;index++){
m_MemberList.add(index,ZERO_UUID);
}
m_GroupArray.put(GroupUUID, new Farm(Name, m_MemberList));
m_GroupNameList.put(Name, GroupUUID);
return true;
}
}
public boolean PutGroup(UUID GroupUUID, String Name,List<UUID> PlayerUUID){
List<UUID> m_MemberList = new ArrayList<>();
Iterator <UUID> it = PlayerUUID.iterator();
while(it.hasNext()){
m_MemberList.add(it.next());
}
for(int index=MAX_GROUP_NUM-PlayerUUID.size();index<MAX_GROUP_NUM;index++){
m_MemberList.add(ZERO_UUID);
}
m_GroupArray.put(GroupUUID, new Farm(Name, m_MemberList));
m_GroupNameList.put(Name,GroupUUID);
return true;
}
public UUID GetUUID(String name){
return m_GroupNameList.get(name);
}
public boolean CheckGroup(String GroupType, String Name){
return m_GroupArray.containsKey(m_GroupNameList.get(Name));
}
public static <K, V> K getKey(Map<K, V> map, V value) {
for (K key : map.keySet()) {
if (value.equals(map.get(key))) {
return key;
}
}
return null;
}
public boolean DeleteGroup(UUID GroupUUID, String GroupType){
if(m_GroupArray.containsKey(GroupUUID)){
for(UUID key: GetGroupMembersUUID(GroupUUID)){
m_UserInfoArray.setUserGroupUUID(GroupType,key,new UUID(0,0));
}
m_GroupNameList.remove(GetGroupName(GroupUUID));
m_GroupArray.remove(GroupUUID);
return true;
}
else{
return false; // Group is not exists.
}
}
public Integer SignUpGroup(String GroupType, UUID GroupUUID, UUID PlayerUUID){
if(m_GroupArray.containsKey(GroupUUID)){
if(isOffline(PlayerUUID)){
Farm m_Group = m_GroupArray.get(GroupUUID);
m_Group.SignUp(PlayerUUID);
m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,GroupUUID);
return 1; // Success
}else{
return 2; // Offline Player
}
} else{
return 3; // Wrong Group
}
}
public boolean ExpulsionGroupPlayer(String GroupType, UUID GroupUUID, UUID PlayerUUID){
if(m_GroupArray.get(GroupUUID).isMember(PlayerUUID)) {
Farm m_Group = m_GroupArray.get(GroupUUID);
m_Group.Expulsion(PlayerUUID);
m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,ZERO_UUID);
List<UUID> temp = m_Group.getGroupMembers();
if(temp.get(0).equals(ZERO_UUID)){
m_GroupArray.remove(GroupUUID);
m_GroupNameList.remove(getKey(m_GroupNameList,GroupUUID));
}
return true;
} else{
return false; // Wrong Player Name. FIXME{Need Checking function for a validate user name's }
/* Player op = Bukkit.getPlayer(args[1]);
if (op != null) {
*/
}
}
public List<String> GetGroupMembersName(UUID GroupUUID){
List<String> MembersName = new ArrayList<>();
for (UUID key : m_GroupArray.get(GroupUUID).getGroupMembers()){
try {
MembersName.add(Bukkit.getPlayer(key).getDisplayName());
}
catch(NullPointerException e){
}
}
return MembersName;
}
public List<UUID> GetGroupMembersUUID(UUID GroupUUID){
return m_GroupArray.get(GroupUUID).getGroupMembers();
}
public boolean isGroupMember(UUID GroupUUID, UUID PlayerUUID){
Farm m_Group = m_GroupArray.get(GroupUUID);
return m_Group.isMember(PlayerUUID);
}
public Set<String> GetGroupNameList(){
return m_GroupNameList.keySet();
}
public Set<UUID> getKeySet(){ // 유저 목록 return
return m_GroupArray.keySet();
}
public Set<String> getNameSet() { return m_GroupNameList.keySet(); }
public String GetGroupName(UUID GroupUUID){
Farm m_Group = m_GroupArray.get(GroupUUID);
return m_Group.getGroupName();
}
public static boolean isOffline(UUID uuid){
return Bukkit.getPlayer(uuid).equals(null) && !Bukkit.getOfflinePlayer(uuid).equals(null);
}
public static boolean isOwner(UUID GroupUUID, UUID PlayerUUID){
return m_GroupArray.get(GroupUUID).isOwner(PlayerUUID);
}
private boolean isAvaliableGroup(UUID GroupUUID){
return m_GroupArray.containsKey(GroupUUID);
}
}

@ -1,5 +1,6 @@
package org.poopki.duckdns.user_db;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -9,12 +10,22 @@ import java.util.UUID;
public class FarmEventHandler implements CommandExecutor {
GroupArray m_GroupArray;
FarmArray m_FarmArray;
UserInfoArray m_UserInfoArray;
AccountArray m_AccountArray;
UUID ZERO_UUID = new UUID(0,0);
public FarmEventHandler(GroupArray GA, UserInfoArray UIA){
m_GroupArray = GA;
public FarmEventHandler(FarmArray GA, UserInfoArray UIA, AccountArray AA){
m_FarmArray = GA;
m_UserInfoArray = UIA;
m_AccountArray = AA;
}
public static boolean isStringDouble(String s) {
try {
Double.parseDouble(s);
return true;
} catch (NumberFormatException e) {
return false;
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -25,15 +36,16 @@ public class FarmEventHandler implements CommandExecutor {
case "생성":{
UUID tempUUID = UUID.randomUUID();
if(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm").equals(ZERO_UUID)){
if(m_GroupArray.CreateGroup(tempUUID, args[1], p.getUniqueId())){
if(m_FarmArray.CreateGroup(tempUUID, args[1], p.getUniqueId())){
m_UserInfoArray.setUserGroupUUID("Farm",p.getUniqueId(), tempUUID);
m_AccountArray.putAccountInfo(tempUUID,0);
p.sendMessage(args[1]+"농장이 생성되었습니다.");
p.sendMessage("농장 멤버 목록: ");
for (String Name: m_GroupArray.GetGroupMembersName(tempUUID)){
for (String Name: m_FarmArray.GetGroupMembersName(tempUUID)){
p.sendMessage(Name);
}
p.sendMessage("농장 목록:");
for (String Name: m_GroupArray.GetGroupNameList()){
for (String Name: m_FarmArray.GetGroupNameList()){
p.sendMessage(Name);
}
}
@ -54,13 +66,13 @@ public class FarmEventHandler implements CommandExecutor {
}
else{
p.sendMessage("가입 완료");
m_GroupArray.SignUpGroup("Farm",m_GroupArray.m_GroupNameList.get(args[1]),p.getUniqueId());
m_FarmArray.SignUpGroup("Farm",m_FarmArray.m_GroupNameList.get(args[1]),p.getUniqueId());
p.sendMessage("농장 멤버 목록: ");
for (String Name: m_GroupArray.GetGroupMembersName(m_GroupArray.m_GroupNameList.get(args[1]))){
for (String Name: m_FarmArray.GetGroupMembersName(m_FarmArray.m_GroupNameList.get(args[1]))){
p.sendMessage(Name);
}
p.sendMessage("농장 목록:");
for (String Name: m_GroupArray.GetGroupNameList()){
for (String Name: m_FarmArray.GetGroupNameList()){
p.sendMessage(Name);
}
}
@ -72,31 +84,177 @@ public class FarmEventHandler implements CommandExecutor {
}
case "강퇴":{
p.sendMessage("강퇴 테스트");
if(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm").equals(ZERO_UUID)){
p.sendMessage("가입한 농장이 없습니다."+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm"));
}
else{
if(m_FarmArray.isOwner(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm"), p.getUniqueId())){
if (args.length > 1) {
Player op = Bukkit.getPlayer(args[1]);
if (op != null) {
if(m_FarmArray.isGroupMember(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm"),op.getUniqueId())) {
m_FarmArray.ExpulsionGroupPlayer("Farm", m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm"), p.getUniqueId());
}
else{
p.sendMessage("농장에 가입되지 않은 유저");
}
}
else{
p.sendMessage("잘못된 대상");
}
}
else{
p.sendMessage("강퇴할 대상을 지정");
}
}
else{
p.sendMessage("농장주만 사용 가능한 명령어"+ p.getUniqueId());
}
}
break;
}
case "탈퇴": {
if(!m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm").equals(ZERO_UUID)){
m_GroupArray.ExpulsionGroupPlayer("Farm",m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),"Farm"),p.getUniqueId());
if(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm").equals(ZERO_UUID)){
p.sendMessage("가입한 농장이 없습니다."+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm"));
}
else{
p.sendMessage("가입한 농장이 없습니다."+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm"));
p.sendMessage("탈퇴 플레이어 UUID:"+p.getUniqueId()+" 농장 UUID:"+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Farm"));
m_FarmArray.ExpulsionGroupPlayer("Farm",m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),"Farm"),p.getUniqueId());
}
break;
}
case "이름":{
p.sendMessage("현재 파티 이름"+m_GroupArray.GetGroupName(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),"Party")));
p.sendMessage("현재 파티 이름"+m_FarmArray.GetGroupName(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),"Party")));
break;
}
case "정보": {
for (String Name: m_GroupArray.GetGroupNameList()){
for (String Name: m_FarmArray.GetGroupNameList()){
p.sendMessage("농장 이름:");
p.sendMessage(Name);
p.sendMessage("인원 목록");
for (String Name2: m_GroupArray.GetGroupMembersName(m_GroupArray.m_GroupNameList.get(Name))) {
for (String Name2: m_FarmArray.GetGroupMembersName(m_FarmArray.m_GroupNameList.get(Name))) {
p.sendMessage(Name2);
}
p.sendMessage("계좌 잔액:"+m_AccountArray.getAccountInfo(m_FarmArray.m_GroupNameList.get(Name)));
}
}
case "계좌설정":{
if (p.isOp()) {
if (args.length > 1) {
if (args[1] != null) {
UUID op = m_FarmArray.m_GroupNameList.get(args[1]);
if (op != null) {
if (args.length > 2) {
if (isStringDouble(args[2])) {
if(m_AccountArray.setAccountInfo(op, Long.parseLong(args[2]))){
p.sendMessage(args[1] + "님의 잔액을 " + Integer.parseInt(args[2]) + "원으로 설정하였습니다.");
} else{
p.sendMessage("최대 금액 이상으로 설정할 수 없습니다.");
}
} else {
p.sendMessage("설정 금액은 숫자만 가능합니다.");
}
} else {
p.sendMessage("설정 금액을 입력해주세요.");
}
} else {
p.sendMessage("잘못된 계좌입니다.");
}
}
}else{
p.sendMessage("설정 대상이 지정되지 않았습니다.");
}
} else {
p.sendMessage("관리자만 실행 가능한 명령어입니다.");
}
break;
}
case "입금": {
if (args.length > 1) {
if(args.length > 2) {
UUID op = m_FarmArray.m_GroupNameList.get(args[1]);
if (op != null) {
if (isStringDouble(args[2])) {
if(p.getUniqueId() != op) {
switch(m_AccountArray.transfer(p.getUniqueId(), op, Long.parseLong(args[2])))
{
case 1: {
p.sendMessage(args[1] + "농장에 " + Integer.parseInt(args[2]) + "원을 이체하였습니다.");
break;
}
case 2: {
p.sendMessage("잔액은 최대 금액을 초과할 수 없습니다.");
break;
}
case 3:{
p.sendMessage("잔액이 부족합니다.");
break;
}
}
} else{
p.sendMessage("자기 자신에게는 이체할 수 없습니다.");
}
} else {
p.sendMessage("이체 금액은 숫자만 가능합니다.");
}
} else {
p.sendMessage("잘못된 계좌입니다.");
}
} else {
p.sendMessage("이체 금액을 입력해주세요.");
}
} else {
p.sendMessage("이체 대상이 지정되지 않았습니다.");
}
break;
}
case "출금": {
if (args.length > 1) {
if(args.length > 2) {
UUID op = m_FarmArray.m_GroupNameList.get(args[1]);
if (op != null) {
if (isStringDouble(args[2])) {
if(p.getUniqueId() != op) {
switch(m_AccountArray.transfer(op,p.getUniqueId(), Long.parseLong(args[2])))
{
case 1: {
p.sendMessage(args[1] + "농장에서 " + Integer.parseInt(args[2]) + "원을 출금하였습니다.");
break;
}
case 2: {
p.sendMessage("잔액은 최대 금액을 초과할 수 없습니다.");
break;
}
case 3:{
p.sendMessage("잔액이 부족합니다.");
break;
}
}
} else{
p.sendMessage("자기 자신에게는 이체할 수 없습니다.");
}
} else {
p.sendMessage("이체 금액은 숫자만 가능합니다.");
}
} else {
p.sendMessage("잘못된 계좌입니다.");
}
} else {
p.sendMessage("이체 금액을 입력해주세요.");
}
} else {
p.sendMessage("이체 대상이 지정되지 않았습니다.");
}
break;
}
case "잔액": {
p.sendMessage("==잔액: " + m_AccountArray.getAccountInfo(m_FarmArray.GetUUID(args[1]))+ "원==");
break;
}
default: {
p.sendMessage("잘못된 명령어");
}
}
}
return true;

@ -7,18 +7,25 @@ import java.util.UUID;
public class Group {
private String m_Name;
private List<UUID> m_MemberList = new ArrayList<>();
UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
int MAX_FARM_NUM = 13;
public Group(String Name, UUID uuid){
m_MemberList.add(0, uuid);
public Group(String Name, List<UUID> uuid_list){
int index = 0;
for(UUID key: uuid_list){
m_MemberList.add(index,key);
index++;
}
m_Name = Name;
}
public void SignUp(UUID uuid){
m_MemberList.add(uuid);
m_MemberList.add((UUID)uuid);
}
public void Expulsion(UUID uuid){
m_MemberList.remove(uuid);
m_MemberList.add(ZERO_UUID);
}
public boolean isMember(UUID uuid){
@ -26,10 +33,12 @@ public class Group {
}
public List<UUID> getGroupMembers(){ return m_MemberList;}
public String getGroupName(){ return m_Name; }
public int isEmpty(){return m_MemberList.size();}
public boolean isOwner(UUID uuid){
if(m_MemberList.get(0)==uuid){
if(m_MemberList.get(0).equals(uuid)){
return true;
}else{
return false;

@ -5,24 +5,52 @@ import org.bukkit.Bukkit;
import java.util.*;
public class GroupArray {
public static Map<UUID, Group> m_GroupArray = new HashMap<UUID, Group>();
public static Map<String, UUID> m_GroupNameList = new HashMap<String, UUID>();
public static Map<UUID, Group> m_GroupArray;
public static Map<String, UUID> m_GroupNameList;
UserInfoArray m_UserInfoArray;
UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
int MAX_GROUP_NUM = 13;
public GroupArray(UserInfoArray m_UIA){
m_UserInfoArray = m_UIA;
m_GroupArray = new HashMap<UUID, Group>();
m_GroupNameList = new HashMap<String, UUID>();
}
public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){
if(m_GroupNameList.containsKey(Name)){
return false; // Conflict
} else{
m_GroupArray.put(GroupUUID, new Group(Name, PlayerUUID));
List<UUID> m_MemberList = new ArrayList<>();
m_MemberList.add(PlayerUUID);
for(int index=1; index<MAX_GROUP_NUM;index++){
m_MemberList.add(index,ZERO_UUID);
}
m_GroupArray.put(GroupUUID, new Group(Name, m_MemberList));
m_GroupNameList.put(Name, GroupUUID);
return true;
}
}
public boolean PutGroup(UUID GroupUUID, String Name,List<UUID> PlayerUUID){
List<UUID> m_MemberList = new ArrayList<>();
Iterator <UUID> it = PlayerUUID.iterator();
while(it.hasNext()){
m_MemberList.add(it.next());
}
for(int index=MAX_GROUP_NUM-PlayerUUID.size();index<MAX_GROUP_NUM;index++){
m_MemberList.add(ZERO_UUID);
}
m_GroupArray.put(GroupUUID, new Group(Name, m_MemberList));
m_GroupNameList.put(Name,GroupUUID);
return true;
}
public boolean CheckGroup(String GroupType, String Name){
return m_GroupArray.containsKey(m_GroupNameList.get(Name));
}
@ -71,7 +99,8 @@ public class GroupArray {
Group m_Group = m_GroupArray.get(GroupUUID);
m_Group.Expulsion(PlayerUUID);
m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,ZERO_UUID);
if(m_Group.isEmpty()==0){
List<UUID> temp = m_Group.getGroupMembers();
if(temp.get(0).equals(ZERO_UUID)){
m_GroupArray.remove(GroupUUID);
m_GroupNameList.remove(getKey(m_GroupNameList,GroupUUID));
}
@ -87,7 +116,12 @@ public class GroupArray {
public List<String> GetGroupMembersName(UUID GroupUUID){
List<String> MembersName = new ArrayList<>();
for (UUID key : m_GroupArray.get(GroupUUID).getGroupMembers()){
MembersName.add(Bukkit.getPlayer(key).getDisplayName());
try {
MembersName.add(Bukkit.getPlayer(key).getDisplayName());
}
catch(NullPointerException e){
}
}
return MembersName;
}
@ -103,7 +137,11 @@ public class GroupArray {
return m_GroupNameList.keySet();
}
public Set<UUID> getKeySet(){ // 유저 목록 return
return m_GroupArray.keySet();
}
public Set<String> getNameSet() { return m_GroupNameList.keySet(); }
public String GetGroupName(UUID GroupUUID){
Group m_Group = m_GroupArray.get(GroupUUID);
return m_Group.getGroupName();
@ -112,6 +150,9 @@ public class GroupArray {
return Bukkit.getPlayer(uuid).equals(null) && !Bukkit.getOfflinePlayer(uuid).equals(null);
}
public static boolean isOwner(UUID GroupUUID, UUID PlayerUUID){
return m_GroupArray.get(GroupUUID).isOwner(PlayerUUID);
}
private boolean isAvaliableGroup(UUID GroupUUID){
return m_GroupArray.containsKey(GroupUUID);
}

@ -0,0 +1,47 @@
package org.poopki.duckdns.user_db;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class Nation {
private String m_Name;
private List<UUID> m_MemberList = new ArrayList<>();
UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
int MAX_FARM_NUM = 13;
public Nation(String Name, List<UUID> uuid_list){
int index = 0;
for(UUID key: uuid_list){
m_MemberList.add(index,key);
index++;
}
m_Name = Name;
}
public void SignUp(UUID uuid){
m_MemberList.add((UUID)uuid);
}
public void Expulsion(UUID uuid){
m_MemberList.remove(uuid);
m_MemberList.add(ZERO_UUID);
}
public boolean isMember(UUID uuid){
return m_MemberList.contains(uuid);
}
public List<UUID> getGroupMembers(){ return m_MemberList;}
public String getGroupName(){ return m_Name; }
public int isEmpty(){return m_MemberList.size();}
public boolean isOwner(UUID uuid){
if(m_MemberList.get(0).equals(uuid)){
return true;
}else{
return false;
}
}
}

@ -0,0 +1,162 @@
package org.poopki.duckdns.user_db;
import org.bukkit.Bukkit;
import java.util.*;
public class NationArray {
public static Map<UUID, Nation> m_GroupArray;
public static Map<String, UUID> m_GroupNameList;
UserInfoArray m_UserInfoArray;
UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
int MAX_GROUP_NUM = 13;
public NationArray(UserInfoArray m_UIA){
m_UserInfoArray = m_UIA;
m_GroupArray = new HashMap<UUID, Nation>();
m_GroupNameList = new HashMap<String, UUID>();
}
public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){
if(m_GroupNameList.containsKey(Name)){
return false; // Conflict
} else{
List<UUID> m_MemberList = new ArrayList<>();
m_MemberList.add(PlayerUUID);
for(int index=1; index<MAX_GROUP_NUM;index++){
m_MemberList.add(index,ZERO_UUID);
}
m_GroupArray.put(GroupUUID, new Nation(Name, m_MemberList));
m_GroupNameList.put(Name, GroupUUID);
return true;
}
}
public UUID GetUUID(String name){
return m_GroupNameList.get(name);
}
public boolean PutGroup(UUID GroupUUID, String Name,List<UUID> PlayerUUID){
List<UUID> m_MemberList = new ArrayList<>();
Iterator <UUID> it = PlayerUUID.iterator();
while(it.hasNext()){
m_MemberList.add(it.next());
}
for(int index=MAX_GROUP_NUM-PlayerUUID.size();index<MAX_GROUP_NUM;index++){
m_MemberList.add(ZERO_UUID);
}
m_GroupArray.put(GroupUUID, new Nation(Name, m_MemberList));
m_GroupNameList.put(Name,GroupUUID);
return true;
}
public boolean CheckGroup(String GroupType, String Name){
return m_GroupArray.containsKey(m_GroupNameList.get(Name));
}
public static <K, V> K getKey(Map<K, V> map, V value) {
for (K key : map.keySet()) {
if (value.equals(map.get(key))) {
return key;
}
}
return null;
}
public boolean DeleteGroup(UUID GroupUUID, String GroupType){
if(m_GroupArray.containsKey(GroupUUID)){
for(UUID key: GetGroupMembersUUID(GroupUUID)){
m_UserInfoArray.setUserGroupUUID(GroupType,key,new UUID(0,0));
}
m_GroupNameList.remove(GetGroupName(GroupUUID));
m_GroupArray.remove(GroupUUID);
return true;
}
else{
return false; // Group is not exists.
}
}
public Integer SignUpGroup(String GroupType, UUID GroupUUID, UUID PlayerUUID){
if(m_GroupArray.containsKey(GroupUUID)){
if(isOffline(PlayerUUID)){
Nation m_Group = m_GroupArray.get(GroupUUID);
m_Group.SignUp(PlayerUUID);
m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,GroupUUID);
return 1; // Success
}else{
return 2; // Offline Player
}
} else{
return 3; // Wrong Group
}
}
public boolean ExpulsionGroupPlayer(String GroupType, UUID GroupUUID, UUID PlayerUUID){
if(m_GroupArray.get(GroupUUID).isMember(PlayerUUID)) {
Nation m_Group = m_GroupArray.get(GroupUUID);
m_Group.Expulsion(PlayerUUID);
m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,ZERO_UUID);
List<UUID> temp = m_Group.getGroupMembers();
if(temp.get(0).equals(ZERO_UUID)){
m_GroupArray.remove(GroupUUID);
m_GroupNameList.remove(getKey(m_GroupNameList,GroupUUID));
}
return true;
} else{
return false; // Wrong Player Name. FIXME{Need Checking function for a validate user name's }
/* Player op = Bukkit.getPlayer(args[1]);
if (op != null) {
*/
}
}
public List<String> GetGroupMembersName(UUID GroupUUID){
List<String> MembersName = new ArrayList<>();
for (UUID key : m_GroupArray.get(GroupUUID).getGroupMembers()){
try {
MembersName.add(Bukkit.getPlayer(key).getDisplayName());
}
catch(NullPointerException e){
}
}
return MembersName;
}
public List<UUID> GetGroupMembersUUID(UUID GroupUUID){
return m_GroupArray.get(GroupUUID).getGroupMembers();
}
public boolean isGroupMember(UUID GroupUUID, UUID PlayerUUID){
Nation m_Group = m_GroupArray.get(GroupUUID);
return m_Group.isMember(PlayerUUID);
}
public Set<String> GetGroupNameList(){
return m_GroupNameList.keySet();
}
public Set<UUID> getKeySet(){ // 유저 목록 return
return m_GroupArray.keySet();
}
public Set<String> getNameSet() { return m_GroupNameList.keySet(); }
public String GetGroupName(UUID GroupUUID){
Nation m_Group = m_GroupArray.get(GroupUUID);
return m_Group.getGroupName();
}
public static boolean isOffline(UUID uuid){
return Bukkit.getPlayer(uuid).equals(null) && !Bukkit.getOfflinePlayer(uuid).equals(null);
}
public static boolean isOwner(UUID GroupUUID, UUID PlayerUUID){
return m_GroupArray.get(GroupUUID).isOwner(PlayerUUID);
}
private boolean isAvaliableGroup(UUID GroupUUID){
return m_GroupArray.containsKey(GroupUUID);
}
}

@ -1,5 +1,6 @@
package org.poopki.duckdns.user_db;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -9,12 +10,22 @@ import java.util.UUID;
public class NationEventHandler implements CommandExecutor {
GroupArray m_GroupArray;
NationArray m_NationArray;
UserInfoArray m_UserInfoArray;
public NationEventHandler(GroupArray GA, UserInfoArray UIA){
m_GroupArray = GA;
AccountArray m_AccountArray;
UUID ZERO_UUID = new UUID(0,0);
public NationEventHandler(NationArray GA, UserInfoArray UIA, AccountArray AA){
m_NationArray = GA;
m_UserInfoArray = UIA;
m_AccountArray = AA;
}
public static boolean isStringDouble(String s) {
try {
Double.parseDouble(s);
return true;
} catch (NumberFormatException e) {
return false;
}
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@ -24,21 +35,47 @@ public class NationEventHandler implements CommandExecutor {
switch (args[0]) {
case "생성":{
UUID tempUUID = UUID.randomUUID();
m_GroupArray.CreateGroup(tempUUID, args[1], p.getUniqueId());
m_UserInfoArray.setUserGroupUUID("Party",p.getUniqueId(), tempUUID);
p.sendMessage(args[1]+"파티가 생성되었습니다.");
p.sendMessage("멤버 목록: ");
for (String Name: m_GroupArray.GetGroupMembersName(tempUUID)){
p.sendMessage(Name);
if(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Nation").equals(ZERO_UUID)){
if(m_NationArray.CreateGroup(tempUUID, args[1], p.getUniqueId())){
m_UserInfoArray.setUserGroupUUID("Nation",p.getUniqueId(), tempUUID);
m_AccountArray.putAccountInfo(tempUUID,0);
p.sendMessage(args[1]+"국가 생성되었습니다.");
p.sendMessage("국가 멤버 목록: ");
for (String Name: m_NationArray.GetGroupMembersName(tempUUID)){
p.sendMessage(Name);
}
p.sendMessage("국가 목록:");
for (String Name: m_NationArray.GetGroupNameList()){
p.sendMessage(Name);
}
}
else{
p.sendMessage("이미 존재하는 국가 이름");
}
}
p.sendMessage("파티 목록:");
for (String Name: m_GroupArray.GetGroupNameList()){
p.sendMessage(Name);
else{
p.sendMessage("이미 국가 소유중"+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Nation"));
}
break;
}
case "가입":{
p.sendMessage("가입 테스트");
p.sendMessage("플레이어 UUID:"+p.getUniqueId()+" 국가 UUID:"+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Nation"));
p.sendMessage("ZERO UUID:"+ZERO_UUID);
if(!m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Nation").equals(ZERO_UUID)){
p.sendMessage("이미 가입한 국가 존재");
}
else{
p.sendMessage("가입 완료");
m_NationArray.SignUpGroup("Nation",m_NationArray.m_GroupNameList.get(args[1]),p.getUniqueId());
p.sendMessage("국가 멤버 목록: ");
for (String Name: m_NationArray.GetGroupMembersName(m_NationArray.m_GroupNameList.get(args[1]))){
p.sendMessage(Name);
}
p.sendMessage("국가 목록:");
for (String Name: m_NationArray.GetGroupNameList()){
p.sendMessage(Name);
}
}
break;
}
case "초대":{
@ -47,12 +84,177 @@ public class NationEventHandler implements CommandExecutor {
}
case "강퇴":{
p.sendMessage("강퇴 테스트");
if(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Nation").equals(ZERO_UUID)){
p.sendMessage("가입한 국가 없습니다."+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Nation"));
}
else{
if(m_NationArray.isOwner(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Nation"), p.getUniqueId())){
if (args.length > 1) {
Player op = Bukkit.getPlayer(args[1]);
if (op != null) {
if(m_NationArray.isGroupMember(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Nation"),op.getUniqueId())) {
m_NationArray.ExpulsionGroupPlayer("Nation", m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Nation"), p.getUniqueId());
}
else{
p.sendMessage("국가 가입되지 않은 유저");
}
}
else{
p.sendMessage("잘못된 대상");
}
}
else{
p.sendMessage("강퇴할 대상을 지정");
}
}
else{
p.sendMessage("국가주만 사용 가능한 명령어"+ p.getUniqueId());
}
}
break;
}
case "탈퇴": {
if(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Nation").equals(ZERO_UUID)){
p.sendMessage("가입한 국가 없습니다."+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Nation"));
}
else{
p.sendMessage("탈퇴 플레이어 UUID:"+p.getUniqueId()+" 국가 UUID:"+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), "Nation"));
m_NationArray.ExpulsionGroupPlayer("Nation",m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),"Nation"),p.getUniqueId());
}
break;
}
case "이름":{
p.sendMessage("현재 파티 이름"+m_GroupArray.GetGroupName(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),"Party")));
p.sendMessage("현재 파티 이름"+m_NationArray.GetGroupName(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),"Party")));
break;
}
case "정보": {
for (String Name: m_NationArray.GetGroupNameList()){
p.sendMessage("국가 이름:");
p.sendMessage(Name);
p.sendMessage("인원 목록");
for (String Name2: m_NationArray.GetGroupMembersName(m_NationArray.m_GroupNameList.get(Name))) {
p.sendMessage(Name2);
}
p.sendMessage("계좌 잔액:"+m_AccountArray.getAccountInfo(m_NationArray.m_GroupNameList.get(Name)));
}
}
case "계좌설정":{
if (p.isOp()) {
if (args.length > 1) {
if (args[1] != null) {
UUID op = m_NationArray.m_GroupNameList.get(args[1]);
if (op != null) {
if (args.length > 2) {
if (isStringDouble(args[2])) {
if(m_AccountArray.setAccountInfo(op, Long.parseLong(args[2]))){
p.sendMessage(args[1] + "님의 잔액을 " + Integer.parseInt(args[2]) + "원으로 설정하였습니다.");
} else{
p.sendMessage("최대 금액 이상으로 설정할 수 없습니다.");
}
} else {
p.sendMessage("설정 금액은 숫자만 가능합니다.");
}
} else {
p.sendMessage("설정 금액을 입력해주세요.");
}
} else {
p.sendMessage("잘못된 계좌입니다.");
}
}
}else{
p.sendMessage("설정 대상이 지정되지 않았습니다.");
}
} else {
p.sendMessage("관리자만 실행 가능한 명령어입니다.");
}
break;
}
case "입금": {
if (args.length > 1) {
if(args.length > 2) {
UUID op = m_NationArray.m_GroupNameList.get(args[1]);
if (op != null) {
if (isStringDouble(args[2])) {
if(p.getUniqueId() != op) {
switch(m_AccountArray.transfer(p.getUniqueId(), op, Long.parseLong(args[2])))
{
case 1: {
p.sendMessage(args[1] + "국가 " + Integer.parseInt(args[2]) + "원을 이체하였습니다.");
break;
}
case 2: {
p.sendMessage("잔액은 최대 금액을 초과할 수 없습니다.");
break;
}
case 3:{
p.sendMessage("잔액이 부족합니다.");
break;
}
}
} else{
p.sendMessage("자기 자신에게는 이체할 수 없습니다.");
}
} else {
p.sendMessage("이체 금액은 숫자만 가능합니다.");
}
} else {
p.sendMessage("잘못된 계좌입니다.");
}
} else {
p.sendMessage("이체 금액을 입력해주세요.");
}
} else {
p.sendMessage("이체 대상이 지정되지 않았습니다.");
}
break;
}
case "출금": {
if (args.length > 1) {
if(args.length > 2) {
UUID op = m_NationArray.m_GroupNameList.get(args[1]);
if (op != null) {
if (isStringDouble(args[2])) {
if(p.getUniqueId() != op) {
switch(m_AccountArray.transfer(op,p.getUniqueId(), Long.parseLong(args[2])))
{
case 1: {
p.sendMessage(args[1] + "국가 " + Integer.parseInt(args[2]) + "원을 출금하였습니다.");
break;
}
case 2: {
p.sendMessage("잔액은 최대 금액을 초과할 수 없습니다.");
break;
}
case 3:{
p.sendMessage("잔액이 부족합니다.");
break;
}
}
} else{
p.sendMessage("자기 자신에게는 이체할 수 없습니다.");
}
} else {
p.sendMessage("이체 금액은 숫자만 가능합니다.");
}
} else {
p.sendMessage("잘못된 계좌입니다.");
}
} else {
p.sendMessage("이체 금액을 입력해주세요.");
}
} else {
p.sendMessage("이체 대상이 지정되지 않았습니다.");
}
break;
}
case "잔액": {
p.sendMessage("==잔액: " + m_AccountArray.getAccountInfo(m_NationArray.GetUUID(args[1]))+ "원==");
break;
}
default: {
p.sendMessage("잘못된 명령어");
}
}
}
return true;

@ -11,10 +11,10 @@ public final class User_DB extends JavaPlugin implements Listener {
AccountArray m_AccountArrayInstance = new AccountArray();
UserInfoArray m_InfoArrayInstance = new UserInfoArray(); // UserInfo 저장하는 Array instance 생성
GroupArray m_FarmArrayInstance = new GroupArray(m_InfoArrayInstance);
GroupArray m_NationArrayInstance = new GroupArray(m_InfoArrayInstance);
GroupArray m_SquadArrayInstance = new GroupArray(m_InfoArrayInstance);
DBUpdate Database_backup = new DBUpdate(m_InfoArrayInstance, m_AccountArrayInstance);
FarmArray m_FarmArrayInstance = new FarmArray(m_InfoArrayInstance);
NationArray m_NationArrayInstance = new NationArray(m_InfoArrayInstance);
DBUpdate Database_backup = new DBUpdate(m_InfoArrayInstance, m_AccountArrayInstance, m_FarmArrayInstance, m_NationArrayInstance);
@Override
public void onEnable() {
// Plugin startup logic
@ -25,9 +25,9 @@ public final class User_DB extends JavaPlugin implements Listener {
throw new RuntimeException(e);
}
getCommand("계좌").setExecutor(new AccountEventHandler(m_AccountArrayInstance));
getCommand("농장").setExecutor(new FarmEventHandler(m_FarmArrayInstance, m_InfoArrayInstance));
getCommand("국가").setExecutor(new NationEventHandler(m_FarmArrayInstance, m_InfoArrayInstance));
getCommand("분대").setExecutor(new SquadEventHandler(m_FarmArrayInstance, m_InfoArrayInstance));
getCommand("농장").setExecutor(new FarmEventHandler(m_FarmArrayInstance, m_InfoArrayInstance, m_AccountArrayInstance));
getCommand("국가").setExecutor(new NationEventHandler(m_NationArrayInstance, m_InfoArrayInstance, m_AccountArrayInstance));
getServer().getPluginManager().registerEvents(new UserJoin(m_InfoArrayInstance, m_AccountArrayInstance),this);
}

Loading…
Cancel
Save