mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2025-03-12 14:49:52 +01:00
feat: center titles based on length
This commit is contained in:
parent
9e5acdb2e5
commit
4424ee77e6
@ -100,7 +100,7 @@ task copyPlugin() {
|
||||
println "$buildDir/MinecraftServer/plugins/Advanced-Portals-${getVersion()}.jar"
|
||||
try {
|
||||
delete fileTree("$buildDir/MinecraftServer/plugins/") {
|
||||
include "*.jar"
|
||||
include "Advanced-Portals*.jar"
|
||||
}
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
|
@ -64,8 +64,9 @@ public class CommandWithSubCommands implements CommandTemplate {
|
||||
String subCommand = args[1].toLowerCase();
|
||||
if(this.subCommandRegistry.isArgRegistered(subCommand)) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Lang.translateInsertVariables("command.help.subcommandheader",
|
||||
command, subCommand));
|
||||
var helpTitle = Lang.centeredTitle(Lang.translateInsertVariables("command.help.subcommandheader",
|
||||
command, helpPage, pages));
|
||||
sender.sendMessage(helpTitle);
|
||||
sender.sendMessage("\u00A77" + this.getSubCommand(subCommand).getDetailedHelpText());
|
||||
}
|
||||
else {
|
||||
@ -75,8 +76,11 @@ public class CommandWithSubCommands implements CommandTemplate {
|
||||
}
|
||||
}
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Lang.translateInsertVariables("command.help.header",
|
||||
|
||||
var helpTitle = Lang.centeredTitle(Lang.translateInsertVariables("command.help.header",
|
||||
command, helpPage, pages));
|
||||
|
||||
sender.sendMessage(helpTitle);
|
||||
sender.sendMessage("\u00A7a█\u00A77 = Permission \u00A7c█\u00A77 = No Permission");
|
||||
int subCommandOffset = (helpPage - 1) * this.subCommandsPerPage;
|
||||
int displayEnd = subCommandOffset + this.subCommandsPerPage;
|
||||
|
@ -1,10 +1,13 @@
|
||||
package com.sekwah.advancedportals.core.commands.subcommands.desti;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.sekwah.advancedportals.core.commands.SubCommand;
|
||||
import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer;
|
||||
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
|
||||
import com.sekwah.advancedportals.core.destination.Destination;
|
||||
import com.sekwah.advancedportals.core.serializeddata.DataTag;
|
||||
import com.sekwah.advancedportals.core.permissions.PortalPermissions;
|
||||
import com.sekwah.advancedportals.core.services.DestinationServices;
|
||||
import com.sekwah.advancedportals.core.util.Lang;
|
||||
import com.sekwah.advancedportals.core.util.TagReader;
|
||||
|
||||
@ -13,6 +16,9 @@ import java.util.List;
|
||||
|
||||
public class CreateDestiSubCommand implements SubCommand {
|
||||
|
||||
@Inject
|
||||
DestinationServices destinationServices;
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandSenderContainer sender, String[] args) {
|
||||
if(args.length > 1) {
|
||||
@ -21,25 +27,31 @@ public class CreateDestiSubCommand implements SubCommand {
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.createdesti.console"));
|
||||
return;
|
||||
}
|
||||
ArrayList<DataTag> destiTags = TagReader.getTagsFromArgs(args);
|
||||
// TODO sort desti service
|
||||
/*Destination desti = AdvancedPortalsCore.getDestinationServices().createDesti(args[1], player, player.getLoc(), destiTags);
|
||||
if(desti != null) {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.createdesti.complete"));
|
||||
sender.sendMessage(Lang.translateColor("command.create.tags"));
|
||||
ArrayList<DataTag> destiArgs = desti.getArgs();
|
||||
if(destiArgs.size() == 0) {
|
||||
sender.sendMessage(Lang.translateColor("desti.info.noargs"));
|
||||
ArrayList<DataTag> destinationTags = TagReader.getTagsFromArgs(args);
|
||||
|
||||
Destination destination = destinationServices.createDesti(args[1], player, player.getLoc(), destinationTags);
|
||||
if(destination != null) {
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.createdesti.complete"));
|
||||
sender.sendMessage(Lang.translate("command.create.tags"));
|
||||
|
||||
ArrayList<DataTag> destiArgs = destination.getArgs();
|
||||
|
||||
if(destiArgs.isEmpty()) {
|
||||
sender.sendMessage(Lang.translate("desti.info.noargs"));
|
||||
}
|
||||
else {
|
||||
for (DataTag tag : destiArgs) {
|
||||
sender.sendMessage("\u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUE);
|
||||
if(tag.VALUES.length == 1) {
|
||||
sender.sendMessage("\u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUES[0]);
|
||||
} else {
|
||||
sender.sendMessage("\u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUES[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.createdesti.error"));
|
||||
}*/
|
||||
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.createdesti.error"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.error.noname"));
|
||||
|
@ -10,7 +10,7 @@ import java.util.List;
|
||||
|
||||
public class NameTag implements Tag.Activation, Tag.AutoComplete {
|
||||
|
||||
private final TagType[] tagTypes = new TagType[]{ TagType.PORTAL };
|
||||
private final TagType[] tagTypes = new TagType[]{ TagType.PORTAL, TagType.DESTINATION };
|
||||
|
||||
@Override
|
||||
public TagType[] getTagTypes() {
|
||||
|
@ -74,6 +74,38 @@ public class Lang {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Length of text excluding colour codes
|
||||
* @param text
|
||||
* @return
|
||||
*/
|
||||
public static int textLength(String text) {
|
||||
int length = 0;
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
char c = text.charAt(i);
|
||||
if(c == '\u00A7') {
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
length++;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default font is not monospaced, so this will likely be a little thinner to be on the safe side
|
||||
* @param title
|
||||
* @return
|
||||
*/
|
||||
public static String centeredTitle(String title) {
|
||||
var titleLength = 54 - (Lang.textLength(title));
|
||||
|
||||
int eachSide = titleLength / 2;
|
||||
|
||||
return "\u00A7e" + "=".repeat(eachSide) + " " + title + " \u00A7e" + "=".repeat(eachSide);
|
||||
}
|
||||
|
||||
private void injectTranslations(String fileName) {
|
||||
try {
|
||||
URL url = Lang.instance.getClass().getClassLoader().getResource("lang/" + fileName + ".lang");
|
||||
|
@ -49,8 +49,8 @@ logger.plugincrafterror=Diese Version von Craftbukkit/Spigot wird derzeit nicht
|
||||
command.noargs= Du musst einen Sub-Command angeben. Bitte benutze &e/%1$s help &c. Falls du eine Liste von möglichen Sub_Command willst.
|
||||
command.subcommand.invalid= Das ist ein ungültiger Sub-Command.
|
||||
|
||||
command.help.header=&e--------------- &a%1$s Hilfe - Seite %2$s of %3$s&e ---------------
|
||||
command.help.subcommandheader=&e--------- &a%1$s Hilfe - %2$s&e ---------
|
||||
command.help.header=&a%1$s Hilfe - Seite %2$s of %3$s
|
||||
command.help.subcommandheader=&a%1$s Hilfe - %2$s
|
||||
command.help.invalidhelp= &e%1$s&c ist keine gültige Seitennummer oder Sub-Command.
|
||||
|
||||
command.reload.help=Ladet die Portal-Dateien neu
|
||||
|
@ -47,8 +47,8 @@ logger.plugincrafterror=This version of craftbukkit is not yet supported or some
|
||||
command.noargs= Sorry but you need to specify a sub command, please use &e/%1$s help &cif you would like a list of possible subcommands.
|
||||
command.subcommand.invalid= Sorry but that is not a valid sub command.
|
||||
|
||||
command.help.header=&e--------------- &a%1$s Help - Page %2$s of %3$s&e ---------------
|
||||
command.help.subcommandheader=&e--------- &a%1$s Help - %2$s&e ---------
|
||||
command.help.header=&a%1$s Help - Page %2$s of %3$s
|
||||
command.help.subcommandheader=&a%1$s Help - %2$s
|
||||
command.help.invalidhelp= Sorry but &e%1$s&c is not a valid page number or sub command.
|
||||
|
||||
command.reload.help=Reloads portal data
|
||||
|
@ -46,8 +46,8 @@ logger.plugincrafterror=Cette version craftbukkit n'est pas supportée, veuillez
|
||||
command.noargs= Vous devez spécifier une sous commande, utilisez &e/%1$s help &cpour avoir la liste des commandes possibles.
|
||||
command.subcommand.invalid= Ce n'est pas une sous commande.
|
||||
|
||||
command.help.header=&e--------------- &a%1$s Aide - Page %2$s sur %3$s&e ---------------
|
||||
command.help.subcommandheader=&e--------- &a%1$s Aide - %2$s&e ---------
|
||||
command.help.header=&a%1$s Aide - Page %2$s sur %3$s
|
||||
command.help.subcommandheader=&a%1$s Aide - %2$s
|
||||
command.help.invalidhelp= Désolé mais &e%1$s&c n'est pas une page ou sous commande valide.
|
||||
|
||||
command.reload.help=Recharge les fichiers
|
||||
|
@ -46,8 +46,8 @@ logger.plugincrafterror=A craftbukkit ezen verziója még nem támogatott, vagy
|
||||
command.noargs= Sajnálom, de meg kell adni egy al parancsot, kérlek, használd &e/%1$s help &cha a lehetséges al parancsok listáját szeretnéd látni.
|
||||
command.subcommand.invalid= Sajnáljuk, de ez nem érvényes al parancs.
|
||||
|
||||
command.help.header=&e--------------- &a%1$s Segítség - Oldal %2$s %3$s&e-ból/-ből ---------------
|
||||
command.help.subcommandheader=&e--------- &a%1$s Segítség - %2$s&e ---------
|
||||
command.help.header=&a%1$s Segítség - Oldal %2$s %3$s&e-ból/-ből
|
||||
command.help.subcommandheader=&a%1$s Segítség - %2$s
|
||||
command.help.invalidhelp= Sajnálom, de &e%1$s&c nem érvényes oldalszám vagy al parancs.
|
||||
|
||||
command.reload.help=Portál adat újratöltése
|
||||
|
Loading…
Reference in New Issue
Block a user