Merge pull request 'Account 모델 구현' (#10) from Account into master
Reviewed-on: http://poopki.duckdns.org:3000/poopki/User_Management_Base_Code/pulls/10Status
commit
4086ce4bb4
7 changed files with 108 additions and 26 deletions
@ -0,0 +1,32 @@ |
||||
package org.poopki.duckdns.user_db; |
||||
|
||||
import org.bukkit.entity.Player; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.UUID; |
||||
|
||||
public class Account { |
||||
private int m_Balance; |
||||
|
||||
public Account(){ |
||||
m_Balance = 0; |
||||
} |
||||
|
||||
public Account(int Balance){ |
||||
m_Balance = Balance; |
||||
} |
||||
|
||||
public int getBalance(){ return m_Balance; } |
||||
public boolean credit(int Amount){ |
||||
m_Balance +=Amount; |
||||
return true; |
||||
} |
||||
public boolean withdraw(int Amount){ |
||||
if((m_Balance - Amount) > 0){ |
||||
m_Balance -= Amount; |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,37 @@ |
||||
package org.poopki.duckdns.user_db; |
||||
|
||||
import org.bukkit.entity.Player; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.UUID; |
||||
|
||||
public class AccountArray { |
||||
public static Map<UUID, Account> m_AccountArray = new HashMap<UUID, Account>(); |
||||
|
||||
public void transfer(UUID Src, UUID Des, int Amount){ |
||||
Account m_Src = m_AccountArray.get(Src); |
||||
Account m_Des = m_AccountArray.get(Des); |
||||
|
||||
if(m_Src.getBalance()-Amount>0){ |
||||
m_Src.withdraw(Amount); |
||||
m_Des.credit(Amount); |
||||
} |
||||
} |
||||
|
||||
public int getAccountInfo(UUID uuid) { |
||||
Account m_Account = m_AccountArray.get(uuid); |
||||
return m_Account.getBalance(); |
||||
} |
||||
|
||||
public Account putAccountInfo(UUID uuid) { |
||||
m_AccountArray.put(uuid, new Account()); |
||||
Account m_Account = m_AccountArray.get(uuid); |
||||
return m_Account; |
||||
} |
||||
public Account putAccountInfo(UUID uuid, int Amount) { |
||||
m_AccountArray.put(uuid, new Account(Amount)); |
||||
Account m_Account = m_AccountArray.get(uuid); |
||||
return m_Account; |
||||
} |
||||
} |
Loading…
Reference in new issue