Compare commits
No commits in common. "dev/storage" and "main" have entirely different histories.
dev/storag
...
main
|
|
@ -3,7 +3,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("com.alttd:Galaxy-API:1.20.4-R0.1-SNAPSHOT")
|
compileOnly("com.alttd:Comet-API:1.20.4-R0.1-SNAPSHOT")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
|
@ -16,7 +16,7 @@ publishing {
|
||||||
publications {
|
publications {
|
||||||
create<MavenPublication>("mavenJava") {
|
create<MavenPublication>("mavenJava") {
|
||||||
from(components["java"])
|
from(components["java"])
|
||||||
artifactId = "${project.name}-$version.jar"
|
artifactId = "${rootProject.name}-${project.name}-$version.jar"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
package com.alttd.essentia.api.events;
|
|
||||||
|
|
||||||
import com.alttd.essentia.api.user.User;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class EssentiaUserLoadEvent extends EssentiaEvent {
|
|
||||||
|
|
||||||
private static final HandlerList handlerList = new HandlerList();
|
|
||||||
|
|
||||||
private final User user;
|
|
||||||
|
|
||||||
public EssentiaUserLoadEvent(User user) {
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlerList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlerList;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
package com.alttd.essentia.api.model;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
|
|
||||||
public interface Home {
|
|
||||||
|
|
||||||
String name();
|
|
||||||
|
|
||||||
Location location();
|
|
||||||
}
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
package com.alttd.essentia.api.model;
|
|
||||||
|
|
||||||
public interface UserSettings {
|
|
||||||
|
|
||||||
boolean godMode();
|
|
||||||
|
|
||||||
void godMode(boolean godMode);
|
|
||||||
|
|
||||||
boolean allowTeleports();
|
|
||||||
|
|
||||||
void allowTeleports(boolean allowTeleports);
|
|
||||||
|
|
||||||
boolean flying();
|
|
||||||
|
|
||||||
void flying(boolean flying);
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
package com.alttd.essentia.api.request;
|
|
||||||
|
|
||||||
public interface Request {
|
|
||||||
|
|
||||||
void accept();
|
|
||||||
|
|
||||||
void deny();
|
|
||||||
|
|
||||||
void cancel();
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
package com.alttd.essentia.api.user;
|
|
||||||
|
|
||||||
import com.alttd.essentia.api.model.Home;
|
|
||||||
import com.alttd.essentia.api.model.UserSettings;
|
|
||||||
import com.alttd.essentia.api.request.Request;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface User {
|
|
||||||
|
|
||||||
UUID getUUID();
|
|
||||||
|
|
||||||
Location getBackLocation(boolean death);
|
|
||||||
|
|
||||||
void setBackLocation(boolean death, Location location);
|
|
||||||
|
|
||||||
boolean hasHome(String name);
|
|
||||||
|
|
||||||
Home getHome(String name);
|
|
||||||
|
|
||||||
void setHome(String name, Location location);
|
|
||||||
|
|
||||||
void removeHome(String name);
|
|
||||||
|
|
||||||
int getHomeCount();
|
|
||||||
|
|
||||||
List<String> getMatchingHomeNames(String homeName);
|
|
||||||
|
|
||||||
Map<String, Home> getHomeData();
|
|
||||||
|
|
||||||
Set<String> getHomes();
|
|
||||||
|
|
||||||
UserSettings getUserSettings();
|
|
||||||
|
|
||||||
Request request();
|
|
||||||
|
|
||||||
void request(Request request);
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
package com.alttd.essentia.api.user;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public interface UserManager {
|
|
||||||
|
|
||||||
User getUser(Player player);
|
|
||||||
|
|
||||||
User getUser(UUID uuid);
|
|
||||||
|
|
||||||
void addUser(User user);
|
|
||||||
|
|
||||||
void removeUser(UUID uuid);
|
|
||||||
|
|
||||||
boolean hasUser(UUID uuid);
|
|
||||||
|
|
||||||
Map<UUID, User> getUsers();
|
|
||||||
|
|
||||||
User createNewUser(UUID uuid);
|
|
||||||
|
|
||||||
void saveAllUsers();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.essentia.api.events;
|
package com.alttd.essentia.events;
|
||||||
|
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.alttd.essentia.api.events;
|
package com.alttd.essentia.events;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.essentia.api.events;
|
package com.alttd.essentia.events;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.essentia.api.events;
|
package com.alttd.essentia.events;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.essentia.api.events;
|
package com.alttd.essentia.events;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.essentia.api.events;
|
package com.alttd.essentia.events;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
@ -69,7 +69,7 @@ tasks {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("com.alttd:Galaxy-API:1.20.4-R0.1-SNAPSHOT")
|
compileOnly("com.alttd:Comet-API:1.20.4-R0.1-SNAPSHOT")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun gitCommit(): String {
|
fun gitCommit(): String {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ plugins {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":api"))
|
implementation(project(":api"))
|
||||||
compileOnly("com.alttd:Galaxy-API:1.20.4-R0.1-SNAPSHOT")
|
compileOnly("com.alttd:Comet-API:1.20.4-R0.1-SNAPSHOT")
|
||||||
|
|
||||||
compileOnly("org.projectlombok:lombok:1.18.24")
|
compileOnly("org.projectlombok:lombok:1.18.24")
|
||||||
annotationProcessor("org.projectlombok:lombok:1.18.24")
|
annotationProcessor("org.projectlombok:lombok:1.18.24")
|
||||||
|
|
|
||||||
|
|
@ -4,26 +4,18 @@ import com.alttd.essentia.commands.admin.*;
|
||||||
import com.alttd.essentia.commands.player.*;
|
import com.alttd.essentia.commands.player.*;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.listeners.PlayerListener;
|
import com.alttd.essentia.listeners.PlayerListener;
|
||||||
import com.alttd.essentia.storage.StorageManager;
|
|
||||||
import com.alttd.essentia.storage.StorageProvider;
|
|
||||||
import com.alttd.essentia.storage.StorageType;
|
|
||||||
import com.alttd.essentia.user.EssentiaUserManager;
|
|
||||||
import com.alttd.essentia.api.user.UserManager;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private static EssentiaPlugin instance;
|
private static EssentiaPlugin instance;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private UserManager userManager;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private StorageProvider storageProvider;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
@ -35,22 +27,18 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
||||||
loadConfiguration();
|
loadConfiguration();
|
||||||
loadCommands();
|
loadCommands();
|
||||||
loadEventListeners();
|
loadEventListeners();
|
||||||
loadManagers();
|
|
||||||
loadStorageProvider();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
getServer().getScheduler().cancelTasks(this);
|
getServer().getScheduler().cancelTasks(this);
|
||||||
userManager().saveAllUsers();
|
|
||||||
storageProvider().disable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadConfiguration() {
|
public void loadConfiguration() {
|
||||||
Config.init();
|
Config.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadCommands() {
|
public void loadCommands() {
|
||||||
getCommand("essentia").setExecutor(new EssentiaCommand(this));
|
getCommand("essentia").setExecutor(new EssentiaCommand(this));
|
||||||
getCommand("teleportaccept").setExecutor(new TeleportAcceptCommand(this));
|
getCommand("teleportaccept").setExecutor(new TeleportAcceptCommand(this));
|
||||||
getCommand("teleportdeny").setExecutor(new TeleportDenyCommand(this));
|
getCommand("teleportdeny").setExecutor(new TeleportDenyCommand(this));
|
||||||
|
|
@ -72,19 +60,9 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
||||||
getCommand("spawn").setExecutor(new SpawnCommand(this));
|
getCommand("spawn").setExecutor(new SpawnCommand(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadEventListeners() {
|
public void loadEventListeners() {
|
||||||
final PluginManager pluginManager = getServer().getPluginManager();
|
final PluginManager pluginManager = getServer().getPluginManager();
|
||||||
pluginManager.registerEvents(new PlayerListener(this), this);
|
pluginManager.registerEvents(new PlayerListener(this), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadManagers() {
|
|
||||||
userManager = new EssentiaUserManager(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loadStorageProvider() {
|
|
||||||
StorageManager storageManager = new StorageManager(this);
|
|
||||||
storageProvider = storageManager.storageProvider(StorageType.valueOf(Config.STORAGE_TYPE.toUpperCase()));
|
|
||||||
storageProvider.startAutoSaving();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package com.alttd.essentia.commands;
|
package com.alttd.essentia.commands;
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public abstract class AdminSubCommand extends SubCommand {
|
public abstract class AdminSubCommand extends SubCommand {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package com.alttd.essentia.commands;
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
@ -19,8 +19,8 @@ public abstract class PlayerSubCommand extends SubCommand {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return execute(player, plugin.userManager().getUser(player), args);
|
return execute(player, PlayerConfig.getConfig(player), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract boolean execute(Player player, User user, String... args);
|
protected abstract boolean execute(Player player, PlayerConfig playerConfig, String... args);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import java.util.stream.Collectors;
|
||||||
public abstract class SubCommand implements TabExecutor {
|
public abstract class SubCommand implements TabExecutor {
|
||||||
|
|
||||||
protected EssentiaPlugin plugin;
|
protected EssentiaPlugin plugin;
|
||||||
protected final String name;
|
private final String name;
|
||||||
private final String[] aliases;
|
private final String[] aliases;
|
||||||
private final Map<String, SubCommand> subCommands = new LinkedHashMap<>();
|
private final Map<String, SubCommand> subCommands = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
package com.alttd.essentia.commands.admin;
|
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
|
||||||
import com.alttd.essentia.commands.AdminSubCommand;
|
|
||||||
import com.alttd.essentia.configuration.Config;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class BurnCommand extends AdminSubCommand {
|
|
||||||
|
|
||||||
public BurnCommand(EssentiaPlugin plugin) {
|
|
||||||
super(plugin, "burn");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean execute(CommandSender sender, String... args) {
|
|
||||||
Player target = args.length > 0 ? org.bukkit.Bukkit.getPlayer(args[0]) : sender instanceof Player player ? player : null;
|
|
||||||
if (target == null) {
|
|
||||||
sender.sendRichMessage(Config.PLAYER_NOT_FOUND);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!sender.hasPermission("essentia.command." + name + (target != sender ? ".other" : "")) ) {
|
|
||||||
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
TagResolver placeholders = TagResolver.resolver(
|
|
||||||
Placeholder.component("requester", sender.name()),
|
|
||||||
Placeholder.component("target", target.displayName())
|
|
||||||
);
|
|
||||||
target.setFireTicks((int) (3000L / 50));
|
|
||||||
sender.sendRichMessage(target == sender ? Config.BURN_SELF : Config.BURN_OTHER, placeholders);
|
|
||||||
if (target != sender)
|
|
||||||
target.sendRichMessage(Config.BURN_BY_OTHER, placeholders);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -7,8 +7,13 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class FlyCommand extends AdminSubCommand {
|
public class FlyCommand extends AdminSubCommand {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
package com.alttd.essentia.commands.admin;
|
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
|
||||||
import com.alttd.essentia.commands.AdminSubCommand;
|
|
||||||
import com.alttd.essentia.configuration.Config;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class InfoCommand extends AdminSubCommand {
|
|
||||||
|
|
||||||
public InfoCommand(EssentiaPlugin plugin) {
|
|
||||||
super(plugin, "info");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean execute(CommandSender sender, String... args) {
|
|
||||||
Player target = args.length > 0 ? org.bukkit.Bukkit.getPlayer(args[0]) : sender instanceof Player player ? player : null;
|
|
||||||
if (target == null) {
|
|
||||||
sender.sendRichMessage(Config.PLAYER_NOT_FOUND);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!sender.hasPermission("essentia.command." + name + (target != sender ? ".other" : "")) ) {
|
|
||||||
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
TagResolver placeholders = TagResolver.resolver(
|
|
||||||
Placeholder.component("requester", sender.name()),
|
|
||||||
Placeholder.component("target", target.displayName())
|
|
||||||
);
|
|
||||||
// Todo Show player info
|
|
||||||
// target.setHealth(20);
|
|
||||||
// sender.sendRichMessage(target == sender ? Config.HEAL_SELF : Config.HEAL_OTHER, placeholders);
|
|
||||||
// if (target != sender)
|
|
||||||
// target.sendRichMessage(Config.HEAL_BY_OTHER, placeholders);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
package com.alttd.essentia.commands.admin;
|
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
|
||||||
import com.alttd.essentia.commands.AdminSubCommand;
|
|
||||||
import com.alttd.essentia.configuration.Config;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class smiteCommand extends AdminSubCommand {
|
|
||||||
|
|
||||||
public smiteCommand(EssentiaPlugin plugin) {
|
|
||||||
super(plugin, "smite");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean execute(CommandSender sender, String... args) {
|
|
||||||
Player target = args.length > 0 ? org.bukkit.Bukkit.getPlayer(args[0]) : sender instanceof Player player ? player : null;
|
|
||||||
if (target == null) {
|
|
||||||
sender.sendRichMessage(Config.PLAYER_NOT_FOUND);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!sender.hasPermission("essentia.command." + name + (target != sender ? ".other" : "")) ) {
|
|
||||||
sender.sendRichMessage(Config.COMMAND_NO_PERMISSION);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
TagResolver placeholders = TagResolver.resolver(
|
|
||||||
Placeholder.component("requester", sender.name()),
|
|
||||||
Placeholder.component("target", target.displayName())
|
|
||||||
);
|
|
||||||
// Todo smite the user xD
|
|
||||||
// target.setHealth(20);
|
|
||||||
// sender.sendRichMessage(target == sender ? Config.HEAL_SELF : Config.HEAL_OTHER, placeholders);
|
|
||||||
// if (target != sender)
|
|
||||||
// target.sendRichMessage(Config.HEAL_BY_OTHER, placeholders);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -3,10 +3,10 @@ package com.alttd.essentia.commands.player;
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
|
import com.alttd.essentia.events.EssentiaEvent;
|
||||||
|
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
||||||
import com.alttd.essentia.tasks.TeleportSounds;
|
import com.alttd.essentia.tasks.TeleportSounds;
|
||||||
import com.alttd.essentia.api.user.User;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
@ -17,8 +17,8 @@ public class BackCommand extends PlayerSubCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, User user, String... args) {
|
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||||
Location back = user.getBackLocation(false);
|
Location back = playerConfig.getBackLocation(false);
|
||||||
|
|
||||||
if (back == null) {
|
if (back == null) {
|
||||||
player.sendRichMessage(Config.NO_BACK_LOCATION);
|
player.sendRichMessage(Config.NO_BACK_LOCATION);
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ package com.alttd.essentia.commands.player;
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
|
import com.alttd.essentia.events.EssentiaEvent;
|
||||||
|
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
||||||
import com.alttd.essentia.tasks.TeleportSounds;
|
import com.alttd.essentia.tasks.TeleportSounds;
|
||||||
import com.alttd.essentia.api.user.User;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
@ -17,8 +17,8 @@ public class DeathBackCommand extends PlayerSubCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, User user, String... args) {
|
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||||
Location back = user.getBackLocation(true);
|
Location back = playerConfig.getBackLocation(true);
|
||||||
|
|
||||||
if (back == null) {
|
if (back == null) {
|
||||||
player.sendRichMessage(Config.NO_DEATH_LOCATION);
|
player.sendRichMessage(Config.NO_DEATH_LOCATION);
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ package com.alttd.essentia.commands.player;
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import com.alttd.essentia.api.events.PlayerRemoveHomeEvent;
|
import com.alttd.essentia.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.events.PlayerRemoveHomeEvent;
|
||||||
|
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
@ -16,7 +17,7 @@ public class DelHomeCommand extends PlayerSubCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, User user, String... args) {
|
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||||
// TODO -- subcommand to remove other player homes
|
// TODO -- subcommand to remove other player homes
|
||||||
// if (args.length > 1) {
|
// if (args.length > 1) {
|
||||||
// if (!player.hasPermission("essentia.command.delhome.other")) {
|
// if (!player.hasPermission("essentia.command.delhome.other")) {
|
||||||
|
|
@ -25,7 +26,7 @@ public class DelHomeCommand extends PlayerSubCommand {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
String home = (args.length > 0) ? args[0] : "home";
|
String home = (args.length > 0) ? args[0] : "home";
|
||||||
if (!user.hasHome(home)) {
|
if (!playerConfig.hasHome(home)) {
|
||||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.unparsed("home", home));
|
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.unparsed("home", home));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -33,7 +34,7 @@ public class DelHomeCommand extends PlayerSubCommand {
|
||||||
if (!event.callEvent()) {
|
if (!event.callEvent()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
user.setHome(home, null);
|
playerConfig.setHome(home, null);
|
||||||
player.sendRichMessage(Config.HOME_DELETED, Placeholder.unparsed("home", home));
|
player.sendRichMessage(Config.HOME_DELETED, Placeholder.unparsed("home", home));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
package com.alttd.essentia.commands.player;
|
package com.alttd.essentia.commands.player;
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.api.model.Home;
|
|
||||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import com.alttd.essentia.api.events.PlayerTeleportHomeEvent;
|
import com.alttd.essentia.events.EssentiaEvent;
|
||||||
|
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
||||||
|
import com.alttd.essentia.events.PlayerTeleportHomeEvent;
|
||||||
import com.alttd.essentia.tasks.TeleportSounds;
|
import com.alttd.essentia.tasks.TeleportSounds;
|
||||||
import com.alttd.essentia.api.user.User;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
|
|
@ -24,14 +24,19 @@ public class HomeCommand extends PlayerSubCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, User user, String... args) {
|
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||||
String home;
|
String home = null;
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
int count = user.getHomeCount();
|
int count = playerConfig.getHomeCount();
|
||||||
if (count <= 1) {
|
if (count == 0) {
|
||||||
home = user.getHomes().stream().findFirst().orElse(null);
|
if (player.getBedSpawnLocation() != null) {
|
||||||
|
home = "bed";
|
||||||
|
}
|
||||||
|
} else if (count == 1) {
|
||||||
|
home = playerConfig.getConfigurationSection("home").getKeys(false)
|
||||||
|
.stream().findFirst().orElse(null);
|
||||||
} else {
|
} else {
|
||||||
player.sendRichMessage(Config.SPECIFY_HOME, Placeholder.unparsed("homelist", String.join(", ", user.getHomes())));
|
player.sendRichMessage(Config.SPECIFY_HOME, Placeholder.unparsed("homelist", String.join(", ", playerConfig.getHomeList())));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (home == null || home.isEmpty()) {
|
if (home == null || home.isEmpty()) {
|
||||||
|
|
@ -48,12 +53,9 @@ public class HomeCommand extends PlayerSubCommand {
|
||||||
// return true
|
// return true
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
Home essentiaHome = user.getHome(home);
|
|
||||||
if (essentiaHome == null) {
|
Location homeLoc = home.equalsIgnoreCase("bed") ?
|
||||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
|
player.getBedSpawnLocation() : playerConfig.getHome(home);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Location homeLoc = essentiaHome.location();
|
|
||||||
if (homeLoc == null) {
|
if (homeLoc == null) {
|
||||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
|
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -75,7 +77,7 @@ public class HomeCommand extends PlayerSubCommand {
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
return plugin.userManager().getUser((Player) sender).getMatchingHomeNames(args[0]);
|
return PlayerConfig.getConfig((Player) sender).getMatchingHomeNames(args[0]);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package com.alttd.essentia.commands.player;
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@ public class HomeListCommand extends PlayerSubCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, User user, String... args) {
|
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||||
// TODO - subcommand to list other homes
|
// TODO - subcommand to list other homes
|
||||||
// if (args.length > 0) {
|
// if (args.length > 0) {
|
||||||
// if (!player.hasPermission("essentia.command.homes.other")) {
|
// if (!player.hasPermission("essentia.command.homes.other")) {
|
||||||
|
|
@ -23,7 +23,7 @@ public class HomeListCommand extends PlayerSubCommand {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// TODO - clickable homes that run /home <name>
|
// TODO - clickable homes that run /home <name>
|
||||||
player.sendRichMessage(Config.HOME_LIST, Placeholder.unparsed("homelist", String.join(", ", user.getHomes())));
|
player.sendRichMessage(Config.HOME_LIST, Placeholder.unparsed("homelist", String.join(", ", playerConfig.getHomeList())));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ package com.alttd.essentia.commands.player;
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import com.alttd.essentia.api.events.PlayerSetHomeEvent;
|
import com.alttd.essentia.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.events.PlayerSetHomeEvent;
|
||||||
|
import com.alttd.essentia.events.PlayerTeleportHomeEvent;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
@ -18,7 +19,7 @@ public class SetHomeCommand extends PlayerSubCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, User user, String... args) {
|
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||||
// TODO -- subcommand to allow setting other player homes
|
// TODO -- subcommand to allow setting other player homes
|
||||||
// if (args.length > 1) {
|
// if (args.length > 1) {
|
||||||
// if (!player.hasPermission("essentia.command.sethome.other")) {
|
// if (!player.hasPermission("essentia.command.sethome.other")) {
|
||||||
|
|
@ -27,13 +28,13 @@ public class SetHomeCommand extends PlayerSubCommand {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
String home = (args.length > 0) ? args[0] : "home";
|
String home = (args.length > 0) ? args[0] : "home";
|
||||||
if (home.contains(".")) {
|
if (home.equalsIgnoreCase("bed") || home.contains(".")) {
|
||||||
player.sendRichMessage(Config.INVALID_HOME_NAME);
|
player.sendRichMessage(Config.INVALID_HOME_NAME);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int limit = 5; // TODO -- player home limits hardcoded for now
|
int limit = 5; // TODO -- player home limits hardcoded for now
|
||||||
int count = user.getHomeCount();
|
int count = playerConfig.getHomeCount();
|
||||||
if (limit >= 0 && count >= limit) {
|
if (limit >= 0 && count >= limit) {
|
||||||
player.sendRichMessage(Config.HOME_SET_MAX, Placeholder.unparsed("limit", String.valueOf(limit)));
|
player.sendRichMessage(Config.HOME_SET_MAX, Placeholder.unparsed("limit", String.valueOf(limit)));
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -43,7 +44,7 @@ public class SetHomeCommand extends PlayerSubCommand {
|
||||||
if (!event.callEvent()) {
|
if (!event.callEvent()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
user.setHome(home, homeLoc);
|
playerConfig.setHome(home, homeLoc);
|
||||||
player.sendRichMessage(Config.HOME_SET, Placeholder.unparsed("home", home));
|
player.sendRichMessage(Config.HOME_SET, Placeholder.unparsed("home", home));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,11 @@ package com.alttd.essentia.commands.player;
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import com.alttd.essentia.api.events.PlayerTeleportSpawnEvent;
|
import com.alttd.essentia.events.EssentiaEvent;
|
||||||
|
import com.alttd.essentia.events.PlayerSetHomeEvent;
|
||||||
|
import com.alttd.essentia.events.PlayerTeleportSpawnEvent;
|
||||||
import com.alttd.essentia.tasks.TeleportSounds;
|
import com.alttd.essentia.tasks.TeleportSounds;
|
||||||
import com.alttd.essentia.api.user.User;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
@ -18,7 +19,7 @@ public class SpawnCommand extends PlayerSubCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, User user, String... args) {
|
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||||
World world = plugin.getServer().getWorld(Config.SPAWN_WORLD);
|
World world = plugin.getServer().getWorld(Config.SPAWN_WORLD);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
player.sendRichMessage("<red>Could not get the configured spawn world! contact and administrator");
|
player.sendRichMessage("<red>Could not get the configured spawn world! contact and administrator");
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ package com.alttd.essentia.commands.player;
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.api.request.Request;
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.request.Request;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class TeleportAcceptCommand extends PlayerSubCommand {
|
public class TeleportAcceptCommand extends PlayerSubCommand {
|
||||||
|
|
@ -14,8 +14,8 @@ public class TeleportAcceptCommand extends PlayerSubCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, User user, String... args) {
|
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||||
Request request = user.request();
|
Request request = playerConfig.request();
|
||||||
if (request == null) {
|
if (request == null) {
|
||||||
player.sendRichMessage(Config.NO_PENDING_REQUESTS);
|
player.sendRichMessage(Config.NO_PENDING_REQUESTS);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ package com.alttd.essentia.commands.player;
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.api.request.Request;
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.request.Request;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class TeleportDenyCommand extends PlayerSubCommand {
|
public class TeleportDenyCommand extends PlayerSubCommand {
|
||||||
|
|
@ -14,8 +14,8 @@ public class TeleportDenyCommand extends PlayerSubCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, User user, String... args) {
|
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||||
Request request = user.request();
|
Request request = playerConfig.request();
|
||||||
if (request == null) {
|
if (request == null) {
|
||||||
player.sendRichMessage(Config.NO_PENDING_REQUESTS);
|
player.sendRichMessage(Config.NO_PENDING_REQUESTS);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ package com.alttd.essentia.commands.player;
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.request.TeleportEssentiaRequest;
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.request.TeleportRequest;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -23,7 +23,7 @@ public class TeleportRequestCommand extends PlayerSubCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, User user, String... args) {
|
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED);
|
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -44,18 +44,18 @@ public class TeleportRequestCommand extends PlayerSubCommand {
|
||||||
Placeholder.component("target", target.displayName())
|
Placeholder.component("target", target.displayName())
|
||||||
);
|
);
|
||||||
|
|
||||||
User targetUser = plugin.userManager().getUser(target);
|
PlayerConfig targetConfig = PlayerConfig.getConfig(target);
|
||||||
if (targetUser.request() != null) {
|
if (targetConfig.request() != null) {
|
||||||
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetUser.getUserSettings().allowTeleports()) {
|
if (!targetConfig.allowTeleports()) {
|
||||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
targetUser.request(new TeleportEssentiaRequest(plugin, player, target));
|
targetConfig.request(new TeleportRequest(plugin, player, target));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,9 @@ package com.alttd.essentia.commands.player;
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.request.TeleportHereEssentiaRequest;
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.request.TeleportHereRequest;
|
||||||
|
import com.alttd.essentia.request.TeleportRequest;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -23,7 +24,7 @@ public class TeleportRequestHereCommand extends PlayerSubCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, User user, String... args) {
|
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED);
|
player.sendRichMessage(Config.NO_PLAYER_SPECIFIED);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -44,18 +45,18 @@ public class TeleportRequestHereCommand extends PlayerSubCommand {
|
||||||
Placeholder.component("target", target.displayName())
|
Placeholder.component("target", target.displayName())
|
||||||
);
|
);
|
||||||
|
|
||||||
User targetUser = plugin.userManager().getUser(target);
|
PlayerConfig targetConfig = PlayerConfig.getConfig(target);
|
||||||
if (targetUser.request() != null) {
|
if (targetConfig.request() != null) {
|
||||||
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetUser.getUserSettings().allowTeleports()) {
|
if (!targetConfig.allowTeleports()) {
|
||||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
targetUser.request(new TeleportHereEssentiaRequest(plugin, player, target));
|
targetConfig.request(new TeleportHereRequest(plugin, player, target));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package com.alttd.essentia.commands.player;
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
|
|
@ -16,10 +16,10 @@ public class TeleportToggleCommand extends PlayerSubCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, User user, String... args) {
|
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
||||||
user.getUserSettings().allowTeleports(!user.getUserSettings().allowTeleports());
|
playerConfig.setAllowTeleports(!playerConfig.allowTeleports());
|
||||||
TagResolver placeholders = TagResolver.resolver(
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(user.getUserSettings().allowTeleports()))
|
Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(playerConfig.allowTeleports()))
|
||||||
);
|
);
|
||||||
player.sendRichMessage(Config.TELEPORT_TOGGLE_SET, placeholders);
|
player.sendRichMessage(Config.TELEPORT_TOGGLE_SET, placeholders);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -187,10 +187,6 @@ public class Config {
|
||||||
public static String FEED_SELF = "You just fed yourself.";
|
public static String FEED_SELF = "You just fed yourself.";
|
||||||
public static String FEED_OTHER = "You have fed <target>.";
|
public static String FEED_OTHER = "You have fed <target>.";
|
||||||
public static String FEED_BY_OTHER = "<requester> has fed you.";
|
public static String FEED_BY_OTHER = "<requester> has fed you.";
|
||||||
|
|
||||||
public static String BURN_SELF = "You have set yourself on fire.";
|
|
||||||
public static String BURN_OTHER = "<target>'s has been set in fire.";
|
|
||||||
public static String BURN_BY_OTHER = "<requester> has set you on fire.";
|
|
||||||
private static void messages() {
|
private static void messages() {
|
||||||
REQUEST_TIMED_OUT = getString("messages.request.time-out", REQUEST_TIMED_OUT);
|
REQUEST_TIMED_OUT = getString("messages.request.time-out", REQUEST_TIMED_OUT);
|
||||||
TELEPORT_ACCEPT_TARGET = getString("messages.request.teleport-accept-target", TELEPORT_ACCEPT_TARGET);
|
TELEPORT_ACCEPT_TARGET = getString("messages.request.teleport-accept-target", TELEPORT_ACCEPT_TARGET);
|
||||||
|
|
@ -207,60 +203,39 @@ public class Config {
|
||||||
|
|
||||||
PLAYER_ONLY_COMMAND = getString("messages.command.player-only-command", PLAYER_ONLY_COMMAND);
|
PLAYER_ONLY_COMMAND = getString("messages.command.player-only-command", PLAYER_ONLY_COMMAND);
|
||||||
NO_PLAYER_SPECIFIED = getString("messages.command.no-player-specified", NO_PLAYER_SPECIFIED);
|
NO_PLAYER_SPECIFIED = getString("messages.command.no-player-specified", NO_PLAYER_SPECIFIED);
|
||||||
PLAYER_NOT_FOUND = getString("messages.command.player-not-found", PLAYER_NOT_FOUND);
|
PLAYER_NOT_FOUND = config.getString("messages.command.player-not-found", PLAYER_NOT_FOUND);
|
||||||
PLAYER_NOT_ONLINE = getString("messages.command.player-not-online", PLAYER_NOT_ONLINE);
|
PLAYER_NOT_ONLINE = config.getString("messages.command.player-not-online", PLAYER_NOT_ONLINE);
|
||||||
COMMAND_NO_PERMISSION = getString("messages.command.no-permission", COMMAND_NO_PERMISSION);
|
COMMAND_NO_PERMISSION = config.getString("messages.command.no-permission", COMMAND_NO_PERMISSION);
|
||||||
PLAYER_INVENTORY_CLEARED = getString("messages.command.clear-inventory.player-inventory-cleared", PLAYER_INVENTORY_CLEARED);
|
PLAYER_INVENTORY_CLEARED = config.getString("messages.command.clear-inventory.player-inventory-cleared", PLAYER_INVENTORY_CLEARED);
|
||||||
INVENTORY_CLEARED_BY_OTHER = getString("messages.command.clear-inventory.inventory-clear-by-other", INVENTORY_CLEARED_BY_OTHER);
|
INVENTORY_CLEARED_BY_OTHER = config.getString("messages.command.clear-inventory.inventory-clear-by-other", INVENTORY_CLEARED_BY_OTHER);
|
||||||
INVENTORY_CLEARED = getString("messages.command.clear-inventory.inventory-cleared", INVENTORY_CLEARED);
|
INVENTORY_CLEARED = config.getString("messages.command.clear-inventory.inventory-cleared", INVENTORY_CLEARED);
|
||||||
SPECIFY_HOME = getString("messages.command.home.specify-home", SPECIFY_HOME);
|
SPECIFY_HOME = config.getString("messages.command.home.specify-home", SPECIFY_HOME);
|
||||||
HOME_NOT_SET = getString("messages.command.home.home-not-set", HOME_NOT_SET);
|
HOME_NOT_SET = config.getString("messages.command.home.home-not-set", HOME_NOT_SET);
|
||||||
HOME_DOES_NOT_EXIST = getString("messages.command.home.home-does-not-exist", HOME_DOES_NOT_EXIST);
|
HOME_DOES_NOT_EXIST = config.getString("messages.command.home.home-does-not-exist", HOME_DOES_NOT_EXIST);
|
||||||
HOME_TELEPORT = getString("messages.command.home.home-teleport", HOME_TELEPORT);
|
HOME_TELEPORT = config.getString("messages.command.home.home-teleport", HOME_TELEPORT);
|
||||||
HOME_LIST = getString("messages.command.home.home-list", HOME_LIST);
|
HOME_LIST = config.getString("messages.command.home.home-list", HOME_LIST);
|
||||||
HOME_SET = getString("messages.command.home.home-set", HOME_SET);
|
HOME_SET = config.getString("messages.command.home.home-set", HOME_SET);
|
||||||
HOME_SET_MAX = getString("messages.command.home.home-set-max", HOME_SET_MAX);
|
HOME_SET_MAX = config.getString("messages.command.home.home-set-max", HOME_SET_MAX);
|
||||||
INVALID_HOME_NAME = getString("messages.command.home.invalid-home-name", INVALID_HOME_NAME);
|
INVALID_HOME_NAME = config.getString("messages.command.home.invalid-home-name", INVALID_HOME_NAME);
|
||||||
HOME_DELETED = getString("messages.command.home.invalid-home-name", HOME_DELETED);
|
HOME_DELETED = config.getString("messages.command.home.invalid-home-name", HOME_DELETED);
|
||||||
|
|
||||||
TOGGLED_FLIGHT_BY_OTHER = getString("messages.command.fly.toggled-by-other", TOGGLED_FLIGHT_BY_OTHER);
|
TOGGLED_FLIGHT_BY_OTHER = config.getString("messages.command.fly.toggled-by-other", TOGGLED_FLIGHT_BY_OTHER);
|
||||||
TOGGLED_FLIGHT_PLAYER = getString("messages.command.fly.toggled-flight-other", TOGGLED_FLIGHT_PLAYER);
|
TOGGLED_FLIGHT_PLAYER = config.getString("messages.command.fly.toggled-flight-other", TOGGLED_FLIGHT_PLAYER);
|
||||||
TOGGLED_FLIGHT = getString("messages.command.fly.toggled-flight", TOGGLED_FLIGHT);
|
TOGGLED_FLIGHT = config.getString("messages.command.fly.toggled-flight", TOGGLED_FLIGHT);
|
||||||
NO_BACK_LOCATION = getString("messages.command.back.no-back-location", NO_BACK_LOCATION);
|
NO_BACK_LOCATION = config.getString("messages.command.back.no-back-location", NO_BACK_LOCATION);
|
||||||
TELEPORTING_BACK = getString("messages.command.back.teleporting-back", TELEPORTING_BACK);
|
TELEPORTING_BACK = config.getString("messages.command.back.teleporting-back", TELEPORTING_BACK);
|
||||||
NO_DEATH_LOCATION = getString("messages.command.back.no-death-location", NO_DEATH_LOCATION);
|
NO_DEATH_LOCATION = config.getString("messages.command.back.no-death-location", NO_DEATH_LOCATION);
|
||||||
TELEPORTING_BACK_DEATH = getString("messages.command.back.teleporting-back-death", TELEPORTING_BACK_DEATH);
|
TELEPORTING_BACK_DEATH = config.getString("messages.command.back.teleporting-back-death", TELEPORTING_BACK_DEATH);
|
||||||
BACK_DEATH_HINT = getString("messages.command.back.dback-hint", BACK_DEATH_HINT);
|
BACK_DEATH_HINT = config.getString("messages.command.back.dback-hint", BACK_DEATH_HINT);
|
||||||
GAMEMODE_SET = getString("messages.command.gamemode.gamemode-set", GAMEMODE_SET);
|
GAMEMODE_SET = config.getString("messages.command.gamemode.gamemode-set", GAMEMODE_SET);
|
||||||
GAMEMODE_SET_OTHER = getString("messages.command.gamemode.gamemode-set-other", GAMEMODE_SET_OTHER);
|
GAMEMODE_SET_OTHER = config.getString("messages.command.gamemode.gamemode-set-other", GAMEMODE_SET_OTHER);
|
||||||
GAMEMODE_SET_BY_OTHER = getString("messages.command.gamemode.gamemode-set-by-other", GAMEMODE_SET_BY_OTHER);
|
GAMEMODE_SET_BY_OTHER = config.getString("messages.command.gamemode.gamemode-set-by-other", GAMEMODE_SET_BY_OTHER);
|
||||||
HEAL_SELF = getString("messages.command.heal.heal-self", HEAL_SELF);
|
HEAL_SELF = config.getString("messages.command.heal.heal-self", HEAL_SELF);
|
||||||
HEAL_OTHER = getString("messages.command.heal.heal-other", HEAL_OTHER);
|
HEAL_OTHER = config.getString("messages.command.heal.heal-other", HEAL_OTHER);
|
||||||
HEAL_BY_OTHER = getString("messages.command.heal.heal-by-other", HEAL_BY_OTHER);
|
HEAL_BY_OTHER = config.getString("messages.command.heal.heal-by-other", HEAL_BY_OTHER);
|
||||||
FEED_SELF = getString("messages.command.feed.feed-self", FEED_SELF);
|
FEED_SELF = config.getString("messages.command.feed.feed-self", FEED_SELF);
|
||||||
FEED_OTHER = getString("messages.command.feed.feed-other", FEED_OTHER);
|
FEED_OTHER = config.getString("messages.command.feed.feed-other", FEED_OTHER);
|
||||||
FEED_BY_OTHER = getString("messages.command.feed.feed-by-other", FEED_BY_OTHER);
|
FEED_BY_OTHER = config.getString("messages.command.feed.feed-by-other", FEED_BY_OTHER);
|
||||||
}
|
|
||||||
|
|
||||||
public static String STORAGE_TYPE = "mysql";
|
|
||||||
public static boolean AUTO_SAVE = true;
|
|
||||||
public static int AUTO_SAVE_DELAY = 60;
|
|
||||||
public static String MYSQL_IP = "localhost";
|
|
||||||
public static String MYSQL_PORT = "3306";
|
|
||||||
public static String MYSQL_DATABASE_NAME = "essentia";
|
|
||||||
public static String MYSQL_USERNAME = "root";
|
|
||||||
public static String MYSQL_PASSWORD = "root";
|
|
||||||
public static int MYSQL_CONNECTIONS = 10;
|
|
||||||
public static int MYSQL_QUEUE_DELAY = 5;
|
|
||||||
private static void storage() {
|
|
||||||
STORAGE_TYPE = getString("storage.type", STORAGE_TYPE);
|
|
||||||
AUTO_SAVE = getBoolean("storage.auto-save", AUTO_SAVE);
|
|
||||||
AUTO_SAVE_DELAY = getInt("storaeg.auto-save-delay", AUTO_SAVE_DELAY);
|
|
||||||
MYSQL_IP = getString("storage.mysql.ip", MYSQL_IP);
|
|
||||||
MYSQL_PORT = getString("storage.mysql.port", MYSQL_PORT);
|
|
||||||
MYSQL_DATABASE_NAME = getString("storage.mysql.database", MYSQL_DATABASE_NAME);
|
|
||||||
MYSQL_USERNAME = getString("storage.mysql.username", MYSQL_USERNAME);
|
|
||||||
MYSQL_PASSWORD = getString("storage.mysql.password", MYSQL_PASSWORD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,186 @@
|
||||||
|
package com.alttd.essentia.configuration;
|
||||||
|
|
||||||
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
|
import com.alttd.essentia.request.Request;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class PlayerConfig extends YamlConfiguration {
|
||||||
|
|
||||||
|
private static final Map<Player, PlayerConfig> configs = new HashMap<>();
|
||||||
|
|
||||||
|
public static PlayerConfig getConfig(Player player) {
|
||||||
|
synchronized (configs) {
|
||||||
|
return configs.computeIfAbsent(player, k -> new PlayerConfig(player));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void remove(Player player) {
|
||||||
|
synchronized (configs) {
|
||||||
|
configs.remove(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeAll() {
|
||||||
|
synchronized (configs) {
|
||||||
|
configs.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final File file;
|
||||||
|
private final Object saveLock = new Object();
|
||||||
|
private final OfflinePlayer player;
|
||||||
|
@Getter @Setter private Request request;
|
||||||
|
|
||||||
|
private PlayerConfig(Player player) {
|
||||||
|
super();
|
||||||
|
this.player = player;
|
||||||
|
this.file = new File(EssentiaPlugin.instance().getDataFolder(), "PlayerData" + File.separator + player.getUniqueId() + ".yml");
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reload() {
|
||||||
|
synchronized (saveLock) {
|
||||||
|
try {
|
||||||
|
load(file);
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void save() {
|
||||||
|
synchronized (saveLock) {
|
||||||
|
try {
|
||||||
|
save(file);
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Location getStoredLocation(String path) {
|
||||||
|
if (get(path) == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
World world = Bukkit.getWorld(getString(path + ".world", ""));
|
||||||
|
if (world == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
double x = getDouble(path + ".x");
|
||||||
|
double y = getDouble(path + ".y");
|
||||||
|
double z = getDouble(path + ".z");
|
||||||
|
float pitch = (float) getDouble(path + ".pitch");
|
||||||
|
float yaw = (float) getDouble(path + ".yaw");
|
||||||
|
return new Location(world, x, y, z, yaw, pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setStoredLocation(String path, Location location) {
|
||||||
|
if (location == null) {
|
||||||
|
set(path, null);
|
||||||
|
save();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
set(path + ".world", location.getWorld().getName());
|
||||||
|
set(path + ".x", location.getX());
|
||||||
|
set(path + ".y", location.getY());
|
||||||
|
set(path + ".z", location.getZ());
|
||||||
|
set(path + ".pitch", location.getPitch());
|
||||||
|
set(path + ".yaw", location.getYaw());
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getBackLocation(boolean death) {
|
||||||
|
return getStoredLocation(death ? "teleports.death" : "teleports.back");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackLocation(boolean death, Location location) {
|
||||||
|
setStoredLocation(death ? "teleports.death" : "teleports.back", location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasHome(String name) {
|
||||||
|
ConfigurationSection section = getConfigurationSection("home." + name);
|
||||||
|
return section != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getHome(String name) {
|
||||||
|
return getStoredLocation("home." + name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setHome(String name, Location location) {
|
||||||
|
setStoredLocation("home." + name, location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHomeCount() {
|
||||||
|
ConfigurationSection section = getConfigurationSection("home");
|
||||||
|
if (section == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return section.getKeys(false).size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getMatchingHomeNames(String name) {
|
||||||
|
ConfigurationSection section = getConfigurationSection("home");
|
||||||
|
if (section == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<String> list = section.getValues(false).keySet().stream()
|
||||||
|
.filter(home -> home.toLowerCase().startsWith(name.toLowerCase()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (player.getBedSpawnLocation() != null && "bed".startsWith(name.toLowerCase()))
|
||||||
|
list.add("bed");
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Location> getHomeData() {
|
||||||
|
ConfigurationSection section = getConfigurationSection("home");
|
||||||
|
if (section == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Map<String, Location> map = new HashMap<>();
|
||||||
|
for (String key : section.getValues(false).keySet()) {
|
||||||
|
map.put(key, getHome(key));
|
||||||
|
}
|
||||||
|
if (player.getBedSpawnLocation() != null)
|
||||||
|
map.put("bed", player.getBedSpawnLocation());
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getHomeList() {
|
||||||
|
ConfigurationSection section = getConfigurationSection("home");
|
||||||
|
if (section == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<String> list = new ArrayList<>(section.getValues(false).keySet());
|
||||||
|
if (player.getBedSpawnLocation() != null)
|
||||||
|
list.add("bed");
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean allowTeleports() {
|
||||||
|
return getBoolean("allow-teleports", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAllowTeleports(boolean allowTeleports) {
|
||||||
|
set("allow-teleports", allowTeleports);
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -2,16 +2,12 @@ package com.alttd.essentia.listeners;
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.user.EssentiaUser;
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import com.alttd.essentia.api.user.User;
|
|
||||||
import com.alttd.essentia.api.user.UserManager;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
@ -19,7 +15,7 @@ import java.util.Set;
|
||||||
|
|
||||||
public class PlayerListener implements Listener {
|
public class PlayerListener implements Listener {
|
||||||
|
|
||||||
private final EssentiaPlugin plugin;
|
private EssentiaPlugin plugin;
|
||||||
private final Set<PlayerTeleportEvent.TeleportCause> backAllowCauses = new HashSet<>();
|
private final Set<PlayerTeleportEvent.TeleportCause> backAllowCauses = new HashSet<>();
|
||||||
|
|
||||||
public PlayerListener(EssentiaPlugin plugin) {
|
public PlayerListener(EssentiaPlugin plugin) {
|
||||||
|
|
@ -40,8 +36,8 @@ public class PlayerListener implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = plugin.userManager().getUser(player);
|
PlayerConfig playerConfig = PlayerConfig.getConfig(player);
|
||||||
user.setBackLocation(true, player.getLocation());
|
playerConfig.setBackLocation(true, player.getLocation());
|
||||||
player.sendRichMessage(Config.BACK_DEATH_HINT);
|
player.sendRichMessage(Config.BACK_DEATH_HINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,33 +57,7 @@ public class PlayerListener implements Listener {
|
||||||
|
|
||||||
// only save location if teleporting more than 5 blocks
|
// only save location if teleporting more than 5 blocks
|
||||||
if (!to.getWorld().equals(from.getWorld()) || to.distanceSquared(from) > 25) {
|
if (!to.getWorld().equals(from.getWorld()) || to.distanceSquared(from) > 25) {
|
||||||
User user = plugin.userManager().getUser(player);
|
PlayerConfig.getConfig(player).setBackLocation(false, event.getFrom());
|
||||||
user.setBackLocation(false, event.getFrom());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (plugin.userManager().hasUser(player.getUniqueId()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
plugin.storageProvider().loadUser(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
UserManager userManager = plugin.userManager();
|
|
||||||
if (!userManager.hasUser(player.getUniqueId())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
User user = userManager.getUser(player);
|
|
||||||
try {
|
|
||||||
if (user instanceof EssentiaUser essentiaUser)
|
|
||||||
plugin.storageProvider().save(essentiaUser);
|
|
||||||
userManager.removeUser(player.getUniqueId());
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
package com.alttd.essentia.model;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
|
|
||||||
public record EssentiaHome(String name, Location location) implements com.alttd.essentia.api.model.Home {}
|
|
||||||
|
|
@ -1,99 +0,0 @@
|
||||||
package com.alttd.essentia.model;
|
|
||||||
|
|
||||||
import com.alttd.essentia.api.model.UserSettings;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class EssentiaUserSettings implements UserSettings {
|
|
||||||
|
|
||||||
boolean godMode;
|
|
||||||
boolean flying;
|
|
||||||
double flySpeed;
|
|
||||||
double walkSpeed;
|
|
||||||
boolean pTime;
|
|
||||||
boolean pWeather;
|
|
||||||
boolean allowTeleports;
|
|
||||||
|
|
||||||
private boolean needsSaving;
|
|
||||||
|
|
||||||
private EssentiaUserSettings(Builder builder) {
|
|
||||||
this.godMode = builder.godMode;;
|
|
||||||
this.flying = builder.flying;
|
|
||||||
this.flySpeed = builder.flySpeed;
|
|
||||||
this.walkSpeed = builder.walkSpeed;
|
|
||||||
this.pTime = builder.pTime;
|
|
||||||
this.pWeather = builder.pWeather;
|
|
||||||
this.allowTeleports = builder.allowTeleports;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void godMode(boolean godMode) {
|
|
||||||
this.godMode = godMode;
|
|
||||||
this.needsSaving = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void allowTeleports(boolean allowTeleports) {
|
|
||||||
this.allowTeleports = allowTeleports;
|
|
||||||
this.needsSaving = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void flying(boolean flying) {
|
|
||||||
this.flying = flying;
|
|
||||||
this.needsSaving = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Builder {
|
|
||||||
|
|
||||||
// TODO - defaults?
|
|
||||||
protected boolean godMode;
|
|
||||||
protected boolean flying;
|
|
||||||
protected double flySpeed;
|
|
||||||
protected double walkSpeed;
|
|
||||||
protected boolean pTime;
|
|
||||||
protected boolean pWeather;
|
|
||||||
protected boolean allowTeleports;
|
|
||||||
|
|
||||||
public Builder godMode(boolean godMode) {
|
|
||||||
this.godMode = godMode;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder flying(boolean flying) {
|
|
||||||
this.flying = flying;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder flySpeed(double flySpeed) {
|
|
||||||
this.flySpeed = flySpeed;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder walkSpeed(double walkSpeed) {
|
|
||||||
this.walkSpeed = walkSpeed;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder pTime(boolean pTime) {
|
|
||||||
this.pTime = pTime;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder pWeather(boolean pWeather) {
|
|
||||||
this.pWeather = pWeather;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder allowTeleports(boolean allowTeleports) {
|
|
||||||
this.allowTeleports = allowTeleports;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EssentiaUserSettings build() {
|
|
||||||
return new EssentiaUserSettings(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
package com.alttd.essentia.model;
|
|
||||||
|
|
||||||
public record Kit() {}
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
package com.alttd.essentia.model;
|
|
||||||
|
|
||||||
public record PlayerInventory() {
|
|
||||||
}
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package com.alttd.essentia.request;
|
package com.alttd.essentia.request;
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.api.request.Request;
|
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
|
import com.alttd.essentia.configuration.PlayerConfig;
|
||||||
import com.alttd.essentia.tasks.RequestTimeout;
|
import com.alttd.essentia.tasks.RequestTimeout;
|
||||||
import com.alttd.essentia.tasks.TeleportSounds;
|
import com.alttd.essentia.tasks.TeleportSounds;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
@ -10,7 +10,7 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public abstract class EssentiaRequest implements Request {
|
public abstract class Request {
|
||||||
|
|
||||||
private final EssentiaPlugin plugin;
|
private final EssentiaPlugin plugin;
|
||||||
@Getter private final Player requester;
|
@Getter private final Player requester;
|
||||||
|
|
@ -19,7 +19,7 @@ public abstract class EssentiaRequest implements Request {
|
||||||
|
|
||||||
TagResolver placeholders;
|
TagResolver placeholders;
|
||||||
|
|
||||||
public EssentiaRequest(EssentiaPlugin plugin, Player requester, Player target) {
|
public Request(EssentiaPlugin plugin, Player requester, Player target) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.requester = requester;
|
this.requester = requester;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
|
@ -65,7 +65,7 @@ public abstract class EssentiaRequest implements Request {
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
try {
|
try {
|
||||||
timeoutTask.cancel();
|
timeoutTask.cancel();
|
||||||
plugin.userManager().getUser(target).request(null);
|
PlayerConfig.getConfig(target).request(null);
|
||||||
} catch (IllegalStateException ignore) {
|
} catch (IllegalStateException ignore) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,9 +4,9 @@ import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class TeleportHereEssentiaRequest extends EssentiaRequest {
|
public class TeleportHereRequest extends Request {
|
||||||
|
|
||||||
public TeleportHereEssentiaRequest(EssentiaPlugin plugin, Player requester, Player target) {
|
public TeleportHereRequest(EssentiaPlugin plugin, Player requester, Player target) {
|
||||||
super(plugin, requester, target);
|
super(plugin, requester, target);
|
||||||
|
|
||||||
target.sendRichMessage(Config.TELEPORT_REQUEST_TARGET, placeholders);
|
target.sendRichMessage(Config.TELEPORT_REQUEST_TARGET, placeholders);
|
||||||
|
|
@ -4,9 +4,9 @@ import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class TeleportEssentiaRequest extends EssentiaRequest {
|
public class TeleportRequest extends Request {
|
||||||
|
|
||||||
public TeleportEssentiaRequest(EssentiaPlugin plugin, Player requester, Player target) {
|
public TeleportRequest(EssentiaPlugin plugin, Player requester, Player target) {
|
||||||
super(plugin, requester, target);
|
super(plugin, requester, target);
|
||||||
|
|
||||||
target.sendRichMessage(Config.TELEPORT_REQUESTHERE_TARGET, placeholders);
|
target.sendRichMessage(Config.TELEPORT_REQUESTHERE_TARGET, placeholders);
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
package com.alttd.essentia.storage;
|
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
|
||||||
import com.alttd.essentia.storage.mysql.SQLStorageProvider;
|
|
||||||
import com.alttd.essentia.storage.yaml.YamlStorageProvider;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class StorageManager {
|
|
||||||
|
|
||||||
protected final EssentiaPlugin plugin;
|
|
||||||
|
|
||||||
public StorageManager(EssentiaPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StorageProvider storageProvider(StorageType type) {
|
|
||||||
return switch (type) {
|
|
||||||
case MYSQL -> new SQLStorageProvider(plugin);
|
|
||||||
case YAML -> new YamlStorageProvider(plugin, plugin.getDataFolder().getPath() + File.separator + "PlayerData");
|
|
||||||
case SQLITE -> throw new UnsupportedOperationException(); // FIXME
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
package com.alttd.essentia.storage;
|
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
|
||||||
import com.alttd.essentia.api.events.EssentiaUserLoadEvent;
|
|
||||||
import com.alttd.essentia.configuration.Config;
|
|
||||||
import com.alttd.essentia.user.EssentiaUser;
|
|
||||||
import com.alttd.essentia.api.user.User;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public abstract class StorageProvider {
|
|
||||||
|
|
||||||
protected final EssentiaPlugin plugin;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private AutoSaveTask autoSaveTask;
|
|
||||||
|
|
||||||
public StorageProvider(EssentiaPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User loadUser(UUID uuid) {
|
|
||||||
User user = load(uuid);
|
|
||||||
|
|
||||||
if (user == null) {
|
|
||||||
user = plugin.userManager().createNewUser(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.userManager().addUser(user);
|
|
||||||
|
|
||||||
new EssentiaUserLoadEvent(user).callEvent();
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startAutoSaving() {
|
|
||||||
if (!Config.AUTO_SAVE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
autoSaveTask = new AutoSaveTask();
|
|
||||||
int delay = Config.AUTO_SAVE_DELAY * 20;
|
|
||||||
autoSaveTask.runTaskTimerAsynchronously(plugin, delay, delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disable() {
|
|
||||||
// Override if some extra steps are required when disabling the plugin.
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract EssentiaUser load(UUID uuid);
|
|
||||||
|
|
||||||
public void startSaving(EssentiaUser user) throws Exception {
|
|
||||||
if (user.saving() || !user.needsSaving()) return;
|
|
||||||
user.saving(true);
|
|
||||||
|
|
||||||
save(user);
|
|
||||||
|
|
||||||
user.saving(false);
|
|
||||||
user.needsSaving(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void save(@NotNull EssentiaUser user) throws Exception;
|
|
||||||
|
|
||||||
public abstract void delete(UUID uuid) throws Exception;
|
|
||||||
|
|
||||||
private class AutoSaveTask extends BukkitRunnable {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
plugin.userManager().saveAllUsers();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
package com.alttd.essentia.storage;
|
|
||||||
|
|
||||||
public enum StorageType {
|
|
||||||
YAML,
|
|
||||||
MYSQL,
|
|
||||||
SQLITE
|
|
||||||
}
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
package com.alttd.essentia.storage.mysql;
|
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
|
||||||
import com.alttd.essentia.configuration.Config;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class DatabaseConnection implements AutoCloseable {
|
|
||||||
private Connection connection;
|
|
||||||
private volatile boolean isActive;
|
|
||||||
protected final EssentiaPlugin plugin;
|
|
||||||
|
|
||||||
public DatabaseConnection(EssentiaPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
try {
|
|
||||||
openConnection();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void openConnection() throws SQLException {
|
|
||||||
if (connection != null && !connection.isClosed()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (this) {
|
|
||||||
if (connection != null && !connection.isClosed()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
connection = DriverManager.getConnection(
|
|
||||||
"jdbc:mysql://" + Config.MYSQL_IP + ":" + Config.MYSQL_PORT + "/" + Config.MYSQL_DATABASE_NAME +
|
|
||||||
"?autoReconnect=true&useSSL=false",
|
|
||||||
Config.MYSQL_USERNAME, Config.MYSQL_PASSWORD);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized Connection get() {
|
|
||||||
try {
|
|
||||||
openConnection();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized boolean isValid() {
|
|
||||||
try {
|
|
||||||
return !connection.isClosed() && connection.isValid(8000);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized void setActive(boolean active) {
|
|
||||||
isActive = active;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized boolean isActive() {
|
|
||||||
return isActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void close() {
|
|
||||||
try {
|
|
||||||
if (!connection.isClosed()) {
|
|
||||||
if (!connection.getAutoCommit()) {
|
|
||||||
connection.commit();
|
|
||||||
}
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
package com.alttd.essentia.storage.mysql;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class DatabaseQuery {
|
|
||||||
|
|
||||||
private final String statement;
|
|
||||||
private final DatabaseTask databaseTask;
|
|
||||||
|
|
||||||
public DatabaseQuery(String statement, DatabaseTask databaseTask) {
|
|
||||||
this.statement = statement;
|
|
||||||
this.databaseTask = databaseTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatabaseQuery(String statement) {
|
|
||||||
this(statement, ps -> {});
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResultSet executeQuery(Connection connection) {
|
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(statement)) {
|
|
||||||
databaseTask.edit(preparedStatement);
|
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
|
||||||
databaseTask.onSuccess(resultSet);
|
|
||||||
return resultSet;
|
|
||||||
} catch (SQLException e) {
|
|
||||||
databaseTask.onFailure(e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void execute(Connection connection) {
|
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(statement)) {
|
|
||||||
databaseTask.edit(preparedStatement);
|
|
||||||
preparedStatement.execute();
|
|
||||||
databaseTask.onSuccess();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
databaseTask.onFailure(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface DatabaseTask {
|
|
||||||
|
|
||||||
void edit(PreparedStatement preparedStatement) throws SQLException;
|
|
||||||
|
|
||||||
default void onSuccess(ResultSet resultSet) throws SQLException {};
|
|
||||||
|
|
||||||
default void onSuccess() throws SQLException {};
|
|
||||||
|
|
||||||
default void onFailure(SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
package com.alttd.essentia.storage.mysql;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Queue;
|
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
|
|
||||||
public class DatabaseQueue extends BukkitRunnable {
|
|
||||||
|
|
||||||
private final SQLStorageProvider sqlStorageProvider;
|
|
||||||
|
|
||||||
public DatabaseQueue(SQLStorageProvider sqlStorageProvider) {
|
|
||||||
this.sqlStorageProvider = sqlStorageProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public final Queue<DatabaseQuery> databaseQueryQueue = new LinkedBlockingQueue<>();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
runTaskQueue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void runTaskQueue() {
|
|
||||||
if (databaseQueryQueue.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
DatabaseConnection databaseConnection = sqlStorageProvider.getDatabaseConnection();
|
|
||||||
Connection connection = databaseConnection.get();
|
|
||||||
|
|
||||||
try {
|
|
||||||
databaseConnection.setActive(true);
|
|
||||||
connection.setAutoCommit(false);
|
|
||||||
while (!databaseQueryQueue.isEmpty()) {
|
|
||||||
if (!databaseConnection.isValid())
|
|
||||||
return;
|
|
||||||
|
|
||||||
DatabaseQuery databaseQuery = databaseQueryQueue.poll();
|
|
||||||
if (databaseQuery == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
databaseQuery.execute(connection);
|
|
||||||
}
|
|
||||||
if (!connection.getAutoCommit()) {
|
|
||||||
connection.commit();
|
|
||||||
connection.setAutoCommit(true);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
databaseConnection.setActive(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,257 +0,0 @@
|
||||||
package com.alttd.essentia.storage.mysql;
|
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
|
||||||
import com.alttd.essentia.configuration.Config;
|
|
||||||
import com.alttd.essentia.api.model.Home;
|
|
||||||
import com.alttd.essentia.model.EssentiaHome;
|
|
||||||
import com.alttd.essentia.model.EssentiaUserSettings;
|
|
||||||
import com.alttd.essentia.storage.StorageProvider;
|
|
||||||
import com.alttd.essentia.user.EssentiaUser;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class SQLStorageProvider extends StorageProvider {
|
|
||||||
|
|
||||||
private final DatabaseQueue databaseQueue;
|
|
||||||
private final List<DatabaseConnection> CONNECTIONPOOL = new ArrayList<>();
|
|
||||||
|
|
||||||
public SQLStorageProvider(EssentiaPlugin plugin) {
|
|
||||||
super(plugin);
|
|
||||||
databaseQueue = new DatabaseQueue(this);
|
|
||||||
int delay = Config.MYSQL_QUEUE_DELAY * 20;
|
|
||||||
databaseQueue.runTaskTimerAsynchronously(plugin, delay, delay);
|
|
||||||
// preload out database connections, TODO FIND A BETTER WAY TO LIMIT THIS
|
|
||||||
for (int i = 1; i < Config.MYSQL_CONNECTIONS; i++) {
|
|
||||||
CONNECTIONPOOL.add(null);
|
|
||||||
}
|
|
||||||
createTables();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createTables() {
|
|
||||||
// TODO -- create table
|
|
||||||
String userTable = "CREATE TABLE IF NOT EXISTS users(" +
|
|
||||||
"UUID VARCHAR(36) NOT NULL, " +
|
|
||||||
"DeathLocation mediumtext DEFAULT NULL, " +
|
|
||||||
"BackLocation mediumtext DEFAULT NULL, " +
|
|
||||||
"TeleportToggled tinyint(1) DEFAULT NULL, " +
|
|
||||||
"PRIMARY KEY (uuid)" +
|
|
||||||
")";
|
|
||||||
String homeTable = "CREATE TABLE IF NOT EXISTS homes(" +
|
|
||||||
"UUID VARCHAR(36) NOT NULL, " +
|
|
||||||
"Name mediumtext DEFAULT NULL, " +
|
|
||||||
"HomeLocation mediumtext DEFAULT NULL, "+
|
|
||||||
")";
|
|
||||||
String settingsTable = "CREATE TABLE IF NOT EXISTS homes(" +
|
|
||||||
"UUID VARCHAR(36) NOT NULL, " +
|
|
||||||
"TeleportToggled tinyint(1) DEFAULT NULL, " +
|
|
||||||
"GodMode tinyint(1) DEFAULT NULL, " +
|
|
||||||
"Flying tinyint(1) DEFAULT NULL, " +
|
|
||||||
"PRIMARY KEY (uuid)" +
|
|
||||||
")";
|
|
||||||
addDatabaseQuery(new DatabaseQuery(userTable), false);
|
|
||||||
addDatabaseQuery(new DatabaseQuery(homeTable), false);
|
|
||||||
addDatabaseQuery(new DatabaseQuery(settingsTable), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatabaseConnection getDatabaseConnection() {
|
|
||||||
for (int i = 0; i < Config.MYSQL_CONNECTIONS; i++) {
|
|
||||||
DatabaseConnection connection = CONNECTIONPOOL.get(i);
|
|
||||||
if (connection == null) {
|
|
||||||
return generateDatabaseConnection(i);
|
|
||||||
} else if (!connection.isActive()) {
|
|
||||||
if (connection.isValid()) {
|
|
||||||
return connection;
|
|
||||||
} else {
|
|
||||||
connection.close();
|
|
||||||
return generateDatabaseConnection(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This will cause an infinite running loop, throw an exception or wait for a connection to be available?
|
|
||||||
return getDatabaseConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
private DatabaseConnection generateDatabaseConnection(int index) {
|
|
||||||
DatabaseConnection connection = new DatabaseConnection(plugin);
|
|
||||||
CONNECTIONPOOL.set(index, connection);
|
|
||||||
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void closeDatabaseConnections() {
|
|
||||||
for (DatabaseConnection connection : CONNECTIONPOOL) {
|
|
||||||
if (connection == null || connection.isValid())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!connection.isActive()) {
|
|
||||||
connection.close();
|
|
||||||
} else {
|
|
||||||
while (connection.isActive()) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// This should not be interrupted as this is saving all the shops in the background for us.
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disable() {
|
|
||||||
if (databaseQueue != null && !databaseQueue.isCancelled()) {
|
|
||||||
databaseQueue.cancel();
|
|
||||||
databaseQueue.runTaskQueue();
|
|
||||||
}
|
|
||||||
closeDatabaseConnections();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addDatabaseQuery(DatabaseQuery databaseQuery, boolean queue) {
|
|
||||||
if (queue) {
|
|
||||||
databaseQueue.databaseQueryQueue().offer(databaseQuery);
|
|
||||||
} else {
|
|
||||||
databaseQuery.execute(getDatabaseConnection().get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO -- make this async
|
|
||||||
@Override
|
|
||||||
protected EssentiaUser load(UUID uuid) {
|
|
||||||
String sql = "SELECT * FROM users WHERE uuid = ?";
|
|
||||||
DatabaseQuery databaseQuery = new DatabaseQuery(sql, ps -> ps.setString(1, uuid.toString()));
|
|
||||||
try (ResultSet resultSet = databaseQuery.executeQuery(getDatabaseConnection().get())) {
|
|
||||||
if (!resultSet.next()) {
|
|
||||||
return null; // user is not in the db
|
|
||||||
}
|
|
||||||
return new EssentiaUser.Builder()
|
|
||||||
.uuid(uuid)
|
|
||||||
.backLocation(locationStringToLocation(resultSet.getString("BackLocation")))
|
|
||||||
.deathLocation(locationStringToLocation(resultSet.getString("DeathLocation")))
|
|
||||||
.homes(loadHomes(uuid))
|
|
||||||
.userSettings(new EssentiaUserSettings
|
|
||||||
.Builder()
|
|
||||||
//.allowTeleports(resultSet.getBoolean("TeleportToggled")) // FIXME
|
|
||||||
.build())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
// catch this nicely
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, Home> loadHomes(UUID uuid) {
|
|
||||||
String sql = "SELECT * FROM homes WHERE uuid = ?";
|
|
||||||
Map<String, Home> locationMap = new HashMap<>();
|
|
||||||
DatabaseQuery databaseQuery = new DatabaseQuery(sql, ps -> ps.setString(1, uuid.toString()));
|
|
||||||
try (ResultSet resultSet = databaseQuery.executeQuery(getDatabaseConnection().get())) {
|
|
||||||
if (!resultSet.next()) {
|
|
||||||
return locationMap;
|
|
||||||
}
|
|
||||||
String homeName = resultSet.getString("Name");
|
|
||||||
while (resultSet.next()) {
|
|
||||||
locationMap.put(
|
|
||||||
homeName,
|
|
||||||
new EssentiaHome(
|
|
||||||
homeName,
|
|
||||||
locationStringToLocation(resultSet.getString("HomeLocation"))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
// catch this nicely
|
|
||||||
}
|
|
||||||
return locationMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save(@NotNull EssentiaUser user) throws Exception {
|
|
||||||
// TODO - convert to json object and save that in sql!
|
|
||||||
// Todo - use reflection to go over the fields to save?
|
|
||||||
// might not be the best way if new fields are added...
|
|
||||||
// split into multiple tables - users, userdata, userhomes, ... ?
|
|
||||||
String sql = "INSERT INTO users" +
|
|
||||||
"(uuid)" + // columns
|
|
||||||
"VALUES (?)" + // data
|
|
||||||
"ON DUPLICATE KEY UPDATE " + // data
|
|
||||||
"uuid = ?";
|
|
||||||
addDatabaseQuery(
|
|
||||||
new DatabaseQuery(sql, new DatabaseQuery.DatabaseTask() {
|
|
||||||
@Override
|
|
||||||
public void edit(PreparedStatement ps) throws SQLException {
|
|
||||||
ps.setString(1, user.getUUID().toString());
|
|
||||||
ps.setString(2, user.getUUID().toString());
|
|
||||||
}
|
|
||||||
}), true
|
|
||||||
);
|
|
||||||
saveHomes(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveHomes(EssentiaUser essentiaUser) {
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete(UUID uuid) throws Exception {
|
|
||||||
String sql = "DELETE FROM users WHERE uuid = ?";
|
|
||||||
addDatabaseQuery(
|
|
||||||
new DatabaseQuery(sql, new DatabaseQuery.DatabaseTask() {
|
|
||||||
@Override
|
|
||||||
public void edit(PreparedStatement ps) throws SQLException {
|
|
||||||
ps.setString(1, uuid.toString());
|
|
||||||
}
|
|
||||||
}), true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String locationToString(Location location) {
|
|
||||||
if (location == null)
|
|
||||||
return "";
|
|
||||||
|
|
||||||
String wordName = location.getWorld().getName();
|
|
||||||
double x = location.getX();
|
|
||||||
double y = location.getY();
|
|
||||||
double z = location.getZ();
|
|
||||||
float pitch = location.getPitch();
|
|
||||||
float yaw = location.getYaw();
|
|
||||||
return wordName + ":" + x + ":" + y + ":" + z + ":" + pitch + ":" + yaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Location locationStringToLocation(String locationString) {
|
|
||||||
if (locationString == null || locationString.isEmpty())
|
|
||||||
return null;
|
|
||||||
String[] split = locationString.split(":");
|
|
||||||
|
|
||||||
// should prob have some error catching
|
|
||||||
World wordName = Bukkit.getWorld(split[0]);
|
|
||||||
double x = Double.parseDouble(split[1]);
|
|
||||||
double y = Double.parseDouble(split[2]);
|
|
||||||
double z = Double.parseDouble(split[3]);
|
|
||||||
float pitch = Float.parseFloat(split[4]);
|
|
||||||
float yaw = Float.parseFloat(split[5]);
|
|
||||||
return new Location(wordName, x, y, z, pitch, yaw);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String locationMapToString(Map<String, Location> map) {
|
|
||||||
// Todo -- can this be better?
|
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
|
||||||
for (Map.Entry<String, Location> entry : map.entrySet()) {
|
|
||||||
if (!stringBuilder.isEmpty())
|
|
||||||
stringBuilder.append(";");
|
|
||||||
|
|
||||||
stringBuilder.append(entry.getKey()).append("%").append(locationToString(entry.getValue()));
|
|
||||||
}
|
|
||||||
return stringBuilder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
package com.alttd.essentia.storage.sqlite;
|
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
|
||||||
import com.alttd.essentia.storage.StorageProvider;
|
|
||||||
import com.alttd.essentia.user.EssentiaUser;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
// TODO -- add support for SQLite
|
|
||||||
public class SQLiteStorageProvider extends StorageProvider {
|
|
||||||
|
|
||||||
public SQLiteStorageProvider(EssentiaPlugin plugin) {
|
|
||||||
super(plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected EssentiaUser load(UUID uuid) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save(@NotNull EssentiaUser user) throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete(UUID uuid) throws Exception {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,112 +0,0 @@
|
||||||
package com.alttd.essentia.storage.yaml;
|
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
|
||||||
import com.alttd.essentia.api.model.Home;
|
|
||||||
import com.alttd.essentia.model.EssentiaHome;
|
|
||||||
import com.alttd.essentia.model.EssentiaUserSettings;
|
|
||||||
import com.alttd.essentia.storage.StorageProvider;
|
|
||||||
import com.alttd.essentia.user.EssentiaUser;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
// TODO -- switch to configurate?
|
|
||||||
public class YamlStorageProvider extends StorageProvider {
|
|
||||||
|
|
||||||
private final String dataDirectory;
|
|
||||||
|
|
||||||
public YamlStorageProvider(EssentiaPlugin plugin, String dataDirectory) {
|
|
||||||
super(plugin);
|
|
||||||
this.dataDirectory = dataDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected EssentiaUser load(UUID uuid) {
|
|
||||||
File configFile = new File(dataDirectory, uuid + ".yml");
|
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
|
||||||
return new EssentiaUser.Builder()
|
|
||||||
.uuid(uuid)
|
|
||||||
.backLocation(getStoredLocation(config,"teleports.back"))
|
|
||||||
.deathLocation(getStoredLocation(config,"teleports.death"))
|
|
||||||
.homes(getHomeData(config))
|
|
||||||
.userSettings(new EssentiaUserSettings
|
|
||||||
.Builder()
|
|
||||||
.allowTeleports(config.getBoolean("allow-teleports", true))
|
|
||||||
.build())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void save(@NotNull EssentiaUser user) throws Exception {
|
|
||||||
File configFile = new File(dataDirectory, user.getUUID() + ".yml");
|
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
|
||||||
|
|
||||||
setStoredLocation(config, "teleports.back", user.getBackLocation(false));
|
|
||||||
setStoredLocation(config, "teleports.death", user.getBackLocation(true));
|
|
||||||
for (Map.Entry<String, Home> entry : user.getHomeData().entrySet()) {
|
|
||||||
setStoredLocation(config, "home." + entry.getKey(), entry.getValue().location());
|
|
||||||
}
|
|
||||||
config.set("allow-teleports", user.getUserSettings().allowTeleports());
|
|
||||||
|
|
||||||
config.save(configFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void delete(UUID uuid) throws Exception {
|
|
||||||
Path path = Path.of(dataDirectory, uuid.toString() + ".yml");
|
|
||||||
Files.deleteIfExists(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setStoredLocation(YamlConfiguration config, String path, Location location) {
|
|
||||||
if (location == null) {
|
|
||||||
config.set(path, null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
config.set(path + ".world", location.getWorld().getName());
|
|
||||||
config.set(path + ".x", location.getX());
|
|
||||||
config.set(path + ".y", location.getY());
|
|
||||||
config.set(path + ".z", location.getZ());
|
|
||||||
config.set(path + ".pitch", location.getPitch());
|
|
||||||
config.set(path + ".yaw", location.getYaw());
|
|
||||||
}
|
|
||||||
|
|
||||||
Location getStoredLocation(YamlConfiguration config, String path) {
|
|
||||||
if (config.get(path) == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
World world = Bukkit.getWorld(config.getString(path + ".world", ""));
|
|
||||||
if (world == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
double x = config.getDouble(path + ".x");
|
|
||||||
double y = config.getDouble(path + ".y");
|
|
||||||
double z = config.getDouble(path + ".z");
|
|
||||||
float pitch = (float) config.getDouble(path + ".pitch");
|
|
||||||
float yaw = (float) config.getDouble(path + ".yaw");
|
|
||||||
return new Location(world, x, y, z, yaw, pitch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, Home> getHomeData(YamlConfiguration config) {
|
|
||||||
ConfigurationSection section = config.getConfigurationSection("home");
|
|
||||||
if (section == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Map<String, Home> map = new HashMap<>();
|
|
||||||
for (String key : section.getValues(false).keySet()) {
|
|
||||||
map.put(key, new EssentiaHome(key, getStoredLocation(config, "home." + key)));
|
|
||||||
}
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +1,15 @@
|
||||||
package com.alttd.essentia.tasks;
|
package com.alttd.essentia.tasks;
|
||||||
|
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
import com.alttd.essentia.request.EssentiaRequest;
|
import com.alttd.essentia.request.Request;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
public class RequestTimeout extends BukkitRunnable {
|
public class RequestTimeout extends BukkitRunnable {
|
||||||
private final EssentiaRequest request;
|
private final Request request;
|
||||||
|
|
||||||
public RequestTimeout(EssentiaRequest request) {
|
public RequestTimeout(Request request) {
|
||||||
this.request = request;
|
this.request = request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.alttd.essentia.tasks;
|
package com.alttd.essentia.tasks;
|
||||||
|
|
||||||
import com.alttd.essentia.configuration.Config;
|
import com.alttd.essentia.configuration.Config;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,167 +0,0 @@
|
||||||
package com.alttd.essentia.user;
|
|
||||||
|
|
||||||
import com.alttd.essentia.api.model.Home;
|
|
||||||
import com.alttd.essentia.api.model.UserSettings;
|
|
||||||
import com.alttd.essentia.api.request.Request;
|
|
||||||
import com.alttd.essentia.api.user.User;
|
|
||||||
import com.alttd.essentia.model.EssentiaHome;
|
|
||||||
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, Home> homes;
|
|
||||||
protected UserSettings userSettings;
|
|
||||||
protected Request request;
|
|
||||||
|
|
||||||
private boolean saving;
|
|
||||||
private boolean needsSaving; // can we use a decorator for this to set it to true on every change?
|
|
||||||
|
|
||||||
private EssentiaUser(Builder builder) {
|
|
||||||
this.uuid = builder.uuid;
|
|
||||||
this.backLocation = builder.backLocation;
|
|
||||||
this.deathLocation = builder.deathLocation;
|
|
||||||
this.homes = builder.homes;
|
|
||||||
this.userSettings = builder.userSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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;
|
|
||||||
needsSaving = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasHome(String name) {
|
|
||||||
return homes.containsKey(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Home getHome(String name) {
|
|
||||||
return homes.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setHome(String name, Location location) {
|
|
||||||
homes.put(name, new EssentiaHome(name, location));
|
|
||||||
needsSaving = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeHome(String name) {
|
|
||||||
homes.remove(name);
|
|
||||||
needsSaving = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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, Home> getHomeData() {
|
|
||||||
return homes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> getHomes() {
|
|
||||||
return homes.keySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserSettings getUserSettings() {
|
|
||||||
return userSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean saving() {
|
|
||||||
return saving;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saving(boolean saving) {
|
|
||||||
this.saving = saving;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean needsSaving() {
|
|
||||||
return needsSaving;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void needsSaving(boolean needsSaving) {
|
|
||||||
this.needsSaving = needsSaving;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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<String, Home> homes = new HashMap<>();
|
|
||||||
protected UserSettings userSettings = null;
|
|
||||||
|
|
||||||
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, Home> homes) {
|
|
||||||
this.homes = homes;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder userSettings(UserSettings userSettings) {
|
|
||||||
this.userSettings = userSettings;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EssentiaUser build() {
|
|
||||||
return new EssentiaUser(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,80 +0,0 @@
|
||||||
package com.alttd.essentia.user;
|
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
|
||||||
import com.alttd.essentia.api.user.User;
|
|
||||||
import com.alttd.essentia.api.user.UserManager;
|
|
||||||
import com.alttd.essentia.model.EssentiaUserSettings;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
public class EssentiaUserManager implements UserManager {
|
|
||||||
|
|
||||||
protected final EssentiaPlugin plugin;
|
|
||||||
|
|
||||||
private final Map<UUID, User> essentiaPlayers = new ConcurrentHashMap<>();
|
|
||||||
|
|
||||||
public EssentiaUserManager(EssentiaPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 new EssentiaUser.Builder().uuid(uuid).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveAllUsers() {
|
|
||||||
for (User user : getUsers().values()) {
|
|
||||||
if (user instanceof EssentiaUser essentiaUser && essentiaUser.getUserSettings() instanceof EssentiaUserSettings essentiaUserSettings) {
|
|
||||||
try {
|
|
||||||
if (essentiaUser.saving() || !essentiaUser.needsSaving() || !essentiaUserSettings.needsSaving()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
plugin.storageProvider().startSaving(essentiaUser);
|
|
||||||
} catch(Exception e){
|
|
||||||
essentiaUser.saving(false);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user