Compare commits
10 Commits
5ed4c32cc1
...
bbd4610fbe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbd4610fbe | ||
|
|
a7f14eb573 | ||
|
|
cf0bcefd06 | ||
|
|
fe83919200 | ||
|
|
5cc798c482 | ||
|
|
f6dd31ba33 | ||
|
|
d1872f6e95 | ||
|
|
bacc44b2b9 | ||
|
|
dacdacf68e | ||
|
|
2e2d370bc6 |
|
|
@ -1,4 +1,4 @@
|
|||
package com.alttd.essentia.events;
|
||||
package com.alttd.essentia.api.events;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
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,4 +1,4 @@
|
|||
package com.alttd.essentia.events;
|
||||
package com.alttd.essentia.api.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.alttd.essentia.events;
|
||||
package com.alttd.essentia.api.events;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.alttd.essentia.events;
|
||||
package com.alttd.essentia.api.events;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.alttd.essentia.events;
|
||||
package com.alttd.essentia.api.events;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.alttd.essentia.events;
|
||||
package com.alttd.essentia.api.events;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
10
api/src/main/java/com/alttd/essentia/api/model/Home.java
Normal file
10
api/src/main/java/com/alttd/essentia/api/model/Home.java
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package com.alttd.essentia.api.model;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public interface Home {
|
||||
|
||||
String name();
|
||||
|
||||
Location location();
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
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.request;
|
||||
package com.alttd.essentia.api.request;
|
||||
|
||||
public interface Request {
|
||||
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
package com.alttd.essentia.user;
|
||||
package com.alttd.essentia.api.user;
|
||||
|
||||
import com.alttd.essentia.request.Request;
|
||||
import com.alttd.essentia.api.model.Home;
|
||||
import com.alttd.essentia.api.model.UserSettings;
|
||||
import com.alttd.essentia.api.request.Request;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -19,7 +20,7 @@ public interface User {
|
|||
|
||||
boolean hasHome(String name);
|
||||
|
||||
Location getHome(String name);
|
||||
Home getHome(String name);
|
||||
|
||||
void setHome(String name, Location location);
|
||||
|
||||
|
|
@ -29,19 +30,11 @@ public interface User {
|
|||
|
||||
List<String> getMatchingHomeNames(String homeName);
|
||||
|
||||
Map<String, Location> getHomeData();
|
||||
Map<String, Home> getHomeData();
|
||||
|
||||
Set<String> getHomes();
|
||||
|
||||
boolean allowTeleports();
|
||||
|
||||
void setAllowTeleports(boolean allowTeleports);
|
||||
|
||||
@ApiStatus.Internal
|
||||
boolean saving();
|
||||
|
||||
@ApiStatus.Internal
|
||||
void saving(boolean saving);
|
||||
UserSettings getUserSettings();
|
||||
|
||||
Request request();
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.alttd.essentia.user;
|
||||
package com.alttd.essentia.api.user;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
@ -21,4 +21,6 @@ public interface UserManager {
|
|||
|
||||
User createNewUser(UUID uuid);
|
||||
|
||||
void saveAllUsers();
|
||||
|
||||
}
|
||||
|
|
@ -4,8 +4,11 @@ import com.alttd.essentia.commands.admin.*;
|
|||
import com.alttd.essentia.commands.player.*;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.listeners.PlayerListener;
|
||||
import com.alttd.essentia.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.UserManager;
|
||||
import com.alttd.essentia.api.user.UserManager;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
|
@ -18,6 +21,9 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
|||
@Getter
|
||||
private UserManager userManager;
|
||||
|
||||
@Getter
|
||||
private StorageProvider storageProvider;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
instance = this;
|
||||
|
|
@ -30,11 +36,14 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
|||
loadCommands();
|
||||
loadEventListeners();
|
||||
loadManagers();
|
||||
loadStorageProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getServer().getScheduler().cancelTasks(this);
|
||||
userManager().saveAllUsers();
|
||||
storageProvider().disable();
|
||||
}
|
||||
|
||||
public void loadConfiguration() {
|
||||
|
|
@ -69,7 +78,13 @@ public class EssentiaPlugin extends JavaPlugin implements EssentiaAPI {
|
|||
}
|
||||
|
||||
void loadManagers() {
|
||||
userManager = new EssentiaUserManager();
|
||||
userManager = new EssentiaUserManager(this);
|
||||
}
|
||||
|
||||
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.configuration.Config;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import java.util.stream.Collectors;
|
|||
public abstract class SubCommand implements TabExecutor {
|
||||
|
||||
protected EssentiaPlugin plugin;
|
||||
private final String name;
|
||||
protected final String name;
|
||||
private final String[] aliases;
|
||||
private final Map<String, SubCommand> subCommands = new LinkedHashMap<>();
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
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.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.events.EssentiaEvent;
|
||||
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||
import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.events.EssentiaEvent;
|
||||
import com.alttd.essentia.events.PlayerTeleportBackEvent;
|
||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||
import com.alttd.essentia.api.events.PlayerTeleportBackEvent;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.events.EssentiaEvent;
|
||||
import com.alttd.essentia.events.PlayerRemoveHomeEvent;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||
import com.alttd.essentia.api.events.PlayerRemoveHomeEvent;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
package com.alttd.essentia.commands.player;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.api.model.Home;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.events.EssentiaEvent;
|
||||
import com.alttd.essentia.events.PlayerTeleportHomeEvent;
|
||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||
import com.alttd.essentia.api.events.PlayerTeleportHomeEvent;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
|
|
@ -24,7 +25,7 @@ public class HomeCommand extends PlayerSubCommand {
|
|||
|
||||
@Override
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
String home = null;
|
||||
String home;
|
||||
if (args.length == 0) {
|
||||
int count = user.getHomeCount();
|
||||
if (count <= 1) {
|
||||
|
|
@ -47,8 +48,12 @@ public class HomeCommand extends PlayerSubCommand {
|
|||
// return true
|
||||
// }
|
||||
// }
|
||||
|
||||
Location homeLoc = user.getHome(home);
|
||||
Home essentiaHome = user.getHome(home);
|
||||
if (essentiaHome == null) {
|
||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
|
||||
return true;
|
||||
}
|
||||
Location homeLoc = essentiaHome.location();
|
||||
if (homeLoc == null) {
|
||||
player.sendRichMessage(Config.HOME_DOES_NOT_EXIST, Placeholder.parsed("home", home));
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.events.EssentiaEvent;
|
||||
import com.alttd.essentia.events.PlayerSetHomeEvent;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||
import com.alttd.essentia.api.events.PlayerSetHomeEvent;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.events.EssentiaEvent;
|
||||
import com.alttd.essentia.events.PlayerTeleportSpawnEvent;
|
||||
import com.alttd.essentia.api.events.EssentiaEvent;
|
||||
import com.alttd.essentia.api.events.PlayerTeleportSpawnEvent;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.request.EssentiaRequest;
|
||||
import com.alttd.essentia.request.Request;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.api.request.Request;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TeleportAcceptCommand extends PlayerSubCommand {
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.request.EssentiaRequest;
|
||||
import com.alttd.essentia.request.Request;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.api.request.Request;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TeleportDenyCommand extends PlayerSubCommand {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import com.alttd.essentia.EssentiaPlugin;
|
|||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.request.TeleportEssentiaRequest;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
@ -50,7 +50,7 @@ public class TeleportRequestCommand extends PlayerSubCommand {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (!targetUser.allowTeleports()) {
|
||||
if (!targetUser.getUserSettings().allowTeleports()) {
|
||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import com.alttd.essentia.EssentiaPlugin;
|
|||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.request.TeleportHereEssentiaRequest;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
@ -50,7 +50,7 @@ public class TeleportRequestHereCommand extends PlayerSubCommand {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (!targetUser.allowTeleports()) {
|
||||
if (!targetUser.getUserSettings().allowTeleports()) {
|
||||
player.sendRichMessage(Config.TELEPORT_TOGGLED_OFF, placeholders);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package com.alttd.essentia.commands.player;
|
|||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.commands.PlayerSubCommand;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
|
|
@ -17,9 +17,9 @@ public class TeleportToggleCommand extends PlayerSubCommand {
|
|||
|
||||
@Override
|
||||
protected boolean execute(Player player, User user, String... args) {
|
||||
user.setAllowTeleports(!user.allowTeleports());
|
||||
user.getUserSettings().allowTeleports(!user.getUserSettings().allowTeleports());
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(user.allowTeleports()))
|
||||
Placeholder.parsed("toggle", BooleanUtils.toStringOnOff(user.getUserSettings().allowTeleports()))
|
||||
);
|
||||
player.sendRichMessage(Config.TELEPORT_TOGGLE_SET, placeholders);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -187,6 +187,10 @@ public class Config {
|
|||
public static String FEED_SELF = "You just fed yourself.";
|
||||
public static String FEED_OTHER = "You have fed <target>.";
|
||||
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() {
|
||||
REQUEST_TIMED_OUT = getString("messages.request.time-out", REQUEST_TIMED_OUT);
|
||||
TELEPORT_ACCEPT_TARGET = getString("messages.request.teleport-accept-target", TELEPORT_ACCEPT_TARGET);
|
||||
|
|
@ -203,41 +207,44 @@ public class Config {
|
|||
|
||||
PLAYER_ONLY_COMMAND = getString("messages.command.player-only-command", PLAYER_ONLY_COMMAND);
|
||||
NO_PLAYER_SPECIFIED = getString("messages.command.no-player-specified", NO_PLAYER_SPECIFIED);
|
||||
PLAYER_NOT_FOUND = config.getString("messages.command.player-not-found", PLAYER_NOT_FOUND);
|
||||
PLAYER_NOT_ONLINE = config.getString("messages.command.player-not-online", PLAYER_NOT_ONLINE);
|
||||
COMMAND_NO_PERMISSION = config.getString("messages.command.no-permission", COMMAND_NO_PERMISSION);
|
||||
PLAYER_INVENTORY_CLEARED = config.getString("messages.command.clear-inventory.player-inventory-cleared", PLAYER_INVENTORY_CLEARED);
|
||||
INVENTORY_CLEARED_BY_OTHER = config.getString("messages.command.clear-inventory.inventory-clear-by-other", INVENTORY_CLEARED_BY_OTHER);
|
||||
INVENTORY_CLEARED = config.getString("messages.command.clear-inventory.inventory-cleared", INVENTORY_CLEARED);
|
||||
SPECIFY_HOME = config.getString("messages.command.home.specify-home", SPECIFY_HOME);
|
||||
HOME_NOT_SET = config.getString("messages.command.home.home-not-set", HOME_NOT_SET);
|
||||
HOME_DOES_NOT_EXIST = config.getString("messages.command.home.home-does-not-exist", HOME_DOES_NOT_EXIST);
|
||||
HOME_TELEPORT = config.getString("messages.command.home.home-teleport", HOME_TELEPORT);
|
||||
HOME_LIST = config.getString("messages.command.home.home-list", HOME_LIST);
|
||||
HOME_SET = config.getString("messages.command.home.home-set", HOME_SET);
|
||||
HOME_SET_MAX = config.getString("messages.command.home.home-set-max", HOME_SET_MAX);
|
||||
INVALID_HOME_NAME = config.getString("messages.command.home.invalid-home-name", INVALID_HOME_NAME);
|
||||
HOME_DELETED = config.getString("messages.command.home.invalid-home-name", HOME_DELETED);
|
||||
PLAYER_NOT_FOUND = getString("messages.command.player-not-found", PLAYER_NOT_FOUND);
|
||||
PLAYER_NOT_ONLINE = getString("messages.command.player-not-online", PLAYER_NOT_ONLINE);
|
||||
COMMAND_NO_PERMISSION = getString("messages.command.no-permission", COMMAND_NO_PERMISSION);
|
||||
PLAYER_INVENTORY_CLEARED = 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 = getString("messages.command.clear-inventory.inventory-cleared", INVENTORY_CLEARED);
|
||||
SPECIFY_HOME = getString("messages.command.home.specify-home", SPECIFY_HOME);
|
||||
HOME_NOT_SET = 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_TELEPORT = getString("messages.command.home.home-teleport", HOME_TELEPORT);
|
||||
HOME_LIST = getString("messages.command.home.home-list", HOME_LIST);
|
||||
HOME_SET = getString("messages.command.home.home-set", HOME_SET);
|
||||
HOME_SET_MAX = getString("messages.command.home.home-set-max", HOME_SET_MAX);
|
||||
INVALID_HOME_NAME = getString("messages.command.home.invalid-home-name", INVALID_HOME_NAME);
|
||||
HOME_DELETED = getString("messages.command.home.invalid-home-name", HOME_DELETED);
|
||||
|
||||
TOGGLED_FLIGHT_BY_OTHER = config.getString("messages.command.fly.toggled-by-other", TOGGLED_FLIGHT_BY_OTHER);
|
||||
TOGGLED_FLIGHT_PLAYER = config.getString("messages.command.fly.toggled-flight-other", TOGGLED_FLIGHT_PLAYER);
|
||||
TOGGLED_FLIGHT = config.getString("messages.command.fly.toggled-flight", TOGGLED_FLIGHT);
|
||||
NO_BACK_LOCATION = config.getString("messages.command.back.no-back-location", NO_BACK_LOCATION);
|
||||
TELEPORTING_BACK = config.getString("messages.command.back.teleporting-back", TELEPORTING_BACK);
|
||||
NO_DEATH_LOCATION = config.getString("messages.command.back.no-death-location", NO_DEATH_LOCATION);
|
||||
TELEPORTING_BACK_DEATH = config.getString("messages.command.back.teleporting-back-death", TELEPORTING_BACK_DEATH);
|
||||
BACK_DEATH_HINT = config.getString("messages.command.back.dback-hint", BACK_DEATH_HINT);
|
||||
GAMEMODE_SET = config.getString("messages.command.gamemode.gamemode-set", GAMEMODE_SET);
|
||||
GAMEMODE_SET_OTHER = config.getString("messages.command.gamemode.gamemode-set-other", GAMEMODE_SET_OTHER);
|
||||
GAMEMODE_SET_BY_OTHER = config.getString("messages.command.gamemode.gamemode-set-by-other", GAMEMODE_SET_BY_OTHER);
|
||||
HEAL_SELF = config.getString("messages.command.heal.heal-self", HEAL_SELF);
|
||||
HEAL_OTHER = config.getString("messages.command.heal.heal-other", HEAL_OTHER);
|
||||
HEAL_BY_OTHER = config.getString("messages.command.heal.heal-by-other", HEAL_BY_OTHER);
|
||||
FEED_SELF = config.getString("messages.command.feed.feed-self", FEED_SELF);
|
||||
FEED_OTHER = config.getString("messages.command.feed.feed-other", FEED_OTHER);
|
||||
FEED_BY_OTHER = config.getString("messages.command.feed.feed-by-other", FEED_BY_OTHER);
|
||||
TOGGLED_FLIGHT_BY_OTHER = 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 = getString("messages.command.fly.toggled-flight", TOGGLED_FLIGHT);
|
||||
NO_BACK_LOCATION = getString("messages.command.back.no-back-location", NO_BACK_LOCATION);
|
||||
TELEPORTING_BACK = getString("messages.command.back.teleporting-back", TELEPORTING_BACK);
|
||||
NO_DEATH_LOCATION = getString("messages.command.back.no-death-location", NO_DEATH_LOCATION);
|
||||
TELEPORTING_BACK_DEATH = getString("messages.command.back.teleporting-back-death", TELEPORTING_BACK_DEATH);
|
||||
BACK_DEATH_HINT = getString("messages.command.back.dback-hint", BACK_DEATH_HINT);
|
||||
GAMEMODE_SET = getString("messages.command.gamemode.gamemode-set", GAMEMODE_SET);
|
||||
GAMEMODE_SET_OTHER = 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);
|
||||
HEAL_SELF = getString("messages.command.heal.heal-self", HEAL_SELF);
|
||||
HEAL_OTHER = getString("messages.command.heal.heal-other", HEAL_OTHER);
|
||||
HEAL_BY_OTHER = getString("messages.command.heal.heal-by-other", HEAL_BY_OTHER);
|
||||
FEED_SELF = getString("messages.command.feed.feed-self", FEED_SELF);
|
||||
FEED_OTHER = getString("messages.command.feed.feed-other", FEED_OTHER);
|
||||
FEED_BY_OTHER = getString("messages.command.feed.feed-by-other", FEED_BY_OTHER);
|
||||
}
|
||||
|
||||
public static String STORAGE_TYPE = "mysql";
|
||||
public static boolean AUTO_SAVE = true;
|
||||
public static int AUTO_SAVE_DELAY = 60;
|
||||
public static String MYSQL_IP = "localhost";
|
||||
public static String MYSQL_PORT = "3306";
|
||||
public static String MYSQL_DATABASE_NAME = "essentia";
|
||||
|
|
@ -246,11 +253,14 @@ public class Config {
|
|||
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);
|
||||
STORAGE_TYPE = getString("storage.type", STORAGE_TYPE);
|
||||
AUTO_SAVE = getBoolean("storage.auto-save", AUTO_SAVE);
|
||||
AUTO_SAVE_DELAY = getInt("storaeg.auto-save-delay", AUTO_SAVE_DELAY);
|
||||
MYSQL_IP = getString("storage.mysql.ip", MYSQL_IP);
|
||||
MYSQL_PORT = getString("storage.mysql.port", MYSQL_PORT);
|
||||
MYSQL_DATABASE_NAME = getString("storage.mysql.database", MYSQL_DATABASE_NAME);
|
||||
MYSQL_USERNAME = getString("storage.mysql.username", MYSQL_USERNAME);
|
||||
MYSQL_PASSWORD = getString("storage.mysql.password", MYSQL_PASSWORD);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,16 @@ package com.alttd.essentia.listeners;
|
|||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.user.EssentiaUser;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.alttd.essentia.api.user.UserManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
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 java.util.HashSet;
|
||||
|
|
@ -15,7 +19,7 @@ import java.util.Set;
|
|||
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
private EssentiaPlugin plugin;
|
||||
private final EssentiaPlugin plugin;
|
||||
private final Set<PlayerTeleportEvent.TeleportCause> backAllowCauses = new HashSet<>();
|
||||
|
||||
public PlayerListener(EssentiaPlugin plugin) {
|
||||
|
|
@ -61,4 +65,29 @@ public class PlayerListener implements Listener {
|
|||
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) {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
package com.alttd.essentia.model;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public record EssentiaHome(String name, Location location) implements com.alttd.essentia.api.model.Home {}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
3
plugin/src/main/java/com/alttd/essentia/model/Kit.java
Normal file
3
plugin/src/main/java/com/alttd/essentia/model/Kit.java
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
package com.alttd.essentia.model;
|
||||
|
||||
public record Kit() {}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package com.alttd.essentia.model;
|
||||
|
||||
public record PlayerInventory() {
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.alttd.essentia.request;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.api.request.Request;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.tasks.RequestTimeout;
|
||||
import com.alttd.essentia.tasks.TeleportSounds;
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@ 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 {
|
||||
public class StorageManager {
|
||||
|
||||
protected final EssentiaPlugin plugin;
|
||||
|
||||
|
|
@ -19,7 +18,7 @@ public abstract class StorageManager {
|
|||
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
|
||||
case SQLITE -> throw new UnsupportedOperationException(); // FIXME
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
package com.alttd.essentia.storage;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.api.events.EssentiaUserLoadEvent;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.user.EssentiaUser;
|
||||
import com.alttd.essentia.user.User;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
@ -11,22 +15,61 @@ public abstract class StorageProvider {
|
|||
|
||||
protected final EssentiaPlugin plugin;
|
||||
|
||||
@Getter
|
||||
private AutoSaveTask autoSaveTask;
|
||||
|
||||
public StorageProvider(EssentiaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public EssentiaUser loadUser(UUID uuid) {
|
||||
EssentiaUser user = load(uuid);
|
||||
public User loadUser(UUID uuid) {
|
||||
User user = load(uuid);
|
||||
|
||||
if (user == null) {
|
||||
user = plugin.userManager().createNewUser(uuid);
|
||||
}
|
||||
|
||||
plugin.userManager().addUser(user);
|
||||
|
||||
// TODO -- UserLoadEvent?
|
||||
new EssentiaUserLoadEvent(user).callEvent();
|
||||
return user;
|
||||
}
|
||||
|
||||
public void startAutoSaving() {
|
||||
if (!Config.AUTO_SAVE)
|
||||
return;
|
||||
|
||||
autoSaveTask = new AutoSaveTask();
|
||||
int delay = Config.AUTO_SAVE_DELAY * 20;
|
||||
autoSaveTask.runTaskTimerAsynchronously(plugin, delay, delay);
|
||||
}
|
||||
|
||||
public void disable() {
|
||||
// Override if some extra steps are required when disabling the plugin.
|
||||
}
|
||||
|
||||
protected abstract EssentiaUser load(UUID uuid);
|
||||
|
||||
public abstract void save(@NotNull User user) throws Exception;
|
||||
public void startSaving(EssentiaUser user) throws Exception {
|
||||
if (user.saving() || !user.needsSaving()) return;
|
||||
user.saving(true);
|
||||
|
||||
save(user);
|
||||
|
||||
user.saving(false);
|
||||
user.needsSaving(false);
|
||||
}
|
||||
|
||||
public abstract void save(@NotNull EssentiaUser user) throws Exception;
|
||||
|
||||
public abstract void delete(UUID uuid) throws Exception;
|
||||
|
||||
private class AutoSaveTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
plugin.userManager().saveAllUsers();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class DatabaseQuery {
|
|||
this(statement, ps -> {});
|
||||
}
|
||||
|
||||
public ResultSet execute(Connection connection) {
|
||||
public ResultSet executeQuery(Connection connection) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(statement)) {
|
||||
databaseTask.edit(preparedStatement);
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
|
|
@ -31,12 +31,24 @@ public class DatabaseQuery {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void execute(Connection connection) {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(statement)) {
|
||||
databaseTask.edit(preparedStatement);
|
||||
preparedStatement.execute();
|
||||
databaseTask.onSuccess();
|
||||
} catch (SQLException e) {
|
||||
databaseTask.onFailure(e);
|
||||
}
|
||||
}
|
||||
|
||||
public interface DatabaseTask {
|
||||
|
||||
void edit(PreparedStatement preparedStatement) throws SQLException;
|
||||
|
||||
default void onSuccess(ResultSet resultSet) throws SQLException {};
|
||||
|
||||
default void onSuccess() throws SQLException {};
|
||||
|
||||
default void onFailure(SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,17 +2,20 @@ package com.alttd.essentia.storage.mysql;
|
|||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.configuration.Config;
|
||||
import com.alttd.essentia.api.model.Home;
|
||||
import com.alttd.essentia.model.EssentiaHome;
|
||||
import com.alttd.essentia.model.EssentiaUserSettings;
|
||||
import com.alttd.essentia.storage.StorageProvider;
|
||||
import com.alttd.essentia.user.EssentiaUser;
|
||||
import com.alttd.essentia.user.User;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class SQLStorageProvider extends StorageProvider {
|
||||
|
||||
|
|
@ -34,10 +37,27 @@ public class SQLStorageProvider extends StorageProvider {
|
|||
private void createTables() {
|
||||
// TODO -- create table
|
||||
String userTable = "CREATE TABLE IF NOT EXISTS users(" +
|
||||
"id VARCHAR(36) NOT NULL, " +
|
||||
"PRIMARY KEY (id)" +
|
||||
"UUID VARCHAR(36) NOT NULL, " +
|
||||
"DeathLocation mediumtext DEFAULT NULL, " +
|
||||
"BackLocation mediumtext DEFAULT NULL, " +
|
||||
"TeleportToggled tinyint(1) DEFAULT NULL, " +
|
||||
"PRIMARY KEY (uuid)" +
|
||||
")";
|
||||
String homeTable = "CREATE TABLE IF NOT EXISTS homes(" +
|
||||
"UUID VARCHAR(36) NOT NULL, " +
|
||||
"Name mediumtext DEFAULT NULL, " +
|
||||
"HomeLocation mediumtext DEFAULT NULL, "+
|
||||
")";
|
||||
String settingsTable = "CREATE TABLE IF NOT EXISTS homes(" +
|
||||
"UUID VARCHAR(36) NOT NULL, " +
|
||||
"TeleportToggled tinyint(1) DEFAULT NULL, " +
|
||||
"GodMode tinyint(1) DEFAULT NULL, " +
|
||||
"Flying tinyint(1) DEFAULT NULL, " +
|
||||
"PRIMARY KEY (uuid)" +
|
||||
")";
|
||||
addDatabaseQuery(new DatabaseQuery(userTable), false);
|
||||
addDatabaseQuery(new DatabaseQuery(homeTable), false);
|
||||
addDatabaseQuery(new DatabaseQuery(settingsTable), false);
|
||||
}
|
||||
|
||||
public DatabaseConnection getDatabaseConnection() {
|
||||
|
|
@ -87,7 +107,8 @@ public class SQLStorageProvider extends StorageProvider {
|
|||
}
|
||||
}
|
||||
|
||||
public void unload() {
|
||||
@Override
|
||||
public void disable() {
|
||||
if (databaseQueue != null && !databaseQueue.isCancelled()) {
|
||||
databaseQueue.cancel();
|
||||
databaseQueue.runTaskQueue();
|
||||
|
|
@ -103,32 +124,24 @@ public class SQLStorageProvider extends StorageProvider {
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// TODO -- make this async
|
||||
@Override
|
||||
protected EssentiaUser load(UUID uuid) {
|
||||
String sql = "SELECT * FROM users WHERE uuid = ?";
|
||||
DatabaseQuery databaseQuery = new DatabaseQuery(sql, ps -> ps.setString(1, uuid.toString()));
|
||||
try (ResultSet resultSet = databaseQuery.execute(getDatabaseConnection().get())) {
|
||||
try (ResultSet resultSet = databaseQuery.executeQuery(getDatabaseConnection().get())) {
|
||||
if (!resultSet.next()) {
|
||||
return null; // user is not in the db
|
||||
}
|
||||
return new EssentiaUser.Builder()
|
||||
.uuid(UUID.fromString(resultSet.getString("id")))
|
||||
.uuid(uuid)
|
||||
.backLocation(locationStringToLocation(resultSet.getString("BackLocation")))
|
||||
.deathLocation(locationStringToLocation(resultSet.getString("DeathLocation")))
|
||||
.homes(loadHomes(uuid))
|
||||
.userSettings(new EssentiaUserSettings
|
||||
.Builder()
|
||||
//.allowTeleports(resultSet.getBoolean("TeleportToggled")) // FIXME
|
||||
.build())
|
||||
.build();
|
||||
|
||||
} catch (SQLException e) {
|
||||
|
|
@ -137,11 +150,48 @@ public class SQLStorageProvider extends StorageProvider {
|
|||
return null;
|
||||
}
|
||||
|
||||
private Map<String, Home> loadHomes(UUID uuid) {
|
||||
String sql = "SELECT * FROM homes WHERE uuid = ?";
|
||||
Map<String, Home> locationMap = new HashMap<>();
|
||||
DatabaseQuery databaseQuery = new DatabaseQuery(sql, ps -> ps.setString(1, uuid.toString()));
|
||||
try (ResultSet resultSet = databaseQuery.executeQuery(getDatabaseConnection().get())) {
|
||||
if (!resultSet.next()) {
|
||||
return locationMap;
|
||||
}
|
||||
String homeName = resultSet.getString("Name");
|
||||
while (resultSet.next()) {
|
||||
locationMap.put(
|
||||
homeName,
|
||||
new EssentiaHome(
|
||||
homeName,
|
||||
locationStringToLocation(resultSet.getString("HomeLocation"))
|
||||
)
|
||||
);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
// catch this nicely
|
||||
}
|
||||
return locationMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(@NotNull User user) throws Exception {
|
||||
String sql = "INSERT INTO users WHERE uuid = ?"; // upsert query
|
||||
public void save(@NotNull EssentiaUser user) throws Exception {
|
||||
// Todo - use reflection to go over the fields to save?
|
||||
// might not be the best way if new fields are added...
|
||||
// split into multiple tables - users, userdata, userhomes, ... ?
|
||||
String sql = "INSERT INTO users" +
|
||||
"(uuid)" + // columns
|
||||
"VALUES (?)" + // data
|
||||
"ON DUPLICATE KEY UPDATE " + // data
|
||||
"uuid = ?";
|
||||
addDatabaseQuery(
|
||||
new DatabaseQuery(sql, ps -> ps.setString(1, user.getUUID().toString())), true
|
||||
new DatabaseQuery(sql, new DatabaseQuery.DatabaseTask() {
|
||||
@Override
|
||||
public void edit(PreparedStatement ps) throws SQLException {
|
||||
ps.setString(1, user.getUUID().toString());
|
||||
ps.setString(2, user.getUUID().toString());
|
||||
}
|
||||
}), true
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -158,4 +208,44 @@ 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,7 +3,6 @@ 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;
|
||||
|
|
@ -20,7 +19,7 @@ public class SQLiteStorageProvider extends StorageProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void save(@NotNull User user) throws Exception {
|
||||
public void save(@NotNull EssentiaUser user) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package com.alttd.essentia.storage.yaml;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.api.model.Home;
|
||||
import com.alttd.essentia.model.EssentiaHome;
|
||||
import com.alttd.essentia.model.EssentiaUserSettings;
|
||||
import com.alttd.essentia.storage.StorageProvider;
|
||||
import com.alttd.essentia.user.EssentiaUser;
|
||||
import com.alttd.essentia.user.User;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
|
@ -37,27 +39,26 @@ public class YamlStorageProvider extends StorageProvider {
|
|||
.backLocation(getStoredLocation(config,"teleports.back"))
|
||||
.deathLocation(getStoredLocation(config,"teleports.death"))
|
||||
.homes(getHomeData(config))
|
||||
.allowTeleports(config.getBoolean("allow-teleports", true))
|
||||
.userSettings(new EssentiaUserSettings
|
||||
.Builder()
|
||||
.allowTeleports(config.getBoolean("allow-teleports", true))
|
||||
.build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(@NotNull User user) throws Exception {
|
||||
if (user.saving()) return;
|
||||
user.saving(true);
|
||||
|
||||
public void save(@NotNull EssentiaUser user) throws Exception {
|
||||
File configFile = new File(dataDirectory, user.getUUID() + ".yml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
setStoredLocation(config, "teleports.back", user.getBackLocation(false));
|
||||
setStoredLocation(config, "teleports.death", user.getBackLocation(true));
|
||||
for (Map.Entry<String, Location> entry : user.getHomeData().entrySet()) {
|
||||
setStoredLocation(config, "home." + entry.getKey(), entry.getValue());
|
||||
for (Map.Entry<String, Home> entry : user.getHomeData().entrySet()) {
|
||||
setStoredLocation(config, "home." + entry.getKey(), entry.getValue().location());
|
||||
}
|
||||
config.set("allow-teleports", user.allowTeleports());
|
||||
config.set("allow-teleports", user.getUserSettings().allowTeleports());
|
||||
|
||||
config.save(configFile);
|
||||
user.saving(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -95,14 +96,14 @@ public class YamlStorageProvider extends StorageProvider {
|
|||
return new Location(world, x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
public Map<String, Location> getHomeData(YamlConfiguration config) {
|
||||
public Map<String, Home> getHomeData(YamlConfiguration config) {
|
||||
ConfigurationSection section = config.getConfigurationSection("home");
|
||||
if (section == null) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Location> map = new HashMap<>();
|
||||
Map<String, Home> map = new HashMap<>();
|
||||
for (String key : section.getValues(false).keySet()) {
|
||||
map.put(key, getStoredLocation(config, "home." + key));
|
||||
map.put(key, new EssentiaHome(key, getStoredLocation(config, "home." + key)));
|
||||
}
|
||||
|
||||
return map;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package com.alttd.essentia.user;
|
||||
|
||||
import com.alttd.essentia.request.Request;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import com.alttd.essentia.api.model.Home;
|
||||
import com.alttd.essentia.api.model.UserSettings;
|
||||
import com.alttd.essentia.api.request.Request;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.alttd.essentia.model.EssentiaHome;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.*;
|
||||
|
|
@ -14,18 +16,19 @@ public class EssentiaUser implements User {
|
|||
|
||||
protected Location backLocation;
|
||||
protected Location deathLocation;
|
||||
protected Map<String, Location> homes;
|
||||
protected boolean allowTeleports;
|
||||
protected Map<String, Home> homes;
|
||||
protected UserSettings userSettings;
|
||||
protected Request request;
|
||||
|
||||
private boolean saving;
|
||||
private boolean needsSaving; // can we use a decorator for this to set it to true on every change?
|
||||
|
||||
private EssentiaUser(Builder builder) {
|
||||
this.uuid = builder.uuid;
|
||||
this.backLocation = builder.backLocation;
|
||||
this.deathLocation = builder.deathLocation;
|
||||
this.homes = builder.homes;
|
||||
this.allowTeleports = builder.allowTeleports;
|
||||
this.userSettings = builder.userSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -45,6 +48,7 @@ public class EssentiaUser implements User {
|
|||
return;
|
||||
}
|
||||
backLocation = location;
|
||||
needsSaving = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -53,18 +57,20 @@ public class EssentiaUser implements User {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Location getHome(String name) {
|
||||
public Home getHome(String name) {
|
||||
return homes.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHome(String name, Location location) {
|
||||
homes.put(name, location);
|
||||
homes.put(name, new EssentiaHome(name, location));
|
||||
needsSaving = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeHome(String name) {
|
||||
homes.remove(name);
|
||||
needsSaving = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -80,7 +86,7 @@ public class EssentiaUser implements User {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Location> getHomeData() {
|
||||
public Map<String, Home> getHomeData() {
|
||||
return homes;
|
||||
}
|
||||
|
||||
|
|
@ -90,25 +96,26 @@ public class EssentiaUser implements User {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean allowTeleports() {
|
||||
return allowTeleports;
|
||||
public UserSettings getUserSettings() {
|
||||
return userSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAllowTeleports(boolean allowTeleports) {
|
||||
this.allowTeleports = allowTeleports;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saving() {
|
||||
return saving;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saving(boolean saving) {
|
||||
this.saving = saving;
|
||||
}
|
||||
|
||||
public boolean needsSaving() {
|
||||
return needsSaving;
|
||||
}
|
||||
|
||||
public void needsSaving(boolean needsSaving) {
|
||||
this.needsSaving = needsSaving;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request request() {
|
||||
return request;
|
||||
|
|
@ -124,8 +131,8 @@ public class EssentiaUser implements User {
|
|||
protected UUID uuid;
|
||||
protected Location backLocation = null;
|
||||
protected Location deathLocation = null;
|
||||
protected Map<String, Location> homes = new HashMap<>();
|
||||
protected boolean allowTeleports;
|
||||
protected Map<String, Home> homes = new HashMap<>();
|
||||
protected UserSettings userSettings = null;
|
||||
|
||||
public Builder uuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
|
|
@ -142,13 +149,13 @@ public class EssentiaUser implements User {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder homes(Map<String, Location> homes) {
|
||||
public Builder homes(Map<String, Home> homes) {
|
||||
this.homes = homes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder allowTeleports(boolean allowTeleports) {
|
||||
this.allowTeleports = allowTeleports;
|
||||
public Builder userSettings(UserSettings userSettings) {
|
||||
this.userSettings = userSettings;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
package com.alttd.essentia.user;
|
||||
|
||||
import com.alttd.essentia.EssentiaPlugin;
|
||||
import com.alttd.essentia.api.user.User;
|
||||
import com.alttd.essentia.api.user.UserManager;
|
||||
import com.alttd.essentia.model.EssentiaUserSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
|
@ -8,8 +12,14 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
public class EssentiaUserManager implements UserManager {
|
||||
|
||||
protected final EssentiaPlugin plugin;
|
||||
|
||||
private final Map<UUID, User> essentiaPlayers = new ConcurrentHashMap<>();
|
||||
|
||||
public EssentiaUserManager(EssentiaPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser(Player player) {
|
||||
return getUser(player.getUniqueId());
|
||||
|
|
@ -47,7 +57,24 @@ public class EssentiaUserManager implements UserManager {
|
|||
|
||||
@Override
|
||||
public User createNewUser(UUID uuid) {
|
||||
return null;
|
||||
return new EssentiaUser.Builder().uuid(uuid).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAllUsers() {
|
||||
for (User user : getUsers().values()) {
|
||||
if (user instanceof EssentiaUser essentiaUser && essentiaUser.getUserSettings() instanceof EssentiaUserSettings essentiaUserSettings) {
|
||||
try {
|
||||
if (essentiaUser.saving() || !essentiaUser.needsSaving() || !essentiaUserSettings.needsSaving()) {
|
||||
continue;
|
||||
}
|
||||
plugin.storageProvider().startSaving(essentiaUser);
|
||||
} catch(Exception e){
|
||||
essentiaUser.saving(false);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user