Skip to content

Commit

Permalink
fix misc issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dries007 committed Nov 3, 2015
1 parent a2f54e0 commit 8bb5705
Show file tree
Hide file tree
Showing 61 changed files with 5,770 additions and 31 deletions.
13 changes: 7 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apply plugin: "idea-utils"
archivesBaseName = "D3Backend"
group = "net.doubledoordev.backend"

version = "0.9.0"
version = "0.9.1"
if (System.getenv().BUILD_NUMBER != null) version += "." + System.getenv().BUILD_NUMBER

def vendor = "DoubleDoorDevelopment"
Expand Down Expand Up @@ -59,10 +59,10 @@ idea {

repositories {
mavenCentral()
maven {
name = 'sk89q'
url = "http://maven.sk89q.com/repo/"
}
// maven {
// name = 'sk89q'
// url = "http://maven.sk89q.com/repo/"
// }
maven {
name = 'sonatype-nexus'
url = 'https://oss.sonatype.org/content/groups/public/'
Expand All @@ -78,10 +78,11 @@ dependencies {
compile group: "org.freemarker", name: "freemarker", version: "2.3.20"
compile group: "org.apache.logging.log4j", name: "log4j-core", version: "2.0.2"
compile group: "net.lingala.zip4j", name: "zip4j", version: "1.3.2"
compile group: "com.sk89q", name: "intake", version: "3.1.1-SNAPSHOT"
//compile group: "com.sk89q", name: "intake", version: "3.1.1-SNAPSHOT"
compile group: "org.glassfish.grizzly", name: "grizzly-http-all", version: "2.3.17"
compile group: "com.flowpowered", name: "flow-nbt", version: "1.0.0"
compile group: "net.doubledoordev.cmd", name: "CurseModpackDownloader", version: "0.+"
compile group: "com.google.guava", name: "guava", version: "18.0"
}

processResources {
Expand Down
102 changes: 102 additions & 0 deletions src/main/java/com/sk89q/intake/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Intake, a command processing library
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) Intake 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.intake;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotates a method that is to be registered as a command.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Command {

/**
* A list of aliases for the command. The first alias is the name of
* the command and considered the main alias.
*
* @return aliases for a command
*/
String[] aliases();

/**
* An example usage string of the command.
*
* <p>An example would be
* {@code [-h &lt;value&gt;] &lt;name&gt; &lt;message&gt;}.</p>
*
* @return usage instructions for a command
*/
String usage() default "";

/**
* A short description of the command.
*
* @return a short description for the command.
*/
String desc();

/**
* The minimum number of arguments. This should be 0 or above.
*
* @return the minimum number of arguments
*/
int min() default 0;

/**
* The maximum number of arguments. Use -1 for an unlimited number
* of arguments.
*
* @return the maximum number of arguments
*/
int max() default -1;

/**
* Flags allow special processing for flags such as -h in the command,
* allowing users to easily turn on a flag. This is a string with
* each character being a flag. Use A-Z and a-z as possible flags.
* Appending a flag with a : makes the flag character before a value flag,
* meaning that if it is given, it must have a value.
*
* @return flags matching a-zA-Z
* @see #anyFlags() to see accept any flag
*/
String flags() default "";

/**
* A long description for the command.
*
* @return A long description for the command.
*/
String help() default "";

/**
* Get whether any flag can be used.
*
* <p>The value of this property overrides {@link #flags()}.</p>
*
* @return true if so
*/
boolean anyFlags() default false;

}
60 changes: 60 additions & 0 deletions src/main/java/com/sk89q/intake/CommandCallable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Intake, a command processing library
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) Intake 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.intake;

import com.sk89q.intake.completion.CommandCompleter;
import com.sk89q.intake.context.CommandLocals;
import com.sk89q.intake.util.auth.AuthorizationException;

/**
* A command that can be executed.
*/
public interface CommandCallable extends CommandCompleter {

/**
* Execute the correct command based on the input.
*
* <p>The implementing class must perform the necessary permission
* checks.</p>
*
* @param arguments the arguments
* @param locals the locals
* @param parentCommands a list of parent commands, with the first most entry being the top-level command
* @return the called command, or null if there was no command found
* @throws CommandException thrown on a command error
*/
boolean call(String arguments, CommandLocals locals, String[] parentCommands) throws CommandException, AuthorizationException;

/**
* Get an object describing this command.
*
* @return the command description
*/
Description getDescription();

/**
* Test whether this command can be executed with the given context.
*
* @param locals the locals
* @return true if execution is permitted
*/
boolean testPermission(CommandLocals locals);

}
127 changes: 127 additions & 0 deletions src/main/java/com/sk89q/intake/CommandException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Intake, a command processing library
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) Intake 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.intake;


import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* Thrown when an executed command raises an error or when execution of
* the command failed.
*/
public class CommandException extends Exception {

private final List<String> commandStack = new ArrayList<String>();

/**
* Constructs a new exception with {@code null} as its detail message.
* The cause is not initialized, and may subsequently be initialized by a
* call to {@link #initCause}.
*/
public CommandException() {
}

/**
* Constructs a new exception with the specified detail message. The
* cause is not initialized, and may subsequently be initialized by
* a call to {@link #initCause}.
*
* @param message the detail message. The detail message is saved for
* later retrieval by the {@link #getMessage()} method.
*/
public CommandException(String message) {
super(message);
}

/**
* Constructs a new exception with the specified detail message and
* cause. <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this exception's detail message.
*
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
*/
public CommandException(String message, Throwable cause) {
super(message, cause);
}

/**
* Constructs a new exception with the specified cause and a detail
* message of <tt>(cause==null ? null : cause.toString())</tt> (which
* typically contains the class and detail message of <tt>cause</tt>).
*
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
*/
public CommandException(Throwable cause) {
super(cause);
}

/**
* Add the command to the stack of commands that are a parent to the
* command that was called.
*
* @param name the parent command
*/
public void prependStack(String name) {
checkNotNull(name);
commandStack.add(name);
}

/**
* Gets the command that was called, which will include the sub-command
* (i.e. "/br sphere").
*
* @param prefix the command shebang character (such as "/") -- may be empty
* @param spacedSuffix a suffix to put at the end (optional) -- may be null
* @return the command that was used
*/
public String getCommandUsed(String prefix, String spacedSuffix) {
checkNotNull(prefix);
StringBuilder builder = new StringBuilder();
builder.append(prefix);
ListIterator<String> li = commandStack.listIterator(commandStack.size());
while (li.hasPrevious()) {
if (li.previousIndex() != commandStack.size() - 1) {
builder.append(" ");
}
builder.append(li.previous());
}
if (spacedSuffix != null) {
if (builder.length() > 0) {
builder.append(" ");
}
builder.append(spacedSuffix);
}
return builder.toString().trim();
}

}
55 changes: 55 additions & 0 deletions src/main/java/com/sk89q/intake/CommandMapping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Intake, a command processing library
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) Intake 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.intake;

/**
* Provides information about a mapping between a command and its aliases.
*/
public interface CommandMapping {

/**
* Get the primary alias.
*
* @return the primary alias
*/
String getPrimaryAlias();

/**
* Get a list of all aliases.
*
* @return aliases
*/
String[] getAllAliases();

/**
* Get the callable
*
* @return the callable
*/
CommandCallable getCallable();

/**
* Get the {@link Description} form the callable.
*
* @return the description
*/
Description getDescription();

}
Loading

0 comments on commit 8bb5705

Please sign in to comment.