10000 Update the default namespace by DerEchtePilz · Pull Request #636 · CommandAPI/CommandAPI · GitHub
[go: up one dir, main page]

Skip to content

Update the default namespace #636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Fix the tests" and do some other stuff to fix them
This reverts commit 2e59a9e.
  • Loading branch information
DerEchtePilz committed Mar 13, 2025
commit 7c9204a8b89c85752eebfefc5f35cd1b90199bb0
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.mojang.brigadier.tree.RootCommandNode;
import dev.jorel.commandapi.preprocessor.RequireField;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Player enableWithNamespaces() {
SimpleCommandMap commandMap = mockPlatform.getSimpleCommandMap();
SpigotCommandRegistration<Object> spigotCommandRegistration = (SpigotCommandRegistration<Object>) mockPlatform.getCommandRegistrationStrategy();
for (CommandNode<Object> node : mockPlatform.getBrigadierDispatcher().getRoot().getChildren()) {
commandMap.register("commandapitest", spigotCommandRegistration.wrapToVanillaCommandWrapper(node));
commandMap.register("minecraft", spigotCommandRegistration.wrapToVanillaCommandWrapper(node));
}

// Run the CommandAPI's enable tasks, especially `fixNamespaces`
Expand Down Expand Up @@ -120,8 +120,8 @@ public void testDefaultMinecraftNamespace(boolean enableBeforeRegistering) {
results.set(info.args().getUnchecked("string"));
});

// Make sure the default registration with the minecraft: namespace works
command.register();
// Make sure the special registration with the minecraft: namespace works
command.register("minecraft");

