Override a /pl, /plugins

Discussion in 'Plugin Development' started by Giorgio, Dec 11, 2012.

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

    Giorgio

    When ever i create this method:

    Code:
            if(commandLabel.equalsIgnoreCase("plugins")){
                Player player = (Player) sender;
                player.sendMessage(ChatColor.RED + "Error: "  + ChatColor.WHITE + "Plugins is a blocked command");
            }
    I still get the plugins list, why is this?
     
  2. Offline

    zachoooo

    You need to use the commandpreprocessevent and if its plugins then cancel the event and tell them they can't see it
     
  3. Offline

    Giorgio

    zachoooo

    Sorry, but can you give me an example.
     
  4. Offline

    HappyPikachu

    Use the CommandPreProcessEvent like you would any other then do event.setCancelled(true) followed by <Player>.sendMessage("You can't do this blah blah").
     
  5. Offline

    V10lator

    Shouldn't it be possible to overwrite commands without the need of events?

    Giorgio Did you register the command correctly in the plugin.yml? Is your message printed?
     
  6. Offline

    Giorgio

  7. Offline

    ImDeJay


    ok, seems to me like you dont know much about making plugins.

    ill make you this plugin.

    if im correct, all you want do is stop people from being able to see the /plugins list?

    Actually, im going to make this plugin configurable for anybody else that may want to use it for other means.

    give me 30 minutes.
     
  8. Offline

    RobotA69

    Look at the boss leet coder. You're not much help just making the plugin.. he's here to learn how to make them.
     
  9. Offline

    ImDeJay

    im not trying to be a boss leet coder, im still learning myself, but from the way he's explaining, he doesnt know much at all about making bukkit plugins.

    i planned on making the plugin and releasing the source to him, therefor there is no reason to be a douche.

    Im still going to make this plugin BUT, since you think im just trying to be a boss leet coder, ill do it your way...

    in your plugin.yml you need to have something like this

    Code:
    commands:
      myCommand:
        usage: /<command>
        description: "breif description"
    where as "myCommand" is what your going to use as your command like "/myCommand"
    be sure to use proper .yml formatting.
     
  10. Offline

    Tirelessly

    Code:java
    1.  
    2. @EventHandler(priority=EventPriority.HIGHEST)
    3. public void onCmd(PlayerCommandPreprocessEvent e){
    4. if(e.getMessage().startsWith("/pl")||e.getMessage().startsWith("/plugins")){
    5. e.setCancelled(true);
    6. e.getPlayer().sendMessage("You can't use this command.");
    7. }
    8. }
    9.  
     
    Giorgio likes this.
  11. Offline

    ImDeJay

    Alright, looks to me like the OP does know how to make plugins as he's already made a few in the past, so sorry to judge so fast.

    but here is the code your wanting, im just going to post my entire plugin code.
    if you have any questions, feel free to ask.

    Code:java
    1. package com.gmail.dejayyy.stopCommands;
    2.  
    3. import java.util.List;
    4.  
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class Main extends JavaPlugin implements Listener {
    12.  
    13.  
    14. public void onEnable(){
    15.  
    16. // you need to be sure to registerevents anytime your going to use any type of bukkit event.
    17.  
    18. this.getServer().getPluginManager().registerEvents(this, this);
    19.  
    20. // here, im saving the default config thats created inside the .jar into a folder so it can be modified.
    21. this.saveDefaultConfig();
    22.  
    23. }
    24.  
    25. public void onDisable(){
    26.  
    27. }
    28.  
    29. @EventHandler
    30. public void stopCommands(PlayerCommandPreprocessEvent event){
    31.  
    32. // defining 'player'
    33. Player player = event.getPlayer();
    34.  
    35. // get the error message to display to people that try to run a disabled command.
    36. String errorMSG = this.getConfig().getString("errorMSG");
    37.  
    38. //get the list of disabled commands.
    39. List<String> disabledCommands = this.getConfig().getStringList("disabledCommands");
    40.  
    41. //loop through the list of disabled commands to read them 1 by 1
    42. for(String blah : disabledCommands){
    43.  
    44. // if the command being sent is a command that is on the disabled list, we need to cancel it and send them an error message.
    45. if(event.getMessage().equalsIgnoreCase("/" + blah)){
    46.  
    47. // there is where we tell the player he/she isnt allowed to use that command!
    48. player.sendMessage(errorMSG);
    49.  
    50. // cancel the event so the command doesnt go through to be executed.
    51. event.setCancelled(true);
    52.  
    53. }
    54. }
    55.  
    56.  
    57. }
    58. }


    here is the plugin.yml

    Code:
    name: stopCommands
    main: com.gmail.dejayyy.stopCommands.Main
    description: 'Stop players from being able to access certain commands.'
    version: 1.0
    author: ImDeJay
    here is the config.yml

    Code:
    # stopCommands config
     
    # This message will be displayed to the player when he/she tries to access a disabled command
    errorMSG: "Sorry, your not allowed to use that command!"
     
    # Put the commands in which you'd like to disable here. DO NOT PUT THE "/"
    disabledCommands:
      - plugins
      - pl
      
    *EDIT*

    idk why its not tabbing out my code like it should, so sorry about that, its suppose to be tabbed correctly.
     
  12. Offline

    Giorgio

    Thank you all for your help, trying to learn how to create this for my MCTeam. Thank you
     
  13. Offline

    V10lator

    No need for a plugin if this is all that should be archived: http://wiki.bukkit.org/CraftBukkit_commands - Important part: "Default Minecraft Commands and Permissions". ;)
     
  14. Offline

    ImDeJay

    Yeah, thought there was a way to do it without a plugin just couldnt remember, but thats why i made the plugin so that you can change what commands can be disabled. Might come in handy for somebody one day, cured a few minutes of boredom anyways lol.
     
Thread Status:
Not open for further replies.

Share This Page