mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-01 07:36:42 +00:00
Wow
This commit is contained in:
@ -1,16 +0,0 @@
|
||||
package me.totalfreedom.plex.command;
|
||||
|
||||
import me.totalfreedom.plex.PlexBase;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class PlexCommand extends PlexBase implements CommandExecutor
|
||||
{
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command message, String s, String[] args)
|
||||
{
|
||||
sender.sendMessage(plugin.config.getString("server.test"));
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package me.totalfreedom.plex.command.impl;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandParameters
|
||||
{
|
||||
String description() default "";
|
||||
String usage() default "/<command>";
|
||||
String aliases() default "";
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package me.totalfreedom.plex.command.impl;
|
||||
|
||||
import me.totalfreedom.plex.rank.enums.Rank;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandPermissions
|
||||
{
|
||||
Rank level() default Rank.IMPOSTOR;
|
||||
RequiredCommandSource source();
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package me.totalfreedom.plex.command.impl;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.plex.player.PlexPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandSource
|
||||
{
|
||||
@Getter
|
||||
private CommandSender sender;
|
||||
@Getter
|
||||
private Player player;
|
||||
private PlexPlayer plexPlayer;
|
||||
|
||||
public CommandSource(CommandSender sender)
|
||||
{
|
||||
this.sender = sender;
|
||||
this.player = Bukkit.getPlayer(sender.getName());
|
||||
this.plexPlayer = null;
|
||||
}
|
||||
|
||||
|
||||
}
|
106
src/main/java/me/totalfreedom/plex/command/impl/PlexCommand.java
Normal file
106
src/main/java/me/totalfreedom/plex/command/impl/PlexCommand.java
Normal file
@ -0,0 +1,106 @@
|
||||
package me.totalfreedom.plex.command.impl;
|
||||
|
||||
import me.totalfreedom.plex.PlexBase;
|
||||
import me.totalfreedom.plex.rank.enums.Rank;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class PlexCommand extends PlexBase implements CommandExecutor, TabCompleter
|
||||
{
|
||||
private static final String COMMAND_PREFIX = "Command_";
|
||||
private static CommandMap COMMAND_MAP;
|
||||
|
||||
private final CommandParameters params;
|
||||
private final CommandPermissions perms;
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final String usage;
|
||||
private final List<String> aliases;
|
||||
private final Rank level;
|
||||
private final RequiredCommandSource source;
|
||||
|
||||
protected PlexCommand()
|
||||
{
|
||||
this.params = this.getClass().getAnnotation(CommandParameters.class);
|
||||
this.perms = this.getClass().getAnnotation(CommandPermissions.class);
|
||||
this.name = this.getClass().getSimpleName().toLowerCase().replace(COMMAND_PREFIX.toLowerCase(), "");
|
||||
this.description = this.params.description();
|
||||
this.usage = this.params.usage();
|
||||
this.aliases = Arrays.asList(this.params.aliases().split(","));
|
||||
this.level = this.perms.level();
|
||||
this.source = this.perms.source();
|
||||
}
|
||||
|
||||
public void register()
|
||||
{
|
||||
PCommand command = new PCommand(this.name);
|
||||
command.setDescription(this.description);
|
||||
command.setUsage(this.usage);
|
||||
command.setAliases(this.aliases);
|
||||
this.getCommandMap().register("", command);
|
||||
command.setExecutor(this);
|
||||
}
|
||||
|
||||
protected CommandMap getCommandMap()
|
||||
{
|
||||
if (COMMAND_MAP == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Field f = Bukkit.getServer().getClass().getDeclaredField("commandMap");
|
||||
f.setAccessible(true);
|
||||
COMMAND_MAP = (CommandMap) f.get(Bukkit.getServer());
|
||||
return getCommandMap();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
return COMMAND_MAP;
|
||||
return getCommandMap();
|
||||
}
|
||||
|
||||
private static class PCommand extends Command
|
||||
{
|
||||
private PlexCommand command = null;
|
||||
|
||||
private PCommand(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void setExecutor(PlexCommand command)
|
||||
{
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String c, String[] args)
|
||||
{
|
||||
if (command == null)
|
||||
return false;
|
||||
return command.onCommand(sender, this, c, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
|
||||
{
|
||||
if (command == null)
|
||||
return null;
|
||||
return Objects.requireNonNull(command.onTabComplete(sender, this, alias, args));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String c, String[] args)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package me.totalfreedom.plex.command.impl;
|
||||
|
||||
public enum RequiredCommandSource
|
||||
{
|
||||
IN_GAME,
|
||||
CONSOLE,
|
||||
ANY
|
||||
}
|
Reference in New Issue
Block a user