그룹 초대 시스템 구현

그룹 시스템 개선
 - DB 연동 삭제

GUI 기능 추가
 - 잔액 확인
 - 금액 추가 기능 버튼
Group_System
poopki 2 years ago
parent de6b3de02f
commit d464d5a77d
  1. 2
      Array/Account.java
  2. 2
      Array/AccountArray.java
  3. 25
      Array/AccountEventHandler.java
  4. 11
      Array/Farm.java
  5. 12
      Array/FarmArray.java
  6. 3
      Array/FarmEventHandler.java
  7. 15
      Array/Group.java
  8. 64
      Array/GroupArray.java
  9. 268
      Array/GroupEventHandler.java
  10. 11
      Array/Nation.java
  11. 9
      Array/NationArray.java
  12. 3
      Array/NationEventHandler.java
  13. 71
      DB/DBUpdate.java
  14. 47
      Farm.java
  15. 162
      FarmArray.java
  16. 107
      GUI/BaseGUI.java
  17. 59
      GUI/ItemManager.java
  18. 47
      GUI/OpenInv.java
  19. 60
      GroupEventHandler.java
  20. 40
      Invite/Invitation.java
  21. 158
      Invite/InviteMaster.java
  22. 47
      Nation.java
  23. 162
      NationArray.java
  24. 1
      SquadEventHandler.java
  25. 7
      UserInfoArray.java
  26. 1
      UserJoin.java
  27. 14
      User_DB.java

