Example plugin

Discussion in 'Archived: Plugin Requests' started by newboyhun, Mar 21, 2012.

  1. Offline

    newboyhun

    Hi all!
    Okay,i'm noob =D
    I need an example plugin with source about the new event system.
    Just a simple plugin what gives 1000 experience to the player onlogin.
    Thanks !!!
     
  2. Offline

    CRAZYxMUNK3Y

    This is roughly how it would be done, haven't tested it though, so it may not work;

    Main:
    Code:java
    1.  
    2. package me.crazy.loginxp;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.plugin.PluginManager;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public class LoginXP extends JavaPlugin{
    9.  
    10. LoginXPListener listener;
    11.  
    12. public void onEnable(){
    13. listener = new LoginXPListener(this);
    14. PluginManager pm = Bukkit.getServer().getPluginManager();
    15. pm.registerEvents(this.listener, this);
    16.  
    17. }
    18.  
    19. }
    20.  


    Listener:
    Code:java
    1.  
    2. package me.crazy.loginxp;
    3.  
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerJoinEvent;
    8.  
    9. public class LoginXPListener implements Listener {
    10.  
    11. public static LoginXP plugin;
    12.  
    13. public LoginXPListener(LoginXP instance) {
    14. instance = plugin;
    15. }
    16.  
    17. @EventHandler
    18. public void onPlayerJoin(PlayerJoinEvent event){
    19. Player player = event.getPlayer();
    20. player.setExp(player.getExp() + 1000);
    21. player.sendMessage("1000 XP has been added"); // Optional
    22. }
    23. }
    24.  
     
  3. Offline

    Zaros

    The bukkit wiki has a beautiful section about the new event system here.
     
  4. Offline

    newboyhun

    Yes thanks,i checked and i did a plugin,but it wasn't works,that's why i wanted an example
    Thanks a lot!
     
  5. Offline

    CRAZYxMUNK3Y

  6. Offline

    iMint

    I prefer doing it all on one line :p

    Code:java
    1.  
    2. @Override
    3. public void onEnable(){
    4. getServer().getPluginManager().registerEvents(new myListener(this), this);
    5. }
    6.  

    Of course when im using multiple Listeners its much cleaner to use variables :
     
  7. Offline

    CRAZYxMUNK3Y

    Everyone has their own personal way of doing it.
     
  8. Offline

    iMint

    Yep, I was just showing him that it is possible to do it that way as well.
     

Share This Page