getOnlineUsers() {
return Bukkit.getOnlinePlayers().stream()
- .map(player -> (OnlineUser) BukkitUser.adapt(player))
+ .map(player -> (OnlineUser) BukkitUser.adapt(player, this))
.toList();
}
@@ -369,7 +351,7 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
// Update the world spawn location, too
BukkitAdapter.adaptLocation(location).ifPresent(bukkitLocation -> {
- assert bukkitLocation.getWorld() != null;
+ assert bukkitLocation.getWorld() != null : "World was null when setting server spawn";
bukkitLocation.getWorld().setSpawnLocation(bukkitLocation);
});
} catch (IOException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
@@ -451,14 +433,23 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
try {
final Metrics metrics = new Metrics(this, metricsId);
- metrics.addCustomChart(new SimplePie("bungee_mode", () -> Boolean.toString(getSettings().doCrossServer())));
+ metrics.addCustomChart(new SimplePie("bungee_mode",
+ () -> Boolean.toString(getSettings().doCrossServer())));
+
if (getSettings().doCrossServer()) {
- metrics.addCustomChart(new SimplePie("messenger_type", () -> getSettings().getBrokerType().getDisplayName()));
+ metrics.addCustomChart(new SimplePie("messenger_type",
+ () -> getSettings().getBrokerType().getDisplayName()));
}
- metrics.addCustomChart(new SimplePie("language", () -> getSettings().getLanguage().toLowerCase()));
- metrics.addCustomChart(new SimplePie("database_type", () -> getSettings().getDatabaseType().getDisplayName()));
- metrics.addCustomChart(new SimplePie("using_economy", () -> Boolean.toString(getSettings().doEconomy())));
- metrics.addCustomChart(new SimplePie("using_map", () -> Boolean.toString(getSettings().doMapHook())));
+
+ metrics.addCustomChart(new SimplePie("language",
+ () -> getSettings().getLanguage().toLowerCase()));
+ metrics.addCustomChart(new SimplePie("database_type",
+ () -> getSettings().getDatabaseType().getDisplayName()));
+ metrics.addCustomChart(new SimplePie("using_economy",
+ () -> Boolean.toString(getSettings().doEconomy())));
+ metrics.addCustomChart(new SimplePie("using_map",
+ () -> Boolean.toString(getSettings().doMapHook())));
+
getMapHook().ifPresent(hook -> metrics.addCustomChart(new SimplePie("map_type", hook::getName)));
} catch (Throwable e) {
log(Level.WARNING, "Failed to register bStats metrics (" + e.getMessage() + ")");
@@ -467,8 +458,9 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
@Override
public void initializePluginChannels() {
- Bukkit.getMessenger().registerIncomingPluginChannel(this, PluginMessageBroker.BUNGEE_CHANNEL_ID, this);
- Bukkit.getMessenger().registerOutgoingPluginChannel(this, PluginMessageBroker.BUNGEE_CHANNEL_ID);
+ final String channelId = PluginMessageBroker.BUNGEE_CHANNEL_ID;
+ Bukkit.getMessenger().registerIncomingPluginChannel(this, channelId, this);
+ Bukkit.getMessenger().registerOutgoingPluginChannel(this, channelId);
}
@Override
@@ -483,8 +475,8 @@ 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().getBrokerType() == Broker.Type.PLUGIN_MESSAGE) {
- pluginMessenger.onReceive(channel, BukkitUser.adapt(player), message);
+ && getSettings().getBrokerType() == Broker.Type.PLUGIN_MESSAGE) {
+ pluginMessenger.onReceive(channel, BukkitUser.adapt(player, this), message);
}
}
@@ -498,4 +490,5 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes, BukkitTask
public HuskHomes getPlugin() {
return this;
}
+
}
diff --git a/bukkit/src/main/java/net/william278/huskhomes/api/HuskHomesAPI.java b/bukkit/src/main/java/net/william278/huskhomes/api/HuskHomesAPI.java
index a8d6add3..fed4b34b 100644
--- a/bukkit/src/main/java/net/william278/huskhomes/api/HuskHomesAPI.java
+++ b/bukkit/src/main/java/net/william278/huskhomes/api/HuskHomesAPI.java
@@ -28,6 +28,7 @@ import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.User;
import net.william278.huskhomes.util.BukkitAdapter;
import org.bukkit.entity.Player;
+import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -36,32 +37,53 @@ import java.util.Objects;
/**
* The HuskHomes API implementation for the Bukkit platform, providing methods to access player data, homes, warps
* and process teleports
- *
- * Retrieve an instance of the API class via {@link #getInstance()}.
+ *
+ *
Retrieve an instance of the API class via {@link #getInstance()}.
*/
@SuppressWarnings("unused")
public class HuskHomesAPI extends BaseHuskHomesAPI {
- /**
- * (Internal use only) - Instance of the API class
- */
+ // Instance of the plugin
private static HuskHomesAPI instance;
/**
- * (Internal use only) - Constructor, instantiating the API
+ * (Internal use only) - Constructor, instantiating the API.
*/
- private HuskHomesAPI() {
- super(BukkitHuskHomes.getInstance());
+ @ApiStatus.Internal
+ private HuskHomesAPI(@NotNull BukkitHuskHomes plugin) {
+ super(plugin);
}
/**
- * Entrypoint to the HuskHomes API - returns an instance of the API
+ * Get an instance of the HuskHomes API.
*
* @return instance of the HuskHomes API
+ * @throws NotRegisteredException if the API has not yet been registered.
*/
@NotNull
- public static HuskHomesAPI getInstance() {
- return instance == null ? instance = new HuskHomesAPI() : instance;
+ public static HuskHomesAPI getInstance() throws NotRegisteredException {
+ if (instance == null) {
+ throw new NotRegisteredException();
+ }
+ return instance;
+ }
+
+ /**
+ * (Internal use only) - Register the API for this platform.
+ *
+ * @param plugin the plugin instance
+ */
+ @ApiStatus.Internal
+ public static void register(@NotNull BukkitHuskHomes plugin) {
+ instance = new HuskHomesAPI(plugin);
+ }
+
+ /**
+ * (Internal use only) - Unregister the API for this platform.
+ */
+ @ApiStatus.Internal
+ public static void unregister() {
+ instance = null;
}
/**
@@ -73,7 +95,7 @@ public class HuskHomesAPI extends BaseHuskHomesAPI {
*/
@NotNull
public OnlineUser adaptUser(@NotNull Player player) {
- return BukkitUser.adapt(player);
+ return BukkitUser.adapt(player, (BukkitHuskHomes) plugin);
}
/**
@@ -101,7 +123,7 @@ public class HuskHomesAPI extends BaseHuskHomesAPI {
}
/**
- * Returns a {@link Location} instance for the given bukkit {@link Location}.
+ * Returns a {@link Location} instance for the given bukkit {@link Location} on the server.
*
* @param location the bukkit location to get the {@link Location} instance for
* @return the {@link Location} instance for the given bukkit {@link Location}
@@ -113,7 +135,7 @@ public class HuskHomesAPI extends BaseHuskHomesAPI {
}
/**
- * Returns a {@link Position} instance for the given bukkit {@link Location} on the given {@link Server}.
+ * Returns a {@link Position} instance for the given bukkit {@link Location} on the server.
*
* @param location the bukkit location to get the {@link Position} instance for
* @param server the {@link Server} the position is on
@@ -127,10 +149,10 @@ public class HuskHomesAPI extends BaseHuskHomesAPI {
}
/**
- * Returns a {@link Position} instance for the given bukkit {@link Location} on the server the plugin is running on.
+ * Returns a {@link Position} instance for the given bukkit {@link Location} on the server.
*
* @param location the bukkit location to get the {@link Position} instance for
- * @return the {@link Position} instance for the given bukkit {@link Location} on the server the plugin is running on
+ * @return the {@link Position} instance for the given {@link Location} on the server
* @since 4.0
*/
@NotNull
@@ -139,9 +161,9 @@ public class HuskHomesAPI extends BaseHuskHomesAPI {
}
/**
- * Get the {@link Server}, containing the ID of the server the plugin is running on
+ * Get the name of this server.
*
- * @return the {@link Server}
+ * @return the server name
* @since 4.0
*/
@NotNull
diff --git a/bukkit/src/main/java/net/william278/huskhomes/command/BrigadierUtil.java b/bukkit/src/main/java/net/william278/huskhomes/command/BrigadierUtil.java
index 3b975574..a026d183 100644
--- a/bukkit/src/main/java/net/william278/huskhomes/command/BrigadierUtil.java
+++ b/bukkit/src/main/java/net/william278/huskhomes/command/BrigadierUtil.java
@@ -31,25 +31,28 @@ import java.util.logging.Level;
public class BrigadierUtil {
/**
- * Uses commodore to register command completions
+ * Uses commodore to register command completions.
*
* @param plugin instance of the registering Bukkit plugin
* @param bukkitCommand the Bukkit PluginCommand to register completions for
* @param command the {@link Command} to register completions for
*/
- protected static void registerCommodore(@NotNull BukkitHuskHomes plugin, @NotNull org.bukkit.command.Command bukkitCommand,
+ protected static void registerCommodore(@NotNull BukkitHuskHomes plugin,
+ @NotNull org.bukkit.command.Command bukkitCommand,
@NotNull Command command) {
- final InputStream commandCommodore = plugin.getResource("commodore/" + bukkitCommand.getName() + ".commodore");
- if (commandCommodore == null) {
+ final InputStream commodoreFile = plugin.getResource(
+ "commodore/" + bukkitCommand.getName() + ".commodore"
+ );
+ if (commodoreFile == null) {
return;
}
try {
CommodoreProvider.getCommodore(plugin).register(bukkitCommand,
- CommodoreFileReader.INSTANCE.parse(commandCommodore),
+ CommodoreFileReader.INSTANCE.parse(commodoreFile),
player -> player.hasPermission(command.getPermission()));
} catch (IOException e) {
plugin.log(Level.SEVERE, "Failed to read command commodore completions for "
- + bukkitCommand.getName(), e);
+ + bukkitCommand.getName(), e);
}
}
diff --git a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java
index d81aebf6..f45e2145 100644
--- a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java
+++ b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java
@@ -21,6 +21,7 @@ package net.william278.huskhomes.command;
import me.lucko.commodore.CommodoreProvider;
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;
@@ -36,6 +37,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
+import java.util.function.Function;
public class BukkitCommand implements CommandExecutor, TabCompleter {
@@ -50,7 +52,7 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command command,
@NotNull String label, @NotNull String[] args) {
- this.command.onExecuted(sender instanceof Player player ? BukkitUser.adapt(player) : plugin.getConsole(), args);
+ this.command.onExecuted(sender instanceof Player p ? BukkitUser.adapt(p, plugin) : plugin.getConsole(), args);
return true;
}
@@ -61,7 +63,7 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
if (!(this.command instanceof TabProvider provider)) {
return List.of();
}
- final CommandUser user = sender instanceof Player player ? BukkitUser.adapt(player) : plugin.getConsole();
+ final CommandUser user = sender instanceof Player p ? BukkitUser.adapt(p, plugin) : plugin.getConsole();
return provider.getSuggestions(user, args);
}
@@ -73,7 +75,12 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
}
// Register permissions
- addPermission(plugin, command.getPermission(), command.getUsage(), getPermissionDefault(command.isOperatorCommand()));
+ addPermission(
+ plugin,
+ command.getPermission(),
+ command.getUsage(),
+ getPermissionDefault(command.isOperatorCommand())
+ );
final List childNodes = command.getAdditionalPermissions()
.entrySet().stream()
.map((entry) -> addPermission(plugin, entry.getKey(), "", getPermissionDefault(entry.getValue())))
@@ -81,7 +88,7 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
.toList();
if (!childNodes.isEmpty()) {
addPermission(plugin, command.getPermission("*"), command.getUsage(), PermissionDefault.FALSE,
- childNodes.toArray(new Permission[0]));
+ childNodes.toArray((plugin) -> new Permission[0]));
}
// Set command parameters
@@ -97,8 +104,9 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
}
@Nullable
- protected static Permission addPermission(@NotNull BukkitHuskHomes plugin, @NotNull String node, @NotNull String description,
- @NotNull PermissionDefault permissionDefault, @NotNull Permission... children) {
+ protected static Permission addPermission(@NotNull BukkitHuskHomes plugin, @NotNull String node,
+ @NotNull String description, @NotNull PermissionDefault permissionDefault,
+ @NotNull Permission... children) {
final Map childNodes = Arrays.stream(children)
.map(Permission::getName)
.collect(HashMap::new, (map, child) -> map.put(child, true), HashMap::putAll);
@@ -125,46 +133,62 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
}
/**
- * Commands available on the Bukkit HuskHomes implementation
+ * Commands available on the Bukkit HuskHomes implementation.
*/
public enum Type {
- HOME_COMMAND(new PrivateHomeCommand(BukkitHuskHomes.getInstance())),
- SET_HOME_COMMAND(new SetHomeCommand(BukkitHuskHomes.getInstance())),
- HOME_LIST_COMMAND(new PrivateHomeListCommand(BukkitHuskHomes.getInstance())),
- DEL_HOME_COMMAND(new DelHomeCommand(BukkitHuskHomes.getInstance())),
- EDIT_HOME_COMMAND(new EditHomeCommand(BukkitHuskHomes.getInstance())),
- PUBLIC_HOME_COMMAND(new PublicHomeCommand(BukkitHuskHomes.getInstance())),
- PUBLIC_HOME_LIST_COMMAND(new PublicHomeListCommand(BukkitHuskHomes.getInstance())),
- WARP_COMMAND(new WarpCommand(BukkitHuskHomes.getInstance())),
- SET_WARP_COMMAND(new SetWarpCommand(BukkitHuskHomes.getInstance())),
- WARP_LIST_COMMAND(new WarpListCommand(BukkitHuskHomes.getInstance())),
- DEL_WARP_COMMAND(new DelWarpCommand(BukkitHuskHomes.getInstance())),
- EDIT_WARP_COMMAND(new EditWarpCommand(BukkitHuskHomes.getInstance())),
- TP_COMMAND(new TpCommand(BukkitHuskHomes.getInstance())),
- TP_HERE_COMMAND(new TpHereCommand(BukkitHuskHomes.getInstance())),
- TPA_COMMAND(new TeleportRequestCommand(BukkitHuskHomes.getInstance(), TeleportRequest.Type.TPA)),
- TPA_HERE_COMMAND(new TeleportRequestCommand(BukkitHuskHomes.getInstance(), TeleportRequest.Type.TPA_HERE)),
- TPACCEPT_COMMAND(new TpRespondCommand(BukkitHuskHomes.getInstance(), true)),
- TPDECLINE_COMMAND(new TpRespondCommand(BukkitHuskHomes.getInstance(), false)),
- RTP_COMMAND(new RtpCommand(BukkitHuskHomes.getInstance())),
- TP_IGNORE_COMMAND(new TpIgnoreCommand(BukkitHuskHomes.getInstance())),
- TP_OFFLINE_COMMAND(new TpOfflineCommand(BukkitHuskHomes.getInstance())),
- TP_ALL_COMMAND(new TpAllCommand(BukkitHuskHomes.getInstance())),
- TPA_ALL_COMMAND(new TpaAllCommand(BukkitHuskHomes.getInstance())),
- SPAWN_COMMAND(new SpawnCommand(BukkitHuskHomes.getInstance())),
- SET_SPAWN_COMMAND(new SetSpawnCommand(BukkitHuskHomes.getInstance())),
- BACK_COMMAND(new BackCommand(BukkitHuskHomes.getInstance())),
- HUSKHOMES_COMMAND(new HuskHomesCommand(BukkitHuskHomes.getInstance()));
+ HOME_COMMAND(PrivateHomeCommand::new),
+ SET_HOME_COMMAND(SetHomeCommand::new),
+ HOME_LIST_COMMAND(PrivateHomeListCommand::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 Command command;
+ private final Function supplier;
- Type(@NotNull Command command) {
- this.command = command;
+ Type(@NotNull Function supplier) {
+ this.supplier = supplier;
}
@NotNull
- public Command getCommand() {
- return command;
+ public Command createCommand(@NotNull HuskHomes plugin) {
+ return supplier.apply(plugin);
}
+
+ @NotNull
+ public static List getCommands(@NotNull BukkitHuskHomes plugin) {
+ return Arrays.stream(values())
+ .map((type) -> {
+ Command command = type.createCommand(plugin);
+ if (plugin.getSettings().isCommandDisabled(command)) {
+ command = new DisabledCommand(command.getName(), plugin);
+ }
+ new BukkitCommand(command, plugin).register();
+ return command;
+ })
+ .filter((command) -> !(command instanceof DisabledCommand))
+ .toList();
+ }
+
}
}
\ No newline at end of file
diff --git a/bukkit/src/main/java/net/william278/huskhomes/event/BukkitEventDispatcher.java b/bukkit/src/main/java/net/william278/huskhomes/event/BukkitEventDispatcher.java
index 6dc5bec3..a0c087a7 100644
--- a/bukkit/src/main/java/net/william278/huskhomes/event/BukkitEventDispatcher.java
+++ b/bukkit/src/main/java/net/william278/huskhomes/event/BukkitEventDispatcher.java
@@ -36,83 +36,90 @@ import java.util.List;
public interface BukkitEventDispatcher extends EventDispatcher {
@Override
- default boolean fireIsCancelled(@NotNull T event) {
+ default @NotNull boolean fireIsCancelled(@NotNull T event) {
Bukkit.getPluginManager().callEvent((org.bukkit.event.Event) event);
return event instanceof Cancellable cancellable && cancellable.isCancelled();
}
@Override
+ @NotNull
default ITeleportEvent getTeleportEvent(@NotNull Teleport teleport) {
return teleport.getType() == Teleport.Type.BACK ? new TeleportBackEvent(teleport) : new TeleportEvent(teleport);
}
@Override
- default ITeleportWarmupEvent getTeleportWarmupEvent(@NotNull TimedTeleport teleport, int duration) {
+ default @NotNull ITeleportWarmupEvent getTeleportWarmupEvent(@NotNull TimedTeleport teleport, int duration) {
return new TeleportWarmupEvent(teleport, duration);
}
@Override
- default ISendTeleportRequestEvent getSendTeleportRequestEvent(@NotNull OnlineUser sender, @NotNull TeleportRequest request) {
+ default @NotNull ISendTeleportRequestEvent getSendTeleportRequestEvent(@NotNull OnlineUser sender,
+ @NotNull TeleportRequest request) {
return new SendTeleportRequestEvent(sender, request);
}
@Override
- default IReceiveTeleportRequestEvent getReceiveTeleportRequestEvent(@NotNull OnlineUser recipient, @NotNull TeleportRequest request) {
+ default @NotNull IReceiveTeleportRequestEvent getReceiveTeleportRequestEvent(@NotNull OnlineUser recipient,
+ @NotNull TeleportRequest request) {
return new ReceiveTeleportRequestEvent(recipient, request);
}
@Override
- default IReplyTeleportRequestEvent getReplyTeleportRequestEvent(@NotNull OnlineUser recipient, @NotNull TeleportRequest request) {
+ default @NotNull IReplyTeleportRequestEvent getReplyTeleportRequestEvent(@NotNull OnlineUser recipient,
+ @NotNull TeleportRequest request) {
return new ReplyTeleportRequestEvent(recipient, request);
}
@Override
- default IHomeCreateEvent getHomeCreateEvent(@NotNull User owner, @NotNull String name, @NotNull Position position, @NotNull CommandUser creator) {
+ default @NotNull IHomeCreateEvent getHomeCreateEvent(@NotNull User owner, @NotNull String name,
+ @NotNull Position position, @NotNull CommandUser creator) {
return new HomeCreateEvent(owner, name, position, creator);
}
@Override
- default IHomeEditEvent getHomeEditEvent(@NotNull Home home, @NotNull CommandUser editor) {
+ default @NotNull IHomeEditEvent getHomeEditEvent(@NotNull Home home, @NotNull CommandUser editor) {
return new HomeEditEvent(home, editor);
}
@Override
- default IHomeDeleteEvent getHomeDeleteEvent(@NotNull Home home, @NotNull CommandUser deleter) {
+ default @NotNull IHomeDeleteEvent getHomeDeleteEvent(@NotNull Home home, @NotNull CommandUser deleter) {
return new HomeDeleteEvent(home, deleter);
}
@Override
- default IWarpCreateEvent getWarpCreateEvent(@NotNull String name, @NotNull Position position, @NotNull CommandUser creator) {
+ default @NotNull IWarpCreateEvent getWarpCreateEvent(@NotNull String name, @NotNull Position position,
+ @NotNull CommandUser creator) {
return new WarpCreateEvent(name, position, creator);
}
@Override
- default IWarpEditEvent getWarpEditEvent(@NotNull Warp warp, @NotNull CommandUser editor) {
+ default @NotNull IWarpEditEvent getWarpEditEvent(@NotNull Warp warp, @NotNull CommandUser editor) {
return new WarpEditEvent(warp, editor);
}
@Override
- default IWarpDeleteEvent getWarpDeleteEvent(@NotNull Warp warp, @NotNull CommandUser deleter) {
+ default @NotNull IWarpDeleteEvent getWarpDeleteEvent(@NotNull Warp warp, @NotNull CommandUser deleter) {
return new WarpDeleteEvent(warp, deleter);
}
@Override
- default IHomeListEvent getViewHomeListEvent(@NotNull List homes, @NotNull CommandUser listViewer, boolean publicHomeList) {
+ default @NotNull IHomeListEvent getViewHomeListEvent(@NotNull List homes, @NotNull CommandUser listViewer,
+ boolean publicHomeList) {
return new HomeListEvent(homes, listViewer, publicHomeList);
}
@Override
- default IWarpListEvent getViewWarpListEvent(@NotNull List warps, @NotNull CommandUser listViewer) {
+ default @NotNull IWarpListEvent getViewWarpListEvent(@NotNull List warps, @NotNull CommandUser listViewer) {
return new WarpListEvent(warps, listViewer);
}
@Override
- default IDeleteAllHomesEvent getDeleteAllHomesEvent(@NotNull User user, @NotNull CommandUser deleter) {
+ default @NotNull IDeleteAllHomesEvent getDeleteAllHomesEvent(@NotNull User user, @NotNull CommandUser deleter) {
return new DeleteAllHomesEvent(user, deleter);
}
@Override
- default IDeleteAllWarpsEvent getDeleteAllWarpsEvent(@NotNull CommandUser deleter) {
+ default @NotNull IDeleteAllWarpsEvent getDeleteAllWarpsEvent(@NotNull CommandUser deleter) {
return new DeleteAllWarpsEvent(deleter);
}
diff --git a/bukkit/src/main/java/net/william278/huskhomes/event/HomeCreateEvent.java b/bukkit/src/main/java/net/william278/huskhomes/event/HomeCreateEvent.java
index 9eb21fba..08986873 100644
--- a/bukkit/src/main/java/net/william278/huskhomes/event/HomeCreateEvent.java
+++ b/bukkit/src/main/java/net/william278/huskhomes/event/HomeCreateEvent.java
@@ -37,7 +37,8 @@ public class HomeCreateEvent extends Event implements IHomeCreateEvent, Cancella
private final CommandUser creator;
private boolean cancelled;
- public HomeCreateEvent(@NotNull User owner, @NotNull String name, @NotNull Position position, @NotNull CommandUser creator) {
+ public HomeCreateEvent(@NotNull User owner, @NotNull String name, @NotNull Position position,
+ @NotNull CommandUser creator) {
this.owner = owner;
this.name = name;
this.position = position;
diff --git a/bukkit/src/main/java/net/william278/huskhomes/hook/PlaceholderAPIHook.java b/bukkit/src/main/java/net/william278/huskhomes/hook/PlaceholderAPIHook.java
index 65de4a92..e175feb3 100644
--- a/bukkit/src/main/java/net/william278/huskhomes/hook/PlaceholderAPIHook.java
+++ b/bukkit/src/main/java/net/william278/huskhomes/hook/PlaceholderAPIHook.java
@@ -21,7 +21,7 @@ package net.william278.huskhomes.hook;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
-import net.william278.huskhomes.HuskHomes;
+import net.william278.huskhomes.BukkitHuskHomes;
import net.william278.huskhomes.user.BukkitUser;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.SavedUser;
@@ -33,21 +33,21 @@ import java.util.List;
public class PlaceholderAPIHook extends Hook {
- public PlaceholderAPIHook(@NotNull HuskHomes plugin) {
+ public PlaceholderAPIHook(@NotNull BukkitHuskHomes plugin) {
super(plugin, "PlaceholderAPI");
}
@Override
public void initialize() {
- new HuskHomesExpansion(plugin).register();
+ new HuskHomesExpansion((BukkitHuskHomes) plugin).register();
}
public static class HuskHomesExpansion extends PlaceholderExpansion {
@NotNull
- private final HuskHomes plugin;
+ private final BukkitHuskHomes plugin;
- private HuskHomesExpansion(@NotNull HuskHomes plugin) {
+ private HuskHomesExpansion(@NotNull BukkitHuskHomes plugin) {
this.plugin = plugin;
}
@@ -59,7 +59,7 @@ public class PlaceholderAPIHook extends Hook {
}
// Return the requested data
- final OnlineUser player = BukkitUser.adapt(offlinePlayer.getPlayer());
+ final OnlineUser player = BukkitUser.adapt(offlinePlayer.getPlayer(), plugin);
return switch (params) {
case "homes_count" -> String.valueOf(plugin.getManager().homes()
.getUserHomes()
diff --git a/bukkit/src/main/java/net/william278/huskhomes/hook/VaultEconomyHook.java b/bukkit/src/main/java/net/william278/huskhomes/hook/VaultEconomyHook.java
index 170c5367..923524d7 100644
--- a/bukkit/src/main/java/net/william278/huskhomes/hook/VaultEconomyHook.java
+++ b/bukkit/src/main/java/net/william278/huskhomes/hook/VaultEconomyHook.java
@@ -29,7 +29,7 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import org.jetbrains.annotations.NotNull;
/**
- * A hook that hooks into the Vault API to provide economy features
+ * A hook that hooks into the Vault API to provide economy features.
*/
public class VaultEconomyHook extends EconomyHook {
diff --git a/bukkit/src/main/java/net/william278/huskhomes/importer/EssentialsXImporter.java b/bukkit/src/main/java/net/william278/huskhomes/importer/EssentialsXImporter.java
index f1cfb2b4..696796f7 100644
--- a/bukkit/src/main/java/net/william278/huskhomes/importer/EssentialsXImporter.java
+++ b/bukkit/src/main/java/net/william278/huskhomes/importer/EssentialsXImporter.java
@@ -38,7 +38,8 @@ public class EssentialsXImporter extends Importer {
public EssentialsXImporter(@NotNull HuskHomes plugin) {
super("EssentialsX", List.of(ImportData.HOMES, ImportData.WARPS), plugin);
- this.essentials = (Essentials) ((BukkitHuskHomes) plugin).getServer().getPluginManager().getPlugin("Essentials");
+ this.essentials = (Essentials) ((BukkitHuskHomes) plugin).getServer()
+ .getPluginManager().getPlugin("Essentials");
}
private int importHomes() {
diff --git a/bukkit/src/main/java/net/william278/huskhomes/listener/BukkitEventListener.java b/bukkit/src/main/java/net/william278/huskhomes/listener/BukkitEventListener.java
index 84f017bc..911e8f3e 100644
--- a/bukkit/src/main/java/net/william278/huskhomes/listener/BukkitEventListener.java
+++ b/bukkit/src/main/java/net/william278/huskhomes/listener/BukkitEventListener.java
@@ -38,24 +38,24 @@ public class BukkitEventListener extends EventListener implements Listener {
protected boolean checkForBed = true;
- public BukkitEventListener(@NotNull BukkitHuskHomes huskHomes) {
- super(huskHomes);
- huskHomes.getServer().getPluginManager().registerEvents(this, huskHomes);
+ public BukkitEventListener(@NotNull BukkitHuskHomes plugin) {
+ super(plugin);
+ plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent event) {
- super.handlePlayerJoin(BukkitUser.adapt(event.getPlayer()));
+ super.handlePlayerJoin(BukkitUser.adapt(event.getPlayer(), (BukkitHuskHomes) plugin));
}
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerLeave(PlayerQuitEvent event) {
- super.handlePlayerLeave(BukkitUser.adapt(event.getPlayer()));
+ super.handlePlayerLeave(BukkitUser.adapt(event.getPlayer(), (BukkitHuskHomes) plugin));
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerDeath(PlayerDeathEvent event) {
- super.handlePlayerDeath(BukkitUser.adapt(event.getEntity()));
+ super.handlePlayerDeath(BukkitUser.adapt(event.getEntity(), (BukkitHuskHomes) plugin));
}
@EventHandler(priority = EventPriority.NORMAL)
@@ -63,7 +63,7 @@ public class BukkitEventListener extends EventListener implements Listener {
if (event.getRespawnReason() != PlayerRespawnEvent.RespawnReason.DEATH) {
return;
}
- super.handlePlayerRespawn(BukkitUser.adapt(event.getPlayer()));
+ super.handlePlayerRespawn(BukkitUser.adapt(event.getPlayer(), (BukkitHuskHomes) plugin));
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@@ -71,29 +71,37 @@ public class BukkitEventListener extends EventListener implements Listener {
final Player player = event.getPlayer();
// Return if the disconnecting entity is a Citizens NPC, or if the teleport was naturally caused
- if (player.hasMetadata("NPC")) return;
+ if (player.hasMetadata("NPC")) {
+ return;
+ }
if (!(event.getCause() == PlayerTeleportEvent.TeleportCause.COMMAND
- || event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN)) return;
+ || event.getCause() == PlayerTeleportEvent.TeleportCause.PLUGIN)) {
+ return;
+ }
- final BukkitUser bukkitUser = BukkitUser.adapt(player);
+ final BukkitUser bukkitUser = BukkitUser.adapt(player, (BukkitHuskHomes) plugin);
BukkitAdapter.adaptLocation(event.getFrom()).ifPresent(sourceLocation ->
handlePlayerTeleport(bukkitUser, Position.at(sourceLocation, plugin.getServerName())));
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerUpdateRespawnLocation(PlayerInteractEvent event) {
- if (!checkForBed) return;
- if (!(plugin.getSettings().doCrossServer() && plugin.getSettings().isGlobalRespawning())) return;
- if (event.getClickedBlock() == null) return;
- if (!(event.getClickedBlock().getBlockData() instanceof Bed
- || event.getClickedBlock().getBlockData() instanceof RespawnAnchor)) return;
+ if (!checkForBed || !(plugin.getSettings().doCrossServer() && plugin.getSettings().isGlobalRespawning())) {
+ return;
+ }
+ if (event.getClickedBlock() == null || !(event.getClickedBlock().getBlockData() instanceof Bed
+ || event.getClickedBlock().getBlockData() instanceof RespawnAnchor)) {
+ return;
+ }
final Location location = event.getPlayer().getBedSpawnLocation();
- if (location == null) return;
+ if (location == null) {
+ return;
+ }
// Update the player's respawn location
BukkitAdapter.adaptLocation(location).ifPresent(adaptedLocation -> super.handlePlayerUpdateSpawnPoint(
- BukkitUser.adapt(event.getPlayer()),
+ BukkitUser.adapt(event.getPlayer(), (BukkitHuskHomes) plugin),
Position.at(adaptedLocation, plugin.getServerName()))
);
}
diff --git a/bukkit/src/main/java/net/william278/huskhomes/user/BukkitUser.java b/bukkit/src/main/java/net/william278/huskhomes/user/BukkitUser.java
index 53f54579..008ac5d2 100644
--- a/bukkit/src/main/java/net/william278/huskhomes/user/BukkitUser.java
+++ b/bukkit/src/main/java/net/william278/huskhomes/user/BukkitUser.java
@@ -38,34 +38,45 @@ import java.util.logging.Level;
import java.util.stream.Collectors;
/**
- * Bukkit implementation of an {@link OnlineUser}
+ * Bukkit's implementation of an {@link OnlineUser}.
*/
public class BukkitUser extends OnlineUser {
private final BukkitHuskHomes plugin;
private final Player player;
- private BukkitUser(@NotNull Player player) {
+ private BukkitUser(@NotNull Player player, @NotNull BukkitHuskHomes plugin) {
super(player.getUniqueId(), player.getName());
- this.plugin = BukkitHuskHomes.getInstance();
this.player = player;
+ this.plugin = plugin;
}
/**
- * Adapt a {@link Player} to a {@link OnlineUser}
+ * Adapt a {@link Player} to a {@link OnlineUser}.
*
* @param player the online {@link Player} to adapt
* @return the adapted {@link OnlineUser}
*/
@NotNull
- public static BukkitUser adapt(@NotNull Player player) {
- return new BukkitUser(player);
+ public static BukkitUser adapt(@NotNull Player player, @NotNull BukkitHuskHomes plugin) {
+ return new BukkitUser(player, plugin);
+ }
+
+ /**
+ * Return the {@link Player} wrapped by this {@link BukkitUser}.
+ *
+ * @return the {@link Player} wrapped by this {@link BukkitUser}
+ */
+ @NotNull
+ public Player getPlayer() {
+ return player;
}
@Override
public Position getPosition() {
- return Position.at(BukkitAdapter.adaptLocation(player.getLocation())
- .orElseThrow(() -> new IllegalStateException("Failed to get the position of a BukkitPlayer (null)")),
+ return Position.at(BukkitAdapter.adaptLocation(player.getLocation()).orElseThrow(
+ () -> new IllegalStateException("Failed to get the position of a BukkitPlayer (null)")
+ ),
plugin.getServerName());
}
@@ -104,7 +115,7 @@ public class BukkitUser extends OnlineUser {
}
@Override
- public void teleportLocally(@NotNull Location location, boolean asynchronous) throws TeleportationException {
+ public void teleportLocally(@NotNull Location location, boolean async) throws TeleportationException {
// Ensure the world exists
final Optional resolvedLocation = BukkitAdapter.adaptLocation(location);
if (resolvedLocation.isEmpty() || resolvedLocation.get().getWorld() == null) {
@@ -120,7 +131,7 @@ public class BukkitUser extends OnlineUser {
// Run on the appropriate thread scheduler for this platform
plugin.getScheduler().entitySpecificScheduler(player).run(
() -> {
- if (asynchronous || plugin.getScheduler().isUsingFolia()) {
+ if (async || plugin.getScheduler().isUsingFolia()) {
PaperLib.teleportAsync(player, bukkitLocation, PlayerTeleportEvent.TeleportCause.PLUGIN);
return;
}
@@ -131,7 +142,7 @@ public class BukkitUser extends OnlineUser {
}
/**
- * Get the player momentum and return if they are moving
+ * Get the player momentum and return if they are moving.
*
* @return {@code true} if the player is moving, {@code false} otherwise
**/
@@ -141,7 +152,7 @@ public class BukkitUser extends OnlineUser {
}
/**
- * Return the value of the player's "vanished" metadata tag if they have it
+ * Return the value of the player's "vanished" metadata tag if they have it.
*
* @return {@code true} if the player is vanished, {@code false} otherwise
*/
@@ -155,18 +166,10 @@ public class BukkitUser extends OnlineUser {
}
/**
- * Send a Bukkit plugin message to the player
+ * Send a Bukkit plugin message to the player.
*/
public void sendPluginMessage(@NotNull String channel, final byte[] message) {
player.sendPluginMessage(plugin, channel, message);
}
- /**
- * Return the {@link Player} wrapped by this {@link BukkitUser}
- *
- * @return the {@link Player} wrapped by this {@link BukkitUser}
- */
- public Player getPlayer() {
- return player;
- }
}
diff --git a/bukkit/src/main/java/net/william278/huskhomes/util/BukkitAdapter.java b/bukkit/src/main/java/net/william278/huskhomes/util/BukkitAdapter.java
index 0a480ef0..cf853422 100644
--- a/bukkit/src/main/java/net/william278/huskhomes/util/BukkitAdapter.java
+++ b/bukkit/src/main/java/net/william278/huskhomes/util/BukkitAdapter.java
@@ -28,12 +28,12 @@ import org.jetbrains.annotations.Nullable;
import java.util.Optional;
/**
- * Static class providing utility methods for adapting Bukkit objects to HuskHomes and vice versa
+ * Static class providing utility methods for adapting Bukkit objects to HuskHomes and vice versa.
*/
public final class BukkitAdapter {
/**
- * Adapt a Bukkit {@link org.bukkit.Location} to a HuskHomes {@link Location}
+ * Adapt a Bukkit {@link org.bukkit.Location} to a HuskHomes {@link Location}.
*
* @param location the Bukkit {@link org.bukkit.Location} to adapt
* @return the adapted {@link Location}
@@ -45,8 +45,9 @@ public final class BukkitAdapter {
}
if (world == null) {
world = Bukkit.getWorlds().stream()
- .filter(w -> w.getEnvironment().name().equalsIgnoreCase(location.getWorld().getEnvironment().name()))
- .findFirst().orElse(null);
+ .filter(w -> w.getEnvironment().name().equalsIgnoreCase(
+ location.getWorld().getEnvironment().name())).findFirst()
+ .orElse(null);
}
if (world == null) {
return Optional.empty();
@@ -62,13 +63,15 @@ public final class BukkitAdapter {
}
/**
- * Adapt a HuskHomes {@link org.bukkit.Location} to a Bukkit {@link org.bukkit.Location}
+ * Adapt a HuskHomes {@link org.bukkit.Location} to a Bukkit {@link org.bukkit.Location}.
*
* @param location the HuskHomes {@link org.bukkit.Location} to adapt
* @return the adapted {@link org.bukkit.Location}
*/
public static Optional adaptLocation(@NotNull org.bukkit.Location location) {
- if (location.getWorld() == null) return Optional.empty();
+ if (location.getWorld() == null) {
+ return Optional.empty();
+ }
return Optional.of(Location.at(location.getX(), location.getY(), location.getZ(),
location.getYaw(), location.getPitch(),
adaptWorld(location.getWorld()).orElse(new net.william278.huskhomes.position.World())));
@@ -78,12 +81,13 @@ public final class BukkitAdapter {
if (world == null) {
return Optional.empty();
}
- return Optional.of(World.from(world.getName(), world.getUID(),
+ return Optional.of(World.from(
+ world.getName(), world.getUID(),
switch (world.getEnvironment()) {
case NORMAL -> World.Environment.OVERWORLD;
case NETHER -> World.Environment.NETHER;
case THE_END -> World.Environment.THE_END;
- case CUSTOM -> World.Environment.CUSTOM;
+ default -> World.Environment.CUSTOM;
})
);
}
diff --git a/bukkit/src/main/java/net/william278/huskhomes/util/BukkitSafetyResolver.java b/bukkit/src/main/java/net/william278/huskhomes/util/BukkitSafetyResolver.java
index 921c9767..2cedf58f 100644
--- a/bukkit/src/main/java/net/william278/huskhomes/util/BukkitSafetyResolver.java
+++ b/bukkit/src/main/java/net/william278/huskhomes/util/BukkitSafetyResolver.java
@@ -54,49 +54,50 @@ public interface BukkitSafetyResolver extends SafetyResolver {
}
/**
- * Search for a safe ground location near the given location
+ * Search for a safe ground location near the given location.
*
* @param location The location to search around
- * @param snapshot The chunk snapshot to search
+ * @param chunk The chunk snapshot to search
* @param minY The minimum Y value of the world
* @return An optional safe location, within 4 blocks of the given location
*/
- private Optional findSafeLocationNear(@NotNull Location location, @NotNull ChunkSnapshot snapshot, int minY) {
+ private Optional findSafeLocationNear(@NotNull Location location, @NotNull ChunkSnapshot chunk,
+ int minY) {
final int chunkX = ((int) location.getX()) & 0xF;
final int chunkZ = ((int) location.getZ()) & 0xF;
- for (int dX = -SEARCH_RADIUS; dX <= SEARCH_RADIUS; dX++) {
- for (int dZ = -SEARCH_RADIUS; dZ <= SEARCH_RADIUS; dZ++) {
- final int x = chunkX + dX;
- final int z = chunkZ + dZ;
+ for (int dx = -SEARCH_RADIUS; dx <= SEARCH_RADIUS; dx++) {
+ for (int dz = -SEARCH_RADIUS; dz <= SEARCH_RADIUS; dz++) {
+ final int x = chunkX + dx;
+ final int z = chunkZ + dz;
if (x < 0 || x >= 16 || z < 0 || z >= 16) {
continue;
}
- final int y = Math.max((minY + 1), snapshot.getHighestBlockYAt(x, z)) + 1;
- final Material blockType = snapshot.getBlockType(x, y - 1, z);
- final Material bodyBlockType = snapshot.getBlockType(x, y, z);
- final Material headBlockType = snapshot.getBlockType(x, y + 1, z);
+ final int y = Math.max((minY + 1), chunk.getHighestBlockYAt(x, z)) + 1;
+ final Material blockType = chunk.getBlockType(x, y - 1, z);
+ final Material bodyBlockType = chunk.getBlockType(x, y, z);
+ final Material headBlockType = chunk.getBlockType(x, y + 1, z);
if (isBlockSafeForStanding(blockType.getKey().toString())
- && isBlockSafeForOccupation(bodyBlockType.getKey().toString())
- && isBlockSafeForOccupation(headBlockType.getKey().toString())) {
- double locx = Math.floor(location.getX()) + dX;
- if (locx < 0) {
- locx += 1.5d;
- } else {
- locx = locx + 0.5d;
- }
- double locz = Math.floor(location.getZ()) + dZ;
- if (locz < 0) {
- locz += 1.5d;
- } else {
- locz = locz + 0.5d;
- }
- return Optional.of(Location.at(
- locx,
- y,
- locz,
- location.getWorld()
- ));
+ && isBlockSafeForOccupation(bodyBlockType.getKey().toString())
+ && isBlockSafeForOccupation(headBlockType.getKey().toString())) {
+ double locx = Math.floor(location.getX()) + dx;
+ if (locx < 0) {
+ locx += 1.5d;
+ } else {
+ locx = locx + 0.5d;
+ }
+ double locz = Math.floor(location.getZ()) + dz;
+ if (locz < 0) {
+ locz += 1.5d;
+ } else {
+ locz = locz + 0.5d;
+ }
+ return Optional.of(Location.at(
+ locx,
+ y,
+ locz,
+ location.getWorld()
+ ));
}
}
}
diff --git a/bukkit/src/test/java/net/william278/huskhomes/BukkitPluginTests.java b/bukkit/src/test/java/net/william278/huskhomes/BukkitPluginTests.java
index abfa63e4..d8fe5804 100644
--- a/bukkit/src/test/java/net/william278/huskhomes/BukkitPluginTests.java
+++ b/bukkit/src/test/java/net/william278/huskhomes/BukkitPluginTests.java
@@ -77,7 +77,7 @@ public class BukkitPluginTests {
@DisplayName("Test Command Registration")
public void testCommandRegistration() {
for (BukkitCommand.Type command : BukkitCommand.Type.values()) {
- Assertions.assertNotNull(plugin.getCommand(command.getCommand().getName()));
+ Assertions.assertNotNull(plugin.getCommand(command.createCommand(plugin).getName()));
}
Assertions.assertEquals(BukkitCommand.Type.values().length, plugin.getCommands().size());
}
@@ -86,7 +86,7 @@ public class BukkitPluginTests {
@DisplayName("Test Player Adapter")
public void testPlayerAdaption() {
PlayerMock player = server.addPlayer();
- Assertions.assertNotNull(BukkitUser.adapt(player));
+ Assertions.assertNotNull(BukkitUser.adapt(player, plugin));
}
}
@@ -105,22 +105,22 @@ 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).sendMessage(simpleLocale);
+ BukkitUser.adapt(player, plugin).sendMessage(simpleLocale);
player.assertSaid(simpleLocaleText);
}
@Test
@DisplayName("Test Message Dispatching")
public void testMessageDispatching() {
- PlayerMock player = server.addPlayer();
+ final BukkitUser user = BukkitUser.adapt(server.addPlayer(), plugin);
final MineDown locale = plugin.getLocales()
.getLocale("teleporting_action_bar_warmup", Integer.toString(3))
.orElseThrow(() -> new IllegalStateException("Failed to load locale"));
- BukkitUser.adapt(player).sendActionBar(locale);
- BukkitUser.adapt(player).sendMessage(locale);
- BukkitUser.adapt(player).sendTitle(locale, false);
- BukkitUser.adapt(player).sendTitle(locale, true);
+ user.sendActionBar(locale);
+ user.sendMessage(locale);
+ user.sendTitle(locale, false);
+ user.sendTitle(locale, true);
}
@Test
@@ -135,11 +135,11 @@ public class BukkitPluginTests {
@DisplayName("Test Locale Parsing")
public void testLocaleParsing() {
final Map rawLocales = plugin.getLocales().rawLocales;
- BukkitUser bukkitUser = BukkitUser.adapt(server.addPlayer());
+ BukkitUser user = BukkitUser.adapt(server.addPlayer(), plugin);
rawLocales.forEach((key, value) -> {
Optional locale = plugin.getLocales().getLocale(key);
Assertions.assertTrue(locale.isPresent());
- bukkitUser.sendMessage(locale.get());
+ user.sendMessage(locale.get());
});
}
@@ -174,7 +174,7 @@ public class BukkitPluginTests {
final PlayerMock player = server.addPlayer();
player.setOp(true);
- final BukkitUser playerUser = BukkitUser.adapt(player);
+ final BukkitUser playerUser = BukkitUser.adapt(player, plugin);
return commands.stream()
.flatMap(command -> Stream.of(Arguments.of(command, playerUser, command.getName())));
}
@@ -194,14 +194,18 @@ public class BukkitPluginTests {
@DisplayName("Test Validator Accepts Valid Names")
@ParameterizedTest(name = "Valid Name: \"{0}\"")
- @ValueSource(strings = {"ValidName", "Valid_Name", "Valid-Name", "ValidN4me", "ValidName123", "ValidName-123", "ValidName_123", "V"})
+ @ValueSource(strings = {
+ "ValidName", "Valid_Name", "Valid-Name", "ValidN4me", "ValidName123", "VN-123", "ValidName_123", "V"
+ })
public void testValidNameIsValid(@NotNull String name) {
Assertions.assertTrue(plugin.getValidator().isValidName(name));
}
@DisplayName("Test Validator Rejects Invalid Names")
@ParameterizedTest(name = "Invalid Name: \"{0}\"")
- @ValueSource(strings = {"Invalid Name", "•♣♠", "Invali♣Name", "Invalid.Name", "", " ", "\0", "InvalidName12345678901234567890"})
+ @ValueSource(strings = {
+ "Invalid Name", "•♣♠", "Invali♣Name", "Invalid.Name", "", " ", "\0", "InvalidName12345678901234567890"
+ })
public void testInvalidNameIsInvalid(@NotNull String name) {
Assertions.assertFalse(plugin.getValidator().isValidName(name));
}
@@ -212,8 +216,8 @@ public class BukkitPluginTests {
"Lorem ipsum text", "Lorem ipsum text with special characters •♣♠",
"Lorem ipsum text with special characters •♣♠ and numbers 1234567890",
"Lorem ipsum text with special characters •♣♠ and numbers 1234567890 and whitespace",
- "Lorem ipsum text with special characters •♣♠ and numbers 1234567890 and whitespace and a very long" +
- " description that is 255 characters long and should be accepted by the validator"
+ "Lorem ipsum text with special characters •♣♠ and numbers 1234567890 and whitespace and a very long"
+ + " description that is 255 characters long and should be accepted by the validator"
})
public void testValidDescriptionIsValid(@NotNull String description) {
Assertions.assertTrue(plugin.getValidator().isValidDescription(description));
@@ -221,10 +225,12 @@ public class BukkitPluginTests {
@DisplayName("Test Validator Rejects Invalid Descriptions")
@ParameterizedTest(name = "Invalid Description: \"{0}\"")
- @ValueSource(strings = {"Lorem ipsum text with special characters •♣♠ and numbers 1234567890 and whitespace and" +
- "a very long description that is more than 256 characters long and should be rejected " +
- "by the validator because it is far, far too long and thus exceeds the maximum length " +
- "of 255 characters that are allowed for a description of a home or a warp."})
+ @ValueSource(strings = {
+ "Lorem ipsum text with special characters •♣♠ and numbers 1234567890 and whitespace and"
+ + "a very long description that is more than 256 characters long and should be rejected "
+ + "by the validator because it is far, far too long and thus exceeds the maximum length "
+ + "of 255 characters that are allowed for a description of a home or a warp."
+ })
public void testInvalidDescriptionIsInvalid(@NotNull String description) {
Assertions.assertFalse(plugin.getValidator().isValidDescription(description));
}
@@ -241,7 +247,7 @@ public class BukkitPluginTests {
@BeforeAll
public static void setup() {
- player = BukkitUser.adapt(server.addPlayer());
+ player = BukkitUser.adapt(server.addPlayer(), plugin);
}
@DisplayName("Test Applying Cooldown")
@@ -283,7 +289,14 @@ public class BukkitPluginTests {
@DisplayName("Warp Tests")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class WarpTests {
- private static final List WARP_NAMES = List.of("warple", "example", "exmaination", "123234__44", "a", "1");
+ private static final List WARP_NAMES = List.of(
+ "warple",
+ "example",
+ "exmaination",
+ "123234__44",
+ "a",
+ "1"
+ );
@DisplayName("Test Warp Creation")
@ParameterizedTest(name = "Warp Name: \"{0}\"")
@@ -302,7 +315,8 @@ public class BukkitPluginTests {
@ParameterizedTest(name = "Rename: \"{0}\" > \"{0}2\"")
@MethodSource("provideWarpData")
@Order(2)
- public void testWarpRenaming(@NotNull String name, @SuppressWarnings("unused") @NotNull Position position) {
+ @SuppressWarnings("unused")
+ public void testWarpRenaming(@NotNull String name, @NotNull Position position) {
final String newName = (name + "2");
plugin.getManager().warps().setWarpName(name, newName);
Assertions.assertTrue(plugin.getDatabase().getWarp(newName).isPresent());
@@ -322,7 +336,8 @@ public class BukkitPluginTests {
@ParameterizedTest(name = "Edit Description: \"{0}\"")
@MethodSource("provideWarpData")
@Order(3)
- public void testWarpChangingDescription(@NotNull String name, @SuppressWarnings("unused") @NotNull Position position) {
+ @SuppressWarnings("unused")
+ public void testWarpChangingDescription(@NotNull String name, @NotNull Position position) {
final String description = "This is a test description for " + name + ".";
plugin.getManager().warps().setWarpDescription(name, description);
final Optional warpDescription = plugin.getDatabase().getWarp(name)
@@ -338,8 +353,11 @@ public class BukkitPluginTests {
@Order(4)
public void testWarpRelocation(@NotNull String name, @NotNull Position position) {
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
- final Position newPosition = Position.at(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
- 0, 0, world, plugin.getServerName());
+ final Position newPosition = Position.at(
+ position.getX() + 10, position.getY() + 10, position.getZ() + 10,
+ 0, 0,
+ world, plugin.getServerName()
+ );
plugin.getManager().warps().setWarpPosition(name, newPosition);
final Optional warpPosition = plugin.getDatabase().getWarp(name).map(warp -> warp);
@@ -355,8 +373,11 @@ public class BukkitPluginTests {
@Order(5)
public void testWarpOverwrite(@NotNull String name, @NotNull Position position) {
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
- final Position newPosition = Position.at(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
- 0, 0, world, plugin.getServerName());
+ final Position newPosition = Position.at(
+ position.getX() + 10, position.getY() + 10, position.getZ() + 10,
+ 0, 0,
+ world, plugin.getServerName()
+ );
plugin.getManager().warps().createWarp(name, newPosition, true);
final Optional warpPosition = plugin.getDatabase().getWarp(name).map(warp -> warp);
@@ -370,7 +391,8 @@ public class BukkitPluginTests {
@ParameterizedTest(name = "Delete Warp: \"{0}\"")
@MethodSource("provideWarpData")
@Order(6)
- public void testWarpDeletion(@NotNull String name, @SuppressWarnings("unused") @NotNull Position position) {
+ @SuppressWarnings("unused")
+ public void testWarpDeletion(@NotNull String name, @NotNull Position position) {
plugin.getManager().warps().deleteWarp(name);
Assertions.assertFalse(plugin.getDatabase().getWarp(name).isPresent());
Assertions.assertFalse(plugin.getManager().warps()
@@ -385,7 +407,8 @@ public class BukkitPluginTests {
@ParameterizedTest(name = "Query: \"{0}\"")
@MethodSource("provideWarpData")
@Order(8)
- public void testWarpCaseInsensitiveQuery(@NotNull String name, @SuppressWarnings("unused") @NotNull Position position) {
+ @SuppressWarnings("unused")
+ public void testWarpCaseInsensitiveQuery(@NotNull String name, @NotNull Position position) {
final String nameUpper = name.toUpperCase();
final Optional nameUpperWarp = plugin.getDatabase().getWarp(nameUpper, true);
Assertions.assertTrue(nameUpperWarp.isPresent());
@@ -421,13 +444,21 @@ public class BukkitPluginTests {
@DisplayName("Home Tests")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class HomeTests {
- private static final List HOME_NAMES = List.of("mr_home", "homble", "seaside", "hovel", "tokyo-3", "testington", "h");
+ private static final List HOME_NAMES = List.of(
+ "mr_home",
+ "homble",
+ "seaside",
+ "hovel",
+ "tokyo-3",
+ "testington",
+ "h"
+ );
private static BukkitUser homeOwner;
@DisplayName("Ensure User Data")
@BeforeAll
public static void createHomeUser() {
- homeOwner = BukkitUser.adapt(server.addPlayer("TestUser278"));
+ homeOwner = BukkitUser.adapt(server.addPlayer("TestUser278"), plugin);
plugin.getDatabase().ensureUser(homeOwner);
Assertions.assertTrue(plugin.getDatabase().getUserData(homeOwner.getUuid()).isPresent());
}
@@ -449,7 +480,8 @@ public class BukkitPluginTests {
@ParameterizedTest(name = "Rename: \"{1}\" > \"{1}2\"")
@MethodSource("provideHomeData")
@Order(2)
- public void testHomeRenaming(@NotNull OnlineUser owner, @NotNull String name, @SuppressWarnings("unused") @NotNull Position position) {
+ @SuppressWarnings("unused")
+ public void testHomeRenaming(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position position) {
final String newName = "new_" + name;
plugin.getManager().homes().setHomeName(owner, name, newName);
Assertions.assertTrue(plugin.getDatabase().getHome(owner, newName).isPresent());
@@ -476,7 +508,8 @@ public class BukkitPluginTests {
@ParameterizedTest(name = "Edit Description: \"{1}\"")
@MethodSource("provideHomeData")
@Order(3)
- public void testHomeDescription(@NotNull OnlineUser owner, @NotNull String name, @SuppressWarnings("unused") @NotNull Position position) {
+ @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 + "!";
plugin.getManager().homes().setHomeDescription(owner, name, description);
Assertions.assertTrue(plugin.getDatabase().getHome(owner, name).isPresent());
@@ -494,8 +527,11 @@ public class BukkitPluginTests {
@Order(4)
public void testHomeRelocation(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position position) {
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
- final Position newPosition = Position.at(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
- 0, 0, world, plugin.getServerName());
+ final Position newPosition = Position.at(
+ position.getX() + 10, position.getY() + 10, position.getZ() + 10,
+ 0, 0,
+ world, plugin.getServerName()
+ );
plugin.getManager().homes().setHomePosition(owner, name, newPosition);
Assertions.assertTrue(plugin.getDatabase().getHome(owner, name).isPresent());
@@ -512,8 +548,11 @@ public class BukkitPluginTests {
@Order(5)
public void testHomeOverwrite(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position position) {
final World world = BukkitAdapter.adaptWorld(server.getWorld("world")).orElseThrow();
- final Position newPosition = Position.at(position.getX() + 10, position.getY() + 10, position.getZ() + 10,
- 0, 0, world, plugin.getServerName());
+ final Position newPosition = Position.at(
+ position.getX() + 10, position.getY() + 10, position.getZ() + 10,
+ 0, 0,
+ world, plugin.getServerName()
+ );
plugin.getManager().homes().setHomePosition(owner, name, newPosition);
Assertions.assertTrue(plugin.getDatabase().getHome(owner, name).isPresent());
@@ -528,7 +567,8 @@ public class BukkitPluginTests {
@ParameterizedTest(name = "Make Public: \"{1}\"")
@MethodSource("provideHomeData")
@Order(6)
- public void testHomeMakePublic(@NotNull OnlineUser owner, @NotNull String name, @SuppressWarnings("unused") @NotNull Position position) {
+ @SuppressWarnings("unused")
+ public void testHomeMakePublic(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position p) {
plugin.getManager().homes().setHomePrivacy(owner, name, true);
Assertions.assertTrue(plugin.getDatabase().getHome(owner, name).isPresent());
@@ -542,7 +582,8 @@ public class BukkitPluginTests {
@ParameterizedTest(name = "Make Private: \"{1}\"")
@MethodSource("provideHomeData")
@Order(7)
- public void testHomeMakePrivate(@NotNull OnlineUser owner, @NotNull String name, @SuppressWarnings("unused") @NotNull Position position) {
+ @SuppressWarnings("unused")
+ public void testHomeMakePrivate(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position p) {
plugin.getManager().homes().setHomePrivacy(owner, name, false);
Assertions.assertTrue(plugin.getDatabase().getHome(owner, name).isPresent());
@@ -558,7 +599,8 @@ public class BukkitPluginTests {
@ParameterizedTest(name = "Query: \"{1}\"")
@MethodSource("provideHomeData")
@Order(8)
- public void testWarpCaseInsensitiveQuery(@NotNull OnlineUser owner, @NotNull String name, @SuppressWarnings("unused") @NotNull Position position) {
+ @SuppressWarnings("unused")
+ public void testWarpCaseInsensitiveQuery(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position p) {
final String nameUpper = name.toUpperCase();
final Optional nameUpperWarp = plugin.getDatabase().getHome(owner, nameUpper, true);
Assertions.assertTrue(nameUpperWarp.isPresent());
@@ -574,7 +616,7 @@ public class BukkitPluginTests {
@ParameterizedTest(name = "Delete: \"{1}\"")
@MethodSource("provideHomeData")
@Order(9)
- public void testHomeDeletion(@NotNull OnlineUser owner, @NotNull String name, @SuppressWarnings("unused") @NotNull Position position) {
+ public void testHomeDeletion(@NotNull OnlineUser owner, @NotNull String name, @NotNull Position position) {
plugin.getManager().homes().deleteHome(owner, name);
Assertions.assertFalse(plugin.getDatabase().getHome(owner, name).isPresent());
Assertions.assertFalse(plugin.getManager().homes().getUserHomes()
@@ -603,4 +645,4 @@ public class BukkitPluginTests {
}
}
-}
\ No newline at end of file
+}
diff --git a/common/build.gradle b/common/build.gradle
index b999af48..fabc5d46 100644
--- a/common/build.gradle
+++ b/common/build.gradle
@@ -25,7 +25,7 @@ dependencies {
compileOnly 'com.mysql:mysql-connector-j:' + mysql_driver_version
compileOnly 'org.jetbrains:annotations:24.0.1'
- compileOnly 'com.google.guava:guava:32.0.1-jre'
+ compileOnly 'com.google.guava:guava:32.1.0-jre'
compileOnly 'com.github.plan-player-analytics:Plan:5.5.2391'
compileOnly 'com.github.BlueMap-Minecraft:BlueMapAPI:2.5.0'
compileOnly 'us.dynmap:DynmapCoreAPI:3.4'
diff --git a/common/src/main/java/net/william278/huskhomes/HuskHomes.java b/common/src/main/java/net/william278/huskhomes/HuskHomes.java
index fe13db76..f6836b96 100644
--- a/common/src/main/java/net/william278/huskhomes/HuskHomes.java
+++ b/common/src/main/java/net/william278/huskhomes/HuskHomes.java
@@ -61,17 +61,25 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
- * Represents a cross-platform instance of the plugin
+ * Represents a cross-platform instance of the plugin.
*/
public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolver, TransactionResolver {
+ /**
+ * The spigot resource ID, used for update checking.
+ */
int SPIGOT_RESOURCE_ID = 83767;
+ /**
+ * Get the user representing the server console.
+ *
+ * @return the {@link ConsoleUser}
+ */
@NotNull
ConsoleUser getConsole();
/**
- * The {@link Set} of online {@link OnlineUser}s on this server
+ * The {@link Set} of online {@link OnlineUser}s on this server.
*
* @return a {@link Set} of currently online {@link OnlineUser}s
*/
@@ -121,7 +129,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
}
/**
- * Initialize a faucet of the plugin
+ * Initialize a faucet of the plugin.
*
* @param name the name of the faucet
* @param runner a runnable for initializing the faucet
@@ -137,7 +145,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
}
/**
- * The plugin {@link Settings} loaded from file
+ * The plugin {@link Settings} loaded from file.
*
* @return the plugin {@link Settings}
*/
@@ -147,7 +155,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
void setSettings(@NotNull Settings settings);
/**
- * The plugin messages loaded from file
+ * The plugin messages loaded from file.
*
* @return The plugin {@link Locales}
*/
@@ -157,17 +165,29 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
void setLocales(@NotNull Locales locales);
/**
- * The local {@link Spawn} location of this server, as cached to disk
+ * The local {@link Spawn} location of this server, as cached to disk.
*
* @return the {@link Spawn} location data
* @see #getSpawn() for the canonical spawn point to use
*/
Optional getServerSpawn();
+ /**
+ * Update the local {@link Spawn} config file.
+ *
+ * @param spawn the new {@link Spawn} data
+ */
void setServerSpawn(@NotNull Spawn spawn);
/**
- * The canonical spawn {@link Position} of this server, if it has been set
+ * Update the {@link Spawn} position to a location on the server.
+ *
+ * @param location the new {@link Spawn} location
+ */
+ void setServerSpawn(@NotNull Location location);
+
+ /**
+ * The canonical spawn {@link Position} of this server, if it has been set.
*
* @return the {@link Position} of the spawn, or an empty {@link Optional} if it has not been set
*/
@@ -178,7 +198,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
}
/**
- * Returns the {@link Server} the plugin is on
+ * Returns the {@link Server} the plugin is on.
*
* @return The {@link Server} object
*/
@@ -193,7 +213,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
UnsafeBlocks getUnsafeBlocks();
/**
- * The {@link Database} that store persistent plugin data
+ * The {@link Database} that store persistent plugin data.
*
* @return the {@link Database} implementation for accessing data
*/
@@ -201,7 +221,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
Database getDatabase();
/**
- * The {@link Validator} for validating home names and descriptions
+ * The {@link Validator} for validating home names and descriptions.
*
* @return the {@link Validator} instance
*/
@@ -209,7 +229,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
Validator getValidator();
/**
- * The {@link Manager} that manages home, warp and user data
+ * The {@link Manager} that manages home, warp and user data.
*
* @return the {@link Manager} implementation
*/
@@ -217,7 +237,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
Manager getManager();
/**
- * The {@link Broker} that sends cross-network messages
+ * The {@link Broker} that sends cross-network messages.
*
* @return the {@link Broker} implementation
*/
@@ -225,7 +245,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
Broker getMessenger();
/**
- * The {@link RandomTeleportEngine} that manages random teleports
+ * The {@link RandomTeleportEngine} that manages random teleports.
*
* @return the {@link RandomTeleportEngine} implementation
*/
@@ -233,22 +253,14 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
RandomTeleportEngine getRandomTeleportEngine();
/**
- * Sets the {@link RandomTeleportEngine} to be used for processing random teleports
+ * Sets the {@link RandomTeleportEngine} to be used for processing random teleports.
*
* @param randomTeleportEngine the {@link RandomTeleportEngine} to use
*/
void setRandomTeleportEngine(@NotNull RandomTeleportEngine randomTeleportEngine);
-
/**
- * Update the {@link Spawn} position to a location on the server
- *
- * @param location the new {@link Spawn} location
- */
- void setServerSpawn(@NotNull Location location);
-
- /**
- * Set of active {@link Hook}s running on the server
+ * Set of active {@link Hook}s running on the server.
*
* @return the {@link Set} of active {@link Hook}s
*/
@@ -277,7 +289,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
}
/**
- * Returns a resource read from the plugin resources folder
+ * Returns a resource read from the plugin resources folder.
*
* @param name the name of the resource
* @return the resource read as an {@link InputStream}
@@ -286,7 +298,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
InputStream getResource(@NotNull String name);
/**
- * Returns the plugin data folder containing the plugin config, etc
+ * Returns the plugin data folder containing the plugin config, etc.
*
* @return the plugin data folder
*/
@@ -294,7 +306,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
File getDataFolder();
/**
- * Returns a list of worlds on the server
+ * Returns a list of worlds on the server.
*
* @return a list of worlds on the server
*/
@@ -302,7 +314,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
List getWorlds();
/**
- * Returns the plugin version
+ * Returns the plugin version.
*
* @return the plugin {@link Version}
*/
@@ -310,7 +322,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
Version getVersion();
/**
- * Returns a list of enabled commands
+ * Returns a list of enabled commands.
*
* @return A list of registered and enabled {@link Command}s
*/
@@ -396,7 +408,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
}
/**
- * Reloads the {@link Settings} and {@link Locales} from their respective config files
+ * Reloads the {@link Settings} and {@link Locales} from their respective config files.
*
* @return {@code true} if the reload was successful, {@code false} otherwise
*/
@@ -407,8 +419,14 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
setSettings(Annotaml.create(new File(getDataFolder(), "config.yml"), Settings.class).get());
// Load locales from language preset default
- final Locales languagePresets = Annotaml.create(Locales.class, Objects.requireNonNull(getResource("locales/" + getSettings().getLanguage() + ".yml"))).get();
- setLocales(Annotaml.create(new File(getDataFolder(), "messages_" + getSettings().getLanguage() + ".yml"), languagePresets).get());
+ final Locales languagePresets = Annotaml.create(
+ Locales.class,
+ Objects.requireNonNull(getResource("locales/" + getSettings().getLanguage() + ".yml"))
+ ).get();
+ setLocales(Annotaml.create(new File(
+ getDataFolder(),
+ "messages_" + getSettings().getLanguage() + ".yml"
+ ), languagePresets).get());
// Load server from file
if (getSettings().doCrossServer()) {
@@ -448,26 +466,26 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
getUpdateChecker().check().thenAccept(checked -> {
if (!checked.isUpToDate()) {
log(Level.WARNING, "A new version of HuskHomes is available: v"
- + checked.getLatestVersion() + " (running v" + getVersion() + ")");
+ + checked.getLatestVersion() + " (running v" + getVersion() + ")");
}
});
}
}
/**
- * Registers the plugin with bStats metrics
+ * Registers the plugin with bStats metrics.
*
* @param metricsId the bStats id for the plugin
*/
void registerMetrics(int metricsId);
/**
- * Initialize plugin messaging channels
+ * Initialize plugin messaging channels.
*/
void initializePluginChannels();
/**
- * Log a message to the console
+ * Log a message to the console.
*
* @param level the level to log at
* @param message the message to log
@@ -476,7 +494,7 @@ public interface HuskHomes extends Task.Supplier, EventDispatcher, SafetyResolve
void log(@NotNull Level level, @NotNull String message, Throwable... exceptions);
/**
- * Create a resource key namespaced with the plugin id
+ * Create a resource key namespaced with the plugin id.
*
* @param data the string ID elements to join
* @return the key
diff --git a/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java b/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java
index b5399b85..ff008edd 100644
--- a/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java
+++ b/common/src/main/java/net/william278/huskhomes/api/BaseHuskHomesAPI.java
@@ -33,6 +33,7 @@ import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.user.SavedUser;
import net.william278.huskhomes.user.User;
import net.william278.huskhomes.util.TransactionResolver;
+import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.time.Duration;
@@ -59,8 +60,9 @@ public abstract class BaseHuskHomesAPI {
protected final HuskHomes plugin;
/**
- * (Internal use only) - Constructor, instantiating the base API class
+ * (Internal use only) - Constructor, instantiating the base API class.
*/
+ @ApiStatus.Internal
protected BaseHuskHomesAPI(@NotNull HuskHomes plugin) {
this.plugin = plugin;
}
@@ -88,19 +90,20 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Get the timestamp of when a user's cooldown for performing an {@link TransactionResolver.Action action} expires
+ * Get the timestamp of when a user's cooldown for performing an {@link TransactionResolver.Action action} expires.
*
* @param user The {@link User} to get data for.
* @param action The {@link TransactionResolver.Action} to get the cooldown for
* @return An {@link Optional} containing the {@link Instant} the cooldown expires, if there is one
* @since 4.4
*/
- public final CompletableFuture> getCooldown(@NotNull User user, @NotNull TransactionResolver.Action action) {
+ public final CompletableFuture> getCooldown(@NotNull User user,
+ @NotNull TransactionResolver.Action action) {
return plugin.supplyAsync(() -> plugin.getDatabase().getCooldown(action, user));
}
/**
- * Set a cooldown for a user performing an {@link TransactionResolver.Action action}
+ * Set a cooldown for a user performing an {@link TransactionResolver.Action action}.
*
* @param user The {@link User} to set data for.
* @param action The {@link TransactionResolver.Action} to set the cooldown for
@@ -108,7 +111,8 @@ public abstract class BaseHuskHomesAPI {
* @throws IllegalArgumentException if the expiry is in the past
* @since 4.4
*/
- public final void setCooldown(@NotNull User user, @NotNull TransactionResolver.Action action, @NotNull Instant expiry) throws IllegalArgumentException {
+ public final void setCooldown(@NotNull User user, @NotNull TransactionResolver.Action action,
+ @NotNull Instant expiry) throws IllegalArgumentException {
if (Instant.now().isAfter(expiry)) {
throw new IllegalArgumentException("Cooldown expiry time must be in the future");
}
@@ -116,7 +120,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Set a cooldown for a user performing an {@link TransactionResolver.Action action}
+ * Set a cooldown for a user performing an {@link TransactionResolver.Action action}.
*
* @param user The {@link User} to set data for.
* @param action The {@link TransactionResolver.Action} to set the cooldown for
@@ -124,12 +128,13 @@ public abstract class BaseHuskHomesAPI {
* @throws IllegalArgumentException if the duration is negative
* @since 4.4
*/
- public final void setCooldown(@NotNull User user, @NotNull TransactionResolver.Action action, @NotNull Duration duration) throws IllegalArgumentException {
+ public final void setCooldown(@NotNull User user, @NotNull TransactionResolver.Action action,
+ @NotNull Duration duration) throws IllegalArgumentException {
this.setCooldown(user, action, Instant.now().plus(duration));
}
/**
- * Remove a cooldown for a user performing an {@link TransactionResolver.Action action}
+ * Remove a cooldown for a user performing an {@link TransactionResolver.Action action}.
*
* @param user The {@link User} to remove the cooldown for
* @param action The {@link TransactionResolver.Action} to remove the cooldown for
@@ -140,7 +145,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Returns the last position, as used in the {@code /back} command, for this user
+ * Returns the last position, as used in the {@code /back} command, for this user.
*
* @param user The {@link User} to get the last position for
* @return The user's last {@link Position}, if there is one
@@ -151,7 +156,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Set the last {@link Position}, as used in the {@code /back} command, for this user
+ * Set the last {@link Position}, as used in the {@code /back} command, for this user.
*
* @param user The {@link User} to set the last position for
* @param position The {@link Position} to set as the user's last position
@@ -162,7 +167,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Returns where the user last disconnected from a server
+ * Returns where the user last disconnected from a server.
*
* @param user The {@link User} to get the last disconnect position for
* @return The user's offline {@link Position}, if there is one
@@ -173,9 +178,9 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Returns where the user last set their spawn point by right-clicking a bed or respawn anchor
- *
- * The optional returned by this method will be empty unless HuskHomes is running cross-server mode
+ * Returns where the user last set their spawn point by right-clicking a bed or respawn anchor.
+ *
+ *
The optional returned by this method will be empty unless HuskHomes is running cross-server mode
* and global respawning is enabled
*
* @param user The {@link User} to get the respawn position of
@@ -191,7 +196,7 @@ public abstract class BaseHuskHomesAPI {
/**
* Returns if a user is currently warming up for a timed teleport; that is, they are in the state where they
- * must stand still and not take damage for the set amount of seconds before a teleport can be executed.
+ * must stand still and not take damage for the set number of seconds before a teleport can be executed.
*
* @param user The {@link User} to check
* @return {@code true} if the user is currently warming up, otherwise {@code false}
@@ -202,7 +207,8 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Save {@link SavedUser} to the database, updating it if data for the user already exists, or adding new user data if it doesn't.
+ * Save {@link SavedUser} to the database, updating it if data for the user already exists,
+ * or adding new user data if it doesn't.
*
* @param savedUser The {@link SavedUser} to save
* @since 3.0
@@ -254,11 +260,9 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Get a list of {@link Home}s set by the given user that they have made public
+ * Get a list of {@link Home}s set by the given user that they have made public.
*
- * @param user The {@link User} to get the public homes of
- * @return A {@link CompletableFuture} that will complete with a list of {@link Home}s set by the user that
- * they have made public (where {@link Home#isPublic()})
+ * @return A {@link CompletableFuture} with the user's public homes (where {@link Home#isPublic()})
* @since 3.0
*/
public final CompletableFuture> getUserPublicHomes(@NotNull User user) {
@@ -268,7 +272,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Get a list of public homes local to this server
+ * Get a list of public homes local to this server.
*
* @param user The {@link User} to get the local public homes of
* @return A {@link CompletableFuture} that will complete with a list of public {@link Home}s local to the server
@@ -279,7 +283,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Get a list of homes that have been made public ("public homes")
+ * Get a list of homes that have been made public ("public homes").
*
* @return A {@link CompletableFuture} that will complete with a list of public {@link Home}s
* @since 3.0
@@ -289,11 +293,11 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Get a {@link Home} from the database owned by a given {@link User} with the specified name
+ * Get a {@link Home} from the database owned by a given {@link User} with the specified name.
*
* @param user The {@link User} to get the home of
* @param homeName The name of the home to get
- * @return A {@link CompletableFuture} that will complete with the {@link Home} if it exists, otherwise an empty {@link Optional}
+ * @return A {@link CompletableFuture} with the {@link Home} if it exists, otherwise an empty {@link Optional}
* @since 3.0
*/
public final CompletableFuture> getHome(@NotNull User user, @NotNull String homeName) {
@@ -302,17 +306,17 @@ public abstract class BaseHuskHomesAPI {
/**
- * Get a {@link Home} from the database by its' unique id
+ * Get a {@link Home} from the database by its {@link UUID unique ID}.
*
* @param homeUuid The {@link UUID} of the home to get
- * @return A {@link CompletableFuture} that will complete with the {@link Home} if it exists, otherwise an empty {@link Optional}
+ * @return A {@link CompletableFuture} with the {@link Home} if it exists, otherwise an empty {@link Optional}
*/
public final CompletableFuture> getHome(@NotNull UUID homeUuid) {
return plugin.supplyAsync(() -> plugin.getDatabase().getHome(homeUuid));
}
/**
- * Create a home for a given user with the specified name and position
+ * Create a home for a given user with the specified name and position.
*
* @param owner The {@link User} to create the home for
* @param name The name of the home
@@ -324,7 +328,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Delete a home for a given user with the specified name
+ * Delete a home for a given user with the specified name.
*
* @param owner The {@link User} to delete the home for
* @param name The name of the home
@@ -335,7 +339,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Delete a home
+ * Delete a home.
*
* @param home The {@link Home} to delete
* @since 4.0
@@ -345,7 +349,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Rename a home for a given user
+ * Rename a home for a given user.
*
* @param owner The {@link User} to rename the home for
* @param oldName The name of the home to rename
@@ -357,7 +361,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Rename a home
+ * Rename a home.
*
* @param home The {@link Home} to rename
* @param newName The new name of the home
@@ -368,7 +372,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Set the privacy of a home
+ * Set the privacy of a home.
*
* @param owner The {@link User} to set the privacy of the home for
* @param name The name of the home
@@ -380,7 +384,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Set the privacy of a home
+ * Set the privacy of a home.
*
* @param home The {@link Home} to set the privacy of
* @param isPublic Whether the home should be public or not
@@ -391,7 +395,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Set the description of a home
+ * Set the description of a home.
*
* @param owner The {@link User} to set the description of the home for
* @param name The name of the home
@@ -403,7 +407,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Set the description of a home
+ * Set the description of a home.
*
* @param home The {@link Home} to set the description of
* @param description The description of the home
@@ -414,7 +418,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Relocate a home for a given user
+ * Relocate a home for a given user.
*
* @param owner The {@link User} to relocate the home for
* @param name The name of the home
@@ -426,7 +430,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Relocate a home
+ * Relocate a home.
*
* @param home The {@link Home} to relocate
* @param position The new {@link Position} of the home
@@ -438,7 +442,7 @@ public abstract class BaseHuskHomesAPI {
/**
- * Set the meta tags of a home
+ * Set the meta tags of a home.
*
* @param owner The {@link User} to set the meta tags of the home for
* @param name The name of the home
@@ -450,7 +454,7 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Set the meta tags of a home
+ * Set the meta tags of a home.
*
* @param home The {@link Home} to set the meta tags of
* @param tags The meta tags to set
@@ -461,14 +465,15 @@ public abstract class BaseHuskHomesAPI {
}
/**
- * Edit the meta tags of a home
+ * Edit the meta tags of a home.
*
* @param owner The {@link User} to edit the meta tags of the home for
* @param name The name of the home
* @param tagEditor The {@link Consumer} to edit the meta tags with
* @since 4.0
*/
- public final void editHomeMetaTags(@NotNull User owner, @NotNull String name, @NotNull Consumer