Esempio n. 1
0
  static {
    modCommands.add(new CommandReload());
    modCommands.add(new CommandWebHook());
    modCommands.add(new CommandToken());
    modCommands.add(new CommandPort());
    modCommands.add(new CommandFormat());
    modCommands.add(new CommandOP());

    for (CommandBase commandBase : modCommands) {
      commands.add(commandBase.getCommandName());
    }
  }
Esempio n. 2
0
 @Override
 public void doCommand(ItemStack duplicator, EntityPlayerMP sender, String[] arguments) {
   try {
     String name = arguments.length == 2 ? arguments[1] : sender.getCommandSenderName();
     File file =
         new File(
             DimensionManager.getCurrentSaveRootDirectory().getPath()
                 + File.separator
                 + "managers"
                 + File.separator
                 + name
                 + ".nbt");
     if (!file.exists()) {
       throw new CommandException("Couldn't access file: " + name + ".nbt");
     }
     NBTTagCompound tagCompound = CompressedStreamTools.read(file);
     duplicator.setTagCompound(unstripBaseNBT(tagCompound));
     CommandBase.getCommandSenderAsPlayer(sender)
         .addChatComponentMessage(
             new ChatComponentText(
                 LocalizationHelper.translateFormatted(
                     "stevesaddons.command.loadSuccess", name + ".nbt")));
   } catch (IOException e) {
     throw new CommandException("stevesaddons.command.loadFailed");
   }
 }
  @Override
  public List<String> addTabCompletionOptions(ICommandSender sender, String[] args) {

    if (args.length == 2) {
      return CommandBase.getListOfStringsMatchingLastWord(
          args, MinecraftServer.getServer().getAllUsernames());
    }
    return null;
  }
Esempio n. 4
0
  @Override
  public List<String> addTabCompletionOptions(ICommandSender sender, String[] args) {

    if (args.length == 2) {
      return CommandBase.getListOfStringsFromIterableMatchingLastWord(
          args, CommandHandler.getCommandList());
    }
    return null;
  }
Esempio n. 5
0
  @Override
  public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) {
    if (args.length >= 1) {
      for (CommandBase command : modCommands) {
        if (command.getCommandName().equalsIgnoreCase(args[0])
            && command.checkPermission(server, commandSender)) {
          try {
            command.execute(server, commandSender, args);
          } catch (CommandException e) {

          }
        }
      }
    } else {
      if (commandSender instanceof EntityPlayerMP) {
        commandSender.addChatMessage(new TextComponentString(Messages.Commands.BASE_COMMAND_USAGE));
      }
      LogHelper.info(Messages.Commands.BASE_COMMAND_USAGE);
    }
  }
 @SuppressWarnings("unchecked")
 @Override
 public List<?> addTabCompletionOptions(ICommandSender sender, String[] args) {
   ArrayList<String> list = new ArrayList<String>();
   switch (args.length) {
     case 1:
       if (sender instanceof EntityPlayer) {
         list.addAll(CommandBase.getListOfStringsMatchingLastWord(args, playerCommands));
       } else {
         list.addAll(CommandBase.getListOfStringsMatchingLastWord(args, serverCommands));
       }
       break;
     case 2:
       if (args[0].equalsIgnoreCase("kick")
           || args[0].equalsIgnoreCase("setpass")
           || args[0].equalsIgnoreCase("unregister")) {
         list.addAll(
             CommandBase.getListOfStringsMatchingLastWord(
                 args,
                 FMLCommonHandler.instance().getMinecraftServerInstance().getAllUsernames()));
       }
   }
   return list;
 }
