mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 06:28:49 +00:00
Fix global player list propagation
This commit is contained in:
8 files changed
+51
-25
No files matched your search
@@ -12,7 +12,10 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class EditHomeCommand extends SavedPositionCommand<Home> {
|
public class EditHomeCommand extends SavedPositionCommand<Home> {
|
||||||
|
|||||||
@@ -361,7 +361,7 @@ public class Settings {
|
|||||||
return listItemsPerPage;
|
return listItemsPerPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAsynchronousTeleports() {
|
public boolean doAsynchronousTeleports() {
|
||||||
return asynchronousTeleports;
|
return asynchronousTeleports;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import de.themoep.minedown.adventure.MineDown;
|
|||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
import net.william278.huskhomes.command.BackCommand;
|
import net.william278.huskhomes.command.BackCommand;
|
||||||
import net.william278.huskhomes.command.Command;
|
import net.william278.huskhomes.command.Command;
|
||||||
|
import net.william278.huskhomes.network.Broker;
|
||||||
import net.william278.huskhomes.network.Message;
|
import net.william278.huskhomes.network.Message;
|
||||||
import net.william278.huskhomes.network.Payload;
|
import net.william278.huskhomes.network.Payload;
|
||||||
import net.william278.huskhomes.position.Position;
|
import net.william278.huskhomes.position.Position;
|
||||||
@@ -11,6 +12,7 @@ import net.william278.huskhomes.teleport.Teleport;
|
|||||||
import net.william278.huskhomes.user.OnlineUser;
|
import net.william278.huskhomes.user.OnlineUser;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@@ -40,21 +42,11 @@ public class EventListener {
|
|||||||
if (plugin.getSettings().isCrossServer()) {
|
if (plugin.getSettings().isCrossServer()) {
|
||||||
this.handleInboundTeleport(onlineUser);
|
this.handleInboundTeleport(onlineUser);
|
||||||
|
|
||||||
// Send a player list update to other servers
|
// Synchronize the global player list
|
||||||
this.sendPlayerListUpdates(onlineUser);
|
plugin.runLater(() -> this.synchronizeGlobalPlayerList(onlineUser, plugin.getLocalPlayerList()), 40L);
|
||||||
|
|
||||||
// Request updated player lists from other servers
|
// Request updated player lists from other servers
|
||||||
if (plugin.getOnlineUsers().size() == 1) {
|
if (plugin.getOnlineUsers().size() == 1) {
|
||||||
plugin.runLater(() -> {
|
|
||||||
plugin.getGlobalPlayerList().clear();
|
|
||||||
Message.builder()
|
|
||||||
.type(Message.Type.REQUEST_PLAYER_LIST)
|
|
||||||
.scope(Message.Scope.SERVER)
|
|
||||||
.target(Message.TARGET_ALL)
|
|
||||||
.build().send(plugin.getMessenger(), onlineUser);
|
|
||||||
}, 40L);
|
|
||||||
|
|
||||||
// Update caches
|
|
||||||
plugin.getManager().homes().updatePublicHomeCache();
|
plugin.getManager().homes().updatePublicHomeCache();
|
||||||
plugin.getManager().warps().updateWarpCache();
|
plugin.getManager().warps().updateWarpCache();
|
||||||
}
|
}
|
||||||
@@ -96,19 +88,19 @@ public class EventListener {
|
|||||||
.updateLastPosition(false)
|
.updateLastPosition(false)
|
||||||
.toTeleport().execute(), 40L);
|
.toTeleport().execute(), 40L);
|
||||||
} else {
|
} else {
|
||||||
teleporter.teleportLocally(spawn, plugin.getSettings().isAsynchronousTeleports());
|
teleporter.teleportLocally(spawn, plugin.getSettings().doAsynchronousTeleports());
|
||||||
}
|
}
|
||||||
teleporter.sendTranslatableMessage("block.minecraft.spawn.not_valid");
|
teleporter.sendTranslatableMessage("block.minecraft.spawn.not_valid");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
teleporter.teleportLocally(bedPosition.get(), plugin.getSettings().isAsynchronousTeleports());
|
teleporter.teleportLocally(bedPosition.get(), plugin.getSettings().doAsynchronousTeleports());
|
||||||
}
|
}
|
||||||
plugin.getDatabase().setCurrentTeleport(teleporter, null);
|
plugin.getDatabase().setCurrentTeleport(teleporter, null);
|
||||||
plugin.getDatabase().setRespawnPosition(teleporter, bedPosition.orElse(null));
|
plugin.getDatabase().setRespawnPosition(teleporter, bedPosition.orElse(null));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
teleporter.teleportLocally((Position) teleport.getTarget(), plugin.getSettings().isAsynchronousTeleports());
|
teleporter.teleportLocally((Position) teleport.getTarget(), plugin.getSettings().doAsynchronousTeleports());
|
||||||
plugin.getDatabase().setCurrentTeleport(teleporter, null);
|
plugin.getDatabase().setCurrentTeleport(teleporter, null);
|
||||||
teleport.displayTeleportingComplete(teleporter);
|
teleport.displayTeleportingComplete(teleporter);
|
||||||
});
|
});
|
||||||
@@ -128,19 +120,41 @@ public class EventListener {
|
|||||||
|
|
||||||
// Update global lists
|
// Update global lists
|
||||||
if (plugin.getSettings().isCrossServer()) {
|
if (plugin.getSettings().isCrossServer()) {
|
||||||
|
final List<String> localPlayerList = plugin.getLocalPlayerList().stream()
|
||||||
|
.filter(player -> !player.equals(onlineUser.getUsername()))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
if (plugin.getSettings().getBrokerType() == Broker.Type.REDIS) {
|
||||||
|
this.synchronizeGlobalPlayerList(onlineUser, localPlayerList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
plugin.getOnlineUsers().stream()
|
plugin.getOnlineUsers().stream()
|
||||||
.filter(user -> !user.equals(onlineUser))
|
.filter(user -> !user.equals(onlineUser))
|
||||||
.findAny()
|
.findAny()
|
||||||
.ifPresent(this::sendPlayerListUpdates);
|
.ifPresent(player -> this.synchronizeGlobalPlayerList(player, localPlayerList));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendPlayerListUpdates(@NotNull OnlineUser user) {
|
// Synchronize the global player list
|
||||||
|
private void synchronizeGlobalPlayerList(@NotNull OnlineUser user, @NotNull List<String> localPlayerList) {
|
||||||
|
// Send this server's player list to all servers
|
||||||
Message.builder()
|
Message.builder()
|
||||||
|
.type(Message.Type.PLAYER_LIST)
|
||||||
.scope(Message.Scope.SERVER)
|
.scope(Message.Scope.SERVER)
|
||||||
.target(Message.TARGET_ALL)
|
.target(Message.TARGET_ALL)
|
||||||
.payload(Payload.withStringList(plugin.getLocalPlayerList()))
|
.payload(Payload.withStringList(localPlayerList))
|
||||||
.build().send(plugin.getMessenger(), user);
|
.build().send(plugin.getMessenger(), user);
|
||||||
|
|
||||||
|
// Clear cached global player lists and request updated lists from all servers
|
||||||
|
if (plugin.getOnlineUsers().size() == 1) {
|
||||||
|
plugin.getGlobalPlayerList().clear();
|
||||||
|
Message.builder()
|
||||||
|
.type(Message.Type.REQUEST_PLAYER_LIST)
|
||||||
|
.scope(Message.Scope.SERVER)
|
||||||
|
.target(Message.TARGET_ALL)
|
||||||
|
.build().send(plugin.getMessenger(), user);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import net.william278.huskhomes.position.Warp;
|
|||||||
import net.william278.huskhomes.teleport.Teleport;
|
import net.william278.huskhomes.teleport.Teleport;
|
||||||
import net.william278.huskhomes.user.OnlineUser;
|
import net.william278.huskhomes.user.OnlineUser;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -30,8 +29,8 @@ public abstract class Broker {
|
|||||||
* @param receiver The user who received the message, if a receiver exists
|
* @param receiver The user who received the message, if a receiver exists
|
||||||
* @param message The message
|
* @param message The message
|
||||||
*/
|
*/
|
||||||
protected void handle(@Nullable OnlineUser receiver, @NotNull Message message) {
|
protected void handle(@NotNull OnlineUser receiver, @NotNull Message message) {
|
||||||
if (message.getSourceServer().equals(getServer()) || receiver == null) {
|
if (message.getSourceServer().equals(getServer())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (message.getType()) {
|
switch (message.getType()) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.william278.huskhomes.network;
|
package net.william278.huskhomes.network;
|
||||||
|
|
||||||
import com.google.gson.annotations.Expose;
|
import com.google.gson.annotations.Expose;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
import net.william278.huskhomes.user.OnlineUser;
|
import net.william278.huskhomes.user.OnlineUser;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ public class Message {
|
|||||||
@Expose
|
@Expose
|
||||||
private String sender;
|
private String sender;
|
||||||
@Expose
|
@Expose
|
||||||
|
@SerializedName("source_server")
|
||||||
private String sourceServer;
|
private String sourceServer;
|
||||||
|
|
||||||
private Message(@NotNull Type type, @NotNull Scope scope, @NotNull String target, @NotNull Payload payload) {
|
private Message(@NotNull Type type, @NotNull Scope scope, @NotNull String target, @NotNull Payload payload) {
|
||||||
@@ -127,6 +129,12 @@ public class Message {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Message build() {
|
public Message build() {
|
||||||
|
if (type == null) {
|
||||||
|
throw new IllegalStateException("Message type must be set");
|
||||||
|
}
|
||||||
|
if (target == null) {
|
||||||
|
throw new IllegalStateException("Message target must be set");
|
||||||
|
}
|
||||||
return new Message(type, scope, target, payload);
|
return new Message(type, scope, target, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ public class RedisBroker extends PluginMessageBroker {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.getTarget().equals(plugin.getServerName())) {
|
if (message.getTarget().equals(plugin.getServerName())
|
||||||
|
|| message.getTarget().equals(Message.TARGET_ALL)) {
|
||||||
plugin.getOnlineUsers().stream()
|
plugin.getOnlineUsers().stream()
|
||||||
.findAny()
|
.findAny()
|
||||||
.ifPresent(receiver -> handle(receiver, message));
|
.ifPresent(receiver -> handle(receiver, message));
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class Teleport {
|
|||||||
this.target = target;
|
this.target = target;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.economyActions = actions;
|
this.economyActions = actions;
|
||||||
this.async = plugin.getSettings().isAsynchronousTeleports();
|
this.async = plugin.getSettings().doAsynchronousTeleports();
|
||||||
this.updateLastPosition = updateLastPosition && plugin.getCommand(BackCommand.class)
|
this.updateLastPosition = updateLastPosition && plugin.getCommand(BackCommand.class)
|
||||||
.map(command -> executor.hasPermission(command.getPermission()))
|
.map(command -> executor.hasPermission(command.getPermission()))
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class TeleportRequest {
|
|||||||
@Expose
|
@Expose
|
||||||
private Status status;
|
private Status status;
|
||||||
@Expose
|
@Expose
|
||||||
|
@SerializedName("recipient_name")
|
||||||
private String recipientName;
|
private String recipientName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user