mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
refactor: significantly refactor internals, remove Sponge (#708)
* feat: start database refactor Adds database migrations * refactor: refactor database system Now supports migrations * refactor: begin major internals rewrite move to using provider-style interfaces similar to huskclaims bukkit done, still need to do fabric and sponge * refactor: remove sponge, checkstyle Low usage and high maintenance time cost. We will examine Forge instead in the future. * refactor: implement refactoring changes on fabric also fix various refactor quirks on Bukkit * refactor: tidy metrics logic * build: bump deps
This commit is contained in:
1 parent
05bcad9249
commit
ffe995ef5f
162 files changed
+3890
-5730
No files matched your search
@@ -19,13 +19,14 @@
|
||||
|
||||
package net.william278.huskhomes;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.platform.AudienceProvider;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.william278.desertwell.util.Version;
|
||||
import net.william278.huskhomes.api.HuskHomesAPI;
|
||||
@@ -35,31 +36,23 @@ import net.william278.huskhomes.config.Locales;
|
||||
import net.william278.huskhomes.config.Server;
|
||||
import net.william278.huskhomes.config.Settings;
|
||||
import net.william278.huskhomes.config.Spawn;
|
||||
import net.william278.huskhomes.database.*;
|
||||
import net.william278.huskhomes.database.Database;
|
||||
import net.william278.huskhomes.event.BukkitEventDispatcher;
|
||||
import net.william278.huskhomes.hook.BukkitHookProvider;
|
||||
import net.william278.huskhomes.hook.Hook;
|
||||
import net.william278.huskhomes.hook.PlaceholderAPIHook;
|
||||
import net.william278.huskhomes.hook.VaultEconomyHook;
|
||||
import net.william278.huskhomes.importer.EssentialsXImporter;
|
||||
import net.william278.huskhomes.listener.BukkitEventListener;
|
||||
import net.william278.huskhomes.listener.EventListener;
|
||||
import net.william278.huskhomes.manager.Manager;
|
||||
import net.william278.huskhomes.network.Broker;
|
||||
import net.william278.huskhomes.network.PluginMessageBroker;
|
||||
import net.william278.huskhomes.network.RedisBroker;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.position.World;
|
||||
import net.william278.huskhomes.random.NormalDistributionEngine;
|
||||
import net.william278.huskhomes.random.RandomTeleportEngine;
|
||||
import net.william278.huskhomes.user.BukkitUser;
|
||||
import net.william278.huskhomes.user.ConsoleUser;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.user.SavedUser;
|
||||
import net.william278.huskhomes.util.BukkitSafetyResolver;
|
||||
import net.william278.huskhomes.user.*;
|
||||
import net.william278.huskhomes.util.BukkitSavePositionProvider;
|
||||
import net.william278.huskhomes.util.BukkitTask;
|
||||
import net.william278.huskhomes.util.UnsafeBlocks;
|
||||
import net.william278.huskhomes.util.Validator;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -72,7 +65,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import space.arim.morepaperlib.MorePaperLib;
|
||||
import space.arim.morepaperlib.commands.CommandRegistration;
|
||||
import space.arim.morepaperlib.scheduling.AsynchronousScheduler;
|
||||
import space.arim.morepaperlib.scheduling.AttachedScheduler;
|
||||
import space.arim.morepaperlib.scheduling.GracefulScheduling;
|
||||
@@ -82,45 +74,48 @@ import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask.Supplier, BukkitEventDispatcher,
|
||||
PluginMessageListener, BukkitSafetyResolver {
|
||||
PluginMessageListener, BukkitHookProvider, BukkitSavePositionProvider, BukkitUserProvider {
|
||||
|
||||
/**
|
||||
* Metrics ID for <a href="https://bstats.org/plugin/bukkit/HuskHomes/8430">HuskHomes on Bukkit</a>.
|
||||
*/
|
||||
private static final int METRICS_ID = 8430;
|
||||
|
||||
private final Set<SavedUser> savedUsers = Sets.newHashSet();
|
||||
private final Map<String, List<String>> globalPlayerList = Maps.newConcurrentMap();
|
||||
private final Set<UUID> currentlyOnWarmup = Sets.newConcurrentHashSet();
|
||||
private final Set<UUID> currentlyInvulnerable = Sets.newConcurrentHashSet();
|
||||
|
||||
private Settings settings;
|
||||
private Locales locales;
|
||||
private Database database;
|
||||
private Validator validator;
|
||||
private Manager manager;
|
||||
private EventListener eventListener;
|
||||
private RandomTeleportEngine randomTeleportEngine;
|
||||
private Spawn serverSpawn;
|
||||
private UnsafeBlocks unsafeBlocks;
|
||||
private List<Hook> hooks;
|
||||
private List<Command> commands;
|
||||
@Getter(AccessLevel.NONE)
|
||||
private Server server;
|
||||
@Getter(AccessLevel.NONE)
|
||||
private BukkitAudiences audiences;
|
||||
@Getter(AccessLevel.NONE)
|
||||
private MorePaperLib paperLib;
|
||||
private AudienceProvider audiences;
|
||||
private AsynchronousScheduler asyncScheduler;
|
||||
private RegionalScheduler regionalScheduler;
|
||||
private MorePaperLib morePaperLib;
|
||||
|
||||
private final Set<SavedUser> savedUsers = Sets.newHashSet();
|
||||
private final Set<UUID> currentlyOnWarmup = Sets.newConcurrentHashSet();
|
||||
private final Set<UUID> currentlyInvulnerable = Sets.newConcurrentHashSet();
|
||||
private final Map<UUID, OnlineUser> onlineUserMap = Maps.newHashMap();
|
||||
private final Map<String, List<User>> globalUserList = Maps.newConcurrentMap();
|
||||
private final List<Command> commands = Lists.newArrayList();
|
||||
|
||||
@Setter
|
||||
private Set<Hook> hooks = Sets.newHashSet();
|
||||
@Setter
|
||||
private Settings settings;
|
||||
@Setter
|
||||
private Locales locales;
|
||||
@Setter
|
||||
private Database database;
|
||||
@Setter
|
||||
private Manager manager;
|
||||
@Setter
|
||||
private EventListener eventListener;
|
||||
@Setter
|
||||
private RandomTeleportEngine randomTeleportEngine;
|
||||
@Setter
|
||||
private Spawn serverSpawn;
|
||||
@Setter
|
||||
private UnsafeBlocks unsafeBlocks;
|
||||
@Setter
|
||||
@Nullable
|
||||
private Broker broker;
|
||||
@Setter
|
||||
@Nullable
|
||||
private Server serverName;
|
||||
|
||||
// Super constructor for unit testing
|
||||
@TestOnly
|
||||
@@ -129,130 +124,105 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
super(loader, description, dataFolder, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
this.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Create adventure audience
|
||||
this.audiences = BukkitAudiences.create(this);
|
||||
this.paperLib = new MorePaperLib(this);
|
||||
this.validator = new Validator(this);
|
||||
|
||||
// Load settings and locales
|
||||
initialize("plugin config & locale files", (plugin) -> loadConfigs());
|
||||
|
||||
// Initialize the database
|
||||
final Database.Type type = getSettings().getDatabase().getType();
|
||||
initialize(type.getDisplayName() + " database connection", (plugin) -> {
|
||||
this.database = switch (type) {
|
||||
case MYSQL, MARIADB -> new MySqlDatabase(this);
|
||||
case SQLITE -> new SqLiteDatabase(this);
|
||||
case H2 -> new H2Database(this);
|
||||
case POSTGRESQL -> new PostgreSqlDatabase(this);
|
||||
};
|
||||
|
||||
database.initialize();
|
||||
});
|
||||
|
||||
// Initialize the manager
|
||||
this.manager = new Manager(this);
|
||||
|
||||
// Initialize the network messenger if proxy mode is enabled
|
||||
final Settings.CrossServerSettings crossServer = getSettings().getCrossServer();
|
||||
if (crossServer.isEnabled()) {
|
||||
initialize(crossServer.getBrokerType().getDisplayName() + " message broker", (plugin) -> {
|
||||
broker = switch (crossServer.getBrokerType()) {
|
||||
case PLUGIN_MESSAGE -> new PluginMessageBroker(this);
|
||||
case REDIS -> new RedisBroker(this);
|
||||
};
|
||||
broker.initialize();
|
||||
});
|
||||
}
|
||||
|
||||
// Set the random teleport engine
|
||||
setRandomTeleportEngine(new NormalDistributionEngine(this));
|
||||
|
||||
// Register plugin hooks (Economy, Maps, Plan)
|
||||
initialize("hooks", (plugin) -> {
|
||||
this.registerHooks();
|
||||
|
||||
if (!hooks.isEmpty()) {
|
||||
hooks.forEach(hook -> {
|
||||
try {
|
||||
hook.initialize();
|
||||
} catch (Throwable e) {
|
||||
log(Level.WARNING, "Failed to initialize " + hook.getName() + " hook", e);
|
||||
}
|
||||
});
|
||||
log(Level.INFO, "Registered " + hooks.size() + " plugin hooks: " + hooks.stream()
|
||||
.map(Hook::getName)
|
||||
.collect(Collectors.joining(", ")));
|
||||
}
|
||||
});
|
||||
|
||||
// Register event listener
|
||||
initialize("events", (plugin) -> this.eventListener = getListener().register(this));
|
||||
|
||||
// Register commands
|
||||
initialize("commands", (plugin) -> this.commands = BukkitCommand.Type.getCommands(this));
|
||||
|
||||
// Initialize the API
|
||||
initialize("API", (plugin) -> HuskHomesAPI.register(this));
|
||||
|
||||
// Hook into bStats and check for updates
|
||||
initialize("metrics", (plugin) -> this.registerMetrics(METRICS_ID));
|
||||
this.checkForUpdates();
|
||||
}
|
||||
|
||||
// Register the event listener
|
||||
@NotNull
|
||||
protected BukkitEventListener getListener() {
|
||||
return new BukkitEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerHooks() {
|
||||
HuskHomes.super.registerHooks();
|
||||
|
||||
// Hooks
|
||||
if (getSettings().getEconomy().isEnabled() && isDependencyLoaded("Vault")) {
|
||||
getHooks().add(new VaultEconomyHook(this));
|
||||
}
|
||||
if (isDependencyLoaded("PlaceholderAPI")) {
|
||||
getHooks().add(new PlaceholderAPIHook(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerImporters() {
|
||||
HuskHomes.super.registerImporters();
|
||||
|
||||
// Importers
|
||||
if (isDependencyLoaded("Essentials")) {
|
||||
getHooks().add(new EssentialsXImporter(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDependencyLoaded(@NotNull String name) {
|
||||
return Bukkit.getPluginManager().getPlugin(name) != null;
|
||||
this.morePaperLib = new MorePaperLib(this);
|
||||
this.enable();
|
||||
this.loadCommands();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
HuskHomesAPI.unregister();
|
||||
if (this.eventListener != null) {
|
||||
this.eventListener.handlePluginDisable();
|
||||
this.shutdown();
|
||||
if (this.audiences != null) {
|
||||
this.audiences.close();
|
||||
}
|
||||
if (database != null) {
|
||||
database.terminate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAPI() {
|
||||
HuskHomesAPI.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMetrics() {
|
||||
try {
|
||||
final Metrics metrics = new Metrics(this, BSTATS_BUKKIT_PLUGIN_ID);
|
||||
metrics.addCustomChart(new SimplePie("bungee_mode",
|
||||
() -> Boolean.toString(getSettings().getCrossServer().isEnabled()))
|
||||
);
|
||||
metrics.addCustomChart(new SimplePie("language",
|
||||
() -> getSettings().getLanguage().toLowerCase())
|
||||
);
|
||||
metrics.addCustomChart(new SimplePie("database_type",
|
||||
() -> getSettings().getDatabase().getType().getDisplayName())
|
||||
);
|
||||
metrics.addCustomChart(new SimplePie("using_economy",
|
||||
() -> Boolean.toString(getSettings().getEconomy().isEnabled()))
|
||||
);
|
||||
metrics.addCustomChart(new SimplePie("using_map",
|
||||
() -> Boolean.toString(getSettings().getMapHook().isEnabled()))
|
||||
);
|
||||
getBroker().ifPresent(broker -> metrics.addCustomChart(new SimplePie("messenger_type",
|
||||
() -> settings.getCrossServer().getBrokerType().getDisplayName()
|
||||
)));
|
||||
} catch (Throwable e) {
|
||||
log(Level.WARNING, "Failed to register plugin metrics", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Register the event listener
|
||||
@Override
|
||||
@NotNull
|
||||
public BukkitEventListener createListener() {
|
||||
return new BukkitEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disablePlugin() {
|
||||
log(Level.INFO, "Disabling HuskHomes...");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Version getPluginVersion() {
|
||||
return Version.fromString(getDescription().getVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getServerType() {
|
||||
return String.format("%s/%s", getServer().getName(), getServer().getVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Version getMinecraftVersion() {
|
||||
return Version.fromString(getServer().getBukkitVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDependencyAvailable(@NotNull String name) {
|
||||
return Bukkit.getPluginManager().getPlugin(name) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Broker> getBroker() {
|
||||
return Optional.ofNullable(broker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeBroker() {
|
||||
if (broker != null) {
|
||||
broker.close();
|
||||
}
|
||||
if (audiences != null) {
|
||||
audiences.close();
|
||||
audiences = null;
|
||||
}
|
||||
cancelTasks();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -261,14 +231,6 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
return new ConsoleUser(audiences.console());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<OnlineUser> getOnlineUsers() {
|
||||
return Bukkit.getOnlinePlayers().stream()
|
||||
.map(player -> (OnlineUser) BukkitUser.adapt(player, this))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Audience getAudience(@NotNull UUID user) {
|
||||
@@ -280,13 +242,11 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
Objects.requireNonNull(Adapter.adapt(position).getWorld()).setSpawnLocation(Adapter.adapt(position));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Broker getMessenger() {
|
||||
if (broker == null) {
|
||||
throw new IllegalStateException("Attempted to access message broker when it was not initialized");
|
||||
}
|
||||
return broker;
|
||||
public void registerCommands(@NotNull List<Command> commands) {
|
||||
commands.stream().peek(this.commands::add)
|
||||
.map(c -> new BukkitCommand(c, getPlugin()))
|
||||
.forEach(BukkitCommand::register);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -294,26 +254,10 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
return Optional.ofNullable(serverSpawn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setServerSpawn(@NotNull Spawn spawn) {
|
||||
this.serverSpawn = spawn;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Version getVersion() {
|
||||
return Version.fromString(getDescription().getVersion(), "-");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getServerName() {
|
||||
return server != null ? server.getName() : "server";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setServerName(@NotNull Server server) {
|
||||
this.server = server;
|
||||
return serverName != null ? serverName.getName() : "server";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -329,40 +273,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerMetrics(int metricsId) {
|
||||
if (!getVersion().getMetadata().isBlank()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final Metrics metrics = new Metrics(this, metricsId);
|
||||
metrics.addCustomChart(new SimplePie("bungee_mode",
|
||||
() -> Boolean.toString(getSettings().getCrossServer().isEnabled())
|
||||
));
|
||||
|
||||
if (getSettings().getCrossServer().isEnabled()) {
|
||||
metrics.addCustomChart(new SimplePie("messenger_type",
|
||||
() -> getSettings().getCrossServer().getBrokerType().getDisplayName())
|
||||
);
|
||||
}
|
||||
|
||||
metrics.addCustomChart(new SimplePie("language",
|
||||
() -> getSettings().getLanguage().toLowerCase()));
|
||||
metrics.addCustomChart(new SimplePie("database_type",
|
||||
() -> getSettings().getDatabase().getType().getDisplayName()));
|
||||
metrics.addCustomChart(new SimplePie("using_economy",
|
||||
() -> Boolean.toString(getSettings().getEconomy().isEnabled())));
|
||||
metrics.addCustomChart(new SimplePie("using_map",
|
||||
() -> Boolean.toString(getSettings().getMapHook().isEnabled())));
|
||||
|
||||
getMapHook().ifPresent(hook -> metrics.addCustomChart(new SimplePie("map_type", hook::getName)));
|
||||
} catch (Throwable e) {
|
||||
log(Level.WARNING, "Failed to register bStats metrics (" + e.getMessage() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializePluginChannels() {
|
||||
public void setupPluginMessagingChannels() {
|
||||
final String channelId = PluginMessageBroker.BUNGEE_CHANNEL_ID;
|
||||
getServer().getMessenger().registerIncomingPluginChannel(this, channelId, this);
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, channelId);
|
||||
@@ -379,15 +290,15 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
|
||||
@Override
|
||||
public void onPluginMessageReceived(@NotNull String channel, @NotNull Player player, byte[] message) {
|
||||
if (broker != null && broker instanceof PluginMessageBroker pluginMessenger
|
||||
&& getSettings().getCrossServer().getBrokerType() == Broker.Type.PLUGIN_MESSAGE) {
|
||||
pluginMessenger.onReceive(channel, BukkitUser.adapt(player, this), message);
|
||||
if (broker != null && broker instanceof PluginMessageBroker pluginMessenger &&
|
||||
getSettings().getCrossServer().getBrokerType() == Broker.Type.PLUGIN_MESSAGE) {
|
||||
pluginMessenger.onReceive(channel, getOnlineUser(player), message);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GracefulScheduling getScheduler() {
|
||||
return paperLib.scheduling();
|
||||
return morePaperLib.scheduling();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -407,9 +318,11 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
|
||||
return getScheduler().entitySpecificScheduler(((BukkitUser) user).getPlayer());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CommandRegistration getCommandRegistrar() {
|
||||
return paperLib.commandRegistration();
|
||||
@Override
|
||||
public void closeDatabase() {
|
||||
if (database != null) {
|
||||
database.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -82,7 +82,7 @@ public class HuskHomesAPI extends BaseHuskHomesAPI {
|
||||
*/
|
||||
@NotNull
|
||||
public OnlineUser adaptUser(@NotNull Player player) {
|
||||
return BukkitUser.adapt(player, (BukkitHuskHomes) plugin);
|
||||
return ((BukkitHuskHomes) plugin).getOnlineUser(player);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,9 +20,6 @@
|
||||
package net.william278.huskhomes.command;
|
||||
|
||||
import net.william278.huskhomes.BukkitHuskHomes;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.teleport.TeleportRequest;
|
||||
import net.william278.huskhomes.user.BukkitUser;
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -33,7 +30,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class BukkitCommand extends org.bukkit.command.Command {
|
||||
|
||||
@@ -48,7 +44,7 @@ public class BukkitCommand extends org.bukkit.command.Command {
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
|
||||
this.command.onExecuted(sender instanceof Player p ? BukkitUser.adapt(p, plugin) : plugin.getConsole(), args);
|
||||
this.command.onExecuted(sender instanceof Player p ? plugin.getOnlineUser(p) : plugin.getConsole(), args);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -56,16 +52,17 @@ public class BukkitCommand extends org.bukkit.command.Command {
|
||||
@Override
|
||||
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias,
|
||||
@NotNull String[] args) throws IllegalArgumentException {
|
||||
if (!(this.command instanceof TabProvider provider)) {
|
||||
if (!(this.command instanceof TabCompletable completable)) {
|
||||
return List.of();
|
||||
}
|
||||
final CommandUser user = sender instanceof Player p ? BukkitUser.adapt(p, plugin) : plugin.getConsole();
|
||||
return provider.getSuggestions(user, args);
|
||||
final CommandUser user = sender instanceof Player p ? plugin.getOnlineUser(p) : plugin.getConsole();
|
||||
return completable.getSuggestions(user, args);
|
||||
}
|
||||
|
||||
public void register() {
|
||||
// Register with bukkit
|
||||
plugin.getCommandRegistrar().getServerCommandMap().register("huskhomes", this);
|
||||
plugin.getMorePaperLib().commandRegistration().getServerCommandMap()
|
||||
.register("huskhomes", this);
|
||||
|
||||
// Register permissions
|
||||
BukkitCommand.addPermission(
|
||||
@@ -108,7 +105,7 @@ public class BukkitCommand extends org.bukkit.command.Command {
|
||||
return null;
|
||||
}
|
||||
|
||||
Permission permission;
|
||||
final Permission permission;
|
||||
if (description.isEmpty()) {
|
||||
permission = new Permission(node, permissionDefault, childNodes);
|
||||
} else {
|
||||
@@ -124,58 +121,4 @@ public class BukkitCommand extends org.bukkit.command.Command {
|
||||
return isOperatorCommand ? PermissionDefault.OP : PermissionDefault.TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Commands available on the Bukkit HuskHomes implementation.
|
||||
*/
|
||||
public enum Type {
|
||||
HOME_COMMAND(PrivateHomeCommand::new),
|
||||
SET_HOME_COMMAND(SetHomeCommand::new),
|
||||
HOME_LIST_COMMAND(HomeListCommand::new),
|
||||
DEL_HOME_COMMAND(DelHomeCommand::new),
|
||||
EDIT_HOME_COMMAND(EditHomeCommand::new),
|
||||
PUBLIC_HOME_COMMAND(PublicHomeCommand::new),
|
||||
PUBLIC_HOME_LIST_COMMAND(PublicHomeListCommand::new),
|
||||
WARP_COMMAND(WarpCommand::new),
|
||||
SET_WARP_COMMAND(SetWarpCommand::new),
|
||||
WARP_LIST_COMMAND(WarpListCommand::new),
|
||||
DEL_WARP_COMMAND(DelWarpCommand::new),
|
||||
EDIT_WARP_COMMAND(EditWarpCommand::new),
|
||||
TP_COMMAND(TpCommand::new),
|
||||
TP_HERE_COMMAND(TpHereCommand::new),
|
||||
TPA_COMMAND((plugin) -> new TeleportRequestCommand(plugin, TeleportRequest.Type.TPA)),
|
||||
TPA_HERE_COMMAND((plugin) -> new TeleportRequestCommand(plugin, TeleportRequest.Type.TPA_HERE)),
|
||||
TPACCEPT_COMMAND((plugin) -> new TpRespondCommand(plugin, true)),
|
||||
TPDECLINE_COMMAND((plugin) -> new TpRespondCommand(plugin, false)),
|
||||
RTP_COMMAND(RTPCommand::new),
|
||||
TP_IGNORE_COMMAND(TpIgnoreCommand::new),
|
||||
TP_OFFLINE_COMMAND(TpOfflineCommand::new),
|
||||
TP_ALL_COMMAND(TpAllCommand::new),
|
||||
TPA_ALL_COMMAND(TpaAllCommand::new),
|
||||
SPAWN_COMMAND(SpawnCommand::new),
|
||||
SET_SPAWN_COMMAND(SetSpawnCommand::new),
|
||||
BACK_COMMAND(BackCommand::new),
|
||||
HUSKHOMES_COMMAND(HuskHomesCommand::new);
|
||||
|
||||
private final Function<HuskHomes, Command> supplier;
|
||||
|
||||
Type(@NotNull Function<HuskHomes, Command> supplier) {
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Command createCommand(@NotNull HuskHomes plugin) {
|
||||
return supplier.apply(plugin);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<Command> getCommands(@NotNull BukkitHuskHomes plugin) {
|
||||
return Arrays.stream(values())
|
||||
.map((type) -> type.createCommand(plugin))
|
||||
.filter((command) -> !plugin.getSettings().isCommandDisabled(command))
|
||||
.peek((command) -> new BukkitCommand(command, plugin).register())
|
||||
.toList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.hook;
|
||||
|
||||
import net.william278.huskhomes.BukkitHuskHomes;
|
||||
import net.william278.huskhomes.importer.EssentialsXImporter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BukkitHookProvider extends HookProvider {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
default List<Hook> getAvailableHooks() {
|
||||
final List<Hook> hooks = HookProvider.super.getAvailableHooks();
|
||||
|
||||
// Hooks
|
||||
if (getPlugin().getSettings().getEconomy().isEnabled() && isDependencyAvailable("Vault")) {
|
||||
getHooks().add(new VaultEconomyHook(getPlugin()));
|
||||
}
|
||||
if (isDependencyAvailable("PlaceholderAPI")) {
|
||||
getHooks().add(new PlaceholderAPIHook(getPlugin()));
|
||||
}
|
||||
|
||||
// Importers
|
||||
if (isDependencyAvailable("Essentials")) {
|
||||
getHooks().add(new EssentialsXImporter(getPlugin()));
|
||||
}
|
||||
|
||||
return hooks;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
default boolean isDependencyAvailable(@NotNull String name) {
|
||||
return getPlugin().getServer().getPluginManager().getPlugin(name) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
BukkitHuskHomes getPlugin();
|
||||
|
||||
}
|
||||
@@ -19,10 +19,12 @@
|
||||
|
||||
package net.william278.huskhomes.hook;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import net.william278.huskhomes.BukkitHuskHomes;
|
||||
import net.william278.huskhomes.user.BukkitUser;
|
||||
import net.william278.huskhomes.user.OnlineUser;
|
||||
import net.william278.huskhomes.user.SavedUser;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@@ -31,25 +33,38 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@PluginHook(
|
||||
name = "PlaceholderAPI",
|
||||
register = PluginHook.Register.ON_LOAD
|
||||
)
|
||||
public class PlaceholderAPIHook extends Hook {
|
||||
|
||||
public PlaceholderAPIHook(@NotNull BukkitHuskHomes plugin) {
|
||||
super(plugin, "PlaceholderAPI");
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
new HuskHomesExpansion((BukkitHuskHomes) plugin).register();
|
||||
public void load() {
|
||||
new HuskHomesExpansion(
|
||||
(BukkitHuskHomes) plugin,
|
||||
plugin.getPluginVersion().toStringWithoutMetadata()
|
||||
).register();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
}
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public static class HuskHomesExpansion extends PlaceholderExpansion {
|
||||
|
||||
@NotNull
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final BukkitHuskHomes plugin;
|
||||
|
||||
private HuskHomesExpansion(@NotNull BukkitHuskHomes plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
private final String version;
|
||||
private final String author = "William278";
|
||||
private final String identifier = "huskhomes";
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
@@ -59,11 +74,11 @@ public class PlaceholderAPIHook extends Hook {
|
||||
}
|
||||
|
||||
// Return the requested data
|
||||
final OnlineUser player = BukkitUser.adapt(offlinePlayer.getPlayer(), plugin);
|
||||
final OnlineUser player = plugin.getOnlineUser(offlinePlayer.getPlayer());
|
||||
return switch (params) {
|
||||
case "homes_count" -> String.valueOf(plugin.getManager().homes()
|
||||
.getUserHomes()
|
||||
.getOrDefault(player.getUsername(), List.of()).size());
|
||||
.getOrDefault(player.getName(), List.of()).size());
|
||||
case "max_homes" -> String.valueOf(plugin.getManager().homes().getMaxHomes(player));
|
||||
case "max_public_homes" -> String.valueOf(plugin.getManager().homes().getMaxPublicHomes(player));
|
||||
case "free_home_slots" -> String.valueOf(plugin.getManager().homes().getFreeHomes(player));
|
||||
@@ -72,42 +87,19 @@ public class PlaceholderAPIHook extends Hook {
|
||||
.orElse(0));
|
||||
case "homes_list" -> String.join(", ", plugin.getManager().homes()
|
||||
.getUserHomes()
|
||||
.getOrDefault(player.getUsername(), List.of()));
|
||||
.getOrDefault(player.getName(), List.of()));
|
||||
case "public_homes_count" -> String.valueOf(plugin.getManager().homes()
|
||||
.getPublicHomes()
|
||||
.getOrDefault(player.getUsername(), List.of()).size());
|
||||
.getOrDefault(player.getName(), List.of()).size());
|
||||
case "public_homes_list" -> String.join(", ", plugin.getManager().homes()
|
||||
.getPublicHomes()
|
||||
.getOrDefault(player.getUsername(), List.of()));
|
||||
.getOrDefault(player.getName(), List.of()));
|
||||
case "ignoring_tp_requests" -> getBooleanValue(plugin.getManager().requests()
|
||||
.isIgnoringRequests(player));
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getIdentifier() {
|
||||
return "huskhomes";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getAuthor() {
|
||||
return "William278";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getVersion() {
|
||||
return plugin.getVersion().toStringWithoutMetadata();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getBooleanValue(final boolean bool) {
|
||||
return bool ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse();
|
||||
|
||||
@@ -31,16 +31,20 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* A hook that hooks into the Vault API to provide economy features.
|
||||
*/
|
||||
@PluginHook(
|
||||
name = "Vault",
|
||||
register = PluginHook.Register.ON_LOAD
|
||||
)
|
||||
public class VaultEconomyHook extends EconomyHook {
|
||||
|
||||
protected Economy economy;
|
||||
|
||||
public VaultEconomyHook(@NotNull HuskHomes plugin) {
|
||||
super(plugin, "Vault (Economy)");
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
public void load() {
|
||||
final RegisteredServiceProvider<Economy> economyProvider = ((BukkitHuskHomes) plugin).getServer()
|
||||
.getServicesManager().getRegistration(Economy.class);
|
||||
if (economyProvider != null) {
|
||||
@@ -48,6 +52,11 @@ public class VaultEconomyHook extends EconomyHook {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
this.economy = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPlayerBalance(@NotNull OnlineUser player) {
|
||||
return economy.getBalance(((BukkitUser) player).getPlayer());
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.earth2me.essentials.Warps;
|
||||
import com.earth2me.essentials.commands.WarpNotFoundException;
|
||||
import net.william278.huskhomes.BukkitHuskHomes;
|
||||
import net.william278.huskhomes.HuskHomes;
|
||||
import net.william278.huskhomes.hook.PluginHook;
|
||||
import net.william278.huskhomes.user.User;
|
||||
import net.william278.huskhomes.util.ValidationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -33,12 +34,16 @@ import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@PluginHook(
|
||||
name = "EssentialsX",
|
||||
register = PluginHook.Register.ON_LOAD
|
||||
)
|
||||
public class EssentialsXImporter extends Importer {
|
||||
|
||||
private final Essentials essentials;
|
||||
|
||||
public EssentialsXImporter(@NotNull HuskHomes plugin) {
|
||||
super("EssentialsX", List.of(ImportData.HOMES, ImportData.WARPS), plugin);
|
||||
super(List.of(ImportData.HOMES, ImportData.WARPS), plugin);
|
||||
this.essentials = (Essentials) ((BukkitHuskHomes) plugin).getServer()
|
||||
.getPluginManager().getPlugin("Essentials");
|
||||
}
|
||||
@@ -96,7 +101,7 @@ public class EssentialsXImporter extends Importer {
|
||||
@NotNull
|
||||
private String normalizeName(@NotNull String name) {
|
||||
try {
|
||||
plugin.getValidator().validateName(name);
|
||||
plugin.validateName(name);
|
||||
return name;
|
||||
} catch (ValidationException e) {
|
||||
// Remove spaces
|
||||
|
||||
@@ -21,7 +21,6 @@ package net.william278.huskhomes.listener;
|
||||
|
||||
import net.william278.huskhomes.BukkitHuskHomes;
|
||||
import net.william278.huskhomes.config.Settings;
|
||||
import net.william278.huskhomes.user.BukkitUser;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.data.type.Bed;
|
||||
import org.bukkit.block.data.type.RespawnAnchor;
|
||||
@@ -41,25 +40,24 @@ public class BukkitEventListener extends EventListener implements Listener {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BukkitEventListener register(@NotNull BukkitHuskHomes plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
return this;
|
||||
@Override
|
||||
public void register() {
|
||||
getPlugin().getServer().getPluginManager().registerEvents(this, getPlugin());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
super.handlePlayerJoin(BukkitUser.adapt(event.getPlayer(), (BukkitHuskHomes) plugin));
|
||||
super.handlePlayerJoin(getPlugin().getOnlineUser(event.getPlayer()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
super.handlePlayerLeave(BukkitUser.adapt(event.getPlayer(), (BukkitHuskHomes) plugin));
|
||||
super.handlePlayerLeave(getPlugin().getOnlineUser(event.getPlayer()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||
super.handlePlayerDeath(BukkitUser.adapt(event.getEntity(), (BukkitHuskHomes) plugin));
|
||||
super.handlePlayerDeath(getPlugin().getOnlineUser(event.getEntity()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
@@ -67,7 +65,7 @@ public class BukkitEventListener extends EventListener implements Listener {
|
||||
if (usePaperEvents) {
|
||||
return;
|
||||
}
|
||||
super.handlePlayerRespawn(BukkitUser.adapt(event.getPlayer(), (BukkitHuskHomes) plugin));
|
||||
super.handlePlayerRespawn(getPlugin().getOnlineUser(event.getPlayer()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
@@ -78,25 +76,25 @@ public class BukkitEventListener extends EventListener implements Listener {
|
||||
if (player.hasMetadata("NPC")) {
|
||||
return;
|
||||
}
|
||||
if (!(event.getCause() == PlayerTeleportEvent.TeleportCause.COMMAND
|
||||
|| event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN)) {
|
||||
if (!(event.getCause() == PlayerTeleportEvent.TeleportCause.COMMAND ||
|
||||
event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.handlePlayerTeleport(
|
||||
BukkitUser.adapt(player, (BukkitHuskHomes) plugin),
|
||||
BukkitHuskHomes.Adapter.adapt(event.getFrom(), plugin.getServerName())
|
||||
getPlugin().getOnlineUser(player),
|
||||
BukkitHuskHomes.Adapter.adapt(event.getFrom(), getPlugin().getServerName())
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onPlayerUpdateRespawnLocation(PlayerInteractEvent event) {
|
||||
final Settings.CrossServerSettings crossServer = plugin.getSettings().getCrossServer();
|
||||
final Settings.CrossServerSettings crossServer = getPlugin().getSettings().getCrossServer();
|
||||
if (usePaperEvents || !(crossServer.isEnabled()) && crossServer.isGlobalRespawning()) {
|
||||
return;
|
||||
}
|
||||
if (event.getClickedBlock() == null || !(event.getClickedBlock().getBlockData() instanceof Bed
|
||||
|| event.getClickedBlock().getBlockData() instanceof RespawnAnchor)) {
|
||||
|| event.getClickedBlock().getBlockData() instanceof RespawnAnchor)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -107,10 +105,16 @@ public class BukkitEventListener extends EventListener implements Listener {
|
||||
|
||||
// Update the player's respawn location
|
||||
this.handlePlayerUpdateSpawnPoint(
|
||||
BukkitUser.adapt(event.getPlayer(), (BukkitHuskHomes) plugin),
|
||||
BukkitHuskHomes.Adapter.adapt(location, plugin.getServerName())
|
||||
getPlugin().getOnlineUser(event.getPlayer()),
|
||||
BukkitHuskHomes.Adapter.adapt(location, getPlugin().getServerName())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected BukkitHuskHomes getPlugin() {
|
||||
return (BukkitHuskHomes) super.getPlugin();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -49,6 +50,7 @@ public class BukkitUser extends OnlineUser {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ApiStatus.Internal
|
||||
public static BukkitUser adapt(@NotNull Player player, @NotNull BukkitHuskHomes plugin) {
|
||||
return new BukkitUser(player, plugin);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of HuskHomes, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.william278.huskhomes.user;
|
||||
|
||||
import net.william278.huskhomes.BukkitHuskHomes;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface BukkitUserProvider extends UserProvider {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
default OnlineUser getOnlineUser(@NotNull UUID uuid) {
|
||||
return getOnlineUser(getPlugin().getServer().getPlayer(uuid));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
default BukkitUser getOnlineUser(@Nullable Player player) {
|
||||
if (player == null) {
|
||||
throw new IllegalArgumentException("Player is not online");
|
||||
}
|
||||
BukkitUser user = (BukkitUser) getOnlineUserMap().get(player.getUniqueId());
|
||||
if (user == null) {
|
||||
user = BukkitUser.adapt(player, getPlugin());
|
||||
getOnlineUserMap().put(player.getUniqueId(), user);
|
||||
return user;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
BukkitHuskHomes getPlugin();
|
||||
|
||||
}
|
||||
+1
-1
@@ -30,7 +30,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface BukkitSafetyResolver extends SafetyResolver {
|
||||
public interface BukkitSavePositionProvider extends SavePositionProvider {
|
||||
|
||||
@Override
|
||||
default CompletableFuture<Optional<Location>> findSafeGroundLocation(@NotNull Location location) {
|
||||
@@ -23,7 +23,6 @@ import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import de.themoep.minedown.adventure.MineDown;
|
||||
import net.william278.huskhomes.command.BukkitCommand;
|
||||
import net.william278.huskhomes.command.Command;
|
||||
import net.william278.huskhomes.position.*;
|
||||
import net.william278.huskhomes.user.BukkitUser;
|
||||
@@ -47,7 +46,7 @@ import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Uses MockBukkit to test the plugin on a mock Paper server implementing the Bukkit 1.17 API.
|
||||
* Uses MockBukkit to test the plugin on a mock Paper server implementing the Bukkit API.
|
||||
*/
|
||||
@DisplayName("Bukkit Plugin Tests (1.17.1)")
|
||||
public class BukkitPluginTests {
|
||||
@@ -76,14 +75,14 @@ public class BukkitPluginTests {
|
||||
@Test
|
||||
@DisplayName("Test Command Registration")
|
||||
public void testCommandRegistration() {
|
||||
Assertions.assertEquals(BukkitCommand.Type.values().length, plugin.getCommands().size());
|
||||
Assertions.assertFalse(plugin.getCommands().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test Player Adapter")
|
||||
public void testPlayerAdaption() {
|
||||
PlayerMock player = server.addPlayer();
|
||||
Assertions.assertNotNull(BukkitUser.adapt(player, plugin));
|
||||
Assertions.assertNotNull(plugin.getOnlineUser(player));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,14 +108,14 @@ public class BukkitPluginTests {
|
||||
.orElseThrow(() -> new IllegalStateException("Failed to load locale"));
|
||||
final String simpleLocaleText = plugin.getLocales().getRawLocale("error_in_game_only")
|
||||
.orElseThrow(() -> new IllegalStateException("Failed to load raw locale"));
|
||||
BukkitUser.adapt(player, plugin).sendMessage(simpleLocale);
|
||||
plugin.getOnlineUser(player).sendMessage(simpleLocale);
|
||||
player.assertSaid(simpleLocaleText);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test Message Dispatching")
|
||||
public void testMessageDispatching() {
|
||||
final BukkitUser user = BukkitUser.adapt(server.addPlayer(), plugin);
|
||||
final BukkitUser user = plugin.getOnlineUser(server.addPlayer());
|
||||
|
||||
final MineDown locale = plugin.getLocales()
|
||||
.getLocale("teleporting_action_bar_warmup", Integer.toString(3))
|
||||
@@ -139,7 +138,7 @@ public class BukkitPluginTests {
|
||||
@DisplayName("Test Locale Parsing")
|
||||
public void testLocaleParsing() {
|
||||
final Map<String, String> rawLocales = plugin.getLocales().getRawLocales();
|
||||
BukkitUser user = BukkitUser.adapt(server.addPlayer(), plugin);
|
||||
BukkitUser user = plugin.getOnlineUser(server.addPlayer());
|
||||
rawLocales.forEach((key, value) -> {
|
||||
Optional<MineDown> locale = plugin.getLocales().getLocale(key);
|
||||
Assertions.assertTrue(locale.isPresent());
|
||||
@@ -178,7 +177,7 @@ public class BukkitPluginTests {
|
||||
final PlayerMock player = server.addPlayer();
|
||||
player.setOp(true);
|
||||
|
||||
final BukkitUser playerUser = BukkitUser.adapt(player, plugin);
|
||||
final OnlineUser playerUser = (plugin).getOnlineUser(player);
|
||||
return commands.stream()
|
||||
.flatMap(command -> Stream.of(Arguments.of(command, playerUser, command.getName())));
|
||||
}
|
||||
@@ -194,7 +193,7 @@ public class BukkitPluginTests {
|
||||
|
||||
@Nested
|
||||
@DisplayName("Validator Tests")
|
||||
public class ValidatorTests {
|
||||
public class TextValidatorTests {
|
||||
|
||||
@DisplayName("Test Validator Accepts Valid Names")
|
||||
@ParameterizedTest(name = "Valid Name: \"{0}\"")
|
||||
@@ -202,7 +201,7 @@ public class BukkitPluginTests {
|
||||
"ValidName", "Valid_Name", "Valid-Name", "ValidN4me", "ValidName123", "VN-123", "ValidName_123", "V"
|
||||
})
|
||||
public void testValidNameIsValid(@NotNull String name) {
|
||||
Assertions.assertDoesNotThrow(() -> plugin.getValidator().validateName(name));
|
||||
Assertions.assertDoesNotThrow(() -> plugin.validateName(name));
|
||||
}
|
||||
|
||||
@DisplayName("Test Validator Rejects Invalid Names")
|
||||
@@ -213,7 +212,7 @@ public class BukkitPluginTests {
|
||||
public void testInvalidNameIsInvalid(@NotNull String name) {
|
||||
Assertions.assertThrows(
|
||||
ValidationException.class,
|
||||
() -> plugin.getValidator().validateName(name)
|
||||
() -> plugin.validateName(name)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -227,7 +226,7 @@ public class BukkitPluginTests {
|
||||
+ " description that is 255 characters long and should be accepted by the validator"
|
||||
})
|
||||
public void testValidDescriptionIsValid(@NotNull String description) {
|
||||
Assertions.assertDoesNotThrow(() -> plugin.getValidator().validateDescription(description));
|
||||
Assertions.assertDoesNotThrow(() -> plugin.validateDescription(description));
|
||||
}
|
||||
|
||||
@DisplayName("Test Validator Rejects Invalid Descriptions")
|
||||
@@ -241,7 +240,7 @@ public class BukkitPluginTests {
|
||||
public void testInvalidDescriptionIsInvalid(@NotNull String description) {
|
||||
Assertions.assertThrows(
|
||||
ValidationException.class,
|
||||
() -> plugin.getValidator().validateDescription(description)
|
||||
() -> plugin.validateDescription(description)
|
||||
);
|
||||
|
||||
}
|
||||
@@ -256,7 +255,7 @@ public class BukkitPluginTests {
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
player = BukkitUser.adapt(server.addPlayer(), plugin);
|
||||
player = plugin.getOnlineUser(server.addPlayer());
|
||||
}
|
||||
|
||||
@DisplayName("Test Applying Cooldown")
|
||||
@@ -264,7 +263,7 @@ public class BukkitPluginTests {
|
||||
@Test
|
||||
public void testApplyingCooldown() {
|
||||
plugin.getDatabase().ensureUser(player);
|
||||
Assertions.assertTrue(plugin.getDatabase().getUserData(player.getUuid()).isPresent());
|
||||
Assertions.assertTrue(plugin.getDatabase().getUser(player.getUuid()).isPresent());
|
||||
|
||||
plugin.getDatabase().setCooldown(ACTION, player, Instant.now().plus(DURATION));
|
||||
Assertions.assertTrue(plugin.getDatabase().getCooldown(ACTION, player).isPresent());
|
||||
@@ -319,7 +318,7 @@ public class BukkitPluginTests {
|
||||
.anyMatch(warp -> warp.equals(name)));
|
||||
}
|
||||
|
||||
// test warp renaming
|
||||
// Test warp renaming
|
||||
@DisplayName("Test Warp Renaming")
|
||||
@ParameterizedTest(name = "Rename: \"{0}\" > \"{0}2\"")
|
||||
@MethodSource("provideWarpData")
|
||||
@@ -465,9 +464,9 @@ public class BukkitPluginTests {
|
||||
@DisplayName("Ensure User Data")
|
||||
@BeforeAll
|
||||
public static void createHomeUser() {
|
||||
homeOwner = BukkitUser.adapt(server.addPlayer("TestUser278"), plugin);
|
||||
homeOwner = plugin.getOnlineUser(server.addPlayer("TestUser278"));
|
||||
plugin.getDatabase().ensureUser(homeOwner);
|
||||
Assertions.assertTrue(plugin.getDatabase().getUserData(homeOwner.getUuid()).isPresent());
|
||||
Assertions.assertTrue(plugin.getDatabase().getUser(homeOwner.getUuid()).isPresent());
|
||||
}
|
||||
|
||||
@DisplayName("Test Home Creation")
|
||||
@@ -479,7 +478,7 @@ public class BukkitPluginTests {
|
||||
Assertions.assertTrue(plugin.getDatabase().getHome(owner, name).isPresent());
|
||||
Assertions.assertTrue(plugin.getManager().homes()
|
||||
.getUserHomes()
|
||||
.get(owner.getUsername()).stream()
|
||||
.get(owner.getName()).stream()
|
||||
.anyMatch(home -> home.equals(name)));
|
||||
}
|
||||
|
||||
@@ -495,11 +494,11 @@ public class BukkitPluginTests {
|
||||
Assertions.assertFalse(plugin.getDatabase().getHome(owner, name).isPresent());
|
||||
Assertions.assertTrue(plugin.getManager().homes()
|
||||
.getUserHomes()
|
||||
.get(owner.getUsername()).stream()
|
||||
.get(owner.getName()).stream()
|
||||
.anyMatch(home -> home.equals(newName)));
|
||||
Assertions.assertFalse(plugin.getManager().homes()
|
||||
.getUserHomes()
|
||||
.get(owner.getUsername()).stream()
|
||||
.get(owner.getName()).stream()
|
||||
.anyMatch(home -> home.equals(name)));
|
||||
|
||||
// Rename back to original name
|
||||
@@ -507,7 +506,7 @@ public class BukkitPluginTests {
|
||||
Assertions.assertTrue(plugin.getDatabase().getHome(owner, name).isPresent());
|
||||
Assertions.assertTrue(plugin.getManager().homes()
|
||||
.getUserHomes()
|
||||
.get(owner.getUsername()).stream()
|
||||
.get(owner.getName()).stream()
|
||||
.anyMatch(home -> home.equals(name)));
|
||||
}
|
||||
|
||||
@@ -518,7 +517,7 @@ public class BukkitPluginTests {
|
||||
@SuppressWarnings("unused")
|
||||
public void testHomeDescription(@NotNull OnlineUser owner, @NotNull String name,
|
||||
@NotNull Position position) {
|
||||
final String description = "This is a test description for the home " + name + "!";
|
||||
final String description = "This is a description for the home " + name + "!";
|
||||
plugin.getManager().homes().setHomeDescription(owner, name, description);
|
||||
Assertions.assertTrue(plugin.getDatabase().getHome(owner, name).isPresent());
|
||||
|
||||
@@ -585,7 +584,7 @@ public class BukkitPluginTests {
|
||||
Assertions.assertTrue(homePrivacy.isPresent());
|
||||
Assertions.assertTrue(homePrivacy.get());
|
||||
Assertions.assertTrue(plugin.getManager().homes().getPublicHomes()
|
||||
.get(owner.getUsername()).contains(name));
|
||||
.get(owner.getName()).contains(name));
|
||||
}
|
||||
|
||||
@DisplayName("Test Making Home Private")
|
||||
@@ -601,7 +600,7 @@ public class BukkitPluginTests {
|
||||
Assertions.assertTrue(homePrivacy.isPresent());
|
||||
Assertions.assertFalse(homePrivacy.get());
|
||||
Assertions.assertFalse(plugin.getManager().homes().getPublicHomes()
|
||||
.getOrDefault(owner.getUsername(), List.of())
|
||||
.getOrDefault(owner.getName(), List.of())
|
||||
.contains(name));
|
||||
}
|
||||
|
||||
@@ -631,7 +630,7 @@ public class BukkitPluginTests {
|
||||
plugin.getManager().homes().deleteHome(owner, name);
|
||||
Assertions.assertFalse(plugin.getDatabase().getHome(owner, name).isPresent());
|
||||
Assertions.assertFalse(plugin.getManager().homes().getUserHomes()
|
||||
.getOrDefault(owner.getUsername(), List.of())
|
||||
.getOrDefault(owner.getName(), List.of())
|
||||
.contains(name));
|
||||
|
||||
plugin.getManager().homes().createHome(owner, name, position);
|
||||
@@ -644,7 +643,7 @@ public class BukkitPluginTests {
|
||||
final int deleted = plugin.getManager().homes().deleteAllHomes(homeOwner);
|
||||
Assertions.assertTrue(plugin.getDatabase().getHomes(homeOwner).isEmpty());
|
||||
Assertions.assertTrue(plugin.getManager().homes().getUserHomes()
|
||||
.get(homeOwner.getUsername()).isEmpty());
|
||||
.get(homeOwner.getName()).isEmpty());
|
||||
Assertions.assertEquals(HOME_NAMES.size(), deleted);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user