Esempio n. 7
0
  @Override
  public void handleCommand(ICommandSender sender, String[] args) {

    List<String> commandList = new ArrayList<String>(CommandHandler.getCommandList());
    Collections.sort(commandList, String.CASE_INSENSITIVE_ORDER);
    commandList.remove(getCommandName());
    for (int i = 0; i < commandList.size(); ++i) {
      String name = commandList.get(i);
      if (!CommandHandler.canUseCommand(sender, CommandHandler.getCommandPermission(name), name)) {
        commandList.remove(i--);
      }
    }
    final int pageSize = 7;
    int maxPages = (commandList.size() - 1) / pageSize;
    int page;

    try {
      page =
          args.length == 1 ? 0 : CommandBase.parseIntBounded(sender, args[1], 1, maxPages + 1) - 1;
    } catch (NumberInvalidException numberinvalidexception) {
      String commandName = args[1];
      if (!CommandHandler.getCommandExists(commandName)) {
        throw new CommandNotFoundException("info.cofh.command.notFound");
      }
      sender.addChatMessage(
          new ChatComponentTranslation("info.cofh.command." + commandName + ".syntax"));
      return;
    }

    int maxIndex = Math.min((page + 1) * pageSize, commandList.size());
    IChatComponent chatcomponenttranslation1 =
        new ChatComponentTranslation("commands.help.header", page + 1, maxPages + 1);
    chatcomponenttranslation1.getChatStyle().setColor(EnumChatFormatting.DARK_GREEN);
    sender.addChatMessage(chatcomponenttranslation1);

    for (int i = page * pageSize; i < maxIndex; ++i) {
      IChatComponent chatcomponenttranslation =
          new ChatComponentText("/cofh " + StringHelper.YELLOW + commandList.get(i));
      chatcomponenttranslation
          .getChatStyle()
          .setChatClickEvent(
              new ClickEvent(
                  ClickEvent.Action.SUGGEST_COMMAND, "/cofh syntax " + commandList.get(i)));
      sender.addChatMessage(chatcomponenttranslation);
    }
  }
Esempio n. 8
0
  public List func_180506_a(ICommandSender p_180506_1_, String p_180506_2_, BlockPos p_180506_3_) {
    ArrayList var4 = Lists.newArrayList();

    if (p_180506_2_.startsWith("/")) {
      p_180506_2_ = p_180506_2_.substring(1);
      boolean var11 = !p_180506_2_.contains(" ");
      List var12 =
          this.commandManager.getTabCompletionOptions(p_180506_1_, p_180506_2_, p_180506_3_);

      if (var12 != null) {
        Iterator var13 = var12.iterator();

        while (var13.hasNext()) {
          String var14 = (String) var13.next();

          if (var11) {
            var4.add("/" + var14);
          } else {
            var4.add(var14);
          }
        }
      }

      return var4;
    } else {
      String[] var5 = p_180506_2_.split(" ", -1);
      String var6 = var5[var5.length - 1];
      String[] var7 = this.serverConfigManager.getAllUsernames();
      int var8 = var7.length;

      for (int var9 = 0; var9 < var8; ++var9) {
        String var10 = var7[var9];

        if (CommandBase.doesStringStartWith(var6, var10)) {
          var4.add(var10);
        }
      }

      return var4;
    }
  }
