mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 02:04:44 +02:00
Fix wiki links being outdated
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package com.gmail.nossr50.commands.skills;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
||||
import com.gmail.nossr50.listeners.InteractionManager;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
@ -29,14 +28,11 @@ public class MmoInfoCommand implements TabExecutor {
|
||||
*/
|
||||
if(commandSender instanceof Player player)
|
||||
{
|
||||
if(args.length < 1)
|
||||
if(args == null || args.length < 1 || args[0] == null || args[0].isEmpty())
|
||||
return false;
|
||||
|
||||
if(Permissions.mmoinfo(player))
|
||||
{
|
||||
if(args == null || args[0] == null)
|
||||
return false;
|
||||
|
||||
if(args[0].equalsIgnoreCase( "???"))
|
||||
{
|
||||
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.Header"));
|
||||
@ -44,14 +40,15 @@ public class MmoInfoCommand implements TabExecutor {
|
||||
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.DetailsHeader"));
|
||||
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.Mystery"));
|
||||
return true;
|
||||
} else if(InteractionManager.getAbstractByName(args[0]) != null || mcMMO.p.getSkillTools().EXACT_SUBSKILL_NAMES.contains(args[0]))
|
||||
{
|
||||
displayInfo(player, args[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
//Not a real skill
|
||||
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.NoMatch"));
|
||||
final SubSkillType subSkillType = matchSubSkill(args[0]);
|
||||
if (subSkillType != null) {
|
||||
displayInfo(player, subSkillType);
|
||||
} else {
|
||||
//Not a real skill
|
||||
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.NoMatch"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -59,6 +56,16 @@ public class MmoInfoCommand implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
public SubSkillType matchSubSkill(String name) {
|
||||
for(SubSkillType subSkillType : SubSkillType.values())
|
||||
{
|
||||
if(subSkillType.getNiceNameNoSpaces(subSkillType).equalsIgnoreCase(name)
|
||||
|| subSkillType.name().equalsIgnoreCase(name))
|
||||
return subSkillType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||
if (args.length == 1) {
|
||||
@ -67,20 +74,13 @@ public class MmoInfoCommand implements TabExecutor {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
private void displayInfo(Player player, String subSkillName)
|
||||
private void displayInfo(Player player, SubSkillType subSkillType)
|
||||
{
|
||||
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.Header"));
|
||||
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.SubSkillHeader", subSkillName));
|
||||
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.SubSkillHeader", subSkillType.getLocaleName()));
|
||||
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.DetailsHeader"));
|
||||
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.OldSkill"));
|
||||
|
||||
for(SubSkillType subSkillType : SubSkillType.values())
|
||||
{
|
||||
if(subSkillType.getNiceNameNoSpaces(subSkillType).equalsIgnoreCase(subSkillName))
|
||||
subSkillName = subSkillType.getWikiName(subSkillType.toString());
|
||||
}
|
||||
|
||||
//Send Player Wiki Link
|
||||
TextComponentFactory.sendPlayerSubSkillWikiLink(player, subSkillName);
|
||||
TextComponentFactory.sendPlayerSubSkillWikiLink(player, subSkillType.getLocaleName(), subSkillType);
|
||||
}
|
||||
}
|
||||
|
@ -213,35 +213,12 @@ public enum SubSkillType {
|
||||
return endResult.toString();
|
||||
}
|
||||
|
||||
public String getWikiName(String subSkillName) {
|
||||
/*
|
||||
* Find where to begin our substring (after the prefix)
|
||||
*/
|
||||
StringBuilder endResult = new StringBuilder();
|
||||
int subStringIndex = getSubStringIndex(subSkillName);
|
||||
|
||||
/*
|
||||
* Split the string up so we can capitalize each part
|
||||
*/
|
||||
String subskillNameWithoutPrefix = subSkillName.substring(subStringIndex);
|
||||
if(subskillNameWithoutPrefix.contains("_"))
|
||||
{
|
||||
String[] splitStrings = subskillNameWithoutPrefix.split("_");
|
||||
|
||||
for(int i = 0; i < splitStrings.length; i++)
|
||||
{
|
||||
if(i+1 >= splitStrings.length)
|
||||
endResult.append(StringUtils.getCapitalized(splitStrings[i]));
|
||||
else {
|
||||
endResult.append(StringUtils.getCapitalized(splitStrings[i]));
|
||||
endResult.append("_");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
endResult.append(StringUtils.getCapitalized(subskillNameWithoutPrefix));
|
||||
}
|
||||
|
||||
return endResult.toString();
|
||||
public String getWikiUrl() {
|
||||
// remove the text before the first underscore
|
||||
int subStringIndex = getSubStringIndex(name());
|
||||
String afterPrefix = name().substring(subStringIndex);
|
||||
// replace _ or spaces with -
|
||||
return afterPrefix.replace("_", "-").replace(" ", "-").toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,8 +34,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
public final class SkillUtils {
|
||||
/**
|
||||
* This is a static utility class, therefore we don't want any instances of
|
||||
|
@ -56,18 +56,23 @@ public class TextComponentFactory {
|
||||
return Component.text(text);
|
||||
}
|
||||
|
||||
public static void sendPlayerSubSkillWikiLink(Player player, String subskillformatted) {
|
||||
public static String getSubSkillWikiLink(SubSkillType subSkillType) {
|
||||
return "https://wiki.mcmmo.org/en/skills/"
|
||||
+ subSkillType.getParentSkill().toString().toLowerCase(Locale.ENGLISH) + "#"
|
||||
+ subSkillType.getWikiUrl().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public static void sendPlayerSubSkillWikiLink(Player player, String subskillformatted, SubSkillType subSkillType) {
|
||||
if (!mcMMO.p.getGeneralConfig().getUrlLinksEnabled())
|
||||
return;
|
||||
|
||||
TextComponent.Builder wikiLinkComponent = Component.text().content(LocaleLoader.getString("Overhaul.mcMMO.MmoInfo.Wiki"));
|
||||
wikiLinkComponent.decoration(TextDecoration.UNDERLINED, true);
|
||||
|
||||
String wikiUrl = "https://wiki.mcmmo.org/" + subskillformatted;
|
||||
final String subSkillWikiLink = getSubSkillWikiLink(subSkillType);
|
||||
wikiLinkComponent.clickEvent(ClickEvent.openUrl(subSkillWikiLink));
|
||||
|
||||
wikiLinkComponent.clickEvent(ClickEvent.openUrl(wikiUrl));
|
||||
|
||||
TextComponent.Builder componentBuilder = Component.text().content(subskillformatted).append(Component.newline()).append(Component.text(wikiUrl)).color(NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, true);
|
||||
TextComponent.Builder componentBuilder = Component.text().content(subskillformatted).append(Component.newline()).append(Component.text(subSkillWikiLink)).color(NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, true);
|
||||
|
||||
wikiLinkComponent.hoverEvent(HoverEvent.showText(componentBuilder.build()));
|
||||
|
||||
|
Reference in New Issue
Block a user