Solved HELP! Plugin.YML doesn't like me...

Discussion in 'Plugin Development' started by Qaisar101, Aug 18, 2014.

?

What is better?

  1. Christmas...

    100.0%
  2. or Halloween!

    0 vote(s)
    0.0%
Thread Status:
Not open for further replies.
  1. Offline

    Qaisar101

    I'm making a Bukkit plugin. It is called Vitals. I have two features so far, a firework on join and /hub, a command to teleport to spawn. /Hub has a class called 'main' and the firework has a class called 'firework'. In the plugin.yml, I put 'main: me.BukkitQaisar.Vitals.main' but the firework doesn't work. When I put 'main: me.BukkitQaisar.Vitals.firework', /hub doesn't work! Please help! Here is what is in my plugin.yml file, and my two classes...

    Code:
    name: Vitals
    author: BukkitQaisar
    version: 1.02
    description: Adds a lot of VITAL commands. /HUB, Firework on join!
    prefix: Vitals
    main: me.BukkitQaisar.Vitals.
    commands:
      hub:
        description: Teleports player to hub/spawn!
    Code:java
    1. package me.BukkitQaisar.Vitals;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class main extends JavaPlugin{
    11.  
    12. public void onEnable() {
    13. getLogger().info("Successfully enabled plugin! :)");
    14. }
    15.  
    16. public void onDisable() {
    17. getLogger().info("Successfully disabled plugin! :(");
    18. }
    19.  
    20. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    21. if(sender instanceof Player) {
    22. Player player = (Player) sender;
    23. if(cmd.getName().equalsIgnoreCase("hub")) {
    24. String hub = "spawn " + player.getName();
    25. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), hub);
    26. player.sendMessage(ChatColor.AQUA + "Teleporting to " + ChatColor.DARK_AQUA + "Hub" + ChatColor.AQUA + "!");
    27.  
    28. }
    29. }
    30. return false;
    31.  
    32. }
    33. }
    34.  


    Code:java
    1. package me.BukkitQaisar.Vitals;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Color;
    5. import org.bukkit.FireworkEffect;
    6. import org.bukkit.FireworkEffect.Type;
    7. import org.bukkit.entity.Firework;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerJoinEvent;
    11. import org.bukkit.inventory.meta.FireworkMeta;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class firework extends JavaPlugin implements Listener {
    15.  
    16. public void onEnable(){
    17. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    18. }
    19.  
    20. @EventHandler
    21. public void onPlayerJoin (final PlayerJoinEvent pje) {
    22. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    23. public void run(){
    24.  
    25. Firework f = (Firework) pje.getPlayer().getWorld().spawn(pje.getPlayer().getLocation(), Firework.class);
    26.  
    27. FireworkMeta fm = f.getFireworkMeta();
    28. fm.addEffect(FireworkEffect.builder()
    29. .flicker(true)
    30. .trail(true)
    31. .with(Type.BALL)
    32. .with(Type.BALL_LARGE)
    33. .withColor(Color.AQUA)
    34. .withColor(Color.BLUE)
    35. .withColor(Color.PURPLE)
    36. .withFade(Color.TEAL)
    37. .build());
    38. fm.setPower(2);
    39. f.setFireworkMeta(fm);
    40.  
    41. }
    42. }, 30);
    43. }
    44.  
    45. }
    46.  


    Thanks for the help!
     
  2. Offline

    Forseth11

    Change the main in your plugin.yml to this:
    Code:
    main: me.BukkitQaisar.Vitals.main
     
  3. Offline

    Qaisar101

    Forseth11
    Now, /hub is working, but the firework is not.
    If the main was 'main: me.BukkitQaisar.Vitals.firework', the firework will work and /hub will be an unknown command! Please help!
     
  4. Offline

    Gater12

    Qaisar101
    Only your main class should be the subclass of JavaPlugin.

    Since firework is a listener you want to register it in the main class.
     
  5. Offline

    Qaisar101

    If the main was 'main: me.BukkitQaisar.Vitals.firework', the firework will work and /hub will be an unknown command! Please help!
     
  6. Offline

    Gater12

  7. Offline

    Forseth11

    Just like what Gater12 said you can not have two subclasses of JavaPlugin. Register the event for the firework class in the main class.
     
  8. Offline

    Qaisar101

    Thank you in advance! :) This was very helpful! Also, I left a like.
     
  9. Your Main Class:
    Code:java
    1. package me.BukkitQaisar.Vitals;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class main extends JavaPlugin{
    11.  
    12. public void onEnable() {
    13. getLogger().info("Successfully enabled plugin! :)");
    14. Bukkit.getPluginManager().registerEvents(new fireworkListener(this), this);
    15. }
    16.  
    17. public void onDisable() {
    18. getLogger().info("Successfully disabled plugin! :(");
    19. }
    20.  
    21. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    22. if(sender instanceof Player) {
    23. Player player = (Player) sender;
    24. if(cmd.getName().equalsIgnoreCase("hub")) {
    25. String hub = "spawn " + player.getName();
    26. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), hub);
    27. player.sendMessage(ChatColor.AQUA + "Teleporting to " + ChatColor.DARK_AQUA + "Hub" + ChatColor.AQUA + "!");
    28.  
    29. }
    30. }
    31. return false;
    32.  
    33. }
    34. }


    Your Listener Class:
    Code:java
    1. package me.BukkitQaisar.Vitals;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Color;
    5. import org.bukkit.FireworkEffect;
    6. import org.bukkit.FireworkEffect.Type;
    7. import org.bukkit.entity.Firework;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerJoinEvent;
    11. import org.bukkit.inventory.meta.FireworkMeta;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class fireworkListener
    15. {
    16. public firework plugin;
    17.  
    18. public fireworkListener(firework plugin)
    19. {
    20. this.plugin = plugin;
    21. }
    22.  
    23. @EventHandler
    24. public void onPlayerJoin (final PlayerJoinEvent pje) {
    25. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    26. public void run(){
    27.  
    28. Firework f = (Firework) pje.getPlayer().getWorld().spawn(pje.getPlayer().getLocation(), Firework.class);
    29.  
    30. FireworkMeta fm = f.getFireworkMeta();
    31. fm.addEffect(FireworkEffect.builder().flicker(true).trail(true).with(Type.BALL).with(Type.BALL_LARGE).withColor(Color.AQUA).withColor(Color.BLUE).withColor(Color.PURPLE).withFade(Color.TEAL).build());
    32. fm.setPower(2);
    33. f.setFireworkMeta(fm);
    34.  
    35. }
    36. }, 30);
    37. }


    + you sould learn a bit more Java!!
     
  10. Offline

    Qaisar101

    Actually, the firework still doesn't work! I did everything the wiki said! :(

    First off, I'm only 11. Second, the classes are 'main' and 'firework'. Third, scheduleSyncDelayedTask is underlined red in Eclipse! I appreciate it, though! :)

    greaperc4
    The firework isn't working? May you please send me the code for plugin.yml, main.class, and firework.class? PLEASE! No one is replying anymore.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  11. Offline

    Lactem

    fireworkListener needs to be an event class. To do that, make it implements Listener:
    Code:
    public class fireworkListener implements Listener
    {
    
    Also change
    Code:
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    to
    Code:
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
     
  12. Offline

    Qaisar101

    Lactem
    THANK YOU VERY MUCH! :)
     
  13. Offline

    ProMCKingz

    Qaisar101
    Please change the prefix of this thread to [Solved]
     
  14. oops.... forgot to do the: implements Listener... I had it beforesorry for that
     
  15. Offline

    Qaisar101

    How to do that? LOL! But in all seriousness, I don't know how to.
     
  16. Offline

    ProMCKingz

    Qaisar101 the bottom right of your (pointless) poll, has Thread Tools, click on that and then go to your title and add a prefix [Solved]
     
Thread Status:
Not open for further replies.

Share This Page