Fix team chat from being reset after cycle
This commit is contained in:
parent
1eaae36b32
commit
9b59cc0cde
|
@ -34,6 +34,7 @@ public interface ChatDoc {
|
|||
@Serialize
|
||||
interface Complete extends Base {
|
||||
@Nullable PlayerId sender();
|
||||
@Serialize(false) default boolean local() { return false; }
|
||||
}
|
||||
|
||||
enum Type {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package tc.oc.commons.bukkit.channels;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -21,7 +19,6 @@ import tc.oc.commons.core.plugin.PluginFacet;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class SimpleChannel implements MultiAudience, Channel, PluginFacet {
|
||||
|
@ -32,15 +29,9 @@ public abstract class SimpleChannel implements MultiAudience, Channel, PluginFac
|
|||
@Inject protected ChatCreator chatCreator;
|
||||
@Inject protected IdentityProvider identityProvider;
|
||||
|
||||
// Chat messages are sent to the local server before API verification.
|
||||
// This prevents downtime or lockup from stopping all local server chat.
|
||||
protected Cache<String, Boolean> chatCache = CacheBuilder.newBuilder()
|
||||
.expireAfterWrite(10, TimeUnit.MINUTES)
|
||||
.build();
|
||||
|
||||
public abstract BaseComponent prefix();
|
||||
|
||||
public abstract BaseComponent format(PlayerComponent player, String message);
|
||||
public abstract BaseComponent format(Chat chat, PlayerComponent sender, String message);
|
||||
|
||||
@Override
|
||||
public void sendMessage(BaseComponent message) {
|
||||
|
@ -63,16 +54,13 @@ public abstract class SimpleChannel implements MultiAudience, Channel, PluginFac
|
|||
|
||||
@Override
|
||||
public void show(Chat chat) {
|
||||
if(chatCache.getIfPresent(chat._id()) == null) {
|
||||
chatCache.put(chat._id(), true);
|
||||
sendMessage(format(
|
||||
new PlayerComponent(
|
||||
identityProvider.currentOrConsoleIdentity(chat.sender()),
|
||||
NameStyle.FANCY
|
||||
),
|
||||
chat.message()
|
||||
));
|
||||
}
|
||||
sendMessage(format(
|
||||
chat,
|
||||
new PlayerComponent(
|
||||
identityProvider.currentOrConsoleIdentity(chat.sender()),
|
||||
NameStyle.VERBOSE_SIMPLE
|
||||
), chat.message()
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,10 +9,14 @@ import org.bukkit.command.CommandSender;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import tc.oc.api.docs.Chat;
|
||||
import tc.oc.api.docs.Server;
|
||||
import tc.oc.api.docs.virtual.ChatDoc;
|
||||
import tc.oc.api.servers.ServerStore;
|
||||
import tc.oc.commons.bukkit.channels.PermissibleChannel;
|
||||
import tc.oc.commons.bukkit.channels.SimpleChannel;
|
||||
import tc.oc.commons.bukkit.chat.PlayerComponent;
|
||||
import tc.oc.commons.bukkit.format.ServerFormatter;
|
||||
import tc.oc.commons.bukkit.permissions.PermissionRegistry;
|
||||
import tc.oc.commons.bukkit.settings.SettingManagerProvider;
|
||||
import tc.oc.commons.core.chat.Component;
|
||||
|
@ -34,10 +38,12 @@ public class AdminChannel extends SimpleChannel implements PermissibleChannel {
|
|||
|
||||
private final SettingManagerProvider settings;
|
||||
private final PermissionRegistry permissions;
|
||||
private final ServerStore serverStore;
|
||||
|
||||
@Inject AdminChannel(PermissionRegistry permissions, SettingManagerProvider settings) {
|
||||
@Inject AdminChannel(PermissionRegistry permissions, SettingManagerProvider settings, ServerStore serverStore) {
|
||||
this.settings = settings;
|
||||
this.permissions = permissions;
|
||||
this.serverStore = serverStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,8 +69,17 @@ public class AdminChannel extends SimpleChannel implements PermissibleChannel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent format(PlayerComponent player, String message) {
|
||||
return new Component(player).extra(": ").extra(message);
|
||||
public BaseComponent format(Chat chat, PlayerComponent player, String message) {
|
||||
BaseComponent stub;
|
||||
if(chat.local()) {
|
||||
stub = player;
|
||||
} else {
|
||||
final Server server = serverStore.byId(chat.server_id());
|
||||
stub = ServerFormatter.light.nameWithDatacenter(server);
|
||||
stub.addExtra(" ");
|
||||
stub.addExtra(player);
|
||||
}
|
||||
return new Component(stub).extra(": ").extra(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,6 +2,7 @@ package tc.oc.commons.bukkit.channels.server;
|
|||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import tc.oc.api.docs.Chat;
|
||||
import tc.oc.api.docs.virtual.ChatDoc;
|
||||
import tc.oc.commons.bukkit.channels.SimpleChannel;
|
||||
import tc.oc.commons.bukkit.chat.PlayerComponent;
|
||||
|
@ -21,8 +22,8 @@ public class ServerChannel extends SimpleChannel {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent format(PlayerComponent player, String message) {
|
||||
return new Component().extra("<").extra(player).extra(">: ").extra(message);
|
||||
public BaseComponent format(Chat chat, PlayerComponent sender, String message) {
|
||||
return new Component().extra("<").extra(sender).extra(">: ").extra(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,6 +3,7 @@ package tc.oc.commons.bukkit.chat;
|
|||
import tc.oc.api.docs.Chat;
|
||||
import tc.oc.api.docs.Server;
|
||||
import tc.oc.api.docs.virtual.ChatDoc;
|
||||
import tc.oc.api.docs.virtual.ServerDoc;
|
||||
import tc.oc.api.message.MessageListener;
|
||||
import tc.oc.api.message.types.ModelUpdate;
|
||||
import tc.oc.api.queue.PrimaryQueue;
|
||||
|
@ -62,15 +63,13 @@ public class ChatAnnouncer implements PluginFacet, MessageListener {
|
|||
}
|
||||
|
||||
public boolean shouldAnnounce(Chat chat) {
|
||||
final Server origin = serverStore.byId(chat.server_id());
|
||||
final boolean local = server.equals(origin);
|
||||
final boolean remote = serverStore.canCommunicate(server._id(), origin._id());
|
||||
final boolean remote = serverStore.canCommunicate(server._id(), chat.server_id());
|
||||
switch(chat.type()) {
|
||||
case SERVER:
|
||||
case TEAM:
|
||||
return local;
|
||||
return false;
|
||||
case ADMIN:
|
||||
return local || remote;
|
||||
return remote;
|
||||
case BROADCAST:
|
||||
return shouldAnnounce(chat.broadcast());
|
||||
}
|
||||
|
@ -83,12 +82,14 @@ public class ChatAnnouncer implements PluginFacet, MessageListener {
|
|||
case SERVER:
|
||||
return server._id().equalsIgnoreCase(destination);
|
||||
case FAMILY:
|
||||
return server.family().equalsIgnoreCase(destination);
|
||||
final String family = server.family();
|
||||
return family == null || family.equalsIgnoreCase(destination);
|
||||
case GAME:
|
||||
final String game = server.game_id();
|
||||
return game == null || game.equalsIgnoreCase(destination);
|
||||
case NETWORK:
|
||||
return server.network().name().equalsIgnoreCase(destination);
|
||||
final ServerDoc.Network network = server.network();
|
||||
return network == null || network.name().equalsIgnoreCase(destination);
|
||||
case GLOBAL:
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -85,6 +85,7 @@ public class ChatCreator implements PluginFacet, Listener {
|
|||
public ChatDoc.Type type() { return chat.type(); }
|
||||
public Instant sent_at() { return chat.sent_at(); }
|
||||
public ChatDoc.Broadcast broadcast() { return chat.broadcast(); }
|
||||
public boolean local() { return true; }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,13 @@ public class NameStyle extends ForwardingSet<NameFlag> {
|
|||
);
|
||||
|
||||
|
||||
public static final NameStyle VERBOSE_SIMPLE = new NameStyle(
|
||||
Sets.difference(
|
||||
VERBOSE,
|
||||
Sets.newHashSet(NameFlag.SELF, NameFlag.FRIEND)
|
||||
)
|
||||
);
|
||||
|
||||
// Fancy minus mapmaker flair (for display in map credits)
|
||||
public static final NameStyle MAPMAKER = new NameStyle(
|
||||
Sets.difference(
|
||||
|
|
|
@ -46,8 +46,12 @@ public class ChannelMatchModule extends MatchModule implements Listener {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
public void disable() {
|
||||
channelRouter.setTeamChannelFunction(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload() {
|
||||
match.getParties().forEach(this::remove);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package tc.oc.pgm.channels;
|
|||
import com.google.inject.assistedinject.Assisted;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import tc.oc.api.docs.Chat;
|
||||
import tc.oc.api.docs.virtual.ChatDoc;
|
||||
import tc.oc.commons.bukkit.channels.SimpleChannel;
|
||||
import tc.oc.commons.bukkit.chat.PlayerComponent;
|
||||
|
@ -39,7 +40,7 @@ public class PartyChannel extends SimpleChannel implements MultiAudience {
|
|||
}
|
||||
|
||||
@Override
|
||||
public BaseComponent format(PlayerComponent player, String message) {
|
||||
public BaseComponent format(Chat chat, PlayerComponent player, String message) {
|
||||
return new Component(player).extra(": ").extra(message);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue