Search in sources :

Example 1 with Player

use of de.codecrafter47.taboverlay.config.player.Player in project BungeeTabListPlus by CodeCrafter47.

the class API method removeCustomTabList0.

@Override
protected void removeCustomTabList0(ProxiedPlayer player) {
    TabView tabView = tabViewManager.getTabView(player);
    if (tabView == null) {
        throw new IllegalStateException("unknown player");
    }
    tabView.getTabOverlayProviders().removeProviders(DefaultCustomTablist.TabOverlayProviderImpl.class);
}
Also used : DefaultCustomTablist(codecrafter47.bungeetablistplus.tablist.DefaultCustomTablist) TabView(de.codecrafter47.taboverlay.TabView)

Example 2 with Player

use of de.codecrafter47.taboverlay.config.player.Player in project BungeeTabListPlus by CodeCrafter47.

the class API method setCustomTabList0.

@Override
protected void setCustomTabList0(ProxiedPlayer player, CustomTablist customTablist) {
    TabView tabView = tabViewManager.getTabView(player);
    if (tabView == null) {
        throw new IllegalStateException("unknown player");
    }
    if (customTablist instanceof DefaultCustomTablist) {
        tabView.getTabOverlayProviders().removeProviders(DefaultCustomTablist.TabOverlayProviderImpl.class);
        ((DefaultCustomTablist) customTablist).addToPlayer(tabView);
    } else {
        throw new IllegalArgumentException("customTablist not created by createCustomTablist()");
    }
}
Also used : DefaultCustomTablist(codecrafter47.bungeetablistplus.tablist.DefaultCustomTablist) TabView(de.codecrafter47.taboverlay.TabView)

Example 3 with Player

use of de.codecrafter47.taboverlay.config.player.Player in project BungeeTabListPlus by CodeCrafter47.

the class RedisPlayerManager method onRedisMessage.

@EventHandler
@SuppressWarnings("unchecked")
public void onRedisMessage(PubSubMessageEvent event) {
    String channel = event.getChannel();
    if (channel.equals(CHANNEL_DATA_REQUEST)) {
        ByteArrayDataInput input = ByteStreams.newDataInput(Base64.getDecoder().decode(event.getMessage()));
        try {
            UUID uuid = DataStreamUtils.readUUID(input);
            ProxiedPlayer proxiedPlayer = ProxyServer.getInstance().getPlayer(uuid);
            if (proxiedPlayer != null) {
                BungeePlayer player = bungeePlayerProvider.getPlayerIfPresent(proxiedPlayer);
                if (player != null) {
                    DataKey<?> key = DataStreamUtils.readDataKey(input, keyRegistry, missingDataKeyLogger);
                    if (key != null) {
                        player.addDataChangeListener((DataKey<Object>) key, new DataChangeListener(player, (DataKey<Object>) key));
                        updateData(uuid, (DataKey<Object>) key, player.get(key));
                    }
                }
            }
        } catch (IOException ex) {
            logger.log(Level.SEVERE, "Unexpected error reading redis message", ex);
        }
    } else if (channel.equals(CHANNEL_DATA_UPDATE)) {
        ByteArrayDataInput input = ByteStreams.newDataInput(Base64.getDecoder().decode(event.getMessage()));
        try {
            UUID uuid = DataStreamUtils.readUUID(input);
            RedisPlayer player = byUUID.get(uuid);
            if (player != null) {
                DataCache cache = player.getData();
                DataKey<?> key = DataStreamUtils.readDataKey(input, keyRegistry, missingDataKeyLogger);
                if (key != null) {
                    boolean removed = input.readBoolean();
                    if (removed) {
                        mainThread.execute(() -> cache.updateValue(key, null));
                    } else {
                        Object value = typeRegistry.getTypeAdapter(key.getType()).read(input);
                        mainThread.execute(() -> cache.updateValue((DataKey<Object>) key, value));
                    }
                }
            }
        } catch (IOException ex) {
            logger.log(Level.SEVERE, "Unexpected error reading redis message", ex);
        }
    } else if (channel.equals(CHANNEL_DATA_OLD) || channel.equals(CHANNEL_REQUEST_DATA_OLD)) {
        logger.warning("BungeeTabListPlus on at least one proxy in your network is outdated.");
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) BungeePlayer(codecrafter47.bungeetablistplus.player.BungeePlayer) DataKey(de.codecrafter47.data.api.DataKey) IOException(java.io.IOException) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) RedisPlayer(codecrafter47.bungeetablistplus.player.RedisPlayer) DataCache(de.codecrafter47.data.api.DataCache) EventHandler(net.md_5.bungee.event.EventHandler)

Example 4 with Player

