mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 14:38:53 +00:00
Add /tphere, make /tp instantaneous, add images, slight refactoring
This commit is contained in:
1 parent
e37a55b214
commit
6149ebe983
17 files changed
+198
-50
No files matched your search
@@ -82,6 +82,7 @@ public class Message {
|
||||
*/
|
||||
public enum MessageType {
|
||||
TP_REQUEST,
|
||||
TP_TO_POSITION_REQUEST,
|
||||
POSITION_REQUEST
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package net.william278.huskhomes.messenger;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import net.william278.huskhomes.position.Position;
|
||||
import net.william278.huskhomes.teleport.TeleportResult;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -15,6 +17,13 @@ public class MessagePayload {
|
||||
@Nullable
|
||||
public Position position;
|
||||
|
||||
/**
|
||||
* A teleport result field
|
||||
*/
|
||||
@Nullable
|
||||
@SerializedName("teleport_result")
|
||||
public TeleportResult teleportResult;
|
||||
|
||||
/**
|
||||
* Returns an empty cross-server message payload
|
||||
*
|
||||
@@ -38,6 +47,19 @@ public class MessagePayload {
|
||||
return payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a payload containing a {@link TeleportResult}
|
||||
*
|
||||
* @param teleportResult the teleport to send
|
||||
* @return a payload containing the teleport result
|
||||
*/
|
||||
@NotNull
|
||||
public static MessagePayload withTeleportResult(@NotNull TeleportResult teleportResult) {
|
||||
final MessagePayload payload = new MessagePayload();
|
||||
payload.teleportResult = teleportResult;
|
||||
return payload;
|
||||
}
|
||||
|
||||
private MessagePayload() {
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,11 @@ public abstract class NetworkMessenger {
|
||||
*/
|
||||
protected String clusterId;
|
||||
|
||||
/**
|
||||
* The implementing HuskHomes plugin instance
|
||||
*/
|
||||
private HuskHomes plugin;
|
||||
|
||||
/**
|
||||
* Initialize the network messenger
|
||||
*
|
||||
@@ -50,6 +55,7 @@ public abstract class NetworkMessenger {
|
||||
public void initialize(@NotNull HuskHomes implementor) {
|
||||
this.processingMessages = new HashMap<>();
|
||||
this.clusterId = implementor.getSettings().clusterId;
|
||||
this.plugin = implementor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,9 +103,8 @@ public abstract class NetworkMessenger {
|
||||
* Send a reply to a received {@link Message}
|
||||
*
|
||||
* @param reply The reply {@link Message} to send
|
||||
* @return A future completing when the message has been sent
|
||||
*/
|
||||
protected abstract CompletableFuture<Void> sendReply(@NotNull OnlineUser replier, @NotNull Message reply);
|
||||
protected abstract void sendReply(@NotNull OnlineUser replier, @NotNull Message reply);
|
||||
|
||||
/**
|
||||
* Handle and action received network {@link Message}s
|
||||
@@ -128,6 +133,14 @@ public abstract class NetworkMessenger {
|
||||
case TP_REQUEST -> {
|
||||
//todo
|
||||
}
|
||||
case TP_TO_POSITION_REQUEST -> {
|
||||
if (message.payload.position != null) {
|
||||
message.payload = MessagePayload.withTeleportResult(plugin.getTeleportManager()
|
||||
.teleport(receiver, message.payload.position).join());
|
||||
} else {
|
||||
message.payload = MessagePayload.empty();
|
||||
}
|
||||
}
|
||||
case POSITION_REQUEST -> message.payload = MessagePayload.withPosition(receiver.getPosition().join());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user