Merge commit '2af8c8dbf2d5eb16d7492fd12b4b786d6205d0f9' as 'lib'
This commit is contained in:
58
lib/bungee/pom.xml
Normal file
58
lib/bungee/pom.xml
Normal file
@@ -0,0 +1,58 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>command-framework-parent</artifactId>
|
||||
<version>0.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>command-framework-bungee</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.5-SNAPSHOT</version>
|
||||
<name>Sk89q Command Framework for BungeeCord</name>
|
||||
<description>Supporting classes for using the command framework on BungeeCord.</description>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sonatype-public</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.sk89q</groupId>
|
||||
<artifactId>command-framework-core</artifactId>
|
||||
<version>0.5-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.5-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.1</version>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.sk89q:command-framework-core</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@@ -0,0 +1,12 @@
|
||||
package com.sk89q.bungee.util;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandsManager;
|
||||
|
||||
public class BungeeCommandsManager extends CommandsManager<CommandSender> {
|
||||
@Override
|
||||
public boolean hasPermission(CommandSender player, String perm) {
|
||||
return player.hasPermission(perm);
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
package com.sk89q.bungee.util;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.WrappedCommandSender;
|
||||
|
||||
public class BungeeWrappedCommandSender implements WrappedCommandSender {
|
||||
public BungeeWrappedCommandSender(CommandSender wrapped) {
|
||||
this.wrapped = wrapped;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.wrapped.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
this.wrapped.sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String[] messages) {
|
||||
this.wrapped.sendMessages(messages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String permission) {
|
||||
return this.wrapped.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
if (this.wrapped.getName().equals("CONSOLE")) { // hack because Bungee does not export ConsoleCommandSender
|
||||
return Type.CONSOLE;
|
||||
} else {
|
||||
return Type.PLAYER;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCommandSender() {
|
||||
return this.wrapped;
|
||||
}
|
||||
|
||||
private final CommandSender wrapped;
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
package com.sk89q.bungee.util;
|
||||
|
||||
|
||||
public interface CommandExecutor<T> {
|
||||
void onCommand(T sender, String commandName, String[] args);
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
package com.sk89q.bungee.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.plugin.PluginManager;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandsManager;
|
||||
|
||||
public class CommandRegistration {
|
||||
public CommandRegistration(Plugin plugin, PluginManager pluginManager, CommandsManager<?> commands, CommandExecutor<CommandSender> executor) {
|
||||
this.plugin = plugin;
|
||||
this.pluginManager = pluginManager;
|
||||
this.commands = commands;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public boolean register(Class<?> clazz) {
|
||||
return this.registerAll(this.commands.registerAndReturn(clazz));
|
||||
}
|
||||
|
||||
public boolean registerAll(List<Command> registered) {
|
||||
for(Command command : registered) {
|
||||
CommandWrapper wrapper = new CommandWrapper(this.executor, command.aliases()[0], command.aliases());
|
||||
this.pluginManager.registerCommand(this.plugin, wrapper);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private final Plugin plugin;
|
||||
private final PluginManager pluginManager;
|
||||
private final CommandsManager<?> commands;
|
||||
private final CommandExecutor<CommandSender> executor;
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.sk89q.bungee.util;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
public class CommandWrapper extends Command {
|
||||
public CommandWrapper(CommandExecutor<CommandSender> executor, String commandName, String... aliases) {
|
||||
super(commandName, null, aliases);
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
this.executor.onCommand(sender, this.getName(), args);
|
||||
}
|
||||
|
||||
private final CommandExecutor<CommandSender> executor;
|
||||
}
|
Reference in New Issue
Block a user