@ -1,4 +1,4 @@
package org.poopki.duckdns.user_db; package org.poopki.duckdns.user_db.Array;
public class Account { public class Account {
private int m_Balance; private int m_Balance;

@ -1,4 +1,4 @@
package org.poopki.duckdns.user_db; package org.poopki.duckdns.user_db.Array;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

@ -1,15 +1,20 @@
package org.poopki.duckdns.user_db; package org.poopki.duckdns.user_db.Array;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.poopki.duckdns.user_db.UserInfoArray;
import java.util.UUID;
public class AccountEventHandler implements CommandExecutor { public class AccountEventHandler implements CommandExecutor {
AccountArray m_AccountArray; AccountArray m_AccountArray;
public AccountEventHandler(AccountArray AA){ UserInfoArray m_UserInfoArray;
public AccountEventHandler(AccountArray AA, UserInfoArray UIA){
m_AccountArray = AA; m_AccountArray = AA;
m_UserInfoArray = UIA;
} }
public static boolean isStringDouble(String s) { public static boolean isStringDouble(String s) {
try { try {
@ -29,12 +34,13 @@ public class AccountEventHandler implements CommandExecutor {
if (p.isOp()) { if (p.isOp()) {
if (args.length > 1) { if (args.length > 1) {
if (args[1] != null) { if (args[1] != null) {
Player op = Bukkit.getPlayer(args[1]); UUID op = m_UserInfoArray.getUserUUID(args[1]);
if (op != null) { if (op != null) {
if (args.length > 2) { if (args.length > 2) {
if (isStringDouble(args[2])) { if (isStringDouble(args[2])) {
if(m_AccountArray.setAccountInfo(op.getUniqueId(), Long.parseLong(args[2]))){ if(m_AccountArray.setAccountInfo(m_UserInfoArray.getUserUUID(args[1]), Long.parseLong(args[2]))){
p.sendMessage(op.getName() + "님의 잔액을 " + Integer.parseInt(args[2]) + "원으로 설정하였습니다."); p.sendMessage(args[1] + "님의 잔액을 " + Integer.parseInt(args[2]) + "원으로 설정하였습니다.");
} else{ } else{
p.sendMessage("최대 금액 이상으로 설정할 수 없습니다."); p.sendMessage("최대 금액 이상으로 설정할 수 없습니다.");
} }
@ -67,14 +73,15 @@ public class AccountEventHandler implements CommandExecutor {
case "이체": { case "이체": {
if (args.length > 1) { if (args.length > 1) {
if(args.length > 2) { if(args.length > 2) {
Player op = Bukkit.getPlayer(args[1]); UUID op = m_UserInfoArray.getUserUUID(args[1]);
p.sendMessage("이체"+args[1]+op);
if (op != null) { if (op != null) {
if (isStringDouble(args[2])) { if (isStringDouble(args[2])) {
if(p.getUniqueId() != op.getUniqueId()) { if(p.getUniqueId() != op) {
switch(m_AccountArray.transfer(p.getUniqueId(), op.getUniqueId(), Long.parseLong(args[2]))) switch(m_AccountArray.transfer(p.getUniqueId(), op, Long.parseLong(args[2])))
{ {
case 1: { case 1: {
p.sendMessage(op.getName() + "님에게 " + Integer.parseInt(args[2]) + "원을 이체하였습니다."); p.sendMessage(args[1]+ "님에게 " + Integer.parseInt(args[2]) + "원을 이체하였습니다.");
break; break;
} }
case 2: { case 2: {

@ -0,0 +1,11 @@
package org.poopki.duckdns.user_db.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class Farm extends Group{
public Farm(String Name, List<UUID> uuid_list){
super(Name, uuid_list);
}
}

@ -0,0 +1,12 @@
package org.poopki.duckdns.user_db.Array;
import org.bukkit.Bukkit;
import org.poopki.duckdns.user_db.UserInfoArray;
import java.util.*;
public class FarmArray extends GroupArray{
public FarmArray(UserInfoArray m_UIA){
super(m_UIA, 10);
}
}

@ -1,10 +1,11 @@
package org.poopki.duckdns.user_db; package org.poopki.duckdns.user_db.Array;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.poopki.duckdns.user_db.UserInfoArray;
import java.util.UUID; import java.util.UUID;

@ -1,5 +1,6 @@
package org.poopki.duckdns.user_db; package org.poopki.duckdns.user_db.Array;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.UUID; import java.util.UUID;
@ -8,7 +9,7 @@ public class Group {
private String m_Name; private String m_Name;
private List<UUID> m_MemberList = new ArrayList<>(); private List<UUID> m_MemberList = new ArrayList<>();
UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
int MAX_FARM_NUM = 13; int MAX_FARM_NUM = 10;
public Group(String Name, List<UUID> uuid_list){ public Group(String Name, List<UUID> uuid_list){
int index = 0; int index = 0;
@ -25,15 +26,19 @@ public class Group {
public void Expulsion(UUID uuid){ public void Expulsion(UUID uuid){
m_MemberList.remove(uuid); m_MemberList.remove(uuid);
m_MemberList.add(ZERO_UUID);
} }
public boolean isMember(UUID uuid){ public boolean isMember(UUID uuid){
return m_MemberList.contains(uuid); return m_MemberList.contains(uuid);
} }
public int getMemMaxNUM(){
return MAX_FARM_NUM;
}
public List<UUID> getGroupMembers(){ return m_MemberList;} public List<UUID> getGroupMembers(){ return m_MemberList;}
public int getMemNUM(){
int num = m_MemberList.size();
return num;
}
public String getGroupName(){ return m_Name; } public String getGroupName(){ return m_Name; }
public int isEmpty(){return m_MemberList.size();} public int isEmpty(){return m_MemberList.size();}

@ -1,22 +1,26 @@
package org.poopki.duckdns.user_db; package org.poopki.duckdns.user_db.Array;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.poopki.duckdns.user_db.UserInfoArray;
import java.util.*; import java.util.*;
public class GroupArray { public class GroupArray {
public static Map<UUID, Group> m_GroupArray; protected Map<UUID, Group> m_GroupArray;
public static Map<String, UUID> m_GroupNameList; protected Map<String, UUID> m_GroupNameList;
public List<UUID> m_DeleteQueue = new ArrayList<>();
UserInfoArray m_UserInfoArray; UserInfoArray m_UserInfoArray;
UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000"); UUID ZERO_UUID = UUID.fromString("00000000-0000-0000-0000-000000000000");
int MAX_GROUP_NUM = 13; int MAX_GROUP_NUM = 10;
public GroupArray(UserInfoArray m_UIA){ public GroupArray(UserInfoArray m_UIA, int num){
m_UserInfoArray = m_UIA; m_UserInfoArray = m_UIA;
m_GroupArray = new HashMap<UUID, Group>(); m_GroupArray = new HashMap<UUID, Group>();
m_GroupNameList = new HashMap<String, UUID>(); m_GroupNameList = new HashMap<String, UUID>();
MAX_GROUP_NUM = num;
} }
public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){ public boolean CreateGroup(UUID GroupUUID, String Name, UUID PlayerUUID){
@ -25,9 +29,7 @@ public class GroupArray {
} else{ } else{
List<UUID> m_MemberList = new ArrayList<>(); List<UUID> m_MemberList = new ArrayList<>();
m_MemberList.add(PlayerUUID); 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_GroupArray.put(GroupUUID, new Group(Name, m_MemberList));
m_GroupNameList.put(Name, GroupUUID); m_GroupNameList.put(Name, GroupUUID);
return true; return true;
@ -43,9 +45,6 @@ public class GroupArray {
m_MemberList.add(it.next()); 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_GroupArray.put(GroupUUID, new Group(Name, m_MemberList));
m_GroupNameList.put(Name,GroupUUID); m_GroupNameList.put(Name,GroupUUID);
return true; return true;
@ -63,6 +62,11 @@ public class GroupArray {
} }
return null; return null;
} }
public UUID GetUUID(String name){
return m_GroupNameList.get(name);
}
public boolean DeleteGroup(UUID GroupUUID, String GroupType){ public boolean DeleteGroup(UUID GroupUUID, String GroupType){
if(m_GroupArray.containsKey(GroupUUID)){ if(m_GroupArray.containsKey(GroupUUID)){
for(UUID key: GetGroupMembersUUID(GroupUUID)){ for(UUID key: GetGroupMembersUUID(GroupUUID)){
@ -80,18 +84,16 @@ public class GroupArray {
} }
public Integer SignUpGroup(String GroupType, UUID GroupUUID, UUID PlayerUUID){ public Integer SignUpGroup(String GroupType, UUID GroupUUID, UUID PlayerUUID){
if(m_GroupArray.containsKey(GroupUUID)){ if(m_GroupArray.containsKey(GroupUUID) & !m_UserInfoArray.getUserGroupUUID(PlayerUUID, GroupType).equals(ZERO_UUID)){
if(isOffline(PlayerUUID)){
Group m_Group = m_GroupArray.get(GroupUUID); Group m_Group = m_GroupArray.get(GroupUUID);
m_Group.SignUp(PlayerUUID); m_Group.SignUp(PlayerUUID);
m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,GroupUUID); m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,GroupUUID);
return 1; // Success
}else{
return 2; // Offline Player
}
} else{ } else{
return 3; // Wrong Group return 3; // Wrong Group
} }
return 0;
} }
public boolean ExpulsionGroupPlayer(String GroupType, UUID GroupUUID, UUID PlayerUUID){ public boolean ExpulsionGroupPlayer(String GroupType, UUID GroupUUID, UUID PlayerUUID){
@ -99,10 +101,13 @@ public class GroupArray {
Group m_Group = m_GroupArray.get(GroupUUID); Group m_Group = m_GroupArray.get(GroupUUID);
m_Group.Expulsion(PlayerUUID); m_Group.Expulsion(PlayerUUID);
m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,ZERO_UUID); m_UserInfoArray.setUserGroupUUID(GroupType,PlayerUUID,ZERO_UUID);
List<UUID> temp = m_Group.getGroupMembers(); int temp = m_GroupArray.get(GroupUUID).getMemNUM();
if(temp.get(0).equals(ZERO_UUID)){
if(temp==0){
m_GroupNameList.remove(m_Group.getGroupName());
m_GroupArray.remove(GroupUUID); m_GroupArray.remove(GroupUUID);
m_GroupNameList.remove(getKey(m_GroupNameList,GroupUUID)); m_DeleteQueue.add(GroupUUID);
Bukkit.getPlayer(PlayerUUID).sendMessage(""+temp+" "+m_DeleteQueue);
} }
return true; return true;
} else{ } else{
@ -132,7 +137,10 @@ public class GroupArray {
Group m_Group = m_GroupArray.get(GroupUUID); Group m_Group = m_GroupArray.get(GroupUUID);
return m_Group.isMember(PlayerUUID); return m_Group.isMember(PlayerUUID);
} }
public int GetGroupMemNUM(UUID GroupUUID){
Group m_Group = m_GroupArray.get(GroupUUID);
return m_Group.getMemNUM();
}
public Set<String> GetGroupNameList(){ public Set<String> GetGroupNameList(){
return m_GroupNameList.keySet(); return m_GroupNameList.keySet();
} }
@ -146,11 +154,15 @@ public class GroupArray {
Group m_Group = m_GroupArray.get(GroupUUID); Group m_Group = m_GroupArray.get(GroupUUID);
return m_Group.getGroupName(); return m_Group.getGroupName();
} }
public static boolean isOffline(UUID uuid){ public int GetGroupMemMaxNum(UUID GroupUUID){
Group m_Group = m_GroupArray.get(GroupUUID);
return m_Group.getMemMaxNUM();
}
public boolean isOffline(UUID uuid){
return Bukkit.getPlayer(uuid).equals(null) && !Bukkit.getOfflinePlayer(uuid).equals(null); return Bukkit.getPlayer(uuid).equals(null) && !Bukkit.getOfflinePlayer(uuid).equals(null);
} }
public static boolean isOwner(UUID GroupUUID, UUID PlayerUUID){ public boolean isOwner(UUID GroupUUID, UUID PlayerUUID){
return m_GroupArray.get(GroupUUID).isOwner(PlayerUUID); return m_GroupArray.get(GroupUUID).isOwner(PlayerUUID);
} }
private boolean isAvaliableGroup(UUID GroupUUID){ private boolean isAvaliableGroup(UUID GroupUUID){

@ -0,0 +1,268 @@
package org.poopki.duckdns.user_db.Array;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.poopki.duckdns.user_db.UserInfoArray;
import java.util.UUID;
public class GroupEventHandler implements CommandExecutor {
GroupArray m_GroupArray;
UserInfoArray m_UserInfoArray;
AccountArray m_AccountArray;
UUID ZERO_UUID = new UUID(0,0);
String m_GroupType;
String m_Type;
public GroupEventHandler(GroupArray GA, UserInfoArray UIA, AccountArray AA, String GroupType, String Type){
m_GroupArray = GA;
m_UserInfoArray = UIA;
m_GroupType = GroupType;
m_Type=Type;
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) {
Player p = (Player) sender;
if (args.length != 0) {
switch (args[0]) {
case "생성":{
UUID tempUUID = UUID.randomUUID();
if(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type).equals(ZERO_UUID)){
if(m_GroupArray.CreateGroup(tempUUID, args[1], p.getUniqueId())){
m_UserInfoArray.setUserGroupUUID(m_Type,p.getUniqueId(), tempUUID);
m_AccountArray.putAccountInfo(tempUUID,0);
p.sendMessage(args[1]+m_GroupType+"이 생성되었습니다.");
p.sendMessage(m_GroupType+" 멤버 목록: ");
for (String Name: m_GroupArray.GetGroupMembersName(tempUUID)){
p.sendMessage(Name);
}
p.sendMessage(m_GroupType+" 목록:");
for (String Name: m_GroupArray.GetGroupNameList()){
p.sendMessage(Name);
}
}
else{
p.sendMessage("이미 존재하는 "+m_GroupType+" 이름입니다.");
}
}
else{
p.sendMessage("이미"+m_GroupType+"을(를) 소유중입니다."+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type));
}
break;
}
case "가입":{
p.sendMessage("플레이어 UUID:"+p.getUniqueId()+" 농장 UUID:"+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type));
p.sendMessage("ZERO UUID:"+ZERO_UUID);
if(!m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type).equals(ZERO_UUID)){
p.sendMessage("이미 가입한 "+m_GroupType+"이(가) 존재합니다.");
}
else{
p.sendMessage("가입 완료");
m_GroupArray.SignUpGroup(m_Type,m_GroupArray.m_GroupNameList.get(args[1]),p.getUniqueId());
p.sendMessage(m_GroupType+" 멤버 목록: ");
for (String Name: m_GroupArray.GetGroupMembersName(m_GroupArray.m_GroupNameList.get(args[1]))){
p.sendMessage(Name);
}
p.sendMessage(m_GroupType+" 목록:");
for (String Name: m_GroupArray.GetGroupNameList()){
p.sendMessage(Name);
}
}
break;
}
case "초대":{
p.sendMessage("초대 테스트");
break;
}
case "강퇴":{
p.sendMessage("강퇴 테스트");
if(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type).equals(ZERO_UUID)){
p.sendMessage("가입한 "+m_GroupType+"이(가) 없습니다."+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type));
}
else{
if(m_GroupArray.isOwner(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type), p.getUniqueId())){
if (args.length > 1) {
Player op = Bukkit.getPlayer(args[1]);
if (op != null) {
if(m_GroupArray.isGroupMember(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type),op.getUniqueId())) {
m_GroupArray.ExpulsionGroupPlayer(m_Type, m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type), p.getUniqueId());
}
else{
p.sendMessage(m_GroupType+"에 가입되지 않은 유저입니다");
}
}
else{
p.sendMessage("잘못된 대상입니다.");
}
}
else{
p.sendMessage("강퇴할 대상을 지정");
}
}
else{
p.sendMessage(m_GroupType+"주만 사용 가능한 명령어입니다."+ p.getUniqueId());
}
}
break;
}
case "탈퇴": {
if(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type).equals(ZERO_UUID)){
p.sendMessage("가입한 "+m_GroupType+"이(가) 없습니다."+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type));
}
else{
p.sendMessage("탈퇴 플레이어 UUID:"+p.getUniqueId()+m_GroupType+" UUID:"+m_UserInfoArray.getUserGroupUUID(p.getUniqueId(), m_Type));
m_GroupArray.ExpulsionGroupPlayer(m_Type,m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),m_Type),p.getUniqueId());
}
break;
}
case "이름":{
p.sendMessage("현재 "+m_GroupType+" 이름"+m_GroupArray.GetGroupName(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),"Party")));
break;
}
case "정보": {
for (String Name: m_GroupArray.GetGroupNameList()){
p.sendMessage(m_GroupType+" 이름:");
p.sendMessage(Name);
p.sendMessage("인원 목록");
for (String Name2: m_GroupArray.GetGroupMembersName(m_GroupArray.m_GroupNameList.get(Name))) {
p.sendMessage(Name2);
}
p.sendMessage("계좌 잔액:"+m_AccountArray.getAccountInfo(m_GroupArray.m_GroupNameList.get(Name)));
}
}
case "계좌설정":{
if (p.isOp()) {
if (args.length > 1) {
if (args[1] != null) {
UUID op = m_GroupArray.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_GroupArray.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] + m_GroupType+"에 " + 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_GroupArray.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] + m_GroupType+"에서 " + 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_GroupArray.GetUUID(args[1]))+ "원==");
break;
}
default: {
p.sendMessage("잘못된 명령어");
}
}
}
return true;
}
}

@ -0,0 +1,11 @@
package org.poopki.duckdns.user_db.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class Nation extends Group{
public Nation(String Name, List<UUID> uuid_list){
super(Name, uuid_list);
}
}

@ -0,0 +1,9 @@
package org.poopki.duckdns.user_db.Array;
import org.poopki.duckdns.user_db.UserInfoArray;
public class NationArray extends GroupArray{
public NationArray(UserInfoArray m_UIA){
super(m_UIA, 50);
}
}

@ -1,10 +1,11 @@
package org.poopki.duckdns.user_db; package org.poopki.duckdns.user_db.Array;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.poopki.duckdns.user_db.UserInfoArray;
import java.util.UUID; import java.util.UUID;

@ -1,11 +1,13 @@
package org.poopki.duckdns.user_db.DB; package org.poopki.duckdns.user_db.DB;
import org.poopki.duckdns.user_db.*; import org.poopki.duckdns.user_db.*;
import org.poopki.duckdns.user_db.Array.AccountArray;
import org.poopki.duckdns.user_db.Array.FarmArray;
import org.poopki.duckdns.user_db.Array.NationArray;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
public class DBUpdate { public class DBUpdate {
@ -115,7 +117,9 @@ public class DBUpdate {
List<UUID> m_MemberList = new ArrayList<>(); List<UUID> m_MemberList = new ArrayList<>();
for(int index = 4; index<MAX_FARM_NUM; index++){ for(int index = 4; index<MAX_FARM_NUM; index++){
m_MemberList.add(index-4,UUID.fromString(rs.getString(index))); if(rs.getString(index) != null){
m_MemberList.add(index-4,UUID.fromString(rs.getString(index)));
}
} }
m_FarmArray.PutGroup(UUID.fromString(rs.getString(1)), m_FarmArray.PutGroup(UUID.fromString(rs.getString(1)),
rs.getString(2), rs.getString(2),
@ -150,7 +154,9 @@ public class DBUpdate {
List<UUID> m_MemberList = new ArrayList<>(); List<UUID> m_MemberList = new ArrayList<>();
for(int index = 4; index<MAX_FARM_NUM; index++){ for(int index = 4; index<MAX_FARM_NUM; index++){
m_MemberList.add(index-4,UUID.fromString(rs.getString(index))); if(rs.getString(index) != null){
m_MemberList.add(index-4,UUID.fromString(rs.getString(index)));
}
} }
m_NationArray.PutGroup(UUID.fromString(rs.getString(1)), m_NationArray.PutGroup(UUID.fromString(rs.getString(1)),
rs.getString(2), rs.getString(2),
@ -232,7 +238,7 @@ public class DBUpdate {
index++; index++;
} }
for(; index<=MAX_FARM_NUM;index++){ for(; index<=MAX_FARM_NUM;index++){
pstmt.setString(index, String.valueOf(ZERO_UUID)); pstmt.setString(index, null);
} }
int cnt = pstmt.executeUpdate(); int cnt = pstmt.executeUpdate();
@ -258,11 +264,41 @@ public class DBUpdate {
} }
} }
// Update nation Info
try{ try{
Class.forName("org.mariadb.jdbc.Driver"); Class.forName("org.mariadb.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
for (UUID key: m_FarmArray.m_DeleteQueue){
String sql = "DELETE FROM Farm WHERE FARM_UUID=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, String.valueOf(key.toString()));
int cnt = pstmt.executeUpdate();
m_FarmArray.m_DeleteQueue.remove(key);
}
}
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.m_DeleteQueue){
String sql = "DELETE FROM Nation WHERE NATION_UUID (?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, String.valueOf(key.toString()));
int cnt = pstmt.executeUpdate();
m_NationArray.m_DeleteQueue.remove(key);
}
for (UUID key : m_NationArray.getKeySet()) { for (UUID key : m_NationArray.getKeySet()) {
String sql = "REPLACE INTO Nation VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"; String sql = "REPLACE INTO Nation VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
@ -276,7 +312,7 @@ public class DBUpdate {
index++; index++;
} }
for(; index<=MAX_FARM_NUM;index++){ for(; index<=MAX_FARM_NUM;index++){
pstmt.setString(index, String.valueOf(ZERO_UUID)); pstmt.setString(index, null);
} }
int cnt = pstmt.executeUpdate(); int cnt = pstmt.executeUpdate();
@ -301,5 +337,28 @@ public class DBUpdate {
conn.close(); conn.close();
} }
} }
try{
Class.forName("org.mariadb.jdbc.Driver");
conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
for (UUID key: m_NationArray.m_DeleteQueue){
String sql = "DELETE FROM Nation WHERE NATION_UUID=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, String.valueOf(key.toString()));
int cnt = pstmt.executeUpdate();
m_NationArray.m_DeleteQueue.remove(key);
}
}
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();
}
}
} }
} }

@ -1,47 +0,0 @@
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;
}
}
}

@ -1,162 +0,0 @@
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 = 10;
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);
}
}

@ -0,0 +1,107 @@
package org.poopki.duckdns.user_db.GUI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.poopki.duckdns.user_db.Array.AccountArray;
import org.poopki.duckdns.user_db.Array.FarmArray;
import org.poopki.duckdns.user_db.Array.NationArray;
import org.poopki.duckdns.user_db.UserInfoArray;
import java.util.UUID;
public class BaseGUI implements Listener{
private final Inventory inv;
UUID m_uuid;
ItemManager m_ItemManager= new ItemManager();
AccountArray m_AA;
UserInfoArray m_UIA;
FarmArray m_FA;
NationArray m_NA;
public BaseGUI(AccountArray AA, UserInfoArray UIA, FarmArray FA, NationArray NA, UUID uuid, InventoryClickEvent e) {
m_uuid=uuid;
this.inv = Bukkit.createInventory(null,27,"TESTGUI");
m_AA=AA;
m_UIA=UIA;
m_FA=FA;
m_NA=NA;
initItemSetting();
}
private void initItemSetting() {
inv.setItem(0,m_ItemManager.GetBalance(m_AA, m_UIA, m_FA, m_NA,m_uuid, "User"));
inv.setItem(1,m_ItemManager.GetBalance(m_AA, m_UIA, m_FA, m_NA,m_uuid, "Nation"));
inv.setItem(2,m_ItemManager.GetBalance(m_AA, m_UIA, m_FA, m_NA,m_uuid, "Farm"));
inv.setItem(9, m_ItemManager.btn1);
inv.setItem(18, m_ItemManager.btn2);
inv.setItem(10, m_ItemManager.btn3);
inv.setItem(19, m_ItemManager.btn4);
inv.setItem(11, m_ItemManager.btn5);
inv.setItem(20, m_ItemManager.btn6);
}
public void open(Player player){
player.openInventory(inv);
}
public void inven(InventoryClickEvent e){
Player p = (Player) e.getWhoClicked();
Inventory m_inv = e.getClickedInventory();
if (e.getInventory() != m_inv) return;
switch(e.getCurrentItem().getType()){
case CANDLE:
e.setCancelled(true);
p.sendMessage("10000원 증가");
m_AA.setAccountInfo(p.getUniqueId(), (long)m_AA.getAccountInfo(p.getUniqueId())+10000);
initItemSetting();
p.openInventory(inv);
break;
case BEEF:
e.setCancelled(true);
p.sendMessage("10000원 감소");
m_AA.setAccountInfo(p.getUniqueId(), (long)m_AA.getAccountInfo(p.getUniqueId())-10000);
initItemSetting();
p.openInventory(inv);
break;
case TORCH:
e.setCancelled(true);
p.sendMessage("국가 10000원 증가"+ m_AA.getAccountInfo(m_UIA.getUserGroupUUID(m_uuid, "Nation")));
m_AA.setAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Nation"), (long)m_AA.getAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Nation"))+10000);
initItemSetting();
p.openInventory(inv);
break;
case GRASS:
e.setCancelled(true);
p.sendMessage("국가 10000원 감소"+ m_AA.getAccountInfo(m_UIA.getUserGroupUUID(m_uuid, "Nation")));
m_AA.setAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Nation"), (long)m_AA.getAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Nation"))-10000);
initItemSetting();
p.openInventory(inv);
break;
case DIAMOND:
e.setCancelled(true);
p.sendMessage("농장 10000원 증가"+ m_AA.getAccountInfo(m_UIA.getUserGroupUUID(m_uuid, "Farm")));
m_AA.setAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Farm"), (long)m_AA.getAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Farm"))+10000);
initItemSetting();
p.openInventory(inv);
break;
case IRON_INGOT:
e.setCancelled(true);
p.sendMessage("농장 10000원 감소"+ m_AA.getAccountInfo(m_UIA.getUserGroupUUID(m_uuid, "Farm")));
m_AA.setAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Farm"), (long)m_AA.getAccountInfo(m_UIA.getUserGroupUUID(p.getUniqueId(),"Farm"))-10000);
initItemSetting();
p.openInventory(inv);
break;
}
}
}

@ -0,0 +1,59 @@
package org.poopki.duckdns.user_db.GUI;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.poopki.duckdns.user_db.Array.AccountArray;
import org.poopki.duckdns.user_db.Array.FarmArray;
import org.poopki.duckdns.user_db.Array.NationArray;
import org.poopki.duckdns.user_db.UserInfoArray;
import java.util.Arrays;
import java.util.UUID;
public class ItemManager {
UUID ZERO_UUID = new UUID(0,0);
public ItemStack btn1 = buildItem(Material.CANDLE, 1, ChatColor.AQUA +"지갑 10000원 증가", "", ChatColor.GREEN + "----");
public ItemStack btn2 = buildItem(Material.BEEF, 1, ChatColor.AQUA +"지갑 10000원 감소", "", ChatColor.GREEN + "----");
public ItemStack btn3 = buildItem(Material.TORCH, 1, ChatColor.AQUA +"국가 10000원 증가", "", ChatColor.GREEN + "----");
public ItemStack btn4 = buildItem(Material.GRASS, 1, ChatColor.AQUA +"국가 10000원 감소", "", ChatColor.GREEN + "----");
public ItemStack btn5 = buildItem(Material.DIAMOND, 1, ChatColor.AQUA +"농장 10000원 증가", "", ChatColor.GREEN + "----");
public ItemStack btn6 = buildItem(Material.IRON_INGOT, 1, ChatColor.AQUA +"농장 10000원 증가", "", ChatColor.GREEN + "----");
private static ItemStack buildItem(Material type, int amount, String displayName, String... lore) {
ItemStack stack = new ItemStack(type, amount);
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(displayName);
meta.setLore(Arrays.asList(lore));
stack.setItemMeta(meta);
return stack;
}
public ItemStack GetBalance(AccountArray AA, UserInfoArray UIA, FarmArray FA, NationArray NA, UUID m_uuid, String Type){
ItemStack dia = null;
switch (Type){
case "User":
dia = buildItem(Material.DIAMOND, 1, ChatColor.AQUA +""+UIA.getUserName(m_uuid), "잔액", ChatColor.GREEN + ""+AA.getAccountInfo(m_uuid));
break;
case "Farm":
if(ZERO_UUID.equals(UIA.getUserGroupUUID(m_uuid, "Farm"))){
dia = buildItem(Material.DIAMOND, 1, ChatColor.AQUA +"농장 없음", "잔액", ChatColor.GREEN + "----");
}else{
dia = buildItem(Material.DIAMOND, 1, ChatColor.AQUA +""+FA.GetGroupName(UIA.getUserGroupUUID(m_uuid,"Farm")), "잔액", ChatColor.GREEN + ""+AA.getAccountInfo(UIA.getUserGroupUUID(m_uuid, "Farm")));
}
break;
case "Nation":
if(ZERO_UUID.equals(UIA.getUserGroupUUID(m_uuid, "Nation"))){
dia = buildItem(Material.DIAMOND, 1, ChatColor.AQUA +"국가 없음", "잔액", ChatColor.GREEN + "----");
}
else{
dia = buildItem(Material.DIAMOND, 1, ChatColor.AQUA +""+NA.GetGroupName(UIA.getUserGroupUUID(m_uuid, "Nation")), "잔액", ChatColor.GREEN + ""+AA.getAccountInfo(UIA.getUserGroupUUID(m_uuid, "Nation")));
}
break;
}
return dia;
}
}

@ -0,0 +1,47 @@
package org.poopki.duckdns.user_db.GUI;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.poopki.duckdns.user_db.Array.AccountArray;
import org.poopki.duckdns.user_db.Array.FarmArray;
import org.poopki.duckdns.user_db.Array.NationArray;
import org.poopki.duckdns.user_db.UserInfoArray;
public class OpenInv implements Listener,CommandExecutor {
AccountArray m_AccountArray;
UserInfoArray m_UserInfoArray;
FarmArray m_FarmArray;
NationArray m_NationArray;
public OpenInv(AccountArray AA, UserInfoArray m_UIA, FarmArray FA, NationArray NA){
m_UserInfoArray = m_UIA;
m_AccountArray = AA;
m_FarmArray = FA;
m_NationArray = NA;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player){
Player player = (Player) sender;
player.sendMessage("이벤트 발생");
BaseGUI inv = new BaseGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, ((Player) sender).getUniqueId(), null);
inv.open(player);
}
return false;
}
@EventHandler
public void inven2(InventoryClickEvent e){
Player player = (Player) e.getWhoClicked();;
player.sendMessage("이벤트 발생");
BaseGUI inv = new BaseGUI(m_AccountArray,m_UserInfoArray,m_FarmArray,m_NationArray, player.getUniqueId(), e);
inv.inven(e);
}
}

@ -1,60 +0,0 @@
package org.poopki.duckdns.user_db;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.UUID;
public class GroupEventHandler implements CommandExecutor {
GroupArray m_GroupArray;
UserInfoArray m_UserInfoArray;
public GroupEventHandler(GroupArray GA, UserInfoArray UIA){
m_GroupArray = GA;
m_UserInfoArray = UIA;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player p = (Player) sender;
if (args.length != 0) {
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);
}
p.sendMessage("파티 목록:");
for (String Name: m_GroupArray.GetGroupNameList()){
p.sendMessage(Name);
}
break;
}
case "가입":{
p.sendMessage("가입 테스트");
break;
}
case "초대":{
p.sendMessage("초대 테스트");
break;
}
case "강퇴":{
p.sendMessage("강퇴 테스트");
break;
}
case "이름":{
p.sendMessage("현재 파티 이름"+m_GroupArray.GetGroupName(m_UserInfoArray.getUserGroupUUID(p.getUniqueId(),"Party")));
break;
}
}
}
return true;
}
}

@ -0,0 +1,40 @@
package org.poopki.duckdns.user_db.Invite;
import org.bukkit.entity.Player;
import org.poopki.duckdns.user_db.Array.FarmArray;
import org.poopki.duckdns.user_db.Array.NationArray;
import org.poopki.duckdns.user_db.UserInfoArray;
import java.util.UUID;
public class Invitation {
protected long Time;
protected String Type;
protected UUID uuid;
protected Player sender;
protected Player receiver;
public Invitation(long Time, String Type, UUID uuid, Player sender, Player receiver){
this.Time = Time;
this.Type = Type;
this.uuid = uuid;
this.sender = sender;
this.receiver = receiver;
}
public long getTime(){
return this.Time;
}
public String getType(){
return this.Type;
}
public UUID getUUID(){
return this.uuid;
}
public Player getSender(){return this.sender;}
public Player getReceiver(){ return this.receiver;}
}

@ -0,0 +1,158 @@
package org.poopki.duckdns.user_db.Invite;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.poopki.duckdns.user_db.Array.FarmArray;
import org.poopki.duckdns.user_db.Array.NationArray;
import org.poopki.duckdns.user_db.UserInfoArray;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class InviteMaster implements CommandExecutor {
private static Map<UUID, Invitation> m_InviteQueue = new HashMap<UUID, Invitation>();
UserInfoArray m_UserInfoArray;
FarmArray m_FarmArray;
NationArray m_NationArray;
public InviteMaster(UserInfoArray UIA, FarmArray FA, NationArray NA){
m_UserInfoArray = UIA;
m_FarmArray = FA;
m_NationArray = NA;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
Player p = (Player)sender;
switch (args[0]) {
case "발송": {
if (args.length > 1) {
if (args.length > 2) {
UUID op = m_UserInfoArray.getUserUUID(args[2]);
if (op != null) {
if (p.getUniqueId().equals(op)) {
p.sendMessage("자기 자신에게 초대를 보낼 수 없습니다.");
} else {
sendInvite(p, Bukkit.getPlayer(args[2]), m_UserInfoArray, m_FarmArray, m_NationArray, args[1]);
}
} else {
p.sendMessage("잘못된 대상입니다.");
}
} else {
p.sendMessage("초대 대상을 입력해주세요.");
}
} else {
p.sendMessage("국가/농장이 지정되지 않았습니다.");
}
break;
}
case "응답": {
if (args.length > 1) {
if (args.length > 2) {
switch (args[2]) {
case "수락":
replyInvite(p, m_UserInfoArray, m_FarmArray, m_NationArray, args[1], true);
p.sendMessage("수락하였습니다.");
break;
case "거절":
replyInvite(p, m_UserInfoArray, m_FarmArray, m_NationArray, args[1], false);
p.sendMessage("거절하였습니다.");
break;
default:
p.sendMessage("/초대 응답 국가|농장 수락|거절");
}
} else {
p.sendMessage("초대 대상을 입력해주세요.");
}
} else {
p.sendMessage("국가/농장이 지정되지 않았습니다.");
}
break;
}
}
return true;
}
public boolean sendInvite(Player sender, Player receiver, UserInfoArray UIA, FarmArray FA, NationArray NA, String Type){
if(!isExpired(receiver.getUniqueId())){
sender.sendMessage("응답 대기중");
return false;
}
switch (Type){
case "농장":
if(FA.GetGroupMemNUM(UIA.getUserGroupUUID(sender.getUniqueId(),"Farm"))>FA.GetGroupMemMaxNum(UIA.getUserGroupUUID(sender.getUniqueId(),"Farm"))){
sender.sendMessage("인원이 초과되었습니다.");
return false;
}
else{
m_InviteQueue.put(receiver.getUniqueId(), new Invitation(System.currentTimeMillis(), "Farm", UIA.getUserGroupUUID(sender.getUniqueId(),"Farm"), sender, receiver));
receiver.sendMessage(sender.getDisplayName()+"님의 "+FA.GetGroupName(UIA.getUserGroupUUID(sender.getUniqueId(),"Farm"))+"에 초대되었습니다.");
receiver.sendMessage("제한시간(5분)내 /농장 수락 혹은 /농장 거절 입력해주시기 바랍니다.");
}
break;
case "국가":
if(NA.GetGroupMemNUM(UIA.getUserGroupUUID(sender.getUniqueId(),"Nation"))>NA.GetGroupMemMaxNum(UIA.getUserGroupUUID(sender.getUniqueId(),"Nation"))){
sender.sendMessage("인원이 초과되었습니다.");
return false;
}
else{
m_InviteQueue.put(receiver.getUniqueId(), new Invitation(System.currentTimeMillis(), "Nation", UIA.getUserGroupUUID(sender.getUniqueId(),"Nation"), sender, receiver));
receiver.sendMessage(sender.getDisplayName()+"님의 "+NA.GetGroupName(UIA.getUserGroupUUID(sender.getUniqueId(),"Nation"))+"에 초대되었습니다.");
receiver.sendMessage("제한시간(5분)내 /국가 수락 혹은 /국가 거절 입력해주시기 바랍니다."+receiver.getUniqueId());
}
break;
}
return true;
}
public boolean replyInvite(Player receiver, UserInfoArray UIA, FarmArray FA, NationArray NA, String Type, boolean accept){
Player sender = m_InviteQueue.get(receiver.getUniqueId()).getSender();
if(isExpired(receiver.getUniqueId())){
m_InviteQueue.remove(receiver.getUniqueId());
receiver.sendMessage("수신 받은 초대가 없거나, 초대가 만료되었습니다.");
return false;
}
if(!accept){
sender.sendMessage("초대를 거절하였습니다.");
receiver.sendMessage("초대를 거절하였습니다.");
m_InviteQueue.remove(receiver.getUniqueId());
return false;
}
switch (Type){
case "농장":
if(FA.GetGroupMemNUM(m_InviteQueue.get(sender.getUniqueId()).getUUID())>FA.GetGroupMemMaxNum(m_InviteQueue.get(sender.getUniqueId()).getUUID())){
sender.sendMessage("인원이 초과되었습니다.");
receiver.sendMessage("인원이 초과되었습니다..");
m_InviteQueue.remove(receiver.getUniqueId());
return false;
}
else{
FA.SignUpGroup("Farm", m_InviteQueue.get(receiver.getUniqueId()).getUUID(), m_InviteQueue.get(receiver.getUniqueId()).getReceiver().getUniqueId());
m_InviteQueue.remove(receiver.getUniqueId());
}
break;
case "국가":
if(NA.GetGroupMemNUM(m_InviteQueue.get(sender.getUniqueId()).getUUID())>NA.GetGroupMemMaxNum(m_InviteQueue.get(sender.getUniqueId()).getUUID())){
sender.sendMessage("인원이 초과되었습니다.");
receiver.sendMessage("인원이 초과되었습니다.");
m_InviteQueue.remove(receiver.getUniqueId());
return false;
}
else{
receiver.sendMessage("가입되었습니다."+m_InviteQueue.get(receiver.getUniqueId()).getUUID()+ " "+ m_InviteQueue.get(receiver.getUniqueId()).getReceiver());
NA.SignUpGroup("Nation", m_InviteQueue.get(receiver.getUniqueId()).getUUID(), m_InviteQueue.get(receiver.getUniqueId()).getReceiver().getUniqueId());
m_InviteQueue.remove(receiver.getUniqueId());
}
break;
}
return true;
}
private boolean isExpired(UUID uuid){
return !m_InviteQueue.containsKey(uuid) || (System.currentTimeMillis() - m_InviteQueue.get(uuid).getTime()) >= 300000L;
}
}

@ -1,47 +0,0 @@
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;
}
}
}

@ -1,162 +0,0 @@
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);
}
}

@ -4,6 +4,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.poopki.duckdns.user_db.Array.GroupArray;
import java.util.UUID; import java.util.UUID;

@ -7,7 +7,7 @@ import java.util.UUID;
public class UserInfoArray { public class UserInfoArray {
private static Map<UUID, UserInfo> m_UserInfoArray = new HashMap<UUID, UserInfo>(); private static Map<UUID, UserInfo> m_UserInfoArray = new HashMap<UUID, UserInfo>();
private static Map<String, UUID> m_UserNameUUID = new HashMap();
public String getUserName(UUID uuid){ // 유저 이름 return public String getUserName(UUID uuid){ // 유저 이름 return
return m_UserInfoArray.get(uuid).getUserName(); return m_UserInfoArray.get(uuid).getUserName();
} }
@ -21,13 +21,16 @@ public class UserInfoArray {
public UUID getUserGroupUUID(UUID PlayerUUID, String GroupType){ public UUID getUserGroupUUID(UUID PlayerUUID, String GroupType){
return m_UserInfoArray.get(PlayerUUID).GetGroupUUID(GroupType); return m_UserInfoArray.get(PlayerUUID).GetGroupUUID(GroupType);
} }
public UUID getUserUUID(String Name){
return m_UserNameUUID.get(Name);
}
public void setUserGroupUUID(String GroupType, UUID PlayerUUID, UUID GroupUUID){ public void setUserGroupUUID(String GroupType, UUID PlayerUUID, UUID GroupUUID){
m_UserInfoArray.get(PlayerUUID).SetGroupUUID(GroupType,GroupUUID); m_UserInfoArray.get(PlayerUUID).SetGroupUUID(GroupType,GroupUUID);
} }
public void putUserInfo(UUID uuid,String Name, UUID Nation, UUID Squad, UUID Farm, UUID Party) { // UserInfoArray entry 입력 public void putUserInfo(UUID uuid,String Name, UUID Nation, UUID Squad, UUID Farm, UUID Party) { // UserInfoArray entry 입력
m_UserInfoArray.put(uuid, new UserInfo(uuid,Name, Nation, Squad, Farm, Party)); m_UserInfoArray.put(uuid, new UserInfo(uuid,Name, Nation, Squad, Farm, Party));
m_UserNameUUID.put(Name, uuid);
} }
} }

@ -3,6 +3,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.poopki.duckdns.user_db.Array.AccountArray;
import java.util.UUID; import java.util.UUID;

@ -2,8 +2,10 @@ package org.poopki.duckdns.user_db;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.poopki.duckdns.user_db.Array.*;
import org.poopki.duckdns.user_db.DB.*; import org.poopki.duckdns.user_db.DB.*;
import org.poopki.duckdns.user_db.GUI.*;
import org.poopki.duckdns.user_db.Invite.*;
import java.sql.SQLException; import java.sql.SQLException;
@ -13,8 +15,8 @@ public final class User_DB extends JavaPlugin implements Listener {
UserInfoArray m_InfoArrayInstance = new UserInfoArray(); // UserInfo 저장하는 Array instance 생성 UserInfoArray m_InfoArrayInstance = new UserInfoArray(); // UserInfo 저장하는 Array instance 생성
FarmArray m_FarmArrayInstance = new FarmArray(m_InfoArrayInstance); FarmArray m_FarmArrayInstance = new FarmArray(m_InfoArrayInstance);
NationArray m_NationArrayInstance = new NationArray(m_InfoArrayInstance); NationArray m_NationArrayInstance = new NationArray(m_InfoArrayInstance);
DBUpdate Database_backup = new DBUpdate(m_InfoArrayInstance, m_AccountArrayInstance, m_FarmArrayInstance, m_NationArrayInstance); DBUpdate Database_backup = new DBUpdate(m_InfoArrayInstance, m_AccountArrayInstance, m_FarmArrayInstance, m_NationArrayInstance);
@Override @Override
public void onEnable() { public void onEnable() {
// Plugin startup logic // Plugin startup logic
@ -24,11 +26,15 @@ public final class User_DB extends JavaPlugin implements Listener {
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
getCommand("계좌").setExecutor(new AccountEventHandler(m_AccountArrayInstance)); getCommand("계좌").setExecutor(new AccountEventHandler(m_AccountArrayInstance,m_InfoArrayInstance));
getCommand("농장").setExecutor(new FarmEventHandler(m_FarmArrayInstance, m_InfoArrayInstance, m_AccountArrayInstance)); getCommand("농장").setExecutor(new FarmEventHandler(m_FarmArrayInstance, m_InfoArrayInstance, m_AccountArrayInstance));
getCommand("국가").setExecutor(new NationEventHandler(m_NationArrayInstance, m_InfoArrayInstance, m_AccountArrayInstance)); getCommand("국가").setExecutor(new NationEventHandler(m_NationArrayInstance, m_InfoArrayInstance, m_AccountArrayInstance));
getCommand("opitem").setExecutor(new OpenInv(m_AccountArrayInstance, m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance));
getCommand("초대").setExecutor(new InviteMaster(m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance));
getServer().getPluginManager().registerEvents(new UserJoin(m_InfoArrayInstance, m_AccountArrayInstance),this); getServer().getPluginManager().registerEvents(new UserJoin(m_InfoArrayInstance, m_AccountArrayInstance),this);
getServer().getPluginManager().registerEvents(new OpenInv(m_AccountArrayInstance, m_InfoArrayInstance, m_FarmArrayInstance, m_NationArrayInstance), this);
} }

Loading…
Cancel
Save