Esempio n. 9
0
  /** If par2Str begins with /, then it searches for commands, otherwise it returns players. */
  public List getPossibleCompletions(ICommandSender par1ICommandSender, String par2Str) {
    ArrayList arraylist = new ArrayList();

    if (par2Str.startsWith("/")) {
      par2Str = par2Str.substring(1);
      boolean flag = !par2Str.contains(" ");
      List list = this.commandManager.getPossibleCommands(par1ICommandSender, par2Str);

      if (list != null) {
        Iterator iterator = list.iterator();

        while (iterator.hasNext()) {
          String s1 = (String) iterator.next();

          if (flag) {
            arraylist.add("/" + s1);
          } else {
            arraylist.add(s1);
          }
        }
      }

      return arraylist;
    } else {
      String[] astring = par2Str.split(" ", -1);
      String s2 = astring[astring.length - 1];
      String[] astring1 = this.serverConfigManager.getAllUsernames();
      int i = astring1.length;

      for (int j = 0; j < i; ++j) {
        String s3 = astring1[j];

        if (CommandBase.doesStringStartWith(s2, s3)) {
          arraylist.add(s3);
        }
      }

      return arraylist;
    }
  }
  @Override
  public List<String> getTabCompletionOptions(
      MinecraftServer server,
      ICommandSender iCommandSender,
      String[] typedValue,
      @Nullable BlockPos pos) {
    if (!PlayerMPUtil.isPlayer(iCommandSender)) {
      return null;
    }
    if (typedValue.length == 1) {

      EntityPlayerMP player = (EntityPlayerMP) PlayerMPUtil.castToPlayer(iCommandSender);
      if (player == null) {
        return null;
      }

      ItemStack stack = player.getHeldItemMainhand();
      if (stack == null) {
        return null;
      }

      // Get Enchantment List
      @SuppressWarnings("unchecked")
      List<String> validEnchantmentNames = new ArrayList<String>();
      Map<String, Enchantment> validEnchantments = new HashMap<String, Enchantment>();
      for (Enchantment enchantment : Enchantment.REGISTRY) {
        if (enchantment != null) {
          String name = I18n.translateToLocal(enchantment.getName()).replaceAll(" ", "");
          validEnchantmentNames.add(name);
        }
      }

      String[] validEnchantmentArray = new String[validEnchantmentNames.size()];
      validEnchantmentArray = validEnchantmentNames.toArray(validEnchantmentArray);
      return CommandBase.getListOfStringsMatchingLastWord(typedValue, validEnchantmentArray);
    }

    return null;
  }
  @SuppressWarnings("Duplicates")
  @Override
  public void execute(MinecraftServer server, ICommandSender iCommandSender, String[] args)
      throws CommandException {
    if (args.length == 0) {
      ChatHelper.sendMessage(
          iCommandSender, TextFormatting.RED + "Usage: /enchantforce <enchantmentname> [level]");
      return;
    }

    if (!PlayerMPUtil.isPlayer(iCommandSender)) {
      ChatHelper.sendMessage(iCommandSender, "Cannot enchant an item for CONSOLE");
      return;
    }

    String enchantstring = args[0];

    EntityPlayerMP player = (EntityPlayerMP) PlayerMPUtil.castToPlayer(iCommandSender);
    if (player == null) {
      ChatHelper.sendMessage(
          iCommandSender, "Cannot enchant an item for " + iCommandSender.getName());
      return;
    }

    ItemStack stack = player.getHeldItemMainhand();
    if (stack == null) {
      ChatHelper.sendMessage(iCommandSender, TextFormatting.RED + "Invalid Item held");
      return;
    }

    // Get Enchantment List
    @SuppressWarnings("unchecked")
    List<String> validEnchantmentNames = new ArrayList<String>();
    Map<String, Enchantment> validEnchantments = new HashMap<String, Enchantment>();
    for (Enchantment enchantment : Enchantment.REGISTRY) {
      if (enchantment != null) {
        String name = I18n.translateToLocal(enchantment.getName()).replaceAll(" ", "");
        validEnchantmentNames.add(name);
        validEnchantments.put(name.toLowerCase(), enchantment);
      }
    }

    @SuppressWarnings("unchecked")
    Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(stack);
    Enchantment enchantment = validEnchantments.get(enchantstring.toLowerCase());
    if (enchantment == null) {
      ChatHelper.sendMessage(
          iCommandSender, TextFormatting.RED + "Invalid enchantment: " + enchantstring);
      return;
    }

    int enchantlevel = enchantment.getMaxLevel();
    if (args.length == 2) {
      enchantlevel = CommandBase.parseInt(args[1]);
    }

    enchantments.put(enchantment, enchantlevel);

    EnchantmentHelper.setEnchantments(enchantments, stack);

    ChatHelper.sendMessage(
        iCommandSender,
        TextFormatting.GOLD
            + "Enchanted "
            + stack.getDisplayName()
            + " with "
            + TextFormatting.AQUA
            + enchantstring
            + TextFormatting.GOLD
            + " ("
            + TextFormatting.LIGHT_PURPLE
            + enchantlevel
            + TextFormatting.GOLD
            + ")");
    ChatHelper.sendAdminMessage(
        iCommandSender,
        "Enchanted "
            + stack.getDisplayName()
            + " with "
            + enchantstring
            + " ("
            + enchantlevel
            + ")");
  }
  @Override
  public void handleCommand(ICommandSender sender, String[] args) {

    if (args.length < 7) {
      sender.addChatMessage(new ChatComponentTranslation("info.cofh.command.syntaxError"));
      throw new WrongUsageException("info.cofh.command." + getCommandName() + ".syntax");
    }
    World world = sender.getEntityWorld();
    if (world.isRemote) {
      return;
    }

    ChunkCoordinates center = null;
    int i = 1;
    int xS, xL;
    if ("@".equals(args[i])) {
      center = sender.getPlayerCoordinates();
      ++i;
      xS = CommandBase.parseInt(sender, args[i++]);
    } else {
      try {
        xS = CommandBase.parseInt(sender, args[i++]);
      } catch (Throwable t) {
        center = CommandBase.getPlayer(sender, args[i - 1]).getPlayerCoordinates();
        xS = CommandBase.parseInt(sender, args[i++]);
      }
    }
    int yS = CommandBase.parseInt(sender, args[i++]), yL;
    int zS = CommandBase.parseInt(sender, args[i++]), zL;
    int t = i + 1;

    try {
      xL = CommandBase.parseInt(sender, args[i++]);
      yL = CommandBase.parseInt(sender, args[i++]);
      zL = CommandBase.parseInt(sender, args[i++]);
    } catch (Throwable e) {
      if (i > t || center == null) {
        throw Throwables.propagate(e);
      }
      --i;
      xL = xS;
      yL = yS;
      zL = zS;
    }

    if (center != null) {
      xS = center.posX - xS;
      yS = center.posY - yS;
      zS = center.posZ - zS;

      xL = center.posX + xL;
      yL = center.posY + yL;
      zL = center.posZ + zL;
    }

    yS &= ~yS >> 31; // max(yS, 0)
    yL &= ~yL >> 31; // max(yL, 0)

    if (xL < xS) {
      t = xS;
      xS = xL;
      xL = t;
    }
    if (yL < yS) {
      t = yS;
      yS = yL;
      yL = t;
    }
    if (zL < zS) {
      t = zS;
      zS = zL;
      zL = t;
    }

    if (yS > 255) {
      sender.addChatMessage(new ChatComponentTranslation("info.cofh.command.syntaxError"));
      sender.addChatMessage(
          new ChatComponentTranslation("info.cofh.command." + getCommandName() + ".syntax"));
      return;
    } else if (yL > 255) {
      yL = 255;
    }

    Block replBlock;
    int replMeta;
    String blockReplRaw;
    {
      int meta = 0;
      String blockRaw = args[i];
      blockReplRaw = blockRaw;
      t = blockRaw.indexOf('#');
      if (t > 0) {
        meta = CommandBase.parseInt(sender, blockRaw.substring(t + 1));
        blockRaw = blockRaw.substring(0, t);
      }
      Block block = Block.getBlockFromName(blockRaw);
      if (block == Blocks.air || meta > 15 || meta < 0) {
        sender.addChatMessage(new ChatComponentTranslation("info.cofh.command.syntaxError"));
        sender.addChatMessage(
            new ChatComponentTranslation("info.cofh.command." + getCommandName() + ".syntax"));
        // TODO: more descriptive error
        return;
      }
      replBlock = block;
      replMeta = meta;
    }

    long blockCounter = ((long) xL - xS) * ((long) yL - yS) * ((long) zL - zS);
    CommandHandler.logAdminCommand(
        sender,
        this,
        "info.cofh.command.replaceblocks.start",
        blockCounter,
        xS,
        yS,
        zS,
        xL,
        yL,
        zL,
        blockReplRaw);

    THashSet<Chunk> set = new THashSet<Chunk>();

    blockCounter = 0;
    for (int e = args.length; i < e; ++i) {
      String blockRaw = args[i];
      if (blockRaw.charAt(0) == '*') {
        if (blockRaw.equals("*fluid")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.getMaterial().isLiquid()) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*tree")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.isWood(world, x, y, z) || block.isLeaves(world, x, y, z)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.startsWith("*repl")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.isReplaceable(world, x, y, z)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*stone")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.isReplaceableOreGen(world, x, y, z, Blocks.stone)
                    || block.isReplaceableOreGen(world, x, y, z, Blocks.netherrack)
                    || block.isReplaceableOreGen(world, x, y, z, Blocks.end_stone)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*rock")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.getMaterial() == Material.rock) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*sand")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                if (block.getMaterial() == Material.sand) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*dirt")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                Material m = block.getMaterial();
                if (m == Material.grass
                    || m == Material.ground
                    || m == Material.clay
                    || m == Material.snow
                    || m == Material.craftedSnow
                    || m == Material.ice
                    || m == Material.packedIce) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.startsWith("*plant")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                Material m = block.getMaterial();
                if (m == Material.plants
                    || m == Material.vine
                    || m == Material.cactus
                    || m == Material.leaves) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        } else if (blockRaw.equals("*fire")) {
          for (int x = xS; x <= xL; ++x) {
            for (int z = zS; z <= zL; ++z) {
              Chunk chunk = world.getChunkFromBlockCoords(x, z);
              int cX = x & 15, cZ = z & 15;
              for (int y = yS; y <= yL; ++y) {
                Block block = chunk.getBlock(cX, y, cZ);
                Material m = block.getMaterial();
                if (m == Material.fire || m == Material.lava || block.isBurning(world, x, y, z)) {
                  if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                    ++blockCounter;
                    set.add(chunk);
                  }
                }
              }
            }
          }
        }
        continue;
      }
      int meta = -1;
      t = blockRaw.indexOf('#');
      if (t > 0) {
        meta = CommandBase.parseInt(sender, blockRaw.substring(t + 1));
        blockRaw = blockRaw.substring(0, t);
      }
      Block block = Block.getBlockFromName(blockRaw);
      if (block == Blocks.air) {
        continue;
      }

      for (int x = xS; x <= xL; ++x) {
        for (int z = zS; z <= zL; ++z) {
          Chunk chunk = world.getChunkFromBlockCoords(x, z);
          int cX = x & 15, cZ = z & 15;
          for (int y = yS; y <= yL; ++y) {
            boolean v = meta == -1 || chunk.getBlockMetadata(cX, y, cZ) == meta;
            if (v && chunk.getBlock(cX, y, cZ) == block) {
              if (chunk.func_150807_a(cX, y, cZ, replBlock, replMeta)) {
                ++blockCounter;
                set.add(chunk);
              }
            }
          }
        }
      }
    }
    if (!set.isEmpty()) {
      CommandHandler.logAdminCommand(
          sender,
          this,
          "info.cofh.command.replaceblocks.success",
          blockCounter,
          xS,
          yS,
          zS,
          xL,
          yL,
          zL,
          blockReplRaw);
    } else {
      CommandHandler.logAdminCommand(sender, this, "info.cofh.command.replaceblocks.failure");
    }

    if (world instanceof WorldServer) {
      TObjectHashIterator<Chunk> c = set.iterator();
      for (int k = 0, e = set.size(); k < e; ++k) {
        Chunk chunk = c.next();
        PlayerManager manager = ((WorldServer) world).getPlayerManager();
        if (manager == null) {
          return;
        }
        PlayerInstance watcher =
            manager.getOrCreateChunkWatcher(chunk.xPosition, chunk.zPosition, false);
        if (watcher != null) {
          watcher.sendToAllPlayersWatchingChunk(new S21PacketChunkData(chunk, false, -1));
        }
      }
    }
  }