mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
SQLite, network messaging, caching, redis, more bukkit implementing
This commit is contained in:
1 parent
28a54b0b4a
commit
052eb57438
24 files changed
+1855
-38
No files matched your search
@@ -1,10 +1,14 @@
|
||||
package net.william278.huskhomes.player;
|
||||
|
||||
import de.themoep.minedown.MineDown;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.william278.huskhomes.HuskHomesBukkit;
|
||||
import net.william278.huskhomes.position.Location;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.teleport.TeleportResult;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -31,10 +35,22 @@ public class BukkitPlayer implements Player {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static Optional<BukkitPlayer> get(@NotNull String username) {
|
||||
final org.bukkit.entity.Player bukkitPlayer = Bukkit.getPlayerExact(username);
|
||||
if (bukkitPlayer != null) {
|
||||
return Optional.of(adapt(bukkitPlayer));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static BukkitPlayer adapt(@NotNull org.bukkit.entity.Player player) {
|
||||
return new BukkitPlayer(player);
|
||||
}
|
||||
|
||||
public org.bukkit.entity.Player getBukkitPlayer() {
|
||||
return bukkitPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return bukkitPlayer.getName();
|
||||
@@ -46,8 +62,13 @@ public class BukkitPlayer implements Player {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Position getPosition() {
|
||||
return null;
|
||||
public CompletableFuture<Position> getPosition() {
|
||||
final org.bukkit.Location location = bukkitPlayer.getLocation();
|
||||
return HuskHomesBukkit.getInstance().getServer(this).thenApplyAsync(server ->
|
||||
new Position(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch(),
|
||||
new net.william278.huskhomes.position.World(bukkitPlayer.getWorld().getName(),
|
||||
bukkitPlayer.getWorld().getUID()), server));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,7 +83,17 @@ public class BukkitPlayer implements Player {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<TeleportResult> teleport(Location location) {
|
||||
return null; //todo
|
||||
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);
|
||||
}
|
||||
return PaperLib.teleportAsync(bukkitPlayer, bukkitLocation.get(),
|
||||
PlayerTeleportEvent.TeleportCause.COMMAND)
|
||||
.thenApplyAsync(result -> TeleportResult.COMPLETED_LOCALLY);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,4 +106,10 @@ public class BukkitPlayer implements Player {
|
||||
return null; //todo
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a Bukkit plugin message
|
||||
*/
|
||||
public void sendPluginMessage(@NotNull Plugin source, @NotNull String channel, byte @NotNull [] message) {
|
||||
bukkitPlayer.sendPluginMessage(source, channel, message);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user