3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-24 18:10:08 +01:00

Fixed bug with wands and updated tests

Dieser Commit ist enthalten in:
MattBDev 2019-09-18 15:09:04 -04:00
Ursprung 4357c4b049
Commit 3bcfcd3008
7 geänderte Dateien mit 92 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -48,7 +48,7 @@ public abstract class CachedBukkitAdapter implements IBukkitAdapter {
@Override @Override
public ItemType asItemType(Material material) { public ItemType asItemType(Material material) {
try { try {
return ItemTypes.get(itemTypes[material.ordinal()]); return ItemTypes.get(material.getKey().getKey());
} catch (NullPointerException e) { } catch (NullPointerException e) {
if (init()) return asItemType(material); if (init()) return asItemType(material);
return ItemTypes.get(itemTypes[material.ordinal()]); return ItemTypes.get(itemTypes[material.ordinal()]);

Datei anzeigen

@ -31,6 +31,10 @@ import java.util.stream.Stream;
public class CommandArgParser { public class CommandArgParser {
public static CommandArgParser forArgString(String argString) {
return new CommandArgParser(spaceSplit(argString));
}
public static ImmutableList<Substring> spaceSplit(String string) { public static ImmutableList<Substring> spaceSplit(String string) {
ImmutableList.Builder<Substring> result = ImmutableList.builder(); ImmutableList.Builder<Substring> result = ImmutableList.builder();
int index = 0; int index = 0;
@ -67,16 +71,28 @@ public class CommandArgParser {
handleQuote(nextPart); handleQuote(nextPart);
} }
} }
if (currentArg.size() > 0) {
finishArg(); // force finish "hanging" args
}
return args.build(); return args.build();
} }
private void handleNormal(Substring part) { private void handleNormal(Substring part) {
if (part.getSubstring().startsWith("\"")) { final String strPart = part.getSubstring();
state = State.QUOTE; if (strPart.startsWith("\"")) {
currentArg.add(Substring.wrap( if (strPart.endsWith("\"") && strPart.length() > 1) {
part.getSubstring().substring(1), currentArg.add(Substring.wrap(
part.getStart(), part.getEnd() strPart.substring(1, strPart.length() - 1),
)); part.getStart() + 1, part.getEnd() - 1
));
finishArg();
} else {
state = State.QUOTE;
currentArg.add(Substring.wrap(
strPart.substring(1),
part.getStart() + 1, part.getEnd()
));
}
} else { } else {
currentArg.add(part); currentArg.add(part);
finishArg(); finishArg();
@ -88,7 +104,7 @@ public class CommandArgParser {
state = State.NORMAL; state = State.NORMAL;
currentArg.add(Substring.wrap( currentArg.add(Substring.wrap(
part.getSubstring().substring(0, part.getSubstring().length() - 1), part.getSubstring().substring(0, part.getSubstring().length() - 1),
part.getStart(), part.getEnd() part.getStart(), part.getEnd() - 1
)); ));
finishArg(); finishArg();
} else { } else {

Datei anzeigen

@ -232,7 +232,7 @@ public final class ItemTypes {
@Nullable public static final ItemType CYAN_WOOL = get("minecraft:cyan_wool"); @Nullable public static final ItemType CYAN_WOOL = get("minecraft:cyan_wool");
@Nullable public static final ItemType DAMAGED_ANVIL = get("minecraft:damaged_anvil"); @Nullable public static final ItemType DAMAGED_ANVIL = get("minecraft:damaged_anvil");
@Nullable public static final ItemType DANDELION = get("minecraft:dandelion"); @Nullable public static final ItemType DANDELION = get("minecraft:dandelion");
@Deprecated @Nullable public static final ItemType DANDELION_YELLOW = Optional.ofNullable(get("minecraft:dandelion_yellow")).orElseGet(() -> (get("minecraft:yellow_dye"))); @Deprecated @Nullable public static final ItemType DANDELION_YELLOW = Optional.ofNullable(get("minecraft:dandelion_yellow")).orElseGet(() -> get("minecraft:yellow_dye"));
@Nullable public static final ItemType DARK_OAK_BOAT = get("minecraft:dark_oak_boat"); @Nullable public static final ItemType DARK_OAK_BOAT = get("minecraft:dark_oak_boat");
@Nullable public static final ItemType DARK_OAK_BUTTON = get("minecraft:dark_oak_button"); @Nullable public static final ItemType DARK_OAK_BUTTON = get("minecraft:dark_oak_button");
@Nullable public static final ItemType DARK_OAK_DOOR = get("minecraft:dark_oak_door"); @Nullable public static final ItemType DARK_OAK_DOOR = get("minecraft:dark_oak_door");
@ -730,7 +730,7 @@ public final class ItemTypes {
@Nullable public static final ItemType REPEATER = get("minecraft:repeater"); @Nullable public static final ItemType REPEATER = get("minecraft:repeater");
@Nullable public static final ItemType REPEATING_COMMAND_BLOCK = get("minecraft:repeating_command_block"); @Nullable public static final ItemType REPEATING_COMMAND_BLOCK = get("minecraft:repeating_command_block");
@Nullable public static final ItemType ROSE_BUSH = get("minecraft:rose_bush"); @Nullable public static final ItemType ROSE_BUSH = get("minecraft:rose_bush");
@Deprecated @Nullable public static final ItemType ROSE_RED = Optional.ofNullable(get("minecraft:rose_red")).orElseGet(() -> (get("minecraft:red_dye"))); @Deprecated @Nullable public static final ItemType ROSE_RED = Optional.ofNullable(get("minecraft:rose_red")).orElseGet(() -> get("minecraft:red_dye"));
@Nullable public static final ItemType ROTTEN_FLESH = get("minecraft:rotten_flesh"); @Nullable public static final ItemType ROTTEN_FLESH = get("minecraft:rotten_flesh");
@Nullable public static final ItemType SADDLE = get("minecraft:saddle"); @Nullable public static final ItemType SADDLE = get("minecraft:saddle");
@Nullable public static final ItemType SALMON = get("minecraft:salmon"); @Nullable public static final ItemType SALMON = get("minecraft:salmon");
@ -752,7 +752,7 @@ public final class ItemTypes {
@Nullable public static final ItemType SHULKER_BOX = get("minecraft:shulker_box"); @Nullable public static final ItemType SHULKER_BOX = get("minecraft:shulker_box");
@Nullable public static final ItemType SHULKER_SHELL = get("minecraft:shulker_shell"); @Nullable public static final ItemType SHULKER_SHELL = get("minecraft:shulker_shell");
@Nullable public static final ItemType SHULKER_SPAWN_EGG = get("minecraft:shulker_spawn_egg"); @Nullable public static final ItemType SHULKER_SPAWN_EGG = get("minecraft:shulker_spawn_egg");
@Deprecated @Nullable public static final ItemType SIGN = Optional.ofNullable(get("minecraft:sign")).orElseGet(() -> (get("minecraft:oak_sign"))); @Deprecated @Nullable public static final ItemType SIGN = Optional.ofNullable(get("minecraft:sign")).orElseGet(() -> get("minecraft:oak_sign"));
@Nullable public static final ItemType SILVERFISH_SPAWN_EGG = get("minecraft:silverfish_spawn_egg"); @Nullable public static final ItemType SILVERFISH_SPAWN_EGG = get("minecraft:silverfish_spawn_egg");
@Nullable public static final ItemType SKELETON_HORSE_SPAWN_EGG = get("minecraft:skeleton_horse_spawn_egg"); @Nullable public static final ItemType SKELETON_HORSE_SPAWN_EGG = get("minecraft:skeleton_horse_spawn_egg");
@Nullable public static final ItemType SKELETON_SKULL = get("minecraft:skeleton_skull"); @Nullable public static final ItemType SKELETON_SKULL = get("minecraft:skeleton_skull");
@ -929,12 +929,12 @@ public final class ItemTypes {
return get(input); return get(input);
} }
public static @Nullable ItemType get(final String id) { public static @Nullable ItemType get(String id) {
return ItemType.REGISTRY.get(id); return ItemType.REGISTRY.get(id);
} }
@Deprecated @Deprecated
public static ItemType get(final int ordinal) { public static ItemType get(int ordinal) {
return ItemType.REGISTRY.getByInternalId(ordinal); return ItemType.REGISTRY.getByInternalId(ordinal);
} }

Datei anzeigen

@ -54,7 +54,7 @@ public class CommandContextTest {
public void testInvalidFlags() { public void testInvalidFlags() {
final String failingCommand = "herpderp -opw testers"; final String failingCommand = "herpderp -opw testers";
assertThrows(CommandException.class, () -> { assertThrows(CommandException.class, () -> {
new CommandContext(failingCommand, new HashSet<>(Arrays.asList('o', 'w'))); new CommandContext(failingCommand, new HashSet<>(Arrays.asList('o', 'w')));
}); });
} }

Datei anzeigen

@ -24,9 +24,9 @@ import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockType;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@Disabled("A platform is currently required to get properties, preventing this test.") @Disabled("A platform is currently required to get properties, preventing this test.")
public class BlockTransformExtentTest { public class BlockTransformExtentTest {
@ -37,7 +37,7 @@ public class BlockTransformExtentTest {
@BeforeEach @BeforeEach
public void setUp() { public void setUp() {
// BlockType.REGISTRY.register("worldedit:test", new BlockType("worldedit:test")); //BlockType.REGISTRY.register("worldedit:test", new BlockType("worldedit:test"));
} }
@Test @Test

Datei anzeigen

@ -0,0 +1,58 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.internal.command;
import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.internal.util.Substring;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertEquals;
class CommandArgParserTest {
private static List<Substring> argParse(String s) {
return CommandArgParser.forArgString(s).parseArgs().collect(Collectors.toList());
}
@Test
void testArgumentParsing() {
assertEquals(ImmutableList.of(
Substring.wrap("", 0, 0)
), argParse(""));
assertEquals(ImmutableList.of(
Substring.wrap("ab", 0, 2)
), argParse("ab"));
assertEquals(ImmutableList.of(
Substring.wrap("", 0, 0),
Substring.wrap("", 1, 1)
), argParse(" "));
assertEquals(ImmutableList.of(
Substring.wrap("a", 0, 1),
Substring.wrap("", 2, 2)
), argParse("a "));
assertEquals(ImmutableList.of(
Substring.wrap("a", 0, 1),
Substring.wrap("b", 2, 3)
), argParse("a b"));
}
}

Datei anzeigen

@ -19,12 +19,12 @@
package com.sk89q.worldedit.util; package com.sk89q.worldedit.util;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import org.junit.Test; import org.junit.jupiter.api.Test;
/** /**
* Tests {@link Location}. * Tests {@link Location}.