use of net.minecraft.util.text.event.ClickEvent in project minecolonies by Minecolonies.
the class CheckForAutoDeletesCommand method executeShared.
private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, final boolean confirmDelete) throws CommandException {
if (sender instanceof EntityPlayer && !isPlayerOpped(sender)) {
sender.sendMessage(new TextComponentString("Must be OP to use command"));
return;
} else if (sender instanceof TileEntity) {
return;
}
final List<Colony> colonies = ColonyManager.getColonies();
final List<Colony> coloniesToDelete = new ArrayList<>();
for (int index = 0; colonies.size() - 1 >= index; index++) {
final Colony colony = colonies.get(index);
if (colony.canBeAutoDeleted() && Configurations.gameplay.autoDeleteColoniesInHours != 0 && colony.getLastContactInHours() >= Configurations.gameplay.autoDeleteColoniesInHours) {
coloniesToDelete.add(colony);
}
}
if (confirmDelete) {
sender.sendMessage(new TextComponentString("Successful"));
for (final Colony col : coloniesToDelete) {
server.addScheduledTask(() -> ColonyManager.deleteColony(col.getID(), Configurations.gameplay.autoDestroyColonyBlocks));
}
} else {
final ITextComponent deleteButton = new TextComponentString("[DELETE]").setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, COMMAND_CHECK_FOR_AUTODELETES)));
sender.sendMessage(new TextComponentString("There are: " + coloniesToDelete.size() + " of a total of " + colonies.size() + " to delete."));
sender.sendMessage(new TextComponentString("Click [DELETE] to confirm"));
sender.sendMessage(deleteButton);
}
}
use of net.minecraft.util.text.event.ClickEvent in project minecolonies by Minecolonies.
the class DeleteColonyCommand method executeShared.
private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, final Colony colony, final boolean canDestroy, final boolean confirmDelete) throws CommandException {
if (!confirmDelete) {
final ITextComponent deleteButton = new TextComponentString("[DELETE]").setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(DELETE_COLONY_CONFIRM_DELETE_COMMAND_SUGGESTED, colony.getID(), canDestroy ? "true" : "false"))));
sender.sendMessage(new TextComponentString("Click [DELETE] to confirm the deletion of colony: " + colony.getID()));
sender.sendMessage(deleteButton);
return;
}
final Entity senderEntity = sender.getCommandSenderEntity();
if (senderEntity instanceof EntityPlayer) {
final EntityPlayer player = (EntityPlayer) sender;
if (!canPlayerUseCommand(player, DELETECOLONY, colony.getID())) {
senderEntity.sendMessage(new TextComponentString(NOT_PERMITTED));
return;
}
}
final boolean shouldDestroy = canDestroy;
// TODO: pass in sender and notify when the delete task finishes.
server.addScheduledTask(() -> ColonyManager.deleteColony(colony.getID(), shouldDestroy));
senderEntity.sendMessage(new TextComponentString(DELETE_COLONY_TASK_SCHEDULED));
}
use of net.minecraft.util.text.event.ClickEvent in project ChatTweaks by blay09.
the class GuiChatExt method handleComponentClick.
@Override
public boolean handleComponentClick(ITextComponent component) {
if (component != null) {
if (MinecraftForge.EVENT_BUS.post(new ChatComponentClickEvent(component))) {
return true;
}
ClickEvent clickEvent = component.getStyle().getClickEvent();
if (clickEvent != null) {
if (clickEvent.getAction() == ClickEvent.Action.OPEN_URL) {
String url = clickEvent.getValue();
String directURL = null;
for (Function<String, String> function : ChatTweaks.getImageURLTransformers()) {
directURL = function.apply(url);
if (directURL != null) {
break;
}
}
if (directURL != null) {
try {
Minecraft.getMinecraft().displayGuiScreen(new GuiImagePreview(Minecraft.getMinecraft().currentScreen, new URL(url), new URL(directURL)));
return true;
} catch (MalformedURLException e) {
ChatTweaks.logger.error("Could not open image preview: ", e);
}
}
}
}
}
return super.handleComponentClick(component);
}
use of net.minecraft.util.text.event.ClickEvent in project Bookshelf by Darkhax-Minecraft.
the class CommandHand method hand.
private int hand(CommandContext<CommandSource> context) throws CommandSyntaxException {
final OutputType type = context.getArgument("type", OutputType.class);
final ServerPlayerEntity player = context.getSource().getPlayerOrException();
final String outputText = type.converter.apply(player.getMainHandItem());
final ITextComponent component = TextComponentUtils.wrapInSquareBrackets(new StringTextComponent(outputText).withStyle((style) -> {
return style.withColor(TextFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, outputText)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslationTextComponent("chat.copy.click"))).withInsertion(outputText);
}));
context.getSource().sendSuccess(component, false);
return 0;
}
use of net.minecraft.util.text.event.ClickEvent in project Pearcel-Mod by MiningMark48.
the class EventOnJoin method onJoin.
@SubscribeEvent
public void onJoin(TickEvent.PlayerTickEvent e) {
if (!PearcelMod.haveWarnedVersionOutOfDate && e.player.world.isRemote) {
if (!PearcelMod.versionChecker.isLatestVersion()) {
ClickEvent versionCheckClickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, "https://minecraft.curseforge.com/projects/pearcel-mod");
e.player.sendMessage(new TextComponentString(TextFormatting.YELLOW + Translate.toLocal("chat.versionChecker.outOfDate") + TextFormatting.AQUA + " v" + PearcelMod.versionChecker.getLatestVersion()).setStyle(new Style().setClickEvent(versionCheckClickEvent)));
PearcelMod.haveWarnedVersionOutOfDate = true;
}
}
if (!JoinMessageWikiSent && e.player.world.isRemote) {
// TODO: Make config setting for message
ClickEvent versionCheckClickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, "http://miningmark48.xyz/pearcelmod");
e.player.sendMessage(new TextComponentString(TextFormatting.GREEN + Translate.toLocal("chat.joinMessage.wiki")).setStyle(new Style().setClickEvent(versionCheckClickEvent)));
JoinMessageWikiSent = true;
}
}
Aggregations