@Override public ComponentBuilder append(String text, ChatColor color) { builder.append(text, net.md_5.bungee.api.chat.ComponentBuilder.FormatRetention.FORMATTING).color(color.asBungee()); return this; }
private BaseComponent[] formatTraceElement(StackTraceElement traceElement) { String className = Pages.filterPackageNames(traceElement.getClassName()); String methodName = traceElement.getMethodName(); boolean nativeMethod = traceElement.isNativeMethod(); int lineNumber = traceElement.getLineNumber(); String line = Integer.toString(lineNumber); if (nativeMethod) { line = "Native"; } return new ComponentBuilder(className + '.') .color(PRIMARY_COLOR.asBungee()) .append(methodName + ':') .color(ChatColor.DARK_GREEN) .append(line) .color(ChatColor.DARK_PURPLE) .create(); }
private BaseComponent[] formatTask(BukkitTask pendingTask) { Plugin owner = pendingTask.getOwner(); int taskId = pendingTask.getTaskId(); boolean sync = pendingTask.isSync(); String id = Integer.toString(taskId); if (sync) { id += "-Sync"; } else if (Bukkit.getScheduler().isCurrentlyRunning(taskId)) { id += "-Running"; } return new ComponentBuilder(owner.getName()) .color(PRIMARY_COLOR.asBungee()) .append('-' + id) .color(SECONDARY_COLOR.asBungee()) .create(); }
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!canExecute(sender, command)) { return true; } List<BaseComponent[]> lines = new ArrayList<>(); List<BukkitTask> pendingTasks = Bukkit.getScheduler().getPendingTasks(); for (BukkitTask pendingTask : pendingTasks) { lines.add(formatTask(pendingTask)); Class<?> runnableClass = getRunnableClass(pendingTask); if (runnableClass != null) { lines.add(new ComponentBuilder(" Task: ") .color(PRIMARY_COLOR.asBungee()) .append(runnableClass.getSimpleName()) .color(SECONDARY_COLOR.asBungee()) .create()); } } Pages pagination = new Pages("Stacktrace", lines); pagination.send(sender); plugin.getPageManager().setPagination(sender.getName(), pagination); return true; }
private void printChildren(Object parent, Object childData, Map<Integer, String> idMap, Collection<BaseComponent[]> lines) { int childId = Reflection.getField(DATA_CLASS, "id", Integer.TYPE).get(childData); String handlerName = idMap.get(childId); String childName; if (handlerName == null) { childName = "Unknown-" + childId; } else { childName = handlerName; } int childCount = Reflection.getField(DATA_CLASS, "count", Integer.TYPE).get(childData); long childTime = Reflection.getField(DATA_CLASS, "totalTime", Long.TYPE).get(childData); long parentTime = Reflection.getField(DATA_CLASS, "totalTime", Long.TYPE).get(parent); double percent = (double) childTime / parentTime; lines.add(new ComponentBuilder(" " + childName + " Count: " + childCount + " Time: " + childTime + ' ' + round(percent) + '%') .color(PRIMARY_COLOR.asBungee()).create()); }
private BaseComponent[] formatJavaVersion(JavaVersion version) { ComponentBuilder builder = new ComponentBuilder("Java version: ").color(PRIMARY_COLOR.asBungee()) .append(version.getRaw()).color(SECONDARY_COLOR.asBungee()); if (version.isOutdated()) { builder = builder.append(" (").color(ChatColor.WHITE) .append("Outdated").color(ChatColor.DARK_RED) .event(new HoverEvent(Action.SHOW_TEXT, new ComponentBuilder("You're running an outdated Java version. \n" + "Java 9 and 10 are already released. \n" + "Newer versions could improve the performance or include bug or security fixes.") .color(ChatColor.DARK_AQUA).create())) .append(")").color(ChatColor.WHITE); } return builder.create(); } }