Examples of PlayerCommandPreprocessEvent


Examples of org.bukkit.event.player.PlayerCommandPreprocessEvent

        switch (Type.valueOf(type.asString())) {

        case AS_PLAYER:
            try {
                PlayerCommandPreprocessEvent pcpe = new PlayerCommandPreprocessEvent(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity(), "/" + command);
                Bukkit.getPluginManager().callEvent(pcpe);
                if (!pcpe.isCancelled())
                    ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity().performCommand(
                            pcpe.getMessage().startsWith("/") ? pcpe.getMessage().substring(1): pcpe.getMessage());
            }
            catch (Throwable e) {
                dB.echoError(scriptEntry.getResidingQueue(), "Exception while executing command as player.");
                dB.echoError(scriptEntry.getResidingQueue(), e);
            }
            return;

        case AS_OP:
            boolean isOp = ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity().isOp();
            if (!isOp) ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity().setOp(true);
            try {
                PlayerCommandPreprocessEvent pcpe = new PlayerCommandPreprocessEvent(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity(), "/" + command);
                Bukkit.getPluginManager().callEvent(pcpe);
                if (!pcpe.isCancelled())
                    ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity().performCommand(
                            pcpe.getMessage().startsWith("/") ? pcpe.getMessage().substring(1): pcpe.getMessage());
            }
            catch (Throwable e) {
                dB.echoError(scriptEntry.getResidingQueue(), "Exception while executing command as OP.");
                dB.echoError(scriptEntry.getResidingQueue(), e);
            }
View Full Code Here

Examples of org.bukkit.event.player.PlayerCommandPreprocessEvent

   * @return Whether the command was run
   */
  public final static boolean dispatchCommand(final CommandSender sender, final String command) {
    try {
      if (sender instanceof Player) {
        final PlayerCommandPreprocessEvent e = new PlayerCommandPreprocessEvent((Player) sender, "/" + command);
        Bukkit.getPluginManager().callEvent(e);
        if (e.isCancelled() || e.getMessage() == null || !e.getMessage().startsWith("/"))
          return false;
        return Bukkit.dispatchCommand(e.getPlayer(), e.getMessage().substring(1));
      } else {
        final ServerCommandEvent e = new ServerCommandEvent(sender, command);
        Bukkit.getPluginManager().callEvent(e);
        if (e.getCommand() == null || e.getCommand().isEmpty())
          return false;
        return Bukkit.dispatchCommand(e.getSender(), e.getCommand());
      }
    } catch (final Exception ex) {
      ex.printStackTrace(); // just like Bukkit
      return false;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.