Permission failure - title updated.

Discussion in 'Plugin Development' started by chocolate_with, Jul 1, 2014.

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

    chocolate_with

    Hello,

    first of all I am new to plugin development and I tried to do everything alone.
    But whenever I want to add a permission, it says that the plugin already initialized.
    This leaves me clueless and don't know what to do to fix this error, also there is an error that says " Caused by: " and doesn't lead to my .java files?

    Here is the error:
    Code:
    [09:38:18] [Server thread/INFO]: [AntiBanBypass] Enabling AntiBanBypass v0.0.2a
    [09:38:18] [Server thread/ERROR]: Error occurred while enabling AntiBanBypass v0.0.2a (Is it up to date?)
    java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:98) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:59) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at com.cab.abb.AntiBB.<init>(AntiBB.java:11) ~[?:?]
        at com.cab.abb.PlayerLoginListener.<init>(PlayerLoginListener.java:14) ~[?:?]
        at com.cab.abb.AntiBB.onEnable(AntiBB.java:31) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:250) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugin(CraftServer.java:439) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.enablePlugins(CraftServer.java:375) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.reload(CraftServer.java:773) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.Bukkit.reload(Bukkit.java:279) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:175) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:683) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchServerCommand(CraftServer.java:670) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.aw(DedicatedServer.java:286) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:251) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    Caused by: java.lang.IllegalStateException: Initial initialization
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:101) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:59) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at com.cab.abb.AntiBB.<init>(AntiBB.java:11) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_05]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_05]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_05]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_05]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_05]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:127) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.java:350) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.reload(CraftServer.java:771) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
        ... 10 more
    
    Here is my main .java file:
    Code:
    package com.cab.abb;
     
    import java.io.File;
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    import com.cab.abb.commands.BanExecutor;
    import com.cab.abb.commands.KickExecutor;
    import com.cab.abb.util.ListStore;
     
    public class AntiBB extends JavaPlugin {
     
        public AntiBBLogger log;
        public ListStore bannedPlayers;
     
        @Override
        public void onEnable() {
            this.log = new AntiBBLogger(this);
     
            String pluginFolder = this.getDataFolder().getAbsolutePath();
     
            (new File(pluginFolder)).mkdirs();
     
            this.bannedPlayers = new ListStore(new File(pluginFolder + File.separator + "banned-players.txt"));
     
            this.bannedPlayers.load();
     
            this.getCommand("kick").setExecutor(new KickExecutor(this));
            this.getCommand("ban").setExecutor(new BanExecutor(this));
     
            this.getServer().getPluginManager().registerEvents(new PlayerLoginListener(this), this);
        }
     
        @Override
        public void onDisable() {
            this.bannedPlayers.save();
        }
     
     
    }
    
    Here is the PlayerLoginListener.java(Here was my first error and was fixed: please ignore " public class PlayerLoginListener extends AntiBB implements Listener "):
    Code:
    package com.cab.abb;
     
    import org.bukkit.ChatColor;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.event.player.PlayerLoginEvent.Result;
     
    public class PlayerLoginListener extends AntiBB implements Listener {
     
        private AntiBB plugin;
     
        public PlayerLoginListener(AntiBB plugin) {
            this.plugin = plugin;
        }
     
        @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
        public void onPlayerLogin(PlayerLoginEvent e) {
            String playerName = e.getPlayer().getName();
     
            if (plugin.bannedPlayers.contains(playerName)) {
                e.setKickMessage(ChatColor.RED + "You have been banned");
                e.setResult(Result.KICK_BANNED);
            }
        }
     
    }
    
    Here is my BanExecutor.java:
    Code:
    package com.cab.abb.commands;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    import com.cab.abb.AntiBB;
    import com.cab.abb.util.Permissions;
     
    public class BanExecutor implements CommandExecutor {
     
        private AntiBB plugin;
     
        public BanExecutor(AntiBB plugin) {
            this.plugin = plugin;
        }
     
        public boolean onCommand(CommandSender snr, Command cmd, String lab, String[] args) {
            if(snr.hasPermission(new Permissions().canBan)) {
                if (args.length != 1) {
                    snr.sendMessage(ChatColor.GOLD + "Usage: /ban <player> [reason]");
                    return true;
                }
     
                Player b = plugin.getServer().getPlayer(args[0]);
     
                plugin.bannedPlayers.add(args[0]);
     
                if (b != null) {
                    b.kickPlayer(ChatColor.RED + "You have been banned by " + ChatColor.GOLD + snr);
                }
                String message = "";
     
                if (args.length > 1) {
                    for (int i = 1; i < args.length; ++i) {
                        message += args[i] + ChatColor.RED + " " + " by:" + snr;
                    }
                } else {
                    message = "You have been kicked from this server.";
                }
     
                snr.sendMessage(ChatColor.GREEN + args[0] + "Has been banned from the server");
                plugin.log.info(ChatColor.GREEN + args[0] + "Has been banned by: " + snr);
                return true;
            } else {
                snr.sendMessage(ChatColor.RED + "You have no permissions to execute this command :(.");
            }
            return true;
        }
     
    }
    
    Here is my Permissions.java:
    Code:
    package com.cab.abb.util;
     
    import org.bukkit.permissions.Permission;
     
    public class Permissions {
     
        public Permission canBan = new Permission("AntiBB.set.ban");
    }
    
     
  2. Offline

    St3venAU

    You shouldn't have PlayerLoginListener extend AntiBB
     
  3. Offline

    chocolate_with

    Well that explains a lot.
    It is fixed now and now I have 2 questions.

    1:
    Must all .java file not extend the main file?

    2(the most noob question -_-):
    Will the plugin able to run if it is saved as JavaSE6 from the source of JDK8?
    I'm using Maven intergration with Eclipse to compile, this is because I kept getting errors about "Plugin.yml not found", while it was in the compiled .jar file without Maven.
    - My Maven ingegration can only use JDK 8 for compiling because I don't have JDK 6 anymore :s.

    ..., oh dear I have another problem.

    I can't seem to let my permissions work.
    I've tried every option to set a permission and it just doesn't work :s.

    So can somebody help?
    All the required classes are in the first post.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  4. Offline

    Rocoty

    1. Only the main class should extend JavaPlugin. None of your other classes should extend JavaPlugin, or by extension, your main class.
    2. I'm not sure I understand the question, sorry. If you are asking if a plugin built towards Java 8 will run in a Java 6 JRE, then yes. Yes it will.
     
  5. Offline

    chocolate_with

    Rocoty

    Sorry that I was not clear for number 2.
    I'm currently using JDK 8 and write the code in JavaSE-6.
    But Maven intergration requires JDK 8 to compile, so I need to switch that in Eclipse.
    So I don't know if Eclipse changes the whole project back to JavaSe-8.
     
  6. Offline

    Rocoty

    chocolate_with If it's a Maven thing I guess I won't be of much help, seeing as I have never touched it before.
     
  7. Offline

    chocolate_with

    Rocoty

    Same for me.., but I installed "Eclipse for Java Developers" wich includes Maven intergration.
    I tried first to make it as a normal java project, but it's exporting and compiling kept failing saying that plugin.yml is not found, whilst it was still in the .jar.
    So that is why I use Maven from now on :s.

    Thanks for explaining the first one wich was more important for me.
     
  8. Offline

    Tss1410

    PermissionAttachment attachment = player.addAttachment(plugin);
    attachment.setPermission(permissionName,permissionValue);
     
  9. Offline

    chocolate_with

    Tss1410

    Doesn't work for me.., bukkit is now overriding my ban command.
    It's probably in the wrong .java file.
    So in wich .java file must that line be?
     
  10. Offline

    Necrodoom

  11. Offline

    chocolate_with

    Necrodoom

    The code is different since 10 minutes ago, well not much updated.
    But I'll add the new code when I can.

    As for plugin.yml when I want to set the permissions in there, then the plugin.yml cannot load because it is invalid?
     
  12. Offline

    Necrodoom

    chocolate_with Paste the invalid plugin.yml then? I cant see whats wrong if you dont show it.
     
  13. Offline

    chocolate_with

    Necrodoom

    Here is the new code from the banExecutor.java and AntiBB.java.

    AntiBB.java:
    Code:
    package com.cab.abb;
    
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.cab.abb.commands.BanExecutor;
    import com.cab.abb.commands.KickExecutor;
    import com.cab.abb.util.ListStore;
    
    public class AntiBB extends JavaPlugin {
        
        public AntiBBLogger log;
        public ListStore bannedPlayers;
        private static List<Listener> e = new ArrayList<Listener>();
        
        @Override
        public void onEnable() {
            this.log = new AntiBBLogger(this);
            
            String pluginFolder = this.getDataFolder().getAbsolutePath();
            
            (new File(pluginFolder)).mkdirs();
            
            this.bannedPlayers = new ListStore(new File(pluginFolder + File.separator + "banned-players.txt"));
            
            this.bannedPlayers.load();
            
            e.add(new BanExecutor(this));
            
            this.getServer().getPluginManager().registerEvents(new PlayerLoginListener(this), this);
        }
        
        @Override
        public void onDisable() {
        }
        
    
    }
    
    BanExecutor.java:
    Code:
    package com.cab.abb.commands;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import com.cab.abb.AntiBB;
    
    public class BanExecutor implements CommandExecutor, Listener {
    
        private AntiBB plugin;
        
        public BanExecutor(AntiBB plugin) {
            this.plugin = plugin;
        }
        
        public boolean onCommand(CommandSender snr, Command cmd, String lab, String[] args) {
            if (cmd.getName().equalsIgnoreCase("ban")) {
                if (!snr.hasPermission("AntiBB.set.ban")) {
                    snr.sendMessage(ChatColor.RED + "Failed to execute, monkeys have been dispatched.");
                    return true;
                } else {
                if (args.length != 1) {
                    snr.sendMessage(ChatColor.GOLD + "Usage: /ban <player> [reason]");
                    return true;
                }
                
                Player b = plugin.getServer().getPlayer(args[0]);
                
                plugin.bannedPlayers.add(args[0]);
                
                if (b != null) {
                    b.kickPlayer(ChatColor.RED + "You have been banned by " + ChatColor.GOLD + snr);
                    return true;
                }
                String message = "";
                
                if (args.length > 1) {
                    for (int i = 1; i < args.length; ++i) {
                        message += args[i] + ChatColor.RED + " " + " by:" + snr; 
                    }
                } else {
                    message = "You have been kicked from this server.";
                    return true;
                }
                
                snr.sendMessage(ChatColor.GREEN + args[0] + " Has been banned from the server");
                plugin.log.info(ChatColor.GREEN + args[0] + " Has been banned by: " + snr);
                plugin.bannedPlayers.save();
                return true;
        }
            }
            return true;
        }
    }
    
    Oh and ofcourse the plugin.yml:
    Code:
    name: AntiBanBypass
    main: com.cab.abb.AntiBB
    version: 0.0.3a
    commands:
      ban:
        description: Bans a player
        usage: /ban <player_name> [reason]
        
    permissions:
      AntiBB.set.ban:
        description: Permission to access the command /ban
        default: op
    
    ----
    Note: Like I said, this is my first time with plugin development and I tried to do everything alone.
    for the permissions, I took tutorials.
    But none of these tutorials worked, well that I have seen(even from the bukkit wiki).

    I quess my java is trolling...

    Redone every tutorial for the permissions and it still doesn't work.
    This leaves me clueless. :s

    There is also no Stacktrace aswell for any errors.

    Then bukkit overrides my command and I rewrite the code and then the permissions work, but it returns everytime that no one has the permission.
    Then there is a little change that it will ignore the permissions totally.

    Sooo.., any other suggestions or not?

    If not then I think the topic can be closed.

    I don't know if it is a bukkit 1.7.4 dev build(lastest) bug or a JDK 8 bug.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page