Solved Help: Need help with on join event

Discussion in 'Plugin Development' started by Smalltrout, Sep 16, 2014.

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

    Smalltrout

    Hello,

    I am new to coding and so it may be messy. I am currently working on this plugin that goes along with one of our servers "Infection" game types. I have got the config working i just need to make it so lightning strikes when the player joins. This is my current code:

    Code:java
    1. public class InfectionPL extends JavaPlugin implements Listener{
    2. public static InfectionPL plugin;
    3. public final Logger logger = Logger.getLogger("Minecraft");
    4.  
    5. @Override
    6. public void onDisable() {
    7. PluginDescriptionFile p = this.getDescription();
    8. this.logger.info(p.getName() + " V" + p.getVersion() + "Has Been Enabled");
    9. this.reloadConfig();
    10. this.saveConfig();
    11. getServer().getPluginManager().registerEvents(this, this);
    12.  
    13. }
    14.  
    15. @Override
    16. public void onEnable(){
    17. PluginDescriptionFile p = this.getDescription();
    18. this.logger.info(p.getName() + " V" + p.getVersion() + "Has Been Enabled");
    19. this.getConfig().options().copyDefaults(true);
    20. this.saveConfig();
    21. }
    22.  
    23. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    24. Player player = (Player) sender;
    25. if(commandLabel.equalsIgnoreCase("Infection")){
    26. player.sendMessage(getConfig().getString("Infection").replaceAll("&a", ChatColor.BLUE + ""));
    27. }
    28. return false;
    29.  
    30.  
    31. }
    32.  
    33. @EventHandler
    34. public void onPlayerJoin(PlayerJoinEvent event){
    35. Player player = event.getPlayer();
    36. player.getWorld().strikeLightning(player.getLocation());
    37. }
    38. }
    39.  


    Another thing that is not working is the color codes in my config. If you could help me with those two things that would be great.

    Thanks!

    - Smalltrout
     
  2. Offline

    Skionz

  3. Offline

    Smalltrout

    Thanks! How can i make support for colors in my config? The way i did it did not work. Skionz
     
  4. Offline

    Skionz

    Smalltrout Look at the javadocs. I posted the link in my last post.
     
  5. Offline

    Totom3

    Smalltrout Hey,

    You code tells me that you are learning from TheBCBroz's videos... Would just like to inform you that these 'tutorials' are some of the worst you can possibly find on the internet, so stay away from them, you won't learn anything from them. If you want to make Bukkit plugins, you'll have to properly learn Java first, and then jump into modding with Bukkit.

    A few tips :
    • Don't use Logger.getLogger("Minecraft"), use the one CraftBukkit gave you. To get it, simply do this.getLogger() in the Main class.
    • No need to log when your plugin is enabled/disabled since CraftBukkit does that for you.
    • getConfig().getString("Infection") could return null, and paste you a big stacktrace (error) in the log. Use the method like this : getConfig().getString("Infection", "")
     
    Skionz likes this.
Thread Status:
Not open for further replies.

Share This Page