home, sethome and homelist implementation

This commit is contained in:
William committed 2022-05-28 23:03:04 +01:00
1 parent 5e793e8ec7
commit 0e33fb8014
18 files changed
+349 -138

No files matched your search

@@ -7,15 +7,13 @@ import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import net.william278.huskhomes.cache.Cache;
import net.william278.huskhomes.command.BukkitCommand;
import net.william278.huskhomes.command.CommandBase;
import net.william278.huskhomes.command.HomeCommand;
import net.william278.huskhomes.command.SetHomeCommand;
import net.william278.huskhomes.command.*;
import net.william278.huskhomes.config.Locales;
import net.william278.huskhomes.config.Settings;
import net.william278.huskhomes.data.Database;
import net.william278.huskhomes.data.MySqlDatabase;
import net.william278.huskhomes.data.SqLiteDatabase;
import net.william278.huskhomes.listener.BukkitEventProcessor;
import net.william278.huskhomes.messenger.NetworkMessenger;
import net.william278.huskhomes.messenger.PluginMessenger;
import net.william278.huskhomes.messenger.RedisMessenger;
@@ -78,12 +76,12 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes {
if (server != null) {
return CompletableFuture.supplyAsync(() -> server);
}
if (getSettings().getBooleanValue(Settings.ConfigOption.ENABLE_PROXY_MODE)) {
if (!getSettings().getBooleanValue(Settings.ConfigOption.ENABLE_PROXY_MODE)) {
server = new Server("server");
return CompletableFuture.supplyAsync(() -> server);
}
assert networkMessenger != null;
return networkMessenger.getServerName(player).thenApply(server -> {
return networkMessenger.getServerName(player).thenApplyAsync(server -> {
this.server = new Server(server);
return this.server;
});
@@ -133,22 +131,26 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes {
// Initialize the cache
cache = new Cache();
cache.initialize(database);
});
}).thenRun(() -> {
// Prepare the teleport manager
this.teleportManager = new BukkitTeleportManager(this);
// Prepare the teleport manager
this.teleportManager = new BukkitTeleportManager(this);
// Prepare the home and warp position manager
this.savedPositionManager = new SavedPositionManager(database, cache);
// Prepare the home and warp position manager
this.savedPositionManager = new SavedPositionManager(database, cache);
// Register commands - todo add all here
final CommandBase[] commands = new CommandBase[]{new HomeCommand(this), new SetHomeCommand(this)};
for (CommandBase commandBase : commands) {
final PluginCommand pluginCommand = getCommand(commandBase.command);
if (pluginCommand != null) {
new BukkitCommand(commandBase, this).register(pluginCommand);
// Register commands - todo add all here
final CommandBase[] commands = new CommandBase[]{new HomeCommand(this), new SetHomeCommand(this),
new HomeListCommand(this)};
for (CommandBase commandBase : commands) {
final PluginCommand pluginCommand = getCommand(commandBase.command);
if (pluginCommand != null) {
new BukkitCommand(commandBase, this).register(pluginCommand);
}
}
}
// Register listener
getServer().getPluginManager().registerEvents(new BukkitEventProcessor(this), this);
});
}
@Override
@@ -38,7 +38,7 @@ public class BukkitCommand implements CommandExecutor, TabExecutor {
public void register(@NotNull PluginCommand pluginCommand) {
pluginCommand.setExecutor(this);
pluginCommand.setTabCompleter(this);
pluginCommand.setDescription(pluginCommand.getDescription());
pluginCommand.setDescription(command.getDescription());
}
@Override
@@ -61,7 +61,7 @@ public class BukkitCommand implements CommandExecutor, TabExecutor {
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, @NotNull String[] args) {
if (command instanceof TabCompletable tabCompletable) {
if (this.command instanceof TabCompletable tabCompletable) {
return tabCompletable.onTabComplete(BukkitPlayer.adapt((Player) sender), args);
}
return Collections.emptyList();
@@ -92,20 +92,28 @@ public class BukkitPlayer implements Player {
@Override
public CompletableFuture<TeleportResult> teleport(Location location) {
final Optional<org.bukkit.Location> bukkitLocation = HuskHomesBukkit.BukkitAdapter.adaptLocation(location);
if (bukkitLocation.isEmpty()) {
return CompletableFuture.supplyAsync(() -> TeleportResult.FAILED_INVALID_WORLD);
}
assert bukkitLocation.get().getWorld() != null;
if (!bukkitLocation.get().getWorld().getWorldBorder().isInside(bukkitLocation.get())) {
return CompletableFuture.supplyAsync(() -> TeleportResult.FAILED_ILLEGAL_COORDINATES);
}
final CompletableFuture<TeleportResult> resultCompletableFuture = new CompletableFuture<>();
Bukkit.getScheduler().runTask(HuskHomesBukkit.getInstance(), () ->
resultCompletableFuture.complete(PaperLib.teleportAsync(bukkitPlayer, bukkitLocation.get(),
PlayerTeleportEvent.TeleportCause.COMMAND)
.thenApply(result -> TeleportResult.COMPLETED_LOCALLY).join()));
return resultCompletableFuture;
return CompletableFuture.supplyAsync(() -> {
final Optional<org.bukkit.Location> bukkitLocation = HuskHomesBukkit.BukkitAdapter.adaptLocation(location);
if (bukkitLocation.isEmpty()) {
return TeleportResult.FAILED_INVALID_WORLD;
}
assert bukkitLocation.get().getWorld() != null;
if (!bukkitLocation.get().getWorld().getWorldBorder().isInside(bukkitLocation.get())) {
return TeleportResult.FAILED_ILLEGAL_COORDINATES;
}
System.out.println("teleport 5");
final CompletableFuture<TeleportResult> resultCompletableFuture = new CompletableFuture<>();
Bukkit.getScheduler().runTask(HuskHomesBukkit.getInstance(), () ->
PaperLib.teleportAsync(bukkitPlayer, bukkitLocation.get(), PlayerTeleportEvent.TeleportCause.COMMAND)
.thenAccept(result -> {
if (result) {
resultCompletableFuture.completeAsync(() -> TeleportResult.COMPLETED_LOCALLY);
} else {
resultCompletableFuture.completeAsync(() -> TeleportResult.FAILED_INVALID_WORLD);
}
}));
return resultCompletableFuture.join();
});
}
@Override
@@ -5,6 +5,7 @@ import net.william278.huskhomes.HuskHomesBukkit;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
/**
@@ -18,17 +19,24 @@ public class BukkitTeleportManager extends TeleportManager {
@Override
public CompletableFuture<TimedTeleport> processTimedTeleport(@NotNull final TimedTeleport teleport) {
final CompletableFuture<TimedTeleport> timedTeleportCompletableFuture = new CompletableFuture<>();
new BukkitRunnable() {
@Override
public void run() {
// Tick (decrement) the timed teleport timer
if (tickTimedTeleport(teleport, timedTeleportCompletableFuture)) {
this.cancel();
return CompletableFuture.supplyAsync(() -> {
CompletableFuture<TimedTeleport> teleportCompletableFuture = new CompletableFuture<>();
new BukkitRunnable() {
@Override
public void run() {
System.out.println("teleport warmup tick");
// Tick (decrement) the timed teleport timer
final Optional<TimedTeleport> result = tickTimedTeleport(teleport);
if (result.isPresent()) {
System.out.println("task cancelled... ");
teleportCompletableFuture.complete(teleport);
this.cancel();
}
}
}
}.runTaskTimerAsynchronously((HuskHomesBukkit) plugin, 0L, 20L);
return timedTeleportCompletableFuture;
}.runTaskTimerAsynchronously((HuskHomesBukkit) plugin, 0L, 20L);
return teleportCompletableFuture.join();
});
}
}
+5 -1
View File
@@ -1,9 +1,13 @@
name: 'HuskHomes'
description: 'A powerful, intuitive and flexible teleportation suite'
author: 'William278'
main: 'net.william278.huskhomes.HuskHomesBukkit'
version: '${version}'
api-version: 1.16
commands:
home:
usage: /home <name>
sethome:
usage: /sethome <name>
usage: /sethome <name>
homelist:
usage: /homelist [page]