Compare commits
No commits in common. "bbd4610fbe96cc66ea63ac35c28bf386cb081316" and "5ed4c32cc1430e4dce3eb1ef467d27eee5326d6f" have entirely different histories.
bbd4610fbe
...
5ed4c32cc1
|
|
@ -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,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,4 +1,4 @@
|
||||||
package com.alttd.essentia.api.events;
|
package com.alttd.essentia.events;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.essentia.api.request;
|
package com.alttd.essentia.request;
|
||||||
|
|
||||||
public interface Request {
|
public interface Request {
|
||||||
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
package com.alttd.essentia.api.user;
|
package com.alttd.essentia.user;
|
||||||
|
|
||||||
import com.alttd.essentia.api.model.Home;
|
import com.alttd.essentia.request.Request;
|
||||||
import com.alttd.essentia.api.model.UserSettings;
|
|
||||||
import com.alttd.essentia.api.request.Request;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -20,7 +19,7 @@ public interface User {
|
||||||
|
|
||||||
boolean hasHome(String name);
|
boolean hasHome(String name);
|
||||||
|
|
||||||
Home getHome(String name);
|
Location getHome(String name);
|
||||||
|
|
||||||
void setHome(String name, Location location);
|
void setHome(String name, Location location);
|
||||||
|
|
||||||
|
|
@ -30,11 +29,19 @@ public interface User {
|
||||||
|
|
||||||
List<String> getMatchingHomeNames(String homeName);
|
List<String> getMatchingHomeNames(String homeName);
|
||||||
|
|
||||||
Map<String, Home> getHomeData();
|
Map<String, Location> getHomeData();
|
||||||
|
|
||||||
Set<String> getHomes();
|
Set<String> getHomes();
|
||||||
|
|
||||||
UserSettings getUserSettings();
|
boolean allowTeleports();
|
||||||
|
|
||||||
|
void setAllowTeleports(boolean allowTeleports);
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
|
boolean saving();
|
||||||
|
|
||||||
|
@ApiStatus.Internal
|
||||||
|
void saving(boolean saving);
|
||||||
|
|
||||||
Request request();
|
Request request();
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.essentia.api.user;
|
package com.alttd.essentia.user;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
@ -21,6 +21,4 @@ public interface UserManager {
|
||||||
|
|
||||||
User createNewUser(UUID uuid);
|
User createNewUser(UUID uuid);
|
||||||
|
|
||||||
void saveAllUsers();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -4,11 +4,8 @@ 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.user.EssentiaUserManager;
|
||||||
import com.alttd.essentia.api.user.UserManager;
|
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;
|
||||||
|
|
@ -21,9 +18,6 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
||||||
@Getter
|
@Getter
|
||||||
private UserManager userManager;
|
private UserManager userManager;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private StorageProvider storageProvider;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
instance = this;
|
instance = this;
|
||||||
|
|
@ -36,14 +30,11 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
||||||
loadCommands();
|
loadCommands();
|
||||||
loadEventListeners();
|
loadEventListeners();
|
||||||
loadManagers();
|
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() {
|
||||||
|
|
@ -78,13 +69,7 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadManagers() {
|
void loadManagers() {
|
||||||
userManager = new EssentiaUserManager(this);
|
userManager = new EssentiaUserManager();
|
||||||
}
|
|
||||||
|
|
||||||
void loadStorageProvider() {
|
|
||||||
StorageManager storageManager = new StorageManager(this);
|
|
||||||
storageProvider = storageManager.storageProvider(StorageType.valueOf(Config.STORAGE_TYPE.toUpperCase()));
|
|
||||||
storageProvider.startAutoSaving();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.user.User;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
|
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 com.alttd.essentia.user.User;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
|
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 com.alttd.essentia.user.User;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +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.api.events.EssentiaEvent;
|
import com.alttd.essentia.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.api.events.PlayerRemoveHomeEvent;
|
import com.alttd.essentia.events.PlayerRemoveHomeEvent;
|
||||||
import com.alttd.essentia.api.user.User;
|
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;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
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.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.api.events.PlayerTeleportHomeEvent;
|
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 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;
|
||||||
|
|
@ -25,7 +24,7 @@ public class HomeCommand extends PlayerSubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, User user, String... args) {
|
protected boolean execute(Player player, User user, String... args) {
|
||||||
String home;
|
String home = null;
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
int count = user.getHomeCount();
|
int count = user.getHomeCount();
|
||||||
if (count <= 1) {
|
if (count <= 1) {
|
||||||
|
|
@ -48,12 +47,8 @@ public class HomeCommand extends PlayerSubCommand {
|
||||||
// return true
|
// return true
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
Home essentiaHome = user.getHome(home);
|
|
||||||
if (essentiaHome == null) {
|
Location homeLoc = user.getHome(home);
|
||||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", 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;
|
||||||
|
|
|
||||||
|
|
@ -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.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;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +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.api.events.EssentiaEvent;
|
import com.alttd.essentia.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.api.events.PlayerSetHomeEvent;
|
import com.alttd.essentia.events.PlayerSetHomeEvent;
|
||||||
import com.alttd.essentia.api.user.User;
|
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;
|
||||||
|
|
|
||||||
|
|
@ -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.events.EssentiaEvent;
|
||||||
import com.alttd.essentia.api.events.PlayerTeleportSpawnEvent;
|
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 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;
|
||||||
|
|
|
||||||
|
|
@ -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.api.request.Request;
|
import com.alttd.essentia.request.EssentiaRequest;
|
||||||
import com.alttd.essentia.api.user.User;
|
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 {
|
||||||
|
|
|
||||||
|
|
@ -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.api.request.Request;
|
import com.alttd.essentia.request.EssentiaRequest;
|
||||||
import com.alttd.essentia.api.user.User;
|
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 {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ 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.request.TeleportEssentiaRequest;
|
||||||
import com.alttd.essentia.api.user.User;
|
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;
|
||||||
|
|
@ -50,7 +50,7 @@ public class TeleportRequestCommand extends PlayerSubCommand {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetUser.getUserSettings().allowTeleports()) {
|
if (!targetUser.allowTeleports()) {
|
||||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ 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.request.TeleportHereEssentiaRequest;
|
||||||
import com.alttd.essentia.api.user.User;
|
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;
|
||||||
|
|
@ -50,7 +50,7 @@ public class TeleportRequestHereCommand extends PlayerSubCommand {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!targetUser.getUserSettings().allowTeleports()) {
|
if (!targetUser.allowTeleports()) {
|
||||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||||
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.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;
|
||||||
|
|
@ -17,9 +17,9 @@ public class TeleportToggleCommand extends PlayerSubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean execute(Player player, User user, String... args) {
|
protected boolean execute(Player player, User user, String... args) {
|
||||||
user.getUserSettings().allowTeleports(!user.getUserSettings().allowTeleports());
|
user.setAllowTeleports(!user.allowTeleports());
|
||||||
TagResolver placeholders = TagResolver.resolver(
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(user.getUserSettings().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;
|
||||||
|
|
|
||||||
|
|
@ -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,44 +203,41 @@ 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_IP = "localhost";
|
||||||
public static String MYSQL_PORT = "3306";
|
public static String MYSQL_PORT = "3306";
|
||||||
public static String MYSQL_DATABASE_NAME = "essentia";
|
public static String MYSQL_DATABASE_NAME = "essentia";
|
||||||
|
|
@ -253,14 +246,11 @@ public class Config {
|
||||||
public static int MYSQL_CONNECTIONS = 10;
|
public static int MYSQL_CONNECTIONS = 10;
|
||||||
public static int MYSQL_QUEUE_DELAY = 5;
|
public static int MYSQL_QUEUE_DELAY = 5;
|
||||||
private static void storage() {
|
private static void storage() {
|
||||||
STORAGE_TYPE = getString("storage.type", STORAGE_TYPE);
|
MYSQL_IP = config.getString("storage.mysql.ip", MYSQL_IP);
|
||||||
AUTO_SAVE = getBoolean("storage.auto-save", AUTO_SAVE);
|
MYSQL_PORT = config.getString("storage.mysql.port", MYSQL_PORT);
|
||||||
AUTO_SAVE_DELAY = getInt("storaeg.auto-save-delay", AUTO_SAVE_DELAY);
|
MYSQL_DATABASE_NAME = config.getString("storage.mysql.database", MYSQL_DATABASE_NAME);
|
||||||
MYSQL_IP = getString("storage.mysql.ip", MYSQL_IP);
|
MYSQL_USERNAME = config.getString("storage.mysql.username", MYSQL_USERNAME);
|
||||||
MYSQL_PORT = getString("storage.mysql.port", MYSQL_PORT);
|
MYSQL_PASSWORD = config.getString("storage.mysql.password", MYSQL_PASSWORD);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.user.User;
|
||||||
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) {
|
||||||
|
|
@ -65,29 +61,4 @@ public class PlayerListener implements Listener {
|
||||||
user.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,7 +1,6 @@
|
||||||
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.tasks.RequestTimeout;
|
import com.alttd.essentia.tasks.RequestTimeout;
|
||||||
import com.alttd.essentia.tasks.TeleportSounds;
|
import com.alttd.essentia.tasks.TeleportSounds;
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,12 @@ package com.alttd.essentia.storage;
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.storage.mysql.SQLStorageProvider;
|
import com.alttd.essentia.storage.mysql.SQLStorageProvider;
|
||||||
|
import com.alttd.essentia.storage.sqlite.SQLiteStorageProvider;
|
||||||
import com.alttd.essentia.storage.yaml.YamlStorageProvider;
|
import com.alttd.essentia.storage.yaml.YamlStorageProvider;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class StorageManager {
|
public abstract class StorageManager {
|
||||||
|
|
||||||
protected final EssentiaPlugin plugin;
|
protected final EssentiaPlugin plugin;
|
||||||
|
|
||||||
|
|
@ -18,7 +19,7 @@ public class StorageManager {
|
||||||
return switch (type) {
|
return switch (type) {
|
||||||
case MYSQL -> new SQLStorageProvider(plugin);
|
case MYSQL -> new SQLStorageProvider(plugin);
|
||||||
case YAML -> new YamlStorageProvider(plugin, plugin.getDataFolder().getPath() + File.separator + "PlayerData");
|
case YAML -> new YamlStorageProvider(plugin, plugin.getDataFolder().getPath() + File.separator + "PlayerData");
|
||||||
case SQLITE -> throw new UnsupportedOperationException(); // FIXME
|
case SQLITE -> throw new UnsupportedOperationException(); // TODO
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
package com.alttd.essentia.storage;
|
package com.alttd.essentia.storage;
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
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.user.EssentiaUser;
|
||||||
import com.alttd.essentia.api.user.User;
|
import com.alttd.essentia.user.User;
|
||||||
import lombok.Getter;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
@ -15,61 +11,22 @@ public abstract class StorageProvider {
|
||||||
|
|
||||||
protected final EssentiaPlugin plugin;
|
protected final EssentiaPlugin plugin;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private AutoSaveTask autoSaveTask;
|
|
||||||
|
|
||||||
public StorageProvider(EssentiaPlugin plugin) {
|
public StorageProvider(EssentiaPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User loadUser(UUID uuid) {
|
public EssentiaUser loadUser(UUID uuid) {
|
||||||
User user = load(uuid);
|
EssentiaUser user = load(uuid);
|
||||||
|
|
||||||
if (user == null) {
|
|
||||||
user = plugin.userManager().createNewUser(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.userManager().addUser(user);
|
plugin.userManager().addUser(user);
|
||||||
|
|
||||||
new EssentiaUserLoadEvent(user).callEvent();
|
// TODO -- UserLoadEvent?
|
||||||
return user;
|
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);
|
protected abstract EssentiaUser load(UUID uuid);
|
||||||
|
|
||||||
public void startSaving(EssentiaUser user) throws Exception {
|
public abstract void save(@NotNull User 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;
|
public abstract void delete(UUID uuid) throws Exception;
|
||||||
|
|
||||||
private class AutoSaveTask extends BukkitRunnable {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
plugin.userManager().saveAllUsers();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public class DatabaseQuery {
|
||||||
this(statement, ps -> {});
|
this(statement, ps -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultSet executeQuery(Connection connection) {
|
public ResultSet execute(Connection connection) {
|
||||||
try (PreparedStatement preparedStatement = connection.prepareStatement(statement)) {
|
try (PreparedStatement preparedStatement = connection.prepareStatement(statement)) {
|
||||||
databaseTask.edit(preparedStatement);
|
databaseTask.edit(preparedStatement);
|
||||||
ResultSet resultSet = preparedStatement.executeQuery();
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
|
@ -31,24 +31,12 @@ public class DatabaseQuery {
|
||||||
return null;
|
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 {
|
public interface DatabaseTask {
|
||||||
|
|
||||||
void edit(PreparedStatement preparedStatement) throws SQLException;
|
void edit(PreparedStatement preparedStatement) throws SQLException;
|
||||||
|
|
||||||
default void onSuccess(ResultSet resultSet) throws SQLException {};
|
default void onSuccess(ResultSet resultSet) throws SQLException {};
|
||||||
|
|
||||||
default void onSuccess() throws SQLException {};
|
|
||||||
|
|
||||||
default void onFailure(SQLException e) {
|
default void onFailure(SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,17 @@ package com.alttd.essentia.storage.mysql;
|
||||||
|
|
||||||
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.model.Home;
|
|
||||||
import com.alttd.essentia.model.EssentiaHome;
|
|
||||||
import com.alttd.essentia.model.EssentiaUserSettings;
|
|
||||||
import com.alttd.essentia.storage.StorageProvider;
|
import com.alttd.essentia.storage.StorageProvider;
|
||||||
import com.alttd.essentia.user.EssentiaUser;
|
import com.alttd.essentia.user.EssentiaUser;
|
||||||
import org.bukkit.Bukkit;
|
import com.alttd.essentia.user.User;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class SQLStorageProvider extends StorageProvider {
|
public class SQLStorageProvider extends StorageProvider {
|
||||||
|
|
||||||
|
|
@ -37,27 +34,10 @@ public class SQLStorageProvider extends StorageProvider {
|
||||||
private void createTables() {
|
private void createTables() {
|
||||||
// TODO -- create table
|
// TODO -- create table
|
||||||
String userTable = "CREATE TABLE IF NOT EXISTS users(" +
|
String userTable = "CREATE TABLE IF NOT EXISTS users(" +
|
||||||
"UUID VARCHAR(36) NOT NULL, " +
|
"id VARCHAR(36) NOT NULL, " +
|
||||||
"DeathLocation mediumtext DEFAULT NULL, " +
|
"PRIMARY KEY (id)" +
|
||||||
"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(userTable), false);
|
||||||
addDatabaseQuery(new DatabaseQuery(homeTable), false);
|
|
||||||
addDatabaseQuery(new DatabaseQuery(settingsTable), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatabaseConnection getDatabaseConnection() {
|
public DatabaseConnection getDatabaseConnection() {
|
||||||
|
|
@ -107,8 +87,7 @@ public class SQLStorageProvider extends StorageProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void unload() {
|
||||||
public void disable() {
|
|
||||||
if (databaseQueue != null && !databaseQueue.isCancelled()) {
|
if (databaseQueue != null && !databaseQueue.isCancelled()) {
|
||||||
databaseQueue.cancel();
|
databaseQueue.cancel();
|
||||||
databaseQueue.runTaskQueue();
|
databaseQueue.runTaskQueue();
|
||||||
|
|
@ -124,24 +103,32 @@ public class SQLStorageProvider extends StorageProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO -- make this async
|
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
|
@Override
|
||||||
protected EssentiaUser load(UUID uuid) {
|
protected EssentiaUser load(UUID uuid) {
|
||||||
String sql = "SELECT * FROM users WHERE uuid = ?";
|
String sql = "SELECT * FROM users WHERE uuid = ?";
|
||||||
DatabaseQuery databaseQuery = new DatabaseQuery(sql, ps -> ps.setString(1, uuid.toString()));
|
DatabaseQuery databaseQuery = new DatabaseQuery(sql, ps -> ps.setString(1, uuid.toString()));
|
||||||
try (ResultSet resultSet = databaseQuery.executeQuery(getDatabaseConnection().get())) {
|
try (ResultSet resultSet = databaseQuery.execute(getDatabaseConnection().get())) {
|
||||||
if (!resultSet.next()) {
|
if (!resultSet.next()) {
|
||||||
return null; // user is not in the db
|
return null; // user is not in the db
|
||||||
}
|
}
|
||||||
return new EssentiaUser.Builder()
|
return new EssentiaUser.Builder()
|
||||||
.uuid(uuid)
|
.uuid(UUID.fromString(resultSet.getString("id")))
|
||||||
.backLocation(locationStringToLocation(resultSet.getString("BackLocation")))
|
|
||||||
.deathLocation(locationStringToLocation(resultSet.getString("DeathLocation")))
|
|
||||||
.homes(loadHomes(uuid))
|
|
||||||
.userSettings(new EssentiaUserSettings
|
|
||||||
.Builder()
|
|
||||||
//.allowTeleports(resultSet.getBoolean("TeleportToggled")) // FIXME
|
|
||||||
.build())
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
|
@ -150,48 +137,11 @@ public class SQLStorageProvider extends StorageProvider {
|
||||||
return null;
|
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
|
@Override
|
||||||
public void save(@NotNull EssentiaUser user) throws Exception {
|
public void save(@NotNull User user) throws Exception {
|
||||||
// Todo - use reflection to go over the fields to save?
|
String sql = "INSERT INTO users WHERE uuid = ?"; // upsert query
|
||||||
// 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(
|
addDatabaseQuery(
|
||||||
new DatabaseQuery(sql, new DatabaseQuery.DatabaseTask() {
|
new DatabaseQuery(sql, ps -> ps.setString(1, user.getUUID().toString())), true
|
||||||
@Override
|
|
||||||
public void edit(PreparedStatement ps) throws SQLException {
|
|
||||||
ps.setString(1, user.getUUID().toString());
|
|
||||||
ps.setString(2, user.getUUID().toString());
|
|
||||||
}
|
|
||||||
}), true
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,44 +158,4 @@ public class SQLStorageProvider extends StorageProvider {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.alttd.essentia.storage.sqlite;
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
import com.alttd.essentia.EssentiaPlugin;
|
||||||
import com.alttd.essentia.storage.StorageProvider;
|
import com.alttd.essentia.storage.StorageProvider;
|
||||||
import com.alttd.essentia.user.EssentiaUser;
|
import com.alttd.essentia.user.EssentiaUser;
|
||||||
|
import com.alttd.essentia.user.User;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
@ -19,7 +20,7 @@ public class SQLiteStorageProvider extends StorageProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(@NotNull EssentiaUser user) throws Exception {
|
public void save(@NotNull User user) throws Exception {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
package com.alttd.essentia.storage.yaml;
|
package com.alttd.essentia.storage.yaml;
|
||||||
|
|
||||||
import com.alttd.essentia.EssentiaPlugin;
|
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.storage.StorageProvider;
|
||||||
import com.alttd.essentia.user.EssentiaUser;
|
import com.alttd.essentia.user.EssentiaUser;
|
||||||
|
import com.alttd.essentia.user.User;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
@ -39,26 +37,27 @@ public class YamlStorageProvider extends StorageProvider {
|
||||||
.backLocation(getStoredLocation(config,"teleports.back"))
|
.backLocation(getStoredLocation(config,"teleports.back"))
|
||||||
.deathLocation(getStoredLocation(config,"teleports.death"))
|
.deathLocation(getStoredLocation(config,"teleports.death"))
|
||||||
.homes(getHomeData(config))
|
.homes(getHomeData(config))
|
||||||
.userSettings(new EssentiaUserSettings
|
|
||||||
.Builder()
|
|
||||||
.allowTeleports(config.getBoolean("allow-teleports", true))
|
.allowTeleports(config.getBoolean("allow-teleports", true))
|
||||||
.build())
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save(@NotNull EssentiaUser user) throws Exception {
|
public void save(@NotNull User user) throws Exception {
|
||||||
|
if (user.saving()) return;
|
||||||
|
user.saving(true);
|
||||||
|
|
||||||
File configFile = new File(dataDirectory, user.getUUID() + ".yml");
|
File configFile = new File(dataDirectory, user.getUUID() + ".yml");
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
|
||||||
setStoredLocation(config, "teleports.back", user.getBackLocation(false));
|
setStoredLocation(config, "teleports.back", user.getBackLocation(false));
|
||||||
setStoredLocation(config, "teleports.death", user.getBackLocation(true));
|
setStoredLocation(config, "teleports.death", user.getBackLocation(true));
|
||||||
for (Map.Entry<String, Home> entry : user.getHomeData().entrySet()) {
|
for (Map.Entry<String, Location> entry : user.getHomeData().entrySet()) {
|
||||||
setStoredLocation(config, "home." + entry.getKey(), entry.getValue().location());
|
setStoredLocation(config, "home." + entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
config.set("allow-teleports", user.getUserSettings().allowTeleports());
|
config.set("allow-teleports", user.allowTeleports());
|
||||||
|
|
||||||
config.save(configFile);
|
config.save(configFile);
|
||||||
|
user.saving(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -96,14 +95,14 @@ public class YamlStorageProvider extends StorageProvider {
|
||||||
return new Location(world, x, y, z, yaw, pitch);
|
return new Location(world, x, y, z, yaw, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Home> getHomeData(YamlConfiguration config) {
|
public Map<String, Location> getHomeData(YamlConfiguration config) {
|
||||||
ConfigurationSection section = config.getConfigurationSection("home");
|
ConfigurationSection section = config.getConfigurationSection("home");
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Map<String, Home> map = new HashMap<>();
|
Map<String, Location> map = new HashMap<>();
|
||||||
for (String key : section.getValues(false).keySet()) {
|
for (String key : section.getValues(false).keySet()) {
|
||||||
map.put(key, new EssentiaHome(key, getStoredLocation(config, "home." + key)));
|
map.put(key, getStoredLocation(config, "home." + key));
|
||||||
}
|
}
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
package com.alttd.essentia.user;
|
package com.alttd.essentia.user;
|
||||||
|
|
||||||
import com.alttd.essentia.api.model.Home;
|
import com.alttd.essentia.request.Request;
|
||||||
import com.alttd.essentia.api.model.UserSettings;
|
import lombok.Getter;
|
||||||
import com.alttd.essentia.api.request.Request;
|
import lombok.Setter;
|
||||||
import com.alttd.essentia.api.user.User;
|
|
||||||
import com.alttd.essentia.model.EssentiaHome;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -16,19 +14,18 @@ public class EssentiaUser implements User {
|
||||||
|
|
||||||
protected Location backLocation;
|
protected Location backLocation;
|
||||||
protected Location deathLocation;
|
protected Location deathLocation;
|
||||||
protected Map<String, Home> homes;
|
protected Map<String, Location> homes;
|
||||||
protected UserSettings userSettings;
|
protected boolean allowTeleports;
|
||||||
protected Request request;
|
protected Request request;
|
||||||
|
|
||||||
private boolean saving;
|
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) {
|
private EssentiaUser(Builder builder) {
|
||||||
this.uuid = builder.uuid;
|
this.uuid = builder.uuid;
|
||||||
this.backLocation = builder.backLocation;
|
this.backLocation = builder.backLocation;
|
||||||
this.deathLocation = builder.deathLocation;
|
this.deathLocation = builder.deathLocation;
|
||||||
this.homes = builder.homes;
|
this.homes = builder.homes;
|
||||||
this.userSettings = builder.userSettings;
|
this.allowTeleports = builder.allowTeleports;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -48,7 +45,6 @@ public class EssentiaUser implements User {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
backLocation = location;
|
backLocation = location;
|
||||||
needsSaving = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -57,20 +53,18 @@ public class EssentiaUser implements User {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Home getHome(String name) {
|
public Location getHome(String name) {
|
||||||
return homes.get(name);
|
return homes.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setHome(String name, Location location) {
|
public void setHome(String name, Location location) {
|
||||||
homes.put(name, new EssentiaHome(name, location));
|
homes.put(name, location);
|
||||||
needsSaving = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeHome(String name) {
|
public void removeHome(String name) {
|
||||||
homes.remove(name);
|
homes.remove(name);
|
||||||
needsSaving = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -86,7 +80,7 @@ public class EssentiaUser implements User {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Home> getHomeData() {
|
public Map<String, Location> getHomeData() {
|
||||||
return homes;
|
return homes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,26 +90,25 @@ public class EssentiaUser implements User {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserSettings getUserSettings() {
|
public boolean allowTeleports() {
|
||||||
return userSettings;
|
return allowTeleports;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAllowTeleports(boolean allowTeleports) {
|
||||||
|
this.allowTeleports = allowTeleports;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean saving() {
|
public boolean saving() {
|
||||||
return saving;
|
return saving;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void saving(boolean saving) {
|
public void saving(boolean saving) {
|
||||||
this.saving = saving;
|
this.saving = saving;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean needsSaving() {
|
|
||||||
return needsSaving;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void needsSaving(boolean needsSaving) {
|
|
||||||
this.needsSaving = needsSaving;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Request request() {
|
public Request request() {
|
||||||
return request;
|
return request;
|
||||||
|
|
@ -131,8 +124,8 @@ public class EssentiaUser implements User {
|
||||||
protected UUID uuid;
|
protected UUID uuid;
|
||||||
protected Location backLocation = null;
|
protected Location backLocation = null;
|
||||||
protected Location deathLocation = null;
|
protected Location deathLocation = null;
|
||||||
protected Map<String, Home> homes = new HashMap<>();
|
protected Map<String, Location> homes = new HashMap<>();
|
||||||
protected UserSettings userSettings = null;
|
protected boolean allowTeleports;
|
||||||
|
|
||||||
public Builder uuid(UUID uuid) {
|
public Builder uuid(UUID uuid) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
|
|
@ -149,13 +142,13 @@ public class EssentiaUser implements User {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder homes(Map<String, Home> homes) {
|
public Builder homes(Map<String, Location> homes) {
|
||||||
this.homes = homes;
|
this.homes = homes;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder userSettings(UserSettings userSettings) {
|
public Builder allowTeleports(boolean allowTeleports) {
|
||||||
this.userSettings = userSettings;
|
this.allowTeleports = allowTeleports;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,5 @@
|
||||||
package com.alttd.essentia.user;
|
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 org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -12,14 +8,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class EssentiaUserManager implements UserManager {
|
public class EssentiaUserManager implements UserManager {
|
||||||
|
|
||||||
protected final EssentiaPlugin plugin;
|
|
||||||
|
|
||||||
private final Map<UUID, User> essentiaPlayers = new ConcurrentHashMap<>();
|
private final Map<UUID, User> essentiaPlayers = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public EssentiaUserManager(EssentiaPlugin plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User getUser(Player player) {
|
public User getUser(Player player) {
|
||||||
return getUser(player.getUniqueId());
|
return getUser(player.getUniqueId());
|
||||||
|
|
@ -57,24 +47,7 @@ public class EssentiaUserManager implements UserManager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User createNewUser(UUID uuid) {
|
public User createNewUser(UUID uuid) {
|
||||||
return new EssentiaUser.Builder().uuid(uuid).build();
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
@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