diff --git a/bukkit/src/main/java/net/william278/huskhomes/HuskHomesBukkit.java b/bukkit/src/main/java/net/william278/huskhomes/HuskHomesBukkit.java index d9cd3cb7..678a93b4 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/HuskHomesBukkit.java +++ b/bukkit/src/main/java/net/william278/huskhomes/HuskHomesBukkit.java @@ -139,8 +139,9 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes { this.savedPositionManager = new SavedPositionManager(database, cache); // Register commands - todo add all here - final CommandBase[] commands = new CommandBase[]{new HomeCommand(this), new SetHomeCommand(this), - new HomeListCommand(this)}; + final CommandBase[] commands = new CommandBase[]{ + new HomeCommand(this), new SetHomeCommand(this), + new HomeListCommand(this), new BackCommand(this)}; for (CommandBase commandBase : commands) { final PluginCommand pluginCommand = getCommand(commandBase.command); if (pluginCommand != null) { diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index c9b02c2a..cadc4bde 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -10,4 +10,6 @@ commands: sethome: usage: /sethome homelist: - usage: /homelist [page] \ No newline at end of file + usage: /homelist [page] + back: + usage: /back \ No newline at end of file diff --git a/common/src/main/java/net/william278/huskhomes/command/BackCommand.java b/common/src/main/java/net/william278/huskhomes/command/BackCommand.java new file mode 100644 index 00000000..a9b35ab3 --- /dev/null +++ b/common/src/main/java/net/william278/huskhomes/command/BackCommand.java @@ -0,0 +1,24 @@ +package net.william278.huskhomes.command; + +import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.player.Player; +import net.william278.huskhomes.player.User; +import org.jetbrains.annotations.NotNull; + +public class BackCommand extends CommandBase { + + private final static String PERMISSION = "huskhomes.command.back"; + + public BackCommand(@NotNull HuskHomes implementor) { + super("back", PERMISSION, implementor); + } + + @Override + public void onExecute(@NotNull Player player, @NotNull String[] args) { + plugin.getDatabase().getLastPosition(new User(player)).thenAccept(lastPosition -> + lastPosition.ifPresentOrElse(position -> plugin.getTeleportManager().teleport(player, position) + .thenAccept(result -> plugin.getTeleportManager().finishTeleport(player, result)), + () -> plugin.getLocales().getLocale("error_no_last_position").ifPresent(player::sendMessage))); + } + +} diff --git a/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java b/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java index 4f89c071..1b4a99a6 100644 --- a/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/HomeListCommand.java @@ -4,12 +4,8 @@ import net.william278.huskhomes.HuskHomes; import net.william278.huskhomes.list.PrivateHomeList; import net.william278.huskhomes.player.Player; import net.william278.huskhomes.player.User; -import net.william278.huskhomes.util.RegexUtil; import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.stream.Collectors; - public class HomeListCommand extends CommandBase implements ConsoleExecutable { private final static String PERMISSION = "huskhomes.command.home"; @@ -21,9 +17,7 @@ public class HomeListCommand extends CommandBase implements ConsoleExecutable { @Override public void onExecute(@NotNull Player player, @NotNull String[] args) { switch (args.length) { - case 0 -> { - showHomeList(player, 1); - } + case 0 -> showHomeList(player, 1); case 1 -> { try { int pageNumber = Integer.parseInt(args[0]); diff --git a/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java index bc784c2b..e06e9675 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java @@ -2,16 +2,11 @@ package net.william278.huskhomes.command; import de.themoep.minedown.MineDown; import net.william278.huskhomes.HuskHomes; -import net.william278.huskhomes.list.PrivateHomeList; import net.william278.huskhomes.player.Player; import net.william278.huskhomes.player.User; import net.william278.huskhomes.position.PositionMeta; -import net.william278.huskhomes.util.RegexUtil; import org.jetbrains.annotations.NotNull; -import java.util.List; -import java.util.stream.Collectors; - public class SetHomeCommand extends CommandBase { private final static String PERMISSION = "huskhomes.command.sethome"; diff --git a/common/src/main/java/net/william278/huskhomes/list/PublicHomeList.java b/common/src/main/java/net/william278/huskhomes/list/PublicHomeList.java deleted file mode 100644 index bcbe8116..00000000 --- a/common/src/main/java/net/william278/huskhomes/list/PublicHomeList.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.william278.huskhomes.list; - -import de.themoep.minedown.MineDown; -import net.william278.huskhomes.position.Home; -import net.william278.huskhomes.position.SavedPosition; -import net.william278.huskhomes.position.Warp; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.stream.Collectors; - -public class PublicHomeList extends PositionList { - - public PublicHomeList(@NotNull List homes, int itemsPerPage) { - super(homes.stream().map(position -> (SavedPosition) position).collect(Collectors.toList()), itemsPerPage); - } - - @Override - protected String getItemSeparator() { - return null; - } - - @Override - protected MineDown getHeader(int pageItemStart, int pageItemEnd, int totalItemCount) { - return null; - } - - @Override - protected MineDown getFooter(@NotNull FooterLayout layout, int pageNumber, int maxPages) { - return null; - } - - @Override - protected String getFormattedItem(SavedPosition position) { - return null; - } - - @Override - protected MineDown getNoItemsMessage() { - return null; - } - - @Override - protected MineDown getInvalidPageNumberMessage() { - return null; - } -} diff --git a/common/src/main/java/net/william278/huskhomes/list/WarpList.java b/common/src/main/java/net/william278/huskhomes/list/WarpList.java deleted file mode 100644 index 2ce91208..00000000 --- a/common/src/main/java/net/william278/huskhomes/list/WarpList.java +++ /dev/null @@ -1,46 +0,0 @@ -package net.william278.huskhomes.list; - -import de.themoep.minedown.MineDown; -import net.william278.huskhomes.position.SavedPosition; -import net.william278.huskhomes.position.Warp; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.stream.Collectors; - -public class WarpList extends PositionList { - - public WarpList(@NotNull List warps, int itemsPerPage) { - super(warps.stream().map(position -> (SavedPosition) position).collect(Collectors.toList()), itemsPerPage); - } - - @Override - protected String getItemSeparator() { - return null; - } - - @Override - protected MineDown getHeader(int pageItemStart, int pageItemEnd, int totalItemCount) { - return null; - } - - @Override - protected MineDown getFooter(@NotNull FooterLayout layout, int pageNumber, int maxPages) { - return null; - } - - @Override - protected String getFormattedItem(SavedPosition position) { - return null; - } - - @Override - protected MineDown getNoItemsMessage() { - return null; - } - - @Override - protected MineDown getInvalidPageNumberMessage() { - return null; - } -}