How do I declare player in general?

Discussion in 'Plugin Development' started by football70500, Nov 3, 2012.

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

    football70500

    I forgot how to declare the general player in bukkit. Meaning any random player that joins. What do I make Player p = ? This is prbably very simple but I had a brain fart and forgot =(
     
  2. Offline

    iTechRemix

    You would do:

    PHP:
    Player p event.getPlayer();
    That assumes that your event variable is called "event".
     
  3. Offline

    football70500

    getPlayer gets underlined

    Code:JAVA
    1. public boolean onCommand(CommandSender sender, Command command, String c, String[] args, Event event){
    2. Player send = (Player) sender;
    3. Player player = event.getPlayer();
    4. if(command.getName().equalsIgnoreCase("griefhere") && send.hasPermission("sc.slay")){
    5. if (sender instanceof Player){
    6. send.sendMessage(ChatColor.GREEN + "Mods have been notified of this grief.");
    7. return true;
    8. }
    9. if(player.hasPermission("ma.get")){
    10. player.sendMessage(ChatColor.GREEN + send.getDisplayName() + " has found grief, teleport to them to fix it.");
    11. return true;
    12. }
    13. }
    14. return false;
    15.  
    16.  
    17. }
    18. }
    19.  
     
  4. Offline

    iTechRemix

    Sorry, didn't know you were doing it in your onCommand. :) In that case, you should just be able to use your "send" variable you made. The "event.getPlayer()" won't work in an onCommand method.

    Tell me if that works!
     
  5. cant you do "sender" insteadof "player"
    you can do sender.hasPermission
    you can do sender.sendMessage
     
    ZeusAllMighty11 likes this.
  6. Offline

    raGan.

    What you probably want to do is broadcast message to all players with specified permission. It is done by Bukkit.broadcast(message, permission)

    Another thing is, you return true right after you find out that sender is player, which is before you notify mods.
     
  7. Offline

    football70500

    How do I adress the permission? just as the normal ma.get or do "ma.get" or something? I can use chatColor, right?
     
  8. Offline

    raGan.

    message is String, which may contain colors. Permission is string like.this, which should not contain colors.
     
  9. Offline

    football70500

    I did that, I think :p

    Code:JAVA
    1. public boolean onCommand(CommandSender sender, Command command, String c, String[] args){
    2. Player send = (Player) sender;
    3. if(command.getName().equalsIgnoreCase("griefhere")){
    4. if (sender instanceof Player){
    5. send.sendMessage(ChatColor.GREEN + "Mods have been notified of this grief");
    6. if(send.hasPermission("ma.getticket")){
    7. send.sendMessage(ChatColor.GREEN + send.getDisplayName() + ChatColor.GOLD + " has found grief, telelport to them to fix it!");
    8. }
    9. return true;
    10. }
    11. }
    12. return false;
    13.  
    14.  
    15. }
     
  10. Offline

    raGan.

    What you have done is that when someone types /griefhere, it tells him "Mods have been notified of this grief" and if he has "ma.getticket" permission, it also tells him "(His name) has found grief, telelport to them to fix it!"

    replace
    Code:
    if(send.hasPermission("ma.getticket")){
    send.sendMessage(ChatColor.GREEN + send.getDisplayName() + ChatColor.GOLD + " has found grief, telelport to them to fix it!");
    }
    with
    Code:
    Bukkit.broadcast(ChatColor.GREEN + send.getDisplayName() + ChatColor.GOLD + " has found grief, telelport to them to fix it!", "ma.getticket")
    This way, everyone who has "ma.getticket" will recieve message with the name of the one who issued a command.

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

    football70500

    Still nothing :p my plugin.yml is fine.
     
  12. Offline

    iTechRemix

    I have been away for a little while, so I don't know exactly where you are in all of this, but have you registered your permissions and commands in your plugin.yml?
     
  13. Offline

    raGan.

    I don't understand.
     
  14. Offline

    football70500

    Neither do I... I've been making commands the same for the past year and never had this problem. EVER.
    Code:JAVA
    1. name: ModAssistance
    2. version: 1.0
    3. main: me.football70500.modassistance.ma
    4. commands:
    5. griefhere:
    6. description: Notifies online moderators of grief.
    7.  
     
  15. Offline

    raGan.

    plugin.yml looks good, as long as your main class is "ma". I still don't get why my replacement solution doesn't work.
     
  16. Offline

    iTechRemix

    Maybe try putting your permissions in your plugin.yml. I got a NPE on my plugin if I didn't...
     
  17. Offline

    fireblast709

    Could be true, but as always this will be depending on the stacktrace :3
     
  18. Offline

    iTechRemix

    Yea, I know, I just said that cause I haven't seen his stacktrace :p
     
  19. Offline

    football70500

    Must just hate us XD
     
  20. Offline

    raGan.

    But really, is there anything wrong with it ? What is expected behavior and what is actual behavior ?
     
Thread Status:
Not open for further replies.

Share This Page