Strange issue with vanilla /execute command and CommandSender type.

Discussion in 'Spigot Plugin Development' started by FlyingLlama, Jun 20, 2015.

  1. I am attempting to process a command that is being run via /execute (vanilla command that makes targeted entities run another command with inherited permissions) from nearby entities (including players, mobs and arrows). It does not work in any fashion at all, for no clear reason.

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)

    if(sender instanceof Player)"Player");
    if(sender instanceof Entity)"Entity");
    if(sender instanceof BlockCommandSender)"block");
    if(sender instanceof LivingEntity)"Living");
    if(sender instanceof ConsoleCommandSender)"ccs");

    The following code return the sender name and applicable types when run directly by a player or console, but if run on a player via /execute @p, all if( instanceof ) tests fail and only the name is returned. The same behavior results from making an entity run the command.

    The issue appears to be that commands run via /execute cannot be cast into Entity or Player and are not recognized as such, but the same command run directly is.

    I would prefer an explanation of what is going on, if anyone has one, not questions about why i would even want to do this (easy interaction with commandblocks and other plugins), and suggestions to not even try.
  2. Why not debug it with a simple System.out.println(sender)?
  3. [19:16:44 INFO]: command /execute @p ~ ~ ~ runentity
    [19:16:44 INFO]: [CmdRandomize] Shiny_Latias
    [19:16:44 INFO]: or[email protected]145b4fee

    [19:16:57 INFO]: command /runentity
    [19:16:57 INFO]: [CmdRandomize] Shiny_Latias
    [19:16:57 INFO]: CraftPlayer{name=Shiny_Latias}

    Thank you. i have figured out that it seems to be a ProxiedCommandSender type. The ProxiedNativeCommandSender seems to be missing from the javadocs though.