Simple plugin

Discussion in 'Plugin Development' started by Bush, Sep 20, 2011.

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

    Bush

    can someone pls give me a simple plugin to make...
    if i can make it then i know i can continue on my quest lol
     
  2. Offline

    dbizzzle

    Make a god plugin
     
  3. Offline

    Bush

    mmm looks like i should rather leave this to u guys
     
  4. Offline

    Zaros

    Try making a plugin (for yourself) that returns a message when a command is used. Here, I'll start you off:

    Show Spoiler

    Code:
    package me.Bush.FIRSTPlugin;
    // Importing stuff
        import java.util.logging.Logger;
        import org.bukkit.command.Command;
        import org.bukkit.command.CommandSender;
        import org.bukkit.entity.Player;
        import org.bukkit.plugin.java.JavaPlugin;
    
    //main method
    public class FIRSTPlugin extends JavaPlugin {
    //log messages to console
        Logger log = Logger.getLogger("Minecraft");
    //version number
        double version = 0.1;
    
    //when plugin is enabled
        public void onEnable(){
            //print to system "FIRSTPlugin" + double version + " - Enabled"
            System.out.println("FIRSTPlugin " + version + " - Enabled");
    
        }
    //when plugin is disabled
        public void onDisable(){
            //Same as enabled
            System.out.println("FIRSTPlugin " + version + " - Disabled");
        }
    
    //grab player commands
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            //if message sender is a player
            if(sender instanceof Player){
                //if command = "hai"
                if(cmd.getName().equalsIgnoreCase("hai")){
                    Player player = (Player) sender;
                    //send player message "ohhai"
                    player.sendMessage("ohhai");
                    return true;
    
                }
            }
            return false;
        }
    }
     
    r3Fuze likes this.
  5. Offline

    Bush

    @Zaros thnx i'm busy with one like that, so i'll use your code as refrence when i get stuck
     
  6. Offline

    Zaros

    Alright, feel free to ask me questions. Im pretty new to this too.

    My source is your source
     
  7. Offline

    Bush

    thnx my plugin works, yay
     
  8. Offline

    dbizzzle

    Try making a godmode plugin like I said above,
    Hint: (open)
    1. Add player to an ArrayList onCommand
    2. Create an EntityListener
    3. Call the event EntityDamage
    4. Check if they are in the ArrayList
    5. If they are, event.setCancelled(true);


    Example Main Class
    Code:java
    1.  
    2. package me.Bush.GodMode;
    3.  
    4. import org.bukkit.plugin.JavaPlugin;
    5. import java.util.logging.Logger;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.command.Command;
    8. import ArrayList (I forget the import);
    9. import Priority (Don't remember import);
    10.  
    11. public class GodMode extends JavaPlugin {
    12. public Logger log = Logger.getLogger("Minecraft");
    13.  
    14. public ArrayList godmode = new ArrayList(this);
    15.  
    16. public final GodModeEntityListener entityListener = new GodModeEntityListener(this);
    17.  
    18. public void onEnable() {
    19. log.info("[GodMode] Plugin Enabled.");
    20. PluginManager pm = pluginManager.getPluginManager();
    21. pm.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, event.Priority.Low, this);
    22. }
    23.  
    24. public void onDisable() {
    25. log.info("[GodMode] Plugin Disabled.");
    26. }
    27.  
    28. public boolean onCommand(CommandSender sender, Command command,
    29. String label, String[] args) {
    30. if (command.getName().equalsIgnoreCase("god") {
    31. Player s = (Player) sender;
    32. if (!godmode.contains(s)) {
    33. godmode.add(s);
    34. s.sendMessage("You are now god.");
    35. } else {
    36. s.sendMessage("You are already god.");
    37. }
    38. }
    39.  
    40. if (command.getName().equalsIgnoreCase("ungod") {
    41. Player s = (Player) sender;
    42. if (godmode.contains(s)) {
    43. godmode.remove(s);
    44. s.sendMessage("You are no longer god.");
    45. } else {
    46. s.sendMessage("You are not god.");
    47. }
    48. }
    49. }
    50. }
    51.  

    I may of made a few small errors (spelling, capitals, and such) but eclipse will catch them


    If you need more help just add me on skype, dbizzzle
     
  9. Offline

    Bush

    i can't get this to work, soz
    well atleast i know how to make commands display messages now haha
     
  10. Offline

    dbizzzle

    Just add me on skype and I can give you more help.
     
  11. Offline

    emericask8ur

    Bro its so easy its not even funny, when people look at code they freak out but if you get to know it
     
    r3Fuze likes this.
  12. Offline

    Celeixen

    It helps if you have done previous coding before but if your starting of you may as well start with java.
     
  13. Offline

    Zaros

    Had not coded since High school(VB), read this and was coding basic java in under 2 hours ;)
     
  14. Offline

    Celeixen

    Well its always possible but i am pretty good with C# which is basically the same as java, less then 1hr after installing eclipse i had made my first plugin (Bucket furnace) :p
     
  15. Offline

    BenyTheBuff

Thread Status:
Not open for further replies.

Share This Page