Need help in developing a plugin for my server...

Discussion in 'Plugin Development' started by hiiiboy111, Mar 24, 2014.

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

    hiiiboy111

    Hello, I am just trying to create a simple "tpa" plugin like the one to essentials. However, this one will ask an administrator if it would be alright for them to teleport to the request, if so type /helpaccept. If you know what I mean here, just check this coding.
    I am farely new at this java coding, but am getting better! All comments are welcome, I would love to get this fixed to see what I did wrong.

    NOTE: I believe that the bug is inside the args methods or declaring the target/player. I typed this very fast.

    Code:java
    1. package me.voridy.tphelp;
    2.  
    3. import org.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.  
    13.  
    14. public void onEnable(){
    15. getLogger().info("Enabled!");
    16. }
    17.  
    18. public void onDisable(){
    19. getLogger().info("Disabled! :(");
    20. }
    21.  
    22.  
    23. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    24.  
    25. //This is what the player has to type
    26. //To the admin to get help
    27. if(sender instanceof Player){
    28.  
    29. //Defining the target and player
    30. //Target as in the administrator
    31. //And Player as in the Sender
    32. Player player = (Player) sender;
    33. Player target = player.getServer().getPlayer(args[0]);
    34. if (cmd.getName().equalsIgnoreCase("tphelp")) {
    35. if (args.length != 0){
    36. player.sendMessage(ChatColor.RED + "Not enough arguments...");
    37. player.sendMessage(ChatColor.RED + "Try this '/tphelp <administrator's name>'");
    38. }
    39.  
    40. //If player types correctly
    41. if (args.length != 1) {
    42. //The console will tell the player:
    43. player.sendMessage(ChatColor.YELLOW + "You have asked the admin" + ChatColor.YELLOW + (args[0]) + " for teleport help!");
    44.  
    45. //Then the console will tell the administrator
    46. target.sendMessage(ChatColor.BOLD.RED + "Player" + sender + " has asked for you to teleport to them.");
    47. target.sendMessage(ChatColor.BOLD.RED + "Type '/helpaccept <playername>' to teleport to them");
    48.  
    49. return false;
    50. }
    51. //This section shows what the administrator has to do
    52. //for the player to have the staff member teleport to
    53. //them
    54.  
    55. //This is the permissions for the admin
    56. if (player.hasPermission("tphelp.accept")){
    57. if(sender instanceof Player){
    58.  
    59.  
    60. //this is the admin command
    61. if (cmd.getName().equalsIgnoreCase("helpaccept")){
    62.  
    63. //too little arguments
    64. if (args.length != 0){
    65. target.sendMessage(ChatColor.RED + "Try typing '/helpaccept <playername>'");
    66. }
    67.  
    68. //if 1 argument, if that 1 argument = the player, then say:
    69. if (args.length != 1){
    70. target.sendMessage(ChatColor.RED + "Now teleporting...");
    71. Location requestTeleport = target.getLocation();
    72. target.teleport(requestTeleport);
    73.  
    74. }
    75.  
    76. }
    77. }
    78. }
    79. if (target == null);
    80. if (player == null);
    81. player.sendMessage(ChatColor.RED + "That player is currently offline!");
    82. target.sendMessage(ChatColor.RED + "That player is currently offline!");
    83. }
    84.  
    85.  
    86. }
    87. return false;
    88. }
    89. }
    90.  
     
  2. Offline

    JBoss925

    lol well first off the != operator means "is not equal to" so that's a problem. And I'm confused on what the problem is? Is it a tpa command that asks the operator if they want to be teleported before they are or is it a tphelp command where you ask ops for help? Please elaborate and tell me what you want to happen.
     
  3. Offline

    Booshayy

    Like JBoss925 said, you are using " if (args.length != _ )", when really you should be using " if (args.length < _)" or " if (args.length > _ )". That's only the beginning as well, there are a few other errors. I will get to those once these if statements are fixed.
     
Thread Status:
Not open for further replies.

Share This Page