[Tutorial] How to make a Simple Basic Bukkit Plugin

Discussion in 'Resources' started by emericask8ur, Oct 15, 2011.

  1. Offline

    orano

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

    orano

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    u want the network id and password?
  3. Offline

    emericask8ur

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Private Message me your info
  4. Offline

    orano

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I'm sorry for my extreme noobiness but how do I pm you on this site?
  5. Offline

    emericask8ur

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Click my name here and Click Start Conversation
  6. Offline

    orano

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    thanks for being so helpful emericask before, so can you help me again by saying what would you do if you wanted to say something to the whole server. A bit like [BROADCAST] and [SERVER] except custom text like [ORANOBROADCAST]? So you could have a custom tag that goes to everyone on the server, and then some text afterwards like, [ORANOBROADCAST] Everyone Get in side your homes!
    emericask8ur likes this.
  7. Offline

    orano

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    and of course this could be activated via a command?
  8. Offline

    emericask8ur

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Make a variable for Server
    Server server = sender.getServer();


    And then look in the API! It has broadcast
  9. Offline

    orano

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    thanks, also my plugin has the same problem as before you helped me!
  10. Offline

    emericask8ur

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Just remember what I showed you, use the same method.
  11. Offline

    bierbuikje

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I'm new to making plugins so to get at least something to work I copied your whole code from the tutorial, but I'm very confused because it doesn't work. Red and yellow underlines everywhere, what could the problem be? Thanks!


    [IMG]
    [IMG]
    [IMG]
    [IMG]

    This post has been edited 2 times. It was last edited by bierbuikje Feb 1, 2012.
  12. Offline

    emericask8ur

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Chat color needs to be imported and with capital C (ChatColor) and yellow is because the new Bukkit doesn't use the methods for old events anymore
  13. Offline

    Jag.1000

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Im not getting the Events When you type Event.type.?
    Help?
  14. Offline

    Killifactor

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Im having the same problems as bierbuikje i believe.

    Any help is appreciated as i'm doing this for a project in school.

    Here is my code

    Main.java

    Code:
    package me.MyPlugin.MyPlugin;
    
    import org.bukkit.event.Event;
    import org.bukkit.event.EventPriority;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.PluginManager;
    
    public class Main extends JavaPlugin{
        
        private final BL BlockListener = new BL();
        
        @Override
        public void onDisable()
        {
            System.out.println("My plugin is disabled.");
        }
        
        @Override
        public void onEnable()
        {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.BLOCK_BREAK, BlockListener, EventPriority.NORMAL, this);
            System.out.println("My plugin is enabled.");
        }
    
    
    }
    BL.java

    Code:
    package me.MyPlugin.MyPlugin;
    
    
    import org.bukkit.ChatColor;
    import org.bukkit.Server;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.BlockListener;
    import org.bukkit.event.block.BlockBreakEvent;
    
    public class BL extends BlockListener
    {
        public void onBlockBreak(BlockBreakEvent event)
        {
            Player p = event.getPlayer();
            Server s = p.getServer();
            String playername = p.getName();
            ChatColor blue = ChatColor.BLUE;
            s.broadcastMessage(blue + playername + "Has broke a block!");
        }
    }
    
    Also here is my plugin.yml

    Code:
    name: MyPlugin
    version: 0.1
    main: me.MyPlugin.MyPlugin.Main
    And these are the errors i'm receiving when trying to run the plugin.

    Code:
    182 recipes
    27 achievements
    23:35:50 [INFO] Starting minecraft server version 1.2.5
    23:35:50 [INFO] Loading properties
    23:35:50 [INFO] Starting Minecraft server on *:25565
    23:35:50 [INFO] This server is running CraftBukkit version git-Bukkit-1.2.5-R1.0
    -b2149jnks (MC: 1.2.5) (Implementing API version 1.2.5-R1.0)
    23:35:51 [SEVERE] Could not load 'plugins\MyPlugin.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.Error: Unresolved compilatio
    n problems:
            The import org.bukkit.event.block.BlockListener cannot be resolved
            BlockListener cannot be resolved to a type
     
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:148)
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:305)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:230)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:207)
            at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:183)
            at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigur
    ationManager.java:53)
            at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:156)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:422)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.Error: Unresolved compilation problems:
            The import org.bukkit.event.block.BlockListener cannot be resolved
            BlockListener cannot be resolved to a type
     
            at me.MyPlugin.MyPlugin.BL.<init>(BL.java:7)
            at me.MyPlugin.MyPlugin.Main.<init>(Main.java:10)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
     
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:144)
            ... 8 more
    23:35:51 [INFO] Preparing level "world"
    23:35:51 [INFO] Default game type: 0
    23:35:51 [INFO] Preparing start region for level 0 (Seed: 4044050814232608057)
    23:35:51 [INFO] Preparing start region for level 1 (Seed: 4044050814232608057)
    23:35:52 [INFO] Preparing spawn area: 65%
    23:35:53 [INFO] Preparing start region for level 2 (Seed: 4044050814232608057)
    23:35:53 [INFO] Preparing spawn area: 48%
    23:35:53 [INFO] Server permissions file permissions.yml is empty, ignoring it
    23:35:53 [INFO] Done (2.247s)! For help, type "help" or "?"
    >
    Ok so ive narrowed it down somewhat. Basically i think my problems are:
    The import org.bukkit.event.block.BlockListener cannot be resolved and BlockListener cannot be resolved to a type.

    This post has been edited 5 times. It was last edited by Killifactor May 9, 2012.
  15. Offline

    teetor

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Nice nice
  16. Offline

    zajacmp3

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

    I did watched whole your video. Thanks for making this tutorial.
    I wanted to make something simple just to get me started with writing plugins for minecraft on eclipse.
    And really everything is going just great only minecraft is not cooperating with me or other way around.

    I have this error on start from console.
    Code:
    182 recipes
    27 achievements
    20:02:12 [INFO] Starting minecraft server version 1.2.4
    20:02:12 [INFO] Loading properties
    20:02:12 [INFO] Starting Minecraft server on *:25565
    20:02:12 [INFO] This server is running CraftBukkit version git-Bukkit-1.2.4-R1.0
    -b2126jnks (MC: 1.2.4) (Implementing API version 1.2.4-R1.0)
    20:02:12 [SEVERE] Could not load 'plugins\Plugin.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.UnsupportedClassVersionError
    : zajacmp3/plugin/plugin/Main : Unsupported major.minor version 51.0
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:150)
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:305)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:230)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:207)
            at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:183)
            at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigur
    ationManager.java:53)
            at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:156)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:425)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:490)
    Caused by: java.lang.UnsupportedClassVersionError: zajacmp3/plugin/plugin/Main :
     Unsupported major.minor version 51.0
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClassCond(Unknown Source)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at java.security.SecureClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.access$000(Unknown Source)
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.
    java:41)
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.
    java:29)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:139)
            ... 8 more

    This is my project
    [IMG]
  17. Offline

    emericask8ur

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    This tut is very outdated. Bukkit has new events, new methods, etc. I will create a new video soon.
  18. Offline

    zajacmp3

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Would be great. I just need to figure out what craftbukkit expects from me. Java as I see it is very similar to C and C++ so I should not have problem with it :)
  19. Offline

    ROBERTLEEOBRIEN

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    yes that would be great
  20. Offline

    emericask8ur

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Guys new video above!
  21. Offline

    SumoBanana

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Where do I get that thing you call Eclipse?
  22. Offline

    emericask8ur

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Google it >.>
  23. Offline

    BenRush

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Thanks, it works! :)
    But i want to do it in other way.. I want this: When player breaks diamond/emerald/gold ore admins got a message : 'playername' breaked 'orename'. Maybe you can help me to do this? I tried to rename OnBlockPlace to OnBlockBreak but it doesn't work :(

    This post has been edited 3 times. It was last edited by BenRush Aug 8, 2012.

Share This Page