Skip to content
This repository has been archived by the owner on Aug 31, 2019. It is now read-only.

Add enforcement of @Console, update dependencies, bump version to 0.4.1-SNAPSHOT #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</parent>
<artifactId>command-framework-bukkit</artifactId>
<packaging>jar</packaging>
<version>0.4-SNAPSHOT</version>
<version>0.4.1-SNAPSHOT</version>
<name>Sk89q Command Framework for Bukkit</name>
<description>Supporting classes for running the command framework on Bukkit servers.</description>

Expand All @@ -22,12 +22,12 @@
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>command-framework-core</artifactId>
<version>0.4-SNAPSHOT</version>
<version>0.4.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.4.7-R1.0</version>
<version>1.5.2-R1.0</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
package com.sk89q.bukkit.util;

import com.sk89q.minecraft.util.commands.ConsoleCommandException;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;

import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandsManager;
import com.sk89q.minecraft.util.commands.Console;

import java.lang.reflect.Method;

public class BukkitCommandsManager extends CommandsManager<CommandSender> {
@Override
public boolean hasPermission(CommandSender player, String perm) {
return player.hasPermission(perm);
}

@Override
public void checkSender(CommandSender sender, Method method) throws CommandException {
if (!method.isAnnotationPresent(Console.class) && sender instanceof ConsoleCommandSender) {
throw new ConsoleCommandException();
}
}
}
6 changes: 3 additions & 3 deletions bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</parent>
<artifactId>command-framework-bungee</artifactId>
<packaging>jar</packaging>
<version>0.4-SNAPSHOT</version>
<version>0.4.1-SNAPSHOT</version>
<name>Sk89q Command Framework for BungeeCord</name>
<description>Supporting classes for using the command framework on BungeeCord.</description>

Expand All @@ -22,12 +22,12 @@
<dependency>
<groupId>com.sk89q</groupId>
<artifactId>command-framework-core</artifactId>
<version>0.4-SNAPSHOT</version>
<version>0.4.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.5-SNAPSHOT</version>
<version>1.6.1-SNAPSHOT</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

import com.sk89q.minecraft.util.commands.CommandsManager;

import java.lang.reflect.Method;

public class BungeeCommandsManager extends CommandsManager<CommandSender> {
@Override
public void checkSender(CommandSender sender, Method method) {
// Sender will never be the console
}

@Override
public boolean hasPermission(CommandSender player, String perm) {
return player.hasPermission(perm);
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</parent>
<artifactId>command-framework-core</artifactId>
<packaging>jar</packaging>
<version>0.4-SNAPSHOT</version>
<version>0.4.1-SNAPSHOT</version>
<name>Sk89q Command Fraework Core</name>
<description>Core classes for the sk89q command framework.</description>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,15 @@

package com.sk89q.minecraft.util.commands;

import com.sk89q.util.StringUtil;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.sk89q.util.StringUtil;

/**
* <p>Manager for handling commands. This allows you to easily process commands,
* including nested commands, by correctly annotating methods of a class.</p>
Expand Down Expand Up @@ -425,6 +420,8 @@ public void execute(String[] args, T player,
executeMethod(null, args, player, newMethodArgs, 0);
}

public abstract void checkSender(T sender, Method method) throws CommandException;

/**
* Attempt to execute a command.
*
Expand Down Expand Up @@ -453,6 +450,7 @@ public void executeMethod(Method parent, String[] args,
}

checkPermission(player, method);
checkSender(player, method);

int argsCount = args.length - 1 - level;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.sk89q.minecraft.util.commands;

/**
* Raised when the console attempts to execute a command not annotated with {@link Console}.
*/
public class ConsoleCommandException extends CommandException {
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.sk89q.bukkit.pagination;
package com.sk89q.minecraft.util.pagination;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.bukkit.command.CommandSender;

import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.WrappedCommandSender;

/**
* Commands that wish to display a paginated list of results can use this class to do
Expand All @@ -42,11 +41,11 @@ public PaginatedResult(int resultsPerPage) {
this.resultsPerPage = resultsPerPage;
}

public void display(CommandSender sender, Collection<? extends T> results, int page) throws CommandException {
public void display(WrappedCommandSender sender, Collection<? extends T> results, int page) throws CommandException {
this.display(sender, new ArrayList<T>(results), page);
}

public void display(CommandSender sender, List<? extends T> results, int page) throws CommandException {
public void display(WrappedCommandSender sender, List<? extends T> results, int page) throws CommandException {
if (results.size() == 0) throw new CommandException("No results match!");

int maxPages = results.size() / this.resultsPerPage + 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sk89q.bukkit.pagination;
package com.sk89q.minecraft.util.pagination;

import org.bukkit.ChatColor;
import com.sk89q.minecraft.util.commands.ChatColor;


public abstract class SimplePaginatedResult<T> extends PaginatedResult<T> {
Expand Down