Solved Plugin aliases

Discussion in 'Plugin Development' started by Protophite, May 1, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Protophite

    I'm pretty sure I've set everything correctly, but when I try to use an aliase in game there is no response from the server.

    Code:
    public class CommandHandler implements CommandExecutor
    {
    
        private final CoreFrags instance;
        private final Map<String, CommandBase> commands = new HashMap<>();
    
        public CommandHandler(CoreFrags instance) {
    
            this.instance = instance;
    
            CommandBase[] cmds = { new BalanceCommand(this.instance), new SetspawnCommand(this.instance), new SpawnCommand(this.instance) };
    
            for (CommandBase cmd : cmds) {
                this.commands.put(cmd.getName(), cmd);
                this.instance.getCommand(cmd.getName()).setExecutor(this);
            }
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            CommandBase command = (CommandBase)this.commands.get(commandLabel);
            if (command != null)
                return command.execute(sender, cmd, commandLabel, args);
            return false;
        }
    
    }
    Code:
    public class SetspawnCommand implements CommandBase {
    
        private final CoreFrags instance;
    
        public SetspawnCommand(CoreFrags instance){
            this.instance = instance;
        }
    
        @Override
        public boolean execute(CommandSender pureSender, Command cmd, String label, String[] args) {
           
            String noPerm = this.instance.PREFIX + ChatColor.RED + "You do not have permission to use this command."
           
            if(!(pureSender instanceof Player)){
                pureSender.sendMessage(noPerm);
                return false;
            }
           
            FragsPlayer sender = this.instance.getPlayerManager().getPlayer(pureSender.getName());
           
            if(!sender.hasPerm(Permissions.SPAWN_SET)){
                pureSender.sendMessage(noPerm);
                return false;
            }
    
            Location spawn = sender.getPlayer().getLocation();
           
            LocationsModule locationModule = (LocationsModule)this.instance.getModuleHandler().getModule("locations module");
            locationModule.setSpawn(spawn);
           
            pureSender.sendMessage(this.instance.PREFIX + ChatColor.DARK_GREEN + "You have set a new spawn point. /spawn to teleport!");
           
            return true;
        }
    
        @Override
        public String getName() {
            return "setspawn";
        }
    }
    Code:
    main: ca.frags.protophite.CoreFrags
    name: FragsCore
    version: 1.0
    description: A core to the frags server.
    author: Protophite
    
    commands:
      setspawn:
        description: Set spawn location.
        aliases: [spawnset, sespawn, setpsawn, setspawm]
     
  2. Online

    timtower Administrator Administrator Moderator

    @Protophite Because you are checking using the commandLabel, that can be one of the aliases so it won't work.
    Check the command.getName() instead.
     
    Protophite likes this.
  3. Offline

    Protophite

  4. Offline

    WolfMage1

    Please change SetspawnCommand to a capital S for Spawn, <3, it annoys the hell out of me
     
  5. Offline

    Protophite

    @WolfMage1 No? remove the 1 in your ID... it annoys me.
     
  6. Offline

    WolfMage1

    Just... ignore that post xD
     
Thread Status:
Not open for further replies.

Share This Page