Need help pls

Discussion in 'Plugin Development' started by Bush, Oct 7, 2011.

?

Will this be a handy plugin when done?

  1. Yes

    2 vote(s)
    66.7%
  2. No

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

    Bush

    Can anyone pls help me with the following pease of code, i can't get it to work
    Code:
    http://pastie.org/2657734
    plugin.yml
    http://pastie.org/2657740
    the last command /tpto will not register, when i use it in game it returns the usage of it to me, and if any1 can tell me how i can get the name entered with the cammand as a variable i will be very thankfull
     
  2. Offline

    wwsean08

    nobody's gonna help you if you don't say whats wrong with it, and any errors given to you in the console
     
  3. Offline

    Bush

    beter?
     
  4. Offline

    wwsean08

    it is, however i'm not seeing any problems so i'll let others look, maybe you'll get lucky
     
  5. Offline

    Bush

  6. Offline

    emericask8ur

    Remember to return true; !
     
  7. Offline

    wwsean08

    can't believe i missed that
     
    emericask8ur likes this.
  8. Offline

    Celeixen

    So you know from now on, if it sends back the usage you havent returned true.
     
  9. Offline

    Bush

    i added the return true now; but now nothing happens, it looks to me like i'm doing this wrong.. i'am not getiing the player name as input correctly
    this is new code
    http://pastie.org/2659202
     
  10. Offline

    Ahniolator

    Code:java
    1. package me.bush.banplayertp;
    2. import java.io.File;
    3. import java.util.logging.Logger;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.plugin.PluginDescriptionFile;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. import org.bukkit.util.config.Configuration;
    10. public class BanPlayerTP extends JavaPlugin {
    11. private Logger log = Logger.getLogger("Minecraft");
    12. public Configuration config, Hdata;
    13. public File directory;
    14. @Override
    15. public void onDisable() {
    16. this.logMessage("Disabled");
    17. Hdata.save();
    18. }
    19. @Override
    20. public void onEnable() {
    21. Hdata = getConfiguration();
    22. File configs = new File(getDataFolder() + File.separator + "Hdata.yml");
    23. Hdata = new Configuration(configs);
    24. Hdata.load();
    25. Hdata.setHeader("#This is a list of players, if set to false then tping to the is disabled");
    26. Hdata.save();
    27. this.logMessage("Enabled");
    28. }
    29. protected void logMessage(String msg) {
    30. PluginDescriptionFile pdFile = this.getDescription();
    31. this.log.info(pdFile.getName() + " " + pdFile.getVersion() + ": " + msg);
    32. }
    33. public boolean onCommand(CommandSender sender, Command cmd,
    34. String commandLabel, String[] args) {
    35. if (sender instanceof Player) {
    36. if (cmd.getName().equalsIgnoreCase("tpdisable")) {
    37. Player p = (Player) sender;
    38. Hdata.getBoolean("Players."+p.getDisplayName()+".enabled", false);
    39. Hdata.save();
    40. p.sendMessage("Nobody can teleport to you now.");
    41. return true;
    42. }
    43. if (cmd.getName().equalsIgnoreCase("tpenable")) {
    44. Player p = (Player) sender;
    45. Hdata.getBoolean("Players."+p.getDisplayName()+".enabled", true);
    46. Hdata.save();
    47. p.sendMessage("Players can teleport to you again");
    48. return true;
    49. }
    50. if (cmd.getName().equalsIgnoreCase("tpto")) {
    51. Player p = (Player) sender;
    52. Player target = getServer().getPlayer(args[0]);
    53. if (Hdata.getBoolean("Players."+target.getDisplayName()+".enabled", true))
    54. {
    55. p.teleport(target);
    56. }
    57. else if (Hdata.getBoolean("Players."+target.getDisplayName()+".enabled", false))
    58. {
    59. p.sendMessage("Teleporting to that player is disabled");
    60. }
    61. return true;
    62. }
    63. }
    64. return false;
    65. }
    66. }
    Well, first off on lines 44 and 51, you are not actually setting a boolean value, you are getting it, so calling Hdata.save(); will not do you any good. In order to set anything in a config file or otherwise, the appropriate usage for setting a boolean value would be:
    Code:java
    1. Hdata.setProperty("Players."+p.getDisplayName()".enabled", true);


    I'd also recommend changing p.getDisplayName to p.getName(), so if their display name changes you still retrieve the same data for the same person

    Edit: And I just realized how broken my English was in the previous paragraph. :p
     
  11. Offline

    Bush

    @Ahniolator
    i did what you said, but still nothing, it seems like the command isn't registring and so its doing nothing.
     
  12. Offline

    Ahniolator

    Did you register the commands in your plugin.yml?

    Edit: Also on line 52 in my previous post, you check for a player by name on the server. If the player's name doesn't exist on the server it will return null and you will get a nullpointer exception when you call the code after line 52. I recommend checking if that player is null and if the player is null then sending the player a custom error message and returning null
     
  13. Offline

    Bush

    do you maybe know how the original tp command was coded?
    where you would say /tp bush Ahniolator?? how did they get the player names entered?
     
  14. Offline

    Ahniolator

    I need you to post your plugin.yml. Otherwise I can't accurately say whether or not you are doing it right.
     
  15. Offline

    Bush

  16. /tp bush Ahniolator
    args[0] is equal to "bush"
    args[1] is equal to "Ahniolator"
     
  17. Offline

    Razorcane

    it may also help if you do p.teleport(target.getLocation());
     
  18. Offline

    Bush

    @Ribesg
    @Razorcane
    i think it works now, just need to test it, but i need some1 willing to test it with me
     
  19. Offline

    Celeixen

    Just run two minecrafts at the same time, start one offline by logging in with a bad password & then login normally with the other.
     
  20. Offline

    Bush

    Last edited by a moderator: May 20, 2016
Thread Status:
Not open for further replies.

Share This Page