Add API and beans for User and UserManager.
This commit is contained in:
@@ -4,18 +4,20 @@ import com.alttd.essentia.commands.admin.*;
|
||||
import com.alttd.essentia.commands.player.*;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.listeners.PlayerListener;
|
||||
import com.alttd.essentia.user.EssentiaUserManager;
|
||||
import com.alttd.essentia.user.UserManager;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
||||
|
||||
@Getter
|
||||
private static EssentiaPlugin instance;
|
||||
|
||||
@Getter
|
||||
private UserManager userManager;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
instance = this;
|
||||
@@ -27,6 +29,7 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
||||
loadConfiguration();
|
||||
loadCommands();
|
||||
loadEventListeners();
|
||||
loadManagers();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,7 +41,7 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
||||
Config.init();
|
||||
}
|
||||
|
||||
public void loadCommands() {
|
||||
void loadCommands() {
|
||||
getCommand("essentia").setExecutor(new EssentiaCommand(this));
|
||||
getCommand("teleportaccept").setExecutor(new TeleportAcceptCommand(this));
|
||||
getCommand("teleportdeny").setExecutor(new TeleportDenyCommand(this));
|
||||
@@ -60,9 +63,13 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
||||
getCommand("spawn").setExecutor(new SpawnCommand(this));
|
||||
}
|
||||
|
||||
public void loadEventListeners() {
|
||||
void loadEventListeners() {
|
||||
final PluginManager pluginManager = getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new PlayerListener(this), this);
|
||||
}
|
||||
|
||||
void loadManagers() {
|
||||
userManager = new EssentiaUserManager();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
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<String, Location> homes;
|
||||
protected boolean allowTeleports;
|
||||
|
||||
@Getter @Setter
|
||||
private 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<String> getMatchingHomeNames(String homeName) {
|
||||
return getHomes().stream()
|
||||
.filter(home -> home.toLowerCase().startsWith(homeName.toLowerCase()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Location> getHomeData() {
|
||||
return homes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> 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;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
protected UUID uuid;
|
||||
protected Location backLocation = null;
|
||||
protected Location deathLocation = null;
|
||||
protected Map<String, Location> 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<String, Location> homes) {
|
||||
this.homes = homes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder allowTeleports(boolean allowTeleports) {
|
||||
this.allowTeleports = allowTeleports;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EssentiaUser build() {
|
||||
return new EssentiaUser(this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.alttd.essentia.user;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class EssentiaUserManager implements UserManager {
|
||||
|
||||
private final Map<UUID, User> essentiaPlayers = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public User getUser(Player player) {
|
||||
return getUser(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(UUID uuid) {
|
||||
User user = essentiaPlayers.get(uuid);
|
||||
if (user != null) {
|
||||
return user;
|
||||
} else {
|
||||
return createNewUser(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUser(User user) {
|
||||
essentiaPlayers.put(user.getUUID(), user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUser(UUID uuid) {
|
||||
essentiaPlayers.remove(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasUser(UUID uuid) {
|
||||
return essentiaPlayers.containsKey(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<UUID, User> getUsers() {
|
||||
return essentiaPlayers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User createNewUser(UUID uuid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user