Skip to content

Commit

Permalink
Fix wiki links being outdated
Browse files Browse the repository at this point in the history
  • Loading branch information
nossr50 committed Apr 6, 2024
1 parent ffc6061 commit 4d98d25
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 60 deletions.
3 changes: 3 additions & 0 deletions Changelog.txt
@@ -1,4 +1,6 @@
Version 2.2.006
Updated outdated wiki URLs in commands to point to the new wiki
Removed the msg about skills being migrated to a new system when using /mmoinfo command
Added new config custom_item_support.yml
Added setting to disable repair on items with custom models, this is not on by default
Added new locale entry 'Anvil.Repair.Reject.CustomModelData'
Expand All @@ -9,6 +11,7 @@ Version 2.2.006
This update adds a new config file to allow server owners to disable repair or salvage on items with custom models,
This prevention mechanism is not enabled by default, change the settings in custom_item_support.yml if you want to enable it.
This feature is off by default for now to keep compatibility with existing servers, but it may be enabled by default in the future if feedback suggests it should be.
As a reminder, anyone can update the wiki by clicking on the "edit on github" link on various pages, this will take you to the wiki's source code on GitHub, submit a PR to make changes

Version 2.2.005
Fixed a bug where certain skills such as Dodge/Arrow Deflect had no skill cap and would continue improving forever
Expand Down
42 changes: 21 additions & 21 deletions src/main/java/com/gmail/nossr50/commands/skills/MmoInfoCommand.java
@@ -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;
Expand Down Expand Up @@ -29,36 +28,44 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command
*/
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"));
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.SubSkillHeader", "???"));
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;
}
}

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) {
Expand All @@ -67,20 +74,13 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Comman
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);
}
}
35 changes: 6 additions & 29 deletions src/main/java/com/gmail/nossr50/datatypes/skills/SubSkillType.java
Expand Up @@ -213,35 +213,12 @@ private String getConfigName(String subSkillName) {
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);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/gmail/nossr50/util/skills/SkillUtils.java
Expand Up @@ -34,8 +34,6 @@

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
Expand Down
Expand Up @@ -56,18 +56,23 @@ private static TextComponent getNotificationTextComponent(String text) {
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;

wikiLinkComponent.clickEvent(ClickEvent.openUrl(wikiUrl));
final String subSkillWikiLink = getSubSkillWikiLink(subSkillType);
wikiLinkComponent.clickEvent(ClickEvent.openUrl(subSkillWikiLink));

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()));

Expand Down
Expand Up @@ -17,7 +17,6 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;

Expand Down Expand Up @@ -74,8 +73,9 @@ void harvestLumberShouldDoubleDrop() {
woodcuttingManager.processBonusDropCheck(blockState);

// verify bonus drops were spawned
// TODO: Can fail if triple drops happen, need to update test
Mockito.verify(woodcuttingManager, Mockito.times(1)).spawnHarvestLumberBonusDrops(blockState);
// TODO: using at least once since triple drops can also happen
// TODO: Change the test env to disallow triple drop in the future
Mockito.verify(woodcuttingManager, Mockito.atLeastOnce()).spawnHarvestLumberBonusDrops(blockState);
}

@Test
Expand Down

0 comments on commit 4d98d25

Please sign in to comment.