mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 06:28:49 +00:00
Finish /huskhomes command
This commit is contained in:
1 parent
bb66246fb6
commit
f12490951a
3 files changed
+82
-21
No files matched your search
@@ -2,6 +2,7 @@ package net.william278.huskhomes;
|
|||||||
|
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import net.william278.annotaml.Annotaml;
|
import net.william278.annotaml.Annotaml;
|
||||||
|
import net.william278.desertwell.Version;
|
||||||
import net.william278.huskhomes.command.BukkitCommand;
|
import net.william278.huskhomes.command.BukkitCommand;
|
||||||
import net.william278.huskhomes.command.BukkitCommandType;
|
import net.william278.huskhomes.command.BukkitCommandType;
|
||||||
import net.william278.huskhomes.command.CommandBase;
|
import net.william278.huskhomes.command.CommandBase;
|
||||||
@@ -21,14 +22,15 @@ import net.william278.huskhomes.messenger.PluginMessenger;
|
|||||||
import net.william278.huskhomes.messenger.RedisMessenger;
|
import net.william278.huskhomes.messenger.RedisMessenger;
|
||||||
import net.william278.huskhomes.player.BukkitPlayer;
|
import net.william278.huskhomes.player.BukkitPlayer;
|
||||||
import net.william278.huskhomes.player.OnlineUser;
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
import net.william278.huskhomes.position.*;
|
import net.william278.huskhomes.position.Location;
|
||||||
|
import net.william278.huskhomes.position.SavedPositionManager;
|
||||||
|
import net.william278.huskhomes.position.Server;
|
||||||
|
import net.william278.huskhomes.position.World;
|
||||||
import net.william278.huskhomes.random.NormalDistributionEngine;
|
import net.william278.huskhomes.random.NormalDistributionEngine;
|
||||||
import net.william278.huskhomes.random.RtpEngine;
|
import net.william278.huskhomes.random.RtpEngine;
|
||||||
import net.william278.huskhomes.request.RequestManager;
|
import net.william278.huskhomes.request.RequestManager;
|
||||||
import net.william278.huskhomes.teleport.TeleportManager;
|
import net.william278.huskhomes.teleport.TeleportManager;
|
||||||
import net.william278.huskhomes.util.*;
|
import net.william278.huskhomes.util.*;
|
||||||
import net.william278.desertwell.Version;
|
|
||||||
import net.william278.desertwell.UpdateChecker;
|
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
@@ -212,14 +214,10 @@ public class BukkitHuskHomes extends JavaPlugin implements HuskHomes {
|
|||||||
// Check for updates
|
// Check for updates
|
||||||
if (settings.checkForUpdates) {
|
if (settings.checkForUpdates) {
|
||||||
getLoggingAdapter().log(Level.INFO, "Checking for updates...");
|
getLoggingAdapter().log(Level.INFO, "Checking for updates...");
|
||||||
final UpdateChecker updateChecker = UpdateChecker.create(getPluginVersion(), 83767);
|
getLatestVersionIfOutdated().thenAccept(newestVersion ->
|
||||||
updateChecker.isUpToDate().thenAccept(isUpToDate -> {
|
newestVersion.ifPresent(newVersion -> getLoggingAdapter().log(Level.WARNING,
|
||||||
if (!isUpToDate) {
|
"An update is available for HuskHomes, v" + newVersion
|
||||||
getLoggingAdapter().log(Level.WARNING, "An update is available for HuskHomes, v" +
|
+ " (Currently running v" + getPluginVersion() + ")")));
|
||||||
updateChecker.getLatestVersion().join()
|
|
||||||
+ " (Currently running v" + getPluginVersion() + ")");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (HuskHomesInitializationException exception) {
|
} catch (HuskHomesInitializationException exception) {
|
||||||
getLoggingAdapter().log(Level.SEVERE, exception.getMessage());
|
getLoggingAdapter().log(Level.SEVERE, exception.getMessage());
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.william278.huskhomes;
|
package net.william278.huskhomes;
|
||||||
|
|
||||||
|
import net.william278.desertwell.UpdateChecker;
|
||||||
import net.william278.huskhomes.command.CommandBase;
|
import net.william278.huskhomes.command.CommandBase;
|
||||||
import net.william278.huskhomes.config.Locales;
|
import net.william278.huskhomes.config.Locales;
|
||||||
import net.william278.huskhomes.config.Settings;
|
import net.william278.huskhomes.config.Settings;
|
||||||
@@ -29,6 +30,8 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
*/
|
*/
|
||||||
public interface HuskHomes {
|
public interface HuskHomes {
|
||||||
|
|
||||||
|
int SPIGOT_RESOURCE_ID = 83767;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The platform plugin console logger
|
* The platform plugin console logger
|
||||||
*
|
*
|
||||||
@@ -138,6 +141,22 @@ public interface HuskHomes {
|
|||||||
*/
|
*/
|
||||||
Optional<Spawn> getServerSpawn();
|
Optional<Spawn> getServerSpawn();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a future returning the latest plugin {@link Version} if the plugin is out-of-date
|
||||||
|
*
|
||||||
|
* @return a {@link CompletableFuture} returning the latest {@link Version} if the current one is out-of-date
|
||||||
|
*/
|
||||||
|
default CompletableFuture<Optional<Version>> getLatestVersionIfOutdated() {
|
||||||
|
final UpdateChecker updateChecker = UpdateChecker.create(getPluginVersion(), SPIGOT_RESOURCE_ID);
|
||||||
|
return updateChecker.isUpToDate().thenApply(upToDate -> {
|
||||||
|
if (upToDate) {
|
||||||
|
return Optional.empty();
|
||||||
|
} else {
|
||||||
|
return Optional.of(updateChecker.getLatestVersion().join());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the {@link Spawn} position to a location on the server
|
* Update the {@link Spawn} position to a location on the server
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package net.william278.huskhomes.command;
|
package net.william278.huskhomes.command;
|
||||||
|
|
||||||
|
import de.themoep.minedown.MineDown;
|
||||||
|
import net.william278.desertwell.AboutMenu;
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.player.OnlineUser;
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
import net.william278.desertwell.AboutMenu;
|
|
||||||
import net.william278.huskhomes.util.Permission;
|
import net.william278.huskhomes.util.Permission;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -56,6 +57,11 @@ public class HuskHomesCommand extends CommandBase implements ConsoleExecutable,
|
|||||||
switch (args[0].toLowerCase()) {
|
switch (args[0].toLowerCase()) {
|
||||||
case "about" -> sendAboutMenu(onlineUser);
|
case "about" -> sendAboutMenu(onlineUser);
|
||||||
case "help" -> {
|
case "help" -> {
|
||||||
|
if (!onlineUser.hasPermission(Permission.COMMAND_HUSKHOMES_HELP.node)) {
|
||||||
|
plugin.getLocales().getLocale("error_no_permission")
|
||||||
|
.ifPresent(onlineUser::sendMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
int page = 1;
|
int page = 1;
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
try {
|
try {
|
||||||
@@ -70,10 +76,33 @@ public class HuskHomesCommand extends CommandBase implements ConsoleExecutable,
|
|||||||
plugin.getLocales(), plugin.getCommands(), plugin.getSettings().listItemsPerPage, page));
|
plugin.getLocales(), plugin.getCommands(), plugin.getSettings().listItemsPerPage, page));
|
||||||
}
|
}
|
||||||
case "reload" -> {
|
case "reload" -> {
|
||||||
|
if (!onlineUser.hasPermission(Permission.COMMAND_HUSKHOMES_RELOAD.node)) {
|
||||||
|
plugin.getLocales().getLocale("error_no_permission")
|
||||||
|
.ifPresent(onlineUser::sendMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
plugin.reload().thenAccept(reloaded -> {
|
||||||
|
if (!reloaded) {
|
||||||
|
onlineUser.sendMessage(new MineDown("[Error:](#ff3300) [Failed to reload the plugin. Check console for errors.](#ff7e5e)"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onlineUser.sendMessage(new MineDown("[HuskHomes](#00fb9a bold) �fb9a&| Reloaded config & message files."));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
case "update" -> {
|
case "update" -> {
|
||||||
|
if (!onlineUser.hasPermission(Permission.COMMAND_HUSKHOMES_UPDATE.node)) {
|
||||||
|
plugin.getLocales().getLocale("error_no_permission")
|
||||||
|
.ifPresent(onlineUser::sendMessage);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
plugin.getLatestVersionIfOutdated().thenAccept(newestVersion ->
|
||||||
|
newestVersion.ifPresentOrElse(
|
||||||
|
newVersion -> onlineUser.sendMessage(
|
||||||
|
new MineDown("[HuskHomes](#00fb9a bold) [| A new version of HuskHomes is available!"
|
||||||
|
+ " (v" + newVersion + " (Currently running: v" + plugin.getPluginVersion() + ")](#00fb9a)")),
|
||||||
|
() -> onlineUser.sendMessage(
|
||||||
|
new MineDown("[HuskHomes](#00fb9a bold) [| HuskHomes is up-to-date."
|
||||||
|
+ " (Currently running: v" + plugin.getPluginVersion() + "](#00fb9a)"))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,17 +118,32 @@ public class HuskHomesCommand extends CommandBase implements ConsoleExecutable,
|
|||||||
case "about" -> Arrays.stream(aboutMenu.toString().split("\n")).forEach(message ->
|
case "about" -> Arrays.stream(aboutMenu.toString().split("\n")).forEach(message ->
|
||||||
plugin.getLoggingAdapter().log(Level.INFO, message));
|
plugin.getLoggingAdapter().log(Level.INFO, message));
|
||||||
case "help" -> {
|
case "help" -> {
|
||||||
|
plugin.getLoggingAdapter().log(Level.INFO, "List of enabled console-executable commands:");
|
||||||
}
|
plugin.getCommands()
|
||||||
case "reload" -> {
|
.stream().filter(command -> command instanceof ConsoleExecutable)
|
||||||
|
.forEach(command -> plugin.getLoggingAdapter().log(Level.INFO,
|
||||||
}
|
command.command +
|
||||||
case "update" -> {
|
(command.command.length() < 16 ? " ".repeat(16 - command.command.length()) : "")
|
||||||
|
+ " - " + command.getDescription()));
|
||||||
}
|
}
|
||||||
|
case "reload" -> plugin.reload().thenAccept(reloaded -> {
|
||||||
|
if (!reloaded) {
|
||||||
|
plugin.getLoggingAdapter().log(Level.SEVERE, "Failed to reload the plugin.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
plugin.getLoggingAdapter().log(Level.INFO, "Reloaded config & message files.");
|
||||||
|
});
|
||||||
|
case "update" -> plugin.getLatestVersionIfOutdated().thenAccept(newestVersion ->
|
||||||
|
newestVersion.ifPresentOrElse(newVersion -> plugin.getLoggingAdapter().log(Level.WARNING,
|
||||||
|
"An update is available for HuskHomes, v" + newVersion
|
||||||
|
+ " (Currently running v" + plugin.getPluginVersion() + ")"),
|
||||||
|
() -> plugin.getLoggingAdapter().log(Level.INFO,
|
||||||
|
"HuskHomes is up to date" +
|
||||||
|
" (Currently running v" + plugin.getPluginVersion() + ")")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void sendAboutMenu(@NotNull OnlineUser onlineUser) {
|
private void sendAboutMenu(@NotNull OnlineUser onlineUser) {
|
||||||
if (!onlineUser.hasPermission(Permission.COMMAND_HUSKHOMES_ABOUT.node)) {
|
if (!onlineUser.hasPermission(Permission.COMMAND_HUSKHOMES_ABOUT.node)) {
|
||||||
plugin.getLocales().getLocale("error_no_permission")
|
plugin.getLocales().getLocale("error_no_permission")
|
||||||
|
|||||||
Reference in new issue
Block a user