001/* 002 * PlotSquared, a land and world management plugin for Minecraft. 003 * Copyright (C) IntellectualSites <https://intellectualsites.com> 004 * Copyright (C) IntellectualSites team and contributors 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <https://www.gnu.org/licenses/>. 018 */ 019package com.plotsquared.core.util.helpmenu; 020 021import com.plotsquared.core.command.CommandCategory; 022import com.plotsquared.core.configuration.caption.StaticCaption; 023import com.plotsquared.core.configuration.caption.TranslatableCaption; 024import com.plotsquared.core.player.PlotPlayer; 025import com.plotsquared.core.util.StringMan; 026import net.kyori.adventure.text.minimessage.MiniMessage; 027import net.kyori.adventure.text.minimessage.Template; 028 029import java.util.ArrayList; 030import java.util.List; 031 032public class HelpPage { 033 034 private static final MiniMessage MINI_MESSAGE = MiniMessage.builder().build(); 035 private final List<HelpObject> helpObjects; 036 private final Template catTemplate; 037 private final Template curTemplate; 038 private final Template maxTemplate; 039 040 public HelpPage(CommandCategory category, int currentPage, int maxPages) { 041 this.helpObjects = new ArrayList<>(); 042 this.catTemplate = Template.of("category", category == null ? "ALL" : category.name()); 043 this.curTemplate = Template.of("current", String.valueOf(currentPage + 1)); 044 this.maxTemplate = Template.of("max", String.valueOf(maxPages + 1)); 045 } 046 047 public void render(PlotPlayer<?> player) { 048 if (this.helpObjects.size() < 1) { 049 player.sendMessage(TranslatableCaption.of("help.no_permission")); 050 } else { 051 Template header = Template.of("header", TranslatableCaption.of("help.help_header").getComponent(player)); 052 Template page_header = Template.of( 053 "page_header", 054 MINI_MESSAGE.parse( 055 TranslatableCaption.of("help.help_page_header").getComponent(player), 056 catTemplate, 057 curTemplate, 058 maxTemplate 059 ) 060 ); 061 Template help_objects = Template.of("help_objects", StringMan.join(this.helpObjects, "\n")); 062 Template footer = Template.of("footer", TranslatableCaption.of("help.help_footer").getComponent(player)); 063 player.sendMessage( 064 StaticCaption.of("<header>\n<page_header>\n<help_objects>\n<footer>"), 065 header, 066 page_header, 067 help_objects, 068 footer 069 ); 070 } 071 } 072 073 public void addHelpItem(HelpObject object) { 074 this.helpObjects.add(object); 075 } 076 077}