Add BaseCommand#canRun, OpCommand and MapAdminCommand for permissions

This commit is contained in:
Spencer 2018-03-07 13:32:20 -05:00 committed by Alexander Meech
parent 8c49ddf6f6
commit a9eac7f7e7
4 changed files with 61 additions and 0 deletions

View File

@ -25,6 +25,11 @@ public abstract class BaseCommand
_aliases = Arrays.asList(aliases);
}
public boolean canRun(Player player)
{
return true;
}
public abstract boolean execute(Player player, String alias, String[] args);
public String getDescription()

View File

@ -0,0 +1,32 @@
package mineplex.mapparser.command;
import org.bukkit.World;
import org.bukkit.entity.Player;
import mineplex.mapparser.MapParser;
public abstract class MapAdminCommand extends BaseCommand
{
public MapAdminCommand(MapParser plugin, String... aliases)
{
super(plugin, aliases);
}
@Override
public boolean canRun(Player player)
{
if (player.isOp())
{
return true;
}
World world = player.getWorld();
if (world.getName().equals("world_lobby"))
{
return false;
}
return getPlugin().getData(world.getName()).HasAccess(player);
}
}

View File

@ -0,0 +1,19 @@
package mineplex.mapparser.command;
import org.bukkit.entity.Player;
import mineplex.mapparser.MapParser;
public abstract class OpCommand extends BaseCommand
{
public OpCommand(MapParser plugin, String... aliases)
{
super(plugin, aliases);
}
@Override
public boolean canRun(Player player)
{
return player.isOp();
}
}

View File

@ -95,6 +95,11 @@ public class CommandModule extends Module
event.setCancelled(true);
if (!baseCommand.canRun(player))
{
player.sendMessage(F.main(getPlugin().getName(), "You don't have permission to do that."));
}
if (!baseCommand.execute(player, commandLabel, args))
{
UtilPlayerBase.message(player, F.main("Parser", "Invalid Input."));