Skip to content

Commit

Permalink
feat: center titles based on length
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Dec 3, 2023
1 parent 9e5acdb commit 4424ee7
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public void onCommand(CommandSenderContainer sender, String commandExecuted, Str
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 {
Expand All @@ -75,8 +76,11 @@ public void onCommand(CommandSenderContainer sender, String commandExecuted, Str
}
}
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -13,6 +16,9 @@

public class CreateDestiSubCommand implements SubCommand {

@Inject
DestinationServices destinationServices;

@Override
public void onCommand(CommandSenderContainer sender, String[] args) {
if(args.length > 1) {
Expand All @@ -21,25 +27,31 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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() {
Expand Down
32 changes: 32 additions & 0 deletions core/src/main/java/com/sekwah/advancedportals/core/util/Lang.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,38 @@ public Map<String, String> getInternalLanguageMap(String fileName) {
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");
Expand Down
4 changes: 2 additions & 2 deletions lang/src/main/resources/lang/de_DE.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lang/src/main/resources/lang/en_GB.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lang/src/main/resources/lang/fr_FR.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lang/src/main/resources/lang/hu_HU.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4424ee7

Please sign in to comment.