Search in sources :

Example 1 with TranslatableCaption

use of com.plotsquared.core.configuration.caption.TranslatableCaption in project PlotSquared by IntellectualSites.

the class Debug method onCommand.

@Override
public boolean onCommand(PlotPlayer<?> player, String[] args) {
    if (args.length == 0) {
        player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"), Template.of("value", "/plot debug <loadedchunks | player | debug-players | entitytypes | msg>"));
    }
    if (args.length > 0) {
        if ("player".equalsIgnoreCase(args[0])) {
            for (Map.Entry<String, Object> meta : player.getMeta().entrySet()) {
                player.sendMessage(StaticCaption.of("Key: " + meta.getKey() + " Value: " + meta.getValue().toString() + " , "));
            }
            return true;
        }
    }
    if (args.length > 0 && "loadedchunks".equalsIgnoreCase(args[0])) {
        final long start = System.currentTimeMillis();
        player.sendMessage(TranslatableCaption.of("debug.fetching_loaded_chunks"));
        TaskManager.runTaskAsync(() -> player.sendMessage(StaticCaption.of("Loaded chunks: " + this.worldUtil.getChunkChunks(player.getLocation().getWorldName()).size() + " (" + (System.currentTimeMillis() - start) + "ms) using thread: " + Thread.currentThread().getName())));
        return true;
    }
    if (args.length > 0 && "uuids".equalsIgnoreCase(args[0])) {
        final Collection<UUIDMapping> mappings = PlotSquared.get().getImpromptuUUIDPipeline().getAllImmediately();
        player.sendMessage(TranslatableCaption.of("debug.cached_uuids"), Template.of("value", String.valueOf(mappings.size())));
        return true;
    }
    if (args.length > 0 && "debug-players".equalsIgnoreCase(args[0])) {
        player.sendMessage(TranslatableCaption.of("debug.player_in_debugmode"));
        for (final PlotPlayer<?> pp : PlotPlayer.getDebugModePlayers()) {
            player.sendMessage(TranslatableCaption.of("debug.player_in_debugmode_list"), Template.of("value", pp.getName()));
        }
        return true;
    }
    if (args.length > 0 && "entitytypes".equalsIgnoreCase(args[0])) {
        EntityCategories.init();
        player.sendMessage(TranslatableCaption.of("debug.entity_categories"));
        EntityCategory.REGISTRY.forEach(category -> {
            final StringBuilder builder = new StringBuilder("§7- §6").append(category.getId()).append("§7: §6");
            for (final EntityType entityType : category.getAll()) {
                builder.append(entityType.getId()).append(" ");
            }
            player.sendMessage(StaticCaption.of("<prefix>" + builder));
        });
        EntityType.REGISTRY.values().stream().sorted(Comparator.comparing(EntityType::getId)).forEach(entityType -> {
            long categoryCount = EntityCategory.REGISTRY.values().stream().filter(category -> category.contains(entityType)).count();
            if (categoryCount > 0) {
                return;
            }
            player.sendMessage(StaticCaption.of("<prefix>" + entityType.getName() + " is in " + categoryCount + " categories"));
        });
        return true;
    }
    Set<TranslatableCaption> captions = PlotSquared.get().getCaptionMap(TranslatableCaption.DEFAULT_NAMESPACE).getCaptions();
    TextComponent.Builder information = Component.text();
    Component header = MINI_MESSAGE.parse(TranslatableCaption.of("debug.debug_header").getComponent(player) + "\n");
    String line = TranslatableCaption.of("debug.debug_line").getComponent(player) + "\n";
    String section = TranslatableCaption.of("debug.debug_section").getComponent(player) + "\n";
    information.append(header);
    information.append(MINI_MESSAGE.parse(section, Template.of("val", "PlotArea")));
    information.append(MINI_MESSAGE.parse(line, Template.of("var", "Plot Worlds"), Template.of("val", StringMan.join(this.plotAreaManager.getAllPlotAreas(), ", "))));
    information.append(MINI_MESSAGE.parse(line, Template.of("var", "Owned Plots"), Template.of("val", String.valueOf(PlotQuery.newQuery().allPlots().count()))));
    information.append(MINI_MESSAGE.parse(section, Template.of("val", "Messages")));
    information.append(MINI_MESSAGE.parse(line, Template.of("var", "Total Messages"), Template.of("val", String.valueOf(captions.size()))));
    player.sendMessage(StaticCaption.of(MINI_MESSAGE.serialize(information.build())));
    return true;
}
Also used : NonNull(org.checkerframework.checker.nullness.qual.NonNull) Inject(com.google.inject.Inject) PlotQuery(com.plotsquared.core.util.query.PlotQuery) EntityCategory(com.plotsquared.core.util.entity.EntityCategory) EntityType(com.sk89q.worldedit.world.entity.EntityType) StaticCaption(com.plotsquared.core.configuration.caption.StaticCaption) Component(net.kyori.adventure.text.Component) Locale(java.util.Locale) Map(java.util.Map) Template(net.kyori.adventure.text.minimessage.Template) WorldUtil(com.plotsquared.core.util.WorldUtil) TextComponent(net.kyori.adventure.text.TextComponent) PlotAreaManager(com.plotsquared.core.plot.world.PlotAreaManager) TaskManager(com.plotsquared.core.util.task.TaskManager) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) PlotSquared(com.plotsquared.core.PlotSquared) Stream(java.util.stream.Stream) EntityCategories(com.plotsquared.core.util.entity.EntityCategories) PlotPlayer(com.plotsquared.core.player.PlotPlayer) TranslatableCaption(com.plotsquared.core.configuration.caption.TranslatableCaption) StringMan(com.plotsquared.core.util.StringMan) UUIDMapping(com.plotsquared.core.uuid.UUIDMapping) Comparator(java.util.Comparator) TextComponent(net.kyori.adventure.text.TextComponent) TranslatableCaption(com.plotsquared.core.configuration.caption.TranslatableCaption) EntityType(com.sk89q.worldedit.world.entity.EntityType) UUIDMapping(com.plotsquared.core.uuid.UUIDMapping) Component(net.kyori.adventure.text.Component) TextComponent(net.kyori.adventure.text.TextComponent) Map(java.util.Map)

Aggregations

Inject (com.google.inject.Inject)1 PlotSquared (com.plotsquared.core.PlotSquared)1 StaticCaption (com.plotsquared.core.configuration.caption.StaticCaption)1 TranslatableCaption (com.plotsquared.core.configuration.caption.TranslatableCaption)1 PlotPlayer (com.plotsquared.core.player.PlotPlayer)1 PlotAreaManager (com.plotsquared.core.plot.world.PlotAreaManager)1 StringMan (com.plotsquared.core.util.StringMan)1 WorldUtil (com.plotsquared.core.util.WorldUtil)1 EntityCategories (com.plotsquared.core.util.entity.EntityCategories)1 EntityCategory (com.plotsquared.core.util.entity.EntityCategory)1 PlotQuery (com.plotsquared.core.util.query.PlotQuery)1 TaskManager (com.plotsquared.core.util.task.TaskManager)1 UUIDMapping (com.plotsquared.core.uuid.UUIDMapping)1 EntityType (com.sk89q.worldedit.world.entity.EntityType)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1