Make the -s flag on XP commands silence the sender confirmation too

/addxp, /addlevels, and /mmoedit echoed 'has been modified' back to the
sender even with -s, flooding the log for plugins that award XP by
dispatching these commands from console.
This commit is contained in:
nossr50
2026-07-11 00:09:20 -07:00
parent 2b85a6fc72
commit bb6a395fc6
3 changed files with 91 additions and 1 deletions

View File

@ -57,6 +57,7 @@ Version 2.3.000
Fixed an error when another plugin fires a fish catch carrying a non-item entity
Fixed an error when adding levels to Salvage or Smelting (See notes)
Fixed an error when another plugin reads raw skill XP for Salvage or Smelting
Fixed the -s flag on /addxp, /addlevels, and /mmoedit not silencing the confirmation sent to the command sender (See notes)
Fixed 'Invalid mcMMO skill' console spam when other plugins check skill names through the API (See notes)
Fixed an error when reading XP requirements for offline players while 'Experience_Formula.Cumulative_Curve' is enabled
Fixed a memory leak from Call of the Wild summons that died before their duration ended
@ -136,6 +137,9 @@ Version 2.3.000
-- Level change events --
Only matters on servers running plugins that cancel mcMMO level change events. A cancelled /mmoedit change could reset the skill to level 0 or the wrong level instead of restoring the old one, and cancelling a change for a player whose data was not loaded threw an error; mcMMO now logs a warning instead.
-- Silent flag for XP commands --
/addxp, /addlevels, and /mmoedit accept -s as the last argument to run silently; the flag now also silences the confirmation echoed back to the command sender. Plugins that award XP by dispatching these commands from the console should append -s to keep the server log quiet.
-- Invalid skill name messages --
Skill name lookups that do not match any skill (usually other plugins validating names through the API, but also command typos) no longer print an 'Invalid mcMMO skill' warning to the console. The message is now debug output, visible by enabling 'General.Verbose_Logging' in config.yml.

View File

@ -113,7 +113,11 @@ public abstract class ExperienceCommand implements TabExecutor {
isSilent(args));
}
handleSenderMessage(sender, playerName, skill);
// -s silences the whole command; plugins dispatch it from console for XP
// rewards, and the confirmation would flood the log on every dispatch
if (!isSilent(args)) {
handleSenderMessage(sender, playerName, skill);
}
return true;
} else {
return false;

View File

@ -0,0 +1,82 @@
package com.gmail.nossr50.commands.experience;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.gmail.nossr50.MMOTestEnvironment;
import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.experience.XPGainSource;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
import java.util.logging.Logger;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
/**
* Covers /addxp sender feedback. Other plugins award XP by dispatching this command from the
* console, so the -s flag must silence the command completely: the "has been modified"
* confirmation echoed to the sender otherwise floods the server log on every dispatch.
*/
class AddxpCommandTest extends MMOTestEnvironment {
private static final Logger logger = Logger.getLogger(AddxpCommandTest.class.getName());
private AddxpCommand addxpCommand;
private CommandSender sender;
private Command command;
@BeforeEach
void setUp() {
mockBaseEnvironment(logger);
sender = mock(CommandSender.class);
command = mock(Command.class);
when(Permissions.addxpOthers(sender)).thenReturn(true);
when(UserManager.getOfflinePlayer("testPlayer")).thenReturn(mmoPlayer);
addxpCommand = new AddxpCommand();
}
@AfterEach
void tearDown() {
cleanUpStaticMocks();
}
@Test
void addingXpToAnotherPlayerShouldConfirmToTheSender() {
// Given - a sender with permission to add XP to other players
// When - the sender awards Herbalism XP without the silent flag
final boolean handled = addxpCommand.onCommand(sender, command, "addxp",
new String[]{"testPlayer", "herbalism", "50"});
// Then - the XP gain is processed and the sender gets the confirmation message
assertThat(handled).isTrue();
verify(mmoPlayer).applyXpGain(PrimarySkillType.HERBALISM, 50F, XPGainReason.COMMAND,
XPGainSource.COMMAND);
final ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
verify(sender).sendMessage(messageCaptor.capture());
assertThat(messageCaptor.getValue()).contains("has been modified");
}
@Test
void addingXpWithTheSilentFlagShouldNotMessageTheSender() {
// Given - a sender with permission to add XP to other players
// When - the sender awards Herbalism XP with the -s silent flag
final boolean handled = addxpCommand.onCommand(sender, command, "addxp",
new String[]{"testPlayer", "herbalism", "50", "-s"});
// Then - the XP gain is still processed but the sender hears nothing
assertThat(handled).isTrue();
verify(mmoPlayer).applyXpGain(PrimarySkillType.HERBALISM, 50F, XPGainReason.COMMAND,
XPGainSource.COMMAND);
verify(sender, never()).sendMessage(anyString());
}
}