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

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

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

    MrDent009

    This has been solved, thanks to the help of r0306 and SnRolls. Thank you so much!
     
  2. is it because you forgot to check the bukkitemptyevent? give us more information what part is not working
     
  3. 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... ?!
     
  4. Offline

    MrDent009

    I fixed up my coding a bit. And updated the problem to were you will know! Please help me.. :)
     
  5. Offline

    r0306

    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);
       
        }
     
  6. Offline

    MrDent009

    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
     
  7. Offline

    r0306

    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;
     
  8. Offline

    CorrieKay

    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

    But shouldn't it just block the blocks on the blackList?

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

    r0306

    Yes it should. That's why you return if the block's not in the blacklist.
     
  11. Offline

    CorrieKay

    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

    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]

    I FEEL LIKE A NOOB :eek:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  13. Offline

    CorrieKay

    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.
     
  14. Offline

    r0306

    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.
     
  15. Offline

    MrDent009

    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);
     
  16. Offline

    r0306

    What's the error? Did you register everything correctly and implement listener?
     
  17. Offline

    MrDent009

    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
     
  18. Offline

    CorrieKay

    ...

    Its an issue with your plugin.yml file.

    Post it.
     
  19. Offline

    MrDent009

    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:
    CorrieKay
    r0306

    Is there any problems that you see?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  20. Offline

    JxAxVxAx

    Notice You Have placed 2 times of name and version , edit it

    Hope it helps :)
     
  21. Offline

    MrDent009

    JxAxVxAx
    Okay. I fixed the errors, but my plugin isn't working properly.

    PROBLEM = Disables users to place ANY blocks!
     
  22. Offline

    CorrieKay

    read
     
  23. Offline

    r0306

    Yeah. You need to register the listener.
     
  24. Offline

    MrDent009

    r0306
    CorrieKay

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

    r0306

    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);
     
  26. Offline

    MrDent009

    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 :(
     
  27. Offline

    r0306

  28. Offline

    MrDent009

    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)
     
  29. Offline

    r0306

    MrDent009
    Make these changes to your listener.

    Code:
    public class MyBlockListener implements Listener
    {
        public static BadBlock plugin;
        public static Material[] placedBlacklist = {Material.TNT, Material.LAVA};
        public static Material[] destroyedBlacklist = {Material.TNT, Material.LAVA};
         
         
        public MyBlockListener(BadBlock instance)
        {
            plugin = instance;
        }
     
        @EventHandler(priority = EventPriority.NORMAL)
        public void onBlockPlace(BlockPlaceEvent event) {
            Player player = event.getPlayer();
            player.sendMessage(ChatColor.GREEN + " [BadBlock] Must be member! ");
            event.setCancelled(true);
        }
     
        }
     
  30. Offline

    MrDent009

    r0306
    It is disabling users from placing any blocks now :(

    Better Idea!

    Message me the correct coding? So we don't have to do all of this work :oops:
     
Thread Status:
Not open for further replies.

Share This Page