use of de.codecrafter47.taboverlay.config.player.Player in project BungeeTabListPlus by CodeCrafter47.

the class TabViewManager method createTabView.

private PlayerTabView createTabView(ProxiedPlayer player) {
    try {
        TabOverlayHandler tabOverlayHandler;
        PacketHandler packetHandler;
        Logger logger = new ChildLogger(btlp.getLogger(), player.getName());
        EventLoop eventLoop = ReflectionUtil.getChannelWrapper(player).getHandle().eventLoop();
        if (protocolVersionProvider.has18OrLater(player)) {
            LowMemoryTabOverlayHandlerImpl tabOverlayHandlerImpl = new LowMemoryTabOverlayHandlerImpl(logger, eventLoop, player.getUniqueId(), player, protocolVersionProvider.is18(player), protocolVersionProvider.has113OrLater(player));
            tabOverlayHandler = tabOverlayHandlerImpl;
            packetHandler = new RewriteLogic(new GetGamemodeLogic(tabOverlayHandlerImpl, ((UserConnection) player)));
        } else {
            LegacyTabOverlayHandlerImpl legacyTabOverlayHandler = new LegacyTabOverlayHandlerImpl(logger, player.getPendingConnection().getListener().getTabListSize(), eventLoop, player, protocolVersionProvider.has113OrLater(player));
            tabOverlayHandler = legacyTabOverlayHandler;
            packetHandler = legacyTabOverlayHandler;
        }
        return new PlayerTabView(tabOverlayHandler, logger, btlp.getAsyncExecutor(), packetHandler);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw new AssertionError("Failed to create tab view", e);
    }
}
Also used : ChildLogger(de.codecrafter47.taboverlay.util.ChildLogger) LowMemoryTabOverlayHandlerImpl(codecrafter47.bungeetablistplus.handler.LowMemoryTabOverlayHandlerImpl) GetGamemodeLogic(codecrafter47.bungeetablistplus.handler.GetGamemodeLogic) ChildLogger(de.codecrafter47.taboverlay.util.ChildLogger) Logger(java.util.logging.Logger) UserConnection(net.md_5.bungee.UserConnection) TabOverlayHandler(de.codecrafter47.taboverlay.handler.TabOverlayHandler) PacketHandler(codecrafter47.bungeetablistplus.protocol.PacketHandler) EventLoop(io.netty.channel.EventLoop) LegacyTabOverlayHandlerImpl(codecrafter47.bungeetablistplus.handler.LegacyTabOverlayHandlerImpl) RewriteLogic(codecrafter47.bungeetablistplus.handler.RewriteLogic)

Example 5 with Player

use of de.codecrafter47.taboverlay.config.player.Player in project BungeeTabListPlus by CodeCrafter47.

the class PlayerPlaceholderResolver method resolve.