if (!enableBeforeRegistering) {
player = enableWithNamespaces();
Expand All @@ -137,11 +137,11 @@ public void testDefaultMinecraftNamespace(boolean enableBeforeRegistering) {
// Check contents of Bukkit CommandMap
CommandMap commandMap = MockPlatform.getInstance().getSimpleCommandMap();
assertNotNull(commandMap.getCommand("test"));
assertNotNull(commandMap.getCommand("commandapitest:test"));
assertNotNull(commandMap.getCommand("minecraft:test"));

// Commands should run
assertStoresResult(player, "test alpha", results, "alpha");
assertStoresResult(player, "commandapitest:test alpha", results, "alpha");
assertStoresResult(player, "minecraft:test alpha", results, "alpha");

assertNoMoreResults(results);
}
Expand Down Expand Up @@ -174,7 +174,6 @@ public void testStringNamespace(boolean enableBeforeRegistering) {
assertNotNull(rootNode.getChild("test"));
assertNotNull(rootNode.getChild("commandtest:test"));
assertNull(rootNode.getChild("minecraft:test"));
assertNull(rootNode.getChild("commandapitest:test"));

// Check contents of Bukkit CommandMap
CommandMap commandMap = MockPlatform.getInstance().getSimpleCommandMap();
Expand Down Expand Up @@ -247,7 +246,7 @@ public void testPluginNamespace(boolean enableBeforeRegistering) {

@ParameterizedTest
@ValueSource(booleans = {false, true})
public void testAliasesWithDefaultNamespace(boolean enableBeforeRegistering) {
public void testAliasesWithMinecraftNamespace(boolean enableBeforeRegistering) {
Mut<String> results = Mut.of();

Player player = null;
Expand All @@ -262,8 +261,8 @@ public void testAliasesWithDefaultNamespace(boolean enableBeforeRegistering) {
results.set(info.args().getUnchecked("string"));
});

// Test aliases with the default namespace
command.register();
// Test aliases with the minecraft namespace
command.register("minecraft");

if (!enableBeforeRegistering) {
player = enableWithNamespaces();
Expand All @@ -282,22 +281,19 @@ public void testAliasesWithDefaultNamespace(boolean enableBeforeRegistering) {
// Check contents of Bukkit CommandMap
CommandMap commandMap = MockPlatform.getInstance().getSimpleCommandMap();
assertNotNull(commandMap.getCommand("test"));
assertNull(commandMap.getCommand("minecraft:test"));
assertNotNull(commandMap.getCommand("commandapitest:test"));
assertNotNull(commandMap.getCommand("minecraft:test"));
assertNotNull(commandMap.getCommand("alpha"));
assertNull(commandMap.getCommand("minecraft:alpha"));
assertNotNull(commandMap.getCommand("commandapitest:alpha"));
assertNotNull(commandMap.getCommand("minecraft:alpha"));
assertNotNull(commandMap.getCommand("beta"));
assertNull(commandMap.getCommand("minecraft:beta"));
assertNotNull(commandMap.getCommand("commandapitest:beta"));
assertNotNull(commandMap.getCommand("minecraft:beta"));

// Commands should run
assertStoresResult(player, "test discord", results, "discord");
assertStoresResult(player, "alpha discord", results, "discord");
assertStoresResult(player, "beta discord", results, "discord");
assertStoresResult(player, "commandapitest:test discord", results, "discord");
assertStoresResult(player, "commandapitest:alpha discord", results, "discord");
assertStoresResult(player, "commandapitest:beta discord", results, "discord");
assertStoresResult(player, "minecraft:test discord", results, "discord");
assertStoresResult(player, "minecraft:alpha discord", results, "discord");
assertStoresResult(player, "minecraft:beta discord", results, "discord");

assertNoMoreResults(results);
}
Expand Down Expand Up @@ -519,7 +515,7 @@ public void testCommandNameConflictButDifferentNamespace(boolean enableBeforeReg

@ParameterizedTest
@ValueSource(booleans = {false, true})
public void testSameCommandNameConflictWithDefaultNamespaceAndCustomNamespace(boolean enableBeforeRegistering) {
public void testSameCommandNameConflictWithMinecraftNamespaceAndCustomNamespace(boolean enableBeforeRegistering) {
Mut<String> results = Mut.of();

Player tempPlayer = null;
Expand All @@ -539,7 +535,7 @@ public void testSameCommandNameConflictWithDefaultNamespaceAndCustomNamespace(bo
results.set("b");
});

defaultNamespace.register();
defaultNamespace.register("minecraft");
customNamespace.register("custom");

if (!enableBeforeRegistering) {
Expand All @@ -550,20 +546,19 @@ public void testSameCommandNameConflictWithDefaultNamespaceAndCustomNamespace(bo
RootCommandNode<Object> root = MockPlatform.getInstance().getBrigadierDispatcher().getRoot();
assertNotNull(root.getChild("test"));
assertNotNull(root.getChild("custom:test"));
// The `commandapitest:test` node should exist in the Brigadier map so the `commandapitest:test` VanillaCommandWrapper
// The `minecraft:test` node should exist in the Brigadier map so the `minecraft:test` VanillaCommandWrapper
// can properly execute the command separately from the `custom:test` b branch
assertNotNull(root.getChild("commandapitest:test"));
assertNotNull(root.getChild("minecraft:test"));

CommandMap commandMap = MockPlatform.getInstance().getSimpleCommandMap();
assertNotNull(commandMap.getCommand("test"));
assertNotNull(commandMap.getCommand("commandapitest:test"));
assertNotNull(commandMap.getCommand("minecraft:test"));
assertNotNull(commandMap.getCommand("custom:test"));
assertNull(commandMap.getCommand("minecraft:test"));
assertNull(commandMap.getCommand("minecraft:custom:test"));

assertStoresResult(player, "test a", results, "a");
assertStoresResult(player, "test b", results, "b");
assertStoresResult(player, "commandapitest:test a", results, "a");
assertStoresResult(player, "minecraft:test a", results, "a");
assertStoresResult(player, "custom:test b", results, "b");

assertThrowsWithMessage(
Expand All @@ -573,16 +568,16 @@ public void testSameCommandNameConflictWithDefaultNamespaceAndCustomNamespace(bo
);
assertThrowsWithMessage(
CommandSyntaxException.class,
"Incorrect argument for command at position 20: ...test:test <--[HERE]",
() -> server.dispatchThrowableBrigadierCommand(player, "commandapitest:test b")
"Incorrect argument for command at position 15: ...raft:test <--[HERE]",
() -> server.dispatchThrowableBrigadierCommand(player, "minecraft:test b")
);

assertNoMoreResults(results);
}

@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testCommandTreeRegistrationDefaultNamespace(boolean enableBeforeRegistering) {
public void testCommandTreeRegistrationMinecraftNamespace(boolean enableBeforeRegistering) {
Mut<String> results = Mut.of();

Player player = null;
Expand All @@ -608,8 +603,8 @@ public void testCommandTreeRegistrationDefaultNamespace(boolean enableBeforeRegi
)
);

// Make sure the default registration with the commandapitest: namespace works
command.register();
// Make sure the special registration with the minecraft: namespace works
command.register("minecraft");

if (!enableBeforeRegistering) {
player = enableWithNamespaces();
Expand All @@ -619,15 +614,15 @@ public void testCommandTreeRegistrationDefaultNamespace(boolean enableBeforeRegi
assertEquals("a", results.get());
assertEquals("alpha", results.get());

server.dispatchCommand(player, "commandapitest:test a alpha");
server.dispatchCommand(player, "minecraft:test a alpha");
assertEquals("a", results.get());
assertEquals("alpha", results.get());

server.dispatchCommand(player, "test b 123");
assertEquals("b", results.get());
assertEquals("123", results.get());

server.dispatchCommand(player, "commandapitest:test b 123");
server.dispatchCommand(player, "minecraft:test b 123");
assertEquals("b", results.get());
assertEquals("123", results.get());

Expand Down Expand Up @@ -783,7 +778,7 @@ void assertPermissionCheckFails(CommandSender sender, String commandLine) {

@ParameterizedTest
@ValueSource(booleans = {false,true})
public void testPermissionsWithDefaultNamespace(boolean enableBeforeRegistering) {
public void testPermissionsWithMinecraftNamespace(boolean enableBeforeRegistering) {
Mut<String> commandRan = Mut.of();

Player player = null;
Expand All @@ -797,20 +792,20 @@ public void testPermissionsWithDefaultNamespace(boolean enableBeforeRegistering)
commandRan.set("ran");
});

// Test with default minecraft: namespace
command.register();
// Test with minecraft: namespace
command.register("minecraft");

if (!enableBeforeRegistering) {
player = enableWithNamespaces();
}

assertPermissionCheckFails(player, "test");
assertPermissionCheckFails(player, "commandapitest:test");
assertPermissionCheckFails(player, "minecraft:test");

player.addAttachment(super.plugin, "permission", true);

assertStoresResult(player, "test", commandRan, "ran");
assertStoresResult(player, "commandapitest:test", commandRan, "ran");
assertStoresResult(player, "minecraft:test", commandRan, "ran");

assertNoMoreResults(commandRan);
}
Expand Down Expand Up @@ -949,7 +944,7 @@ public void testConfigNamespace() {
.setNamespace("");
internalConfig = new InternalBukkitConfig(config);

// The namespace was set to an empty namespace so this should result in the default commandapitest namespace
// The namespace was set to an empty namespace so this should result in the default comamndapitest namespace
assertEquals("commandapitest", internalConfig.getNamespace());

config = new CommandAPIBukkitConfig(MockPlatform.getConfiguration().getPlugin())
Expand Down
Loading
Loading
0