use of net.minecraft.text.MutableText in project UniversalGraves by Patbox.
the class GraveListGui method updateIcons.
private void updateIcons() {
var config = ConfigManager.getConfig();
for (int x = 0; x < this.size; x++) {
this.clearSlot(x);
}
for (GraveInfo graveInfo : GraveManager.INSTANCE.getByUuid(this.targetUUID)) {
if (this.getFirstEmptySlot() == -1) {
return;
}
Map<String, Text> placeholders = graveInfo.getPlaceholders();
List<Text> parsed = new ArrayList<>();
for (Text text : graveInfo.isProtected() ? ConfigManager.getConfig().guiProtectedText : ConfigManager.getConfig().guiText) {
MutableText out = (MutableText) PlaceholderAPI.parsePredefinedText(text, PlaceholderAPI.PREDEFINED_PLACEHOLDER_PATTERN, placeholders);
if (out.getStyle().getColor() == null) {
out.setStyle(out.getStyle().withColor(Formatting.WHITE));
}
parsed.add(out);
}
var list = graveInfo.isProtected() ? config.guiProtectedItem : config.guiItem;
this.addSlot(GuiElementBuilder.from(list[Math.abs(graveInfo.hashCode() % list.length)]).setName((MutableText) parsed.remove(0)).setLore(parsed).setCallback((index, type, action) -> {
if (Permissions.check(this.player, "universal_graves.teleport", 3)) {
this.close();
ServerWorld world = this.player.getServer().getWorld(RegistryKey.of(Registry.WORLD_KEY, graveInfo.getWorld()));
if (world != null) {
var pos = graveInfo.getPosition();
this.player.teleport(world, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, this.player.getYaw(), this.player.getPitch());
}
}
}));
}
}
use of net.minecraft.text.MutableText in project BleachHack by BleachDrinker420.
the class Texts method forEachWord.
/**
* Does an operation to each word in a text. *
*/
public static Text forEachWord(Text text, BiFunction<String, Style, Text> operator) {
MutableText newFullText = new LiteralText("");
for (Text t : unpack(text)) {
MutableText newText = new LiteralText("");
String curString = "";
String[] split = t.getString().split(" ", -1);
for (int i = 0; i < split.length; i++) {
Text word = operator.apply(split[i], t.getStyle());
if (word != null) {
if (!curString.isEmpty()) {
newText.append(new LiteralText(curString).setStyle(t.getStyle()));
curString = "";
}
newText.append(word);
} else {
curString += split[i];
}
if (i != split.length - 1)
curString += " ";
}
if (!curString.isEmpty())
newText.append(new LiteralText(curString).setStyle(t.getStyle()));
newFullText.append(newText);
}
return newFullText;
}
use of net.minecraft.text.MutableText in project BleachHack by BleachDrinker420.
the class Texts method replaceAll.
/**
* Replaces every string in this text that matches the pattern with a text from the provider. *
*/
public static Text replaceAll(Text text, Pattern pattern, BiFunction<String, Style, Text> replacement) {
if (pattern.pattern().isEmpty())
return text;
MutableText newText = new LiteralText("");
for (Text t : unpack(text)) {
String string = t.getString();
Map<Integer, Integer> positions = new HashMap<>();
Matcher mat = pattern.matcher(string);
while (mat.find()) {
positions.put(mat.start(), mat.end());
}
String curString = "";
for (int i = 0; i < string.length(); i++) {
if (positions.containsKey(i)) {
if (!curString.isEmpty()) {
newText = newText.append(new LiteralText(curString).setStyle(t.getStyle()));
curString = "";
}
newText.append(replacement.apply(string.substring(i, positions.get(i)), t.getStyle()));
i = positions.get(i) - 1;
} else {
curString += string.charAt(i);
}
}
if (!curString.isEmpty())
newText.append(new LiteralText(curString).setStyle(t.getStyle()));
}
return newText;
}
use of net.minecraft.text.MutableText in project BleachHack by BleachDrinker420.
the class CmdBetterChat method onCommand.
@Override
public void onCommand(String alias, String[] args) throws Exception {
if (args.length < 2) {
throw new CmdSyntaxException();
}
BetterChat chat = ModuleManager.getModule(BetterChat.class);
if (args[0].equalsIgnoreCase("filter")) {
if (args[1].equalsIgnoreCase("list")) {
MutableText text = new LiteralText("Filter Entries:");
int i = 1;
for (Pattern pat : chat.filterPatterns) {
text = text.append(new LiteralText("\n\u00a76" + i + " > \u00a7f" + pat.pattern()).styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Click to remove this filter."))).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, getPrefix() + "betterchat filter remove " + pat.pattern()))));
i++;
}
BleachLogger.info(text);
} else if (args[1].equalsIgnoreCase("add")) {
String arg = String.join(" ", ArrayUtils.subarray(args, 2, args.length)).trim();
chat.filterPatterns.add(Pattern.compile(arg));
JsonArray jsonFilter = new JsonArray();
chat.filterPatterns.forEach(p -> jsonFilter.add(p.toString()));
BleachFileHelper.saveMiscSetting("betterChatFilter", jsonFilter);
BleachLogger.info("Added \"" + arg + "\" to the filter patterns.");
} else if (args[1].equalsIgnoreCase("remove")) {
String arg = String.join(" ", ArrayUtils.subarray(args, 2, args.length)).trim();
if (chat.filterPatterns.removeIf(p -> p.toString().equals(arg))) {
JsonArray jsonFilter = new JsonArray();
chat.filterPatterns.forEach(p -> jsonFilter.add(p.toString()));
BleachFileHelper.saveMiscSetting("betterChatFilter", jsonFilter);
BleachLogger.info("Removed \"" + arg + "\" from the filter patterns.");
} else {
BleachLogger.info("Could not find \"" + arg + "\" in the pattern list.");
}
} else {
throw new CmdSyntaxException();
}
} else if (args[0].equalsIgnoreCase("prefix")) {
if (args[1].equalsIgnoreCase("current")) {
BleachLogger.info("Current prefix: \"" + chat.prefix + "\"");
} else if (args[1].equalsIgnoreCase("reset")) {
chat.prefix = "";
BleachFileHelper.saveMiscSetting("betterChatPrefix", new JsonPrimitive(chat.prefix));
BleachLogger.info("Reset the customchat prefix!");
} else if (args[1].equalsIgnoreCase("set") && args.length >= 3) {
chat.prefix = String.join(" ", ArrayUtils.subarray(args, 2, args.length)).trim() + " ";
BleachFileHelper.saveMiscSetting("betterChatPrefix", new JsonPrimitive(chat.prefix));
BleachLogger.info("Set prefix to: \"" + chat.prefix + "\"");
} else {
throw new CmdSyntaxException();
}
} else if (args[0].equalsIgnoreCase("suffix")) {
if (args[1].equalsIgnoreCase("current")) {
BleachLogger.info("Current suffix: \"" + chat.suffix + "\"");
} else if (args[1].equalsIgnoreCase("reset")) {
chat.suffix = " \u25ba \u0432\u029f\u0454\u03b1c\u043d\u043d\u03b1c\u043a";
BleachFileHelper.saveMiscSetting("betterChatSuffix", new JsonPrimitive(chat.suffix));
BleachLogger.info("Reset the customchat suffix!");
} else if (args[1].equalsIgnoreCase("set") && args.length >= 3) {
chat.suffix = String.join(" ", ArrayUtils.subarray(args, 2, args.length)).trim() + " ";
BleachFileHelper.saveMiscSetting("betterChatSuffix", new JsonPrimitive(chat.suffix));
BleachLogger.info("Set suffix to: \"" + chat.suffix + "\"");
} else {
throw new CmdSyntaxException();
}
} else {
throw new CmdSyntaxException();
}
}
use of net.minecraft.text.MutableText in project BleachHack by BleachDrinker420.
the class CmdHelp method onCommand.
@Override
public void onCommand(String alias, String[] args) throws Exception {
String cmd = args.length == 0 ? "" : args[0];
if (cmd.isEmpty()) {
BleachLogger.info("Commands:");
} else {
BleachLogger.info("Syntax for " + getPrefix() + cmd.toLowerCase(Locale.ENGLISH) + ":");
}
for (Command c : CommandManager.getCommands()) {
if (!cmd.isEmpty() && Stream.of(c.getAliases()).noneMatch(cmd::equalsIgnoreCase))
continue;
MutableText text = new LiteralText(getPrefix() + c.getAliases()[0] + ": \u00a7f" + c.getDescription()).styled(s -> s.withColor(BleachLogger.INFO_COLOR));
BleachLogger.noPrefix(text.styled(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, c.getHelpTooltip()))));
}
}
Aggregations