use of net.minecraft.text.ClickEvent in project fabric-name-history-lookup by Woolyenough.
the class ClientCommands method names.
private static int names(CommandContext<FabricClientCommandSource> context) {
CompletableFuture.runAsync(() -> {
String name = context.getInput().split(" ")[1];
String[] playerNameAndUUID = get_player_name_and_uuid(name);
String username = playerNameAndUUID[0];
String uuid = playerNameAndUUID[1];
if (Objects.equals(username, "None")) {
context.getSource().sendError(new LiteralText("No account exists by that name .-."));
} else {
context.getSource().sendFeedback(new LiteralText("§7[Hover] §eView name history of " + username).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://namemc.com/profile/" + username)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, get_player_name_history(username, uuid).append(new LiteralText("\n\n§7§oClick to open in NameMC!"))))));
}
});
return 0;
}
use of net.minecraft.text.ClickEvent 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.ClickEvent in project meteor-client by MeteorDevelopment.
the class BookBot method onTick.
@EventHandler
private void onTick(TickEvent.Post event) {
FindItemResult writableBook = InvUtils.find(Items.WRITABLE_BOOK);
// Check if there is a book to write
if (!writableBook.found()) {
toggle();
return;
}
// Move the book into hand
if (!writableBook.isMainHand()) {
InvUtils.move().from(writableBook.slot()).toHotbar(mc.player.getInventory().selectedSlot);
return;
}
// If somehow it failed, just dont do anything until it tries again
FindItemResult finalBook = InvUtils.findInHotbar(Items.WRITABLE_BOOK);
if (!finalBook.isMainHand())
return;
// Check delay
if (delayTimer > 0) {
delayTimer--;
return;
}
// Reset delay
delayTimer = delay.get();
if (mode.get() == Mode.Random) {
int origin = onlyAscii.get() ? 0x21 : 0x0800;
int bound = onlyAscii.get() ? 0x7E : 0x10FFFF;
writeBook(// Generate a random load of ints to use as random characters
random.ints(origin, bound).filter(i -> !Character.isWhitespace(i) && i != '\r' && i != '\n').iterator());
} else if (mode.get() == Mode.File) {
// Ignore if somehow the file got deleted
if ((file == null || !file.exists()) && mode.get() == Mode.File) {
info("No file selected, please select a file in the GUI.");
toggle();
return;
}
// Handle the file being empty
if (file.length() == 0) {
MutableText message = new LiteralText("");
message.append(new LiteralText("The bookbot file is empty! ").formatted(Formatting.RED));
message.append(new LiteralText("Click here to edit it.").setStyle(Style.EMPTY.withFormatting(Formatting.UNDERLINE, Formatting.RED).withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, file.getAbsolutePath()))));
info(message);
toggle();
return;
}
// Read each line of the file and construct a string with the needed line breaks
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
StringBuilder file = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
file.append(line).append('\n');
}
reader.close();
// Write the file string to a book
writeBook(file.toString().chars().iterator());
} catch (IOException ignored) {
error("Failed to read the file.");
}
}
}
use of net.minecraft.text.ClickEvent in project mclogs-fabric by aternosorg.
the class CommandMclogsList method register.
static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("mclogs").then(literal("list").requires(source -> source.hasPermissionLevel(2)).executes((context) -> {
ServerCommandSource source = context.getSource();
try {
String[] logs = MclogsFabricLoader.getLogs(context);
if (logs.length == 0) {
source.sendFeedback(new LiteralText("No logs available!"), false);
return 0;
}
LiteralText feedback = new LiteralText("Available Logs:");
for (String log : logs) {
Style s = Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/mclogs share " + log));
LiteralText tempText = new LiteralText("\n" + log);
tempText.setStyle(s);
feedback.append(tempText);
}
source.sendFeedback(feedback, false);
return logs.length;
} catch (Exception e) {
MclogsFabricLoader.logger.error("An error occurred when listing your logs.");
MclogsFabricLoader.logger.error(e);
LiteralText error = new LiteralText("An error occurred. Check your log for more details.");
source.sendError(error);
return -1;
}
})));
}
use of net.minecraft.text.ClickEvent in project mclogs-fabric by aternosorg.
the class MclogsFabricLoader method share.
public static int share(ServerCommandSource source, String filename) {
MclogsAPI.mcversion = source.getMinecraftServer().getVersion();
logger.log(Level.INFO, "Sharing " + filename);
source.sendFeedback(new LiteralText("Sharing " + filename), false);
try {
Path logs = source.getMinecraftServer().getFile("logs/").toPath();
Path log = logs.resolve(filename);
if (!log.getParent().equals(logs)) {
throw new FileNotFoundException();
}
APIResponse response = MclogsAPI.share(log);
if (response.success) {
LiteralText feedback = new LiteralText("Your log has been uploaded: ");
feedback.setStyle(Style.EMPTY.withColor(Formatting.GREEN));
LiteralText link = new LiteralText(response.url);
Style linkStyle = Style.EMPTY.withColor(Formatting.BLUE);
linkStyle = linkStyle.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, response.url));
link.setStyle(linkStyle);
source.sendFeedback(feedback.append(link), true);
return 1;
} else {
logger.error("An error occurred when uploading your log: ");
logger.error(response.error);
LiteralText error = new LiteralText("An error occurred. Check your log for more details");
source.sendError(error);
return 0;
}
} catch (FileNotFoundException | IllegalArgumentException e) {
LiteralText error = new LiteralText("The log file " + filename + " doesn't exist. Use '/mclogs list' to list all logs.");
source.sendError(error);
return -1;
} catch (IOException e) {
source.sendError(new LiteralText("An error occurred. Check your log for more details"));
logger.error("Could not get log file!");
logger.error(e);
return 0;
}
}
Aggregations