Compare commits
4
Commits
main
...
5ed4c32cc1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ed4c32cc1 | ||
|
|
767d248ac8 | ||
|
|
41c5725ea8 | ||
|
|
f5da67cc69 |
@@ -3,7 +3,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("com.alttd:Comet-API:1.20.4-R0.1-SNAPSHOT")
|
compileOnly("com.alttd:Galaxy-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 = "${rootProject.name}-${project.name}-$version.jar"
|
artifactId = "${project.name}-$version.jar"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.alttd.essentia.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;
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.alttd.essentia.request;
|
||||||
|
|
||||||
|
public interface Request {
|
||||||
|
|
||||||
|
void accept();
|
||||||
|
|
||||||
|
void deny();
|
||||||
|
|
||||||
|
void cancel();
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.alttd.essentia.user;
|
||||||
|
|
||||||
|
import com.alttd.essentia.request.Request;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
Location getHome(String name);
|
||||||
|
|
||||||
|
void setHome(String name, Location location);
|
||||||
|
|
||||||
|
void removeHome(String name);
|
||||||
|
|
||||||
|
int getHomeCount();
|
||||||
|
|
||||||
|
List<String> getMatchingHomeNames(String homeName);
|
||||||
|
|
||||||
|
Map<String, Location> getHomeData();
|
||||||
|
|
||||||
|
Set<String> getHomes();
|
||||||
|
|
||||||
|
boolean allowTeleports();
|
||||||
|
|
||||||
|
void setAllowTeleports(boolean allowTeleports);
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
|
boolean saving();
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
|
void saving(boolean saving);
|
||||||
|
|
||||||
|
Request request();
|
||||||
|
|
||||||
|
void request(Request request);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.alttd.essentia.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);
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -69,7 +69,7 @@ tasks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("com.alttd:Comet-API:1.20.4-R0.1-SNAPSHOT")
|
compileOnly("com.alttd:Galaxy-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:Comet-API:1.20.4-R0.1-SNAPSHOT")
|
compileOnly("com.alttd:Galaxy-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,18 +4,20 @@ 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.user.EssentiaUserManager;
|
||||||
|
import com.alttd.essentia.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;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
instance = this;
|
instance = this;
|
||||||
@@ -27,6 +29,7 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
|||||||
loadConfiguration();
|
loadConfiguration();
|
||||||
loadCommands();
|
loadCommands();
|
||||||
loadEventListeners();
|
loadEventListeners();
|
||||||
|
loadManagers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,7 +41,7 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
|||||||
Config.init();
|
Config.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadCommands() {
|
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));
|
||||||
@@ -60,9 +63,13 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
|||||||
getCommand("spawn").setExecutor(new SpawnCommand(this));
|
getCommand("spawn").setExecutor(new SpawnCommand(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadEventListeners() {
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
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.configuration.PlayerConfig;
|
import com.alttd.essentia.user.User;
|
||||||
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, PlayerConfig.getConfig(player), args);
|
return execute(player, plugin.userManager().getUser(player), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract boolean execute(Player player, PlayerConfig playerConfig, String... args);
|
protected abstract boolean execute(Player player, User user, String... args);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,8 @@ 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 {
|
||||||
|
|
||||||
|
|||||||
@@ -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.configuration.PlayerConfig;
|
|
||||||
import com.alttd.essentia.events.EssentiaEvent;
|
import com.alttd.essentia.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
||||||
import com.alttd.essentia.tasks.TeleportSounds;
|
import com.alttd.essentia.tasks.TeleportSounds;
|
||||||
|
import com.alttd.essentia.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, PlayerConfig playerConfig, String... args) {
|
protected boolean execute(Player player, User user, String... args) {
|
||||||
Location back = playerConfig.getBackLocation(false);
|
Location back = user.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.configuration.PlayerConfig;
|
|
||||||
import com.alttd.essentia.events.EssentiaEvent;
|
import com.alttd.essentia.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
||||||
import com.alttd.essentia.tasks.TeleportSounds;
|
import com.alttd.essentia.tasks.TeleportSounds;
|
||||||
|
import com.alttd.essentia.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, PlayerConfig playerConfig, String... args) {
|
protected boolean execute(Player player, User user, String... args) {
|
||||||
Location back = playerConfig.getBackLocation(true);
|
Location back = user.getBackLocation(true);
|
||||||
|
|
||||||
if (back == null) {
|
if (back == null) {
|
||||||
player.sendRichMessage(Config.NO_DEATH_LOCATION);
|
player.sendRichMessage(Config.NO_DEATH_LOCATION);
|
||||||
|
|||||||
@@ -3,10 +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.configuration.PlayerConfig;
|
|
||||||
import com.alttd.essentia.events.EssentiaEvent;
|
import com.alttd.essentia.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.events.PlayerRemoveHomeEvent;
|
import com.alttd.essentia.events.PlayerRemoveHomeEvent;
|
||||||
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
import com.alttd.essentia.user.User;
|
||||||
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;
|
||||||
|
|
||||||
@@ -17,7 +16,7 @@ public class DelHomeCommand extends PlayerSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
protected boolean execute(Player player, User user, 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")) {
|
||||||
@@ -26,7 +25,7 @@ public class DelHomeCommand extends PlayerSubCommand {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
String home = (args.length > 0) ? args[0] : "home";
|
String home = (args.length > 0) ? args[0] : "home";
|
||||||
if (!playerConfig.hasHome(home)) {
|
if (!user.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;
|
||||||
}
|
}
|
||||||
@@ -34,7 +33,7 @@ public class DelHomeCommand extends PlayerSubCommand {
|
|||||||
if (!event.callEvent()) {
|
if (!event.callEvent()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
playerConfig.setHome(home, null);
|
user.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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +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.configuration.PlayerConfig;
|
|
||||||
import com.alttd.essentia.events.EssentiaEvent;
|
import com.alttd.essentia.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
|
||||||
import com.alttd.essentia.events.PlayerTeleportHomeEvent;
|
import com.alttd.essentia.events.PlayerTeleportHomeEvent;
|
||||||
import com.alttd.essentia.tasks.TeleportSounds;
|
import com.alttd.essentia.tasks.TeleportSounds;
|
||||||
|
import com.alttd.essentia.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,19 +23,14 @@ public class HomeCommand extends PlayerSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
protected boolean execute(Player player, User user, String... args) {
|
||||||
String home = null;
|
String home = null;
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
int count = playerConfig.getHomeCount();
|
int count = user.getHomeCount();
|
||||||
if (count == 0) {
|
if (count <= 1) {
|
||||||
if (player.getBedSpawnLocation() != null) {
|
home = user.getHomes().stream().findFirst().orElse(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(", ", playerConfig.getHomeList())));
|
player.sendRichMessage(Config.SPECIFY_HOME, Placeholder.unparsed("homelist", String.join(", ", user.getHomes())));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (home == null || home.isEmpty()) {
|
if (home == null || home.isEmpty()) {
|
||||||
@@ -54,8 +48,7 @@ public class HomeCommand extends PlayerSubCommand {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
Location homeLoc = home.equalsIgnoreCase("bed") ?
|
Location homeLoc = user.getHome(home);
|
||||||
player.getBedSpawnLocation() : playerConfig.getHome(home);
|
|
||||||
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;
|
||||||
@@ -77,7 +70,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 PlayerConfig.getConfig((Player) sender).getMatchingHomeNames(args[0]);
|
return plugin.userManager().getUser((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.configuration.PlayerConfig;
|
import com.alttd.essentia.user.User;
|
||||||
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, PlayerConfig playerConfig, String... args) {
|
protected boolean execute(Player player, User user, 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(", ", playerConfig.getHomeList())));
|
player.sendRichMessage(Config.HOME_LIST, Placeholder.unparsed("homelist", String.join(", ", user.getHomes())));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +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.configuration.PlayerConfig;
|
|
||||||
import com.alttd.essentia.events.EssentiaEvent;
|
import com.alttd.essentia.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.events.PlayerSetHomeEvent;
|
import com.alttd.essentia.events.PlayerSetHomeEvent;
|
||||||
import com.alttd.essentia.events.PlayerTeleportHomeEvent;
|
import com.alttd.essentia.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.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -19,7 +18,7 @@ public class SetHomeCommand extends PlayerSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
protected boolean execute(Player player, User user, 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")) {
|
||||||
@@ -28,13 +27,13 @@ public class SetHomeCommand extends PlayerSubCommand {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
String home = (args.length > 0) ? args[0] : "home";
|
String home = (args.length > 0) ? args[0] : "home";
|
||||||
if (home.equalsIgnoreCase("bed") || home.contains(".")) {
|
if (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 = playerConfig.getHomeCount();
|
int count = user.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;
|
||||||
@@ -44,7 +43,7 @@ public class SetHomeCommand extends PlayerSubCommand {
|
|||||||
if (!event.callEvent()) {
|
if (!event.callEvent()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
playerConfig.setHome(home, homeLoc);
|
user.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,11 +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.configuration.PlayerConfig;
|
|
||||||
import com.alttd.essentia.events.EssentiaEvent;
|
import com.alttd.essentia.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.events.PlayerSetHomeEvent;
|
|
||||||
import com.alttd.essentia.events.PlayerTeleportSpawnEvent;
|
import com.alttd.essentia.events.PlayerTeleportSpawnEvent;
|
||||||
import com.alttd.essentia.tasks.TeleportSounds;
|
import com.alttd.essentia.tasks.TeleportSounds;
|
||||||
|
import com.alttd.essentia.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;
|
||||||
@@ -19,7 +18,7 @@ public class SpawnCommand extends PlayerSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
protected boolean execute(Player player, User user, 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,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.configuration.PlayerConfig;
|
import com.alttd.essentia.request.EssentiaRequest;
|
||||||
import com.alttd.essentia.request.Request;
|
import com.alttd.essentia.request.Request;
|
||||||
|
import com.alttd.essentia.user.User;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class TeleportAcceptCommand extends PlayerSubCommand {
|
public class TeleportAcceptCommand extends PlayerSubCommand {
|
||||||
@@ -14,8 +15,8 @@ public class TeleportAcceptCommand extends PlayerSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
protected boolean execute(Player player, User user, String... args) {
|
||||||
Request request = playerConfig.request();
|
Request request = user.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,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.configuration.PlayerConfig;
|
import com.alttd.essentia.request.EssentiaRequest;
|
||||||
import com.alttd.essentia.request.Request;
|
import com.alttd.essentia.request.Request;
|
||||||
|
import com.alttd.essentia.user.User;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class TeleportDenyCommand extends PlayerSubCommand {
|
public class TeleportDenyCommand extends PlayerSubCommand {
|
||||||
@@ -14,8 +15,8 @@ public class TeleportDenyCommand extends PlayerSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
protected boolean execute(Player player, User user, String... args) {
|
||||||
Request request = playerConfig.request();
|
Request request = user.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.configuration.PlayerConfig;
|
import com.alttd.essentia.request.TeleportEssentiaRequest;
|
||||||
import com.alttd.essentia.request.TeleportRequest;
|
import com.alttd.essentia.user.User;
|
||||||
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, PlayerConfig playerConfig, String... args) {
|
protected boolean execute(Player player, User user, 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())
|
||||||
);
|
);
|
||||||
|
|
||||||
PlayerConfig targetConfig = PlayerConfig.getConfig(target);
|
User targetUser = plugin.userManager().getUser(target);
|
||||||
if (targetConfig.request() != null) {
|
if (targetUser.request() != null) {
|
||||||
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetConfig.allowTeleports()) {
|
if (!targetUser.allowTeleports()) {
|
||||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
targetConfig.request(new TeleportRequest(plugin, player, target));
|
targetUser.request(new TeleportEssentiaRequest(plugin, player, target));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-8
@@ -3,9 +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.configuration.PlayerConfig;
|
import com.alttd.essentia.request.TeleportHereEssentiaRequest;
|
||||||
import com.alttd.essentia.request.TeleportHereRequest;
|
import com.alttd.essentia.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;
|
||||||
@@ -24,7 +23,7 @@ public class TeleportRequestHereCommand extends PlayerSubCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, PlayerConfig playerConfig, String... args) {
|
protected boolean execute(Player player, User user, 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;
|
||||||
@@ -45,18 +44,18 @@ public class TeleportRequestHereCommand extends PlayerSubCommand {
|
|||||||
Placeholder.component("target", target.displayName())
|
Placeholder.component("target", target.displayName())
|
||||||
);
|
);
|
||||||
|
|
||||||
PlayerConfig targetConfig = PlayerConfig.getConfig(target);
|
User targetUser = plugin.userManager().getUser(target);
|
||||||
if (targetConfig.request() != null) {
|
if (targetUser.request() != null) {
|
||||||
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
player.sendRichMessage(Config.TARGET_HAS_PENDING_REQUEST, placeholders);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetConfig.allowTeleports()) {
|
if (!targetUser.allowTeleports()) {
|
||||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
targetConfig.request(new TeleportHereRequest(plugin, player, target));
|
targetUser.request(new TeleportHereEssentiaRequest(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.configuration.PlayerConfig;
|
import com.alttd.essentia.user.User;
|
||||||
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, PlayerConfig playerConfig, String... args) {
|
protected boolean execute(Player player, User user, String... args) {
|
||||||
playerConfig.setAllowTeleports(!playerConfig.allowTeleports());
|
user.setAllowTeleports(!user.allowTeleports());
|
||||||
TagResolver placeholders = TagResolver.resolver(
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(playerConfig.allowTeleports()))
|
Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(user.allowTeleports()))
|
||||||
);
|
);
|
||||||
player.sendRichMessage(Config.TELEPORT_TOGGLE_SET, placeholders);
|
player.sendRichMessage(Config.TELEPORT_TOGGLE_SET, placeholders);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -238,4 +238,19 @@ public class Config {
|
|||||||
FEED_BY_OTHER = config.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 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() {
|
||||||
|
MYSQL_IP = config.getString("storage.mysql.ip", MYSQL_IP);
|
||||||
|
MYSQL_PORT = config.getString("storage.mysql.port", MYSQL_PORT);
|
||||||
|
MYSQL_DATABASE_NAME = config.getString("storage.mysql.database", MYSQL_DATABASE_NAME);
|
||||||
|
MYSQL_USERNAME = config.getString("storage.mysql.username", MYSQL_USERNAME);
|
||||||
|
MYSQL_PASSWORD = config.getString("storage.mysql.password", MYSQL_PASSWORD);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,186 +0,0 @@
|
|||||||
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,7 +2,7 @@ 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.configuration.PlayerConfig;
|
import com.alttd.essentia.user.User;
|
||||||
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;
|
||||||
@@ -36,8 +36,8 @@ public class PlayerListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerConfig playerConfig = PlayerConfig.getConfig(player);
|
User user = plugin.userManager().getUser(player);
|
||||||
playerConfig.setBackLocation(true, player.getLocation());
|
user.setBackLocation(true, player.getLocation());
|
||||||
player.sendRichMessage(Config.BACK_DEATH_HINT);
|
player.sendRichMessage(Config.BACK_DEATH_HINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,8 @@ 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) {
|
||||||
PlayerConfig.getConfig(player).setBackLocation(false, event.getFrom());
|
User user = plugin.userManager().getUser(player);
|
||||||
|
user.setBackLocation(false, event.getFrom());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -2,7 +2,6 @@ package com.alttd.essentia.request;
|
|||||||
|
|
||||||
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.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 +9,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 Request {
|
public abstract class EssentiaRequest implements Request {
|
||||||
|
|
||||||
private final EssentiaPlugin plugin;
|
private final EssentiaPlugin plugin;
|
||||||
@Getter private final Player requester;
|
@Getter private final Player requester;
|
||||||
@@ -19,7 +18,7 @@ public abstract class Request {
|
|||||||
|
|
||||||
TagResolver placeholders;
|
TagResolver placeholders;
|
||||||
|
|
||||||
public Request(EssentiaPlugin plugin, Player requester, Player target) {
|
public EssentiaRequest(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 +64,7 @@ public abstract class Request {
|
|||||||
public void cancel() {
|
public void cancel() {
|
||||||
try {
|
try {
|
||||||
timeoutTask.cancel();
|
timeoutTask.cancel();
|
||||||
PlayerConfig.getConfig(target).request(null);
|
plugin.userManager().getUser(target).request(null);
|
||||||
} catch (IllegalStateException ignore) {
|
} catch (IllegalStateException ignore) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -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 TeleportRequest extends Request {
|
public class TeleportEssentiaRequest extends EssentiaRequest {
|
||||||
|
|
||||||
public TeleportRequest(EssentiaPlugin plugin, Player requester, Player target) {
|
public TeleportEssentiaRequest(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);
|
||||||
+2
-2
@@ -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 TeleportHereRequest extends Request {
|
public class TeleportHereEssentiaRequest extends EssentiaRequest {
|
||||||
|
|
||||||
public TeleportHereRequest(EssentiaPlugin plugin, Player requester, Player target) {
|
public TeleportHereEssentiaRequest(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);
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.alttd.essentia.storage;
|
||||||
|
|
||||||
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
|
import com.alttd.essentia.storage.mysql.SQLStorageProvider;
|
||||||
|
import com.alttd.essentia.storage.sqlite.SQLiteStorageProvider;
|
||||||
|
import com.alttd.essentia.storage.yaml.YamlStorageProvider;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public abstract 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(); // TODO
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.alttd.essentia.storage;
|
||||||
|
|
||||||
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
|
import com.alttd.essentia.user.EssentiaUser;
|
||||||
|
import com.alttd.essentia.user.User;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public abstract class StorageProvider {
|
||||||
|
|
||||||
|
protected final EssentiaPlugin plugin;
|
||||||
|
|
||||||
|
public StorageProvider(EssentiaPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EssentiaUser loadUser(UUID uuid) {
|
||||||
|
EssentiaUser user = load(uuid);
|
||||||
|
|
||||||
|
plugin.userManager().addUser(user);
|
||||||
|
|
||||||
|
// TODO -- UserLoadEvent?
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract EssentiaUser load(UUID uuid);
|
||||||
|
|
||||||
|
public abstract void save(@NotNull User user) throws Exception;
|
||||||
|
|
||||||
|
public abstract void delete(UUID uuid) throws Exception;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.alttd.essentia.storage;
|
||||||
|
|
||||||
|
public enum StorageType {
|
||||||
|
YAML,
|
||||||
|
MYSQL,
|
||||||
|
SQLITE
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
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 execute(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 interface DatabaseTask {
|
||||||
|
|
||||||
|
void edit(PreparedStatement preparedStatement) throws SQLException;
|
||||||
|
|
||||||
|
default void onSuccess(ResultSet resultSet) throws SQLException {};
|
||||||
|
|
||||||
|
default void onFailure(SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
package com.alttd.essentia.storage.mysql;
|
||||||
|
|
||||||
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
|
import com.alttd.essentia.configuration.Config;
|
||||||
|
import com.alttd.essentia.storage.StorageProvider;
|
||||||
|
import com.alttd.essentia.user.EssentiaUser;
|
||||||
|
import com.alttd.essentia.user.User;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
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(" +
|
||||||
|
"id VARCHAR(36) NOT NULL, " +
|
||||||
|
"PRIMARY KEY (id)" +
|
||||||
|
")";
|
||||||
|
addDatabaseQuery(new DatabaseQuery(userTable), 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unload() {
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean hasTable(String table) {
|
||||||
|
DatabaseConnection connection = getDatabaseConnection();
|
||||||
|
boolean match = false;
|
||||||
|
try (ResultSet rs = connection.get().getMetaData().getTables(null, null, table, null)) {
|
||||||
|
while (rs.next()) {
|
||||||
|
if (table.equalsIgnoreCase(rs.getString("TABLE_NAME"))) {
|
||||||
|
match = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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.execute(getDatabaseConnection().get())) {
|
||||||
|
if (!resultSet.next()) {
|
||||||
|
return null; // user is not in the db
|
||||||
|
}
|
||||||
|
return new EssentiaUser.Builder()
|
||||||
|
.uuid(UUID.fromString(resultSet.getString("id")))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// catch this nicely
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(@NotNull User user) throws Exception {
|
||||||
|
String sql = "INSERT INTO users WHERE uuid = ?"; // upsert query
|
||||||
|
addDatabaseQuery(
|
||||||
|
new DatabaseQuery(sql, ps -> ps.setString(1, user.getUUID().toString())), true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.alttd.essentia.storage.sqlite;
|
||||||
|
|
||||||
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
|
import com.alttd.essentia.storage.StorageProvider;
|
||||||
|
import com.alttd.essentia.user.EssentiaUser;
|
||||||
|
import com.alttd.essentia.user.User;
|
||||||
|
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 User user) throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(UUID uuid) throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package com.alttd.essentia.storage.yaml;
|
||||||
|
|
||||||
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
|
import com.alttd.essentia.storage.StorageProvider;
|
||||||
|
import com.alttd.essentia.user.EssentiaUser;
|
||||||
|
import com.alttd.essentia.user.User;
|
||||||
|
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))
|
||||||
|
.allowTeleports(config.getBoolean("allow-teleports", true))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void save(@NotNull User user) throws Exception {
|
||||||
|
if (user.saving()) return;
|
||||||
|
user.saving(true);
|
||||||
|
|
||||||
|
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, Location> entry : user.getHomeData().entrySet()) {
|
||||||
|
setStoredLocation(config, "home." + entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
config.set("allow-teleports", user.allowTeleports());
|
||||||
|
|
||||||
|
config.save(configFile);
|
||||||
|
user.saving(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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, Location> getHomeData(YamlConfiguration config) {
|
||||||
|
ConfigurationSection section = config.getConfigurationSection("home");
|
||||||
|
if (section == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Map<String, Location> map = new HashMap<>();
|
||||||
|
for (String key : section.getValues(false).keySet()) {
|
||||||
|
map.put(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.Request;
|
import com.alttd.essentia.request.EssentiaRequest;
|
||||||
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 Request request;
|
private final EssentiaRequest request;
|
||||||
|
|
||||||
public RequestTimeout(Request request) {
|
public RequestTimeout(EssentiaRequest request) {
|
||||||
this.request = request;
|
this.request = request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
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;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,160 @@
|
|||||||
|
package com.alttd.essentia.user;
|
||||||
|
|
||||||
|
import com.alttd.essentia.request.Request;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class EssentiaUser implements User {
|
||||||
|
|
||||||
|
protected final UUID uuid;
|
||||||
|
|
||||||
|
protected Location backLocation;
|
||||||
|
protected Location deathLocation;
|
||||||
|
protected Map<String, Location> homes;
|
||||||
|
protected boolean allowTeleports;
|
||||||
|
protected Request request;
|
||||||
|
|
||||||
|
private boolean saving;
|
||||||
|
|
||||||
|
private EssentiaUser(Builder builder) {
|
||||||
|
this.uuid = builder.uuid;
|
||||||
|
this.backLocation = builder.backLocation;
|
||||||
|
this.deathLocation = builder.deathLocation;
|
||||||
|
this.homes = builder.homes;
|
||||||
|
this.allowTeleports = builder.allowTeleports;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getUUID() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getBackLocation(boolean death) {
|
||||||
|
return death ? deathLocation : backLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBackLocation(boolean death, Location location) {
|
||||||
|
if (death) {
|
||||||
|
deathLocation = location;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
backLocation = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasHome(String name) {
|
||||||
|
return homes.containsKey(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getHome(String name) {
|
||||||
|
return homes.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHome(String name, Location location) {
|
||||||
|
homes.put(name, location);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeHome(String name) {
|
||||||
|
homes.remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHomeCount() {
|
||||||
|
return homes.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getMatchingHomeNames(String homeName) {
|
||||||
|
return getHomes().stream()
|
||||||
|
.filter(home -> home.toLowerCase().startsWith(homeName.toLowerCase()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Location> getHomeData() {
|
||||||
|
return homes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> getHomes() {
|
||||||
|
return homes.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean allowTeleports() {
|
||||||
|
return allowTeleports;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAllowTeleports(boolean allowTeleports) {
|
||||||
|
this.allowTeleports = allowTeleports;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean saving() {
|
||||||
|
return saving;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saving(boolean saving) {
|
||||||
|
this.saving = saving;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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, Location> homes = new HashMap<>();
|
||||||
|
protected boolean allowTeleports;
|
||||||
|
|
||||||
|
public Builder uuid(UUID uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder backLocation(Location location) {
|
||||||
|
this.backLocation = location;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder deathLocation(Location location) {
|
||||||
|
this.deathLocation = location;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder homes(Map<String, Location> homes) {
|
||||||
|
this.homes = homes;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder allowTeleports(boolean allowTeleports) {
|
||||||
|
this.allowTeleports = allowTeleports;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EssentiaUser build() {
|
||||||
|
return new EssentiaUser(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package com.alttd.essentia.user;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class EssentiaUserManager implements UserManager {
|
||||||
|
|
||||||
|
private final Map<UUID, User> essentiaPlayers = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User getUser(Player player) {
|
||||||
|
return getUser(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User getUser(UUID uuid) {
|
||||||
|
User user = essentiaPlayers.get(uuid);
|
||||||
|
if (user != null) {
|
||||||
|
return user;
|
||||||
|
} else {
|
||||||
|
return createNewUser(uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addUser(User user) {
|
||||||
|
essentiaPlayers.put(user.getUUID(), user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeUser(UUID uuid) {
|
||||||
|
essentiaPlayers.remove(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasUser(UUID uuid) {
|
||||||
|
return essentiaPlayers.containsKey(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<UUID, User> getUsers() {
|
||||||
|
return essentiaPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public User createNewUser(UUID uuid) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user