Need Help with basic programming

Discussion in 'Plugin Development' started by PandaK551, Apr 11, 2011.

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

    PandaK551

    I barely programmed before (in Bukkitl) but I still wanted to add Permissions Support to the SpawnCreature plugin by Protected, but there is a problems:
    I get an error for the "player" in:

    if (!SpawnCreature.Permissions.has(player, "SpawnCreature.spawn")) {
    return;
    }

    All the source code is here:

    http://dl.dropbox.com/u/14508720/SpawnCreaturePermissions.rtf

    I hope someone can help me. If there are very big problems thats because I dont know anything about how to program for bukkit. I had my own plugin for my server in hmod, but bukkit is a big chnage in comparison.
     
  2. Offline

    Sammy

  3. Offline

    ssell

    You have the check for permission in the wrong spot. You also were missing a bracket, causing Permissions to never be initialized.

    I assume you want to restrict access to the spawncreature command. If so, you would do it like this:

    Code:
    package net.myshelter.minecraft;
    
    import java.util.logging.Logger;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.CreatureType;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import com.nijiko.permissions.PermissionHandler;
    import com.nijikokun.bukkit.Permissions.Permissions;
    import org.bukkit.plugin.Plugin;
    
    public class SpawnCreature extends JavaPlugin
    {
        public static Logger log = Logger.getLogger("Minecraft");
    
        public static PermissionHandler Permissions;
    
        public void onEnable( )
        {
            log.info("SpawnCreature is on!");
            setupPermissions();
        }
    
        private void setupPermissions( )
        {
            Plugin test = this.getServer( ).getPluginManager( ).getPlugin( "Permissions" );
    
            if ( SpawnCreature.Permissions == null )
            {
                if (test != null)
                {
                    SpawnCreature.Permissions = ((Permissions)test).getHandler();
                }
                else
                {
                    log.info("[SpawnCreature]Permission system not detected, defaulting to OP");
                }
    
            }
        }
    
        public void onDisable()
        {
            log.info("SpawnCreature is off...");
        }
    
        public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
        {
            if ( !( sender instanceof Player ) )
            {
                return false;
            }
    
            Player player = ( Player )sender;
    
            if( !player.isOp( ) )
            {
                return false;
            }
    
            if( command.getName( ).equalsIgnoreCase( "spawncreature" ) )
            {
                if ( !SpawnCreature.Permissions.has( player, "SpawnCreature.spawn" ) )
                {
                    return true;
                }
    
                if ( args.length < 1 )
                {
                    return true;
                }
    
                CreatureType ct = CreatureType.fromName( args[ 0 ] );
    
                if ( ct == null )
                {
                    return true;
                }
    
                int amount = 1;
    
                if ( args.length > 1 )
                {
                    amount = Integer.parseInt( args[ 1 ] );
                }
    
                for ( int i = 0; i < amount; i++ )
                {
                    player.getWorld( ).spawnCreature( player.getLocation( ), ct );
                }
    
                return true;
            }
            return false;
        }
    }
    
     
Thread Status:
Not open for further replies.

Share This Page