Help me please!

Discussion in 'Plugin Development' started by Corndogoz, Apr 6, 2014.

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

    Corndogoz

    Im making my first plugin, but got this error: http://pastebin.com/8nKB6LaS so would anyone mind helping me? it would make me very happy :pif you do, so please do help. :)
     
  2. Offline

    Gater12

    What is on line 47? And may we see the full code for the onEnable method? Corndogoz
     
  3. Offline

    Corndogoz

    here is the code
    Code:java
    1. public void onEnable() {
    2.  
    3. // TODO: Place any custom enable code here including the registration of any events
    4.  
    5. // Register our events
    6. PluginManager pm = getServer().getPluginManager();
    7. pm.registerEvents(playerListener, this);
    8. pm.registerEvents(blockListener, this);
    9.  
    10. // Register our commands
    11. getCommand("/Cornpos").setExecutor(new SamplePosCommand());
    12. getCommand("/Corndebug").setExecutor(new SampleDebugCommand(this));
    13. getCommand("/Corncast").setExecutor(new SampleCorncastCommand());
    14. getCommand("/CornAFK").setExecutor(new SampleCornAfkCommand());
    15. getCommand("/CornAFKoff").setExecutor(new SampleCornAfkOffCommand());
    16. getCommand("/cornpack").setExecutor(new SampleBackpack());
    17. getCommand("/Troll join").setExecutor(new SampleTrollJoinMsg());
    18. getCommand("/Troll leave").setExecutor(new SampleTrollLeaveMsg());
    19. // EXAMPLE: Custom code, here we just output some info so we can check all is well
    20. PluginDescriptionFile pdfFile = this.getDescription();
    21. getLogger().info( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
    22. }
    23.  


    and line 47 is
    Code:java
    1. getCommand("/Cornpos").setExecutor(new SamplePosCommand());
    please help!

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

    Venexor

    Remove the "/" before each command in your onEnable. Corndogoz

    Corndogoz Also, you only register the base command. Instead of putting "Troll join" you only put "Troll".

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

    Corndogoz

    so then how do i get the join part in their?
     
  6. Offline

    Gater12

  7. Offline

    Corndogoz

    how do i do args?
     
  8. Offline

    Venexor

    Corndogoz If you created your commands correctly with arguments then registering the base command will allow you to use the base command + args in-game. However, this depends if you fixed your plugin.yml and you have checks such as " if(args[0].equalsIgnoreCase("join"); " in your creation of commands.
     
  9. Offline

    BillyBobJoe168

    the first word after the troll command is args[0]. You want to do:
    Code:java
    1. if (args.length == 1) {
    2. if (args[0].equalsIgnoreCase("join")) {
    3. //do stuff here
    4. }
    5. if (args[0].equalsIgnoreCase("leave")) {
    6. //do stuff here
    7. }
    8. }
     
  10. Offline

    Corndogoz

    i guess i didnt do it correct
    can you please tell me what todo to my code?
    here it is:
    Code:
    package com.imaboy321.welcomer;
     
    import java.util.HashMap;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    /**
    * Sample plugin for Bukkit
    *
    * @author Corndogoz
    */
    public class SamplePlugin extends JavaPlugin {
        private final SamplePlayerListener playerListener = new SamplePlayerListener(this);
        public void setDebugging(final Player player, final boolean value) {
            debugees.put(player, value);
        }
     
        private final SampleBlockListener blockListener = new SampleBlockListener();
        private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
     
        @Override
        public void onDisable() {
            // TODO: Place any custom disable code here
     
            // NOTE: All registered events are automatically unregistered when a plugin is disabled
     
            // EXAMPLE: Custom code, here we just output some info so we can check all is well
            getLogger().info("Plugin Corndogoz has been disabled");
        }
     
        @Override
        public void onEnable() {
           
            // TODO: Place any custom enable code here including the registration of any events
     
            // Register our events
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(playerListener, this);
            pm.registerEvents(blockListener, this);
     
            // Register our commands
            getCommand("Cornpos").setExecutor(new SamplePosCommand());
            getCommand("Corndebug").setExecutor(new SampleDebugCommand(this));
            getCommand("Corncast").setExecutor(new SampleCorncastCommand());
            getCommand("CornAFK").setExecutor(new SampleCornAfkCommand());
            getCommand("CornAFKoff").setExecutor(new SampleCornAfkOffCommand());
            getCommand("Cornpack").setExecutor(new SampleBackpack());
            getCommand("/Troll join").setExecutor(new SampleTrollJoinMsg());
            getCommand("/Troll leave").setExecutor(new SampleTrollLeaveMsg());
            // EXAMPLE: Custom code, here we just output some info so we can check all is well
            PluginDescriptionFile pdfFile = this.getDescription();
            getLogger().info( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
        }
     
        public boolean isDebugging(final Player player) {
            if (debugees.containsKey(player)) {
                return debugees.get(player);
            } else {
                return false;
            }
        }
    }
    BillyBobJoe168 but what is args? a varible or what is it?

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

    BillyBobJoe168

    Commands are structured like this: /command args[0] args[1] args[2] etc. Args are arguments which are words after the base command. You can use args but you never put them in your plugin.yml. You put the base command in and when you want to use args, you just put them in your main class.
    EDIT: also, I don't get what you are doing with all the register command stuff. Shouldn't you just put them in a public boolean?
     
  12. Offline

    Corndogoz

    ps, heres my troll code;
    Code:java
    1. package com.imaboy321.welcomer;
    2. import org.bukkit.Bukkit;
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. /**
    10. * Handler for the /pos sample command.
    11. * @author SpaceManiac
    12. */
    13. public class SampleTroll extends JavaPlugin implements Listener {
    14. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] split) {
    15. if (cmd.getName().equalsIgnoreCase("troll-player")){
    16. if (args.length == 1) {
    17. if (args[0].equalsIgnoreCase("join")) {
    18. Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + getConfig().getString("troll-player") + "joined the game");
    19. }
    20. if (args[0].equalsIgnoreCase("leave")) {
    21. Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + getConfig().getString("troll-player") + "left the game");
    22. }
    23. }
    24. return true;
    25. }
    26.  
    27.  
    28. return true;
    29. }
    30. }
    31.  
    32.  

    i need to define args, but what should args be?

    i dont know, i followed the tutorials, and i dont wanna risk it

    if you wouldnt mind, would you redo my code?
    Code:java
    1.  
    2. package com.imaboy321.welcomer;
    3.  
    4. import java.util.HashMap;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.PluginDescriptionFile;
    9. import org.bukkit.plugin.PluginManager;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. /**
    13. * Sample plugin for Bukkit
    14. *
    15. * @author Corndogoz
    16. */
    17. public class SamplePlugin extends JavaPlugin {
    18. private final SamplePlayerListener playerListener = new SamplePlayerListener(this);
    19. public void setDebugging(final Player player, final boolean value) {
    20. debugees.put(player, value);
    21. }
    22.  
    23. private final SampleBlockListener blockListener = new SampleBlockListener();
    24. private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
    25.  
    26. @Override
    27. public void onDisable() {
    28. // TODO: Place any custom disable code here
    29.  
    30. // NOTE: All registered events are automatically unregistered when a plugin is disabled
    31.  
    32. // EXAMPLE: Custom code, here we just output some info so we can check all is well
    33. getLogger().info("Plugin Corndogoz has been disabled");
    34. }
    35.  
    36. @Override
    37. public void onEnable() {
    38.  
    39. // TODO: Place any custom enable code here including the registration of any events
    40.  
    41. // Register our events
    42. PluginManager pm = getServer().getPluginManager();
    43. pm.registerEvents(playerListener, this);
    44. pm.registerEvents(blockListener, this);
    45.  
    46. // Register our commands
    47. getCommand("Cornpos").setExecutor(new SamplePosCommand());
    48. getCommand("Corndebug").setExecutor(new SampleDebugCommand(this));
    49. getCommand("Corncast").setExecutor(new SampleCorncastCommand());
    50. getCommand("CornAFK").setExecutor(new SampleCornAfkCommand());
    51. getCommand("CornAFKoff").setExecutor(new SampleCornAfkOffCommand());
    52. getCommand("Cornpack").setExecutor(new SampleBackpack());
    53. getCommand("Troll").setExecutor(new SampleTroll());
    54. // EXAMPLE: Custom code, here we just output some info so we can check all is well
    55. PluginDescriptionFile pdfFile = this.getDescription();
    56. getLogger().info( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
    57. }
    58.  
    59. public boolean isDebugging(final Player player) {
    60. if (debugees.containsKey(player)) {
    61. return debugees.get(player);
    62. } else {
    63. return false;
    64. }
    65. }
    66. }

    its ok if you cant, :)

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

    BillyBobJoe168

    Corndogoz Why do you have 2 return statements? also, in your public boolean, It should be String[] args not String[] split. From what I see, your command is /troll-player join/leave right? Also, what are you trying to get from the config? under if (cmd.getName().equalsIgnoreCase("troll-player") {, put Player p = (Player) sender; This way, instead of getting stuff from the config, you can just use ChatColor.YELLOW + player.getName() + "joined/left the game" If you want to use the config, you must add the player to the config before you can get anything form it.


    Um I guess I could...Might take a while since I'm doing other things at this time. I'll just get your /troll join part right if that's fine with you.

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

    Corndogoz

    ok, thats fine, but back the the thread topic, does anyone know why is says "
    ?

    my command is /troll join/leave the troll-player is in config

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

    BillyBobJoe168

    BOOM! Here is your code: You will have to also have the Player Listener class and if there is a red underline under getConfig().set then go to your player listener and hover over the @EventHandler and click the option to update the project to IDE 1.5.1 or something like that I forgot what it is exactly. Main class:
    Code:java
    1. package ericwang.forcorndogoz;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. import ericwang.forcorndogoz.PlayerListener;
    12.  
    13. public class ForCorndogoz extends JavaPlugin {
    14.  
    15. public void onEnable() {
    16. new PlayerListener(this);
    17. getConfig().options().copyDefaults(true);
    18. saveConfig();
    19. }
    20.  
    21. public void onDisable() {
    22. }
    23.  
    24. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    25. if (cmd.getName().equalsIgnoreCase("troll")) {
    26. Player player = (Player) sender;
    27. int length = args.length;
    28. if (length == 1) {
    29. if (args[0].equalsIgnoreCase("setspawn")) {
    30. getConfig().set("troll.x", player.getLocation().getX());
    31. getConfig().set("troll.y", player.getLocation().getY());
    32. getConfig().set("troll.z", player.getLocation().getZ());
    33. getConfig().set("troll.yaw", player.getLocation().getYaw());
    34. getConfig().set("troll.pitch", player.getLocation().getPitch());
    35. saveConfig();
    36. player.sendMessage("Spawn point set!");
    37. }
    38. if (args[0].equalsIgnoreCase("join")) {
    39. double x = getConfig().getDouble("troll.x");
    40. double y = getConfig().getDouble("troll.y");
    41. double z = getConfig().getDouble("troll.z");
    42. int yaw = getConfig().getInt("troll.yaw");
    43. int pitch = getConfig().getInt("troll.pitch");
    44. player.teleport(new Location(player.getWorld(), x, y, z, yaw, pitch));
    45. Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + player.getName() + " has joined the game!");
    46. }
    47. if (args[0].equalsIgnoreCase("leave")) {
    48. player.teleport(player.getWorld().getSpawnLocation());
    49. Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + player.getName() + " has left the game!");
    50. }
    51. }
    52. }
    53.  
    54.  
    55. return false;
    56.  
    57. }
    58.  
    59. }
    60.  

    Player Listener class:
    Code:java
    1. package ericwang.forcorndogoz;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.player.PlayerQuitEvent;
    9.  
    10. import ericwang.forcorndogoz.ForCorndogoz;
    11.  
    12. public class PlayerListener implements Listener {
    13.  
    14. public PlayerListener(ForCorndogoz plugin) {
    15. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    16. }
    17.  
    18. @EventHandler
    19. public void onPlayerQuit(PlayerQuitEvent event) {
    20. Player player = event.getPlayer();
    21. Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + player.getName()+ " has left the game!");
    22. }
    23.  
    24. }
    25.  

    plugin.yml:
    Code:
    name: ForCorndogoz
    main: ericwang.forcorndogoz.ForCorndogoz
    version: 0.1
    commands:
      troll:
        description: joins/leaves a game
    Don't need to do anything with the config file except create it:D
     
  16. Offline

    Corndogoz

    not exactly what i wanted, but should be helpful :D

    i have to redo my plugin, thx :D

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

    BillyBobJoe168

  18. Offline

    Corndogoz

    lol, my plugin didnt work at all before, lets test this piece of code you just wrote, if it works, when i do the other parts of the plugin, i will let u download it, :D
     
  19. Offline

    BillyBobJoe168

    Corndogoz lol ok. I did it on eclipse and tested it already so...:D
     
  20. Offline

    Corndogoz

    it works, :)
     
  21. Offline

    BillyBobJoe168

  22. Offline

    Corndogoz

    umm
    what does the player.sendMessage("Spawn point set!"); mean? why is it setting spawnpoint?

    /troll doesnt do anything

    so, umm, how do i make it take a second arg witch is the player to teleport?

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

    BillyBobJoe168

    Corndogoz Well I'm just assuming you want to make a minigame or something like that so that would teleport a player to the minigame spawnpoint(not world spawnpoint) and when they do /troll leave then they would leave the game and teleport back to spawn. You could change the teleport back to spawn to teleport back to a lobby or something or you could get rid of the teleports all together.

    /troll isn't supposed to do anythingXD. /troll is a base command. you could add if (length == 0) {player.sendMessage(ChatColor.RED + "Not enough arguments!");}
    EDIT: To make a 2nd arg, just make if (length == 2) {} and the player to teleport would go into a for loop something like for( Player playertotp : Bukkit.getServer().getOnlinePlayers()) {if (args[1] == playertotp) {playertotp.chat("troll join")}} or something similar. Haven't tested this but you will need to edit it a little probably. I need to go somewhere now so didn't have enough time to make sure this works sorry.

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

    Corndogoz

    ya, i see, thx very much, ya very useful, i want to be able todo /tptroll <player> witch will tp <player> to a place set in the config

    also, how do i make my plugin give someone an effect like blindness?

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

    BillyBobJoe168


    Code:java
    1. player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, duration, 0));
     
  26. Offline

    Corndogoz

    yay, thx!
     
  27. Offline

    Heirteir

    Corndogoz
    You need to put the command in your plugin.yml...
     
  28. Offline

    Corndogoz

    would you mind fixing this up?
    Code:java
    1. if (cmd.getName().equalsIgnoreCase("blackout")) {
    2. player.sendMessage("["+ChatColor.GREEN+"Corndogoz"+ChatColor.RESET+"] Error: You need an arg ps, im a pirate");
    3. if (length == 1) {
    4. if (args[0].equalsIgnoreCase("setblackout")) {
    5. getConfig().set("blackout.x", player.getLocation().getX());
    6. getConfig().set("blackout.y", player.getLocation().getY());
    7. getConfig().set("blackout.z", player.getLocation().getZ());
    8. getConfig().set("blackout.yaw", player.getLocation().getYaw());
    9. getConfig().set("blackout.pitch", player.getLocation().getPitch());
    10. saveConfig();
    11. Bukkit.getServer().broadcastMessage("Blackout spawn has been set, you may now use /blackout join!");
    12. }
    13. }
    14. if (args[0].equalsIgnoreCase("join")) {
    15. double x = getConfig().getDouble("blackout.x");
    16. double y = getConfig().getDouble("blackout.y");
    17. double z = getConfig().getDouble("blackout.z");
    18. int yaw = getConfig().getInt("blackout.yaw");
    19. int pitch = getConfig().getInt("blackout.pitch");
    20. player.teleport(player.getWorld().getBlackoutLocation());
    21. player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, duration, 300));
    22. }
    23. }

    at least its small this time, :)

    and how do i give the player an item?

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

    BillyBobJoe168

    Code:java
    1. if (cmd.getName().equalsIgnoreCase("blackout")) {
    2. int length == args.length;
    3. if (length == 0) {
    4. player.sendMessage("["+ChatColor.GREEN+"Corndogoz"+ChatColor.RESET+"] Error: You need an arg ps, im a pirate");
    5. }
    6. if (length == 1) {
    7. if (args[0].equalsIgnoreCase("setblackout")) {
    8. getConfig().set("blackout.x", player.getLocation().getX());
    9. getConfig().set("blackout.y", player.getLocation().getY());
    10. getConfig().set("blackout.z", player.getLocation().getZ());
    11. getConfig().set("blackout.yaw", player.getLocation().getYaw());
    12. getConfig().set("blackout.pitch", player.getLocation().getPitch());
    13. saveConfig();
    14. Bukkit.getServer().broadcastMessage("Blackout spawn has been set, you may now use /blackout join!");
    15. }
    16. if (args[0].equalsIgnoreCase("join")) {
    17. double x = getConfig().getDouble("blackout.x");
    18. double y = getConfig().getDouble("blackout.y");
    19. double z = getConfig().getDouble("blackout.z");
    20. int yaw = getConfig().getInt("blackout.yaw");
    21. int pitch = getConfig().getInt("blackout.pitch");
    22. player.teleport(player.getWorld(), x, y, z, yaw, pitch);
    23. player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 300, 0)); //this sets the blindness effect for 300 ticks
    24. }
    25. }
    26. }

    done.


    player.getInventory().addItem(new ItemStack(Material.<Itemhere>, <amount>));

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

    Corndogoz

    ok, thank you so much!

    Code:java
    1. player.teleport(player.getWorld(), x, y, z, yaw, pitch);
    gives me an error, :(

    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