[Tutorial] How to make a Simple Basic Bukkit Plugin

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

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

    emericask8ur

    Make a variable for Server
    Server server = sender.getServer();


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

    orano

    thanks, also my plugin has the same problem as before you helped me!
     
  3. Offline

    emericask8ur

    Just remember what I showed you, use the same method.
     
  4. Offline

    bierbuikje

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

    emericask8ur

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

    Jag.1000

    Im not getting the Events When you type Event.type.?
    Help?
     
  7. Offline

    Killifactor

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

    teetor

    Nice nice
     
  9. Offline

    zajacmp3

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

    emericask8ur

    This tut is very outdated. Bukkit has new events, new methods, etc. I will create a new video soon.
     
  11. Offline

    zajacmp3

    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 :)
     
  12. Offline

    ROBERTLEEOBRIEN

    yes that would be great
     
  13. Offline

    emericask8ur

    Guys new video above!
     
  14. Offline

    SumoBanana

    Where do I get that thing you call Eclipse?
     
  15. Offline

    emericask8ur

    Google it >.>
     
  16. Offline

    BenRush

    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 :(
     
Thread Status:
Not open for further replies.

Share This Page