Skip to content
This repository was archived by the owner on Feb 19, 2019. It is now read-only.

Commit 3a9a12d

Browse files
committed
Created ArgumentParser for items
1 parent 232cefe commit 3a9a12d

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/example/java/me/zero/example/command/ExampleCommandManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public final void load() {
4848
handler.registerParser(new CharParser());
4949
handler.registerParser(new ColorParser());
5050
handler.registerParser(new CommandParser(ExampleClient.getInstance().getCommandManager()));
51+
handler.registerParser(new ItemParser());
5152
handler.registerParser(new ModuleParser(ExampleClient.getInstance().getModuleManager()));
5253
handler.registerParser(new NumberParser());
5354
handler.registerParser(new OptionalParser());
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2018 ImpactDevelopment
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientapi.command.executor.parser.impl;
18+
19+
import clientapi.command.executor.ExecutionContext;
20+
import clientapi.command.executor.parser.ArgumentParser;
21+
import net.minecraft.item.Item;
22+
23+
import java.lang.reflect.Type;
24+
25+
/**
26+
* @author Brady
27+
* @since 4/19/2018 3:13 PM
28+
*/
29+
public final class ItemParser implements ArgumentParser<Item> {
30+
31+
@Override
32+
public final Item parse(ExecutionContext context, Type type, String raw) {
33+
return Item.getByNameOrId(raw);
34+
}
35+
36+
@Override
37+
public boolean isTarget(Type type) {
38+
return type instanceof Class && Item.class.isAssignableFrom((Class) type);
39+
}
40+
}

0 commit comments

Comments
 (0)