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

Commit 1eb2a9f

Browse files
committed
Updated javadoc and file licenses
1 parent d2f7c56 commit 1eb2a9f

File tree

9 files changed

+120
-37
lines changed

9 files changed

+120
-37
lines changed

src/main/java/me/zero/client/api/command/exception/CommandInitException.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
import me.zero.client.api.command.Command;
2020

2121
/**
22-
* Called when the initialization of a {@code Command}
23-
* fails.c
22+
* Called when the initialization of a {@code Command} fails.
2423
*
2524
* @author Brady
2625
* @since 5/31/2017 9:08 AM

src/main/java/me/zero/client/api/command/exception/InvalidArgumentException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
import me.zero.client.api.command.Command;
2020

2121
/**
22+
* Thrown when an argument that was passed to the command
23+
* was not the expected type. For example, a number was expected
24+
* but the number was unable to be parsed.
25+
*
2226
* @author Brady
2327
* @since 6/7/2017 9:34 AM
2428
*/

src/main/java/me/zero/client/api/command/exception/UnknownCommandException.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2017 ZeroMemes
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+
117
package me.zero.client.api.command.exception;
218

319
/**

src/main/java/me/zero/client/api/command/executor/CommandExecutor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
import me.zero.client.api.command.executor.sender.CommandSender;
2222

2323
/**
24+
* Takes in a command, and executes it from the specified
25+
* sender and arguments.
26+
*
27+
* @see DirectExecutor
28+
*
2429
* @author Brady
2530
* @since 6/11/2017 9:26 AM
2631
*/

src/main/java/me/zero/client/api/command/executor/DirectExecutor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import me.zero.client.api.command.executor.sender.CommandSender;
2222

2323
/**
24+
* Directly executes commands that are passed to this executor
25+
*
2426
* @author Brady
2527
* @since 6/11/2017 9:27 AM
2628
*/

src/main/java/me/zero/client/api/command/executor/sender/CommandSender.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1+
/*
2+
* Copyright 2017 ZeroMemes
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+
117
package me.zero.client.api.command.executor.sender;
218

319
import net.minecraft.entity.player.EntityPlayer;
420

521
/**
6-
* Represents a
22+
* Represents a sender
723
*
824
* @author Brady
925
* @since 6/11/2017 6:41 PM

src/main/java/me/zero/client/api/command/handler/CommandHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.util.stream.Collectors;
3232

3333
/**
34+
* Handles and processes command execution events
35+
*
3436
* @author Brady
3537
* @since 6/1/2017 3:03 PM
3638
*/
@@ -71,7 +73,10 @@ public CommandHandler(Client client) {
7173
throw new UnknownCommandException();
7274
} catch (CommandException e) {
7375
List<ExceptionHandler> handlers = findHandlers(e);
74-
handlers.forEach(handler -> handler.accept(e));
76+
if (handlers.isEmpty())
77+
e.printStackTrace();
78+
else
79+
handlers.forEach(handler -> handler.accept(e));
7580
}
7681
});
7782

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2017 ZeroMemes
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+
117
package me.zero.client.api.command.handler.listener;
218

319
import me.zero.alpine.listener.EventHandler;
@@ -17,6 +33,9 @@
1733
import java.util.regex.Pattern;
1834

1935
/**
36+
* Command listener setup to listen to chat commands
37+
* sent through client-sided input
38+
*
2039
* @author Brady
2140
* @since 6/11/2017 1:47 PM
2241
*/
@@ -33,54 +52,53 @@ public ChatCommandListener(CommandHandler handler) {
3352
String raw = event.getRawMessage();
3453

3554
// If the user sends a message starting with a backslash, then we'll send whatever follows it.
55+
// So if our command prefix was "." then sending "\.bind" would send ".bind" in chat.
56+
// This replaces the need for the standard ".say" command that is present in most clients.
3657
if (raw.startsWith("\\") && raw.length() > 1) {
3758
event.setMessage(new TextComponentString(raw.substring(1)));
3859
return;
3960
}
4061

62+
// If the message is a command
4163
if (raw.startsWith(handler.getPrefix())) {
42-
try {
43-
// No matter what, always cancel the message if it starts with the command prefix
44-
event.cancel();
64+
// No matter what, always cancel the message if it starts with the command prefix
65+
event.cancel();
4566

46-
// Removed the prefix from the message
47-
raw = raw.substring(handler.getPrefix().length());
67+
// Removed the prefix from the message
68+
raw = raw.substring(handler.getPrefix().length());
4869

49-
// Create a matcher to parse the message
50-
Matcher matcher = REGEX.matcher(raw);
70+
// Create a matcher to parse the message
71+
Matcher matcher = REGEX.matcher(raw);
5172

52-
List<String> matches = new ArrayList<>();
53-
while (matcher.find()) {
54-
matches.add(matcher.group());
55-
}
73+
List<String> matches = new ArrayList<>();
74+
while (matcher.find()) {
75+
matches.add(matcher.group());
76+
}
5677

57-
// Only handle the command if there is at least 1 argument group
58-
if (matches.size() > 0) {
59-
Command command = handler.getClient().getCommandManager().getData().stream().filter(cmd -> {
60-
for (String header : cmd.headers()) {
61-
if (header.equalsIgnoreCase(matches.get(0))) {
62-
return true;
63-
}
78+
// Only handle the command if there is at least 1 argument group
79+
if (matches.size() > 0) {
80+
Command command = handler.getClient().getCommandManager().getData().stream().filter(cmd -> {
81+
for (String header : cmd.headers()) {
82+
if (header.equalsIgnoreCase(matches.get(0))) {
83+
return true;
6484
}
65-
return false;
66-
}).findFirst().orElse(null);
85+
}
86+
return false;
87+
}).findFirst().orElse(null);
6788

68-
// Only handle the command if it's found
69-
if (command != null) {
70-
// Get all matches after the first one, these are treated as arguments
71-
String[] args = new String[matches.size() - 1];
72-
for (int i = 1; i < matches.size(); i++)
73-
args[i - 1] = matches.get(i).replace("\"", "").replace("\'", "");
89+
// Only handle the command if it's found
90+
if (command != null) {
91+
// Get all matches after the first one, these are treated as arguments
92+
String[] args = new String[matches.size() - 1];
93+
for (int i = 1; i < matches.size(); i++)
94+
args[i - 1] = matches.get(i).replace("\"", "").replace("\'", "");
7495

75-
ClientAPI.EVENT_BUS.post(new CommandExecutionEvent(command, CommandSender.from(mc.player), args));
76-
}
96+
ClientAPI.EVENT_BUS.post(new CommandExecutionEvent(command, CommandSender.from(mc.player), args));
7797
}
78-
79-
// This will be interpreted as an unknown command
80-
ClientAPI.EVENT_BUS.post(new CommandExecutionEvent(null, null, null));
81-
} catch (Exception e) {
82-
e.printStackTrace();
8398
}
99+
100+
// This will be interpreted as an unknown command
101+
ClientAPI.EVENT_BUS.post(new CommandExecutionEvent(null, null, null));
84102
}
85103
});
86104
}

src/main/java/me/zero/client/api/command/handler/listener/CommandListener.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1+
/*
2+
* Copyright 2017 ZeroMemes
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+
117
package me.zero.client.api.command.handler.listener;
218

319
import me.zero.client.api.command.handler.CommandHandler;
420

521
/**
22+
* Base for command input listeners
23+
*
624
* @author Brady
725
* @since 6/11/2017 1:47 PM
826
*/

0 commit comments

Comments
 (0)