-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added MissingSubcommandException, plus some more internal changes
- Loading branch information
Showing
16 changed files
with
145 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletions
11
src/main/java/fr/zcraft/quartzlib/components/commands/CommandMethodArgument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/fr/zcraft/quartzlib/components/commands/ExecutionContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package fr.zcraft.quartzlib.components.commands; | ||
|
||
import org.bukkit.command.CommandSender; | ||
|
||
public class ExecutionContext { | ||
private final CommandSender sender; | ||
private final String[] fullArgs; | ||
|
||
public ExecutionContext(CommandSender sender, String[] fullArgs) { | ||
this.sender = sender; | ||
this.fullArgs = fullArgs; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/fr/zcraft/quartzlib/components/commands/exceptions/ArgumentParseException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
package fr.zcraft.quartzlib.components.commands.exceptions; | ||
|
||
import fr.zcraft.quartzlib.components.rawtext.RawText; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class ArgumentParseException extends CommandException { | ||
@Override | ||
public RawText display(CommandSender sender) { | ||
return null; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/fr/zcraft/quartzlib/components/commands/exceptions/CommandException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
package fr.zcraft.quartzlib.components.commands.exceptions; | ||
|
||
import fr.zcraft.quartzlib.components.rawtext.RawText; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public abstract class CommandException extends Exception { | ||
public abstract RawText display(CommandSender sender); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/fr/zcraft/quartzlib/components/commands/exceptions/InvalidSenderException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
package fr.zcraft.quartzlib.components.commands.exceptions; | ||
|
||
import fr.zcraft.quartzlib.components.rawtext.RawText; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class InvalidSenderException extends CommandException { | ||
@Override | ||
public RawText display(CommandSender sender) { | ||
return null; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...n/java/fr/zcraft/quartzlib/components/commands/exceptions/MissingSubcommandException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package fr.zcraft.quartzlib.components.commands.exceptions; | ||
|
||
import fr.zcraft.quartzlib.components.commands.CommandGroup; | ||
import fr.zcraft.quartzlib.components.commands.CommandNode; | ||
import fr.zcraft.quartzlib.components.i18n.I; | ||
import fr.zcraft.quartzlib.components.rawtext.RawText; | ||
import fr.zcraft.quartzlib.components.rawtext.RawTextPart; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.CommandSender; | ||
|
||
public class MissingSubcommandException extends CommandException { | ||
private final CommandGroup commandGroup; | ||
|
||
public MissingSubcommandException(CommandGroup commandGroup) { | ||
this.commandGroup = commandGroup; | ||
} | ||
|
||
@Override | ||
public RawText display(CommandSender sender) { | ||
RawTextPart<?> text = new RawText(I.t("Missing subcommand: ")) | ||
.color(ChatColor.RED) | ||
.then("/").color(ChatColor.WHITE) | ||
.then(getParents()).color(ChatColor.AQUA) | ||
.then(" <").style(ChatColor.GRAY) | ||
.then(I.t("sub-command")) | ||
.style(ChatColor.GRAY, ChatColor.UNDERLINE) | ||
.hover(appendSubCommandList(new RawText())) | ||
.then(">").style(ChatColor.GRAY); | ||
|
||
return text.build(); | ||
} | ||
|
||
private String getParents() { | ||
StringBuilder builder = new StringBuilder(); | ||
|
||
CommandGroup group = commandGroup; | ||
|
||
do { | ||
if (builder.length() > 0) { | ||
builder.append(' '); | ||
} | ||
builder.append(group.getName()); | ||
group = group.getParent(); | ||
} while (group != null); | ||
|
||
return builder.toString(); | ||
} | ||
|
||
private RawTextPart<?> appendSubCommandList(RawTextPart<?> text) { | ||
boolean first = true; | ||
text = text.then(I.t("One of the following:\n ")); | ||
for (CommandNode subCommand : commandGroup.getSubCommands()) { | ||
if (!first) { | ||
text = text.then(", ").color(ChatColor.GRAY); | ||
} | ||
first = false; | ||
|
||
text = text.then(subCommand.getName()).color(ChatColor.AQUA); | ||
} | ||
|
||
return text; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...java/fr/zcraft/quartzlib/components/commands/exceptions/UnknownArgumentTypeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package fr.zcraft.quartzlib.components.commands.exceptions; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
public class UnknownArgumentTypeException extends RuntimeException { | ||
public UnknownArgumentTypeException(Method method, Class<?> foundType) { | ||
super(getErrorMessage(method, foundType)); | ||
} | ||
|
||
private static String getErrorMessage(Method method, Class<?> foundType) { | ||
return "Found unknown command argument type: '" + foundType | ||
+ "' (found in '" + method.toString() + "'). " | ||
+ "Did you forget to register it to the CommandManager?"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters