Server Start - Output To Command Line?

Discussion in 'Plugin Development' started by Favorlock, Oct 9, 2011.

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

    Favorlock

    Hi there, I'm completely new to Java, but I am more of a hands on learner. So basically I decided that I would start simple, or somewhat simple and make plugin called "simplemob" which of course I don't intend to publish. So at the moment I'm just working on the "Permissions" section. I believe I have everything hooked properly, but now what I need to know is how to make a particular value print to the command line via logger. This is what I have so far:

    Code:
    package us.fav.simplemob;
    
    import java.util.logging.Logger;
    
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.nijiko.permissions.PermissionHandler;
    import com.nijikokun.bukkit.Permissions.Permissions;
    
    public class simplemob extends JavaPlugin {
    
        public static PermissionHandler permissionHandler;
    
        private Logger log = Logger.getLogger("Minecraft");
    
        /*-----------------------------------------*/
        /* Enable/Disable */
        /*-----------------------------------------*/
    
        @Override
        public void onEnable() {
    
    
            setupPermissions();
    
            this.logMessage("Enabled!");
        }
    
        @Override
        public void onDisable() {
            this.logMessage("Disabled!");
    
        }
    
        protected void logMessage(String msg) {
            PluginDescriptionFile pdFile = this.getDescription();
            this.log.info(pdFile.getName() + " " + pdFile.getVersion() + ": " + msg);
        }
    
        /*-----------------------------------------*/
        /* Permissions */
        /*-----------------------------------------*/
    
        public void setupPermissions() {
            Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("Permissions");
    
            if (simplemob.permissionHandler == null) {
    
                if (permissionsPlugin != null) {
                    simplemob.permissionHandler = ((Permissions) permissionsPlugin).getHandler();
                }
            }
            else {
                Logger.getLogger("Minecraft");
                this.logMessage("Permissions plugin has not been detected, defaulting to Op.");
            }
        }
    
        public boolean hasPermission(Player player, String string) {
    
            if (null == permissionHandler) {
                return player.isOp();
            }
            if (simplemob.permissionHandler.has(player, string)) {
                return true;
            }
            return false;
        }
    }
    As you can see, the last two methods are where I put everything for the Permissions. I have it so that onEnable calls setupPermissions, but the problem I am having is trying to get the else function to work as I want it to. So basically, I want the else value "Permission plugin has..." to print to the console just like the onEnable prints "simplemob 0.0.2.1: Enabled!" to the console.

    Can anyone enlighten me as to how I can achieve this?
     
  2. Offline

    zhuowei

    Your code only prints "Permissions plugin..." if the permissionHandler is null, which it is at the start of the program. I think I fixed it.
    Off-topic, but it seems to me that most plugins are switching to Bukkit's built-in permissions system instead of using the Permissions plugin.
     
  3. Offline

    Favorlock

    I know, I'm just using it to support the bridge between PEX and the plugin. Like I said, its all just for practice.
     
  4. Offline

    zhuowei

    I thought PermissionsEx supports the new Bukkit permissions?
     
  5. Offline

    Favorlock

    Probably does, but it also has a bridge for Permissions. I tried what you suggested and I got some warnings on the else function. I just want to figure out how to get the plugin to detect and notify which perm plugin it hooks into :\ So troublesome this is.
     
Thread Status:
Not open for further replies.

Share This Page