Skip to content

Commit 698e696

Browse files
committed
Fix various test failures for 1.20.5. See commit description for more info.
- Update some particle tests (but they still fail) - Update ItemStackPredicate suggestion tests which now include # and * in their suggestions, and use square brackets instead of curly braces - Update error message for EntityType and ChatColor argument tests - Implement lookupOrThrow mocked method for arguments that require command build contexts for 1.20.5 - Change item count to 1 for 1.20.5 item arguments (this needs to be backported and updated in the documentation, but isn't a priority)
1 parent fbb285d commit 698e696

File tree

7 files changed

+75
-26
lines changed

7 files changed

+75
-26
lines changed

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-nms/commandapi-bukkit-1.20.5/src/main/java/dev/jorel/commandapi/nms/NMS_1_20_R4.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -613,17 +613,6 @@ public final org.bukkit.inventory.ItemStack getItemStack(CommandContext<CommandS
613613

614614
// Create the basic ItemStack with an amount of 1
615615
net.minecraft.world.item.ItemStack itemWithMaybeTag = input.createItemStack(1, false);
616-
617-
// TODO: Item counts
618-
// Try and find the amount from the CompoundTag (if present)
619-
// final CompoundTag tag = itemInput.get(input);
620-
// if (tag != null) {
621-
// // The tag has some extra metadata we need! Get the Count (amount)
622-
// // and create the ItemStack with the correct metadata
623-
// int count = (int) tag.getByte("Count");
624-
// itemWithMaybeTag = input.createItemStack(count == 0 ? 1 : count, false);
625-
// }
626-
627616
org.bukkit.inventory.ItemStack result = CraftItemStack.asBukkitCopy(itemWithMaybeTag);
628617
result.setItemMeta(CraftItemStack.getItemMeta(itemWithMaybeTag));
629618
return result;

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/ArgumentNMS.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ public final ArgumentType<?> _ArgumentBlockPredicate() {
9393
Mockito
9494
.when(buildContextMock.lookup(any(ResourceKey.class)))
9595
.thenReturn(Optional.of(BuiltInRegistries.BLOCK.asLookup())); // Registry.BLOCK
96+
Mockito
97+
.when(buildContextMock.lookupOrThrow(any(ResourceKey.class)))
98+
.thenReturn(Optional.of(BuiltInRegistries.BLOCK.asLookup()).orElseThrow()); // Registry.BLOCK
9699
return BlockPredicateArgument.blockPredicate(buildContextMock);
97100
}
98101

@@ -102,6 +105,9 @@ public final ArgumentType<?> _ArgumentBlockState() {
102105
Mockito
103106
.when(buildContextMock.lookup(any(ResourceKey.class)))
104107
.thenReturn(Optional.of(BuiltInRegistries.BLOCK.asLookup())); // Registry.BLOCK
108+
Mockito
109+
.when(buildContextMock.lookupOrThrow(any(ResourceKey.class)))
110+
.thenReturn(Optional.of(BuiltInRegistries.BLOCK.asLookup()).orElseThrow()); // Registry.BLOCK
105111
return BlockStateArgument.block(buildContextMock);
106112
}
107113

@@ -131,6 +137,9 @@ public ArgumentType<?> _ArgumentEnchantment() {
131137
Mockito
132138
.when(buildContextMock.lookup(any(ResourceKey.class)))
133139
.thenReturn(Optional.of(BuiltInRegistries.ENCHANTMENT.asLookup())); // Registry.ENCHANTMENT
140+
Mockito
141+
.when(buildContextMock.lookupOrThrow(any(ResourceKey.class)))
142+
.thenReturn(Optional.of(BuiltInRegistries.ENCHANTMENT.asLookup()).orElseThrow()); // Registry.ENCHANTMENT
134143
return ResourceArgument.resource(buildContextMock, Registries.ENCHANTMENT);
135144
}
136145

@@ -148,6 +157,9 @@ public ArgumentType<?> _ArgumentEntitySummon() {
148157
Mockito
149158
.when(buildContextMock.lookup(any(ResourceKey.class)))
150159
.thenReturn(Optional.of(BuiltInRegistries.ENTITY_TYPE.asLookup())); // Registry.ENTITY_TYPE
160+
Mockito
161+
.when(buildContextMock.lookupOrThrow(any(ResourceKey.class)))
162+
.thenReturn(Optional.of(BuiltInRegistries.ENTITY_TYPE.asLookup()).orElseThrow()); // Registry.ENTITY_TYPE
151163
return ResourceArgument.resource(buildContextMock, Registries.ENTITY_TYPE);
152164
}
153165

@@ -167,6 +179,9 @@ public final ArgumentType<?> _ArgumentItemPredicate() {
167179
Mockito
168180
.when(buildContextMock.lookup(any(ResourceKey.class)))
169181
.thenReturn(Optional.of(BuiltInRegistries.ITEM.asLookup())); // Registry.ITEM
182+
Mockito
183+
.when(buildContextMock.lookupOrThrow(any(ResourceKey.class)))
184+
.thenReturn(Optional.of(BuiltInRegistries.ITEM.asLookup()).orElseThrow()); // Registry.ITEM
170185
return ItemPredicateArgument.itemPredicate(buildContextMock);
171186
}
172187

@@ -181,6 +196,9 @@ public final ArgumentType<?> _ArgumentItemStack() {
181196
Mockito
182197
.when(buildContextMock.lookup(any(ResourceKey.class)))
183198
.thenReturn(Optional.of(BuiltInRegistries.ITEM.asLookup())); // Registry.ITEM
199+
Mockito
200+
.when(buildContextMock.lookupOrThrow(any(ResourceKey.class)))
201+
.thenReturn(Optional.of(BuiltInRegistries.ITEM.asLookup()).orElseThrow()); // Registry.ITEM
184202
return ItemArgument.item(buildContextMock);
185203
}
186204

@@ -203,6 +221,9 @@ public ArgumentType<?> _ArgumentMobEffect() {
203221
Mockito
204222
.when(buildContextMock.lookup(any(ResourceKey.class)))
205223
.thenReturn(Optional.of(BuiltInRegistries.MOB_EFFECT.asLookup())); // Registry.MOB_EFFECT
224+
Mockito
225+
.when(buildContextMock.lookupOrThrow(any(ResourceKey.class)))
226+
.thenReturn(Optional.of(BuiltInRegistries.MOB_EFFECT.asLookup()).orElseThrow()); // Registry.MOB_EFFECT
206227
return ResourceArgument.resource(buildContextMock, Registries.MOB_EFFECT);
207228
}
208229

@@ -217,6 +238,9 @@ public ArgumentType<?> _ArgumentParticle() {
217238
Mockito
218239
.when(buildContextMock.lookup(any(ResourceKey.class)))
219240
.thenReturn(Optional.of(BuiltInRegistries.PARTICLE_TYPE.asLookup())); // Registry.PARTICLE_TYPE
241+
Mockito
242+
.when(buildContextMock.lookupOrThrow(any(ResourceKey.class)))
243+
.thenReturn(Optional.of(BuiltInRegistries.PARTICLE_TYPE.asLookup()).orElseThrow()); // Registry.PARTICLE_TYPE
220244
return ParticleArgument.particle(buildContextMock);
221245
}
222246

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-impl-1.20.5/src/main/java/dev/jorel/commandapi/test/MockNMS.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.bukkit.command.Command;
3030
import org.bukkit.command.CommandSender;
3131
import org.bukkit.command.SimpleCommandMap;
32+
import org.bukkit.craftbukkit.v1_20_R4.CraftParticle;
3233
import org.bukkit.craftbukkit.v1_20_R4.CraftWorld;
3334
import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer;
3435
import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemFactory;
@@ -416,7 +417,8 @@ public String getNMSParticleNameFromBukkit(Particle particle) {
416417
// change your mind, here's how to access it via the registry. This doesn't
417418
// scale well for pre 1.19 versions though!
418419
// BuiltInRegistries.PARTICLE_TYPE.getKey(CraftParticle.toNMS(particle).getType()).toString();
419-
return particle.getKey().toString();
420+
return BuiltInRegistries.PARTICLE_TYPE.getKey(CraftParticle.bukkitToMinecraft(particle)).toString();
421+
// return particle.getKey().toString();
420422
}
421423

422424
@Override

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentChatColorTests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,15 @@ void executionTestWithChatColorArgument() {
7878
if(color.isFormat() && !color.equals(ChatColor.RESET)) {
7979
String colorName = color.name().toLowerCase();
8080
if (version.greaterThanOrEqualTo(MCVersion.V1_20_5)) {
81-
assertCommandFailsWith(player, "test " + colorName, "Unknown color '" + colorName + "' at position 10: test magic<--[HERE]");
81+
final String command = "test " + colorName;
82+
final int errorPosition = command.length();
83+
final String truncatedCommand;
84+
if (command.length() > 10) {
85+
truncatedCommand = "..." + command.substring(command.length() - 10, command.length());
86+
} else {
87+
truncatedCommand = command;
88+
}
89+
assertCommandFailsWith(player, command, String.format("Unknown color '%s' at position %d: %s<--[HERE]", colorName, errorPosition, truncatedCommand));
8290
} else {
8391
assertCommandFailsWith(player, "test " + colorName, "Unknown color '" + colorName + "'");
8492
}

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentEntityTypeTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ void executionTestWithEntityTypeArgument() {
8787

8888
// /test giraffe
8989
// Unknown entity, giraffe is not a valid entity type
90-
if (version.greaterThanOrEqualTo(MCVersion.V1_19_4)) {
90+
if (version.greaterThanOrEqualTo(MCVersion.V1_20_5)) {
91+
assertCommandFailsWith(player, "test giraffe", "Can't find element 'minecraft:giraffe' of type 'minecraft:entity_type' at position 12: ...st giraffe<--[HERE]");
92+
} else if (version.greaterThanOrEqualTo(MCVersion.V1_19_4)) {
9193
assertCommandFailsWith(player, "test giraffe", "Can't find element 'minecraft:giraffe' of type 'minecraft:entity_type'");
9294
} else {
9395
assertCommandFailsWith(player, "test giraffe", "Unknown entity: minecraft:giraffe");

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentItemStackPredicateTests.java

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertTrue;
55

6+
import java.util.ArrayList;
67
import java.util.List;
78
import java.util.function.Predicate;
89

@@ -101,28 +102,46 @@ void suggestionTestWithItemStackPredicateArgument() {
101102

102103
PlayerMock player = server.addPlayer();
103104

104-
// Identical to the ItemStackArgument tests
105+
// Identical to the ItemStackArgument tests, except ItemStackPredicates have a slightly
106+
// different list of possible values because it can also accept * and tags (starting with #)
107+
List<String> itemPredicateNames = new ArrayList<>(MockPlatform.getInstance().getAllItemNames());
108+
itemPredicateNames.add(0, "#");
109+
itemPredicateNames.add(1, "*");
105110

106111
// /test
107112
// All items should be suggested
108-
assertEquals(MockPlatform.getInstance().getAllItemNames(), server.getSuggestions(player, "test "));
113+
assertEquals(itemPredicateNames, server.getSuggestions(player, "test "));
109114

110115
// /test x
111116
// All items starting with 'a' should be suggested, as well as items which
112117
// are underscore-separated and start with 'a', such as 'wooden_axe'
113-
assertEquals(MockPlatform.getInstance().getAllItemNames().stream().filter(s -> s.contains(":a") || s.contains("_a")).toList(), server.getSuggestions(player, "test a"));
118+
assertEquals(itemPredicateNames.stream().filter(s -> s.contains(":a") || s.contains("_a")).toList(), server.getSuggestions(player, "test a"));
114119

115-
// test dirt
116-
// Completed item names should suggest open brackets
117-
assertEquals(List.of("{"), server.getSuggestions(player, "test dirt"));
120+
// /test dirt
121+
// Completed item names should suggest open curly braces (or square brackets in 1.20.5+)
122+
if (version.greaterThanOrEqualTo(MCVersion.V1_20_5)) {
123+
assertEquals(List.of("["), server.getSuggestions(player, "test dirt"));
124+
} else {
125+
assertEquals(List.of("{"), server.getSuggestions(player, "test dirt"));
126+
}
118127

119-
// test dirt{
128+
// /test dirt{
129+
// /test dirt[ (1.20.5+)
120130
// NBT has no suggestions
121-
assertEquals(List.of(), server.getSuggestions(player, "test dirt{"));
131+
if (version.greaterThanOrEqualTo(MCVersion.V1_20_5)) {
132+
assertEquals(List.of(), server.getSuggestions(player, "test dirt["));
133+
} else {
134+
assertEquals(List.of(), server.getSuggestions(player, "test dirt{"));
135+
}
122136

123-
// test dirt{}
137+
// /test dirt{}
138+
// /test dirt[] (1.20.5+)
124139
// NBT has no suggestions
125-
assertEquals(List.of(), server.getSuggestions(player, "test dirt{}"));
140+
if (version.greaterThanOrEqualTo(MCVersion.V1_20_5)) {
141+
assertEquals(List.of(), server.getSuggestions(player, "test dirt[]"));
142+
} else {
143+
assertEquals(List.of(), server.getSuggestions(player, "test dirt{}"));
144+
}
126145
}
127146

128147
}

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/arguments/ArgumentParticleTests.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class ArgumentParticleTests extends TestBase {
4141
public void setUp() {
4242
super.setUp();
4343

44-
assumeTrue(version.lessThan(MCVersion.V1_20_3));
44+
// Disabled for 1.20.3+ due to "reasons"
45+
// assumeTrue(version.lessThan(MCVersion.V1_20_3));
4546
}
4647

4748
@AfterEach
@@ -99,7 +100,11 @@ void executionTestWithParticleArgumentDust() {
99100
PlayerMock player = server.addPlayer();
100101

101102
// dust red green blue size, where red, green and blue are between 0 and 1
102-
server.dispatchCommand(player, "test dust 1 0.5 0 4");
103+
if (version.greaterThanOrEqualTo(MCVersion.V1_20_5)) {
104+
server.dispatchCommand(player, "test dust{color:[1.0f,0.5f,0.0f],scale:4.0f}");
105+
} else {
106+
server.dispatchCommand(player, "test dust 1 0.5 0 4");
107+
}
103108
@SuppressWarnings("unchecked")
104109
ParticleData<DustOptions> result = (ParticleData<DustOptions>) results.get();
105110

0 commit comments

Comments
 (0)