how to block anything command, if player put command?

Discussion in 'Plugin Development' started by feaq16, Feb 3, 2013.

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

    feaq16

    Hello,
    I have this code:
    Code:java
    1.  
    2. package feaq16.primarycode;
    3.  
    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 primarycode extends JavaPlugin {
    11.  
    12. public void onEnable() {
    13.  
    14. }
    15.  
    16. public void onDisable() {
    17.  
    18. }
    19.  
    20. public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
    21. Player p = (Player) sender;
    22. if(commandLabel.equalsIgnoreCase("command")){
    23. p.sendMessage(ChatColor.GREEN + "This is a testing command");
    24. }
    25.  
    26. if(commandLabel.equalsIgnoreCase("command1")){
    27. p.sendMessage(ChatColor.GREEN + "This is a testing command");
    28. }
    29. return false;
    30. }
    31.  
    32. }
    33.  

    if the player enters / command, it will block all his commands (with seperate plugin) except / commnad1.
    How to do it?
     
  2. Offline

    Neodork

    Use the CommandPreprocessEvent and cancel it when you don't want the player to use the command. You might need to save the players somewhere.
     
  3. Offline

    feaq16

    I try use this, and I don't have idea how to use this.
    Show me example on my code?
     
  4. Offline

    MrPmiguelP

    Try this:
    Code:
    @EventHandler
    public void onPlayerCommand(CommandPreprocessEvent event) {
    if(!event.getMessage().equalsIgnoreCase("/command") {
        event.setCancelled();
        event.getPlayer().sendMessage("-.-"):
    } else {
        event.getPlayer().sendMessage("Hello"):
    }
    Good luck
     
  5. Offline

    feaq16

    further have idea how to use this.
    /command - block command
    /command1 - allow during event
    /command2 - canceling event

    how to do so to work?
     
  6. Offline

    macguy8

    You'd need to do it like so.

    When they type command1: Add them to a list

    When they type a command (PreProcess): check if the message is /command1 or 2, if it's NOT, then check if they're in your list. If they are, cancel the event.

    When they type command2: Remove them from the list.

    When the leave / are kicked: Remove them from the list, depending on if you want this to keep them in it after they log off
     
  7. Offline

    feaq16

    show me example on my code?

    @ref

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

    McCastleWars

    Have you tried this from above? If the command isn't /command then it cancels the event. and sends the player a message else if it is.. It sends the player a your test message
    Code:
    @EventHandler
    public void onPlayerCommand(CommandPreprocessEvent event) {
    Player p = event.getPlayer();
    if(!event.getMessage().equalsIgnoreCase("/command") {
        event.setCancelled();
        p.sendMessage("-.-"):
    } else {
        p.sendMessage(ChatColor.GREEN + "This is a testing command");
    }

    Edit1:
    Also if your gonna add the event in your main class. To register it add this to your onEnable()
    Code:
    getServer().getPluginManager().registerEvents(this,this);
    This is only a test plugin So I wont tell you how to register events in different classes.
     
  9. Offline

    feaq16

    I try this, and i don't have idea how to use this for 3 commands

    @ref

    if someone will show me how to do it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page