package com.alttd.essentia.user; import com.alttd.essentia.request.Request; import lombok.Getter; import lombok.Setter; import org.bukkit.Location; import java.util.*; import java.util.stream.Collectors; public class EssentiaUser implements User { protected final UUID uuid; protected Location backLocation; protected Location deathLocation; protected Map homes; protected boolean allowTeleports; protected Request request; private boolean saving; private EssentiaUser(Builder builder) { this.uuid = builder.uuid; this.backLocation = builder.backLocation; this.deathLocation = builder.deathLocation; this.homes = builder.homes; this.allowTeleports = builder.allowTeleports; } @Override public UUID getUUID() { return uuid; } @Override public Location getBackLocation(boolean death) { return death ? deathLocation : backLocation; } @Override public void setBackLocation(boolean death, Location location) { if (death) { deathLocation = location; return; } backLocation = location; } @Override public boolean hasHome(String name) { return homes.containsKey(name); } @Override public Location getHome(String name) { return homes.get(name); } @Override public void setHome(String name, Location location) { homes.put(name, location); } @Override public void removeHome(String name) { homes.remove(name); } @Override public int getHomeCount() { return homes.size(); } @Override public List getMatchingHomeNames(String homeName) { return getHomes().stream() .filter(home -> home.toLowerCase().startsWith(homeName.toLowerCase())) .collect(Collectors.toList()); } @Override public Map getHomeData() { return homes; } @Override public Set getHomes() { return homes.keySet(); } @Override public boolean allowTeleports() { return allowTeleports; } @Override public void setAllowTeleports(boolean allowTeleports) { this.allowTeleports = allowTeleports; } @Override public boolean saving() { return saving; } @Override public void saving(boolean saving) { this.saving = saving; } @Override public Request request() { return request; } @Override public void request(Request request) { this.request = request; } public static class Builder { protected UUID uuid; protected Location backLocation = null; protected Location deathLocation = null; protected Map homes = new HashMap<>(); protected boolean allowTeleports; public Builder uuid(UUID uuid) { this.uuid = uuid; return this; } public Builder backLocation(Location location) { this.backLocation = location; return this; } public Builder deathLocation(Location location) { this.deathLocation = location; return this; } public Builder homes(Map homes) { this.homes = homes; return this; } public Builder allowTeleports(boolean allowTeleports) { this.allowTeleports = allowTeleports; return this; } public EssentiaUser build() { return new EssentiaUser(this); } } }