@Nonnull
@Override
public PlaceholderBuilder<?, ?> resolve(PlaceholderBuilder<Player, ?> builder, List<PlaceholderArg> args, TemplateCreationContext tcc) throws UnknownPlaceholderException, PlaceholderException {
    if (!args.isEmpty() && aliasMap.containsKey(args.get(0).getText())) {
        String replacement = aliasMap.get(args.get(0).getText());
        tcc.getErrorHandler().addWarning("Placeholder '" + args.get(0).getText() + "' has been deprecated. Use '" + replacement + "' instead.", null);
        args.set(0, new PlaceholderArg.Text(replacement));
    }
    try {
        return super.resolve(builder, args, tcc);
    } catch (UnknownPlaceholderException e) {
        if (!args.isEmpty()) {
            String id = args.get(0).getText().toLowerCase();
            PlaceholderBuilder<?, ?> result = null;
            if (customPlaceholderDataKeys.containsKey(id)) {
                DataKey<String> dataKey = customPlaceholderDataKeys.get(id);
                result = builder.acquireData(new PlayerPlaceholderDataProviderSupplier<>(TypeToken.STRING, dataKey, (player, replacement) -> replacement), TypeToken.STRING);
            } else if (bridgeCustomPlaceholderDataKeys.containsKey(id)) {
                DataKey<String> dataKey = bridgeCustomPlaceholderDataKeys.get(id);
                result = builder.acquireData(new PlayerPlaceholderDataProviderSupplier<>(TypeToken.STRING, dataKey, (player, replacement) -> replacement), TypeToken.STRING);
            } else {
                for (String prefix : placeholderAPIPluginPrefixes) {
                    if (id.length() >= prefix.length() && id.substring(0, prefix.length()).equalsIgnoreCase(prefix)) {
                        id = args.remove(0).getText();
                        val resolver = create(BTLPDataKeys.createPlaceholderAPIDataKey("%" + id + "%"));
                        addPlaceholder(id, resolver);
                        return resolver.resolve(builder, args, tcc);
                    }
                }
            }
            if (result == null) {
                // prevent errors because bridge information has not been synced yet
                if (cache.getCustomPlaceholdersBridge().contains(id)) {
                    result = builder.acquireData(new PlayerPlaceholderDataProviderSupplier<>(TypeToken.STRING, BTLPDataKeys.createThirdPartyVariableDataKey(id), (player, replacement) -> replacement), TypeToken.STRING);
                } else {
                    for (String prefix : cache.getPAPIPrefixes()) {
                        if (id.length() >= prefix.length() && id.substring(0, prefix.length()).equalsIgnoreCase(prefix)) {
                            result = builder.acquireData(new PlayerPlaceholderDataProviderSupplier<>(TypeToken.STRING, BTLPDataKeys.createPlaceholderAPIDataKey("%" + id + "%"), (player, replacement) -> replacement), TypeToken.STRING);
                        }
                    }
                }
            }
            if (result != null) {
                args.remove(0);
                return result;
            }
        }
        throw e;
    }
}
Also used : Player(de.codecrafter47.taboverlay.config.player.Player) ToStringExpression(de.codecrafter47.taboverlay.config.expression.ToStringExpression) java.util(java.util) ExpressionTemplate(de.codecrafter47.taboverlay.config.expression.template.ExpressionTemplate) DataKey(de.codecrafter47.data.api.DataKey) lombok.val(lombok.val) AbstractActiveElement(de.codecrafter47.taboverlay.config.view.AbstractActiveElement) Function(java.util.function.Function) ExpressionUpdateListener(de.codecrafter47.taboverlay.config.expression.ExpressionUpdateListener) BukkitData(de.codecrafter47.data.bukkit.api.BukkitData) de.codecrafter47.taboverlay.config.placeholder(de.codecrafter47.taboverlay.config.placeholder) TypeToken(de.codecrafter47.data.api.TypeToken) TemplateCreationContext(de.codecrafter47.taboverlay.config.template.TemplateCreationContext) SpongeData(de.codecrafter47.data.sponge.api.SpongeData) Cache(codecrafter47.bungeetablistplus.cache.Cache) BungeeData(de.codecrafter47.data.bungee.api.BungeeData) MinecraftData(de.codecrafter47.data.minecraft.api.MinecraftData) BTLPDataKeys(codecrafter47.bungeetablistplus.common.BTLPDataKeys) Context(de.codecrafter47.taboverlay.config.context.Context) Nonnull(javax.annotation.Nonnull) BTLPBungeeDataKeys(codecrafter47.bungeetablistplus.data.BTLPBungeeDataKeys) lombok.val(lombok.val) DataKey(de.codecrafter47.data.api.DataKey) Nonnull(javax.annotation.Nonnull)

Aggregations

DataKey (de.codecrafter47.data.api.DataKey)3 TabView (de.codecrafter47.taboverlay.TabView)3 Context (de.codecrafter47.taboverlay.config.context.Context)3 TemplateCreationContext (de.codecrafter47.taboverlay.config.template.TemplateCreationContext)3 Cache (codecrafter47.bungeetablistplus.cache.Cache)2 BTLPDataKeys (codecrafter47.bungeetablistplus.common.BTLPDataKeys)2 BTLPBungeeDataKeys (codecrafter47.bungeetablistplus.data.BTLPBungeeDataKeys)2 BungeePlayer (codecrafter47.bungeetablistplus.player.BungeePlayer)2 DefaultCustomTablist (codecrafter47.bungeetablistplus.tablist.DefaultCustomTablist)2 TypeToken (de.codecrafter47.data.api.TypeToken)2 BukkitData (de.codecrafter47.data.bukkit.api.BukkitData)2 BungeeData (de.codecrafter47.data.bungee.api.BungeeData)2 MinecraftData (de.codecrafter47.data.minecraft.api.MinecraftData)2 SpongeData (de.codecrafter47.data.sponge.api.SpongeData)2 ExpressionUpdateListener (de.codecrafter47.taboverlay.config.expression.ExpressionUpdateListener)2 ToStringExpression (de.codecrafter47.taboverlay.config.expression.ToStringExpression)2 ExpressionTemplate (de.codecrafter47.taboverlay.config.expression.template.ExpressionTemplate)2 de.codecrafter47.taboverlay.config.placeholder (de.codecrafter47.taboverlay.config.placeholder)2 Player (de.codecrafter47.taboverlay.config.player.Player)2 BungeeTabListPlus (codecrafter47.bungeetablistplus.BungeeTabListPlus)1