Solved I need help on a plugin I am making...

Discussion in 'Plugin Development' started by NDUGAR, Mar 30, 2014.

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

    NDUGAR

    Hello, I'm new to making plugins, but they seem awfully fun. I'm having problems with both my plugins as in they are not loading on my server... It is a plugin to create a firework when an OP logs in so I am having troubles with creating permissions. Also the entire plugin is broken as it does not even load in my private server...

    Here is my code for the main plugin...

    Code:java
    1. package me.Schnel.EnterWithABang;
    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.Listener;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.player.PlayerJoinEvent;
    12. import org.bukkit.inventory.meta.FireworkMeta;
    13.  
    14. public class Main extends JavaPlugin implements Listener {
    15.  
    16. public void onEnable(){
    17. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    18. getLogger().info("Plugin Enabled");
    19. }
    20.  
    21. public void onDisable(){
    22. getLogger().info("Plugin Disabled");
    23. }
    24.  
    25. @EventHandler
    26. public void onPlayerJoin (final PlayerJoinEvent pje) {
    27. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    28. public void run(){
    29.  
    30. Firework f = (Firework) pje.getPlayer().getWorld().spawn(pje.getPlayer().getLocation(), Firework.class);
    31.  
    32. FireworkMeta fm = f.getFireworkMeta();
    33. fm.addEffect(FireworkEffect.builder()
    34. .flicker(true)
    35. .trail(true)
    36. .with(Type.BALL)
    37. .with(Type.BALL_LARGE)
    38. .with(Type.STAR)
    39. .with(Type.BURST)
    40. .withColor(Color.OLIVE)
    41. .withColor(Color.FUCHSIA)
    42. .withFade(Color.LIME)
    43. .withFade(Color.ORANGE)
    44. .build());
    45. fm.setPower(1);
    46. f.setFireworkMeta(fm);
    47. }
    48. }, 40);
    49.  
    50. }
    51.  
    52. }
    53.  




    And here is my plugin.yml:


    Code:
    name: EnterWithABang
     
    author: Schnel Studios
     
    version: 1.0
     
    description: EnterWithABang allows players to have a firework launched at their feet at login
     
    main: me.Schnel.EnterWithABang.Main
     
     
     
    permissions:
     
      bang.*:
     
        description: Allows players to EnterWithABang
     
        default: op
    Please help me as this is my second plugin, and nor does my first load up... Also here is my download for the entire plugin, it's zipped :D
     

    Attached Files:

  2. Offline

    GotRice

    NDUGAR You could use player.isOp() to see if the player is an op. Is there any errors in the console?
     
  3. Offline

    The Fancy Whale

    Any errors?
     
  4. Offline

    JBoss925

    You don't need the bukkit runnable. And use .isOp() to see if they're op or use .hasPermssion("blah.blah")
     
  5. Offline

    NDUGAR

    No GotRice, it just doesn't load in the console.. Also, could I put the permissions in the plugin.yml so that you can just add the permission nodes, also it doesn't appear in the console...
     
  6. Offline

    Minnymin3

    Make sure that 1. the plugin is in the plugins folder and 2. plugin.yml exists in the jar
     
  7. Offline

    NDUGAR

  8. Offline

    GotRice

    Did you extend JavaPlugin?
     
  9. Offline

    F9Alejandro

    Don't know if this matters or not but aren't the @Override needed above the onEnable and onDisable
     
  10. Offline

    tylersyme

    As a matter of fact, I think he does. It appears that fireworks for some reason have a difficult time spawning in a PlayerJoinEvent.

    NDUGAR
    One thing I don't see is '@Override' above 'public void run'
    I'm not sure if it's required, but I would suggest putting that in there :)
     
  11. Offline

    JBoss925

    No he doesn't. Look at this code I made:
    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent event) {
    3. if(i == 0){
    4. Player p = (Player) event.getEntity();
    5. Firework fw = (Firework) p.getWorld().spawnEntity(p.getLocation(), EntityType.FIREWORK);
    6. FireworkMeta fwm = fw.getFireworkMeta();
    7. Color c = Color.RED;
    8. FireworkEffect effect = FireworkEffect.builder().withColor(c).build();
    9. fwm.addEffect(effect);
    10. fw.setFireworkMeta(fwm);
    11. }
    12. }


    "i" is a variable dependent upon the config if you wanted to know.

    I don't put them there and all my plugins work fine.

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

    Opacification

    Did you even check the code...

    NDUGAR

    To add a permission to a player or if they're op you can do:

    Code:java
    1. if(player.hasPermission("blah.bah") || (player.isOp() {
    2. //allow player to have the feature.


    Also, I am not exactly sure what you're doing wrong. If the plugin isn't loading your plugin.yml file may be incorrect or put in the wrong place.

    If I may ask, what IDE are you using: Example: (Netbeans)

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

    NDUGAR

    @Opacification I'm using Eclipse... Not sure if that makes any difference. Anyway thanks for all of you guys' support, I really need it.

    So, any help; I'm desperate to get this working :p

    Okay, guys in the console it spat out this: org.bukkit.plugin.InvalidPluginException... Any help?

    I managed to get it to boot up but then I got this error, someone help plz?

    Code:
     Could not load 'plugins/EnterWithABang.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
        at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:160) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:133) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.bukkit.craftbukkit.v1_7_R2.CraftServer.loadPlugins(CraftServer.java:350) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.bukkit.craftbukkit.v1_7_R2.CraftServer.<init>(CraftServer.java:312) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at net.minecraft.server.v1_7_R2.PlayerList.<init>(PlayerList.java:63) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at net.minecraft.server.v1_7_R2.DedicatedPlayerList.<init>(SourceFile:14) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at net.minecraft.server.v1_7_R2.DedicatedServer.init(DedicatedServer.java:126) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at net.minecraft.server.v1_7_R2.MinecraftServer.run(MinecraftServer.java:426) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at net.minecraft.server.v1_7_R2.ThreadServerApplication.run(SourceFile:618) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
    Caused by: org.yaml.snakeyaml.scanner.ScannerException: null; mapping values are not allowed here
        at org.yaml.snakeyaml.scanner.ScannerImpl.fetchValue(ScannerImpl.java:733) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:305) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:179) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:563) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:230) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:123) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:106) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.yaml.snakeyaml.Yaml.load(Yaml.java:411) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:189) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:155) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
        ... 8 more
    
    Fixed it, but how would I add permissions to this plugin so only a person or a person in a group has a permission node to let them have the firework?

    Main.java:
    Code:java
    1. package me.Schnel.EnterWithABang;
    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.Listener;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.player.PlayerJoinEvent;
    12. import org.bukkit.inventory.meta.FireworkMeta;
    13.  
    14. public class Main extends JavaPlugin implements Listener {
    15.  
    16. public void onEnable(){
    17. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    18. getLogger().info("Plugin Enabled");
    19. }
    20.  
    21. public void onDisable(){
    22. getLogger().info("Plugin Disabled");
    23. }
    24.  
    25. @EventHandler
    26. public void onPlayerJoin (final PlayerJoinEvent pje) {
    27. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    28. public void run(){
    29.  
    30. Firework f = (Firework) pje.getPlayer().getWorld().spawn(pje.getPlayer().getLocation(), Firework.class);
    31.  
    32. FireworkMeta fm = f.getFireworkMeta();
    33. fm.addEffect(FireworkEffect.builder()
    34. .flicker(true)
    35. .trail(true)
    36. .with(Type.BALL)
    37. .with(Type.BALL_LARGE)
    38. .with(Type.STAR)
    39. .with(Type.BURST)
    40. .withColor(Color.OLIVE)
    41. .withColor(Color.FUCHSIA)
    42. .withFade(Color.LIME)
    43. .withFade(Color.ORANGE)
    44. .build());
    45. fm.setPower(1);
    46. f.setFireworkMeta(fm);
    47. }
    48. }, 40);
    49.  
    50. }
    51.  
    52. }
    53.  


    plugin.yml:

    Code:
    name: EnterWithABang
    author: Schnel Studios
    version: 1.0
    description: EnterWithABang allows players to have a firework launched at their feet at login
    main: me.Schnel.EnterWithABang.Main
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  14. Offline

    F9Alejandro


    look at previous posts to find what you are looking for... also paying attention before post is also useful
     
  15. Offline

    NDUGAR

    F9Alejandro, I only want a permission node to add to groups, that's why I didn't use the OP thing...
     
  16. Offline

    F9Alejandro

    then just go with if(player.hasPermission("{pluginname}.blah.action"){ //then allow player to do }
     
  17. Offline

    MooshViolet


    Code:java
    1. if(player.hasPermission("firework.permission")){
    2. //Then do some stuff here that you want them to be able to do
    3. //you can do the permission node to whatever you want, I just did firework.permisison.
     
    NDUGAR likes this.
  18. Offline

    NDUGAR

    MooshViolet, it cannot find player... Nor can I import it, it says player cannot be resolved
     
  19. Offline

    MooshViolet

    NDUGAR use this in your event:
    Code:java
    1. Player player = pje.getPlayer();
     
  20. Offline

    NDUGAR

    Still broken :(

    @MooshViolet
    It just says player cannot be resolved

    Code:java
    1. package me.Schnel.EnterWithABang;
    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.entity.Player;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.player.PlayerJoinEvent;
    13. import org.bukkit.inventory.meta.FireworkMeta;
    14.  
    15. public class Main extends JavaPlugin implements Listener {
    16.  
    17. public void onEnable(){
    18. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    19. getLogger().info("Plugin Enabled");
    20. }
    21.  
    22. public void onDisable(){
    23. getLogger().info("Plugin Disabled");
    24. }
    25.  
    26. @EventHandler
    27. public void onPlayerJoin (final PlayerJoinEvent pje){
    28. Player player = pje.getPlayer();
    29. if(player.hasPermission("bang.permission")){
    30. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    31. public void run(){
    32.  
    33. Firework f = (Firework) pje.getPlayer().getWorld().spawn(pje.getPlayer().getLocation(), Firework.class);
    34.  
    35. FireworkMeta fm = f.getFireworkMeta();
    36. fm.addEffect(FireworkEffect.builder()
    37. .flicker(true)
    38. .trail(true)
    39. .with(Type.BALL)
    40. .with(Type.BALL_LARGE)
    41. .with(Type.STAR)
    42. .with(Type.BURST)
    43. .withColor(Color.OLIVE)
    44. .withColor(Color.FUCHSIA)
    45. .withFade(Color.LIME)
    46. .withFade(Color.ORANGE)
    47. .build());
    48. fm.setPower(1);
    49. f.setFireworkMeta(fm);
    50. }
    51. }, 10);
    52.  
    53. }
    54.  
    55. }
    56. }
     
  21. Offline

    -TheCreater-

    i had a similar problem. playerJoinEvent is called WHILE the player is joined a.k.a. the player is not in the server YET. use a scheduleSyncDelayedTask to wait about 5 ticks and then run your code.
    eg:
    Code:java
    1. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    2. public void run()
    3. {
    4. //your code here
    5. },5 );


    if that doesn't work use logging statements to debug your code.
    Code:java
    1. getLogger.info("Yak, Yak, Yak.....");


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page