You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
7.8 KiB
158 lines
7.8 KiB
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; |
|
} |
|
}
|
|
|