mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2024-11-22 08:54:59 +00:00
Add economic entity interfaces
I decided to add these interfaces, instead of just building upon the User & UserData interface, as support for commerce between clans & users might be something that we want to add in the future in Clans.
This commit is contained in:
parent
2fd2008f65
commit
2f18e4d8ef
@ -26,6 +26,7 @@ public class SimpleUserData implements UserData
|
|||||||
private boolean frozen;
|
private boolean frozen;
|
||||||
private boolean canInteract;
|
private boolean canInteract;
|
||||||
private boolean caged;
|
private boolean caged;
|
||||||
|
private long balance;
|
||||||
|
|
||||||
public SimpleUserData(final Player player)
|
public SimpleUserData(final Player player)
|
||||||
{
|
{
|
||||||
@ -42,7 +43,8 @@ public class SimpleUserData implements UserData
|
|||||||
final long playtime,
|
final long playtime,
|
||||||
final boolean frozen,
|
final boolean frozen,
|
||||||
final boolean canInteract,
|
final boolean canInteract,
|
||||||
final boolean caged)
|
final boolean caged,
|
||||||
|
final long balance)
|
||||||
{
|
{
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
@ -52,6 +54,7 @@ public class SimpleUserData implements UserData
|
|||||||
this.frozen = frozen;
|
this.frozen = frozen;
|
||||||
this.canInteract = canInteract;
|
this.canInteract = canInteract;
|
||||||
this.caged = caged;
|
this.caged = caged;
|
||||||
|
this.balance = balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SimpleUserData fromSQL(SQL sql, String uuid)
|
public static SimpleUserData fromSQL(SQL sql, String uuid)
|
||||||
@ -82,7 +85,8 @@ public class SimpleUserData implements UserData
|
|||||||
boolean frozen = result.getBoolean("frozen");
|
boolean frozen = result.getBoolean("frozen");
|
||||||
boolean canInteract = result.getBoolean("canInteract");
|
boolean canInteract = result.getBoolean("canInteract");
|
||||||
boolean caged = result.getBoolean("caged");
|
boolean caged = result.getBoolean("caged");
|
||||||
return new SimpleUserData(u, username, user, group, playtime, frozen, canInteract, caged);
|
long balance = result.getLong("balance");
|
||||||
|
return new SimpleUserData(u, username, user, group, playtime, frozen, canInteract, caged, balance);
|
||||||
}
|
}
|
||||||
} catch (SQLException ex)
|
} catch (SQLException ex)
|
||||||
{
|
{
|
||||||
@ -197,4 +201,28 @@ public class SimpleUserData implements UserData
|
|||||||
{
|
{
|
||||||
this.caged = caged;
|
this.caged = caged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getBalance()
|
||||||
|
{
|
||||||
|
return balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addToBalance(long amount)
|
||||||
|
{
|
||||||
|
this.balance += amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeFromBalance(long amount)
|
||||||
|
{
|
||||||
|
this.balance -= amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBalance(long newBalance)
|
||||||
|
{
|
||||||
|
this.balance = newBalance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package me.totalfreedom.economy;
|
||||||
|
|
||||||
|
public interface EconomicEntity
|
||||||
|
{
|
||||||
|
EconomicEntityData getEconomicData();
|
||||||
|
|
||||||
|
String getName();
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package me.totalfreedom.economy;
|
||||||
|
|
||||||
|
public interface EconomicEntityData
|
||||||
|
{
|
||||||
|
long getBalance();
|
||||||
|
|
||||||
|
void addToBalance(final long amount);
|
||||||
|
|
||||||
|
void removeFromBalance(final long amount);
|
||||||
|
|
||||||
|
void setBalance(final long newBalance);
|
||||||
|
}
|
@ -1,10 +1,25 @@
|
|||||||
package me.totalfreedom.user;
|
package me.totalfreedom.user;
|
||||||
|
|
||||||
|
import me.totalfreedom.economy.EconomicEntity;
|
||||||
|
import me.totalfreedom.economy.EconomicEntityData;
|
||||||
import me.totalfreedom.security.PermissionHolder;
|
import me.totalfreedom.security.PermissionHolder;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
public interface User extends PermissionHolder
|
public interface User extends PermissionHolder, EconomicEntity
|
||||||
{
|
{
|
||||||
|
// Implement a few EconomicEntity methods in the User interface
|
||||||
|
@Override
|
||||||
|
default String getName()
|
||||||
|
{
|
||||||
|
return getUserData().getUsername();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default EconomicEntityData getEconomicData()
|
||||||
|
{
|
||||||
|
return getUserData();
|
||||||
|
}
|
||||||
|
|
||||||
UserData getUserData();
|
UserData getUserData();
|
||||||
|
|
||||||
Component getDisplayName();
|
Component getDisplayName();
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package me.totalfreedom.user;
|
package me.totalfreedom.user;
|
||||||
|
|
||||||
|
import me.totalfreedom.economy.EconomicEntityData;
|
||||||
import me.totalfreedom.security.Group;
|
import me.totalfreedom.security.Group;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface UserData
|
public interface UserData extends EconomicEntityData
|
||||||
{
|
{
|
||||||
@NotNull UUID getUniqueId();
|
@NotNull UUID getUniqueId();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user