|
|
|
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.Array.SquadArray;
|
|
|
|
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;
|
|
|
|
SquadArray m_SquadArray;
|
|
|
|
public InviteMaster(UserInfoArray UIA, FarmArray FA, NationArray NA, SquadArray SA){
|
|
|
|
m_UserInfoArray = UIA;
|
|
|
|
m_FarmArray = FA;
|
|
|
|
m_NationArray = NA;
|
|
|
|
m_SquadArray = SA;
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
Player p = (Player)sender;
|
|
|
|
|
|
|
|
if (args.length == 0){
|
|
|
|
p.sendMessage("명령어를 확인해주세요.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch (args[0]) {
|
|
|
|
case "국가": {
|
|
|
|
if (args.length == 1) {
|
|
|
|
p.sendMessage("초대 대상을 입력해주세요.");
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
UUID op = m_UserInfoArray.getUserUUID(args[1]);
|
|
|
|
if (op == null) {
|
|
|
|
p.sendMessage("잘못된 대상입니다.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (p.getUniqueId().equals(op)) {
|
|
|
|
p.sendMessage("자기 자신에게 초대를 보낼 수 없습니다.");
|
|
|
|
} else {
|
|
|
|
p.sendMessage(args[1]+"님께 초대를 발송하였습니다.");
|
|
|
|
sendInvite(p, Bukkit.getPlayer(args[1]), m_UserInfoArray, m_FarmArray, m_NationArray, m_SquadArray,"국가");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "농장": {
|
|
|
|
if (args.length < 1) {
|
|
|
|
p.sendMessage("초대 대상을 입력해주세요.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
UUID op = m_UserInfoArray.getUserUUID(args[1]);
|
|
|
|
if (op == null) {
|
|
|
|
p.sendMessage("잘못된 대상입니다.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (p.getUniqueId().equals(op)) {
|
|
|
|
p.sendMessage("자기 자신에게 초대를 보낼 수 없습니다.");
|
|
|
|
} else {
|
|
|
|
p.sendMessage(args[1]+"님께 초대를 발송하였습니다.");
|
|
|
|
sendInvite(p, Bukkit.getPlayer(args[1]), m_UserInfoArray, m_FarmArray, m_NationArray, m_SquadArray,"농장");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "분대": {
|
|
|
|
if (args.length < 1) {
|
|
|
|
p.sendMessage("초대 대상을 입력해주세요.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
UUID op = m_UserInfoArray.getUserUUID(args[1]);
|
|
|
|
if (op == null) {
|
|
|
|
p.sendMessage("잘못된 대상입니다.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (p.getUniqueId().equals(op)) {
|
|
|
|
p.sendMessage("자기 자신에게 초대를 보낼 수 없습니다.");
|
|
|
|
} else {
|
|
|
|
p.sendMessage(args[1]+"님께 초대를 발송하였습니다.");
|
|
|
|
sendInvite(p, Bukkit.getPlayer(args[1]), m_UserInfoArray, m_FarmArray, m_NationArray, m_SquadArray,"분대");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "수락": {
|
|
|
|
replyInvite(p, m_UserInfoArray, m_FarmArray, m_NationArray, m_SquadArray,true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "거절": {
|
|
|
|
replyInvite(p, m_UserInfoArray, m_FarmArray, m_NationArray, m_SquadArray,false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
p.sendMessage("명령어를 확인해주세요.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
public boolean sendInvite(Player sender, Player receiver, UserInfoArray UIA, FarmArray FA, NationArray NA, SquadArray SA, 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(), "농장", 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(), "국가", UIA.getUserGroupUUID(sender.getUniqueId(),"Nation"), sender, receiver));
|
|
|
|
receiver.sendMessage(sender.getDisplayName()+"님의 "+NA.GetGroupName(UIA.getUserGroupUUID(sender.getUniqueId(),"Nation"))+"에 초대되었습니다.");
|
|
|
|
receiver.sendMessage("제한시간(5분)내 /초대 수락 혹은 /초대 수락 입력해주시기 바랍니다."+receiver.getUniqueId());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "분대":
|
|
|
|
if(SA.GetGroupMemNUM(UIA.getUserGroupUUID(sender.getUniqueId(),"Squad"))>SA.GetGroupMemMaxNum(UIA.getUserGroupUUID(sender.getUniqueId(),"Squad"))){
|
|
|
|
sender.sendMessage("인원이 초과되었습니다.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
m_InviteQueue.put(receiver.getUniqueId(), new Invitation(System.currentTimeMillis(), "분대", UIA.getUserGroupUUID(sender.getUniqueId(),"Squad"), sender, receiver));
|
|
|
|
receiver.sendMessage(sender.getDisplayName()+"님의 "+SA.GetGroupName(UIA.getUserGroupUUID(sender.getUniqueId(),"Squad"))+"에 초대되었습니다.");
|
|
|
|
receiver.sendMessage("제한시간(5분)내 /초대 수락 혹은 /초대 수락 입력해주시기 바랍니다."+receiver.getUniqueId());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean replyInvite(Player receiver, UserInfoArray UIA, FarmArray FA, NationArray NA, SquadArray SA, boolean accept){
|
|
|
|
|
|
|
|
if(isExpired(receiver.getUniqueId())){
|
|
|
|
m_InviteQueue.remove(receiver.getUniqueId());
|
|
|
|
receiver.sendMessage("수신 받은 초대가 없거나, 초대가 만료되었습니다.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Player sender = m_InviteQueue.get(receiver.getUniqueId()).getSender();
|
|
|
|
|
|
|
|
if(!accept){
|
|
|
|
sender.sendMessage(receiver.getDisplayName()+"님께서 초대를 거절하였습니다.");
|
|
|
|
receiver.sendMessage("초대를 거절하였습니다.");
|
|
|
|
m_InviteQueue.remove(receiver.getUniqueId());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
String Type = m_InviteQueue.get(receiver.getUniqueId()).getType();
|
|
|
|
switch (Type){
|
|
|
|
case "농장":
|
|
|
|
if(FA.GetGroupMemNUM(m_InviteQueue.get(receiver.getUniqueId()).getUUID())>FA.GetGroupMemMaxNum(m_InviteQueue.get(receiver.getUniqueId()).getUUID())){
|
|
|
|
sender.sendMessage("인원이 초과되었습니다.");
|
|
|
|
receiver.sendMessage("인원이 초과되었습니다..");
|
|
|
|
m_InviteQueue.remove(receiver.getUniqueId());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
sender.sendMessage(receiver.getDisplayName()+"님께서 초대를 수락하였습니다.");
|
|
|
|
receiver.sendMessage("가입되었습니다. "+ m_InviteQueue.get(receiver.getUniqueId()).getUUID()+" "+ receiver.getUniqueId());
|
|
|
|
receiver.sendMessage(""+FA.SignUpGroup("Farm", m_InviteQueue.get(receiver.getUniqueId()).getUUID(), receiver.getUniqueId()));
|
|
|
|
m_InviteQueue.remove(receiver.getUniqueId());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "국가":
|
|
|
|
if(NA.GetGroupMemNUM(m_InviteQueue.get(receiver.getUniqueId()).getUUID())>NA.GetGroupMemMaxNum(m_InviteQueue.get(receiver.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(), receiver.getUniqueId());
|
|
|
|
m_InviteQueue.remove(receiver.getUniqueId());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "분대":
|
|
|
|
if(SA.GetGroupMemNUM(m_InviteQueue.get(receiver.getUniqueId()).getUUID())>SA.GetGroupMemMaxNum(m_InviteQueue.get(receiver.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());
|
|
|
|
SA.SignUpGroup("Squad", m_InviteQueue.get(receiver.getUniqueId()).getUUID(), receiver.getUniqueId());
|
|
|
|
m_InviteQueue.remove(receiver.getUniqueId());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
receiver.sendMessage("다시 입력");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
private boolean isExpired(UUID uuid){
|
|
|
|
return !m_InviteQueue.containsKey(uuid) || (System.currentTimeMillis() - m_InviteQueue.get(uuid).getTime()) >= 300000L;
|
|
|
|
}
|
|
|
|
}
|