Using Vanilla Commands for CommandBlocks

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

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

    GeekPlaya

    Hello!

    Is it possible to use a vanilla command such as 'give' and change how it works for the player but not a command block?
     
  2. Offline

    gomeow

    You could always listen to PlayerCommandPreprocessEvent
     
  3. Offline

    GeekPlaya

    But as soon as you register a command in plugin.yml, doesn't it override the vanilla command?
     
  4. Offline

    gomeow

    You don't register them this way
     
  5. Offline

    GeekPlaya

    Could you please be a bit more specific?
     
  6. Offline

    GeekPlaya

    Leaving me hanging?
     
  7. Offline

    xXSilentYoshiXx

    GeekPlaya
    He's actually pretty busy helping other people as well. So let me lighten up your night.

    Q: You want to override vanilla commands for Bukkit?

    A: You probably can't. That's why I add new commands. (If you can, I don't know about it yet.)

    Q: You want to make it different?

    A:

    Code:java
    1. @EventHandler
    2. public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
    3. Player p = e.getPlayer();
    4. final String message = e.getMessage();
    5.  
    6. if (message.contains("give")) {
    7. // Do whatever here.
    8. }
    9. }
    10.  


    I'm pretty sure that's it.
     
  8. Offline

    gomeow

    Code:java
    1. @EventHandler
    2. public void onPlayerCommand(PlayerCommandPreprocessEvent e) {
    3. Player p = e.getPlayer();
    4. String command = e.getMessage().substring(1).spilt(" ", 1);
    5. String[] args = e.getMessage().substring(2+command.length()).split(" ");
    6. }
    7.  


    xXSilentYoshiXx
    there is no method .contains for a String, you need to do this:

    Code:java
    1. if(string1.length() != string1.replace("stuff").length()) {
    2. //String contains "stuff"
    3. }
     
Thread Status:
Not open for further replies.

Share This Page