[SOLVED] Need Plugin Help! A.S.A.P!

Discussion in 'Plugin Development' started by MrDent009, Jun 25, 2012.

  1. Offline

    MrDent009

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    This has been solved, thanks to the help of r0306 and SnRolls. Thank you so much!

    This post has been edited 6 times. It was last edited by MrDent009 Jun 27, 2012.
  2. Offline

    ferrybig

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    is it because you forgot to check the bukkitemptyevent? give us more information what part is not working
  3. Offline

    Digi

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I think you mean .java, not .jar.

    Anyway, you used @EventHandler for functions that have nothing to do with events (onEnable, onDisable... ) and you didn't use it on actual events.
    Then, I don't get the reason for those events in the main class, you only check if it's cancelled and just end there... ?!

    This post has been edited 1 time. It was last edited by Digi Jun 25, 2012.
  4. Offline

    MrDent009

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I fixed up my coding a bit. And updated the problem to were you will know! Please help me.. :)
  5. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @MrDent009
    That's because you never checked if the placed block was in the black list and just cancelled the event straight out.
    Code:
    @EventHandler(priority = EventPriority.NORMAL)
        public void onBlockPlace(BlockPlaceEvent event) {
            if (!Arrays.asList(placedBlackList).contains(event.getBlock().getType())) return;
            Player player = event.getPlayer();
            player.sendMessage(ChatColor.DARK_RED + " No! That's a BadBlock!");
            event.setCancelled(true);
       
        }

    This post has been edited 1 time. It was last edited by r0306 Jun 26, 2012.
  6. Offline

    MrDent009

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @r0306
    Is this correct?

    MyBlockListener.java


    Code:
    package me.Dent009.BadBlock;
     
    import java.util.Arrays;
    import net.minecraft.server.Material;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPlaceEvent;
     
     
     
    public class MyBlockListener implements Listener
    {
        public static MyBlockListener plugin;
        public static Material[] placedBlacklist = {Material.TNT, Material.LAVA};
        public static Material[] destroyedBlacklist = {Material.TNT, Material.LAVA};
     
       
        public MyBlockListener(MyBlockListener instance)
        {
            plugin = instance;
        }
        @EventHandler(priority = EventPriority.NORMAL)
        public void onBlockPlace(BlockPlaceEvent event) {
            if (!Arrays.asList(placedBlacklist).contains(event.getBlock().getType())) return;
            Player player = event.getPlayer();
            player.sendMessage(ChatColor.DARK_RED + " No! That's a BadBlock!");
            event.setCancelled(true);
              }
     
     
        }
     
      


    And. How would I make my permission work?
    I'm pretty new with Java. And bukkit.
    Java is good for the soul :D

    This post has been edited 2 times. It was last edited by MrDent009 Jun 26, 2012.
  7. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @MrDent009
    I would just add this permissions check right after the player variable declaration.
    Code:
    if (player.hasPermission("bb.place")) return;
    Or, you could combine it:
    Code:
    if (!Arrays.asList(placedBlacklist).contains(event.getBlock().getType()) || player.hasPermission("bb.place")) return;

    This post has been edited 1 time. It was last edited by r0306 Jun 26, 2012.
  8. Offline

    CorrieKay

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    in your main class, as @Digi said, there is an event that just sets it to cancelled, no matter what. Even if you had set up and registered the events from the listener class (which you didnt, and they therefore do not even execute), the main class's event, and the second class's event methods would both run. Lets say they place a valid block. The second classes event wouldnt change the cancellation, but the main class's would. Remove the event cancellation (preferrably the entire method...) and lets go from there.
  9. Offline

    MrDent009

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    But shouldn't it just block the blocks on the blackList?

    I figured it would....but now I'm confused :(
  10. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Yes it should. That's why you return if the block's not in the blacklist.
  11. Offline

    CorrieKay

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Okay, you gotta think logically how your plugin works.

    In typical programming, when you create an application, everything derives from public static main(String[] args)

    Well in bukkit programming, it starts in onEnable()* Everything you do must start/be initialized from on enable.

    Code:
        public void onEnable()
        {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this, this);
            PluginDescriptionFile pdfFile = this.getDescription();
            this.log.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is now enabled.");
           
        }
    
    Look at your onEnable method. Your second class file is nowhere to be found. All you are doing is registering your main class (not your secondary class) as a listener.

    Well, whats going on there? This:

    Code:
        @EventHandler(priority = EventPriority.NORMAL)
        public void onBlockPlace(BlockPlaceEvent event) {
            Player player = event.getPlayer();
            player.sendMessage(ChatColor.GREEN + " [BadBlock] Must be member! ");
            event.setCancelled(true);
        }
    
    This just flat out cancels all block places.

    You Remove this method, stop making your main class implement Listener, dont register it as a listener, create your secondary class file, and then register it as a listener.

    *Technically not ooooooooooone hundred percent true... If you do some fancy programming you can program outside of onEnable... but it'd be fairly tricky and either niche, or pointless.
  12. Offline

    MrDent009

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    So should it be...
    Code:
    @EventHandler(priority = EventPriority.NORMAL)
        public void onBlockPlace(BlockPlaceEvent event) {
            if (!Arrays.asList(placedBlacklist).contains(event.getBlock().getType()) || player.hasPermission("bb.place")) return;
            Player player = event.getPlayer();
            player.sendMessage(ChatColor.DARK_RED + " No! That's a BadBlock!");
            event.setCancelled(true);
        return false; 
    I'm so sorry if I am bothering you. But I want to see my plugin work [first bukkit plugin]
  13. Offline

    MrDent009

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I FEEL LIKE A NOOB :eek:
  14. Offline

    CorrieKay

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    You are a noob, but dont worry, we all were at one point :p

    Woah, that return looks weird to me. But... technically should work.

    However, they will still be able to place lava, because lava placing doesnt throw a block place event.
  15. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @MrDent009
    Why return false? The method has return type void so that means the return shouldn't return anything. Remove the false after return and also place the Player player declaration in front of the if statement.
  16. Offline

    MrDent009

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @r0306
    So, this is correct? Because it still isn't working correctly. Now I have an error in my log [at startup]

    Code:
        @EventHandler(priority = EventPriority.NORMAL)
        public void onBlockPlace(BlockPlaceEvent event) {
            Player player = event.getPlayer();
            if (!Arrays.asList(placedBlacklist).contains(event.getBlock().getType()) || player.hasPermission("bb.place")) return;
            player.sendMessage(ChatColor.DARK_RED + " No! That's a BadBlock!");
            event.setCancelled(true);
  17. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    What's the error? Did you register everything correctly and implement listener?
  18. Offline

    MrDent009

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Code:
    02:52:59 [SEVERE] Could not load 'plugins\BadBlock.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
            at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPlug
    inLoader.java:194)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:132)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:213)
            at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:189)
            at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigur
    ationManager.java:53)
            at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:166)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:432)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.io.FileNotFoundException: Jar does not contain plugin.yml
            ... 8 more
    This is the error in the log [startup] :p
  19. Offline

    CorrieKay

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    ...

    Its an issue with your plugin.yml file.

    Post it.
  20. Offline

    MrDent009

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Here it is ;)
    Code:
    author: Dent009
    database: false
    description: >
                Stop users from placing lava or tnt!
    main: me.Dent009.BadBlock.BadBlock
    name: BadBlock
    startup: postworld
    version: '1.0'
    commands:

    This post has been edited 3 times. It was last edited by MrDent009 Jun 26, 2012.
  21. Offline

    MrDent009

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  22. Offline

    JxAxVxAx

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Notice You Have placed 2 times of name and version , edit it

    Hope it helps :)
  23. Offline

    MrDent009

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @JxAxVxAx
    Okay. I fixed the errors, but my plugin isn't working properly.

    PROBLEM = Disables users to place ANY blocks!

    This post has been edited 1 time. It was last edited by MrDent009 Jun 26, 2012.
  24. Offline

    CorrieKay

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    read
  25. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Yeah. You need to register the listener.
  26. Offline

    MrDent009

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @r0306
    @CorrieKay

    I updated it to how the project is currently. Check it out and tell me what is wrong with it.
  27. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Your listener class is not in your main class so don't register the main class in the plugin manager. Register your listener class instead.

    Code:
    pm.registerEvents(new MyBlockListener(this), this);
  28. Offline

    MrDent009

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    BadBlock.java



    Code:
    package me.Dent009.BadBlock;
     
     
    import java.util.logging.Logger;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.permissions.Permission;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.event.Listener;
     
    public class BadBlock extends JavaPlugin implements Listener {
        private static final Logger log = Logger.getLogger("Minecraft");
        public Permission openPermission = new Permission("bb.place");
     
        @SuppressWarnings("static-access")
        @Override
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this, this);
            pm.registerEvents(new MyBlockListener(this), this);
            PluginDescriptionFile pdfFile = this.getDescription();
            this.log.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is now enabled.");
       
        }
     
        @SuppressWarnings("static-access")
        @Override
        public void onDisable()
        {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.log.info(pdfFile.getName() + " version " + pdfFile.getVersion() + " is now disabled.");
        }
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            return false;
        }
     
        }
    
    Is this correct....I feel really stupid :(
  29. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  30. Offline

    MrDent009

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @r0306
    Another error on boot-up. Isn't that wonderful?

    Code:
    04:37:59 [SEVERE] Error occurred while enabling BadBlock v1.0 (Is it up to date?
    )
    java.lang.Error: Unresolved compilation problems:
            The method registerEvents(Listener, Plugin) in the type PluginManager is
    not applicable for the arguments (MyBlockListener, BadBlock)
            The constructor MyBlockListener(BadBlock) is undefined
     
            at me.Dent009.BadBlock.BadBlock.onEnable(BadBlock.java:23)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:215)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:337)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:381)
            at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:256)
            at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:238
    )
            at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:381)
            at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:368)
            at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:197)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:432)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)

    This post has been edited 1 time. It was last edited by MrDent009 Jun 26, 2012.

Share This Page