Help about Kinda Whisper Plugin

Discussion in 'Plugin Development' started by Brugz, Sep 9, 2012.

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

    Brugz

    What i want to do is when player types /helpme
    Its calling to one of the Admins or peoples who have permissions and if they typing /answer they could chat with out typing any commands... Well i didnt coded like 3 months and i learn by see examples
    So here is the correctly code... i didnt really started anything -_-
    MainClass

    PHP:
    package me.HelpMe.com;
     
    import java.io.File;
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class 
    MainClass extends JavaPlugin{
    public 
    Logger logger Logger.getLogger("MineCraft");
    public 
    void onDisable() {
    PluginDescriptionFile pdffile this.getDescription();
    this.logger.info(pdffile.getName() + " Is now disabled!");
    }
    public 
    void onEnable() {
    final 
    FileConfiguration config this.getConfig();
    PluginDescriptionFile pdffile this.getDescription();
    this.logger.info(pdffile.getName() + "Is now enabled!");
    config.options().copyDefaults(true);
    saveConfig();
    File config1 = new File(this.getDataFolder(), "config.yml");
    if(!
    config1.exists()) {
    saveDefaultConfig();
    }
    PluginManager pm getServer().getPluginManager();
    pm.registerEvents(new MyBlockListener(this), this);
    }
    public 
    boolean onCommand(CommandSender senderCommand cmd,
    String commandLabelString args[]) {
    Player player = (Playersender;
    if (
    commandLabel.equalsIgnoreCase("helpme")) {
    player.sendMessage(ChatColor.GREEN "Your Help request has been sended to one of the admins please wait untill someone will answer.");
    }
    return 
    false;
    }
    }
    And here is the EventClass
    PHP:
    package me.HelpMe.com;
     
    import java.util.logging.Logger;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerChatEvent;
     
    public class 
    MyBlockListener implements Listener{
    MainClass plugin;
    public 
    MyBlockListener(MainClass instance) {
    plugin instance;
    }
    public 
    Logger log Logger.getLogger("MineCraft");
    @
    EventHandler(priority EventPriority.NORMAL)
    public 
    void onPlayerChat(PlayerChatEvent event) {
    Player p event.getPlayer();
    }
    }
     
  2. Offline

    Tirelessly

    It's AsyncPlayerChatEvent now.
     
  3. Offline

    zack6849

    You could use a permission broadcast
    the syntax for that is
    Bukkit.broadcast("your message here", "permission.node");
     
  4. Offline

    Brugz

    What do u mean? How can i use it?
     
  5. Offline

    zack6849

    with the code below, only users with the permission "adminhelp.notify" would seethe message,
    Code:text
    1.  
    2. if(cmd.getName().equalsIgnoreCase("helpme")){
    3. Bukkit.broadcast(sender.getName() + " Has requested and administrators help.","adminhelp.notify");
    4. return true;
    5. }
    6.  
     
  6. Offline

    Brugz

    Thank u so much :D
    Correctly i have that:
    Code:text
    1.  
    2. package me.HelpMe.com;
    3.  
    4. import java.io.File;
    5. import java.util.logging.Logger;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.configuration.file.FileConfiguration;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.plugin.PluginDescriptionFile;
    14. import org.bukkit.plugin.PluginManager;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17. public class MainClass extends JavaPlugin{
    18. public Logger logger = Logger.getLogger("MineCraft");
    19. public void onDisable() {
    20. PluginDescriptionFile pdffile = this.getDescription();
    21. this.logger.info(pdffile.getName() + " Is now disabled!");
    22. }
    23. public void onEnable() {
    24. final FileConfiguration config = this.getConfig();
    25. PluginDescriptionFile pdffile = this.getDescription();
    26. this.logger.info(pdffile.getName() + "Is now enabled!");
    27. config.options().copyDefaults(true);
    28. saveConfig();
    29. File config1 = new File(this.getDataFolder(), "config.yml");
    30. if(!config1.exists()) {
    31. saveDefaultConfig();
    32. }
    33. PluginManager pm = getServer().getPluginManager();
    34. pm.registerEvents(new MyBlockListener(this), this);
    35. }
    36. public boolean onCommand(CommandSender sender, Command cmd,
    37. String commandLabel, String args[]) {
    38. Player player = (Player) sender;
    39. if (commandLabel.equalsIgnoreCase("helpme")) {
    40. player.sendMessage(ChatColor.GREEN + "Your Help request has been sended to one of the admins please wait untill someone will answer.");
    41. Bukkit.broadcast(ChatColor.RED + sender.getName() + " Has requested and administrators help.","adminhelp.notify");
    42. }
    43. return true;
    44. }
    45. }
    46.  

    Now i want to do then if the player then have thoose permissions types /answer they will have them own chat Like the chat in the factions plugin Im not sure how to do that can u gimme little help.
     
  7. Offline

    zack6849

    No idea how to make chat channels, sorry man
     
  8. Offline

    Brugz

    Ok i quit the idea for making chat channel
    But when player types /helpme its wont send message too one of the Admins
    This is the code
    PHP:
    package me.HelpMe.com;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class 
    MainClass extends JavaPlugin{
        public 
    Logger logger Logger.getLogger("MineCraft");
        public 
    void onDisable() {
            
    PluginDescriptionFile pdffile this.getDescription();
            
    this.logger.info(pdffile.getName() + " Is now disabled!");
        }
        public 
    void onEnable() {
            
    PluginDescriptionFile pdffile this.getDescription();
            
    this.logger.info(pdffile.getName() + "Is now enabled!");
        }
        public 
    boolean onCommand(CommandSender senderCommand cmd,
                
    String commandLabelString args[]) {
            
    Player player = (Playersender;
            if(
    cmd.getName().equalsIgnoreCase("helpme")){
            
    player.sendMessage(ChatColor.GREEN "Your Help request has been sended to one of the admins please wait untill someone will answer.");
            if(
    player.isOp()){
            
    Bukkit.broadcast(sender.getName() + " Has requested and administrators help.","adminhelp.notify");
            }
            return 
    false;
        }
            return 
    false;
    }
    }
     
  9. Offline

    QuantumDev

    Right now it's checking if the player that did the helpme command is an OP. If the player is an operator, then it will broadcast a message to everyone.

    Remove player.isOp(), and run through a loop of ALL online players and check if they're OP, then just send them the message instead of broadcasting it.
     
  10. Offline

    zack6849

    He doesn't need to have that because he is using a permission broadcast, so only players with the node adminhelp.notify will see it, but yes, he needs to remove the isOp Check because if you player was op they wouldn't need an admins help xD
     
  11. Offline

    Brugz

    Just 1 thing what do i need to write in the config
    How i set the permissions in the config?
    Config:
    Code:
    name: HelpModify by Brugz
    version: 1.3.2
    main: me.HelpMe.com.MainClass
    commands:
        helpme:
            description: sending a message to one of the Admins.
    


    Script to check if thats right:
    Code:text
    1.  
    2. package me.HelpMe.com;
    3.  
    4. import java.util.logging.Logger;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.plugin.PluginDescriptionFile;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class MainClass extends JavaPlugin{
    15. public Logger logger = Logger.getLogger("MineCraft");
    16. public void onDisable() {
    17. PluginDescriptionFile pdffile = this.getDescription();
    18. this.logger.info(pdffile.getName() + " Is now disabled!");
    19. }
    20. public void onEnable() {
    21. PluginDescriptionFile pdffile = this.getDescription();
    22. this.logger.info(pdffile.getName() + "Is now enabled!");
    23. }
    24. public boolean onCommand(CommandSender sender, Command cmd,
    25. String commandLabel, String args[]) {
    26. Player player = (Player) sender;
    27. if(cmd.getName().equalsIgnoreCase("helpme")){
    28. player.sendMessage(ChatColor.GREEN + "Your Help request has been sended to one of the admins please wait untill someone will answer.");
    29. Bukkit.broadcast(sender.getName() + " Has requested and administrators help.","adminhelp.notify");
    30. }
    31. return false;
    32. }
    33. }
    34.  

    And thank u so much for the Patience. :)

    Bump -_-

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

    zack6849

    example using my plugin.yml for an old plugin
    Code:text
    1.  
    2. main: me.zack6849.cc.TyChatClear
    3. name: TyChatClear
    4. version: 1.0
    5. commands:
    6. cc:
    7. description: clears the chat
    8. usage: /cc
    9. permission: tychat.clear
    10. permission-message: You don't have <permission>
    11. ccg:
    12. description: clears the global chat
    13. usage: /cc
    14. permission: tychat.clearall
    15. permission-message: You don't have <permission>
    16. permissions:
    17. tychat.clear:
    18. description: permission to clear the chat.
    19. tychat.clearall:
    20. description: permission to clear the whole chat
    21.  
     
Thread Status:
Not open for further replies.

Share This Page