Esempio n. 1
0
  private void handleChange(CommandSender sender, String newMob) {
    if (sender instanceof Player) {
      if (su.isUnkown(newMob)) {
        su.sendMessage(
            sender,
            ChatColor.translateAlternateColorCodes(
                    '\u0026', plugin.localization.getString("unknownCreature"))
                .replace("%creature%", newMob));
        return;
      }

      // entityID
      short entityID = su.name2Eid.get(newMob);
      String creature = su.getCreatureName(entityID);
      // Filter spaces (like Zombie Pigman)
      String mobName = creature.toLowerCase().replace(" ", "");

      Player player = (Player) sender;

      int distance = plugin.config.getInt("spawnerCommandReachDistance", 6);
      // If the distance is -1, return
      if (distance != -1) {
        // Get the block
        Block block = su.nmsProvider.getSpawnerFacing(player, distance);
        if (block != null) {
          handleBlockChange(player, block, entityID, mobName);
          return;
        }
      }

      ItemStack itemInHand = su.nmsProvider.getSpawnerItemInHand(player);
      Material itemMaterial;
      try {
        itemMaterial = itemInHand.getType();
      } catch (NullPointerException e) {
        itemMaterial = null;
      }

      if (itemMaterial != null && itemMaterial == Material.MOB_SPAWNER) {
        handleChangeSpawner(player, entityID, mobName, itemInHand);
      } else if (itemMaterial != null && itemMaterial == SilkUtil.SPAWN_EGG) {
        handleChangeEgg(player, entityID, mobName, itemInHand);
      } else {
        su.sendMessage(
            player,
            ChatColor.translateAlternateColorCodes(
                '\u0026', plugin.localization.getString("spawnerNotDeterminable")));
      }
    } else {
      su.sendMessage(
          sender,
          ChatColor.translateAlternateColorCodes(
              '\u0026', plugin.localization.getString("noConsole")));
    }
  }
Esempio n. 2
0
  private void handleGiveSpawner(CommandSender sender, Player receiver, String mob, int amount) {
    if (su.isUnkown(mob)) {
      su.sendMessage(
          sender,
          ChatColor.translateAlternateColorCodes(
                  '\u0026', plugin.localization.getString("unknownCreature"))
              .replace("%creature%", mob));
      return;
    }

    short entityID = su.name2Eid.get(mob);
    String creature = su.getCreatureName(entityID);
    // Filter spaces (like Zombie Pigman)
    String mobName = creature.toLowerCase().replace(" ", "");

    // Add spawner
    if (sender.hasPermission("silkspawners.freeitem." + mobName)) {
      // Have space in inventory
      if (receiver.getInventory().firstEmpty() == -1) {
        su.sendMessage(
            sender,
            ChatColor.translateAlternateColorCodes(
                '\u0026', plugin.localization.getString("noFreeSlot")));
        return;
      }
      receiver
          .getInventory()
          .addItem(
              su.newSpawnerItem(
                  entityID, su.getCustomSpawnerName(su.eid2MobID.get(entityID)), amount, false));
      if (sender instanceof Player) {
        Player pSender = (Player) sender;
        if (pSender.getUniqueId() == receiver.getUniqueId()) {
          su.sendMessage(
              sender,
              ChatColor.translateAlternateColorCodes(
                      '\u0026', plugin.localization.getString("addedSpawner"))
                  .replace("%creature%", creature)
                  .replace("%amount%", Integer.toString(amount)));
        } else {
          su.sendMessage(
              sender,
              ChatColor.translateAlternateColorCodes(
                      '\u0026',
                      plugin
                          .localization
                          .getString("addedSpawnerOtherPlayer")
                          .replace("%player%", receiver.getName()))
                  .replace("%creature%", creature)
                  .replace("%amount%", Integer.toString(amount)));
        }
      } else {
        su.sendMessage(
            sender,
            ChatColor.translateAlternateColorCodes(
                    '\u0026',
                    plugin
                        .localization
                        .getString("addedSpawnerOtherPlayer")
                        .replace("%player%", receiver.getName()))
                .replace("%creature%", creature)
                .replace("%amount%", Integer.toString(amount)));
      }
      return;
    }
    su.sendMessage(
        sender,
        ChatColor.translateAlternateColorCodes(
            '\u0026', plugin.localization.getString("noPermissionFreeSpawner")));
  }