Ejemplo n.º 1
0
  @Override
  public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
    DrugProperties drugProperties = DrugProperties.getDrugProperties(player);

    if (drugProperties != null && drugProperties.timeBreathingSmoke <= 0) {
      if (getUsedConsumable(player) != null) {
        player.setItemInUse(stack, getMaxItemUseDuration(stack));
      }
    }

    return stack;
  }
Ejemplo n.º 2
0
  @Override
  public ItemStack onEaten(ItemStack stack, World world, EntityPlayer player) {
    ItemBongConsumable usedConsumable = getUsedConsumable(player);

    if (usedConsumable != null) {
      if (IvInventoryHelper.consumeInventoryItem(player.inventory, usedConsumable.consumedItem)) {
        DrugProperties drugProperties = DrugProperties.getDrugProperties(player);

        if (drugProperties != null) {
          for (DrugInfluence influence : usedConsumable.drugInfluences) {
            drugProperties.addToDrug(influence.clone());
          }

          stack.damageItem(1, player);

          drugProperties.startBreathingSmoke(
              10 + world.rand.nextInt(10), usedConsumable.smokeColor);
        }
      }
    }

    return super.onEaten(stack, world, player);
  }
Ejemplo n.º 3
0
  @Override
  public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] arguments) {
    if (arguments.length == 1) return getListOfStringsMatchingLastWord(arguments, getPlayers());
    else if (arguments.length == 2) {
      try {
        DrugProperties drugProperties =
            DrugProperties.getDrugProperties(getPlayer(par1ICommandSender, arguments[0]));
        if (drugProperties != null) {
          String[] drugNames = drugProperties.getAllVisibleDrugNames();
          String[] drugNamesPlusAll = new String[drugNames.length + 1];
          drugNamesPlusAll[0] = "All";
          System.arraycopy(drugNames, 0, drugNamesPlusAll, 1, drugNames.length);
          return getListOfStringsMatchingLastWord(arguments, drugNamesPlusAll);
        } else return null;
      } catch (CommandException ex) {
        return null;
      }
    } else if (arguments.length == 3)
      return getListOfStringsMatchingLastWord(arguments, "set", "lock", "unlock");
    else if (arguments.length == 4)
      return getListOfStringsMatchingLastWord(arguments, "0.0", "0.5", "1.0");

    return null;
  }
Ejemplo n.º 4
0
  @Override
  public void processCommand(ICommandSender commandSender, String[] arguments) {
    if (arguments.length < 3) throw new WrongUsageException(getCommandUsage(commandSender));

    EntityPlayer player = getPlayer(commandSender, arguments[0]);

    String drugName = arguments[1];

    DrugProperties drugProperties = DrugProperties.getDrugProperties(player);
    if (drugProperties == null) return;

    Drug singleDrug = drugProperties.getDrug(drugName);
    boolean modifyAllDrugs = drugName.equalsIgnoreCase("all");
    Collection<Drug> drugs =
        singleDrug != null
            ? Arrays.asList(singleDrug)
            : modifyAllDrugs ? drugProperties.getAllDrugs() : null;
    if (drugs != null) {
      int lock = getLockMode(arguments[2], commandSender);
      if (modifyAllDrugs) drugName = "Drugs";

      drugProperties.hasChanges = true;

      if (lock != 0) {
        for (Drug drug : drugs) drug.setLocked(lock == 1);
      }

      if (arguments.length >= 4) {
        double amount = parseDouble(commandSender, arguments[3]);
        for (Drug drug : drugs) drug.setDesiredValue(amount);

        if (lock == 0)
          commandSender.addChatMessage(
              new ChatComponentTranslation(
                  "commands.drug.success",
                  player.getCommandSenderName(),
                  drugName,
                  String.valueOf(amount)));
        else if (lock == 1)
          commandSender.addChatMessage(
              new ChatComponentTranslation(
                  "commands.drug.success.lock",
                  player.getCommandSenderName(),
                  drugName,
                  String.valueOf(amount)));
        else if (lock == 2)
          commandSender.addChatMessage(
              new ChatComponentTranslation(
                  "commands.drug.success.unlock",
                  player.getCommandSenderName(),
                  drugName,
                  String.valueOf(amount)));
      } else if (lock == 0)
        throw new CommandException(
            getCommandUsage(commandSender), drugName); // Didn't actually do anything
      else if (lock == 1)
        commandSender.addChatMessage(
            new ChatComponentTranslation(
                "commands.drug.success.lock",
                player.getCommandSenderName(),
                drugName,
                drugProperties.getDrugValue(drugName)));
      else if (lock == 2)
        commandSender.addChatMessage(
            new ChatComponentTranslation(
                "commands.drug.success.unlock",
                player.getCommandSenderName(),
                drugName,
                drugProperties.getDrugValue(drugName)));
    } else {
      throw new CommandException("commands.drug.nodrug", drugName);
    }
  }